net: dsa: microchip: Refactor switch shutdown routine for WoL preparation
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 26 Oct 2023 05:10:50 +0000 (07:10 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 27 Oct 2023 21:43:53 +0000 (14:43 -0700)
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>
drivers/net/dsa/microchip/ksz9477_i2c.c
drivers/net/dsa/microchip/ksz_common.c
drivers/net/dsa/microchip/ksz_common.h
drivers/net/dsa/microchip/ksz_spi.c

index 2710afad4f3aff838c4ea30f6db5d79d69c992b3..cac4a607e54a5759f1cc7b0cf08afd64a986c2ba 100644 (file)
@@ -66,10 +66,7 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
        if (!dev)
                return;
 
-       if (dev->dev_ops->reset)
-               dev->dev_ops->reset(dev);
-
-       dsa_switch_shutdown(dev->ds);
+       ksz_switch_shutdown(dev);
 
        i2c_set_clientdata(i2c, NULL);
 }
index 00be812bef409c64839aa05d183080134543a74a..3b48e42148a09806bf9234b494a4f756ece77505 100644 (file)
@@ -3845,6 +3845,25 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 }
 EXPORT_SYMBOL(ksz_switch_alloc);
 
+/**
+ * ksz_switch_shutdown - Shutdown routine for the switch device.
+ * @dev: The switch device structure.
+ *
+ * This function is responsible for initiating a shutdown sequence for the
+ * switch device. It invokes the reset operation defined in the device
+ * operations, if available, to reset the switch. Subsequently, it calls the
+ * DSA framework's shutdown function to ensure a proper shutdown of the DSA
+ * switch.
+ */
+void ksz_switch_shutdown(struct ksz_device *dev)
+{
+       if (dev->dev_ops->reset)
+               dev->dev_ops->reset(dev);
+
+       dsa_switch_shutdown(dev->ds);
+}
+EXPORT_SYMBOL(ksz_switch_shutdown);
+
 static void ksz_parse_rgmii_delay(struct ksz_device *dev, int port_num,
                                  struct device_node *port_dn)
 {
index 06996813f9a8efd16a916e7389116a1e9070ce66..14b4828f80a1ce94f4076ed69816b9d9f0fe1a0a 100644 (file)
@@ -400,6 +400,7 @@ extern const struct ksz_chip_data ksz_switch_chips[];
 int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
                           struct netlink_ext_ack *extack);
 void ksz_switch_macaddr_put(struct dsa_switch *ds);
+void ksz_switch_shutdown(struct ksz_device *dev);
 
 /* Common register access functions */
 static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
index 279338451621b1834c92dda25bbe2d7209da2f8d..6f6d878e742ca0288048643d9a6da3935ea6441d 100644 (file)
@@ -114,10 +114,7 @@ static void ksz_spi_shutdown(struct spi_device *spi)
        if (!dev)
                return;
 
-       if (dev->dev_ops->reset)
-               dev->dev_ops->reset(dev);
-
-       dsa_switch_shutdown(dev->ds);
+       ksz_switch_shutdown(dev);
 
        spi_set_drvdata(spi, NULL);
 }