ehci-sysfs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2007 by Alan Stern
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* this file is part of ehci-hcd.c */
  19. /* Display the ports dedicated to the companion controller */
  20. static ssize_t show_companion(struct device *dev,
  21. struct device_attribute *attr,
  22. char *buf)
  23. {
  24. struct ehci_hcd *ehci;
  25. int nports, index, n;
  26. int count = PAGE_SIZE;
  27. char *ptr = buf;
  28. ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
  29. nports = HCS_N_PORTS(ehci->hcs_params);
  30. for (index = 0; index < nports; ++index) {
  31. if (test_bit(index, &ehci->companion_ports)) {
  32. n = scnprintf(ptr, count, "%d\n", index + 1);
  33. ptr += n;
  34. count -= n;
  35. }
  36. }
  37. return ptr - buf;
  38. }
  39. /*
  40. * Dedicate or undedicate a port to the companion controller.
  41. * Syntax is "[-]portnum", where a leading '-' sign means
  42. * return control of the port to the EHCI controller.
  43. */
  44. static ssize_t store_companion(struct device *dev,
  45. struct device_attribute *attr,
  46. const char *buf, size_t count)
  47. {
  48. struct ehci_hcd *ehci;
  49. int portnum, new_owner;
  50. ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
  51. new_owner = PORT_OWNER; /* Owned by companion */
  52. if (sscanf(buf, "%d", &portnum) != 1)
  53. return -EINVAL;
  54. if (portnum < 0) {
  55. portnum = - portnum;
  56. new_owner = 0; /* Owned by EHCI */
  57. }
  58. if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
  59. return -ENOENT;
  60. portnum--;
  61. if (new_owner)
  62. set_bit(portnum, &ehci->companion_ports);
  63. else
  64. clear_bit(portnum, &ehci->companion_ports);
  65. set_owner(ehci, portnum, new_owner);
  66. return count;
  67. }
  68. static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
  69. /*
  70. * Display / Set uframe_periodic_max
  71. */
  72. static ssize_t show_uframe_periodic_max(struct device *dev,
  73. struct device_attribute *attr,
  74. char *buf)
  75. {
  76. struct ehci_hcd *ehci;
  77. int n;
  78. ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
  79. n = scnprintf(buf, PAGE_SIZE, "%d\n", ehci->uframe_periodic_max);
  80. return n;
  81. }
  82. static ssize_t store_uframe_periodic_max(struct device *dev,
  83. struct device_attribute *attr,
  84. const char *buf, size_t count)
  85. {
  86. struct ehci_hcd *ehci;
  87. unsigned uframe_periodic_max;
  88. unsigned uframe;
  89. unsigned long flags;
  90. ssize_t ret;
  91. ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
  92. if (kstrtouint(buf, 0, &uframe_periodic_max) < 0)
  93. return -EINVAL;
  94. if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) {
  95. ehci_info(ehci, "rejecting invalid request for "
  96. "uframe_periodic_max=%u\n", uframe_periodic_max);
  97. return -EINVAL;
  98. }
  99. ret = -EINVAL;
  100. /*
  101. * lock, so that our checking does not race with possible periodic
  102. * bandwidth allocation through submitting new urbs.
  103. */
  104. spin_lock_irqsave (&ehci->lock, flags);
  105. /*
  106. * for request to decrease max periodic bandwidth, we have to check
  107. * to see whether the decrease is possible.
  108. */
  109. if (uframe_periodic_max < ehci->uframe_periodic_max) {
  110. u8 allocated_max = 0;
  111. for (uframe = 0; uframe < EHCI_BANDWIDTH_SIZE; ++uframe)
  112. allocated_max = max(allocated_max,
  113. ehci->bandwidth[uframe]);
  114. if (allocated_max > uframe_periodic_max) {
  115. ehci_info(ehci,
  116. "cannot decrease uframe_periodic_max because "
  117. "periodic bandwidth is already allocated "
  118. "(%u > %u)\n",
  119. allocated_max, uframe_periodic_max);
  120. goto out_unlock;
  121. }
  122. }
  123. /* increasing is always ok */
  124. ehci_info(ehci, "setting max periodic bandwidth to %u%% "
  125. "(== %u usec/uframe)\n",
  126. 100*uframe_periodic_max/125, uframe_periodic_max);
  127. if (uframe_periodic_max != 100)
  128. ehci_warn(ehci, "max periodic bandwidth set is non-standard\n");
  129. ehci->uframe_periodic_max = uframe_periodic_max;
  130. ret = count;
  131. out_unlock:
  132. spin_unlock_irqrestore (&ehci->lock, flags);
  133. return ret;
  134. }
  135. static DEVICE_ATTR(uframe_periodic_max, 0644, show_uframe_periodic_max, store_uframe_periodic_max);
  136. static inline int create_sysfs_files(struct ehci_hcd *ehci)
  137. {
  138. struct device *controller = ehci_to_hcd(ehci)->self.controller;
  139. int i = 0;
  140. /* with integrated TT there is no companion! */
  141. if (!ehci_is_TDI(ehci))
  142. i = device_create_file(controller, &dev_attr_companion);
  143. if (i)
  144. goto out;
  145. i = device_create_file(controller, &dev_attr_uframe_periodic_max);
  146. out:
  147. return i;
  148. }
  149. static inline void remove_sysfs_files(struct ehci_hcd *ehci)
  150. {
  151. struct device *controller = ehci_to_hcd(ehci)->self.controller;
  152. /* with integrated TT there is no companion! */
  153. if (!ehci_is_TDI(ehci))
  154. device_remove_file(controller, &dev_attr_companion);
  155. device_remove_file(controller, &dev_attr_uframe_periodic_max);
  156. }