diff mbox series

[net-next,v4,9/9] net: dsa: microchip: do not reset the switch on shutdown if WoL is active

Message ID 20231016141256.2011861-10-o.rempel@pengutronix.de
State New
Headers show
Series net: dsa: microchip: provide Wake on LAN support | expand

Commit Message

Oleksij Rempel Oct. 16, 2023, 2:12 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/ksz_common.c | 29 +++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

Comments

Florian Fainelli Oct. 16, 2023, 3:39 p.m. UTC | #1
On 10/16/2023 7:12 AM, 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>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 85513318d165..abfd9dcab450 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -3565,6 +3565,33 @@  static int ksz_set_wol(struct dsa_switch *ds, int port,
 	return -EOPNOTSUPP;
 }
 
+/**
+ * ksz_wol_is_active - Check if Wake-on-LAN is active on any port.
+ * @dev: The device structure.
+ *
+ * This function iterates through each user port on the switch, checking if
+ * Wake-on-LAN (WoL) is active on any of them.
+ *
+ * Return: true if WoL is active on any port, false otherwise.
+ */
+static 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 int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
 				    const unsigned char *addr)
 {
@@ -3822,7 +3849,7 @@  EXPORT_SYMBOL(ksz_switch_alloc);
  */
 void ksz_switch_shutdown(struct ksz_device *dev)
 {
-	if (dev->dev_ops->reset)
+	if (dev->dev_ops->reset && !ksz_wol_is_active(dev))
 		dev->dev_ops->reset(dev);
 
 	dsa_switch_shutdown(dev->ds);