ehci-sysfs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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(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(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(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 frame, uframe;
  89. unsigned short allocated_max;
  90. unsigned long flags;
  91. ssize_t ret;
  92. ehci = hcd_to_ehci(dev_get_drvdata(dev));
  93. if (kstrtouint(buf, 0, &uframe_periodic_max) < 0)
  94. return -EINVAL;
  95. if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) {
  96. ehci_info(ehci, "rejecting invalid request for "
  97. "uframe_periodic_max=%u\n", uframe_periodic_max);
  98. return -EINVAL;
  99. }
  100. ret = -EINVAL;
  101. /*
  102. * lock, so that our checking does not race with possible periodic
  103. * bandwidth allocation through submitting new urbs.
  104. */
  105. spin_lock_irqsave (&ehci->lock, flags);
  106. /*
  107. * for request to decrease max periodic bandwidth, we have to check
  108. * every microframe in the schedule to see whether the decrease is
  109. * possible.
  110. */
  111. if (uframe_periodic_max < ehci->uframe_periodic_max) {
  112. allocated_max = 0;
  113. for (frame = 0; frame < ehci->periodic_size; ++frame)
  114. for (uframe = 0; uframe < 7; ++uframe)
  115. allocated_max = max(allocated_max,
  116. periodic_usecs (ehci, frame, uframe));
  117. if (allocated_max > uframe_periodic_max) {
  118. ehci_info(ehci,
  119. "cannot decrease uframe_periodic_max becase "
  120. "periodic bandwidth is already allocated "
  121. "(%u > %u)\n",
  122. allocated_max, uframe_periodic_max);
  123. goto out_unlock;
  124. }
  125. }
  126. /* increasing is always ok */
  127. ehci_info(ehci, "setting max periodic bandwidth to %u%% "
  128. "(== %u usec/uframe)\n",
  129. 100*uframe_periodic_max/125, uframe_periodic_max);
  130. if (uframe_periodic_max != 100)
  131. ehci_warn(ehci, "max periodic bandwidth set is non-standard\n");
  132. ehci->uframe_periodic_max = uframe_periodic_max;
  133. ret = count;
  134. out_unlock:
  135. spin_unlock_irqrestore (&ehci->lock, flags);
  136. return ret;
  137. }
  138. static DEVICE_ATTR(uframe_periodic_max, 0644, show_uframe_periodic_max, store_uframe_periodic_max);
  139. static inline int create_sysfs_files(struct ehci_hcd *ehci)
  140. {
  141. struct device *controller = ehci_to_hcd(ehci)->self.controller;
  142. int i = 0;
  143. /* with integrated TT there is no companion! */
  144. if (!ehci_is_TDI(ehci))
  145. i = device_create_file(controller, &dev_attr_companion);
  146. if (i)
  147. goto out;
  148. i = device_create_file(controller, &dev_attr_uframe_periodic_max);
  149. out:
  150. return i;
  151. }
  152. static inline void remove_sysfs_files(struct ehci_hcd *ehci)
  153. {
  154. struct device *controller = ehci_to_hcd(ehci)->self.controller;
  155. /* with integrated TT there is no companion! */
  156. if (!ehci_is_TDI(ehci))
  157. device_remove_file(controller, &dev_attr_companion);
  158. device_remove_file(controller, &dev_attr_uframe_periodic_max);
  159. }