aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-q.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/ehci-q.c')
-rw-r--r--drivers/usb/host/ehci-q.c104
1 files changed, 73 insertions, 31 deletions
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 2e49de820b1..5ae689139dd 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -242,7 +242,8 @@ __acquires(ehci->lock)
242 if (unlikely(urb->unlinked)) { 242 if (unlikely(urb->unlinked)) {
243 COUNT(ehci->stats.unlink); 243 COUNT(ehci->stats.unlink);
244 } else { 244 } else {
245 if (likely(status == -EINPROGRESS)) 245 /* report non-error and short read status as zero */
246 if (status == -EINPROGRESS || status == -EREMOTEIO)
246 status = 0; 247 status = 0;
247 COUNT(ehci->stats.complete); 248 COUNT(ehci->stats.complete);
248 } 249 }
@@ -250,7 +251,7 @@ __acquires(ehci->lock)
250#ifdef EHCI_URB_TRACE 251#ifdef EHCI_URB_TRACE
251 ehci_dbg (ehci, 252 ehci_dbg (ehci,
252 "%s %s urb %p ep%d%s status %d len %d/%d\n", 253 "%s %s urb %p ep%d%s status %d len %d/%d\n",
253 __FUNCTION__, urb->dev->devpath, urb, 254 __func__, urb->dev->devpath, urb,
254 usb_pipeendpoint (urb->pipe), 255 usb_pipeendpoint (urb->pipe),
255 usb_pipein (urb->pipe) ? "in" : "out", 256 usb_pipein (urb->pipe) ? "in" : "out",
256 status, 257 status,
@@ -283,7 +284,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
283 int last_status = -EINPROGRESS; 284 int last_status = -EINPROGRESS;
284 int stopped; 285 int stopped;
285 unsigned count = 0; 286 unsigned count = 0;
286 int do_status = 0;
287 u8 state; 287 u8 state;
288 u32 halt = HALT_BIT(ehci); 288 u32 halt = HALT_BIT(ehci);
289 289
@@ -309,7 +309,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
309 struct ehci_qtd *qtd; 309 struct ehci_qtd *qtd;
310 struct urb *urb; 310 struct urb *urb;
311 u32 token = 0; 311 u32 token = 0;
312 int qtd_status;
313 312
314 qtd = list_entry (entry, struct ehci_qtd, qtd_list); 313 qtd = list_entry (entry, struct ehci_qtd, qtd_list);
315 urb = qtd->urb; 314 urb = qtd->urb;
@@ -336,11 +335,20 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
336 /* always clean up qtds the hc de-activated */ 335 /* always clean up qtds the hc de-activated */
337 if ((token & QTD_STS_ACTIVE) == 0) { 336 if ((token & QTD_STS_ACTIVE) == 0) {
338 337
338 /* on STALL, error, and short reads this urb must
339 * complete and all its qtds must be recycled.
340 */
339 if ((token & QTD_STS_HALT) != 0) { 341 if ((token & QTD_STS_HALT) != 0) {
340 stopped = 1; 342 stopped = 1;
341 343
342 /* magic dummy for some short reads; qh won't advance. 344 /* magic dummy for some short reads; qh won't advance.
343 * that silicon quirk can kick in with this dummy too. 345 * that silicon quirk can kick in with this dummy too.
346 *
347 * other short reads won't stop the queue, including
348 * control transfers (status stage handles that) or
349 * most other single-qtd reads ... the queue stops if
350 * URB_SHORT_NOT_OK was set so the driver submitting
351 * the urbs could clean it up.
344 */ 352 */
345 } else if (IS_SHORT_READ (token) 353 } else if (IS_SHORT_READ (token)
346 && !(qtd->hw_alt_next 354 && !(qtd->hw_alt_next
@@ -354,28 +362,21 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
354 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) { 362 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) {
355 break; 363 break;
356 364
365 /* scan the whole queue for unlinks whenever it stops */
357 } else { 366 } else {
358 stopped = 1; 367 stopped = 1;
359 368
360 if (unlikely (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) 369 /* cancel everything if we halt, suspend, etc */
370 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))
361 last_status = -ESHUTDOWN; 371 last_status = -ESHUTDOWN;
362 372
363 /* ignore active urbs unless some previous qtd 373 /* this qtd is active; skip it unless a previous qtd
364 * for the urb faulted (including short read) or 374 * for its urb faulted, or its urb was canceled.
365 * its urb was canceled. we may patch qh or qtds.
366 */ 375 */
367 if (likely(last_status == -EINPROGRESS && 376 else if (last_status == -EINPROGRESS && !urb->unlinked)
368 !urb->unlinked))
369 continue;
370
371 /* issue status after short control reads */
372 if (unlikely (do_status != 0)
373 && QTD_PID (token) == 0 /* OUT */) {
374 do_status = 0;
375 continue; 377 continue;
376 }
377 378
378 /* token in overlay may be most current */ 379 /* qh unlinked; token in overlay may be most current */
379 if (state == QH_STATE_IDLE 380 if (state == QH_STATE_IDLE
380 && cpu_to_hc32(ehci, qtd->qtd_dma) 381 && cpu_to_hc32(ehci, qtd->qtd_dma)
381 == qh->hw_current) 382 == qh->hw_current)
@@ -392,21 +393,32 @@ halt:
392 } 393 }
393 } 394 }
394 395
395 /* remove it from the queue */ 396 /* unless we already know the urb's status, collect qtd status
396 qtd_status = qtd_copy_status(ehci, urb, qtd->length, token); 397 * and update count of bytes transferred. in common short read
397 if (unlikely(qtd_status == -EREMOTEIO)) { 398 * cases with only one data qtd (including control transfers),
398 do_status = (!urb->unlinked && 399 * queue processing won't halt. but with two or more qtds (for
399 usb_pipecontrol(urb->pipe)); 400 * example, with a 32 KB transfer), when the first qtd gets a
400 qtd_status = 0; 401 * short read the second must be removed by hand.
402 */
403 if (last_status == -EINPROGRESS) {
404 last_status = qtd_copy_status(ehci, urb,
405 qtd->length, token);
406 if (last_status == -EREMOTEIO
407 && (qtd->hw_alt_next
408 & EHCI_LIST_END(ehci)))
409 last_status = -EINPROGRESS;
401 } 410 }
402 if (likely(last_status == -EINPROGRESS))
403 last_status = qtd_status;
404 411
412 /* if we're removing something not at the queue head,
413 * patch the hardware queue pointer.
414 */
405 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { 415 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
406 last = list_entry (qtd->qtd_list.prev, 416 last = list_entry (qtd->qtd_list.prev,
407 struct ehci_qtd, qtd_list); 417 struct ehci_qtd, qtd_list);
408 last->hw_next = qtd->hw_next; 418 last->hw_next = qtd->hw_next;
409 } 419 }
420
421 /* remove qtd; it's recycled after possible urb completion */
410 list_del (&qtd->qtd_list); 422 list_del (&qtd->qtd_list);
411 last = qtd; 423 last = qtd;
412 } 424 }
@@ -431,7 +443,15 @@ halt:
431 qh_refresh(ehci, qh); 443 qh_refresh(ehci, qh);
432 break; 444 break;
433 case QH_STATE_LINKED: 445 case QH_STATE_LINKED:
434 /* should be rare for periodic transfers, 446 /* We won't refresh a QH that's linked (after the HC
447 * stopped the queue). That avoids a race:
448 * - HC reads first part of QH;
449 * - CPU updates that first part and the token;
450 * - HC reads rest of that QH, including token
451 * Result: HC gets an inconsistent image, and then
452 * DMAs to/from the wrong memory (corrupting it).
453 *
454 * That should be rare for interrupt transfers,
435 * except maybe high bandwidth ... 455 * except maybe high bandwidth ...
436 */ 456 */
437 if ((cpu_to_hc32(ehci, QH_SMASK) 457 if ((cpu_to_hc32(ehci, QH_SMASK)
@@ -549,6 +569,12 @@ qh_urb_transaction (
549 this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket); 569 this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket);
550 len -= this_qtd_len; 570 len -= this_qtd_len;
551 buf += this_qtd_len; 571 buf += this_qtd_len;
572
573 /*
574 * short reads advance to a "magic" dummy instead of the next
575 * qtd ... that forces the queue to stop, for manual cleanup.
576 * (this will usually be overridden later.)
577 */
552 if (is_input) 578 if (is_input)
553 qtd->hw_alt_next = ehci->async->hw_alt_next; 579 qtd->hw_alt_next = ehci->async->hw_alt_next;
554 580
@@ -568,8 +594,10 @@ qh_urb_transaction (
568 list_add_tail (&qtd->qtd_list, head); 594 list_add_tail (&qtd->qtd_list, head);
569 } 595 }
570 596
571 /* unless the bulk/interrupt caller wants a chance to clean 597 /*
572 * up after short reads, hc should advance qh past this urb 598 * unless the caller requires manual cleanup after short reads,
599 * have the alt_next mechanism keep the queue running after the
600 * last data qtd (the only one, for control and most other cases).
573 */ 601 */
574 if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 602 if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
575 || usb_pipecontrol (urb->pipe))) 603 || usb_pipecontrol (urb->pipe)))
@@ -657,6 +685,14 @@ qh_make (
657 type = usb_pipetype (urb->pipe); 685 type = usb_pipetype (urb->pipe);
658 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input); 686 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
659 687
688 /* 1024 byte maxpacket is a hardware ceiling. High bandwidth
689 * acts like up to 3KB, but is built from smaller packets.
690 */
691 if (max_packet(maxp) > 1024) {
692 ehci_dbg(ehci, "bogus qh maxpacket %d\n", max_packet(maxp));
693 goto done;
694 }
695
660 /* Compute interrupt scheduling parameters just once, and save. 696 /* Compute interrupt scheduling parameters just once, and save.
661 * - allowing for high bandwidth, how many nsec/uframe are used? 697 * - allowing for high bandwidth, how many nsec/uframe are used?
662 * - split transactions need a second CSPLIT uframe; same question 698 * - split transactions need a second CSPLIT uframe; same question
@@ -757,7 +793,13 @@ qh_make (
757 info2 |= (EHCI_TUNE_MULT_HS << 30); 793 info2 |= (EHCI_TUNE_MULT_HS << 30);
758 } else if (type == PIPE_BULK) { 794 } else if (type == PIPE_BULK) {
759 info1 |= (EHCI_TUNE_RL_HS << 28); 795 info1 |= (EHCI_TUNE_RL_HS << 28);
760 info1 |= 512 << 16; /* usb2 fixed maxpacket */ 796 /* The USB spec says that high speed bulk endpoints
797 * always use 512 byte maxpacket. But some device
798 * vendors decided to ignore that, and MSFT is happy
799 * to help them do so. So now people expect to use
800 * such nonconformant devices with Linux too; sigh.
801 */
802 info1 |= max_packet(maxp) << 16;
761 info2 |= (EHCI_TUNE_MULT_HS << 30); 803 info2 |= (EHCI_TUNE_MULT_HS << 30);
762 } else { /* PIPE_INTERRUPT */ 804 } else { /* PIPE_INTERRUPT */
763 info1 |= max_packet (maxp) << 16; 805 info1 |= max_packet (maxp) << 16;
@@ -932,7 +974,7 @@ submit_async (
932#ifdef EHCI_URB_TRACE 974#ifdef EHCI_URB_TRACE
933 ehci_dbg (ehci, 975 ehci_dbg (ehci,
934 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", 976 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
935 __FUNCTION__, urb->dev->devpath, urb, 977 __func__, urb->dev->devpath, urb,
936 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 978 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
937 urb->transfer_buffer_length, 979 urb->transfer_buffer_length,
938 qtd, urb->ep->hcpriv); 980 qtd, urb->ep->hcpriv);