Skip to contentSkip to conversation

Unify platform suspend/resume routines for PCI DWMAC glue

PATCH Superseded Yao Zi 3 participants 8 messages Oct 30, 2025 – Oct 31, 2025

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yao Zi

author
#0 lore raw

v2 cover Unify platform suspend/resume routines for PCI DWMAC glue

There are currently three PCI-based DWMAC glue drivers in tree, stmmac_pci.c, dwmac-intel.c, and dwmac-loongson.c. Both stmmac_pci.c and dwmac-intel.c implements the same and duplicated platform suspend/resume routines.

This series introduces a new PCI helper library, stmmac_libpci.c, providing a pair of helpers, stmmac_pci_plat_{suspend,resume}, and replaces the driver-specific implementation with the helpers to reduce code duplication. The helper will also simplify the Motorcomm DWMAC glue driver which I'm working on.

The glue driver for Intel controllers isn't covered by the series, since its suspend routine doesn't call pci_disable_device() and thus is a little different from the new generic helpers.

I only have Loongson hardware on hand, thus the series is only tested on Loongson 3A5000 machine. I could confirm the controller works after resume, and WoL works as expected. This shouldn't break stmmac_pci.c, either, since the new helpers have the exactly same code as the old driver-specific suspend/resume hooks.

Changed from v1
- Separate the new suspend/resume helpers into a new file, stmmac_libpci.c, and provide Kconfig symbol for it
- Link to v1: https://lore.kernel.org/netdev/[email protected]/

Yao Zi (3):
net: stmmac: Add generic suspend/resume helper for PCI-based
controllers
net: stmmac: loongson: Use generic PCI suspend/resume routines
net: stmmac: pci: Use generic PCI suspend/resume routines

 drivers/net/ethernet/stmicro/stmmac/Kconfig   | 11 +++++
 drivers/net/ethernet/stmicro/stmmac/Makefile  |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++------------
 .../ethernet/stmicro/stmmac/stmmac_libpci.c   | 48 +++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_libpci.h   | 12 +++++
 .../net/ethernet/stmicro/stmmac/stmmac_pci.c  | 36 ++------------
 6 files changed, 78 insertions(+), 66 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.c
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.h
Signature · 1 line
2.51.2
author
#1 lore raw

PATCH v2 1/3 net: stmmac: Add generic suspend/resume helper for PCI-based controllers

Most glue driver for PCI-based DWMAC controllers utilize similar platform suspend/resume routines. Add a generic implementation to reduce duplicated code.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  9 ++++
 drivers/net/ethernet/stmicro/stmmac/Makefile  |  1 +
 .../ethernet/stmicro/stmmac/stmmac_libpci.c   | 48 +++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_libpci.h   | 12 +++++
 4 files changed, 70 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.c
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.h
drivers/net/ethernet/stmicro/stmmac/Kconfig +9 -0
index 87c5bea6c2a2..598bc56edd8d 100644
@@ -349,6 +349,15 @@ config DWMAC_VISCONTI
 
 endif
 
+config STMMAC_LIBPCI
+	tristate "STMMAC PCI helper library"
+	depends on PCI
+	depends on STMMAC_ETH
+	default y
+	help
+	  This selects the PCI bus helpers for the stmmac driver. If you
+	  have a controller with PCI interface, say Y or M here.
+
 config DWMAC_INTEL
 	tristate "Intel GMAC support"
 	default X86
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index 1681a8a28313..7bf528731034 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_DWMAC_VISCONTI)	+= dwmac-visconti.o
 stmmac-platform-objs:= stmmac_platform.o
 dwmac-altr-socfpga-objs := dwmac-socfpga.o
 
+obj-$(CONFIG_STMMAC_LIBPCI)	+= stmmac_libpci.o
 obj-$(CONFIG_STMMAC_PCI)	+= stmmac-pci.o
 obj-$(CONFIG_DWMAC_INTEL)	+= dwmac-intel.o
 obj-$(CONFIG_DWMAC_LOONGSON)	+= dwmac-loongson.o
drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.c new file +48 -0

48 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.h new file +12 -0
new file mode 100644
index 000000000000..71553184f982
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2025 Yao Zi <[email protected]>
+ */
+
+#ifndef __STMMAC_LIBPCI_H__
+#define __STMMAC_LIBPCI_H__
+
+int stmmac_pci_plat_suspend(struct device *dev, void *bsp_priv);
+int stmmac_pci_plat_resume(struct device *dev, void *bsp_priv);
+
+#endif /* __STMMAC_LIBPCI_H__ */
Signature · 1 line
2.51.2
author
#2 lore raw

PATCH v2 2/3 net: stmmac: loongson: Use generic PCI suspend/resume routines

In reply to Yao Zi

Convert glue driver for Loongson DWMAC controller to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 598bc56edd8d..4b6911c62e6f 100644
@@ -373,6 +373,7 @@ config DWMAC_LOONGSON
 	default MACH_LOONGSON64
 	depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI
 	help
 	  This selects the LOONGSON PCI bus support for the stmmac driver,
 	  Support for ethernet controller on Loongson-2K1000 SoC and LS7A1000 bridge.
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -33
index 2a3ac0136cdb..584dc4ff8320 100644
@@ -8,6 +8,7 @@
 #include <linux/device.h>
 #include <linux/of_irq.h>
 #include "stmmac.h"
+#include "stmmac_libpci.h"
 #include "dwmac_dma.h"
 #include "dwmac1000.h"
 
@@ -525,37 +526,6 @@ static int loongson_dwmac_fix_reset(struct stmmac_priv *priv, void __iomem *ioad
 				  10000, 2000000);
 }
 
-static int loongson_dwmac_suspend(struct device *dev, void *bsp_priv)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-	int ret;
-
-	ret = pci_save_state(pdev);
-	if (ret)
-		return ret;
-
-	pci_disable_device(pdev);
-	pci_wake_from_d3(pdev, true);
-	return 0;
-}
-
-static int loongson_dwmac_resume(struct device *dev, void *bsp_priv)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-	int ret;
-
-	pci_restore_state(pdev);
-	pci_set_power_state(pdev, PCI_D0);
-
-	ret = pci_enable_device(pdev);
-	if (ret)
-		return ret;
-
-	pci_set_master(pdev);
-
-	return 0;
-}
-
 static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct plat_stmmacenet_data *plat;
@@ -600,8 +570,8 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 	plat->bsp_priv = ld;
 	plat->setup = loongson_dwmac_setup;
 	plat->fix_soc_reset = loongson_dwmac_fix_reset;
-	plat->suspend = loongson_dwmac_suspend;
-	plat->resume = loongson_dwmac_resume;
+	plat->suspend = stmmac_pci_plat_suspend;
+	plat->resume = stmmac_pci_plat_resume;
 	ld->dev = &pdev->dev;
 	ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff;
 
Signature · 1 line
2.51.2
#3 lore raw

Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines

Hi,

Quoted 15 lines · Yao Zi

Convert glue driver for Loongson DWMAC controller to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +0 -0
index 598bc56edd8d..4b6911c62e6f 100644

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_LOONGSON · line 376

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
@@ -373,6 +373,7 @@ config DWMAC_LOONGSON
 	default MACH_LOONGSON64
 	depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI

If we go with a dedicated module for this, "select STMMAC_LIBPCI" would make more sense here I think. The same applies for the next patch.

Maxime

author
#4 lore raw

Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines

Quoted 13 lines · Maxime Chevallier

Hi,

Quoted 10 lines · Yao Zi

Convert glue driver for Loongson DWMAC controller to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
Quoted 12 lines

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_LOONGSON · line 376

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 598bc56edd8d..4b6911c62e6f 100644
@@ -373,6 +373,7 @@ config DWMAC_LOONGSON
 	default MACH_LOONGSON64
 	depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI

If we go with a dedicated module for this, "select STMMAC_LIBPCI" would make more sense here I think. The same applies for the next patch.

Thanks, it's a reasonable point. I worried about possible unmet dependencies caused by a select, but STMMAC_LIBPCI only depends on PCI and STMMAC_ETH, which are necessary for DWMAC_LOONGSON and STMMAC_PCI to show up.

I will change it to "select STMMAC_LIBPCI" in v3.

Quoted 2 lines

Maxime

Best regards,
Yao Zi

#5 lore raw

Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines

In reply to Maxime Chevallier
Quoted 13 lines · Maxime Chevallier

Hi,

Quoted 10 lines · Yao Zi

Convert glue driver for Loongson DWMAC controller to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
Quoted 12 lines

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_LOONGSON · line 376

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 598bc56edd8d..4b6911c62e6f 100644
@@ -373,6 +373,7 @@ config DWMAC_LOONGSON
 	default MACH_LOONGSON64
 	depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI

If we go with a dedicated module for this, "select STMMAC_LIBPCI" would make more sense here I think. The same applies for the next patch.

Yes, we need it to be this way around at least initially so that STMMAC_LIBPCI gets merged into people's configs.

I'd eventually suggest going the other way.

We already have:

config STMMAC_PLATFORM
tristate "STMMAC Platform bus support"

if STMMAC_PLATFORM

... platform based drivers ...

endif

... three PCI based drivers ...

I'd suggest we do:

config STMMAC_LIBPCI
tristate "STMMAC PCI bus support"
depends on PCI
...

if STMMAC_LIBPCI

... PCI based drivers ...

endif

There's no need to make everything depend on STMMAC_ETH, there's an outer "if STMMAC_ETH" around all the platforms already.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author
#6 lore raw

Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines

Quoted 52 lines · Russell King (Oracle)
Quoted 13 lines · Maxime Chevallier

Hi,

Quoted 10 lines · Yao Zi

Convert glue driver for Loongson DWMAC controller to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
Quoted 12 lines

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_LOONGSON · line 376

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 598bc56edd8d..4b6911c62e6f 100644
@@ -373,6 +373,7 @@ config DWMAC_LOONGSON
 	default MACH_LOONGSON64
 	depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI

If we go with a dedicated module for this, "select STMMAC_LIBPCI" would make more sense here I think. The same applies for the next patch.

Yes, we need it to be this way around at least initially so that STMMAC_LIBPCI gets merged into people's configs.

I'd eventually suggest going the other way.

We already have:

config STMMAC_PLATFORM
tristate "STMMAC Platform bus support"

if STMMAC_PLATFORM

... platform based drivers ...

endif

... three PCI based drivers ...

I'd suggest we do:

config STMMAC_LIBPCI
tristate "STMMAC PCI bus support"
depends on PCI
...

Quoted 5 lines

if STMMAC_LIBPCI

... PCI based drivers ...

endif

Okay, will take this scheme instead.

Quoted 2 lines

There's no need to make everything depend on STMMAC_ETH, there's an outer "if STMMAC_ETH" around all the platforms already.

Okay. Yes, this dependency is redundant. Should we remove the unnecessary depends from other Kconfig options, too? STMMAC_SELFTESTS, STMMAC_PLATFORM, DWMAC_INTEL_PLAT, DWMAC_INTEL, DWMAC_LOONGSON and STMMAC_PCI are all enclosed by "if STMMAC_ETH" but carry this redundant dependency, too.

Regards,
Yao Zi

Quoted 3 lines
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author
#7 lore raw

PATCH v2 3/3 net: stmmac: pci: Use generic PCI suspend/resume routines

In reply to Yao Zi

Convert STMMAC PCI glue driver to use the generic platform suspend/resume routines for PCI controllers, instead of implementing its own one.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../net/ethernet/stmicro/stmmac/stmmac_pci.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index 4b6911c62e6f..eec81f674857 100644
@@ -382,6 +382,7 @@ config STMMAC_PCI
 	tristate "STMMAC PCI bus support"
 	depends on STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on STMMAC_LIBPCI
 	help
 	  This selects the platform specific bus support for the stmmac driver.
 	  This driver was tested on XLINX XC2V3000 FF1152AMT0221
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +3 -33
index 94b3a3b27270..fa92be672c54 100644
@@ -14,6 +14,7 @@
 #include <linux/dmi.h>
 
 #include "stmmac.h"
+#include "stmmac_libpci.h"
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
@@ -139,37 +140,6 @@ static const struct stmmac_pci_info snps_gmac5_pci_info = {
 	.setup = snps_gmac5_default_data,
 };
 
-static int stmmac_pci_suspend(struct device *dev, void *bsp_priv)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-	int ret;
-
-	ret = pci_save_state(pdev);
-	if (ret)
-		return ret;
-
-	pci_disable_device(pdev);
-	pci_wake_from_d3(pdev, true);
-	return 0;
-}
-
-static int stmmac_pci_resume(struct device *dev, void *bsp_priv)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-	int ret;
-
-	pci_restore_state(pdev);
-	pci_set_power_state(pdev, PCI_D0);
-
-	ret = pci_enable_device(pdev);
-	if (ret)
-		return ret;
-
-	pci_set_master(pdev);
-
-	return 0;
-}
-
 /**
  * stmmac_pci_probe
  *
@@ -249,8 +219,8 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 	plat->safety_feat_cfg->prtyen = 1;
 	plat->safety_feat_cfg->tmouten = 1;
 
-	plat->suspend = stmmac_pci_suspend;
-	plat->resume = stmmac_pci_resume;
+	plat->suspend = stmmac_pci_plat_suspend;
+	plat->resume = stmmac_pci_plat_resume;
 
 	return stmmac_dvr_probe(&pdev->dev, plat, &res);
 }
Signature · 1 line
2.51.2