net: dsa: yt921x: Add support for Motorcomm YT921x
David Yang
maintainercover net: dsa: yt921x: Add support for Motorcomm YT921x
Motorcomm YT921x is a series of ethernet switches developed by Shanghai Motorcomm Electronic Technology, including:
- YT9215S / YT9215RB / YT9215SC: 5 GbE phys
- YT9213NB / YT9214NB: 2 GbE phys
- YT9218N / YT9218MB: 8 GbE phys
and up to 2 serdes interfaces.
This patch adds basic support for a working DSA switch, but not including any possible offloading capabilities.
David Yang (2):
net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
net: dsa: yt921x: Add support for Motorcomm YT921x
drivers/net/dsa/Kconfig | 7 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/yt921x.c | 1895 ++++++++++++++++++++++++++++++++++++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt921x.c | 116 +++ 7 files changed, 2028 insertions(+) create mode 100644 drivers/net/dsa/yt921x.c create mode 100644 net/dsa/tag_yt921x.c
Signature · 1 line
2.47.2
David Yang
maintainerPATCH 1/2 net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
Add support for Motorcomm YT921x tags, which includes a configurable ethertype field (default to 0x9988).
--- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt921x.c | 116 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 net/dsa/tag_yt921x.c
include/net/dsa.h +2 -0
@@ -55,6 +55,7 @@ struct tc_action;#define DSA_TAG_PROTO_LAN937X_VALUE 27#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28#define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE 29 +#define DSA_TAG_PROTO_YT921X_VALUE 30enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -87,6 +88,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_RZN1_A5PSW =DSA_TAG_PROTO_RZN1_A5PSW_VALUE ,DSA_TAG_PROTO_LAN937X =DSA_TAG_PROTO_LAN937X_VALUE ,DSA_TAG_PROTO_VSC73XX_8021Q =DSA_TAG_PROTO_VSC73XX_8021Q_VALUE , + DSA_TAG_PROTO_YT921X = DSA_TAG_PROTO_YT921X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -190,4 +190,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" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT921x switches. + endif
net/dsa/Makefile +1 -0
@@ -39,6 +39,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 # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt921x.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.47.2
Andrew Lunn
maintainerRe: [PATCH 1/2] net: dsa: tag_yt921x: add support for Motorcomm YT921x tags
Quoted 2 lines · David Yang
Add support for Motorcomm YT921x tags, which includes a configurable ethertype field (default to
0x9988).
Hi David
Please take a read of:
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
We are in the merge window at the moment, so you need to post patches as RFC. And you need to indicate the tree in the Subject: line.
net/dsa/tag_yt921x.c line 39
Quoted 4 lines
net/dsa/tag_yt921x.c new file +4
-0+#define YT921X_TAG_PORT_ENf BIT(15) +#define YT921X_TAG_RX_PORTf GENMASK(14, 11) +#define YT921X_TAG_TX_PORTf GENMASK(10, 0) +#define YT921X_TAG_TX_PORTnv (port) BIT(port)
These lower case letters at the end are unusual. What do they represent?
net/dsa/tag_yt921x.c line 50
Quoted 10 lines
net/dsa/tag_yt921x.c new file +10
-0+static struct sk_buff * +yt921x_tag_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct dsa_port *dp =dsa_user_to_port (netdev); +__be16 *tag; + +skb_push (skb,YT921X_TAG_LEN ); +dsa_alloc_etype_header (skb,YT921X_TAG_LEN ); + + tag = (__be16 *)(skb->data +2 *ETH_ALEN );
dsa_etype_header_pos_tx() ?
net/dsa/tag_yt921x.c line 72
Quoted 6 lines
net/dsa/tag_yt921x.c new file +6
-0+static struct sk_buff * +yt921x_tag_rcv (struct sk_buff *skb,struct net_device *netdev) +{ +__be16 *tag; +u16 rx; +int rx_port;
Reverse Christmas tree. Longest to shortest.
Andrew
---
pw-bot: cr
David Yang
maintainerPATCH 2/2 net: dsa: yt921x: Add support for Motorcomm YT921x
In reply to David YangMotorcomm YT921x is a series of ethernet switches developed by Shanghai Motorcomm Electronic Technology, including:
- YT9215S / YT9215RB / YT9215SC: 5 GbE phys
- YT9213NB / YT9214NB: 2 GbE phys
- YT9218N / YT9218MB: 8 GbE phys
and up to 2 serdes interfaces.
This patch adds basic support for a working DSA switch, but not including any possible offloading capabilities.
Driver verified on a stock wireless router with IPQ5018 + YT9215S.
--- drivers/net/dsa/Kconfig | 7 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/yt921x.c | 1895 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1903 insertions(+) create mode 100644 drivers/net/dsa/yt921x.c
drivers/net/dsa/Kconfig +7 -0
@@ -152,4 +152,11 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM This enables support for the Vitesse VSC7385, VSC7388, VSC7395 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 + help + This enables support for the Motorcomm YT9215 ethernet switch + chip. endmenu
drivers/net/dsa/Makefile +1 -0
@@ -17,6 +17,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-y += b53/ obj-y += hirschmann/ obj-y += microchip/
drivers/net/dsa/yt921x.c new file +1895 -0
1,895 lines not on this page · raw message
Signature · 1 line
2.47.2
Andrew Lunn
maintainerdrivers/net/dsa/yt921x.c line 20
Quoted 2 lines
drivers/net/dsa/yt921x.c new file +2
-0+#undef dev_dbg +#define dev_dbg dev_info
Things like this should not be in a driver submitted to mainline. It is also just as easy to add #define DEBUG to the first line of the file and recomplie to get _dbg() prints working.
drivers/net/dsa/yt921x.c line 31
Quoted 11 lines
drivers/net/dsa/yt921x.c new file +11
-0+ +/******** hardware definitions ********/ + +#define YT921X_SMI_SWITCHIDf GENMASK(3, 2) +#define YT921X_SMI_SWITCHIDv (x) FIELD_PREP(YT921X_SMI_SWITCHIDf, (x)) +#define YT921X_SMI_ADf BIT(1) +#define YT921X_SMI_ADDRv 0 +#define YT921X_SMI_DATAv YT921X_SMI_ADf +#define YT921X_SMI_RWf BIT(0) +#define YT921X_SMI_WRITEv 0 +#define YT921X_SMI_READv YT921X_SMI_RWf
More of these lower case postfixes.
Documentation/process/coding-style.rst says:
Encoding the type of a function into the name (so-called Hungarian notation) is asinine - the compiler knows the types anyway and can check those, and it only confuses the programmer.
This looks like a form of Hungarian notation. Please don't do that.
Quoted 7 lines
drivers/net/dsa/yt921x.c new file +7
-0+struct yt921x_chip_info { +const char *name; +u16 id; +u8 mode; +u8 extmode; +u16 intif_mask; +u16 extif_mask;
drivers/net/dsa/yt921x.c line 311
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+}; + +static const struct yt921x_chip_info yt921x_chip_infos[] = { + {"YT9215SC" ,0x9002 ,1 ,0 ,GENMASK (4 ,0 ),BIT (8 ) |BIT (9 ), }, + {"YT9215S" ,0x9002 ,2 ,0 ,GENMASK (4 ,0 ),BIT (8 ), }, + {"YT9215RB" ,0x9002 ,3 ,0 ,GENMASK (4 ,0 ),BIT (8 ) |BIT (9 ), }, + {"YT9214NB" ,0x9002 ,3 ,2 ,BIT (1 ) |BIT (3 ),BIT (8 ) |BIT (9 ), }, + {"YT9213NB" ,0x9002 ,3 ,3 ,BIT (1 ) |BIT (3 ),BIT (9 ), }, + {"YT9218N" ,0x9001 ,0 ,0 ,GENMASK (7 ,0 ),0 , }, + {"YT9218MB" ,0x9001 ,1 ,0 ,GENMASK (7 ,0 ),BIT (8 ) |BIT (9 ), },
Please add a few more #defines. e.g. what does mode = 1 mean? A #define with a good name can explain that.
#define EXTERNAL_IF_PORT_8 BIT(8)
#define EXTERNAL_IF_PORT_9 BIT(9)
etc.
drivers/net/dsa/yt921x.c line 389
Quoted 2 lines
drivers/net/dsa/yt921x.c new file +2
-0+static int +__yt921x_smi_read (struct yt921x_priv *priv,u32 reg,u32 *valp)
Try to avoid using __ symbols. They are supposed to be used by the compiler.
drivers/net/dsa/yt921x.c line 399
Quoted 6 lines
drivers/net/dsa/yt921x.c new file +6
-0+static int yt921x_smi_read (struct yt921x_priv *priv,u32 reg,u32 *valp) +{ +int res; + + res =yt921x_smi_acquire (priv); +if (unlikely (res !=0 ))
SMI operations are not fast path. Don't use unlikely(). A typical DSA driver never touches actual Ethernet frames, so there is no need for this anywhere in this code.
Quoted 17 lines
drivers/net/dsa/yt921x.c new file +17
-0+static int yt921x_dsa_setup (struct dsa_switch *ds) +{ +/* Always register one mdio bus for the internal/default mdio bus. This +* maybe represented in the device tree, but is optional. +*/ + child =of_get_child_by_name (np,"mdio" ); + res =yt921x_mbus_int_init (priv, child); +of_node_put (child); +if (unlikely (res !=0 )) +return res; + ds->user_mii_bus = priv->mbus_int; + +/* Walk the device tree, and see if there are any other nodes which say +* they are compatible with the external mdio bus. +*/ + priv->mbus_ext =NULL ; +for_each_available_child_of_node (np, child) {
drivers/net/dsa/yt921x.c line 1122
Quoted 10 lines
drivers/net/dsa/yt921x.c new file +10
-0+if (!of_device_is_compatible (child, +"motorcomm,yt921x-mdio-external" )) +continue ; + + res =yt921x_mbus_ext_init (priv, child); +if (unlikely (res !=0 )) { +of_node_put (child); +return res; + } +break ;
Please add a device tree binding. It needs to be the first patch of the series, and you need to Cc: the device tree Maintainers.
Andrew
---
pw-bot: cr
Dan Carpenter
build botBCC: [email protected] CC: [email protected] In-Reply-To: <[email protected]> References: <[email protected]> TO: David Yang…
BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: David Yang <[email protected]>
TO: [email protected]
CC: David Yang <[email protected]>
CC: Andrew Lunn <[email protected]>
CC: Vladimir Oltean <[email protected]>
CC: Eric Dumazet <[email protected]>
CC: Jakub Kicinski <[email protected]>
CC: Paolo Abeni <[email protected]>
CC: Simon Horman <[email protected]>
CC: Russell King <[email protected]>
CC: [email protected]
Hi David,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
[also build test WARNING on net-next/main linus/master next-20250808] [cannot apply to horms-ipvs/master v6.16]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/David-Yang/net-dsa-tag_yt921x-add-support-for-Motorcomm-YT921x-tags/20250809-014351 base: net/main patch link: https://lore.kernel.org/r/20250808173808.273774-3-mmyangfl%40gmail.com patch subject: [PATCH 2/2] net: dsa: yt921x: Add support for Motorcomm YT921x
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: um-randconfig-r072-20250810 (https://download.01.org/0day-ci/archive/20250811/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/net/dsa/yt921x.c:1090 yt921x_dsa_setup() error: uninitialized symbol 'val'.
vim +/val +1090 drivers/net/dsa/yt921x.c
77de450829a940 David Yang 2025-08-09 1060
77de450829a940 David Yang 2025-08-09 1061 static int yt921x_dsa_setup(struct dsa_switch *ds)
77de450829a940 David Yang 2025-08-09 1062 {
77de450829a940 David Yang 2025-08-09 1063 struct yt921x_priv *priv = ds->priv;
77de450829a940 David Yang 2025-08-09 1064 struct device *dev = priv->dev;
77de450829a940 David Yang 2025-08-09 1065 struct device_node *np = dev->of_node;
77de450829a940 David Yang 2025-08-09 1066
77de450829a940 David Yang 2025-08-09 1067 struct device_node *child;
77de450829a940 David Yang 2025-08-09 1068 int cpu_port;
77de450829a940 David Yang 2025-08-09 1069 u32 val;
77de450829a940 David Yang 2025-08-09 1070 int res;
77de450829a940 David Yang 2025-08-09 1071
77de450829a940 David Yang 2025-08-09 1072 res = yt921x_dsa_cpu_port(ds, &cpu_port);
77de450829a940 David Yang 2025-08-09 1073 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1074 return res;
77de450829a940 David Yang 2025-08-09 1075
77de450829a940 David Yang 2025-08-09 1076 res = yt921x_detect(priv);
77de450829a940 David Yang 2025-08-09 1077 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1078 return res;
77de450829a940 David Yang 2025-08-09 1079
77de450829a940 David Yang 2025-08-09 1080 /* Reset */
77de450829a940 David Yang 2025-08-09 1081 res = yt921x_smi_write(priv, YT921X_RESETm, YT921X_RESET_HWf);
77de450829a940 David Yang 2025-08-09 1082 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1083 return res;
77de450829a940 David Yang 2025-08-09 1084
77de450829a940 David Yang 2025-08-09 1085 /* YT921X_RESET_HWf is almost same as GPIO hard reset. So we need
77de450829a940 David Yang 2025-08-09 1086 * this delay.
77de450829a940 David Yang 2025-08-09 1087 */
77de450829a940 David Yang 2025-08-09 1088 usleep_range(10000, 15000);
77de450829a940 David Yang 2025-08-09 1089
77de450829a940 David Yang 2025-08-09 @1090 res = read_poll_timeout(yt921x_smi_read, res, val == 0,
77de450829a940 David Yang 2025-08-09 1091 YT921X_MDIO_SLEEP_US, YT921X_RESET_TIMEOUT_US,
77de450829a940 David Yang 2025-08-09 1092 false, priv, YT921X_RESETm, &val);
77de450829a940 David Yang 2025-08-09 1093 if (unlikely(res != 0)) {
77de450829a940 David Yang 2025-08-09 1094 dev_err(dev, "Reset timeout\n");
77de450829a940 David Yang 2025-08-09 1095 return res;
77de450829a940 David Yang 2025-08-09 1096 }
77de450829a940 David Yang 2025-08-09 1097
77de450829a940 David Yang 2025-08-09 1098 /* Always register one mdio bus for the internal/default mdio bus. This
77de450829a940 David Yang 2025-08-09 1099 * maybe represented in the device tree, but is optional.
77de450829a940 David Yang 2025-08-09 1100 */
77de450829a940 David Yang 2025-08-09 1101 child = of_get_child_by_name(np, "mdio");
77de450829a940 David Yang 2025-08-09 1102 res = yt921x_mbus_int_init(priv, child);
77de450829a940 David Yang 2025-08-09 1103 of_node_put(child);
77de450829a940 David Yang 2025-08-09 1104 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1105 return res;
77de450829a940 David Yang 2025-08-09 1106 ds->user_mii_bus = priv->mbus_int;
77de450829a940 David Yang 2025-08-09 1107
77de450829a940 David Yang 2025-08-09 1108 /* Walk the device tree, and see if there are any other nodes which say
77de450829a940 David Yang 2025-08-09 1109 * they are compatible with the external mdio bus.
77de450829a940 David Yang 2025-08-09 1110 */
77de450829a940 David Yang 2025-08-09 1111 priv->mbus_ext = NULL;
77de450829a940 David Yang 2025-08-09 1112 for_each_available_child_of_node(np, child) {
77de450829a940 David Yang 2025-08-09 1113 if (!of_device_is_compatible(child,
77de450829a940 David Yang 2025-08-09 1114 "motorcomm,yt921x-mdio-external"))
77de450829a940 David Yang 2025-08-09 1115 continue;
77de450829a940 David Yang 2025-08-09 1116
77de450829a940 David Yang 2025-08-09 1117 res = yt921x_mbus_ext_init(priv, child);
77de450829a940 David Yang 2025-08-09 1118 if (unlikely(res != 0)) {
77de450829a940 David Yang 2025-08-09 1119 of_node_put(child);
77de450829a940 David Yang 2025-08-09 1120 return res;
77de450829a940 David Yang 2025-08-09 1121 }
77de450829a940 David Yang 2025-08-09 1122 break;
77de450829a940 David Yang 2025-08-09 1123 }
77de450829a940 David Yang 2025-08-09 1124
77de450829a940 David Yang 2025-08-09 1125 res = yt921x_smi_acquire(priv);
77de450829a940 David Yang 2025-08-09 1126 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1127 return res;
77de450829a940 David Yang 2025-08-09 1128 do {
77de450829a940 David Yang 2025-08-09 1129 /* Enable DSA */
77de450829a940 David Yang 2025-08-09 1130 val = YT921X_EXT_CPU_PORT_TAG_ENf |
77de450829a940 David Yang 2025-08-09 1131 YT921X_EXT_CPU_PORT_PORT_ENf |
77de450829a940 David Yang 2025-08-09 1132 YT921X_EXT_CPU_PORT_PORTv(cpu_port);
77de450829a940 David Yang 2025-08-09 1133 res = __yt921x_smi_write(priv, YT921X_EXT_CPU_PORTm, val);
77de450829a940 David Yang 2025-08-09 1134 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1135 break;
77de450829a940 David Yang 2025-08-09 1136
77de450829a940 David Yang 2025-08-09 1137 res = __yt921x_smi_read(priv, YT921X_CPU_TAG_TPIDm, &val);
77de450829a940 David Yang 2025-08-09 1138 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1139 break;
77de450829a940 David Yang 2025-08-09 1140 priv->tag_eth_p = FIELD_GET(YT921X_CPU_TAG_TPID_TPIDf, val);
77de450829a940 David Yang 2025-08-09 1141 if (priv->tag_eth_p != YT921X_CPU_TAG_TPID_TPIDv) {
77de450829a940 David Yang 2025-08-09 1142 dev_warn(dev, "Tag type 0x%x != 0x%x\n",
77de450829a940 David Yang 2025-08-09 1143 priv->tag_eth_p, YT921X_CPU_TAG_TPID_TPIDv);
77de450829a940 David Yang 2025-08-09 1144 /* Should we pass tag_eth_p to yt921x_xmit()?
77de450829a940 David Yang 2025-08-09 1145 * Nah, just enforce a fixed value for now.
77de450829a940 David Yang 2025-08-09 1146 */
77de450829a940 David Yang 2025-08-09 1147 res = -EINVAL;
77de450829a940 David Yang 2025-08-09 1148 break;
77de450829a940 David Yang 2025-08-09 1149 }
77de450829a940 David Yang 2025-08-09 1150
77de450829a940 David Yang 2025-08-09 1151 /* Enable MIB */
77de450829a940 David Yang 2025-08-09 1152 res = __yt921x_smi_set_bits(priv, YT921X_FUNCm,
77de450829a940 David Yang 2025-08-09 1153 YT921X_FUNC_MIBf);
77de450829a940 David Yang 2025-08-09 1154 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1155 break;
77de450829a940 David Yang 2025-08-09 1156
77de450829a940 David Yang 2025-08-09 1157 val = YT921X_MIB_CTRL_CLEANf | YT921X_MIB_CTRL_ALL_PORTf;
77de450829a940 David Yang 2025-08-09 1158 res = __yt921x_smi_write(priv, YT921X_MIB_CTRLm, val);
77de450829a940 David Yang 2025-08-09 1159 } while (0);
77de450829a940 David Yang 2025-08-09 1160 yt921x_smi_release(priv);
77de450829a940 David Yang 2025-08-09 1161 if (unlikely(res != 0))
77de450829a940 David Yang 2025-08-09 1162 return res;
77de450829a940 David Yang 2025-08-09 1163
77de450829a940 David Yang 2025-08-09 1164 return 0;
77de450829a940 David Yang 2025-08-09 1165 }
77de450829a940 David Yang 2025-08-09 1166 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki