From patchwork Tue Apr 2 15:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13614368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A09EBCD1284 for ; Tue, 2 Apr 2024 15:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id:MIME-Version:Subject:Cc :To:From:References:In-Reply-To:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6Pjnb47KWJpn7Y7cidsu+Tu20VLECSPpKPJNBGZlTEw=; b=2pk4RIuxg4EmHH /+B09jDlBUkm6HxkLplp4jl6E57uqyJ0LCEWg0NoTMx0F+I9OPWOMo16fSx62WTIt2JpiPtZ6NQan C+r7PMZCaNqejjIFrDlwZy5Bc1lFhf8yOWJH9ANGZrF6cMgiWFErwqfJ4AcAyamEvwJtuu0d/f1yn TJXSjJu00rp20wJzmuhttAJorlI+Ki05SNZ5ClzU7v5/2rw2Awf27/Bcb257NXguiBc2BEj1yclm3 a/NjmqZ6wneacsO4BdSVbhAUdtnzUwHCd2kU8/6afr0ZVXX7xKfRU/ie9y+PAHQqY9Bp0yZj4GY1K FlRzF1rOJJyGq38XO4ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrgSd-0000000BuLy-3KtB; Tue, 02 Apr 2024 15:54:07 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrgSa-0000000Btfq-3Mhk for linux-arm-kernel@lists.infradead.org; Tue, 02 Apr 2024 15:54:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PXpSDMwoudBQQUvwRwf46Fwc8o8+Vle+EwFXwBBNUhQ=; b=xdmmtHtwZUS1EkgJDhgYJ6230L V63f79UsEb3MsGPvSllt3H5Qm+Fc6YCzpMj/hqAu2+gjF+Xdic6CT0A/6auASKucYVgXo3d/6u7df P/dIDT0l3M1vTZDs93ghl+HPeTGusJ3Rn6yn3m/6D7t4P/G3cLv8B7M941Kh9EKjUVTXMndA1o1jA 8Gk+XQpGTTpXPR9h6tChpvpP8bH0XLfC9VZanN5kio5JbfT0Mkh4ilGb5unrWw9dvNhOMWS/7BbHB fr9+HbxscnxX17YgI3ZNqYrVOUAsb1izzEQXkYs06E4F0Y41j6yE894m5IWGlLYmR+qALVPtj1bAo zU6ZoNJQ==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:55404 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rrgQJ-00070v-06; Tue, 02 Apr 2024 16:51:43 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rrgQJ-005ZO4-GB; Tue, 02 Apr 2024 16:51:43 +0100 In-Reply-To: References: From: "Russell King (Oracle)" To: Romain Gantois Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Alexandre Torgue , Jose Abreu , Maxime Coquelin , =?iso-8859-1?q?Cl=E9ment_L=E9g?= =?iso-8859-1?q?er?= , Thomas Petazzoni , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 1/2] net: stmmac: introduce pcs_init/pcs_exit stmmac operations MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 02 Apr 2024 16:51:43 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240402_085404_945698_09A9A4FC X-CRM114-Status: GOOD ( 13.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce a mechanism whereby platforms can create their PCS instances prior to the network device being published to userspace, but after some of the core stmmac initialisation has been completed. This means that the data structures that platforms need will be available. Signed-off-by: Russell King (Oracle) Reviewed-by: Maxime Chevallier --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 14 ++++++++++++++ include/linux/stmmac.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index fe3498e86de9..25fa33ae7017 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7208,6 +7208,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv) if (ret) return ret; + if (priv->plat->pcs_init) { + ret = priv->plat->pcs_init(priv, priv->hw); + if (ret) + return ret; + } + /* Get the HW capability (new GMAC newer than 3.50a) */ priv->hw_cap_support = stmmac_get_hw_features(priv); if (priv->hw_cap_support) { @@ -7290,6 +7296,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv) return 0; } +static void stmmac_hw_exit(struct stmmac_priv *priv) +{ + if (priv->plat->pcs_exit) + priv->plat->pcs_exit(priv, priv->hw); +} + static void stmmac_napi_add(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); @@ -7804,6 +7816,7 @@ int stmmac_dvr_probe(struct device *device, priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); error_mdio_register: + stmmac_hw_exit(priv); stmmac_napi_del(ndev); error_hw_init: destroy_workqueue(priv->wq); @@ -7844,6 +7857,7 @@ void stmmac_dvr_remove(struct device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); + stmmac_hw_exit(priv); destroy_workqueue(priv->wq); mutex_destroy(&priv->lock); bitmap_free(priv->af_xdp_zc_qps); diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index dfa1828cd756..941fde506e51 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -285,6 +285,8 @@ struct plat_stmmacenet_data { int (*crosststamp)(ktime_t *device, struct system_counterval_t *system, void *ctx); void (*dump_debug_regs)(void *priv); + int (*pcs_init)(struct stmmac_priv *priv, struct mac_device_info *hw); + void (*pcs_exit)(struct stmmac_priv *priv, struct mac_device_info *hw); void *bsp_priv; struct clk *stmmac_clk; struct clk *pclk; From patchwork Tue Apr 2 15:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13614369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A62CCD1284 for ; Tue, 2 Apr 2024 15:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id:MIME-Version:Subject:Cc :To:From:References:In-Reply-To:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6LYyZDGqWzm3Feo8kqSysCcQmdLvxGCq9pfVxKvRwek=; b=zsSoBFHcoNgal3 tCrak2i5+Ga2tdnF1tz0irpGPgL+ujWr4WGZiQzcV2vzgPmJF7aiREM5wG95xwz/NJD4eNL1iHT9G BVeFFPiMWyHoWuO9HqKDiQUwXwxHYre6daqk78q+D8/K98T4lQsh9P1wlFTThT70uxhDrG+QnLDOK VaB+y8HHgjl6pLB1rkxCYeO7Uibp4hyBW2CvN+mHa/O/4EgFhdLSSk2EHapevsYG03+CsuTvxr8SV GRadzx5L9bsnnEehm0iALE9RPh4LaAzZEdr5QLzV5uMcI842XxuCI33AgCTmCCxFfMnrDdKQjyF4A bHE6YesNZmuZy/j09SFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrgSf-0000000BuMl-1cR6; Tue, 02 Apr 2024 15:54:09 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrgSb-0000000BtgJ-2wjh for linux-arm-kernel@lists.infradead.org; Tue, 02 Apr 2024 15:54:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RvfXLwxzoiDRSX+2p4VdbeCbmA1uTdKtDMO1TwE8wKQ=; b=yVIFvZCqRAA0hdk4pfGWRpOJKu E70QhvJ1PrTPpPdH6hAZkVEFw9TI+L+5uYvzipMacY+H5ceFkcXFL6cWOmDOLrcfpnD4cY6jua1os isLKYuTBpJ39VD+6i8ptPBsXw5e/COXEBdL9K5iaUZ23RYVVl5N09Jwnt1glNeiePPqBqEbPtFDME D1scf8Gz0HX7g2lCdZx8vkM7tzBgTwFhJfB3eJmwxjT0CmaL6pwJuZ0Qk1RakauJxbkD0gJzCe3UA QLLF/ElOOBoL87IqUHQNL/52zdA+Ab/UqLE2THtF5Kzh/2IxL0Pc8TRB8v0QvZQ5mlozDmcT0Jybr tj5kzhOQ==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:55416 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rrgQO-000715-1J; Tue, 02 Apr 2024 16:51:48 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rrgQO-005ZOA-KT; Tue, 02 Apr 2024 16:51:48 +0100 In-Reply-To: References: From: "Russell King (Oracle)" To: Romain Gantois Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Alexandre Torgue , Jose Abreu , Maxime Coquelin , =?iso-8859-1?q?Cl=E9ment_L=E9g?= =?iso-8859-1?q?er?= , Thomas Petazzoni , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 2/2] net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 02 Apr 2024 16:51:48 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240402_085405_751108_8F8B8354 X-CRM114-Status: GOOD ( 19.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use the newly introduced pcs_init() and pcs_exit() operations to create and destroy the PCS instance at a more appropriate moment during the driver lifecycle, thereby avoiding publishing a network device to userspace that has not yet finished its PCS initialisation. There are other similar issues with this driver which remain unaddressed, but these are out of scope for this patch. Signed-off-by: Russell King (Oracle) Reviewed-by: Maxime Chevallier --- .../ethernet/stmicro/stmmac/dwmac-socfpga.c | 109 +++++++++--------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 12b4a80ea3aa..67ca163936c8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -379,6 +379,58 @@ static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac) return 0; } +static int socfpga_dwmac_pcs_init(struct stmmac_priv *priv, + struct mac_device_info *hw) +{ + struct socfpga_dwmac *dwmac = priv->plat->bsp_priv; + struct regmap_config pcs_regmap_cfg = { + .reg_bits = 16, + .val_bits = 16, + .reg_shift = regmap_upshift(1), + }; + struct mdio_regmap_config mrc; + struct regmap *pcs_regmap; + struct phylink_pcs *pcs; + struct mii_bus *pcs_bus; + + if (!dwmac->tse_pcs_base) + return 0; + + pcs_regmap = devm_regmap_init_mmio(priv->device, dwmac->tse_pcs_base, + &pcs_regmap_cfg); + if (IS_ERR(pcs_regmap)) + return PTR_ERR(pcs_regmap); + + memset(&mrc, 0, sizeof(mrc)); + mrc.regmap = pcs_regmap; + mrc.parent = priv->device; + mrc.valid_addr = 0x0; + mrc.autoscan = false; + + /* Can't use ndev->name here because it will not have been initialised, + * and in any case, the user can rename network interfaces at runtime. + */ + snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", + dev_name(priv->device)); + pcs_bus = devm_mdio_regmap_register(priv->device, &mrc); + if (IS_ERR(pcs_bus)) + return PTR_ERR(pcs_bus); + + pcs = lynx_pcs_create_mdiodev(pcs_bus, 0); + if (IS_ERR(pcs)) + return PTR_ERR(pcs); + + hw->phylink_pcs = pcs; + return 0; +} + +static void socfpga_dwmac_pcs_exit(struct stmmac_priv *priv, + struct mac_device_info *hw) +{ + if (hw->phylink_pcs) + lynx_pcs_destroy(hw->phylink_pcs); +} + static int socfpga_dwmac_probe(struct platform_device *pdev) { struct plat_stmmacenet_data *plat_dat; @@ -426,6 +478,8 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) dwmac->ops = ops; plat_dat->bsp_priv = dwmac; plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed; + plat_dat->pcs_init = socfpga_dwmac_pcs_init; + plat_dat->pcs_exit = socfpga_dwmac_pcs_exit; ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); if (ret) @@ -444,48 +498,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) if (ret) goto err_dvr_remove; - /* Create a regmap for the PCS so that it can be used by the PCS driver, - * if we have such a PCS - */ - if (dwmac->tse_pcs_base) { - struct regmap_config pcs_regmap_cfg; - struct mdio_regmap_config mrc; - struct regmap *pcs_regmap; - struct mii_bus *pcs_bus; - - memset(&pcs_regmap_cfg, 0, sizeof(pcs_regmap_cfg)); - memset(&mrc, 0, sizeof(mrc)); - - pcs_regmap_cfg.reg_bits = 16; - pcs_regmap_cfg.val_bits = 16; - pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1); - - pcs_regmap = devm_regmap_init_mmio(&pdev->dev, dwmac->tse_pcs_base, - &pcs_regmap_cfg); - if (IS_ERR(pcs_regmap)) { - ret = PTR_ERR(pcs_regmap); - goto err_dvr_remove; - } - - mrc.regmap = pcs_regmap; - mrc.parent = &pdev->dev; - mrc.valid_addr = 0x0; - mrc.autoscan = false; - - snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); - pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc); - if (IS_ERR(pcs_bus)) { - ret = PTR_ERR(pcs_bus); - goto err_dvr_remove; - } - - stpriv->hw->phylink_pcs = lynx_pcs_create_mdiodev(pcs_bus, 0); - if (IS_ERR(stpriv->hw->phylink_pcs)) { - ret = PTR_ERR(stpriv->hw->phylink_pcs); - goto err_dvr_remove; - } - } - return 0; err_dvr_remove: @@ -494,17 +506,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) return ret; } -static void socfpga_dwmac_remove(struct platform_device *pdev) -{ - struct net_device *ndev = platform_get_drvdata(pdev); - struct stmmac_priv *priv = netdev_priv(ndev); - struct phylink_pcs *pcs = priv->hw->phylink_pcs; - - stmmac_pltfr_remove(pdev); - - lynx_pcs_destroy(pcs); -} - #ifdef CONFIG_PM_SLEEP static int socfpga_dwmac_resume(struct device *dev) { @@ -576,7 +577,7 @@ MODULE_DEVICE_TABLE(of, socfpga_dwmac_match); static struct platform_driver socfpga_dwmac_driver = { .probe = socfpga_dwmac_probe, - .remove_new = socfpga_dwmac_remove, + .remove_new = stmmac_pltfr_remove, .driver = { .name = "socfpga-dwmac", .pm = &socfpga_dwmac_pm_ops,