aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/xhci.c')
-rw-r--r--drivers/usb/host/xhci.c106
1 files changed, 72 insertions, 34 deletions
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index f5fe1ac301a..5fc595f01b3 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -345,7 +345,8 @@ static void xhci_event_ring_work(unsigned long arg)
345 spin_lock_irqsave(&xhci->lock, flags); 345 spin_lock_irqsave(&xhci->lock, flags);
346 temp = xhci_readl(xhci, &xhci->op_regs->status); 346 temp = xhci_readl(xhci, &xhci->op_regs->status);
347 xhci_dbg(xhci, "op reg status = 0x%x\n", temp); 347 xhci_dbg(xhci, "op reg status = 0x%x\n", temp);
348 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) { 348 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
349 (xhci->xhc_state & XHCI_STATE_HALTED)) {
349 xhci_dbg(xhci, "HW died, polling stopped.\n"); 350 xhci_dbg(xhci, "HW died, polling stopped.\n");
350 spin_unlock_irqrestore(&xhci->lock, flags); 351 spin_unlock_irqrestore(&xhci->lock, flags);
351 return; 352 return;
@@ -656,7 +657,10 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
656 ring = xhci->cmd_ring; 657 ring = xhci->cmd_ring;
657 seg = ring->deq_seg; 658 seg = ring->deq_seg;
658 do { 659 do {
659 memset(seg->trbs, 0, SEGMENT_SIZE); 660 memset(seg->trbs, 0,
661 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1));
662 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &=
663 cpu_to_le32(~TRB_CYCLE);
660 seg = seg->next; 664 seg = seg->next;
661 } while (seg != ring->deq_seg); 665 } while (seg != ring->deq_seg);
662 666
@@ -748,7 +752,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
748 u32 command, temp = 0; 752 u32 command, temp = 0;
749 struct usb_hcd *hcd = xhci_to_hcd(xhci); 753 struct usb_hcd *hcd = xhci_to_hcd(xhci);
750 struct usb_hcd *secondary_hcd; 754 struct usb_hcd *secondary_hcd;
751 int retval; 755 int retval = 0;
752 756
753 /* Wait a bit if either of the roothubs need to settle from the 757 /* Wait a bit if either of the roothubs need to settle from the
754 * transition into bus suspend. 758 * transition into bus suspend.
@@ -758,6 +762,9 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
758 xhci->bus_state[1].next_statechange)) 762 xhci->bus_state[1].next_statechange))
759 msleep(100); 763 msleep(100);
760 764
765 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
766 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
767
761 spin_lock_irq(&xhci->lock); 768 spin_lock_irq(&xhci->lock);
762 if (xhci->quirks & XHCI_RESET_ON_RESUME) 769 if (xhci->quirks & XHCI_RESET_ON_RESUME)
763 hibernated = true; 770 hibernated = true;
@@ -827,20 +834,13 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
827 return retval; 834 return retval;
828 xhci_dbg(xhci, "Start the primary HCD\n"); 835 xhci_dbg(xhci, "Start the primary HCD\n");
829 retval = xhci_run(hcd->primary_hcd); 836 retval = xhci_run(hcd->primary_hcd);
830 if (retval)
831 goto failed_restart;
832
833 xhci_dbg(xhci, "Start the secondary HCD\n");
834 retval = xhci_run(secondary_hcd);
835 if (!retval) { 837 if (!retval) {
836 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 838 xhci_dbg(xhci, "Start the secondary HCD\n");
837 set_bit(HCD_FLAG_HW_ACCESSIBLE, 839 retval = xhci_run(secondary_hcd);
838 &xhci->shared_hcd->flags);
839 } 840 }
840failed_restart:
841 hcd->state = HC_STATE_SUSPENDED; 841 hcd->state = HC_STATE_SUSPENDED;
842 xhci->shared_hcd->state = HC_STATE_SUSPENDED; 842 xhci->shared_hcd->state = HC_STATE_SUSPENDED;
843 return retval; 843 goto done;
844 } 844 }
845 845
846 /* step 4: set Run/Stop bit */ 846 /* step 4: set Run/Stop bit */
@@ -859,11 +859,14 @@ failed_restart:
859 * Running endpoints by ringing their doorbells 859 * Running endpoints by ringing their doorbells
860 */ 860 */
861 861
862 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
863 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
864
865 spin_unlock_irq(&xhci->lock); 862 spin_unlock_irq(&xhci->lock);
866 return 0; 863
864 done:
865 if (retval == 0) {
866 usb_hcd_resume_root_hub(hcd);
867 usb_hcd_resume_root_hub(xhci->shared_hcd);
868 }
869 return retval;
867} 870}
868#endif /* CONFIG_PM */ 871#endif /* CONFIG_PM */
869 872
@@ -939,8 +942,11 @@ static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
939 return 0; 942 return 0;
940 } 943 }
941 944
945 xhci = hcd_to_xhci(hcd);
946 if (xhci->xhc_state & XHCI_STATE_HALTED)
947 return -ENODEV;
948
942 if (check_virt_dev) { 949 if (check_virt_dev) {
943 xhci = hcd_to_xhci(hcd);
944 if (!udev->slot_id || !xhci->devs 950 if (!udev->slot_id || !xhci->devs
945 || !xhci->devs[udev->slot_id]) { 951 || !xhci->devs[udev->slot_id]) {
946 printk(KERN_DEBUG "xHCI %s called with unaddressed " 952 printk(KERN_DEBUG "xHCI %s called with unaddressed "
@@ -1081,8 +1087,11 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1081 if (urb->dev->speed == USB_SPEED_FULL) { 1087 if (urb->dev->speed == USB_SPEED_FULL) {
1082 ret = xhci_check_maxpacket(xhci, slot_id, 1088 ret = xhci_check_maxpacket(xhci, slot_id,
1083 ep_index, urb); 1089 ep_index, urb);
1084 if (ret < 0) 1090 if (ret < 0) {
1091 xhci_urb_free_priv(xhci, urb_priv);
1092 urb->hcpriv = NULL;
1085 return ret; 1093 return ret;
1094 }
1086 } 1095 }
1087 1096
1088 /* We have a spinlock and interrupts disabled, so we must pass 1097 /* We have a spinlock and interrupts disabled, so we must pass
@@ -1093,6 +1102,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1093 goto dying; 1102 goto dying;
1094 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, 1103 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
1095 slot_id, ep_index); 1104 slot_id, ep_index);
1105 if (ret)
1106 goto free_priv;
1096 spin_unlock_irqrestore(&xhci->lock, flags); 1107 spin_unlock_irqrestore(&xhci->lock, flags);
1097 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { 1108 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
1098 spin_lock_irqsave(&xhci->lock, flags); 1109 spin_lock_irqsave(&xhci->lock, flags);
@@ -1113,6 +1124,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1113 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 1124 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
1114 slot_id, ep_index); 1125 slot_id, ep_index);
1115 } 1126 }
1127 if (ret)
1128 goto free_priv;
1116 spin_unlock_irqrestore(&xhci->lock, flags); 1129 spin_unlock_irqrestore(&xhci->lock, flags);
1117 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { 1130 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
1118 spin_lock_irqsave(&xhci->lock, flags); 1131 spin_lock_irqsave(&xhci->lock, flags);
@@ -1120,6 +1133,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1120 goto dying; 1133 goto dying;
1121 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, 1134 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
1122 slot_id, ep_index); 1135 slot_id, ep_index);
1136 if (ret)
1137 goto free_priv;
1123 spin_unlock_irqrestore(&xhci->lock, flags); 1138 spin_unlock_irqrestore(&xhci->lock, flags);
1124 } else { 1139 } else {
1125 spin_lock_irqsave(&xhci->lock, flags); 1140 spin_lock_irqsave(&xhci->lock, flags);
@@ -1127,18 +1142,22 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1127 goto dying; 1142 goto dying;
1128 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, 1143 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb,
1129 slot_id, ep_index); 1144 slot_id, ep_index);
1145 if (ret)
1146 goto free_priv;
1130 spin_unlock_irqrestore(&xhci->lock, flags); 1147 spin_unlock_irqrestore(&xhci->lock, flags);
1131 } 1148 }
1132exit: 1149exit:
1133 return ret; 1150 return ret;
1134dying: 1151dying:
1135 xhci_urb_free_priv(xhci, urb_priv);
1136 urb->hcpriv = NULL;
1137 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " 1152 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
1138 "non-responsive xHCI host.\n", 1153 "non-responsive xHCI host.\n",
1139 urb->ep->desc.bEndpointAddress, urb); 1154 urb->ep->desc.bEndpointAddress, urb);
1155 ret = -ESHUTDOWN;
1156free_priv:
1157 xhci_urb_free_priv(xhci, urb_priv);
1158 urb->hcpriv = NULL;
1140 spin_unlock_irqrestore(&xhci->lock, flags); 1159 spin_unlock_irqrestore(&xhci->lock, flags);
1141 return -ESHUTDOWN; 1160 return ret;
1142} 1161}
1143 1162
1144/* Get the right ring for the given URB. 1163/* Get the right ring for the given URB.
@@ -1235,6 +1254,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1235 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { 1254 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
1236 xhci_dbg(xhci, "HW died, freeing TD.\n"); 1255 xhci_dbg(xhci, "HW died, freeing TD.\n");
1237 urb_priv = urb->hcpriv; 1256 urb_priv = urb->hcpriv;
1257 for (i = urb_priv->td_cnt; i < urb_priv->length; i++) {
1258 td = urb_priv->td[i];
1259 if (!list_empty(&td->td_list))
1260 list_del_init(&td->td_list);
1261 if (!list_empty(&td->cancelled_td_list))
1262 list_del_init(&td->cancelled_td_list);
1263 }
1238 1264
1239 usb_hcd_unlink_urb_from_ep(hcd, urb); 1265 usb_hcd_unlink_urb_from_ep(hcd, urb);
1240 spin_unlock_irqrestore(&xhci->lock, flags); 1266 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -1242,7 +1268,8 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1242 xhci_urb_free_priv(xhci, urb_priv); 1268 xhci_urb_free_priv(xhci, urb_priv);
1243 return ret; 1269 return ret;
1244 } 1270 }
1245 if (xhci->xhc_state & XHCI_STATE_DYING) { 1271 if ((xhci->xhc_state & XHCI_STATE_DYING) ||
1272 (xhci->xhc_state & XHCI_STATE_HALTED)) {
1246 xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on " 1273 xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on "
1247 "non-responsive xHCI host.\n", 1274 "non-responsive xHCI host.\n",
1248 urb->ep->desc.bEndpointAddress, urb); 1275 urb->ep->desc.bEndpointAddress, urb);
@@ -1342,8 +1369,8 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1342 /* If the HC already knows the endpoint is disabled, 1369 /* If the HC already knows the endpoint is disabled,
1343 * or the HCD has noted it is disabled, ignore this request 1370 * or the HCD has noted it is disabled, ignore this request
1344 */ 1371 */
1345 if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == 1372 if (((ep_ctx->ep_info & cpu_to_le32(EP_STATE_MASK)) ==
1346 EP_STATE_DISABLED || 1373 cpu_to_le32(EP_STATE_DISABLED)) ||
1347 le32_to_cpu(ctrl_ctx->drop_flags) & 1374 le32_to_cpu(ctrl_ctx->drop_flags) &
1348 xhci_get_endpoint_flag(&ep->desc)) { 1375 xhci_get_endpoint_flag(&ep->desc)) {
1349 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", 1376 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n",
@@ -1541,6 +1568,7 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1541 /* FIXME: can we allocate more resources for the HC? */ 1568 /* FIXME: can we allocate more resources for the HC? */
1542 break; 1569 break;
1543 case COMP_BW_ERR: 1570 case COMP_BW_ERR:
1571 case COMP_2ND_BW_ERR:
1544 dev_warn(&udev->dev, "Not enough bandwidth " 1572 dev_warn(&udev->dev, "Not enough bandwidth "
1545 "for new device state.\n"); 1573 "for new device state.\n");
1546 ret = -ENOSPC; 1574 ret = -ENOSPC;
@@ -1758,8 +1786,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1758 /* Enqueue pointer can be left pointing to the link TRB, 1786 /* Enqueue pointer can be left pointing to the link TRB,
1759 * we must handle that 1787 * we must handle that
1760 */ 1788 */
1761 if ((le32_to_cpu(command->command_trb->link.control) 1789 if (TRB_TYPE_LINK_LE32(command->command_trb->link.control))
1762 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1763 command->command_trb = 1790 command->command_trb =
1764 xhci->cmd_ring->enq_seg->next->trbs; 1791 xhci->cmd_ring->enq_seg->next->trbs;
1765 1792
@@ -1864,6 +1891,12 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1864 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); 1891 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
1865 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); 1892 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG);
1866 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); 1893 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG));
1894
1895 /* Don't issue the command if there's no endpoints to update. */
1896 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) &&
1897 ctrl_ctx->drop_flags == 0)
1898 return 0;
1899
1867 xhci_dbg(xhci, "New Input Control Context:\n"); 1900 xhci_dbg(xhci, "New Input Control Context:\n");
1868 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 1901 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
1869 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 1902 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
@@ -2150,8 +2183,7 @@ static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci,
2150 if (ret < 0) 2183 if (ret < 0)
2151 return ret; 2184 return ret;
2152 2185
2153 max_streams = USB_SS_MAX_STREAMS( 2186 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp);
2154 eps[i]->ss_ep_comp.bmAttributes);
2155 if (max_streams < (*num_streams - 1)) { 2187 if (max_streams < (*num_streams - 1)) {
2156 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", 2188 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n",
2157 eps[i]->desc.bEndpointAddress, 2189 eps[i]->desc.bEndpointAddress,
@@ -2559,8 +2591,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
2559 /* Enqueue pointer can be left pointing to the link TRB, 2591 /* Enqueue pointer can be left pointing to the link TRB,
2560 * we must handle that 2592 * we must handle that
2561 */ 2593 */
2562 if ((le32_to_cpu(reset_device_cmd->command_trb->link.control) 2594 if (TRB_TYPE_LINK_LE32(reset_device_cmd->command_trb->link.control))
2563 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
2564 reset_device_cmd->command_trb = 2595 reset_device_cmd->command_trb =
2565 xhci->cmd_ring->enq_seg->next->trbs; 2596 xhci->cmd_ring->enq_seg->next->trbs;
2566 2597
@@ -2667,7 +2698,10 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
2667 int i, ret; 2698 int i, ret;
2668 2699
2669 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); 2700 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
2670 if (ret <= 0) 2701 /* If the host is halted due to driver unload, we still need to free the
2702 * device.
2703 */
2704 if (ret <= 0 && ret != -ENODEV)
2671 return; 2705 return;
2672 2706
2673 virt_dev = xhci->devs[udev->slot_id]; 2707 virt_dev = xhci->devs[udev->slot_id];
@@ -2681,7 +2715,8 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
2681 spin_lock_irqsave(&xhci->lock, flags); 2715 spin_lock_irqsave(&xhci->lock, flags);
2682 /* Don't disable the slot if the host controller is dead. */ 2716 /* Don't disable the slot if the host controller is dead. */
2683 state = xhci_readl(xhci, &xhci->op_regs->status); 2717 state = xhci_readl(xhci, &xhci->op_regs->status);
2684 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) { 2718 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
2719 (xhci->xhc_state & XHCI_STATE_HALTED)) {
2685 xhci_free_virt_device(xhci, udev->slot_id); 2720 xhci_free_virt_device(xhci, udev->slot_id);
2686 spin_unlock_irqrestore(&xhci->lock, flags); 2721 spin_unlock_irqrestore(&xhci->lock, flags);
2687 return; 2722 return;
@@ -2840,6 +2875,10 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2840 /* Otherwise, update the control endpoint ring enqueue pointer. */ 2875 /* Otherwise, update the control endpoint ring enqueue pointer. */
2841 else 2876 else
2842 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); 2877 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev);
2878 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
2879 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
2880 ctrl_ctx->drop_flags = 0;
2881
2843 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 2882 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
2844 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); 2883 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
2845 2884
@@ -2921,7 +2960,6 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2921 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) 2960 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
2922 + 1; 2961 + 1;
2923 /* Zero the input context control for later use */ 2962 /* Zero the input context control for later use */
2924 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
2925 ctrl_ctx->add_flags = 0; 2963 ctrl_ctx->add_flags = 0;
2926 ctrl_ctx->drop_flags = 0; 2964 ctrl_ctx->drop_flags = 0;
2927 2965