aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-hub.c
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2010-12-16 14:21:10 -0500
committerSarah Sharp <sarah.a.sharp@linux.intel.com>2011-03-13 21:23:39 -0400
commitf6ff0ac878eb420011fa2448851dd48c3a7e7b31 (patch)
tree4073e9de7541030ee7b775d118a1ee1d1821a0c7 /drivers/usb/host/xhci-hub.c
parent5233630fcdd6f7d415dcbed264031439cab73f9d (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-hub.c')
-rw-r--r--drivers/usb/host/xhci-hub.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 4c3788c128df..ee4af076a8fe 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -28,13 +28,20 @@
28#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 28#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
29 PORT_RC | PORT_PLC | PORT_PE) 29 PORT_RC | PORT_PLC | PORT_PE)
30 30
31static void xhci_hub_descriptor(struct xhci_hcd *xhci, 31static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
32 struct usb_hub_descriptor *desc) 32 struct usb_hub_descriptor *desc)
33{ 33{
34 int ports; 34 int ports;
35 u16 temp; 35 u16 temp;
36 36
37 ports = HCS_MAX_PORTS(xhci->hcs_params1); 37 if (hcd->speed == HCD_USB3)
38 ports = xhci->num_usb3_ports;
39 else
40 ports = xhci->num_usb2_ports;
41
42 /* FIXME: return a USB 3.0 hub descriptor if this request was for the
43 * USB3 roothub.
44 */
38 45
39 /* USB 3.0 hubs have a different descriptor, but we fake this for now */ 46 /* USB 3.0 hubs have a different descriptor, but we fake this for now */
40 desc->bDescriptorType = 0x29; 47 desc->bDescriptorType = 0x29;
@@ -134,18 +141,22 @@ u32 xhci_port_state_to_neutral(u32 state)
134 141
135/* 142/*
136 * find slot id based on port number. 143 * find slot id based on port number.
144 * @port: The one-based port number from one of the two split roothubs.
137 */ 145 */
138int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, 146int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
139 u16 port) 147 u16 port)
140{ 148{
141 int slot_id; 149 int slot_id;
142 int i; 150 int i;
151 enum usb_device_speed speed;
143 152
144 slot_id = 0; 153 slot_id = 0;
145 for (i = 0; i < MAX_HC_SLOTS; i++) { 154 for (i = 0; i < MAX_HC_SLOTS; i++) {
146 if (!xhci->devs[i]) 155 if (!xhci->devs[i])
147 continue; 156 continue;
148 if (xhci->devs[i]->port == port) { 157 speed = xhci->devs[i]->udev->speed;
158 if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3))
159 && xhci->devs[i]->port == port) {
149 slot_id = i; 160 slot_id = i;
150 break; 161 break;
151 } 162 }
@@ -226,11 +237,11 @@ void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
226 return; 237 return;
227} 238}
228 239
229static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex, 240static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
230 u32 __iomem *addr, u32 port_status) 241 u16 wIndex, u32 __iomem *addr, u32 port_status)
231{ 242{
232 /* Don't allow the USB core to disable SuperSpeed ports. */ 243 /* Don't allow the USB core to disable SuperSpeed ports. */
233 if (xhci->port_array[wIndex] == 0x03) { 244 if (hcd->speed == HCD_USB3) {
234 xhci_dbg(xhci, "Ignoring request to disable " 245 xhci_dbg(xhci, "Ignoring request to disable "
235 "SuperSpeed port.\n"); 246 "SuperSpeed port.\n");
236 return; 247 return;
@@ -289,18 +300,16 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
289 unsigned long flags; 300 unsigned long flags;
290 u32 temp, temp1, status; 301 u32 temp, temp1, status;
291 int retval = 0; 302 int retval = 0;
292 u32 __iomem *port_array[15 + USB_MAXCHILDREN]; 303 u32 __iomem **port_array;
293 int i;
294 int slot_id; 304 int slot_id;
295 struct xhci_bus_state *bus_state; 305 struct xhci_bus_state *bus_state;
296 306
297 ports = HCS_MAX_PORTS(xhci->hcs_params1); 307 if (hcd->speed == HCD_USB3) {
298 for (i = 0; i < ports; i++) { 308 ports = xhci->num_usb3_ports;
299 if (i < xhci->num_usb3_ports) 309 port_array = xhci->usb3_ports;
300 port_array[i] = xhci->usb3_ports[i]; 310 } else {
301 else 311 ports = xhci->num_usb2_ports;
302 port_array[i] = 312 port_array = xhci->usb2_ports;
303 xhci->usb2_ports[i - xhci->num_usb3_ports];
304 } 313 }
305 bus_state = &xhci->bus_state[hcd_index(hcd)]; 314 bus_state = &xhci->bus_state[hcd_index(hcd)];
306 315
@@ -311,7 +320,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
311 memset(buf, 0, 4); 320 memset(buf, 0, 4);
312 break; 321 break;
313 case GetHubDescriptor: 322 case GetHubDescriptor:
314 xhci_hub_descriptor(xhci, (struct usb_hub_descriptor *) buf); 323 xhci_hub_descriptor(hcd, xhci,
324 (struct usb_hub_descriptor *) buf);
315 break; 325 break;
316 case GetPortStatus: 326 case GetPortStatus:
317 if (!wIndex || wIndex > ports) 327 if (!wIndex || wIndex > ports)
@@ -518,7 +528,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
518 port_array[wIndex], temp); 528 port_array[wIndex], temp);
519 break; 529 break;
520 case USB_PORT_FEAT_ENABLE: 530 case USB_PORT_FEAT_ENABLE:
521 xhci_disable_port(xhci, wIndex, 531 xhci_disable_port(hcd, xhci, wIndex,
522 port_array[wIndex], temp); 532 port_array[wIndex], temp);
523 break; 533 break;
524 default: 534 default:
@@ -550,16 +560,15 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
550 int i, retval; 560 int i, retval;
551 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 561 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
552 int ports; 562 int ports;
553 u32 __iomem *port_array[15 + USB_MAXCHILDREN]; 563 u32 __iomem **port_array;
554 struct xhci_bus_state *bus_state; 564 struct xhci_bus_state *bus_state;
555 565
556 ports = HCS_MAX_PORTS(xhci->hcs_params1); 566 if (hcd->speed == HCD_USB3) {
557 for (i = 0; i < ports; i++) { 567 ports = xhci->num_usb3_ports;
558 if (i < xhci->num_usb3_ports) 568 port_array = xhci->usb3_ports;
559 port_array[i] = xhci->usb3_ports[i]; 569 } else {
560 else 570 ports = xhci->num_usb2_ports;
561 port_array[i] = 571 port_array = xhci->usb2_ports;
562 xhci->usb2_ports[i - xhci->num_usb3_ports];
563 } 572 }
564 bus_state = &xhci->bus_state[hcd_index(hcd)]; 573 bus_state = &xhci->bus_state[hcd_index(hcd)];
565 574
@@ -592,19 +601,18 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
592{ 601{
593 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 602 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
594 int max_ports, port_index; 603 int max_ports, port_index;
595 u32 __iomem *port_array[15 + USB_MAXCHILDREN]; 604 u32 __iomem **port_array;
596 int i;
597 struct xhci_bus_state *bus_state; 605 struct xhci_bus_state *bus_state;
598 unsigned long flags; 606 unsigned long flags;
599 607
600 xhci_dbg(xhci, "suspend root hub\n"); 608 if (hcd->speed == HCD_USB3) {
601 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); 609 max_ports = xhci->num_usb3_ports;
602 for (i = 0; i < max_ports; i++) { 610 port_array = xhci->usb3_ports;
603 if (i < xhci->num_usb3_ports) 611 xhci_dbg(xhci, "suspend USB 3.0 root hub\n");
604 port_array[i] = xhci->usb3_ports[i]; 612 } else {
605 else 613 max_ports = xhci->num_usb2_ports;
606 port_array[i] = 614 port_array = xhci->usb2_ports;
607 xhci->usb2_ports[i - xhci->num_usb3_ports]; 615 xhci_dbg(xhci, "suspend USB 2.0 root hub\n");
608 } 616 }
609 bus_state = &xhci->bus_state[hcd_index(hcd)]; 617 bus_state = &xhci->bus_state[hcd_index(hcd)];
610 618
@@ -685,20 +693,19 @@ int xhci_bus_resume(struct usb_hcd *hcd)
685{ 693{
686 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 694 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
687 int max_ports, port_index; 695 int max_ports, port_index;
688 u32 __iomem *port_array[15 + USB_MAXCHILDREN]; 696 u32 __iomem **port_array;
689 int i;
690 struct xhci_bus_state *bus_state; 697 struct xhci_bus_state *bus_state;
691 u32 temp; 698 u32 temp;
692 unsigned long flags; 699 unsigned long flags;
693 700
694 xhci_dbg(xhci, "resume root hub\n"); 701 if (hcd->speed == HCD_USB3) {
695 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); 702 max_ports = xhci->num_usb3_ports;
696 for (i = 0; i < max_ports; i++) { 703 port_array = xhci->usb3_ports;
697 if (i < xhci->num_usb3_ports) 704 xhci_dbg(xhci, "resume USB 3.0 root hub\n");
698 port_array[i] = xhci->usb3_ports[i]; 705 } else {
699 else 706 max_ports = xhci->num_usb2_ports;
700 port_array[i] = 707 port_array = xhci->usb2_ports;
701 xhci->usb2_ports[i - xhci->num_usb3_ports]; 708 xhci_dbg(xhci, "resume USB 2.0 root hub\n");
702 } 709 }
703 bus_state = &xhci->bus_state[hcd_index(hcd)]; 710 bus_state = &xhci->bus_state[hcd_index(hcd)];
704 711