mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
291 lines
9.9 KiB
Diff
291 lines
9.9 KiB
Diff
From d5ca0df9c3e3ede29d83aee5f300b1bdc0016dc0 Mon Sep 17 00:00:00 2001
|
|
From: Joachim Wiberg <troglobit@gmail.com>
|
|
Date: Mon, 6 Apr 2026 14:15:43 +0200
|
|
Subject: [PATCH 44/50] net: ethernet: mediatek: add USXGMII support for MT7988
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Add support for the USXGMII path used by gmac1 and gmac2 on the MT7988
|
|
SoC (BananaPi BPI-R4). Changes:
|
|
|
|
- mtk_eth_soc.h: add MTK_USXGMII capability bit, path bits for all
|
|
three GMACs, SYSCFG0_SGMII_GMAC3_V2 mask, usxgmii_pcs pointer in
|
|
struct mtk_mac, and update MT7988_CAPS to include the USXGMII paths
|
|
and mux
|
|
|
|
- mtk_eth_path.c: add set_mux_gmac123_to_usxgmii() which clears the
|
|
SGMII SYSCFG0 bits and for GMAC2 sets MUX_G2_USXGMII_SEL in
|
|
TOP_MISC_NETSYS_PCS_MUX; add mtk_gmac_usxgmii_path_setup()
|
|
|
|
- mtk_eth_soc.c: wire up the USXGMII PCS — look up the pcs-handle DT
|
|
property via devm_of_pcs_get() during MAC probe and store in
|
|
mac->usxgmii_pcs; return it from mtk_mac_select_pcs() for USXGMII,
|
|
10GBase-R and 5GBase-R modes; call mtk_gmac_usxgmii_path_setup() in
|
|
mtk_mac_config(); allow in-band autoneg for XGMII interfaces
|
|
|
|
Based on work by Henry Yen <henry.yen@mediatek.com> and
|
|
Daniel Golle <daniel@makrotopia.org>.
|
|
---
|
|
drivers/net/ethernet/mediatek/mtk_eth_path.c | 64 ++++++++++++++++++++
|
|
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 46 +++++++++++++-
|
|
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 32 +++++++++-
|
|
3 files changed, 139 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_path.c b/drivers/net/ethernet/mediatek/mtk_eth_path.c
|
|
index b4c01e2878f6..57380776032a 100644
|
|
--- a/drivers/net/ethernet/mediatek/mtk_eth_path.c
|
|
+++ b/drivers/net/ethernet/mediatek/mtk_eth_path.c
|
|
@@ -37,6 +37,12 @@ static const char *mtk_eth_path_name(u64 path)
|
|
return "gmac2_gephy";
|
|
case MTK_ETH_PATH_GDM1_ESW:
|
|
return "gdm1_esw";
|
|
+ case MTK_ETH_PATH_GMAC1_USXGMII:
|
|
+ return "gmac1_usxgmii";
|
|
+ case MTK_ETH_PATH_GMAC2_USXGMII:
|
|
+ return "gmac2_usxgmii";
|
|
+ case MTK_ETH_PATH_GMAC3_USXGMII:
|
|
+ return "gmac3_usxgmii";
|
|
default:
|
|
return "unknown path";
|
|
}
|
|
@@ -221,6 +227,48 @@ static int set_mux_gmac12_to_gephy_sgmii(struct mtk_eth *eth, u64 path)
|
|
return 0;
|
|
}
|
|
|
|
+static int set_mux_gmac123_to_usxgmii(struct mtk_eth *eth, u64 path)
|
|
+{
|
|
+ unsigned int val = 0;
|
|
+ bool updated = true;
|
|
+ int mac_id = 0;
|
|
+
|
|
+ /* Disable SYSCFG1 SGMII */
|
|
+ regmap_read(eth->ethsys, ETHSYS_SYSCFG0, &val);
|
|
+
|
|
+ switch (path) {
|
|
+ case MTK_ETH_PATH_GMAC1_USXGMII:
|
|
+ val &= ~(u32)SYSCFG0_SGMII_GMAC1_V2;
|
|
+ mac_id = MTK_GMAC1_ID;
|
|
+ break;
|
|
+ case MTK_ETH_PATH_GMAC2_USXGMII:
|
|
+ val &= ~(u32)SYSCFG0_SGMII_GMAC2_V2;
|
|
+ mac_id = MTK_GMAC2_ID;
|
|
+ break;
|
|
+ case MTK_ETH_PATH_GMAC3_USXGMII:
|
|
+ val &= ~(u32)SYSCFG0_SGMII_GMAC3_V2;
|
|
+ mac_id = MTK_GMAC3_ID;
|
|
+ break;
|
|
+ default:
|
|
+ updated = false;
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ if (updated) {
|
|
+ regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
|
|
+ SYSCFG0_SGMII_MASK, val);
|
|
+
|
|
+ if (mac_id == MTK_GMAC2_ID)
|
|
+ regmap_set_bits(eth->infra, TOP_MISC_NETSYS_PCS_MUX,
|
|
+ MUX_G2_USXGMII_SEL);
|
|
+ }
|
|
+
|
|
+ dev_dbg(eth->dev, "path %s in %s updated = %d\n",
|
|
+ mtk_eth_path_name(path), __func__, updated);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
static const struct mtk_eth_muxc mtk_eth_muxc[] = {
|
|
{
|
|
.name = "mux_gdm1_to_gmac1_esw",
|
|
@@ -246,6 +294,10 @@ static const struct mtk_eth_muxc mtk_eth_muxc[] = {
|
|
.name = "mux_gmac12_to_gephy_sgmii",
|
|
.cap_bit = MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII,
|
|
.set_path = set_mux_gmac12_to_gephy_sgmii,
|
|
+ }, {
|
|
+ .name = "mux_gmac123_to_usxgmii",
|
|
+ .cap_bit = MTK_ETH_MUX_GMAC123_TO_USXGMII,
|
|
+ .set_path = set_mux_gmac123_to_usxgmii,
|
|
},
|
|
};
|
|
|
|
@@ -328,3 +380,15 @@ int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id)
|
|
return mtk_eth_mux_setup(eth, path);
|
|
}
|
|
|
|
+int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id)
|
|
+{
|
|
+ u64 path;
|
|
+
|
|
+ path = (mac_id == MTK_GMAC1_ID) ? MTK_ETH_PATH_GMAC1_USXGMII :
|
|
+ (mac_id == MTK_GMAC2_ID) ? MTK_ETH_PATH_GMAC2_USXGMII :
|
|
+ MTK_ETH_PATH_GMAC3_USXGMII;
|
|
+
|
|
+ /* Setup proper MUXes along the path */
|
|
+ return mtk_eth_mux_setup(eth, path);
|
|
+}
|
|
+
|
|
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
|
|
index 065f969ee44e..180ef6a299ef 100644
|
|
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
|
|
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
|
|
@@ -22,6 +22,7 @@
|
|
#include <linux/pinctrl/devinfo.h>
|
|
#include <linux/phylink.h>
|
|
#include <linux/pcs/pcs-mtk-lynxi.h>
|
|
+#include <linux/pcs/pcs-standalone.h>
|
|
#include <linux/jhash.h>
|
|
#include <linux/bitfield.h>
|
|
#include <net/dsa.h>
|
|
@@ -522,6 +523,17 @@ static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config,
|
|
struct mtk_eth *eth = mac->hw;
|
|
unsigned int sid;
|
|
|
|
+ if (mtk_is_netsys_v3_or_greater(eth)) {
|
|
+ switch (interface) {
|
|
+ case PHY_INTERFACE_MODE_USXGMII:
|
|
+ case PHY_INTERFACE_MODE_10GBASER:
|
|
+ case PHY_INTERFACE_MODE_5GBASER:
|
|
+ return mac->usxgmii_pcs;
|
|
+ default:
|
|
+ return NULL;
|
|
+ }
|
|
+ }
|
|
+
|
|
if (interface == PHY_INTERFACE_MODE_SGMII ||
|
|
phy_interface_mode_is_8023z(interface)) {
|
|
sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
|
|
@@ -601,6 +613,15 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
|
|
goto init_err;
|
|
}
|
|
break;
|
|
+ case PHY_INTERFACE_MODE_USXGMII:
|
|
+ case PHY_INTERFACE_MODE_10GBASER:
|
|
+ case PHY_INTERFACE_MODE_5GBASER:
|
|
+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_USXGMII)) {
|
|
+ err = mtk_gmac_usxgmii_path_setup(eth, mac->id);
|
|
+ if (err)
|
|
+ goto init_err;
|
|
+ }
|
|
+ break;
|
|
default:
|
|
goto err_phy;
|
|
}
|
|
@@ -664,7 +685,8 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
|
|
|
|
/* Save the syscfg0 value for mac_finish */
|
|
mac->syscfg0 = val;
|
|
- } else if (phylink_autoneg_inband(mode)) {
|
|
+ } else if (phylink_autoneg_inband(mode) &&
|
|
+ !mtk_interface_mode_is_xgmii(eth, state->interface)) {
|
|
dev_err(eth->dev,
|
|
"In-band mode not supported in non SGMII mode!\n");
|
|
return;
|
|
@@ -4932,6 +4954,28 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
|
|
mac->phylink_config.supported_interfaces);
|
|
}
|
|
|
|
+ if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_USXGMII)) {
|
|
+ struct phylink_pcs *pcs;
|
|
+
|
|
+ pcs = devm_of_pcs_get(eth->dev, np, 0);
|
|
+ if (IS_ERR(pcs)) {
|
|
+ if (PTR_ERR(pcs) == -ENODEV)
|
|
+ return dev_err_probe(eth->dev, -EPROBE_DEFER,
|
|
+ "waiting for USXGMII PCS\n");
|
|
+ /* No pcs-handle property — USXGMII not wired for this MAC */
|
|
+ } else if (pcs) {
|
|
+ mac->usxgmii_pcs = pcs;
|
|
+ mac->phylink_config.mac_capabilities |= MAC_5000FD |
|
|
+ MAC_10000FD;
|
|
+ __set_bit(PHY_INTERFACE_MODE_USXGMII,
|
|
+ mac->phylink_config.supported_interfaces);
|
|
+ __set_bit(PHY_INTERFACE_MODE_10GBASER,
|
|
+ mac->phylink_config.supported_interfaces);
|
|
+ __set_bit(PHY_INTERFACE_MODE_5GBASER,
|
|
+ mac->phylink_config.supported_interfaces);
|
|
+ }
|
|
+ }
|
|
+
|
|
phylink = phylink_create(&mac->phylink_config,
|
|
of_fwnode_handle(mac->of_node),
|
|
phy_mode, &mtk_phylink_ops);
|
|
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
|
|
index 0168e2fbc619..2b27ef392b76 100644
|
|
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
|
|
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
|
|
@@ -567,6 +567,7 @@
|
|
#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
|
|
#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
|
|
#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
|
|
+#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
|
|
|
|
|
|
/* ethernet subsystem clock register */
|
|
@@ -1012,6 +1013,13 @@ enum mkt_eth_capabilities {
|
|
MTK_ETH_PATH_GMAC2_2P5GPHY_BIT,
|
|
MTK_ETH_PATH_GMAC2_GEPHY_BIT,
|
|
MTK_ETH_PATH_GDM1_ESW_BIT,
|
|
+
|
|
+ /* USXGMII capability and path bits */
|
|
+ MTK_USXGMII_BIT,
|
|
+ MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
|
|
+ MTK_ETH_PATH_GMAC1_USXGMII_BIT,
|
|
+ MTK_ETH_PATH_GMAC2_USXGMII_BIT,
|
|
+ MTK_ETH_PATH_GMAC3_USXGMII_BIT,
|
|
};
|
|
|
|
/* Supported hardware group on SoCs */
|
|
@@ -1092,6 +1100,23 @@ enum mkt_eth_capabilities {
|
|
#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
|
|
(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
|
|
|
|
+/* USXGMII support */
|
|
+#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
|
|
+
|
|
+#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
|
|
+ BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
|
|
+
|
|
+#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
|
|
+#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
|
|
+#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
|
|
+
|
|
+#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
|
|
+#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
|
|
+#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
|
|
+
|
|
+#define MTK_MUX_GMAC123_TO_USXGMII \
|
|
+ (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
|
|
+
|
|
#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
|
|
|
|
#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
|
|
@@ -1124,8 +1149,9 @@ enum mkt_eth_capabilities {
|
|
MTK_RSTCTRL_PPE1 | MTK_SRAM)
|
|
|
|
#define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_GMAC2_2P5GPHY | \
|
|
- MTK_MUX_GMAC2_TO_2P5GPHY | MTK_QDMA | MTK_RSTCTRL_PPE1 | \
|
|
- MTK_RSTCTRL_PPE2 | MTK_SRAM)
|
|
+ MTK_GMAC2_USXGMII | MTK_GMAC3_USXGMII | \
|
|
+ MTK_MUX_GMAC2_TO_2P5GPHY | MTK_MUX_GMAC123_TO_USXGMII | \
|
|
+ MTK_QDMA | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
|
|
|
|
struct mtk_tx_dma_desc_info {
|
|
dma_addr_t addr;
|
|
@@ -1372,6 +1398,7 @@ struct mtk_mac {
|
|
struct device_node *of_node;
|
|
struct phylink *phylink;
|
|
struct phylink_config phylink_config;
|
|
+ struct phylink_pcs *usxgmii_pcs;
|
|
struct mtk_eth *hw;
|
|
struct mtk_hw_stats *hw_stats;
|
|
__be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
|
|
@@ -1506,6 +1533,7 @@ int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
|
|
int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id);
|
|
int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
|
|
int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
|
|
+int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
|
|
|
|
int mtk_eth_offload_init(struct mtk_eth *eth, u8 id);
|
|
int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
|