net: dsa: add support for MT7988
Subsystems (5)
Daniel Golle
maintainerv2 cover net: dsa: add support for MT7988
The MediaTek MT7988 SoC comes with a built-in switch very similar to previous MT7530 and MT7531. However, the switch address space is mapped into the SoCs memory space rather than being connected via MDIO. Using MMIO simplifies register access and also removes the need for a bus lock, and for that reason also makes interrupt handling more light-weight.
Note that this is different from previous SoCs like MT7621 and MT7623N which also came with an integrated MT7530-like switch which yet had to be accessed via MDIO.
Split-off the part of the driver registering an MDIO driver, then add another module acting as MMIO/platform driver.
Changes since initial RFC:
* use regmap for register access and move register access to bus- specific driver
* move initialization of MT7531 SGMII PCS to MDIO driver
Daniel Golle (2):
net: dsa: mt7530: split-off MDIO driver
net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
drivers/net/dsa/Kconfig | 16 +- drivers/net/dsa/Makefile | 4 +- drivers/net/dsa/mt7530-mdio.c | 309 ++++++++++++++++++++++ drivers/net/dsa/mt7530-mmio.c | 143 ++++++++++ drivers/net/dsa/mt7530.c | 479 ++++++++++++++-------------------- drivers/net/dsa/mt7530.h | 38 +-- 6 files changed, 686 insertions(+), 303 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mdio.c create mode 100644 drivers/net/dsa/mt7530-mmio.c
Signature · 1 line
2.39.2
Daniel Golle
maintainerRFC PATCH v2 1/2 net: dsa: mt7530: split-off MDIO driver
In order to support the built-in switch of some MediaTek SoCs we need to use MMIO instead of MDIO to access the switch.
Prepare this be splitting-off the part of the driver registering an MDIO driver, so we can add another module acting as MMIO/platform driver.
--- drivers/net/dsa/Kconfig | 8 +- drivers/net/dsa/Makefile | 3 +- drivers/net/dsa/mt7530-mdio.c | 309 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/mt7530.c | 286 ++++--------------------------- drivers/net/dsa/mt7530.h | 24 +-- 5 files changed, 356 insertions(+), 274 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mdio.c
drivers/net/dsa/Kconfig +7 -1
@@ -35,9 +35,15 @@ config NET_DSA_LANTIQ_GSWIP the xrx200 / VR9 SoC. config NET_DSA_MT7530 - tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + tristate "MediaTek Ethernet switch support" select NET_DSA_TAG_MTK select MEDIATEK_GE_PHY + help + This enables support for the MediaTek Ethernet switch chips. + +config NET_DSA_MT7530_MDIO + tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530 select PCS_MTK_LYNXI help This enables support for the MediaTek MT7530 and MT7531 Ethernet
drivers/net/dsa/Makefile +2 -1
@@ -6,7 +6,8 @@ ifdef CONFIG_NET_DSA_LOOP obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdinfo.o endif obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o -obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
drivers/net/dsa/mt7530-mdio.c new file +309 -0
309 lines not on this page · raw message
drivers/net/dsa/mt7530.c +32 -254
373 lines not on this page · raw message
drivers/net/dsa/mt7530.h +6 -18
@@ -682,24 +682,6 @@ enum p5_interface_select { P5_INTF_SEL_GMAC5_SGMII, }; -static const char *p5_intf_modes (unsigned int p5_interface) -{ -switch (p5_interface) { -case P5_DISABLED : -return "DISABLED" ; -case P5_INTF_SEL_PHY_P0 : -return "PHY P0" ; -case P5_INTF_SEL_PHY_P4 : -return "PHY P4" ; -case P5_INTF_SEL_GMAC5 : -return "GMAC5" ; -case P5_INTF_SEL_GMAC5_SGMII : -return "GMAC5_SGMII" ; -default : -return "unknown" ; - } -} -struct mt7530_priv ;struct mt753x_pcs {
@@ -777,6 +759,7 @@ struct mt7530_priv {struct reset_control *rstc;struct regulator *core_pwr;struct regulator *io_pwr; +struct regmap *regmap;struct gpio_desc *reset;const struct mt753x_info *info;unsigned int id;
@@ -830,4 +813,9 @@ static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p, p->reg = reg; } +void mt7530_free_irq (struct mt7530_priv *priv); + +extern const struct dsa_switch_ops mt7530_switch_ops; +extern const struct mt753x_info mt753x_table[]; +#endif /* __MT7530_H */
Signature · 1 line
2.39.2
Andrew Lunn
maintainerRe: [RFC PATCH net-next v2 1/2] net: dsa: mt7530: split-off MDIO driver
Quoted 6 lines · Daniel Golle
In order to support the built-in switch of some MediaTek SoCs we need to use MMIO instead of MDIO to access the switch.
Prepare this be splitting-off the part of the driver registering an MDIO driver, so we can add another module acting as MMIO/platform driver.Signed-off-by Daniel Golle <[email protected]>
Hi Daniel
This is getting better.
Please try to split this patch up. Ideally you want lots of small patches which are obviously correct. So maybe refactor the creation of the PCS as a patch. Move p5_intf_modes() as a patch, etc.
Also, look at mt7530_probe() and mt7988_probe() side by side and see what is common and can be put into one shared function in the core. Same for remove. It could be that creating that helper is a patch done before adding mt7530-mdio.c.
Andrew
Daniel Golle
maintainerRFC PATCH v2 2/2 net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
In reply to Daniel GolleThe MediaTek MT7988 SoC comes with a built-in switch very similar to previous MT7530 and MT7531. However, the switch address space is mapped into the SoCs memory space rather than being connected via MDIO. Using MMIO simplifies register access and also removes the need for a bus lock, and for that reason also makes interrupt handling more light-weight.
Note that this is different from previous SoCs like MT7621 and MT7623N which also came with an integrated MT7530-like switch which yet had to be accessed via MDIO.
--- drivers/net/dsa/Kconfig | 8 ++ drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mt7530-mmio.c | 143 +++++++++++++++++++++++++ drivers/net/dsa/mt7530.c | 195 +++++++++++++++++++++++++++++----- drivers/net/dsa/mt7530.h | 14 +-- 5 files changed, 331 insertions(+), 30 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mmio.c
drivers/net/dsa/Kconfig +8 -0
@@ -50,6 +50,14 @@ config NET_DSA_MT7530_MDIO switch chips. Multi-chip module MT7530 in MT7621AT, MT7621DAT, MT7621ST and MT7623AI SoCs is supported. +config NET_DSA_MT7530_MMIO + tristate "MediaTek MT7988 built-in Ethernet switch support" + select NET_DSA_MT7530 + depends on HAS_IOMEM + help + This enables support for the built-in Ethernet switch of the + MediaTek MT7988 SoC. + config NET_DSA_MV88E6060 tristate "Marvell 88E6060 ethernet switch chip support" select NET_DSA_TAG_TRAILER
drivers/net/dsa/Makefile +1 -0
@@ -8,6 +8,7 @@ endif obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o +obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
drivers/net/dsa/mt7530-mmio.c new file +143 -0
143 lines not on this page · raw message
drivers/net/dsa/mt7530.c +171 -24
349 lines not on this page · raw message
drivers/net/dsa/mt7530.h +8 -6
@@ -11,6 +11,8 @@#define MT7530_NUM_FDB_RECORDS 2048#define MT7530_ALL_MEMBERS 0xff +#define MT7988_CPU_PORT 6 +#define MTK_HDR_LEN 4#define MT7530_MAX_MTU (15 * 1024 - ETH_HLEN - ETH_FCS_LEN - MTK_HDR_LEN)
@@ -18,6 +20,7 @@ enum mt753x_id {ID_MT7530 =0 ,ID_MT7621 =1 ,ID_MT7531 =2 , + ID_MT7988 = 3, };#define NUM_TRGMII_CTRL 5
@@ -54,11 +57,11 @@ enum mt753x_id {#define MT7531_MIRROR_PORT_SET (x) (((x) & MIRROR_MASK) << 16)#define MT7531_CPU_PMAP_MASK GENMASK(7, 0) -#define MT753X_MIRROR_REG (id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_REG (id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_CFC : MT7530_MFC) -#define MT753X_MIRROR_EN (id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_EN (id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_MIRROR_EN : MIRROR_EN) -#define MT753X_MIRROR_MASK (id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_MASK (id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_MIRROR_MASK : MIRROR_MASK)/* Registers for BPDU and PAE frame control*/
@@ -295,9 +298,8 @@ enum mt7530_vlan_port_acc_frm { MT7531_FORCE_DPX | \ MT7531_FORCE_RX_FC | \ MT7531_FORCE_TX_FC) -#define PMCR_FORCE_MODE_ID (id) (((id) == ID_MT7531) ? \ - MT7531_FORCE_MODE : \ - PMCR_FORCE_MODE) +#define PMCR_FORCE_MODE_ID (id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ + MT7531_FORCE_MODE : PMCR_FORCE_MODE)#define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \ PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \ PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
Signature · 1 line
2.39.2
Andrew Lunn
maintainerRe: [RFC PATCH net-next v2 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
Quoted 4 lines
drivers/net/dsa/mt7530.c +0
-0@@ -146,11 +149,13 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val) {struct mii_bus *bus = priv->bus;
drivers/net/dsa/mt7530.c core_write(struct mt7530_priv *priv, u32 reg, u32 val) · line 159
Quoted 10 lines
drivers/net/dsa/mt7530.c +4
-2-mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); +if (bus) +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );core_write_mmd_indirect (priv, reg,MDIO_MMD_VEND2 , val); -mutex_unlock (&bus->mdio_lock); +if (bus) +mutex_unlock (&bus->mdio_lock); }
All this if (bus) is pretty ugly.
First off, what is this mutex actually protecting? And why is the same protection not required for MMIO?
If you have a convincing argument the mutex is not needed, please add two helpers:
mt7530_mutex_lock(struct mt7530_priv *priv)mt7530_mutex_unlock(struct mt7530_priv *priv)
and hide the if inside that. As part of the commit message, explain why the mutex is not needed for MDIO.
Adding these helpers and changing all calls can be a preparation patch. It is the sort of patch which should be obviously correct.
Quoted 10 lines
drivers/net/dsa/mt7530.c +2
-0@@ -2588,6 +2664,8 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_NA :case PHY_INTERFACE_MODE_1000BASEX :case PHY_INTERFACE_MODE_2500BASEX : +case PHY_INTERFACE_MODE_USXGMII : +case PHY_INTERFACE_MODE_10GKR :/* handled in SGMII PCS driver */ return 0 ;default :
drivers/net/dsa/mt7530.c static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, · line 2798
Quoted 10 lines
drivers/net/dsa/mt7530.c +3
-1@@ -2712,7 +2790,9 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port,* variants. */ if (interface ==PHY_INTERFACE_MODE_TRGMII || - (phy_interface_mode_is_8023z (interface))) { + interface ==PHY_INTERFACE_MODE_USXGMII || + interface ==PHY_INTERFACE_MODE_10GKR || +phy_interface_mode_is_8023z (interface)) { speed =SPEED_1000 ; duplex =DUPLEX_FULL ; }
This looks like something which should be in a separate patch.
Quoted 37 lines
drivers/net/dsa/mt7530.c +37
-0+static int mt7988_setup (struct dsa_switch *ds) +{ +struct mt7530_priv *priv = ds->priv; +u32 unused_pm =0 ; +int i; + +/* Reset the switch */ +reset_control_assert (priv->rstc); +udelay (20 ); +reset_control_deassert (priv->rstc); +udelay (20 ); + +/* Reset the switch PHYs */ +mt7530_write (priv,MT7530_SYS_CTRL ,SYS_CTRL_PHY_RST ); + +/* BPDU to CPU port */ +mt7530_rmw (priv,MT7531_CFC ,MT7531_CPU_PMAP_MASK , +BIT (MT7988_CPU_PORT )); +mt7530_rmw (priv,MT753X_BPC ,MT753X_BPDU_PORT_FW_MASK , +MT753X_BPDU_CPU_ONLY ); + +/* Enable and reset MIB counters */ +mt7530_mib_reset (ds); + +for (i =0 ; i <MT7530_NUM_PORTS ; i++) { +/* Disable forwarding by default on all ports */ +mt7530_rmw (priv,MT7530_PCR_P (i),PCR_MATRIX_MASK , +PCR_MATRIX_CLR ); + +mt7530_set (priv,MT7531_DBG_CNT (i),MT7531_DIS_CLR ); + +if (dsa_is_unused_port (ds, i)) + unused_pm |=BIT (i); +else if (dsa_is_cpu_port (ds, i)) +mt753x_cpu_port_enable (ds, i); +else +mt7530_port_disable (ds, i);
drivers/net/dsa/mt7530.c static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, · line 3067
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+ +/* Enable consistent egress tag */ +mt7530_rmw (priv,MT7530_PVC_P (i),PVC_EG_TAG_MASK , +PVC_EG_TAG (MT7530_VLAN_EG_CONSISTENT )); + } + + ds->configure_vlan_while_not_filtering = true; + +/* Flush the FDB table */ +return mt7530_fdb_cmd (priv,MT7530_FDB_FLUSH ,NULL );
Is this really specific to the mt7988?
Andrew
Daniel Golle
maintainerRe: [RFC PATCH net-next v2 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
Quoted 17 lines · Andrew Lunn
Quoted 4 lines
drivers/net/dsa/mt7530.c +0
-0@@ -146,11 +149,13 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val) {struct mii_bus *bus = priv->bus;drivers/net/dsa/mt7530.c core_write(struct mt7530_priv *priv, u32 reg, u32 val) · line 159
Quoted 10 lines
drivers/net/dsa/mt7530.c +4
-2-mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); +if (bus) +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );core_write_mmd_indirect (priv, reg,MDIO_MMD_VEND2 , val); -mutex_unlock (&bus->mdio_lock); +if (bus) +mutex_unlock (&bus->mdio_lock); }All this if (bus) is pretty ugly.
Quoted 2 lines
First off, what is this mutex actually protecting? And why is the same protection not required for MMIO?
The mutex is protecting the MDIO bus. Each access to any register of the MT753x switch requires at least two operations on the MDIO bus. Hence if there is congruent access, e.g. due to PCS or PHY polling, this can mess up and interfere with another ongoing register access sequence.
You may argue that we should just use regmap's locking API for that, as it is done also when creating the pcs-mtk-lynxi instance. However, some things like interrupt handling require more complex (as in: not covered by regmap_update_bits) pseudo-atomic operations, so the idea was to keep the locking just like it was before for MDIO-connected MT753x switches and provide a lock-less regmap replacing the former mt7530_mii_write() and mt7530_mii_read() functions.
If we use MMIO we can directly access the 32-bit wide registers and hence do not require locking.
Quoted 9 lines
If you have a convincing argument the mutex is not needed, please add two helpers:
mt7530_mutex_lock(struct mt7530_priv *priv)mt7530_mutex_unlock(struct mt7530_priv *priv)and hide the if inside that. As part of the commit message, explain why the mutex is not needed for MDIO.
Ok, will do.
Quoted 3 lines
Adding these helpers and changing all calls can be a preparation patch. It is the sort of patch which should be obviously correct.
Understood.
Quoted 15 lines
Quoted 15 lines
drivers/net/dsa/mt7530.c +2
-1@@ -2588,6 +2664,8 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode,case PHY_INTERFACE_MODE_NA :case PHY_INTERFACE_MODE_1000BASEX :case PHY_INTERFACE_MODE_2500BASEX : +case PHY_INTERFACE_MODE_USXGMII : +case PHY_INTERFACE_MODE_10GKR :/* handled in SGMII PCS driver */ return 0 ;default :@@ -2712,7 +2790,9 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port,* variants. */ if (interface == PHY_INTERFACE_MODE_TRGMII || - (phy_interface_mode_is_8023z (interface))) {
Quoted 8 lines
drivers/net/dsa/mt7530.c static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, · line 2798
Quoted 6 lines
drivers/net/dsa/mt7530.c +3
-0+ interface == PHY_INTERFACE_MODE_USXGMII || + interface == PHY_INTERFACE_MODE_10GKR || + phy_interface_mode_is_8023z(interface)) { speed =SPEED_1000 ; duplex =DUPLEX_FULL ; }This looks like something which should be in a separate patch.
Ok, I will put it into a separate patch before adding support for MT7988 which is the only switch supporting those modes (and also requiring them).
Quoted 42 lines
Quoted 42 lines
drivers/net/dsa/mt7530.c +41
-0+static int mt7988_setup (struct dsa_switch *ds) +{ +struct mt7530_priv *priv = ds->priv; +u32 unused_pm =0 ; +int i; + +/* Reset the switch */ +reset_control_assert (priv->rstc); +udelay (20 ); +reset_control_deassert (priv->rstc); +udelay (20 ); + +/* Reset the switch PHYs */ +mt7530_write (priv,MT7530_SYS_CTRL ,SYS_CTRL_PHY_RST ); + +/* BPDU to CPU port */ +mt7530_rmw (priv,MT7531_CFC ,MT7531_CPU_PMAP_MASK , +BIT (MT7988_CPU_PORT )); +mt7530_rmw (priv,MT753X_BPC ,MT753X_BPDU_PORT_FW_MASK , +MT753X_BPDU_CPU_ONLY ); + +/* Enable and reset MIB counters */ +mt7530_mib_reset (ds); + +for (i =0 ; i <MT7530_NUM_PORTS ; i++) { +/* Disable forwarding by default on all ports */ +mt7530_rmw (priv,MT7530_PCR_P (i),PCR_MATRIX_MASK , +PCR_MATRIX_CLR ); + +mt7530_set (priv,MT7531_DBG_CNT (i),MT7531_DIS_CLR ); + +if (dsa_is_unused_port (ds, i)) + unused_pm |=BIT (i); +else if (dsa_is_cpu_port (ds, i)) +mt753x_cpu_port_enable (ds, i); +else +mt7530_port_disable (ds, i); + +/* Enable consistent egress tag */ +mt7530_rmw (priv,MT7530_PVC_P (i),PVC_EG_TAG_MASK , +PVC_EG_TAG (MT7530_VLAN_EG_CONSISTENT ));
Quoted 8 lines
drivers/net/dsa/mt7530.c static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, · line 3067
Quoted 6 lines
drivers/net/dsa/mt7530.c +6
-0+ } + + ds->configure_vlan_while_not_filtering = true; + +/* Flush the FDB table */ +return mt7530_fdb_cmd (priv,MT7530_FDB_FLUSH ,NULL );Is this really specific to the mt7988?
While the setup function is somehow similar to mt7530_setup or mt7531_setup there are also differences. It would be possible to split this more, so more common parts can be shared, such as the loop over the ports which is the same as for MT7531. The way initial reset is carried out as well as setting up the CPU port is specific to MT7988.
Quoted 2 lines
Andrew