Skip to contentSkip to conversation

net: stmmac: Add NCSI support

PATCH In review Marvin Lin 2 participants 2 messages Jul 14, 2025

Subsystems (4)
lore
Share & tools
lore

Marvin Lin

author
#0 lore raw

PATCH 1/1 net: stmmac: Add NCSI support

The NCSI is defined as the interface between BMC and Network Controller on Host side. The interface is responsible for providing external network connectivity for BMC.

This patch adds support for NCSI that registers and starts NCSI device, it also skips PHY-related operations if use-ncsi property is defined in the DTS.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |   2 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 166 +++++++++++++-----
 .../ethernet/stmicro/stmmac/stmmac_platform.c |  27 ++-
 include/linux/stmmac.h                        |   1 +
 4 files changed, 142 insertions(+), 54 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +2 -0
index cda09cf5dcca..9dc386e0bc6b 100644
@@ -365,6 +365,8 @@ struct stmmac_priv {
 	/* XDP BPF Program */
 	unsigned long *af_xdp_zc_qps;
 	struct bpf_prog *xdp_prog;
+
+	struct ncsi_dev *ncsidev;
 };
 
 enum stmmac_state {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +119 -47

268 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +20 -7
index b80c1efdb323..de500e59461f 100644
@@ -447,17 +447,30 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
 		eth_zero_addr(mac);
 	}
 
-	phy_mode = device_get_phy_mode(&pdev->dev);
-	if (phy_mode < 0)
-		return ERR_PTR(phy_mode);
+	if (of_get_property(pdev->dev.of_node, "use-ncsi", NULL)) {
+		plat->use_ncsi = true;
+		plat->has_xgmac = 0;
+		plat->has_gmac4 = 0;
+		plat->has_gmac = 0;
+	} else {
+		plat->use_ncsi = false;
+	}
 
-	plat->phy_interface = phy_mode;
+	if (!plat->use_ncsi) {
+		phy_mode = device_get_phy_mode(&pdev->dev);
+		if (phy_mode < 0)
+			return ERR_PTR(phy_mode);
+
+		plat->phy_interface = phy_mode;
+	}
 	rc = stmmac_of_get_mac_mode(np);
 	plat->mac_interface = rc < 0 ? plat->phy_interface : rc;
 
-	/* Some wrapper drivers still rely on phy_node. Let's save it while
-	 * they are not converted to phylink. */
-	plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
+	if (!plat->use_ncsi) {
+		/* Some wrapper drivers still rely on phy_node. Let's save it while
+		 * they are not converted to phylink. */
+		plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
+	}
 
 	/* PHYLINK automatically parses the phy-handle property */
 	plat->port_node = of_fwnode_handle(np);
include/linux/stmmac.h +1 -0
index 26ddf95d23f9..668768043f7e 100644
@@ -288,5 +288,6 @@ struct plat_stmmacenet_data {
 	int msi_tx_base_vec;
 	const struct dwmac4_addrs *dwmac4_addrs;
 	unsigned int flags;
+	int use_ncsi;
 };
 #endif
Signature · 1 line
2.34.1
#1 lore raw

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_init_dma_engine(struct stmmac_priv *priv) · line 3141

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +6 -4
-	ret = stmmac_reset(priv, priv->ioaddr);
-	if (ret) {
-		netdev_err(priv->dev, "Failed to reset the dma\n");
-		return ret;
+	if (!priv->plat->use_ncsi) {
+		ret = stmmac_reset(priv, priv->ioaddr);
+		if (ret) {
+			netdev_err(priv->dev, "Failed to reset the dma\n");
+			return ret;
+		}
 	}

Please break this patch up into a series and include good commit messages. You can then explain why this change is safe.

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_hw_teardown(struct net_device *dev) · line 3654

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +6 -0
 	/* DMA Configuration */
@@ -3643,6 +3646,14 @@ static void stmmac_hw_teardown(struct net_device *dev)
 	clk_disable_unprepare(priv->plat->clk_ptp_ref);
 }
 
+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");

Please don't spam the kernel log. Only do prints if something goes wrong.

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
+}
+
 static void stmmac_free_irq(struct net_device *dev,
 			    enum request_irq_err irq_err, int irq_idx)
 {
@@ -4046,14 +4057,16 @@ static int __stmmac_open(struct net_device *dev,
 	if (ret < 0)
 		return ret;
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_open(struct net_device *dev, · line 4061

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -8
-	if ((!priv->hw->xpcs ||
-	     xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) {
-		ret = stmmac_init_phy(dev);
-		if (ret) {
-			netdev_err(priv->dev,
-				   "%s: Cannot attach to PHY (error: %d)\n",
-				   __func__, ret);
-			goto init_phy_error;
+	if (!priv->plat->use_ncsi) {
+		if ((!priv->hw->xpcs ||

My understanding of NCSI is that you have an additional RGMII like port feeding into the MAC. The MAC still has all its media machinery, a PCS, PHY etc. Something needs to drive that PCS and PHY. So it would be good to explain in the commit message why you are removing all this.

Andrew