Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1306812lqp; Mon, 15 Apr 2024 02:18:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMKLYRpIoxqaYBe7Oneiad2/gKElic0lne/MZEBS9TXQJ4xpRLwX0OvpLBSvC0DfDIf6FGvGPK9+IS681hkIncCEzx2e14kMf+cL8KPw== X-Google-Smtp-Source: AGHT+IGQL2Jfg66l0r9xLpNmzTzKqZ0/Kgr/qAt0TfhfuGYwTK8n1MRkQqAld0U3FjL5lf9HIRjq X-Received: by 2002:a17:902:d2c9:b0:1e5:c131:cae7 with SMTP id n9-20020a170902d2c900b001e5c131cae7mr9920559plc.29.1713172729658; Mon, 15 Apr 2024 02:18:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713172729; cv=pass; d=google.com; s=arc-20160816; b=M3zVcRPQN36XU3jfSBEg7B+jSTg3AZQcDvo2Gagy8SLuYJPLPUGRnPIK++iuo8eAhH Wm9La8eT9KrqjenfWRltMFABOHEalycgS3ijUI1f3VqPA7Thi700BkKbSmPqwJ/KMjYO dwgVRMOubshdooH/UVrpww6+QrcISJ1pmM6reXZr2IHyWcAqV1Uo8uhMCKF7y598yOwc VRnrfFGqAQR3Jht721IUObtkCWWugIOKhYIoEI9pDneGt5d46cZUrqjUoFDnHwFagSoZ fL2p4Lh4m00aMqWr1lePz988/8yALkU9WOMOTSMCtzaJISqeM29ciEPPRgzYekRBLQPb aKLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=EAUfjnMwkfhw75GgdSBPU2SHhCPG3M+EbZlGjKz3ysw=; fh=zv4dUbjyDRUMvZQKv32vARXx9tsay/V0VtwBaT9TpJI=; b=OXMzfhITYPXZpUMDaPR9nOazRKAAFXoBPURkTCCBXrSmZShLaDhMLXUvHIJ6TPSIDQ NlPEtwHjjHnC2AUnCXNOX92sMuPf7ZLgkGOO/KnYqMrkJd93iT8evsen4Jy+829TOzJH Gl2Y7E+KvcN3SvgSbBF7G9OKSVp+df937DYptQMNS+IYY6Ct/Z/nOFXuNjjQTDikexe9 5LpPxf+ewlOlVrJdlD5hmAcqqMDEEr2+IEsjcWAV8zwViJuo5opt1pdiieuNrBasEryH +cRRfXQwUwuTnH0fBH5FuZfl/85n8pwCjwdJFbkL80YxXIlcI4Lp4ekU+9z7Fb704ZtI JBIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MLcW8Kcb; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-144824-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lq14-20020a170903144e00b001e78888b147si754957plb.562.2024.04.15.02.18.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:18:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144824-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MLcW8Kcb; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-144824-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 50EF6281C29 for ; Mon, 15 Apr 2024 09:18:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B05114438A; Mon, 15 Apr 2024 09:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MLcW8Kcb" Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 327D53C087; Mon, 15 Apr 2024 09:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713172694; cv=none; b=kZQajb/Lad5WOWVE7j2HKA3A4+Wa1bKnSnD41UaET1BbwZ7M+uSuhcomoPCUMCszjvzEluL9HMRK525+yBfkuIZ8uJwOW1G0HoVRb7AYB0mGZZySa/WwIt3D9odXcFzRWMm5/84zjNDkWlVp+7N0SyU4owPTP7jjgPvt6rDwwCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713172694; c=relaxed/simple; bh=QLrHTPl6mjs8wBzRGDjP0lMyULnAE25B3bQkmEV1X40=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T1QVH1CKEo6FsUAmjAkZFneKp0Rj5BhfExVM3z84K74jYeY4YIOlx9m7jZSSp4rn6bvTozz4vxtMsf/08OxzjNihAFGLkSA4j5D5cSqZZSfZxq7D0UFEfJW4gDTBT3IQTt+5XkGTZHA/pKl/cC8GPTkV6Qn3wnxz0tCZqnHHWTY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MLcW8Kcb; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 6D308C0008; Mon, 15 Apr 2024 09:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713172690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EAUfjnMwkfhw75GgdSBPU2SHhCPG3M+EbZlGjKz3ysw=; b=MLcW8KcbzZTBiQ1kc7AJtN/69zVcUm3/1XZMJyv1ueSWJ58CnxEQA2T7PmHtJAUpQHVzSe s4Xr407VlmSLRRa1m63Lfj7WZHqwJTO4jqnpG381SKc77QkfKXmciDv0iQbuGQM71s3M46 qlsEMKJjWPsPaO4hOXJQy63Sf+7OJpT6H6peQg/A+ICU7PsSwsuue83l3fOoZsWwfFx4gh pZeCENIg4+rwsly4wjPhxLeUIxZczpWjiwZvFS2kju5jD9fGp0opAtuA2Udy0m30J9yOM3 BErLoNVkSaunDhon9Ucp5yK7nNd70Te8DQjySULgP0UnGqv/grw2luQC3M0wFA== From: Romain Gantois Date: Mon, 15 Apr 2024 11:18:43 +0200 Subject: [PATCH net-next v3 3/5] net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240415-rzn1-gmac1-v3-3-ab12f2c4401d@bootlin.com> References: <20240415-rzn1-gmac1-v3-0-ab12f2c4401d@bootlin.com> In-Reply-To: <20240415-rzn1-gmac1-v3-0-ab12f2c4401d@bootlin.com> To: "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 , Russell King , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= Cc: 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, "Russell King (Oracle)" , Maxime Chevallier , Romain Gantois X-Mailer: b4 0.13.0 X-GND-Sasl: romain.gantois@bootlin.com From: "Russell King (Oracle)" 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 Signed-off-by: Romain Gantois --- .../net/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 12b4a80ea3aa1..339cc42c776fb 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, -- 2.44.0