Lines Matching full:xhci

3  * xHCI host controller driver
15 #include "xhci.h"
16 #include "xhci-trace.h"
55 static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf, in xhci_create_usb3_bos_desc() argument
67 /* does xhci support USB 3.1 Enhanced SuperSpeed */ in xhci_create_usb3_bos_desc()
68 for (i = 0; i < xhci->num_port_caps; i++) { in xhci_create_usb3_bos_desc()
69 if (xhci->port_caps[i].maj_rev == 0x03 && in xhci_create_usb3_bos_desc()
70 xhci->port_caps[i].min_rev >= 0x01) { in xhci_create_usb3_bos_desc()
72 port_cap = &xhci->port_caps[i]; in xhci_create_usb3_bos_desc()
78 /* does xhci provide a PSI table for SSA speed attributes? */ in xhci_create_usb3_bos_desc()
99 temp = readl(&xhci->cap_regs->hcc_params); in xhci_create_usb3_bos_desc()
104 if ((xhci->quirks & XHCI_LPM_SUPPORT)) { in xhci_create_usb3_bos_desc()
105 temp = readl(&xhci->cap_regs->hcs_params3); in xhci_create_usb3_bos_desc()
130 * The xhci PSI field and USB 3.1 SSA fields are very similar, in xhci_create_usb3_bos_desc()
132 * xhci has also only one PSI entry for a symmetric link when in xhci_create_usb3_bos_desc()
169 static void xhci_common_hub_descriptor(struct xhci_hcd *xhci, in xhci_common_hub_descriptor() argument
179 if (HCC_PPC(xhci->hcc_params)) in xhci_common_hub_descriptor()
192 static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, in xhci_usb2_hub_descriptor() argument
202 rhub = &xhci->usb2_rhub; in xhci_usb2_hub_descriptor()
204 xhci_common_hub_descriptor(xhci, desc, ports); in xhci_usb2_hub_descriptor()
208 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.8 says 20ms */ in xhci_usb2_hub_descriptor()
247 static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, in xhci_usb3_hub_descriptor() argument
256 rhub = &xhci->usb3_rhub; in xhci_usb3_hub_descriptor()
258 xhci_common_hub_descriptor(xhci, desc, ports); in xhci_usb3_hub_descriptor()
280 static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, in xhci_hub_descriptor() argument
285 xhci_usb3_hub_descriptor(hcd, xhci, desc); in xhci_hub_descriptor()
287 xhci_usb2_hub_descriptor(hcd, xhci, desc); in xhci_hub_descriptor()
361 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, in xhci_find_slot_id_by_port() argument
370 if (!xhci->devs[i] || !xhci->devs[i]->udev) in xhci_find_slot_id_by_port()
372 speed = xhci->devs[i]->udev->speed; in xhci_find_slot_id_by_port()
374 && xhci->devs[i]->fake_port == port) { in xhci_find_slot_id_by_port()
389 static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) in xhci_stop_device() argument
398 virt_dev = xhci->devs[slot_id]; in xhci_stop_device()
404 cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_stop_device()
408 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_device()
414 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, i); in xhci_stop_device()
420 command = xhci_alloc_command(xhci, false, GFP_NOWAIT); in xhci_stop_device()
422 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_device()
427 ret = xhci_queue_stop_endpoint(xhci, command, slot_id, in xhci_stop_device()
430 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_device()
431 xhci_free_command(xhci, command); in xhci_stop_device()
436 ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend); in xhci_stop_device()
438 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_device()
442 xhci_ring_cmd_db(xhci); in xhci_stop_device()
443 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_device()
450 xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); in xhci_stop_device()
455 ret = xhci_vendor_sync_dev_ctx(xhci, slot_id); in xhci_stop_device()
457 xhci_warn(xhci, "Sync device context failed, ret=%d\n", ret); in xhci_stop_device()
460 xhci_free_command(xhci, cmd); in xhci_stop_device()
467 void xhci_ring_device(struct xhci_hcd *xhci, int slot_id) in xhci_ring_device() argument
473 ep = &xhci->devs[slot_id]->eps[i]; in xhci_ring_device()
477 xhci_ring_ep_doorbell(xhci, slot_id, i, s); in xhci_ring_device()
479 xhci_ring_ep_doorbell(xhci, slot_id, i, 0); in xhci_ring_device()
486 static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, in xhci_disable_port() argument
491 xhci_dbg(xhci, "Ignoring request to disable " in xhci_disable_port()
496 if (xhci->quirks & XHCI_BROKEN_PORT_PED) { in xhci_disable_port()
497 xhci_dbg(xhci, in xhci_disable_port()
505 xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n", in xhci_disable_port()
509 static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, in xhci_clear_port_change_bit() argument
556 xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n", in xhci_clear_port_change_bit()
562 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_rhub() local
565 return &xhci->usb3_rhub; in xhci_get_rhub()
566 return &xhci->usb2_rhub; in xhci_get_rhub()
570 * xhci_set_port_power() must be called with xhci->lock held.
574 static void xhci_set_port_power(struct xhci_hcd *xhci, struct usb_hcd *hcd, in xhci_set_port_power() argument
576 __must_hold(&xhci->lock) in xhci_set_port_power()
586 xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n", in xhci_set_port_power()
600 spin_unlock_irqrestore(&xhci->lock, *flags); in xhci_set_port_power()
606 spin_lock_irqsave(&xhci->lock, *flags); in xhci_set_port_power()
609 static void xhci_port_set_test_mode(struct xhci_hcd *xhci, in xhci_port_set_test_mode() argument
615 /* xhci only supports test mode for usb2 ports */ in xhci_port_set_test_mode()
616 port = xhci->usb2_rhub.ports[wIndex]; in xhci_port_set_test_mode()
620 xhci->test_mode = test_mode; in xhci_port_set_test_mode()
622 xhci_start(xhci); in xhci_port_set_test_mode()
625 static int xhci_enter_test_mode(struct xhci_hcd *xhci, in xhci_enter_test_mode() argument
627 __must_hold(&xhci->lock) in xhci_enter_test_mode()
632 xhci_dbg(xhci, "Disable all slots\n"); in xhci_enter_test_mode()
633 spin_unlock_irqrestore(&xhci->lock, *flags); in xhci_enter_test_mode()
634 for (i = 1; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_enter_test_mode()
635 if (!xhci->devs[i]) in xhci_enter_test_mode()
638 retval = xhci_disable_slot(xhci, i); in xhci_enter_test_mode()
639 xhci_free_virt_device(xhci, i); in xhci_enter_test_mode()
641 xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n", in xhci_enter_test_mode()
644 spin_lock_irqsave(&xhci->lock, *flags); in xhci_enter_test_mode()
646 xhci_dbg(xhci, "Disable all port (PP = 0)\n"); in xhci_enter_test_mode()
648 for (i = 0; i < xhci->usb3_rhub.num_ports; i++) in xhci_enter_test_mode()
649 xhci_set_port_power(xhci, xhci->shared_hcd, i, false, flags); in xhci_enter_test_mode()
651 for (i = 0; i < xhci->usb2_rhub.num_ports; i++) in xhci_enter_test_mode()
652 xhci_set_port_power(xhci, xhci->main_hcd, i, false, flags); in xhci_enter_test_mode()
654 xhci_dbg(xhci, "Stop controller\n"); in xhci_enter_test_mode()
655 retval = xhci_halt(xhci); in xhci_enter_test_mode()
659 pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller); in xhci_enter_test_mode()
662 xhci_dbg(xhci, "Enter Test Mode: %d, Port_id=%d\n", in xhci_enter_test_mode()
664 xhci_port_set_test_mode(xhci, test_mode, wIndex); in xhci_enter_test_mode()
668 static int xhci_exit_test_mode(struct xhci_hcd *xhci) in xhci_exit_test_mode() argument
672 if (!xhci->test_mode) { in xhci_exit_test_mode()
673 xhci_err(xhci, "Not in test mode, do nothing.\n"); in xhci_exit_test_mode()
676 if (xhci->test_mode == USB_TEST_FORCE_ENABLE && in xhci_exit_test_mode()
677 !(xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_exit_test_mode()
678 retval = xhci_halt(xhci); in xhci_exit_test_mode()
682 pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); in xhci_exit_test_mode()
683 xhci->test_mode = 0; in xhci_exit_test_mode()
684 return xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_exit_test_mode()
687 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, in xhci_set_link_state() argument
699 xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x", in xhci_set_link_state()
704 static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, in xhci_set_remote_wake_mask() argument
731 void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port, in xhci_test_and_clear_bit() argument
745 static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, in xhci_hub_report_usb3_link_state() argument
772 * Resume state is an xHCI internal state. Do not report it to in xhci_hub_report_usb3_link_state()
789 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_hub_report_usb3_link_state()
805 static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, in xhci_del_comp_mod_timer() argument
808 u32 all_ports_seen_u0 = ((1 << xhci->usb3_rhub.num_ports) - 1); in xhci_del_comp_mod_timer()
811 if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK)) in xhci_del_comp_mod_timer()
814 if ((xhci->port_status_u0 != all_ports_seen_u0) && port_in_u0) { in xhci_del_comp_mod_timer()
815 xhci->port_status_u0 |= 1 << wIndex; in xhci_del_comp_mod_timer()
816 if (xhci->port_status_u0 == all_ports_seen_u0) { in xhci_del_comp_mod_timer()
817 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_del_comp_mod_timer()
818 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_del_comp_mod_timer()
820 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_del_comp_mod_timer()
831 struct xhci_hcd *xhci; in xhci_handle_usb2_port_link_resume() local
838 xhci = hcd_to_xhci(hcd); in xhci_handle_usb2_port_link_resume()
871 xhci_dbg(xhci, "resume USB2 port %d-%d\n", in xhci_handle_usb2_port_link_resume()
879 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in xhci_handle_usb2_port_link_resume()
880 xhci_set_link_state(xhci, port, XDEV_U0); in xhci_handle_usb2_port_link_resume()
882 spin_unlock_irqrestore(&xhci->lock, *flags); in xhci_handle_usb2_port_link_resume()
886 spin_lock_irqsave(&xhci->lock, *flags); in xhci_handle_usb2_port_link_resume()
889 slot_id = xhci_find_slot_id_by_port(hcd, xhci, in xhci_handle_usb2_port_link_resume()
892 xhci_dbg(xhci, "slot_id is zero\n"); in xhci_handle_usb2_port_link_resume()
896 xhci_ring_device(xhci, slot_id); in xhci_handle_usb2_port_link_resume()
900 xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n", in xhci_handle_usb2_port_link_resume()
941 struct xhci_hcd *xhci; in xhci_get_usb3_port_status() local
947 xhci = hcd_to_xhci(port->rhub->hcd); in xhci_get_usb3_port_status()
956 * handled by xhci driver. Reporting PLC to usbcore may in xhci_get_usb3_port_status()
984 xhci_hub_report_usb3_link_state(xhci, status, portsc); in xhci_get_usb3_port_status()
985 xhci_del_comp_mod_timer(xhci, portsc, portnum); in xhci_get_usb3_port_status()
1030 * Converts a raw xHCI port status into the format that external USB 2.0 or USB
1037 * - Drop and reacquire the xHCI lock, in order to wait for port resume.
1043 __releases(&xhci->lock) in xhci_get_port_status()
1044 __acquires(&xhci->lock) in xhci_get_port_status()
1103 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_hub_control() local
1122 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1136 xhci_dbg(xhci, "Wrong hub descriptor type for " in xhci_hub_control()
1140 xhci_hub_descriptor(hcd, xhci, in xhci_hub_control()
1150 retval = xhci_create_usb3_bos_desc(xhci, buf, wLength); in xhci_hub_control()
1151 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1159 xhci_hc_died(xhci); in xhci_hub_control()
1169 xhci_dbg(xhci, "Get port status %d-%d read: 0x%x, return 0x%x", in xhci_hub_control()
1178 xhci_err(xhci, "get ext port status invalid parameter\n"); in xhci_hub_control()
1202 xhci_hc_died(xhci); in xhci_hub_control()
1213 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1215 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1217 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1226 xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n", in xhci_hub_control()
1231 slot_id = xhci_find_slot_id_by_port(hcd, xhci, in xhci_hub_control()
1234 xhci_warn(xhci, "slot_id is zero\n"); in xhci_hub_control()
1238 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1239 xhci_stop_device(xhci, slot_id, 1); in xhci_hub_control()
1240 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1242 xhci_set_link_state(xhci, ports[wIndex], XDEV_U3); in xhci_hub_control()
1244 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1246 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1255 xhci_dbg(xhci, "Disable port %d-%d\n", in xhci_hub_control()
1272 xhci_dbg(xhci, "Enable port %d-%d\n", in xhci_hub_control()
1274 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1281 * For xHCI 1.1 according to section 4.19.1.2.4.1 a in xhci_hub_control()
1295 if (!HCC2_CTC(xhci->hcc_params2)) { in xhci_hub_control()
1296 xhci_dbg(xhci, "CTC flag is 0, port already supports entering compliance mode\n"); in xhci_hub_control()
1301 xhci_warn(xhci, "Can't set compliance mode when port is connected\n"); in xhci_hub_control()
1305 xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n", in xhci_hub_control()
1307 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1320 xhci_warn(xhci, "Cannot set port %d-%d link state %d\n", in xhci_hub_control()
1347 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1354 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1357 xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n", in xhci_hub_control()
1359 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1366 slot_id = xhci_find_slot_id_by_port(hcd, xhci, in xhci_hub_control()
1371 spin_unlock_irqrestore(&xhci->lock, in xhci_hub_control()
1373 xhci_stop_device(xhci, slot_id, 1); in xhci_hub_control()
1374 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1376 xhci_set_link_state(xhci, ports[wIndex], USB_SS_PORT_LS_U3); in xhci_hub_control()
1377 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1384 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1396 xhci_set_port_power(xhci, hcd, wIndex, true, &flags); in xhci_hub_control()
1403 xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n", in xhci_hub_control()
1407 xhci_set_remote_wake_mask(xhci, ports[wIndex], in xhci_hub_control()
1410 xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n", in xhci_hub_control()
1441 retval = xhci_enter_test_mode(xhci, test_mode, wIndex, in xhci_hub_control()
1456 xhci_hc_died(xhci); in xhci_hub_control()
1465 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); in xhci_hub_control()
1466 xhci_dbg(xhci, "PORTSC %04x\n", temp); in xhci_hub_control()
1475 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1477 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1479 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_control()
1480 xhci_set_link_state(xhci, ports[wIndex], in xhci_hub_control()
1487 slot_id = xhci_find_slot_id_by_port(hcd, xhci, in xhci_hub_control()
1490 xhci_dbg(xhci, "slot_id is zero\n"); in xhci_hub_control()
1493 xhci_ring_device(xhci, slot_id); in xhci_hub_control()
1505 xhci_clear_port_change_bit(xhci, wValue, wIndex, in xhci_hub_control()
1509 xhci_disable_port(hcd, xhci, wIndex, in xhci_hub_control()
1513 xhci_set_port_power(xhci, hcd, wIndex, false, &flags); in xhci_hub_control()
1516 retval = xhci_exit_test_mode(xhci); in xhci_hub_control()
1527 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_control()
1545 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_hub_status_data() local
1565 spin_lock_irqsave(&xhci->lock, flags); in xhci_hub_status_data()
1575 xhci_hc_died(xhci); in xhci_hub_status_data()
1594 xhci_dbg(xhci, "%s: stopping usb%d port polling\n", in xhci_hub_status_data()
1598 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_hub_status_data()
1606 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_bus_suspend() local
1621 spin_lock_irqsave(&xhci->lock, flags); in xhci_bus_suspend()
1626 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1627 xhci_dbg(xhci, "usb%d bus suspend to fail because a port is resuming\n", in xhci_bus_suspend()
1652 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1654 spin_lock_irqsave(&xhci->lock, flags); in xhci_bus_suspend()
1655 xhci_dbg(xhci, "port %d-%d polling in bus suspend, waiting\n", in xhci_bus_suspend()
1662 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1663 xhci_dbg(xhci, "Bus suspend bailout, port over-current detected\n"); in xhci_bus_suspend()
1670 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1671 xhci_dbg(xhci, "Bus suspend bailout, port connect change\n"); in xhci_bus_suspend()
1674 xhci_dbg(xhci, "port %d-%d not suspended\n", in xhci_bus_suspend()
1679 } else if ((xhci->quirks & XHCI_U2_BROKEN_SUSPEND) && in xhci_bus_suspend()
1707 if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) && in xhci_bus_suspend()
1729 slot_id = xhci_find_slot_id_by_port(hcd, xhci, in xhci_bus_suspend()
1732 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1733 xhci_stop_device(xhci, slot_id, 1); in xhci_bus_suspend()
1734 spin_lock_irqsave(&xhci->lock, flags); in xhci_bus_suspend()
1741 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_suspend()
1780 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_bus_resume() local
1799 spin_lock_irqsave(&xhci->lock, flags); in xhci_bus_resume()
1801 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_resume()
1806 temp = readl(&xhci->op_regs->command); in xhci_bus_resume()
1808 writel(temp, &xhci->op_regs->command); in xhci_bus_resume()
1821 if ((xhci->quirks & XHCI_MISSING_CAS) && in xhci_bus_resume()
1824 xhci_dbg(xhci, "reset stuck port %d-%d\n", in xhci_bus_resume()
1854 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_resume()
1856 spin_lock_irqsave(&xhci->lock, flags); in xhci_bus_resume()
1861 xhci_test_and_clear_bit(xhci, ports[port_index], in xhci_bus_resume()
1863 xhci_set_link_state(xhci, ports[port_index], XDEV_U0); in xhci_bus_resume()
1872 xhci_warn(xhci, "port %d-%d resume PLC timeout\n", in xhci_bus_resume()
1876 xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC); in xhci_bus_resume()
1877 slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1); in xhci_bus_resume()
1879 xhci_ring_device(xhci, slot_id); in xhci_bus_resume()
1881 (void) readl(&xhci->op_regs->command); in xhci_bus_resume()
1885 temp = readl(&xhci->op_regs->command); in xhci_bus_resume()
1887 writel(temp, &xhci->op_regs->command); in xhci_bus_resume()
1888 temp = readl(&xhci->op_regs->command); in xhci_bus_resume()
1890 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_bus_resume()