diff options
author | Sarah Sharp <sarah.a.sharp@linux.intel.com> | 2010-12-16 14:21:10 -0500 |
---|---|---|
committer | Sarah Sharp <sarah.a.sharp@linux.intel.com> | 2011-03-13 21:23:39 -0400 |
commit | f6ff0ac878eb420011fa2448851dd48c3a7e7b31 (patch) | |
tree | 4073e9de7541030ee7b775d118a1ee1d1821a0c7 /drivers/usb/host/xhci.c | |
parent | 5233630fcdd6f7d415dcbed264031439cab73f9d (diff) |
xhci: Register second xHCI roothub.
This patch changes the xHCI driver to allocate two roothubs. This touches
the driver initialization and shutdown paths, roothub emulation code, and
port status change event handlers. This is a rather large patch, but it
can't be broken up, or it would break git-bisect.
Make the xHCI driver register its own PCI probe function. This will call
the USB core to create the USB 2.0 roothub, and then create the USB 3.0
roothub. This gets the code for registering a shared roothub out of the
USB core, and allows other HCDs later to decide if and how many shared
roothubs they want to allocate.
Make sure the xHCI's reset method marks the xHCI host controller's primary
roothub as the USB 2.0 roothub. This ensures that the high speed bus will
be processed first when the PCI device is resumed, and any USB 3.0 devices
that have migrated over to high speed will migrate back after being reset.
This ensures that USB persist works with these odd devices.
The reset method will also mark the xHCI USB2 roothub as having an
integrated TT. Like EHCI host controllers with a "rate matching hub" the
xHCI USB 2.0 roothub doesn't have an OHCI or UHCI companion controller.
It doesn't really have a TT, but we'll lie and say it has an integrated
TT. We need to do this because the USB core will reject LS/FS devices
under a HS hub without a TT.
Other details:
-------------
The roothub emulation code is changed to return the correct number of
ports for the two roothubs. For the USB 3.0 roothub, it only reports the
USB 3.0 ports. For the USB 2.0 roothub, it reports all the LS/FS/HS
ports. The code to disable a port now checks the speed of the roothub,
and refuses to disable SuperSpeed ports under the USB 3.0 roothub.
The code for initializing a new device context must be changed to set the
proper roothub port number. Since we've split the xHCI host into two
roothubs, we can't just use the port number in the ancestor hub. Instead,
we loop through the array of hardware port status register speeds and find
the Nth port with a similar speed.
The port status change event handler is updated to figure out whether the
port that reported the change is a USB 3.0 port, or a non-SuperSpeed port.
Once it figures out the port speed, it kicks the proper roothub.
The function to find a slot ID based on the port index is updated to take
into account that the two roothubs will have over-lapping port indexes.
It checks that the virtual device with a matching port index is the same
speed as the passed in roothub.
There's also changes to the driver initialization and shutdown paths:
1. Make sure that the xhci_hcd pointer is shared across the two
usb_hcd structures. The xhci_hcd pointer is allocated and the
registers are mapped in when xhci_pci_setup() is called with the
primary HCD. When xhci_pci_setup() is called with the non-primary
HCD, the xhci_hcd pointer is stored.
2. Make sure to set the sg_tablesize for both usb_hcd structures. Set
the PCI DMA mask for the non-primary HCD to allow for 64-bit or 32-bit
DMA. (The PCI DMA mask is set from the primary HCD further down in
the xhci_pci_setup() function.)
3. Ensure that the host controller doesn't start kicking khubd in
response to port status changes before both usb_hcd structures are
registered. xhci_run() only starts the xHC running once it has been
called with the non-primary roothub. Similarly, the xhci_stop()
function only halts the host controller when it is called with the
non-primary HCD. Then on the second call, it resets and cleans up the
MSI-X irqs.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Diffstat (limited to 'drivers/usb/host/xhci.c')
-rw-r--r-- | drivers/usb/host/xhci.c | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 8d45bbde3da4..4549068758f5 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -375,6 +375,21 @@ void xhci_event_ring_work(unsigned long arg) | |||
375 | } | 375 | } |
376 | #endif | 376 | #endif |
377 | 377 | ||
378 | static int xhci_run_finished(struct xhci_hcd *xhci) | ||
379 | { | ||
380 | if (xhci_start(xhci)) { | ||
381 | xhci_halt(xhci); | ||
382 | return -ENODEV; | ||
383 | } | ||
384 | xhci->shared_hcd->state = HC_STATE_RUNNING; | ||
385 | |||
386 | if (xhci->quirks & XHCI_NEC_HOST) | ||
387 | xhci_ring_cmd_db(xhci); | ||
388 | |||
389 | xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n"); | ||
390 | return 0; | ||
391 | } | ||
392 | |||
378 | /* | 393 | /* |
379 | * Start the HC after it was halted. | 394 | * Start the HC after it was halted. |
380 | * | 395 | * |
@@ -395,7 +410,13 @@ int xhci_run(struct usb_hcd *hcd) | |||
395 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 410 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
396 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 411 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
397 | 412 | ||
413 | /* Start the xHCI host controller running only after the USB 2.0 roothub | ||
414 | * is setup. | ||
415 | */ | ||
416 | |||
398 | hcd->uses_new_polling = 1; | 417 | hcd->uses_new_polling = 1; |
418 | if (!usb_hcd_is_primary_hcd(hcd)) | ||
419 | return xhci_run_finished(xhci); | ||
399 | 420 | ||
400 | xhci_dbg(xhci, "xhci_run\n"); | 421 | xhci_dbg(xhci, "xhci_run\n"); |
401 | /* unregister the legacy interrupt */ | 422 | /* unregister the legacy interrupt */ |
@@ -469,16 +490,23 @@ int xhci_run(struct usb_hcd *hcd) | |||
469 | xhci_queue_vendor_command(xhci, 0, 0, 0, | 490 | xhci_queue_vendor_command(xhci, 0, 0, 0, |
470 | TRB_TYPE(TRB_NEC_GET_FW)); | 491 | TRB_TYPE(TRB_NEC_GET_FW)); |
471 | 492 | ||
472 | if (xhci_start(xhci)) { | 493 | xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n"); |
473 | xhci_halt(xhci); | 494 | return 0; |
474 | return -ENODEV; | 495 | } |
475 | } | ||
476 | 496 | ||
477 | if (xhci->quirks & XHCI_NEC_HOST) | 497 | static void xhci_only_stop_hcd(struct usb_hcd *hcd) |
478 | xhci_ring_cmd_db(xhci); | 498 | { |
499 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
479 | 500 | ||
480 | xhci_dbg(xhci, "Finished xhci_run\n"); | 501 | spin_lock_irq(&xhci->lock); |
481 | return 0; | 502 | xhci_halt(xhci); |
503 | |||
504 | /* The shared_hcd is going to be deallocated shortly (the USB core only | ||
505 | * calls this function when allocation fails in usb_add_hcd(), or | ||
506 | * usb_remove_hcd() is called). So we need to unset xHCI's pointer. | ||
507 | */ | ||
508 | xhci->shared_hcd = NULL; | ||
509 | spin_unlock_irq(&xhci->lock); | ||
482 | } | 510 | } |
483 | 511 | ||
484 | /* | 512 | /* |
@@ -495,7 +523,15 @@ void xhci_stop(struct usb_hcd *hcd) | |||
495 | u32 temp; | 523 | u32 temp; |
496 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 524 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
497 | 525 | ||
526 | if (!usb_hcd_is_primary_hcd(hcd)) { | ||
527 | xhci_only_stop_hcd(xhci->shared_hcd); | ||
528 | return; | ||
529 | } | ||
530 | |||
498 | spin_lock_irq(&xhci->lock); | 531 | spin_lock_irq(&xhci->lock); |
532 | /* Make sure the xHC is halted for a USB3 roothub | ||
533 | * (xhci_stop() could be called as part of failed init). | ||
534 | */ | ||
499 | xhci_halt(xhci); | 535 | xhci_halt(xhci); |
500 | xhci_reset(xhci); | 536 | xhci_reset(xhci); |
501 | spin_unlock_irq(&xhci->lock); | 537 | spin_unlock_irq(&xhci->lock); |
@@ -528,6 +564,8 @@ void xhci_stop(struct usb_hcd *hcd) | |||
528 | * This is called when the machine is rebooting or halting. We assume that the | 564 | * This is called when the machine is rebooting or halting. We assume that the |
529 | * machine will be powered off, and the HC's internal state will be reset. | 565 | * machine will be powered off, and the HC's internal state will be reset. |
530 | * Don't bother to free memory. | 566 | * Don't bother to free memory. |
567 | * | ||
568 | * This will only ever be called with the main usb_hcd (the USB3 roothub). | ||
531 | */ | 569 | */ |
532 | void xhci_shutdown(struct usb_hcd *hcd) | 570 | void xhci_shutdown(struct usb_hcd *hcd) |
533 | { | 571 | { |
@@ -694,10 +732,12 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
694 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 732 | struct usb_hcd *hcd = xhci_to_hcd(xhci); |
695 | int retval; | 733 | int retval; |
696 | 734 | ||
697 | /* Wait a bit if the bus needs to settle from the transistion to | 735 | /* Wait a bit if either of the roothubs need to settle from the |
698 | * suspend. | 736 | * transistion into bus suspend. |
699 | */ | 737 | */ |
700 | if (time_before(jiffies, xhci->bus_state[0].next_statechange)) | 738 | if (time_before(jiffies, xhci->bus_state[0].next_statechange) || |
739 | time_before(jiffies, | ||
740 | xhci->bus_state[1].next_statechange)) | ||
701 | msleep(100); | 741 | msleep(100); |
702 | 742 | ||
703 | spin_lock_irq(&xhci->lock); | 743 | spin_lock_irq(&xhci->lock); |