From patchwork Mon Oct 16 14:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 734133 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F3AD28E13 for ; Mon, 16 Oct 2023 14:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B3E9F for ; Mon, 16 Oct 2023 07:13:24 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qsOL4-0002pI-HV; Mon, 16 Oct 2023 16:12:58 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qsOL3-0026aT-F0; Mon, 16 Oct 2023 16:12:57 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qsOL3-008RPT-1G; Mon, 16 Oct 2023 16:12:57 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss , Conor Dooley , Krzysztof Kozlowski , Rob Herring Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, "Russell King (Oracle)" , devicetree@vger.kernel.org Subject: [PATCH net-next v4 9/9] net: dsa: microchip: do not reset the switch on shutdown if WoL is active Date: Mon, 16 Oct 2023 16:12:56 +0200 Message-Id: <20231016141256.2011861-10-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016141256.2011861-1-o.rempel@pengutronix.de> References: <20231016141256.2011861-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net For Wake on Lan we should not reconfigure, reset or power down the switch on shut down sequence. Signed-off-by: Oleksij Rempel Reviewed-by: Florian Fainelli --- drivers/net/dsa/microchip/ksz_common.c | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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);