net:dsa:yt922x: Add support for Motorcomm YT922x
Subsystems (3)
RFC v2 1/1 net:dsa:yt922x: Add support for Motorcomm YT922x
Motorcomm YT922x is a series of ethernet developed by Motorcomm Electronic Technology, including YT9224 and YT9228.
Add support for the yt922x-series DSA driver in the existing files.
---
changes in v2:
1. Separate tag_yt922x into an individual file.
2. Fix the issues from the previous version.
3. Optimize the code style to keep it consistent with the existing code style.
changes in v1:
1. Add basic functional interfaces for the YT922X DSA driver.
2. Although the DSA driver supports both YT922X and YT921X simultaneously, the original file names are still maintained for now;
the file naming may be optimized in the future.
3. Currently, the dsa_switch_ops structure is employed as the operational interface. In future phases, as functionality expands, the architecture will be refactored to introduce yt922x_dsa_ops, where chip-specific operations will be distinguished between YT922X and YT921X, following a design pattern commonly adopted by other existing multi-series DSA drivers.
4. A new thread(patch series) is created. Although a previous version was submitted, the changes are substantial, so the old version is not relevant for reference.
drivers/net/dsa/Kconfig | 7 +- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/yt921x.c | 819 ++++++++++++++++++++++++++++++++++++++- drivers/net/dsa/yt921x.h | 99 +++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 ++++++ 8 files changed, 1022 insertions(+), 25 deletions(-) create mode 100644 net/dsa/tag_yt922x.c
drivers/net/dsa/Kconfig +4 -3
@@ -169,11 +169,12 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM and VSC7398 SparX integrated ethernet switches, connected over a CPU-attached address bus and work in memory-mapped I/O mode. -config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" +config NET_DSA_YT92XX + tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support" select NET_DSA_TAG_YT921X + select NET_DSA_TAG_YT922X select NET_IEEE8021Q_HELPERS if DCB help - This enables support for the Motorcomm YT9215 ethernet switch + This enables support for the Motorcomm YT9215 and YT9224 ethernet switch chip. endmenu
drivers/net/dsa/Makefile +1 -1
@@ -15,7 +15,7 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx-core.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM) += vitesse-vsc73xx-platform.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o -obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o +obj-$(CONFIG_NET_DSA_YT92XX) += yt921x.o obj-y += b53/ obj-y += hirschmann/ obj-y += lantiq/
drivers/net/dsa/yt921x.c +798 -21
925 lines not on this page · raw message
drivers/net/dsa/yt921x.h +99 -0
120 lines not on this page · raw message
include/net/dsa.h +2 -0
@@ -61,6 +61,7 @@ struct tc_action;#define DSA_TAG_PROTO_NETC_VALUE 33#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35 +#define DSA_TAG_PROTO_YT922X_VALUE 36enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -99,6 +100,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE ,DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -227,4 +227,10 @@ config NET_DSA_TAG_YT921X Say Y or M if you want to enable support for tagging frames for Motorcomm YT921x switches. +config NET_DSA_TAG_YT922X + tristate "Tag driver for Motorcomm YT922x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT922x switches. + endif
net/dsa/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o +obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.25.1
Andrew Lunn
maintainerQuoted 3 lines
drivers/net/dsa/Kconfig | 7 +- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/yt921x.c | 819 ++++++++++++++++++++++++++++++++++++++-
That is a lot of new code. Please try to break it up into a number of smaller patches, with good commit messages, which are obviously correct.
Since this is a new device, it does not need to work with a big bang. You can slowly add the needed bits, such that when the last patch is merged the device is functional.
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 171
Quoted 6 lines
drivers/net/dsa/yt921x.c +6
-0+#define YT922X_INTERNAL_SDS1_PHYADDR 0 +#define YT922X_INTERNAL_UTP0_PHYADDR 4 +#define YT922X_INTERNAL_UTP1_PHYADDR 5 +#define YT922X_INTERNAL_UTP2_PHYADDR 6 +#define YT922X_INTERNAL_UTP3_PHYADDR 7 +#define YT922X_INTERNAL_SDS0_PHYADDR 8
These don't seem to be used. Generally, a MAC driver does not need to know the mapping to PHY addresses, the phandles in the DT indicates it.
drivers/net/dsa/yt921x.c yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) · line 580
Quoted 10 lines
static int
yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg){drivers/net/dsa/yt921x.c +3
-1struct yt921x_priv *priv = mbus->priv; +int max_ports;u16 val;int res; -if (port >=YT921X_PORT_NUM ) + max_ports = priv->series_info->ports; +if (port >= max_ports)
This sort of code change would make a nice simple patch. Change all current instances of YT921X_PORT_NUM to priv->series_info->ports. Easy to review.
drivers/net/dsa/yt921x.c static int yt921x_dsa_setup(struct dsa_switch *ds) · line 4774
Quoted 10 lines
drivers/net/dsa/yt921x.c +6
-0@@ -4748,6 +4766,13 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)struct device_node *child;int res; +for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { +struct yt921x_port *pp = &priv->ports[i]; + + pp->index = i; +INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); + }
This should be a patch, with an explanation why it is needed. Also please take a look at ethtool -c stats-block-usecs, which indicates how out of date the statistics are. It is currently not well supported, i only learned of it recently, but setting it will help you get the self tests passing.
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+static void +yt922x_phylink_mac_link_down (struct phylink_config *config,unsigned int mode, +phy_interface_t interface) +{ +struct dsa_port *dp =dsa_phylink_to_port (config); +struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +int port = dp->index;
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4941
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+int res; + +mutex_lock (&priv->reg_lock); + res =yt922x_port_down (priv, port); +mutex_unlock (&priv->reg_lock); + +if (res) +dev_err (dp->ds->dev,"Failed to %s port %d: %i\n" ,"bring down" , + port, res); +}
This appears to be a cut/paste of yt921x_phylink_mac_link_down(). Don't do that. Refactor existing functions to make them generic.
Quoted 29 lines
drivers/net/dsa/yt921x.c +29
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get (port, +YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 );
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5099
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+if (res) +return res; + } +/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res)
What is this function doing?
Andrew
---
pw-bot: cr
Quoted 10 lines · Andrew Lunn
Quoted 3 lines
drivers/net/dsa/Kconfig | 7 +- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/yt921x.c | 819 ++++++++++++++++++++++++++++++++++++++-That is a lot of new code. Please try to break it up into a number of smaller patches, with good commit messages, which are obviously correct.
Since this is a new device, it does not need to work with a big bang. You can slowly add the needed bits, such that when the last patch is merged the device is functional.
Ans: I have now split the original patch into two separate patches
— one for the tag and the other for the YT922x DSA switch.
Quoted 9 lines
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 171
Quoted 6 lines
drivers/net/dsa/yt921x.c +6
-0+#define YT922X_INTERNAL_SDS1_PHYADDR 0 +#define YT922X_INTERNAL_UTP0_PHYADDR 4 +#define YT922X_INTERNAL_UTP1_PHYADDR 5 +#define YT922X_INTERNAL_UTP2_PHYADDR 6 +#define YT922X_INTERNAL_UTP3_PHYADDR 7 +#define YT922X_INTERNAL_SDS0_PHYADDR 8These don't seem to be used. Generally, a MAC driver does not need to know the mapping to PHY addresses, the phandles in the DT indicates it.
Ans: fix done in v3 to remove the unnecessary macros.
Quoted 18 lines
drivers/net/dsa/yt921x.c yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) · line 580
Quoted 10 lines
static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) { struct yt921x_priv *priv = mbus->priv;drivers/net/dsa/yt921x.c +3
-1+int max_ports;u16 val;int res; -if (port >=YT921X_PORT_NUM ) + max_ports = priv->series_info->ports; +if (port >= max_ports)This sort of code change would make a nice simple patch. Change all current instances of
YT921X_PORT_NUMtopriv->series_info->ports. Easy to review.Quoted 4 lines
drivers/net/dsa/yt921x.c +0
-0@@ -4748,6 +4766,13 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)struct device_node *child;int res;
Quoted 11 lines
drivers/net/dsa/yt921x.c static int yt921x_dsa_setup(struct dsa_switch *ds) · line 4774
Quoted 6 lines
drivers/net/dsa/yt921x.c +6
-0+for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { +struct yt921x_port *pp = &priv->ports[i]; + + pp->index = i; +INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); + }This should be a patch, with an explanation why it is needed. Also please take a look at ethtool -c stats-block-usecs, which indicates how out of date the statistics are. It is currently not well supported, i only learned of it recently, but setting it will help you get the self tests passing.
Ans: The initialization logic was already there. I've moved it from probe()
to yt921x_dsa_setup() because the YT922x doesn't support MIB stats
in this series, and the MIB support between the two chips is different.
Quoted 53 lines
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+static void +yt922x_phylink_mac_link_down (struct phylink_config *config,unsigned int mode, +phy_interface_t interface) +{ +struct dsa_port *dp =dsa_phylink_to_port (config); +struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +int port = dp->index;drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4941
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+int res; + +mutex_lock (&priv->reg_lock); + res =yt922x_port_down (priv, port); +mutex_unlock (&priv->reg_lock); + +if (res) +dev_err (dp->ds->dev,"Failed to %s port %d: %i\n" ,"bring down" , + port, res); +}This appears to be a cut/paste of
yt921x_phylink_mac_link_down(). Don't do that. Refactor existing functions to make them generic.Quoted 32 lines
drivers/net/dsa/yt921x.c +32
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get (port, +YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + }
Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5099
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res)What is this function doing?
Ans: Complete some init configuration according to serdes interface mode.
Quoted 5 lines
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerQuoted 40 lines
Quoted 32 lines
Quoted 32 lines
drivers/net/dsa/yt921x.c +32
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get (port, +YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + }Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5099
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res)What is this function doing?
Quoted 1 line
Ans: Complete some init configuration according to serdes interface mode.
Sorry, missed this email until today.
Which SERDES? The switches SERDES, or the PHY SERDES.
We normally refer to the switch SERDES as a PCS, and have a PCS driver for it. Sometimes you also need a generic PHY. Please look around at other devices and understand the architecture.
The PHYs SERDES interface is configured by the PHY driver. The MAC driver should never touch PHY registers. Same as the PHY driver should never touch MAC registers.
Andrew
Quoted 45 lines · Andrew Lunn
Quoted 40 lines
Quoted 32 lines
Quoted 32 lines
drivers/net/dsa/yt921x.c +32
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get (port, +YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + }Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5099
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res)What is this function doing?
Quoted 1 line
Ans: Complete some init configuration according to serdes interface mode.
Sorry, missed this email until today.
Which SERDES? The switches SERDES, or the PHY SERDES.
Quoted 7 lines
We normally refer to the switch SERDES as a PCS, and have a PCS driver for it. Sometimes you also need a generic PHY. Please look around at other devices and understand the architecture.
The PHYs SERDES interface is configured by the PHY driver. The MAC driver should never touch PHY registers. Same as the PHY driver should never touch MAC registers.
Ans: Okay, this is the switch SerDes. We will refer to the existing
implementation and modify the code logic accordingly
Quoted 2 lines
Andrew