Skip to content

Commit dc7623d

Browse files
AlanSterngregkh
authored andcommitted
EHCI: workaround for MosChip controller bug
commit 68aa95d upstream. This patch (as1489) works around a hardware bug in MosChip EHCI controllers. Evidently when one of these controllers increments the frame-index register, it changes the three low-order bits (the microframe counter) before changing the higher order bits (the frame counter). If the register is read at just the wrong time, the value obtained is too low by 8. When the appropriate quirk flag is set, we work around this problem by reading the frame-index register a second time if the first value's three low-order bits are all 0. This gives the hardware a chance to finish updating the register, yielding the correct value. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Tested-by: Jason N Pitt <jpitt@fhcrc.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent ad758ad commit dc7623d

5 files changed

Lines changed: 49 additions & 8 deletions

File tree

‎drivers/usb/host/ehci-dbg.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
808808
next += temp;
809809

810810
temp = scnprintf (next, size, "uframe %04x\n",
811-
ehci_readl(ehci, &ehci->regs->frame_index));
811+
ehci_read_frame_index(ehci));
812812
size -= temp;
813813
next += temp;
814814

‎drivers/usb/host/ehci-hcd.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
11951195
static int ehci_get_frame (struct usb_hcd *hcd)
11961196
{
11971197
struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1198-
return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
1199-
ehci->periodic_size;
1198+
return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
12001199
}
12011200

12021201
/*-------------------------------------------------------------------------*/

‎drivers/usb/host/ehci-pci.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
224224
pci_dev_put(p_smbus);
225225
}
226226
break;
227+
case PCI_VENDOR_ID_NETMOS:
228+
/* MosChip frame-index-register bug */
229+
ehci_info(ehci, "applying MosChip frame-index workaround\n");
230+
ehci->frame_index_bug = 1;
231+
break;
227232
}
228233

229234
/* optional debug port, normally in the first BAR */

‎drivers/usb/host/ehci-sched.c‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@
3636

3737
static int ehci_get_frame (struct usb_hcd *hcd);
3838

39+
#ifdef CONFIG_PCI
40+
41+
static unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
42+
{
43+
unsigned uf;
44+
45+
/*
46+
* The MosChip MCS9990 controller updates its microframe counter
47+
* a little before the frame counter, and occasionally we will read
48+
* the invalid intermediate value. Avoid problems by checking the
49+
* microframe number (the low-order 3 bits); if they are 0 then
50+
* re-read the register to get the correct value.
51+
*/
52+
uf = ehci_readl(ehci, &ehci->regs->frame_index);
53+
if (unlikely(ehci->frame_index_bug && ((uf & 7) == 0)))
54+
uf = ehci_readl(ehci, &ehci->regs->frame_index);
55+
return uf;
56+
}
57+
58+
#endif
59+
3960
/*-------------------------------------------------------------------------*/
4061

4162
/*
@@ -482,7 +503,7 @@ static int enable_periodic (struct ehci_hcd *ehci)
482503
ehci_to_hcd(ehci)->state = HC_STATE_RUNNING;
483504

484505
/* make sure ehci_work scans these */
485-
ehci->next_uframe = ehci_readl(ehci, &ehci->regs->frame_index)
506+
ehci->next_uframe = ehci_read_frame_index(ehci)
486507
% (ehci->periodic_size << 3);
487508
if (unlikely(ehci->broken_periodic))
488509
ehci->last_periodic_enable = ktime_get_real();
@@ -1409,7 +1430,7 @@ iso_stream_schedule (
14091430
goto fail;
14101431
}
14111432

1412-
now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1);
1433+
now = ehci_read_frame_index(ehci) & (mod - 1);
14131434

14141435
/* Typical case: reuse current schedule, stream is still active.
14151436
* Hopefully there are no gaps from the host falling behind
@@ -2276,7 +2297,7 @@ scan_periodic (struct ehci_hcd *ehci)
22762297
*/
22772298
now_uframe = ehci->next_uframe;
22782299
if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
2279-
clock = ehci_readl(ehci, &ehci->regs->frame_index);
2300+
clock = ehci_read_frame_index(ehci);
22802301
clock_frame = (clock >> 3) & (ehci->periodic_size - 1);
22812302
} else {
22822303
clock = now_uframe + mod - 1;
@@ -2455,8 +2476,7 @@ scan_periodic (struct ehci_hcd *ehci)
24552476
|| ehci->periodic_sched == 0)
24562477
break;
24572478
ehci->next_uframe = now_uframe;
2458-
now = ehci_readl(ehci, &ehci->regs->frame_index) &
2459-
(mod - 1);
2479+
now = ehci_read_frame_index(ehci) & (mod - 1);
24602480
if (now_uframe == now)
24612481
break;
24622482

‎drivers/usb/host/ehci.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct ehci_hcd { /* one per controller */
139139
unsigned fs_i_thresh:1; /* Intel iso scheduling */
140140
unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
141141
unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
142+
unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
142143

143144
/* required for usb32 quirk */
144145
#define OHCI_CTRL_HCFS (3 << 6)
@@ -740,6 +741,22 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
740741

741742
/*-------------------------------------------------------------------------*/
742743

744+
#ifdef CONFIG_PCI
745+
746+
/* For working around the MosChip frame-index-register bug */
747+
static unsigned ehci_read_frame_index(struct ehci_hcd *ehci);
748+
749+
#else
750+
751+
static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
752+
{
753+
return ehci_readl(ehci, &ehci->regs->frame_index);
754+
}
755+
756+
#endif
757+
758+
/*-------------------------------------------------------------------------*/
759+
743760
#ifndef DEBUG
744761
#define STUB_DEBUG_FILES
745762
#endif /* DEBUG */

0 commit comments

Comments
 (0)