aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
commit971f115a50afbe409825c9f3399d5a3b9aca4381 (patch)
treecb42dc07a032e325f22b64d961587c081225c6d6 /drivers/usb/host/xhci.c
parent2e270d84223262a38d4755c61d55f5c73ea89e56 (diff)
parent500132a0f26ad7d9916102193cbc6c1b1becb373 (diff)
Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (172 commits) USB: Add support for SuperSpeed isoc endpoints xhci: Clean up cycle bit math used during stalls. xhci: Fix cycle bit calculation during stall handling. xhci: Update internal dequeue pointers after stalls. USB: Disable auto-suspend for USB 3.0 hubs. USB: Remove bogus USB_PORT_STAT_SUPER_SPEED symbol. xhci: Return canceled URBs immediately when host is halted. xhci: Fixes for suspend/resume of shared HCDs. xhci: Fix re-init on power loss after resume. xhci: Make roothub functions deal with device removal. xhci: Limit roothub ports to 15 USB3 & 31 USB2 ports. xhci: Return a USB 3.0 hub descriptor for USB3 roothub. xhci: Register second xHCI roothub. xhci: Change xhci_find_slot_id_by_port() API. xhci: Refactor bus suspend state into a struct. xhci: Index with a port array instead of PORTSC addresses. USB: Set usb_hcd->state and flags for shared roothubs. usb: Make core allocate resources per PCI-device. usb: Store bus type in usb_hcd, not in driver flags. usb: Change usb_hcd->bandwidth_mutex to a pointer. ...
Diffstat (limited to 'drivers/usb/host/xhci.c')
-rw-r--r--drivers/usb/host/xhci.c129
1 files changed, 90 insertions, 39 deletions
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2083fc2179b2..9a3645fd759b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -93,17 +93,20 @@ void xhci_quiesce(struct xhci_hcd *xhci)
93 * 93 *
94 * Disable any IRQs and clear the run/stop bit. 94 * Disable any IRQs and clear the run/stop bit.
95 * HC will complete any current and actively pipelined transactions, and 95 * HC will complete any current and actively pipelined transactions, and
96 * should halt within 16 microframes of the run/stop bit being cleared. 96 * should halt within 16 ms of the run/stop bit being cleared.
97 * Read HC Halted bit in the status register to see when the HC is finished. 97 * Read HC Halted bit in the status register to see when the HC is finished.
98 * XXX: shouldn't we set HC_STATE_HALT here somewhere?
99 */ 98 */
100int xhci_halt(struct xhci_hcd *xhci) 99int xhci_halt(struct xhci_hcd *xhci)
101{ 100{
101 int ret;
102 xhci_dbg(xhci, "// Halt the HC\n"); 102 xhci_dbg(xhci, "// Halt the HC\n");
103 xhci_quiesce(xhci); 103 xhci_quiesce(xhci);
104 104
105 return handshake(xhci, &xhci->op_regs->status, 105 ret = handshake(xhci, &xhci->op_regs->status,
106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); 106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
107 if (!ret)
108 xhci->xhc_state |= XHCI_STATE_HALTED;
109 return ret;
107} 110}
108 111
109/* 112/*
@@ -130,11 +133,13 @@ static int xhci_start(struct xhci_hcd *xhci)
130 xhci_err(xhci, "Host took too long to start, " 133 xhci_err(xhci, "Host took too long to start, "
131 "waited %u microseconds.\n", 134 "waited %u microseconds.\n",
132 XHCI_MAX_HALT_USEC); 135 XHCI_MAX_HALT_USEC);
136 if (!ret)
137 xhci->xhc_state &= ~XHCI_STATE_HALTED;
133 return ret; 138 return ret;
134} 139}
135 140
136/* 141/*
137 * Reset a halted HC, and set the internal HC state to HC_STATE_HALT. 142 * Reset a halted HC.
138 * 143 *
139 * This resets pipelines, timers, counters, state machines, etc. 144 * This resets pipelines, timers, counters, state machines, etc.
140 * Transactions will be terminated immediately, and operational registers 145 * Transactions will be terminated immediately, and operational registers
@@ -156,8 +161,6 @@ int xhci_reset(struct xhci_hcd *xhci)
156 command = xhci_readl(xhci, &xhci->op_regs->command); 161 command = xhci_readl(xhci, &xhci->op_regs->command);
157 command |= CMD_RESET; 162 command |= CMD_RESET;
158 xhci_writel(xhci, command, &xhci->op_regs->command); 163 xhci_writel(xhci, command, &xhci->op_regs->command);
159 /* XXX: Why does EHCI set this here? Shouldn't other code do this? */
160 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
161 164
162 ret = handshake(xhci, &xhci->op_regs->command, 165 ret = handshake(xhci, &xhci->op_regs->command,
163 CMD_RESET, 0, 250 * 1000); 166 CMD_RESET, 0, 250 * 1000);
@@ -350,7 +353,6 @@ static void xhci_event_ring_work(unsigned long arg)
350 353
351 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 354 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
352 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); 355 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp);
353 xhci_dbg(xhci, "No-op commands handled = %d\n", xhci->noops_handled);
354 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); 356 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask);
355 xhci->error_bitmask = 0; 357 xhci->error_bitmask = 0;
356 xhci_dbg(xhci, "Event ring:\n"); 358 xhci_dbg(xhci, "Event ring:\n");
@@ -370,10 +372,6 @@ static void xhci_event_ring_work(unsigned long arg)
370 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]); 372 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]);
371 } 373 }
372 } 374 }
373
374 if (xhci->noops_submitted != NUM_TEST_NOOPS)
375 if (xhci_setup_one_noop(xhci))
376 xhci_ring_cmd_db(xhci);
377 spin_unlock_irqrestore(&xhci->lock, flags); 375 spin_unlock_irqrestore(&xhci->lock, flags);
378 376
379 if (!xhci->zombie) 377 if (!xhci->zombie)
@@ -383,6 +381,21 @@ static void xhci_event_ring_work(unsigned long arg)
383} 381}
384#endif 382#endif
385 383
384static int xhci_run_finished(struct xhci_hcd *xhci)
385{
386 if (xhci_start(xhci)) {
387 xhci_halt(xhci);
388 return -ENODEV;
389 }
390 xhci->shared_hcd->state = HC_STATE_RUNNING;
391
392 if (xhci->quirks & XHCI_NEC_HOST)
393 xhci_ring_cmd_db(xhci);
394
395 xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n");
396 return 0;
397}
398
386/* 399/*
387 * Start the HC after it was halted. 400 * Start the HC after it was halted.
388 * 401 *
@@ -402,9 +415,14 @@ int xhci_run(struct usb_hcd *hcd)
402 u32 ret; 415 u32 ret;
403 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 416 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
404 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 417 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
405 void (*doorbell)(struct xhci_hcd *) = NULL; 418
419 /* Start the xHCI host controller running only after the USB 2.0 roothub
420 * is setup.
421 */
406 422
407 hcd->uses_new_polling = 1; 423 hcd->uses_new_polling = 1;
424 if (!usb_hcd_is_primary_hcd(hcd))
425 return xhci_run_finished(xhci);
408 426
409 xhci_dbg(xhci, "xhci_run\n"); 427 xhci_dbg(xhci, "xhci_run\n");
410 /* unregister the legacy interrupt */ 428 /* unregister the legacy interrupt */
@@ -461,7 +479,6 @@ int xhci_run(struct usb_hcd *hcd)
461 xhci_writel(xhci, temp, &xhci->ir_set->irq_control); 479 xhci_writel(xhci, temp, &xhci->ir_set->irq_control);
462 480
463 /* Set the HCD state before we enable the irqs */ 481 /* Set the HCD state before we enable the irqs */
464 hcd->state = HC_STATE_RUNNING;
465 temp = xhci_readl(xhci, &xhci->op_regs->command); 482 temp = xhci_readl(xhci, &xhci->op_regs->command);
466 temp |= (CMD_EIE); 483 temp |= (CMD_EIE);
467 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", 484 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n",
@@ -475,24 +492,27 @@ int xhci_run(struct usb_hcd *hcd)
475 &xhci->ir_set->irq_pending); 492 &xhci->ir_set->irq_pending);
476 xhci_print_ir_set(xhci, 0); 493 xhci_print_ir_set(xhci, 0);
477 494
478 if (NUM_TEST_NOOPS > 0)
479 doorbell = xhci_setup_one_noop(xhci);
480 if (xhci->quirks & XHCI_NEC_HOST) 495 if (xhci->quirks & XHCI_NEC_HOST)
481 xhci_queue_vendor_command(xhci, 0, 0, 0, 496 xhci_queue_vendor_command(xhci, 0, 0, 0,
482 TRB_TYPE(TRB_NEC_GET_FW)); 497 TRB_TYPE(TRB_NEC_GET_FW));
483 498
484 if (xhci_start(xhci)) { 499 xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n");
485 xhci_halt(xhci); 500 return 0;
486 return -ENODEV; 501}
487 }
488 502
489 if (doorbell) 503static void xhci_only_stop_hcd(struct usb_hcd *hcd)
490 (*doorbell)(xhci); 504{
491 if (xhci->quirks & XHCI_NEC_HOST) 505 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
492 xhci_ring_cmd_db(xhci);
493 506
494 xhci_dbg(xhci, "Finished xhci_run\n"); 507 spin_lock_irq(&xhci->lock);
495 return 0; 508 xhci_halt(xhci);
509
510 /* The shared_hcd is going to be deallocated shortly (the USB core only
511 * calls this function when allocation fails in usb_add_hcd(), or
512 * usb_remove_hcd() is called). So we need to unset xHCI's pointer.
513 */
514 xhci->shared_hcd = NULL;
515 spin_unlock_irq(&xhci->lock);
496} 516}
497 517
498/* 518/*
@@ -509,7 +529,15 @@ void xhci_stop(struct usb_hcd *hcd)
509 u32 temp; 529 u32 temp;
510 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 530 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
511 531
532 if (!usb_hcd_is_primary_hcd(hcd)) {
533 xhci_only_stop_hcd(xhci->shared_hcd);
534 return;
535 }
536
512 spin_lock_irq(&xhci->lock); 537 spin_lock_irq(&xhci->lock);
538 /* Make sure the xHC is halted for a USB3 roothub
539 * (xhci_stop() could be called as part of failed init).
540 */
513 xhci_halt(xhci); 541 xhci_halt(xhci);
514 xhci_reset(xhci); 542 xhci_reset(xhci);
515 spin_unlock_irq(&xhci->lock); 543 spin_unlock_irq(&xhci->lock);
@@ -542,6 +570,8 @@ void xhci_stop(struct usb_hcd *hcd)
542 * This is called when the machine is rebooting or halting. We assume that the 570 * This is called when the machine is rebooting or halting. We assume that the
543 * machine will be powered off, and the HC's internal state will be reset. 571 * machine will be powered off, and the HC's internal state will be reset.
544 * Don't bother to free memory. 572 * Don't bother to free memory.
573 *
574 * This will only ever be called with the main usb_hcd (the USB3 roothub).
545 */ 575 */
546void xhci_shutdown(struct usb_hcd *hcd) 576void xhci_shutdown(struct usb_hcd *hcd)
547{ 577{
@@ -657,6 +687,7 @@ int xhci_suspend(struct xhci_hcd *xhci)
657 687
658 spin_lock_irq(&xhci->lock); 688 spin_lock_irq(&xhci->lock);
659 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 689 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
690 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
660 /* step 1: stop endpoint */ 691 /* step 1: stop endpoint */
661 /* skipped assuming that port suspend has done */ 692 /* skipped assuming that port suspend has done */
662 693
@@ -706,10 +737,15 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
706{ 737{
707 u32 command, temp = 0; 738 u32 command, temp = 0;
708 struct usb_hcd *hcd = xhci_to_hcd(xhci); 739 struct usb_hcd *hcd = xhci_to_hcd(xhci);
709 int old_state, retval; 740 struct usb_hcd *secondary_hcd;
741 int retval;
710 742
711 old_state = hcd->state; 743 /* Wait a bit if either of the roothubs need to settle from the
712 if (time_before(jiffies, xhci->next_statechange)) 744 * transistion into bus suspend.
745 */
746 if (time_before(jiffies, xhci->bus_state[0].next_statechange) ||
747 time_before(jiffies,
748 xhci->bus_state[1].next_statechange))
713 msleep(100); 749 msleep(100);
714 750
715 spin_lock_irq(&xhci->lock); 751 spin_lock_irq(&xhci->lock);
@@ -762,16 +798,34 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
762 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", 798 xhci_dbg(xhci, "xhci_stop completed - status = %x\n",
763 xhci_readl(xhci, &xhci->op_regs->status)); 799 xhci_readl(xhci, &xhci->op_regs->status));
764 800
765 xhci_dbg(xhci, "Initialize the HCD\n"); 801 /* USB core calls the PCI reinit and start functions twice:
766 retval = xhci_init(hcd); 802 * first with the primary HCD, and then with the secondary HCD.
803 * If we don't do the same, the host will never be started.
804 */
805 if (!usb_hcd_is_primary_hcd(hcd))
806 secondary_hcd = hcd;
807 else
808 secondary_hcd = xhci->shared_hcd;
809
810 xhci_dbg(xhci, "Initialize the xhci_hcd\n");
811 retval = xhci_init(hcd->primary_hcd);
767 if (retval) 812 if (retval)
768 return retval; 813 return retval;
814 xhci_dbg(xhci, "Start the primary HCD\n");
815 retval = xhci_run(hcd->primary_hcd);
816 if (retval)
817 goto failed_restart;
769 818
770 xhci_dbg(xhci, "Start the HCD\n"); 819 xhci_dbg(xhci, "Start the secondary HCD\n");
771 retval = xhci_run(hcd); 820 retval = xhci_run(secondary_hcd);
772 if (!retval) 821 if (!retval) {
773 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 822 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
823 set_bit(HCD_FLAG_HW_ACCESSIBLE,
824 &xhci->shared_hcd->flags);
825 }
826failed_restart:
774 hcd->state = HC_STATE_SUSPENDED; 827 hcd->state = HC_STATE_SUSPENDED;
828 xhci->shared_hcd->state = HC_STATE_SUSPENDED;
775 return retval; 829 return retval;
776 } 830 }
777 831
@@ -792,10 +846,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
792 */ 846 */
793 847
794 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 848 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
795 if (!hibernated) 849 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
796 hcd->state = old_state;
797 else
798 hcd->state = HC_STATE_SUSPENDED;
799 850
800 spin_unlock_irq(&xhci->lock); 851 spin_unlock_irq(&xhci->lock);
801 return 0; 852 return 0;
@@ -1167,13 +1218,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1167 if (ret || !urb->hcpriv) 1218 if (ret || !urb->hcpriv)
1168 goto done; 1219 goto done;
1169 temp = xhci_readl(xhci, &xhci->op_regs->status); 1220 temp = xhci_readl(xhci, &xhci->op_regs->status);
1170 if (temp == 0xffffffff) { 1221 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
1171 xhci_dbg(xhci, "HW died, freeing TD.\n"); 1222 xhci_dbg(xhci, "HW died, freeing TD.\n");
1172 urb_priv = urb->hcpriv; 1223 urb_priv = urb->hcpriv;
1173 1224
1174 usb_hcd_unlink_urb_from_ep(hcd, urb); 1225 usb_hcd_unlink_urb_from_ep(hcd, urb);
1175 spin_unlock_irqrestore(&xhci->lock, flags); 1226 spin_unlock_irqrestore(&xhci->lock, flags);
1176 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 1227 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
1177 xhci_urb_free_priv(xhci, urb_priv); 1228 xhci_urb_free_priv(xhci, urb_priv);
1178 return ret; 1229 return ret;
1179 } 1230 }