diff options
Diffstat (limited to 'drivers/usb/host/xhci.c')
-rw-r--r-- | drivers/usb/host/xhci.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 763f484bc092..3a0f695138f4 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; |
@@ -939,8 +940,11 @@ static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, | |||
939 | return 0; | 940 | return 0; |
940 | } | 941 | } |
941 | 942 | ||
943 | xhci = hcd_to_xhci(hcd); | ||
944 | if (xhci->xhc_state & XHCI_STATE_HALTED) | ||
945 | return -ENODEV; | ||
946 | |||
942 | if (check_virt_dev) { | 947 | if (check_virt_dev) { |
943 | xhci = hcd_to_xhci(hcd); | ||
944 | if (!udev->slot_id || !xhci->devs | 948 | if (!udev->slot_id || !xhci->devs |
945 | || !xhci->devs[udev->slot_id]) { | 949 | || !xhci->devs[udev->slot_id]) { |
946 | printk(KERN_DEBUG "xHCI %s called with unaddressed " | 950 | printk(KERN_DEBUG "xHCI %s called with unaddressed " |
@@ -1081,8 +1085,11 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
1081 | if (urb->dev->speed == USB_SPEED_FULL) { | 1085 | if (urb->dev->speed == USB_SPEED_FULL) { |
1082 | ret = xhci_check_maxpacket(xhci, slot_id, | 1086 | ret = xhci_check_maxpacket(xhci, slot_id, |
1083 | ep_index, urb); | 1087 | ep_index, urb); |
1084 | if (ret < 0) | 1088 | if (ret < 0) { |
1089 | xhci_urb_free_priv(xhci, urb_priv); | ||
1090 | urb->hcpriv = NULL; | ||
1085 | return ret; | 1091 | return ret; |
1092 | } | ||
1086 | } | 1093 | } |
1087 | 1094 | ||
1088 | /* We have a spinlock and interrupts disabled, so we must pass | 1095 | /* We have a spinlock and interrupts disabled, so we must pass |
@@ -1093,6 +1100,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
1093 | goto dying; | 1100 | goto dying; |
1094 | ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, | 1101 | ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, |
1095 | slot_id, ep_index); | 1102 | slot_id, ep_index); |
1103 | if (ret) | ||
1104 | goto free_priv; | ||
1096 | spin_unlock_irqrestore(&xhci->lock, flags); | 1105 | spin_unlock_irqrestore(&xhci->lock, flags); |
1097 | } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { | 1106 | } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { |
1098 | spin_lock_irqsave(&xhci->lock, flags); | 1107 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -1113,6 +1122,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, | 1122 | ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, |
1114 | slot_id, ep_index); | 1123 | slot_id, ep_index); |
1115 | } | 1124 | } |
1125 | if (ret) | ||
1126 | goto free_priv; | ||
1116 | spin_unlock_irqrestore(&xhci->lock, flags); | 1127 | spin_unlock_irqrestore(&xhci->lock, flags); |
1117 | } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { | 1128 | } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { |
1118 | spin_lock_irqsave(&xhci->lock, flags); | 1129 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -1120,6 +1131,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
1120 | goto dying; | 1131 | goto dying; |
1121 | ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, | 1132 | ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, |
1122 | slot_id, ep_index); | 1133 | slot_id, ep_index); |
1134 | if (ret) | ||
1135 | goto free_priv; | ||
1123 | spin_unlock_irqrestore(&xhci->lock, flags); | 1136 | spin_unlock_irqrestore(&xhci->lock, flags); |
1124 | } else { | 1137 | } else { |
1125 | spin_lock_irqsave(&xhci->lock, flags); | 1138 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -1127,18 +1140,22 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
1127 | goto dying; | 1140 | goto dying; |
1128 | ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, | 1141 | ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, |
1129 | slot_id, ep_index); | 1142 | slot_id, ep_index); |
1143 | if (ret) | ||
1144 | goto free_priv; | ||
1130 | spin_unlock_irqrestore(&xhci->lock, flags); | 1145 | spin_unlock_irqrestore(&xhci->lock, flags); |
1131 | } | 1146 | } |
1132 | exit: | 1147 | exit: |
1133 | return ret; | 1148 | return ret; |
1134 | dying: | 1149 | dying: |
1135 | xhci_urb_free_priv(xhci, urb_priv); | ||
1136 | urb->hcpriv = NULL; | ||
1137 | xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " | 1150 | xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " |
1138 | "non-responsive xHCI host.\n", | 1151 | "non-responsive xHCI host.\n", |
1139 | urb->ep->desc.bEndpointAddress, urb); | 1152 | urb->ep->desc.bEndpointAddress, urb); |
1153 | ret = -ESHUTDOWN; | ||
1154 | free_priv: | ||
1155 | xhci_urb_free_priv(xhci, urb_priv); | ||
1156 | urb->hcpriv = NULL; | ||
1140 | spin_unlock_irqrestore(&xhci->lock, flags); | 1157 | spin_unlock_irqrestore(&xhci->lock, flags); |
1141 | return -ESHUTDOWN; | 1158 | return ret; |
1142 | } | 1159 | } |
1143 | 1160 | ||
1144 | /* Get the right ring for the given URB. | 1161 | /* Get the right ring for the given URB. |
@@ -1235,6 +1252,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1235 | if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { | 1252 | if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { |
1236 | xhci_dbg(xhci, "HW died, freeing TD.\n"); | 1253 | xhci_dbg(xhci, "HW died, freeing TD.\n"); |
1237 | urb_priv = urb->hcpriv; | 1254 | urb_priv = urb->hcpriv; |
1255 | for (i = urb_priv->td_cnt; i < urb_priv->length; i++) { | ||
1256 | td = urb_priv->td[i]; | ||
1257 | if (!list_empty(&td->td_list)) | ||
1258 | list_del_init(&td->td_list); | ||
1259 | if (!list_empty(&td->cancelled_td_list)) | ||
1260 | list_del_init(&td->cancelled_td_list); | ||
1261 | } | ||
1238 | 1262 | ||
1239 | usb_hcd_unlink_urb_from_ep(hcd, urb); | 1263 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
1240 | spin_unlock_irqrestore(&xhci->lock, flags); | 1264 | spin_unlock_irqrestore(&xhci->lock, flags); |
@@ -1242,7 +1266,8 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1242 | xhci_urb_free_priv(xhci, urb_priv); | 1266 | xhci_urb_free_priv(xhci, urb_priv); |
1243 | return ret; | 1267 | return ret; |
1244 | } | 1268 | } |
1245 | if (xhci->xhc_state & XHCI_STATE_DYING) { | 1269 | if ((xhci->xhc_state & XHCI_STATE_DYING) || |
1270 | (xhci->xhc_state & XHCI_STATE_HALTED)) { | ||
1246 | xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on " | 1271 | xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on " |
1247 | "non-responsive xHCI host.\n", | 1272 | "non-responsive xHCI host.\n", |
1248 | urb->ep->desc.bEndpointAddress, urb); | 1273 | urb->ep->desc.bEndpointAddress, urb); |
@@ -2665,7 +2690,10 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
2665 | int i, ret; | 2690 | int i, ret; |
2666 | 2691 | ||
2667 | ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); | 2692 | ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); |
2668 | if (ret <= 0) | 2693 | /* If the host is halted due to driver unload, we still need to free the |
2694 | * device. | ||
2695 | */ | ||
2696 | if (ret <= 0 && ret != -ENODEV) | ||
2669 | return; | 2697 | return; |
2670 | 2698 | ||
2671 | virt_dev = xhci->devs[udev->slot_id]; | 2699 | virt_dev = xhci->devs[udev->slot_id]; |
@@ -2679,7 +2707,8 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
2679 | spin_lock_irqsave(&xhci->lock, flags); | 2707 | spin_lock_irqsave(&xhci->lock, flags); |
2680 | /* Don't disable the slot if the host controller is dead. */ | 2708 | /* Don't disable the slot if the host controller is dead. */ |
2681 | state = xhci_readl(xhci, &xhci->op_regs->status); | 2709 | state = xhci_readl(xhci, &xhci->op_regs->status); |
2682 | if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) { | 2710 | if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || |
2711 | (xhci->xhc_state & XHCI_STATE_HALTED)) { | ||
2683 | xhci_free_virt_device(xhci, udev->slot_id); | 2712 | xhci_free_virt_device(xhci, udev->slot_id); |
2684 | spin_unlock_irqrestore(&xhci->lock, flags); | 2713 | spin_unlock_irqrestore(&xhci->lock, flags); |
2685 | return; | 2714 | return; |