Skip to contentSkip to conversation

MediaTek ethernet driver refactor and updates

PATCH In review Weijie Gao 2 participants 5 messages Jan 10, 2025 – Jan 24, 2025

Subsystems (2)
lore
Share & tools
lore

Weijie Gao

author
#0 lore raw

cover MediaTek ethernet driver refactor and updates

This patch series will split the switch initialization code from mtk_eth driver into their own files and then add new SoC and switch support.

Weijie Gao (3):
net: mediatek: split ethernet switch code from mtk_eth.c
net: mediatek: add support for MediaTek MT7987 SoC
net: mediatek: add support for Airoha AN8855 ethernet switch

 drivers/net/Kconfig                 |   21 +-
 drivers/net/Makefile                |    2 +-
 drivers/net/mtk_eth/Kconfig         |   39 +
 drivers/net/mtk_eth/Makefile        |   10 +
 drivers/net/mtk_eth/an8855.c        | 1096 +++++++++++++++++++++++++++
 drivers/net/mtk_eth/mt7530.c        |  281 +++++++
 drivers/net/mtk_eth/mt7531.c        |  293 +++++++
 drivers/net/mtk_eth/mt753x.c        |  262 +++++++
 drivers/net/mtk_eth/mt753x.h        |  286 +++++++
 drivers/net/mtk_eth/mt7988.c        |  160 ++++
 drivers/net/{ => mtk_eth}/mtk_eth.c |  981 ++++--------------------
 drivers/net/{ => mtk_eth}/mtk_eth.h |  301 ++------
 12 files changed, 2631 insertions(+), 1101 deletions(-)
 create mode 100644 drivers/net/mtk_eth/Kconfig
 create mode 100644 drivers/net/mtk_eth/Makefile
 create mode 100644 drivers/net/mtk_eth/an8855.c
 create mode 100644 drivers/net/mtk_eth/mt7530.c
 create mode 100644 drivers/net/mtk_eth/mt7531.c
 create mode 100644 drivers/net/mtk_eth/mt753x.c
 create mode 100644 drivers/net/mtk_eth/mt753x.h
 create mode 100644 drivers/net/mtk_eth/mt7988.c
 rename drivers/net/{ => mtk_eth}/mtk_eth.c (62%)
 rename drivers/net/{ => mtk_eth}/mtk_eth.h (59%)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 net: mediatek: split ethernet switch code from mtk_eth.c

mtk_eth.c contains not only the ethernet GMAC/DMA driver, but also some ethernet switch initialization code. As we may add more switch support in the future, it's better to move them out of mtk_eth.c to avoid increasing the code complexity.

Since not all switches are supported for a particular board, Kconfig options are added to allow user to select which switch should be built into u-boot. If multiple switches are selected, auto-detecting can also be enabled.

---
 drivers/net/Kconfig                 |  21 +-
 drivers/net/Makefile                |   2 +-
 drivers/net/mtk_eth/Kconfig         |  35 +
 drivers/net/mtk_eth/Makefile        |   9 +
 drivers/net/mtk_eth/mt7530.c        | 281 ++++++++
 drivers/net/mtk_eth/mt7531.c        | 293 +++++++++
 drivers/net/mtk_eth/mt753x.c        | 262 ++++++++
 drivers/net/mtk_eth/mt753x.h        | 286 ++++++++
 drivers/net/mtk_eth/mt7988.c        | 160 +++++
 drivers/net/{ => mtk_eth}/mtk_eth.c | 971 ++++------------------------
 drivers/net/{ => mtk_eth}/mtk_eth.h | 301 ++-------
 11 files changed, 1520 insertions(+), 1101 deletions(-)
 create mode 100644 drivers/net/mtk_eth/Kconfig
 create mode 100644 drivers/net/mtk_eth/Makefile
 create mode 100644 drivers/net/mtk_eth/mt7530.c
 create mode 100644 drivers/net/mtk_eth/mt7531.c
 create mode 100644 drivers/net/mtk_eth/mt753x.c
 create mode 100644 drivers/net/mtk_eth/mt753x.h
 create mode 100644 drivers/net/mtk_eth/mt7988.c
 rename drivers/net/{ => mtk_eth}/mtk_eth.c (62%)
 rename drivers/net/{ => mtk_eth}/mtk_eth.h (59%)
drivers/net/Kconfig +1 -20
index 88ff025a37b..e48e28d00a3 100644
@@ -966,26 +966,7 @@ config TSEC_ENET
 	  This driver implements support for the (Enhanced) Three-Speed
 	  Ethernet Controller found on Freescale SoCs.
 
-config MEDIATEK_ETH
-	bool "MediaTek Ethernet GMAC Driver"
-	select PHYLIB
-	select DM_GPIO
-	select DM_RESET
-	help
-	  This Driver support MediaTek Ethernet GMAC
-	  Say Y to enable support for the MediaTek Ethernet GMAC.
-
-if MEDIATEK_ETH
-
-config MTK_ETH_SGMII
-	bool
-	default y if ARCH_MEDIATEK && !TARGET_MT7623
-
-config MTK_ETH_XGMII
-	bool
-	default y if TARGET_MT7987 || TARGET_MT7988
-
-endif # MEDIATEK_ETH
+source "drivers/net/mtk_eth/Kconfig"
 
 config HIFEMAC_ETH
 	bool "HiSilicon Fast Ethernet Controller"
drivers/net/Makefile +1 -1
index e51a917933e..6f3d63dc4cd 100644
@@ -68,7 +68,7 @@ obj-$(CONFIG_MDIO_MUX_MESON_GXL) += mdio_mux_meson_gxl.o
 obj-$(CONFIG_MDIO_MUX_MMIOREG) += mdio_mux_mmioreg.o
 obj-$(CONFIG_MDIO_MUX_SANDBOX) += mdio_mux_sandbox.o
 obj-$(CONFIG_MDIO_SANDBOX) += mdio_sandbox.o
-obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o
+obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth/
 obj-$(CONFIG_MPC8XX_FEC) += mpc8xx_fec.o
 obj-$(CONFIG_MT7620_ETH) += mt7620-eth.o
 obj-$(CONFIG_MT7628_ETH) += mt7628-eth.o
drivers/net/mtk_eth/Kconfig new file +35 -0
new file mode 100644
index 00000000000..8d012fb1374
@@ -0,0 +1,35 @@
+
+config MEDIATEK_ETH
+	bool "MediaTek Ethernet GMAC Driver"
+	select PHYLIB
+	select DM_GPIO
+	select DM_RESET
+	help
+	  This Driver support MediaTek Ethernet GMAC
+	  Say Y to enable support for the MediaTek Ethernet GMAC.
+
+if MEDIATEK_ETH
+
+config MTK_ETH_SGMII
+	bool
+	default y if ARCH_MEDIATEK && !TARGET_MT7623
+
+config MTK_ETH_XGMII
+	bool
+	default y if TARGET_MT7988
+
+config MTK_ETH_SWITCH_MT7530
+	bool "Support for MediaTek MT7530 ethernet switch"
+	default y if TARGET_MT7623 || SOC_MT7621
+
+config MTK_ETH_SWITCH_MT7531
+	bool "Support for MediaTek MT7531 ethernet switch"
+	default y if TARGET_MT7622 || TARGET_MT7629 || TARGET_MT7981 || \
+		     TARGET_MT7986
+
+config MTK_ETH_SWITCH_MT7988
+	bool "Support for MediaTek MT7988 built-in ethernet switch"
+	depends on TARGET_MT7988
+	default y
+
+endif # MEDIATEK_ETH
drivers/net/mtk_eth/Makefile new file +9 -0
new file mode 100644
index 00000000000..885375c5b38
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2025 MediaTek Inc.
+# Author: Weijie Gao <[email protected]>
+
+obj-y += mtk_eth.o
+obj-$(CONFIG_MTK_ETH_SWITCH_MT7530) += mt753x.o mt7530.o
+obj-$(CONFIG_MTK_ETH_SWITCH_MT7531) += mt753x.o mt7531.o
+obj-$(CONFIG_MTK_ETH_SWITCH_MT7988) += mt753x.o mt7988.o
drivers/net/mtk_eth/mt7530.c new file +281 -0

281 lines not on this page · raw message

drivers/net/mtk_eth/mt7531.c new file +293 -0

293 lines not on this page · raw message

drivers/net/mtk_eth/mt753x.c new file +262 -0

262 lines not on this page · raw message

drivers/net/mtk_eth/mt753x.h new file +286 -0

286 lines not on this page · raw message

drivers/net/mtk_eth/mt7988.c new file +160 -0

160 lines not on this page · raw message

drivers/net/mtk_eth/mtk_eth.c renamed from drivers/net/mtk_eth.c +127 -844

1,178 lines not on this page · raw message

drivers/net/mtk_eth/mtk_eth.h renamed from drivers/net/mtk_eth.h +65 -236

361 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 net: mediatek: add support for MediaTek MT7987 SoC

In reply to Weijie Gao

This patch adds support for MediaTek MT7987.

MT7987 features MediaTek NETSYS v3, similar to MT7988, features three GMACs which support 2.5Gb HSGMII. One 2.5Gb PHY is also embedded an can be connected to a dedicated GMAC.

---
 drivers/net/mtk_eth/Kconfig   |  4 ++--
 drivers/net/mtk_eth/mtk_eth.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/net/mtk_eth/Kconfig +2 -2
index 8d012fb1374..467684749f1 100644
@@ -16,7 +16,7 @@ config MTK_ETH_SGMII
 
 config MTK_ETH_XGMII
 	bool
-	default y if TARGET_MT7988
+	default y if TARGET_MT7987 || TARGET_MT7988
 
 config MTK_ETH_SWITCH_MT7530
 	bool "Support for MediaTek MT7530 ethernet switch"
@@ -25,7 +25,7 @@ config MTK_ETH_SWITCH_MT7530
 config MTK_ETH_SWITCH_MT7531
 	bool "Support for MediaTek MT7531 ethernet switch"
 	default y if TARGET_MT7622 || TARGET_MT7629 || TARGET_MT7981 || \
-		     TARGET_MT7986
+		     TARGET_MT7986 || TARGET_MT7987
 
 config MTK_ETH_SWITCH_MT7988
 	bool "Support for MediaTek MT7988 built-in ethernet switch"
drivers/net/mtk_eth/mtk_eth.c +10 -0
index 1e6b30769d1..5d6a42bceb4 100644
@@ -1477,6 +1477,15 @@ static const struct mtk_soc_data mt7988_data = {
 	.rxd_size = sizeof(struct mtk_rx_dma_v2),
 };
 
+static const struct mtk_soc_data mt7987_data = {
+	.caps = MT7987_CAPS,
+	.ana_rgc3 = 0x128,
+	.gdma_count = 3,
+	.pdma_base = PDMA_V3_BASE,
+	.txd_size = sizeof(struct mtk_tx_dma_v2),
+	.rxd_size = sizeof(struct mtk_rx_dma_v2),
+};
+
 static const struct mtk_soc_data mt7986_data = {
 	.caps = MT7986_CAPS,
 	.ana_rgc3 = 0x128,
@@ -1531,6 +1540,7 @@ static const struct mtk_soc_data mt7621_data = {
 
 static const struct udevice_id mtk_eth_ids[] = {
 	{ .compatible = "mediatek,mt7988-eth", .data = (ulong)&mt7988_data },
+	{ .compatible = "mediatek,mt7987-eth", .data = (ulong)&mt7987_data },
 	{ .compatible = "mediatek,mt7986-eth", .data = (ulong)&mt7986_data },
 	{ .compatible = "mediatek,mt7981-eth", .data = (ulong)&mt7981_data },
 	{ .compatible = "mediatek,mt7629-eth", .data = (ulong)&mt7629_data },
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/3 net: mediatek: add support for Airoha AN8855 ethernet switch

In reply to Weijie Gao

Airoha AN8855 is a 5-port gigabit switch with a 2.5G HSGMII CPU port

---
 drivers/net/mtk_eth/Kconfig  |    4 +
 drivers/net/mtk_eth/Makefile |    1 +
 drivers/net/mtk_eth/an8855.c | 1096 ++++++++++++++++++++++++++++++++++
 3 files changed, 1101 insertions(+)
 create mode 100644 drivers/net/mtk_eth/an8855.c
drivers/net/mtk_eth/Kconfig +4 -0
index 467684749f1..e8cdf408237 100644
@@ -32,4 +32,8 @@ config MTK_ETH_SWITCH_MT7988
 	depends on TARGET_MT7988
 	default y
 
+config MTK_ETH_SWITCH_AN8855
+	bool "Support for Airoha AN8855 ethernet switch"
+	default y if TARGET_MT7981 || TARGET_MT7987
+
 endif # MEDIATEK_ETH
drivers/net/mtk_eth/Makefile +1 -0
index 885375c5b38..a342325ed5d 100644
@@ -7,3 +7,4 @@ obj-y += mtk_eth.o
 obj-$(CONFIG_MTK_ETH_SWITCH_MT7530) += mt753x.o mt7530.o
 obj-$(CONFIG_MTK_ETH_SWITCH_MT7531) += mt753x.o mt7531.o
 obj-$(CONFIG_MTK_ETH_SWITCH_MT7988) += mt753x.o mt7988.o
+obj-$(CONFIG_MTK_ETH_SWITCH_AN8855) += an8855.o
drivers/net/mtk_eth/an8855.c new file +1096 -0

1,096 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw
In reply to Weijie Gao
Quoted 9 lines · Weijie Gao

This patch series will split the switch initialization code from mtk_eth driver into their own files and then add new SoC and switch support.

Weijie Gao (3):
net: mediatek: split ethernet switch code from mtk_eth.c
net: mediatek: add support for MediaTek MT7987 SoC
net: mediatek: add support for Airoha AN8855 ethernet switch

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom