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

Yao Zi posted 3 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH net-next 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Yao Zi 3 months, 1 week ago
Most glue driver for PCI-based DWMAC controllers utilize similar
platform suspend/resume routines. Add a generic implementation to reduce
duplicated code.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index d5af9344dfb0..baa4ff14bdfe 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -395,6 +395,8 @@ int stmmac_xdp_open(struct net_device *dev);
 void stmmac_xdp_release(struct net_device *dev);
 int stmmac_resume(struct device *dev);
 int stmmac_suspend(struct device *dev);
+int stmmac_pci_plat_suspend(struct device *dev, void *bsp_priv);
+int stmmac_pci_plat_resume(struct device *dev, void *bsp_priv);
 void stmmac_dvr_remove(struct device *dev);
 int stmmac_dvr_probe(struct device *device,
 		     struct plat_stmmacenet_data *plat_dat,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index fd5106880192..3bd284019ca7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -28,6 +28,7 @@
 #include <linux/if_vlan.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/pci.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_wakeirq.h>
 #include <linux/prefetch.h>
@@ -7938,6 +7939,42 @@ EXPORT_SYMBOL_GPL(stmmac_resume);
 DEFINE_SIMPLE_DEV_PM_OPS(stmmac_simple_pm_ops, stmmac_suspend, stmmac_resume);
 EXPORT_SYMBOL_GPL(stmmac_simple_pm_ops);
 
+#ifdef CONFIG_PCI
+int stmmac_pci_plat_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;
+}
+EXPORT_SYMBOL_GPL(stmmac_pci_plat_suspend);
+
+int stmmac_pci_plat_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;
+}
+EXPORT_SYMBOL_GPL(stmmac_pci_plat_resume);
+#endif /* CONFIG_PCI */
+
 #ifndef MODULE
 static int __init stmmac_cmdline_opt(char *str)
 {
-- 
2.50.1
Re: [PATCH net-next 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Russell King (Oracle) 3 months, 1 week ago
On Tue, Oct 28, 2025 at 03:43:30PM +0000, Yao Zi wrote:
> Most glue driver for PCI-based DWMAC controllers utilize similar
> platform suspend/resume routines. Add a generic implementation to reduce
> duplicated code.
> 
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
>  .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++

I would prefer not to make stmmac_main.c even larger by including bus
specific helpers there. We already have stmmac_pltfm.c for those which
use struct platform_device. The logical name would be stmmac_pci.c, but
that's already taken by a driver.

One way around that would be to rename stmmac_pci.c to dwmac-pci.c
(glue drivers tend to be named dwmac-foo.c) and then re-use
stmmac_pci.c for PCI-related stuff in the same way that stmmac_pltfm.c
is used.

Another idea would be stmmac_libpci.c.

-- 
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 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Yanteng Si 3 months, 1 week ago
在 2025/10/28 下午11:59, Russell King (Oracle) 写道:
> On Tue, Oct 28, 2025 at 03:43:30PM +0000, Yao Zi wrote:
>> Most glue driver for PCI-based DWMAC controllers utilize similar
>> platform suspend/resume routines. Add a generic implementation to reduce
>> duplicated code.
>>
>> Signed-off-by: Yao Zi <ziyao@disroot.org>
>> ---
>>   drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
>>   .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++
> I would prefer not to make stmmac_main.c even larger by including bus
> specific helpers there. We already have stmmac_pltfm.c for those which
> use struct platform_device. The logical name would be stmmac_pci.c, but
> that's already taken by a driver.
>
> One way around that would be to rename stmmac_pci.c to dwmac-pci.c
> (glue drivers tend to be named dwmac-foo.c) and then re-use
> stmmac_pci.c for PCI-related stuff in the same way that stmmac_pltfm.c
> is used.
>
> Another idea would be stmmac_libpci.c.

I also don't want stmmac_main.c to grow larger, and I prefer

stmmac_libpci.c instead. Another approach - maybe we can

keep these helper functions in stmmac_pci.c and just declare

them as extern where needed?


Thanks,

Yanteng

>
Re: [PATCH net-next 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Russell King (Oracle) 3 months, 1 week ago
On Wed, Oct 29, 2025 at 10:27:18AM +0800, Yanteng Si wrote:
> 在 2025/10/28 下午11:59, Russell King (Oracle) 写道:
> > On Tue, Oct 28, 2025 at 03:43:30PM +0000, Yao Zi wrote:
> > > Most glue driver for PCI-based DWMAC controllers utilize similar
> > > platform suspend/resume routines. Add a generic implementation to reduce
> > > duplicated code.
> > > 
> > > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > > ---
> > >   drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
> > >   .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++
> > I would prefer not to make stmmac_main.c even larger by including bus
> > specific helpers there. We already have stmmac_pltfm.c for those which
> > use struct platform_device. The logical name would be stmmac_pci.c, but
> > that's already taken by a driver.
> > 
> > One way around that would be to rename stmmac_pci.c to dwmac-pci.c
> > (glue drivers tend to be named dwmac-foo.c) and then re-use
> > stmmac_pci.c for PCI-related stuff in the same way that stmmac_pltfm.c
> > is used.
> > 
> > Another idea would be stmmac_libpci.c.
> 
> I also don't want stmmac_main.c to grow larger, and I prefer
> stmmac_libpci.c instead. Another approach - maybe we can
> keep these helper functions in stmmac_pci.c and just declare
> them as extern where needed?

stmmac_pci.c is itself a glue driver, supporting PCI IDs:

	0x0700, 0x1108	- synthetic ID
	0x104a, 0xcc09	- ST Micro MAC
	0x16c3, 0x7102	- Synopsys GMAC5

I don't think we should try to turn a glue driver into a library,
even though it would be the easier option (we could reuse
CONFIG_STMMAC_PCI.)

-- 
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 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Yanteng Si 3 months, 1 week ago
在 2025/10/29 下午5:00, Russell King (Oracle) 写道:
> On Wed, Oct 29, 2025 at 10:27:18AM +0800, Yanteng Si wrote:
>> 在 2025/10/28 下午11:59, Russell King (Oracle) 写道:
>>> On Tue, Oct 28, 2025 at 03:43:30PM +0000, Yao Zi wrote:
>>>> Most glue driver for PCI-based DWMAC controllers utilize similar
>>>> platform suspend/resume routines. Add a generic implementation to reduce
>>>> duplicated code.
>>>>
>>>> Signed-off-by: Yao Zi<ziyao@disroot.org>
>>>> ---
>>>>    drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
>>>>    .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++
>>> I would prefer not to make stmmac_main.c even larger by including bus
>>> specific helpers there. We already have stmmac_pltfm.c for those which
>>> use struct platform_device. The logical name would be stmmac_pci.c, but
>>> that's already taken by a driver.
>>>
>>> One way around that would be to rename stmmac_pci.c to dwmac-pci.c
>>> (glue drivers tend to be named dwmac-foo.c) and then re-use
>>> stmmac_pci.c for PCI-related stuff in the same way that stmmac_pltfm.c
>>> is used.
>>>
>>> Another idea would be stmmac_libpci.c.
>> I also don't want stmmac_main.c to grow larger, and I prefer
>> stmmac_libpci.c instead. Another approach - maybe we can
>> keep these helper functions in stmmac_pci.c and just declare
>> them as extern where needed?
> stmmac_pci.c is itself a glue driver, supporting PCI IDs:
>
> 	0x0700, 0x1108	- synthetic ID
> 	0x104a, 0xcc09	- ST Micro MAC
> 	0x16c3, 0x7102	- Synopsys GMAC5
>
> I don't think we should try to turn a glue driver into a library,
> even though it would be the easier option (we could reuse
> CONFIG_STMMAC_PCI.)

I agree with your opinion; let's build a new library.


Thanks,

Yanteng

Re: [PATCH net-next 1/3] net: stmmac: Add generic suspend/resume helper for PCI-based controllers
Posted by Yao Zi 3 months, 1 week ago
On Wed, Oct 29, 2025 at 10:27:18AM +0800, Yanteng Si wrote:
> 
> 在 2025/10/28 下午11:59, Russell King (Oracle) 写道:
> > On Tue, Oct 28, 2025 at 03:43:30PM +0000, Yao Zi wrote:
> > > Most glue driver for PCI-based DWMAC controllers utilize similar
> > > platform suspend/resume routines. Add a generic implementation to reduce
> > > duplicated code.
> > > 
> > > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > > ---
> > >   drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
> > >   .../net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++++++++++
> > I would prefer not to make stmmac_main.c even larger by including bus
> > specific helpers there. We already have stmmac_pltfm.c for those which
> > use struct platform_device. The logical name would be stmmac_pci.c, but
> > that's already taken by a driver.
> > 
> > One way around that would be to rename stmmac_pci.c to dwmac-pci.c
> > (glue drivers tend to be named dwmac-foo.c) and then re-use
> > stmmac_pci.c for PCI-related stuff in the same way that stmmac_pltfm.c
> > is used.
> > 
> > Another idea would be stmmac_libpci.c.
> 
> I also don't want stmmac_main.c to grow larger, and I prefer
> 
> stmmac_libpci.c instead.

Okay, then I'll separate the code into stmmac_libpci.c instead. This
also avoids moving code around, making it easier to track git log in the
future.

> Another approach - maybe we can
> 
> keep these helper functions in stmmac_pci.c and just declare
> 
> them as extern where needed?

stmmac_pci.c is a standalone DWMAC glue driver, none of its symbols are
for external usage. I don't think it's appropriate to put these helpers
in the driver. Furthermore, this will also require PCI-based glues
making use of these helpers to depend on an unrelated driver,
introducing unnecessary code size, which doesn't sound like a good idea
to me.

I'd still like to introduce stmmac_libpci.c for these helpers.

> Thanks,
> 
> Yanteng
> 
> > 

Best regards,
Yao Zi