aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/Kconfig13
-rw-r--r--drivers/usb/host/ehci-au1xxx.c6
-rw-r--r--drivers/usb/host/ehci-hcd.c22
-rw-r--r--drivers/usb/host/ehci-pci.c5
-rw-r--r--drivers/usb/host/ehci-ppc-soc.c6
-rw-r--r--drivers/usb/host/ehci-ps3.c2
-rw-r--r--drivers/usb/host/ehci-q.c99
-rw-r--r--drivers/usb/host/ehci-sched.c47
-rw-r--r--drivers/usb/host/isp116x-hcd.c61
-rw-r--r--drivers/usb/host/ohci-dbg.c8
-rw-r--r--drivers/usb/host/ohci-hcd.c234
-rw-r--r--drivers/usb/host/ohci-mem.c1
-rw-r--r--drivers/usb/host/ohci-pci.c22
-rw-r--r--drivers/usb/host/ohci-ppc-of.c5
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c5
-rw-r--r--drivers/usb/host/ohci-q.c187
-rw-r--r--drivers/usb/host/ohci-ssb.c247
-rw-r--r--drivers/usb/host/ohci.h39
-rw-r--r--drivers/usb/host/r8a66597-hcd.c172
-rw-r--r--drivers/usb/host/sl811-hcd.c74
-rw-r--r--drivers/usb/host/u132-hcd.c370
-rw-r--r--drivers/usb/host/uhci-debug.c4
-rw-r--r--drivers/usb/host/uhci-hcd.h16
-rw-r--r--drivers/usb/host/uhci-q.c70
24 files changed, 1088 insertions, 627 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 565d6ef4c4cf..c978d622fa8a 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -154,6 +154,19 @@ config USB_OHCI_HCD_PCI
154 Enables support for PCI-bus plug-in USB controller cards. 154 Enables support for PCI-bus plug-in USB controller cards.
155 If unsure, say Y. 155 If unsure, say Y.
156 156
157config USB_OHCI_HCD_SSB
158 bool "OHCI support for Broadcom SSB OHCI core"
159 depends on USB_OHCI_HCD && SSB && EXPERIMENTAL
160 default n
161 ---help---
162 Support for the Sonics Silicon Backplane (SSB) attached
163 Broadcom USB OHCI core.
164
165 This device is present in some embedded devices with
166 Broadcom based SSB bus.
167
168 If unsure, say N.
169
157config USB_OHCI_BIG_ENDIAN_DESC 170config USB_OHCI_BIG_ENDIAN_DESC
158 bool 171 bool
159 depends on USB_OHCI_HCD 172 depends on USB_OHCI_HCD
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index b1d19268cb23..766ef68a0b43 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -220,10 +220,8 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
220 */ 220 */
221 .hub_status_data = ehci_hub_status_data, 221 .hub_status_data = ehci_hub_status_data,
222 .hub_control = ehci_hub_control, 222 .hub_control = ehci_hub_control,
223#ifdef CONFIG_PM 223 .bus_suspend = ehci_bus_suspend,
224 .hub_suspend = ehci_hub_suspend, 224 .bus_resume = ehci_bus_resume,
225 .hub_resume = ehci_hub_resume,
226#endif
227}; 225};
228 226
229/*-------------------------------------------------------------------------*/ 227/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 35cdba10411b..c1514442883e 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -570,10 +570,18 @@ static int ehci_run (struct usb_hcd *hcd)
570 * are explicitly handed to companion controller(s), so no TT is 570 * are explicitly handed to companion controller(s), so no TT is
571 * involved with the root hub. (Except where one is integrated, 571 * involved with the root hub. (Except where one is integrated,
572 * and there's no companion controller unless maybe for USB OTG.) 572 * and there's no companion controller unless maybe for USB OTG.)
573 *
574 * Turning on the CF flag will transfer ownership of all ports
575 * from the companions to the EHCI controller. If any of the
576 * companions are in the middle of a port reset at the time, it
577 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
578 * guarantees that no resets are in progress.
573 */ 579 */
580 down_write(&ehci_cf_port_reset_rwsem);
574 hcd->state = HC_STATE_RUNNING; 581 hcd->state = HC_STATE_RUNNING;
575 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 582 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
576 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 583 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
584 up_write(&ehci_cf_port_reset_rwsem);
577 585
578 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); 586 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
579 ehci_info (ehci, 587 ehci_info (ehci,
@@ -719,7 +727,6 @@ dead:
719 */ 727 */
720static int ehci_urb_enqueue ( 728static int ehci_urb_enqueue (
721 struct usb_hcd *hcd, 729 struct usb_hcd *hcd,
722 struct usb_host_endpoint *ep,
723 struct urb *urb, 730 struct urb *urb,
724 gfp_t mem_flags 731 gfp_t mem_flags
725) { 732) {
@@ -734,12 +741,12 @@ static int ehci_urb_enqueue (
734 default: 741 default:
735 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 742 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
736 return -ENOMEM; 743 return -ENOMEM;
737 return submit_async (ehci, ep, urb, &qtd_list, mem_flags); 744 return submit_async(ehci, urb, &qtd_list, mem_flags);
738 745
739 case PIPE_INTERRUPT: 746 case PIPE_INTERRUPT:
740 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 747 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
741 return -ENOMEM; 748 return -ENOMEM;
742 return intr_submit (ehci, ep, urb, &qtd_list, mem_flags); 749 return intr_submit(ehci, urb, &qtd_list, mem_flags);
743 750
744 case PIPE_ISOCHRONOUS: 751 case PIPE_ISOCHRONOUS:
745 if (urb->dev->speed == USB_SPEED_HIGH) 752 if (urb->dev->speed == USB_SPEED_HIGH)
@@ -777,13 +784,18 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
777 * completions normally happen asynchronously 784 * completions normally happen asynchronously
778 */ 785 */
779 786
780static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 787static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
781{ 788{
782 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 789 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
783 struct ehci_qh *qh; 790 struct ehci_qh *qh;
784 unsigned long flags; 791 unsigned long flags;
792 int rc;
785 793
786 spin_lock_irqsave (&ehci->lock, flags); 794 spin_lock_irqsave (&ehci->lock, flags);
795 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
796 if (rc)
797 goto done;
798
787 switch (usb_pipetype (urb->pipe)) { 799 switch (usb_pipetype (urb->pipe)) {
788 // case PIPE_CONTROL: 800 // case PIPE_CONTROL:
789 // case PIPE_BULK: 801 // case PIPE_BULK:
@@ -838,7 +850,7 @@ static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
838 } 850 }
839done: 851done:
840 spin_unlock_irqrestore (&ehci->lock, flags); 852 spin_unlock_irqrestore (&ehci->lock, flags);
841 return 0; 853 return rc;
842} 854}
843 855
844/*-------------------------------------------------------------------------*/ 856/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index a7816e392a85..ad0d4965f2fb 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -58,8 +58,6 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
58 if (!retval) 58 if (!retval)
59 ehci_dbg(ehci, "MWI active\n"); 59 ehci_dbg(ehci, "MWI active\n");
60 60
61 ehci_port_power(ehci, 0);
62
63 return 0; 61 return 0;
64} 62}
65 63
@@ -156,8 +154,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
156 break; 154 break;
157 } 155 }
158 156
159 if (ehci_is_TDI(ehci)) 157 ehci_reset(ehci);
160 ehci_reset(ehci);
161 158
162 /* at least the Genesys GL880S needs fixup here */ 159 /* at least the Genesys GL880S needs fixup here */
163 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params); 160 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
diff --git a/drivers/usb/host/ehci-ppc-soc.c b/drivers/usb/host/ehci-ppc-soc.c
index 4f99b0eb27bc..452d4b1bc859 100644
--- a/drivers/usb/host/ehci-ppc-soc.c
+++ b/drivers/usb/host/ehci-ppc-soc.c
@@ -160,10 +160,8 @@ static const struct hc_driver ehci_ppc_soc_hc_driver = {
160 */ 160 */
161 .hub_status_data = ehci_hub_status_data, 161 .hub_status_data = ehci_hub_status_data,
162 .hub_control = ehci_hub_control, 162 .hub_control = ehci_hub_control,
163#ifdef CONFIG_PM 163 .bus_suspend = ehci_bus_suspend,
164 .hub_suspend = ehci_hub_suspend, 164 .bus_resume = ehci_bus_resume,
165 .hub_resume = ehci_hub_resume,
166#endif
167}; 165};
168 166
169static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev) 167static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 829fe649a981..03a6b2f4e6ed 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -47,7 +47,7 @@ static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
47 if (result) 47 if (result)
48 return result; 48 return result;
49 49
50 ehci_port_power(ehci, 0); 50 ehci_reset(ehci);
51 51
52 return result; 52 return result;
53} 53}
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 140bfa423e07..b10f39c047e9 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -139,63 +139,65 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
139 139
140/*-------------------------------------------------------------------------*/ 140/*-------------------------------------------------------------------------*/
141 141
142static void qtd_copy_status ( 142static int qtd_copy_status (
143 struct ehci_hcd *ehci, 143 struct ehci_hcd *ehci,
144 struct urb *urb, 144 struct urb *urb,
145 size_t length, 145 size_t length,
146 u32 token 146 u32 token
147) 147)
148{ 148{
149 int status = -EINPROGRESS;
150
149 /* count IN/OUT bytes, not SETUP (even short packets) */ 151 /* count IN/OUT bytes, not SETUP (even short packets) */
150 if (likely (QTD_PID (token) != 2)) 152 if (likely (QTD_PID (token) != 2))
151 urb->actual_length += length - QTD_LENGTH (token); 153 urb->actual_length += length - QTD_LENGTH (token);
152 154
153 /* don't modify error codes */ 155 /* don't modify error codes */
154 if (unlikely (urb->status != -EINPROGRESS)) 156 if (unlikely(urb->unlinked))
155 return; 157 return status;
156 158
157 /* force cleanup after short read; not always an error */ 159 /* force cleanup after short read; not always an error */
158 if (unlikely (IS_SHORT_READ (token))) 160 if (unlikely (IS_SHORT_READ (token)))
159 urb->status = -EREMOTEIO; 161 status = -EREMOTEIO;
160 162
161 /* serious "can't proceed" faults reported by the hardware */ 163 /* serious "can't proceed" faults reported by the hardware */
162 if (token & QTD_STS_HALT) { 164 if (token & QTD_STS_HALT) {
163 if (token & QTD_STS_BABBLE) { 165 if (token & QTD_STS_BABBLE) {
164 /* FIXME "must" disable babbling device's port too */ 166 /* FIXME "must" disable babbling device's port too */
165 urb->status = -EOVERFLOW; 167 status = -EOVERFLOW;
166 } else if (token & QTD_STS_MMF) { 168 } else if (token & QTD_STS_MMF) {
167 /* fs/ls interrupt xfer missed the complete-split */ 169 /* fs/ls interrupt xfer missed the complete-split */
168 urb->status = -EPROTO; 170 status = -EPROTO;
169 } else if (token & QTD_STS_DBE) { 171 } else if (token & QTD_STS_DBE) {
170 urb->status = (QTD_PID (token) == 1) /* IN ? */ 172 status = (QTD_PID (token) == 1) /* IN ? */
171 ? -ENOSR /* hc couldn't read data */ 173 ? -ENOSR /* hc couldn't read data */
172 : -ECOMM; /* hc couldn't write data */ 174 : -ECOMM; /* hc couldn't write data */
173 } else if (token & QTD_STS_XACT) { 175 } else if (token & QTD_STS_XACT) {
174 /* timeout, bad crc, wrong PID, etc; retried */ 176 /* timeout, bad crc, wrong PID, etc; retried */
175 if (QTD_CERR (token)) 177 if (QTD_CERR (token))
176 urb->status = -EPIPE; 178 status = -EPIPE;
177 else { 179 else {
178 ehci_dbg (ehci, "devpath %s ep%d%s 3strikes\n", 180 ehci_dbg (ehci, "devpath %s ep%d%s 3strikes\n",
179 urb->dev->devpath, 181 urb->dev->devpath,
180 usb_pipeendpoint (urb->pipe), 182 usb_pipeendpoint (urb->pipe),
181 usb_pipein (urb->pipe) ? "in" : "out"); 183 usb_pipein (urb->pipe) ? "in" : "out");
182 urb->status = -EPROTO; 184 status = -EPROTO;
183 } 185 }
184 /* CERR nonzero + no errors + halt --> stall */ 186 /* CERR nonzero + no errors + halt --> stall */
185 } else if (QTD_CERR (token)) 187 } else if (QTD_CERR (token))
186 urb->status = -EPIPE; 188 status = -EPIPE;
187 else /* unknown */ 189 else /* unknown */
188 urb->status = -EPROTO; 190 status = -EPROTO;
189 191
190 ehci_vdbg (ehci, 192 ehci_vdbg (ehci,
191 "dev%d ep%d%s qtd token %08x --> status %d\n", 193 "dev%d ep%d%s qtd token %08x --> status %d\n",
192 usb_pipedevice (urb->pipe), 194 usb_pipedevice (urb->pipe),
193 usb_pipeendpoint (urb->pipe), 195 usb_pipeendpoint (urb->pipe),
194 usb_pipein (urb->pipe) ? "in" : "out", 196 usb_pipein (urb->pipe) ? "in" : "out",
195 token, urb->status); 197 token, status);
196 198
197 /* if async CSPLIT failed, try cleaning out the TT buffer */ 199 /* if async CSPLIT failed, try cleaning out the TT buffer */
198 if (urb->status != -EPIPE 200 if (status != -EPIPE
199 && urb->dev->tt && !usb_pipeint (urb->pipe) 201 && urb->dev->tt && !usb_pipeint (urb->pipe)
200 && ((token & QTD_STS_MMF) != 0 202 && ((token & QTD_STS_MMF) != 0
201 || QTD_CERR(token) == 0) 203 || QTD_CERR(token) == 0)
@@ -212,10 +214,12 @@ static void qtd_copy_status (
212 usb_hub_tt_clear_buffer (urb->dev, urb->pipe); 214 usb_hub_tt_clear_buffer (urb->dev, urb->pipe);
213 } 215 }
214 } 216 }
217
218 return status;
215} 219}
216 220
217static void 221static void
218ehci_urb_done (struct ehci_hcd *ehci, struct urb *urb) 222ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status)
219__releases(ehci->lock) 223__releases(ehci->lock)
220__acquires(ehci->lock) 224__acquires(ehci->lock)
221{ 225{
@@ -231,25 +235,13 @@ __acquires(ehci->lock)
231 qh_put (qh); 235 qh_put (qh);
232 } 236 }
233 237
234 spin_lock (&urb->lock); 238 if (unlikely(urb->unlinked)) {
235 urb->hcpriv = NULL; 239 COUNT(ehci->stats.unlink);
236 switch (urb->status) { 240 } else {
237 case -EINPROGRESS: /* success */ 241 if (likely(status == -EINPROGRESS))
238 urb->status = 0; 242 status = 0;
239 default: /* fault */ 243 COUNT(ehci->stats.complete);
240 COUNT (ehci->stats.complete);
241 break;
242 case -EREMOTEIO: /* fault or normal */
243 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
244 urb->status = 0;
245 COUNT (ehci->stats.complete);
246 break;
247 case -ECONNRESET: /* canceled */
248 case -ENOENT:
249 COUNT (ehci->stats.unlink);
250 break;
251 } 244 }
252 spin_unlock (&urb->lock);
253 245
254#ifdef EHCI_URB_TRACE 246#ifdef EHCI_URB_TRACE
255 ehci_dbg (ehci, 247 ehci_dbg (ehci,
@@ -257,13 +249,14 @@ __acquires(ehci->lock)
257 __FUNCTION__, urb->dev->devpath, urb, 249 __FUNCTION__, urb->dev->devpath, urb,
258 usb_pipeendpoint (urb->pipe), 250 usb_pipeendpoint (urb->pipe),
259 usb_pipein (urb->pipe) ? "in" : "out", 251 usb_pipein (urb->pipe) ? "in" : "out",
260 urb->status, 252 status,
261 urb->actual_length, urb->transfer_buffer_length); 253 urb->actual_length, urb->transfer_buffer_length);
262#endif 254#endif
263 255
264 /* complete() can reenter this HCD */ 256 /* complete() can reenter this HCD */
257 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
265 spin_unlock (&ehci->lock); 258 spin_unlock (&ehci->lock);
266 usb_hcd_giveback_urb (ehci_to_hcd(ehci), urb); 259 usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status);
267 spin_lock (&ehci->lock); 260 spin_lock (&ehci->lock);
268} 261}
269 262
@@ -283,6 +276,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
283{ 276{
284 struct ehci_qtd *last = NULL, *end = qh->dummy; 277 struct ehci_qtd *last = NULL, *end = qh->dummy;
285 struct list_head *entry, *tmp; 278 struct list_head *entry, *tmp;
279 int last_status = -EINPROGRESS;
286 int stopped; 280 int stopped;
287 unsigned count = 0; 281 unsigned count = 0;
288 int do_status = 0; 282 int do_status = 0;
@@ -311,6 +305,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
311 struct ehci_qtd *qtd; 305 struct ehci_qtd *qtd;
312 struct urb *urb; 306 struct urb *urb;
313 u32 token = 0; 307 u32 token = 0;
308 int qtd_status;
314 309
315 qtd = list_entry (entry, struct ehci_qtd, qtd_list); 310 qtd = list_entry (entry, struct ehci_qtd, qtd_list);
316 urb = qtd->urb; 311 urb = qtd->urb;
@@ -318,11 +313,12 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
318 /* clean up any state from previous QTD ...*/ 313 /* clean up any state from previous QTD ...*/
319 if (last) { 314 if (last) {
320 if (likely (last->urb != urb)) { 315 if (likely (last->urb != urb)) {
321 ehci_urb_done (ehci, last->urb); 316 ehci_urb_done(ehci, last->urb, last_status);
322 count++; 317 count++;
323 } 318 }
324 ehci_qtd_free (ehci, last); 319 ehci_qtd_free (ehci, last);
325 last = NULL; 320 last = NULL;
321 last_status = -EINPROGRESS;
326 } 322 }
327 323
328 /* ignore urbs submitted during completions we reported */ 324 /* ignore urbs submitted during completions we reported */
@@ -358,13 +354,14 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
358 stopped = 1; 354 stopped = 1;
359 355
360 if (unlikely (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) 356 if (unlikely (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)))
361 urb->status = -ESHUTDOWN; 357 last_status = -ESHUTDOWN;
362 358
363 /* ignore active urbs unless some previous qtd 359 /* ignore active urbs unless some previous qtd
364 * for the urb faulted (including short read) or 360 * for the urb faulted (including short read) or
365 * its urb was canceled. we may patch qh or qtds. 361 * its urb was canceled. we may patch qh or qtds.
366 */ 362 */
367 if (likely (urb->status == -EINPROGRESS)) 363 if (likely(last_status == -EINPROGRESS &&
364 !urb->unlinked))
368 continue; 365 continue;
369 366
370 /* issue status after short control reads */ 367 /* issue status after short control reads */
@@ -392,11 +389,14 @@ halt:
392 } 389 }
393 390
394 /* remove it from the queue */ 391 /* remove it from the queue */
395 spin_lock (&urb->lock); 392 qtd_status = qtd_copy_status(ehci, urb, qtd->length, token);
396 qtd_copy_status (ehci, urb, qtd->length, token); 393 if (unlikely(qtd_status == -EREMOTEIO)) {
397 do_status = (urb->status == -EREMOTEIO) 394 do_status = (!urb->unlinked &&
398 && usb_pipecontrol (urb->pipe); 395 usb_pipecontrol(urb->pipe));
399 spin_unlock (&urb->lock); 396 qtd_status = 0;
397 }
398 if (likely(last_status == -EINPROGRESS))
399 last_status = qtd_status;
400 400
401 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { 401 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
402 last = list_entry (qtd->qtd_list.prev, 402 last = list_entry (qtd->qtd_list.prev,
@@ -409,7 +409,7 @@ halt:
409 409
410 /* last urb's completion might still need calling */ 410 /* last urb's completion might still need calling */
411 if (likely (last != NULL)) { 411 if (likely (last != NULL)) {
412 ehci_urb_done (ehci, last->urb); 412 ehci_urb_done(ehci, last->urb, last_status);
413 count++; 413 count++;
414 ehci_qtd_free (ehci, last); 414 ehci_qtd_free (ehci, last);
415 } 415 }
@@ -913,7 +913,6 @@ static struct ehci_qh *qh_append_tds (
913static int 913static int
914submit_async ( 914submit_async (
915 struct ehci_hcd *ehci, 915 struct ehci_hcd *ehci,
916 struct usb_host_endpoint *ep,
917 struct urb *urb, 916 struct urb *urb,
918 struct list_head *qtd_list, 917 struct list_head *qtd_list,
919 gfp_t mem_flags 918 gfp_t mem_flags
@@ -922,10 +921,10 @@ submit_async (
922 int epnum; 921 int epnum;
923 unsigned long flags; 922 unsigned long flags;
924 struct ehci_qh *qh = NULL; 923 struct ehci_qh *qh = NULL;
925 int rc = 0; 924 int rc;
926 925
927 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list); 926 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
928 epnum = ep->desc.bEndpointAddress; 927 epnum = urb->ep->desc.bEndpointAddress;
929 928
930#ifdef EHCI_URB_TRACE 929#ifdef EHCI_URB_TRACE
931 ehci_dbg (ehci, 930 ehci_dbg (ehci,
@@ -933,7 +932,7 @@ submit_async (
933 __FUNCTION__, urb->dev->devpath, urb, 932 __FUNCTION__, urb->dev->devpath, urb,
934 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 933 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
935 urb->transfer_buffer_length, 934 urb->transfer_buffer_length,
936 qtd, ep->hcpriv); 935 qtd, urb->ep->hcpriv);
937#endif 936#endif
938 937
939 spin_lock_irqsave (&ehci->lock, flags); 938 spin_lock_irqsave (&ehci->lock, flags);
@@ -942,9 +941,13 @@ submit_async (
942 rc = -ESHUTDOWN; 941 rc = -ESHUTDOWN;
943 goto done; 942 goto done;
944 } 943 }
944 rc = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
945 if (unlikely(rc))
946 goto done;
945 947
946 qh = qh_append_tds (ehci, urb, qtd_list, epnum, &ep->hcpriv); 948 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
947 if (unlikely(qh == NULL)) { 949 if (unlikely(qh == NULL)) {
950 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
948 rc = -ENOMEM; 951 rc = -ENOMEM;
949 goto done; 952 goto done;
950 } 953 }
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index e682f2342ef8..80d99bce2b38 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -797,7 +797,6 @@ done:
797 797
798static int intr_submit ( 798static int intr_submit (
799 struct ehci_hcd *ehci, 799 struct ehci_hcd *ehci,
800 struct usb_host_endpoint *ep,
801 struct urb *urb, 800 struct urb *urb,
802 struct list_head *qtd_list, 801 struct list_head *qtd_list,
803 gfp_t mem_flags 802 gfp_t mem_flags
@@ -805,23 +804,26 @@ static int intr_submit (
805 unsigned epnum; 804 unsigned epnum;
806 unsigned long flags; 805 unsigned long flags;
807 struct ehci_qh *qh; 806 struct ehci_qh *qh;
808 int status = 0; 807 int status;
809 struct list_head empty; 808 struct list_head empty;
810 809
811 /* get endpoint and transfer/schedule data */ 810 /* get endpoint and transfer/schedule data */
812 epnum = ep->desc.bEndpointAddress; 811 epnum = urb->ep->desc.bEndpointAddress;
813 812
814 spin_lock_irqsave (&ehci->lock, flags); 813 spin_lock_irqsave (&ehci->lock, flags);
815 814
816 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 815 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
817 &ehci_to_hcd(ehci)->flags))) { 816 &ehci_to_hcd(ehci)->flags))) {
818 status = -ESHUTDOWN; 817 status = -ESHUTDOWN;
819 goto done; 818 goto done_not_linked;
820 } 819 }
820 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
821 if (unlikely(status))
822 goto done_not_linked;
821 823
822 /* get qh and force any scheduling errors */ 824 /* get qh and force any scheduling errors */
823 INIT_LIST_HEAD (&empty); 825 INIT_LIST_HEAD (&empty);
824 qh = qh_append_tds (ehci, urb, &empty, epnum, &ep->hcpriv); 826 qh = qh_append_tds(ehci, urb, &empty, epnum, &urb->ep->hcpriv);
825 if (qh == NULL) { 827 if (qh == NULL) {
826 status = -ENOMEM; 828 status = -ENOMEM;
827 goto done; 829 goto done;
@@ -832,13 +834,16 @@ static int intr_submit (
832 } 834 }
833 835
834 /* then queue the urb's tds to the qh */ 836 /* then queue the urb's tds to the qh */
835 qh = qh_append_tds (ehci, urb, qtd_list, epnum, &ep->hcpriv); 837 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
836 BUG_ON (qh == NULL); 838 BUG_ON (qh == NULL);
837 839
838 /* ... update usbfs periodic stats */ 840 /* ... update usbfs periodic stats */
839 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++; 841 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++;
840 842
841done: 843done:
844 if (unlikely(status))
845 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
846done_not_linked:
842 spin_unlock_irqrestore (&ehci->lock, flags); 847 spin_unlock_irqrestore (&ehci->lock, flags);
843 if (status) 848 if (status)
844 qtd_list_free (ehci, urb, qtd_list); 849 qtd_list_free (ehci, urb, qtd_list);
@@ -1622,7 +1627,7 @@ itd_complete (
1622 1627
1623 /* give urb back to the driver ... can be out-of-order */ 1628 /* give urb back to the driver ... can be out-of-order */
1624 dev = urb->dev; 1629 dev = urb->dev;
1625 ehci_urb_done (ehci, urb); 1630 ehci_urb_done(ehci, urb, 0);
1626 urb = NULL; 1631 urb = NULL;
1627 1632
1628 /* defer stopping schedule; completion can submit */ 1633 /* defer stopping schedule; completion can submit */
@@ -1686,12 +1691,19 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1686 /* schedule ... need to lock */ 1691 /* schedule ... need to lock */
1687 spin_lock_irqsave (&ehci->lock, flags); 1692 spin_lock_irqsave (&ehci->lock, flags);
1688 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1693 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
1689 &ehci_to_hcd(ehci)->flags))) 1694 &ehci_to_hcd(ehci)->flags))) {
1690 status = -ESHUTDOWN; 1695 status = -ESHUTDOWN;
1691 else 1696 goto done_not_linked;
1692 status = iso_stream_schedule (ehci, urb, stream); 1697 }
1698 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
1699 if (unlikely(status))
1700 goto done_not_linked;
1701 status = iso_stream_schedule(ehci, urb, stream);
1693 if (likely (status == 0)) 1702 if (likely (status == 0))
1694 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1703 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1704 else
1705 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
1706done_not_linked:
1695 spin_unlock_irqrestore (&ehci->lock, flags); 1707 spin_unlock_irqrestore (&ehci->lock, flags);
1696 1708
1697done: 1709done:
@@ -1988,7 +2000,7 @@ sitd_complete (
1988 2000
1989 /* give urb back to the driver */ 2001 /* give urb back to the driver */
1990 dev = urb->dev; 2002 dev = urb->dev;
1991 ehci_urb_done (ehci, urb); 2003 ehci_urb_done(ehci, urb, 0);
1992 urb = NULL; 2004 urb = NULL;
1993 2005
1994 /* defer stopping schedule; completion can submit */ 2006 /* defer stopping schedule; completion can submit */
@@ -2049,12 +2061,19 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2049 /* schedule ... need to lock */ 2061 /* schedule ... need to lock */
2050 spin_lock_irqsave (&ehci->lock, flags); 2062 spin_lock_irqsave (&ehci->lock, flags);
2051 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2063 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
2052 &ehci_to_hcd(ehci)->flags))) 2064 &ehci_to_hcd(ehci)->flags))) {
2053 status = -ESHUTDOWN; 2065 status = -ESHUTDOWN;
2054 else 2066 goto done_not_linked;
2055 status = iso_stream_schedule (ehci, urb, stream); 2067 }
2068 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
2069 if (unlikely(status))
2070 goto done_not_linked;
2071 status = iso_stream_schedule(ehci, urb, stream);
2056 if (status == 0) 2072 if (status == 0)
2057 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2073 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2074 else
2075 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
2076done_not_linked:
2058 spin_unlock_irqrestore (&ehci->lock, flags); 2077 spin_unlock_irqrestore (&ehci->lock, flags);
2059 2078
2060done: 2079done:
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 5c851a36de72..c27417f5b9d8 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -277,12 +277,11 @@ static void preproc_atl_queue(struct isp116x *isp116x)
277 processed urbs. 277 processed urbs.
278*/ 278*/
279static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep, 279static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
280 struct urb *urb) 280 struct urb *urb, int status)
281__releases(isp116x->lock) __acquires(isp116x->lock) 281__releases(isp116x->lock) __acquires(isp116x->lock)
282{ 282{
283 unsigned i; 283 unsigned i;
284 284
285 urb->hcpriv = NULL;
286 ep->error_count = 0; 285 ep->error_count = 0;
287 286
288 if (usb_pipecontrol(urb->pipe)) 287 if (usb_pipecontrol(urb->pipe))
@@ -290,8 +289,9 @@ __releases(isp116x->lock) __acquires(isp116x->lock)
290 289
291 urb_dbg(urb, "Finish"); 290 urb_dbg(urb, "Finish");
292 291
292 usb_hcd_unlink_urb_from_ep(isp116x_to_hcd(isp116x), urb);
293 spin_unlock(&isp116x->lock); 293 spin_unlock(&isp116x->lock);
294 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb); 294 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, status);
295 spin_lock(&isp116x->lock); 295 spin_lock(&isp116x->lock);
296 296
297 /* take idle endpoints out of the schedule */ 297 /* take idle endpoints out of the schedule */
@@ -445,12 +445,7 @@ static void postproc_atl_queue(struct isp116x *isp116x)
445 if (PTD_GET_ACTIVE(ptd) 445 if (PTD_GET_ACTIVE(ptd)
446 || (cc != TD_CC_NOERROR && cc < 0x0E)) 446 || (cc != TD_CC_NOERROR && cc < 0x0E))
447 break; 447 break;
448 if ((urb->transfer_flags & URB_SHORT_NOT_OK) && 448 status = 0;
449 urb->actual_length <
450 urb->transfer_buffer_length)
451 status = -EREMOTEIO;
452 else
453 status = 0;
454 ep->nextpid = 0; 449 ep->nextpid = 0;
455 break; 450 break;
456 default: 451 default:
@@ -458,14 +453,8 @@ static void postproc_atl_queue(struct isp116x *isp116x)
458 } 453 }
459 454
460 done: 455 done:
461 if (status != -EINPROGRESS) { 456 if (status != -EINPROGRESS || urb->unlinked)
462 spin_lock(&urb->lock); 457 finish_request(isp116x, ep, urb, status);
463 if (urb->status == -EINPROGRESS)
464 urb->status = status;
465 spin_unlock(&urb->lock);
466 }
467 if (urb->status != -EINPROGRESS)
468 finish_request(isp116x, ep, urb);
469 } 458 }
470} 459}
471 460
@@ -673,7 +662,7 @@ static int balance(struct isp116x *isp116x, u16 period, u16 load)
673/*-----------------------------------------------------------------*/ 662/*-----------------------------------------------------------------*/
674 663
675static int isp116x_urb_enqueue(struct usb_hcd *hcd, 664static int isp116x_urb_enqueue(struct usb_hcd *hcd,
676 struct usb_host_endpoint *hep, struct urb *urb, 665 struct urb *urb,
677 gfp_t mem_flags) 666 gfp_t mem_flags)
678{ 667{
679 struct isp116x *isp116x = hcd_to_isp116x(hcd); 668 struct isp116x *isp116x = hcd_to_isp116x(hcd);
@@ -682,6 +671,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
682 int is_out = !usb_pipein(pipe); 671 int is_out = !usb_pipein(pipe);
683 int type = usb_pipetype(pipe); 672 int type = usb_pipetype(pipe);
684 int epnum = usb_pipeendpoint(pipe); 673 int epnum = usb_pipeendpoint(pipe);
674 struct usb_host_endpoint *hep = urb->ep;
685 struct isp116x_ep *ep = NULL; 675 struct isp116x_ep *ep = NULL;
686 unsigned long flags; 676 unsigned long flags;
687 int i; 677 int i;
@@ -705,7 +695,12 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
705 if (!HC_IS_RUNNING(hcd->state)) { 695 if (!HC_IS_RUNNING(hcd->state)) {
706 kfree(ep); 696 kfree(ep);
707 ret = -ENODEV; 697 ret = -ENODEV;
708 goto fail; 698 goto fail_not_linked;
699 }
700 ret = usb_hcd_link_urb_to_ep(hcd, urb);
701 if (ret) {
702 kfree(ep);
703 goto fail_not_linked;
709 } 704 }
710 705
711 if (hep->hcpriv) 706 if (hep->hcpriv)
@@ -808,16 +803,13 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
808 } 803 }
809 } 804 }
810 805
811 /* in case of unlink-during-submit */
812 if (urb->status != -EINPROGRESS) {
813 finish_request(isp116x, ep, urb);
814 ret = 0;
815 goto fail;
816 }
817 urb->hcpriv = hep; 806 urb->hcpriv = hep;
818 start_atl_transfers(isp116x); 807 start_atl_transfers(isp116x);
819 808
820 fail: 809 fail:
810 if (ret)
811 usb_hcd_unlink_urb_from_ep(hcd, urb);
812 fail_not_linked:
821 spin_unlock_irqrestore(&isp116x->lock, flags); 813 spin_unlock_irqrestore(&isp116x->lock, flags);
822 return ret; 814 return ret;
823} 815}
@@ -825,20 +817,21 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
825/* 817/*
826 Dequeue URBs. 818 Dequeue URBs.
827*/ 819*/
828static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 820static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
821 int status)
829{ 822{
830 struct isp116x *isp116x = hcd_to_isp116x(hcd); 823 struct isp116x *isp116x = hcd_to_isp116x(hcd);
831 struct usb_host_endpoint *hep; 824 struct usb_host_endpoint *hep;
832 struct isp116x_ep *ep, *ep_act; 825 struct isp116x_ep *ep, *ep_act;
833 unsigned long flags; 826 unsigned long flags;
827 int rc;
834 828
835 spin_lock_irqsave(&isp116x->lock, flags); 829 spin_lock_irqsave(&isp116x->lock, flags);
830 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
831 if (rc)
832 goto done;
833
836 hep = urb->hcpriv; 834 hep = urb->hcpriv;
837 /* URB already unlinked (or never linked)? */
838 if (!hep) {
839 spin_unlock_irqrestore(&isp116x->lock, flags);
840 return 0;
841 }
842 ep = hep->hcpriv; 835 ep = hep->hcpriv;
843 WARN_ON(hep != ep->hep); 836 WARN_ON(hep != ep->hep);
844 837
@@ -855,10 +848,10 @@ static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
855 } 848 }
856 849
857 if (urb) 850 if (urb)
858 finish_request(isp116x, ep, urb); 851 finish_request(isp116x, ep, urb, status);
859 852 done:
860 spin_unlock_irqrestore(&isp116x->lock, flags); 853 spin_unlock_irqrestore(&isp116x->lock, flags);
861 return 0; 854 return rc;
862} 855}
863 856
864static void isp116x_endpoint_disable(struct usb_hcd *hcd, 857static void isp116x_endpoint_disable(struct usb_hcd *hcd,
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index f61c6cdd06f2..ebab5ce8f5ce 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -24,7 +24,7 @@
24 * small: 0) header + data packets 1) just header 24 * small: 0) header + data packets 1) just header
25 */ 25 */
26static void __maybe_unused 26static void __maybe_unused
27urb_print (struct urb * urb, char * str, int small) 27urb_print(struct urb * urb, char * str, int small, int status)
28{ 28{
29 unsigned int pipe= urb->pipe; 29 unsigned int pipe= urb->pipe;
30 30
@@ -34,7 +34,7 @@ urb_print (struct urb * urb, char * str, int small)
34 } 34 }
35 35
36#ifndef OHCI_VERBOSE_DEBUG 36#ifndef OHCI_VERBOSE_DEBUG
37 if (urb->status != 0) 37 if (status != 0)
38#endif 38#endif
39 dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d", 39 dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d",
40 str, 40 str,
@@ -46,7 +46,7 @@ urb_print (struct urb * urb, char * str, int small)
46 urb->transfer_flags, 46 urb->transfer_flags,
47 urb->actual_length, 47 urb->actual_length,
48 urb->transfer_buffer_length, 48 urb->transfer_buffer_length,
49 urb->status); 49 status);
50 50
51#ifdef OHCI_VERBOSE_DEBUG 51#ifdef OHCI_VERBOSE_DEBUG
52 if (!small) { 52 if (!small) {
@@ -66,7 +66,7 @@ urb_print (struct urb * urb, char * str, int small)
66 urb->transfer_buffer_length: urb->actual_length; 66 urb->transfer_buffer_length: urb->actual_length;
67 for (i = 0; i < 16 && i < len; i++) 67 for (i = 0; i < 16 && i < len; i++)
68 printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]); 68 printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]);
69 printk ("%s stat:%d\n", i < len? "...": "", urb->status); 69 printk ("%s stat:%d\n", i < len? "...": "", status);
70 } 70 }
71 } 71 }
72#endif 72#endif
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 6edf4097d2d2..240c7f507541 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -81,7 +81,6 @@ static void ohci_dump (struct ohci_hcd *ohci, int verbose);
81static int ohci_init (struct ohci_hcd *ohci); 81static int ohci_init (struct ohci_hcd *ohci);
82static void ohci_stop (struct usb_hcd *hcd); 82static void ohci_stop (struct usb_hcd *hcd);
83static int ohci_restart (struct ohci_hcd *ohci); 83static int ohci_restart (struct ohci_hcd *ohci);
84static void ohci_quirk_nec_worker (struct work_struct *work);
85 84
86#include "ohci-hub.c" 85#include "ohci-hub.c"
87#include "ohci-dbg.c" 86#include "ohci-dbg.c"
@@ -118,7 +117,6 @@ MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
118 */ 117 */
119static int ohci_urb_enqueue ( 118static int ohci_urb_enqueue (
120 struct usb_hcd *hcd, 119 struct usb_hcd *hcd,
121 struct usb_host_endpoint *ep,
122 struct urb *urb, 120 struct urb *urb,
123 gfp_t mem_flags 121 gfp_t mem_flags
124) { 122) {
@@ -131,11 +129,11 @@ static int ohci_urb_enqueue (
131 int retval = 0; 129 int retval = 0;
132 130
133#ifdef OHCI_VERBOSE_DEBUG 131#ifdef OHCI_VERBOSE_DEBUG
134 urb_print (urb, "SUB", usb_pipein (pipe)); 132 urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
135#endif 133#endif
136 134
137 /* every endpoint has a ed, locate and maybe (re)initialize it */ 135 /* every endpoint has a ed, locate and maybe (re)initialize it */
138 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval))) 136 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
139 return -ENOMEM; 137 return -ENOMEM;
140 138
141 /* for the private part of the URB we need the number of TDs (size) */ 139 /* for the private part of the URB we need the number of TDs (size) */
@@ -200,22 +198,17 @@ static int ohci_urb_enqueue (
200 retval = -ENODEV; 198 retval = -ENODEV;
201 goto fail; 199 goto fail;
202 } 200 }
203 201 retval = usb_hcd_link_urb_to_ep(hcd, urb);
204 /* in case of unlink-during-submit */ 202 if (retval)
205 spin_lock (&urb->lock);
206 if (urb->status != -EINPROGRESS) {
207 spin_unlock (&urb->lock);
208 urb->hcpriv = urb_priv;
209 finish_urb (ohci, urb);
210 retval = 0;
211 goto fail; 203 goto fail;
212 }
213 204
214 /* schedule the ed if needed */ 205 /* schedule the ed if needed */
215 if (ed->state == ED_IDLE) { 206 if (ed->state == ED_IDLE) {
216 retval = ed_schedule (ohci, ed); 207 retval = ed_schedule (ohci, ed);
217 if (retval < 0) 208 if (retval < 0) {
218 goto fail0; 209 usb_hcd_unlink_urb_from_ep(hcd, urb);
210 goto fail;
211 }
219 if (ed->type == PIPE_ISOCHRONOUS) { 212 if (ed->type == PIPE_ISOCHRONOUS) {
220 u16 frame = ohci_frame_no(ohci); 213 u16 frame = ohci_frame_no(ohci);
221 214
@@ -239,8 +232,6 @@ static int ohci_urb_enqueue (
239 urb->hcpriv = urb_priv; 232 urb->hcpriv = urb_priv;
240 td_submit_urb (ohci, urb); 233 td_submit_urb (ohci, urb);
241 234
242fail0:
243 spin_unlock (&urb->lock);
244fail: 235fail:
245 if (retval) 236 if (retval)
246 urb_free_priv (ohci, urb_priv); 237 urb_free_priv (ohci, urb_priv);
@@ -249,22 +240,26 @@ fail:
249} 240}
250 241
251/* 242/*
252 * decouple the URB from the HC queues (TDs, urb_priv); it's 243 * decouple the URB from the HC queues (TDs, urb_priv).
253 * already marked using urb->status. reporting is always done 244 * reporting is always done
254 * asynchronously, and we might be dealing with an urb that's 245 * asynchronously, and we might be dealing with an urb that's
255 * partially transferred, or an ED with other urbs being unlinked. 246 * partially transferred, or an ED with other urbs being unlinked.
256 */ 247 */
257static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 248static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
258{ 249{
259 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 250 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
260 unsigned long flags; 251 unsigned long flags;
252 int rc;
261 253
262#ifdef OHCI_VERBOSE_DEBUG 254#ifdef OHCI_VERBOSE_DEBUG
263 urb_print (urb, "UNLINK", 1); 255 urb_print(urb, "UNLINK", 1, status);
264#endif 256#endif
265 257
266 spin_lock_irqsave (&ohci->lock, flags); 258 spin_lock_irqsave (&ohci->lock, flags);
267 if (HC_IS_RUNNING(hcd->state)) { 259 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
260 if (rc) {
261 ; /* Do nothing */
262 } else if (HC_IS_RUNNING(hcd->state)) {
268 urb_priv_t *urb_priv; 263 urb_priv_t *urb_priv;
269 264
270 /* Unless an IRQ completed the unlink while it was being 265 /* Unless an IRQ completed the unlink while it was being
@@ -282,10 +277,10 @@ static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
282 * any more ... just clean up every urb's memory. 277 * any more ... just clean up every urb's memory.
283 */ 278 */
284 if (urb->hcpriv) 279 if (urb->hcpriv)
285 finish_urb (ohci, urb); 280 finish_urb(ohci, urb, status);
286 } 281 }
287 spin_unlock_irqrestore (&ohci->lock, flags); 282 spin_unlock_irqrestore (&ohci->lock, flags);
288 return 0; 283 return rc;
289} 284}
290 285
291/*-------------------------------------------------------------------------*/ 286/*-------------------------------------------------------------------------*/
@@ -314,6 +309,8 @@ rescan:
314 if (!HC_IS_RUNNING (hcd->state)) { 309 if (!HC_IS_RUNNING (hcd->state)) {
315sanitize: 310sanitize:
316 ed->state = ED_IDLE; 311 ed->state = ED_IDLE;
312 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
313 ohci->eds_scheduled--;
317 finish_unlinks (ohci, 0); 314 finish_unlinks (ohci, 0);
318 } 315 }
319 316
@@ -321,7 +318,12 @@ sanitize:
321 case ED_UNLINK: /* wait for hw to finish? */ 318 case ED_UNLINK: /* wait for hw to finish? */
322 /* major IRQ delivery trouble loses INTR_SF too... */ 319 /* major IRQ delivery trouble loses INTR_SF too... */
323 if (limit-- == 0) { 320 if (limit-- == 0) {
324 ohci_warn (ohci, "IRQ INTR_SF lossage\n"); 321 ohci_warn(ohci, "ED unlink timeout\n");
322 if (quirk_zfmicro(ohci)) {
323 ohci_warn(ohci, "Attempting ZF TD recovery\n");
324 ohci->ed_to_check = ed;
325 ohci->zf_delay = 2;
326 }
325 goto sanitize; 327 goto sanitize;
326 } 328 }
327 spin_unlock_irqrestore (&ohci->lock, flags); 329 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -379,6 +381,93 @@ ohci_shutdown (struct usb_hcd *hcd)
379 (void) ohci_readl (ohci, &ohci->regs->control); 381 (void) ohci_readl (ohci, &ohci->regs->control);
380} 382}
381 383
384static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
385{
386 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
387 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
388 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
389 && !list_empty(&ed->td_list);
390}
391
392/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
393 * an interrupt TD but neglects to add it to the donelist. On systems with
394 * this chipset, we need to periodically check the state of the queues to look
395 * for such "lost" TDs.
396 */
397static void unlink_watchdog_func(unsigned long _ohci)
398{
399 long flags;
400 unsigned max;
401 unsigned seen_count = 0;
402 unsigned i;
403 struct ed **seen = NULL;
404 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
405
406 spin_lock_irqsave(&ohci->lock, flags);
407 max = ohci->eds_scheduled;
408 if (!max)
409 goto done;
410
411 if (ohci->ed_to_check)
412 goto out;
413
414 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
415 if (!seen)
416 goto out;
417
418 for (i = 0; i < NUM_INTS; i++) {
419 struct ed *ed = ohci->periodic[i];
420
421 while (ed) {
422 unsigned temp;
423
424 /* scan this branch of the periodic schedule tree */
425 for (temp = 0; temp < seen_count; temp++) {
426 if (seen[temp] == ed) {
427 /* we've checked it and what's after */
428 ed = NULL;
429 break;
430 }
431 }
432 if (!ed)
433 break;
434 seen[seen_count++] = ed;
435 if (!check_ed(ohci, ed)) {
436 ed = ed->ed_next;
437 continue;
438 }
439
440 /* HC's TD list is empty, but HCD sees at least one
441 * TD that's not been sent through the donelist.
442 */
443 ohci->ed_to_check = ed;
444 ohci->zf_delay = 2;
445
446 /* The HC may wait until the next frame to report the
447 * TD as done through the donelist and INTR_WDH. (We
448 * just *assume* it's not a multi-TD interrupt URB;
449 * those could defer the IRQ more than one frame, using
450 * DI...) Check again after the next INTR_SF.
451 */
452 ohci_writel(ohci, OHCI_INTR_SF,
453 &ohci->regs->intrstatus);
454 ohci_writel(ohci, OHCI_INTR_SF,
455 &ohci->regs->intrenable);
456
457 /* flush those writes */
458 (void) ohci_readl(ohci, &ohci->regs->control);
459
460 goto out;
461 }
462 }
463out:
464 kfree(seen);
465 if (ohci->eds_scheduled)
466 mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
467done:
468 spin_unlock_irqrestore(&ohci->lock, flags);
469}
470
382/*-------------------------------------------------------------------------* 471/*-------------------------------------------------------------------------*
383 * HC functions 472 * HC functions
384 *-------------------------------------------------------------------------*/ 473 *-------------------------------------------------------------------------*/
@@ -616,6 +705,15 @@ retry:
616 mdelay ((temp >> 23) & 0x1fe); 705 mdelay ((temp >> 23) & 0x1fe);
617 hcd->state = HC_STATE_RUNNING; 706 hcd->state = HC_STATE_RUNNING;
618 707
708 if (quirk_zfmicro(ohci)) {
709 /* Create timer to watch for bad queue state on ZF Micro */
710 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
711 (unsigned long) ohci);
712
713 ohci->eds_scheduled = 0;
714 ohci->ed_to_check = NULL;
715 }
716
619 ohci_dump (ohci, 1); 717 ohci_dump (ohci, 1);
620 718
621 return 0; 719 return 0;
@@ -629,10 +727,11 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
629{ 727{
630 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 728 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
631 struct ohci_regs __iomem *regs = ohci->regs; 729 struct ohci_regs __iomem *regs = ohci->regs;
632 int ints; 730 int ints;
633 731
634 /* we can eliminate a (slow) ohci_readl() 732 /* we can eliminate a (slow) ohci_readl()
635 if _only_ WDH caused this irq */ 733 * if _only_ WDH caused this irq
734 */
636 if ((ohci->hcca->done_head != 0) 735 if ((ohci->hcca->done_head != 0)
637 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head) 736 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
638 & 0x01)) { 737 & 0x01)) {
@@ -651,7 +750,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
651 750
652 if (ints & OHCI_INTR_UE) { 751 if (ints & OHCI_INTR_UE) {
653 // e.g. due to PCI Master/Target Abort 752 // e.g. due to PCI Master/Target Abort
654 if (ohci->flags & OHCI_QUIRK_NEC) { 753 if (quirk_nec(ohci)) {
655 /* Workaround for a silicon bug in some NEC chips used 754 /* Workaround for a silicon bug in some NEC chips used
656 * in Apple's PowerBooks. Adapted from Darwin code. 755 * in Apple's PowerBooks. Adapted from Darwin code.
657 */ 756 */
@@ -713,6 +812,31 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
713 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable); 812 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
714 } 813 }
715 814
815 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
816 spin_lock(&ohci->lock);
817 if (ohci->ed_to_check) {
818 struct ed *ed = ohci->ed_to_check;
819
820 if (check_ed(ohci, ed)) {
821 /* HC thinks the TD list is empty; HCD knows
822 * at least one TD is outstanding
823 */
824 if (--ohci->zf_delay == 0) {
825 struct td *td = list_entry(
826 ed->td_list.next,
827 struct td, td_list);
828 ohci_warn(ohci,
829 "Reclaiming orphan TD %p\n",
830 td);
831 takeback_td(ohci, td);
832 ohci->ed_to_check = NULL;
833 }
834 } else
835 ohci->ed_to_check = NULL;
836 }
837 spin_unlock(&ohci->lock);
838 }
839
716 /* could track INTR_SO to reduce available PCI/... bandwidth */ 840 /* could track INTR_SO to reduce available PCI/... bandwidth */
717 841
718 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled 842 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
@@ -721,7 +845,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
721 spin_lock (&ohci->lock); 845 spin_lock (&ohci->lock);
722 if (ohci->ed_rm_list) 846 if (ohci->ed_rm_list)
723 finish_unlinks (ohci, ohci_frame_no(ohci)); 847 finish_unlinks (ohci, ohci_frame_no(ohci));
724 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list 848 if ((ints & OHCI_INTR_SF) != 0
849 && !ohci->ed_rm_list
850 && !ohci->ed_to_check
725 && HC_IS_RUNNING(hcd->state)) 851 && HC_IS_RUNNING(hcd->state))
726 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable); 852 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
727 spin_unlock (&ohci->lock); 853 spin_unlock (&ohci->lock);
@@ -751,6 +877,9 @@ static void ohci_stop (struct usb_hcd *hcd)
751 free_irq(hcd->irq, hcd); 877 free_irq(hcd->irq, hcd);
752 hcd->irq = -1; 878 hcd->irq = -1;
753 879
880 if (quirk_zfmicro(ohci))
881 del_timer(&ohci->unlink_watchdog);
882
754 remove_debug_files (ohci); 883 remove_debug_files (ohci);
755 ohci_mem_cleanup (ohci); 884 ohci_mem_cleanup (ohci);
756 if (ohci->hcca) { 885 if (ohci->hcca) {
@@ -798,9 +927,8 @@ static int ohci_restart (struct ohci_hcd *ohci)
798 ed, ed->state); 927 ed, ed->state);
799 } 928 }
800 929
801 spin_lock (&urb->lock); 930 if (!urb->unlinked)
802 urb->status = -ESHUTDOWN; 931 urb->unlinked = -ESHUTDOWN;
803 spin_unlock (&urb->lock);
804 } 932 }
805 finish_unlinks (ohci, 0); 933 finish_unlinks (ohci, 0);
806 spin_unlock_irq(&ohci->lock); 934 spin_unlock_irq(&ohci->lock);
@@ -828,27 +956,6 @@ static int ohci_restart (struct ohci_hcd *ohci)
828 956
829/*-------------------------------------------------------------------------*/ 957/*-------------------------------------------------------------------------*/
830 958
831/* NEC workaround */
832static void ohci_quirk_nec_worker(struct work_struct *work)
833{
834 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
835 int status;
836
837 status = ohci_init(ohci);
838 if (status != 0) {
839 ohci_err(ohci, "Restarting NEC controller failed "
840 "in ohci_init, %d\n", status);
841 return;
842 }
843
844 status = ohci_restart(ohci);
845 if (status != 0)
846 ohci_err(ohci, "Restarting NEC controller failed "
847 "in ohci_restart, %d\n", status);
848}
849
850/*-------------------------------------------------------------------------*/
851
852#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC 959#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
853 960
854MODULE_AUTHOR (DRIVER_AUTHOR); 961MODULE_AUTHOR (DRIVER_AUTHOR);
@@ -926,11 +1033,17 @@ MODULE_LICENSE ("GPL");
926#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 1033#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
927#endif 1034#endif
928 1035
1036#ifdef CONFIG_USB_OHCI_HCD_SSB
1037#include "ohci-ssb.c"
1038#define SSB_OHCI_DRIVER ssb_ohci_driver
1039#endif
1040
929#if !defined(PCI_DRIVER) && \ 1041#if !defined(PCI_DRIVER) && \
930 !defined(PLATFORM_DRIVER) && \ 1042 !defined(PLATFORM_DRIVER) && \
931 !defined(OF_PLATFORM_DRIVER) && \ 1043 !defined(OF_PLATFORM_DRIVER) && \
932 !defined(SA1111_DRIVER) && \ 1044 !defined(SA1111_DRIVER) && \
933 !defined(PS3_SYSTEM_BUS_DRIVER) 1045 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1046 !defined(SSB_OHCI_DRIVER)
934#error "missing bus glue for ohci-hcd" 1047#error "missing bus glue for ohci-hcd"
935#endif 1048#endif
936 1049
@@ -975,10 +1088,20 @@ static int __init ohci_hcd_mod_init(void)
975 goto error_pci; 1088 goto error_pci;
976#endif 1089#endif
977 1090
1091#ifdef SSB_OHCI_DRIVER
1092 retval = ssb_driver_register(&SSB_OHCI_DRIVER);
1093 if (retval)
1094 goto error_ssb;
1095#endif
1096
978 return retval; 1097 return retval;
979 1098
980 /* Error path */ 1099 /* Error path */
1100#ifdef SSB_OHCI_DRIVER
1101 error_ssb:
1102#endif
981#ifdef PCI_DRIVER 1103#ifdef PCI_DRIVER
1104 pci_unregister_driver(&PCI_DRIVER);
982 error_pci: 1105 error_pci:
983#endif 1106#endif
984#ifdef SA1111_DRIVER 1107#ifdef SA1111_DRIVER
@@ -1003,6 +1126,9 @@ module_init(ohci_hcd_mod_init);
1003 1126
1004static void __exit ohci_hcd_mod_exit(void) 1127static void __exit ohci_hcd_mod_exit(void)
1005{ 1128{
1129#ifdef SSB_OHCI_DRIVER
1130 ssb_driver_unregister(&SSB_OHCI_DRIVER);
1131#endif
1006#ifdef PCI_DRIVER 1132#ifdef PCI_DRIVER
1007 pci_unregister_driver(&PCI_DRIVER); 1133 pci_unregister_driver(&PCI_DRIVER);
1008#endif 1134#endif
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index 450c7b460c5a..2f20d3dc895b 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -28,7 +28,6 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
28 ohci->next_statechange = jiffies; 28 ohci->next_statechange = jiffies;
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_WORK (&ohci->nec_work, ohci_quirk_nec_worker);
32} 31}
33 32
34/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index a5e2eb85d073..d0360f65ebd9 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -84,7 +84,7 @@ static int ohci_quirk_zfmicro(struct usb_hcd *hcd)
84 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 84 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
85 85
86 ohci->flags |= OHCI_QUIRK_ZFMICRO; 86 ohci->flags |= OHCI_QUIRK_ZFMICRO;
87 ohci_dbg (ohci, "enabled Compaq ZFMicro chipset quirk\n"); 87 ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n");
88 88
89 return 0; 89 return 0;
90} 90}
@@ -113,11 +113,31 @@ static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd)
113 113
114/* Check for NEC chip and apply quirk for allegedly lost interrupts. 114/* Check for NEC chip and apply quirk for allegedly lost interrupts.
115 */ 115 */
116
117static void ohci_quirk_nec_worker(struct work_struct *work)
118{
119 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
120 int status;
121
122 status = ohci_init(ohci);
123 if (status != 0) {
124 ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
125 "ohci_init", status);
126 return;
127 }
128
129 status = ohci_restart(ohci);
130 if (status != 0)
131 ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
132 "ohci_restart", status);
133}
134
116static int ohci_quirk_nec(struct usb_hcd *hcd) 135static int ohci_quirk_nec(struct usb_hcd *hcd)
117{ 136{
118 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 137 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
119 138
120 ohci->flags |= OHCI_QUIRK_NEC; 139 ohci->flags |= OHCI_QUIRK_NEC;
140 INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker);
121 ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n"); 141 ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n");
122 142
123 return 0; 143 return 0;
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index c43b66acd4d5..0a7426920150 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -134,8 +134,11 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
134 } 134 }
135 135
136 ohci = hcd_to_ohci(hcd); 136 ohci = hcd_to_ohci(hcd);
137 if (is_bigendian) 137 if (is_bigendian) {
138 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC; 138 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
139 if (of_device_is_compatible(dn, "mpc5200-ohci"))
140 ohci->flags |= OHCI_QUIRK_FRAME_NO;
141 }
139 142
140 ohci_hcd_init(ohci); 143 ohci_hcd_init(ohci);
141 144
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 1a2e1777ca61..f95be1896b0d 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -73,6 +73,11 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
73 73
74 ohci = hcd_to_ohci(hcd); 74 ohci = hcd_to_ohci(hcd);
75 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC; 75 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
76
77#ifdef CONFIG_PPC_MPC52xx
78 /* MPC52xx doesn't need frame_no shift */
79 ohci->flags |= OHCI_QUIRK_FRAME_NO;
80#endif
76 ohci_hcd_init(ohci); 81 ohci_hcd_init(ohci);
77 82
78 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); 83 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 830a3fe8615e..51817322232b 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -36,29 +36,15 @@ static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
36 * PRECONDITION: ohci lock held, irqs blocked. 36 * PRECONDITION: ohci lock held, irqs blocked.
37 */ 37 */
38static void 38static void
39finish_urb (struct ohci_hcd *ohci, struct urb *urb) 39finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
40__releases(ohci->lock) 40__releases(ohci->lock)
41__acquires(ohci->lock) 41__acquires(ohci->lock)
42{ 42{
43 // ASSERT (urb->hcpriv != 0); 43 // ASSERT (urb->hcpriv != 0);
44 44
45 urb_free_priv (ohci, urb->hcpriv); 45 urb_free_priv (ohci, urb->hcpriv);
46 urb->hcpriv = NULL; 46 if (likely(status == -EINPROGRESS))
47 47 status = 0;
48 spin_lock (&urb->lock);
49 if (likely (urb->status == -EINPROGRESS))
50 urb->status = 0;
51 /* report short control reads right even though the data TD always
52 * has TD_R set. (much simpler, but creates the 1-td limit.)
53 */
54 if (unlikely (urb->transfer_flags & URB_SHORT_NOT_OK)
55 && unlikely (usb_pipecontrol (urb->pipe))
56 && urb->actual_length < urb->transfer_buffer_length
57 && usb_pipein (urb->pipe)
58 && urb->status == 0) {
59 urb->status = -EREMOTEIO;
60 }
61 spin_unlock (&urb->lock);
62 48
63 switch (usb_pipetype (urb->pipe)) { 49 switch (usb_pipetype (urb->pipe)) {
64 case PIPE_ISOCHRONOUS: 50 case PIPE_ISOCHRONOUS:
@@ -70,12 +56,13 @@ __acquires(ohci->lock)
70 } 56 }
71 57
72#ifdef OHCI_VERBOSE_DEBUG 58#ifdef OHCI_VERBOSE_DEBUG
73 urb_print (urb, "RET", usb_pipeout (urb->pipe)); 59 urb_print(urb, "RET", usb_pipeout (urb->pipe), status);
74#endif 60#endif
75 61
76 /* urb->complete() can reenter this HCD */ 62 /* urb->complete() can reenter this HCD */
63 usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb);
77 spin_unlock (&ohci->lock); 64 spin_unlock (&ohci->lock);
78 usb_hcd_giveback_urb (ohci_to_hcd(ohci), urb); 65 usb_hcd_giveback_urb(ohci_to_hcd(ohci), urb, status);
79 spin_lock (&ohci->lock); 66 spin_lock (&ohci->lock);
80 67
81 /* stop periodic dma if it's not needed */ 68 /* stop periodic dma if it's not needed */
@@ -179,6 +166,10 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
179 ed->ed_prev = NULL; 166 ed->ed_prev = NULL;
180 ed->ed_next = NULL; 167 ed->ed_next = NULL;
181 ed->hwNextED = 0; 168 ed->hwNextED = 0;
169 if (quirk_zfmicro(ohci)
170 && (ed->type == PIPE_INTERRUPT)
171 && !(ohci->eds_scheduled++))
172 mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
182 wmb (); 173 wmb ();
183 174
184 /* we care about rm_list when setting CLE/BLE in case the HC was at 175 /* we care about rm_list when setting CLE/BLE in case the HC was at
@@ -708,19 +699,18 @@ static void td_submit_urb (
708 * Done List handling functions 699 * Done List handling functions
709 *-------------------------------------------------------------------------*/ 700 *-------------------------------------------------------------------------*/
710 701
711/* calculate transfer length/status and update the urb 702/* calculate transfer length/status and update the urb */
712 * PRECONDITION: irqsafe (only for urb->status locking) 703static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td)
713 */
714static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
715{ 704{
716 u32 tdINFO = hc32_to_cpup (ohci, &td->hwINFO); 705 u32 tdINFO = hc32_to_cpup (ohci, &td->hwINFO);
717 int cc = 0; 706 int cc = 0;
707 int status = -EINPROGRESS;
718 708
719 list_del (&td->td_list); 709 list_del (&td->td_list);
720 710
721 /* ISO ... drivers see per-TD length/status */ 711 /* ISO ... drivers see per-TD length/status */
722 if (tdINFO & TD_ISO) { 712 if (tdINFO & TD_ISO) {
723 u16 tdPSW = ohci_hwPSW (ohci, td, 0); 713 u16 tdPSW = ohci_hwPSW(ohci, td, 0);
724 int dlen = 0; 714 int dlen = 0;
725 715
726 /* NOTE: assumes FC in tdINFO == 0, and that 716 /* NOTE: assumes FC in tdINFO == 0, and that
@@ -729,7 +719,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
729 719
730 cc = (tdPSW >> 12) & 0xF; 720 cc = (tdPSW >> 12) & 0xF;
731 if (tdINFO & TD_CC) /* hc didn't touch? */ 721 if (tdINFO & TD_CC) /* hc didn't touch? */
732 return; 722 return status;
733 723
734 if (usb_pipeout (urb->pipe)) 724 if (usb_pipeout (urb->pipe))
735 dlen = urb->iso_frame_desc [td->index].length; 725 dlen = urb->iso_frame_desc [td->index].length;
@@ -762,12 +752,8 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
762 if (cc == TD_DATAUNDERRUN 752 if (cc == TD_DATAUNDERRUN
763 && !(urb->transfer_flags & URB_SHORT_NOT_OK)) 753 && !(urb->transfer_flags & URB_SHORT_NOT_OK))
764 cc = TD_CC_NOERROR; 754 cc = TD_CC_NOERROR;
765 if (cc != TD_CC_NOERROR && cc < 0x0E) { 755 if (cc != TD_CC_NOERROR && cc < 0x0E)
766 spin_lock (&urb->lock); 756 status = cc_to_error[cc];
767 if (urb->status == -EINPROGRESS)
768 urb->status = cc_to_error [cc];
769 spin_unlock (&urb->lock);
770 }
771 757
772 /* count all non-empty packets except control SETUP packet */ 758 /* count all non-empty packets except control SETUP packet */
773 if ((type != PIPE_CONTROL || td->index != 0) && tdBE != 0) { 759 if ((type != PIPE_CONTROL || td->index != 0) && tdBE != 0) {
@@ -786,14 +772,15 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
786 urb->actual_length, 772 urb->actual_length,
787 urb->transfer_buffer_length); 773 urb->transfer_buffer_length);
788 } 774 }
775 return status;
789} 776}
790 777
791/*-------------------------------------------------------------------------*/ 778/*-------------------------------------------------------------------------*/
792 779
793static inline struct td * 780static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc)
794ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
795{ 781{
796 struct urb *urb = td->urb; 782 struct urb *urb = td->urb;
783 urb_priv_t *urb_priv = urb->hcpriv;
797 struct ed *ed = td->ed; 784 struct ed *ed = td->ed;
798 struct list_head *tmp = td->td_list.next; 785 struct list_head *tmp = td->td_list.next;
799 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C); 786 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
@@ -805,13 +792,12 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
805 wmb (); 792 wmb ();
806 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H); 793 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H);
807 794
808 /* put any later tds from this urb onto the donelist, after 'td', 795 /* Get rid of all later tds from this urb. We don't have
809 * order won't matter here: no errors, and nothing was transferred. 796 * to be careful: no errors and nothing was transferred.
810 * also patch the ed so it looks as if those tds completed normally. 797 * Also patch the ed so it looks as if those tds completed normally.
811 */ 798 */
812 while (tmp != &ed->td_list) { 799 while (tmp != &ed->td_list) {
813 struct td *next; 800 struct td *next;
814 __hc32 info;
815 801
816 next = list_entry (tmp, struct td, td_list); 802 next = list_entry (tmp, struct td, td_list);
817 tmp = next->td_list.next; 803 tmp = next->td_list.next;
@@ -826,14 +812,9 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
826 * then we need to leave the control STATUS packet queued 812 * then we need to leave the control STATUS packet queued
827 * and clear ED_SKIP. 813 * and clear ED_SKIP.
828 */ 814 */
829 info = next->hwINFO;
830 info |= cpu_to_hc32 (ohci, TD_DONE);
831 info &= ~cpu_to_hc32 (ohci, TD_CC);
832 next->hwINFO = info;
833
834 next->next_dl_td = rev;
835 rev = next;
836 815
816 list_del(&next->td_list);
817 urb_priv->td_cnt++;
837 ed->hwHeadP = next->hwNextTD | toggle; 818 ed->hwHeadP = next->hwNextTD | toggle;
838 } 819 }
839 820
@@ -859,8 +840,6 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
859 hc32_to_cpu (ohci, td->hwINFO), 840 hc32_to_cpu (ohci, td->hwINFO),
860 cc, cc_to_error [cc]); 841 cc, cc_to_error [cc]);
861 } 842 }
862
863 return rev;
864} 843}
865 844
866/* replies to the request have to be on a FIFO basis so 845/* replies to the request have to be on a FIFO basis so
@@ -897,7 +876,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
897 */ 876 */
898 if (cc != TD_CC_NOERROR 877 if (cc != TD_CC_NOERROR
899 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) 878 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
900 td_rev = ed_halted (ohci, td, cc, td_rev); 879 ed_halted(ohci, td, cc);
901 880
902 td->next_dl_td = td_rev; 881 td->next_dl_td = td_rev;
903 td_rev = td; 882 td_rev = td;
@@ -940,8 +919,12 @@ skip_ed:
940 TD_MASK; 919 TD_MASK;
941 920
942 /* INTR_WDH may need to clean up first */ 921 /* INTR_WDH may need to clean up first */
943 if (td->td_dma != head) 922 if (td->td_dma != head) {
944 goto skip_ed; 923 if (ed == ohci->ed_to_check)
924 ohci->ed_to_check = NULL;
925 else
926 goto skip_ed;
927 }
945 } 928 }
946 } 929 }
947 930
@@ -974,7 +957,7 @@ rescan_this:
974 urb = td->urb; 957 urb = td->urb;
975 urb_priv = td->urb->hcpriv; 958 urb_priv = td->urb->hcpriv;
976 959
977 if (urb->status == -EINPROGRESS) { 960 if (!urb->unlinked) {
978 prev = &td->hwNextTD; 961 prev = &td->hwNextTD;
979 continue; 962 continue;
980 } 963 }
@@ -990,7 +973,7 @@ rescan_this:
990 /* if URB is done, clean up */ 973 /* if URB is done, clean up */
991 if (urb_priv->td_cnt == urb_priv->length) { 974 if (urb_priv->td_cnt == urb_priv->length) {
992 modified = completed = 1; 975 modified = completed = 1;
993 finish_urb (ohci, urb); 976 finish_urb(ohci, urb, 0);
994 } 977 }
995 } 978 }
996 if (completed && !list_empty (&ed->td_list)) 979 if (completed && !list_empty (&ed->td_list))
@@ -998,6 +981,8 @@ rescan_this:
998 981
999 /* ED's now officially unlinked, hc doesn't see */ 982 /* ED's now officially unlinked, hc doesn't see */
1000 ed->state = ED_IDLE; 983 ed->state = ED_IDLE;
984 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
985 ohci->eds_scheduled--;
1001 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H); 986 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
1002 ed->hwNextED = 0; 987 ed->hwNextED = 0;
1003 wmb (); 988 wmb ();
@@ -1021,7 +1006,7 @@ rescan_this:
1021 1006
1022 if (ohci->ed_controltail) { 1007 if (ohci->ed_controltail) {
1023 command |= OHCI_CLF; 1008 command |= OHCI_CLF;
1024 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1009 if (quirk_zfmicro(ohci))
1025 mdelay(1); 1010 mdelay(1);
1026 if (!(ohci->hc_control & OHCI_CTRL_CLE)) { 1011 if (!(ohci->hc_control & OHCI_CTRL_CLE)) {
1027 control |= OHCI_CTRL_CLE; 1012 control |= OHCI_CTRL_CLE;
@@ -1031,7 +1016,7 @@ rescan_this:
1031 } 1016 }
1032 if (ohci->ed_bulktail) { 1017 if (ohci->ed_bulktail) {
1033 command |= OHCI_BLF; 1018 command |= OHCI_BLF;
1034 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1019 if (quirk_zfmicro(ohci))
1035 mdelay(1); 1020 mdelay(1);
1036 if (!(ohci->hc_control & OHCI_CTRL_BLE)) { 1021 if (!(ohci->hc_control & OHCI_CTRL_BLE)) {
1037 control |= OHCI_CTRL_BLE; 1022 control |= OHCI_CTRL_BLE;
@@ -1043,13 +1028,13 @@ rescan_this:
1043 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */ 1028 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
1044 if (control) { 1029 if (control) {
1045 ohci->hc_control |= control; 1030 ohci->hc_control |= control;
1046 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1031 if (quirk_zfmicro(ohci))
1047 mdelay(1); 1032 mdelay(1);
1048 ohci_writel (ohci, ohci->hc_control, 1033 ohci_writel (ohci, ohci->hc_control,
1049 &ohci->regs->control); 1034 &ohci->regs->control);
1050 } 1035 }
1051 if (command) { 1036 if (command) {
1052 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1037 if (quirk_zfmicro(ohci))
1053 mdelay(1); 1038 mdelay(1);
1054 ohci_writel (ohci, command, &ohci->regs->cmdstatus); 1039 ohci_writel (ohci, command, &ohci->regs->cmdstatus);
1055 } 1040 }
@@ -1061,11 +1046,60 @@ rescan_this:
1061/*-------------------------------------------------------------------------*/ 1046/*-------------------------------------------------------------------------*/
1062 1047
1063/* 1048/*
1049 * Used to take back a TD from the host controller. This would normally be
1050 * called from within dl_done_list, however it may be called directly if the
1051 * HC no longer sees the TD and it has not appeared on the donelist (after
1052 * two frames). This bug has been observed on ZF Micro systems.
1053 */
1054static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1055{
1056 struct urb *urb = td->urb;
1057 urb_priv_t *urb_priv = urb->hcpriv;
1058 struct ed *ed = td->ed;
1059 int status;
1060
1061 /* update URB's length and status from TD */
1062 status = td_done(ohci, urb, td);
1063 urb_priv->td_cnt++;
1064
1065 /* If all this urb's TDs are done, call complete() */
1066 if (urb_priv->td_cnt == urb_priv->length)
1067 finish_urb(ohci, urb, status);
1068
1069 /* clean schedule: unlink EDs that are no longer busy */
1070 if (list_empty(&ed->td_list)) {
1071 if (ed->state == ED_OPER)
1072 start_ed_unlink(ohci, ed);
1073
1074 /* ... reenabling halted EDs only after fault cleanup */
1075 } else if ((ed->hwINFO & cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE))
1076 == cpu_to_hc32(ohci, ED_SKIP)) {
1077 td = list_entry(ed->td_list.next, struct td, td_list);
1078 if (!(td->hwINFO & cpu_to_hc32(ohci, TD_DONE))) {
1079 ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP);
1080 /* ... hc may need waking-up */
1081 switch (ed->type) {
1082 case PIPE_CONTROL:
1083 ohci_writel(ohci, OHCI_CLF,
1084 &ohci->regs->cmdstatus);
1085 break;
1086 case PIPE_BULK:
1087 ohci_writel(ohci, OHCI_BLF,
1088 &ohci->regs->cmdstatus);
1089 break;
1090 }
1091 }
1092 }
1093}
1094
1095/*
1064 * Process normal completions (error or success) and clean the schedules. 1096 * Process normal completions (error or success) and clean the schedules.
1065 * 1097 *
1066 * This is the main path for handing urbs back to drivers. The only other 1098 * This is the main path for handing urbs back to drivers. The only other
1067 * path is finish_unlinks(), which unlinks URBs using ed_rm_list, instead of 1099 * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list,
1068 * scanning the (re-reversed) donelist as this does. 1100 * instead of scanning the (re-reversed) donelist as this does. There's
1101 * an abnormal path too, handling a quirk in some Compaq silicon: URBs
1102 * with TDs that appear to be orphaned are directly reclaimed.
1069 */ 1103 */
1070static void 1104static void
1071dl_done_list (struct ohci_hcd *ohci) 1105dl_done_list (struct ohci_hcd *ohci)
@@ -1074,44 +1108,7 @@ dl_done_list (struct ohci_hcd *ohci)
1074 1108
1075 while (td) { 1109 while (td) {
1076 struct td *td_next = td->next_dl_td; 1110 struct td *td_next = td->next_dl_td;
1077 struct urb *urb = td->urb; 1111 takeback_td(ohci, td);
1078 urb_priv_t *urb_priv = urb->hcpriv;
1079 struct ed *ed = td->ed;
1080
1081 /* update URB's length and status from TD */
1082 td_done (ohci, urb, td);
1083 urb_priv->td_cnt++;
1084
1085 /* If all this urb's TDs are done, call complete() */
1086 if (urb_priv->td_cnt == urb_priv->length)
1087 finish_urb (ohci, urb);
1088
1089 /* clean schedule: unlink EDs that are no longer busy */
1090 if (list_empty (&ed->td_list)) {
1091 if (ed->state == ED_OPER)
1092 start_ed_unlink (ohci, ed);
1093
1094 /* ... reenabling halted EDs only after fault cleanup */
1095 } else if ((ed->hwINFO & cpu_to_hc32 (ohci,
1096 ED_SKIP | ED_DEQUEUE))
1097 == cpu_to_hc32 (ohci, ED_SKIP)) {
1098 td = list_entry (ed->td_list.next, struct td, td_list);
1099 if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
1100 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP);
1101 /* ... hc may need waking-up */
1102 switch (ed->type) {
1103 case PIPE_CONTROL:
1104 ohci_writel (ohci, OHCI_CLF,
1105 &ohci->regs->cmdstatus);
1106 break;
1107 case PIPE_BULK:
1108 ohci_writel (ohci, OHCI_BLF,
1109 &ohci->regs->cmdstatus);
1110 break;
1111 }
1112 }
1113 }
1114
1115 td = td_next; 1112 td = td_next;
1116 } 1113 }
1117} 1114}
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
new file mode 100644
index 000000000000..bc3e785d8c00
--- /dev/null
+++ b/drivers/usb/host/ohci-ssb.c
@@ -0,0 +1,247 @@
1/*
2 * Sonics Silicon Backplane
3 * Broadcom USB-core OHCI driver
4 *
5 * Copyright 2007 Michael Buesch <mb@bu3sch.de>
6 *
7 * Derived from the OHCI-PCI driver
8 * Copyright 1999 Roman Weissgaerber
9 * Copyright 2000-2002 David Brownell
10 * Copyright 1999 Linus Torvalds
11 * Copyright 1999 Gregory P. Smith
12 *
13 * Derived from the USBcore related parts of Broadcom-SB
14 * Copyright 2005 Broadcom Corporation
15 *
16 * Licensed under the GNU/GPL. See COPYING for details.
17 */
18#include <linux/ssb/ssb.h>
19
20
21#define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
22
23struct ssb_ohci_device {
24 struct ohci_hcd ohci; /* _must_ be at the beginning. */
25
26 u32 enable_flags;
27};
28
29static inline
30struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
31{
32 return (struct ssb_ohci_device *)(hcd->hcd_priv);
33}
34
35
36static int ssb_ohci_reset(struct usb_hcd *hcd)
37{
38 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
39 struct ohci_hcd *ohci = &ohcidev->ohci;
40 int err;
41
42 ohci_hcd_init(ohci);
43 err = ohci_init(ohci);
44
45 return err;
46}
47
48static int ssb_ohci_start(struct usb_hcd *hcd)
49{
50 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
51 struct ohci_hcd *ohci = &ohcidev->ohci;
52 int err;
53
54 err = ohci_run(ohci);
55 if (err < 0) {
56 ohci_err(ohci, "can't start\n");
57 ohci_stop(hcd);
58 }
59
60 return err;
61}
62
63#ifdef CONFIG_PM
64static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
65{
66 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
67 struct ohci_hcd *ohci = &ohcidev->ohci;
68 unsigned long flags;
69
70 spin_lock_irqsave(&ohci->lock, flags);
71
72 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
73 ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
74
75 /* make sure snapshot being resumed re-enumerates everything */
76 if (message.event == PM_EVENT_PRETHAW)
77 ohci_usb_reset(ohci);
78
79 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
80
81 spin_unlock_irqrestore(&ohci->lock, flags);
82 return 0;
83}
84
85static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
86{
87 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
88 usb_hcd_resume_root_hub(hcd);
89 return 0;
90}
91#endif /* CONFIG_PM */
92
93static const struct hc_driver ssb_ohci_hc_driver = {
94 .description = "ssb-usb-ohci",
95 .product_desc = "SSB OHCI Controller",
96 .hcd_priv_size = sizeof(struct ssb_ohci_device),
97
98 .irq = ohci_irq,
99 .flags = HCD_MEMORY | HCD_USB11,
100
101 .reset = ssb_ohci_reset,
102 .start = ssb_ohci_start,
103 .stop = ohci_stop,
104 .shutdown = ohci_shutdown,
105
106#ifdef CONFIG_PM
107 .suspend = ssb_ohci_hcd_suspend,
108 .resume = ssb_ohci_hcd_resume,
109#endif
110
111 .urb_enqueue = ohci_urb_enqueue,
112 .urb_dequeue = ohci_urb_dequeue,
113 .endpoint_disable = ohci_endpoint_disable,
114
115 .get_frame_number = ohci_get_frame,
116
117 .hub_status_data = ohci_hub_status_data,
118 .hub_control = ohci_hub_control,
119 .hub_irq_enable = ohci_rhsc_enable,
120 .bus_suspend = ohci_bus_suspend,
121 .bus_resume = ohci_bus_resume,
122
123 .start_port_reset = ohci_start_port_reset,
124};
125
126static void ssb_ohci_detach(struct ssb_device *dev)
127{
128 struct usb_hcd *hcd = ssb_get_drvdata(dev);
129
130 usb_remove_hcd(hcd);
131 iounmap(hcd->regs);
132 usb_put_hcd(hcd);
133 ssb_device_disable(dev, 0);
134}
135
136static int ssb_ohci_attach(struct ssb_device *dev)
137{
138 struct ssb_ohci_device *ohcidev;
139 struct usb_hcd *hcd;
140 int err = -ENOMEM;
141 u32 tmp, flags = 0;
142
143 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
144 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
145
146 ssb_device_enable(dev, flags);
147
148 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
149 dev->dev->bus_id);
150 if (!hcd)
151 goto err_dev_disable;
152 ohcidev = hcd_to_ssb_ohci(hcd);
153 ohcidev->enable_flags = flags;
154
155 tmp = ssb_read32(dev, SSB_ADMATCH0);
156 hcd->rsrc_start = ssb_admatch_base(tmp);
157 hcd->rsrc_len = ssb_admatch_size(tmp);
158 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
159 if (!hcd->regs)
160 goto err_put_hcd;
161 err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
162 if (err)
163 goto err_iounmap;
164
165 ssb_set_drvdata(dev, hcd);
166
167 return err;
168
169err_iounmap:
170 iounmap(hcd->regs);
171err_put_hcd:
172 usb_put_hcd(hcd);
173err_dev_disable:
174 ssb_device_disable(dev, flags);
175 return err;
176}
177
178static int ssb_ohci_probe(struct ssb_device *dev,
179 const struct ssb_device_id *id)
180{
181 int err;
182 u16 chipid_top;
183
184 /* USBcores are only connected on embedded devices. */
185 chipid_top = (dev->bus->chip_id & 0xFF00);
186 if (chipid_top != 0x4700 && chipid_top != 0x5300)
187 return -ENODEV;
188
189 /* TODO: Probably need checks here; is the core connected? */
190
191 if (usb_disabled())
192 return -ENODEV;
193
194 /* We currently always attach SSB_DEV_USB11_HOSTDEV
195 * as HOST OHCI. If we want to attach it as Client device,
196 * we must branch here and call into the (yet to
197 * be written) Client mode driver. Same for remove(). */
198
199 err = ssb_ohci_attach(dev);
200
201 return err;
202}
203
204static void ssb_ohci_remove(struct ssb_device *dev)
205{
206 ssb_ohci_detach(dev);
207}
208
209#ifdef CONFIG_PM
210
211static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
212{
213 ssb_device_disable(dev, 0);
214
215 return 0;
216}
217
218static int ssb_ohci_resume(struct ssb_device *dev)
219{
220 struct usb_hcd *hcd = ssb_get_drvdata(dev);
221 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
222
223 ssb_device_enable(dev, ohcidev->enable_flags);
224
225 return 0;
226}
227
228#else /* !CONFIG_PM */
229#define ssb_ohci_suspend NULL
230#define ssb_ohci_resume NULL
231#endif /* CONFIG_PM */
232
233static const struct ssb_device_id ssb_ohci_table[] = {
234 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
235 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
236 SSB_DEVTABLE_END
237};
238MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
239
240static struct ssb_driver ssb_ohci_driver = {
241 .name = KBUILD_MODNAME,
242 .id_table = ssb_ohci_table,
243 .probe = ssb_ohci_probe,
244 .remove = ssb_ohci_remove,
245 .suspend = ssb_ohci_suspend,
246 .resume = ssb_ohci_resume,
247};
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 4ada43cf1387..47c5c66a282c 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -398,11 +398,38 @@ struct ohci_hcd {
398#define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */ 398#define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */
399#define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/ 399#define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/
400#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ 400#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */
401#define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */
401 // there are also chip quirks/bugs in init logic 402 // there are also chip quirks/bugs in init logic
402 403
403 struct work_struct nec_work; /* Worker for NEC quirk */ 404 struct work_struct nec_work; /* Worker for NEC quirk */
405
406 /* Needed for ZF Micro quirk */
407 struct timer_list unlink_watchdog;
408 unsigned eds_scheduled;
409 struct ed *ed_to_check;
410 unsigned zf_delay;
404}; 411};
405 412
413#ifdef CONFIG_PCI
414static inline int quirk_nec(struct ohci_hcd *ohci)
415{
416 return ohci->flags & OHCI_QUIRK_NEC;
417}
418static inline int quirk_zfmicro(struct ohci_hcd *ohci)
419{
420 return ohci->flags & OHCI_QUIRK_ZFMICRO;
421}
422#else
423static inline int quirk_nec(struct ohci_hcd *ohci)
424{
425 return 0;
426}
427static inline int quirk_zfmicro(struct ohci_hcd *ohci)
428{
429 return 0;
430}
431#endif
432
406/* convert between an hcd pointer and the corresponding ohci_hcd */ 433/* convert between an hcd pointer and the corresponding ohci_hcd */
407static inline struct ohci_hcd *hcd_to_ohci (struct usb_hcd *hcd) 434static inline struct ohci_hcd *hcd_to_ohci (struct usb_hcd *hcd)
408{ 435{
@@ -607,15 +634,12 @@ static inline u32 hc32_to_cpup (const struct ohci_hcd *ohci, const __hc32 *x)
607/* HCCA frame number is 16 bits, but is accessed as 32 bits since not all 634/* HCCA frame number is 16 bits, but is accessed as 32 bits since not all
608 * hardware handles 16 bit reads. That creates a different confusion on 635 * hardware handles 16 bit reads. That creates a different confusion on
609 * some big-endian SOC implementations. Same thing happens with PSW access. 636 * some big-endian SOC implementations. Same thing happens with PSW access.
610 *
611 * FIXME: Deal with that as a runtime quirk when STB03xxx is ported over
612 * to arch/powerpc
613 */ 637 */
614 638
615#ifdef CONFIG_STB03xxx 639#ifdef CONFIG_PPC_MPC52xx
616#define OHCI_BE_FRAME_NO_SHIFT 16 640#define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
617#else 641#else
618#define OHCI_BE_FRAME_NO_SHIFT 0 642#define big_endian_frame_no_quirk(ohci) 0
619#endif 643#endif
620 644
621static inline u16 ohci_frame_no(const struct ohci_hcd *ohci) 645static inline u16 ohci_frame_no(const struct ohci_hcd *ohci)
@@ -623,7 +647,8 @@ static inline u16 ohci_frame_no(const struct ohci_hcd *ohci)
623 u32 tmp; 647 u32 tmp;
624 if (big_endian_desc(ohci)) { 648 if (big_endian_desc(ohci)) {
625 tmp = be32_to_cpup((__force __be32 *)&ohci->hcca->frame_no); 649 tmp = be32_to_cpup((__force __be32 *)&ohci->hcca->frame_no);
626 tmp >>= OHCI_BE_FRAME_NO_SHIFT; 650 if (!big_endian_frame_no_quirk(ohci))
651 tmp >>= 16;
627 } else 652 } else
628 tmp = le32_to_cpup((__force __le32 *)&ohci->hcca->frame_no); 653 tmp = le32_to_cpup((__force __le32 *)&ohci->hcca->frame_no);
629 654
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 40a1de4c256e..ae8ec4474eb8 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -782,10 +782,12 @@ static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
782 kfree(td); 782 kfree(td);
783 783
784 if (urb) { 784 if (urb) {
785 urb->status = -ENODEV; 785 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597),
786 urb->hcpriv = NULL; 786 urb);
787
787 spin_unlock(&r8a66597->lock); 788 spin_unlock(&r8a66597->lock);
788 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb); 789 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb,
790 -ENODEV);
789 spin_lock(&r8a66597->lock); 791 spin_lock(&r8a66597->lock);
790 } 792 }
791 break; 793 break;
@@ -832,7 +834,7 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
832 info.pipenum = get_empty_pipenum(r8a66597, ep); 834 info.pipenum = get_empty_pipenum(r8a66597, ep);
833 info.address = get_urb_to_r8a66597_addr(r8a66597, urb); 835 info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
834 info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 836 info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
835 info.maxpacket = ep->wMaxPacketSize; 837 info.maxpacket = le16_to_cpu(ep->wMaxPacketSize);
836 info.type = get_r8a66597_type(ep->bmAttributes 838 info.type = get_r8a66597_type(ep->bmAttributes
837 & USB_ENDPOINT_XFERTYPE_MASK); 839 & USB_ENDPOINT_XFERTYPE_MASK);
838 info.bufnum = get_bufnum(info.pipenum); 840 info.bufnum = get_bufnum(info.pipenum);
@@ -923,7 +925,7 @@ static void prepare_setup_packet(struct r8a66597 *r8a66597,
923 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1); 925 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
924 926
925 for (i = 0; i < 4; i++) { 927 for (i = 0; i < 4; i++) {
926 r8a66597_write(r8a66597, p[i], setup_addr); 928 r8a66597_write(r8a66597, cpu_to_le16(p[i]), setup_addr);
927 setup_addr += 2; 929 setup_addr += 2;
928 } 930 }
929 r8a66597_write(r8a66597, SUREQ, DCPCTR); 931 r8a66597_write(r8a66597, SUREQ, DCPCTR);
@@ -1032,6 +1034,15 @@ static void prepare_status_packet(struct r8a66597 *r8a66597,
1032 pipe_start(r8a66597, td->pipe); 1034 pipe_start(r8a66597, td->pipe);
1033} 1035}
1034 1036
1037static int is_set_address(unsigned char *setup_packet)
1038{
1039 if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) &&
1040 setup_packet[1] == USB_REQ_SET_ADDRESS)
1041 return 1;
1042 else
1043 return 0;
1044}
1045
1035/* this function must be called with interrupt disabled */ 1046/* this function must be called with interrupt disabled */
1036static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td) 1047static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1037{ 1048{
@@ -1039,7 +1050,7 @@ static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1039 1050
1040 switch (td->type) { 1051 switch (td->type) {
1041 case USB_PID_SETUP: 1052 case USB_PID_SETUP:
1042 if (td->urb->setup_packet[1] == USB_REQ_SET_ADDRESS) { 1053 if (is_set_address(td->urb->setup_packet)) {
1043 td->set_address = 1; 1054 td->set_address = 1;
1044 td->urb->setup_packet[2] = alloc_usb_address(r8a66597, 1055 td->urb->setup_packet[2] = alloc_usb_address(r8a66597,
1045 td->urb); 1056 td->urb);
@@ -1106,8 +1117,9 @@ static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1106} 1117}
1107 1118
1108/* this function must be called with interrupt disabled */ 1119/* this function must be called with interrupt disabled */
1109static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td, 1120static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1110 u16 pipenum, struct urb *urb) 1121 u16 pipenum, struct urb *urb, int status)
1122__releases(r8a66597->lock) __acquires(r8a66597->lock)
1111{ 1123{
1112 int restart = 0; 1124 int restart = 0;
1113 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); 1125 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
@@ -1115,7 +1127,7 @@ static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1115 r8a66597->timeout_map &= ~(1 << pipenum); 1127 r8a66597->timeout_map &= ~(1 << pipenum);
1116 1128
1117 if (likely(td)) { 1129 if (likely(td)) {
1118 if (td->set_address && urb->status != 0) 1130 if (td->set_address && (status != 0 || urb->unlinked))
1119 r8a66597->address_map &= ~(1 << urb->setup_packet[2]); 1131 r8a66597->address_map &= ~(1 << urb->setup_packet[2]);
1120 1132
1121 pipe_toggle_save(r8a66597, td->pipe, urb); 1133 pipe_toggle_save(r8a66597, td->pipe, urb);
@@ -1130,9 +1142,9 @@ static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1130 if (usb_pipeisoc(urb->pipe)) 1142 if (usb_pipeisoc(urb->pipe))
1131 urb->start_frame = r8a66597_get_frame(hcd); 1143 urb->start_frame = r8a66597_get_frame(hcd);
1132 1144
1133 urb->hcpriv = NULL; 1145 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
1134 spin_unlock(&r8a66597->lock); 1146 spin_unlock(&r8a66597->lock);
1135 usb_hcd_giveback_urb(hcd, urb); 1147 usb_hcd_giveback_urb(hcd, urb, status);
1136 spin_lock(&r8a66597->lock); 1148 spin_lock(&r8a66597->lock);
1137 } 1149 }
1138 1150
@@ -1146,14 +1158,6 @@ static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1146 } 1158 }
1147} 1159}
1148 1160
1149/* this function must be called with interrupt disabled */
1150static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1151 u16 pipenum, struct urb *urb)
1152__releases(r8a66597->lock) __acquires(r8a66597->lock)
1153{
1154 done(r8a66597, td, pipenum, urb);
1155}
1156
1157static void packet_read(struct r8a66597 *r8a66597, u16 pipenum) 1161static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1158{ 1162{
1159 u16 tmp; 1163 u16 tmp;
@@ -1162,6 +1166,7 @@ static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1162 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); 1166 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1163 struct urb *urb; 1167 struct urb *urb;
1164 int finish = 0; 1168 int finish = 0;
1169 int status = 0;
1165 1170
1166 if (unlikely(!td)) 1171 if (unlikely(!td))
1167 return; 1172 return;
@@ -1170,17 +1175,15 @@ static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1170 fifo_change_from_pipe(r8a66597, td->pipe); 1175 fifo_change_from_pipe(r8a66597, td->pipe);
1171 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); 1176 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1172 if (unlikely((tmp & FRDY) == 0)) { 1177 if (unlikely((tmp & FRDY) == 0)) {
1173 urb->status = -EPIPE;
1174 pipe_stop(r8a66597, td->pipe); 1178 pipe_stop(r8a66597, td->pipe);
1175 pipe_irq_disable(r8a66597, pipenum); 1179 pipe_irq_disable(r8a66597, pipenum);
1176 err("in fifo not ready (%d)", pipenum); 1180 err("in fifo not ready (%d)", pipenum);
1177 finish_request(r8a66597, td, pipenum, td->urb); 1181 finish_request(r8a66597, td, pipenum, td->urb, -EPIPE);
1178 return; 1182 return;
1179 } 1183 }
1180 1184
1181 /* prepare parameters */ 1185 /* prepare parameters */
1182 rcv_len = tmp & DTLN; 1186 rcv_len = tmp & DTLN;
1183 bufsize = td->maxpacket;
1184 if (usb_pipeisoc(urb->pipe)) { 1187 if (usb_pipeisoc(urb->pipe)) {
1185 buf = (u16 *)(urb->transfer_buffer + 1188 buf = (u16 *)(urb->transfer_buffer +
1186 urb->iso_frame_desc[td->iso_cnt].offset); 1189 urb->iso_frame_desc[td->iso_cnt].offset);
@@ -1189,29 +1192,31 @@ static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1189 buf = (void *)urb->transfer_buffer + urb->actual_length; 1192 buf = (void *)urb->transfer_buffer + urb->actual_length;
1190 urb_len = urb->transfer_buffer_length - urb->actual_length; 1193 urb_len = urb->transfer_buffer_length - urb->actual_length;
1191 } 1194 }
1192 if (rcv_len < bufsize) 1195 bufsize = min(urb_len, (int) td->maxpacket);
1193 size = min(rcv_len, urb_len); 1196 if (rcv_len <= bufsize) {
1194 else 1197 size = rcv_len;
1195 size = min(bufsize, urb_len); 1198 } else {
1199 size = bufsize;
1200 status = -EOVERFLOW;
1201 finish = 1;
1202 }
1196 1203
1197 /* update parameters */ 1204 /* update parameters */
1198 urb->actual_length += size; 1205 urb->actual_length += size;
1199 if (rcv_len == 0) 1206 if (rcv_len == 0)
1200 td->zero_packet = 1; 1207 td->zero_packet = 1;
1201 if ((size % td->maxpacket) > 0) { 1208 if (rcv_len < bufsize) {
1202 td->short_packet = 1; 1209 td->short_packet = 1;
1203 if (urb->transfer_buffer_length != urb->actual_length &&
1204 urb->transfer_flags & URB_SHORT_NOT_OK)
1205 td->urb->status = -EREMOTEIO;
1206 } 1210 }
1207 if (usb_pipeisoc(urb->pipe)) { 1211 if (usb_pipeisoc(urb->pipe)) {
1208 urb->iso_frame_desc[td->iso_cnt].actual_length = size; 1212 urb->iso_frame_desc[td->iso_cnt].actual_length = size;
1209 urb->iso_frame_desc[td->iso_cnt].status = 0; 1213 urb->iso_frame_desc[td->iso_cnt].status = status;
1210 td->iso_cnt++; 1214 td->iso_cnt++;
1215 finish = 0;
1211 } 1216 }
1212 1217
1213 /* check transfer finish */ 1218 /* check transfer finish */
1214 if (check_transfer_finish(td, urb)) { 1219 if (finish || check_transfer_finish(td, urb)) {
1215 pipe_stop(r8a66597, td->pipe); 1220 pipe_stop(r8a66597, td->pipe);
1216 pipe_irq_disable(r8a66597, pipenum); 1221 pipe_irq_disable(r8a66597, pipenum);
1217 finish = 1; 1222 finish = 1;
@@ -1226,11 +1231,8 @@ static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1226 buf, size); 1231 buf, size);
1227 } 1232 }
1228 1233
1229 if (finish && pipenum != 0) { 1234 if (finish && pipenum != 0)
1230 if (td->urb->status == -EINPROGRESS) 1235 finish_request(r8a66597, td, pipenum, urb, status);
1231 td->urb->status = 0;
1232 finish_request(r8a66597, td, pipenum, urb);
1233 }
1234} 1236}
1235 1237
1236static void packet_write(struct r8a66597 *r8a66597, u16 pipenum) 1238static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
@@ -1248,11 +1250,10 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1248 fifo_change_from_pipe(r8a66597, td->pipe); 1250 fifo_change_from_pipe(r8a66597, td->pipe);
1249 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); 1251 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1250 if (unlikely((tmp & FRDY) == 0)) { 1252 if (unlikely((tmp & FRDY) == 0)) {
1251 urb->status = -EPIPE;
1252 pipe_stop(r8a66597, td->pipe); 1253 pipe_stop(r8a66597, td->pipe);
1253 pipe_irq_disable(r8a66597, pipenum); 1254 pipe_irq_disable(r8a66597, pipenum);
1254 err("out write fifo not ready. (%d)", pipenum); 1255 err("out write fifo not ready. (%d)", pipenum);
1255 finish_request(r8a66597, td, pipenum, td->urb); 1256 finish_request(r8a66597, td, pipenum, urb, -EPIPE);
1256 return; 1257 return;
1257 } 1258 }
1258 1259
@@ -1297,7 +1298,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1297} 1298}
1298 1299
1299 1300
1300static void check_next_phase(struct r8a66597 *r8a66597) 1301static void check_next_phase(struct r8a66597 *r8a66597, int status)
1301{ 1302{
1302 struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0); 1303 struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0);
1303 struct urb *urb; 1304 struct urb *urb;
@@ -1310,49 +1311,41 @@ static void check_next_phase(struct r8a66597 *r8a66597)
1310 switch (td->type) { 1311 switch (td->type) {
1311 case USB_PID_IN: 1312 case USB_PID_IN:
1312 case USB_PID_OUT: 1313 case USB_PID_OUT:
1313 if (urb->status != -EINPROGRESS) {
1314 finish = 1;
1315 break;
1316 }
1317 if (check_transfer_finish(td, urb)) 1314 if (check_transfer_finish(td, urb))
1318 td->type = USB_PID_ACK; 1315 td->type = USB_PID_ACK;
1319 break; 1316 break;
1320 case USB_PID_SETUP: 1317 case USB_PID_SETUP:
1321 if (urb->status != -EINPROGRESS) 1318 if (urb->transfer_buffer_length == urb->actual_length)
1322 finish = 1;
1323 else if (urb->transfer_buffer_length == urb->actual_length) {
1324 td->type = USB_PID_ACK; 1319 td->type = USB_PID_ACK;
1325 urb->status = 0; 1320 else if (usb_pipeout(urb->pipe))
1326 } else if (usb_pipeout(urb->pipe))
1327 td->type = USB_PID_OUT; 1321 td->type = USB_PID_OUT;
1328 else 1322 else
1329 td->type = USB_PID_IN; 1323 td->type = USB_PID_IN;
1330 break; 1324 break;
1331 case USB_PID_ACK: 1325 case USB_PID_ACK:
1332 finish = 1; 1326 finish = 1;
1333 if (urb->status == -EINPROGRESS)
1334 urb->status = 0;
1335 break; 1327 break;
1336 } 1328 }
1337 1329
1338 if (finish) 1330 if (finish || status != 0 || urb->unlinked)
1339 finish_request(r8a66597, td, 0, urb); 1331 finish_request(r8a66597, td, 0, urb, status);
1340 else 1332 else
1341 start_transfer(r8a66597, td); 1333 start_transfer(r8a66597, td);
1342} 1334}
1343 1335
1344static void set_urb_error(struct r8a66597 *r8a66597, u16 pipenum) 1336static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum)
1345{ 1337{
1346 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); 1338 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1347 1339
1348 if (td && td->urb) { 1340 if (td) {
1349 u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID; 1341 u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID;
1350 1342
1351 if (pid == PID_NAK) 1343 if (pid == PID_NAK)
1352 td->urb->status = -ECONNRESET; 1344 return -ECONNRESET;
1353 else 1345 else
1354 td->urb->status = -EPIPE; 1346 return -EPIPE;
1355 } 1347 }
1348 return 0;
1356} 1349}
1357 1350
1358static void irq_pipe_ready(struct r8a66597 *r8a66597) 1351static void irq_pipe_ready(struct r8a66597 *r8a66597)
@@ -1371,7 +1364,7 @@ static void irq_pipe_ready(struct r8a66597 *r8a66597)
1371 packet_read(r8a66597, 0); 1364 packet_read(r8a66597, 0);
1372 else 1365 else
1373 pipe_irq_disable(r8a66597, 0); 1366 pipe_irq_disable(r8a66597, 0);
1374 check_next_phase(r8a66597); 1367 check_next_phase(r8a66597, 0);
1375 } 1368 }
1376 1369
1377 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { 1370 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
@@ -1405,7 +1398,7 @@ static void irq_pipe_empty(struct r8a66597 *r8a66597)
1405 td = r8a66597_get_td(r8a66597, 0); 1398 td = r8a66597_get_td(r8a66597, 0);
1406 if (td && td->type != USB_PID_OUT) 1399 if (td && td->type != USB_PID_OUT)
1407 disable_irq_empty(r8a66597, 0); 1400 disable_irq_empty(r8a66597, 0);
1408 check_next_phase(r8a66597); 1401 check_next_phase(r8a66597, 0);
1409 } 1402 }
1410 1403
1411 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { 1404 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
@@ -1420,9 +1413,8 @@ static void irq_pipe_empty(struct r8a66597 *r8a66597)
1420 if ((tmp & INBUFM) == 0) { 1413 if ((tmp & INBUFM) == 0) {
1421 disable_irq_empty(r8a66597, pipenum); 1414 disable_irq_empty(r8a66597, pipenum);
1422 pipe_irq_disable(r8a66597, pipenum); 1415 pipe_irq_disable(r8a66597, pipenum);
1423 if (td->urb->status == -EINPROGRESS) 1416 finish_request(r8a66597, td, pipenum, td->urb,
1424 td->urb->status = 0; 1417 0);
1425 finish_request(r8a66597, td, pipenum, td->urb);
1426 } 1418 }
1427 } 1419 }
1428 } 1420 }
@@ -1433,15 +1425,16 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1433 u16 check; 1425 u16 check;
1434 u16 pipenum; 1426 u16 pipenum;
1435 u16 mask; 1427 u16 mask;
1428 int status;
1436 1429
1437 mask = r8a66597_read(r8a66597, NRDYSTS) 1430 mask = r8a66597_read(r8a66597, NRDYSTS)
1438 & r8a66597_read(r8a66597, NRDYENB); 1431 & r8a66597_read(r8a66597, NRDYENB);
1439 r8a66597_write(r8a66597, ~mask, NRDYSTS); 1432 r8a66597_write(r8a66597, ~mask, NRDYSTS);
1440 if (mask & NRDY0) { 1433 if (mask & NRDY0) {
1441 cfifo_change(r8a66597, 0); 1434 cfifo_change(r8a66597, 0);
1442 set_urb_error(r8a66597, 0); 1435 status = get_urb_error(r8a66597, 0);
1443 pipe_irq_disable(r8a66597, 0); 1436 pipe_irq_disable(r8a66597, 0);
1444 check_next_phase(r8a66597); 1437 check_next_phase(r8a66597, status);
1445 } 1438 }
1446 1439
1447 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { 1440 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
@@ -1452,10 +1445,10 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1452 if (unlikely(!td)) 1445 if (unlikely(!td))
1453 continue; 1446 continue;
1454 1447
1455 set_urb_error(r8a66597, pipenum); 1448 status = get_urb_error(r8a66597, pipenum);
1456 pipe_irq_disable(r8a66597, pipenum); 1449 pipe_irq_disable(r8a66597, pipenum);
1457 pipe_stop(r8a66597, td->pipe); 1450 pipe_stop(r8a66597, td->pipe);
1458 finish_request(r8a66597, td, pipenum, td->urb); 1451 finish_request(r8a66597, td, pipenum, td->urb, status);
1459 } 1452 }
1460 } 1453 }
1461} 1454}
@@ -1475,6 +1468,7 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1475 u16 intsts0, intsts1, intsts2; 1468 u16 intsts0, intsts1, intsts2;
1476 u16 intenb0, intenb1, intenb2; 1469 u16 intenb0, intenb1, intenb2;
1477 u16 mask0, mask1, mask2; 1470 u16 mask0, mask1, mask2;
1471 int status;
1478 1472
1479 spin_lock(&r8a66597->lock); 1473 spin_lock(&r8a66597->lock);
1480 1474
@@ -1518,12 +1512,12 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1518 } 1512 }
1519 if (mask1 & SIGN) { 1513 if (mask1 & SIGN) {
1520 r8a66597_write(r8a66597, ~SIGN, INTSTS1); 1514 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1521 set_urb_error(r8a66597, 0); 1515 status = get_urb_error(r8a66597, 0);
1522 check_next_phase(r8a66597); 1516 check_next_phase(r8a66597, status);
1523 } 1517 }
1524 if (mask1 & SACK) { 1518 if (mask1 & SACK) {
1525 r8a66597_write(r8a66597, ~SACK, INTSTS1); 1519 r8a66597_write(r8a66597, ~SACK, INTSTS1);
1526 check_next_phase(r8a66597); 1520 check_next_phase(r8a66597, 0);
1527 } 1521 }
1528 } 1522 }
1529 if (mask0) { 1523 if (mask0) {
@@ -1722,21 +1716,25 @@ static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1722} 1716}
1723 1717
1724static int r8a66597_urb_enqueue(struct usb_hcd *hcd, 1718static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1725 struct usb_host_endpoint *hep,
1726 struct urb *urb, 1719 struct urb *urb,
1727 gfp_t mem_flags) 1720 gfp_t mem_flags)
1728{ 1721{
1722 struct usb_host_endpoint *hep = urb->ep;
1729 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1723 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1730 struct r8a66597_td *td = NULL; 1724 struct r8a66597_td *td = NULL;
1731 int ret = 0, request = 0; 1725 int ret, request = 0;
1732 unsigned long flags; 1726 unsigned long flags;
1733 1727
1734 spin_lock_irqsave(&r8a66597->lock, flags); 1728 spin_lock_irqsave(&r8a66597->lock, flags);
1735 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) { 1729 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
1736 ret = -ENODEV; 1730 ret = -ENODEV;
1737 goto error; 1731 goto error_not_linked;
1738 } 1732 }
1739 1733
1734 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1735 if (ret)
1736 goto error_not_linked;
1737
1740 if (!hep->hcpriv) { 1738 if (!hep->hcpriv) {
1741 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), 1739 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1742 GFP_ATOMIC); 1740 GFP_ATOMIC);
@@ -1761,15 +1759,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1761 if (list_empty(&r8a66597->pipe_queue[td->pipenum])) 1759 if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
1762 request = 1; 1760 request = 1;
1763 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]); 1761 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
1764
1765 spin_lock(&urb->lock);
1766 if (urb->status != -EINPROGRESS) {
1767 spin_unlock(&urb->lock);
1768 ret = -EPIPE;
1769 goto error;
1770 }
1771 urb->hcpriv = td; 1762 urb->hcpriv = td;
1772 spin_unlock(&urb->lock);
1773 1763
1774 if (request) { 1764 if (request) {
1775 ret = start_transfer(r8a66597, td); 1765 ret = start_transfer(r8a66597, td);
@@ -1781,26 +1771,36 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1781 set_td_timer(r8a66597, td); 1771 set_td_timer(r8a66597, td);
1782 1772
1783error: 1773error:
1774 if (ret)
1775 usb_hcd_unlink_urb_from_ep(hcd, urb);
1776error_not_linked:
1784 spin_unlock_irqrestore(&r8a66597->lock, flags); 1777 spin_unlock_irqrestore(&r8a66597->lock, flags);
1785 return ret; 1778 return ret;
1786} 1779}
1787 1780
1788static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 1781static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1782 int status)
1789{ 1783{
1790 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1784 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1791 struct r8a66597_td *td; 1785 struct r8a66597_td *td;
1792 unsigned long flags; 1786 unsigned long flags;
1787 int rc;
1793 1788
1794 spin_lock_irqsave(&r8a66597->lock, flags); 1789 spin_lock_irqsave(&r8a66597->lock, flags);
1790 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1791 if (rc)
1792 goto done;
1793
1795 if (urb->hcpriv) { 1794 if (urb->hcpriv) {
1796 td = urb->hcpriv; 1795 td = urb->hcpriv;
1797 pipe_stop(r8a66597, td->pipe); 1796 pipe_stop(r8a66597, td->pipe);
1798 pipe_irq_disable(r8a66597, td->pipenum); 1797 pipe_irq_disable(r8a66597, td->pipenum);
1799 disable_irq_empty(r8a66597, td->pipenum); 1798 disable_irq_empty(r8a66597, td->pipenum);
1800 done(r8a66597, td, td->pipenum, urb); 1799 finish_request(r8a66597, td, td->pipenum, urb, status);
1801 } 1800 }
1801 done:
1802 spin_unlock_irqrestore(&r8a66597->lock, flags); 1802 spin_unlock_irqrestore(&r8a66597->lock, flags);
1803 return 0; 1803 return rc;
1804} 1804}
1805 1805
1806static void r8a66597_endpoint_disable(struct usb_hcd *hcd, 1806static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
@@ -1830,7 +1830,7 @@ static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
1830 td = r8a66597_get_td(r8a66597, pipenum); 1830 td = r8a66597_get_td(r8a66597, pipenum);
1831 if (td) 1831 if (td)
1832 urb = td->urb; 1832 urb = td->urb;
1833 done(r8a66597, td, pipenum, urb); 1833 finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN);
1834 kfree(hep->hcpriv); 1834 kfree(hep->hcpriv);
1835 hep->hcpriv = NULL; 1835 hep->hcpriv = NULL;
1836 spin_unlock_irqrestore(&r8a66597->lock, flags); 1836 spin_unlock_irqrestore(&r8a66597->lock, flags);
@@ -2027,7 +2027,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2027 case GetPortStatus: 2027 case GetPortStatus:
2028 if (wIndex > R8A66597_MAX_ROOT_HUB) 2028 if (wIndex > R8A66597_MAX_ROOT_HUB)
2029 goto error; 2029 goto error;
2030 *(u32 *)buf = rh->port; 2030 *(u32 *)buf = cpu_to_le32(rh->port);
2031 break; 2031 break;
2032 case SetPortFeature: 2032 case SetPortFeature:
2033 if (wIndex > R8A66597_MAX_ROOT_HUB) 2033 if (wIndex > R8A66597_MAX_ROOT_HUB)
@@ -2126,8 +2126,8 @@ static int __init_or_module r8a66597_remove(struct platform_device *pdev)
2126 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); 2126 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
2127 2127
2128 del_timer_sync(&r8a66597->rh_timer); 2128 del_timer_sync(&r8a66597->rh_timer);
2129 iounmap((void *)r8a66597->reg);
2130 usb_remove_hcd(hcd); 2129 usb_remove_hcd(hcd);
2130 iounmap((void *)r8a66597->reg);
2131 usb_put_hcd(hcd); 2131 usb_put_hcd(hcd);
2132 return 0; 2132 return 0;
2133} 2133}
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 4cfa3ff2c993..94d859aa73f8 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -435,14 +435,9 @@ static void finish_request(
435 if (usb_pipecontrol(urb->pipe)) 435 if (usb_pipecontrol(urb->pipe))
436 ep->nextpid = USB_PID_SETUP; 436 ep->nextpid = USB_PID_SETUP;
437 437
438 spin_lock(&urb->lock); 438 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811), urb);
439 if (urb->status == -EINPROGRESS)
440 urb->status = status;
441 urb->hcpriv = NULL;
442 spin_unlock(&urb->lock);
443
444 spin_unlock(&sl811->lock); 439 spin_unlock(&sl811->lock);
445 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb); 440 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb, status);
446 spin_lock(&sl811->lock); 441 spin_lock(&sl811->lock);
447 442
448 /* leave active endpoints in the schedule */ 443 /* leave active endpoints in the schedule */
@@ -538,35 +533,21 @@ done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank)
538 bank + SL11H_XFERCNTREG); 533 bank + SL11H_XFERCNTREG);
539 if (len > ep->length) { 534 if (len > ep->length) {
540 len = ep->length; 535 len = ep->length;
541 urb->status = -EOVERFLOW; 536 urbstat = -EOVERFLOW;
542 } 537 }
543 urb->actual_length += len; 538 urb->actual_length += len;
544 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0), 539 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
545 buf, len); 540 buf, len);
546 usb_dotoggle(udev, ep->epnum, 0); 541 usb_dotoggle(udev, ep->epnum, 0);
547 if (urb->actual_length == urb->transfer_buffer_length) 542 if (urbstat == -EINPROGRESS &&
548 urbstat = 0; 543 (len < ep->maxpacket ||
549 else if (len < ep->maxpacket) { 544 urb->actual_length ==
550 if (urb->transfer_flags & URB_SHORT_NOT_OK) 545 urb->transfer_buffer_length)) {
551 urbstat = -EREMOTEIO; 546 if (usb_pipecontrol(urb->pipe))
547 ep->nextpid = USB_PID_ACK;
552 else 548 else
553 urbstat = 0; 549 urbstat = 0;
554 } 550 }
555 if (usb_pipecontrol(urb->pipe)
556 && (urbstat == -EREMOTEIO
557 || urbstat == 0)) {
558
559 /* NOTE if the status stage STALLs (why?),
560 * this reports the wrong urb status.
561 */
562 spin_lock(&urb->lock);
563 if (urb->status == -EINPROGRESS)
564 urb->status = urbstat;
565 spin_unlock(&urb->lock);
566
567 urb = NULL;
568 ep->nextpid = USB_PID_ACK;
569 }
570 break; 551 break;
571 case USB_PID_SETUP: 552 case USB_PID_SETUP:
572 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep); 553 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
@@ -605,7 +586,7 @@ done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank)
605 bank, status, ep, urbstat); 586 bank, status, ep, urbstat);
606 } 587 }
607 588
608 if (urb && (urbstat != -EINPROGRESS || urb->status != -EINPROGRESS)) 589 if (urbstat != -EINPROGRESS || urb->unlinked)
609 finish_request(sl811, ep, urb, urbstat); 590 finish_request(sl811, ep, urb, urbstat);
610} 591}
611 592
@@ -807,7 +788,6 @@ static int balance(struct sl811 *sl811, u16 period, u16 load)
807 788
808static int sl811h_urb_enqueue( 789static int sl811h_urb_enqueue(
809 struct usb_hcd *hcd, 790 struct usb_hcd *hcd,
810 struct usb_host_endpoint *hep,
811 struct urb *urb, 791 struct urb *urb,
812 gfp_t mem_flags 792 gfp_t mem_flags
813) { 793) {
@@ -820,7 +800,8 @@ static int sl811h_urb_enqueue(
820 struct sl811h_ep *ep = NULL; 800 struct sl811h_ep *ep = NULL;
821 unsigned long flags; 801 unsigned long flags;
822 int i; 802 int i;
823 int retval = 0; 803 int retval;
804 struct usb_host_endpoint *hep = urb->ep;
824 805
825#ifdef DISABLE_ISO 806#ifdef DISABLE_ISO
826 if (type == PIPE_ISOCHRONOUS) 807 if (type == PIPE_ISOCHRONOUS)
@@ -838,7 +819,12 @@ static int sl811h_urb_enqueue(
838 || !HC_IS_RUNNING(hcd->state)) { 819 || !HC_IS_RUNNING(hcd->state)) {
839 retval = -ENODEV; 820 retval = -ENODEV;
840 kfree(ep); 821 kfree(ep);
841 goto fail; 822 goto fail_not_linked;
823 }
824 retval = usb_hcd_link_urb_to_ep(hcd, urb);
825 if (retval) {
826 kfree(ep);
827 goto fail_not_linked;
842 } 828 }
843 829
844 if (hep->hcpriv) { 830 if (hep->hcpriv) {
@@ -951,37 +937,31 @@ static int sl811h_urb_enqueue(
951 sofirq_on(sl811); 937 sofirq_on(sl811);
952 } 938 }
953 939
954 /* in case of unlink-during-submit */
955 spin_lock(&urb->lock);
956 if (urb->status != -EINPROGRESS) {
957 spin_unlock(&urb->lock);
958 finish_request(sl811, ep, urb, 0);
959 retval = 0;
960 goto fail;
961 }
962 urb->hcpriv = hep; 940 urb->hcpriv = hep;
963 spin_unlock(&urb->lock);
964
965 start_transfer(sl811); 941 start_transfer(sl811);
966 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable); 942 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
967fail: 943fail:
944 if (retval)
945 usb_hcd_unlink_urb_from_ep(hcd, urb);
946fail_not_linked:
968 spin_unlock_irqrestore(&sl811->lock, flags); 947 spin_unlock_irqrestore(&sl811->lock, flags);
969 return retval; 948 return retval;
970} 949}
971 950
972static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 951static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
973{ 952{
974 struct sl811 *sl811 = hcd_to_sl811(hcd); 953 struct sl811 *sl811 = hcd_to_sl811(hcd);
975 struct usb_host_endpoint *hep; 954 struct usb_host_endpoint *hep;
976 unsigned long flags; 955 unsigned long flags;
977 struct sl811h_ep *ep; 956 struct sl811h_ep *ep;
978 int retval = 0; 957 int retval;
979 958
980 spin_lock_irqsave(&sl811->lock, flags); 959 spin_lock_irqsave(&sl811->lock, flags);
981 hep = urb->hcpriv; 960 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
982 if (!hep) 961 if (retval)
983 goto fail; 962 goto fail;
984 963
964 hep = urb->hcpriv;
985 ep = hep->hcpriv; 965 ep = hep->hcpriv;
986 if (ep) { 966 if (ep) {
987 /* finish right away if this urb can't be active ... 967 /* finish right away if this urb can't be active ...
@@ -1029,8 +1009,8 @@ static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1029 VDBG("dequeue, urb %p active %s; wait4irq\n", urb, 1009 VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1030 (sl811->active_a == ep) ? "A" : "B"); 1010 (sl811->active_a == ep) ? "A" : "B");
1031 } else 1011 } else
1032fail:
1033 retval = -EINVAL; 1012 retval = -EINVAL;
1013 fail:
1034 spin_unlock_irqrestore(&sl811->lock, flags); 1014 spin_unlock_irqrestore(&sl811->lock, flags);
1035 return retval; 1015 return retval;
1036} 1016}
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index b88eb3c62c02..ac283b09a63f 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -51,7 +51,6 @@
51#include <linux/usb.h> 51#include <linux/usb.h>
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/platform_device.h> 53#include <linux/platform_device.h>
54#include <linux/pci_ids.h>
55#include <linux/mutex.h> 54#include <linux/mutex.h>
56#include <asm/io.h> 55#include <asm/io.h>
57#include <asm/irq.h> 56#include <asm/irq.h>
@@ -184,7 +183,7 @@ struct u132_ring {
184struct u132 { 183struct u132 {
185 struct kref kref; 184 struct kref kref;
186 struct list_head u132_list; 185 struct list_head u132_list;
187 struct semaphore sw_lock; 186 struct mutex sw_lock;
188 struct semaphore scheduler_lock; 187 struct semaphore scheduler_lock;
189 struct u132_platform_data *board; 188 struct u132_platform_data *board;
190 struct platform_device *platform_dev; 189 struct platform_device *platform_dev;
@@ -493,20 +492,20 @@ static void u132_hcd_monitor_work(struct work_struct *work)
493 return; 492 return;
494 } else { 493 } else {
495 int retval; 494 int retval;
496 down(&u132->sw_lock); 495 mutex_lock(&u132->sw_lock);
497 retval = read_roothub_info(u132); 496 retval = read_roothub_info(u132);
498 if (retval) { 497 if (retval) {
499 struct usb_hcd *hcd = u132_to_hcd(u132); 498 struct usb_hcd *hcd = u132_to_hcd(u132);
500 u132_disable(u132); 499 u132_disable(u132);
501 u132->going = 1; 500 u132->going = 1;
502 up(&u132->sw_lock); 501 mutex_unlock(&u132->sw_lock);
503 usb_hc_died(hcd); 502 usb_hc_died(hcd);
504 ftdi_elan_gone_away(u132->platform_dev); 503 ftdi_elan_gone_away(u132->platform_dev);
505 u132_monitor_put_kref(u132); 504 u132_monitor_put_kref(u132);
506 return; 505 return;
507 } else { 506 } else {
508 u132_monitor_requeue_work(u132, 500); 507 u132_monitor_requeue_work(u132, 500);
509 up(&u132->sw_lock); 508 mutex_unlock(&u132->sw_lock);
510 return; 509 return;
511 } 510 }
512 } 511 }
@@ -519,9 +518,8 @@ static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
519 unsigned long irqs; 518 unsigned long irqs;
520 struct usb_hcd *hcd = u132_to_hcd(u132); 519 struct usb_hcd *hcd = u132_to_hcd(u132);
521 urb->error_count = 0; 520 urb->error_count = 0;
522 urb->status = status;
523 urb->hcpriv = NULL;
524 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 521 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
522 usb_hcd_unlink_urb_from_ep(hcd, urb);
525 endp->queue_next += 1; 523 endp->queue_next += 1;
526 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 524 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
527 endp->active = 0; 525 endp->active = 0;
@@ -543,7 +541,7 @@ static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
543 u132_ring_queue_work(u132, ring, 0); 541 u132_ring_queue_work(u132, ring, 0);
544 up(&u132->scheduler_lock); 542 up(&u132->scheduler_lock);
545 u132_endp_put_kref(u132, endp); 543 u132_endp_put_kref(u132, endp);
546 usb_hcd_giveback_urb(hcd, urb); 544 usb_hcd_giveback_urb(hcd, urb, status);
547 return; 545 return;
548} 546}
549 547
@@ -559,9 +557,8 @@ static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
559 unsigned long irqs; 557 unsigned long irqs;
560 struct usb_hcd *hcd = u132_to_hcd(u132); 558 struct usb_hcd *hcd = u132_to_hcd(u132);
561 urb->error_count = 0; 559 urb->error_count = 0;
562 urb->status = status;
563 urb->hcpriv = NULL;
564 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 560 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
561 usb_hcd_unlink_urb_from_ep(hcd, urb);
565 endp->queue_next += 1; 562 endp->queue_next += 1;
566 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 563 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
567 endp->active = 0; 564 endp->active = 0;
@@ -576,7 +573,7 @@ static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
576 endp->active = 0; 573 endp->active = 0;
577 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 574 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
578 kfree(urbq); 575 kfree(urbq);
579 } usb_hcd_giveback_urb(hcd, urb); 576 } usb_hcd_giveback_urb(hcd, urb, status);
580 return; 577 return;
581} 578}
582 579
@@ -646,12 +643,12 @@ static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
646 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 643 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
647 return; 644 return;
648 } else if (u132->going > 0) { 645 } else if (u132->going > 0) {
649 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 646 dev_err(&u132->platform_dev->dev, "device is being removed "
650 "%p status=%d\n", urb, urb->status); 647 "urb=%p\n", urb);
651 up(&u132->scheduler_lock); 648 up(&u132->scheduler_lock);
652 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 649 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
653 return; 650 return;
654 } else if (urb->status == -EINPROGRESS) { 651 } else if (!urb->unlinked) {
655 struct u132_ring *ring = endp->ring; 652 struct u132_ring *ring = endp->ring;
656 u8 *u = urb->transfer_buffer + urb->actual_length; 653 u8 *u = urb->transfer_buffer + urb->actual_length;
657 u8 *b = buf; 654 u8 *b = buf;
@@ -717,10 +714,10 @@ static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
717 return; 714 return;
718 } 715 }
719 } else { 716 } else {
720 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 717 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
721 "s=%d\n", urb, urb->status); 718 "unlinked=%d\n", urb, urb->unlinked);
722 up(&u132->scheduler_lock); 719 up(&u132->scheduler_lock);
723 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 720 u132_hcd_giveback_urb(u132, endp, urb, 0);
724 return; 721 return;
725 } 722 }
726} 723}
@@ -745,12 +742,12 @@ static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
745 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 742 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
746 return; 743 return;
747 } else if (u132->going > 0) { 744 } else if (u132->going > 0) {
748 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 745 dev_err(&u132->platform_dev->dev, "device is being removed "
749 "%p status=%d\n", urb, urb->status); 746 "urb=%p\n", urb);
750 up(&u132->scheduler_lock); 747 up(&u132->scheduler_lock);
751 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 748 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
752 return; 749 return;
753 } else if (urb->status == -EINPROGRESS) { 750 } else if (!urb->unlinked) {
754 struct u132_ring *ring = endp->ring; 751 struct u132_ring *ring = endp->ring;
755 urb->actual_length += len; 752 urb->actual_length += len;
756 endp->toggle_bits = toggle_bits; 753 endp->toggle_bits = toggle_bits;
@@ -769,10 +766,10 @@ static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
769 return; 766 return;
770 } 767 }
771 } else { 768 } else {
772 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
773 "s=%d\n", urb, urb->status); 770 "unlinked=%d\n", urb, urb->unlinked);
774 up(&u132->scheduler_lock); 771 up(&u132->scheduler_lock);
775 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 772 u132_hcd_giveback_urb(u132, endp, urb, 0);
776 return; 773 return;
777 } 774 }
778} 775}
@@ -798,12 +795,12 @@ static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
798 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
799 return; 796 return;
800 } else if (u132->going > 0) { 797 } else if (u132->going > 0) {
801 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 798 dev_err(&u132->platform_dev->dev, "device is being removed "
802 "%p status=%d\n", urb, urb->status); 799 "urb=%p\n", urb);
803 up(&u132->scheduler_lock); 800 up(&u132->scheduler_lock);
804 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
805 return; 802 return;
806 } else if (urb->status == -EINPROGRESS) { 803 } else if (!urb->unlinked) {
807 struct u132_ring *ring = endp->ring; 804 struct u132_ring *ring = endp->ring;
808 u8 *u = urb->transfer_buffer + urb->actual_length; 805 u8 *u = urb->transfer_buffer + urb->actual_length;
809 u8 *b = buf; 806 u8 *b = buf;
@@ -872,10 +869,10 @@ static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
872 return; 869 return;
873 } 870 }
874 } else { 871 } else {
875 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
876 "s=%d\n", urb, urb->status); 873 "unlinked=%d\n", urb, urb->unlinked);
877 up(&u132->scheduler_lock); 874 up(&u132->scheduler_lock);
878 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 875 u132_hcd_giveback_urb(u132, endp, urb, 0);
879 return; 876 return;
880 } 877 }
881} 878}
@@ -899,20 +896,20 @@ static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
899 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
900 return; 897 return;
901 } else if (u132->going > 0) { 898 } else if (u132->going > 0) {
902 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 899 dev_err(&u132->platform_dev->dev, "device is being removed "
903 "%p status=%d\n", urb, urb->status); 900 "urb=%p\n", urb);
904 up(&u132->scheduler_lock); 901 up(&u132->scheduler_lock);
905 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
906 return; 903 return;
907 } else if (urb->status == -EINPROGRESS) { 904 } else if (!urb->unlinked) {
908 up(&u132->scheduler_lock); 905 up(&u132->scheduler_lock);
909 u132_hcd_giveback_urb(u132, endp, urb, 0); 906 u132_hcd_giveback_urb(u132, endp, urb, 0);
910 return; 907 return;
911 } else { 908 } else {
912 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
913 "s=%d\n", urb, urb->status); 910 "unlinked=%d\n", urb, urb->unlinked);
914 up(&u132->scheduler_lock); 911 up(&u132->scheduler_lock);
915 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 912 u132_hcd_giveback_urb(u132, endp, urb, 0);
916 return; 913 return;
917 } 914 }
918} 915}
@@ -937,12 +934,12 @@ static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
937 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
938 return; 935 return;
939 } else if (u132->going > 0) { 936 } else if (u132->going > 0) {
940 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 937 dev_err(&u132->platform_dev->dev, "device is being removed "
941 "%p status=%d\n", urb, urb->status); 938 "urb=%p\n", urb);
942 up(&u132->scheduler_lock); 939 up(&u132->scheduler_lock);
943 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
944 return; 941 return;
945 } else if (urb->status == -EINPROGRESS) { 942 } else if (!urb->unlinked) {
946 struct u132_ring *ring = endp->ring; 943 struct u132_ring *ring = endp->ring;
947 u8 *u = urb->transfer_buffer; 944 u8 *u = urb->transfer_buffer;
948 u8 *b = buf; 945 u8 *b = buf;
@@ -981,10 +978,10 @@ static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
981 return; 978 return;
982 } 979 }
983 } else { 980 } else {
984 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
985 "s=%d\n", urb, urb->status); 982 "unlinked=%d\n", urb, urb->unlinked);
986 up(&u132->scheduler_lock); 983 up(&u132->scheduler_lock);
987 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 984 u132_hcd_giveback_urb(u132, endp, urb, 0);
988 return; 985 return;
989 } 986 }
990} 987}
@@ -1008,20 +1005,20 @@ static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
1008 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1009 return; 1006 return;
1010 } else if (u132->going > 0) { 1007 } else if (u132->going > 0) {
1011 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1008 dev_err(&u132->platform_dev->dev, "device is being removed "
1012 "%p status=%d\n", urb, urb->status); 1009 "urb=%p\n", urb);
1013 up(&u132->scheduler_lock); 1010 up(&u132->scheduler_lock);
1014 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1015 return; 1012 return;
1016 } else if (urb->status == -EINPROGRESS) { 1013 } else if (!urb->unlinked) {
1017 up(&u132->scheduler_lock); 1014 up(&u132->scheduler_lock);
1018 u132_hcd_giveback_urb(u132, endp, urb, 0); 1015 u132_hcd_giveback_urb(u132, endp, urb, 0);
1019 return; 1016 return;
1020 } else { 1017 } else {
1021 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1022 "s=%d\n", urb, urb->status); 1019 "unlinked=%d\n", urb, urb->unlinked);
1023 up(&u132->scheduler_lock); 1020 up(&u132->scheduler_lock);
1024 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1021 u132_hcd_giveback_urb(u132, endp, urb, 0);
1025 return; 1022 return;
1026 } 1023 }
1027} 1024}
@@ -1046,12 +1043,12 @@ static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1046 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1047 return; 1044 return;
1048 } else if (u132->going > 0) { 1045 } else if (u132->going > 0) {
1049 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1046 dev_err(&u132->platform_dev->dev, "device is being removed "
1050 "%p status=%d\n", urb, urb->status); 1047 "urb=%p\n", urb);
1051 up(&u132->scheduler_lock); 1048 up(&u132->scheduler_lock);
1052 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1053 return; 1050 return;
1054 } else if (urb->status == -EINPROGRESS) { 1051 } else if (!urb->unlinked) {
1055 if (usb_pipein(urb->pipe)) { 1052 if (usb_pipein(urb->pipe)) {
1056 int retval; 1053 int retval;
1057 struct u132_ring *ring = endp->ring; 1054 struct u132_ring *ring = endp->ring;
@@ -1078,10 +1075,10 @@ static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1078 return; 1075 return;
1079 } 1076 }
1080 } else { 1077 } else {
1081 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1078 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1082 "s=%d\n", urb, urb->status); 1079 "unlinked=%d\n", urb, urb->unlinked);
1083 up(&u132->scheduler_lock); 1080 up(&u132->scheduler_lock);
1084 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1081 u132_hcd_giveback_urb(u132, endp, urb, 0);
1085 return; 1082 return;
1086 } 1083 }
1087} 1084}
@@ -1107,22 +1104,22 @@ static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1107 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1104 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1108 return; 1105 return;
1109 } else if (u132->going > 0) { 1106 } else if (u132->going > 0) {
1110 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1107 dev_err(&u132->platform_dev->dev, "device is being removed "
1111 "%p status=%d\n", urb, urb->status); 1108 "urb=%p\n", urb);
1112 up(&u132->scheduler_lock); 1109 up(&u132->scheduler_lock);
1113 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1110 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1114 return; 1111 return;
1115 } else if (urb->status == -EINPROGRESS) { 1112 } else if (!urb->unlinked) {
1116 u132->addr[0].address = 0; 1113 u132->addr[0].address = 0;
1117 endp->usb_addr = udev->usb_addr; 1114 endp->usb_addr = udev->usb_addr;
1118 up(&u132->scheduler_lock); 1115 up(&u132->scheduler_lock);
1119 u132_hcd_giveback_urb(u132, endp, urb, 0); 1116 u132_hcd_giveback_urb(u132, endp, urb, 0);
1120 return; 1117 return;
1121 } else { 1118 } else {
1122 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1119 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1123 "s=%d\n", urb, urb->status); 1120 "unlinked=%d\n", urb, urb->unlinked);
1124 up(&u132->scheduler_lock); 1121 up(&u132->scheduler_lock);
1125 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1122 u132_hcd_giveback_urb(u132, endp, urb, 0);
1126 return; 1123 return;
1127 } 1124 }
1128} 1125}
@@ -1146,12 +1143,12 @@ static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1146 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1143 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1147 return; 1144 return;
1148 } else if (u132->going > 0) { 1145 } else if (u132->going > 0) {
1149 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1146 dev_err(&u132->platform_dev->dev, "device is being removed "
1150 "%p status=%d\n", urb, urb->status); 1147 "urb=%p\n", urb);
1151 up(&u132->scheduler_lock); 1148 up(&u132->scheduler_lock);
1152 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1149 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1153 return; 1150 return;
1154 } else if (urb->status == -EINPROGRESS) { 1151 } else if (!urb->unlinked) {
1155 int retval; 1152 int retval;
1156 struct u132_ring *ring = endp->ring; 1153 struct u132_ring *ring = endp->ring;
1157 up(&u132->scheduler_lock); 1154 up(&u132->scheduler_lock);
@@ -1163,10 +1160,10 @@ static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1163 u132_hcd_giveback_urb(u132, endp, urb, retval); 1160 u132_hcd_giveback_urb(u132, endp, urb, retval);
1164 return; 1161 return;
1165 } else { 1162 } else {
1166 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1163 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1167 "s=%d\n", urb, urb->status); 1164 "unlinked=%d\n", urb, urb->unlinked);
1168 up(&u132->scheduler_lock); 1165 up(&u132->scheduler_lock);
1169 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1166 u132_hcd_giveback_urb(u132, endp, urb, 0);
1170 return; 1167 return;
1171 } 1168 }
1172} 1169}
@@ -1190,20 +1187,20 @@ static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1190 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1187 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1191 return; 1188 return;
1192 } else if (u132->going > 0) { 1189 } else if (u132->going > 0) {
1193 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1190 dev_err(&u132->platform_dev->dev, "device is being removed "
1194 "%p status=%d\n", urb, urb->status); 1191 "urb=%p\n", urb);
1195 up(&u132->scheduler_lock); 1192 up(&u132->scheduler_lock);
1196 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1193 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1197 return; 1194 return;
1198 } else if (urb->status == -EINPROGRESS) { 1195 } else if (!urb->unlinked) {
1199 up(&u132->scheduler_lock); 1196 up(&u132->scheduler_lock);
1200 u132_hcd_giveback_urb(u132, endp, urb, 0); 1197 u132_hcd_giveback_urb(u132, endp, urb, 0);
1201 return; 1198 return;
1202 } else { 1199 } else {
1203 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1200 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1204 "s=%d\n", urb, urb->status); 1201 "unlinked=%d\n", urb, urb->unlinked);
1205 up(&u132->scheduler_lock); 1202 up(&u132->scheduler_lock);
1206 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1203 u132_hcd_giveback_urb(u132, endp, urb, 0);
1207 return; 1204 return;
1208 } 1205 }
1209} 1206}
@@ -1228,12 +1225,12 @@ static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1228 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1225 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1229 return; 1226 return;
1230 } else if (u132->going > 0) { 1227 } else if (u132->going > 0) {
1231 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1228 dev_err(&u132->platform_dev->dev, "device is being removed "
1232 "%p status=%d\n", urb, urb->status); 1229 "urb=%p\n", urb);
1233 up(&u132->scheduler_lock); 1230 up(&u132->scheduler_lock);
1234 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1231 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1235 return; 1232 return;
1236 } else if (urb->status == -EINPROGRESS) { 1233 } else if (!urb->unlinked) {
1237 int retval; 1234 int retval;
1238 struct u132_ring *ring = endp->ring; 1235 struct u132_ring *ring = endp->ring;
1239 u8 *u = urb->transfer_buffer; 1236 u8 *u = urb->transfer_buffer;
@@ -1252,10 +1249,10 @@ static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1252 u132_hcd_giveback_urb(u132, endp, urb, retval); 1249 u132_hcd_giveback_urb(u132, endp, urb, retval);
1253 return; 1250 return;
1254 } else { 1251 } else {
1255 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1252 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1256 "s=%d\n", urb, urb->status); 1253 "unlinked=%d\n", urb, urb->unlinked);
1257 up(&u132->scheduler_lock); 1254 up(&u132->scheduler_lock);
1258 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1255 u132_hcd_giveback_urb(u132, endp, urb, 0);
1259 return; 1256 return;
1260 } 1257 }
1261} 1258}
@@ -1280,12 +1277,12 @@ static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1280 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1277 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1281 return; 1278 return;
1282 } else if (u132->going > 0) { 1279 } else if (u132->going > 0) {
1283 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 1280 dev_err(&u132->platform_dev->dev, "device is being removed "
1284 "%p status=%d\n", urb, urb->status); 1281 "urb=%p\n", urb);
1285 up(&u132->scheduler_lock); 1282 up(&u132->scheduler_lock);
1286 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1283 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1287 return; 1284 return;
1288 } else if (urb->status == -EINPROGRESS) { 1285 } else if (!urb->unlinked) {
1289 int retval; 1286 int retval;
1290 struct u132_ring *ring = endp->ring; 1287 struct u132_ring *ring = endp->ring;
1291 up(&u132->scheduler_lock); 1288 up(&u132->scheduler_lock);
@@ -1297,10 +1294,10 @@ static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1297 u132_hcd_giveback_urb(u132, endp, urb, retval); 1294 u132_hcd_giveback_urb(u132, endp, urb, retval);
1298 return; 1295 return;
1299 } else { 1296 } else {
1300 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" 1297 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1301 "s=%d\n", urb, urb->status); 1298 "unlinked=%d\n", urb, urb->unlinked);
1302 up(&u132->scheduler_lock); 1299 up(&u132->scheduler_lock);
1303 u132_hcd_giveback_urb(u132, endp, urb, urb->status); 1300 u132_hcd_giveback_urb(u132, endp, urb, 0);
1304 return; 1301 return;
1305 } 1302 }
1306} 1303}
@@ -1805,10 +1802,10 @@ static void u132_hcd_stop(struct usb_hcd *hcd)
1805 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 1802 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1806 "ed\n", hcd); 1803 "ed\n", hcd);
1807 } else { 1804 } else {
1808 down(&u132->sw_lock); 1805 mutex_lock(&u132->sw_lock);
1809 msleep(100); 1806 msleep(100);
1810 u132_power(u132, 0); 1807 u132_power(u132, 0);
1811 up(&u132->sw_lock); 1808 mutex_unlock(&u132->sw_lock);
1812 } 1809 }
1813} 1810}
1814 1811
@@ -1830,7 +1827,7 @@ static int u132_hcd_start(struct usb_hcd *hcd)
1830 (pdev->dev.platform_data))->vendor; 1827 (pdev->dev.platform_data))->vendor;
1831 u16 device = ((struct u132_platform_data *) 1828 u16 device = ((struct u132_platform_data *)
1832 (pdev->dev.platform_data))->device; 1829 (pdev->dev.platform_data))->device;
1833 down(&u132->sw_lock); 1830 mutex_lock(&u132->sw_lock);
1834 msleep(10); 1831 msleep(10);
1835 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { 1832 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1836 u132->flags = OHCI_QUIRK_AMD756; 1833 u132->flags = OHCI_QUIRK_AMD756;
@@ -1845,7 +1842,7 @@ static int u132_hcd_start(struct usb_hcd *hcd)
1845 u132->going = 1; 1842 u132->going = 1;
1846 } 1843 }
1847 msleep(100); 1844 msleep(100);
1848 up(&u132->sw_lock); 1845 mutex_unlock(&u132->sw_lock);
1849 return retval; 1846 return retval;
1850 } else { 1847 } else {
1851 dev_err(&u132->platform_dev->dev, "platform_device missing\n"); 1848 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
@@ -1865,32 +1862,44 @@ static int u132_hcd_reset(struct usb_hcd *hcd)
1865 return -ESHUTDOWN; 1862 return -ESHUTDOWN;
1866 } else { 1863 } else {
1867 int retval; 1864 int retval;
1868 down(&u132->sw_lock); 1865 mutex_lock(&u132->sw_lock);
1869 retval = u132_init(u132); 1866 retval = u132_init(u132);
1870 if (retval) { 1867 if (retval) {
1871 u132_disable(u132); 1868 u132_disable(u132);
1872 u132->going = 1; 1869 u132->going = 1;
1873 } 1870 }
1874 up(&u132->sw_lock); 1871 mutex_unlock(&u132->sw_lock);
1875 return retval; 1872 return retval;
1876 } 1873 }
1877} 1874}
1878 1875
1879static int create_endpoint_and_queue_int(struct u132 *u132, 1876static int create_endpoint_and_queue_int(struct u132 *u132,
1880 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, 1877 struct u132_udev *udev, struct urb *urb,
1881 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1878 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1882 gfp_t mem_flags) 1879 gfp_t mem_flags)
1883{ 1880{
1884 struct u132_ring *ring; 1881 struct u132_ring *ring;
1885 unsigned long irqs; 1882 unsigned long irqs;
1886 u8 endp_number = ++u132->num_endpoints; 1883 int rc;
1887 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 1884 u8 endp_number;
1888 kmalloc(sizeof(struct u132_endp), mem_flags); 1885 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1886
1889 if (!endp) { 1887 if (!endp) {
1890 return -ENOMEM; 1888 return -ENOMEM;
1891 } 1889 }
1890
1891 spin_lock_init(&endp->queue_lock.slock);
1892 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1893 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1894 if (rc) {
1895 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1896 kfree(endp);
1897 return rc;
1898 }
1899
1900 endp_number = ++u132->num_endpoints;
1901 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1892 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1902 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1893 spin_lock_init(&endp->queue_lock.slock);
1894 INIT_LIST_HEAD(&endp->urb_more); 1903 INIT_LIST_HEAD(&endp->urb_more);
1895 ring = endp->ring = &u132->ring[0]; 1904 ring = endp->ring = &u132->ring[0];
1896 if (ring->curr_endp) { 1905 if (ring->curr_endp) {
@@ -1906,7 +1915,7 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1906 endp->delayed = 0; 1915 endp->delayed = 0;
1907 endp->endp_number = endp_number; 1916 endp->endp_number = endp_number;
1908 endp->u132 = u132; 1917 endp->u132 = u132;
1909 endp->hep = hep; 1918 endp->hep = urb->ep;
1910 endp->pipetype = usb_pipetype(urb->pipe); 1919 endp->pipetype = usb_pipetype(urb->pipe);
1911 u132_endp_init_kref(u132, endp); 1920 u132_endp_init_kref(u132, endp);
1912 if (usb_pipein(urb->pipe)) { 1921 if (usb_pipein(urb->pipe)) {
@@ -1925,7 +1934,6 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1925 u132_udev_get_kref(u132, udev); 1934 u132_udev_get_kref(u132, udev);
1926 } 1935 }
1927 urb->hcpriv = u132; 1936 urb->hcpriv = u132;
1928 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1929 endp->delayed = 1; 1937 endp->delayed = 1;
1930 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1938 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1931 endp->udev_number = address; 1939 endp->udev_number = address;
@@ -1940,8 +1948,8 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1940 return 0; 1948 return 0;
1941} 1949}
1942 1950
1943static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 1951static int queue_int_on_old_endpoint(struct u132 *u132,
1944 struct usb_host_endpoint *hep, struct urb *urb, 1952 struct u132_udev *udev, struct urb *urb,
1945 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 1953 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1946 u8 usb_endp, u8 address) 1954 u8 usb_endp, u8 address)
1947{ 1955{
@@ -1965,21 +1973,33 @@ static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1965} 1973}
1966 1974
1967static int create_endpoint_and_queue_bulk(struct u132 *u132, 1975static int create_endpoint_and_queue_bulk(struct u132 *u132,
1968 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, 1976 struct u132_udev *udev, struct urb *urb,
1969 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1977 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1970 gfp_t mem_flags) 1978 gfp_t mem_flags)
1971{ 1979{
1972 int ring_number; 1980 int ring_number;
1973 struct u132_ring *ring; 1981 struct u132_ring *ring;
1974 unsigned long irqs; 1982 unsigned long irqs;
1975 u8 endp_number = ++u132->num_endpoints; 1983 int rc;
1976 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 1984 u8 endp_number;
1977 kmalloc(sizeof(struct u132_endp), mem_flags); 1985 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1986
1978 if (!endp) { 1987 if (!endp) {
1979 return -ENOMEM; 1988 return -ENOMEM;
1980 } 1989 }
1990
1991 spin_lock_init(&endp->queue_lock.slock);
1992 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1993 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1994 if (rc) {
1995 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1996 kfree(endp);
1997 return rc;
1998 }
1999
2000 endp_number = ++u132->num_endpoints;
2001 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1981 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2002 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1982 spin_lock_init(&endp->queue_lock.slock);
1983 INIT_LIST_HEAD(&endp->urb_more); 2003 INIT_LIST_HEAD(&endp->urb_more);
1984 endp->dequeueing = 0; 2004 endp->dequeueing = 0;
1985 endp->edset_flush = 0; 2005 endp->edset_flush = 0;
@@ -1987,7 +2007,7 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
1987 endp->delayed = 0; 2007 endp->delayed = 0;
1988 endp->endp_number = endp_number; 2008 endp->endp_number = endp_number;
1989 endp->u132 = u132; 2009 endp->u132 = u132;
1990 endp->hep = hep; 2010 endp->hep = urb->ep;
1991 endp->pipetype = usb_pipetype(urb->pipe); 2011 endp->pipetype = usb_pipetype(urb->pipe);
1992 u132_endp_init_kref(u132, endp); 2012 u132_endp_init_kref(u132, endp);
1993 if (usb_pipein(urb->pipe)) { 2013 if (usb_pipein(urb->pipe)) {
@@ -2016,7 +2036,6 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
2016 } 2036 }
2017 ring->length += 1; 2037 ring->length += 1;
2018 urb->hcpriv = u132; 2038 urb->hcpriv = u132;
2019 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2020 endp->udev_number = address; 2039 endp->udev_number = address;
2021 endp->usb_addr = usb_addr; 2040 endp->usb_addr = usb_addr;
2022 endp->usb_endp = usb_endp; 2041 endp->usb_endp = usb_endp;
@@ -2030,7 +2049,7 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
2030} 2049}
2031 2050
2032static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 2051static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2033 struct usb_host_endpoint *hep, struct urb *urb, 2052 struct urb *urb,
2034 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2053 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2035 u8 usb_endp, u8 address) 2054 u8 usb_endp, u8 address)
2036{ 2055{
@@ -2052,19 +2071,32 @@ static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2052} 2071}
2053 2072
2054static int create_endpoint_and_queue_control(struct u132 *u132, 2073static int create_endpoint_and_queue_control(struct u132 *u132,
2055 struct usb_host_endpoint *hep, struct urb *urb, 2074 struct urb *urb,
2056 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, 2075 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2057 gfp_t mem_flags) 2076 gfp_t mem_flags)
2058{ 2077{
2059 struct u132_ring *ring; 2078 struct u132_ring *ring;
2060 u8 endp_number = ++u132->num_endpoints; 2079 unsigned long irqs;
2061 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 2080 int rc;
2062 kmalloc(sizeof(struct u132_endp), mem_flags); 2081 u8 endp_number;
2082 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2083
2063 if (!endp) { 2084 if (!endp) {
2064 return -ENOMEM; 2085 return -ENOMEM;
2065 } 2086 }
2087
2088 spin_lock_init(&endp->queue_lock.slock);
2089 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2090 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2091 if (rc) {
2092 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2093 kfree(endp);
2094 return rc;
2095 }
2096
2097 endp_number = ++u132->num_endpoints;
2098 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2066 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2099 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2067 spin_lock_init(&endp->queue_lock.slock);
2068 INIT_LIST_HEAD(&endp->urb_more); 2100 INIT_LIST_HEAD(&endp->urb_more);
2069 ring = endp->ring = &u132->ring[0]; 2101 ring = endp->ring = &u132->ring[0];
2070 if (ring->curr_endp) { 2102 if (ring->curr_endp) {
@@ -2080,11 +2112,10 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2080 endp->delayed = 0; 2112 endp->delayed = 0;
2081 endp->endp_number = endp_number; 2113 endp->endp_number = endp_number;
2082 endp->u132 = u132; 2114 endp->u132 = u132;
2083 endp->hep = hep; 2115 endp->hep = urb->ep;
2084 u132_endp_init_kref(u132, endp); 2116 u132_endp_init_kref(u132, endp);
2085 u132_endp_get_kref(u132, endp); 2117 u132_endp_get_kref(u132, endp);
2086 if (usb_addr == 0) { 2118 if (usb_addr == 0) {
2087 unsigned long irqs;
2088 u8 address = u132->addr[usb_addr].address; 2119 u8 address = u132->addr[usb_addr].address;
2089 struct u132_udev *udev = &u132->udev[address]; 2120 struct u132_udev *udev = &u132->udev[address];
2090 endp->udev_number = address; 2121 endp->udev_number = address;
@@ -2098,7 +2129,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2098 udev->endp_number_in[usb_endp] = endp_number; 2129 udev->endp_number_in[usb_endp] = endp_number;
2099 udev->endp_number_out[usb_endp] = endp_number; 2130 udev->endp_number_out[usb_endp] = endp_number;
2100 urb->hcpriv = u132; 2131 urb->hcpriv = u132;
2101 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2102 endp->queue_size = 1; 2132 endp->queue_size = 1;
2103 endp->queue_last = 0; 2133 endp->queue_last = 0;
2104 endp->queue_next = 0; 2134 endp->queue_next = 0;
@@ -2107,7 +2137,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2107 u132_endp_queue_work(u132, endp, 0); 2137 u132_endp_queue_work(u132, endp, 0);
2108 return 0; 2138 return 0;
2109 } else { /*(usb_addr > 0) */ 2139 } else { /*(usb_addr > 0) */
2110 unsigned long irqs;
2111 u8 address = u132->addr[usb_addr].address; 2140 u8 address = u132->addr[usb_addr].address;
2112 struct u132_udev *udev = &u132->udev[address]; 2141 struct u132_udev *udev = &u132->udev[address];
2113 endp->udev_number = address; 2142 endp->udev_number = address;
@@ -2121,7 +2150,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2121 udev->endp_number_in[usb_endp] = endp_number; 2150 udev->endp_number_in[usb_endp] = endp_number;
2122 udev->endp_number_out[usb_endp] = endp_number; 2151 udev->endp_number_out[usb_endp] = endp_number;
2123 urb->hcpriv = u132; 2152 urb->hcpriv = u132;
2124 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2125 endp->queue_size = 1; 2153 endp->queue_size = 1;
2126 endp->queue_last = 0; 2154 endp->queue_last = 0;
2127 endp->queue_next = 0; 2155 endp->queue_next = 0;
@@ -2133,7 +2161,7 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2133} 2161}
2134 2162
2135static int queue_control_on_old_endpoint(struct u132 *u132, 2163static int queue_control_on_old_endpoint(struct u132 *u132,
2136 struct usb_host_endpoint *hep, struct urb *urb, 2164 struct urb *urb,
2137 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2165 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2138 u8 usb_endp) 2166 u8 usb_endp)
2139{ 2167{
@@ -2233,8 +2261,8 @@ static int queue_control_on_old_endpoint(struct u132 *u132,
2233 } 2261 }
2234} 2262}
2235 2263
2236static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep, 2264static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2237 struct urb *urb, gfp_t mem_flags) 2265 gfp_t mem_flags)
2238{ 2266{
2239 struct u132 *u132 = hcd_to_u132(hcd); 2267 struct u132 *u132 = hcd_to_u132(hcd);
2240 if (irqs_disabled()) { 2268 if (irqs_disabled()) {
@@ -2249,8 +2277,8 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2249 , u132->going); 2277 , u132->going);
2250 return -ENODEV; 2278 return -ENODEV;
2251 } else if (u132->going > 0) { 2279 } else if (u132->going > 0) {
2252 dev_err(&u132->platform_dev->dev, "device is being removed urb=" 2280 dev_err(&u132->platform_dev->dev, "device is being removed "
2253 "%p status=%d\n", urb, urb->status); 2281 "urb=%p\n", urb);
2254 return -ESHUTDOWN; 2282 return -ESHUTDOWN;
2255 } else { 2283 } else {
2256 u8 usb_addr = usb_pipedevice(urb->pipe); 2284 u8 usb_addr = usb_pipedevice(urb->pipe);
@@ -2259,16 +2287,24 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2259 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 2287 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2260 u8 address = u132->addr[usb_addr].address; 2288 u8 address = u132->addr[usb_addr].address;
2261 struct u132_udev *udev = &u132->udev[address]; 2289 struct u132_udev *udev = &u132->udev[address];
2262 struct u132_endp *endp = hep->hcpriv; 2290 struct u132_endp *endp = urb->ep->hcpriv;
2263 urb->actual_length = 0; 2291 urb->actual_length = 0;
2264 if (endp) { 2292 if (endp) {
2265 unsigned long irqs; 2293 unsigned long irqs;
2266 int retval; 2294 int retval;
2267 spin_lock_irqsave(&endp->queue_lock.slock, 2295 spin_lock_irqsave(&endp->queue_lock.slock,
2268 irqs); 2296 irqs);
2269 retval = queue_int_on_old_endpoint(u132, udev, 2297 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2270 hep, urb, usb_dev, endp, usb_addr, 2298 if (retval == 0) {
2271 usb_endp, address); 2299 retval = queue_int_on_old_endpoint(
2300 u132, udev, urb,
2301 usb_dev, endp,
2302 usb_addr, usb_endp,
2303 address);
2304 if (retval)
2305 usb_hcd_unlink_urb_from_ep(
2306 hcd, urb);
2307 }
2272 spin_unlock_irqrestore(&endp->queue_lock.slock, 2308 spin_unlock_irqrestore(&endp->queue_lock.slock,
2273 irqs); 2309 irqs);
2274 if (retval) { 2310 if (retval) {
@@ -2283,8 +2319,8 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2283 return -EINVAL; 2319 return -EINVAL;
2284 } else { /*(endp == NULL) */ 2320 } else { /*(endp == NULL) */
2285 return create_endpoint_and_queue_int(u132, udev, 2321 return create_endpoint_and_queue_int(u132, udev,
2286 hep, urb, usb_dev, usb_addr, usb_endp, 2322 urb, usb_dev, usb_addr,
2287 address, mem_flags); 2323 usb_endp, address, mem_flags);
2288 } 2324 }
2289 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { 2325 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2290 dev_err(&u132->platform_dev->dev, "the hardware does no" 2326 dev_err(&u132->platform_dev->dev, "the hardware does no"
@@ -2293,16 +2329,24 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2293 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { 2329 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2294 u8 address = u132->addr[usb_addr].address; 2330 u8 address = u132->addr[usb_addr].address;
2295 struct u132_udev *udev = &u132->udev[address]; 2331 struct u132_udev *udev = &u132->udev[address];
2296 struct u132_endp *endp = hep->hcpriv; 2332 struct u132_endp *endp = urb->ep->hcpriv;
2297 urb->actual_length = 0; 2333 urb->actual_length = 0;
2298 if (endp) { 2334 if (endp) {
2299 unsigned long irqs; 2335 unsigned long irqs;
2300 int retval; 2336 int retval;
2301 spin_lock_irqsave(&endp->queue_lock.slock, 2337 spin_lock_irqsave(&endp->queue_lock.slock,
2302 irqs); 2338 irqs);
2303 retval = queue_bulk_on_old_endpoint(u132, udev, 2339 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2304 hep, urb, usb_dev, endp, usb_addr, 2340 if (retval == 0) {
2305 usb_endp, address); 2341 retval = queue_bulk_on_old_endpoint(
2342 u132, udev, urb,
2343 usb_dev, endp,
2344 usb_addr, usb_endp,
2345 address);
2346 if (retval)
2347 usb_hcd_unlink_urb_from_ep(
2348 hcd, urb);
2349 }
2306 spin_unlock_irqrestore(&endp->queue_lock.slock, 2350 spin_unlock_irqrestore(&endp->queue_lock.slock,
2307 irqs); 2351 irqs);
2308 if (retval) { 2352 if (retval) {
@@ -2315,10 +2359,10 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2315 return -EINVAL; 2359 return -EINVAL;
2316 } else 2360 } else
2317 return create_endpoint_and_queue_bulk(u132, 2361 return create_endpoint_and_queue_bulk(u132,
2318 udev, hep, urb, usb_dev, usb_addr, 2362 udev, urb, usb_dev, usb_addr,
2319 usb_endp, address, mem_flags); 2363 usb_endp, address, mem_flags);
2320 } else { 2364 } else {
2321 struct u132_endp *endp = hep->hcpriv; 2365 struct u132_endp *endp = urb->ep->hcpriv;
2322 u16 urb_size = 8; 2366 u16 urb_size = 8;
2323 u8 *b = urb->setup_packet; 2367 u8 *b = urb->setup_packet;
2324 int i = 0; 2368 int i = 0;
@@ -2341,9 +2385,16 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2341 int retval; 2385 int retval;
2342 spin_lock_irqsave(&endp->queue_lock.slock, 2386 spin_lock_irqsave(&endp->queue_lock.slock,
2343 irqs); 2387 irqs);
2344 retval = queue_control_on_old_endpoint(u132, 2388 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2345 hep, urb, usb_dev, endp, usb_addr, 2389 if (retval == 0) {
2346 usb_endp); 2390 retval = queue_control_on_old_endpoint(
2391 u132, urb, usb_dev,
2392 endp, usb_addr,
2393 usb_endp);
2394 if (retval)
2395 usb_hcd_unlink_urb_from_ep(
2396 hcd, urb);
2397 }
2347 spin_unlock_irqrestore(&endp->queue_lock.slock, 2398 spin_unlock_irqrestore(&endp->queue_lock.slock,
2348 irqs); 2399 irqs);
2349 if (retval) { 2400 if (retval) {
@@ -2356,7 +2407,7 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2356 return -EINVAL; 2407 return -EINVAL;
2357 } else 2408 } else
2358 return create_endpoint_and_queue_control(u132, 2409 return create_endpoint_and_queue_control(u132,
2359 hep, urb, usb_dev, usb_addr, usb_endp, 2410 urb, usb_dev, usb_addr, usb_endp,
2360 mem_flags); 2411 mem_flags);
2361 } 2412 }
2362 } 2413 }
@@ -2375,8 +2426,7 @@ static int dequeue_from_overflow_chain(struct u132 *u132,
2375 list_del(scan); 2426 list_del(scan);
2376 endp->queue_size -= 1; 2427 endp->queue_size -= 1;
2377 urb->error_count = 0; 2428 urb->error_count = 0;
2378 urb->hcpriv = NULL; 2429 usb_hcd_giveback_urb(hcd, urb, 0);
2379 usb_hcd_giveback_urb(hcd, urb);
2380 return 0; 2430 return 0;
2381 } else 2431 } else
2382 continue; 2432 continue;
@@ -2391,10 +2441,17 @@ static int dequeue_from_overflow_chain(struct u132 *u132,
2391} 2441}
2392 2442
2393static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, 2443static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2394 struct urb *urb) 2444 struct urb *urb, int status)
2395{ 2445{
2396 unsigned long irqs; 2446 unsigned long irqs;
2447 int rc;
2448
2397 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2449 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2450 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2451 if (rc) {
2452 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2453 return rc;
2454 }
2398 if (endp->queue_size == 0) { 2455 if (endp->queue_size == 0) {
2399 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" 2456 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2400 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, 2457 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
@@ -2410,11 +2467,10 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2410 endp->edset_flush = 1; 2467 endp->edset_flush = 1;
2411 u132_endp_queue_work(u132, endp, 0); 2468 u132_endp_queue_work(u132, endp, 0);
2412 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2469 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2413 urb->hcpriv = NULL;
2414 return 0; 2470 return 0;
2415 } else { 2471 } else {
2416 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2472 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2417 u132_hcd_abandon_urb(u132, endp, urb, urb->status); 2473 u132_hcd_abandon_urb(u132, endp, urb, status);
2418 return 0; 2474 return 0;
2419 } 2475 }
2420 } else { 2476 } else {
@@ -2439,6 +2495,8 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2439 } 2495 }
2440 if (urb_slot) { 2496 if (urb_slot) {
2441 struct usb_hcd *hcd = u132_to_hcd(u132); 2497 struct usb_hcd *hcd = u132_to_hcd(u132);
2498
2499 usb_hcd_unlink_urb_from_ep(hcd, urb);
2442 endp->queue_size -= 1; 2500 endp->queue_size -= 1;
2443 if (list_empty(&endp->urb_more)) { 2501 if (list_empty(&endp->urb_more)) {
2444 spin_unlock_irqrestore(&endp->queue_lock.slock, 2502 spin_unlock_irqrestore(&endp->queue_lock.slock,
@@ -2453,8 +2511,7 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2453 irqs); 2511 irqs);
2454 kfree(urbq); 2512 kfree(urbq);
2455 } urb->error_count = 0; 2513 } urb->error_count = 0;
2456 urb->hcpriv = NULL; 2514 usb_hcd_giveback_urb(hcd, urb, status);
2457 usb_hcd_giveback_urb(hcd, urb);
2458 return 0; 2515 return 0;
2459 } else if (list_empty(&endp->urb_more)) { 2516 } else if (list_empty(&endp->urb_more)) {
2460 dev_err(&u132->platform_dev->dev, "urb=%p not found in " 2517 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
@@ -2468,7 +2525,10 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2468 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2525 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2469 return -EINVAL; 2526 return -EINVAL;
2470 } else { 2527 } else {
2471 int retval = dequeue_from_overflow_chain(u132, endp, 2528 int retval;
2529
2530 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2531 retval = dequeue_from_overflow_chain(u132, endp,
2472 urb); 2532 urb);
2473 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2533 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2474 return retval; 2534 return retval;
@@ -2476,7 +2536,7 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2476 } 2536 }
2477} 2537}
2478 2538
2479static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 2539static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2480{ 2540{
2481 struct u132 *u132 = hcd_to_u132(hcd); 2541 struct u132 *u132 = hcd_to_u132(hcd);
2482 if (u132->going > 2) { 2542 if (u132->going > 2) {
@@ -2491,11 +2551,11 @@ static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2491 if (usb_pipein(urb->pipe)) { 2551 if (usb_pipein(urb->pipe)) {
2492 u8 endp_number = udev->endp_number_in[usb_endp]; 2552 u8 endp_number = udev->endp_number_in[usb_endp];
2493 struct u132_endp *endp = u132->endp[endp_number - 1]; 2553 struct u132_endp *endp = u132->endp[endp_number - 1];
2494 return u132_endp_urb_dequeue(u132, endp, urb); 2554 return u132_endp_urb_dequeue(u132, endp, urb, status);
2495 } else { 2555 } else {
2496 u8 endp_number = udev->endp_number_out[usb_endp]; 2556 u8 endp_number = udev->endp_number_out[usb_endp];
2497 struct u132_endp *endp = u132->endp[endp_number - 1]; 2557 struct u132_endp *endp = u132->endp[endp_number - 1];
2498 return u132_endp_urb_dequeue(u132, endp, urb); 2558 return u132_endp_urb_dequeue(u132, endp, urb, status);
2499 } 2559 }
2500 } 2560 }
2501} 2561}
@@ -2805,7 +2865,7 @@ static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2805 return -ESHUTDOWN; 2865 return -ESHUTDOWN;
2806 } else { 2866 } else {
2807 int retval = 0; 2867 int retval = 0;
2808 down(&u132->sw_lock); 2868 mutex_lock(&u132->sw_lock);
2809 switch (typeReq) { 2869 switch (typeReq) {
2810 case ClearHubFeature: 2870 case ClearHubFeature:
2811 switch (wValue) { 2871 switch (wValue) {
@@ -2868,7 +2928,7 @@ static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2868 stall:retval = -EPIPE; 2928 stall:retval = -EPIPE;
2869 break; 2929 break;
2870 } 2930 }
2871 up(&u132->sw_lock); 2931 mutex_unlock(&u132->sw_lock);
2872 return retval; 2932 return retval;
2873 } 2933 }
2874} 2934}
@@ -3004,7 +3064,7 @@ static int __devexit u132_remove(struct platform_device *pdev)
3004 dev_err(&u132->platform_dev->dev, "removing device u132" 3064 dev_err(&u132->platform_dev->dev, "removing device u132"
3005 ".%d\n", u132->sequence_num); 3065 ".%d\n", u132->sequence_num);
3006 msleep(100); 3066 msleep(100);
3007 down(&u132->sw_lock); 3067 mutex_lock(&u132->sw_lock);
3008 u132_monitor_cancel_work(u132); 3068 u132_monitor_cancel_work(u132);
3009 while (rings-- > 0) { 3069 while (rings-- > 0) {
3010 struct u132_ring *ring = &u132->ring[rings]; 3070 struct u132_ring *ring = &u132->ring[rings];
@@ -3017,7 +3077,7 @@ static int __devexit u132_remove(struct platform_device *pdev)
3017 u132->going += 1; 3077 u132->going += 1;
3018 printk(KERN_INFO "removing device u132.%d\n", 3078 printk(KERN_INFO "removing device u132.%d\n",
3019 u132->sequence_num); 3079 u132->sequence_num);
3020 up(&u132->sw_lock); 3080 mutex_unlock(&u132->sw_lock);
3021 usb_remove_hcd(hcd); 3081 usb_remove_hcd(hcd);
3022 u132_u132_put_kref(u132); 3082 u132_u132_put_kref(u132);
3023 return 0; 3083 return 0;
@@ -3037,7 +3097,7 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3037 u132->platform_dev = pdev; 3097 u132->platform_dev = pdev;
3038 u132->power = 0; 3098 u132->power = 0;
3039 u132->reset = 0; 3099 u132->reset = 0;
3040 init_MUTEX(&u132->sw_lock); 3100 mutex_init(&u132->sw_lock);
3041 init_MUTEX(&u132->scheduler_lock); 3101 init_MUTEX(&u132->scheduler_lock);
3042 while (rings-- > 0) { 3102 while (rings-- > 0) {
3043 struct u132_ring *ring = &u132->ring[rings]; 3103 struct u132_ring *ring = &u132->ring[rings];
@@ -3047,7 +3107,7 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3047 ring->curr_endp = NULL; 3107 ring->curr_endp = NULL;
3048 INIT_DELAYED_WORK(&ring->scheduler, 3108 INIT_DELAYED_WORK(&ring->scheduler,
3049 u132_hcd_ring_work_scheduler); 3109 u132_hcd_ring_work_scheduler);
3050 } down(&u132->sw_lock); 3110 } mutex_lock(&u132->sw_lock);
3051 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work); 3111 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3052 while (ports-- > 0) { 3112 while (ports-- > 0) {
3053 struct u132_port *port = &u132->port[ports]; 3113 struct u132_port *port = &u132->port[ports];
@@ -3077,7 +3137,7 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3077 while (endps-- > 0) { 3137 while (endps-- > 0) {
3078 u132->endp[endps] = NULL; 3138 u132->endp[endps] = NULL;
3079 } 3139 }
3080 up(&u132->sw_lock); 3140 mutex_unlock(&u132->sw_lock);
3081 return; 3141 return;
3082} 3142}
3083 3143
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 1497371583b9..20cc58b97807 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -120,8 +120,8 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
120 out += sprintf(out, "%s%s", ptype, (urbp->fsbr ? " FSBR" : "")); 120 out += sprintf(out, "%s%s", ptype, (urbp->fsbr ? " FSBR" : ""));
121 out += sprintf(out, " Actlen=%d", urbp->urb->actual_length); 121 out += sprintf(out, " Actlen=%d", urbp->urb->actual_length);
122 122
123 if (urbp->urb->status != -EINPROGRESS) 123 if (urbp->urb->unlinked)
124 out += sprintf(out, " Status=%d", urbp->urb->status); 124 out += sprintf(out, " Unlinked=%d", urbp->urb->unlinked);
125 out += sprintf(out, "\n"); 125 out += sprintf(out, "\n");
126 126
127 i = nactive = ninactive = 0; 127 i = nactive = ninactive = 0;
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 1b3d23406ac4..340d6ed3e6e9 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -146,7 +146,6 @@ struct uhci_qh {
146 short phase; /* Between 0 and period-1 */ 146 short phase; /* Between 0 and period-1 */
147 short load; /* Periodic time requirement, in us */ 147 short load; /* Periodic time requirement, in us */
148 unsigned int iso_frame; /* Frame # for iso_packet_desc */ 148 unsigned int iso_frame; /* Frame # for iso_packet_desc */
149 int iso_status; /* Status for Isochronous URBs */
150 149
151 int state; /* QH_STATE_xxx; see above */ 150 int state; /* QH_STATE_xxx; see above */
152 int type; /* Queue type (control, bulk, etc) */ 151 int type; /* Queue type (control, bulk, etc) */
@@ -457,21 +456,6 @@ struct urb_priv {
457}; 456};
458 457
459 458
460/*
461 * Locking in uhci.c
462 *
463 * Almost everything relating to the hardware schedule and processing
464 * of URBs is protected by uhci->lock. urb->status is protected by
465 * urb->lock; that's the one exception.
466 *
467 * To prevent deadlocks, never lock uhci->lock while holding urb->lock.
468 * The safe order of locking is:
469 *
470 * #1 uhci->lock
471 * #2 urb->lock
472 */
473
474
475/* Some special IDs */ 459/* Some special IDs */
476 460
477#define PCI_VENDOR_ID_GENESYS 0x17a0 461#define PCI_VENDOR_ID_GENESYS 0x17a0
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 3bb908ca38e9..e5d60d5b105a 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -757,7 +757,6 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci,
757 uhci_free_td(uhci, td); 757 uhci_free_td(uhci, td);
758 } 758 }
759 759
760 urbp->urb->hcpriv = NULL;
761 kmem_cache_free(uhci_up_cachep, urbp); 760 kmem_cache_free(uhci_up_cachep, urbp);
762} 761}
763 762
@@ -1324,7 +1323,6 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1324 if (list_empty(&qh->queue)) { 1323 if (list_empty(&qh->queue)) {
1325 qh->iso_packet_desc = &urb->iso_frame_desc[0]; 1324 qh->iso_packet_desc = &urb->iso_frame_desc[0];
1326 qh->iso_frame = urb->start_frame; 1325 qh->iso_frame = urb->start_frame;
1327 qh->iso_status = 0;
1328 } 1326 }
1329 1327
1330 qh->skel = SKEL_ISO; 1328 qh->skel = SKEL_ISO;
@@ -1361,22 +1359,18 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1361 qh->iso_packet_desc->actual_length = actlength; 1359 qh->iso_packet_desc->actual_length = actlength;
1362 qh->iso_packet_desc->status = status; 1360 qh->iso_packet_desc->status = status;
1363 } 1361 }
1364 1362 if (status)
1365 if (status) {
1366 urb->error_count++; 1363 urb->error_count++;
1367 qh->iso_status = status;
1368 }
1369 1364
1370 uhci_remove_td_from_urbp(td); 1365 uhci_remove_td_from_urbp(td);
1371 uhci_free_td(uhci, td); 1366 uhci_free_td(uhci, td);
1372 qh->iso_frame += qh->period; 1367 qh->iso_frame += qh->period;
1373 ++qh->iso_packet_desc; 1368 ++qh->iso_packet_desc;
1374 } 1369 }
1375 return qh->iso_status; 1370 return 0;
1376} 1371}
1377 1372
1378static int uhci_urb_enqueue(struct usb_hcd *hcd, 1373static int uhci_urb_enqueue(struct usb_hcd *hcd,
1379 struct usb_host_endpoint *hep,
1380 struct urb *urb, gfp_t mem_flags) 1374 struct urb *urb, gfp_t mem_flags)
1381{ 1375{
1382 int ret; 1376 int ret;
@@ -1387,19 +1381,19 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1387 1381
1388 spin_lock_irqsave(&uhci->lock, flags); 1382 spin_lock_irqsave(&uhci->lock, flags);
1389 1383
1390 ret = urb->status; 1384 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1391 if (ret != -EINPROGRESS) /* URB already unlinked! */ 1385 if (ret)
1392 goto done; 1386 goto done_not_linked;
1393 1387
1394 ret = -ENOMEM; 1388 ret = -ENOMEM;
1395 urbp = uhci_alloc_urb_priv(uhci, urb); 1389 urbp = uhci_alloc_urb_priv(uhci, urb);
1396 if (!urbp) 1390 if (!urbp)
1397 goto done; 1391 goto done;
1398 1392
1399 if (hep->hcpriv) 1393 if (urb->ep->hcpriv)
1400 qh = (struct uhci_qh *) hep->hcpriv; 1394 qh = urb->ep->hcpriv;
1401 else { 1395 else {
1402 qh = uhci_alloc_qh(uhci, urb->dev, hep); 1396 qh = uhci_alloc_qh(uhci, urb->dev, urb->ep);
1403 if (!qh) 1397 if (!qh)
1404 goto err_no_qh; 1398 goto err_no_qh;
1405 } 1399 }
@@ -1440,27 +1434,29 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1440err_submit_failed: 1434err_submit_failed:
1441 if (qh->state == QH_STATE_IDLE) 1435 if (qh->state == QH_STATE_IDLE)
1442 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */ 1436 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */
1443
1444err_no_qh: 1437err_no_qh:
1445 uhci_free_urb_priv(uhci, urbp); 1438 uhci_free_urb_priv(uhci, urbp);
1446
1447done: 1439done:
1440 if (ret)
1441 usb_hcd_unlink_urb_from_ep(hcd, urb);
1442done_not_linked:
1448 spin_unlock_irqrestore(&uhci->lock, flags); 1443 spin_unlock_irqrestore(&uhci->lock, flags);
1449 return ret; 1444 return ret;
1450} 1445}
1451 1446
1452static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 1447static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1453{ 1448{
1454 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1449 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1455 unsigned long flags; 1450 unsigned long flags;
1456 struct urb_priv *urbp;
1457 struct uhci_qh *qh; 1451 struct uhci_qh *qh;
1452 int rc;
1458 1453
1459 spin_lock_irqsave(&uhci->lock, flags); 1454 spin_lock_irqsave(&uhci->lock, flags);
1460 urbp = urb->hcpriv; 1455 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1461 if (!urbp) /* URB was never linked! */ 1456 if (rc)
1462 goto done; 1457 goto done;
1463 qh = urbp->qh; 1458
1459 qh = ((struct urb_priv *) urb->hcpriv)->qh;
1464 1460
1465 /* Remove Isochronous TDs from the frame list ASAP */ 1461 /* Remove Isochronous TDs from the frame list ASAP */
1466 if (qh->type == USB_ENDPOINT_XFER_ISOC) { 1462 if (qh->type == USB_ENDPOINT_XFER_ISOC) {
@@ -1477,14 +1473,14 @@ static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1477 1473
1478done: 1474done:
1479 spin_unlock_irqrestore(&uhci->lock, flags); 1475 spin_unlock_irqrestore(&uhci->lock, flags);
1480 return 0; 1476 return rc;
1481} 1477}
1482 1478
1483/* 1479/*
1484 * Finish unlinking an URB and give it back 1480 * Finish unlinking an URB and give it back
1485 */ 1481 */
1486static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh, 1482static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh,
1487 struct urb *urb) 1483 struct urb *urb, int status)
1488__releases(uhci->lock) 1484__releases(uhci->lock)
1489__acquires(uhci->lock) 1485__acquires(uhci->lock)
1490{ 1486{
@@ -1497,13 +1493,6 @@ __acquires(uhci->lock)
1497 * unlinked first. Regardless, don't confuse people with a 1493 * unlinked first. Regardless, don't confuse people with a
1498 * negative length. */ 1494 * negative length. */
1499 urb->actual_length = max(urb->actual_length, 0); 1495 urb->actual_length = max(urb->actual_length, 0);
1500
1501 /* Report erroneous short transfers */
1502 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1503 urb->actual_length <
1504 urb->transfer_buffer_length &&
1505 urb->status == 0))
1506 urb->status = -EREMOTEIO;
1507 } 1496 }
1508 1497
1509 /* When giving back the first URB in an Isochronous queue, 1498 /* When giving back the first URB in an Isochronous queue,
@@ -1516,7 +1505,6 @@ __acquires(uhci->lock)
1516 1505
1517 qh->iso_packet_desc = &nurb->iso_frame_desc[0]; 1506 qh->iso_packet_desc = &nurb->iso_frame_desc[0];
1518 qh->iso_frame = nurb->start_frame; 1507 qh->iso_frame = nurb->start_frame;
1519 qh->iso_status = 0;
1520 } 1508 }
1521 1509
1522 /* Take the URB off the QH's queue. If the queue is now empty, 1510 /* Take the URB off the QH's queue. If the queue is now empty,
@@ -1529,9 +1517,10 @@ __acquires(uhci->lock)
1529 } 1517 }
1530 1518
1531 uhci_free_urb_priv(uhci, urbp); 1519 uhci_free_urb_priv(uhci, urbp);
1520 usb_hcd_unlink_urb_from_ep(uhci_to_hcd(uhci), urb);
1532 1521
1533 spin_unlock(&uhci->lock); 1522 spin_unlock(&uhci->lock);
1534 usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb); 1523 usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb, status);
1535 spin_lock(&uhci->lock); 1524 spin_lock(&uhci->lock);
1536 1525
1537 /* If the queue is now empty, we can unlink the QH and give up its 1526 /* If the queue is now empty, we can unlink the QH and give up its
@@ -1567,24 +1556,17 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
1567 if (status == -EINPROGRESS) 1556 if (status == -EINPROGRESS)
1568 break; 1557 break;
1569 1558
1570 spin_lock(&urb->lock);
1571 if (urb->status == -EINPROGRESS) /* Not dequeued */
1572 urb->status = status;
1573 else
1574 status = ECONNRESET; /* Not -ECONNRESET */
1575 spin_unlock(&urb->lock);
1576
1577 /* Dequeued but completed URBs can't be given back unless 1559 /* Dequeued but completed URBs can't be given back unless
1578 * the QH is stopped or has finished unlinking. */ 1560 * the QH is stopped or has finished unlinking. */
1579 if (status == ECONNRESET) { 1561 if (urb->unlinked) {
1580 if (QH_FINISHED_UNLINKING(qh)) 1562 if (QH_FINISHED_UNLINKING(qh))
1581 qh->is_stopped = 1; 1563 qh->is_stopped = 1;
1582 else if (!qh->is_stopped) 1564 else if (!qh->is_stopped)
1583 return; 1565 return;
1584 } 1566 }
1585 1567
1586 uhci_giveback_urb(uhci, qh, urb); 1568 uhci_giveback_urb(uhci, qh, urb, status);
1587 if (status < 0 && qh->type != USB_ENDPOINT_XFER_ISOC) 1569 if (status < 0)
1588 break; 1570 break;
1589 } 1571 }
1590 1572
@@ -1599,7 +1581,7 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
1599restart: 1581restart:
1600 list_for_each_entry(urbp, &qh->queue, node) { 1582 list_for_each_entry(urbp, &qh->queue, node) {
1601 urb = urbp->urb; 1583 urb = urbp->urb;
1602 if (urb->status != -EINPROGRESS) { 1584 if (urb->unlinked) {
1603 1585
1604 /* Fix up the TD links and save the toggles for 1586 /* Fix up the TD links and save the toggles for
1605 * non-Isochronous queues. For Isochronous queues, 1587 * non-Isochronous queues. For Isochronous queues,
@@ -1608,7 +1590,7 @@ restart:
1608 qh->is_stopped = 0; 1590 qh->is_stopped = 0;
1609 return; 1591 return;
1610 } 1592 }
1611 uhci_giveback_urb(uhci, qh, urb); 1593 uhci_giveback_urb(uhci, qh, urb, 0);
1612 goto restart; 1594 goto restart;
1613 } 1595 }
1614 } 1596 }