814
814
ep0_ctx->deq |= ep_ring->cycle_state;
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.
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.
829
static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
830
struct usb_device *udev)
832
struct usb_device *top_dev;
833
unsigned int num_similar_speed_ports;
834
unsigned int faked_port_num;
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];
846
* Skip ports that don't have known speeds, or have duplicate
847
* Extended Capabilities port speed entries.
849
if (port_speed == 0 || port_speed == -1)
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.
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 */
817
866
/* Setup an xHCI virtual device for a Set Address command */
818
867
int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev)
820
869
struct xhci_virt_device *dev;
821
870
struct xhci_ep_ctx *ep0_ctx;
822
struct usb_device *top_dev;
823
871
struct xhci_slot_ctx *slot_ctx;
824
872
struct xhci_input_control_ctx *ctrl_ctx;
874
struct usb_device *top_dev;
826
876
dev = xhci->devs[udev->slot_id];
827
877
/* Slot ID 0 is reserved */
865
915
/* Find the root hub port this device is under */
916
port_num = xhci_find_real_port_number(xhci, udev);
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
921
for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
867
922
top_dev = top_dev->parent)
868
923
/* Found device below root hub */;
869
slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(top_dev->portnum);
870
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);
873
/* Is this a LS/FS device under a HS hub? */
874
if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) &&
928
/* Is this a LS/FS device under an external HS hub? */
929
if (udev->tt && udev->tt->hub->parent) {
876
930
slot_ctx->tt_info = udev->tt->hub->slot_id;
877
931
slot_ctx->tt_info |= udev->ttport << 8;
878
932
if (udev->tt->multi)
1749
1804
xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n",
1750
1805
xhci->num_usb2_ports, xhci->num_usb3_ports);
1807
/* Place limits on the number of roothub ports so that the hub
1808
* descriptors aren't longer than the USB core will allocate.
1810
if (xhci->num_usb3_ports > 15) {
1811
xhci_dbg(xhci, "Limiting USB 3.0 roothub ports to 15.\n");
1812
xhci->num_usb3_ports = 15;
1814
if (xhci->num_usb2_ports > USB_MAXCHILDREN) {
1815
xhci_dbg(xhci, "Limiting USB 2.0 roothub ports to %u.\n",
1817
xhci->num_usb2_ports = USB_MAXCHILDREN;
1752
1821
* Note we could have all USB 3.0 ports, or all USB 2.0 ports.
1753
1822
* Not sure how the USB core will handle a hub with no ports...
1971
2044
init_completion(&xhci->addr_dev);
1972
2045
for (i = 0; i < MAX_HC_SLOTS; ++i)
1973
2046
xhci->devs[i] = NULL;
1974
for (i = 0; i < MAX_HC_PORTS; ++i)
1975
xhci->resume_done[i] = 0;
2047
for (i = 0; i < USB_MAXCHILDREN; ++i) {
2048
xhci->bus_state[0].resume_done[i] = 0;
2049
xhci->bus_state[1].resume_done[i] = 0;
1977
2052
if (scratchpad_alloc(xhci, flags))