amd-xgbe: Improve power management for S0i3
Subsystems (3)
Raju Rangoju
maintainercover amd-xgbe: Improve power management for S0i3
Improve the amd-xgbe power management handling to allow AMD platforms to reach the deepest suspend state (S0i3) when modern standby is used.
The first patch cleans up the xgbe_powerdown() and xgbe_powerup() helpers by removing an unused caller distinction and aligning the ordering of operations with xgbe_stop().
The second patch adds proper PCI power management operations, following the standard PCI PM model, so that the device can be cleanly put into D3 and resumed back to D0. Without this, the amd_pmc driver reports:
"Last suspend didn't reach deepest state"
when the amd-xgbe driver is enabled.
These changes have been tested on AMD platforms using S0i3 modern standby.
Raju Rangoju (2):
amd-xgbe: Simplify powerdown/powerup paths
amd-xgbe: add PCI power management for S0i3 support
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 47 ++++++++----------- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 41 ++++++++++++++-- drivers/net/ethernet/amd/xgbe/xgbe-platform.c | 4 +- drivers/net/ethernet/amd/xgbe/xgbe.h | 8 +--- 4 files changed, 61 insertions(+), 39 deletions(-)
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH 1/2 amd-xgbe: Simplify powerdown/powerup paths
The caller parameter in xgbe_powerdown() and xgbe_powerup() was intended to differentiate between driver and ioctl contexts, but the only remaining usage is from the driver suspend/resume path.
Simplify this by:
- Removing the unused XGMAC_DRIVER_CONTEXT and XGMAC_IOCTL_CONTEXT macros
- Dropping the now-unused caller parameter
- Reordering operations in xgbe_powerdown() to disable NAPI before stopping TX/RX, matching the order used in xgbe_stop()
This makes the powerdown/powerup paths easier to follow and keeps the ordering consistent with the rest of the driver.
--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 47 ++++++++----------- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 8 ++-- drivers/net/ethernet/amd/xgbe/xgbe-platform.c | 4 +- drivers/net/ethernet/amd/xgbe/xgbe.h | 8 +--- 4 files changed, 28 insertions(+), 39 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +20 -27
@@ -1116,69 +1116,62 @@ static int xgbe_phy_reset(struct xgbe_prv_data *pdata)return pdata->phy_if.phy_reset (pdata); } -int xgbe_powerdown (struct net_device *netdev,unsigned int caller) +int xgbe_powerdown (struct net_device *netdev) {struct xgbe_prv_data *pdata =netdev_priv (netdev);struct xgbe_hw_if *hw_if = &pdata->hw_if; -DBGPR ("-->xgbe_powerdown\n" ); - -if (!netif_running (netdev) || - (caller ==XGMAC_IOCTL_CONTEXT && pdata->power_down)) { -netdev_alert (netdev,"Device is already powered down\n" ); -DBGPR ("<--xgbe_powerdown\n" ); +if (!netif_running (netdev)) { +netdev_dbg (netdev,"Device is not running, skipping powerdown\n" );return -EINVAL ; } -if (caller ==XGMAC_DRIVER_CONTEXT ) -netif_device_detach (netdev); +if (pdata->power_down) { +netdev_dbg (netdev,"Device is already powered down\n" ); +return -EINVAL ; + } +netif_device_detach (netdev);netif_tx_stop_all_queues (netdev);xgbe_stop_timers (pdata);flush_workqueue (pdata->dev_workqueue); +xgbe_napi_disable (pdata,0 ); + hw_if->powerdown_tx (pdata); hw_if->powerdown_rx (pdata); -xgbe_napi_disable (pdata,0 ); - pdata->power_down =1 ; -DBGPR ("<--xgbe_powerdown\n" ); -return 0 ; } -int xgbe_powerup (struct net_device *netdev,unsigned int caller) +int xgbe_powerup (struct net_device *netdev) {struct xgbe_prv_data *pdata =netdev_priv (netdev);struct xgbe_hw_if *hw_if = &pdata->hw_if; -DBGPR ("-->xgbe_powerup\n" ); - -if (!netif_running (netdev) || - (caller ==XGMAC_IOCTL_CONTEXT && !pdata->power_down)) { -netdev_alert (netdev,"Device is already powered up\n" ); -DBGPR ("<--xgbe_powerup\n" ); +if (!netif_running (netdev)) { +netdev_dbg (netdev,"Device is not running, skipping powerup\n" );return -EINVAL ; } - pdata->power_down =0 ; - -xgbe_napi_enable (pdata,0 ); +if (!pdata->power_down) { +netdev_dbg (netdev,"Device is already powered up\n" ); +return -EINVAL ; + } hw_if->powerup_tx (pdata); hw_if->powerup_rx (pdata); -if (caller ==XGMAC_DRIVER_CONTEXT ) -netif_device_attach (netdev); +xgbe_napi_enable (pdata,0 );netif_tx_start_all_queues (netdev); -xgbe_start_timers (pdata); +netif_device_attach (netdev); -DBGPR ("<--xgbe_powerup\n" ); + pdata->power_down =0 ;return 0 ; }
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +4 -4
@@ -360,14 +360,14 @@ static void xgbe_pci_remove(struct pci_dev *pdev)xgbe_free_pdata (pdata); } -static int __maybe_unused xgbe_pci_suspend (struct device *dev) +static int xgbe_pci_suspend (struct device *dev) {struct xgbe_prv_data *pdata =dev_get_drvdata (dev);struct net_device *netdev = pdata->netdev;int ret =0 ;if (netif_running (netdev)) - ret =xgbe_powerdown (netdev,XGMAC_DRIVER_CONTEXT ); + ret =xgbe_powerdown (netdev); pdata->lpm_ctrl =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 ); pdata->lpm_ctrl |=MDIO_CTRL1_LPOWER ;
@@ -376,7 +376,7 @@ static int __maybe_unused xgbe_pci_suspend(struct device *dev)return ret; } -static int __maybe_unused xgbe_pci_resume (struct device *dev) +static int xgbe_pci_resume (struct device *dev) {struct xgbe_prv_data *pdata =dev_get_drvdata (dev);struct net_device *netdev = pdata->netdev;
@@ -388,7 +388,7 @@ static int __maybe_unused xgbe_pci_resume(struct device *dev)XMDIO_WRITE (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 , pdata->lpm_ctrl);if (netif_running (netdev)) { - ret =xgbe_powerup (netdev,XGMAC_DRIVER_CONTEXT ); + ret =xgbe_powerup (netdev);/* Schedule a restart in case the link or phy state changed * while we were powered down.
drivers/net/ethernet/amd/xgbe/xgbe-platform.c +2 -2
@@ -384,7 +384,7 @@ static int xgbe_platform_suspend(struct device *dev)DBGPR ("-->xgbe_suspend\n" );if (netif_running (netdev)) - ret =xgbe_powerdown (netdev,XGMAC_DRIVER_CONTEXT ); + ret =xgbe_powerdown (netdev); pdata->lpm_ctrl =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 ); pdata->lpm_ctrl |=MDIO_CTRL1_LPOWER ;
@@ -407,7 +407,7 @@ static int xgbe_platform_resume(struct device *dev)XMDIO_WRITE (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 , pdata->lpm_ctrl);if (netif_running (netdev)) { - ret =xgbe_powerup (netdev,XGMAC_DRIVER_CONTEXT ); + ret =xgbe_powerup (netdev);/* Schedule a restart in case the link or phy state changed * while we were powered down.
drivers/net/ethernet/amd/xgbe/xgbe.h +2 -6
@@ -146,10 +146,6 @@#define XGBE_MAX_PPS_OUT 4#define XGBE_MAX_AUX_SNAP 4 -/* Driver PMT macros */ -#define XGMAC_DRIVER_CONTEXT 1 -#define XGMAC_IOCTL_CONTEXT 2 -#define XGMAC_FIFO_MIN_ALLOC 2048#define XGMAC_FIFO_UNIT 256#define XGMAC_FIFO_ALIGN (_x) \
@@ -1309,8 +1305,8 @@ void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *, unsigned int);void xgbe_print_pkt (struct net_device *,struct sk_buff *,bool );void xgbe_get_all_hw_features (struct xgbe_prv_data *); -int xgbe_powerup (struct net_device *,unsigned int ); -int xgbe_powerdown (struct net_device *,unsigned int ); +int xgbe_powerup (struct net_device *netdev); +int xgbe_powerdown (struct net_device *netdev);void xgbe_init_rx_coalesce (struct xgbe_prv_data *);void xgbe_init_tx_coalesce (struct xgbe_prv_data *);void xgbe_restart_dev (struct xgbe_prv_data *pdata);
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH net-next 1/2] amd-xgbe: Simplify powerdown/powerup paths
kernel test robot noticed the following build warnings:
Hi Raju,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Raju-Rangoju/amd-xgbe-Simplify-powerdown-powerup-paths/20260306-202410 base: net-next/main patch link: https://lore.kernel.org/r/20260306121047.1231755-2-Raju.Rangoju%40amd.com patch subject: [PATCH net-next 1/2] amd-xgbe: Simplify powerdown/powerup paths config: sparc-randconfig-001-20260307 (https://download.01.org/0day-ci/archive/20260307/[email protected]/config) compiler: sparc-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260307/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/amd/xgbe/xgbe-pci.c:379:12: warning: 'xgbe_pci_resume' defined but not used [-Wunused-function]
379 | static int xgbe_pci_resume(struct device *dev)
| ^~~~~~~~~~~~~~~
>> drivers/net/ethernet/amd/xgbe/xgbe-pci.c:363:12: warning: 'xgbe_pci_suspend' defined but not used [-Wunused-function] 363 | static int xgbe_pci_suspend(struct device *dev)
| ^~~~~~~~~~~~~~~~
vim +/xgbe_pci_resume +379 drivers/net/ethernet/amd/xgbe/xgbe-pci.c
362
> 363 static int xgbe_pci_suspend(struct device *dev)
364 {
365 struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
366 struct net_device *netdev = pdata->netdev;
367 int ret = 0;
368
369 if (netif_running(netdev))
370 ret = xgbe_powerdown(netdev);
371
372 pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
373 pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
374 XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
375
376 return ret;
377 }
378
> 379 static int xgbe_pci_resume(struct device *dev) 380 {
381 struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
382 struct net_device *netdev = pdata->netdev;
383 int ret = 0;
384
385 XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
386
387 pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
388 XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
389
390 if (netif_running(netdev)) {
391 ret = xgbe_powerup(netdev);
392
393 /* Schedule a restart in case the link or phy state changed
394 * while we were powered down.
395 */
396 schedule_work(&pdata->restart_work);
397 }
398
399 return ret;
400 }
401
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Raju Rangoju
maintainerPATCH 2/2 amd-xgbe: add PCI power management for S0i3 support
In reply to Raju RangojuThe current suspend/resume implementation does not correctly handle PCI device power state transitions, which prevents AMD platforms from reaching the deepest suspend state (S0i3) when the amd-xgbe driver is enabled.
In particular, the amd_pmc driver reports:
"Last suspend didn't reach deepest state"
when this device is present.
Implement proper PCI power management operations following the standard PCI PM model so that the device can be cleanly powered down and resumed.
Suspend path:
- Power down the network interface
- Put the PHY into low-power mode
- Disable bus mastering to prevent DMA activity
- Save PCI configuration space
- Disable the PCI device
- Disable wake from D3 (S0i3 does not require Wake-on-LAN)
- Set the device to D3hot
Resume path:
- Restore the PCI power state to D0
- Restore PCI configuration space
- Enable the PCI device
- Re-enable bus mastering
- Re-enable device interrupts
- Clear the PHY low-power mode
- Power up the network interface
This allows systems using amd-xgbe to reach the deepest suspend state when entering modern standby (S0i3).
--- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +33 -0
@@ -364,15 +364,31 @@ static int xgbe_pci_suspend(struct device *dev) {struct xgbe_prv_data *pdata =dev_get_drvdata (dev);struct net_device *netdev = pdata->netdev; +struct pci_dev *pdev =to_pci_dev (dev);int ret =0 ;if (netif_running (netdev)) ret =xgbe_powerdown (netdev); +/* Disable all device interrupts to prevent spurious wakeups */ +XP_IOWRITE (pdata,XP_INT_EN ,0x0 ); + +/* Set PHY to low-power mode */ pdata->lpm_ctrl =XMDIO_READ (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 ); pdata->lpm_ctrl |=MDIO_CTRL1_LPOWER ;XMDIO_WRITE (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 , pdata->lpm_ctrl); +/* Disable bus mastering to prevent DMA activity */ +pci_clear_master (pdev); + +/* Save PCI configuration state and disable device */ +pci_save_state (pdev); +pci_disable_device (pdev); + +/* Disable wake from D3 - required for S0i3 deep sleep */ +pci_wake_from_d3 (pdev, false); +pci_set_power_state (pdev, PCI_D3hot); +return ret; }
@@ -380,10 +396,27 @@ static int xgbe_pci_resume(struct device *dev) {struct xgbe_prv_data *pdata =dev_get_drvdata (dev);struct net_device *netdev = pdata->netdev; +struct pci_dev *pdev =to_pci_dev (dev);int ret =0 ; +/* Restore PCI power state */ +pci_set_power_state (pdev,PCI_D0 ); + +/* Restore PCI configuration state */ +pci_restore_state (pdev); + +/* Enable PCI device */ + ret =pci_enable_device (pdev); +if (ret) +return ret; + +/* Re-enable bus mastering */ +pci_set_master (pdev); + +/* Re-enable all device interrupts */ XP_IOWRITE (pdata,XP_INT_EN ,0x1fffff ); +/* Clear PHY low-power mode */ pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER ;XMDIO_WRITE (pdata,MDIO_MMD_PCS ,MDIO_CTRL1 , pdata->lpm_ctrl);
Signature · 1 line
2.34.1