Fix NEC OHCI chip silicon bug
Subsystems (2)
PATCH 1/1 Fix NEC OHCI chip silicon bug
This patch fixes a silicon bug in some NEC OHCI chips. The bug appears at random times and is very, very difficult to reproduce. Without the following patch, Linux would shut the chip and its associated devices down. In Apple PowerBooks this leads to an unusable keyboard and mouse (SSH still working). The idea of restarting the chip is taken from public Darwin code.
---
The OHCI driver uses inconsistent code formatting. I tried to stay with the used style where I modified functions while using Doc/CodingStyle for new functions.
drivers/usb/host/ohci.h +2 -0
@@ -397,8 +397,10 @@ struct ohci_hcd {#define OHCI_QUIRK_BE_DESC 0x08/* BE descriptors */ #define OHCI_QUIRK_BE_MMIO 0x10/* BE registers */ #define OHCI_QUIRK_ZFMICRO 0x20/* Compaq ZFMicro chipset*/ +#define OHCI_QUIRK_NEC 0x40/* lost interrupts */ // there are also chip quirks/bugs in init logic +struct work_struct nec_work;/* Worker for NEC quirk */ };/* convert between an hcd pointer and the corresponding ohci_hcd */
drivers/usb/host/ohci-hcd.c +41 -6
85 lines not on this page · raw message
drivers/usb/host/ohci-hub.c +0 -2
@@ -55,8 +55,6 @@ static void dl_done_list (struct ohci_hcstatic void finish_unlinks (struct ohci_hcd *,u16 );#ifdef CONFIG_PM -static int ohci_restart (struct ohci_hcd *ohci); - static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) __releases(ohci->lock) __acquires(ohci->lock)
drivers/usb/host/ohci-mem.c +1 -0
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_h ohci->next_statechange = jiffies;spin_lock_init (&ohci->lock);INIT_LIST_HEAD (&ohci->pending); +INIT_WORK (&ohci->nec_work, ohci_quirk_nec_worker); }/*-------------------------------------------------------------------------*/
drivers/usb/host/ohci-pci.c +16 -0
@@ -111,6 +111,18 @@ static int ohci_quirk_toshiba_scc(struct#endif } +/* Check for NEC chip and apply quirk for allegedly lost interrupts. +*/ +static int ohci_quirk_nec (struct usb_hcd *hcd) +{ +struct ohci_hcd *ohci =hcd_to_ohci (hcd); + + ohci->flags |=OHCI_QUIRK_NEC ; +ohci_dbg (ohci,"enabled NEC chipset lost interrupt quirk\n" ); + +return 0 ; +} +/* List of quirks for OHCI */ static const struct pci_device_id ohci_pci_quirks[] = { {
@@ -134,6 +146,10 @@ static const struct pci_device_id ohci_p .driver_data = (unsigned long)ohci_quirk_toshiba_scc, }, { + PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB), + .driver_data = (unsigned long)ohci_quirk_nec, + }, + {/* Toshiba portege 4000 */ .vendor = PCI_VENDOR_ID_AL, .device = 0x5237,
Alan Stern
maintainerQuoted 8 lines · Michael Hanselmann
This patch fixes a silicon bug in some NEC OHCI chips. The bug appears at random times and is very, very difficult to reproduce. Without the following patch, Linux would shut the chip and its associated devices down. In Apple PowerBooks this leads to an unusable keyboard and mouse (SSH still working). The idea of restarting the chip is taken from public Darwin code.
drivers/usb/host/ohci-hcd.c static int ohci_restart (struct ohci_hcd · line 797
Quoted 8 lines
drivers/usb/host/ohci-hcd.c +4
-0@@ -779,7 +790,11 @@ static int ohci_restart (struct ohci_hcd*/ spin_lock_irq (&ohci->lock);disable (ohci); + +#ifdef CONFIG_PM usb_root_hub_lost_power (ohci_to_hcd (ohci)->self.root_hub); +#endif +
Suppose CONFIG_PM isn't defined. How are you going to let usbcore know about all the old connections which no longer exist?
Alan Stern
Quoted 4 lines · Alan Stern
Quoted 4 lines
(quoted diff) +0
-0@@ -779,7 +790,11 @@ static int ohci_restart (struct ohci_hcd */ spin_lock_irq(&ohci->lock); disable (ohci);
Quoted 8 lines
Review static int ohci_restart (struct ohci_hcd · line 797
Quoted 5 lines
(quoted diff) +4
-0+ +#ifdef CONFIG_PM usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); +#endif +Suppose
CONFIG_PMisn't defined. How are you going to let usbcore know about all the old connections which no longer exist?
You're right, something is wrong there. The patch below uses usb_root_hub_lost_power again but disables CONFIG_PM specific code in it when CONFIG_PM isn't defined. It seems to work for me with and without CONFIG_PM, but I have to confess I might not know enough about Linux' USB core. Is it better now?
---
drivers/usb/core/hub.c +2 -5
@@ -1089,9 +1089,6 @@ void usb_set_device_state(struct usb_devspin_unlock_irqrestore (&device_state_lock, flags); } - -#ifdef CONFIG_PM -/** * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power * @rhdev: struct usb_device for the root hub
@@ -1109,10 +1106,12 @@ void usb_root_hub_lost_power(struct usb_dev_warn (&rhdev->dev,"root hub lost power or was reset\n" ); +#ifdef CONFIG_PM /* Make sure no potential wakeup events get lost, * by forcing the root hub to be resumed. */ rhdev->dev.power.prev_state.event =PM_EVENT_ON ; +#endif /* CONFIG_PM */ spin_lock_irqsave (&device_state_lock, flags); hub =hdev_to_hub (rhdev);
@@ -1127,8 +1126,6 @@ void usb_root_hub_lost_power(struct usb_ }EXPORT_SYMBOL_GPL (usb_root_hub_lost_power); -#endif /* CONFIG_PM */ -static void choose_address (struct usb_device *udev) {int devnum;
drivers/usb/host/ohci.h +2 -0
@@ -397,8 +397,10 @@ struct ohci_hcd {#define OHCI_QUIRK_BE_DESC 0x08/* BE descriptors */ #define OHCI_QUIRK_BE_MMIO 0x10/* BE registers */ #define OHCI_QUIRK_ZFMICRO 0x20/* Compaq ZFMicro chipset*/ +#define OHCI_QUIRK_NEC 0x40/* lost interrupts */ // there are also chip quirks/bugs in init logic +struct work_struct nec_work;/* Worker for NEC quirk */ };/* convert between an hcd pointer and the corresponding ohci_hcd */
drivers/usb/host/ohci-hcd.c +37 -6
74 lines not on this page · raw message
drivers/usb/host/ohci-hub.c +0 -2
@@ -55,8 +55,6 @@ static void dl_done_list (struct ohci_hcstatic void finish_unlinks (struct ohci_hcd *,u16 );#ifdef CONFIG_PM -static int ohci_restart (struct ohci_hcd *ohci); - static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) __releases(ohci->lock) __acquires(ohci->lock)
drivers/usb/host/ohci-mem.c +1 -0
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_h ohci->next_statechange = jiffies;spin_lock_init (&ohci->lock);INIT_LIST_HEAD (&ohci->pending); +INIT_WORK (&ohci->nec_work, ohci_quirk_nec_worker); }/*-------------------------------------------------------------------------*/
drivers/usb/host/ohci-pci.c +16 -0
@@ -111,6 +111,18 @@ static int ohci_quirk_toshiba_scc(struct#endif } +/* Check for NEC chip and apply quirk for allegedly lost interrupts. +*/ +static int ohci_quirk_nec (struct usb_hcd *hcd) +{ +struct ohci_hcd *ohci =hcd_to_ohci (hcd); + + ohci->flags |=OHCI_QUIRK_NEC ; +ohci_dbg (ohci,"enabled NEC chipset lost interrupt quirk\n" ); + +return 0 ; +} +/* List of quirks for OHCI */ static const struct pci_device_id ohci_pci_quirks[] = { {
@@ -134,6 +146,10 @@ static const struct pci_device_id ohci_p .driver_data = (unsigned long)ohci_quirk_toshiba_scc, }, { + PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB), + .driver_data = (unsigned long)ohci_quirk_nec, + }, + {/* Toshiba portege 4000 */ .vendor = PCI_VENDOR_ID_AL, .device = 0x5237,
Alan Stern
maintainerQuoted 14 lines · Michael Hanselmann
Quoted 4 lines · Alan Stern
Quoted 4 lines
(quoted diff) +0
-0@@ -779,7 +790,11 @@ static int ohci_restart (struct ohci_hcd */ spin_lock_irq(&ohci->lock); disable (ohci);Quoted 8 lines
Review static int ohci_restart (struct ohci_hcd · line 797
Quoted 5 lines
(quoted diff) +4
-0+ +#ifdef CONFIG_PM usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); +#endif +Suppose
CONFIG_PMisn't defined. How are you going to let usbcore know about all the old connections which no longer exist?
Quoted 5 lines
You're right, something is wrong there. The patch below uses
usb_root_hub_lost_poweragain but disablesCONFIG_PMspecific code in it whenCONFIG_PMisn't defined. It seems to work for me with and withoutCONFIG_PM, but I have to confess I might not know enough about Linux' USB core. Is it better now?
Well no, even this is still wrong.
What you don't understand is how usb_root_hub_lost_power() works. It doesn't actually do much of anything itself; it simply sets a flag in the root hub's device structure. Then later on, when the hub driver is resumed it will see the flag and disconnect all the devices below the root hub.
In your case the last step won't work, because the hub driver will never be resumed since it wasn't suspended to begin with. You need to use a completely different approach. For instance, you could force ohci-hcd to report connect-change events on all the ports. Perhaps it does something like that anyway, in which case you wouldn't have to worry about it.
Alan Stern
Quoted 6 lines · Alan Stern
Then later on, when the hub driver is resumed it will see the flag and disconnect all the devices below the root hub.
For instance, you could force ohci-hcd to report connect-change events on all the ports. Perhaps it does something like that anyway, in which case you wouldn't have to worry about it.
After studying the code for two evenings, I'm quite sure it does that already.
A comment in ohci-hcd.c:ohci_restart reads:
/* mark any devices gone, so they do nothing till khubd disconnects.
* recycle any "live" eds/tds (and urbs) right away.
* later, khubd disconnect processing will recycle the other state,
* (either as disconnect/reconnect, or maybe someday as a reset). */
usb_root_hub_lost_power marks the ports as gone, khubd will disconnect them. After restarting the chip, khubd will cause them to be detected again.
This is also what I can watch in the logs:
ohci_hcd 0001:10:15.1: OHCI Unrecoverable Error, scheduling NEC chip restart
usb usb2: root hub lost power or was reset
usb 2-2: USB disconnect, address 2
input: appletouch disconnected
usb 2-2: new full speed USB device using ohci_hcd and address 3
usb 2-2: configuration #1 chosen from 1 choice
input: Apple Computer Apple Internal Keyboard / Trackpad as /class/input/input16 on usb-0001:10:15.1-2
input: appletouch as /class/input/input17
input: Apple Computer Apple Internal Keyboard / Trackpad as /class/input/input18 on usb-0001:10:15.1-2
(Actually, I added some code to trigger the error handling code, reliably reproducing it otherwise is impossible.)
Thanks,
Michael
Alan Stern
maintainerQuoted 11 lines · Michael Hanselmann
Quoted 6 lines · Alan Stern
Then later on, when the hub driver is resumed it will see the flag and disconnect all the devices below the root hub.
For instance, you could force ohci-hcd to report connect-change events on all the ports. Perhaps it does something like that anyway, in which case you wouldn't have to worry about it.
After studying the code for two evenings, I'm quite sure it does that already.
Quoted 6 lines
A comment in ohci-hcd.c:ohci_restart reads:
/* mark any devices gone, so they do nothing till khubd disconnects.
* recycle any "live" eds/tds (and urbs) right away.
* later, khubd disconnect processing will recycle the other state,
* (either as disconnect/reconnect, or maybe someday as a reset). */
Don't believe everything you read in comments. That one is very out of date. It should be removed.
Quoted 1 line
usb_root_hub_lost_powermarks the ports as gone, khubd will disconnect them.
Wrong. usb_root_hub_lost_power does _not_ mark the ports as gone, and it does _not_ tell khubd to disconnect them. (Depending on which version of the kernel you are looking at -- I'm referring to the latest development kernel including the gregkh-all patch set. Earlier versions did behave the way you describe.)
Quoted 13 lines
After restarting the chip, khubd will cause them to be detected again.
This is also what I can watch in the logs:
ohci_hcd0001:10:15.1: OHCI Unrecoverable Error, scheduling NEC chip restart
usb usb2: root hub lost power or was reset
usb 2-2: USB disconnect, address 2
input: appletouch disconnected
usb 2-2: new full speed USB device usingohci_hcdand address 3
usb 2-2: configuration #1 chosen from 1 choice
input: Apple Computer Apple Internal Keyboard / Trackpad as /class/input/input16 on usb-0001:10:15.1-2
input: appletouch as /class/input/input17
input: Apple Computer Apple Internal Keyboard / Trackpad as /class/input/input18 on usb-0001:10:15.1-2
Quoted 2 lines
(Actually, I added some code to trigger the error handling code, reliably reproducing it otherwise is impossible.)
So the system is behaving the way you want, but not for the reason you think. I bet you could remove the call to usb_root_hub_lost_power() entirely and it wouldn't make any difference at all.
Alan stern
Quoted 2 lines · Alan Stern
(Depending on which version of the kernel you are looking at -- [...] Earlier versions did behave the way you describe.)
I was looking at 2.6.22-rc3 which might explain the differences.
Quoted 3 lines
So the system is behaving the way you want, but not for the reason you think. I bet you could remove the call to
usb_root_hub_lost_power()entirely and it wouldn't make any difference at all.
Actually, that's true. René Nussbaumer tried without that call and it still works as intended. Should I leave that call out and drop the changes on usb_root_hub_lost_power for CONFIG_PM?
Greets,
Michael
Alan Stern
maintainerQuoted 7 lines · Michael Hanselmann
Quoted 3 lines
So the system is behaving the way you want, but not for the reason you think. I bet you could remove the call to
usb_root_hub_lost_power()entirely and it wouldn't make any difference at all.Actually, that's true. René Nussbaumer tried without that call and it still works as intended. Should I leave that call out and drop the changes on
usb_root_hub_lost_powerforCONFIG_PM?
That would be best. usb_root_hub_lost_power() is really meant to be used only when resuming from a suspend; it isn't appropriate for your situation.
Alan Stern