From: Minda Chen <minda.chen@starfivetech.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jose Abreu <joabreu@synopsys.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor@kernel.org>,
netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
devicetree@vger.kernel.org,
Minda Chen <minda.chen@starfivetech.com>
Subject: [net-next v1 3/6] net: stmmac: Add register NCSI device support
Date: Wed, 10 Jun 2026 15:24:17 +0800 [thread overview]
Message-ID: <20260610072420.64699-4-minda.chen@starfivetech.com> (raw)
In-Reply-To: <20260610072420.64699-1-minda.chen@starfivetech.com>
Add stmmac register support. The register NCSI code is
almost from faraday ftgmac100.c
Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 +
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 44 +++++++++++++++++--
.../ethernet/stmicro/stmmac/stmmac_platform.c | 10 ++++-
include/linux/stmmac.h | 1 +
4 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 8ba8f03e1ce0..1df0689e22a5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -383,6 +383,7 @@ struct stmmac_priv {
struct bpf_prog *xdp_prog;
struct devlink *devlink;
+ struct ncsi_dev *nsdev;
};
enum stmmac_state {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 010802389772..b6af53783883 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -41,6 +41,7 @@
#include <linux/udp.h>
#include <linux/bpf_trace.h>
#include <net/devlink.h>
+#include <net/ncsi.h>
#include <net/page_pool/helpers.h>
#include <net/pkt_cls.h>
#include <net/xdp_sock_drv.h>
@@ -4167,6 +4168,16 @@ static int __stmmac_open(struct net_device *dev,
if (ret)
goto irq_error;
+ if (priv->plat->use_ncsi) {
+ /* If using NC-SI, set our carrier on and start the stack */
+ netif_carrier_on(priv->dev);
+
+ /* Start the NCSI device */
+ ret = ncsi_start_dev(priv->nsdev);
+ if (ret)
+ goto irq_error;
+ }
+
stmmac_enable_all_queues(priv);
netif_tx_start_all_queues(priv->dev);
stmmac_enable_all_dma_irq(priv);
@@ -4250,6 +4261,9 @@ static void __stmmac_release(struct net_device *dev)
netif_tx_disable(dev);
+ if (priv->plat->use_ncsi)
+ ncsi_stop_dev(priv->nsdev);
+
/* Free the IRQ lines */
stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
@@ -7795,6 +7809,15 @@ struct plat_stmmacenet_data *stmmac_plat_dat_alloc(struct device *dev)
}
EXPORT_SYMBOL_GPL(stmmac_plat_dat_alloc);
+static void stmmac_ncsi_handler(struct ncsi_dev *nd)
+{
+ if (unlikely(nd->state != ncsi_dev_state_functional))
+ return;
+
+ netdev_info(nd->dev, "NCSI interface %s\n",
+ nd->link_up ? "up" : "down");
+}
+
static int __stmmac_dvr_probe(struct device *device,
struct plat_stmmacenet_data *plat_dat,
struct stmmac_resources *res)
@@ -8048,10 +8071,19 @@ static int __stmmac_dvr_probe(struct device *device,
if (ret)
goto error_pcs_setup;
- ret = stmmac_phylink_setup(priv);
- if (ret) {
- netdev_err(ndev, "failed to setup phy (%d)\n", ret);
- goto error_phy_setup;
+ if (priv->plat->use_ncsi) {
+ dev_info(priv->device, "Using NCSI interface\n");
+ priv->nsdev = ncsi_register_dev(ndev, stmmac_ncsi_handler);
+ if (!priv->nsdev) {
+ ret = -ENODEV;
+ goto error_phy_setup;
+ }
+ } else {
+ ret = stmmac_phylink_setup(priv);
+ if (ret) {
+ netdev_err(ndev, "failed to setup phy (%d)\n", ret);
+ goto error_phy_setup;
+ }
}
ret = stmmac_register_devlink(priv);
@@ -8082,6 +8114,8 @@ static int __stmmac_dvr_probe(struct device *device,
error_netdev_register:
stmmac_unregister_devlink(priv);
error_devlink_setup:
+ if (priv->nsdev)
+ ncsi_unregister_dev(priv->nsdev);
stmmac_phylink_destroy(priv->phylink);
error_phy_setup:
stmmac_pcs_clean(ndev);
@@ -8141,6 +8175,8 @@ void stmmac_dvr_remove(struct device *dev)
pm_runtime_get_sync(dev);
+ if (priv->nsdev)
+ ncsi_unregister_dev(priv->nsdev);
unregister_netdev(ndev);
#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 5cae2aa72906..483ecf06fc13 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -348,7 +348,7 @@ static int stmmac_mdio_setup(struct plat_stmmacenet_data *plat,
* described assume this is the case since there must be something
* connected to the MAC.
*/
- legacy_mdio = !of_phy_is_fixed_link(np) && !plat->phy_node;
+ legacy_mdio = !of_phy_is_fixed_link(np) && !plat->phy_node && !plat->use_ncsi;
if (legacy_mdio)
dev_info(dev, "Deprecated MDIO bus assumption used\n");
@@ -451,6 +451,14 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
* they are not converted to phylink. */
plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
+ if (of_property_read_bool(np, "snps,use-ncsi")) {
+ if (!IS_ENABLED(CONFIG_NET_NCSI)) {
+ dev_err(&pdev->dev, "NCSI stack not enabled\n");
+ return ERR_PTR(-EINVAL);
+ }
+ plat->use_ncsi = true;
+ }
+
/* Get max speed of operation from device tree */
of_property_read_u32(np, "max-speed", &plat->max_speed);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 4430b967abde..8c4f1b0a1a42 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -348,6 +348,7 @@ struct plat_stmmacenet_data {
int mac_port_sel_speed;
u8 vlan_fail_q;
bool provide_bus_info;
+ bool use_ncsi;
int int_snapshot_num;
int msi_mac_vec;
int msi_wol_vec;
--
2.17.1
next prev parent reply other threads:[~2026-06-10 8:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 7:24 [net-next v1 0/6] Add synopsys designware GMAC NCSI support Minda Chen
2026-06-10 7:24 ` [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property Minda Chen
2026-06-10 7:50 ` Krzysztof Kozlowski
2026-06-10 8:17 ` Andrew Lunn
2026-06-10 7:24 ` [net-next v1 2/6] net: stmmac: Checking whether priv->phylink if NULL in NCSI case Minda Chen
2026-06-10 8:26 ` Andrew Lunn
2026-06-10 7:24 ` Minda Chen [this message]
2026-06-10 7:24 ` [net-next v1 4/6] net: stmmac: Add NCSI VLAN setting Minda Chen
2026-06-10 7:24 ` [net-next v1 5/6] net: dwmac4: Add NCSI mac speed and duplex setting in NCSI case Minda Chen
2026-06-10 7:24 ` [net-next v1 6/6] net: stmmac: ethtool: Do NOT call phylink function in NCSI mode Minda Chen
2026-06-10 8:31 ` Andrew Lunn
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=20260610072420.64699-4-minda.chen@starfivetech.com \
--to=minda.chen@starfivetech.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=conor@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux@armlinux.org.uk \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=robh+dt@kernel.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