net:dsa:yt922x: Add support for Motorcomm YT922x
PATCH 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 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 | 8 +- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/yt921x.c | 901 +++++++++++++++++++++++++++++++++++++-- drivers/net/dsa/yt921x.h | 108 +++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +- net/dsa/Makefile | 2 +- net/dsa/tag_yt921x.c | 115 ++++- 8 files changed, 1101 insertions(+), 43 deletions(-)
drivers/net/dsa/Kconfig +4 -4
@@ -159,11 +159,11 @@ 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" - select NET_DSA_TAG_YT921X +config NET_DSA_YT92XX + tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support" + select NET_DSA_TAG_YT92XX 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
@@ -14,7 +14,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 +870 -31
1,002 lines not on this page · raw message
drivers/net/dsa/yt921x.h +108 -0
129 lines not on this page · raw message
include/net/dsa.h +2 -0
@@ -60,6 +60,7 @@ struct tc_action;#define DSA_TAG_PROTO_MXL862_VALUE 32#define DSA_TAG_PROTO_NETC_VALUE 33#define DSA_TAG_PROTO_KSZ8463_VALUE 34 +#define DSA_TAG_PROTO_YT922X_VALUE 35enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -97,6 +98,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_MXL862 =DSA_TAG_PROTO_MXL862_VALUE ,DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE ,DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +3 -3
@@ -215,10 +215,10 @@ config NET_DSA_TAG_XRS700X Say Y or M if you want to enable support for tagging frames for Arrow SpeedChips XRS700x switches that use a single byte tag trailer. -config NET_DSA_TAG_YT921X - tristate "Tag driver for Motorcomm YT921x switches" +config NET_DSA_TAG_YT92XX + tristate "Tag driver for Motorcomm YT921x and YT922x switches" help Say Y or M if you want to enable support for tagging frames for - Motorcomm YT921x switches. + Motorcomm YT921x and YT922x switches. endif
net/dsa/Makefile +1 -1
@@ -42,7 +42,7 @@ obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o 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_YT92XX) += tag_yt921x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt921x.c +112 -3
128 lines not on this page · raw message
Signature · 1 line
2.25.1
David Yang
maintainerdrivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 155
Quoted 9 lines · Kyle Switch
drivers/net/dsa/yt921x.c +5
-0@@ -148,10 +148,15 @@ static const struct yt921x_info yt921x_infos[] = {YT921X_PORT_MASK_INT0_n (8 ),YT921X_PORT_MASK_EXT0 |YT921X_PORT_MASK_EXT1 , }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +0x1f1 , + 0x0, + },
Why plain magic numbers here, despite what the above entries shows?
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 159
Quoted 5 lines
drivers/net/dsa/yt921x.c +1
-1{} }; -#define YT921X_NAME "yt921x" +#define YT92XX_NAME "yt92xx"
This changed the module name which may affect end users. While I have no objection to this, subsystem maintainers may have different opinions.
Quoted 2 lines
drivers/net/dsa/yt921x.c +2
-0+static int +yt922x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp)
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+static int +yt921x_intif_ext_write(struct yt921x_priv *priv, int port, int reg, u16 val)
Place them with yt921x_*if_*().
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5055
Quoted 3 lines
drivers/net/dsa/yt921x.c +3
-0+static int yt922x_internal_phyaddr_get (int port, +enum yt922x_phy_reg_type reg_type, +enum yt922x_phy_reg_space reg_space)
[...]
This makes me headache and is prone to errors (an example below). Reorder it with early returns and/or lookup tables so that it is obviously correct.
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5076
Quoted 4 lines
drivers/net/dsa/yt921x.c +4
-0+default : +if (reg_space !=YT922X_PHY_REG_SPACE_PHY ) + res = -EINVAL ; +break ;
What would you expect here, when reg_space == YT922X_PHY_REG_SPACE_PHY?
Quoted 2 lines
drivers/net/dsa/yt921x.c +2
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface)
[...]
Quoted 12 lines
drivers/net/dsa/yt921x.c +12
-0+ addr =yt922x_internal_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x2000 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x2000 , data); +if (res) +return res; + addr = yt922x_internal_phyaddr_get(port, YT922X_PHY_REG_TYPE_MII,
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5286
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+ YT922X_PHY_REG_SPACE_USXGMII); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res;
Numerous magic numbers. On YT9215, same finetunes are not required for a usable port. If you cannot name it, drop it if it is not mandatory.
Quoted 28 lines
drivers/net/dsa/yt921x.c +28
-0+static int yt922x_cpu_tag_mode_set (struct yt921x_priv *priv) +{ +struct device *dev =to_device (priv); +u16 eth_p_tag; +u32 val; +u32 val1; +int res; + +/* cpu tag mode set */ + res =yt921x_reg_read (priv,YT922X_CPU_TAG_RX_CTRL , &val); +if (res) +return res; + res =yt921x_reg_read (priv,YT922X_CPU_TAG_TX_CTRL , &val1); +if (res) +return res; + val &= ~YT922X_CPU_TAG_RX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_TYPE ; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_RX_CTRL , val); +if (res) +return res; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_TX_CTRL , val1); +if (res) +return res; + +/* tpid check */ + res =yt921x_reg_read (priv,YT921X_CPU_TAG_TPID , &val); +if (res)
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5603
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+return res; + eth_p_tag =FIELD_GET (YT921X_CPU_TAG_TPID_TPID_M , val); +if (eth_p_tag !=ETH_P_YT921X ) { +dev_err (dev,"Tag type 0x%x != 0x%x\n" , eth_p_tag, +ETH_P_YT921X ); +return -EINVAL ; + } + +return 0 ; +}
This looks similar to yt921x_chip_reset(), so you'd better merge it into yt922x_chip_reset() above.
Quoted 17 lines
drivers/net/dsa/yt921x.c +17
-0+static int yt922x_cpu_port_set (struct yt921x_priv *priv) +{ +struct dsa_switch *ds = &priv->ds; +u32 ctrl; +int res; + +/* cpu tag mode */ + res =yt922x_cpu_tag_mode_set (priv); +if (res) +return res; + +/* Enable DSA */ + priv->cpu_ports_mask =dsa_cpu_ports (ds); + ctrl =YT921X_EXT_CPU_PORT_TAG_EN |YT921X_EXT_CPU_PORT_PORT_EN | +YT921X_EXT_CPU_PORT_PORT (__ffs (priv->cpu_ports_mask)); + res =yt921x_reg_write (priv,YT921X_EXT_CPU_PORT , ctrl); +if (res)
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5631
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+return res; + +/* Setup software switch */ + ctrl =YT922X_CPU_COPY_TO_EXT_CPU ; + res =yt921x_reg_write (priv,YT922X_CPU_COPY , ctrl); +if (res) +return res; + +return res; +}
Also, snippets from yt921x_chip_setup_dsa() and unaligned function names.
drivers/net/dsa/yt921x.c static void yt921x_mdio_shutdown(struct mdio_device *mdiodev) · line 5714
Quoted 2 lines
drivers/net/dsa/yt921x.c +1
-1-static void yt921x_mdio_remove (struct mdio_device *mdiodev) +static void yt92xx_mdio_remove (struct mdio_device *mdiodev)
Unnecessary renaming.
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 886
Quoted 8 lines
drivers/net/dsa/yt921x.h +8
-0+#define YT922X_PORT_SDS_MODE 0x400 +#define YT922X_PORT_SDS_MODE_M GENMASK(6, 4) +#define YT92XX_SERDES_MODE_SGMII 0 +#define YT92XX_SERDES_MODE_REVSGMII 1 +#define YT92XX_SERDES_MODE_1000BASEX 2 +#define YT92XX_SERDES_MODE_100BASEX 3 +#define YT92XX_SERDES_MODE_2500BASEX 4 +#define YT92XX_SERDES_MODE_USXGMII 6
Not an objection, but better to keep the formats with YT921X_SERDESn:
#define YT922X_PORT_SERDES 0x400
#define YT922X_PORT_SERDES_MODE_M GENMASK(6, 4)
#define YT922X_PORT_SERDES_MODE(x)FIELD_PREP(YT922X_PORT_SERDES_MODE_M, (x))
#define YT922X_PORT_SERDES_MODE_SGMII YT922X_PORT_SERDES_MODE(0)
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 911
Quoted 7 lines
drivers/net/dsa/yt921x.h +7
-0+#define YT922X_ACT_UNK_ACTn_M (port) GENMASK(2 * (port) + 1, 2 * (port)) +#define YT922X_ACT_UNK_ACTn (port, x) ((x) << (2 * (port))) +#define YT922X_ACT_UNK_ACTn_FORWARD (port) YT922X_ACT_UNK_ACTn(port, 0)/* flood */ +#define YT922X_ACT_UNK_ACTn_TRAP (port) YT922X_ACT_UNK_ACTn(port, 3)/* steer to CPU */ +#define YT922X_ACT_UNK_ACTn_DROP (port) YT922X_ACT_UNK_ACTn(port, 1)/* discard */ +/* NEVER use this action; see comments in the tag driver */ +#define YT922X_ACT_UNK_ACTn_COPY (port) YT922X_ACT_UNK_ACTn(port, 2)/* flood and copy */
Sort them in numerical order.
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 923
Quoted 12 lines
drivers/net/dsa/yt921x.h +12
-0+ +/* CPU PORT */ +#define YT922X_CPU_COPY 0x181100 +#define YT922X_CPU_COPY_TO_INT_CPU BIT(1) +#define YT922X_CPU_COPY_TO_EXT_CPU BIT(0) +#define YT922X_CPU_TAG_RX_CTRL 0x80504 +#define YT922X_CPU_TAG_RX_MODE BIT(0) +#define YT922X_CPU_TAG_TX_CTRL 0x100710 +#define YT922X_CPU_TAG_TX_TYPE BIT(0) +#define YT922X_CPU_TAG_TX_MODE BIT(1) +#define YT922X_CPU_TAG_TX_CTAG_OP BIT(2) +#define YT922X_CPU_TAG_TX_STAG_OP BIT(3)
Not an objection, but better to keep the indentation formats of yt921x register definitions above.
drivers/net/dsa/yt921x.h struct yt921x_reg_ops { · line 1048
Quoted 5 lines
drivers/net/dsa/yt921x.h +5
-0+struct yt92xx_chip_info { +enum yt92xx_mode mode; +const char *name; +unsigned int ports; +unsigned int lag_id;
lag_ids, or num_lag_ids (and num_ports) for consistency.
Quoted 5 lines
struct yt921x_priv { struct dsa_switch ds;+ const struct yt92xx_chip_info *chip_info; const struct yt921x_info *info;
yt921x_priv :: info is chip info already. You may want series_info, or more straightforward, series and struct yt92xx_series.
Quoted 4 lines
net/dsa/tag_yt921x.c +0
-0
[...]
net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 183
Quoted 10 lines
net/dsa/tag_yt921x.c +10
-0+/* To define the from cpu tag format 8 bytes: +* +* 0 1 2 3 4 5 6 7 |0 1 2 3 4 5 6 7 +*|<------------TPID 0x9988------->| +*|<--RESERVE-->|<-----DST POR---->| +*|-|<---------RESERVE------------>| +*|<------------------------------>| +*/ +#define YT922X_TAG_NAME "yt922x" +#define YT922X_TAG_PORTMASK_0 BIT(15)
Sort them according to their corresponding word.
net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 191
Quoted 8 lines
net/dsa/tag_yt921x.c +8
-0+#define YT922X_TAG_PORTMASK_M GENMASK(8, 0) +#define YT922X_TAG_PORTS (x) FIELD_PREP(YT922X_TAG_PORTMASK_M, (x)) +#define YT922X_TAG_FORCE_DST BIT(9) +#define YT922X_TAG_PRIO_M GENMASK(12, 10) +#define YT922X_TAG_PRIO_EN BIT(13) +#define YT922X_TAG_PRIO (x) (FIELD_PREP(YT922X_TAG_PRIO_M, (x)) | YT922X_TAG_PRIO_EN) +#define YT922X_TAG_RX_PORT_M GENMASK(5, 2) +#define YT922X_TAG_RX_PRIO_M GENMASK(15, 13)
This did not answer the question in the previous review: do tag_yt922x and tag_yt921x share any common routines? If not, better to make tag_yt922x a separate file.
Quoted 6 lines
net/dsa/tag_yt921x.c +6
-0+static struct sk_buff * +yt922x_tag_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct dsa_port *dp =dsa_user_to_port (netdev); +__be16 *tag; +u16 ctrl;
net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 208
Quoted 10 lines
net/dsa/tag_yt921x.c +10
-0+ +skb_push (skb,YT921X_TAG_LEN ); +dsa_alloc_etype_header (skb,YT921X_TAG_LEN ); + tag =dsa_etype_header_pos_tx (skb); + + tag[0 ] =htons (ETH_P_YT921X ); +if (dp->index !=0 ) { +/* Port index is not equal 0 in tag[1] */ + ctrl =YT922X_TAG_PRIO (skb->priority) |YT922X_TAG_FORCE_DST | +YT922X_TAG_PORTS (dsa_xmit_port_mask (skb, netdev) -1 );
dsa_xmit_port_mask() returns a bit mask - you won't do arithmetic operations to a bit mask normally.
The field name does suggest it is a port mask. Have you noticed excessive packets on other ports?
Quoted 12 lines · David Yang
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 155
Quoted 9 lines · Kyle Switch
drivers/net/dsa/yt921x.c +5
-0@@ -148,10 +148,15 @@ static const struct yt921x_info yt921x_infos[] = {YT921X_PORT_MASK_INT0_n (8 ),YT921X_PORT_MASK_EXT0 |YT921X_PORT_MASK_EXT1 , }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +0x1f1 , + 0x0, + },Why plain magic numbers here, despite what the above entries shows?
Ans: will fixed done in patch v2.
Quoted 9 lines
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 159
Quoted 6 lines
drivers/net/dsa/yt921x.c +1
-1{} }; -#define YT921X_NAME "yt921x" +#define YT92XX_NAME "yt92xx"This changed the module name which may affect end users. While I have no objection to this, subsystem maintainers may have different opinions.
Ans: This is used to indicate support for both YT921X and YT922X.
Quoted 8 lines
Quoted 3 lines
drivers/net/dsa/yt921x.c +2
-0+static int +yt922x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp)[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+static int +yt921x_intif_ext_write(struct yt921x_priv *priv, int port, int reg, u16 val)Place them with yt921x_*if_*().
Ans: fix done in patch v2.
Quoted 9 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5055
Quoted 4 lines
drivers/net/dsa/yt921x.c +3
-0+static int yt922x_internal_phyaddr_get (int port, +enum yt922x_phy_reg_type reg_type, +enum yt922x_phy_reg_space reg_space)[...]
This makes me headache and is prone to errors (an example below). Reorder it with early returns and/or lookup tables so that it is obviously correct.
Ans: The interface will be optimized in v1 using early returns.
Quoted 6 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5076
Quoted 5 lines
drivers/net/dsa/yt921x.c +4
-0+default : +if (reg_space !=YT922X_PHY_REG_SPACE_PHY ) + res = -EINVAL ; +break ;What would you expect here, when
reg_space==YT922X_PHY_REG_SPACE_PHY?
Ans: The expected return result is an error.
Quoted 27 lines
Quoted 3 lines
drivers/net/dsa/yt921x.c +2
-0+static int yt922x_port_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface)[...]
Quoted 12 lines
drivers/net/dsa/yt921x.c +12
-0+ addr =yt922x_internal_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x2000 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x2000 , data); +if (res) +return res; + addr = yt922x_internal_phyaddr_get(port, YT922X_PHY_REG_TYPE_MII,drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5286
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+ YT922X_PHY_REG_SPACE_USXGMII); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res;
Quoted 2 lines
Numerous magic numbers. On YT9215, same finetunes are not required for a usable port. If you cannot name it, drop it if it is not mandatory.
Ans: Some patches are mandatory, while others are for performance optimization.
These will be further refined/optimized in the future.
Quoted 33 lines
Quoted 33 lines
drivers/net/dsa/yt921x.c +32
-0+static int yt922x_cpu_tag_mode_set (struct yt921x_priv *priv) +{ +struct device *dev =to_device (priv); +u16 eth_p_tag; +u32 val; +u32 val1; +int res; + +/* cpu tag mode set */ + res =yt921x_reg_read (priv,YT922X_CPU_TAG_RX_CTRL , &val); +if (res) +return res; + res =yt921x_reg_read (priv,YT922X_CPU_TAG_TX_CTRL , &val1); +if (res) +return res; + val &= ~YT922X_CPU_TAG_RX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_TYPE ; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_RX_CTRL , val); +if (res) +return res; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_TX_CTRL , val1); +if (res) +return res; + +/* tpid check */ + res =yt921x_reg_read (priv,YT921X_CPU_TAG_TPID , &val); +if (res) +return res; + eth_p_tag =FIELD_GET (YT921X_CPU_TAG_TPID_TPID_M , val); +if (eth_p_tag !=ETH_P_YT921X ) { + dev_err(dev, "Tag type 0x%x != 0x%x\n", eth_p_tag,
Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5603
Quoted 6 lines
drivers/net/dsa/yt921x.c +6
-0+ ETH_P_YT921X); +return -EINVAL ; + } + +return 0 ; +}This looks similar to
yt921x_chip_reset(), so you'd better merge it intoyt922x_chip_reset()above.
Ans:Given that this interface is responsible for mode selection related to CPU tags, the cpu tag
TPID check has been consolidated here as well.
Quoted 34 lines
Quoted 18 lines
drivers/net/dsa/yt921x.c +17
-0+static int yt922x_cpu_port_set (struct yt921x_priv *priv) +{ +struct dsa_switch *ds = &priv->ds; +u32 ctrl; +int res; + +/* cpu tag mode */ + res =yt922x_cpu_tag_mode_set (priv); +if (res) +return res; + +/* Enable DSA */ + priv->cpu_ports_mask =dsa_cpu_ports (ds); + ctrl =YT921X_EXT_CPU_PORT_TAG_EN |YT921X_EXT_CPU_PORT_PORT_EN | +YT921X_EXT_CPU_PORT_PORT (__ffs (priv->cpu_ports_mask)); + res =yt921x_reg_write (priv,YT921X_EXT_CPU_PORT , ctrl); +if (res)drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5631
Quoted 10 lines
drivers/net/dsa/yt921x.c +10
-0+return res; + +/* Setup software switch */ + ctrl =YT922X_CPU_COPY_TO_EXT_CPU ; + res =yt921x_reg_write (priv,YT922X_CPU_COPY , ctrl); +if (res) +return res; + +return res; +}Also, snippets from
yt921x_chip_setup_dsa()and unaligned function names.drivers/net/dsa/yt921x.c static void yt921x_mdio_shutdown(struct mdio_device *mdiodev) · line 5714
Quoted 2 lines
drivers/net/dsa/yt921x.c +1
-1-static void yt921x_mdio_remove (struct mdio_device *mdiodev) +static void yt92xx_mdio_remove (struct mdio_device *mdiodev)Unnecessary renaming.
Quoted 9 lines
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 886
Quoted 8 lines
drivers/net/dsa/yt921x.h +8
-0+#define YT922X_PORT_SDS_MODE 0x400 +#define YT922X_PORT_SDS_MODE_M GENMASK(6, 4) +#define YT92XX_SERDES_MODE_SGMII 0 +#define YT92XX_SERDES_MODE_REVSGMII 1 +#define YT92XX_SERDES_MODE_1000BASEX 2 +#define YT92XX_SERDES_MODE_100BASEX 3 +#define YT92XX_SERDES_MODE_2500BASEX 4 +#define YT92XX_SERDES_MODE_USXGMII 6Not an objection, but better to keep the formats with
YT921X_SERDESn:
Ans: fix done in patch v2.
Quoted 7 lines
#define
YT922X_PORT_SERDES0x400
#defineYT922X_PORT_SERDES_MODE_MGENMASK(6, 4)
#defineYT922X_PORT_SERDES_MODE(x)FIELD_PREP(YT922X_PORT_SERDES_MODE_M, (x))
#defineYT922X_PORT_SERDES_MODE_SGMIIYT922X_PORT_SERDES_MODE(0)
Quoted 8 lines
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 911
Quoted 7 lines
drivers/net/dsa/yt921x.h +7
-0+#define YT922X_ACT_UNK_ACTn_M (port) GENMASK(2 * (port) + 1, 2 * (port)) +#define YT922X_ACT_UNK_ACTn (port, x) ((x) << (2 * (port))) +#define YT922X_ACT_UNK_ACTn_FORWARD (port) YT922X_ACT_UNK_ACTn(port, 0)/* flood */ +#define YT922X_ACT_UNK_ACTn_TRAP (port) YT922X_ACT_UNK_ACTn(port, 3)/* steer to CPU */ +#define YT922X_ACT_UNK_ACTn_DROP (port) YT922X_ACT_UNK_ACTn(port, 1)/* discard */ +/* NEVER use this action; see comments in the tag driver */ +#define YT922X_ACT_UNK_ACTn_COPY (port) YT922X_ACT_UNK_ACTn(port, 2)/* flood and copy */ Sort them in numerical order.
Ans: Fix done.
Quoted 23 lines
drivers/net/dsa/yt921x.h enum yt921x_fdb_entry_status { · line 923
Quoted 13 lines
drivers/net/dsa/yt921x.h +12
-0+ +/* CPU PORT */ +#define YT922X_CPU_COPY 0x181100 +#define YT922X_CPU_COPY_TO_INT_CPU BIT(1) +#define YT922X_CPU_COPY_TO_EXT_CPU BIT(0) +#define YT922X_CPU_TAG_RX_CTRL 0x80504 +#define YT922X_CPU_TAG_RX_MODE BIT(0) +#define YT922X_CPU_TAG_TX_CTRL 0x100710 +#define YT922X_CPU_TAG_TX_TYPE BIT(0) +#define YT922X_CPU_TAG_TX_MODE BIT(1) +#define YT922X_CPU_TAG_TX_CTAG_OP BIT(2) +#define YT922X_CPU_TAG_TX_STAG_OP BIT(3)Not an objection, but better to keep the indentation formats of yt921x register definitions above.
drivers/net/dsa/yt921x.h struct yt921x_reg_ops { · line 1048
Quoted 5 lines
drivers/net/dsa/yt921x.h +5
-0+struct yt92xx_chip_info { +enum yt92xx_mode mode; +const char *name; +unsigned int ports; +unsigned int lag_id;
lag_ids, ornum_lag_ids(andnum_ports) for consistency.
Quoted 7 lines
Quoted 5 lines
struct yt921x_priv { struct dsa_switch ds;+ const struct yt92xx_chip_info *chip_info; const struct yt921x_info *info;
yt921x_priv:: info is chip info already. You may wantseries_info, or more straightforward,seriesandstruct yt92xx_series.
Ans: Fix done.
Quoted 19 lines
Quoted 5 lines
net/dsa/tag_yt921x.c +0
-0[...]
net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 183
Quoted 10 lines
net/dsa/tag_yt921x.c +10
-0+/* To define the from cpu tag format 8 bytes: +* +* 0 1 2 3 4 5 6 7 |0 1 2 3 4 5 6 7 +*|<------------TPID 0x9988------->| +*|<--RESERVE-->|<-----DST POR---->| +*|-|<---------RESERVE------------>| +*|<------------------------------>| +*/ +#define YT922X_TAG_NAME "yt922x" +#define YT922X_TAG_PORTMASK_0 BIT(15)Sort them according to their corresponding word.
Quoted 11 lines
net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 191
Quoted 8 lines
net/dsa/tag_yt921x.c +8
-0+#define YT922X_TAG_PORTMASK_M GENMASK(8, 0) +#define YT922X_TAG_PORTS (x) FIELD_PREP(YT922X_TAG_PORTMASK_M, (x)) +#define YT922X_TAG_FORCE_DST BIT(9) +#define YT922X_TAG_PRIO_M GENMASK(12, 10) +#define YT922X_TAG_PRIO_EN BIT(13) +#define YT922X_TAG_PRIO (x) (FIELD_PREP(YT922X_TAG_PRIO_M, (x)) | YT922X_TAG_PRIO_EN) +#define YT922X_TAG_RX_PORT_M GENMASK(5, 2) +#define YT922X_TAG_RX_PRIO_M GENMASK(15, 13)This did not answer the question in the previous review: do
tag_yt922xandtag_yt921xshare any common routines? If not, better to maketag_yt922xa separate file.
Ans: Fix done.
Quoted 20 lines
Quoted 7 lines
net/dsa/tag_yt921x.c +6
-0+static struct sk_buff * +yt922x_tag_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct dsa_port *dp =dsa_user_to_port (netdev); +__be16 *tag; +u16 ctrl;net/dsa/tag_yt921x.c static const struct dsa_device_ops yt921x_netdev_ops = { · line 208
Quoted 10 lines
net/dsa/tag_yt921x.c +10
-0+ +skb_push (skb,YT921X_TAG_LEN ); +dsa_alloc_etype_header (skb,YT921X_TAG_LEN ); + tag =dsa_etype_header_pos_tx (skb); + + tag[0 ] =htons (ETH_P_YT921X ); +if (dp->index !=0 ) { +/* Port index is not equal 0 in tag[1] */ + ctrl =YT922X_TAG_PRIO (skb->priority) |YT922X_TAG_FORCE_DST | +YT922X_TAG_PORTS (dsa_xmit_port_mask (skb, netdev) -1 );
dsa_xmit_port_mask()returns a bit mask - you won't do arithmetic operations to a bit mask normally.
Quoted 2 lines
The field name does suggest it is a port mask. Have you noticed excessive packets on other ports?
Ans: yes, There are some issues here that will be fixed in patch v2.
Andrew Lunn
maintainerQuoted 19 lines · Kyle Switch
Quoted 12 lines · David Yang
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 155
Quoted 9 lines · Kyle Switch
drivers/net/dsa/yt921x.c +5
-0@@ -148,10 +148,15 @@ static const struct yt921x_info yt921x_infos[] = {YT921X_PORT_MASK_INT0_n (8 ),YT921X_PORT_MASK_EXT0 |YT921X_PORT_MASK_EXT1 , }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +0x1f1 , + 0x0, + },Why plain magic numbers here, despite what the above entries shows?
Ans: will fixed done in patch v2.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0{} };
Quoted 6 lines
Quoted 5 lines
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 159
Quoted 2 lines
drivers/net/dsa/yt921x.c +1
-1-#define YT921X_NAME "yt921x" +#define YT92XX_NAME "yt92xx"This changed the module name which may affect end users. While I have no objection to this, subsystem maintainers may have different opinions.
Ans: This is used to indicate support for both YT921X and YT922X.
It is pretty common for newer generations of devices to be mostly backwards compatible, with older generations. The driver does not change name in Linux it causes too much pointless churn. Please just get the names correct in the struct phy_driver.
Quoted 11 lines
Quoted 9 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5286
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+ res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res;Numerous magic numbers. On YT9215, same finetunes are not required for a usable port. If you cannot name it, drop it if it is not mandatory.
Ans: Some patches are mandatory
If they are mandatory, why are they needed at all? Why are they not in the firmware. Seems like a poor hardware/firmware design to me.
Quoted 1 line
while others are for performance optimization.
For these, it would be good to fully document them, because board designers might want to optimze them in other ways.
Quoted 3 lines
Quoted 3 lines
drivers/net/dsa/yt921x.c static void yt921x_mdio_shutdown(struct mdio_device *mdiodev) · line 5714
Quoted 2 lines
drivers/net/dsa/yt921x.c +1
-1-static void yt921x_mdio_remove (struct mdio_device *mdiodev) +static void yt92xx_mdio_remove (struct mdio_device *mdiodev)Unnecessary renaming.
And taking this to its logical conclusion...
In a few years time you want to rename to yt9xxx. And a few years after that, rename to ytxxxx.
Andrew
David Yang
maintainerQuoted 41 lines · Kyle Switch
Quoted 32 lines
Quoted 32 lines
drivers/net/dsa/yt921x.c +32
-0+static int yt922x_cpu_tag_mode_set (struct yt921x_priv *priv) +{ +struct device *dev =to_device (priv); +u16 eth_p_tag; +u32 val; +u32 val1; +int res; + +/* cpu tag mode set */ + res =yt921x_reg_read (priv,YT922X_CPU_TAG_RX_CTRL , &val); +if (res) +return res; + res =yt921x_reg_read (priv,YT922X_CPU_TAG_TX_CTRL , &val1); +if (res) +return res; + val &= ~YT922X_CPU_TAG_RX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_MODE ; + val1 &= ~YT922X_CPU_TAG_TX_TYPE ; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_RX_CTRL , val); +if (res) +return res; + res =yt921x_reg_write (priv,YT922X_CPU_TAG_TX_CTRL , val1); +if (res) +return res; + +/* tpid check */ + res =yt921x_reg_read (priv,YT921X_CPU_TAG_TPID , &val); +if (res) +return res; + eth_p_tag =FIELD_GET (YT921X_CPU_TAG_TPID_TPID_M , val); +if (eth_p_tag !=ETH_P_YT921X ) { + dev_err(dev, "Tag type 0x%x != 0x%x\n", eth_p_tag,Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5603
Quoted 6 lines
drivers/net/dsa/yt921x.c +6
-0+ ETH_P_YT921X); +return -EINVAL ; + } + +return 0 ; +}This looks similar to
yt921x_chip_reset(), so you'd better merge it intoyt922x_chip_reset()above.
Quoted 4 lines
Ans:Given that this interface is responsible for mode selection related to CPU tags, the cpu tag
TPID check has been consolidated here as well.
TPID does not depend on the tag mode, so this is a one-time validation right after resetting in yt921x_chip_reset().
Also the naming is confusing: why mode_set clears the RX/TX_MODE. It would be self-explanatory to rename it to set_8b and RX/TX_TAG_4B, and/or mention the existence of 4b mode in the comment for tag_yt922x as well.
Quoted 23 lines · Andrew Lunn
Quoted 22 lines · Kyle Switch
Quoted 12 lines · David Yang
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 155
Quoted 9 lines · Kyle Switch
drivers/net/dsa/yt921x.c +5
-0@@ -148,10 +148,15 @@ static const struct yt921x_info yt921x_infos[] = {YT921X_PORT_MASK_INT0_n (8 ),YT921X_PORT_MASK_EXT0 |YT921X_PORT_MASK_EXT1 , }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +0x1f1 , + 0x0, + },Why plain magic numbers here, despite what the above entries shows?
Ans: will fixed done in patch v2.
Quoted 8 lines
drivers/net/dsa/yt921x.c static const struct yt921x_info yt921x_infos[] = { · line 159
Quoted 5 lines
drivers/net/dsa/yt921x.c +1
-1{} }; -#define YT921X_NAME "yt921x" +#define YT92XX_NAME "yt92xx"This changed the module name which may affect end users. While I have no objection to this, subsystem maintainers may have different opinions.
Quoted 5 lines
Quoted 1 line
Ans: This is used to indicate support for both YT921X and YT922X.
It is pretty common for newer generations of devices to be mostly backwards compatible, with older generations. The driver does not change name in Linux it causes too much pointless churn. Please just get the names correct in the struct
phy_driver.
Ans: The modifications in the next version V2 will retain the previous naming.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/dsa/yt921x.c +7
-0+ res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res;
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Numerous magic numbers. On YT9215, same finetunes are not required for a usable port. If you cannot name it, drop it if it is not mandatory.
Ans: Some patches are mandatory
If they are mandatory, why are they needed at all? Why are they not in the firmware. Seems like a poor hardware/firmware design to me.
Ans: In this application scenario, there is no firmware, and the eFuse
may not be able to support so many registers.
Quoted 5 lines
Quoted 2 lines
while others are for performance optimization.
For these, it would be good to fully document them, because board designers might want to optimze them in other ways.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/dsa/yt921x.c static void yt921x_mdio_shutdown(struct mdio_device *mdiodev) · line 5714
Quoted 2 lines
drivers/net/dsa/yt921x.c +1
-1-static void yt921x_mdio_remove (struct mdio_device *mdiodev) +static void yt92xx_mdio_remove (struct mdio_device *mdiodev)Unnecessary renaming.
And taking this to its logical conclusion...
In a few years time you want to rename to yt9xxx. And a few years after that, rename to ytxxxx.
Ans: Considering that the Motorcomm switch series currently all
start with '92', and there will be driver work for other series in the future,
the name was modified to 'yt92xx'. However, since it is uncertain whether
there will be 'yt9xxx' in the future, the name has been reverted to the
existing one for now.
Quoted 2 lines
Andrew