xhci: features for usb-next
Subsystems (4)
cover xhci: features for usb-next
Hi Greg
These following xhci patches are for usb-next and hopefully for 3.16
This patcheseries includes a bigger change in xhci command queue code, (last four patches), a task that I've been working on for a longer time. Sarah gave green light for v5 before she went on her sabbatical.
http://marc.info/?l=linux-usb&m=139889908701592&w=2
-Mathias
Alexander Gordeev (1):
xhci: Use pci_enable_msix_exact() instead of pci_enable_msix()
Dan Williams (2):
xhci: 'noxhci_port_switch' kernel parameter
usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Fabio Estevam (1):
usb: xhci: Use IS_ENABLED() macro
Lin Wang (1):
xhci: fix wrong port number reported when setting USB2.0 hardware LPM.
Mathias Nyman (4):
xhci: Use command structures when queuing commands on the command ring
xhci: Add a global command queue
xhci: Use completion and status in global command queue
xhci: rework command timeout and cancellation,
Sarah Sharp (1):
xhci: Report max device limit when Enable Slot command fails.
Documentation/kernel-parameters.txt | 3 + drivers/usb/core/hcd.c | 3 + drivers/usb/host/pci-quirks.c | 15 +- drivers/usb/host/xhci-hub.c | 43 ++- drivers/usb/host/xhci-mem.c | 17 +- drivers/usb/host/xhci-ring.c | 587 ++++++++++++++---------------------- drivers/usb/host/xhci.c | 271 +++++++++-------- drivers/usb/host/xhci.h | 47 +-- 8 files changed, 440 insertions(+), 546 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/10 xhci: fix wrong port number reported when setting USB2.0 hardware LPM.
From: Lin Wang <[email protected]>
This patch fix wrong port number reported when trying to enable/disable USB2.0 hardware LPM.
--- drivers/usb/host/xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci.c +1 -1
@@ -4092,7 +4092,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, field =le32_to_cpu (udev->bos->ext_cap->bmAttributes);xhci_dbg (xhci,"%s port %d USB2 hardware LPM\n" , - enable ?"enable" :"disable" , port_num); + enable ?"enable" :"disable" , port_num +1 );if (enable) {/* Host supports BESL timeout instead of HIRD */
Signature · 1 line
1.8.3.2
PATCH 2/10 xhci: 'noxhci_port_switch' kernel parameter
In reply to Mathias NymanFrom: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
Documentation/kernel-parameters.txt +3 -0
@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available + cpu0_hotplug [X86] Turn on CPU0 hotplug feature when CONFIG_BOOTPARAM_HOTPLUG_CPU0 is off. Some features depend on CPU0. Known dependencies are:
drivers/usb/host/pci-quirks.c +13 -2
@@ -823,6 +823,15 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,return -ETIMEDOUT ; } +static int noxhci_port_switch; + +static int __init noxhci_port_switch_setup (char *str) +{ + noxhci_port_switch =1 ; +return 0 ; +} +early_param ("noxhci_port_switch" , noxhci_port_switch_setup); +/* * Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that * share some number of ports. These ports can be switched between either
@@ -860,8 +869,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)return ;/* Don't switchover the ports if the user hasn't compiled the xHCI -* driver. Otherwise they will see "dead" USB ports that don't power -* the devices. +* driver or has explicitly disabled switchover */ if (!IS_ENABLED (CONFIG_USB_XHCI_HCD )) { dev_warn(&xhci_pdev->dev,
@@ -871,6 +879,9 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev) "USB 3.0 devices will work at USB 2.0 speeds.\n");usb_disable_xhci_ports (xhci_pdev);return ; + }else if (noxhci_port_switch) { +usb_disable_xhci_ports (xhci_pdev); +return ; }/* Read USB3PRM, the USB 3.0 Port Routing Mask Register
Signature · 1 line
1.8.3.2
Greg KH
maintainerRe: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0
Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +
Ugh, I really don't like new command line options.
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
thanks,
greg k-h
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2
This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
-Mathias
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
thanks,
Takashi
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 71 lines · Takashi Iwai
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
Quoted 8 lines
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
I'm not sure we want to make this more complex. Ideally this is just a stop-gap measure for users to workaround incompatibilities in xhci while the xhci fix is identified. The fact that it is a coarse hammer at least, in my mind, keeps more pressure on identifying the necessary xhci quirk/fix to make it as functional as ehci. We need that fix anyways for platforms with xhci ports without an ehci companion, so what purpose is served by letting users avoid xhci with finer granularity?
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
At Tue, 20 May 2014 11:25:37 -0700,
Quoted 82 lines · Dan Williams
Quoted 71 lines · Takashi Iwai
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
Quoted 8 lines
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
Quoted 8 lines
I'm not sure we want to make this more complex. Ideally this is just a stop-gap measure for users to workaround incompatibilities in xhci while the xhci fix is identified. The fact that it is a coarse hammer at least, in my mind, keeps more pressure on identifying the necessary xhci quirk/fix to make it as functional as ehci. We need that fix anyways for platforms with xhci ports without an ehci companion, so what purpose is served by letting users avoid xhci with finer granularity?
There are cases where only certain ports suffer from the problem of XHCI. The finer granularity allows user to identify the affected ports, and at least, more-or-less working state.
But the main purpose of this option is to give the pressure to XHCI developers, then I agree with it. But, in that case, it must be documented properly. Namely, this option is only for testing/debugging, and shouldn't be applied to any running system for real use as a workaround.
Takashi
Greg KH
maintainerRe: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
In reply to Dan WilliamsQuoted 81 lines · Dan Williams
Quoted 71 lines · Takashi Iwai
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
Quoted 8 lines
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
Quoted 3 lines
I'm not sure we want to make this more complex. Ideally this is just a stop-gap measure for users to workaround incompatibilities in xhci while the xhci fix is identified.
We can't use a kernel command line option as a "stop-gap", sorry. Let's just fix the real problem here.
thanks,
greg k-h
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 82 lines · Greg KH
Quoted 81 lines · Dan Williams
Quoted 79 lines · Takashi Iwai
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
Quoted 7 lines
Quoted 3 lines
I'm not sure we want to make this more complex. Ideally this is just a stop-gap measure for users to workaround incompatibilities in xhci while the xhci fix is identified.
We can't use a kernel command line option as a "stop-gap", sorry. Let's just fix the real problem here.
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work. Granted, I'm new to USB development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works with noxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).
Ideally, we could just tell users to blacklist xhci and use ehci while we work on a fix for their problem, but this ehci port-switchover happens well in advance of the xhci driver loading. Ultimately, it's a userspace policy decision of what driver to use when multiple are available and for ehci vs xhci we currently force a xhci-only policy at compile time.
--
Dan
Greg KH
maintainerRe: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 87 lines · Dan Williams
Quoted 86 lines · Greg KH
Quoted 84 lines · Dan Williams
Quoted 71 lines · Takashi Iwai
At Tue, 20 May 2014 12:47:36 +0300,
Quoted 65 lines · Mathias Nyman
Quoted 34 lines · Greg KH
Quoted 24 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Add a command line switch for disabling ehci port switchover. Useful for working around / debugging xhci incompatibilities where ehci operation is available.
Reference: http://marc.info/?l=linux-usb&m=138920063001509&w=2
Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Cc Holger Hans Peter Freyther <[email protected]>Suggested-by Alan Stern <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- Documentation/kernel-parameters.txt | 3 +++ drivers/usb/host/pci-quirks.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)Documentation/kernel-parameters.txt +0
-0Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 2256
Quoted 6 lines
Documentation/kernel-parameters.txt +3
-0@@ -2251,6 +2251,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nox2apic [X86-64,APIC] Do not enable x2APIC mode. + noxhci_port_switch + [USB] Use EHCI instead of XHCI where available +Ugh, I really don't like new command line options.
Quoted 8 lines
Especially one that isn't very well documented. Why would someone want to enable this? What problem is it solving? Can we detect this automatically and do it for the user? Is this just for prototype hardware that has not shipped? What hardware needs this?
I need a whole lot more documentation at the very least before I will apply this.
On Intel hardware with both ehci and xhci controllers we can select if a usb2 port is controlled by ehci or xhci. This capability can be checked from Intel xhci pci config space. Xhci driver checks this on boot and switches over the supported ports.
This is a feature in Intel Panther point and later chipsets, in shipped hardware. Its working quite well in most cases, but sometimes vendors claim they support switchover, but then forget to connect some wires, and the usb2 port ends up dead after switching.
A recently found case is the Sony VAIO T-series. (I'll send you a different patch for that shortly)
http://marc.info/?l=linux-usb&m=139993106029340&w=2This is the extreme case that the usb2 ports appears completely dead. Other reasons are that some devices might work better under ehci than xhci, and users want to enforce the ehci opton. For powermanagement developers it's nice to disable switchover as it turns out some hardware are quirky with port switchover and suspend/resume. (might need to turn port back to ehci before suspending).
Quoted 3 lines
I don't think we can detect this automatically.
Dan, can you add more documentation to this patch?
Quoted 8 lines
While we're at it: can we implement a bitmask instead?
We've seen lots of HP laptops having Webcams or BT devices that don't work XHCI but only with EHCI. For making them working properly, the specific xhci ports have to be disabled. But, we don't want to kill the whole XHCI at all. The single boolean option doesn't work for such a case.
I'm not sure we want to make this more complex. Ideally this is just a stop-gap measure for users to workaround incompatibilities in xhci while the xhci fix is identified.
Quoted 8 lines
Quoted 3 lines
We can't use a kernel command line option as a "stop-gap", sorry. Let's just fix the real problem here.
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
thanks,
greg k-h
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 16 lines · Greg KH
Quoted 4 lines
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).
Quoted 2 lines
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
The only thing stopping me from saying "deal." is that this darn things is presently a pci quirk. So it happens well before the user has a chance to manually override it with a debugfs file.
Let me look into delaying the quirk until the driver loads, because ideally the right interface for this is "blacklist xhci_hcd" in /etc/modprobe.conf.
Greg KH
maintainerRe: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 17 lines · Dan Williams
Quoted 16 lines · Greg KH
Quoted 4 lines
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).
Quoted 6 lines
Quoted 2 lines
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
The only thing stopping me from saying "deal." is that this darn things is presently a pci quirk. So it happens well before the user has a chance to manually override it with a debugfs file.
Then have the debugfs file disconnect the device and reconnect it.
Quoted 3 lines
Let me look into delaying the quirk until the driver loads, because ideally the right interface for this is "blacklist
xhci_hcd" in/etc/modprobe.conf.
Which really doesn't work for systems / distros that build the driver into the kernel.
thanks,
greg k-h
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 18 lines · Greg KH
Quoted 17 lines · Dan Williams
Quoted 16 lines · Greg KH
Quoted 4 lines
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
The only thing stopping me from saying "deal." is that this darn things is presently a pci quirk. So it happens well before the user has a chance to manually override it with a debugfs file.
Then have the debugfs file disconnect the device and reconnect it.
We also need to reload the ehci hcd driver since it needs to know its port count at load time as well. Which is more violent and error prone than I think we want.
Quoted 6 lines
Quoted 3 lines
Let me look into delaying the quirk until the driver loads, because ideally the right interface for this is "blacklist
xhci_hcd" in/etc/modprobe.conf.Which really doesn't work for systems / distros that build the driver into the kernel.
True. I'm back to a kernel command line option as the only viable way forward, but let me try to wordsmith the description to make clear when to use this workaround and the obligation to report upstream when this workaround works so we can queue up the fix for xhci.
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 26 lines · Dan Williams
Quoted 25 lines · Greg KH
Quoted 23 lines · Dan Williams
Quoted 16 lines · Greg KH
Quoted 4 lines
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).Quoted 2 lines
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
The only thing stopping me from saying "deal." is that this darn things is presently a pci quirk. So it happens well before the user has a chance to manually override it with a debugfs file.
Quoted 5 lines
Quoted 1 line
Then have the debugfs file disconnect the device and reconnect it.
We also need to reload the ehci hcd driver since it needs to know its port count at load time as well. Which is more violent and error prone than I think we want.
Does the port count change? Maybe nothing needs to be unloaded or reloaded. Has anyone tried it?
Alan Stern
Greg KH
maintainerRe: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
In reply to Dan WilliamsQuoted 26 lines · Dan Williams
Quoted 25 lines · Greg KH
Quoted 23 lines · Dan Williams
Quoted 16 lines · Greg KH
Quoted 4 lines
Greg,
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work.
I totally agree.
Quoted 8 lines
Granted, I'm new to USB
development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to me. So, I don't think it is fair to expect that the tide of quirky devices will be stemmed in any reasonable amount of time. Having a "works withnoxhci_port_switch" report from users is good data (hmm, I think a printk to tell users to file a report upstream if the option resolves their issue is needed).Quoted 2 lines
How about just adding a debugfs file instead? That way, once you fix this, we can then remove it and no one will care.
The only thing stopping me from saying "deal." is that this darn things is presently a pci quirk. So it happens well before the user has a chance to manually override it with a debugfs file.
Quoted 5 lines
Quoted 1 line
Then have the debugfs file disconnect the device and reconnect it.
We also need to reload the ehci hcd driver since it needs to know its port count at load time as well. Which is more violent and error prone than I think we want.
Why is that a problem?
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Let me look into delaying the quirk until the driver loads, because ideally the right interface for this is "blacklist
xhci_hcd" in/etc/modprobe.conf.Which really doesn't work for systems / distros that build the driver into the kernel.
True. I'm back to a kernel command line option as the only viable way forward, but let me try to wordsmith the description to make clear when to use this workaround and the obligation to report upstream when this workaround works so we can queue up the fix for xhci.
No, I really don't want a command line option if at all possible as you will have to support it for forever.
greg k-h
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
In reply to Dan WilliamsOn Tue, May 20, 2014 at 03:40:16PM -0700, Dan Williams wrote:
Dear Dan,
Quoted 4 lines
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work. Granted, I'm new to USB development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to
thank you very much for this statement. xhci-hcd is unusable for many people. On my laptop I can't scan more than one document, the laptop sometimes immediately wakes up after suspend and after almost two years all of these issues remain.
I am running kernels with a hacked up pci-quirks.c for months and scanning documents work, suspend/resume is working, no issues with USB serials. My job is not related to Linux kernel development so I would love to go back to a distribution kernel. Please make this possible. In the end "xhci" appears to be a "supported" driver?
cheers
holger
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
Quoted 9 lines · Holger Hans Peter Freyther
On Tue, May 20, 2014 at 03:40:16PM -0700, Dan Williams wrote:
Dear Dan,
Quoted 4 lines
Sorry, I don't think it is fair to users to force them to re-compile their kernel to get their device to work. Granted, I'm new to USB development, but the rate of reports of endpoint devices that mess up and require quirks in the hcd-driver or usb-core seems un-ending to
Quoted 4 lines
thank you very much for this statement. xhci-hcd is unusable for many people. On my laptop I can't scan more than one document, the laptop sometimes immediately wakes up after suspend and after almost two years all of these issues remain.
That's sad. We (Sarah, Mathias, and I) really want to fix that.
Quoted 5 lines
I am running kernels with a hacked up
pci-quirks.cfor months and scanning documents work, suspend/resume is working, no issues with USB serials. My job is not related to Linux kernel development so I would love to go back to a distribution kernel. Please make this possible. In the end "xhci" appears to be a "supported" driver?
Yes, there are presently 3 people hacking on the xhci bug report backlog at Intel where it was just a solitary hero before. To be fair I believe the rate of discovery of non-spec compliant quirkiness is to blame. In the meantime, as we ramp to get back on top of the tidal wave of weird device interactions with xhci, I believe it is fair to offer a workaround.
Let me see if I can achieve this with a debugfs interface so that 'noxhci_port_switch' does not become a permanent ABI per Greg's concern.
--
Dan
Re: [PATCH 02/10] xhci: 'noxhci_port_switch' kernel parameter
On Sat, May 24, 2014 at 07:13:12AM -0700, Dan Williams wrote:
Good Afternoon,
Quoted 3 lines
Let me see if I can achieve this with a debugfs interface so that '
noxhci_port_switch' does not become a permanent ABI per Greg's concern.
I wonder if there is another non-ABI option? Couldn't the ports be unconditionall switched back to EHCI when unloading the xhci module? I know it is just a workaround (but then again I don't have any usb 3.0 devices). :)
cheers
holger
PATCH 3/10 usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
In reply to Mathias NymanFrom: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Return -EAGAIN matching the return value for dma_mapping_error() cases.
--- drivers/usb/core/hcd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/hcd.c +3 -0
@@ -1502,6 +1502,9 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, ret = -EAGAIN ; else urb->transfer_flags |= URB_DMA_MAP_PAGE; + }else if (is_vmalloc_addr (urb->transfer_buffer)) { +WARN_ONCE (1 ,"transfer buffer not dma capable\n" ); + ret = -EAGAIN ; }else { urb->transfer_dma = dma_map_single( hcd->self.controller,
Signature · 1 line
1.8.3.2
Re: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Quoted 7 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Quoted 7 lines
Return
-EAGAINmatching the return value fordma_mapping_error()cases.Cc Alan Stern <[email protected]>Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>
Thanks Mathias.
One note, this was acked-by Alan here:
Re: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Quoted 17 lines · Dan Williams
Quoted 7 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Quoted 7 lines
Return
-EAGAINmatching the return value fordma_mapping_error()cases.Cc Alan Stern <[email protected]>Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>
Quoted 6 lines
Thanks Mathias.
One note, this was acked-by Alan here:
Ah, Right
Greg, Alan, Should I resubmit this series with the added ACK for this patch?
-Mathias
Greg KH
maintainerRe: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Quoted 20 lines · Mathias Nyman
Quoted 19 lines · Dan Williams
Quoted 7 lines · Mathias Nyman
From: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Quoted 7 lines
Return
-EAGAINmatching the return value fordma_mapping_error()cases.Cc Alan Stern <[email protected]>Cc Sarah Sharp <[email protected]>Cc Mathias Nyman <[email protected]>Signed-off-by Dan Williams <[email protected]>Signed-off-by Mathias Nyman <[email protected]>Thanks Mathias.
Quoted 8 lines
Quoted 4 lines
One note, this was acked-by Alan here:
Ah, Right
Greg, Alan, Should I resubmit this series with the added ACK for this patch?
No need, I can add it.
RE: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
In reply to Mathias NymanFrom: Mathias Nyman
Quoted 8 lines
From: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Return
-EAGAINmatching the return value fordma_mapping_error()cases.
Won't that just cause the request to be resubmitted a few clock cycles later?
Surely you either need to error the request, or panic. In any case is this the right place for this sort of test?
(Yes I've spent some time before realising that Linux doesn't have a proper vtop() function ....)
David
...
Quoted 14 lines
drivers/usb/core/hcd.c +3
-0@@ -1502,6 +1502,9 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, ret = -EAGAIN ; else urb->transfer_flags |= URB_DMA_MAP_PAGE; + }else if (is_vmalloc_addr (urb->transfer_buffer)) { +WARN_ONCE (1 ,"transfer buffer not dma capable\n" ); + ret = -EAGAIN ; }else { urb->transfer_dma = dma_map_single( hcd->self.controller,
Re: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Quoted 8 lines · David Laight
From: Mathias Nyman
Quoted 7 lines
From: Dan Williams <[email protected]>
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Quoted 5 lines
Quoted 1 line
Return
-EAGAINmatching the return value fordma_mapping_error()cases.Won't that just cause the request to be resubmitted a few clock cycles later?
Surely you either need to error the request, or panic.
No, panic() is too drastic for this.
Quoted 1 line
In any case is this the right place for this sort of test?
Yes.
The system is already compromised because the driver is broken. The expectation is that this is a clue bat for a driver developer to fix their code before it goes upstream. I found this while debugging an interaction with a new driver that was causing the xhci controller to lock up. Had this warning been there I likely never would have received the xhci bug report.
Re: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
In reply to Mathias NymanQuoted 6 lines · Mathias Nyman
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Return
-EAGAINmatching the return value fordma_mapping_error()cases.
[]
drivers/usb/core/hcd.c
Quoted 1 line
drivers/usb/core/hcd.c +0
-0
[]
drivers/usb/core/hcd.c int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 1510
Quoted 10 lines
drivers/usb/core/hcd.c +3
-0@@ -1502,6 +1502,9 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, ret = -EAGAIN ; else urb->transfer_flags |= URB_DMA_MAP_PAGE; + }else if (is_vmalloc_addr (urb->transfer_buffer)) { +WARN_ONCE (1 ,"transfer buffer not dma capable\n" ); + ret = -EAGAIN ; }else { urb->transfer_dma = dma_map_single( hcd->self.controller,
Perhaps this could be #ifdef'd here or moved to and tested in dma_map_single/dma_map_single_attr instead.
Re: [PATCH 03/10] usb: catch attempts to submit urbs with a vmalloc'd transfer buffer
Quoted 10 lines · Joe Perches
Quoted 6 lines · Mathias Nyman
Save someone else the debug cycles of figuring out why a driver's transfer request is failing or causing undefined system behavior. Buffers submitted for dma must come from GFP allocated / DMA-able memory.
Return
-EAGAINmatching the return value fordma_mapping_error()cases.[]
drivers/usb/core/hcd.c
Quoted 1 line
drivers/usb/core/hcd.c +0
-0[]
Quoted 14 lines
drivers/usb/core/hcd.c int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 1510
Quoted 10 lines
drivers/usb/core/hcd.c +3
-0@@ -1502,6 +1502,9 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, ret = -EAGAIN ; else urb->transfer_flags |= URB_DMA_MAP_PAGE; + }else if (is_vmalloc_addr (urb->transfer_buffer)) { +WARN_ONCE (1 ,"transfer buffer not dma capable\n" ); + ret = -EAGAIN ; }else { urb->transfer_dma = dma_map_single( hcd->self.controller,Perhaps this could be #ifdef'd here or moved to and tested in dma_map_single/dma_map_single_attr instead.
What problem are you trying to solve? Adding it to dma_map() means incurring the overhead of checking on every call and it would be akin to adding dma_mapping_error() to dma_map(). Otherwise, if it is ifdef'd that will miss the very same driver developers that didn't know they couldn't do that. USB core has already committed to validating the input buffers in this routine, what's wrong with one more check?
PATCH 4/10 usb: xhci: Use IS_ENABLED() macro
In reply to Mathias NymanFrom: Fabio Estevam <[email protected]>
Using the IS_ENABLED() macro can make the code shorter and easier to read.
--- drivers/usb/host/xhci.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/xhci.h +1 -2
@@ -1738,8 +1738,7 @@ static inline int xhci_register_pci(void) { return 0; }static inline void xhci_unregister_pci (void ) {}#endif -#if defined(CONFIG_USB_XHCI_PLATFORM ) \ - || defined(CONFIG_USB_XHCI_PLATFORM_MODULE ) +#if IS_ENABLED (CONFIG_USB_XHCI_PLATFORM )int xhci_register_plat (void );void xhci_unregister_plat (void );#else
Signature · 1 line
1.8.3.2
PATCH 5/10 xhci: Use pci_enable_msix_exact() instead of pci_enable_msix()
In reply to Mathias NymanFrom: Alexander Gordeev <[email protected]>
As result of deprecation of MSI-X/MSI enablement functions pci_enable_msix() and pci_enable_msi_block() all drivers using these two interfaces need to be updated to use the new pci_enable_msi_range() or pci_enable_msi_exact() and pci_enable_msix_range() or pci_enable_msix_exact() interfaces.
--- drivers/usb/host/xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci.c +1 -1
@@ -291,7 +291,7 @@ static int xhci_setup_msix(struct xhci_hcd *xhci) xhci->msix_entries[i].vector =0 ; } - ret =pci_enable_msix (pdev, xhci->msix_entries, xhci->msix_count); + ret =pci_enable_msix_exact (pdev, xhci->msix_entries, xhci->msix_count);if (ret) {xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Failed to enable MSI-X" );
Signature · 1 line
1.8.3.2
PATCH 6/10 xhci: Report max device limit when Enable Slot command fails.
In reply to Mathias NymanFrom: Sarah Sharp <[email protected]>
xHCI host controllers may only support a limited number of device slot IDs, which is usually far less than the theoretical maximum number of devices (255) that the USB specifications advertise. This is frustrating to consumers that expect to be able to plug in a large number of devices.
Add a print statement when the Enable Slot command fails to show how many devices the host supports. We can't change hardware manufacturer's design decisions, but hopefully we can save customers a little bit of time trying to debug why their host mysteriously fails when too many devices are plugged in.
--- drivers/usb/host/xhci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/host/xhci.c +3 -0
@@ -3696,6 +3696,9 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)if (!xhci->slot_id) {xhci_err (xhci,"Error while assigning device slot ID\n" ); +xhci_err (xhci,"Max number of devices this xHCI host supports is %u.\n" , +HCS_MAX_SLOTS ( +readl (&xhci->cap_regs->hcs_params1)));return 0 ; }
Signature · 1 line
1.8.3.2
PATCH 7/10 xhci: Use command structures when queuing commands on the command ring
In reply to Mathias NymanTo create a global command queue we require that each command put on the command ring is submitted with a command structure.
Functions that queue commands and wait for completion need to allocate a command before submitting it, and free it once completed. The following command queuing functions need to be modified.
xhci_configure_endpoint()xhci_address_device()xhci_queue_slot_control()xhci_queue_stop_endpoint()xhci_queue_new_dequeue_state()xhci_queue_reset_ep()xhci_configure_endpoint()
xhci_configure_endpoint() could already be called with a command structure, and only xhci_check_maxpacket and xhci_check_bandwidth did not do so. These are changed and a command structure is now required. This change also simplifies the configure endpoint command completion handling and the "goto bandwidth_change" handling code can be removed.
In some cases the command queuing function is called in interrupt context. These commands needs to be allocated atomically, and they can't wait for completion. These commands will in this patch be freed directly after queuing, but freeing will be moved to the command completion event handler in a later patch once we get the global command queue up.(Just so that we won't leak memory in the middle of the patch set)
--- drivers/usb/host/xhci-hub.c | 21 +++-- drivers/usb/host/xhci-ring.c | 107 +++++++++++++----------- drivers/usb/host/xhci.c | 194 ++++++++++++++++++++++++++++--------------- drivers/usb/host/xhci.h | 31 +++---- 4 files changed, 216 insertions(+), 137 deletions(-)
drivers/usb/host/xhci-hub.c +16 -5
@@ -20,7 +20,8 @@* Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/gfp.h> + +#include <linux/slab.h> #include <asm/unaligned.h> #include "xhci.h"
@@ -284,12 +285,22 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)spin_lock_irqsave (&xhci->lock, flags);for (i =LAST_EP_INDEX ; i >0 ; i--) { -if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) -xhci_queue_stop_endpoint (xhci, slot_id, i, suspend); +if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { +struct xhci_command *command; + command =xhci_alloc_command (xhci, false, false, +GFP_NOIO ); +if (!command) { +spin_unlock_irqrestore (&xhci->lock, flags); +xhci_free_command (xhci, cmd); +return -ENOMEM ; + + } +xhci_queue_stop_endpoint (xhci, command, slot_id, i, + suspend); + } } - cmd->command_trb =xhci_find_next_enqueue (xhci->cmd_ring);list_add_tail (&cmd->cmd_list, &virt_dev->cmd_list); -xhci_queue_stop_endpoint (xhci, slot_id,0 , suspend); +xhci_queue_stop_endpoint (xhci, cmd, slot_id,0 , suspend);xhci_ring_cmd_db (xhci);spin_unlock_irqrestore (&xhci->lock, flags);
drivers/usb/host/xhci-ring.c +57 -50
252 lines not on this page · raw message
drivers/usb/host/xhci.c +126 -68
491 lines not on this page · raw message
drivers/usb/host/xhci.h +17 -14
@@ -1807,13 +1807,14 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, dma_addr_t suspect_dma);int xhci_is_vendor_info_code (struct xhci_hcd *xhci,unsigned int trb_comp_code);void xhci_ring_cmd_db (struct xhci_hcd *xhci); -int xhci_queue_slot_control (struct xhci_hcd *xhci,u32 trb_type,u32 slot_id); -int xhci_queue_address_device (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,enum xhci_setup_dev ); -int xhci_queue_vendor_command (struct xhci_hcd *xhci, +int xhci_queue_slot_control (struct xhci_hcd *xhci,struct xhci_command *cmd, +u32 trb_type,u32 slot_id); +int xhci_queue_address_device (struct xhci_hcd *xhci,struct xhci_command *cmd, +dma_addr_t in_ctx_ptr,u32 slot_id,enum xhci_setup_dev ); +int xhci_queue_vendor_command (struct xhci_hcd *xhci,struct xhci_command *cmd,u32 field1,u32 field2,u32 field3,u32 field4); -int xhci_queue_stop_endpoint (struct xhci_hcd *xhci,int slot_id, -unsigned int ep_index,int suspend); +int xhci_queue_stop_endpoint (struct xhci_hcd *xhci,struct xhci_command *cmd, +int slot_id,unsigned int ep_index,int suspend);int xhci_queue_ctrl_tx (struct xhci_hcd *xhci,gfp_t mem_flags,struct urb *urb,int slot_id,unsigned int ep_index); int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
@@ -1822,18 +1823,21 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, int slot_id, unsigned int ep_index);int xhci_queue_isoc_tx_prepare (struct xhci_hcd *xhci,gfp_t mem_flags,struct urb *urb,int slot_id,unsigned int ep_index); -int xhci_queue_configure_endpoint (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,bool command_must_succeed); -int xhci_queue_evaluate_context (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,bool command_must_succeed); -int xhci_queue_reset_ep (struct xhci_hcd *xhci,int slot_id, -unsigned int ep_index); -int xhci_queue_reset_device (struct xhci_hcd *xhci,u32 slot_id); +int xhci_queue_configure_endpoint (struct xhci_hcd *xhci, +struct xhci_command *cmd,dma_addr_t in_ctx_ptr,u32 slot_id, +bool command_must_succeed); +int xhci_queue_evaluate_context (struct xhci_hcd *xhci,struct xhci_command *cmd, +dma_addr_t in_ctx_ptr,u32 slot_id,bool command_must_succeed); +int xhci_queue_reset_ep (struct xhci_hcd *xhci,struct xhci_command *cmd, +int slot_id,unsigned int ep_index); +int xhci_queue_reset_device (struct xhci_hcd *xhci,struct xhci_command *cmd, +u32 slot_id);void xhci_find_new_dequeue_state (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id,struct xhci_td *cur_td,struct xhci_dequeue_state *state);void xhci_queue_new_dequeue_state (struct xhci_hcd *xhci, +struct xhci_command *cmd,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id,struct xhci_dequeue_state *deq_state);
@@ -1847,7 +1851,6 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, union xhci_trb *cmd_trb);void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id); -union xhci_trb *xhci_find_next_enqueue (struct xhci_ring *ring);/* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
Signature · 1 line
1.8.3.2
Re: [PATCH 07/10] xhci: Use command structures when queuing commands on the command ring
Hi Mathias, hit a small issue playing with -next:
Quoted 51 lines · Mathias Nyman
To create a global command queue we require that each command put on the command ring is submitted with a command structure.
Functions that queue commands and wait for completion need to allocate a command before submitting it, and free it once completed. The following command queuing functions need to be modified.
xhci_configure_endpoint()xhci_address_device()xhci_queue_slot_control()xhci_queue_stop_endpoint()xhci_queue_new_dequeue_state()xhci_queue_reset_ep()xhci_configure_endpoint()
xhci_configure_endpoint()could already be called with a command structure, and onlyxhci_check_maxpacketandxhci_check_bandwidthdid not do so. These are changed and a command structure is now required. This change also simplifies the configure endpoint command completion handling and the "gotobandwidth_change" handling code can be removed.In some cases the command queuing function is called in interrupt context. These commands needs to be allocated atomically, and they can't wait for completion. These commands will in this patch be freed directly after queuing, but freeing will be moved to the command completion event handler in a later patch once we get the global command queue up.(Just so that we won't leak memory in the middle of the patch set)
Signed-off-by Mathias Nyman <[email protected]>--- drivers/usb/host/xhci-hub.c | 21 +++-- drivers/usb/host/xhci-ring.c | 107 +++++++++++++----------- drivers/usb/host/xhci.c | 194 ++++++++++++++++++++++++++++--------------- drivers/usb/host/xhci.h | 31 +++---- 4 files changed, 216 insertions(+), 137 deletions(-)drivers/usb/host/xhci-hub.c +2
-1@@ -20,7 +20,8 @@* Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/gfp.h> + +#include <linux/slab.h> #include <asm/unaligned.h> #include "xhci.h"
drivers/usb/host/xhci-hub.c static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) · line 291
Quoted 9 lines
drivers/usb/host/xhci-hub.c +4
-2@@ -284,12 +285,22 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)spin_lock_irqsave (&xhci->lock, flags);for (i =LAST_EP_INDEX ; i >0 ; i--) { -if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) -xhci_queue_stop_endpoint (xhci, slot_id, i, suspend); +if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { +struct xhci_command *command; + command =xhci_alloc_command (xhci, false, false, +GFP_NOIO );
...this needs to be GFP_NOWAIT, or move it outside the lock.
Re: [PATCH 07/10] xhci: Use command structures when queuing commands on the command ring
Quoted 56 lines · Dan Williams
Hi Mathias, hit a small issue playing with -next:
Quoted 52 lines · Mathias Nyman
To create a global command queue we require that each command put on the command ring is submitted with a command structure.
Functions that queue commands and wait for completion need to allocate a command before submitting it, and free it once completed. The following command queuing functions need to be modified.
xhci_configure_endpoint()xhci_address_device()xhci_queue_slot_control()xhci_queue_stop_endpoint()xhci_queue_new_dequeue_state()xhci_queue_reset_ep()xhci_configure_endpoint()
xhci_configure_endpoint()could already be called with a command structure, and onlyxhci_check_maxpacketandxhci_check_bandwidthdid not do so. These are changed and a command structure is now required. This change also simplifies the configure endpoint command completion handling and the "gotobandwidth_change" handling code can be removed.In some cases the command queuing function is called in interrupt context. These commands needs to be allocated atomically, and they can't wait for completion. These commands will in this patch be freed directly after queuing, but freeing will be moved to the command completion event handler in a later patch once we get the global command queue up.(Just so that we won't leak memory in the middle of the patch set)
Signed-off-by Mathias Nyman <[email protected]>--- drivers/usb/host/xhci-hub.c | 21 +++-- drivers/usb/host/xhci-ring.c | 107 +++++++++++++----------- drivers/usb/host/xhci.c | 194 ++++++++++++++++++++++++++++--------------- drivers/usb/host/xhci.h | 31 +++---- 4 files changed, 216 insertions(+), 137 deletions(-)drivers/usb/host/xhci-hub.c +2
-1@@ -20,7 +20,8 @@* Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/gfp.h> + +#include <linux/slab.h> #include <asm/unaligned.h> #include "xhci.h" @@ -284,12 +285,22 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
Quoted 11 lines
drivers/usb/host/xhci-hub.c static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) · line 291
Quoted 8 lines
drivers/usb/host/xhci-hub.c +4
-2spin_lock_irqsave (&xhci->lock, flags);for (i =LAST_EP_INDEX ; i >0 ; i--) { -if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) -xhci_queue_stop_endpoint (xhci, slot_id, i, suspend); +if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { +struct xhci_command *command; + command =xhci_alloc_command (xhci, false, false, +GFP_NOIO );...this needs to be
GFP_NOWAIT, or move it outside the lock.
That's right, thanks, I'll fix it.
-Mathias
PATCH 8/10 xhci: Add a global command queue
In reply to Mathias NymanCreate a list to store command structures, add a structure to it every time a command is submitted, and remove it from the list once we get a command completion event matching the command.
Callers that wait for completion will free their command structures themselves. The other command structures are freed in the command completion event handler.
Also add a check that prevents queuing commands if host is dying
--- drivers/usb/host/xhci-mem.c | 2 ++ drivers/usb/host/xhci-ring.c | 34 ++++++++++++++++++++++++++++++---- drivers/usb/host/xhci.c | 2 -- drivers/usb/host/xhci.h | 2 ++ 4 files changed, 34 insertions(+), 6 deletions(-)
drivers/usb/host/xhci-mem.c +2 -0
@@ -1821,6 +1821,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)list_del (&cur_cd->cancel_cmd_list);kfree (cur_cd); } +xhci_cleanup_command_queue (xhci);for (i =1 ; i <MAX_HC_SLOTS ; ++i)xhci_free_virt_device (xhci, i);
@@ -2324,6 +2325,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)int i;INIT_LIST_HEAD (&xhci->cancel_cmd_list); +INIT_LIST_HEAD (&xhci->cmd_list); page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,
drivers/usb/host/xhci-ring.c +30 -4
@@ -1520,6 +1520,20 @@ static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, NEC_FW_MINOR(le32_to_cpu(event->status))); } +static void xhci_del_and_free_cmd (struct xhci_command *cmd) +{ +list_del (&cmd->cmd_list); +if (!cmd->completion) +kfree (cmd); +} + +void xhci_cleanup_command_queue (struct xhci_hcd *xhci) +{ +struct xhci_command *cur_cmd, *tmp_cmd; +list_for_each_entry_safe (cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) +xhci_del_and_free_cmd (cur_cmd); +} +static void handle_cmd_completion (struct xhci_hcd *xhci,struct xhci_event_cmd *event) {
@@ -1528,6 +1542,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,dma_addr_t cmd_dequeue_dma;u32 cmd_comp_code;union xhci_trb *cmd_trb; +struct xhci_command *cmd;u32 cmd_type; cmd_dma =le64_to_cpu (event->cmd_trb);
@@ -1545,6 +1560,13 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,return ; } + cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); + +if (cmd->command_trb != xhci->cmd_ring->dequeue) { +xhci_err (xhci, +"Command completion event does not match command\n" ); +return ; + }trace_xhci_cmd_completion (cmd_trb, (struct xhci_generic_trb *) event); cmd_comp_code =GET_COMP_CODE (le32_to_cpu (event->status));
@@ -1614,6 +1636,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, xhci->error_bitmask |=1 <<6 ;break ; } + +xhci_del_and_free_cmd (cmd); +inc_deq (xhci, xhci->cmd_ring); }
@@ -3998,6 +4023,8 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, {int reserved_trbs = xhci->cmd_ring_reserved_trbs;int ret; +if (xhci->xhc_state &XHCI_STATE_DYING ) +return -ESHUTDOWN ;if (!command_must_succeed) reserved_trbs++;
@@ -4011,10 +4038,9 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, "unfailable commands failed.\n");return ret; } -if (cmd->completion) - cmd->command_trb = xhci->cmd_ring->enqueue; -else -kfree (cmd); + + cmd->command_trb = xhci->cmd_ring->enqueue; +list_add_tail (&cmd->cmd_list, &xhci->cmd_list);queue_trb (xhci, xhci->cmd_ring, false, field1, field2, field3, field4 | xhci->cmd_ring->cycle_state);
drivers/usb/host/xhci.c +0 -2
@@ -3732,7 +3732,6 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) timeleft == 0 ? "Timeout" : "Signal");/* cancel the enable slot request */ ret =xhci_cancel_cmd (xhci,NULL , command->command_trb); -kfree (command);return ret; }
@@ -3891,7 +3890,6 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, timeleft == 0 ? "Timeout" : "Signal", act);/* cancel the address device command */ ret =xhci_cancel_cmd (xhci,NULL , command->command_trb); -kfree (command);if (ret <0 )return ret;return -ETIME ;
drivers/usb/host/xhci.h +2 -0
@@ -1484,6 +1484,7 @@ struct xhci_hcd {#define CMD_RING_STATE_ABORTED (1 << 1)#define CMD_RING_STATE_STOPPED (1 << 2)struct list_head cancel_cmd_list; +struct list_head cmd_list;unsigned int cmd_ring_reserved_trbs;struct xhci_ring *event_ring;struct xhci_erst erst;
@@ -1851,6 +1852,7 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, union xhci_trb *cmd_trb);void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id); +void xhci_cleanup_command_queue (struct xhci_hcd *xhci);/* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
Signature · 1 line
1.8.3.2
PATCH 9/10 xhci: Use completion and status in global command queue
In reply to Mathias NymanRemove the per-device command list and handle_cmd_in_cmd_wait_list() and use the completion and status variables found in the command structure in the global command list.
--- drivers/usb/host/xhci-hub.c | 11 ------ drivers/usb/host/xhci-mem.c | 1 - drivers/usb/host/xhci-ring.c | 84 ++++++++------------------------------------ drivers/usb/host/xhci.c | 16 ++------- drivers/usb/host/xhci.h | 3 -- 5 files changed, 17 insertions(+), 98 deletions(-)
drivers/usb/host/xhci-hub.c +0 -11
@@ -299,7 +299,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) suspend); } } -list_add_tail (&cmd->cmd_list, &virt_dev->cmd_list);xhci_queue_stop_endpoint (xhci, cmd, slot_id,0 , suspend);xhci_ring_cmd_db (xhci);spin_unlock_irqrestore (&xhci->lock, flags);
@@ -311,18 +310,8 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)if (timeleft <=0 ) {xhci_warn (xhci,"%s while waiting for stop endpoint command\n" , timeleft ==0 ?"Timeout" :"Signal" ); -spin_lock_irqsave (&xhci->lock, flags); -/* The timeout might have raced with the event ring handler, so -* only delete from the list if the item isn't poisoned. -*/ -if (cmd->cmd_list.next !=LIST_POISON1 ) -list_del (&cmd->cmd_list); -spin_unlock_irqrestore (&xhci->lock, flags); ret = -ETIME ; - goto command_cleanup; } - -command_cleanup:xhci_free_command (xhci, cmd);return ret; }
drivers/usb/host/xhci-mem.c +0 -1
@@ -1020,7 +1020,6 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, dev->num_rings_cached =0 ;init_completion (&dev->cmd_completion); -INIT_LIST_HEAD (&dev->cmd_list); dev->udev = udev;/* Point to output device context in dcbaa. */
drivers/usb/host/xhci-ring.c +15 -69
167 lines not on this page · raw message
drivers/usb/host/xhci.c +2 -14
@@ -2626,8 +2626,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,return -ENOMEM ; } -list_add_tail (&command->cmd_list, &virt_dev->cmd_list); -if (!ctx_change) ret = xhci_queue_configure_endpoint(xhci, command, command->in_ctx->dma,
@@ -2637,7 +2635,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, command->in_ctx->dma, udev->slot_id, must_succeed);if (ret <0 ) { -list_del (&command->cmd_list);if ((xhci->quirks &XHCI_EP_LIMIT_QUIRK ))xhci_free_host_resources (xhci, ctrl_ctx);spin_unlock_irqrestore (&xhci->lock, flags);
@@ -3499,11 +3496,9 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)/* Attempt to submit the Reset Device command to the command ring */ spin_lock_irqsave (&xhci->lock, flags); -list_add_tail (&reset_device_cmd->cmd_list, &virt_dev->cmd_list); ret =xhci_queue_reset_device (xhci, reset_device_cmd, slot_id);if (ret) {xhci_dbg (xhci,"FIXME: allocate a command ring segment\n" ); -list_del (&reset_device_cmd->cmd_list);spin_unlock_irqrestore (&xhci->lock, flags); goto command_cleanup; }
@@ -3517,13 +3512,6 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)if (timeleft <=0 ) {xhci_warn (xhci,"%s while waiting for reset device command\n" , timeleft ==0 ?"Timeout" :"Signal" ); -spin_lock_irqsave (&xhci->lock, flags); -/* The timeout might have raced with the event ring handler, so -* only delete from the list if the item isn't poisoned. -*/ -if (reset_device_cmd->cmd_list.next !=LIST_POISON1 ) -list_del (&reset_device_cmd->cmd_list); -spin_unlock_irqrestore (&xhci->lock, flags); ret = -ETIME ; goto command_cleanup; }
@@ -3895,7 +3883,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,return -ETIME ; } -switch (virt_dev->cmd_status) { +switch (command->status) {case COMP_CTX_STATE :case COMP_EBADSLT : xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n",
@@ -3918,7 +3906,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,default :xhci_err (xhci,"ERROR: unexpected setup %s command completion code 0x%x.\n" , - act, virt_dev->cmd_status); + act, command->status);xhci_dbg (xhci,"Slot ID %d Output Context:\n" , udev->slot_id);xhci_dbg_ctx (xhci, virt_dev->out_ctx,2 );trace_xhci_address_ctx (xhci, virt_dev->out_ctx,1 );
drivers/usb/host/xhci.h +0 -3
@@ -937,9 +937,6 @@ struct xhci_virt_device {#define XHCI_MAX_RINGS_CACHED 31struct xhci_virt_ep eps[31 ];struct completion cmd_completion; -/* Status of the last command issued for this device */ -u32 cmd_status; -struct list_head cmd_list;u8 fake_port;u8 real_port;struct xhci_interval_bw_table *bw_table;
Signature · 1 line
1.8.3.2
PATCH 10/10 xhci: rework command timeout and cancellation,
In reply to Mathias NymanUse one timer to control command timeout.
start/kick the timer every time a command is completed and a new command is waiting, or a new command is added to a empty list.
If the timer runs out, then tag the current command as "aborted", and start the xhci command abortion process.
Previously each function that submitted a command had its own timer. If that command timed out, a new command structure for the command was created and it was put on a cancel_cmd_list list, then a pci write to abort the command ring was issued.
when the ring was aborted, it checked if the current command was the one to be canceled, later when the ring was stopped the driver got ownership of the TRBs in the command ring, compared then to the TRBs in the cancel_cmd_list,
and turned them into No-ops.
Now, instead, at timeout we tag the status of the command in the command queue to be aborted, and start the ring abortion. Ring abortion stops the command ring and gives control of the commands to us.
All the aborted commands are now turned into No-ops.
If the ring is already stopped when the command times outs its not possible to start the ring abortion, in this case the command is turnd to No-op right away.
All these changes allows us to remove the entire cancel_cmd_list code.
The functions waiting for a command to finish no longer have their own timeouts. They will wait either until the command completes normally,
or until the whole command abortion is done.
--- drivers/usb/host/xhci-hub.c | 11 +- drivers/usb/host/xhci-mem.c | 14 +- drivers/usb/host/xhci-ring.c | 378 +++++++++++++++---------------------------- drivers/usb/host/xhci.c | 78 +++------ drivers/usb/host/xhci.h | 8 +- 5 files changed, 169 insertions(+), 320 deletions(-)
drivers/usb/host/xhci-hub.c +4 -7
@@ -271,7 +271,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)struct xhci_virt_device *virt_dev;struct xhci_command *cmd;unsigned long flags; -int timeleft;int ret;int i;
@@ -304,12 +303,10 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)spin_unlock_irqrestore (&xhci->lock, flags);/* Wait for last stop endpoint command to finish */ - timeleft =wait_for_completion_interruptible_timeout ( - cmd->completion, -XHCI_CMD_DEFAULT_TIMEOUT ); -if (timeleft <=0 ) { -xhci_warn (xhci,"%s while waiting for stop endpoint command\n" , - timeleft ==0 ?"Timeout" :"Signal" ); +wait_for_completion (cmd->completion); + +if (cmd->status ==COMP_CMD_ABORT || cmd->status ==COMP_CMD_STOP ) { +xhci_warn (xhci,"Timeout while waiting for stop endpoint command\n" ); ret = -ETIME ; }xhci_free_command (xhci, cmd);
drivers/usb/host/xhci-mem.c +7 -7
@@ -1793,10 +1793,11 @@ void xhci_free_command(struct xhci_hcd *xhci,void xhci_mem_cleanup (struct xhci_hcd *xhci) {struct device *dev =xhci_to_hcd (xhci)->self.controller; -struct xhci_cd *cur_cd, *next_cd;int size;int i, j, num_ports; +del_timer_sync (&xhci->cmd_timer); +/* Free the Event Ring Segment Table and the actual Event Ring */ size =sizeof (struct xhci_erst_entry )*(xhci->erst.num_entries);if (xhci->erst.entries)
@@ -1815,11 +1816,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)xhci_ring_free (xhci, xhci->cmd_ring); xhci->cmd_ring =NULL ;xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Freed command ring" ); -list_for_each_entry_safe (cur_cd, next_cd, - &xhci->cancel_cmd_list, cancel_cmd_list) { -list_del (&cur_cd->cancel_cmd_list); -kfree (cur_cd); - }xhci_cleanup_command_queue (xhci);for (i =1 ; i <MAX_HC_SLOTS ; ++i)
@@ -2323,7 +2319,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)u32 page_size, temp;int i; -INIT_LIST_HEAD (&xhci->cancel_cmd_list);INIT_LIST_HEAD (&xhci->cmd_list); page_size =readl (&xhci->op_regs->page_size);
@@ -2510,6 +2505,11 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) "Wrote ERST address to ir_set 0.");xhci_print_ir_set (xhci,0 ); +/* init command timeout timer */ +init_timer (&xhci->cmd_timer); + xhci->cmd_timer.data = (unsigned long ) xhci; + xhci->cmd_timer.function = xhci_handle_command_timeout; +/* * XXX: Might need to set the Interrupter Moderation Register to * something other than the default (~1ms minimum between interrupts).
drivers/usb/host/xhci-ring.c +128 -250
430 lines not on this page · raw message
drivers/usb/host/xhci.c +26 -52
150 lines not on this page · raw message
drivers/usb/host/xhci.h +4 -4
@@ -1295,7 +1295,6 @@ struct xhci_td {/* command descriptor */ struct xhci_cd { -struct list_head cancel_cmd_list;struct xhci_command *command;union xhci_trb *cmd_trb; };
@@ -1480,9 +1479,10 @@ struct xhci_hcd {#define CMD_RING_STATE_RUNNING (1 << 0)#define CMD_RING_STATE_ABORTED (1 << 1)#define CMD_RING_STATE_STOPPED (1 << 2) -struct list_head cancel_cmd_list;struct list_head cmd_list;unsigned int cmd_ring_reserved_trbs; +struct timer_list cmd_timer; +struct xhci_command *current_cmd;struct xhci_ring *event_ring;struct xhci_erst erst;/* Scratchpad */
@@ -1845,8 +1845,8 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, struct xhci_dequeue_state *deq_state);void xhci_stop_endpoint_command_watchdog (unsigned long arg); -int xhci_cancel_cmd (struct xhci_hcd *xhci,struct xhci_command *command, -union xhci_trb *cmd_trb); +void xhci_handle_command_timeout (unsigned long data); +void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id);void xhci_cleanup_command_queue (struct xhci_hcd *xhci);
Signature · 1 line
1.8.3.2
Quoted 4 lines · Mathias Nyman
Hi Greg
These following xhci patches are for usb-next and hopefully for 3.16
Quoted 8 lines
This patcheseries includes a bigger change in xhci command queue code, (last four patches), a task that I've been working on for a longer time. Sarah gave green light for v5 before she went on her sabbatical.
http://marc.info/?l=linux-usb&m=139889908701592&w=2
-Mathias
Ping
Any chance of getting these into your usb-next tree?
-Mathias
Greg KH
maintainerQuoted 9 lines · Mathias Nyman
Hi Greg
These following xhci patches are for usb-next and hopefully for 3.16
This patcheseries includes a bigger change in xhci command queue code, (last four patches), a task that I've been working on for a longer time. Sarah gave green light for v5 before she went on her sabbatical.
I've applied 9 of these.
thanks,
greg k-h