aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2009-10-27 13:57:01 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:55:17 -0500
commit6f5165cf989387e84ef23122330b27cca1cbe831 (patch)
tree44ff1ea0590b00f2851f50ffa2cf9954eb70a767 /drivers/usb/host
parent4f0f0baef017dfd5d62b749716ab980a825e1071 (diff)
USB: xhci: Add watchdog timer for URB cancellation.
In order to giveback a canceled URB, we must ensure that the xHCI hardware will not access the buffer in an URB. We can't modify the buffer pointers on endpoint rings without issuing and waiting for a stop endpoint command. Since URBs can be canceled in interrupt context, we can't wait on that command. The old code trusted that the host controller would respond to the command, and would giveback the URBs in the event handler. If the hardware never responds to the stop endpoint command, the URBs will never be completed, and we might hang the USB subsystem. Implement a watchdog timer that is spawned whenever a stop endpoint command is queued. If a stop endpoint command event is found on the event ring during an interrupt, we need to stop the watchdog timer with del_timer(). Since del_timer() can fail if the timer is running and waiting on the xHCI lock, we need a way to signal to the timer that everything is fine and it should exit. If we simply clear EP_HALT_PENDING, a new stop endpoint command could sneak in and set it before the watchdog timer can grab the lock. Instead we use a combination of the EP_HALT_PENDING flag and a counter for the number of pending stop endpoint commands (xhci_virt_ep->stop_cmds_pending). If we need to cancel the watchdog timer and del_timer() succeeds, we decrement the number of pending stop endpoint commands. If del_timer() fails, we leave the number of pending stop endpoint commands alone. In either case, we clear the EP_HALT_PENDING flag. The timer will decrement the number of pending stop endpoint commands once it obtains the lock. If the timer is the tail end of the last stop endpoint command (xhci_virt_ep->stop_cmds_pending == 0), and the endpoint's command is still pending (EP_HALT_PENDING is set), we assume the host is dying. The watchdog timer will set XHCI_STATE_DYING, try to halt the xHCI host, and give back all pending URBs. Various other places in the driver need to check whether the xHCI host is dying. If the interrupt handler ever notices, it should immediately stop processing events. The URB enqueue function should also return -ESHUTDOWN. The URB dequeue function should simply return the value of usb_hcd_check_unlink_urb() and the watchdog timer will take care of giving the URB back. When a device is disconnected, the xHCI hardware structures should be freed without issuing a disable slot command (since the hardware probably won't respond to it anyway). The debugging polling loop should stop polling if the host is dying. When a device is disconnected, any pending watchdog timers are killed with del_timer_sync(). It must be synchronous so that the watchdog timer doesn't attempt to access the freed endpoint structures. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/xhci-hcd.c52
-rw-r--r--drivers/usb/host/xhci-mem.c15
-rw-r--r--drivers/usb/host/xhci-ring.c170
-rw-r--r--drivers/usb/host/xhci.h22
4 files changed, 243 insertions, 16 deletions
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
index 5839453d342b..0d5a8564ed17 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci-hcd.c
@@ -246,8 +246,14 @@ static void xhci_work(struct xhci_hcd *xhci)
246 /* Flush posted writes */ 246 /* Flush posted writes */
247 xhci_readl(xhci, &xhci->ir_set->irq_pending); 247 xhci_readl(xhci, &xhci->ir_set->irq_pending);
248 248
249 /* FIXME this should be a delayed service routine that clears the EHB */ 249 if (xhci->xhc_state & XHCI_STATE_DYING)
250 xhci_handle_event(xhci); 250 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
251 "Shouldn't IRQs be disabled?\n");
252 else
253 /* FIXME this should be a delayed service routine
254 * that clears the EHB.
255 */
256 xhci_handle_event(xhci);
251 257
252 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */ 258 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */
253 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 259 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
@@ -320,7 +326,7 @@ void xhci_event_ring_work(unsigned long arg)
320 spin_lock_irqsave(&xhci->lock, flags); 326 spin_lock_irqsave(&xhci->lock, flags);
321 temp = xhci_readl(xhci, &xhci->op_regs->status); 327 temp = xhci_readl(xhci, &xhci->op_regs->status);
322 xhci_dbg(xhci, "op reg status = 0x%x\n", temp); 328 xhci_dbg(xhci, "op reg status = 0x%x\n", temp);
323 if (temp == 0xffffffff) { 329 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) {
324 xhci_dbg(xhci, "HW died, polling stopped.\n"); 330 xhci_dbg(xhci, "HW died, polling stopped.\n");
325 spin_unlock_irqrestore(&xhci->lock, flags); 331 spin_unlock_irqrestore(&xhci->lock, flags);
326 return; 332 return;
@@ -710,16 +716,22 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
710 * atomic context to this function, which may allocate memory. 716 * atomic context to this function, which may allocate memory.
711 */ 717 */
712 spin_lock_irqsave(&xhci->lock, flags); 718 spin_lock_irqsave(&xhci->lock, flags);
719 if (xhci->xhc_state & XHCI_STATE_DYING)
720 goto dying;
713 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, 721 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
714 slot_id, ep_index); 722 slot_id, ep_index);
715 spin_unlock_irqrestore(&xhci->lock, flags); 723 spin_unlock_irqrestore(&xhci->lock, flags);
716 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { 724 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
717 spin_lock_irqsave(&xhci->lock, flags); 725 spin_lock_irqsave(&xhci->lock, flags);
726 if (xhci->xhc_state & XHCI_STATE_DYING)
727 goto dying;
718 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 728 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
719 slot_id, ep_index); 729 slot_id, ep_index);
720 spin_unlock_irqrestore(&xhci->lock, flags); 730 spin_unlock_irqrestore(&xhci->lock, flags);
721 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { 731 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
722 spin_lock_irqsave(&xhci->lock, flags); 732 spin_lock_irqsave(&xhci->lock, flags);
733 if (xhci->xhc_state & XHCI_STATE_DYING)
734 goto dying;
723 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, 735 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
724 slot_id, ep_index); 736 slot_id, ep_index);
725 spin_unlock_irqrestore(&xhci->lock, flags); 737 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -728,6 +740,12 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
728 } 740 }
729exit: 741exit:
730 return ret; 742 return ret;
743dying:
744 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
745 "non-responsive xHCI host.\n",
746 urb->ep->desc.bEndpointAddress, urb);
747 spin_unlock_irqrestore(&xhci->lock, flags);
748 return -ESHUTDOWN;
731} 749}
732 750
733/* 751/*
@@ -789,6 +807,17 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
789 kfree(td); 807 kfree(td);
790 return ret; 808 return ret;
791 } 809 }
810 if (xhci->xhc_state & XHCI_STATE_DYING) {
811 xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on "
812 "non-responsive xHCI host.\n",
813 urb->ep->desc.bEndpointAddress, urb);
814 /* Let the stop endpoint command watchdog timer (which set this
815 * state) finish cleaning up the endpoint TD lists. We must
816 * have caught it in the middle of dropping a lock and giving
817 * back an URB.
818 */
819 goto done;
820 }
792 821
793 xhci_dbg(xhci, "Cancel URB %p\n", urb); 822 xhci_dbg(xhci, "Cancel URB %p\n", urb);
794 xhci_dbg(xhci, "Event ring:\n"); 823 xhci_dbg(xhci, "Event ring:\n");
@@ -806,6 +835,10 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
806 */ 835 */
807 if (!(ep->ep_state & EP_HALT_PENDING)) { 836 if (!(ep->ep_state & EP_HALT_PENDING)) {
808 ep->ep_state |= EP_HALT_PENDING; 837 ep->ep_state |= EP_HALT_PENDING;
838 ep->stop_cmds_pending++;
839 ep->stop_cmd_timer.expires = jiffies +
840 XHCI_STOP_EP_CMD_TIMEOUT * HZ;
841 add_timer(&ep->stop_cmd_timer);
809 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); 842 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index);
810 xhci_ring_cmd_db(xhci); 843 xhci_ring_cmd_db(xhci);
811 } 844 }
@@ -1410,16 +1443,27 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1410void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) 1443void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
1411{ 1444{
1412 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1445 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1446 struct xhci_virt_device *virt_dev;
1413 unsigned long flags; 1447 unsigned long flags;
1414 u32 state; 1448 u32 state;
1449 int i;
1415 1450
1416 if (udev->slot_id == 0) 1451 if (udev->slot_id == 0)
1417 return; 1452 return;
1453 virt_dev = xhci->devs[udev->slot_id];
1454 if (!virt_dev)
1455 return;
1456
1457 /* Stop any wayward timer functions (which may grab the lock) */
1458 for (i = 0; i < 31; ++i) {
1459 virt_dev->eps[i].ep_state &= ~EP_HALT_PENDING;
1460 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
1461 }
1418 1462
1419 spin_lock_irqsave(&xhci->lock, flags); 1463 spin_lock_irqsave(&xhci->lock, flags);
1420 /* Don't disable the slot if the host controller is dead. */ 1464 /* Don't disable the slot if the host controller is dead. */
1421 state = xhci_readl(xhci, &xhci->op_regs->status); 1465 state = xhci_readl(xhci, &xhci->op_regs->status);
1422 if (state == 0xffffffff) { 1466 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) {
1423 xhci_free_virt_device(xhci, udev->slot_id); 1467 xhci_free_virt_device(xhci, udev->slot_id);
1424 spin_unlock_irqrestore(&xhci->lock, flags); 1468 spin_unlock_irqrestore(&xhci->lock, flags);
1425 return; 1469 return;
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index b8fd270a8b0d..fd05247b7bb1 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -248,6 +248,15 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
248 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); 248 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
249} 249}
250 250
251static void xhci_init_endpoint_timer(struct xhci_hcd *xhci,
252 struct xhci_virt_ep *ep)
253{
254 init_timer(&ep->stop_cmd_timer);
255 ep->stop_cmd_timer.data = (unsigned long) ep;
256 ep->stop_cmd_timer.function = xhci_stop_endpoint_command_watchdog;
257 ep->xhci = xhci;
258}
259
251/* All the xhci_tds in the ring's TD list should be freed at this point */ 260/* All the xhci_tds in the ring's TD list should be freed at this point */
252void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) 261void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
253{ 262{
@@ -309,9 +318,11 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
309 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, 318 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id,
310 (unsigned long long)dev->in_ctx->dma); 319 (unsigned long long)dev->in_ctx->dma);
311 320
312 /* Initialize the cancellation list for each endpoint */ 321 /* Initialize the cancellation list and watchdog timers for each ep */
313 for (i = 0; i < 31; i++) 322 for (i = 0; i < 31; i++) {
323 xhci_init_endpoint_timer(xhci, &dev->eps[i]);
314 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); 324 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list);
325 }
315 326
316 /* Allocate endpoint 0 ring */ 327 /* Allocate endpoint 0 ring */
317 dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); 328 dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 184e8b6f30b2..9541e88df68f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -475,6 +475,35 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
475 ep->ep_state |= SET_DEQ_PENDING; 475 ep->ep_state |= SET_DEQ_PENDING;
476} 476}
477 477
478static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
479 struct xhci_virt_ep *ep)
480{
481 ep->ep_state &= ~EP_HALT_PENDING;
482 /* Can't del_timer_sync in interrupt, so we attempt to cancel. If the
483 * timer is running on another CPU, we don't decrement stop_cmds_pending
484 * (since we didn't successfully stop the watchdog timer).
485 */
486 if (del_timer(&ep->stop_cmd_timer))
487 ep->stop_cmds_pending--;
488}
489
490/* Must be called with xhci->lock held in interrupt context */
491static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
492 struct xhci_td *cur_td, int status, char *adjective)
493{
494 struct usb_hcd *hcd = xhci_to_hcd(xhci);
495
496 cur_td->urb->hcpriv = NULL;
497 usb_hcd_unlink_urb_from_ep(hcd, cur_td->urb);
498 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, cur_td->urb);
499
500 spin_unlock(&xhci->lock);
501 usb_hcd_giveback_urb(hcd, cur_td->urb, status);
502 kfree(cur_td);
503 spin_lock(&xhci->lock);
504 xhci_dbg(xhci, "%s URB given back\n", adjective);
505}
506
478/* 507/*
479 * When we get a command completion for a Stop Endpoint Command, we need to 508 * When we get a command completion for a Stop Endpoint Command, we need to
480 * unlink any cancelled TDs from the ring. There are two ways to do that: 509 * unlink any cancelled TDs from the ring. There are two ways to do that:
@@ -508,7 +537,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
508 ep_ring = ep->ring; 537 ep_ring = ep->ring;
509 538
510 if (list_empty(&ep->cancelled_td_list)) { 539 if (list_empty(&ep->cancelled_td_list)) {
511 ep->ep_state &= ~EP_HALT_PENDING; 540 xhci_stop_watchdog_timer_in_irq(xhci, ep);
512 ring_ep_doorbell(xhci, slot_id, ep_index); 541 ring_ep_doorbell(xhci, slot_id, ep_index);
513 return; 542 return;
514 } 543 }
@@ -540,7 +569,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
540 list_del(&cur_td->td_list); 569 list_del(&cur_td->td_list);
541 } 570 }
542 last_unlinked_td = cur_td; 571 last_unlinked_td = cur_td;
543 ep->ep_state &= ~EP_HALT_PENDING; 572 xhci_stop_watchdog_timer_in_irq(xhci, ep);
544 573
545 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ 574 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */
546 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { 575 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
@@ -568,23 +597,136 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
568 hcd_stat_update(xhci->tp_stat, cur_td->urb->actual_length, 597 hcd_stat_update(xhci->tp_stat, cur_td->urb->actual_length,
569 ktime_sub(stop_time, cur_td->start_time)); 598 ktime_sub(stop_time, cur_td->start_time));
570#endif 599#endif
571 cur_td->urb->hcpriv = NULL;
572 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), cur_td->urb);
573
574 xhci_dbg(xhci, "Giveback cancelled URB %p\n", cur_td->urb);
575 spin_unlock(&xhci->lock);
576 /* Doesn't matter what we pass for status, since the core will 600 /* Doesn't matter what we pass for status, since the core will
577 * just overwrite it (because the URB has been unlinked). 601 * just overwrite it (because the URB has been unlinked).
578 */ 602 */
579 usb_hcd_giveback_urb(xhci_to_hcd(xhci), cur_td->urb, 0); 603 xhci_giveback_urb_in_irq(xhci, cur_td, 0, "cancelled");
580 kfree(cur_td);
581 604
582 spin_lock(&xhci->lock); 605 /* Stop processing the cancelled list if the watchdog timer is
606 * running.
607 */
608 if (xhci->xhc_state & XHCI_STATE_DYING)
609 return;
583 } while (cur_td != last_unlinked_td); 610 } while (cur_td != last_unlinked_td);
584 611
585 /* Return to the event handler with xhci->lock re-acquired */ 612 /* Return to the event handler with xhci->lock re-acquired */
586} 613}
587 614
615/* Watchdog timer function for when a stop endpoint command fails to complete.
616 * In this case, we assume the host controller is broken or dying or dead. The
617 * host may still be completing some other events, so we have to be careful to
618 * let the event ring handler and the URB dequeueing/enqueueing functions know
619 * through xhci->state.
620 *
621 * The timer may also fire if the host takes a very long time to respond to the
622 * command, and the stop endpoint command completion handler cannot delete the
623 * timer before the timer function is called. Another endpoint cancellation may
624 * sneak in before the timer function can grab the lock, and that may queue
625 * another stop endpoint command and add the timer back. So we cannot use a
626 * simple flag to say whether there is a pending stop endpoint command for a
627 * particular endpoint.
628 *
629 * Instead we use a combination of that flag and a counter for the number of
630 * pending stop endpoint commands. If the timer is the tail end of the last
631 * stop endpoint command, and the endpoint's command is still pending, we assume
632 * the host is dying.
633 */
634void xhci_stop_endpoint_command_watchdog(unsigned long arg)
635{
636 struct xhci_hcd *xhci;
637 struct xhci_virt_ep *ep;
638 struct xhci_virt_ep *temp_ep;
639 struct xhci_ring *ring;
640 struct xhci_td *cur_td;
641 int ret, i, j;
642
643 ep = (struct xhci_virt_ep *) arg;
644 xhci = ep->xhci;
645
646 spin_lock(&xhci->lock);
647
648 ep->stop_cmds_pending--;
649 if (xhci->xhc_state & XHCI_STATE_DYING) {
650 xhci_dbg(xhci, "Stop EP timer ran, but another timer marked "
651 "xHCI as DYING, exiting.\n");
652 spin_unlock(&xhci->lock);
653 return;
654 }
655 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
656 xhci_dbg(xhci, "Stop EP timer ran, but no command pending, "
657 "exiting.\n");
658 spin_unlock(&xhci->lock);
659 return;
660 }
661
662 xhci_warn(xhci, "xHCI host not responding to stop endpoint command.\n");
663 xhci_warn(xhci, "Assuming host is dying, halting host.\n");
664 /* Oops, HC is dead or dying or at least not responding to the stop
665 * endpoint command.
666 */
667 xhci->xhc_state |= XHCI_STATE_DYING;
668 /* Disable interrupts from the host controller and start halting it */
669 xhci_quiesce(xhci);
670 spin_unlock(&xhci->lock);
671
672 ret = xhci_halt(xhci);
673
674 spin_lock(&xhci->lock);
675 if (ret < 0) {
676 /* This is bad; the host is not responding to commands and it's
677 * not allowing itself to be halted. At least interrupts are
678 * disabled, so we can set HC_STATE_HALT and notify the
679 * USB core. But if we call usb_hc_died(), it will attempt to
680 * disconnect all device drivers under this host. Those
681 * disconnect() methods will wait for all URBs to be unlinked,
682 * so we must complete them.
683 */
684 xhci_warn(xhci, "Non-responsive xHCI host is not halting.\n");
685 xhci_warn(xhci, "Completing active URBs anyway.\n");
686 /* We could turn all TDs on the rings to no-ops. This won't
687 * help if the host has cached part of the ring, and is slow if
688 * we want to preserve the cycle bit. Skip it and hope the host
689 * doesn't touch the memory.
690 */
691 }
692 for (i = 0; i < MAX_HC_SLOTS; i++) {
693 if (!xhci->devs[i])
694 continue;
695 for (j = 0; j < 31; j++) {
696 temp_ep = &xhci->devs[i]->eps[j];
697 ring = temp_ep->ring;
698 if (!ring)
699 continue;
700 xhci_dbg(xhci, "Killing URBs for slot ID %u, "
701 "ep index %u\n", i, j);
702 while (!list_empty(&ring->td_list)) {
703 cur_td = list_first_entry(&ring->td_list,
704 struct xhci_td,
705 td_list);
706 list_del(&cur_td->td_list);
707 if (!list_empty(&cur_td->cancelled_td_list))
708 list_del(&cur_td->cancelled_td_list);
709 xhci_giveback_urb_in_irq(xhci, cur_td,
710 -ESHUTDOWN, "killed");
711 }
712 while (!list_empty(&temp_ep->cancelled_td_list)) {
713 cur_td = list_first_entry(
714 &temp_ep->cancelled_td_list,
715 struct xhci_td,
716 cancelled_td_list);
717 list_del(&cur_td->cancelled_td_list);
718 xhci_giveback_urb_in_irq(xhci, cur_td,
719 -ESHUTDOWN, "killed");
720 }
721 }
722 }
723 spin_unlock(&xhci->lock);
724 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
725 xhci_dbg(xhci, "Calling usb_hc_died()\n");
726 usb_hc_died(xhci_to_hcd(xhci));
727 xhci_dbg(xhci, "xHCI host controller is dead.\n");
728}
729
588/* 730/*
589 * When we get a completion for a Set Transfer Ring Dequeue Pointer command, 731 * When we get a completion for a Set Transfer Ring Dequeue Pointer command,
590 * we need to clear the set deq pending flag in the endpoint ring state, so that 732 * we need to clear the set deq pending flag in the endpoint ring state, so that
@@ -1333,6 +1475,14 @@ void xhci_handle_event(struct xhci_hcd *xhci)
1333 default: 1475 default:
1334 xhci->error_bitmask |= 1 << 3; 1476 xhci->error_bitmask |= 1 << 3;
1335 } 1477 }
1478 /* Any of the above functions may drop and re-acquire the lock, so check
1479 * to make sure a watchdog timer didn't mark the host as non-responsive.
1480 */
1481 if (xhci->xhc_state & XHCI_STATE_DYING) {
1482 xhci_dbg(xhci, "xHCI host dying, returning from "
1483 "event handler.\n");
1484 return;
1485 }
1336 1486
1337 if (update_ptrs) { 1487 if (update_ptrs) {
1338 /* Update SW and HC event ring dequeue pointer */ 1488 /* Update SW and HC event ring dequeue pointer */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index af3c5638526c..c92f84154fb5 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -659,6 +659,10 @@ struct xhci_virt_ep {
659 /* The TRB that was last reported in a stopped endpoint ring */ 659 /* The TRB that was last reported in a stopped endpoint ring */
660 union xhci_trb *stopped_trb; 660 union xhci_trb *stopped_trb;
661 struct xhci_td *stopped_td; 661 struct xhci_td *stopped_td;
662 /* Watchdog timer for stop endpoint command to cancel URBs */
663 struct timer_list stop_cmd_timer;
664 int stop_cmds_pending;
665 struct xhci_hcd *xhci;
662}; 666};
663 667
664struct xhci_virt_device { 668struct xhci_virt_device {
@@ -1022,6 +1026,8 @@ struct xhci_scratchpad {
1022#define ERST_ENTRIES 1 1026#define ERST_ENTRIES 1
1023/* Poll every 60 seconds */ 1027/* Poll every 60 seconds */
1024#define POLL_TIMEOUT 60 1028#define POLL_TIMEOUT 60
1029/* Stop endpoint command timeout (secs) for URB cancellation watchdog timer */
1030#define XHCI_STOP_EP_CMD_TIMEOUT 5
1025/* XXX: Make these module parameters */ 1031/* XXX: Make these module parameters */
1026 1032
1027 1033
@@ -1083,6 +1089,21 @@ struct xhci_hcd {
1083 struct timer_list event_ring_timer; 1089 struct timer_list event_ring_timer;
1084 int zombie; 1090 int zombie;
1085#endif 1091#endif
1092 /* Host controller watchdog timer structures */
1093 unsigned int xhc_state;
1094/* Host controller is dying - not responding to commands. "I'm not dead yet!"
1095 *
1096 * xHC interrupts have been disabled and a watchdog timer will (or has already)
1097 * halt the xHCI host, and complete all URBs with an -ESHUTDOWN code. Any code
1098 * that sees this status (other than the timer that set it) should stop touching
1099 * hardware immediately. Interrupt handlers should return immediately when
1100 * they see this status (any time they drop and re-acquire xhci->lock).
1101 * xhci_urb_dequeue() should call usb_hcd_check_unlink_urb() and return without
1102 * putting the TD on the canceled list, etc.
1103 *
1104 * There are no reports of xHCI host controllers that display this issue.
1105 */
1106#define XHCI_STATE_DYING (1 << 0)
1086 /* Statistics */ 1107 /* Statistics */
1087 int noops_submitted; 1108 int noops_submitted;
1088 int noops_handled; 1109 int noops_handled;
@@ -1279,6 +1300,7 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1279void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, 1300void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1280 unsigned int slot_id, unsigned int ep_index, 1301 unsigned int slot_id, unsigned int ep_index,
1281 struct xhci_dequeue_state *deq_state); 1302 struct xhci_dequeue_state *deq_state);
1303void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1282 1304
1283/* xHCI roothub code */ 1305/* xHCI roothub code */
1284int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1306int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,