Lines Matching defs:xhci

15 #include "xhci.h"
16 #include "xhci-trace.h"
55 static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf,
67 /* does xhci support USB 3.1 Enhanced SuperSpeed */
68 for (i = 0; i < xhci->num_port_caps; i++) {
69 if (xhci->port_caps[i].maj_rev == 0x03 &&
70 xhci->port_caps[i].min_rev >= 0x01) {
72 port_cap = &xhci->port_caps[i];
78 /* does xhci provide a PSI table for SSA speed attributes? */
99 temp = readl(&xhci->cap_regs->hcc_params);
104 if ((xhci->quirks & XHCI_LPM_SUPPORT)) {
105 temp = readl(&xhci->cap_regs->hcs_params3);
130 * The xhci PSI field and USB 3.1 SSA fields are very similar,
132 * xhci has also only one PSI entry for a symmetric link when
169 static void xhci_common_hub_descriptor(struct xhci_hcd *xhci,
179 if (HCC_PPC(xhci->hcc_params))
192 static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
202 rhub = &xhci->usb2_rhub;
204 xhci_common_hub_descriptor(xhci, desc, ports);
208 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.8 says 20ms */
247 static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
256 rhub = &xhci->usb3_rhub;
258 xhci_common_hub_descriptor(xhci, desc, ports);
280 static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
285 xhci_usb3_hub_descriptor(hcd, xhci, desc);
287 xhci_usb2_hub_descriptor(hcd, xhci, desc);
361 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
370 if (!xhci->devs[i] || !xhci->devs[i]->udev)
372 speed = xhci->devs[i]->udev->speed;
374 && xhci->devs[i]->fake_port == port) {
389 static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
398 virt_dev = xhci->devs[slot_id];
404 cmd = xhci_alloc_command(xhci, true, GFP_NOIO);
408 spin_lock_irqsave(&xhci->lock, flags);
414 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, i);
420 command = xhci_alloc_command(xhci, false, GFP_NOWAIT);
422 spin_unlock_irqrestore(&xhci->lock, flags);
427 ret = xhci_queue_stop_endpoint(xhci, command, slot_id,
430 spin_unlock_irqrestore(&xhci->lock, flags);
431 xhci_free_command(xhci, command);
436 ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend);
438 spin_unlock_irqrestore(&xhci->lock, flags);
442 xhci_ring_cmd_db(xhci);
443 spin_unlock_irqrestore(&xhci->lock, flags);
450 xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n");
455 xhci_free_command(xhci, cmd);
462 void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
468 ep = &xhci->devs[slot_id]->eps[i];
472 xhci_ring_ep_doorbell(xhci, slot_id, i, s);
474 xhci_ring_ep_doorbell(xhci, slot_id, i, 0);
481 static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
486 xhci_dbg(xhci, "Ignoring request to disable "
491 if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
492 xhci_dbg(xhci,
500 xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n",
504 static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
551 xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n",
557 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
560 return &xhci->usb3_rhub;
561 return &xhci->usb2_rhub;
565 * xhci_set_port_power() must be called with xhci->lock held.
569 static void xhci_set_port_power(struct xhci_hcd *xhci, struct usb_hcd *hcd,
571 __must_hold(&xhci->lock)
581 xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n",
595 spin_unlock_irqrestore(&xhci->lock, *flags);
601 spin_lock_irqsave(&xhci->lock, *flags);
604 static void xhci_port_set_test_mode(struct xhci_hcd *xhci,
610 /* xhci only supports test mode for usb2 ports */
611 port = xhci->usb2_rhub.ports[wIndex];
615 xhci->test_mode = test_mode;
617 xhci_start(xhci);
620 static int xhci_enter_test_mode(struct xhci_hcd *xhci,
622 __must_hold(&xhci->lock)
627 xhci_dbg(xhci, "Disable all slots\n");
628 spin_unlock_irqrestore(&xhci->lock, *flags);
629 for (i = 1; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
630 if (!xhci->devs[i])
633 retval = xhci_disable_slot(xhci, i);
634 xhci_free_virt_device(xhci, i);
636 xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n",
639 spin_lock_irqsave(&xhci->lock, *flags);
641 xhci_dbg(xhci, "Disable all port (PP = 0)\n");
643 for (i = 0; i < xhci->usb3_rhub.num_ports; i++)
644 xhci_set_port_power(xhci, xhci->shared_hcd, i, false, flags);
646 for (i = 0; i < xhci->usb2_rhub.num_ports; i++)
647 xhci_set_port_power(xhci, xhci->main_hcd, i, false, flags);
649 xhci_dbg(xhci, "Stop controller\n");
650 retval = xhci_halt(xhci);
654 pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller);
657 xhci_dbg(xhci, "Enter Test Mode: %d, Port_id=%d\n",
659 xhci_port_set_test_mode(xhci, test_mode, wIndex);
663 static int xhci_exit_test_mode(struct xhci_hcd *xhci)
667 if (!xhci->test_mode) {
668 xhci_err(xhci, "Not in test mode, do nothing.\n");
671 if (xhci->test_mode == USB_TEST_FORCE_ENABLE &&
672 !(xhci->xhc_state & XHCI_STATE_HALTED)) {
673 retval = xhci_halt(xhci);
677 pm_runtime_allow(xhci_to_hcd(xhci)->self.controller);
678 xhci->test_mode = 0;
679 return xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
682 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
694 xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x",
699 static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
726 void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
740 static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci,
784 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
800 static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status,
803 u32 all_ports_seen_u0 = ((1 << xhci->usb3_rhub.num_ports) - 1);
806 if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK))
809 if ((xhci->port_status_u0 != all_ports_seen_u0) && port_in_u0) {
810 xhci->port_status_u0 |= 1 << wIndex;
811 if (xhci->port_status_u0 == all_ports_seen_u0) {
812 del_timer_sync(&xhci->comp_mode_recovery_timer);
813 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
815 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
826 struct xhci_hcd *xhci;
833 xhci = hcd_to_xhci(hcd);
865 xhci_dbg(xhci, "resume USB2 port %d-%d\n",
874 xhci_test_and_clear_bit(xhci, port, PORT_PLC);
875 xhci_set_link_state(xhci, port, XDEV_U0);
877 spin_unlock_irqrestore(&xhci->lock, *flags);
881 spin_lock_irqsave(&xhci->lock, *flags);
884 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
887 xhci_dbg(xhci, "slot_id is zero\n");
890 xhci_ring_device(xhci, slot_id);
894 xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n",
932 struct xhci_hcd *xhci;
938 xhci = hcd_to_xhci(port->rhub->hcd);
947 * handled by xhci driver. Reporting PLC to usbcore may
975 xhci_hub_report_usb3_link_state(xhci, status, portsc);
976 xhci_del_comp_mod_timer(xhci, portsc, portnum);
1047 __releases(&xhci->lock)
1048 __acquires(&xhci->lock)
1095 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1117 spin_lock_irqsave(&xhci->lock, flags);
1131 xhci_dbg(xhci, "Wrong hub descriptor type for "
1135 xhci_hub_descriptor(hcd, xhci,
1145 retval = xhci_create_usb3_bos_desc(xhci, buf, wLength);
1146 spin_unlock_irqrestore(&xhci->lock, flags);
1156 xhci_hc_died(xhci);
1166 xhci_dbg(xhci, "Get port status %d-%d read: 0x%x, return 0x%x",
1175 xhci_err(xhci, "get ext port status invalid parameter\n");
1202 xhci_hc_died(xhci);
1213 xhci_set_link_state(xhci, port, XDEV_U0);
1214 spin_unlock_irqrestore(&xhci->lock, flags);
1216 spin_lock_irqsave(&xhci->lock, flags);
1225 xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
1230 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1233 xhci_warn(xhci, "slot_id is zero\n");
1237 spin_unlock_irqrestore(&xhci->lock, flags);
1238 xhci_stop_device(xhci, slot_id, 1);
1239 spin_lock_irqsave(&xhci->lock, flags);
1241 xhci_set_link_state(xhci, port, XDEV_U3);
1243 spin_unlock_irqrestore(&xhci->lock, flags);
1245 spin_lock_irqsave(&xhci->lock, flags);
1254 xhci_dbg(xhci, "Disable port %d-%d\n",
1271 xhci_dbg(xhci, "Enable port %d-%d\n",
1273 xhci_set_link_state(xhci, port, link_state);
1293 if (!HCC2_CTC(xhci->hcc_params2)) {
1294 xhci_dbg(xhci, "CTC flag is 0, port already supports entering compliance mode\n");
1299 xhci_warn(xhci, "Can't set compliance mode when port is connected\n");
1303 xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n",
1305 xhci_set_link_state(xhci, port, link_state);
1317 xhci_warn(xhci, "Cannot set port %d-%d link state %d\n",
1343 xhci_set_link_state(xhci, port, USB_SS_PORT_LS_U0);
1349 spin_unlock_irqrestore(&xhci->lock, flags);
1352 xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n",
1354 spin_lock_irqsave(&xhci->lock, flags);
1361 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1366 spin_unlock_irqrestore(&xhci->lock,
1368 xhci_stop_device(xhci, slot_id, 1);
1369 spin_lock_irqsave(&xhci->lock, flags);
1371 xhci_set_link_state(xhci, port, USB_SS_PORT_LS_U3);
1372 spin_unlock_irqrestore(&xhci->lock, flags);
1379 spin_lock_irqsave(&xhci->lock, flags);
1391 xhci_set_port_power(xhci, hcd, wIndex, true, &flags);
1398 xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n",
1402 xhci_set_remote_wake_mask(xhci, port, wake_mask);
1404 xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n",
1435 retval = xhci_enter_test_mode(xhci, test_mode, wIndex,
1453 xhci_hc_died(xhci);
1462 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
1463 xhci_dbg(xhci, "PORTSC %04x\n", temp);
1472 xhci_set_link_state(xhci, port, XDEV_RESUME);
1473 spin_unlock_irqrestore(&xhci->lock, flags);
1475 spin_lock_irqsave(&xhci->lock, flags);
1476 xhci_set_link_state(xhci, port, XDEV_U0);
1482 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1485 xhci_dbg(xhci, "slot_id is zero\n");
1488 xhci_ring_device(xhci, slot_id);
1500 xhci_clear_port_change_bit(xhci, wValue, wIndex,
1504 xhci_disable_port(hcd, xhci, wIndex,
1508 xhci_set_port_power(xhci, hcd, wIndex, false, &flags);
1511 retval = xhci_exit_test_mode(xhci);
1522 spin_unlock_irqrestore(&xhci->lock, flags);
1540 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1560 spin_lock_irqsave(&xhci->lock, flags);
1568 if (xhci->run_graceperiod) {
1569 if (time_before(jiffies, xhci->run_graceperiod))
1572 xhci->run_graceperiod = 0;
1581 xhci_hc_died(xhci);
1600 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
1603 spin_unlock_irqrestore(&xhci->lock, flags);
1611 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1626 spin_lock_irqsave(&xhci->lock, flags);
1631 spin_unlock_irqrestore(&xhci->lock, flags);
1632 xhci_dbg(xhci, "suspend failed because a port is resuming\n");
1656 spin_unlock_irqrestore(&xhci->lock, flags);
1658 spin_lock_irqsave(&xhci->lock, flags);
1659 xhci_dbg(xhci, "port %d-%d polling in bus suspend, waiting\n",
1666 spin_unlock_irqrestore(&xhci->lock, flags);
1667 xhci_dbg(xhci, "Bus suspend bailout, port over-current detected\n");
1674 spin_unlock_irqrestore(&xhci->lock, flags);
1675 xhci_dbg(xhci, "Bus suspend bailout, port connect change\n");
1678 xhci_dbg(xhci, "port %d-%d not suspended\n",
1697 if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) &&
1719 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1722 spin_unlock_irqrestore(&xhci->lock, flags);
1723 xhci_stop_device(xhci, slot_id, 1);
1724 spin_lock_irqsave(&xhci->lock, flags);
1731 spin_unlock_irqrestore(&xhci->lock, flags);
1769 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1788 spin_lock_irqsave(&xhci->lock, flags);
1790 spin_unlock_irqrestore(&xhci->lock, flags);
1795 temp = readl(&xhci->op_regs->command);
1797 writel(temp, &xhci->op_regs->command);
1810 if ((xhci->quirks & XHCI_MISSING_CAS) &&
1813 xhci_dbg(xhci, "reset stuck port %d-%d\n",
1843 spin_unlock_irqrestore(&xhci->lock, flags);
1845 spin_lock_irqsave(&xhci->lock, flags);
1850 xhci_test_and_clear_bit(xhci, ports[port_index],
1852 xhci_set_link_state(xhci, ports[port_index], XDEV_U0);
1861 xhci_warn(xhci, "port %d-%d resume PLC timeout\n",
1865 xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC);
1866 slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1);
1868 xhci_ring_device(xhci, slot_id);
1870 (void) readl(&xhci->op_regs->command);
1874 temp = readl(&xhci->op_regs->command);
1876 writel(temp, &xhci->op_regs->command);
1877 temp = readl(&xhci->op_regs->command);
1879 spin_unlock_irqrestore(&xhci->lock, flags);