Skip to content

Commit 77c819c

Browse files
oleremkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 818cdb0 commit 77c819c

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

drivers/net/dsa/microchip/ksz9477_i2c.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
6666
if (!dev)
6767
return;
6868

69-
if (dev->dev_ops->reset)
70-
dev->dev_ops->reset(dev);
71-
72-
dsa_switch_shutdown(dev->ds);
69+
ksz_switch_shutdown(dev);
7370

7471
i2c_set_clientdata(i2c, NULL);
7572
}

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,6 +3845,25 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
38453845
}
38463846
EXPORT_SYMBOL(ksz_switch_alloc);
38473847

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+
38483867
static void ksz_parse_rgmii_delay(struct ksz_device *dev, int port_num,
38493868
struct device_node *port_dn)
38503869
{

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ extern const struct ksz_chip_data ksz_switch_chips[];
400400
int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
401401
struct netlink_ext_ack *extack);
402402
void ksz_switch_macaddr_put(struct dsa_switch *ds);
403+
void ksz_switch_shutdown(struct ksz_device *dev);
403404

404405
/* Common register access functions */
405406
static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)

drivers/net/dsa/microchip/ksz_spi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ static void ksz_spi_shutdown(struct spi_device *spi)
114114
if (!dev)
115115
return;
116116

117-
if (dev->dev_ops->reset)
118-
dev->dev_ops->reset(dev);
119-
120-
dsa_switch_shutdown(dev->ds);
117+
ksz_switch_shutdown(dev);
121118

122119
spi_set_drvdata(spi, NULL);
123120
}

0 commit comments

Comments
 (0)