From: Bartosz Golaszewski <brgl@bgdev.pl>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Andrew Halaney <ahalaney@redhat.com>,
Alex Elder <elder@linaro.org>,
Srini Kandagatla <srinivas.kandagatla@linaro.org>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH 2/2] net: stmmac: support shared MDIO
Date: Mon, 7 Aug 2023 21:31:02 +0200 [thread overview]
Message-ID: <20230807193102.6374-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20230807193102.6374-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
When two MACs share the MDIO lines to their respective PHYs, one is
considered the logical "owner" of the bus. The secondary controller must
wait until the MDIO bus is registered before trying to attach to the
PHY.
If the mdio node is not defined for given MAC, try to read the
"snps,shared-mdio" property on its node. If it exists, parse the phandle
and store the result as the MAC's mdio device-tree node.
When registering the MDIO bus: if we know that we share it with another
MAC, lookup the MDIO bus and if it's not up yet, defer probe until it
is.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 8 ++++++++
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 ++++++
include/linux/stmmac.h | 1 +
3 files changed, 15 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index dd9e2fec5328..6a74b91595d0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -543,6 +543,14 @@ int stmmac_mdio_register(struct net_device *ndev)
if (!mdio_bus_data)
return 0;
+ if (priv->plat->flags & STMMAC_FLAG_SHARED_MDIO) {
+ new_bus = of_mdio_find_bus(mdio_node);
+ if (!new_bus)
+ return -EPROBE_DEFER;
+
+ goto bus_register_done;
+ }
+
new_bus = mdiobus_alloc();
if (!new_bus)
return -ENOMEM;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index be8e79c7aa34..11a24b1c7beb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -340,6 +340,12 @@ static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
}
}
+ if (!plat->mdio_node) {
+ plat->mdio_node = of_parse_phandle(np, "snps,shared-mdio", 0);
+ if (plat->mdio_node)
+ plat->flags |= STMMAC_FLAG_SHARED_MDIO;
+ }
+
if (plat->mdio_node) {
dev_dbg(dev, "Found MDIO subnode\n");
mdio = true;
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 3d0702510224..892f61051002 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -218,6 +218,7 @@ struct dwmac4_addrs {
#define STMMAC_FLAG_INT_SNAPSHOT_EN BIT(9)
#define STMMAC_FLAG_RX_CLK_RUNS_IN_LPI BIT(10)
#define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING BIT(11)
+#define STMMAC_FLAG_SHARED_MDIO BIT(12)
struct plat_stmmacenet_data {
int bus_id;
--
2.39.2
next prev parent reply other threads:[~2023-08-07 19:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 19:31 [PATCH 0/2] net: stmmac: allow sharing MDIO lines Bartosz Golaszewski
2023-08-07 19:31 ` [PATCH 1/2] dt-bindings: net: snps,dwmac: document the snps,shared-mdio property Bartosz Golaszewski
2023-08-07 19:31 ` Bartosz Golaszewski [this message]
2023-08-07 19:50 ` [PATCH 0/2] net: stmmac: allow sharing MDIO lines Andrew Lunn
2023-08-08 8:13 ` Bartosz Golaszewski
2023-08-08 13:09 ` Andrew Lunn
2023-08-08 13:26 ` Russell King (Oracle)
2023-08-08 14:09 ` Bartosz Golaszewski
2023-08-08 14:25 ` Andrew Lunn
2023-08-08 14:30 ` Bartosz Golaszewski
2023-08-08 14:44 ` Andrew Halaney
2023-08-08 15:10 ` Russell King (Oracle)
2023-08-08 15:15 ` Andrew Lunn
2023-08-08 15:27 ` Russell King (Oracle)
2023-08-08 18:26 ` Bartosz Golaszewski
2023-08-08 18:38 ` Russell King (Oracle)
2023-08-08 14:30 ` Russell King (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230807193102.6374-3-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=ahalaney@redhat.com \
--cc=alexandre.torgue@foss.st.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=elder@linaro.org \
--cc=joabreu@synopsys.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).