Lines Matching refs:xhci

16 #include "xhci.h"
17 #include "xhci-trace.h"
35 static int xhci_create_usb3x_bos_desc(struct xhci_hcd *xhci, char *buf,
60 for (i = 0; i < xhci->num_port_caps; i++) {
61 u8 major = xhci->port_caps[i].maj_rev;
62 u8 minor = xhci->port_caps[i].min_rev;
67 port_cap = &xhci->port_caps[i];
111 reg = readl(&xhci->cap_regs->hcc_params);
115 if ((xhci->quirks & XHCI_LPM_SUPPORT)) {
116 reg = readl(&xhci->cap_regs->hcs_params3);
255 static void xhci_common_hub_descriptor(struct xhci_hcd *xhci,
265 if (HCC_PPC(xhci->hcc_params))
278 static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
288 rhub = &xhci->usb2_rhub;
290 xhci_common_hub_descriptor(xhci, desc, ports);
294 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.8 says 20ms */
333 static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
342 rhub = &xhci->usb3_rhub;
344 xhci_common_hub_descriptor(xhci, desc, ports);
366 static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
371 xhci_usb3_hub_descriptor(hcd, xhci, desc);
373 xhci_usb2_hub_descriptor(hcd, xhci, desc);
454 * @xhci: pointer to xhci structure
460 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
469 if (!xhci->devs[i] || !xhci->devs[i]->udev)
471 speed = xhci->devs[i]->udev->speed;
473 && xhci->devs[i]->fake_port == port) {
489 static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
498 virt_dev = xhci->devs[slot_id];
504 cmd = xhci_alloc_command(xhci, true, GFP_NOIO);
508 spin_lock_irqsave(&xhci->lock, flags);
514 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, i);
520 command = xhci_alloc_command(xhci, false, GFP_NOWAIT);
522 spin_unlock_irqrestore(&xhci->lock, flags);
527 ret = xhci_queue_stop_endpoint(xhci, command, slot_id,
530 spin_unlock_irqrestore(&xhci->lock, flags);
531 xhci_free_command(xhci, command);
536 ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend);
538 spin_unlock_irqrestore(&xhci->lock, flags);
542 xhci_ring_cmd_db(xhci);
543 spin_unlock_irqrestore(&xhci->lock, flags);
550 xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n");
555 xhci_free_command(xhci, cmd);
562 void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
568 ep = &xhci->devs[slot_id]->eps[i];
572 xhci_ring_ep_doorbell(xhci, slot_id, i, s);
574 xhci_ring_ep_doorbell(xhci, slot_id, i, 0);
581 static void xhci_disable_port(struct xhci_hcd *xhci, struct xhci_port *port)
590 xhci_dbg(xhci, "Ignoring request to disable SuperSpeed port.\n");
594 if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
595 xhci_dbg(xhci,
607 xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n",
611 static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
658 xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n",
664 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
667 return &xhci->usb3_rhub;
668 return &xhci->usb2_rhub;
672 * xhci_set_port_power() must be called with xhci->lock held.
676 static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
678 __must_hold(&xhci->lock)
686 xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n",
700 spin_unlock_irqrestore(&xhci->lock, *flags);
706 spin_lock_irqsave(&xhci->lock, *flags);
709 static void xhci_port_set_test_mode(struct xhci_hcd *xhci,
715 /* xhci only supports test mode for usb2 ports */
716 port = xhci->usb2_rhub.ports[wIndex];
720 xhci->test_mode = test_mode;
722 xhci_start(xhci);
725 static int xhci_enter_test_mode(struct xhci_hcd *xhci,
727 __must_hold(&xhci->lock)
732 xhci_dbg(xhci, "Disable all slots\n");
733 spin_unlock_irqrestore(&xhci->lock, *flags);
734 for (i = 1; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
735 if (!xhci->devs[i])
738 retval = xhci_disable_slot(xhci, i);
739 xhci_free_virt_device(xhci, i);
741 xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n",
744 spin_lock_irqsave(&xhci->lock, *flags);
746 xhci_dbg(xhci, "Disable all port (PP = 0)\n");
748 for (i = 0; i < xhci->usb3_rhub.num_ports; i++)
749 xhci_set_port_power(xhci, xhci->usb3_rhub.ports[i], false, flags);
751 for (i = 0; i < xhci->usb2_rhub.num_ports; i++)
752 xhci_set_port_power(xhci, xhci->usb2_rhub.ports[i], false, flags);
754 xhci_dbg(xhci, "Stop controller\n");
755 retval = xhci_halt(xhci);
759 pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller);
762 xhci_dbg(xhci, "Enter Test Mode: %d, Port_id=%d\n",
764 xhci_port_set_test_mode(xhci, test_mode, wIndex);
768 static int xhci_exit_test_mode(struct xhci_hcd *xhci)
772 if (!xhci->test_mode) {
773 xhci_err(xhci, "Not in test mode, do nothing.\n");
776 if (xhci->test_mode == USB_TEST_FORCE_ENABLE &&
777 !(xhci->xhc_state & XHCI_STATE_HALTED)) {
778 retval = xhci_halt(xhci);
782 pm_runtime_allow(xhci_to_hcd(xhci)->self.controller);
783 xhci->test_mode = 0;
784 return xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
787 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
799 xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x",
804 static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
831 void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
845 static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci,
889 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
905 static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status,
908 u32 all_ports_seen_u0 = ((1 << xhci->usb3_rhub.num_ports) - 1);
911 if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK))
914 if ((xhci->port_status_u0 != all_ports_seen_u0) && port_in_u0) {
915 xhci->port_status_u0 |= 1 << wIndex;
916 if (xhci->port_status_u0 == all_ports_seen_u0) {
917 del_timer_sync(&xhci->comp_mode_recovery_timer);
918 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
920 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
931 struct xhci_hcd *xhci;
938 xhci = hcd_to_xhci(hcd);
970 xhci_dbg(xhci, "resume USB2 port %d-%d\n",
979 xhci_test_and_clear_bit(xhci, port, PORT_PLC);
980 xhci_set_link_state(xhci, port, XDEV_U0);
982 spin_unlock_irqrestore(&xhci->lock, *flags);
986 spin_lock_irqsave(&xhci->lock, *flags);
989 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
992 xhci_dbg(xhci, "slot_id is zero\n");
995 xhci_ring_device(xhci, slot_id);
999 xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n",
1037 struct xhci_hcd *xhci;
1043 xhci = hcd_to_xhci(port->rhub->hcd);
1052 * handled by xhci driver. Reporting PLC to usbcore may
1080 xhci_hub_report_usb3_link_state(xhci, status, portsc);
1081 xhci_del_comp_mod_timer(xhci, portsc, portnum);
1152 __releases(&xhci->lock)
1153 __acquires(&xhci->lock)
1200 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1222 spin_lock_irqsave(&xhci->lock, flags);
1236 xhci_dbg(xhci, "Wrong hub descriptor type for "
1240 xhci_hub_descriptor(hcd, xhci,
1250 retval = xhci_create_usb3x_bos_desc(xhci, buf, wLength);
1251 spin_unlock_irqrestore(&xhci->lock, flags);
1261 xhci_hc_died(xhci);
1271 xhci_dbg(xhci, "Get port status %d-%d read: 0x%x, return 0x%x",
1280 xhci_err(xhci, "get ext port status invalid parameter\n");
1307 xhci_hc_died(xhci);
1318 xhci_set_link_state(xhci, port, XDEV_U0);
1319 spin_unlock_irqrestore(&xhci->lock, flags);
1321 spin_lock_irqsave(&xhci->lock, flags);
1330 xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
1335 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1338 xhci_warn(xhci, "slot_id is zero\n");
1342 spin_unlock_irqrestore(&xhci->lock, flags);
1343 xhci_stop_device(xhci, slot_id, 1);
1344 spin_lock_irqsave(&xhci->lock, flags);
1346 xhci_set_link_state(xhci, port, XDEV_U3);
1348 spin_unlock_irqrestore(&xhci->lock, flags);
1350 spin_lock_irqsave(&xhci->lock, flags);
1359 xhci_dbg(xhci, "Disable port %d-%d\n",
1376 xhci_dbg(xhci, "Enable port %d-%d\n",
1378 xhci_set_link_state(xhci, port, link_state);
1398 if (!HCC2_CTC(xhci->hcc_params2)) {
1399 xhci_dbg(xhci, "CTC flag is 0, port already supports entering compliance mode\n");
1404 xhci_warn(xhci, "Can't set compliance mode when port is connected\n");
1408 xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n",
1410 xhci_set_link_state(xhci, port, link_state);
1422 xhci_warn(xhci, "Cannot set port %d-%d link state %d\n",
1448 xhci_set_link_state(xhci, port, USB_SS_PORT_LS_U0);
1454 spin_unlock_irqrestore(&xhci->lock, flags);
1457 xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n",
1459 spin_lock_irqsave(&xhci->lock, flags);
1466 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1471 spin_unlock_irqrestore(&xhci->lock,
1473 xhci_stop_device(xhci, slot_id, 1);
1474 spin_lock_irqsave(&xhci->lock, flags);
1476 xhci_set_link_state(xhci, port, USB_SS_PORT_LS_U3);
1477 spin_unlock_irqrestore(&xhci->lock, flags);
1484 spin_lock_irqsave(&xhci->lock, flags);
1496 xhci_set_port_power(xhci, port, true, &flags);
1503 xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n",
1507 xhci_set_remote_wake_mask(xhci, port, wake_mask);
1509 xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n",
1540 retval = xhci_enter_test_mode(xhci, test_mode, wIndex,
1558 xhci_hc_died(xhci);
1567 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
1568 xhci_dbg(xhci, "PORTSC %04x\n", temp);
1577 xhci_set_link_state(xhci, port, XDEV_RESUME);
1578 spin_unlock_irqrestore(&xhci->lock, flags);
1580 spin_lock_irqsave(&xhci->lock, flags);
1581 xhci_set_link_state(xhci, port, XDEV_U0);
1587 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1590 xhci_dbg(xhci, "slot_id is zero\n");
1593 xhci_ring_device(xhci, slot_id);
1605 xhci_clear_port_change_bit(xhci, wValue, wIndex,
1609 xhci_disable_port(xhci, port);
1612 xhci_set_port_power(xhci, port, false, &flags);
1615 retval = xhci_exit_test_mode(xhci);
1626 spin_unlock_irqrestore(&xhci->lock, flags);
1645 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1665 spin_lock_irqsave(&xhci->lock, flags);
1673 if (xhci->run_graceperiod) {
1674 if (time_before(jiffies, xhci->run_graceperiod))
1677 xhci->run_graceperiod = 0;
1686 xhci_hc_died(xhci);
1705 xhci_dbg(xhci, "%s: stopping usb%d port polling\n",
1709 spin_unlock_irqrestore(&xhci->lock, flags);
1717 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1732 spin_lock_irqsave(&xhci->lock, flags);
1737 spin_unlock_irqrestore(&xhci->lock, flags);
1738 xhci_dbg(xhci, "usb%d bus suspend to fail because a port is resuming\n",
1763 spin_unlock_irqrestore(&xhci->lock, flags);
1765 spin_lock_irqsave(&xhci->lock, flags);
1766 xhci_dbg(xhci, "port %d-%d polling in bus suspend, waiting\n",
1773 spin_unlock_irqrestore(&xhci->lock, flags);
1774 xhci_dbg(xhci, "Bus suspend bailout, port over-current detected\n");
1781 spin_unlock_irqrestore(&xhci->lock, flags);
1782 xhci_dbg(xhci, "Bus suspend bailout, port connect change\n");
1785 xhci_dbg(xhci, "port %d-%d not suspended\n",
1804 if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) &&
1826 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1829 spin_unlock_irqrestore(&xhci->lock, flags);
1830 xhci_stop_device(xhci, slot_id, 1);
1831 spin_lock_irqsave(&xhci->lock, flags);
1838 spin_unlock_irqrestore(&xhci->lock, flags);
1876 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1895 spin_lock_irqsave(&xhci->lock, flags);
1897 spin_unlock_irqrestore(&xhci->lock, flags);
1902 temp = readl(&xhci->op_regs->command);
1904 writel(temp, &xhci->op_regs->command);
1917 if ((xhci->quirks & XHCI_MISSING_CAS) &&
1920 xhci_dbg(xhci, "reset stuck port %d-%d\n",
1950 spin_unlock_irqrestore(&xhci->lock, flags);
1952 spin_lock_irqsave(&xhci->lock, flags);
1957 xhci_test_and_clear_bit(xhci, ports[port_index],
1959 xhci_set_link_state(xhci, ports[port_index], XDEV_U0);
1968 xhci_warn(xhci, "port %d-%d resume PLC timeout\n",
1972 xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC);
1973 slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1);
1975 xhci_ring_device(xhci, slot_id);
1977 (void) readl(&xhci->op_regs->command);
1981 temp = readl(&xhci->op_regs->command);
1983 writel(temp, &xhci->op_regs->command);
1984 temp = readl(&xhci->op_regs->command);
1986 spin_unlock_irqrestore(&xhci->lock, flags);