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

net: dsa: microchip: Refactor switch shutdown routine for WoL preparation

Centralize the switch shutdown routine in a dedicated function,
ksz_switch_shutdown(), to enhance code maintainability and reduce
redundancy. This change abstracts the common shutdown operations
previously duplicated in ksz9477_i2c_shutdown() and ksz_spi_shutdown().

This refactoring is a preparatory step for an upcoming patch to avoid
reset on shutdown if Wake-on-LAN (WoL) is enabled.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20231026051051.2316937-5-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Oleksij Rempel and committed by
Jakub Kicinski
77c819cb 818cdb0f

+22 -8
+1 -4
drivers/net/dsa/microchip/ksz9477_i2c.c
··· 66 66 if (!dev) 67 67 return; 68 68 69 - if (dev->dev_ops->reset) 70 - dev->dev_ops->reset(dev); 71 - 72 - dsa_switch_shutdown(dev->ds); 69 + ksz_switch_shutdown(dev); 73 70 74 71 i2c_set_clientdata(i2c, NULL); 75 72 }
+19
drivers/net/dsa/microchip/ksz_common.c
··· 3845 3845 } 3846 3846 EXPORT_SYMBOL(ksz_switch_alloc); 3847 3847 3848 + /** 3849 + * ksz_switch_shutdown - Shutdown routine for the switch device. 3850 + * @dev: The switch device structure. 3851 + * 3852 + * This function is responsible for initiating a shutdown sequence for the 3853 + * switch device. It invokes the reset operation defined in the device 3854 + * operations, if available, to reset the switch. Subsequently, it calls the 3855 + * DSA framework's shutdown function to ensure a proper shutdown of the DSA 3856 + * switch. 3857 + */ 3858 + void ksz_switch_shutdown(struct ksz_device *dev) 3859 + { 3860 + if (dev->dev_ops->reset) 3861 + dev->dev_ops->reset(dev); 3862 + 3863 + dsa_switch_shutdown(dev->ds); 3864 + } 3865 + EXPORT_SYMBOL(ksz_switch_shutdown); 3866 + 3848 3867 static void ksz_parse_rgmii_delay(struct ksz_device *dev, int port_num, 3849 3868 struct device_node *port_dn) 3850 3869 {
+1
drivers/net/dsa/microchip/ksz_common.h
··· 400 400 int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, 401 401 struct netlink_ext_ack *extack); 402 402 void ksz_switch_macaddr_put(struct dsa_switch *ds); 403 + void ksz_switch_shutdown(struct ksz_device *dev); 403 404 404 405 /* Common register access functions */ 405 406 static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
+1 -4
drivers/net/dsa/microchip/ksz_spi.c
··· 114 114 if (!dev) 115 115 return; 116 116 117 - if (dev->dev_ops->reset) 118 - dev->dev_ops->reset(dev); 119 - 120 - dsa_switch_shutdown(dev->ds); 117 + ksz_switch_shutdown(dev); 121 118 122 119 spi_set_drvdata(spi, NULL); 123 120 }