Handle PM events for pci resume
Subsystems (5)
v2 cover Handle PM events for pci resume
This series includes enhancements to the PCI resume function that allow it to handle PM events in order to improve the XHCI system resume time.
v2:
- use the same indentation style.
- keep same function name.
- avoid wrapper for uhci_resume.
- use pm_message_t type for PM events.
- reword commit title and commit message accordingly.
Basavaraj Natikar (2):
USB: Extend pci resume function to handle PM events
xhci: Improve the XHCI system resume time
drivers/usb/core/hcd-pci.c | 24 +++++++++++++----------- drivers/usb/host/ehci-pci.c | 3 ++- drivers/usb/host/ohci-pci.c | 8 +++++++- drivers/usb/host/uhci-pci.c | 7 ++++--- drivers/usb/host/xhci-pci.c | 4 ++-- drivers/usb/host/xhci-plat.c | 4 ++-- drivers/usb/host/xhci.c | 5 +++-- drivers/usb/host/xhci.h | 2 +- include/linux/usb/hcd.h | 2 +- 9 files changed, 35 insertions(+), 24 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 USB: Extend pci resume function to handle PM events
Currently, the pci_resume method has only a flag indicating whether the system is resuming from hibernation. In order to handle all PM events like AUTO_RESUME (runtime resume from device in D3), RESUME (system resume from s2idle, S3 or S4 states) etc change the pci_resume method to handle all PM events.
--- drivers/usb/core/hcd-pci.c | 24 +++++++++++++----------- drivers/usb/host/ehci-pci.c | 3 ++- drivers/usb/host/ohci-pci.c | 8 +++++++- drivers/usb/host/uhci-pci.c | 7 ++++--- drivers/usb/host/xhci-pci.c | 4 ++-- drivers/usb/host/xhci-plat.c | 4 ++-- drivers/usb/host/xhci.c | 3 ++- drivers/usb/host/xhci.h | 2 +- include/linux/usb/hcd.h | 2 +- 9 files changed, 34 insertions(+), 23 deletions(-)
drivers/usb/core/hcd-pci.c +13 -11
@@ -415,12 +415,15 @@ static int check_root_hub_suspended(struct device *dev)return 0 ; } -static int suspend_common (struct device *dev,bool do_wakeup) +static int suspend_common (struct device *dev,pm_message_t msg) {struct pci_dev *pci_dev =to_pci_dev (dev);struct usb_hcd *hcd =pci_get_drvdata (pci_dev); +bool do_wakeup;int retval; + do_wakeup =PMSG_IS_AUTO (msg) ? true :device_may_wakeup (dev); +/* Root hub suspend should have stopped all downstream traffic, * and all bus master traffic. And done so for both the interface * and the stub usb_device (which we check here). But maybe it
@@ -447,7 +450,7 @@ static int suspend_common(struct device *dev, bool do_wakeup) (retval == 0 && do_wakeup && hcd->shared_hcd && HCD_WAKEUP_PENDING(hcd->shared_hcd))) {if (hcd->driver->pci_resume) - hcd->driver->pci_resume (hcd, false); + hcd->driver->pci_resume (hcd, msg); retval = -EBUSY ; }if (retval)
@@ -470,7 +473,7 @@ static int suspend_common(struct device *dev, bool do_wakeup)return retval; } -static int resume_common (struct device *dev,int event) +static int resume_common (struct device *dev,pm_message_t msg) {struct pci_dev *pci_dev =to_pci_dev (dev);struct usb_hcd *hcd =pci_get_drvdata (pci_dev);
@@ -498,12 +501,11 @@ static int resume_common(struct device *dev, int event)* No locking is needed because PCI controller drivers do not * get unbound during system resume. */ -if (pci_dev->class ==CL_EHCI && event !=PM_EVENT_AUTO_RESUME ) +if (pci_dev->class ==CL_EHCI && msg.event !=PM_EVENT_AUTO_RESUME )for_each_companion (pci_dev, hcd, ehci_wait_for_companions); - retval = hcd->driver->pci_resume (hcd, - event ==PM_EVENT_RESTORE ); + retval = hcd->driver->pci_resume (hcd, msg);if (retval) {dev_err (dev,"PCI post-resume error %d!\n" , retval);usb_hc_died (hcd);
@@ -516,7 +518,7 @@ static int resume_common(struct device *dev, int event)static int hcd_pci_suspend (struct device *dev) { -return suspend_common (dev,device_may_wakeup (dev)); +return suspend_common (dev,PMSG_SUSPEND ); }static int hcd_pci_suspend_noirq (struct device *dev)
@@ -577,12 +579,12 @@ static int hcd_pci_resume_noirq(struct device *dev)static int hcd_pci_resume (struct device *dev) { -return resume_common (dev,PM_EVENT_RESUME ); +return resume_common (dev,PMSG_RESUME ); }static int hcd_pci_restore (struct device *dev) { -return resume_common (dev,PM_EVENT_RESTORE ); +return resume_common (dev,PMSG_RESTORE ); }#else
@@ -600,7 +602,7 @@ static int hcd_pci_runtime_suspend(struct device *dev) {int retval; - retval =suspend_common (dev, true); + retval =suspend_common (dev,PMSG_AUTO_SUSPEND );if (retval ==0 )powermac_set_asic (to_pci_dev (dev),0 );dev_dbg (dev,"hcd_pci_runtime_suspend: %d\n" , retval);
@@ -612,7 +614,7 @@ static int hcd_pci_runtime_resume(struct device *dev)int retval;powermac_set_asic (to_pci_dev (dev),1 ); - retval =resume_common (dev,PM_EVENT_AUTO_RESUME ); + retval =resume_common (dev,PMSG_AUTO_RESUME );dev_dbg (dev,"hcd_pci_runtime_resume: %d\n" , retval);return retval; }
drivers/usb/host/ehci-pci.c +2 -1
@@ -354,10 +354,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)* Also they depend on separate root hub suspend/resume. */ -static int ehci_pci_resume (struct usb_hcd *hcd,bool hibernated) +static int ehci_pci_resume (struct usb_hcd *hcd,pm_message_t msg) {struct ehci_hcd *ehci =hcd_to_ehci (hcd);struct pci_dev *pdev =to_pci_dev (hcd->self.controller); +bool hibernated = (msg.event ==PM_EVENT_RESTORE );if (ehci_resume (hcd, hibernated) !=0 ) (void )ehci_pci_reinit (ehci, pdev);
drivers/usb/host/ohci-pci.c +7 -1
@@ -301,6 +301,12 @@ static struct pci_driver ohci_pci_driver = {#endif }; +#ifdef CONFIG_PM +static int ohci_pci_resume (struct usb_hcd *hcd,pm_message_t msg) +{ +return ohci_resume (hcd, msg.event ==PM_EVENT_RESTORE ); +} +#endif static int __init ohci_pci_init (void ) {if (usb_disabled ())
@@ -311,7 +317,7 @@ static int __init ohci_pci_init(void)#ifdef CONFIG_PM /* Entries for the PCI suspend/resume callbacks are special */ ohci_pci_hc_driver.pci_suspend = ohci_suspend; - ohci_pci_hc_driver.pci_resume = ohci_resume; + ohci_pci_hc_driver.pci_resume = ohci_pci_resume;#endif return pci_register_driver (&ohci_pci_driver);
drivers/usb/host/uhci-pci.c +4 -3
@@ -167,7 +167,7 @@ static void uhci_shutdown(struct pci_dev *pdev)#ifdef CONFIG_PM -static int uhci_pci_resume (struct usb_hcd *hcd,bool hibernated); +static int uhci_pci_resume (struct usb_hcd *hcd,pm_message_t state);static int uhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {
@@ -202,14 +202,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)/* Check for race with a wakeup request */ if (do_wakeup &&HCD_WAKEUP_PENDING (hcd)) { -uhci_pci_resume (hcd, false); +uhci_pci_resume (hcd,PMSG_SUSPEND ); rc = -EBUSY ; }return rc; } -static int uhci_pci_resume (struct usb_hcd *hcd,bool hibernated) +static int uhci_pci_resume (struct usb_hcd *hcd,pm_message_t msg) { +bool hibernated = (msg.event ==PM_EVENT_RESTORE );struct uhci_hcd *uhci =hcd_to_uhci (hcd);dev_dbg (uhci_dev (uhci),"%s\n" , __func__);
drivers/usb/host/xhci-pci.c +2 -2
@@ -628,7 +628,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)return ret; } -static int xhci_pci_resume (struct usb_hcd *hcd,bool hibernated) +static int xhci_pci_resume (struct usb_hcd *hcd,pm_message_t msg) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);struct pci_dev *pdev =to_pci_dev (hcd->self.controller);
@@ -663,7 +663,7 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)if (xhci->quirks &XHCI_PME_STUCK_QUIRK )xhci_pme_quirk (hcd); - retval =xhci_resume (xhci, hibernated); + retval =xhci_resume (xhci, msg);return retval; }
drivers/usb/host/xhci-plat.c +2 -2
@@ -465,7 +465,7 @@ static int __maybe_unused xhci_plat_resume(struct device *dev)if (ret)return ret; - ret =xhci_resume (xhci,0 ); + ret =xhci_resume (xhci,PMSG_ON );if (ret)return ret;
@@ -494,7 +494,7 @@ static int __maybe_unused xhci_plat_runtime_resume(struct device *dev)struct usb_hcd *hcd =dev_get_drvdata (dev);struct xhci_hcd *xhci =hcd_to_xhci (hcd); -return xhci_resume (xhci,0 ); +return xhci_resume (xhci,PMSG_ON ); }const struct dev_pm_ops xhci_plat_pm_ops = {
drivers/usb/host/xhci.c +2 -1
@@ -1157,8 +1157,9 @@ EXPORT_SYMBOL_GPL(xhci_suspend);* This is called when the machine transition from S3/S4 mode. * */ -int xhci_resume (struct xhci_hcd *xhci,bool hibernated) +int xhci_resume (struct xhci_hcd *xhci,pm_message_t msg) { +bool hibernated = (msg.event ==PM_EVENT_RESTORE );u32 command, temp =0 ;struct usb_hcd *hcd =xhci_to_hcd (xhci);int retval =0 ;
drivers/usb/host/xhci.h +1 -1
@@ -2139,7 +2139,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);int xhci_ext_cap_init (struct xhci_hcd *xhci);int xhci_suspend (struct xhci_hcd *xhci,bool do_wakeup); -int xhci_resume (struct xhci_hcd *xhci,bool hibernated); +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);
include/linux/usb/hcd.h +1 -1
@@ -267,7 +267,7 @@ struct hc_driver {int (*pci_suspend)(struct usb_hcd *hcd,bool do_wakeup);/* called after entering D0 (etc), before resuming the hub */ -int (*pci_resume)(struct usb_hcd *hcd,bool hibernated); +int (*pci_resume)(struct usb_hcd *hcd,pm_message_t state);/* called just before hibernate final D3 state, allows host to poweroff parts */ int (*pci_poweroff_late)(struct usb_hcd *hcd,bool do_wakeup);
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v2 1/2] USB: Extend pci resume function to handle PM events
kernel test robot noticed the following build errors:
Hi Basavaraj,
kernel test robot noticed the following build errors:
[auto build test ERROR on usb/usb-testing]
[also build test ERROR on usb/usb-next usb/usb-linus linus/master v6.3 next-20230426] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Basavaraj-Natikar/USB-Extend-pci-resume-function-to-handle-PM-events/20230427-185141 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing patch link: https://lore.kernel.org/r/20230427104805.3560591-2-Basavaraj.Natikar%40amd.com patch subject: [PATCH v2 1/2] USB: Extend pci resume function to handle PM events config: arc-randconfig-r043-20230427 (https://download.01.org/0day-ci/archive/20230427/[email protected]/config) compiler: arceb-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c56600f81d90e04002ac435d27ccd0358b560d88
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Basavaraj-Natikar/USB-Extend-pci-resume-function-to-handle-PM-events/20230427-185141 git checkout c56600f81d90e04002ac435d27ccd0358b560d88
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash drivers/usb/host/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/usb/host/xhci-histb.c: In function 'xhci_histb_resume':
>> drivers/usb/host/xhci-histb.c:370:34: error: incompatible type for argument 2 of 'xhci_resume'
370 | return xhci_resume(xhci, 0);
| ^
| |
| int
In file included from drivers/usb/host/xhci-histb.c:19:
drivers/usb/host/xhci.h:2143:53: note: expected 'pm_message_t' {aka 'struct pm_message'} but argument is of type 'int'
2143 | int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);
| ~~~~~~~~~~~~~^~~vim +/xhci_resume +370 drivers/usb/host/xhci-histb.c
c508f41da07882 Jianguo Sun 2018-05-21 360
c508f41da07882 Jianguo Sun 2018-05-21 361 static int __maybe_unused xhci_histb_resume(struct device *dev)
c508f41da07882 Jianguo Sun 2018-05-21 362 {
c508f41da07882 Jianguo Sun 2018-05-21 363 struct xhci_hcd_histb *histb = dev_get_drvdata(dev);
c508f41da07882 Jianguo Sun 2018-05-21 364 struct usb_hcd *hcd = histb->hcd;
c508f41da07882 Jianguo Sun 2018-05-21 365 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
c508f41da07882 Jianguo Sun 2018-05-21 366
c508f41da07882 Jianguo Sun 2018-05-21 367 if (!device_may_wakeup(dev))
c508f41da07882 Jianguo Sun 2018-05-21 368 xhci_histb_host_enable(histb);
c508f41da07882 Jianguo Sun 2018-05-21 369 c508f41da07882 Jianguo Sun 2018-05-21 @370 return xhci_resume(xhci, 0);c508f41da07882 Jianguo Sun 2018-05-21 371 }c508f41da07882 Jianguo Sun 2018-05-21 372
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH v2 1/2] USB: Extend pci resume function to handle PM events
In reply to Basavaraj Natikarkernel test robot noticed the following build errors:
Hi Basavaraj,
kernel test robot noticed the following build errors:
[auto build test ERROR on usb/usb-testing]
[also build test ERROR on usb/usb-next usb/usb-linus linus/master v6.3 next-20230426] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Basavaraj-Natikar/USB-Extend-pci-resume-function-to-handle-PM-events/20230427-185141 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing patch link: https://lore.kernel.org/r/20230427104805.3560591-2-Basavaraj.Natikar%40amd.com patch subject: [PATCH v2 1/2] USB: Extend pci resume function to handle PM events config: hexagon-randconfig-r045-20230427 (https://download.01.org/0day-ci/archive/20230427/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c56600f81d90e04002ac435d27ccd0358b560d88
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Basavaraj-Natikar/USB-Extend-pci-resume-function-to-handle-PM-events/20230427-185141 git checkout c56600f81d90e04002ac435d27ccd0358b560d88
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/usb/host/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/usb/host/xhci-histb.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from drivers/usb/host/xhci-histb.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from drivers/usb/host/xhci-histb.c:11:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
>> drivers/usb/host/xhci-histb.c:370:27: error: passing 'int' to parameter of incompatible type 'pm_message_t' (aka 'struct pm_message')
return xhci_resume(xhci, 0);
^
drivers/usb/host/xhci.h:2143:53: note: passing argument to parameter 'msg' here
int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);
^6 warnings and 1 error generated.
vim +370 drivers/usb/host/xhci-histb.c
c508f41da07882 Jianguo Sun 2018-05-21 360
c508f41da07882 Jianguo Sun 2018-05-21 361 static int __maybe_unused xhci_histb_resume(struct device *dev)
c508f41da07882 Jianguo Sun 2018-05-21 362 {
c508f41da07882 Jianguo Sun 2018-05-21 363 struct xhci_hcd_histb *histb = dev_get_drvdata(dev);
c508f41da07882 Jianguo Sun 2018-05-21 364 struct usb_hcd *hcd = histb->hcd;
c508f41da07882 Jianguo Sun 2018-05-21 365 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
c508f41da07882 Jianguo Sun 2018-05-21 366
c508f41da07882 Jianguo Sun 2018-05-21 367 if (!device_may_wakeup(dev))
c508f41da07882 Jianguo Sun 2018-05-21 368 xhci_histb_host_enable(histb);
c508f41da07882 Jianguo Sun 2018-05-21 369 c508f41da07882 Jianguo Sun 2018-05-21 @370 return xhci_resume(xhci, 0);c508f41da07882 Jianguo Sun 2018-05-21 371 }c508f41da07882 Jianguo Sun 2018-05-21 372
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
PATCH v2 2/2 xhci: Improve the XHCI system resume time
In reply to Basavaraj NatikarAvoid extra 120ms delay during system resume.
The xHC controller may signal wake up to 120ms before showing which usb device caused the wake on the xHC port registers.
The xhci driver therefore checks for port activity up to 120ms during resume, making sure that the hub driver can see the port change, and won't immediately runtime suspend back due to no port activity.
This is however only needed for runtime resume as system resume will resume all child hubs and other child usb devices anyway.
--- drivers/usb/host/xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci.c +1 -1
@@ -1315,7 +1315,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)* the first wake signalling failed, give it that chance. */ pending_portevent =xhci_pending_portevent (xhci); -if (!pending_portevent) { +if (!pending_portevent && msg.event ==PM_EVENT_AUTO_RESUME ) {msleep (120 ); pending_portevent =xhci_pending_portevent (xhci); }
Signature · 1 line
2.25.1