[PATCH net-next v3 2/2] net: stmmac: dwmac-socfpga: Add support for Agilex5 TSN GMAC with FPGA converter

muhammad.nazim.amirul.nazle.asmade at altera.com muhammad.nazim.amirul.nazle.asmade at altera.com
Wed Dec 2 21:09:00 PST 2026


From: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade at altera.com>

The Agilex5 SoCDK TSN Config2 board uses a GMII-to-RGMII converter
implemented as FPGA soft IP between gmac1 and its PHY. The converter
presents GMII to the MAC and adds both the RGMII TX and RX delays, so
"rgmii-id" is the only RGMII phy-mode that describes this board.

Add the "altr,socfpga-stmmac-agilex5-tsn" compatible with dedicated
match .data ops that extend the standard Agilex5 setup. For RGMII
phy-modes, select GMII for the MAC interface and set
has_internal_tx_delay and has_internal_rx_delay. The stmmac core then
passes "rgmii" to the PHY for "rgmii-id", and rejects "rgmii",
"rgmii-txid" and "rgmii-rxid" at probe time. Other phy-modes do not go
through the converter and keep the standard Agilex5 behaviour.

Store the MAC-side mode in a new mac_interface field, and rename
socfpga_get_plat_phymode() to socfpga_get_mac_interface() to match.

Signed-off-by: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade at altera.com>
Reviewed-by: Andrew Lunn <andrew at lunn.ch>
Reviewed-by: Maxime Chevallier <maxime.chevallier at bootlin.com>
---
Previously patch 4 of the v6 board series; split out for net-next.

v3: Address the netdev AI review on v2, forwarded by Jakub Kicinski:
    - Only apply the converter setup for RGMII phy-modes, so SGMII and
      1000base-x keep the standard Agilex5 behaviour.
    - Set has_internal_tx_delay and has_internal_rx_delay instead of
      rewriting phy_interface. "rgmii-id" is now the only accepted RGMII
      phy-mode; "rgmii", "rgmii-txid" and "rgmii-rxid" are rejected at
      probe time. This replaces the v2 behaviour of silently rewriting
      every RGMII mode to "rgmii".
    - Rename socfpga_get_plat_phymode() to socfpga_get_mac_interface()
      and update the splitter comments to match.
    - Rebase on current net-next.
v2: No driver changes.
v6: No changes from v5.
v5: Replace of_device_is_compatible() probe check with dedicated
    socfpga_agilex5_tsn_gmac_ops via match .data, per Krzysztof
    Kozlowski and Dinh Nguyen.
v4: Add Reviewed-by from Andrew Lunn.

 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   | 49 ++++++++++++++-----
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index 4e0187ffe0d3..273ff8b08c76 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -69,12 +69,13 @@ struct socfpga_dwmac {
 	void __iomem *tse_pcs_base;
 	void __iomem *sgmii_adapter_base;
 	bool f2h_ptp_ref_clk;
+	phy_interface_t mac_interface;
 	const struct socfpga_dwmac_ops *ops;
 };
 
-static phy_interface_t socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
+static phy_interface_t socfpga_get_mac_interface(struct socfpga_dwmac *dwmac)
 {
-	return dwmac->plat_dat->phy_interface;
+	return dwmac->mac_interface;
 }
 
 static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
@@ -90,7 +91,7 @@ static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 {
 	struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)bsp_priv;
 	void __iomem *sgmii_adapter_base = dwmac->sgmii_adapter_base;
-	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
+	phy_interface_t phymode = socfpga_get_mac_interface(dwmac);
 	void __iomem *splitter_base = dwmac->splitter_base;
 	u32 val;
 
@@ -385,7 +386,7 @@ static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac,
 				     struct device *dev)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
-	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
+	phy_interface_t phymode = socfpga_get_mac_interface(dwmac);
 	u32 reg_offset = dwmac->reg_offset;
 	u32 reg_shift = dwmac->reg_shift;
 	u32 ctrl, val, module;
@@ -395,9 +396,9 @@ static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac,
 		return -EINVAL;
 	}
 
-	/* Overwrite val to GMII if splitter core is enabled. The phymode here
-	 * is the actual phy mode on phy hardware, but phy interface from
-	 * EMAC core is GMII.
+	/* Overwrite val to GMII if splitter core is enabled. The splitter
+	 * converts the GMII interface of the EMAC core to the mode given by
+	 * phy-mode.
 	 */
 	if (dwmac->splitter_base)
 		val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
@@ -444,7 +445,7 @@ static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac,
 				      struct device *dev)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
-	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
+	phy_interface_t phymode = socfpga_get_mac_interface(dwmac);
 	u32 reg_offset = dwmac->reg_offset;
 	u32 reg_shift = dwmac->reg_shift;
 	u32 ctrl, val, module;
@@ -452,9 +453,9 @@ static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac,
 	if (socfpga_set_phy_mode_common(phymode, &val))
 		return -EINVAL;
 
-	/* Overwrite val to GMII if splitter core is enabled. The phymode here
-	 * is the actual phy mode on phy hardware, but phy interface from
-	 * EMAC core is GMII.
+	/* Overwrite val to GMII if splitter core is enabled. The splitter
+	 * converts the GMII interface of the EMAC core to the mode given by
+	 * phy-mode.
 	 */
 	if (dwmac->splitter_base)
 		val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
@@ -682,6 +683,8 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
 	plat_dat->pcs_exit = socfpga_dwmac_pcs_exit;
 	plat_dat->select_pcs = socfpga_dwmac_select_pcs;
 
+	dwmac->mac_interface = plat_dat->phy_interface;
+
 	ops->setup_plat_dat(dwmac);
 
 	socfpga_dwmac_setup_multi_irq(dev, plat_dat, &stmmac_res);
@@ -704,10 +707,34 @@ static const struct socfpga_dwmac_ops socfpga_agilex5_ops = {
 	.setup_plat_dat = socfpga_agilex5_setup_plat_dat,
 };
 
+static void socfpga_agilex5_tsn_gmac_setup_plat_dat(struct socfpga_dwmac *dwmac)
+{
+	struct plat_stmmacenet_data *plat_dat = dwmac->plat_dat;
+
+	socfpga_agilex5_setup_plat_dat(dwmac);
+
+	/* The FPGA GMII-to-RGMII converter is only in the RGMII path. It
+	 * presents GMII to the MAC and adds both RGMII delays, so only
+	 * phy-mode "rgmii-id" describes the board correctly.
+	 */
+	if (!phy_interface_mode_is_rgmii(plat_dat->phy_interface))
+		return;
+
+	dwmac->mac_interface = PHY_INTERFACE_MODE_GMII;
+	plat_dat->has_internal_tx_delay = true;
+	plat_dat->has_internal_rx_delay = true;
+}
+
+static const struct socfpga_dwmac_ops socfpga_agilex5_tsn_gmac_ops = {
+	.set_phy_mode = socfpga_gen10_set_phy_mode,
+	.setup_plat_dat = socfpga_agilex5_tsn_gmac_setup_plat_dat,
+};
+
 static const struct of_device_id socfpga_dwmac_match[] = {
 	{ .compatible = "altr,socfpga-stmmac", .data = &socfpga_gen5_ops },
 	{ .compatible = "altr,socfpga-stmmac-a10-s10", .data = &socfpga_gen10_ops },
 	{ .compatible = "altr,socfpga-stmmac-agilex5", .data = &socfpga_agilex5_ops },
+	{ .compatible = "altr,socfpga-stmmac-agilex5-tsn", .data = &socfpga_agilex5_tsn_gmac_ops },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
-- 
2.43.7




More information about the linux-arm-kernel mailing list