Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'unify-platform-suspend-resume-routines-for-pci-dwmac-glue'

Yao Zi says:

====================
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.
====================

Link: https://patch.msgid.link/20251124160417.51514-1-ziyao@disroot.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+76 -68
+9 -2
drivers/net/ethernet/stmicro/stmmac/Kconfig
··· 349 349 350 350 endif 351 351 352 + config STMMAC_LIBPCI 353 + tristate 354 + help 355 + This option enables the PCI bus helpers for the stmmac driver. 356 + 352 357 config DWMAC_INTEL 353 358 tristate "Intel GMAC support" 354 359 default X86 ··· 367 362 config DWMAC_LOONGSON 368 363 tristate "Loongson PCI DWMAC support" 369 364 default MACH_LOONGSON64 370 - depends on (MACH_LOONGSON64 || COMPILE_TEST) && STMMAC_ETH && PCI 365 + depends on (MACH_LOONGSON64 || COMPILE_TEST) && PCI 371 366 depends on COMMON_CLK 367 + select STMMAC_LIBPCI 372 368 help 373 369 This selects the LOONGSON PCI bus support for the stmmac driver, 374 370 Support for ethernet controller on Loongson-2K1000 SoC and LS7A1000 bridge. 375 371 376 372 config STMMAC_PCI 377 373 tristate "STMMAC PCI bus support" 378 - depends on STMMAC_ETH && PCI 374 + depends on PCI 379 375 depends on COMMON_CLK 376 + select STMMAC_LIBPCI 380 377 help 381 378 This selects the platform specific bus support for the stmmac driver. 382 379 This driver was tested on XLINX XC2V3000 FF1152AMT0221
+1
drivers/net/ethernet/stmicro/stmmac/Makefile
··· 44 44 stmmac-platform-objs:= stmmac_platform.o 45 45 dwmac-altr-socfpga-objs := dwmac-socfpga.o 46 46 47 + obj-$(CONFIG_STMMAC_LIBPCI) += stmmac_libpci.o 47 48 obj-$(CONFIG_STMMAC_PCI) += stmmac-pci.o 48 49 obj-$(CONFIG_DWMAC_INTEL) += dwmac-intel.o 49 50 obj-$(CONFIG_DWMAC_LOONGSON) += dwmac-loongson.o
+3 -33
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
··· 8 8 #include <linux/device.h> 9 9 #include <linux/of_irq.h> 10 10 #include "stmmac.h" 11 + #include "stmmac_libpci.h" 11 12 #include "dwmac_dma.h" 12 13 #include "dwmac1000.h" 13 14 ··· 503 502 10000, 2000000); 504 503 } 505 504 506 - static int loongson_dwmac_suspend(struct device *dev, void *bsp_priv) 507 - { 508 - struct pci_dev *pdev = to_pci_dev(dev); 509 - int ret; 510 - 511 - ret = pci_save_state(pdev); 512 - if (ret) 513 - return ret; 514 - 515 - pci_disable_device(pdev); 516 - pci_wake_from_d3(pdev, true); 517 - return 0; 518 - } 519 - 520 - static int loongson_dwmac_resume(struct device *dev, void *bsp_priv) 521 - { 522 - struct pci_dev *pdev = to_pci_dev(dev); 523 - int ret; 524 - 525 - pci_restore_state(pdev); 526 - pci_set_power_state(pdev, PCI_D0); 527 - 528 - ret = pci_enable_device(pdev); 529 - if (ret) 530 - return ret; 531 - 532 - pci_set_master(pdev); 533 - 534 - return 0; 535 - } 536 - 537 505 static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id) 538 506 { 539 507 struct plat_stmmacenet_data *plat; ··· 547 577 plat->bsp_priv = ld; 548 578 plat->mac_setup = loongson_dwmac_setup; 549 579 plat->fix_soc_reset = loongson_dwmac_fix_reset; 550 - plat->suspend = loongson_dwmac_suspend; 551 - plat->resume = loongson_dwmac_resume; 580 + plat->suspend = stmmac_pci_plat_suspend; 581 + plat->resume = stmmac_pci_plat_resume; 552 582 ld->dev = &pdev->dev; 553 583 ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff; 554 584
+48
drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * PCI bus helpers for STMMAC driver 4 + * Copyright (C) 2025 Yao Zi <ziyao@disroot.org> 5 + */ 6 + 7 + #include <linux/device.h> 8 + #include <linux/pci.h> 9 + 10 + #include "stmmac_libpci.h" 11 + 12 + int stmmac_pci_plat_suspend(struct device *dev, void *bsp_priv) 13 + { 14 + struct pci_dev *pdev = to_pci_dev(dev); 15 + int ret; 16 + 17 + ret = pci_save_state(pdev); 18 + if (ret) 19 + return ret; 20 + 21 + pci_disable_device(pdev); 22 + pci_wake_from_d3(pdev, true); 23 + 24 + return 0; 25 + } 26 + EXPORT_SYMBOL_GPL(stmmac_pci_plat_suspend); 27 + 28 + int stmmac_pci_plat_resume(struct device *dev, void *bsp_priv) 29 + { 30 + struct pci_dev *pdev = to_pci_dev(dev); 31 + int ret; 32 + 33 + pci_restore_state(pdev); 34 + pci_set_power_state(pdev, PCI_D0); 35 + 36 + ret = pci_enable_device(pdev); 37 + if (ret) 38 + return ret; 39 + 40 + pci_set_master(pdev); 41 + 42 + return 0; 43 + } 44 + EXPORT_SYMBOL_GPL(stmmac_pci_plat_resume); 45 + 46 + MODULE_DESCRIPTION("STMMAC PCI helper library"); 47 + MODULE_AUTHOR("Yao Zi <ziyao@disroot.org>"); 48 + MODULE_LICENSE("GPL");
+12
drivers/net/ethernet/stmicro/stmmac/stmmac_libpci.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2025 Yao Zi <ziyao@disroot.org> 4 + */ 5 + 6 + #ifndef __STMMAC_LIBPCI_H__ 7 + #define __STMMAC_LIBPCI_H__ 8 + 9 + int stmmac_pci_plat_suspend(struct device *dev, void *bsp_priv); 10 + int stmmac_pci_plat_resume(struct device *dev, void *bsp_priv); 11 + 12 + #endif /* __STMMAC_LIBPCI_H__ */
+3 -33
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
··· 14 14 #include <linux/dmi.h> 15 15 16 16 #include "stmmac.h" 17 + #include "stmmac_libpci.h" 17 18 18 19 struct stmmac_pci_info { 19 20 int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat); ··· 103 102 .setup = snps_gmac5_default_data, 104 103 }; 105 104 106 - static int stmmac_pci_suspend(struct device *dev, void *bsp_priv) 107 - { 108 - struct pci_dev *pdev = to_pci_dev(dev); 109 - int ret; 110 - 111 - ret = pci_save_state(pdev); 112 - if (ret) 113 - return ret; 114 - 115 - pci_disable_device(pdev); 116 - pci_wake_from_d3(pdev, true); 117 - return 0; 118 - } 119 - 120 - static int stmmac_pci_resume(struct device *dev, void *bsp_priv) 121 - { 122 - struct pci_dev *pdev = to_pci_dev(dev); 123 - int ret; 124 - 125 - pci_restore_state(pdev); 126 - pci_set_power_state(pdev, PCI_D0); 127 - 128 - ret = pci_enable_device(pdev); 129 - if (ret) 130 - return ret; 131 - 132 - pci_set_master(pdev); 133 - 134 - return 0; 135 - } 136 - 137 105 /** 138 106 * stmmac_pci_probe 139 107 * ··· 182 212 plat->safety_feat_cfg->prtyen = 1; 183 213 plat->safety_feat_cfg->tmouten = 1; 184 214 185 - plat->suspend = stmmac_pci_suspend; 186 - plat->resume = stmmac_pci_resume; 215 + plat->suspend = stmmac_pci_plat_suspend; 216 + plat->resume = stmmac_pci_plat_resume; 187 217 188 218 return stmmac_dvr_probe(&pdev->dev, plat, &res); 189 219 }