diff options
Diffstat (limited to 'drivers/usb/host')
-rw-r--r-- | drivers/usb/host/Kconfig | 23 | ||||
-rw-r--r-- | drivers/usb/host/ehci-au1xxx.c | 21 | ||||
-rw-r--r-- | drivers/usb/host/ehci-fsl.c | 37 | ||||
-rw-r--r-- | drivers/usb/host/ehci-hcd.c | 50 | ||||
-rw-r--r-- | drivers/usb/host/ehci-pci.c | 59 | ||||
-rw-r--r-- | drivers/usb/host/ehci-sched.c | 216 | ||||
-rw-r--r-- | drivers/usb/host/isp116x-hcd.c | 4 | ||||
-rw-r--r-- | drivers/usb/host/ohci-pxa27x.c | 3 | ||||
-rw-r--r-- | drivers/usb/host/sl811-hcd.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/sl811_cs.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/uhci-debug.c | 45 | ||||
-rw-r--r-- | drivers/usb/host/uhci-hcd.c | 139 | ||||
-rw-r--r-- | drivers/usb/host/uhci-hcd.h | 81 | ||||
-rw-r--r-- | drivers/usb/host/uhci-hub.c | 5 | ||||
-rw-r--r-- | drivers/usb/host/uhci-q.c | 947 |
15 files changed, 994 insertions, 640 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index e27b79a3c05f..b93d71d28db7 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -47,12 +47,29 @@ config USB_EHCI_ROOT_HUB_TT | |||
47 | controller is needed. It's safe to say "y" even if your | 47 | controller is needed. It's safe to say "y" even if your |
48 | controller doesn't support this feature. | 48 | controller doesn't support this feature. |
49 | 49 | ||
50 | This supports the EHCI implementation from TransDimension Inc. | 50 | This supports the EHCI implementation that's originally |
51 | from ARC, and has since changed hands a few times. | ||
52 | |||
53 | config USB_EHCI_TT_NEWSCHED | ||
54 | bool "Improved Transaction Translator scheduling (EXPERIMENTAL)" | ||
55 | depends on USB_EHCI_HCD && EXPERIMENTAL | ||
56 | ---help--- | ||
57 | This changes the periodic scheduling code to fill more of the low | ||
58 | and full speed bandwidth available from the Transaction Translator | ||
59 | (TT) in USB 2.0 hubs. Without this, only one transfer will be | ||
60 | issued in each microframe, significantly reducing the number of | ||
61 | periodic low/fullspeed transfers possible. | ||
62 | |||
63 | If you have multiple periodic low/fullspeed devices connected to a | ||
64 | highspeed USB hub which is connected to a highspeed USB Host | ||
65 | Controller, and some of those devices will not work correctly | ||
66 | (possibly due to "ENOSPC" or "-28" errors), say Y. | ||
67 | |||
68 | If unsure, say N. | ||
51 | 69 | ||
52 | config USB_ISP116X_HCD | 70 | config USB_ISP116X_HCD |
53 | tristate "ISP116X HCD support" | 71 | tristate "ISP116X HCD support" |
54 | depends on USB | 72 | depends on USB |
55 | default N | ||
56 | ---help--- | 73 | ---help--- |
57 | The ISP1160 and ISP1161 chips are USB host controllers. Enable this | 74 | The ISP1160 and ISP1161 chips are USB host controllers. Enable this |
58 | option if your board has this chip. If unsure, say N. | 75 | option if your board has this chip. If unsure, say N. |
@@ -127,7 +144,6 @@ config USB_UHCI_HCD | |||
127 | config USB_SL811_HCD | 144 | config USB_SL811_HCD |
128 | tristate "SL811HS HCD support" | 145 | tristate "SL811HS HCD support" |
129 | depends on USB | 146 | depends on USB |
130 | default N | ||
131 | help | 147 | help |
132 | The SL811HS is a single-port USB controller that supports either | 148 | The SL811HS is a single-port USB controller that supports either |
133 | host side or peripheral side roles. Enable this option if your | 149 | host side or peripheral side roles. Enable this option if your |
@@ -140,7 +156,6 @@ config USB_SL811_HCD | |||
140 | config USB_SL811_CS | 156 | config USB_SL811_CS |
141 | tristate "CF/PCMCIA support for SL811HS HCD" | 157 | tristate "CF/PCMCIA support for SL811HS HCD" |
142 | depends on USB_SL811_HCD && PCMCIA | 158 | depends on USB_SL811_HCD && PCMCIA |
143 | default N | ||
144 | help | 159 | help |
145 | Wraps a PCMCIA driver around the SL811HS HCD, supporting the RATOC | 160 | Wraps a PCMCIA driver around the SL811HS HCD, supporting the RATOC |
146 | REX-CFU1U CF card (often used with PDAs). If unsure, say N. | 161 | REX-CFU1U CF card (often used with PDAs). If unsure, say N. |
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c index 63eadeec1324..9b4697add313 100644 --- a/drivers/usb/host/ehci-au1xxx.c +++ b/drivers/usb/host/ehci-au1xxx.c | |||
@@ -16,10 +16,6 @@ | |||
16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
17 | #include <asm/mach-au1x00/au1000.h> | 17 | #include <asm/mach-au1x00/au1000.h> |
18 | 18 | ||
19 | #ifndef CONFIG_SOC_AU1200 | ||
20 | #error "this Alchemy chip doesn't have EHCI" | ||
21 | #else /* Au1200 */ | ||
22 | |||
23 | #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG) | 19 | #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG) |
24 | #define USB_MCFG_PFEN (1<<31) | 20 | #define USB_MCFG_PFEN (1<<31) |
25 | #define USB_MCFG_RDCOMB (1<<30) | 21 | #define USB_MCFG_RDCOMB (1<<30) |
@@ -272,6 +268,8 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev) | |||
272 | return 0; | 268 | return 0; |
273 | } | 269 | } |
274 | */ | 270 | */ |
271 | MODULE_ALIAS("au1xxx-ehci"); | ||
272 | /* FIXME use "struct platform_driver" */ | ||
275 | static struct device_driver ehci_hcd_au1xxx_driver = { | 273 | static struct device_driver ehci_hcd_au1xxx_driver = { |
276 | .name = "au1xxx-ehci", | 274 | .name = "au1xxx-ehci", |
277 | .bus = &platform_bus_type, | 275 | .bus = &platform_bus_type, |
@@ -280,18 +278,3 @@ static struct device_driver ehci_hcd_au1xxx_driver = { | |||
280 | /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ | 278 | /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ |
281 | /*.resume = ehci_hcd_au1xxx_drv_resume, */ | 279 | /*.resume = ehci_hcd_au1xxx_drv_resume, */ |
282 | }; | 280 | }; |
283 | |||
284 | static int __init ehci_hcd_au1xxx_init(void) | ||
285 | { | ||
286 | pr_debug(DRIVER_INFO " (Au1xxx)\n"); | ||
287 | |||
288 | return driver_register(&ehci_hcd_au1xxx_driver); | ||
289 | } | ||
290 | |||
291 | static void __exit ehci_hcd_au1xxx_cleanup(void) | ||
292 | { | ||
293 | driver_unregister(&ehci_hcd_au1xxx_driver); | ||
294 | } | ||
295 | |||
296 | module_init(ehci_hcd_au1xxx_init); | ||
297 | module_exit(ehci_hcd_au1xxx_cleanup); | ||
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index f985f121a245..a49a689bf423 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
@@ -324,43 +324,12 @@ static int ehci_fsl_drv_remove(struct platform_device *pdev) | |||
324 | return 0; | 324 | return 0; |
325 | } | 325 | } |
326 | 326 | ||
327 | static struct platform_driver ehci_fsl_dr_driver = { | 327 | MODULE_ALIAS("fsl-ehci"); |
328 | .probe = ehci_fsl_drv_probe, | ||
329 | .remove = ehci_fsl_drv_remove, | ||
330 | .driver = { | ||
331 | .name = "fsl-usb2-dr", | ||
332 | }, | ||
333 | }; | ||
334 | 328 | ||
335 | static struct platform_driver ehci_fsl_mph_driver = { | 329 | static struct platform_driver ehci_fsl_driver = { |
336 | .probe = ehci_fsl_drv_probe, | 330 | .probe = ehci_fsl_drv_probe, |
337 | .remove = ehci_fsl_drv_remove, | 331 | .remove = ehci_fsl_drv_remove, |
338 | .driver = { | 332 | .driver = { |
339 | .name = "fsl-usb2-mph", | 333 | .name = "fsl-ehci", |
340 | }, | 334 | }, |
341 | }; | 335 | }; |
342 | |||
343 | static int __init ehci_fsl_init(void) | ||
344 | { | ||
345 | int retval; | ||
346 | |||
347 | pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", | ||
348 | hcd_name, | ||
349 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), | ||
350 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); | ||
351 | |||
352 | retval = platform_driver_register(&ehci_fsl_dr_driver); | ||
353 | if (retval) | ||
354 | return retval; | ||
355 | |||
356 | return platform_driver_register(&ehci_fsl_mph_driver); | ||
357 | } | ||
358 | |||
359 | static void __exit ehci_fsl_cleanup(void) | ||
360 | { | ||
361 | platform_driver_unregister(&ehci_fsl_mph_driver); | ||
362 | platform_driver_unregister(&ehci_fsl_dr_driver); | ||
363 | } | ||
364 | |||
365 | module_init(ehci_fsl_init); | ||
366 | module_exit(ehci_fsl_cleanup); | ||
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 79f2d8b9bfb6..9b37e508ada3 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -889,19 +889,59 @@ MODULE_LICENSE ("GPL"); | |||
889 | 889 | ||
890 | #ifdef CONFIG_PCI | 890 | #ifdef CONFIG_PCI |
891 | #include "ehci-pci.c" | 891 | #include "ehci-pci.c" |
892 | #define EHCI_BUS_GLUED | 892 | #define PCI_DRIVER ehci_pci_driver |
893 | #endif | 893 | #endif |
894 | 894 | ||
895 | #ifdef CONFIG_PPC_83xx | 895 | #ifdef CONFIG_PPC_83xx |
896 | #include "ehci-fsl.c" | 896 | #include "ehci-fsl.c" |
897 | #define EHCI_BUS_GLUED | 897 | #define PLATFORM_DRIVER ehci_fsl_driver |
898 | #endif | 898 | #endif |
899 | 899 | ||
900 | #ifdef CONFIG_SOC_AU1X00 | 900 | #ifdef CONFIG_SOC_AU1200 |
901 | #include "ehci-au1xxx.c" | 901 | #include "ehci-au1xxx.c" |
902 | #define EHCI_BUS_GLUED | 902 | #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver |
903 | #endif | 903 | #endif |
904 | 904 | ||
905 | #ifndef EHCI_BUS_GLUED | 905 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) |
906 | #error "missing bus glue for ehci-hcd" | 906 | #error "missing bus glue for ehci-hcd" |
907 | #endif | 907 | #endif |
908 | |||
909 | static int __init ehci_hcd_init(void) | ||
910 | { | ||
911 | int retval = 0; | ||
912 | |||
913 | pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", | ||
914 | hcd_name, | ||
915 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), | ||
916 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); | ||
917 | |||
918 | #ifdef PLATFORM_DRIVER | ||
919 | retval = platform_driver_register(&PLATFORM_DRIVER); | ||
920 | if (retval < 0) | ||
921 | return retval; | ||
922 | #endif | ||
923 | |||
924 | #ifdef PCI_DRIVER | ||
925 | retval = pci_register_driver(&PCI_DRIVER); | ||
926 | if (retval < 0) { | ||
927 | #ifdef PLATFORM_DRIVER | ||
928 | platform_driver_unregister(&PLATFORM_DRIVER); | ||
929 | #endif | ||
930 | } | ||
931 | #endif | ||
932 | |||
933 | return retval; | ||
934 | } | ||
935 | module_init(ehci_hcd_init); | ||
936 | |||
937 | static void __exit ehci_hcd_cleanup(void) | ||
938 | { | ||
939 | #ifdef PLATFORM_DRIVER | ||
940 | platform_driver_unregister(&PLATFORM_DRIVER); | ||
941 | #endif | ||
942 | #ifdef PCI_DRIVER | ||
943 | pci_unregister_driver(&PCI_DRIVER); | ||
944 | #endif | ||
945 | } | ||
946 | module_exit(ehci_hcd_cleanup); | ||
947 | |||
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index a1bd2bea6deb..cadffacd945b 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -76,6 +76,30 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
76 | dbg_hcs_params(ehci, "reset"); | 76 | dbg_hcs_params(ehci, "reset"); |
77 | dbg_hcc_params(ehci, "reset"); | 77 | dbg_hcc_params(ehci, "reset"); |
78 | 78 | ||
79 | /* ehci_init() causes memory for DMA transfers to be | ||
80 | * allocated. Thus, any vendor-specific workarounds based on | ||
81 | * limiting the type of memory used for DMA transfers must | ||
82 | * happen before ehci_init() is called. */ | ||
83 | switch (pdev->vendor) { | ||
84 | case PCI_VENDOR_ID_NVIDIA: | ||
85 | /* NVidia reports that certain chips don't handle | ||
86 | * QH, ITD, or SITD addresses above 2GB. (But TD, | ||
87 | * data buffer, and periodic schedule are normal.) | ||
88 | */ | ||
89 | switch (pdev->device) { | ||
90 | case 0x003c: /* MCP04 */ | ||
91 | case 0x005b: /* CK804 */ | ||
92 | case 0x00d8: /* CK8 */ | ||
93 | case 0x00e8: /* CK8S */ | ||
94 | if (pci_set_consistent_dma_mask(pdev, | ||
95 | DMA_31BIT_MASK) < 0) | ||
96 | ehci_warn(ehci, "can't enable NVidia " | ||
97 | "workaround for >2GB RAM\n"); | ||
98 | break; | ||
99 | } | ||
100 | break; | ||
101 | } | ||
102 | |||
79 | /* cache this readonly data; minimize chip reads */ | 103 | /* cache this readonly data; minimize chip reads */ |
80 | ehci->hcs_params = readl(&ehci->caps->hcs_params); | 104 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
81 | 105 | ||
@@ -88,8 +112,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
88 | if (retval) | 112 | if (retval) |
89 | return retval; | 113 | return retval; |
90 | 114 | ||
91 | /* NOTE: only the parts below this line are PCI-specific */ | ||
92 | |||
93 | switch (pdev->vendor) { | 115 | switch (pdev->vendor) { |
94 | case PCI_VENDOR_ID_TDI: | 116 | case PCI_VENDOR_ID_TDI: |
95 | if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { | 117 | if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { |
@@ -107,19 +129,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
107 | break; | 129 | break; |
108 | case PCI_VENDOR_ID_NVIDIA: | 130 | case PCI_VENDOR_ID_NVIDIA: |
109 | switch (pdev->device) { | 131 | switch (pdev->device) { |
110 | /* NVidia reports that certain chips don't handle | ||
111 | * QH, ITD, or SITD addresses above 2GB. (But TD, | ||
112 | * data buffer, and periodic schedule are normal.) | ||
113 | */ | ||
114 | case 0x003c: /* MCP04 */ | ||
115 | case 0x005b: /* CK804 */ | ||
116 | case 0x00d8: /* CK8 */ | ||
117 | case 0x00e8: /* CK8S */ | ||
118 | if (pci_set_consistent_dma_mask(pdev, | ||
119 | DMA_31BIT_MASK) < 0) | ||
120 | ehci_warn(ehci, "can't enable NVidia " | ||
121 | "workaround for >2GB RAM\n"); | ||
122 | break; | ||
123 | /* Some NForce2 chips have problems with selective suspend; | 132 | /* Some NForce2 chips have problems with selective suspend; |
124 | * fixed in newer silicon. | 133 | * fixed in newer silicon. |
125 | */ | 134 | */ |
@@ -370,23 +379,3 @@ static struct pci_driver ehci_pci_driver = { | |||
370 | .resume = usb_hcd_pci_resume, | 379 | .resume = usb_hcd_pci_resume, |
371 | #endif | 380 | #endif |
372 | }; | 381 | }; |
373 | |||
374 | static int __init ehci_hcd_pci_init(void) | ||
375 | { | ||
376 | if (usb_disabled()) | ||
377 | return -ENODEV; | ||
378 | |||
379 | pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", | ||
380 | hcd_name, | ||
381 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), | ||
382 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); | ||
383 | |||
384 | return pci_register_driver(&ehci_pci_driver); | ||
385 | } | ||
386 | module_init(ehci_hcd_pci_init); | ||
387 | |||
388 | static void __exit ehci_hcd_pci_cleanup(void) | ||
389 | { | ||
390 | pci_unregister_driver(&ehci_pci_driver); | ||
391 | } | ||
392 | module_exit(ehci_hcd_pci_cleanup); | ||
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 5871944e6145..4859900bd135 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -163,6 +163,190 @@ static int same_tt (struct usb_device *dev1, struct usb_device *dev2) | |||
163 | return 1; | 163 | return 1; |
164 | } | 164 | } |
165 | 165 | ||
166 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED | ||
167 | |||
168 | /* Which uframe does the low/fullspeed transfer start in? | ||
169 | * | ||
170 | * The parameter is the mask of ssplits in "H-frame" terms | ||
171 | * and this returns the transfer start uframe in "B-frame" terms, | ||
172 | * which allows both to match, e.g. a ssplit in "H-frame" uframe 0 | ||
173 | * will cause a transfer in "B-frame" uframe 0. "B-frames" lag | ||
174 | * "H-frames" by 1 uframe. See the EHCI spec sec 4.5 and figure 4.7. | ||
175 | */ | ||
176 | static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __le32 mask) | ||
177 | { | ||
178 | unsigned char smask = QH_SMASK & le32_to_cpu(mask); | ||
179 | if (!smask) { | ||
180 | ehci_err(ehci, "invalid empty smask!\n"); | ||
181 | /* uframe 7 can't have bw so this will indicate failure */ | ||
182 | return 7; | ||
183 | } | ||
184 | return ffs(smask) - 1; | ||
185 | } | ||
186 | |||
187 | static const unsigned char | ||
188 | max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 30, 0 }; | ||
189 | |||
190 | /* carryover low/fullspeed bandwidth that crosses uframe boundries */ | ||
191 | static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8]) | ||
192 | { | ||
193 | int i; | ||
194 | for (i=0; i<7; i++) { | ||
195 | if (max_tt_usecs[i] < tt_usecs[i]) { | ||
196 | tt_usecs[i+1] += tt_usecs[i] - max_tt_usecs[i]; | ||
197 | tt_usecs[i] = max_tt_usecs[i]; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /* How many of the tt's periodic downstream 1000 usecs are allocated? | ||
203 | * | ||
204 | * While this measures the bandwidth in terms of usecs/uframe, | ||
205 | * the low/fullspeed bus has no notion of uframes, so any particular | ||
206 | * low/fullspeed transfer can "carry over" from one uframe to the next, | ||
207 | * since the TT just performs downstream transfers in sequence. | ||
208 | * | ||
209 | * For example two seperate 100 usec transfers can start in the same uframe, | ||
210 | * and the second one would "carry over" 75 usecs into the next uframe. | ||
211 | */ | ||
212 | static void | ||
213 | periodic_tt_usecs ( | ||
214 | struct ehci_hcd *ehci, | ||
215 | struct usb_device *dev, | ||
216 | unsigned frame, | ||
217 | unsigned short tt_usecs[8] | ||
218 | ) | ||
219 | { | ||
220 | __le32 *hw_p = &ehci->periodic [frame]; | ||
221 | union ehci_shadow *q = &ehci->pshadow [frame]; | ||
222 | unsigned char uf; | ||
223 | |||
224 | memset(tt_usecs, 0, 16); | ||
225 | |||
226 | while (q->ptr) { | ||
227 | switch (Q_NEXT_TYPE(*hw_p)) { | ||
228 | case Q_TYPE_ITD: | ||
229 | hw_p = &q->itd->hw_next; | ||
230 | q = &q->itd->itd_next; | ||
231 | continue; | ||
232 | case Q_TYPE_QH: | ||
233 | if (same_tt(dev, q->qh->dev)) { | ||
234 | uf = tt_start_uframe(ehci, q->qh->hw_info2); | ||
235 | tt_usecs[uf] += q->qh->tt_usecs; | ||
236 | } | ||
237 | hw_p = &q->qh->hw_next; | ||
238 | q = &q->qh->qh_next; | ||
239 | continue; | ||
240 | case Q_TYPE_SITD: | ||
241 | if (same_tt(dev, q->sitd->urb->dev)) { | ||
242 | uf = tt_start_uframe(ehci, q->sitd->hw_uframe); | ||
243 | tt_usecs[uf] += q->sitd->stream->tt_usecs; | ||
244 | } | ||
245 | hw_p = &q->sitd->hw_next; | ||
246 | q = &q->sitd->sitd_next; | ||
247 | continue; | ||
248 | // case Q_TYPE_FSTN: | ||
249 | default: | ||
250 | ehci_dbg(ehci, | ||
251 | "ignoring periodic frame %d FSTN\n", frame); | ||
252 | hw_p = &q->fstn->hw_next; | ||
253 | q = &q->fstn->fstn_next; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | carryover_tt_bandwidth(tt_usecs); | ||
258 | |||
259 | if (max_tt_usecs[7] < tt_usecs[7]) | ||
260 | ehci_err(ehci, "frame %d tt sched overrun: %d usecs\n", | ||
261 | frame, tt_usecs[7] - max_tt_usecs[7]); | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * Return true if the device's tt's downstream bus is available for a | ||
266 | * periodic transfer of the specified length (usecs), starting at the | ||
267 | * specified frame/uframe. Note that (as summarized in section 11.19 | ||
268 | * of the usb 2.0 spec) TTs can buffer multiple transactions for each | ||
269 | * uframe. | ||
270 | * | ||
271 | * The uframe parameter is when the fullspeed/lowspeed transfer | ||
272 | * should be executed in "B-frame" terms, which is the same as the | ||
273 | * highspeed ssplit's uframe (which is in "H-frame" terms). For example | ||
274 | * a ssplit in "H-frame" 0 causes a transfer in "B-frame" 0. | ||
275 | * See the EHCI spec sec 4.5 and fig 4.7. | ||
276 | * | ||
277 | * This checks if the full/lowspeed bus, at the specified starting uframe, | ||
278 | * has the specified bandwidth available, according to rules listed | ||
279 | * in USB 2.0 spec section 11.18.1 fig 11-60. | ||
280 | * | ||
281 | * This does not check if the transfer would exceed the max ssplit | ||
282 | * limit of 16, specified in USB 2.0 spec section 11.18.4 requirement #4, | ||
283 | * since proper scheduling limits ssplits to less than 16 per uframe. | ||
284 | */ | ||
285 | static int tt_available ( | ||
286 | struct ehci_hcd *ehci, | ||
287 | unsigned period, | ||
288 | struct usb_device *dev, | ||
289 | unsigned frame, | ||
290 | unsigned uframe, | ||
291 | u16 usecs | ||
292 | ) | ||
293 | { | ||
294 | if ((period == 0) || (uframe >= 7)) /* error */ | ||
295 | return 0; | ||
296 | |||
297 | for (; frame < ehci->periodic_size; frame += period) { | ||
298 | unsigned short tt_usecs[8]; | ||
299 | |||
300 | periodic_tt_usecs (ehci, dev, frame, tt_usecs); | ||
301 | |||
302 | ehci_vdbg(ehci, "tt frame %d check %d usecs start uframe %d in" | ||
303 | " schedule %d/%d/%d/%d/%d/%d/%d/%d\n", | ||
304 | frame, usecs, uframe, | ||
305 | tt_usecs[0], tt_usecs[1], tt_usecs[2], tt_usecs[3], | ||
306 | tt_usecs[4], tt_usecs[5], tt_usecs[6], tt_usecs[7]); | ||
307 | |||
308 | if (max_tt_usecs[uframe] <= tt_usecs[uframe]) { | ||
309 | ehci_vdbg(ehci, "frame %d uframe %d fully scheduled\n", | ||
310 | frame, uframe); | ||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | /* special case for isoc transfers larger than 125us: | ||
315 | * the first and each subsequent fully used uframe | ||
316 | * must be empty, so as to not illegally delay | ||
317 | * already scheduled transactions | ||
318 | */ | ||
319 | if (125 < usecs) { | ||
320 | int ufs = (usecs / 125) - 1; | ||
321 | int i; | ||
322 | for (i = uframe; i < (uframe + ufs) && i < 8; i++) | ||
323 | if (0 < tt_usecs[i]) { | ||
324 | ehci_vdbg(ehci, | ||
325 | "multi-uframe xfer can't fit " | ||
326 | "in frame %d uframe %d\n", | ||
327 | frame, i); | ||
328 | return 0; | ||
329 | } | ||
330 | } | ||
331 | |||
332 | tt_usecs[uframe] += usecs; | ||
333 | |||
334 | carryover_tt_bandwidth(tt_usecs); | ||
335 | |||
336 | /* fail if the carryover pushed bw past the last uframe's limit */ | ||
337 | if (max_tt_usecs[7] < tt_usecs[7]) { | ||
338 | ehci_vdbg(ehci, | ||
339 | "tt unavailable usecs %d frame %d uframe %d\n", | ||
340 | usecs, frame, uframe); | ||
341 | return 0; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | return 1; | ||
346 | } | ||
347 | |||
348 | #else | ||
349 | |||
166 | /* return true iff the device's transaction translator is available | 350 | /* return true iff the device's transaction translator is available |
167 | * for a periodic transfer starting at the specified frame, using | 351 | * for a periodic transfer starting at the specified frame, using |
168 | * all the uframes in the mask. | 352 | * all the uframes in the mask. |
@@ -237,6 +421,8 @@ static int tt_no_collision ( | |||
237 | return 1; | 421 | return 1; |
238 | } | 422 | } |
239 | 423 | ||
424 | #endif /* CONFIG_USB_EHCI_TT_NEWSCHED */ | ||
425 | |||
240 | /*-------------------------------------------------------------------------*/ | 426 | /*-------------------------------------------------------------------------*/ |
241 | 427 | ||
242 | static int enable_periodic (struct ehci_hcd *ehci) | 428 | static int enable_periodic (struct ehci_hcd *ehci) |
@@ -481,7 +667,7 @@ static int check_intr_schedule ( | |||
481 | ) | 667 | ) |
482 | { | 668 | { |
483 | int retval = -ENOSPC; | 669 | int retval = -ENOSPC; |
484 | u8 mask; | 670 | u8 mask = 0; |
485 | 671 | ||
486 | if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ | 672 | if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ |
487 | goto done; | 673 | goto done; |
@@ -494,6 +680,24 @@ static int check_intr_schedule ( | |||
494 | goto done; | 680 | goto done; |
495 | } | 681 | } |
496 | 682 | ||
683 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED | ||
684 | if (tt_available (ehci, qh->period, qh->dev, frame, uframe, | ||
685 | qh->tt_usecs)) { | ||
686 | unsigned i; | ||
687 | |||
688 | /* TODO : this may need FSTN for SSPLIT in uframe 5. */ | ||
689 | for (i=uframe+1; i<8 && i<uframe+4; i++) | ||
690 | if (!check_period (ehci, frame, i, | ||
691 | qh->period, qh->c_usecs)) | ||
692 | goto done; | ||
693 | else | ||
694 | mask |= 1 << i; | ||
695 | |||
696 | retval = 0; | ||
697 | |||
698 | *c_maskp = cpu_to_le32 (mask << 8); | ||
699 | } | ||
700 | #else | ||
497 | /* Make sure this tt's buffer is also available for CSPLITs. | 701 | /* Make sure this tt's buffer is also available for CSPLITs. |
498 | * We pessimize a bit; probably the typical full speed case | 702 | * We pessimize a bit; probably the typical full speed case |
499 | * doesn't need the second CSPLIT. | 703 | * doesn't need the second CSPLIT. |
@@ -514,6 +718,7 @@ static int check_intr_schedule ( | |||
514 | goto done; | 718 | goto done; |
515 | retval = 0; | 719 | retval = 0; |
516 | } | 720 | } |
721 | #endif | ||
517 | done: | 722 | done: |
518 | return retval; | 723 | return retval; |
519 | } | 724 | } |
@@ -1047,12 +1252,21 @@ sitd_slot_ok ( | |||
1047 | frame = uframe >> 3; | 1252 | frame = uframe >> 3; |
1048 | uf = uframe & 7; | 1253 | uf = uframe & 7; |
1049 | 1254 | ||
1255 | #ifdef CONFIG_USB_EHCI_TT_NEWSCHED | ||
1256 | /* The tt's fullspeed bus bandwidth must be available. | ||
1257 | * tt_available scheduling guarantees 10+% for control/bulk. | ||
1258 | */ | ||
1259 | if (!tt_available (ehci, period_uframes << 3, | ||
1260 | stream->udev, frame, uf, stream->tt_usecs)) | ||
1261 | return 0; | ||
1262 | #else | ||
1050 | /* tt must be idle for start(s), any gap, and csplit. | 1263 | /* tt must be idle for start(s), any gap, and csplit. |
1051 | * assume scheduling slop leaves 10+% for control/bulk. | 1264 | * assume scheduling slop leaves 10+% for control/bulk. |
1052 | */ | 1265 | */ |
1053 | if (!tt_no_collision (ehci, period_uframes << 3, | 1266 | if (!tt_no_collision (ehci, period_uframes << 3, |
1054 | stream->udev, frame, mask)) | 1267 | stream->udev, frame, mask)) |
1055 | return 0; | 1268 | return 0; |
1269 | #endif | ||
1056 | 1270 | ||
1057 | /* check starts (OUT uses more than one) */ | 1271 | /* check starts (OUT uses more than one) */ |
1058 | max_used = 100 - stream->usecs; | 1272 | max_used = 100 - stream->usecs; |
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index e99210b7909b..14386254c870 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #include <linux/init.h> | 63 | #include <linux/init.h> |
64 | #include <linux/list.h> | 64 | #include <linux/list.h> |
65 | #include <linux/usb.h> | 65 | #include <linux/usb.h> |
66 | #include <linux/usb_isp116x.h> | 66 | #include <linux/usb/isp116x.h> |
67 | #include <linux/platform_device.h> | 67 | #include <linux/platform_device.h> |
68 | 68 | ||
69 | #include <asm/io.h> | 69 | #include <asm/io.h> |
@@ -781,7 +781,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd, | |||
781 | if (ep->branch < PERIODIC_SIZE) | 781 | if (ep->branch < PERIODIC_SIZE) |
782 | break; | 782 | break; |
783 | 783 | ||
784 | ret = ep->branch = balance(isp116x, ep->period, ep->load); | 784 | ep->branch = ret = balance(isp116x, ep->period, ep->load); |
785 | if (ret < 0) | 785 | if (ret < 0) |
786 | goto fail; | 786 | goto fail; |
787 | ret = 0; | 787 | ret = 0; |
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index acde8868da21..fafe7c1265b3 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
@@ -185,6 +185,9 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
185 | /* Select Power Management Mode */ | 185 | /* Select Power Management Mode */ |
186 | pxa27x_ohci_select_pmm(inf->port_mode); | 186 | pxa27x_ohci_select_pmm(inf->port_mode); |
187 | 187 | ||
188 | if (inf->power_budget) | ||
189 | hcd->power_budget = inf->power_budget; | ||
190 | |||
188 | ohci_hcd_init(hcd_to_ohci(hcd)); | 191 | ohci_hcd_init(hcd_to_ohci(hcd)); |
189 | 192 | ||
190 | retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT); | 193 | retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT); |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index a92343052751..6b4bc3f2bd86 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -46,7 +46,7 @@ | |||
46 | #include <linux/list.h> | 46 | #include <linux/list.h> |
47 | #include <linux/interrupt.h> | 47 | #include <linux/interrupt.h> |
48 | #include <linux/usb.h> | 48 | #include <linux/usb.h> |
49 | #include <linux/usb_sl811.h> | 49 | #include <linux/usb/sl811.h> |
50 | #include <linux/platform_device.h> | 50 | #include <linux/platform_device.h> |
51 | 51 | ||
52 | #include <asm/io.h> | 52 | #include <asm/io.h> |
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index 302aa1ec312f..54f554e0f0ad 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <pcmcia/cisreg.h> | 27 | #include <pcmcia/cisreg.h> |
28 | #include <pcmcia/ds.h> | 28 | #include <pcmcia/ds.h> |
29 | 29 | ||
30 | #include <linux/usb_sl811.h> | 30 | #include <linux/usb/sl811.h> |
31 | 31 | ||
32 | MODULE_AUTHOR("Botond Botyanszki"); | 32 | MODULE_AUTHOR("Botond Botyanszki"); |
33 | MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6"); | 33 | MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6"); |
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c index e1239319655c..6637a0e49978 100644 --- a/drivers/usb/host/uhci-debug.c +++ b/drivers/usb/host/uhci-debug.c | |||
@@ -98,6 +98,7 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) | |||
98 | char *out = buf; | 98 | char *out = buf; |
99 | struct uhci_td *td; | 99 | struct uhci_td *td; |
100 | int i, nactive, ninactive; | 100 | int i, nactive, ninactive; |
101 | char *ptype; | ||
101 | 102 | ||
102 | if (len < 200) | 103 | if (len < 200) |
103 | return 0; | 104 | return 0; |
@@ -110,13 +111,15 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) | |||
110 | (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT")); | 111 | (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT")); |
111 | 112 | ||
112 | switch (usb_pipetype(urbp->urb->pipe)) { | 113 | switch (usb_pipetype(urbp->urb->pipe)) { |
113 | case PIPE_ISOCHRONOUS: out += sprintf(out, "ISO"); break; | 114 | case PIPE_ISOCHRONOUS: ptype = "ISO"; break; |
114 | case PIPE_INTERRUPT: out += sprintf(out, "INT"); break; | 115 | case PIPE_INTERRUPT: ptype = "INT"; break; |
115 | case PIPE_BULK: out += sprintf(out, "BLK"); break; | 116 | case PIPE_BULK: ptype = "BLK"; break; |
116 | case PIPE_CONTROL: out += sprintf(out, "CTL"); break; | 117 | default: |
118 | case PIPE_CONTROL: ptype = "CTL"; break; | ||
117 | } | 119 | } |
118 | 120 | ||
119 | out += sprintf(out, "%s", (urbp->fsbr ? " FSBR" : "")); | 121 | out += sprintf(out, "%s%s", ptype, (urbp->fsbr ? " FSBR" : "")); |
122 | out += sprintf(out, " Actlen=%d", urbp->urb->actual_length); | ||
120 | 123 | ||
121 | if (urbp->urb->status != -EINPROGRESS) | 124 | if (urbp->urb->status != -EINPROGRESS) |
122 | out += sprintf(out, " Status=%d", urbp->urb->status); | 125 | out += sprintf(out, " Status=%d", urbp->urb->status); |
@@ -124,7 +127,8 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) | |||
124 | 127 | ||
125 | i = nactive = ninactive = 0; | 128 | i = nactive = ninactive = 0; |
126 | list_for_each_entry(td, &urbp->td_list, list) { | 129 | list_for_each_entry(td, &urbp->td_list, list) { |
127 | if (++i <= 10 || debug > 2) { | 130 | if (urbp->qh->type != USB_ENDPOINT_XFER_ISOC && |
131 | (++i <= 10 || debug > 2)) { | ||
128 | out += sprintf(out, "%*s%d: ", space + 2, "", i); | 132 | out += sprintf(out, "%*s%d: ", space + 2, "", i); |
129 | out += uhci_show_td(td, out, len - (out - buf), 0); | 133 | out += uhci_show_td(td, out, len - (out - buf), 0); |
130 | } else { | 134 | } else { |
@@ -147,13 +151,27 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) | |||
147 | char *out = buf; | 151 | char *out = buf; |
148 | int i, nurbs; | 152 | int i, nurbs; |
149 | __le32 element = qh_element(qh); | 153 | __le32 element = qh_element(qh); |
154 | char *qtype; | ||
150 | 155 | ||
151 | /* Try to make sure there's enough memory */ | 156 | /* Try to make sure there's enough memory */ |
152 | if (len < 80 * 6) | 157 | if (len < 80 * 7) |
153 | return 0; | 158 | return 0; |
154 | 159 | ||
155 | out += sprintf(out, "%*s[%p] link (%08x) element (%08x)\n", space, "", | 160 | switch (qh->type) { |
156 | qh, le32_to_cpu(qh->link), le32_to_cpu(element)); | 161 | case USB_ENDPOINT_XFER_ISOC: qtype = "ISO"; break; |
162 | case USB_ENDPOINT_XFER_INT: qtype = "INT"; break; | ||
163 | case USB_ENDPOINT_XFER_BULK: qtype = "BLK"; break; | ||
164 | case USB_ENDPOINT_XFER_CONTROL: qtype = "CTL"; break; | ||
165 | default: qtype = "Skel" ; break; | ||
166 | } | ||
167 | |||
168 | out += sprintf(out, "%*s[%p] %s QH link (%08x) element (%08x)\n", | ||
169 | space, "", qh, qtype, | ||
170 | le32_to_cpu(qh->link), le32_to_cpu(element)); | ||
171 | if (qh->type == USB_ENDPOINT_XFER_ISOC) | ||
172 | out += sprintf(out, "%*s period %d frame %x desc [%p]\n", | ||
173 | space, "", qh->period, qh->iso_frame, | ||
174 | qh->iso_packet_desc); | ||
157 | 175 | ||
158 | if (element & UHCI_PTR_QH) | 176 | if (element & UHCI_PTR_QH) |
159 | out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); | 177 | out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); |
@@ -261,7 +279,8 @@ static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len) | |||
261 | default: | 279 | default: |
262 | rh_state = "?"; break; | 280 | rh_state = "?"; break; |
263 | } | 281 | } |
264 | out += sprintf(out, "Root-hub state: %s\n", rh_state); | 282 | out += sprintf(out, "Root-hub state: %s FSBR: %d\n", |
283 | rh_state, uhci->fsbr_is_on); | ||
265 | return out - buf; | 284 | return out - buf; |
266 | } | 285 | } |
267 | 286 | ||
@@ -275,7 +294,7 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) | |||
275 | unsigned short portsc1, portsc2; | 294 | unsigned short portsc1, portsc2; |
276 | 295 | ||
277 | /* Try to make sure there's enough memory */ | 296 | /* Try to make sure there's enough memory */ |
278 | if (len < 80 * 6) | 297 | if (len < 80 * 9) |
279 | return 0; | 298 | return 0; |
280 | 299 | ||
281 | usbcmd = inw(io_addr + 0); | 300 | usbcmd = inw(io_addr + 0); |
@@ -314,6 +333,10 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) | |||
314 | out += sprintf(out, " sof = %02x\n", sof); | 333 | out += sprintf(out, " sof = %02x\n", sof); |
315 | out += uhci_show_sc(1, portsc1, out, len - (out - buf)); | 334 | out += uhci_show_sc(1, portsc1, out, len - (out - buf)); |
316 | out += uhci_show_sc(2, portsc2, out, len - (out - buf)); | 335 | out += uhci_show_sc(2, portsc2, out, len - (out - buf)); |
336 | out += sprintf(out, "Most recent frame: %x (%d) " | ||
337 | "Last ISO frame: %x (%d)\n", | ||
338 | uhci->frame_number, uhci->frame_number & 1023, | ||
339 | uhci->last_iso_frame, uhci->last_iso_frame & 1023); | ||
317 | 340 | ||
318 | return out - buf; | 341 | return out - buf; |
319 | } | 342 | } |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index d225e11f4055..7b48567622ef 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -13,7 +13,7 @@ | |||
13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
16 | * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu | 16 | * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu |
17 | * | 17 | * |
18 | * Intel documents this fairly well, and as far as I know there | 18 | * Intel documents this fairly well, and as far as I know there |
19 | * are no royalties or anything like that, but even so there are | 19 | * are no royalties or anything like that, but even so there are |
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/ioport.h> | 31 | #include <linux/ioport.h> |
32 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <linux/smp_lock.h> | ||
35 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
36 | #include <linux/unistd.h> | 35 | #include <linux/unistd.h> |
37 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
@@ -88,15 +87,6 @@ static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state); | |||
88 | static void wakeup_rh(struct uhci_hcd *uhci); | 87 | static void wakeup_rh(struct uhci_hcd *uhci); |
89 | static void uhci_get_current_frame_number(struct uhci_hcd *uhci); | 88 | static void uhci_get_current_frame_number(struct uhci_hcd *uhci); |
90 | 89 | ||
91 | /* If a transfer is still active after this much time, turn off FSBR */ | ||
92 | #define IDLE_TIMEOUT msecs_to_jiffies(50) | ||
93 | #define FSBR_DELAY msecs_to_jiffies(50) | ||
94 | |||
95 | /* When we timeout an idle transfer for FSBR, we'll switch it over to */ | ||
96 | /* depth first traversal. We'll do it in groups of this number of TDs */ | ||
97 | /* to make sure it doesn't hog all of the bandwidth */ | ||
98 | #define DEPTH_INTERVAL 5 | ||
99 | |||
100 | #include "uhci-debug.c" | 90 | #include "uhci-debug.c" |
101 | #include "uhci-q.c" | 91 | #include "uhci-q.c" |
102 | #include "uhci-hub.c" | 92 | #include "uhci-hub.c" |
@@ -120,22 +110,29 @@ static void finish_reset(struct uhci_hcd *uhci) | |||
120 | uhci->is_stopped = UHCI_IS_STOPPED; | 110 | uhci->is_stopped = UHCI_IS_STOPPED; |
121 | uhci_to_hcd(uhci)->state = HC_STATE_HALT; | 111 | uhci_to_hcd(uhci)->state = HC_STATE_HALT; |
122 | uhci_to_hcd(uhci)->poll_rh = 0; | 112 | uhci_to_hcd(uhci)->poll_rh = 0; |
113 | |||
114 | uhci->dead = 0; /* Full reset resurrects the controller */ | ||
123 | } | 115 | } |
124 | 116 | ||
125 | /* | 117 | /* |
126 | * Last rites for a defunct/nonfunctional controller | 118 | * Last rites for a defunct/nonfunctional controller |
127 | * or one we don't want to use any more. | 119 | * or one we don't want to use any more. |
128 | */ | 120 | */ |
129 | static void hc_died(struct uhci_hcd *uhci) | 121 | static void uhci_hc_died(struct uhci_hcd *uhci) |
130 | { | 122 | { |
123 | uhci_get_current_frame_number(uhci); | ||
131 | uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); | 124 | uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); |
132 | finish_reset(uhci); | 125 | finish_reset(uhci); |
133 | uhci->hc_inaccessible = 1; | 126 | uhci->dead = 1; |
127 | |||
128 | /* The current frame may already be partway finished */ | ||
129 | ++uhci->frame_number; | ||
134 | } | 130 | } |
135 | 131 | ||
136 | /* | 132 | /* |
137 | * Initialize a controller that was newly discovered or has just been | 133 | * Initialize a controller that was newly discovered or has lost power |
138 | * resumed. In either case we can't be sure of its previous state. | 134 | * or otherwise been reset while it was suspended. In none of these cases |
135 | * can we be sure of its previous state. | ||
139 | */ | 136 | */ |
140 | static void check_and_reset_hc(struct uhci_hcd *uhci) | 137 | static void check_and_reset_hc(struct uhci_hcd *uhci) |
141 | { | 138 | { |
@@ -155,7 +152,8 @@ static void configure_hc(struct uhci_hcd *uhci) | |||
155 | outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD); | 152 | outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD); |
156 | 153 | ||
157 | /* Set the current frame number */ | 154 | /* Set the current frame number */ |
158 | outw(uhci->frame_number, uhci->io_addr + USBFRNUM); | 155 | outw(uhci->frame_number & UHCI_MAX_SOF_NUMBER, |
156 | uhci->io_addr + USBFRNUM); | ||
159 | 157 | ||
160 | /* Mark controller as not halted before we enable interrupts */ | 158 | /* Mark controller as not halted before we enable interrupts */ |
161 | uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED; | 159 | uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED; |
@@ -207,7 +205,8 @@ __acquires(uhci->lock) | |||
207 | int int_enable; | 205 | int int_enable; |
208 | 206 | ||
209 | auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); | 207 | auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); |
210 | dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, | 208 | dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, |
209 | "%s%s\n", __FUNCTION__, | ||
211 | (auto_stop ? " (auto-stop)" : "")); | 210 | (auto_stop ? " (auto-stop)" : "")); |
212 | 211 | ||
213 | /* If we get a suspend request when we're already auto-stopped | 212 | /* If we get a suspend request when we're already auto-stopped |
@@ -241,27 +240,27 @@ __acquires(uhci->lock) | |||
241 | spin_unlock_irq(&uhci->lock); | 240 | spin_unlock_irq(&uhci->lock); |
242 | msleep(1); | 241 | msleep(1); |
243 | spin_lock_irq(&uhci->lock); | 242 | spin_lock_irq(&uhci->lock); |
244 | if (uhci->hc_inaccessible) /* Died */ | 243 | if (uhci->dead) |
245 | return; | 244 | return; |
246 | } | 245 | } |
247 | if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) | 246 | if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) |
248 | dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); | 247 | dev_warn(&uhci_to_hcd(uhci)->self.root_hub->dev, |
248 | "Controller not stopped yet!\n"); | ||
249 | 249 | ||
250 | uhci_get_current_frame_number(uhci); | 250 | uhci_get_current_frame_number(uhci); |
251 | smp_wmb(); | ||
252 | 251 | ||
253 | uhci->rh_state = new_state; | 252 | uhci->rh_state = new_state; |
254 | uhci->is_stopped = UHCI_IS_STOPPED; | 253 | uhci->is_stopped = UHCI_IS_STOPPED; |
255 | uhci_to_hcd(uhci)->poll_rh = !int_enable; | 254 | uhci_to_hcd(uhci)->poll_rh = !int_enable; |
256 | 255 | ||
257 | uhci_scan_schedule(uhci, NULL); | 256 | uhci_scan_schedule(uhci, NULL); |
257 | uhci_fsbr_off(uhci); | ||
258 | } | 258 | } |
259 | 259 | ||
260 | static void start_rh(struct uhci_hcd *uhci) | 260 | static void start_rh(struct uhci_hcd *uhci) |
261 | { | 261 | { |
262 | uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; | 262 | uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; |
263 | uhci->is_stopped = 0; | 263 | uhci->is_stopped = 0; |
264 | smp_wmb(); | ||
265 | 264 | ||
266 | /* Mark it configured and running with a 64-byte max packet. | 265 | /* Mark it configured and running with a 64-byte max packet. |
267 | * All interrupts are enabled, even though RESUME won't do anything. | 266 | * All interrupts are enabled, even though RESUME won't do anything. |
@@ -278,7 +277,8 @@ static void wakeup_rh(struct uhci_hcd *uhci) | |||
278 | __releases(uhci->lock) | 277 | __releases(uhci->lock) |
279 | __acquires(uhci->lock) | 278 | __acquires(uhci->lock) |
280 | { | 279 | { |
281 | dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, | 280 | dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, |
281 | "%s%s\n", __FUNCTION__, | ||
282 | uhci->rh_state == UHCI_RH_AUTO_STOPPED ? | 282 | uhci->rh_state == UHCI_RH_AUTO_STOPPED ? |
283 | " (auto-start)" : ""); | 283 | " (auto-start)" : ""); |
284 | 284 | ||
@@ -293,7 +293,7 @@ __acquires(uhci->lock) | |||
293 | spin_unlock_irq(&uhci->lock); | 293 | spin_unlock_irq(&uhci->lock); |
294 | msleep(20); | 294 | msleep(20); |
295 | spin_lock_irq(&uhci->lock); | 295 | spin_lock_irq(&uhci->lock); |
296 | if (uhci->hc_inaccessible) /* Died */ | 296 | if (uhci->dead) |
297 | return; | 297 | return; |
298 | 298 | ||
299 | /* End Global Resume and wait for EOP to be sent */ | 299 | /* End Global Resume and wait for EOP to be sent */ |
@@ -345,7 +345,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) | |||
345 | errbuf, ERRBUF_LEN); | 345 | errbuf, ERRBUF_LEN); |
346 | lprintk(errbuf); | 346 | lprintk(errbuf); |
347 | } | 347 | } |
348 | hc_died(uhci); | 348 | uhci_hc_died(uhci); |
349 | 349 | ||
350 | /* Force a callback in case there are | 350 | /* Force a callback in case there are |
351 | * pending unlinks */ | 351 | * pending unlinks */ |
@@ -368,12 +368,21 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) | |||
368 | 368 | ||
369 | /* | 369 | /* |
370 | * Store the current frame number in uhci->frame_number if the controller | 370 | * Store the current frame number in uhci->frame_number if the controller |
371 | * is runnning | 371 | * is runnning. Expand from 11 bits (of which we use only 10) to a |
372 | * full-sized integer. | ||
373 | * | ||
374 | * Like many other parts of the driver, this code relies on being polled | ||
375 | * more than once per second as long as the controller is running. | ||
372 | */ | 376 | */ |
373 | static void uhci_get_current_frame_number(struct uhci_hcd *uhci) | 377 | static void uhci_get_current_frame_number(struct uhci_hcd *uhci) |
374 | { | 378 | { |
375 | if (!uhci->is_stopped) | 379 | if (!uhci->is_stopped) { |
376 | uhci->frame_number = inw(uhci->io_addr + USBFRNUM); | 380 | unsigned delta; |
381 | |||
382 | delta = (inw(uhci->io_addr + USBFRNUM) - uhci->frame_number) & | ||
383 | (UHCI_NUMFRAMES - 1); | ||
384 | uhci->frame_number += delta; | ||
385 | } | ||
377 | } | 386 | } |
378 | 387 | ||
379 | /* | 388 | /* |
@@ -407,7 +416,7 @@ static void release_uhci(struct uhci_hcd *uhci) | |||
407 | uhci->frame, uhci->frame_dma_handle); | 416 | uhci->frame, uhci->frame_dma_handle); |
408 | } | 417 | } |
409 | 418 | ||
410 | static int uhci_reset(struct usb_hcd *hcd) | 419 | static int uhci_init(struct usb_hcd *hcd) |
411 | { | 420 | { |
412 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 421 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
413 | unsigned io_size = (unsigned) hcd->rsrc_len; | 422 | unsigned io_size = (unsigned) hcd->rsrc_len; |
@@ -459,7 +468,7 @@ static void uhci_shutdown(struct pci_dev *pdev) | |||
459 | { | 468 | { |
460 | struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev); | 469 | struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev); |
461 | 470 | ||
462 | hc_died(hcd_to_uhci(hcd)); | 471 | uhci_hc_died(hcd_to_uhci(hcd)); |
463 | } | 472 | } |
464 | 473 | ||
465 | /* | 474 | /* |
@@ -487,14 +496,10 @@ static int uhci_start(struct usb_hcd *hcd) | |||
487 | 496 | ||
488 | hcd->uses_new_polling = 1; | 497 | hcd->uses_new_polling = 1; |
489 | 498 | ||
490 | uhci->fsbr = 0; | ||
491 | uhci->fsbrtimeout = 0; | ||
492 | |||
493 | spin_lock_init(&uhci->lock); | 499 | spin_lock_init(&uhci->lock); |
494 | 500 | setup_timer(&uhci->fsbr_timer, uhci_fsbr_timeout, | |
495 | INIT_LIST_HEAD(&uhci->td_remove_list); | 501 | (unsigned long) uhci); |
496 | INIT_LIST_HEAD(&uhci->idle_qh_list); | 502 | INIT_LIST_HEAD(&uhci->idle_qh_list); |
497 | |||
498 | init_waitqueue_head(&uhci->waitqh); | 503 | init_waitqueue_head(&uhci->waitqh); |
499 | 504 | ||
500 | if (DEBUG_CONFIGURED) { | 505 | if (DEBUG_CONFIGURED) { |
@@ -665,11 +670,12 @@ static void uhci_stop(struct usb_hcd *hcd) | |||
665 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 670 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
666 | 671 | ||
667 | spin_lock_irq(&uhci->lock); | 672 | spin_lock_irq(&uhci->lock); |
668 | if (!uhci->hc_inaccessible) | 673 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead) |
669 | hc_died(uhci); | 674 | uhci_hc_died(uhci); |
670 | uhci_scan_schedule(uhci, NULL); | 675 | uhci_scan_schedule(uhci, NULL); |
671 | spin_unlock_irq(&uhci->lock); | 676 | spin_unlock_irq(&uhci->lock); |
672 | 677 | ||
678 | del_timer_sync(&uhci->fsbr_timer); | ||
673 | release_uhci(uhci); | 679 | release_uhci(uhci); |
674 | } | 680 | } |
675 | 681 | ||
@@ -677,12 +683,15 @@ static void uhci_stop(struct usb_hcd *hcd) | |||
677 | static int uhci_rh_suspend(struct usb_hcd *hcd) | 683 | static int uhci_rh_suspend(struct usb_hcd *hcd) |
678 | { | 684 | { |
679 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 685 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
686 | int rc = 0; | ||
680 | 687 | ||
681 | spin_lock_irq(&uhci->lock); | 688 | spin_lock_irq(&uhci->lock); |
682 | if (!uhci->hc_inaccessible) /* Not dead */ | 689 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) |
690 | rc = -ESHUTDOWN; | ||
691 | else if (!uhci->dead) | ||
683 | suspend_rh(uhci, UHCI_RH_SUSPENDED); | 692 | suspend_rh(uhci, UHCI_RH_SUSPENDED); |
684 | spin_unlock_irq(&uhci->lock); | 693 | spin_unlock_irq(&uhci->lock); |
685 | return 0; | 694 | return rc; |
686 | } | 695 | } |
687 | 696 | ||
688 | static int uhci_rh_resume(struct usb_hcd *hcd) | 697 | static int uhci_rh_resume(struct usb_hcd *hcd) |
@@ -691,13 +700,10 @@ static int uhci_rh_resume(struct usb_hcd *hcd) | |||
691 | int rc = 0; | 700 | int rc = 0; |
692 | 701 | ||
693 | spin_lock_irq(&uhci->lock); | 702 | spin_lock_irq(&uhci->lock); |
694 | if (uhci->hc_inaccessible) { | 703 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
695 | if (uhci->rh_state == UHCI_RH_SUSPENDED) { | 704 | dev_warn(&hcd->self.root_hub->dev, "HC isn't running!\n"); |
696 | dev_warn(uhci_dev(uhci), "HC isn't running!\n"); | 705 | rc = -ESHUTDOWN; |
697 | rc = -ENODEV; | 706 | } else if (!uhci->dead) |
698 | } | ||
699 | /* Otherwise the HC is dead */ | ||
700 | } else | ||
701 | wakeup_rh(uhci); | 707 | wakeup_rh(uhci); |
702 | spin_unlock_irq(&uhci->lock); | 708 | spin_unlock_irq(&uhci->lock); |
703 | return rc; | 709 | return rc; |
@@ -711,8 +717,8 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) | |||
711 | dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); | 717 | dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); |
712 | 718 | ||
713 | spin_lock_irq(&uhci->lock); | 719 | spin_lock_irq(&uhci->lock); |
714 | if (uhci->hc_inaccessible) /* Dead or already suspended */ | 720 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) |
715 | goto done; | 721 | goto done_okay; /* Already suspended or dead */ |
716 | 722 | ||
717 | if (uhci->rh_state > UHCI_RH_SUSPENDED) { | 723 | if (uhci->rh_state > UHCI_RH_SUSPENDED) { |
718 | dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); | 724 | dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); |
@@ -725,12 +731,12 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) | |||
725 | */ | 731 | */ |
726 | pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); | 732 | pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); |
727 | mb(); | 733 | mb(); |
728 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
729 | uhci->hc_inaccessible = 1; | ||
730 | hcd->poll_rh = 0; | 734 | hcd->poll_rh = 0; |
731 | 735 | ||
732 | /* FIXME: Enable non-PME# remote wakeup? */ | 736 | /* FIXME: Enable non-PME# remote wakeup? */ |
733 | 737 | ||
738 | done_okay: | ||
739 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
734 | done: | 740 | done: |
735 | spin_unlock_irq(&uhci->lock); | 741 | spin_unlock_irq(&uhci->lock); |
736 | return rc; | 742 | return rc; |
@@ -743,24 +749,22 @@ static int uhci_resume(struct usb_hcd *hcd) | |||
743 | dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); | 749 | dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); |
744 | 750 | ||
745 | /* Since we aren't in D3 any more, it's safe to set this flag | 751 | /* Since we aren't in D3 any more, it's safe to set this flag |
746 | * even if the controller was dead. It might not even be dead | 752 | * even if the controller was dead. |
747 | * any more, if the firmware or quirks code has reset it. | ||
748 | */ | 753 | */ |
749 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 754 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
750 | mb(); | 755 | mb(); |
751 | 756 | ||
752 | if (uhci->rh_state == UHCI_RH_RESET) /* Dead */ | ||
753 | return 0; | ||
754 | spin_lock_irq(&uhci->lock); | 757 | spin_lock_irq(&uhci->lock); |
755 | 758 | ||
756 | /* FIXME: Disable non-PME# remote wakeup? */ | 759 | /* FIXME: Disable non-PME# remote wakeup? */ |
757 | 760 | ||
758 | uhci->hc_inaccessible = 0; | 761 | /* The firmware or a boot kernel may have changed the controller |
759 | 762 | * settings during a system wakeup. Check it and reconfigure | |
760 | /* The BIOS may have changed the controller settings during a | 763 | * to avoid problems. |
761 | * system wakeup. Check it and reconfigure to avoid problems. | ||
762 | */ | 764 | */ |
763 | check_and_reset_hc(uhci); | 765 | check_and_reset_hc(uhci); |
766 | |||
767 | /* If the controller was dead before, it's back alive now */ | ||
764 | configure_hc(uhci); | 768 | configure_hc(uhci); |
765 | 769 | ||
766 | if (uhci->rh_state == UHCI_RH_RESET) { | 770 | if (uhci->rh_state == UHCI_RH_RESET) { |
@@ -810,18 +814,15 @@ done: | |||
810 | static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) | 814 | static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) |
811 | { | 815 | { |
812 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 816 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
813 | unsigned long flags; | 817 | unsigned frame_number; |
814 | int is_stopped; | 818 | unsigned delta; |
815 | int frame_number; | ||
816 | 819 | ||
817 | /* Minimize latency by avoiding the spinlock */ | 820 | /* Minimize latency by avoiding the spinlock */ |
818 | local_irq_save(flags); | 821 | frame_number = uhci->frame_number; |
819 | is_stopped = uhci->is_stopped; | 822 | barrier(); |
820 | smp_rmb(); | 823 | delta = (inw(uhci->io_addr + USBFRNUM) - frame_number) & |
821 | frame_number = (is_stopped ? uhci->frame_number : | 824 | (UHCI_NUMFRAMES - 1); |
822 | inw(uhci->io_addr + USBFRNUM)); | 825 | return frame_number + delta; |
823 | local_irq_restore(flags); | ||
824 | return frame_number; | ||
825 | } | 826 | } |
826 | 827 | ||
827 | static const char hcd_name[] = "uhci_hcd"; | 828 | static const char hcd_name[] = "uhci_hcd"; |
@@ -836,7 +837,7 @@ static const struct hc_driver uhci_driver = { | |||
836 | .flags = HCD_USB11, | 837 | .flags = HCD_USB11, |
837 | 838 | ||
838 | /* Basic lifecycle operations */ | 839 | /* Basic lifecycle operations */ |
839 | .reset = uhci_reset, | 840 | .reset = uhci_init, |
840 | .start = uhci_start, | 841 | .start = uhci_start, |
841 | #ifdef CONFIG_PM | 842 | #ifdef CONFIG_PM |
842 | .suspend = uhci_suspend, | 843 | .suspend = uhci_suspend, |
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h index d5c8f4d92823..108e3de2dc26 100644 --- a/drivers/usb/host/uhci-hcd.h +++ b/drivers/usb/host/uhci-hcd.h | |||
@@ -84,6 +84,13 @@ | |||
84 | #define CAN_SCHEDULE_FRAMES 1000 /* how far in the future frames | 84 | #define CAN_SCHEDULE_FRAMES 1000 /* how far in the future frames |
85 | * can be scheduled */ | 85 | * can be scheduled */ |
86 | 86 | ||
87 | /* When no queues need Full-Speed Bandwidth Reclamation, | ||
88 | * delay this long before turning FSBR off */ | ||
89 | #define FSBR_OFF_DELAY msecs_to_jiffies(10) | ||
90 | |||
91 | /* If a queue hasn't advanced after this much time, assume it is stuck */ | ||
92 | #define QH_WAIT_TIMEOUT msecs_to_jiffies(200) | ||
93 | |||
87 | 94 | ||
88 | /* | 95 | /* |
89 | * Queue Headers | 96 | * Queue Headers |
@@ -121,21 +128,31 @@ struct uhci_qh { | |||
121 | __le32 element; /* Queue element (TD) pointer */ | 128 | __le32 element; /* Queue element (TD) pointer */ |
122 | 129 | ||
123 | /* Software fields */ | 130 | /* Software fields */ |
124 | dma_addr_t dma_handle; | ||
125 | |||
126 | struct list_head node; /* Node in the list of QHs */ | 131 | struct list_head node; /* Node in the list of QHs */ |
127 | struct usb_host_endpoint *hep; /* Endpoint information */ | 132 | struct usb_host_endpoint *hep; /* Endpoint information */ |
128 | struct usb_device *udev; | 133 | struct usb_device *udev; |
129 | struct list_head queue; /* Queue of urbps for this QH */ | 134 | struct list_head queue; /* Queue of urbps for this QH */ |
130 | struct uhci_qh *skel; /* Skeleton for this QH */ | 135 | struct uhci_qh *skel; /* Skeleton for this QH */ |
131 | struct uhci_td *dummy_td; /* Dummy TD to end the queue */ | 136 | struct uhci_td *dummy_td; /* Dummy TD to end the queue */ |
137 | struct uhci_td *post_td; /* Last TD completed */ | ||
132 | 138 | ||
139 | struct usb_iso_packet_descriptor *iso_packet_desc; | ||
140 | /* Next urb->iso_frame_desc entry */ | ||
141 | unsigned long advance_jiffies; /* Time of last queue advance */ | ||
133 | unsigned int unlink_frame; /* When the QH was unlinked */ | 142 | unsigned int unlink_frame; /* When the QH was unlinked */ |
143 | unsigned int period; /* For Interrupt and Isochronous QHs */ | ||
144 | unsigned int iso_frame; /* Frame # for iso_packet_desc */ | ||
145 | int iso_status; /* Status for Isochronous URBs */ | ||
146 | |||
134 | int state; /* QH_STATE_xxx; see above */ | 147 | int state; /* QH_STATE_xxx; see above */ |
148 | int type; /* Queue type (control, bulk, etc) */ | ||
149 | |||
150 | dma_addr_t dma_handle; | ||
135 | 151 | ||
136 | unsigned int initial_toggle:1; /* Endpoint's current toggle value */ | 152 | unsigned int initial_toggle:1; /* Endpoint's current toggle value */ |
137 | unsigned int needs_fixup:1; /* Must fix the TD toggle values */ | 153 | unsigned int needs_fixup:1; /* Must fix the TD toggle values */ |
138 | unsigned int is_stopped:1; /* Queue was stopped by an error */ | 154 | unsigned int is_stopped:1; /* Queue was stopped by error/unlink */ |
155 | unsigned int wait_expired:1; /* QH_WAIT_TIMEOUT has expired */ | ||
139 | } __attribute__((aligned(16))); | 156 | } __attribute__((aligned(16))); |
140 | 157 | ||
141 | /* | 158 | /* |
@@ -226,7 +243,6 @@ struct uhci_td { | |||
226 | dma_addr_t dma_handle; | 243 | dma_addr_t dma_handle; |
227 | 244 | ||
228 | struct list_head list; | 245 | struct list_head list; |
229 | struct list_head remove_list; | ||
230 | 246 | ||
231 | int frame; /* for iso: what frame? */ | 247 | int frame; /* for iso: what frame? */ |
232 | struct list_head fl_list; | 248 | struct list_head fl_list; |
@@ -305,38 +321,8 @@ static inline u32 td_status(struct uhci_td *td) { | |||
305 | #define skel_bulk_qh skelqh[12] | 321 | #define skel_bulk_qh skelqh[12] |
306 | #define skel_term_qh skelqh[13] | 322 | #define skel_term_qh skelqh[13] |
307 | 323 | ||
308 | /* | 324 | /* Find the skelqh entry corresponding to an interval exponent */ |
309 | * Search tree for determining where <interval> fits in the skelqh[] | 325 | #define UHCI_SKEL_INDEX(exponent) (9 - exponent) |
310 | * skeleton. | ||
311 | * | ||
312 | * An interrupt request should be placed into the slowest skelqh[] | ||
313 | * which meets the interval/period/frequency requirement. | ||
314 | * An interrupt request is allowed to be faster than <interval> but not slower. | ||
315 | * | ||
316 | * For a given <interval>, this function returns the appropriate/matching | ||
317 | * skelqh[] index value. | ||
318 | */ | ||
319 | static inline int __interval_to_skel(int interval) | ||
320 | { | ||
321 | if (interval < 16) { | ||
322 | if (interval < 4) { | ||
323 | if (interval < 2) | ||
324 | return 9; /* int1 for 0-1 ms */ | ||
325 | return 8; /* int2 for 2-3 ms */ | ||
326 | } | ||
327 | if (interval < 8) | ||
328 | return 7; /* int4 for 4-7 ms */ | ||
329 | return 6; /* int8 for 8-15 ms */ | ||
330 | } | ||
331 | if (interval < 64) { | ||
332 | if (interval < 32) | ||
333 | return 5; /* int16 for 16-31 ms */ | ||
334 | return 4; /* int32 for 32-63 ms */ | ||
335 | } | ||
336 | if (interval < 128) | ||
337 | return 3; /* int64 for 64-127 ms */ | ||
338 | return 2; /* int128 for 128-255 ms (Max.) */ | ||
339 | } | ||
340 | 326 | ||
341 | 327 | ||
342 | /* | 328 | /* |
@@ -396,32 +382,32 @@ struct uhci_hcd { | |||
396 | __le32 *frame; | 382 | __le32 *frame; |
397 | void **frame_cpu; /* CPU's frame list */ | 383 | void **frame_cpu; /* CPU's frame list */ |
398 | 384 | ||
399 | int fsbr; /* Full-speed bandwidth reclamation */ | ||
400 | unsigned long fsbrtimeout; /* FSBR delay */ | ||
401 | |||
402 | enum uhci_rh_state rh_state; | 385 | enum uhci_rh_state rh_state; |
403 | unsigned long auto_stop_time; /* When to AUTO_STOP */ | 386 | unsigned long auto_stop_time; /* When to AUTO_STOP */ |
404 | 387 | ||
405 | unsigned int frame_number; /* As of last check */ | 388 | unsigned int frame_number; /* As of last check */ |
406 | unsigned int is_stopped; | 389 | unsigned int is_stopped; |
407 | #define UHCI_IS_STOPPED 9999 /* Larger than a frame # */ | 390 | #define UHCI_IS_STOPPED 9999 /* Larger than a frame # */ |
391 | unsigned int last_iso_frame; /* Frame of last scan */ | ||
392 | unsigned int cur_iso_frame; /* Frame for current scan */ | ||
408 | 393 | ||
409 | unsigned int scan_in_progress:1; /* Schedule scan is running */ | 394 | unsigned int scan_in_progress:1; /* Schedule scan is running */ |
410 | unsigned int need_rescan:1; /* Redo the schedule scan */ | 395 | unsigned int need_rescan:1; /* Redo the schedule scan */ |
411 | unsigned int hc_inaccessible:1; /* HC is suspended or dead */ | 396 | unsigned int dead:1; /* Controller has died */ |
412 | unsigned int working_RD:1; /* Suspended root hub doesn't | 397 | unsigned int working_RD:1; /* Suspended root hub doesn't |
413 | need to be polled */ | 398 | need to be polled */ |
414 | unsigned int is_initialized:1; /* Data structure is usable */ | 399 | unsigned int is_initialized:1; /* Data structure is usable */ |
400 | unsigned int fsbr_is_on:1; /* FSBR is turned on */ | ||
401 | unsigned int fsbr_is_wanted:1; /* Does any URB want FSBR? */ | ||
402 | unsigned int fsbr_expiring:1; /* FSBR is timing out */ | ||
403 | |||
404 | struct timer_list fsbr_timer; /* For turning off FBSR */ | ||
415 | 405 | ||
416 | /* Support for port suspend/resume/reset */ | 406 | /* Support for port suspend/resume/reset */ |
417 | unsigned long port_c_suspend; /* Bit-arrays of ports */ | 407 | unsigned long port_c_suspend; /* Bit-arrays of ports */ |
418 | unsigned long resuming_ports; | 408 | unsigned long resuming_ports; |
419 | unsigned long ports_timeout; /* Time to stop signalling */ | 409 | unsigned long ports_timeout; /* Time to stop signalling */ |
420 | 410 | ||
421 | /* List of TDs that are done, but waiting to be freed (race) */ | ||
422 | struct list_head td_remove_list; | ||
423 | unsigned int td_remove_age; /* Age in frames */ | ||
424 | |||
425 | struct list_head idle_qh_list; /* Where the idle QHs live */ | 411 | struct list_head idle_qh_list; /* Where the idle QHs live */ |
426 | 412 | ||
427 | int rh_numports; /* Number of root-hub ports */ | 413 | int rh_numports; /* Number of root-hub ports */ |
@@ -442,6 +428,9 @@ static inline struct usb_hcd *uhci_to_hcd(struct uhci_hcd *uhci) | |||
442 | 428 | ||
443 | #define uhci_dev(u) (uhci_to_hcd(u)->self.controller) | 429 | #define uhci_dev(u) (uhci_to_hcd(u)->self.controller) |
444 | 430 | ||
431 | /* Utility macro for comparing frame numbers */ | ||
432 | #define uhci_frame_before_eq(f1, f2) (0 <= (int) ((f2) - (f1))) | ||
433 | |||
445 | 434 | ||
446 | /* | 435 | /* |
447 | * Private per-URB data | 436 | * Private per-URB data |
@@ -454,9 +443,7 @@ struct urb_priv { | |||
454 | struct uhci_qh *qh; /* QH for this URB */ | 443 | struct uhci_qh *qh; /* QH for this URB */ |
455 | struct list_head td_list; | 444 | struct list_head td_list; |
456 | 445 | ||
457 | unsigned fsbr : 1; /* URB turned on FSBR */ | 446 | unsigned fsbr:1; /* URB wants FSBR */ |
458 | unsigned short_transfer : 1; /* URB got a short transfer, no | ||
459 | * need to rescan */ | ||
460 | }; | 447 | }; |
461 | 448 | ||
462 | 449 | ||
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c index c8451d9578f1..c545ef92fe29 100644 --- a/drivers/usb/host/uhci-hub.c +++ b/drivers/usb/host/uhci-hub.c | |||
@@ -171,9 +171,8 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
171 | spin_lock_irqsave(&uhci->lock, flags); | 171 | spin_lock_irqsave(&uhci->lock, flags); |
172 | 172 | ||
173 | uhci_scan_schedule(uhci, NULL); | 173 | uhci_scan_schedule(uhci, NULL); |
174 | if (uhci->hc_inaccessible) | 174 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) |
175 | goto done; | 175 | goto done; |
176 | check_fsbr(uhci); | ||
177 | uhci_check_ports(uhci); | 176 | uhci_check_ports(uhci); |
178 | 177 | ||
179 | status = get_hub_status_data(uhci, buf); | 178 | status = get_hub_status_data(uhci, buf); |
@@ -228,7 +227,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
228 | u16 wPortChange, wPortStatus; | 227 | u16 wPortChange, wPortStatus; |
229 | unsigned long flags; | 228 | unsigned long flags; |
230 | 229 | ||
231 | if (uhci->hc_inaccessible) | 230 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) |
232 | return -ETIMEDOUT; | 231 | return -ETIMEDOUT; |
233 | 232 | ||
234 | spin_lock_irqsave(&uhci->lock, flags); | 233 | spin_lock_irqsave(&uhci->lock, flags); |
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index a06d84c19e13..c9d72ac0a1d7 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
@@ -13,10 +13,9 @@ | |||
13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
16 | * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu | 16 | * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu |
17 | */ | 17 | */ |
18 | 18 | ||
19 | static void uhci_free_pending_tds(struct uhci_hcd *uhci); | ||
20 | 19 | ||
21 | /* | 20 | /* |
22 | * Technically, updating td->status here is a race, but it's not really a | 21 | * Technically, updating td->status here is a race, but it's not really a |
@@ -38,6 +37,60 @@ static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) | |||
38 | uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); | 37 | uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); |
39 | } | 38 | } |
40 | 39 | ||
40 | |||
41 | /* | ||
42 | * Full-Speed Bandwidth Reclamation (FSBR). | ||
43 | * We turn on FSBR whenever a queue that wants it is advancing, | ||
44 | * and leave it on for a short time thereafter. | ||
45 | */ | ||
46 | static void uhci_fsbr_on(struct uhci_hcd *uhci) | ||
47 | { | ||
48 | uhci->fsbr_is_on = 1; | ||
49 | uhci->skel_term_qh->link = cpu_to_le32( | ||
50 | uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; | ||
51 | } | ||
52 | |||
53 | static void uhci_fsbr_off(struct uhci_hcd *uhci) | ||
54 | { | ||
55 | uhci->fsbr_is_on = 0; | ||
56 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | ||
57 | } | ||
58 | |||
59 | static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
60 | { | ||
61 | struct urb_priv *urbp = urb->hcpriv; | ||
62 | |||
63 | if (!(urb->transfer_flags & URB_NO_FSBR)) | ||
64 | urbp->fsbr = 1; | ||
65 | } | ||
66 | |||
67 | static void uhci_urbp_wants_fsbr(struct uhci_hcd *uhci, struct urb_priv *urbp) | ||
68 | { | ||
69 | if (urbp->fsbr) { | ||
70 | uhci->fsbr_is_wanted = 1; | ||
71 | if (!uhci->fsbr_is_on) | ||
72 | uhci_fsbr_on(uhci); | ||
73 | else if (uhci->fsbr_expiring) { | ||
74 | uhci->fsbr_expiring = 0; | ||
75 | del_timer(&uhci->fsbr_timer); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | static void uhci_fsbr_timeout(unsigned long _uhci) | ||
81 | { | ||
82 | struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci; | ||
83 | unsigned long flags; | ||
84 | |||
85 | spin_lock_irqsave(&uhci->lock, flags); | ||
86 | if (uhci->fsbr_expiring) { | ||
87 | uhci->fsbr_expiring = 0; | ||
88 | uhci_fsbr_off(uhci); | ||
89 | } | ||
90 | spin_unlock_irqrestore(&uhci->lock, flags); | ||
91 | } | ||
92 | |||
93 | |||
41 | static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) | 94 | static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) |
42 | { | 95 | { |
43 | dma_addr_t dma_handle; | 96 | dma_addr_t dma_handle; |
@@ -51,7 +104,6 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) | |||
51 | td->frame = -1; | 104 | td->frame = -1; |
52 | 105 | ||
53 | INIT_LIST_HEAD(&td->list); | 106 | INIT_LIST_HEAD(&td->list); |
54 | INIT_LIST_HEAD(&td->remove_list); | ||
55 | INIT_LIST_HEAD(&td->fl_list); | 107 | INIT_LIST_HEAD(&td->fl_list); |
56 | 108 | ||
57 | return td; | 109 | return td; |
@@ -61,8 +113,6 @@ static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) | |||
61 | { | 113 | { |
62 | if (!list_empty(&td->list)) | 114 | if (!list_empty(&td->list)) |
63 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); | 115 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); |
64 | if (!list_empty(&td->remove_list)) | ||
65 | dev_warn(uhci_dev(uhci), "td %p still in remove_list!\n", td); | ||
66 | if (!list_empty(&td->fl_list)) | 116 | if (!list_empty(&td->fl_list)) |
67 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); | 117 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); |
68 | 118 | ||
@@ -77,6 +127,16 @@ static inline void uhci_fill_td(struct uhci_td *td, u32 status, | |||
77 | td->buffer = cpu_to_le32(buffer); | 127 | td->buffer = cpu_to_le32(buffer); |
78 | } | 128 | } |
79 | 129 | ||
130 | static void uhci_add_td_to_urbp(struct uhci_td *td, struct urb_priv *urbp) | ||
131 | { | ||
132 | list_add_tail(&td->list, &urbp->td_list); | ||
133 | } | ||
134 | |||
135 | static void uhci_remove_td_from_urbp(struct uhci_td *td) | ||
136 | { | ||
137 | list_del_init(&td->list); | ||
138 | } | ||
139 | |||
80 | /* | 140 | /* |
81 | * We insert Isochronous URBs directly into the frame list at the beginning | 141 | * We insert Isochronous URBs directly into the frame list at the beginning |
82 | */ | 142 | */ |
@@ -138,6 +198,24 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci, | |||
138 | td->frame = -1; | 198 | td->frame = -1; |
139 | } | 199 | } |
140 | 200 | ||
201 | static inline void uhci_remove_tds_from_frame(struct uhci_hcd *uhci, | ||
202 | unsigned int framenum) | ||
203 | { | ||
204 | struct uhci_td *ftd, *ltd; | ||
205 | |||
206 | framenum &= (UHCI_NUMFRAMES - 1); | ||
207 | |||
208 | ftd = uhci->frame_cpu[framenum]; | ||
209 | if (ftd) { | ||
210 | ltd = list_entry(ftd->fl_list.prev, struct uhci_td, fl_list); | ||
211 | uhci->frame[framenum] = ltd->link; | ||
212 | uhci->frame_cpu[framenum] = NULL; | ||
213 | |||
214 | while (!list_empty(&ftd->fl_list)) | ||
215 | list_del_init(ftd->fl_list.prev); | ||
216 | } | ||
217 | } | ||
218 | |||
141 | /* | 219 | /* |
142 | * Remove all the TDs for an Isochronous URB from the frame list | 220 | * Remove all the TDs for an Isochronous URB from the frame list |
143 | */ | 221 | */ |
@@ -148,7 +226,6 @@ static void uhci_unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb) | |||
148 | 226 | ||
149 | list_for_each_entry(td, &urbp->td_list, list) | 227 | list_for_each_entry(td, &urbp->td_list, list) |
150 | uhci_remove_td_from_frame_list(uhci, td); | 228 | uhci_remove_td_from_frame_list(uhci, td); |
151 | wmb(); | ||
152 | } | 229 | } |
153 | 230 | ||
154 | static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | 231 | static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, |
@@ -161,6 +238,7 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
161 | if (!qh) | 238 | if (!qh) |
162 | return NULL; | 239 | return NULL; |
163 | 240 | ||
241 | memset(qh, 0, sizeof(*qh)); | ||
164 | qh->dma_handle = dma_handle; | 242 | qh->dma_handle = dma_handle; |
165 | 243 | ||
166 | qh->element = UHCI_PTR_TERM; | 244 | qh->element = UHCI_PTR_TERM; |
@@ -179,10 +257,11 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
179 | qh->hep = hep; | 257 | qh->hep = hep; |
180 | qh->udev = udev; | 258 | qh->udev = udev; |
181 | hep->hcpriv = qh; | 259 | hep->hcpriv = qh; |
260 | qh->type = hep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
182 | 261 | ||
183 | } else { /* Skeleton QH */ | 262 | } else { /* Skeleton QH */ |
184 | qh->state = QH_STATE_ACTIVE; | 263 | qh->state = QH_STATE_ACTIVE; |
185 | qh->udev = NULL; | 264 | qh->type = -1; |
186 | } | 265 | } |
187 | return qh; | 266 | return qh; |
188 | } | 267 | } |
@@ -202,35 +281,64 @@ static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
202 | } | 281 | } |
203 | 282 | ||
204 | /* | 283 | /* |
205 | * When the currently executing URB is dequeued, save its current toggle value | 284 | * When a queue is stopped and a dequeued URB is given back, adjust |
285 | * the previous TD link (if the URB isn't first on the queue) or | ||
286 | * save its toggle value (if it is first and is currently executing). | ||
287 | * | ||
288 | * Returns 0 if the URB should not yet be given back, 1 otherwise. | ||
206 | */ | 289 | */ |
207 | static void uhci_save_toggle(struct uhci_qh *qh, struct urb *urb) | 290 | static int uhci_cleanup_queue(struct uhci_hcd *uhci, struct uhci_qh *qh, |
291 | struct urb *urb) | ||
208 | { | 292 | { |
209 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 293 | struct urb_priv *urbp = urb->hcpriv; |
210 | struct uhci_td *td; | 294 | struct uhci_td *td; |
295 | int ret = 1; | ||
296 | |||
297 | /* Isochronous pipes don't use toggles and their TD link pointers | ||
298 | * get adjusted during uhci_urb_dequeue(). But since their queues | ||
299 | * cannot truly be stopped, we have to watch out for dequeues | ||
300 | * occurring after the nominal unlink frame. */ | ||
301 | if (qh->type == USB_ENDPOINT_XFER_ISOC) { | ||
302 | ret = (uhci->frame_number + uhci->is_stopped != | ||
303 | qh->unlink_frame); | ||
304 | goto done; | ||
305 | } | ||
306 | |||
307 | /* If the URB isn't first on its queue, adjust the link pointer | ||
308 | * of the last TD in the previous URB. The toggle doesn't need | ||
309 | * to be saved since this URB can't be executing yet. */ | ||
310 | if (qh->queue.next != &urbp->node) { | ||
311 | struct urb_priv *purbp; | ||
312 | struct uhci_td *ptd; | ||
313 | |||
314 | purbp = list_entry(urbp->node.prev, struct urb_priv, node); | ||
315 | WARN_ON(list_empty(&purbp->td_list)); | ||
316 | ptd = list_entry(purbp->td_list.prev, struct uhci_td, | ||
317 | list); | ||
318 | td = list_entry(urbp->td_list.prev, struct uhci_td, | ||
319 | list); | ||
320 | ptd->link = td->link; | ||
321 | goto done; | ||
322 | } | ||
211 | 323 | ||
212 | /* If the QH element pointer is UHCI_PTR_TERM then then currently | 324 | /* If the QH element pointer is UHCI_PTR_TERM then then currently |
213 | * executing URB has already been unlinked, so this one isn't it. */ | 325 | * executing URB has already been unlinked, so this one isn't it. */ |
214 | if (qh_element(qh) == UHCI_PTR_TERM || | 326 | if (qh_element(qh) == UHCI_PTR_TERM) |
215 | qh->queue.next != &urbp->node) | 327 | goto done; |
216 | return; | ||
217 | qh->element = UHCI_PTR_TERM; | 328 | qh->element = UHCI_PTR_TERM; |
218 | 329 | ||
219 | /* Only bulk and interrupt pipes have to worry about toggles */ | 330 | /* Control pipes have to worry about toggles */ |
220 | if (!(usb_pipetype(urb->pipe) == PIPE_BULK || | 331 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) |
221 | usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) | 332 | goto done; |
222 | return; | ||
223 | 333 | ||
224 | /* Find the first active TD; that's the device's toggle state */ | 334 | /* Save the next toggle value */ |
225 | list_for_each_entry(td, &urbp->td_list, list) { | 335 | WARN_ON(list_empty(&urbp->td_list)); |
226 | if (td_status(td) & TD_CTRL_ACTIVE) { | 336 | td = list_entry(urbp->td_list.next, struct uhci_td, list); |
227 | qh->needs_fixup = 1; | 337 | qh->needs_fixup = 1; |
228 | qh->initial_toggle = uhci_toggle(td_token(td)); | 338 | qh->initial_toggle = uhci_toggle(td_token(td)); |
229 | return; | ||
230 | } | ||
231 | } | ||
232 | 339 | ||
233 | WARN_ON(1); | 340 | done: |
341 | return ret; | ||
234 | } | 342 | } |
235 | 343 | ||
236 | /* | 344 | /* |
@@ -305,6 +413,10 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
305 | qh->element = cpu_to_le32(td->dma_handle); | 413 | qh->element = cpu_to_le32(td->dma_handle); |
306 | } | 414 | } |
307 | 415 | ||
416 | /* Treat the queue as if it has just advanced */ | ||
417 | qh->wait_expired = 0; | ||
418 | qh->advance_jiffies = jiffies; | ||
419 | |||
308 | if (qh->state == QH_STATE_ACTIVE) | 420 | if (qh->state == QH_STATE_ACTIVE) |
309 | return; | 421 | return; |
310 | qh->state = QH_STATE_ACTIVE; | 422 | qh->state = QH_STATE_ACTIVE; |
@@ -370,6 +482,12 @@ static void uhci_make_qh_idle(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
370 | list_move(&qh->node, &uhci->idle_qh_list); | 482 | list_move(&qh->node, &uhci->idle_qh_list); |
371 | qh->state = QH_STATE_IDLE; | 483 | qh->state = QH_STATE_IDLE; |
372 | 484 | ||
485 | /* Now that the QH is idle, its post_td isn't being used */ | ||
486 | if (qh->post_td) { | ||
487 | uhci_free_td(uhci, qh->post_td); | ||
488 | qh->post_td = NULL; | ||
489 | } | ||
490 | |||
373 | /* If anyone is waiting for a QH to become idle, wake them up */ | 491 | /* If anyone is waiting for a QH to become idle, wake them up */ |
374 | if (uhci->num_waiting) | 492 | if (uhci->num_waiting) |
375 | wake_up_all(&uhci->waitqh); | 493 | wake_up_all(&uhci->waitqh); |
@@ -395,21 +513,6 @@ static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, | |||
395 | return urbp; | 513 | return urbp; |
396 | } | 514 | } |
397 | 515 | ||
398 | static void uhci_add_td_to_urb(struct urb *urb, struct uhci_td *td) | ||
399 | { | ||
400 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
401 | |||
402 | list_add_tail(&td->list, &urbp->td_list); | ||
403 | } | ||
404 | |||
405 | static void uhci_remove_td_from_urb(struct uhci_td *td) | ||
406 | { | ||
407 | if (list_empty(&td->list)) | ||
408 | return; | ||
409 | |||
410 | list_del_init(&td->list); | ||
411 | } | ||
412 | |||
413 | static void uhci_free_urb_priv(struct uhci_hcd *uhci, | 516 | static void uhci_free_urb_priv(struct uhci_hcd *uhci, |
414 | struct urb_priv *urbp) | 517 | struct urb_priv *urbp) |
415 | { | 518 | { |
@@ -419,48 +522,15 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci, | |||
419 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", | 522 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", |
420 | urbp->urb); | 523 | urbp->urb); |
421 | 524 | ||
422 | uhci_get_current_frame_number(uhci); | ||
423 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) { | ||
424 | uhci_free_pending_tds(uhci); | ||
425 | uhci->td_remove_age = uhci->frame_number; | ||
426 | } | ||
427 | |||
428 | /* Check to see if the remove list is empty. Set the IOC bit */ | ||
429 | /* to force an interrupt so we can remove the TDs. */ | ||
430 | if (list_empty(&uhci->td_remove_list)) | ||
431 | uhci_set_next_interrupt(uhci); | ||
432 | |||
433 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { | 525 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
434 | uhci_remove_td_from_urb(td); | 526 | uhci_remove_td_from_urbp(td); |
435 | list_add(&td->remove_list, &uhci->td_remove_list); | 527 | uhci_free_td(uhci, td); |
436 | } | 528 | } |
437 | 529 | ||
438 | urbp->urb->hcpriv = NULL; | 530 | urbp->urb->hcpriv = NULL; |
439 | kmem_cache_free(uhci_up_cachep, urbp); | 531 | kmem_cache_free(uhci_up_cachep, urbp); |
440 | } | 532 | } |
441 | 533 | ||
442 | static void uhci_inc_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
443 | { | ||
444 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
445 | |||
446 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && !urbp->fsbr) { | ||
447 | urbp->fsbr = 1; | ||
448 | if (!uhci->fsbr++ && !uhci->fsbrtimeout) | ||
449 | uhci->skel_term_qh->link = cpu_to_le32(uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; | ||
450 | } | ||
451 | } | ||
452 | |||
453 | static void uhci_dec_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
454 | { | ||
455 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
456 | |||
457 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && urbp->fsbr) { | ||
458 | urbp->fsbr = 0; | ||
459 | if (!--uhci->fsbr) | ||
460 | uhci->fsbrtimeout = jiffies + FSBR_DELAY; | ||
461 | } | ||
462 | } | ||
463 | |||
464 | /* | 534 | /* |
465 | * Map status to standard result codes | 535 | * Map status to standard result codes |
466 | * | 536 | * |
@@ -487,7 +557,6 @@ static int uhci_map_status(int status, int dir_out) | |||
487 | return -ENOSR; | 557 | return -ENOSR; |
488 | if (status & TD_CTRL_STALLED) /* Stalled */ | 558 | if (status & TD_CTRL_STALLED) /* Stalled */ |
489 | return -EPIPE; | 559 | return -EPIPE; |
490 | WARN_ON(status & TD_CTRL_ACTIVE); /* Active */ | ||
491 | return 0; | 560 | return 0; |
492 | } | 561 | } |
493 | 562 | ||
@@ -503,6 +572,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
503 | int len = urb->transfer_buffer_length; | 572 | int len = urb->transfer_buffer_length; |
504 | dma_addr_t data = urb->transfer_dma; | 573 | dma_addr_t data = urb->transfer_dma; |
505 | __le32 *plink; | 574 | __le32 *plink; |
575 | struct urb_priv *urbp = urb->hcpriv; | ||
506 | 576 | ||
507 | /* The "pipe" thing contains the destination in bits 8--18 */ | 577 | /* The "pipe" thing contains the destination in bits 8--18 */ |
508 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; | 578 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; |
@@ -516,7 +586,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
516 | * Build the TD for the control request setup packet | 586 | * Build the TD for the control request setup packet |
517 | */ | 587 | */ |
518 | td = qh->dummy_td; | 588 | td = qh->dummy_td; |
519 | uhci_add_td_to_urb(urb, td); | 589 | uhci_add_td_to_urbp(td, urbp); |
520 | uhci_fill_td(td, status, destination | uhci_explen(8), | 590 | uhci_fill_td(td, status, destination | uhci_explen(8), |
521 | urb->setup_dma); | 591 | urb->setup_dma); |
522 | plink = &td->link; | 592 | plink = &td->link; |
@@ -548,7 +618,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
548 | /* Alternate Data0/1 (start with Data1) */ | 618 | /* Alternate Data0/1 (start with Data1) */ |
549 | destination ^= TD_TOKEN_TOGGLE; | 619 | destination ^= TD_TOKEN_TOGGLE; |
550 | 620 | ||
551 | uhci_add_td_to_urb(urb, td); | 621 | uhci_add_td_to_urbp(td, urbp); |
552 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), | 622 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), |
553 | data); | 623 | data); |
554 | plink = &td->link; | 624 | plink = &td->link; |
@@ -579,7 +649,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
579 | 649 | ||
580 | status &= ~TD_CTRL_SPD; | 650 | status &= ~TD_CTRL_SPD; |
581 | 651 | ||
582 | uhci_add_td_to_urb(urb, td); | 652 | uhci_add_td_to_urbp(td, urbp); |
583 | uhci_fill_td(td, status | TD_CTRL_IOC, | 653 | uhci_fill_td(td, status | TD_CTRL_IOC, |
584 | destination | uhci_explen(0), 0); | 654 | destination | uhci_explen(0), 0); |
585 | plink = &td->link; | 655 | plink = &td->link; |
@@ -606,145 +676,19 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
606 | qh->skel = uhci->skel_ls_control_qh; | 676 | qh->skel = uhci->skel_ls_control_qh; |
607 | else { | 677 | else { |
608 | qh->skel = uhci->skel_fs_control_qh; | 678 | qh->skel = uhci->skel_fs_control_qh; |
609 | uhci_inc_fsbr(uhci, urb); | 679 | uhci_add_fsbr(uhci, urb); |
610 | } | 680 | } |
681 | |||
682 | urb->actual_length = -8; /* Account for the SETUP packet */ | ||
611 | return 0; | 683 | return 0; |
612 | 684 | ||
613 | nomem: | 685 | nomem: |
614 | /* Remove the dummy TD from the td_list so it doesn't get freed */ | 686 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
615 | uhci_remove_td_from_urb(qh->dummy_td); | 687 | uhci_remove_td_from_urbp(qh->dummy_td); |
616 | return -ENOMEM; | 688 | return -ENOMEM; |
617 | } | 689 | } |
618 | 690 | ||
619 | /* | 691 | /* |
620 | * If control-IN transfer was short, the status packet wasn't sent. | ||
621 | * This routine changes the element pointer in the QH to point at the | ||
622 | * status TD. It's safe to do this even while the QH is live, because | ||
623 | * the hardware only updates the element pointer following a successful | ||
624 | * transfer. The inactive TD for the short packet won't cause an update, | ||
625 | * so the pointer won't get overwritten. The next time the controller | ||
626 | * sees this QH, it will send the status packet. | ||
627 | */ | ||
628 | static int usb_control_retrigger_status(struct uhci_hcd *uhci, struct urb *urb) | ||
629 | { | ||
630 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
631 | struct uhci_td *td; | ||
632 | |||
633 | urbp->short_transfer = 1; | ||
634 | |||
635 | td = list_entry(urbp->td_list.prev, struct uhci_td, list); | ||
636 | urbp->qh->element = cpu_to_le32(td->dma_handle); | ||
637 | |||
638 | return -EINPROGRESS; | ||
639 | } | ||
640 | |||
641 | |||
642 | static int uhci_result_control(struct uhci_hcd *uhci, struct urb *urb) | ||
643 | { | ||
644 | struct list_head *tmp, *head; | ||
645 | struct urb_priv *urbp = urb->hcpriv; | ||
646 | struct uhci_td *td; | ||
647 | unsigned int status; | ||
648 | int ret = 0; | ||
649 | |||
650 | head = &urbp->td_list; | ||
651 | if (urbp->short_transfer) { | ||
652 | tmp = head->prev; | ||
653 | goto status_stage; | ||
654 | } | ||
655 | |||
656 | urb->actual_length = 0; | ||
657 | |||
658 | tmp = head->next; | ||
659 | td = list_entry(tmp, struct uhci_td, list); | ||
660 | |||
661 | /* The first TD is the SETUP stage, check the status, but skip */ | ||
662 | /* the count */ | ||
663 | status = uhci_status_bits(td_status(td)); | ||
664 | if (status & TD_CTRL_ACTIVE) | ||
665 | return -EINPROGRESS; | ||
666 | |||
667 | if (status) | ||
668 | goto td_error; | ||
669 | |||
670 | /* The rest of the TDs (but the last) are data */ | ||
671 | tmp = tmp->next; | ||
672 | while (tmp != head && tmp->next != head) { | ||
673 | unsigned int ctrlstat; | ||
674 | |||
675 | td = list_entry(tmp, struct uhci_td, list); | ||
676 | tmp = tmp->next; | ||
677 | |||
678 | ctrlstat = td_status(td); | ||
679 | status = uhci_status_bits(ctrlstat); | ||
680 | if (status & TD_CTRL_ACTIVE) | ||
681 | return -EINPROGRESS; | ||
682 | |||
683 | urb->actual_length += uhci_actual_length(ctrlstat); | ||
684 | |||
685 | if (status) | ||
686 | goto td_error; | ||
687 | |||
688 | /* Check to see if we received a short packet */ | ||
689 | if (uhci_actual_length(ctrlstat) < | ||
690 | uhci_expected_length(td_token(td))) { | ||
691 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
692 | ret = -EREMOTEIO; | ||
693 | goto err; | ||
694 | } | ||
695 | |||
696 | return usb_control_retrigger_status(uhci, urb); | ||
697 | } | ||
698 | } | ||
699 | |||
700 | status_stage: | ||
701 | td = list_entry(tmp, struct uhci_td, list); | ||
702 | |||
703 | /* Control status stage */ | ||
704 | status = td_status(td); | ||
705 | |||
706 | #ifdef I_HAVE_BUGGY_APC_BACKUPS | ||
707 | /* APC BackUPS Pro kludge */ | ||
708 | /* It tries to send all of the descriptor instead of the amount */ | ||
709 | /* we requested */ | ||
710 | if (status & TD_CTRL_IOC && /* IOC is masked out by uhci_status_bits */ | ||
711 | status & TD_CTRL_ACTIVE && | ||
712 | status & TD_CTRL_NAK) | ||
713 | return 0; | ||
714 | #endif | ||
715 | |||
716 | status = uhci_status_bits(status); | ||
717 | if (status & TD_CTRL_ACTIVE) | ||
718 | return -EINPROGRESS; | ||
719 | |||
720 | if (status) | ||
721 | goto td_error; | ||
722 | |||
723 | return 0; | ||
724 | |||
725 | td_error: | ||
726 | ret = uhci_map_status(status, uhci_packetout(td_token(td))); | ||
727 | |||
728 | err: | ||
729 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
730 | /* Some debugging code */ | ||
731 | dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n", | ||
732 | __FUNCTION__, status); | ||
733 | |||
734 | if (errbuf) { | ||
735 | /* Print the chain for debugging purposes */ | ||
736 | uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); | ||
737 | lprintk(errbuf); | ||
738 | } | ||
739 | } | ||
740 | |||
741 | /* Note that the queue has stopped */ | ||
742 | urbp->qh->element = UHCI_PTR_TERM; | ||
743 | urbp->qh->is_stopped = 1; | ||
744 | return ret; | ||
745 | } | ||
746 | |||
747 | /* | ||
748 | * Common submit for bulk and interrupt | 692 | * Common submit for bulk and interrupt |
749 | */ | 693 | */ |
750 | static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | 694 | static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, |
@@ -756,6 +700,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
756 | int len = urb->transfer_buffer_length; | 700 | int len = urb->transfer_buffer_length; |
757 | dma_addr_t data = urb->transfer_dma; | 701 | dma_addr_t data = urb->transfer_dma; |
758 | __le32 *plink; | 702 | __le32 *plink; |
703 | struct urb_priv *urbp = urb->hcpriv; | ||
759 | unsigned int toggle; | 704 | unsigned int toggle; |
760 | 705 | ||
761 | if (len < 0) | 706 | if (len < 0) |
@@ -793,7 +738,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
793 | goto nomem; | 738 | goto nomem; |
794 | *plink = cpu_to_le32(td->dma_handle); | 739 | *plink = cpu_to_le32(td->dma_handle); |
795 | } | 740 | } |
796 | uhci_add_td_to_urb(urb, td); | 741 | uhci_add_td_to_urbp(td, urbp); |
797 | uhci_fill_td(td, status, | 742 | uhci_fill_td(td, status, |
798 | destination | uhci_explen(pktsze) | | 743 | destination | uhci_explen(pktsze) | |
799 | (toggle << TD_TOKEN_TOGGLE_SHIFT), | 744 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
@@ -821,7 +766,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
821 | goto nomem; | 766 | goto nomem; |
822 | *plink = cpu_to_le32(td->dma_handle); | 767 | *plink = cpu_to_le32(td->dma_handle); |
823 | 768 | ||
824 | uhci_add_td_to_urb(urb, td); | 769 | uhci_add_td_to_urbp(td, urbp); |
825 | uhci_fill_td(td, status, | 770 | uhci_fill_td(td, status, |
826 | destination | uhci_explen(0) | | 771 | destination | uhci_explen(0) | |
827 | (toggle << TD_TOKEN_TOGGLE_SHIFT), | 772 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
@@ -851,6 +796,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
851 | wmb(); | 796 | wmb(); |
852 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); | 797 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); |
853 | qh->dummy_td = td; | 798 | qh->dummy_td = td; |
799 | qh->period = urb->interval; | ||
854 | 800 | ||
855 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | 801 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
856 | usb_pipeout(urb->pipe), toggle); | 802 | usb_pipeout(urb->pipe), toggle); |
@@ -858,90 +804,10 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
858 | 804 | ||
859 | nomem: | 805 | nomem: |
860 | /* Remove the dummy TD from the td_list so it doesn't get freed */ | 806 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
861 | uhci_remove_td_from_urb(qh->dummy_td); | 807 | uhci_remove_td_from_urbp(qh->dummy_td); |
862 | return -ENOMEM; | 808 | return -ENOMEM; |
863 | } | 809 | } |
864 | 810 | ||
865 | /* | ||
866 | * Common result for bulk and interrupt | ||
867 | */ | ||
868 | static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | ||
869 | { | ||
870 | struct urb_priv *urbp = urb->hcpriv; | ||
871 | struct uhci_td *td; | ||
872 | unsigned int status = 0; | ||
873 | int ret = 0; | ||
874 | |||
875 | urb->actual_length = 0; | ||
876 | |||
877 | list_for_each_entry(td, &urbp->td_list, list) { | ||
878 | unsigned int ctrlstat = td_status(td); | ||
879 | |||
880 | status = uhci_status_bits(ctrlstat); | ||
881 | if (status & TD_CTRL_ACTIVE) | ||
882 | return -EINPROGRESS; | ||
883 | |||
884 | urb->actual_length += uhci_actual_length(ctrlstat); | ||
885 | |||
886 | if (status) | ||
887 | goto td_error; | ||
888 | |||
889 | if (uhci_actual_length(ctrlstat) < | ||
890 | uhci_expected_length(td_token(td))) { | ||
891 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
892 | ret = -EREMOTEIO; | ||
893 | goto err; | ||
894 | } | ||
895 | |||
896 | /* | ||
897 | * This URB stopped short of its end. We have to | ||
898 | * fix up the toggles of the following URBs on the | ||
899 | * queue and restart the queue. | ||
900 | * | ||
901 | * Do this only the first time we encounter the | ||
902 | * short URB. | ||
903 | */ | ||
904 | if (!urbp->short_transfer) { | ||
905 | urbp->short_transfer = 1; | ||
906 | urbp->qh->initial_toggle = | ||
907 | uhci_toggle(td_token(td)) ^ 1; | ||
908 | uhci_fixup_toggles(urbp->qh, 1); | ||
909 | |||
910 | td = list_entry(urbp->td_list.prev, | ||
911 | struct uhci_td, list); | ||
912 | urbp->qh->element = td->link; | ||
913 | } | ||
914 | break; | ||
915 | } | ||
916 | } | ||
917 | |||
918 | return 0; | ||
919 | |||
920 | td_error: | ||
921 | ret = uhci_map_status(status, uhci_packetout(td_token(td))); | ||
922 | |||
923 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
924 | /* Some debugging code */ | ||
925 | dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n", | ||
926 | __FUNCTION__, status); | ||
927 | |||
928 | if (debug > 1 && errbuf) { | ||
929 | /* Print the chain for debugging purposes */ | ||
930 | uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); | ||
931 | lprintk(errbuf); | ||
932 | } | ||
933 | } | ||
934 | err: | ||
935 | |||
936 | /* Note that the queue has stopped and save the next toggle value */ | ||
937 | urbp->qh->element = UHCI_PTR_TERM; | ||
938 | urbp->qh->is_stopped = 1; | ||
939 | urbp->qh->needs_fixup = 1; | ||
940 | urbp->qh->initial_toggle = uhci_toggle(td_token(td)) ^ | ||
941 | (ret == -EREMOTEIO); | ||
942 | return ret; | ||
943 | } | ||
944 | |||
945 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | 811 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, |
946 | struct uhci_qh *qh) | 812 | struct uhci_qh *qh) |
947 | { | 813 | { |
@@ -954,22 +820,163 @@ static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | |||
954 | qh->skel = uhci->skel_bulk_qh; | 820 | qh->skel = uhci->skel_bulk_qh; |
955 | ret = uhci_submit_common(uhci, urb, qh); | 821 | ret = uhci_submit_common(uhci, urb, qh); |
956 | if (ret == 0) | 822 | if (ret == 0) |
957 | uhci_inc_fsbr(uhci, urb); | 823 | uhci_add_fsbr(uhci, urb); |
958 | return ret; | 824 | return ret; |
959 | } | 825 | } |
960 | 826 | ||
961 | static inline int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, | 827 | static int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, |
962 | struct uhci_qh *qh) | 828 | struct uhci_qh *qh) |
963 | { | 829 | { |
830 | int exponent; | ||
831 | |||
964 | /* USB 1.1 interrupt transfers only involve one packet per interval. | 832 | /* USB 1.1 interrupt transfers only involve one packet per interval. |
965 | * Drivers can submit URBs of any length, but longer ones will need | 833 | * Drivers can submit URBs of any length, but longer ones will need |
966 | * multiple intervals to complete. | 834 | * multiple intervals to complete. |
967 | */ | 835 | */ |
968 | qh->skel = uhci->skelqh[__interval_to_skel(urb->interval)]; | 836 | |
837 | /* Figure out which power-of-two queue to use */ | ||
838 | for (exponent = 7; exponent >= 0; --exponent) { | ||
839 | if ((1 << exponent) <= urb->interval) | ||
840 | break; | ||
841 | } | ||
842 | if (exponent < 0) | ||
843 | return -EINVAL; | ||
844 | urb->interval = 1 << exponent; | ||
845 | |||
846 | if (qh->period == 0) | ||
847 | qh->skel = uhci->skelqh[UHCI_SKEL_INDEX(exponent)]; | ||
848 | else if (qh->period != urb->interval) | ||
849 | return -EINVAL; /* Can't change the period */ | ||
850 | |||
969 | return uhci_submit_common(uhci, urb, qh); | 851 | return uhci_submit_common(uhci, urb, qh); |
970 | } | 852 | } |
971 | 853 | ||
972 | /* | 854 | /* |
855 | * Fix up the data structures following a short transfer | ||
856 | */ | ||
857 | static int uhci_fixup_short_transfer(struct uhci_hcd *uhci, | ||
858 | struct uhci_qh *qh, struct urb_priv *urbp) | ||
859 | { | ||
860 | struct uhci_td *td; | ||
861 | struct list_head *tmp; | ||
862 | int ret; | ||
863 | |||
864 | td = list_entry(urbp->td_list.prev, struct uhci_td, list); | ||
865 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) { | ||
866 | |||
867 | /* When a control transfer is short, we have to restart | ||
868 | * the queue at the status stage transaction, which is | ||
869 | * the last TD. */ | ||
870 | WARN_ON(list_empty(&urbp->td_list)); | ||
871 | qh->element = cpu_to_le32(td->dma_handle); | ||
872 | tmp = td->list.prev; | ||
873 | ret = -EINPROGRESS; | ||
874 | |||
875 | } else { | ||
876 | |||
877 | /* When a bulk/interrupt transfer is short, we have to | ||
878 | * fix up the toggles of the following URBs on the queue | ||
879 | * before restarting the queue at the next URB. */ | ||
880 | qh->initial_toggle = uhci_toggle(td_token(qh->post_td)) ^ 1; | ||
881 | uhci_fixup_toggles(qh, 1); | ||
882 | |||
883 | if (list_empty(&urbp->td_list)) | ||
884 | td = qh->post_td; | ||
885 | qh->element = td->link; | ||
886 | tmp = urbp->td_list.prev; | ||
887 | ret = 0; | ||
888 | } | ||
889 | |||
890 | /* Remove all the TDs we skipped over, from tmp back to the start */ | ||
891 | while (tmp != &urbp->td_list) { | ||
892 | td = list_entry(tmp, struct uhci_td, list); | ||
893 | tmp = tmp->prev; | ||
894 | |||
895 | uhci_remove_td_from_urbp(td); | ||
896 | uhci_free_td(uhci, td); | ||
897 | } | ||
898 | return ret; | ||
899 | } | ||
900 | |||
901 | /* | ||
902 | * Common result for control, bulk, and interrupt | ||
903 | */ | ||
904 | static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | ||
905 | { | ||
906 | struct urb_priv *urbp = urb->hcpriv; | ||
907 | struct uhci_qh *qh = urbp->qh; | ||
908 | struct uhci_td *td, *tmp; | ||
909 | unsigned status; | ||
910 | int ret = 0; | ||
911 | |||
912 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { | ||
913 | unsigned int ctrlstat; | ||
914 | int len; | ||
915 | |||
916 | ctrlstat = td_status(td); | ||
917 | status = uhci_status_bits(ctrlstat); | ||
918 | if (status & TD_CTRL_ACTIVE) | ||
919 | return -EINPROGRESS; | ||
920 | |||
921 | len = uhci_actual_length(ctrlstat); | ||
922 | urb->actual_length += len; | ||
923 | |||
924 | if (status) { | ||
925 | ret = uhci_map_status(status, | ||
926 | uhci_packetout(td_token(td))); | ||
927 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
928 | /* Some debugging code */ | ||
929 | dev_dbg(&urb->dev->dev, | ||
930 | "%s: failed with status %x\n", | ||
931 | __FUNCTION__, status); | ||
932 | |||
933 | if (debug > 1 && errbuf) { | ||
934 | /* Print the chain for debugging */ | ||
935 | uhci_show_qh(urbp->qh, errbuf, | ||
936 | ERRBUF_LEN, 0); | ||
937 | lprintk(errbuf); | ||
938 | } | ||
939 | } | ||
940 | |||
941 | } else if (len < uhci_expected_length(td_token(td))) { | ||
942 | |||
943 | /* We received a short packet */ | ||
944 | if (urb->transfer_flags & URB_SHORT_NOT_OK) | ||
945 | ret = -EREMOTEIO; | ||
946 | else if (ctrlstat & TD_CTRL_SPD) | ||
947 | ret = 1; | ||
948 | } | ||
949 | |||
950 | uhci_remove_td_from_urbp(td); | ||
951 | if (qh->post_td) | ||
952 | uhci_free_td(uhci, qh->post_td); | ||
953 | qh->post_td = td; | ||
954 | |||
955 | if (ret != 0) | ||
956 | goto err; | ||
957 | } | ||
958 | return ret; | ||
959 | |||
960 | err: | ||
961 | if (ret < 0) { | ||
962 | /* In case a control transfer gets an error | ||
963 | * during the setup stage */ | ||
964 | urb->actual_length = max(urb->actual_length, 0); | ||
965 | |||
966 | /* Note that the queue has stopped and save | ||
967 | * the next toggle value */ | ||
968 | qh->element = UHCI_PTR_TERM; | ||
969 | qh->is_stopped = 1; | ||
970 | qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL); | ||
971 | qh->initial_toggle = uhci_toggle(td_token(td)) ^ | ||
972 | (ret == -EREMOTEIO); | ||
973 | |||
974 | } else /* Short packet received */ | ||
975 | ret = uhci_fixup_short_transfer(uhci, qh, urbp); | ||
976 | return ret; | ||
977 | } | ||
978 | |||
979 | /* | ||
973 | * Isochronous transfers | 980 | * Isochronous transfers |
974 | */ | 981 | */ |
975 | static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | 982 | static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, |
@@ -980,38 +987,57 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
980 | unsigned long destination, status; | 987 | unsigned long destination, status; |
981 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 988 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
982 | 989 | ||
983 | if (urb->number_of_packets > 900) /* 900? Why? */ | 990 | /* Values must not be too big (could overflow below) */ |
991 | if (urb->interval >= UHCI_NUMFRAMES || | ||
992 | urb->number_of_packets >= UHCI_NUMFRAMES) | ||
984 | return -EFBIG; | 993 | return -EFBIG; |
985 | 994 | ||
986 | status = TD_CTRL_ACTIVE | TD_CTRL_IOS; | 995 | /* Check the period and figure out the starting frame number */ |
987 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); | 996 | if (qh->period == 0) { |
988 | 997 | if (urb->transfer_flags & URB_ISO_ASAP) { | |
989 | /* Figure out the starting frame number */ | ||
990 | if (urb->transfer_flags & URB_ISO_ASAP) { | ||
991 | if (list_empty(&qh->queue)) { | ||
992 | uhci_get_current_frame_number(uhci); | 998 | uhci_get_current_frame_number(uhci); |
993 | urb->start_frame = (uhci->frame_number + 10); | 999 | urb->start_frame = uhci->frame_number + 10; |
1000 | } else { | ||
1001 | i = urb->start_frame - uhci->last_iso_frame; | ||
1002 | if (i <= 0 || i >= UHCI_NUMFRAMES) | ||
1003 | return -EINVAL; | ||
1004 | } | ||
1005 | } else if (qh->period != urb->interval) { | ||
1006 | return -EINVAL; /* Can't change the period */ | ||
994 | 1007 | ||
995 | } else { /* Go right after the last one */ | 1008 | } else { /* Pick up where the last URB leaves off */ |
996 | struct urb *last_urb; | 1009 | if (list_empty(&qh->queue)) { |
1010 | frame = qh->iso_frame; | ||
1011 | } else { | ||
1012 | struct urb *lurb; | ||
997 | 1013 | ||
998 | last_urb = list_entry(qh->queue.prev, | 1014 | lurb = list_entry(qh->queue.prev, |
999 | struct urb_priv, node)->urb; | 1015 | struct urb_priv, node)->urb; |
1000 | urb->start_frame = (last_urb->start_frame + | 1016 | frame = lurb->start_frame + |
1001 | last_urb->number_of_packets * | 1017 | lurb->number_of_packets * |
1002 | last_urb->interval); | 1018 | lurb->interval; |
1003 | } | 1019 | } |
1004 | } else { | 1020 | if (urb->transfer_flags & URB_ISO_ASAP) |
1005 | /* FIXME: Sanity check */ | 1021 | urb->start_frame = frame; |
1022 | else if (urb->start_frame != frame) | ||
1023 | return -EINVAL; | ||
1006 | } | 1024 | } |
1007 | urb->start_frame &= (UHCI_NUMFRAMES - 1); | 1025 | |
1026 | /* Make sure we won't have to go too far into the future */ | ||
1027 | if (uhci_frame_before_eq(uhci->last_iso_frame + UHCI_NUMFRAMES, | ||
1028 | urb->start_frame + urb->number_of_packets * | ||
1029 | urb->interval)) | ||
1030 | return -EFBIG; | ||
1031 | |||
1032 | status = TD_CTRL_ACTIVE | TD_CTRL_IOS; | ||
1033 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); | ||
1008 | 1034 | ||
1009 | for (i = 0; i < urb->number_of_packets; i++) { | 1035 | for (i = 0; i < urb->number_of_packets; i++) { |
1010 | td = uhci_alloc_td(uhci); | 1036 | td = uhci_alloc_td(uhci); |
1011 | if (!td) | 1037 | if (!td) |
1012 | return -ENOMEM; | 1038 | return -ENOMEM; |
1013 | 1039 | ||
1014 | uhci_add_td_to_urb(urb, td); | 1040 | uhci_add_td_to_urbp(td, urbp); |
1015 | uhci_fill_td(td, status, destination | | 1041 | uhci_fill_td(td, status, destination | |
1016 | uhci_explen(urb->iso_frame_desc[i].length), | 1042 | uhci_explen(urb->iso_frame_desc[i].length), |
1017 | urb->transfer_dma + | 1043 | urb->transfer_dma + |
@@ -1022,12 +1048,19 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
1022 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); | 1048 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); |
1023 | 1049 | ||
1024 | qh->skel = uhci->skel_iso_qh; | 1050 | qh->skel = uhci->skel_iso_qh; |
1051 | qh->period = urb->interval; | ||
1025 | 1052 | ||
1026 | /* Add the TDs to the frame list */ | 1053 | /* Add the TDs to the frame list */ |
1027 | frame = urb->start_frame; | 1054 | frame = urb->start_frame; |
1028 | list_for_each_entry(td, &urbp->td_list, list) { | 1055 | list_for_each_entry(td, &urbp->td_list, list) { |
1029 | uhci_insert_td_in_frame_list(uhci, td, frame); | 1056 | uhci_insert_td_in_frame_list(uhci, td, frame); |
1030 | frame += urb->interval; | 1057 | frame += qh->period; |
1058 | } | ||
1059 | |||
1060 | if (list_empty(&qh->queue)) { | ||
1061 | qh->iso_packet_desc = &urb->iso_frame_desc[0]; | ||
1062 | qh->iso_frame = urb->start_frame; | ||
1063 | qh->iso_status = 0; | ||
1031 | } | 1064 | } |
1032 | 1065 | ||
1033 | return 0; | 1066 | return 0; |
@@ -1035,37 +1068,44 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
1035 | 1068 | ||
1036 | static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) | 1069 | static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) |
1037 | { | 1070 | { |
1038 | struct uhci_td *td; | 1071 | struct uhci_td *td, *tmp; |
1039 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | 1072 | struct urb_priv *urbp = urb->hcpriv; |
1040 | int status; | 1073 | struct uhci_qh *qh = urbp->qh; |
1041 | int i, ret = 0; | ||
1042 | |||
1043 | urb->actual_length = urb->error_count = 0; | ||
1044 | 1074 | ||
1045 | i = 0; | 1075 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
1046 | list_for_each_entry(td, &urbp->td_list, list) { | 1076 | unsigned int ctrlstat; |
1077 | int status; | ||
1047 | int actlength; | 1078 | int actlength; |
1048 | unsigned int ctrlstat = td_status(td); | ||
1049 | 1079 | ||
1050 | if (ctrlstat & TD_CTRL_ACTIVE) | 1080 | if (uhci_frame_before_eq(uhci->cur_iso_frame, qh->iso_frame)) |
1051 | return -EINPROGRESS; | 1081 | return -EINPROGRESS; |
1052 | 1082 | ||
1053 | actlength = uhci_actual_length(ctrlstat); | 1083 | uhci_remove_tds_from_frame(uhci, qh->iso_frame); |
1054 | urb->iso_frame_desc[i].actual_length = actlength; | 1084 | |
1055 | urb->actual_length += actlength; | 1085 | ctrlstat = td_status(td); |
1086 | if (ctrlstat & TD_CTRL_ACTIVE) { | ||
1087 | status = -EXDEV; /* TD was added too late? */ | ||
1088 | } else { | ||
1089 | status = uhci_map_status(uhci_status_bits(ctrlstat), | ||
1090 | usb_pipeout(urb->pipe)); | ||
1091 | actlength = uhci_actual_length(ctrlstat); | ||
1092 | |||
1093 | urb->actual_length += actlength; | ||
1094 | qh->iso_packet_desc->actual_length = actlength; | ||
1095 | qh->iso_packet_desc->status = status; | ||
1096 | } | ||
1056 | 1097 | ||
1057 | status = uhci_map_status(uhci_status_bits(ctrlstat), | ||
1058 | usb_pipeout(urb->pipe)); | ||
1059 | urb->iso_frame_desc[i].status = status; | ||
1060 | if (status) { | 1098 | if (status) { |
1061 | urb->error_count++; | 1099 | urb->error_count++; |
1062 | ret = status; | 1100 | qh->iso_status = status; |
1063 | } | 1101 | } |
1064 | 1102 | ||
1065 | i++; | 1103 | uhci_remove_td_from_urbp(td); |
1104 | uhci_free_td(uhci, td); | ||
1105 | qh->iso_frame += qh->period; | ||
1106 | ++qh->iso_packet_desc; | ||
1066 | } | 1107 | } |
1067 | 1108 | return qh->iso_status; | |
1068 | return ret; | ||
1069 | } | 1109 | } |
1070 | 1110 | ||
1071 | static int uhci_urb_enqueue(struct usb_hcd *hcd, | 1111 | static int uhci_urb_enqueue(struct usb_hcd *hcd, |
@@ -1099,14 +1139,14 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
1099 | } | 1139 | } |
1100 | urbp->qh = qh; | 1140 | urbp->qh = qh; |
1101 | 1141 | ||
1102 | switch (usb_pipetype(urb->pipe)) { | 1142 | switch (qh->type) { |
1103 | case PIPE_CONTROL: | 1143 | case USB_ENDPOINT_XFER_CONTROL: |
1104 | ret = uhci_submit_control(uhci, urb, qh); | 1144 | ret = uhci_submit_control(uhci, urb, qh); |
1105 | break; | 1145 | break; |
1106 | case PIPE_BULK: | 1146 | case USB_ENDPOINT_XFER_BULK: |
1107 | ret = uhci_submit_bulk(uhci, urb, qh); | 1147 | ret = uhci_submit_bulk(uhci, urb, qh); |
1108 | break; | 1148 | break; |
1109 | case PIPE_INTERRUPT: | 1149 | case USB_ENDPOINT_XFER_INT: |
1110 | if (list_empty(&qh->queue)) { | 1150 | if (list_empty(&qh->queue)) { |
1111 | bustime = usb_check_bandwidth(urb->dev, urb); | 1151 | bustime = usb_check_bandwidth(urb->dev, urb); |
1112 | if (bustime < 0) | 1152 | if (bustime < 0) |
@@ -1125,7 +1165,8 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
1125 | ret = uhci_submit_interrupt(uhci, urb, qh); | 1165 | ret = uhci_submit_interrupt(uhci, urb, qh); |
1126 | } | 1166 | } |
1127 | break; | 1167 | break; |
1128 | case PIPE_ISOCHRONOUS: | 1168 | case USB_ENDPOINT_XFER_ISOC: |
1169 | urb->error_count = 0; | ||
1129 | bustime = usb_check_bandwidth(urb->dev, urb); | 1170 | bustime = usb_check_bandwidth(urb->dev, urb); |
1130 | if (bustime < 0) { | 1171 | if (bustime < 0) { |
1131 | ret = bustime; | 1172 | ret = bustime; |
@@ -1146,9 +1187,12 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
1146 | 1187 | ||
1147 | /* If the new URB is the first and only one on this QH then either | 1188 | /* If the new URB is the first and only one on this QH then either |
1148 | * the QH is new and idle or else it's unlinked and waiting to | 1189 | * the QH is new and idle or else it's unlinked and waiting to |
1149 | * become idle, so we can activate it right away. */ | 1190 | * become idle, so we can activate it right away. But only if the |
1150 | if (qh->queue.next == &urbp->node) | 1191 | * queue isn't stopped. */ |
1192 | if (qh->queue.next == &urbp->node && !qh->is_stopped) { | ||
1151 | uhci_activate_qh(uhci, qh); | 1193 | uhci_activate_qh(uhci, qh); |
1194 | uhci_urbp_wants_fsbr(uhci, urbp); | ||
1195 | } | ||
1152 | goto done; | 1196 | goto done; |
1153 | 1197 | ||
1154 | err_submit_failed: | 1198 | err_submit_failed: |
@@ -1168,16 +1212,26 @@ static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) | |||
1168 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 1212 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
1169 | unsigned long flags; | 1213 | unsigned long flags; |
1170 | struct urb_priv *urbp; | 1214 | struct urb_priv *urbp; |
1215 | struct uhci_qh *qh; | ||
1171 | 1216 | ||
1172 | spin_lock_irqsave(&uhci->lock, flags); | 1217 | spin_lock_irqsave(&uhci->lock, flags); |
1173 | urbp = urb->hcpriv; | 1218 | urbp = urb->hcpriv; |
1174 | if (!urbp) /* URB was never linked! */ | 1219 | if (!urbp) /* URB was never linked! */ |
1175 | goto done; | 1220 | goto done; |
1221 | qh = urbp->qh; | ||
1176 | 1222 | ||
1177 | /* Remove Isochronous TDs from the frame list ASAP */ | 1223 | /* Remove Isochronous TDs from the frame list ASAP */ |
1178 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | 1224 | if (qh->type == USB_ENDPOINT_XFER_ISOC) { |
1179 | uhci_unlink_isochronous_tds(uhci, urb); | 1225 | uhci_unlink_isochronous_tds(uhci, urb); |
1180 | uhci_unlink_qh(uhci, urbp->qh); | 1226 | mb(); |
1227 | |||
1228 | /* If the URB has already started, update the QH unlink time */ | ||
1229 | uhci_get_current_frame_number(uhci); | ||
1230 | if (uhci_frame_before_eq(urb->start_frame, uhci->frame_number)) | ||
1231 | qh->unlink_frame = uhci->frame_number; | ||
1232 | } | ||
1233 | |||
1234 | uhci_unlink_qh(uhci, qh); | ||
1181 | 1235 | ||
1182 | done: | 1236 | done: |
1183 | spin_unlock_irqrestore(&uhci->lock, flags); | 1237 | spin_unlock_irqrestore(&uhci->lock, flags); |
@@ -1194,22 +1248,17 @@ __acquires(uhci->lock) | |||
1194 | { | 1248 | { |
1195 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 1249 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
1196 | 1250 | ||
1197 | /* Isochronous TDs get unlinked directly from the frame list */ | 1251 | /* When giving back the first URB in an Isochronous queue, |
1198 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | 1252 | * reinitialize the QH's iso-related members for the next URB. */ |
1199 | uhci_unlink_isochronous_tds(uhci, urb); | 1253 | if (qh->type == USB_ENDPOINT_XFER_ISOC && |
1200 | 1254 | urbp->node.prev == &qh->queue && | |
1201 | /* If the URB isn't first on its queue, adjust the link pointer | 1255 | urbp->node.next != &qh->queue) { |
1202 | * of the last TD in the previous URB. */ | 1256 | struct urb *nurb = list_entry(urbp->node.next, |
1203 | else if (qh->queue.next != &urbp->node) { | 1257 | struct urb_priv, node)->urb; |
1204 | struct urb_priv *purbp; | 1258 | |
1205 | struct uhci_td *ptd, *ltd; | 1259 | qh->iso_packet_desc = &nurb->iso_frame_desc[0]; |
1206 | 1260 | qh->iso_frame = nurb->start_frame; | |
1207 | purbp = list_entry(urbp->node.prev, struct urb_priv, node); | 1261 | qh->iso_status = 0; |
1208 | ptd = list_entry(purbp->td_list.prev, struct uhci_td, | ||
1209 | list); | ||
1210 | ltd = list_entry(urbp->td_list.prev, struct uhci_td, | ||
1211 | list); | ||
1212 | ptd->link = ltd->link; | ||
1213 | } | 1262 | } |
1214 | 1263 | ||
1215 | /* Take the URB off the QH's queue. If the queue is now empty, | 1264 | /* Take the URB off the QH's queue. If the queue is now empty, |
@@ -1221,16 +1270,15 @@ __acquires(uhci->lock) | |||
1221 | qh->needs_fixup = 0; | 1270 | qh->needs_fixup = 0; |
1222 | } | 1271 | } |
1223 | 1272 | ||
1224 | uhci_dec_fsbr(uhci, urb); /* Safe since it checks */ | ||
1225 | uhci_free_urb_priv(uhci, urbp); | 1273 | uhci_free_urb_priv(uhci, urbp); |
1226 | 1274 | ||
1227 | switch (usb_pipetype(urb->pipe)) { | 1275 | switch (qh->type) { |
1228 | case PIPE_ISOCHRONOUS: | 1276 | case USB_ENDPOINT_XFER_ISOC: |
1229 | /* Release bandwidth for Interrupt or Isoc. transfers */ | 1277 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
1230 | if (urb->bandwidth) | 1278 | if (urb->bandwidth) |
1231 | usb_release_bandwidth(urb->dev, urb, 1); | 1279 | usb_release_bandwidth(urb->dev, urb, 1); |
1232 | break; | 1280 | break; |
1233 | case PIPE_INTERRUPT: | 1281 | case USB_ENDPOINT_XFER_INT: |
1234 | /* Release bandwidth for Interrupt or Isoc. transfers */ | 1282 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
1235 | /* Make sure we don't release if we have a queued URB */ | 1283 | /* Make sure we don't release if we have a queued URB */ |
1236 | if (list_empty(&qh->queue) && urb->bandwidth) | 1284 | if (list_empty(&qh->queue) && urb->bandwidth) |
@@ -1252,6 +1300,7 @@ __acquires(uhci->lock) | |||
1252 | uhci_unlink_qh(uhci, qh); | 1300 | uhci_unlink_qh(uhci, qh); |
1253 | 1301 | ||
1254 | /* Bandwidth stuff not yet implemented */ | 1302 | /* Bandwidth stuff not yet implemented */ |
1303 | qh->period = 0; | ||
1255 | } | 1304 | } |
1256 | } | 1305 | } |
1257 | 1306 | ||
@@ -1273,17 +1322,10 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
1273 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | 1322 | urbp = list_entry(qh->queue.next, struct urb_priv, node); |
1274 | urb = urbp->urb; | 1323 | urb = urbp->urb; |
1275 | 1324 | ||
1276 | switch (usb_pipetype(urb->pipe)) { | 1325 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
1277 | case PIPE_CONTROL: | ||
1278 | status = uhci_result_control(uhci, urb); | ||
1279 | break; | ||
1280 | case PIPE_ISOCHRONOUS: | ||
1281 | status = uhci_result_isochronous(uhci, urb); | 1326 | status = uhci_result_isochronous(uhci, urb); |
1282 | break; | 1327 | else |
1283 | default: /* PIPE_BULK or PIPE_INTERRUPT */ | ||
1284 | status = uhci_result_common(uhci, urb); | 1328 | status = uhci_result_common(uhci, urb); |
1285 | break; | ||
1286 | } | ||
1287 | if (status == -EINPROGRESS) | 1329 | if (status == -EINPROGRESS) |
1288 | break; | 1330 | break; |
1289 | 1331 | ||
@@ -1291,31 +1333,43 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
1291 | if (urb->status == -EINPROGRESS) /* Not dequeued */ | 1333 | if (urb->status == -EINPROGRESS) /* Not dequeued */ |
1292 | urb->status = status; | 1334 | urb->status = status; |
1293 | else | 1335 | else |
1294 | status = -ECONNRESET; | 1336 | status = ECONNRESET; /* Not -ECONNRESET */ |
1295 | spin_unlock(&urb->lock); | 1337 | spin_unlock(&urb->lock); |
1296 | 1338 | ||
1297 | /* Dequeued but completed URBs can't be given back unless | 1339 | /* Dequeued but completed URBs can't be given back unless |
1298 | * the QH is stopped or has finished unlinking. */ | 1340 | * the QH is stopped or has finished unlinking. */ |
1299 | if (status == -ECONNRESET && | 1341 | if (status == ECONNRESET) { |
1300 | !(qh->is_stopped || QH_FINISHED_UNLINKING(qh))) | 1342 | if (QH_FINISHED_UNLINKING(qh)) |
1301 | return; | 1343 | qh->is_stopped = 1; |
1344 | else if (!qh->is_stopped) | ||
1345 | return; | ||
1346 | } | ||
1302 | 1347 | ||
1303 | uhci_giveback_urb(uhci, qh, urb, regs); | 1348 | uhci_giveback_urb(uhci, qh, urb, regs); |
1304 | if (qh->is_stopped) | 1349 | if (status < 0) |
1305 | break; | 1350 | break; |
1306 | } | 1351 | } |
1307 | 1352 | ||
1308 | /* If the QH is neither stopped nor finished unlinking (normal case), | 1353 | /* If the QH is neither stopped nor finished unlinking (normal case), |
1309 | * our work here is done. */ | 1354 | * our work here is done. */ |
1310 | restart: | 1355 | if (QH_FINISHED_UNLINKING(qh)) |
1311 | if (!(qh->is_stopped || QH_FINISHED_UNLINKING(qh))) | 1356 | qh->is_stopped = 1; |
1357 | else if (!qh->is_stopped) | ||
1312 | return; | 1358 | return; |
1313 | 1359 | ||
1314 | /* Otherwise give back each of the dequeued URBs */ | 1360 | /* Otherwise give back each of the dequeued URBs */ |
1361 | restart: | ||
1315 | list_for_each_entry(urbp, &qh->queue, node) { | 1362 | list_for_each_entry(urbp, &qh->queue, node) { |
1316 | urb = urbp->urb; | 1363 | urb = urbp->urb; |
1317 | if (urb->status != -EINPROGRESS) { | 1364 | if (urb->status != -EINPROGRESS) { |
1318 | uhci_save_toggle(qh, urb); | 1365 | |
1366 | /* Fix up the TD links and save the toggles for | ||
1367 | * non-Isochronous queues. For Isochronous queues, | ||
1368 | * test for too-recent dequeues. */ | ||
1369 | if (!uhci_cleanup_queue(uhci, qh, urb)) { | ||
1370 | qh->is_stopped = 0; | ||
1371 | return; | ||
1372 | } | ||
1319 | uhci_giveback_urb(uhci, qh, urb, regs); | 1373 | uhci_giveback_urb(uhci, qh, urb, regs); |
1320 | goto restart; | 1374 | goto restart; |
1321 | } | 1375 | } |
@@ -1327,6 +1381,18 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
1327 | if (!list_empty(&qh->queue)) { | 1381 | if (!list_empty(&qh->queue)) { |
1328 | if (qh->needs_fixup) | 1382 | if (qh->needs_fixup) |
1329 | uhci_fixup_toggles(qh, 0); | 1383 | uhci_fixup_toggles(qh, 0); |
1384 | |||
1385 | /* If the first URB on the queue wants FSBR but its time | ||
1386 | * limit has expired, set the next TD to interrupt on | ||
1387 | * completion before reactivating the QH. */ | ||
1388 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | ||
1389 | if (urbp->fsbr && qh->wait_expired) { | ||
1390 | struct uhci_td *td = list_entry(urbp->td_list.next, | ||
1391 | struct uhci_td, list); | ||
1392 | |||
1393 | td->status |= __cpu_to_le32(TD_CTRL_IOC); | ||
1394 | } | ||
1395 | |||
1330 | uhci_activate_qh(uhci, qh); | 1396 | uhci_activate_qh(uhci, qh); |
1331 | } | 1397 | } |
1332 | 1398 | ||
@@ -1336,15 +1402,84 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
1336 | uhci_make_qh_idle(uhci, qh); | 1402 | uhci_make_qh_idle(uhci, qh); |
1337 | } | 1403 | } |
1338 | 1404 | ||
1339 | static void uhci_free_pending_tds(struct uhci_hcd *uhci) | 1405 | /* |
1406 | * Check for queues that have made some forward progress. | ||
1407 | * Returns 0 if the queue is not Isochronous, is ACTIVE, and | ||
1408 | * has not advanced since last examined; 1 otherwise. | ||
1409 | * | ||
1410 | * Early Intel controllers have a bug which causes qh->element sometimes | ||
1411 | * not to advance when a TD completes successfully. The queue remains | ||
1412 | * stuck on the inactive completed TD. We detect such cases and advance | ||
1413 | * the element pointer by hand. | ||
1414 | */ | ||
1415 | static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
1340 | { | 1416 | { |
1341 | struct uhci_td *td, *tmp; | 1417 | struct urb_priv *urbp = NULL; |
1418 | struct uhci_td *td; | ||
1419 | int ret = 1; | ||
1420 | unsigned status; | ||
1342 | 1421 | ||
1343 | list_for_each_entry_safe(td, tmp, &uhci->td_remove_list, remove_list) { | 1422 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
1344 | list_del_init(&td->remove_list); | 1423 | goto done; |
1345 | 1424 | ||
1346 | uhci_free_td(uhci, td); | 1425 | /* Treat an UNLINKING queue as though it hasn't advanced. |
1426 | * This is okay because reactivation will treat it as though | ||
1427 | * it has advanced, and if it is going to become IDLE then | ||
1428 | * this doesn't matter anyway. Furthermore it's possible | ||
1429 | * for an UNLINKING queue not to have any URBs at all, or | ||
1430 | * for its first URB not to have any TDs (if it was dequeued | ||
1431 | * just as it completed). So it's not easy in any case to | ||
1432 | * test whether such queues have advanced. */ | ||
1433 | if (qh->state != QH_STATE_ACTIVE) { | ||
1434 | urbp = NULL; | ||
1435 | status = 0; | ||
1436 | |||
1437 | } else { | ||
1438 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | ||
1439 | td = list_entry(urbp->td_list.next, struct uhci_td, list); | ||
1440 | status = td_status(td); | ||
1441 | if (!(status & TD_CTRL_ACTIVE)) { | ||
1442 | |||
1443 | /* We're okay, the queue has advanced */ | ||
1444 | qh->wait_expired = 0; | ||
1445 | qh->advance_jiffies = jiffies; | ||
1446 | goto done; | ||
1447 | } | ||
1448 | ret = 0; | ||
1449 | } | ||
1450 | |||
1451 | /* The queue hasn't advanced; check for timeout */ | ||
1452 | if (qh->wait_expired) | ||
1453 | goto done; | ||
1454 | |||
1455 | if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { | ||
1456 | |||
1457 | /* Detect the Intel bug and work around it */ | ||
1458 | if (qh->post_td && qh_element(qh) == | ||
1459 | cpu_to_le32(qh->post_td->dma_handle)) { | ||
1460 | qh->element = qh->post_td->link; | ||
1461 | qh->advance_jiffies = jiffies; | ||
1462 | ret = 1; | ||
1463 | goto done; | ||
1464 | } | ||
1465 | |||
1466 | qh->wait_expired = 1; | ||
1467 | |||
1468 | /* If the current URB wants FSBR, unlink it temporarily | ||
1469 | * so that we can safely set the next TD to interrupt on | ||
1470 | * completion. That way we'll know as soon as the queue | ||
1471 | * starts moving again. */ | ||
1472 | if (urbp && urbp->fsbr && !(status & TD_CTRL_IOC)) | ||
1473 | uhci_unlink_qh(uhci, qh); | ||
1474 | |||
1475 | } else { | ||
1476 | /* Unmoving but not-yet-expired queues keep FSBR alive */ | ||
1477 | if (urbp) | ||
1478 | uhci_urbp_wants_fsbr(uhci, urbp); | ||
1347 | } | 1479 | } |
1480 | |||
1481 | done: | ||
1482 | return ret; | ||
1348 | } | 1483 | } |
1349 | 1484 | ||
1350 | /* | 1485 | /* |
@@ -1361,14 +1496,13 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) | |||
1361 | return; | 1496 | return; |
1362 | } | 1497 | } |
1363 | uhci->scan_in_progress = 1; | 1498 | uhci->scan_in_progress = 1; |
1364 | rescan: | 1499 | rescan: |
1365 | uhci->need_rescan = 0; | 1500 | uhci->need_rescan = 0; |
1501 | uhci->fsbr_is_wanted = 0; | ||
1366 | 1502 | ||
1367 | uhci_clear_next_interrupt(uhci); | 1503 | uhci_clear_next_interrupt(uhci); |
1368 | uhci_get_current_frame_number(uhci); | 1504 | uhci_get_current_frame_number(uhci); |
1369 | 1505 | uhci->cur_iso_frame = uhci->frame_number; | |
1370 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) | ||
1371 | uhci_free_pending_tds(uhci); | ||
1372 | 1506 | ||
1373 | /* Go through all the QH queues and process the URBs in each one */ | 1507 | /* Go through all the QH queues and process the URBs in each one */ |
1374 | for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { | 1508 | for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { |
@@ -1377,33 +1511,30 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) | |||
1377 | while ((qh = uhci->next_qh) != uhci->skelqh[i]) { | 1511 | while ((qh = uhci->next_qh) != uhci->skelqh[i]) { |
1378 | uhci->next_qh = list_entry(qh->node.next, | 1512 | uhci->next_qh = list_entry(qh->node.next, |
1379 | struct uhci_qh, node); | 1513 | struct uhci_qh, node); |
1380 | uhci_scan_qh(uhci, qh, regs); | 1514 | |
1515 | if (uhci_advance_check(uhci, qh)) { | ||
1516 | uhci_scan_qh(uhci, qh, regs); | ||
1517 | if (qh->state == QH_STATE_ACTIVE) { | ||
1518 | uhci_urbp_wants_fsbr(uhci, | ||
1519 | list_entry(qh->queue.next, struct urb_priv, node)); | ||
1520 | } | ||
1521 | } | ||
1381 | } | 1522 | } |
1382 | } | 1523 | } |
1383 | 1524 | ||
1525 | uhci->last_iso_frame = uhci->cur_iso_frame; | ||
1384 | if (uhci->need_rescan) | 1526 | if (uhci->need_rescan) |
1385 | goto rescan; | 1527 | goto rescan; |
1386 | uhci->scan_in_progress = 0; | 1528 | uhci->scan_in_progress = 0; |
1387 | 1529 | ||
1388 | /* If the controller is stopped, we can finish these off right now */ | 1530 | if (uhci->fsbr_is_on && !uhci->fsbr_is_wanted && |
1389 | if (uhci->is_stopped) | 1531 | !uhci->fsbr_expiring) { |
1390 | uhci_free_pending_tds(uhci); | 1532 | uhci->fsbr_expiring = 1; |
1533 | mod_timer(&uhci->fsbr_timer, jiffies + FSBR_OFF_DELAY); | ||
1534 | } | ||
1391 | 1535 | ||
1392 | if (list_empty(&uhci->td_remove_list) && | 1536 | if (list_empty(&uhci->skel_unlink_qh->node)) |
1393 | list_empty(&uhci->skel_unlink_qh->node)) | ||
1394 | uhci_clear_next_interrupt(uhci); | 1537 | uhci_clear_next_interrupt(uhci); |
1395 | else | 1538 | else |
1396 | uhci_set_next_interrupt(uhci); | 1539 | uhci_set_next_interrupt(uhci); |
1397 | } | 1540 | } |
1398 | |||
1399 | static void check_fsbr(struct uhci_hcd *uhci) | ||
1400 | { | ||
1401 | /* For now, don't scan URBs for FSBR timeouts. | ||
1402 | * Add it back in later... */ | ||
1403 | |||
1404 | /* Really disable FSBR */ | ||
1405 | if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { | ||
1406 | uhci->fsbrtimeout = 0; | ||
1407 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | ||
1408 | } | ||
1409 | } | ||