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

Yao Zi posted 3 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines
Posted by Yao Zi 1 month, 2 weeks ago
Convert glue driver for Loongson DWMAC controller to use the generic
platform suspend/resume routines for PCI controllers, instead of
implementing its own one.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
 2 files changed, 4 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 598bc56edd8d..4b6911c62e6f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -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.
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index 2a3ac0136cdb..584dc4ff8320 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -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;
 
-- 
2.51.2
Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines
Posted by Maxime Chevallier 1 month, 2 weeks ago
Hi,

On 30/10/2025 05:19, Yao Zi wrote:
> Convert glue driver for Loongson DWMAC controller to use the generic
> platform suspend/resume routines for PCI controllers, instead of
> implementing its own one.
> 
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
>  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
>  2 files changed, 4 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> index 598bc56edd8d..4b6911c62e6f 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> @@ -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
Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines
Posted by Russell King (Oracle) 1 month, 2 weeks ago
On Thu, Oct 30, 2025 at 08:38:12AM +0100, Maxime Chevallier wrote:
> Hi,
> 
> On 30/10/2025 05:19, Yao Zi wrote:
> > Convert glue driver for Loongson DWMAC controller to use the generic
> > platform suspend/resume routines for PCI controllers, instead of
> > implementing its own one.
> > 
> > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
> >  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
> >  2 files changed, 4 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > index 598bc56edd8d..4b6911c62e6f 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > @@ -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.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines
Posted by Yao Zi 1 month, 2 weeks ago
On Thu, Oct 30, 2025 at 09:30:35AM +0000, Russell King (Oracle) wrote:
> On Thu, Oct 30, 2025 at 08:38:12AM +0100, Maxime Chevallier wrote:
> > Hi,
> > 
> > On 30/10/2025 05:19, Yao Zi wrote:
> > > Convert glue driver for Loongson DWMAC controller to use the generic
> > > platform suspend/resume routines for PCI controllers, instead of
> > > implementing its own one.
> > > 
> > > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > > ---
> > >  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
> > >  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
> > >  2 files changed, 4 insertions(+), 33 deletions(-)
> > > 
> > > diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > > index 598bc56edd8d..4b6911c62e6f 100644
> > > --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > > +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > > @@ -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

Okay, will take this scheme instead.

> 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

> -- 
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH net-next v2 2/3] net: stmmac: loongson: Use generic PCI suspend/resume routines
Posted by Yao Zi 1 month, 2 weeks ago
On Thu, Oct 30, 2025 at 08:38:12AM +0100, Maxime Chevallier wrote:
> Hi,
> 
> On 30/10/2025 05:19, Yao Zi wrote:
> > Convert glue driver for Loongson DWMAC controller to use the generic
> > platform suspend/resume routines for PCI controllers, instead of
> > implementing its own one.
> > 
> > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
> >  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 36 ++-----------------
> >  2 files changed, 4 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > index 598bc56edd8d..4b6911c62e6f 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > @@ -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.

> Maxime
> 

Best regards,
Yao Zi