aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2014-07-18 16:26:12 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-18 19:34:07 -0400
commit81e38333513cec155c720432226dabe9f9f76a77 (patch)
tree27889eb4e928866b5ea6496dbcdd9abc1c23e9e3
parentcdb4dd15e62eb984d9461b520d15d00ff2b88d9d (diff)
USB: OHCI: add I/O watchdog for orphan TDs
Some OHCI controllers have a bug: They fail to add completed TDs to the done queue. Examining this queue is the only method ohci-hcd has for telling when a transfer is complete; failure to add a TD can result in an URB that never completes and cannot be unlinked. This patch adds a watchdog routine to ohci-hcd. The routine periodically scans the active ED and TD lists, looking for TDs which are finished but not on the done queue. When one is found, and it is certain that the controller hardware will never add the TD to the done queue, the watchdog routine manually puts the TD on the done list so that it can be handled normally. The watchdog routine also checks for a condition indicating the controller has died. If the done queue is non-empty but the HccaDoneHead pointer hasn't been updated for a few hundred milliseconds, we assume the controller will never update it and therefore is dead. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/host/ohci-hcd.c125
-rw-r--r--drivers/usb/host/ohci-hub.c3
-rw-r--r--drivers/usb/host/ohci-mem.c1
-rw-r--r--drivers/usb/host/ohci-q.c6
-rw-r--r--drivers/usb/host/ohci.h13
5 files changed, 148 insertions, 0 deletions
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index ad588538e2e7..aba8f19eae4d 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -72,12 +72,14 @@
72static const char hcd_name [] = "ohci_hcd"; 72static const char hcd_name [] = "ohci_hcd";
73 73
74#define STATECHANGE_DELAY msecs_to_jiffies(300) 74#define STATECHANGE_DELAY msecs_to_jiffies(300)
75#define IO_WATCHDOG_DELAY msecs_to_jiffies(250)
75 76
76#include "ohci.h" 77#include "ohci.h"
77#include "pci-quirks.h" 78#include "pci-quirks.h"
78 79
79static void ohci_dump(struct ohci_hcd *ohci); 80static void ohci_dump(struct ohci_hcd *ohci);
80static void ohci_stop(struct usb_hcd *hcd); 81static void ohci_stop(struct usb_hcd *hcd);
82static void io_watchdog_func(unsigned long _ohci);
81 83
82#include "ohci-hub.c" 84#include "ohci-hub.c"
83#include "ohci-dbg.c" 85#include "ohci-dbg.c"
@@ -225,6 +227,14 @@ static int ohci_urb_enqueue (
225 usb_hcd_unlink_urb_from_ep(hcd, urb); 227 usb_hcd_unlink_urb_from_ep(hcd, urb);
226 goto fail; 228 goto fail;
227 } 229 }
230
231 /* Start up the I/O watchdog timer, if it's not running */
232 if (!timer_pending(&ohci->io_watchdog) &&
233 list_empty(&ohci->eds_in_use))
234 mod_timer(&ohci->io_watchdog,
235 jiffies + IO_WATCHDOG_DELAY);
236 list_add(&ed->in_use_list, &ohci->eds_in_use);
237
228 if (ed->type == PIPE_ISOCHRONOUS) { 238 if (ed->type == PIPE_ISOCHRONOUS) {
229 u16 frame = ohci_frame_no(ohci); 239 u16 frame = ohci_frame_no(ohci);
230 240
@@ -416,6 +426,7 @@ ohci_shutdown (struct usb_hcd *hcd)
416 udelay(10); 426 udelay(10);
417 427
418 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); 428 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
429 ohci->rh_state = OHCI_RH_HALTED;
419} 430}
420 431
421/*-------------------------------------------------------------------------* 432/*-------------------------------------------------------------------------*
@@ -484,6 +495,10 @@ static int ohci_init (struct ohci_hcd *ohci)
484 if (ohci->hcca) 495 if (ohci->hcca)
485 return 0; 496 return 0;
486 497
498 setup_timer(&ohci->io_watchdog, io_watchdog_func,
499 (unsigned long) ohci);
500 set_timer_slack(&ohci->io_watchdog, msecs_to_jiffies(20));
501
487 ohci->hcca = dma_alloc_coherent (hcd->self.controller, 502 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
488 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL); 503 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
489 if (!ohci->hcca) 504 if (!ohci->hcca)
@@ -694,6 +709,112 @@ static int ohci_start(struct usb_hcd *hcd)
694 709
695/*-------------------------------------------------------------------------*/ 710/*-------------------------------------------------------------------------*/
696 711
712/*
713 * Some OHCI controllers are known to lose track of completed TDs. They
714 * don't add the TDs to the hardware done queue, which means we never see
715 * them as being completed.
716 *
717 * This watchdog routine checks for such problems. Without some way to
718 * tell when those TDs have completed, we would never take their EDs off
719 * the unlink list. As a result, URBs could never be dequeued and
720 * endpoints could never be released.
721 */
722static void io_watchdog_func(unsigned long _ohci)
723{
724 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
725 bool takeback_all_pending = false;
726 u32 status;
727 u32 head;
728 struct ed *ed;
729 struct td *td, *td_start, *td_next;
730 unsigned long flags;
731
732 spin_lock_irqsave(&ohci->lock, flags);
733
734 /*
735 * One way to lose track of completed TDs is if the controller
736 * never writes back the done queue head. If it hasn't been
737 * written back since the last time this function ran and if it
738 * was non-empty at that time, something is badly wrong with the
739 * hardware.
740 */
741 status = ohci_readl(ohci, &ohci->regs->intrstatus);
742 if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
743 if (ohci->prev_donehead) {
744 ohci_err(ohci, "HcDoneHead not written back; disabled\n");
745 usb_hc_died(ohci_to_hcd(ohci));
746 ohci_dump(ohci);
747 ohci_shutdown(ohci_to_hcd(ohci));
748 goto done;
749 } else {
750 /* No write back because the done queue was empty */
751 takeback_all_pending = true;
752 }
753 }
754
755 /* Check every ED which might have pending TDs */
756 list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
757 if (ed->pending_td) {
758 if (takeback_all_pending ||
759 OKAY_TO_TAKEBACK(ohci, ed)) {
760 unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
761
762 ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
763 0x007f & tmp,
764 (0x000f & (tmp >> 7)) +
765 ((tmp & ED_IN) >> 5));
766 add_to_done_list(ohci, ed->pending_td);
767 }
768 }
769
770 /* Starting from the latest pending TD, */
771 td = ed->pending_td;
772
773 /* or the last TD on the done list, */
774 if (!td) {
775 list_for_each_entry(td_next, &ed->td_list, td_list) {
776 if (!td_next->next_dl_td)
777 break;
778 td = td_next;
779 }
780 }
781
782 /* find the last TD processed by the controller. */
783 head = hc32_to_cpu(ohci, ACCESS_ONCE(ed->hwHeadP)) & TD_MASK;
784 td_start = td;
785 td_next = list_prepare_entry(td, &ed->td_list, td_list);
786 list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
787 if (head == (u32) td_next->td_dma)
788 break;
789 td = td_next; /* head pointer has passed this TD */
790 }
791 if (td != td_start) {
792 /*
793 * In case a WDH cycle is in progress, we will wait
794 * for the next two cycles to complete before assuming
795 * this TD will never get on the done queue.
796 */
797 ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
798 ed->pending_td = td;
799 }
800 }
801
802 ohci_work(ohci);
803
804 if (ohci->rh_state == OHCI_RH_RUNNING) {
805 if (!list_empty(&ohci->eds_in_use)) {
806 ohci->prev_wdh_cnt = ohci->wdh_cnt;
807 ohci->prev_donehead = ohci_readl(ohci,
808 &ohci->regs->donehead);
809 mod_timer(&ohci->io_watchdog,
810 jiffies + IO_WATCHDOG_DELAY);
811 }
812 }
813
814 done:
815 spin_unlock_irqrestore(&ohci->lock, flags);
816}
817
697/* an interrupt happens */ 818/* an interrupt happens */
698 819
699static irqreturn_t ohci_irq (struct usb_hcd *hcd) 820static irqreturn_t ohci_irq (struct usb_hcd *hcd)
@@ -796,6 +917,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
796 917
797 if (ohci->rh_state == OHCI_RH_RUNNING) { 918 if (ohci->rh_state == OHCI_RH_RUNNING) {
798 ohci_writel (ohci, ints, &regs->intrstatus); 919 ohci_writel (ohci, ints, &regs->intrstatus);
920 if (ints & OHCI_INTR_WDH)
921 ++ohci->wdh_cnt;
922
799 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable); 923 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
800 // flush those writes 924 // flush those writes
801 (void) ohci_readl (ohci, &ohci->regs->control); 925 (void) ohci_readl (ohci, &ohci->regs->control);
@@ -815,6 +939,7 @@ static void ohci_stop (struct usb_hcd *hcd)
815 939
816 if (quirk_nec(ohci)) 940 if (quirk_nec(ohci))
817 flush_work(&ohci->nec_work); 941 flush_work(&ohci->nec_work);
942 del_timer_sync(&ohci->io_watchdog);
818 943
819 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 944 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
820 ohci_usb_reset(ohci); 945 ohci_usb_reset(ohci);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 8991692bcfb8..17d32b0ea565 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -309,6 +309,9 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
309 else 309 else
310 rc = ohci_rh_suspend (ohci, 0); 310 rc = ohci_rh_suspend (ohci, 0);
311 spin_unlock_irq (&ohci->lock); 311 spin_unlock_irq (&ohci->lock);
312
313 if (rc == 0)
314 del_timer_sync(&ohci->io_watchdog);
312 return rc; 315 return rc;
313} 316}
314 317
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index 2f20d3dc895b..c9e315c6808a 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
28 ohci->next_statechange = jiffies; 28 ohci->next_statechange = jiffies;
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_LIST_HEAD(&ohci->eds_in_use);
31} 32}
32 33
33/*-------------------------------------------------------------------------*/ 34/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 1974ddc68e45..1463c398d322 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -921,6 +921,11 @@ static void add_to_done_list(struct ohci_hcd *ohci, struct td *td)
921 * that td is on the done list. 921 * that td is on the done list.
922 */ 922 */
923 ohci->dl_end = td->next_dl_td = td; 923 ohci->dl_end = td->next_dl_td = td;
924
925 /* Did we just add the latest pending TD? */
926 td2 = ed->pending_td;
927 if (td2 && td2->next_dl_td)
928 ed->pending_td = NULL;
924} 929}
925 930
926/* Get the entries on the hardware done queue and put them on our list */ 931/* Get the entries on the hardware done queue and put them on our list */
@@ -1082,6 +1087,7 @@ rescan_this:
1082 if (list_empty(&ed->td_list)) { 1087 if (list_empty(&ed->td_list)) {
1083 *last = ed->ed_next; 1088 *last = ed->ed_next;
1084 ed->ed_next = NULL; 1089 ed->ed_next = NULL;
1090 list_del(&ed->in_use_list);
1085 } else if (ohci->rh_state == OHCI_RH_RUNNING) { 1091 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
1086 *last = ed->ed_next; 1092 *last = ed->ed_next;
1087 ed->ed_next = NULL; 1093 ed->ed_next = NULL;
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index ef348c2e1e4b..0548f5ca18e2 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -47,6 +47,7 @@ struct ed {
47 struct ed *ed_next; /* on schedule or rm_list */ 47 struct ed *ed_next; /* on schedule or rm_list */
48 struct ed *ed_prev; /* for non-interrupt EDs */ 48 struct ed *ed_prev; /* for non-interrupt EDs */
49 struct list_head td_list; /* "shadow list" of our TDs */ 49 struct list_head td_list; /* "shadow list" of our TDs */
50 struct list_head in_use_list;
50 51
51 /* create --> IDLE --> OPER --> ... --> IDLE --> destroy 52 /* create --> IDLE --> OPER --> ... --> IDLE --> destroy
52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... 53 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
@@ -66,6 +67,13 @@ struct ed {
66 67
67 /* HC may see EDs on rm_list until next frame (frame_no == tick) */ 68 /* HC may see EDs on rm_list until next frame (frame_no == tick) */
68 u16 tick; 69 u16 tick;
70
71 /* Detect TDs not added to the done queue */
72 unsigned takeback_wdh_cnt;
73 struct td *pending_td;
74#define OKAY_TO_TAKEBACK(ohci, ed) \
75 ((int) (ohci->wdh_cnt - ed->takeback_wdh_cnt) >= 0)
76
69} __attribute__ ((aligned(16))); 77} __attribute__ ((aligned(16)));
70 78
71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ 79#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
@@ -382,6 +390,7 @@ struct ohci_hcd {
382 struct td *td_hash [TD_HASH_SIZE]; 390 struct td *td_hash [TD_HASH_SIZE];
383 struct td *dl_start, *dl_end; /* the done list */ 391 struct td *dl_start, *dl_end; /* the done list */
384 struct list_head pending; 392 struct list_head pending;
393 struct list_head eds_in_use; /* all EDs with at least 1 TD */
385 394
386 /* 395 /*
387 * driver state 396 * driver state
@@ -412,6 +421,10 @@ struct ohci_hcd {
412 421
413 // there are also chip quirks/bugs in init logic 422 // there are also chip quirks/bugs in init logic
414 423
424 unsigned wdh_cnt, prev_wdh_cnt;
425 u32 prev_donehead;
426 struct timer_list io_watchdog;
427
415 struct work_struct nec_work; /* Worker for NEC quirk */ 428 struct work_struct nec_work; /* Worker for NEC quirk */
416 429
417 struct dentry *debug_dir; 430 struct dentry *debug_dir;