xhci fixes for usb-linus
Subsystems (3)
cover xhci fixes for usb-linus
Hi Greg
A few fixes for usb-linus 6.18-rc
Solve an issue in the USB2 only PCI xHCI controller support added to 6.18 Solve two DbC cases that have been around since beginning of DbC support.
Thanks
Mathias
Mathias Nyman (2):
xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall
event
xhci: dbc: enable back DbC in resume if it was enabled before suspend
Michal Pecio (1):
usb: xhci-pci: Fix USB2-only root hub registration
drivers/usb/host/xhci-dbgcap.c | 15 ++++++++++++--- drivers/usb/host/xhci-pci.c | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 usb: xhci-pci: Fix USB2-only root hub registration
From: Michal Pecio <[email protected]>
A recent change to hide USB3 root hubs of USB2-only controllers broke registration of USB2 root hubs - allow_single_roothub is set too late, and by this time xhci_run() has already deferred root hub registration until after the shared HCD is added, which will never happen.
This makes such controllers unusable, but testers didn't notice since they were only bothered by warnings about empty USB3 root hubs. The bug causes problems to other people who actually use such HCs and I was able to confirm it on an ordinary HC by patching to ignore USB3 ports.
Setting allow_single_roothub during early setup fixes things.
--- drivers/usb/host/xhci-pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-pci.c +2 -1
@@ -582,6 +582,8 @@ static int xhci_pci_setup(struct usb_hcd *hcd)if (!usb_hcd_is_primary_hcd (hcd))return 0 ; + xhci->allow_single_roothub =1 ; +if (xhci->quirks &XHCI_PME_STUCK_QUIRK )xhci_pme_acpi_rtd3_enable (pdev);
@@ -637,7 +639,6 @@ int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id) xhci =hcd_to_xhci (hcd); xhci->reset = reset; - xhci->allow_single_roothub =1 ;if (!xhci_has_one_roothub (xhci)) { xhci->shared_hcd =usb_create_shared_hcd (&xhci_pci_hc_driver, &dev->dev,pci_name (dev), hcd);
Signature · 1 line
2.43.0
PATCH 2/3 xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event
In reply to Mathias NymanDbC may add 1024 bogus bytes to the beginneing of the receiving endpoint if DbC hw triggers a STALL event before any Transfer Blocks (TRBs) for incoming data are queued, but driver handles the event after it queued the TRBs.
This is possible as xHCI DbC hardware may trigger spurious STALL transfer events even if endpoint is empty. The STALL event contains a pointer to the stalled TRB, and "remaining" untransferred data length.
As there are no TRBs queued yet the STALL event will just point to first TRB position of the empty ring, with '0' bytes remaining untransferred.
DbC driver is polling for events, and may not handle the STALL event before /dev/ttyDBC0 is opened and incoming data TRBs are queued.
The DbC event handler will now assume the first queued TRB (length 1024) has stalled with '0' bytes remaining untransferred, and copies the data
This race situation can be practically mitigated by making sure the event handler handles all pending transfer events when DbC reaches configured state, and only then create dev/ttyDbC0, and start queueing transfers. The event handler can this way detect the STALL events on empty rings and discard them before any transfers are queued.
This does in practice solve the issue, but still leaves a small possible gap for the race to trigger.
We still need a way to distinguish spurious STALLs on empty rings with '0' bytes remaing, from actual STALL events with all bytes transmitted.
--- drivers/usb/host/xhci-dbgcap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-dbgcap.c +4 -2
@@ -892,7 +892,8 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)dev_info (dbc->dev,"DbC configured\n" ); portsc =readl (&dbc->regs->portsc);writel (portsc, &dbc->regs->portsc); -return EVT_GSER ; + ret =EVT_GSER ; +break ; }return EVT_DONE ;
@@ -954,7 +955,8 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)break ;case TRB_TYPE (TRB_TRANSFER ):dbc_handle_xfer_event (dbc, evt); - ret =EVT_XFER_DONE ; +if (ret !=EVT_GSER ) + ret =EVT_XFER_DONE ;break ;default :break ;
Signature · 1 line
2.43.0
PATCH 3/3 xhci: dbc: enable back DbC in resume if it was enabled before suspend
In reply to Mathias NymanDbC is currently only enabled back if it's in configured state during suspend.
If system is suspended after DbC is enabled, but before the device is properly enumerated by the host, then DbC would not be enabled back in resume.
Always enable DbC back in resume if it's suspended in enabled, connected, or configured state
--- drivers/usb/host/xhci-dbgcap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +8 -1
@@ -1392,8 +1392,15 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)if (!dbc)return 0 ; -if (dbc->state ==DS_CONFIGURED ) +switch (dbc->state) { +case DS_ENABLED : +case DS_CONNECTED : +case DS_CONFIGURED : dbc->resume_required =1 ; +break ; +default : +break ; + }xhci_dbc_stop (dbc);
Signature · 1 line
2.43.0