| .. | .. |
|---|
| 449 | 449 | cmd->status == COMP_COMMAND_RING_STOPPED) { |
|---|
| 450 | 450 | xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); |
|---|
| 451 | 451 | ret = -ETIME; |
|---|
| 452 | + goto cmd_cleanup; |
|---|
| 452 | 453 | } |
|---|
| 454 | + |
|---|
| 455 | + ret = xhci_vendor_sync_dev_ctx(xhci, slot_id); |
|---|
| 456 | + if (ret) |
|---|
| 457 | + xhci_warn(xhci, "Sync device context failed, ret=%d\n", ret); |
|---|
| 453 | 458 | |
|---|
| 454 | 459 | cmd_cleanup: |
|---|
| 455 | 460 | xhci_free_command(xhci, cmd); |
|---|
| .. | .. |
|---|
| 497 | 502 | /* Write 1 to disable the port */ |
|---|
| 498 | 503 | writel(port_status | PORT_PE, addr); |
|---|
| 499 | 504 | port_status = readl(addr); |
|---|
| 500 | | - xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n", |
|---|
| 501 | | - wIndex, port_status); |
|---|
| 505 | + xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n", |
|---|
| 506 | + hcd->self.busnum, wIndex + 1, port_status); |
|---|
| 502 | 507 | } |
|---|
| 503 | 508 | |
|---|
| 504 | 509 | static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, |
|---|
| .. | .. |
|---|
| 547 | 552 | /* Change bits are all write 1 to clear */ |
|---|
| 548 | 553 | writel(port_status | status, addr); |
|---|
| 549 | 554 | port_status = readl(addr); |
|---|
| 550 | | - xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n", |
|---|
| 551 | | - port_change_bit, wIndex, port_status); |
|---|
| 555 | + |
|---|
| 556 | + xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n", |
|---|
| 557 | + wIndex + 1, port_change_bit, port_status); |
|---|
| 552 | 558 | } |
|---|
| 553 | 559 | |
|---|
| 554 | 560 | struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd) |
|---|
| .. | .. |
|---|
| 567 | 573 | */ |
|---|
| 568 | 574 | static void xhci_set_port_power(struct xhci_hcd *xhci, struct usb_hcd *hcd, |
|---|
| 569 | 575 | u16 index, bool on, unsigned long *flags) |
|---|
| 576 | + __must_hold(&xhci->lock) |
|---|
| 570 | 577 | { |
|---|
| 571 | 578 | struct xhci_hub *rhub; |
|---|
| 572 | 579 | struct xhci_port *port; |
|---|
| .. | .. |
|---|
| 575 | 582 | rhub = xhci_get_rhub(hcd); |
|---|
| 576 | 583 | port = rhub->ports[index]; |
|---|
| 577 | 584 | temp = readl(port->addr); |
|---|
| 585 | + |
|---|
| 586 | + xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n", |
|---|
| 587 | + hcd->self.busnum, index + 1, on ? "ON" : "OFF", temp); |
|---|
| 588 | + |
|---|
| 578 | 589 | temp = xhci_port_state_to_neutral(temp); |
|---|
| 590 | + |
|---|
| 579 | 591 | if (on) { |
|---|
| 580 | 592 | /* Power on */ |
|---|
| 581 | 593 | writel(temp | PORT_POWER, port->addr); |
|---|
| 582 | | - temp = readl(port->addr); |
|---|
| 583 | | - xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", |
|---|
| 584 | | - index, temp); |
|---|
| 594 | + readl(port->addr); |
|---|
| 585 | 595 | } else { |
|---|
| 586 | 596 | /* Power off */ |
|---|
| 587 | 597 | writel(temp & ~PORT_POWER, port->addr); |
|---|
| .. | .. |
|---|
| 608 | 618 | temp |= test_mode << PORT_TEST_MODE_SHIFT; |
|---|
| 609 | 619 | writel(temp, port->addr + PORTPMSC); |
|---|
| 610 | 620 | xhci->test_mode = test_mode; |
|---|
| 611 | | - if (test_mode == TEST_FORCE_EN) |
|---|
| 621 | + if (test_mode == USB_TEST_FORCE_ENABLE) |
|---|
| 612 | 622 | xhci_start(xhci); |
|---|
| 613 | 623 | } |
|---|
| 614 | 624 | |
|---|
| 615 | 625 | static int xhci_enter_test_mode(struct xhci_hcd *xhci, |
|---|
| 616 | 626 | u16 test_mode, u16 wIndex, unsigned long *flags) |
|---|
| 627 | + __must_hold(&xhci->lock) |
|---|
| 617 | 628 | { |
|---|
| 618 | 629 | int i, retval; |
|---|
| 619 | 630 | |
|---|
| .. | .. |
|---|
| 662 | 673 | xhci_err(xhci, "Not in test mode, do nothing.\n"); |
|---|
| 663 | 674 | return 0; |
|---|
| 664 | 675 | } |
|---|
| 665 | | - if (xhci->test_mode == TEST_FORCE_EN && |
|---|
| 676 | + if (xhci->test_mode == USB_TEST_FORCE_ENABLE && |
|---|
| 666 | 677 | !(xhci->xhc_state & XHCI_STATE_HALTED)) { |
|---|
| 667 | 678 | retval = xhci_halt(xhci); |
|---|
| 668 | 679 | if (retval) |
|---|
| .. | .. |
|---|
| 670 | 681 | } |
|---|
| 671 | 682 | pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); |
|---|
| 672 | 683 | xhci->test_mode = 0; |
|---|
| 673 | | - return xhci_reset(xhci); |
|---|
| 684 | + return xhci_reset(xhci, XHCI_RESET_SHORT_USEC); |
|---|
| 674 | 685 | } |
|---|
| 675 | 686 | |
|---|
| 676 | 687 | void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, |
|---|
| 677 | 688 | u32 link_state) |
|---|
| 678 | 689 | { |
|---|
| 679 | 690 | u32 temp; |
|---|
| 691 | + u32 portsc; |
|---|
| 680 | 692 | |
|---|
| 681 | | - temp = readl(port->addr); |
|---|
| 682 | | - temp = xhci_port_state_to_neutral(temp); |
|---|
| 693 | + portsc = readl(port->addr); |
|---|
| 694 | + temp = xhci_port_state_to_neutral(portsc); |
|---|
| 683 | 695 | temp &= ~PORT_PLS_MASK; |
|---|
| 684 | 696 | temp |= PORT_LINK_STROBE | link_state; |
|---|
| 685 | 697 | writel(temp, port->addr); |
|---|
| 698 | + |
|---|
| 699 | + xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x", |
|---|
| 700 | + port->rhub->hcd->self.busnum, port->hcd_portnum + 1, |
|---|
| 701 | + portsc, temp); |
|---|
| 686 | 702 | } |
|---|
| 687 | 703 | |
|---|
| 688 | 704 | static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, |
|---|
| .. | .. |
|---|
| 723 | 739 | temp |= port_bit; |
|---|
| 724 | 740 | writel(temp, port->addr); |
|---|
| 725 | 741 | } |
|---|
| 726 | | -} |
|---|
| 727 | | - |
|---|
| 728 | | -/* Updates Link Status for USB 2.1 port */ |
|---|
| 729 | | -static void xhci_hub_report_usb2_link_state(u32 *status, u32 status_reg) |
|---|
| 730 | | -{ |
|---|
| 731 | | - if ((status_reg & PORT_PLS_MASK) == XDEV_U2) |
|---|
| 732 | | - *status |= USB_PORT_STAT_L1; |
|---|
| 733 | 742 | } |
|---|
| 734 | 743 | |
|---|
| 735 | 744 | /* Updates Link Status for super Speed port */ |
|---|
| .. | .. |
|---|
| 814 | 823 | } |
|---|
| 815 | 824 | } |
|---|
| 816 | 825 | |
|---|
| 826 | +static int xhci_handle_usb2_port_link_resume(struct xhci_port *port, |
|---|
| 827 | + u32 *status, u32 portsc, |
|---|
| 828 | + unsigned long *flags) |
|---|
| 829 | +{ |
|---|
| 830 | + struct xhci_bus_state *bus_state; |
|---|
| 831 | + struct xhci_hcd *xhci; |
|---|
| 832 | + struct usb_hcd *hcd; |
|---|
| 833 | + int slot_id; |
|---|
| 834 | + u32 wIndex; |
|---|
| 835 | + |
|---|
| 836 | + hcd = port->rhub->hcd; |
|---|
| 837 | + bus_state = &port->rhub->bus_state; |
|---|
| 838 | + xhci = hcd_to_xhci(hcd); |
|---|
| 839 | + wIndex = port->hcd_portnum; |
|---|
| 840 | + |
|---|
| 841 | + if ((portsc & PORT_RESET) || !(portsc & PORT_PE)) { |
|---|
| 842 | + *status = 0xffffffff; |
|---|
| 843 | + return -EINVAL; |
|---|
| 844 | + } |
|---|
| 845 | + /* did port event handler already start resume timing? */ |
|---|
| 846 | + if (!bus_state->resume_done[wIndex]) { |
|---|
| 847 | + /* If not, maybe we are in a host initated resume? */ |
|---|
| 848 | + if (test_bit(wIndex, &bus_state->resuming_ports)) { |
|---|
| 849 | + /* Host initated resume doesn't time the resume |
|---|
| 850 | + * signalling using resume_done[]. |
|---|
| 851 | + * It manually sets RESUME state, sleeps 20ms |
|---|
| 852 | + * and sets U0 state. This should probably be |
|---|
| 853 | + * changed, but not right now. |
|---|
| 854 | + */ |
|---|
| 855 | + } else { |
|---|
| 856 | + /* port resume was discovered now and here, |
|---|
| 857 | + * start resume timing |
|---|
| 858 | + */ |
|---|
| 859 | + unsigned long timeout = jiffies + |
|---|
| 860 | + msecs_to_jiffies(USB_RESUME_TIMEOUT); |
|---|
| 861 | + |
|---|
| 862 | + set_bit(wIndex, &bus_state->resuming_ports); |
|---|
| 863 | + bus_state->resume_done[wIndex] = timeout; |
|---|
| 864 | + mod_timer(&hcd->rh_timer, timeout); |
|---|
| 865 | + usb_hcd_start_port_resume(&hcd->self, wIndex); |
|---|
| 866 | + } |
|---|
| 867 | + /* Has resume been signalled for USB_RESUME_TIME yet? */ |
|---|
| 868 | + } else if (time_after_eq(jiffies, bus_state->resume_done[wIndex])) { |
|---|
| 869 | + int time_left; |
|---|
| 870 | + |
|---|
| 871 | + xhci_dbg(xhci, "resume USB2 port %d-%d\n", |
|---|
| 872 | + hcd->self.busnum, wIndex + 1); |
|---|
| 873 | + |
|---|
| 874 | + bus_state->resume_done[wIndex] = 0; |
|---|
| 875 | + clear_bit(wIndex, &bus_state->resuming_ports); |
|---|
| 876 | + |
|---|
| 877 | + set_bit(wIndex, &bus_state->rexit_ports); |
|---|
| 878 | + |
|---|
| 879 | + xhci_test_and_clear_bit(xhci, port, PORT_PLC); |
|---|
| 880 | + xhci_set_link_state(xhci, port, XDEV_U0); |
|---|
| 881 | + |
|---|
| 882 | + spin_unlock_irqrestore(&xhci->lock, *flags); |
|---|
| 883 | + time_left = wait_for_completion_timeout( |
|---|
| 884 | + &bus_state->rexit_done[wIndex], |
|---|
| 885 | + msecs_to_jiffies(XHCI_MAX_REXIT_TIMEOUT_MS)); |
|---|
| 886 | + spin_lock_irqsave(&xhci->lock, *flags); |
|---|
| 887 | + |
|---|
| 888 | + if (time_left) { |
|---|
| 889 | + slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
|---|
| 890 | + wIndex + 1); |
|---|
| 891 | + if (!slot_id) { |
|---|
| 892 | + xhci_dbg(xhci, "slot_id is zero\n"); |
|---|
| 893 | + *status = 0xffffffff; |
|---|
| 894 | + return -ENODEV; |
|---|
| 895 | + } |
|---|
| 896 | + xhci_ring_device(xhci, slot_id); |
|---|
| 897 | + } else { |
|---|
| 898 | + int port_status = readl(port->addr); |
|---|
| 899 | + |
|---|
| 900 | + xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n", |
|---|
| 901 | + hcd->self.busnum, wIndex + 1, port_status); |
|---|
| 902 | + *status |= USB_PORT_STAT_SUSPEND; |
|---|
| 903 | + clear_bit(wIndex, &bus_state->rexit_ports); |
|---|
| 904 | + } |
|---|
| 905 | + |
|---|
| 906 | + usb_hcd_end_port_resume(&hcd->self, wIndex); |
|---|
| 907 | + bus_state->port_c_suspend |= 1 << wIndex; |
|---|
| 908 | + bus_state->suspended_ports &= ~(1 << wIndex); |
|---|
| 909 | + } else { |
|---|
| 910 | + /* |
|---|
| 911 | + * The resume has been signaling for less than |
|---|
| 912 | + * USB_RESUME_TIME. Report the port status as SUSPEND, |
|---|
| 913 | + * let the usbcore check port status again and clear |
|---|
| 914 | + * resume signaling later. |
|---|
| 915 | + */ |
|---|
| 916 | + *status |= USB_PORT_STAT_SUSPEND; |
|---|
| 917 | + } |
|---|
| 918 | + return 0; |
|---|
| 919 | +} |
|---|
| 920 | + |
|---|
| 817 | 921 | static u32 xhci_get_ext_port_status(u32 raw_port_status, u32 port_li) |
|---|
| 818 | 922 | { |
|---|
| 819 | 923 | u32 ext_stat = 0; |
|---|
| .. | .. |
|---|
| 828 | 932 | ext_stat |= PORT_TX_LANES(port_li) << 12; /* bits 15:12 Tx lane count */ |
|---|
| 829 | 933 | |
|---|
| 830 | 934 | return ext_stat; |
|---|
| 935 | +} |
|---|
| 936 | + |
|---|
| 937 | +static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status, |
|---|
| 938 | + u32 portsc) |
|---|
| 939 | +{ |
|---|
| 940 | + struct xhci_bus_state *bus_state; |
|---|
| 941 | + struct xhci_hcd *xhci; |
|---|
| 942 | + struct usb_hcd *hcd; |
|---|
| 943 | + u32 link_state; |
|---|
| 944 | + u32 portnum; |
|---|
| 945 | + |
|---|
| 946 | + bus_state = &port->rhub->bus_state; |
|---|
| 947 | + xhci = hcd_to_xhci(port->rhub->hcd); |
|---|
| 948 | + hcd = port->rhub->hcd; |
|---|
| 949 | + link_state = portsc & PORT_PLS_MASK; |
|---|
| 950 | + portnum = port->hcd_portnum; |
|---|
| 951 | + |
|---|
| 952 | + /* USB3 specific wPortChange bits |
|---|
| 953 | + * |
|---|
| 954 | + * Port link change with port in resume state should not be |
|---|
| 955 | + * reported to usbcore, as this is an internal state to be |
|---|
| 956 | + * handled by xhci driver. Reporting PLC to usbcore may |
|---|
| 957 | + * cause usbcore clearing PLC first and port change event |
|---|
| 958 | + * irq won't be generated. |
|---|
| 959 | + */ |
|---|
| 960 | + |
|---|
| 961 | + if (portsc & PORT_PLC && (link_state != XDEV_RESUME)) |
|---|
| 962 | + *status |= USB_PORT_STAT_C_LINK_STATE << 16; |
|---|
| 963 | + if (portsc & PORT_WRC) |
|---|
| 964 | + *status |= USB_PORT_STAT_C_BH_RESET << 16; |
|---|
| 965 | + if (portsc & PORT_CEC) |
|---|
| 966 | + *status |= USB_PORT_STAT_C_CONFIG_ERROR << 16; |
|---|
| 967 | + |
|---|
| 968 | + /* USB3 specific wPortStatus bits */ |
|---|
| 969 | + if (portsc & PORT_POWER) { |
|---|
| 970 | + *status |= USB_SS_PORT_STAT_POWER; |
|---|
| 971 | + /* link state handling */ |
|---|
| 972 | + if (link_state == XDEV_U0) |
|---|
| 973 | + bus_state->suspended_ports &= ~(1 << portnum); |
|---|
| 974 | + } |
|---|
| 975 | + |
|---|
| 976 | + /* remote wake resume signaling complete */ |
|---|
| 977 | + if (bus_state->port_remote_wakeup & (1 << portnum) && |
|---|
| 978 | + link_state != XDEV_RESUME && |
|---|
| 979 | + link_state != XDEV_RECOVERY) { |
|---|
| 980 | + bus_state->port_remote_wakeup &= ~(1 << portnum); |
|---|
| 981 | + usb_hcd_end_port_resume(&hcd->self, portnum); |
|---|
| 982 | + } |
|---|
| 983 | + |
|---|
| 984 | + xhci_hub_report_usb3_link_state(xhci, status, portsc); |
|---|
| 985 | + xhci_del_comp_mod_timer(xhci, portsc, portnum); |
|---|
| 986 | +} |
|---|
| 987 | + |
|---|
| 988 | +static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status, |
|---|
| 989 | + u32 portsc, unsigned long *flags) |
|---|
| 990 | +{ |
|---|
| 991 | + struct xhci_bus_state *bus_state; |
|---|
| 992 | + u32 link_state; |
|---|
| 993 | + u32 portnum; |
|---|
| 994 | + int ret; |
|---|
| 995 | + |
|---|
| 996 | + bus_state = &port->rhub->bus_state; |
|---|
| 997 | + link_state = portsc & PORT_PLS_MASK; |
|---|
| 998 | + portnum = port->hcd_portnum; |
|---|
| 999 | + |
|---|
| 1000 | + /* USB2 wPortStatus bits */ |
|---|
| 1001 | + if (portsc & PORT_POWER) { |
|---|
| 1002 | + *status |= USB_PORT_STAT_POWER; |
|---|
| 1003 | + |
|---|
| 1004 | + /* link state is only valid if port is powered */ |
|---|
| 1005 | + if (link_state == XDEV_U3) |
|---|
| 1006 | + *status |= USB_PORT_STAT_SUSPEND; |
|---|
| 1007 | + if (link_state == XDEV_U2) |
|---|
| 1008 | + *status |= USB_PORT_STAT_L1; |
|---|
| 1009 | + if (link_state == XDEV_U0) { |
|---|
| 1010 | + if (bus_state->resume_done[portnum]) |
|---|
| 1011 | + usb_hcd_end_port_resume(&port->rhub->hcd->self, |
|---|
| 1012 | + portnum); |
|---|
| 1013 | + bus_state->resume_done[portnum] = 0; |
|---|
| 1014 | + clear_bit(portnum, &bus_state->resuming_ports); |
|---|
| 1015 | + if (bus_state->suspended_ports & (1 << portnum)) { |
|---|
| 1016 | + bus_state->suspended_ports &= ~(1 << portnum); |
|---|
| 1017 | + bus_state->port_c_suspend |= 1 << portnum; |
|---|
| 1018 | + } |
|---|
| 1019 | + } |
|---|
| 1020 | + if (link_state == XDEV_RESUME) { |
|---|
| 1021 | + ret = xhci_handle_usb2_port_link_resume(port, status, |
|---|
| 1022 | + portsc, flags); |
|---|
| 1023 | + if (ret) |
|---|
| 1024 | + return; |
|---|
| 1025 | + } |
|---|
| 1026 | + } |
|---|
| 831 | 1027 | } |
|---|
| 832 | 1028 | |
|---|
| 833 | 1029 | /* |
|---|
| .. | .. |
|---|
| 847 | 1043 | __releases(&xhci->lock) |
|---|
| 848 | 1044 | __acquires(&xhci->lock) |
|---|
| 849 | 1045 | { |
|---|
| 850 | | - struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
|---|
| 851 | 1046 | u32 status = 0; |
|---|
| 852 | | - int slot_id; |
|---|
| 853 | 1047 | struct xhci_hub *rhub; |
|---|
| 854 | 1048 | struct xhci_port *port; |
|---|
| 855 | 1049 | |
|---|
| 856 | 1050 | rhub = xhci_get_rhub(hcd); |
|---|
| 857 | 1051 | port = rhub->ports[wIndex]; |
|---|
| 858 | 1052 | |
|---|
| 859 | | - /* wPortChange bits */ |
|---|
| 1053 | + /* common wPortChange bits */ |
|---|
| 860 | 1054 | if (raw_port_status & PORT_CSC) |
|---|
| 861 | 1055 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
|---|
| 862 | 1056 | if (raw_port_status & PORT_PEC) |
|---|
| .. | .. |
|---|
| 865 | 1059 | status |= USB_PORT_STAT_C_OVERCURRENT << 16; |
|---|
| 866 | 1060 | if ((raw_port_status & PORT_RC)) |
|---|
| 867 | 1061 | status |= USB_PORT_STAT_C_RESET << 16; |
|---|
| 868 | | - /* USB3.0 only */ |
|---|
| 869 | | - if (hcd->speed >= HCD_USB3) { |
|---|
| 870 | | - /* Port link change with port in resume state should not be |
|---|
| 871 | | - * reported to usbcore, as this is an internal state to be |
|---|
| 872 | | - * handled by xhci driver. Reporting PLC to usbcore may |
|---|
| 873 | | - * cause usbcore clearing PLC first and port change event |
|---|
| 874 | | - * irq won't be generated. |
|---|
| 875 | | - */ |
|---|
| 876 | | - if ((raw_port_status & PORT_PLC) && |
|---|
| 877 | | - (raw_port_status & PORT_PLS_MASK) != XDEV_RESUME) |
|---|
| 878 | | - status |= USB_PORT_STAT_C_LINK_STATE << 16; |
|---|
| 879 | | - if ((raw_port_status & PORT_WRC)) |
|---|
| 880 | | - status |= USB_PORT_STAT_C_BH_RESET << 16; |
|---|
| 881 | | - if ((raw_port_status & PORT_CEC)) |
|---|
| 882 | | - status |= USB_PORT_STAT_C_CONFIG_ERROR << 16; |
|---|
| 883 | 1062 | |
|---|
| 884 | | - /* USB3 remote wake resume signaling completed */ |
|---|
| 885 | | - if (bus_state->port_remote_wakeup & (1 << wIndex) && |
|---|
| 886 | | - (raw_port_status & PORT_PLS_MASK) != XDEV_RESUME && |
|---|
| 887 | | - (raw_port_status & PORT_PLS_MASK) != XDEV_RECOVERY) { |
|---|
| 888 | | - bus_state->port_remote_wakeup &= ~(1 << wIndex); |
|---|
| 889 | | - usb_hcd_end_port_resume(&hcd->self, wIndex); |
|---|
| 890 | | - } |
|---|
| 1063 | + /* common wPortStatus bits */ |
|---|
| 1064 | + if (raw_port_status & PORT_CONNECT) { |
|---|
| 1065 | + status |= USB_PORT_STAT_CONNECTION; |
|---|
| 1066 | + status |= xhci_port_speed(raw_port_status); |
|---|
| 891 | 1067 | } |
|---|
| 1068 | + if (raw_port_status & PORT_PE) |
|---|
| 1069 | + status |= USB_PORT_STAT_ENABLE; |
|---|
| 1070 | + if (raw_port_status & PORT_OC) |
|---|
| 1071 | + status |= USB_PORT_STAT_OVERCURRENT; |
|---|
| 1072 | + if (raw_port_status & PORT_RESET) |
|---|
| 1073 | + status |= USB_PORT_STAT_RESET; |
|---|
| 892 | 1074 | |
|---|
| 893 | | - if (hcd->speed < HCD_USB3) { |
|---|
| 894 | | - if ((raw_port_status & PORT_PLS_MASK) == XDEV_U3 |
|---|
| 895 | | - && (raw_port_status & PORT_POWER)) |
|---|
| 896 | | - status |= USB_PORT_STAT_SUSPEND; |
|---|
| 897 | | - } |
|---|
| 898 | | - if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME && |
|---|
| 899 | | - !DEV_SUPERSPEED_ANY(raw_port_status) && hcd->speed < HCD_USB3) { |
|---|
| 900 | | - if ((raw_port_status & PORT_RESET) || |
|---|
| 901 | | - !(raw_port_status & PORT_PE)) |
|---|
| 902 | | - return 0xffffffff; |
|---|
| 903 | | - /* did port event handler already start resume timing? */ |
|---|
| 904 | | - if (!bus_state->resume_done[wIndex]) { |
|---|
| 905 | | - /* If not, maybe we are in a host initated resume? */ |
|---|
| 906 | | - if (test_bit(wIndex, &bus_state->resuming_ports)) { |
|---|
| 907 | | - /* Host initated resume doesn't time the resume |
|---|
| 908 | | - * signalling using resume_done[]. |
|---|
| 909 | | - * It manually sets RESUME state, sleeps 20ms |
|---|
| 910 | | - * and sets U0 state. This should probably be |
|---|
| 911 | | - * changed, but not right now. |
|---|
| 912 | | - */ |
|---|
| 913 | | - } else { |
|---|
| 914 | | - /* port resume was discovered now and here, |
|---|
| 915 | | - * start resume timing |
|---|
| 916 | | - */ |
|---|
| 917 | | - unsigned long timeout = jiffies + |
|---|
| 918 | | - msecs_to_jiffies(USB_RESUME_TIMEOUT); |
|---|
| 919 | | - |
|---|
| 920 | | - set_bit(wIndex, &bus_state->resuming_ports); |
|---|
| 921 | | - bus_state->resume_done[wIndex] = timeout; |
|---|
| 922 | | - mod_timer(&hcd->rh_timer, timeout); |
|---|
| 923 | | - usb_hcd_start_port_resume(&hcd->self, wIndex); |
|---|
| 924 | | - } |
|---|
| 925 | | - /* Has resume been signalled for USB_RESUME_TIME yet? */ |
|---|
| 926 | | - } else if (time_after_eq(jiffies, |
|---|
| 927 | | - bus_state->resume_done[wIndex])) { |
|---|
| 928 | | - int time_left; |
|---|
| 929 | | - |
|---|
| 930 | | - xhci_dbg(xhci, "Resume USB2 port %d\n", |
|---|
| 931 | | - wIndex + 1); |
|---|
| 932 | | - bus_state->resume_done[wIndex] = 0; |
|---|
| 933 | | - clear_bit(wIndex, &bus_state->resuming_ports); |
|---|
| 934 | | - |
|---|
| 935 | | - set_bit(wIndex, &bus_state->rexit_ports); |
|---|
| 936 | | - |
|---|
| 937 | | - xhci_test_and_clear_bit(xhci, port, PORT_PLC); |
|---|
| 938 | | - xhci_set_link_state(xhci, port, XDEV_U0); |
|---|
| 939 | | - |
|---|
| 940 | | - spin_unlock_irqrestore(&xhci->lock, *flags); |
|---|
| 941 | | - time_left = wait_for_completion_timeout( |
|---|
| 942 | | - &bus_state->rexit_done[wIndex], |
|---|
| 943 | | - msecs_to_jiffies( |
|---|
| 944 | | - XHCI_MAX_REXIT_TIMEOUT_MS)); |
|---|
| 945 | | - spin_lock_irqsave(&xhci->lock, *flags); |
|---|
| 946 | | - |
|---|
| 947 | | - if (time_left) { |
|---|
| 948 | | - slot_id = xhci_find_slot_id_by_port(hcd, |
|---|
| 949 | | - xhci, wIndex + 1); |
|---|
| 950 | | - if (!slot_id) { |
|---|
| 951 | | - xhci_dbg(xhci, "slot_id is zero\n"); |
|---|
| 952 | | - return 0xffffffff; |
|---|
| 953 | | - } |
|---|
| 954 | | - xhci_ring_device(xhci, slot_id); |
|---|
| 955 | | - } else { |
|---|
| 956 | | - int port_status = readl(port->addr); |
|---|
| 957 | | - xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n", |
|---|
| 958 | | - XHCI_MAX_REXIT_TIMEOUT_MS, |
|---|
| 959 | | - port_status); |
|---|
| 960 | | - status |= USB_PORT_STAT_SUSPEND; |
|---|
| 961 | | - clear_bit(wIndex, &bus_state->rexit_ports); |
|---|
| 962 | | - } |
|---|
| 963 | | - |
|---|
| 964 | | - usb_hcd_end_port_resume(&hcd->self, wIndex); |
|---|
| 965 | | - bus_state->port_c_suspend |= 1 << wIndex; |
|---|
| 966 | | - bus_state->suspended_ports &= ~(1 << wIndex); |
|---|
| 967 | | - } else { |
|---|
| 968 | | - /* |
|---|
| 969 | | - * The resume has been signaling for less than |
|---|
| 970 | | - * USB_RESUME_TIME. Report the port status as SUSPEND, |
|---|
| 971 | | - * let the usbcore check port status again and clear |
|---|
| 972 | | - * resume signaling later. |
|---|
| 973 | | - */ |
|---|
| 974 | | - status |= USB_PORT_STAT_SUSPEND; |
|---|
| 975 | | - } |
|---|
| 976 | | - } |
|---|
| 1075 | + /* USB2 and USB3 specific bits, including Port Link State */ |
|---|
| 1076 | + if (hcd->speed >= HCD_USB3) |
|---|
| 1077 | + xhci_get_usb3_port_status(port, &status, raw_port_status); |
|---|
| 1078 | + else |
|---|
| 1079 | + xhci_get_usb2_port_status(port, &status, raw_port_status, |
|---|
| 1080 | + flags); |
|---|
| 977 | 1081 | /* |
|---|
| 978 | 1082 | * Clear stale usb2 resume signalling variables in case port changed |
|---|
| 979 | 1083 | * state during resume signalling. For example on error |
|---|
| .. | .. |
|---|
| 987 | 1091 | usb_hcd_end_port_resume(&hcd->self, wIndex); |
|---|
| 988 | 1092 | } |
|---|
| 989 | 1093 | |
|---|
| 990 | | - |
|---|
| 991 | | - if ((raw_port_status & PORT_PLS_MASK) == XDEV_U0 && |
|---|
| 992 | | - (raw_port_status & PORT_POWER)) { |
|---|
| 993 | | - if (bus_state->suspended_ports & (1 << wIndex)) { |
|---|
| 994 | | - bus_state->suspended_ports &= ~(1 << wIndex); |
|---|
| 995 | | - if (hcd->speed < HCD_USB3) |
|---|
| 996 | | - bus_state->port_c_suspend |= 1 << wIndex; |
|---|
| 997 | | - } |
|---|
| 998 | | - bus_state->resume_done[wIndex] = 0; |
|---|
| 999 | | - clear_bit(wIndex, &bus_state->resuming_ports); |
|---|
| 1000 | | - } |
|---|
| 1001 | | - if (raw_port_status & PORT_CONNECT) { |
|---|
| 1002 | | - status |= USB_PORT_STAT_CONNECTION; |
|---|
| 1003 | | - status |= xhci_port_speed(raw_port_status); |
|---|
| 1004 | | - } |
|---|
| 1005 | | - if (raw_port_status & PORT_PE) |
|---|
| 1006 | | - status |= USB_PORT_STAT_ENABLE; |
|---|
| 1007 | | - if (raw_port_status & PORT_OC) |
|---|
| 1008 | | - status |= USB_PORT_STAT_OVERCURRENT; |
|---|
| 1009 | | - if (raw_port_status & PORT_RESET) |
|---|
| 1010 | | - status |= USB_PORT_STAT_RESET; |
|---|
| 1011 | | - if (raw_port_status & PORT_POWER) { |
|---|
| 1012 | | - if (hcd->speed >= HCD_USB3) |
|---|
| 1013 | | - status |= USB_SS_PORT_STAT_POWER; |
|---|
| 1014 | | - else |
|---|
| 1015 | | - status |= USB_PORT_STAT_POWER; |
|---|
| 1016 | | - } |
|---|
| 1017 | | - /* Update Port Link State */ |
|---|
| 1018 | | - if (hcd->speed >= HCD_USB3) { |
|---|
| 1019 | | - xhci_hub_report_usb3_link_state(xhci, &status, raw_port_status); |
|---|
| 1020 | | - /* |
|---|
| 1021 | | - * Verify if all USB3 Ports Have entered U0 already. |
|---|
| 1022 | | - * Delete Compliance Mode Timer if so. |
|---|
| 1023 | | - */ |
|---|
| 1024 | | - xhci_del_comp_mod_timer(xhci, raw_port_status, wIndex); |
|---|
| 1025 | | - } else { |
|---|
| 1026 | | - xhci_hub_report_usb2_link_state(&status, raw_port_status); |
|---|
| 1027 | | - } |
|---|
| 1028 | 1094 | if (bus_state->port_c_suspend & (1 << wIndex)) |
|---|
| 1029 | 1095 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
|---|
| 1030 | 1096 | |
|---|
| .. | .. |
|---|
| 1051 | 1117 | rhub = xhci_get_rhub(hcd); |
|---|
| 1052 | 1118 | ports = rhub->ports; |
|---|
| 1053 | 1119 | max_ports = rhub->num_ports; |
|---|
| 1054 | | - bus_state = &xhci->bus_state[hcd_index(hcd)]; |
|---|
| 1120 | + bus_state = &rhub->bus_state; |
|---|
| 1055 | 1121 | |
|---|
| 1056 | 1122 | spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1057 | 1123 | switch (typeReq) { |
|---|
| .. | .. |
|---|
| 1100 | 1166 | if (status == 0xffffffff) |
|---|
| 1101 | 1167 | goto error; |
|---|
| 1102 | 1168 | |
|---|
| 1103 | | - xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", |
|---|
| 1104 | | - wIndex, temp); |
|---|
| 1105 | | - xhci_dbg(xhci, "Get port status returned 0x%x\n", status); |
|---|
| 1169 | + xhci_dbg(xhci, "Get port status %d-%d read: 0x%x, return 0x%x", |
|---|
| 1170 | + hcd->self.busnum, wIndex + 1, temp, status); |
|---|
| 1106 | 1171 | |
|---|
| 1107 | 1172 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
|---|
| 1108 | 1173 | /* if USB 3.1 extended port status return additional 4 bytes */ |
|---|
| .. | .. |
|---|
| 1158 | 1223 | temp = readl(ports[wIndex]->addr); |
|---|
| 1159 | 1224 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) |
|---|
| 1160 | 1225 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { |
|---|
| 1161 | | - xhci_warn(xhci, "USB core suspending device not in U0/U1/U2.\n"); |
|---|
| 1226 | + xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n", |
|---|
| 1227 | + hcd->self.busnum, wIndex + 1); |
|---|
| 1162 | 1228 | goto error; |
|---|
| 1163 | 1229 | } |
|---|
| 1164 | 1230 | |
|---|
| .. | .. |
|---|
| 1186 | 1252 | temp = readl(ports[wIndex]->addr); |
|---|
| 1187 | 1253 | /* Disable port */ |
|---|
| 1188 | 1254 | if (link_state == USB_SS_PORT_LS_SS_DISABLED) { |
|---|
| 1189 | | - xhci_dbg(xhci, "Disable port %d\n", wIndex); |
|---|
| 1255 | + xhci_dbg(xhci, "Disable port %d-%d\n", |
|---|
| 1256 | + hcd->self.busnum, wIndex + 1); |
|---|
| 1190 | 1257 | temp = xhci_port_state_to_neutral(temp); |
|---|
| 1191 | 1258 | /* |
|---|
| 1192 | 1259 | * Clear all change bits, so that we get a new |
|---|
| .. | .. |
|---|
| 1202 | 1269 | |
|---|
| 1203 | 1270 | /* Put link in RxDetect (enable port) */ |
|---|
| 1204 | 1271 | if (link_state == USB_SS_PORT_LS_RX_DETECT) { |
|---|
| 1205 | | - xhci_dbg(xhci, "Enable port %d\n", wIndex); |
|---|
| 1272 | + xhci_dbg(xhci, "Enable port %d-%d\n", |
|---|
| 1273 | + hcd->self.busnum, wIndex + 1); |
|---|
| 1206 | 1274 | xhci_set_link_state(xhci, ports[wIndex], |
|---|
| 1207 | 1275 | link_state); |
|---|
| 1208 | 1276 | temp = readl(ports[wIndex]->addr); |
|---|
| .. | .. |
|---|
| 1234 | 1302 | goto error; |
|---|
| 1235 | 1303 | } |
|---|
| 1236 | 1304 | |
|---|
| 1237 | | - xhci_dbg(xhci, "Enable compliance mode transition for port %d\n", |
|---|
| 1238 | | - wIndex); |
|---|
| 1305 | + xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n", |
|---|
| 1306 | + hcd->self.busnum, wIndex + 1); |
|---|
| 1239 | 1307 | xhci_set_link_state(xhci, ports[wIndex], |
|---|
| 1240 | 1308 | link_state); |
|---|
| 1241 | 1309 | |
|---|
| .. | .. |
|---|
| 1249 | 1317 | } |
|---|
| 1250 | 1318 | /* Can't set port link state above '3' (U3) */ |
|---|
| 1251 | 1319 | if (link_state > USB_SS_PORT_LS_U3) { |
|---|
| 1252 | | - xhci_warn(xhci, "Cannot set port %d link state %d\n", |
|---|
| 1253 | | - wIndex, link_state); |
|---|
| 1320 | + xhci_warn(xhci, "Cannot set port %d-%d link state %d\n", |
|---|
| 1321 | + hcd->self.busnum, wIndex + 1, |
|---|
| 1322 | + link_state); |
|---|
| 1254 | 1323 | goto error; |
|---|
| 1255 | 1324 | } |
|---|
| 1325 | + |
|---|
| 1326 | + /* |
|---|
| 1327 | + * set link to U0, steps depend on current link state. |
|---|
| 1328 | + * U3: set link to U0 and wait for u3exit completion. |
|---|
| 1329 | + * U1/U2: no PLC complete event, only set link to U0. |
|---|
| 1330 | + * Resume/Recovery: device initiated U0, only wait for |
|---|
| 1331 | + * completion |
|---|
| 1332 | + */ |
|---|
| 1333 | + if (link_state == USB_SS_PORT_LS_U0) { |
|---|
| 1334 | + u32 pls = temp & PORT_PLS_MASK; |
|---|
| 1335 | + bool wait_u0 = false; |
|---|
| 1336 | + |
|---|
| 1337 | + /* already in U0 */ |
|---|
| 1338 | + if (pls == XDEV_U0) |
|---|
| 1339 | + break; |
|---|
| 1340 | + if (pls == XDEV_U3 || |
|---|
| 1341 | + pls == XDEV_RESUME || |
|---|
| 1342 | + pls == XDEV_RECOVERY) { |
|---|
| 1343 | + wait_u0 = true; |
|---|
| 1344 | + reinit_completion(&bus_state->u3exit_done[wIndex]); |
|---|
| 1345 | + } |
|---|
| 1346 | + if (pls <= XDEV_U3) /* U1, U2, U3 */ |
|---|
| 1347 | + xhci_set_link_state(xhci, ports[wIndex], |
|---|
| 1348 | + USB_SS_PORT_LS_U0); |
|---|
| 1349 | + if (!wait_u0) { |
|---|
| 1350 | + if (pls > XDEV_U3) |
|---|
| 1351 | + goto error; |
|---|
| 1352 | + break; |
|---|
| 1353 | + } |
|---|
| 1354 | + spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1355 | + if (!wait_for_completion_timeout(&bus_state->u3exit_done[wIndex], |
|---|
| 1356 | + msecs_to_jiffies(500))) |
|---|
| 1357 | + xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n", |
|---|
| 1358 | + hcd->self.busnum, wIndex + 1); |
|---|
| 1359 | + spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1360 | + temp = readl(ports[wIndex]->addr); |
|---|
| 1361 | + break; |
|---|
| 1362 | + } |
|---|
| 1363 | + |
|---|
| 1256 | 1364 | if (link_state == USB_SS_PORT_LS_U3) { |
|---|
| 1365 | + int retries = 16; |
|---|
| 1257 | 1366 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
|---|
| 1258 | 1367 | wIndex + 1); |
|---|
| 1259 | 1368 | if (slot_id) { |
|---|
| .. | .. |
|---|
| 1264 | 1373 | xhci_stop_device(xhci, slot_id, 1); |
|---|
| 1265 | 1374 | spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1266 | 1375 | } |
|---|
| 1267 | | - } |
|---|
| 1268 | | - |
|---|
| 1269 | | - xhci_set_link_state(xhci, ports[wIndex], link_state); |
|---|
| 1270 | | - |
|---|
| 1271 | | - spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1272 | | - if (link_state == USB_SS_PORT_LS_U3) { |
|---|
| 1273 | | - int retries = 16; |
|---|
| 1274 | | - |
|---|
| 1376 | + xhci_set_link_state(xhci, ports[wIndex], USB_SS_PORT_LS_U3); |
|---|
| 1377 | + spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1275 | 1378 | while (retries--) { |
|---|
| 1276 | 1379 | usleep_range(4000, 8000); |
|---|
| 1277 | 1380 | temp = readl(ports[wIndex]->addr); |
|---|
| 1278 | 1381 | if ((temp & PORT_PLS_MASK) == XDEV_U3) |
|---|
| 1279 | 1382 | break; |
|---|
| 1280 | 1383 | } |
|---|
| 1281 | | - } |
|---|
| 1282 | | - spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1283 | | - |
|---|
| 1284 | | - temp = readl(ports[wIndex]->addr); |
|---|
| 1285 | | - if (link_state == USB_SS_PORT_LS_U3) |
|---|
| 1384 | + spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1385 | + temp = readl(ports[wIndex]->addr); |
|---|
| 1286 | 1386 | bus_state->suspended_ports |= 1 << wIndex; |
|---|
| 1387 | + } |
|---|
| 1287 | 1388 | break; |
|---|
| 1288 | 1389 | case USB_PORT_FEAT_POWER: |
|---|
| 1289 | 1390 | /* |
|---|
| .. | .. |
|---|
| 1299 | 1400 | writel(temp, ports[wIndex]->addr); |
|---|
| 1300 | 1401 | |
|---|
| 1301 | 1402 | temp = readl(ports[wIndex]->addr); |
|---|
| 1302 | | - xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); |
|---|
| 1403 | + xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n", |
|---|
| 1404 | + hcd->self.busnum, wIndex + 1, temp); |
|---|
| 1303 | 1405 | break; |
|---|
| 1304 | 1406 | case USB_PORT_FEAT_REMOTE_WAKE_MASK: |
|---|
| 1305 | 1407 | xhci_set_remote_wake_mask(xhci, ports[wIndex], |
|---|
| 1306 | 1408 | wake_mask); |
|---|
| 1307 | 1409 | temp = readl(ports[wIndex]->addr); |
|---|
| 1308 | | - xhci_dbg(xhci, "set port remote wake mask, " |
|---|
| 1309 | | - "actual port %d status = 0x%x\n", |
|---|
| 1310 | | - wIndex, temp); |
|---|
| 1410 | + xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n", |
|---|
| 1411 | + hcd->self.busnum, wIndex + 1, temp); |
|---|
| 1311 | 1412 | break; |
|---|
| 1312 | 1413 | case USB_PORT_FEAT_BH_PORT_RESET: |
|---|
| 1313 | 1414 | temp |= PORT_WR; |
|---|
| .. | .. |
|---|
| 1334 | 1435 | /* 4.19.6 Port Test Modes (USB2 Test Mode) */ |
|---|
| 1335 | 1436 | if (hcd->speed != HCD_USB2) |
|---|
| 1336 | 1437 | goto error; |
|---|
| 1337 | | - if (test_mode > TEST_FORCE_EN || test_mode < TEST_J) |
|---|
| 1438 | + if (test_mode > USB_TEST_FORCE_ENABLE || |
|---|
| 1439 | + test_mode < USB_TEST_J) |
|---|
| 1338 | 1440 | goto error; |
|---|
| 1339 | 1441 | retval = xhci_enter_test_mode(xhci, test_mode, wIndex, |
|---|
| 1340 | 1442 | &flags); |
|---|
| .. | .. |
|---|
| 1392 | 1494 | break; |
|---|
| 1393 | 1495 | case USB_PORT_FEAT_C_SUSPEND: |
|---|
| 1394 | 1496 | bus_state->port_c_suspend &= ~(1 << wIndex); |
|---|
| 1395 | | - /* fall through */ |
|---|
| 1497 | + fallthrough; |
|---|
| 1396 | 1498 | case USB_PORT_FEAT_C_RESET: |
|---|
| 1397 | 1499 | case USB_PORT_FEAT_C_BH_PORT_RESET: |
|---|
| 1398 | 1500 | case USB_PORT_FEAT_C_CONNECTION: |
|---|
| .. | .. |
|---|
| 1450 | 1552 | rhub = xhci_get_rhub(hcd); |
|---|
| 1451 | 1553 | ports = rhub->ports; |
|---|
| 1452 | 1554 | max_ports = rhub->num_ports; |
|---|
| 1453 | | - bus_state = &xhci->bus_state[hcd_index(hcd)]; |
|---|
| 1555 | + bus_state = &rhub->bus_state; |
|---|
| 1454 | 1556 | |
|---|
| 1455 | 1557 | /* Initial status is no changes */ |
|---|
| 1456 | 1558 | retval = (max_ports + 8) / 8; |
|---|
| .. | .. |
|---|
| 1489 | 1591 | status = 1; |
|---|
| 1490 | 1592 | } |
|---|
| 1491 | 1593 | if (!status && !reset_change) { |
|---|
| 1492 | | - xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); |
|---|
| 1594 | + xhci_dbg(xhci, "%s: stopping usb%d port polling\n", |
|---|
| 1595 | + __func__, hcd->self.busnum); |
|---|
| 1493 | 1596 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
|---|
| 1494 | 1597 | } |
|---|
| 1495 | 1598 | spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| .. | .. |
|---|
| 1512 | 1615 | rhub = xhci_get_rhub(hcd); |
|---|
| 1513 | 1616 | ports = rhub->ports; |
|---|
| 1514 | 1617 | max_ports = rhub->num_ports; |
|---|
| 1515 | | - bus_state = &xhci->bus_state[hcd_index(hcd)]; |
|---|
| 1618 | + bus_state = &rhub->bus_state; |
|---|
| 1516 | 1619 | wake_enabled = hcd->self.root_hub->do_remote_wakeup; |
|---|
| 1517 | 1620 | |
|---|
| 1518 | 1621 | spin_lock_irqsave(&xhci->lock, flags); |
|---|
| .. | .. |
|---|
| 1521 | 1624 | if (bus_state->resuming_ports || /* USB2 */ |
|---|
| 1522 | 1625 | bus_state->port_remote_wakeup) { /* USB3 */ |
|---|
| 1523 | 1626 | spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1524 | | - xhci_dbg(xhci, "suspend failed because a port is resuming\n"); |
|---|
| 1627 | + xhci_dbg(xhci, "usb%d bus suspend to fail because a port is resuming\n", |
|---|
| 1628 | + hcd->self.busnum); |
|---|
| 1525 | 1629 | return -EBUSY; |
|---|
| 1526 | 1630 | } |
|---|
| 1527 | 1631 | } |
|---|
| .. | .. |
|---|
| 1548 | 1652 | spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1549 | 1653 | msleep(XHCI_PORT_POLLING_LFPS_TIME); |
|---|
| 1550 | 1654 | spin_lock_irqsave(&xhci->lock, flags); |
|---|
| 1551 | | - xhci_dbg(xhci, "port %d polling in bus suspend, waiting\n", |
|---|
| 1552 | | - port_index); |
|---|
| 1655 | + xhci_dbg(xhci, "port %d-%d polling in bus suspend, waiting\n", |
|---|
| 1656 | + hcd->self.busnum, port_index + 1); |
|---|
| 1553 | 1657 | goto retry; |
|---|
| 1554 | 1658 | } |
|---|
| 1555 | 1659 | /* bail out if port detected a over-current condition */ |
|---|
| .. | .. |
|---|
| 1567 | 1671 | xhci_dbg(xhci, "Bus suspend bailout, port connect change\n"); |
|---|
| 1568 | 1672 | return -EBUSY; |
|---|
| 1569 | 1673 | } |
|---|
| 1570 | | - xhci_dbg(xhci, "port %d not suspended\n", port_index); |
|---|
| 1674 | + xhci_dbg(xhci, "port %d-%d not suspended\n", |
|---|
| 1675 | + hcd->self.busnum, port_index + 1); |
|---|
| 1571 | 1676 | t2 &= ~PORT_PLS_MASK; |
|---|
| 1572 | 1677 | t2 |= PORT_LINK_STROBE | XDEV_U3; |
|---|
| 1573 | 1678 | set_bit(port_index, &bus_state->bus_suspended); |
|---|
| .. | .. |
|---|
| 1640 | 1745 | |
|---|
| 1641 | 1746 | return 0; |
|---|
| 1642 | 1747 | } |
|---|
| 1748 | +EXPORT_SYMBOL_GPL(xhci_bus_suspend); |
|---|
| 1643 | 1749 | |
|---|
| 1644 | 1750 | /* |
|---|
| 1645 | 1751 | * Workaround for missing Cold Attach Status (CAS) if device re-plugged in S3. |
|---|
| .. | .. |
|---|
| 1685 | 1791 | rhub = xhci_get_rhub(hcd); |
|---|
| 1686 | 1792 | ports = rhub->ports; |
|---|
| 1687 | 1793 | max_ports = rhub->num_ports; |
|---|
| 1688 | | - bus_state = &xhci->bus_state[hcd_index(hcd)]; |
|---|
| 1794 | + bus_state = &rhub->bus_state; |
|---|
| 1689 | 1795 | |
|---|
| 1690 | 1796 | if (time_before(jiffies, bus_state->next_statechange)) |
|---|
| 1691 | 1797 | msleep(5); |
|---|
| .. | .. |
|---|
| 1715 | 1821 | if ((xhci->quirks & XHCI_MISSING_CAS) && |
|---|
| 1716 | 1822 | (hcd->speed >= HCD_USB3) && |
|---|
| 1717 | 1823 | xhci_port_missing_cas_quirk(ports[port_index])) { |
|---|
| 1718 | | - xhci_dbg(xhci, "reset stuck port %d\n", port_index); |
|---|
| 1824 | + xhci_dbg(xhci, "reset stuck port %d-%d\n", |
|---|
| 1825 | + hcd->self.busnum, port_index + 1); |
|---|
| 1719 | 1826 | clear_bit(port_index, &bus_state->bus_suspended); |
|---|
| 1720 | 1827 | continue; |
|---|
| 1721 | 1828 | } |
|---|
| .. | .. |
|---|
| 1762 | 1869 | sret = xhci_handshake(ports[port_index]->addr, PORT_PLC, |
|---|
| 1763 | 1870 | PORT_PLC, 10 * 1000); |
|---|
| 1764 | 1871 | if (sret) { |
|---|
| 1765 | | - xhci_warn(xhci, "port %d resume PLC timeout\n", |
|---|
| 1766 | | - port_index); |
|---|
| 1872 | + xhci_warn(xhci, "port %d-%d resume PLC timeout\n", |
|---|
| 1873 | + hcd->self.busnum, port_index + 1); |
|---|
| 1767 | 1874 | continue; |
|---|
| 1768 | 1875 | } |
|---|
| 1769 | 1876 | xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC); |
|---|
| .. | .. |
|---|
| 1783 | 1890 | spin_unlock_irqrestore(&xhci->lock, flags); |
|---|
| 1784 | 1891 | return 0; |
|---|
| 1785 | 1892 | } |
|---|
| 1893 | +EXPORT_SYMBOL_GPL(xhci_bus_resume); |
|---|
| 1786 | 1894 | |
|---|
| 1787 | 1895 | unsigned long xhci_get_resuming_ports(struct usb_hcd *hcd) |
|---|
| 1788 | 1896 | { |
|---|
| 1789 | | - struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
|---|
| 1790 | | - struct xhci_bus_state *bus_state; |
|---|
| 1791 | | - |
|---|
| 1792 | | - bus_state = &xhci->bus_state[hcd_index(hcd)]; |
|---|
| 1897 | + struct xhci_hub *rhub = xhci_get_rhub(hcd); |
|---|
| 1793 | 1898 | |
|---|
| 1794 | 1899 | /* USB3 port wakeups are reported via usb_wakeup_notification() */ |
|---|
| 1795 | | - return bus_state->resuming_ports; /* USB2 ports only */ |
|---|
| 1900 | + return rhub->bus_state.resuming_ports; /* USB2 ports only */ |
|---|
| 1796 | 1901 | } |
|---|
| 1797 | 1902 | |
|---|
| 1798 | 1903 | #endif /* CONFIG_PM */ |
|---|