Message ID | 20231128094538.228039-1-maxime.chevallier@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3771212vqx; Tue, 28 Nov 2023 00:50:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0DufCvFGDxhErpP4mdcSThpV8/XRENBSwqZKmuGL3CxOW018XrZkz6nKOpFtC4cbMfR09 X-Received: by 2002:a17:902:7688:b0:1cf:ef92:18f3 with SMTP id m8-20020a170902768800b001cfef9218f3mr2571980pll.58.1701161455110; Tue, 28 Nov 2023 00:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701161455; cv=none; d=google.com; s=arc-20160816; b=mLOl/r4yAtmpP+HuM6YxJ6D9kH1o/Mz53k/hAb/VJ2+0Wsjq4G3i9DeXc3kaLb/UsM GznnIVIZfKSYyInA1FYh3BVjJXYcidRuItq34+HSrZMK/C1qFNUQjr2hy97UYFfimXvg mvyZsQjIvE3xgNwqeLzZNscI/WZKRp6DY5n/6rFBLzdoaMgbXt5nMHYcihOkRJM7hP7I DIqh6j2Fbs8ToWtqxD96ddcEjjIu30+3hTBbbv2timj6VWjDDsG+9iKdeoCQEMx42IA+ nOtU1Php2Nnizl1kbbpQKgIr+wgOYi4EiwkrPOuJ314e6T87QFMve2ZFLYHZz5sypZCz COCA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=qYJnE4Z1r7jKRPOrGAwXhHc797bbl+1US3cszB9aa9E=; fh=hPtj/h/NSBXiXh9p0DfPt8/pirJa6GzTo0pcgGy579c=; b=FZ+Wy3Ckc83ne63mARo4gRwwR8bQGmr3DdoIM9Au7M1vVCPuIkI5H90FSnb1g4Bul5 vbg7N4I7wgOZAE0fkJ1EwgcqGKRO15Zqlk4FNCtz/VNaXya7KOaBQJrfGTdyNeKJL9WG mii+N1h53sUpa25xS5AWMT5hlQPTwWA5E8C8gT/eU94dC3Au5FXWSWaZxe9+ItWIJfBa SpMAuLTSkwz84ytnKfc2Do0/fWjAGrh0RhNYf6WaRxnSznxl8VcmUGKWtI/8TjNiaqIJ 2xr0N5VkStuGpH7uhuYwEOUlr/BoJPRtyTc7jFeEkyxBFbdzJTvOI/MC30hStY1qpF64 BGmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Biez3ElI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d16-20020a170903231000b001cfd934bda1si2986711plh.232.2023.11.28.00.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:50:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Biez3ElI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 58A4A807DE2B; Tue, 28 Nov 2023 00:50:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232806AbjK1IuF (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 28 Nov 2023 03:50:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234660AbjK1IuE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Nov 2023 03:50:04 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91230E7; Tue, 28 Nov 2023 00:50:09 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2A138C0011; Tue, 28 Nov 2023 08:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1701161408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qYJnE4Z1r7jKRPOrGAwXhHc797bbl+1US3cszB9aa9E=; b=Biez3ElIDFQtKoAoSEC77AQXzKbt7Ch1XeZiVYhh0NXtG9v9GlfxXJMHUGbOSfb77LUOcn 3R+0msBidXWkzyP/oA03LjO59JoGEB8nwVxWQhzryO7/3lBgdfOGe+ccmpFTRzo+6Hyh/S GD+Y3ayQHKYfSpqkoEeBAFW7jASzaG7FBLQy3BcrLGsrxmfREYLffgYMaUk3magZpde8IY Jpkm3fVUL0fUT7BMlooYuZIqQDCRhLrK/p3fM+xSrJ+AkeIXExE94qMn2452ctDbzk7VWP 2n/LDss+hsxqQFoi5sfx/ccHyQ5hgvuoH436OaEzpLi2b4pI+5FaKvrDAG795Q== From: Maxime Chevallier <maxime.chevallier@bootlin.com> To: davem@davemloft.net Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Jakub Kicinski <kuba@kernel.org>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, linux-arm-kernel@lists.infradead.org, Alexandre Torgue <alexandre.torgue@foss.st.com>, Jose Abreu <joabreu@synopsys.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Simon Horman <horms@kernel.org>, linux-stm32@st-md-mailman.stormreply.com, alexis.lothore@bootlin.com Subject: [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available Date: Tue, 28 Nov 2023 10:45:37 +0100 Message-ID: <20231128094538.228039-1-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: maxime.chevallier@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 28 Nov 2023 00:50:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783797073905024886 X-GMAIL-MSGID: 1783797073905024886 |
Series |
[net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
|
|
Commit Message
Maxime Chevallier
Nov. 28, 2023, 9:45 a.m. UTC
The SGMII adapter isn't present on all dwmac-socfpga implementations.
Make sure we don't try to configure it if we don't have this adapter.
Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Tue, 28 Nov 2023 10:45:37 +0100 Maxime Chevallier <maxime.chevallier@bootlin.com> wrote: > The SGMII adapter isn't present on all dwmac-socfpga implementations. > Make sure we don't try to configure it if we don't have this adapter. > > Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver") > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> > --- > drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > index ba2ce776bd4d..ae120792e1b6 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable) > { > u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE; > > - writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); > + if (dwmac->sgmii_adapter_base) > + writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); > } > > static int socfpga_set_phy_mode_common(int phymode, u32 *val) Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> As a follow-up improvement, there's an open-coded version of socfpga_sgmii_config() in socfpga_dwmac_fix_mac_speed(), which could be rewritten as such: socfpga_sgmii_config(dwmac, false); if (splitter_base) { val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG); val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK; switch (speed) { case 1000: val |= EMAC_SPLITTER_CTRL_SPEED_1000; break; case 100: val |= EMAC_SPLITTER_CTRL_SPEED_100; break; case 10: val |= EMAC_SPLITTER_CTRL_SPEED_10; break; default: return; } writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG); } if (phy_dev) socfpga_sgmii_config(dwmac, true); But of course, that's not a fix so it should be a separate improvement. Best regards, Thomas
Hello Thomas, On Tue, 28 Nov 2023 10:18:41 +0100 Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote: > On Tue, 28 Nov 2023 10:45:37 +0100 > Maxime Chevallier <maxime.chevallier@bootlin.com> wrote: > > > The SGMII adapter isn't present on all dwmac-socfpga implementations. > > Make sure we don't try to configure it if we don't have this adapter. > > > > Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver") > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> > > --- > > drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > > index ba2ce776bd4d..ae120792e1b6 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c > > @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable) > > { > > u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE; > > > > - writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); > > + if (dwmac->sgmii_adapter_base) > > + writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); > > } > > > > static int socfpga_set_phy_mode_common(int phymode, u32 *val) > > Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> > > As a follow-up improvement, there's an open-coded version of > socfpga_sgmii_config() in socfpga_dwmac_fix_mac_speed(), which could be > rewritten as such: > > socfpga_sgmii_config(dwmac, false); > > if (splitter_base) { > val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG); > val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK; [...] I did saw this, but as this is merely a non-functional rework, I'd like to target this to net-next, so I'll wait for the fix to land and follow-up with this rework indeed. Thanks for the review, Maxime
On Tue, Nov 28, 2023 at 10:45:37AM +0100, Maxime Chevallier wrote: > The SGMII adapter isn't present on all dwmac-socfpga implementations. > Make sure we don't try to configure it if we don't have this adapter. If it does not exist, why even try to call socfpga_sgmii_config()? It seems like this test needs moving up the call stack. socfpga_gen5_set_phy_mode(): if (phymode == PHY_INTERFACE_MODE_SGMII) if (dwmac->sgmii_adapter_base) socfpga_sgmii_config(dwmac, true); else return -EINVAL; Same in socfpga_gen10_set_phy_mode()? Andrew
Hi Andrew, On Tue, 28 Nov 2023 17:37:30 +0100 Andrew Lunn <andrew@lunn.ch> wrote: > On Tue, Nov 28, 2023 at 10:45:37AM +0100, Maxime Chevallier wrote: > > The SGMII adapter isn't present on all dwmac-socfpga implementations. > > Make sure we don't try to configure it if we don't have this adapter. > > If it does not exist, why even try to call socfpga_sgmii_config()? > > It seems like this test needs moving up the call stack. socfpga_gen5_set_phy_mode(): > > if (phymode == PHY_INTERFACE_MODE_SGMII) > if (dwmac->sgmii_adapter_base) > socfpga_sgmii_config(dwmac, true); > else > return -EINVAL; I don't have access to a platform with the SGMII adapter available, but my understanding is that we shouldn't error-out when we don't have the adapter, as some other component (like the lynx PCS) might be there to handle that mode. However you have a valid point in that we might want to check if we have either an SGMII adapter or a PCS, and if we have none of these we error-out. Thanks for the suggestion, I'll address that :) Maxime
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index ba2ce776bd4d..ae120792e1b6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable) { u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE; - writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); + if (dwmac->sgmii_adapter_base) + writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); } static int socfpga_set_phy_mode_common(int phymode, u32 *val)