xhci: wait CNR when doing xhci resume
Subsystems (2)
PATCH 1/1 xhci: wait CNR when doing xhci resume
From: Rick <[email protected]>
NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.
--- drivers/usb/host/xhci-pci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/usb/host/xhci-pci.c +20 -0
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/module.h> #include <linux/acpi.h> +#include <linux/iopoll.h> #include "xhci.h" #include "xhci-trace.h"
@@ -455,6 +456,19 @@ static void xhci_pme_quirk(struct usb_hcd *hcd)readl (reg); } +static int xhci_poll_cnr (struct usb_hcd *hcd) +{ +struct xhci_hcd *xhci =hcd_to_xhci (hcd); +void __iomem *reg = &xhci->op_regs->status; +u32 result; +int ret; + + ret =readl_poll_timeout_atomic (reg, result, + (result &STS_CNR ) ==0 , +1 ,100 *1000 ); +return ret; +} +static int xhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);
@@ -508,6 +522,12 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)if (pdev->vendor ==PCI_VENDOR_ID_INTEL )usb_enable_intel_xhci_ports (pdev); +if (pdev->vendor ==PCI_VENDOR_ID_NVIDIA ) { + retval =xhci_poll_cnr (hcd); +if (retval !=0 ) +return retval; + } +if (xhci->quirks &XHCI_SSIC_PORT_UNUSED )xhci_ssic_port_unused_quirk (hcd, false);
Signature · 9 lines
2.1.4 ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------
Hi,
drivers/usb/host/xhci-pci.c static void xhci_pme_quirk(struct usb_hcd *hcd) · line 471
Quoted 13 lines · Rick Tseng
drivers/usb/host/xhci-pci.c +13
-0+static int xhci_poll_cnr (struct usb_hcd *hcd) +{ +struct xhci_hcd *xhci =hcd_to_xhci (hcd); +void __iomem *reg = &xhci->op_regs->status; +u32 result; +int ret; + + ret =readl_poll_timeout_atomic (reg, result, + (result &STS_CNR ) ==0 , +1 ,100 *1000 ); +return ret; +} +
instead of defining your own function...
drivers/usb/host/xhci-pci.c static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) · line 526
Quoted 9 lines
static int
xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup){drivers/usb/host/xhci-pci.c +2
-0struct xhci_hcd *xhci =hcd_to_xhci (hcd);@@ -508,6 +522,12 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)if (pdev->vendor ==PCI_VENDOR_ID_INTEL )usb_enable_intel_xhci_ports (pdev); +if (pdev->vendor ==PCI_VENDOR_ID_NVIDIA ) { + retval =xhci_poll_cnr (hcd);
you could just use xhci_handshake() here, right?
Signature · 1 line
balbi
Am Montag, den 12.08.2019, 15:24 +0800 schrieb Rick Tseng:
Quoted 4 lines
From: Rick <[email protected]>
NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.
Should any controller have CNR set? Why is this specific to a vendor?
Regards
Oliver
Greg KH
maintainerQuoted 6 lines · Rick Tseng
From: Rick <[email protected]>
NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.
Signed-off-by Rick <[email protected]>
We need a "full" name on the from and signed-off-by lines, please.
Quoted 37 lines
--- drivers/usb/host/xhci-pci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)drivers/usb/host/xhci-pci.c +14
-0@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/module.h> #include <linux/acpi.h> +#include <linux/iopoll.h> #include "xhci.h" #include "xhci-trace.h" @@ -455,6 +456,19 @@ static void xhci_pme_quirk(struct usb_hcd *hcd)readl (reg); } +static int xhci_poll_cnr (struct usb_hcd *hcd) +{ +struct xhci_hcd *xhci =hcd_to_xhci (hcd); +void __iomem *reg = &xhci->op_regs->status; +u32 result; +int ret; + + ret =readl_poll_timeout_atomic (reg, result, + (result &STS_CNR ) ==0 , +1 ,100 *1000 ); +return ret; +} +static int xhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);
drivers/usb/host/xhci-pci.c static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) · line 525
Quoted 4 lines
drivers/usb/host/xhci-pci.c +1
-0@@ -508,6 +522,12 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)if (pdev->vendor ==PCI_VENDOR_ID_INTEL )usb_enable_intel_xhci_ports (pdev); +if (pdev->vendor ==PCI_VENDOR_ID_NVIDIA ) {
So all devices of this vendor need that? Are you _sure_? Why not just blacklist a single device?
thanks,
greg k-h
Quoted 8 lines · Oliver Neukum
Am Montag, den 12.08.2019, 15:24 +0800 schrieb Rick Tseng:
Quoted 4 lines
From: Rick <[email protected]>
NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.
Should any controller have CNR set? Why is this specific to a vendor?
Good point, always checking CNR in resume sounds like a good idea.
And use xhci_handshake() as Felipe pointed out, just like in xhci_reset():
ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, 10 * 1000 * 1000);
Rick, would you like to write a patch for this?
-Mathias
Hi Mathias,
Thanks for suggestion.
The reason I do not use xhci_handshake() is we get build fail when configuring below as module:USB_XHCI_HCD = mUSB_XHCI_PCI = m
Fail message as below:
ERROR: "xhci_handshake" [drivers/usb/host/xhci-pci.ko] undefined!
So I write my own function to check CNR.
Thanks,
Rick
--
nvpublic
寄件者: Mathias Nyman <[email protected]>
寄件日期: 2019年8月13日 上午 03:39
收件者: Oliver Neukum <[email protected]>; Rick Tseng <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 副本: [email protected] <[email protected]>
主旨: Re: [PATCH] xhci: wait CNR when doing xhci resume
Quoted 8 lines · Oliver Neukum
Am Montag, den 12.08.2019, 15:24 +0800 schrieb Rick Tseng:
Quoted 4 lines
From: Rick <[email protected]>
NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.
Should any controller have CNR set? Why is this specific to a vendor?
Good point, always checking CNR in resume sounds like a good idea.
And use xhci_handshake() as Felipe pointed out, just like in xhci_reset():
ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, 10 * 1000 * 1000);
Rick, would you like to write a patch for this?
-Mathias
(no top-posting, please)
Hi,
Quoted 11 lines · Rick Tseng
Hi Mathias,
Thanks for suggestion.
The reason I do not usexhci_handshake()is we get build fail when configuring below as module:USB_XHCI_HCD= mUSB_XHCI_PCI= mFail message as below:
ERROR: "xhci_handshake" [drivers/usb/host/xhci-pci.ko] undefined!So I write my own function to check CNR.
yeah, move that code to xhci_suspend(). It's valid for any XHCI host.
Signature · 1 line
balbi
Quoted 15 lines
Hi,
Quoted 11 lines · Rick Tseng
Hi Mathias,
Thanks for suggestion.
The reason I do not usexhci_handshake()is we get build fail when configuring below as module:USB_XHCI_HCD= mUSB_XHCI_PCI= mFail message as below:
ERROR: "xhci_handshake" [drivers/usb/host/xhci-pci.ko] undefined!So I write my own function to check CNR.
Adding EXPORT_SYMBOL_GPL(xhci_handshake) after the xhci_handshake() function in xhci.c should solve that.
But I agree with Felipe that checking for Controller Not Ready (CNR) is useful for any xHCI host, not just PCI xHCI hosts,
so move the CNR check to xhci_resume()
Quoted 3 lines
yeah, move that code to
xhci_suspend(). It's valid for any XHCI host.
xhci_resume()
-Mathias