Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp190036rdh; Wed, 25 Oct 2023 22:12:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHW+tpFVMPjQgSaomzlx43In/3IJDy/geJTA5iTQ2G/mXr1pTTL6cy3KgUAxHksHcoT8du9 X-Received: by 2002:a67:b703:0:b0:457:c2ff:ad98 with SMTP id h3-20020a67b703000000b00457c2ffad98mr16668201vsf.13.1698297146049; Wed, 25 Oct 2023 22:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698297146; cv=none; d=google.com; s=arc-20160816; b=tXdQBdDAwMNwoFKR3bNmGSsLjZzQMhsZDUuZts8O/eHcRJ1rMhlik5MEZM5CiKWDke l3xTMBSQoW1JFubqCiBBkOQy0S1fZYullhIV7EWsh+KxeoZtLsKZBCy9BbvaNRScp+4l grzaMU/FOIQBD2uKRyj26NPt/slkYzLA08Z8Te13q5x1Fkw2loJEU3dBek0oGNY14gaE hW9llyDagsGa0mvd4zEvIPXGADg0vLF+9oL4WEHCktRzEB1NGJ0lHLX9TS0O5C2Q8DML B9oO8rqz2CQH+jyduj8+cupjO7A0K1SPEJcb60uvYlNLxAFb2mC3kEfmjAouUQ2eZoo1 FxZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/U+PXeayzjTHzCcnOG6YYmRWlilwvc/ShpQW6JQUM/w=; fh=dtm4yT6MkhVTfBPO3z+Y52DNxAcSgnFad+iu/czBlro=; b=GzZToczjzxFyhquPW9qLhMTabuGTyfJLD+vrzA2GYF92zqd1jN9y0F83qW6jxS06v9 btdvvVqw6Qn+7Nmpe1WPEQ39vg7Jf5lOB4giEl+n482nH+t1OQcPTIzwlFnLh9zJsF/H JyDZbXmdatW8nK6vvMn3x+kNILHZWUBYZY0z3eFcqEuHlMTiJnAGiEVBCmCGhSDNLK3M Y7lAmCLU65/sYnqVtXjEX8nsIFoTKWxLsOJDzewgPyc0iXgrh3SqKpY8rsxvTwL7RuEi pemUGL1whP3thQXgSoXx0V5Hnr5fTxRHBJzkNoOGAW6lhqrRAziUndHZTNz9oAWTUD1v PLuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w21-20020a25df15000000b00da06a0c36aesi5549261ybg.657.2023.10.25.22.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 22:12:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1ED3F80740C7; Wed, 25 Oct 2023 22:11:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343804AbjJZFLb (ORCPT + 99 others); Thu, 26 Oct 2023 01:11:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233186AbjJZFLX (ORCPT ); Thu, 26 Oct 2023 01:11:23 -0400 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 2A66B18C for ; Wed, 25 Oct 2023 22:11:19 -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 1qvsdy-0004YA-OT; Thu, 26 Oct 2023 07:10:54 +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 1qvsdw-004L1U-OA; Thu, 26 Oct 2023 07:10:52 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qvsdw-009il8-2A; Thu, 26 Oct 2023 07:10:52 +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 , Florian Fainelli , Vladimir Oltean , 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 v8 4/5] net: dsa: microchip: Refactor switch shutdown routine for WoL preparation Date: Thu, 26 Oct 2023 07:10:50 +0200 Message-Id: <20231026051051.2316937-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231026051051.2316937-1-o.rempel@pengutronix.de> References: <20231026051051.2316937-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 25 Oct 2023 22:11:50 -0700 (PDT) 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 Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean --- drivers/net/dsa/microchip/ksz9477_i2c.c | 5 +---- drivers/net/dsa/microchip/ksz_common.c | 19 +++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/ksz_spi.c | 5 +---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c index 2710afad4f3a..cac4a607e54a 100644 --- a/drivers/net/dsa/microchip/ksz9477_i2c.c +++ b/drivers/net/dsa/microchip/ksz9477_i2c.c @@ -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); } diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 00be812bef40..3b48e42148a0 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -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) { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 06996813f9a8..14b4828f80a1 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -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) diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c index 279338451621..6f6d878e742c 100644 --- a/drivers/net/dsa/microchip/ksz_spi.c +++ b/drivers/net/dsa/microchip/ksz_spi.c @@ -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); } -- 2.39.2