diff mbox series

[net-next,v3,7/7] net: dsa: microchip: do not shut down the switch if WoL is active

Message ID 20231013122405.3745475-8-o.rempel@pengutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: microchip: provide Wake on LAN support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 1360 this patch: 1366
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang fail Errors and warnings before: 1385 this patch: 1391
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 1385 this patch: 1391
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 50 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Oleksij Rempel Oct. 13, 2023, 12:24 p.m. UTC
For Wake on Lan we should not reconfigure, reset or power down the
switch on shut down sequence.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477_i2c.c |  3 +++
 drivers/net/dsa/microchip/ksz_common.c  | 18 ++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h  |  2 ++
 drivers/net/dsa/microchip/ksz_spi.c     |  3 +++
 4 files changed, 26 insertions(+)

Comments

Vladimir Oltean Oct. 16, 2023, 10:22 a.m. UTC | #1
On Fri, Oct 13, 2023 at 02:24:05PM +0200, Oleksij Rempel wrote:
> For Wake on Lan we should not reconfigure, reset or power down the
> switch on shut down sequence.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz9477_i2c.c |  3 +++
>  drivers/net/dsa/microchip/ksz_common.c  | 18 ++++++++++++++++++
>  drivers/net/dsa/microchip/ksz_common.h  |  2 ++
>  drivers/net/dsa/microchip/ksz_spi.c     |  3 +++
>  4 files changed, 26 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c
> index 2710afad4f3a..fe818742051c 100644
> --- a/drivers/net/dsa/microchip/ksz9477_i2c.c
> +++ b/drivers/net/dsa/microchip/ksz9477_i2c.c
> @@ -66,6 +66,9 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
>  	if (!dev)
>  		return;
>  
> +	if (ksz_wol_is_active(dev))
> +		return;
> +
>  	if (dev->dev_ops->reset)
>  		dev->dev_ops->reset(dev);

The rest of the code used to read:

	dsa_switch_shutdown(dev->ds);

	i2c_set_clientdata(i2c, NULL);
}

and that part is non-optional. Please only skip the dev->dev_ops->reset()
call if ksz_wol_is_active().

>  static void ksz_set_xmii(struct ksz_device *dev, int port,
>  			 phy_interface_t interface)
>  {
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 80679f38ee12..84b1eed8cd2a 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -397,6 +397,8 @@ bool ksz_get_gbit(struct ksz_device *dev, int port);
>  phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
>  extern const struct ksz_chip_data ksz_switch_chips[];
>  
> +bool ksz_wol_is_active(struct ksz_device *dev);
> +
>  /* Common register access functions */
>  static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
>  {
> diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c
> index 279338451621..c5d9c3d86ddb 100644
> --- a/drivers/net/dsa/microchip/ksz_spi.c
> +++ b/drivers/net/dsa/microchip/ksz_spi.c
> @@ -114,6 +114,9 @@ static void ksz_spi_shutdown(struct spi_device *spi)
>  	if (!dev)
>  		return;
>  
> +	if (ksz_wol_is_active(dev))
> +		return;
> +
>  	if (dev->dev_ops->reset)
>  		dev->dev_ops->reset(dev);

Same here. Maybe introducing a common ksz_switch_shutdown() would be
appropriate.
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c
index 2710afad4f3a..fe818742051c 100644
--- a/drivers/net/dsa/microchip/ksz9477_i2c.c
+++ b/drivers/net/dsa/microchip/ksz9477_i2c.c
@@ -66,6 +66,9 @@  static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
 	if (!dev)
 		return;
 
+	if (ksz_wol_is_active(dev))
+		return;
+
 	if (dev->dev_ops->reset)
 		dev->dev_ops->reset(dev);
 
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 820edda82cea..c3669b9cc6ce 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -2959,6 +2959,24 @@  static int ksz_set_wol(struct dsa_switch *ds, int port,
 	return -EOPNOTSUPP;
 }
 
+bool ksz_wol_is_active(struct ksz_device *dev)
+{
+	struct dsa_port *dp;
+
+	if (!dev->wakeup_source)
+		return false;
+
+	dsa_switch_for_each_user_port(dp, dev->ds) {
+		struct ethtool_wolinfo wol;
+
+		ksz_get_wol(dev->ds, dp->index, &wol);
+		if (wol.wolopts)
+			return true;
+	}
+
+	return false;
+}
+
 static void ksz_set_xmii(struct ksz_device *dev, int port,
 			 phy_interface_t interface)
 {
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 80679f38ee12..84b1eed8cd2a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -397,6 +397,8 @@  bool ksz_get_gbit(struct ksz_device *dev, int port);
 phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
 extern const struct ksz_chip_data ksz_switch_chips[];
 
+bool ksz_wol_is_active(struct ksz_device *dev);
+
 /* Common register access functions */
 static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
 {
diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c
index 279338451621..c5d9c3d86ddb 100644
--- a/drivers/net/dsa/microchip/ksz_spi.c
+++ b/drivers/net/dsa/microchip/ksz_spi.c
@@ -114,6 +114,9 @@  static void ksz_spi_shutdown(struct spi_device *spi)
 	if (!dev)
 		return;
 
+	if (ksz_wol_is_active(dev))
+		return;
+
 	if (dev->dev_ops->reset)
 		dev->dev_ops->reset(dev);