From: Vladimir Oltean The ksz_switch driver is one of the few which reset the switch when unbinding the driver or shutting down - in the same category with ar9331_sw_remove(), bcm_sf2_sw_remove(), and ks8995_remove(), vsc73xx_remove() and lan9303_remove(). I don't think there exists any requirement to do this, and in fact it does create complications for WoL, as the code already shows. My issue with this logic is that it is the only thing keeping dev_ops->reset() necessary, which I would like to remove after individual KSZ switch families get their own setup() and teardown() methods that don't go through dev_ops. Don't reset the switch when unbinding the driver or shutting down. Remove the exit callbacks from the ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 8 -------- drivers/net/dsa/microchip/ksz9477.c | 6 ------ drivers/net/dsa/microchip/ksz_common.c | 32 ++++++++------------------------ drivers/net/dsa/microchip/ksz_common.h | 1 - drivers/net/dsa/microchip/lan937x_main.c | 6 ------ 5 files changed, 8 insertions(+), 45 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 825133e9ce6e6..ccbc3480717f0 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -2109,11 +2109,6 @@ static int ksz8_switch_init(struct ksz_device *dev) return 0; } -static void ksz8_switch_exit(struct ksz_device *dev) -{ - ksz8_reset_switch(dev); -} - static enum dsa_tag_protocol ksz8463_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -2226,7 +2221,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, }; const struct ksz_dev_ops ksz87xx_dev_ops = { @@ -2245,7 +2239,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, @@ -2267,7 +2260,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 65fd07ef73ad0..88a5ff62aae89 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1624,11 +1624,6 @@ static int ksz9477_switch_init(struct ksz_device *dev) return 0; } -static void ksz9477_switch_exit(struct ksz_device *dev) -{ - ksz9477_reset_switch(dev); -} - static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -1803,7 +1798,6 @@ const struct ksz_dev_ops ksz9477_dev_ops = { .enable_stp_addr = ksz9477_enable_stp_addr, .reset = ksz9477_reset_switch, .init = ksz9477_switch_init, - .exit = ksz9477_switch_exit, .pcs_create = ksz9477_pcs_create, }; diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 4a7bcd1a93927..78d77a60a6ce2 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -4170,16 +4170,15 @@ int ksz_set_wol(struct dsa_switch *ds, int port, * the wol_enabled flag accordingly to reflect whether WoL is active on any * port. */ -static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) +static void ksz_wol_pre_shutdown(struct ksz_device *dev) { const struct ksz_dev_ops *ops = dev->dev_ops; const u16 *regs = dev->info->regs; u8 pme_pin_en = PME_ENABLE; + bool wol_enabled = false; struct dsa_port *dp; int ret; - *wol_enabled = false; - if (!is_ksz9477(dev) && !ksz_is_ksz87xx(dev)) return; @@ -4192,7 +4191,7 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) ret = ops->pme_pread8(dev, dp->index, regs[REG_PORT_PME_CTRL], &pme_ctrl); if (!ret && pme_ctrl) - *wol_enabled = true; + wol_enabled = true; /* make sure there are no pending wake events which would * prevent the device from going to sleep/shutdown. @@ -4201,7 +4200,7 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) } /* Now we are save to enable PME pin. */ - if (*wol_enabled) { + if (wol_enabled) { if (dev->pme_active_high) pme_pin_en |= PME_POLARITY; ops->pme_write8(dev, regs[REG_SW_PME_CTRL], pme_pin_en); @@ -4480,20 +4479,12 @@ EXPORT_SYMBOL(ksz_switch_alloc); * @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. + * switch device. 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) { - bool wol_enabled = false; - - ksz_wol_pre_shutdown(dev, &wol_enabled); - - if (dev->dev_ops->reset && !wol_enabled) - dev->dev_ops->reset(dev); - + ksz_wol_pre_shutdown(dev); dsa_switch_shutdown(dev->ds); } EXPORT_SYMBOL(ksz_switch_shutdown); @@ -4943,10 +4934,8 @@ int ksz_switch_register(struct ksz_device *dev) } ret = dsa_register_switch(dev->ds); - if (ret) { - dev->dev_ops->exit(dev); + if (ret) return ret; - } /* Read MIB counters every 30 seconds to avoid overflow. */ dev->mib_read_interval = msecs_to_jiffies(5000); @@ -4966,12 +4955,7 @@ void ksz_switch_remove(struct ksz_device *dev) cancel_delayed_work_sync(&dev->mib_read); } - dev->dev_ops->exit(dev); dsa_unregister_switch(dev->ds); - - if (dev->reset_gpio) - gpiod_set_value_cansleep(dev->reset_gpio, 1); - } EXPORT_SYMBOL(ksz_switch_remove); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index f6dad256a550f..1cdb6661729a6 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -421,7 +421,6 @@ struct ksz_dev_ops { int (*enable_stp_addr)(struct ksz_device *dev); int (*reset)(struct ksz_device *dev); int (*init)(struct ksz_device *dev); - void (*exit)(struct ksz_device *dev); int (*pcs_create)(struct ksz_device *dev); }; diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index f84548168b371..778e32f568df4 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -668,11 +668,6 @@ static void lan937x_teardown(struct dsa_switch *ds) } -static void lan937x_switch_exit(struct ksz_device *dev) -{ - lan937x_reset_switch(dev); -} - static enum dsa_tag_protocol lan937x_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -723,7 +718,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .enable_stp_addr = ksz9477_enable_stp_addr, .reset = lan937x_reset_switch, .init = lan937x_switch_init, - .exit = lan937x_switch_exit, }; const struct dsa_switch_ops lan937x_switch_ops = { -- 2.53.0