xhci: Don't issue Reset Device command to Etron xHCI host
Subsystems (3)
PATCH 1/1 xhci: Don't issue Reset Device command to Etron xHCI host
Sometimes hub driver does not recognize USB device that is connected to external USB2.0 Hub when system resumes from S4.
This happens when xHCI driver issue Reset Device command to inform Etron xHCI host that USB device has been reset.
Seems that Etron xHCI host can not perform this command correctly, affecting that USB device.
Instead, to aviod this, xHCI driver should reassign device slot ID by calling xhci_free_dev() and then xhci_alloc_dev(), the effect is the same.
Add XHCI_ETRON_HOST quirk flag to invoke workaround in xhci_discover_or_reset_device().
--- drivers/usb/host/xhci-pci.c | 2 ++ drivers/usb/host/xhci.c | 11 ++++++++++- drivers/usb/host/xhci.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-pci.c +2 -0
@@ -395,11 +395,13 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device == PCI_DEVICE_ID_EJ168) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; }if (pdev->vendor ==PCI_VENDOR_ID_ETRON && pdev->device ==PCI_DEVICE_ID_EJ188 ) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; } if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
drivers/usb/host/xhci.c +10 -1
@@ -3752,6 +3752,15 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd, SLOT_STATE_DISABLED)return 0 ; +if (xhci->quirks &XHCI_ETRON_HOST ) { +xhci_free_dev (hcd, udev); + ret =xhci_alloc_dev (hcd, udev); +if (ret ==1 ) +return 0 ; +else +return -EINVAL ; + } +trace_xhci_discover_or_reset_device (slot_ctx);xhci_dbg (xhci,"Resetting device with slot ID %u\n" , slot_id);
@@ -3862,7 +3871,7 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,* disconnected, and all traffic has been stopped and the endpoints have been * disabled. Free any HC data structures associated with that device. */ -static void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev) +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);struct xhci_virt_device *virt_dev;
drivers/usb/host/xhci.h +2 -0
@@ -1627,6 +1627,7 @@ struct xhci_hcd {#define XHCI_RESET_TO_DEFAULT BIT_ULL(44)#define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(45)#define XHCI_ZHAOXIN_HOST BIT_ULL(46) +#define XHCI_ETRON_HOST BIT_ULL(47)unsigned int num_active_eps;unsigned int limit_active_eps;
@@ -1863,6 +1864,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);irqreturn_t xhci_irq (struct usb_hcd *hcd);irqreturn_t xhci_msi_irq (int irq,void *hcd);int xhci_alloc_dev (struct usb_hcd *hcd,struct usb_device *udev); +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev); int xhci_alloc_tt_info(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_device *hdev,
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 16 lines · Kuangyi Chiang
Sometimes hub driver does not recognize USB device that is connected to external USB2.0 Hub when system resumes from S4.
This happens when xHCI driver issue Reset Device command to inform Etron xHCI host that USB device has been reset.
Seems that Etron xHCI host can not perform this command correctly, affecting that USB device.
Instead, to aviod this, xHCI driver should reassign device slot ID by calling
xhci_free_dev()and thenxhci_alloc_dev(), the effect is the same.Add
XHCI_ETRON_HOSTquirk flag to invoke workaround inxhci_discover_or_reset_device().
Quoted 7 lines
Cc <[email protected]>Signed-off-by Kuangyi Chiang <[email protected]>--- drivers/usb/host/xhci-pci.c | 2 ++ drivers/usb/host/xhci.c | 11 ++++++++++- drivers/usb/host/xhci.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
Greg KH
maintainerQuoted 6 lines · Kuangyi Chiang
Sometimes hub driver does not recognize USB device that is connected to external USB2.0 Hub when system resumes from S4.
This happens when xHCI driver issue Reset Device command to inform Etron xHCI host that USB device has been reset.
Quoted 6 lines
Seems that Etron xHCI host can not perform this command correctly, affecting that USB device.
Instead, to aviod this, xHCI driver should reassign device slot ID by calling
xhci_free_dev()and thenxhci_alloc_dev(), the effect is the same.
How is freeing and then allocating the device doing anything?
Quoted 35 lines
Add
XHCI_ETRON_HOSTquirk flag to invoke workaround inxhci_discover_or_reset_device().Cc <[email protected]>Signed-off-by Kuangyi Chiang <[email protected]>--- drivers/usb/host/xhci-pci.c | 2 ++ drivers/usb/host/xhci.c | 11 ++++++++++- drivers/usb/host/xhci.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)drivers/usb/host/xhci-pci.c +2
-0@@ -395,11 +395,13 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device == PCI_DEVICE_ID_EJ168) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; }if (pdev->vendor ==PCI_VENDOR_ID_ETRON && pdev->device ==PCI_DEVICE_ID_EJ188 ) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; } if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&drivers/usb/host/xhci.c +0
-0
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3757
Quoted 6 lines
drivers/usb/host/xhci.c +3
-0@@ -3752,6 +3752,15 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd, SLOT_STATE_DISABLED)return 0 ; +if (xhci->quirks &XHCI_ETRON_HOST ) { +xhci_free_dev (hcd, udev); + ret =xhci_alloc_dev (hcd, udev);
Wait, why are you freeing and then allocating the same device? That needs a lot of documentation here.
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3759
Quoted 2 lines
drivers/usb/host/xhci.c +2
-0+if (ret ==1 ) +return 0 ;
And why does the function return 1?
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3874
Quoted 13 lines
drivers/usb/host/xhci.c +5
-1+else +return -EINVAL ; + } +trace_xhci_discover_or_reset_device (slot_ctx);xhci_dbg (xhci,"Resetting device with slot ID %u\n" , slot_id);@@ -3862,7 +3871,7 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,* disconnected, and all traffic has been stopped and the endpoints have been * disabled. Free any HC data structures associated with that device. */ -static void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev) +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev)
Why is this now global if you are only calling it in the same file?
drivers/usb/host/xhci.h struct xhci_hcd { · line 1630
Quoted 12 lines
drivers/usb/host/xhci.c +0
-0{struct xhci_hcd *xhci =hcd_to_xhci (hcd);struct xhci_virt_device *virt_dev;drivers/usb/host/xhci.h +1
-0@@ -1627,6 +1627,7 @@ struct xhci_hcd {#define XHCI_RESET_TO_DEFAULT BIT_ULL(44)#define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(45)#define XHCI_ZHAOXIN_HOST BIT_ULL(46) +#define XHCI_ETRON_HOST BIT_ULL(47)
Defining bit quirks just based on the vendor seems wrong to me, as that information can be determined when needed at any time just by the pci id, right? So why is a quirk bit needed?
Shouldn't the quirk bit say what the broken functionality is? Same probably for the XHCI_ZHAOXIN_HOST, but that's not your issue to solve...
drivers/usb/host/xhci.h int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg); · line 1867
Quoted 8 lines
drivers/usb/host/xhci.h +1
-0unsigned int num_active_eps;unsigned int limit_active_eps;@@ -1863,6 +1864,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);irqreturn_t xhci_irq (struct usb_hcd *hcd);irqreturn_t xhci_msi_irq (int irq,void *hcd);int xhci_alloc_dev (struct usb_hcd *hcd,struct usb_device *udev); +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev);
Should not be needed.
thanks,
greg k-h
Hi Greg,
Greg KH <[email protected]> 於 2024年6月12日 週三 下午3:07寫道:
Quoted 8 lines · Kuangyi Chiang
Quoted 6 lines
Sometimes hub driver does not recognize USB device that is connected to external USB2.0 Hub when system resumes from S4.
This happens when xHCI driver issue Reset Device command to inform Etron xHCI host that USB device has been reset.
Quoted 8 lines
Quoted 6 lines
Seems that Etron xHCI host can not perform this command correctly, affecting that USB device.
Instead, to aviod this, xHCI driver should reassign device slot ID by calling
xhci_free_dev()and thenxhci_alloc_dev(), the effect is the same.How is freeing and then allocating the device doing anything?
To replace the Reset Device command, I found another way to inform Etron xHCI host that the USB device has been reset, which is to issue the Disable Slot command and then the Enable Slot command to Etron xHCI host.
The easy way to issue these commands in sequence is by calling xhci_free_dev() and then xhci_alloc_dev(). Apply this patch then the issue is gone.
Quoted 39 lines
Quoted 39 lines
Add
XHCI_ETRON_HOSTquirk flag to invoke workaround inxhci_discover_or_reset_device().Cc <[email protected]>Signed-off-by Kuangyi Chiang <[email protected]>--- drivers/usb/host/xhci-pci.c | 2 ++ drivers/usb/host/xhci.c | 11 ++++++++++- drivers/usb/host/xhci.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)drivers/usb/host/xhci-pci.c +2
-0@@ -395,11 +395,13 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device == PCI_DEVICE_ID_EJ168) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; }if (pdev->vendor ==PCI_VENDOR_ID_ETRON && pdev->device ==PCI_DEVICE_ID_EJ188 ) { xhci->quirks |=XHCI_RESET_ON_RESUME ; xhci->quirks |=XHCI_BROKEN_STREAMS ; + xhci->quirks |=XHCI_ETRON_HOST ; } if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&drivers/usb/host/xhci.c +0
-0@@ -3752,6 +3752,15 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd, SLOT_STATE_DISABLED)return 0 ;
Quoted 6 lines
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3757
Quoted 3 lines
drivers/usb/host/xhci.c +3
-0+if (xhci->quirks &XHCI_ETRON_HOST ) { +xhci_free_dev (hcd, udev); + ret =xhci_alloc_dev (hcd, udev);Wait, why are you freeing and then allocating the same device? That needs a lot of documentation here.
OK, I will add a comment here.
Quoted 5 lines
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3759
Quoted 3 lines
drivers/usb/host/xhci.c +2
-0+if (ret ==1 ) +return 0 ;And why does the function return 1?
xhci_alloc_dev() function returns 1 on success.
Quoted 7 lines
Quoted 7 lines
drivers/usb/host/xhci.c +4
-0+else +return -EINVAL ; + } +trace_xhci_discover_or_reset_device (slot_ctx);
Quoted 9 lines
drivers/usb/host/xhci.c static int xhci_discover_or_reset_device(struct usb_hcd *hcd, · line 3874
Quoted 7 lines
drivers/usb/host/xhci.c +1
-1xhci_dbg (xhci,"Resetting device with slot ID %u\n" , slot_id);@@ -3862,7 +3871,7 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,* disconnected, and all traffic has been stopped and the endpoints have been * disabled. Free any HC data structures associated with that device. */ -static void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev) +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev)Why is this now global if you are only calling it in the same file?
Try to fix compile error like this:drivers/usb/host/xhci.c: In function ‘xhci_discover_or_reset_device’:drivers/usb/host/xhci.c:3756:3: error: implicit declaration of function ‘xhci_free_dev’ [-Werror=implicit-function-declaration]
OK, I will revert it and put xhci_free_dev() function declaration near xhci_discover_or_reset_device() in the same file.
Quoted 19 lines
Quoted 10 lines
drivers/usb/host/xhci.c +0
-0{struct xhci_hcd *xhci =hcd_to_xhci (hcd);struct xhci_virt_device *virt_dev;drivers/usb/host/xhci.h +0
-0drivers/usb/host/xhci.h struct xhci_hcd { · line 1630
Quoted 4 lines
drivers/usb/host/xhci.h +1
-0@@ -1627,6 +1627,7 @@ struct xhci_hcd {#define XHCI_RESET_TO_DEFAULT BIT_ULL(44)#define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(45)#define XHCI_ZHAOXIN_HOST BIT_ULL(46) +#define XHCI_ETRON_HOST BIT_ULL(47)Defining bit quirks just based on the vendor seems wrong to me, as that information can be determined when needed at any time just by the pci id, right? So why is a quirk bit needed?
Quoted 3 lines
Shouldn't the quirk bit say what the broken functionality is? Same probably for the
XHCI_ZHAOXIN_HOST, but that's not your issue to solve...
The XHCI_ETRON_HOST quirk bit is used to solve more issues encountered only by Etron xHCI host.
Would you like me to check the PCI ID like this?
if (dev_is_pci(hcd->self.controller) &&
to_pci_dev(hcd->self.controller)->vendor == 0x1b6f) {
...
}If so, I will modify it and resend this patch.
Quoted 11 lines
drivers/usb/host/xhci.h int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg); · line 1867
Quoted 9 lines
drivers/usb/host/xhci.h +1
-0unsigned int num_active_eps;unsigned int limit_active_eps;@@ -1863,6 +1864,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);irqreturn_t xhci_irq (struct usb_hcd *hcd);irqreturn_t xhci_msi_irq (int irq,void *hcd);int xhci_alloc_dev (struct usb_hcd *hcd,struct usb_device *udev); +void xhci_free_dev (struct usb_hcd *hcd,struct usb_device *udev);Should not be needed.
OK, I will remove it and resend this patch.
Quoted 4 lines
thanks,
greg k-h
Thanks,
Kuangyi Chiang