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-mem.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-mem.c')
-rw-r--r-- | drivers/usb/host/xhci-mem.c | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index bc809cbd570a..180a2abbc868 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -814,14 +814,64 @@ void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci, | |||
814 | ep0_ctx->deq |= ep_ring->cycle_state; | 814 | ep0_ctx->deq |= ep_ring->cycle_state; |
815 | } | 815 | } |
816 | 816 | ||
817 | /* | ||
818 | * The xHCI roothub may have ports of differing speeds in any order in the port | ||
819 | * status registers. xhci->port_array provides an array of the port speed for | ||
820 | * each offset into the port status registers. | ||
821 | * | ||
822 | * The xHCI hardware wants to know the roothub port number that the USB device | ||
823 | * is attached to (or the roothub port its ancestor hub is attached to). All we | ||
824 | * know is the index of that port under either the USB 2.0 or the USB 3.0 | ||
825 | * roothub, but that doesn't give us the real index into the HW port status | ||
826 | * registers. Scan through the xHCI roothub port array, looking for the Nth | ||
827 | * entry of the correct port speed. Return the port number of that entry. | ||
828 | */ | ||
829 | static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, | ||
830 | struct usb_device *udev) | ||
831 | { | ||
832 | struct usb_device *top_dev; | ||
833 | unsigned int num_similar_speed_ports; | ||
834 | unsigned int faked_port_num; | ||
835 | int i; | ||
836 | |||
837 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; | ||
838 | top_dev = top_dev->parent) | ||
839 | /* Found device below root hub */; | ||
840 | faked_port_num = top_dev->portnum; | ||
841 | for (i = 0, num_similar_speed_ports = 0; | ||
842 | i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { | ||
843 | u8 port_speed = xhci->port_array[i]; | ||
844 | |||
845 | /* | ||
846 | * Skip ports that don't have known speeds, or have duplicate | ||
847 | * Extended Capabilities port speed entries. | ||
848 | */ | ||
849 | if (port_speed == 0 || port_speed == -1) | ||
850 | continue; | ||
851 | |||
852 | /* | ||
853 | * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and | ||
854 | * 1.1 ports are under the USB 2.0 hub. If the port speed | ||
855 | * matches the device speed, it's a similar speed port. | ||
856 | */ | ||
857 | if ((port_speed == 0x03) == (udev->speed == USB_SPEED_SUPER)) | ||
858 | num_similar_speed_ports++; | ||
859 | if (num_similar_speed_ports == faked_port_num) | ||
860 | /* Roothub ports are numbered from 1 to N */ | ||
861 | return i+1; | ||
862 | } | ||
863 | return 0; | ||
864 | } | ||
865 | |||
817 | /* Setup an xHCI virtual device for a Set Address command */ | 866 | /* Setup an xHCI virtual device for a Set Address command */ |
818 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) | 867 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) |
819 | { | 868 | { |
820 | struct xhci_virt_device *dev; | 869 | struct xhci_virt_device *dev; |
821 | struct xhci_ep_ctx *ep0_ctx; | 870 | struct xhci_ep_ctx *ep0_ctx; |
822 | struct usb_device *top_dev; | ||
823 | struct xhci_slot_ctx *slot_ctx; | 871 | struct xhci_slot_ctx *slot_ctx; |
824 | struct xhci_input_control_ctx *ctrl_ctx; | 872 | struct xhci_input_control_ctx *ctrl_ctx; |
873 | u32 port_num; | ||
874 | struct usb_device *top_dev; | ||
825 | 875 | ||
826 | dev = xhci->devs[udev->slot_id]; | 876 | dev = xhci->devs[udev->slot_id]; |
827 | /* Slot ID 0 is reserved */ | 877 | /* Slot ID 0 is reserved */ |
@@ -863,12 +913,17 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
863 | BUG(); | 913 | BUG(); |
864 | } | 914 | } |
865 | /* Find the root hub port this device is under */ | 915 | /* Find the root hub port this device is under */ |
916 | port_num = xhci_find_real_port_number(xhci, udev); | ||
917 | if (!port_num) | ||
918 | return -EINVAL; | ||
919 | slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(port_num); | ||
920 | /* Set the port number in the virtual_device to the faked port number */ | ||
866 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; | 921 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; |
867 | top_dev = top_dev->parent) | 922 | top_dev = top_dev->parent) |
868 | /* Found device below root hub */; | 923 | /* Found device below root hub */; |
869 | slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(top_dev->portnum); | ||
870 | dev->port = top_dev->portnum; | 924 | dev->port = top_dev->portnum; |
871 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); | 925 | xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); |
926 | xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->port); | ||
872 | 927 | ||
873 | /* Is this a LS/FS device under an external HS hub? */ | 928 | /* Is this a LS/FS device under an external HS hub? */ |
874 | if (udev->tt && udev->tt->hub->parent) { | 929 | if (udev->tt && udev->tt->hub->parent) { |
@@ -1452,6 +1507,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1452 | xhci->page_size = 0; | 1507 | xhci->page_size = 0; |
1453 | xhci->page_shift = 0; | 1508 | xhci->page_shift = 0; |
1454 | xhci->bus_state[0].bus_suspended = 0; | 1509 | xhci->bus_state[0].bus_suspended = 0; |
1510 | xhci->bus_state[1].bus_suspended = 0; | ||
1455 | } | 1511 | } |
1456 | 1512 | ||
1457 | static int xhci_test_trb_in_td(struct xhci_hcd *xhci, | 1513 | static int xhci_test_trb_in_td(struct xhci_hcd *xhci, |
@@ -1970,8 +2026,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
1970 | init_completion(&xhci->addr_dev); | 2026 | init_completion(&xhci->addr_dev); |
1971 | for (i = 0; i < MAX_HC_SLOTS; ++i) | 2027 | for (i = 0; i < MAX_HC_SLOTS; ++i) |
1972 | xhci->devs[i] = NULL; | 2028 | xhci->devs[i] = NULL; |
1973 | for (i = 0; i < USB_MAXCHILDREN; ++i) | 2029 | for (i = 0; i < USB_MAXCHILDREN; ++i) { |
1974 | xhci->bus_state[0].resume_done[i] = 0; | 2030 | xhci->bus_state[0].resume_done[i] = 0; |
2031 | xhci->bus_state[1].resume_done[i] = 0; | ||
2032 | } | ||
1975 | 2033 | ||
1976 | if (scratchpad_alloc(xhci, flags)) | 2034 | if (scratchpad_alloc(xhci, flags)) |
1977 | goto fail; | 2035 | goto fail; |