net: dsa: motorcomm: add yt92xx dsa driver
PATCH RESEND 1/1 net: dsa: motorcomm: add yt92xx dsa driver
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.
- Merge drivers/net/dsa/yt921x.c and the new yt922x support into a unified yt92xx.c driver.
- Add support for yt922x, which can operate with either 4 bytes or 8 bytes DSA tag.
- Not change yt921x behaviour but use common switch apis
--- drivers/net/dsa/Kconfig | 10 +- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/motorcomm/Kconfig | 30 + drivers/net/dsa/motorcomm/Makefile | 6 + drivers/net/dsa/motorcomm/switch/Makefile | 47 + drivers/net/dsa/motorcomm/switch/i2c.c | 121 + drivers/net/dsa/motorcomm/switch/i2c.h | 21 + drivers/net/dsa/motorcomm/switch/smi.c | 100 + drivers/net/dsa/motorcomm/switch/smi.h | 13 + drivers/net/dsa/motorcomm/switch/yt_cmm.h | 103 + drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.c | 1146 +++ drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.h | 345 + drivers/net/dsa/motorcomm/switch/yt_drv.c | 42 + drivers/net/dsa/motorcomm/switch/yt_drv.h | 25 + drivers/net/dsa/motorcomm/switch/yt_init.c | 348 + drivers/net/dsa/motorcomm/switch/yt_init.h | 30 + .../net/dsa/motorcomm/switch/yt_interrupt.c | 369 + .../net/dsa/motorcomm/switch/yt_interrupt.h | 102 + .../net/dsa/motorcomm/switch/yt_isolation.c | 294 + .../net/dsa/motorcomm/switch/yt_isolation.h | 151 + drivers/net/dsa/motorcomm/switch/yt_l2.c | 1075 +++ drivers/net/dsa/motorcomm/switch/yt_l2.h | 329 + drivers/net/dsa/motorcomm/switch/yt_lag.c | 216 + drivers/net/dsa/motorcomm/switch/yt_lag.h | 119 + drivers/net/dsa/motorcomm/switch/yt_led.c | 1799 +++++ drivers/net/dsa/motorcomm/switch/yt_led.h | 479 ++ .../net/dsa/motorcomm/switch/yt_loopdetect.c | 156 + .../net/dsa/motorcomm/switch/yt_loopdetect.h | 60 + drivers/net/dsa/motorcomm/switch/yt_mirror.c | 205 + drivers/net/dsa/motorcomm/switch/yt_mirror.h | 67 + .../net/dsa/motorcomm/switch/yt_multicast.c | 540 ++ .../net/dsa/motorcomm/switch/yt_multicast.h | 84 + drivers/net/dsa/motorcomm/switch/yt_nic.c | 270 + drivers/net/dsa/motorcomm/switch/yt_nic.h | 168 + drivers/net/dsa/motorcomm/switch/yt_port.c | 6375 +++++++++++++++++ drivers/net/dsa/motorcomm/switch/yt_port.h | 824 +++ drivers/net/dsa/motorcomm/switch/yt_qos.c | 425 ++ drivers/net/dsa/motorcomm/switch/yt_qos.h | 149 + .../net/dsa/motorcomm/switch/yt_reg_921x.h | 422 ++ .../net/dsa/motorcomm/switch/yt_reg_922x.h | 571 ++ .../net/dsa/motorcomm/switch/yt_reg_923x.h | 218 + drivers/net/dsa/motorcomm/switch/yt_stat.c | 167 + drivers/net/dsa/motorcomm/switch/yt_stat.h | 242 + .../net/dsa/motorcomm/switch/yt_storm_ctrl.c | 477 ++ .../net/dsa/motorcomm/switch/yt_storm_ctrl.h | 183 + drivers/net/dsa/motorcomm/switch/yt_stp.c | 155 + drivers/net/dsa/motorcomm/switch/yt_stp.h | 66 + drivers/net/dsa/motorcomm/switch/yt_sys.c | 37 + drivers/net/dsa/motorcomm/switch/yt_sys.h | 56 + drivers/net/dsa/motorcomm/switch/yt_types.h | 172 + drivers/net/dsa/motorcomm/switch/yt_vlan.c | 604 ++ drivers/net/dsa/motorcomm/switch/yt_vlan.h | 361 + drivers/net/dsa/motorcomm/yt92xx.c | 5929 +++++++++++++++ drivers/net/dsa/motorcomm/yt92xx.h | 1218 ++++ drivers/net/dsa/yt921x.c | 4982 ------------- drivers/net/dsa/yt921x.h | 977 --- include/net/dsa.h | 4 + include/uapi/linux/if_ether.h | 2 +- net/dsa/Kconfig | 6 +- net/dsa/Makefile | 2 +- net/dsa/tag_yt921x.c | 168 - net/dsa/tag_yt92xx.c | 376 + 62 files changed, 27899 insertions(+), 6141 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/Kconfig create mode 100644 drivers/net/dsa/motorcomm/Makefile create mode 100644 drivers/net/dsa/motorcomm/switch/Makefile create mode 100644 drivers/net/dsa/motorcomm/switch/i2c.c create mode 100644 drivers/net/dsa/motorcomm/switch/i2c.h create mode 100644 drivers/net/dsa/motorcomm/switch/smi.c create mode 100644 drivers/net/dsa/motorcomm/switch/smi.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_cmm.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_drv.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_drv.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_init.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_init.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_interrupt.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_interrupt.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_isolation.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_isolation.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_l2.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_l2.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_lag.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_lag.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_led.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_led.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_loopdetect.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_loopdetect.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_mirror.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_mirror.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_multicast.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_multicast.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_nic.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_nic.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_port.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_port.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_qos.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_qos.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_reg_921x.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_reg_922x.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_reg_923x.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_stat.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_stat.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_storm_ctrl.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_storm_ctrl.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_stp.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_stp.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_sys.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_sys.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_types.h create mode 100644 drivers/net/dsa/motorcomm/switch/yt_vlan.c create mode 100644 drivers/net/dsa/motorcomm/switch/yt_vlan.h create mode 100644 drivers/net/dsa/motorcomm/yt92xx.c create mode 100644 drivers/net/dsa/motorcomm/yt92xx.h delete mode 100644 drivers/net/dsa/yt921x.c delete mode 100644 drivers/net/dsa/yt921x.h delete mode 100644 net/dsa/tag_yt921x.c create mode 100644 net/dsa/tag_yt92xx.c
drivers/net/dsa/Kconfig +2 -8
@@ -88,6 +88,8 @@ source "drivers/net/dsa/xrs700x/Kconfig" source "drivers/net/dsa/realtek/Kconfig" +source "drivers/net/dsa/motorcomm/Kconfig" + config NET_DSA_RZN1_A5PSW tristate "Renesas RZ/N1 A5PSW Ethernet switch support" depends on OF && (ARCH_RZN1 || COMPILE_TEST)
@@ -158,12 +160,4 @@ 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 - select NET_IEEE8021Q_HELPERS if DCB - help - This enables support for the Motorcomm YT9215 ethernet switch - chip. endmenu
drivers/net/dsa/Makefile +1 -1
@@ -14,7 +14,6 @@ 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 += lantiq/
@@ -27,3 +26,4 @@ obj-y += qca/ obj-y += realtek/ obj-y += sja1105/ obj-y += xrs700x/ +obj-y += motorcomm/
drivers/net/dsa/motorcomm/Kconfig new file +30 -0
@@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MOTORCOMM + tristate "Motorcomm YT92XX switch family support" + depends on NET_DSA + select FIXED_PHY + help + This driver adds support for Motorcomm switch chips. It supports + YT921X and YT922X switch. + +choice + prompt "Motorcomm switch series selection" + depends on MOTORCOMM + +config MOTORCOMM_YT921X + bool "Motorcomm YT921X series." + +config MOTORCOMM_YT922X + bool "Motorcomm YT922X series." +endchoice + +config NET_DSA_MOTORCOMM + tristate "Motorcomm YT92XX switch DSA driver" + depends on MOTORCOMM + depends on (MOTORCOMM_YT921X || MOTORCOMM_YT922X) + select NET_DSA_TAG_MOTORCOMM + select NET_IEEE8021Q_HELPERS if DCB + help + Select to enable support for Motorcomm driver. +
drivers/net/dsa/motorcomm/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_NET_DSA_MOTORCOMM) += dsa_motorcomm.o +dsa_motorcomm-y += \ + yt92xx.o +obj-y += switch/
drivers/net/dsa/motorcomm/switch/Makefile new file +47 -0
47 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/i2c.c new file +121 -0
121 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/i2c.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Motorcomm YT921x/YT922x/YT923x/YT920x Switch Configuration +* +* Copyright (c) 2026 Kyle Switch +*/ +#ifndef __CTRLIF_I2C_H__ +#define __CTRLIF_I2C_H__ +#include "yt_cmm.h" + +#define UINT32_BYTES_NUM (sizeof(u32)) + +enum yt_i2c_mode { +YT_I2C_STD_MSB =1 , +YT_I2C_STD_LSB , +YT_I2C_SIMPLE , +}; + +u32 i2c_switch_write (u8 unit,u32 addr,u32 val); +u32 i2c_switch_read (u8 unit,u32 addr,u32 *val); +#endif
drivers/net/dsa/motorcomm/switch/smi.c new file +100 -0
100 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/smi.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Motorcomm YT921x/YT922x/YT923x/YT920x Switch Configuration +* +* Copyright (c) 2026 Kyle Switch +*/ +#ifndef __CTRLIF_SMI_H__ +#define __CTRLIF_SMI_H__ +#include "yt_types.h" + +u32 smi_switch_write (u8 unit,u32 reg_addr,u32 reg_value); +u32 smi_switch_read (u8 unit,u32 reg_addr,u32 *reg_value); +#endif
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +103 -0
103 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.c new file +1146 -0
1,146 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_ctrlpkt.h new file +345 -0
345 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_drv.c new file +42 -0
42 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_drv.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Motorcomm YT921x/YT922x/YT923x/YT920x Switch Configuration +* +* Copyright (c) 2026 Kyle Switch +*/ + +#ifndef __YT_DRV_H +#define __YT_DRV_H + +/* +* Include Files +*/ +#include "yt_cmm.h" + +struct yt_drv_func { +u32 (*switch_reg_read)(u8 unit,u32 reg_addr,u32 *reg_value_ptr); +u32 (*switch_reg_write)(u8 unit,u32 reg_addr,u32 reg_value); +}; + +u32 yt_drv_register (struct yt_drv_func drv_func); +u32 yt_drv_switch_reg_read (u8 unit,u32 reg_addr,u32 *reg_value_ptr); +u32 yt_drv_switch_reg_write (u8 unit,u32 reg_addr,u32 reg_value); + +#endif
drivers/net/dsa/motorcomm/switch/yt_init.c new file +348 -0
348 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_init.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Motorcomm YT921x/YT922x/YT923x/YT920x Switch Configuration +* +* Copyright (c) 2026 Kyle Switch +*/ + +#ifndef __YT_INIT_H__ +#define __YT_INIT_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* +* Include Files +*/ +#include "yt_cmm.h" + +u32 yt_init (void ); +u32 yt_cal_board_chip_set (enum yt_switch_chip_id chip_id); +u32 yt_cal_board_chip_get (enum yt_switch_chip_id *chip_id); +u32 yt_board_port_num_get (u8 unit,u32 *max_port); +u32 yt_board_port_info_set (u8 unit,struct yt_switch_port_info port_info); +u32 yt_board_port_info_get (u8 unit,struct yt_switch_port_info *port_info); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif
drivers/net/dsa/motorcomm/switch/yt_interrupt.c new file +369 -0
369 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_interrupt.h new file +102 -0
102 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_isolation.c new file +294 -0
121 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_isolation.h new file +151 -0
151 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_l2.c new file +1075 -0
1,075 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_l2.h new file +329 -0
329 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_lag.c new file +216 -0
216 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_lag.h new file +119 -0
119 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_led.c new file +1799 -0
1,799 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_led.h new file +479 -0
479 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_loopdetect.c new file +156 -0
156 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_loopdetect.h new file +60 -0
60 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_mirror.c new file +205 -0
205 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_mirror.h new file +67 -0
67 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_multicast.c new file +540 -0
540 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_multicast.h new file +84 -0
84 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_nic.c new file +270 -0
270 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_nic.h new file +168 -0
168 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_port.c new file +6375 -0
6,375 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_port.h new file +824 -0
824 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_qos.c new file +425 -0
425 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_qos.h new file +149 -0
149 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_reg_921x.h new file +422 -0
422 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_reg_922x.h new file +571 -0
571 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_reg_923x.h new file +218 -0
218 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_stat.c new file +167 -0
167 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_stat.h new file +242 -0
242 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_storm_ctrl.c new file +477 -0
477 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_storm_ctrl.h new file +183 -0
183 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_stp.c new file +155 -0
155 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_stp.h new file +66 -0
66 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_sys.c new file +37 -0
Lines of this file are not shown. View the raw message.
drivers/net/dsa/motorcomm/switch/yt_sys.h new file +56 -0
56 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_types.h new file +172 -0
172 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_vlan.c new file +604 -0
604 lines not on this page · raw message
drivers/net/dsa/motorcomm/switch/yt_vlan.h new file +361 -0
361 lines not on this page · raw message
drivers/net/dsa/motorcomm/yt92xx.c new file +5929 -0
5,929 lines not on this page · raw message
drivers/net/dsa/motorcomm/yt92xx.h new file +1218 -0
1,218 lines not on this page · raw message
drivers/net/dsa/yt921x.c deleted +0 -4982
4,982 lines not on this page · raw message
drivers/net/dsa/yt921x.h deleted +0 -977
977 lines not on this page · raw message
net/dsa/tag_yt921x.c deleted +0 -168
168 lines not on this page · raw message
net/dsa/tag_yt92xx.c new file +376 -0
376 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Andrew Lunn
maintainerQuoted 10 lines · Kyle Switch
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.- Merge
drivers/net/dsa/yt921x.cand the new yt922x support into a unifiedyt92xx.cdriver.- Add support for yt922x, which can operate with either 4 bytes or 8 bytes DSA tag.
- Not change yt921x behaviour but use common switch apis
A 35K line patch is way too big. Please break this up into lots of small patches, each with good commit messages, which are obviously correct.
Andrew
---
pw-bot: cr
Quoted 7 lines · Andrew Lunn
Quoted 6 lines · Kyle Switch
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.- Merge
drivers/net/dsa/yt921x.cand the new yt922x support into a unifiedyt92xx.cdriver.
Quoted 9 lines
Quoted 4 lines
- Add support for yt922x, which can operate with either 4 bytes or 8 bytes DSA tag.
- Not change yt921x behaviour but use common switch apis
A 35K line patch is way too big. Please break this up into lots of small patches, each with good commit messages, which are obviously correct.
Thank you for your reminding, this patch will submitted in a series of small patches.
This patch mainly contains three contents:
1. Underlying function interface for different motorcomm switch series in the file driver/net/dsa/motorcomm/switch/.
2. Optimization existing yt921x dsa driver using common switch function apis.
3. New yt922x dsa driver.
Can you accept break this up into lots of small patch according to this logic? if not, do you have any suggestion? thank you.
Quoted 4 lines
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerQuoted 9 lines
Thank you for your reminding, this patch will submitted in a series of small patches.
This patch mainly contains three contents:
1. Underlying function interface for different motorcomm switch series in the file driver/net/dsa/motorcomm/switch/.
2. Optimization existing yt921x dsa driver using common switch function apis.
3. New yt922x dsa driver.
Can you accept break this up into lots of small patch according to this logic? if not, do you have any suggestion? thank you.
We need to see the patches, but keep them small, and add functionality little by little. I had a very quick look at your first version, and i see a lot you will need to change. So just post small bits of code, learn from the review comments, and fixup all the rest of the code before posting it.
One thing i need to point out. Linux has a long tradition of not replacing existing code with a new implementation. You take the existing code and step by step improve it. So i do not want to see a patch which just removes the existing driver. I want to see patches which add new functionality to the existing driver, doing refactors as needed.
Please also remember:
MOTORCOMM YT921X ETHERNET SWITCH DRIVER
M: David Yang <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml F: drivers/net/dsa/yt921x.* F: net/dsa/tag_yt921x.c
David is the Maintainer of this driver. Listen to what he says. In time, when you have shown you can also can do the job of being a Maintainer, your name will be added.
Andrew
Hi Kyle,
drivers/net/dsa/motorcomm/Makefile
Quoted 37 lines · Kyle Switch
drivers/net/dsa/motorcomm/Kconfig new file +30
-0@@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MOTORCOMM + tristate "Motorcomm YT92XX switch family support" + depends on NET_DSA + select FIXED_PHY + help + This driver adds support for Motorcomm switch chips. It supports + YT921X and YT922X switch. + +choice + prompt "Motorcomm switch series selection" + depends on MOTORCOMM + +config MOTORCOMM_YT921X + bool "Motorcomm YT921X series." + +config MOTORCOMM_YT922X + bool "Motorcomm YT922X series." +endchoice + +config NET_DSA_MOTORCOMM + tristate "Motorcomm YT92XX switch DSA driver" + depends on MOTORCOMM + depends on (MOTORCOMM_YT921X || MOTORCOMM_YT922X) + select NET_DSA_TAG_MOTORCOMM + select NET_IEEE8021Q_HELPERS if DCB + help + Select to enable support for Motorcomm driver. +drivers/net/dsa/motorcomm/Makefile +0
-0
NET_DSA_MOTORCOMM already depends on:
(MOTORCOMM_YT921X || MOTORCOMM_YT922X)
with both of those options depending on MOTORCOMM due to the 'choice' that they're in, so this additional dependency on MOTORCOMM is unnecessary.
You could also consider using a comment to document that this option is depended on indirectly.
- Julian Braha
Quoted 47 lines · Julian Braha
Hi Kyle,
drivers/net/dsa/motorcomm/Makefile
Quoted 37 lines · Kyle Switch
drivers/net/dsa/motorcomm/Kconfig new file +30
-0@@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config MOTORCOMM + tristate "Motorcomm YT92XX switch family support" + depends on NET_DSA + select FIXED_PHY + help + This driver adds support for Motorcomm switch chips. It supports + YT921X and YT922X switch. + +choice + prompt "Motorcomm switch series selection" + depends on MOTORCOMM + +config MOTORCOMM_YT921X + bool "Motorcomm YT921X series." + +config MOTORCOMM_YT922X + bool "Motorcomm YT922X series." +endchoice + +config NET_DSA_MOTORCOMM + tristate "Motorcomm YT92XX switch DSA driver" + depends on MOTORCOMM + depends on (MOTORCOMM_YT921X || MOTORCOMM_YT922X) + select NET_DSA_TAG_MOTORCOMM + select NET_IEEE8021Q_HELPERS if DCB + help + Select to enable support for Motorcomm driver. +drivers/net/dsa/motorcomm/Makefile +0
-0
NET_DSA_MOTORCOMMalready depends on:
(MOTORCOMM_YT921X||MOTORCOMM_YT922X)
with both of those options depending on MOTORCOMM due to the 'choice' that they're in, so this additional dependency on MOTORCOMM is unnecessary.
Quoted 2 lines
You could also consider using a comment to document that this option is depended on indirectly.
Ans: agreed, i will fix this later.
Quoted 2 lines
- Julian Braha
Andrew Lunn
maintainerQuoted 10 lines · Kyle Switch
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.- Merge
drivers/net/dsa/yt921x.cand the new yt922x support into a unifiedyt92xx.cdriver.- Add support for yt922x, which can operate with either 4 bytes or 8 bytes DSA tag.
- Not change yt921x behaviour but use common switch apis
You should comment about why you resent.
Also, you should of waited 24 hours.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Anyway, please don't send it yet again until you have broken it up into lots of smaller patches.
You also have a lot of work to do to bring this code up to Mainline standards. Please spend some time looking at other DSA drivers, and network drivers. Anything your driver does which no other driver does, is probably wrong. Please start with a small patchset with just the core code, enough to have the ports act as independent interfaces, nothing more. You can then submit further patchsets for offloading bridges, statistics, trunks, ptp etc.
Andrew
---
pw-bot: cr
David Yang
maintainerQuoted 3 lines · Kyle Switch
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.
You are blindly plugging existing code into your SDK, without sorting out register operations (for example in set_mac_eee and port_change_mtu).
Do not post code you don't understand. Ask if you are not sure.
drivers/net/dsa/motorcomm/switch/yt_cmm.h line 29
Quoted 13 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +13
-0+#define CMM_PARAM_CHK (expr, err_code) \ + do { \ + if ((u32)(expr)) { \ + return err_code; \ + } \ + } while (0) + +#define CMM_ERR_CHK (op, ret) \ + do { \ + ret = (op); \ + if (ret != CMM_ERR_OK) \ + return ret; \ + } while (0)
Do not use macros like this.
drivers/net/dsa/motorcomm/switch/yt_cmm.h line 48
Quoted 13 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +13
-0+#define GET_FIELD (value, low_bit, width) \ + (((value) >> (low_bit)) & ((1U << (width)) - 1)) +#define CLR_FIELD (value, low_bit, width) \ + ((value) & (~(((1U << (width)) - 1) << (low_bit)))) + +#define HAL_FIELD_SET (low_bit, width, entry, data) \ + do { \ + *(entry) &= (~(((1UL << (width)) - 1) << (low_bit))); \ + *(entry) |= ((data) << (low_bit)); \ + } while (0) + +#define HAL_FIELD_GET (low_bit, width, entry, pdata) \ + (*(pdata) = (((*(entry)) >> (low_bit)) & ((1UL << (width)) - 1)))
FIELD_PREP() and FIELD_GET().
Quoted 4 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +4
-0+/* +* Macro Definition +*/ +#ifndef NULL
drivers/net/dsa/motorcomm/switch/yt_types.h line 42
Quoted 10 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +10
-0+#define NULL 0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif
Nonsense.
drivers/net/dsa/motorcomm/yt92xx.c line 3453
Quoted 4 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+/* Print chipid here since we are interested in lower 16 bits */ +dev_info (dev, +"Motorcomm %s ethernet switch.\n" , + info->name);
Stop copy-n-paste.
Please, start with a minimal patch that only marks functions which use different registers/procedures and makes them virtual, and implement them for yt922x in the future.
drivers/net/dsa/motorcomm/yt92xx.c line 5901
Quoted 4 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+ { + .compatible = "motorcomm,yt9215,8bytes", + .data = &yt92xx_chip_info[YT9215_8B], + },
Do not change devicetree compatible strings.
include/uapi/linux/if_ether.h line 124
Quoted 11 lines
include/uapi/linux/if_ether.h +1
-1@@ -118,7 +118,7 @@#define ETH_P_QINQ1 0x9100/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ -#define ETH_P_YT921X 0x9988/* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_YT92XX 0x9988/* Motorcomm YT92xx DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_A5PSW 0xE001/* A5PSW Tag Value [ NOT AN OFFICIALLY REGISTERED ID ] */
UAPI stands for User-space API. Do not change it unless there is a very very good reason.
Quoted 8 lines
include/uapi/linux/if_ether.h +8
-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 PORT---->| +*|-|<---------RESERVE------------->| +*|<------------------------------->| +*/
include/uapi/linux/if_ether.h
Quoted 10 lines
include/uapi/linux/if_ether.h +10
-0+#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1 +#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1
If yt922x tag format shares no common with yt921x, make a new tag driver.
include/uapi/linux/if_ether.h
Quoted 5 lines
include/uapi/linux/if_ether.h +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};
If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
David Yang
maintainerQuoted 3 lines · David Yang
Please, start with a minimal patch that only marks functions which use different registers/procedures and makes them virtual, and implement them for yt922x in the future.
Sorry, this should be sketching yt922x_dsa_switch_ops with existing methods and filling the unimplemented later.
Quoted 10 lines · David Yang
Quoted 3 lines · Kyle Switch
Add yt92xx dsa driver supports yt921x and yt922x switch series.
To support more switch series in the future (e.g., yt923x), the most common configurations are abstracted into switch operation interfaces, due to yt921x and yt922x share similar register layouts and operational logic.You are blindly plugging existing code into your SDK, without sorting out register operations (for example in
set_mac_eeeandport_change_mtu).Do not post code you don't understand. Ask if you are not sure.
Ans: Thank you for your suggestion. I will recheck the code logic again in the future.
Quoted 16 lines
Quoted 4 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +3
-0+#define CMM_PARAM_CHK (expr, err_code) \ + do { \ + if ((u32)(expr)) { \drivers/net/dsa/motorcomm/switch/yt_cmm.h line 29
Quoted 10 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +10
-0+return err_code; \ + } \ + } while (0) + +#define CMM_ERR_CHK (op, ret) \ + do { \ + ret = (op); \ + if (ret != CMM_ERR_OK) \ + return ret; \ + } while (0)Do not use macros like this.
Ans: Acknowledged, i will consider how to optimize them in the future.
Quoted 17 lines
Quoted 4 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +3
-0+#define GET_FIELD (value, low_bit, width) \ + (((value) >> (low_bit)) & ((1U << (width)) - 1)) +#define CLR_FIELD (value, low_bit, width) \drivers/net/dsa/motorcomm/switch/yt_cmm.h line 48
Quoted 10 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +10
-0+ ((value) & (~(((1U << (width)) - 1) << (low_bit)))) + +#define HAL_FIELD_SET (low_bit, width, entry, data) \ + do { \ + *(entry) &= (~(((1UL << (width)) - 1) << (low_bit))); \ + *(entry) |= ((data) << (low_bit)); \ + } while (0) + +#define HAL_FIELD_GET (low_bit, width, entry, pdata) \ + (*(pdata) = (((*(entry)) >> (low_bit)) & ((1UL << (width)) - 1)))
FIELD_PREP()andFIELD_GET().
Quoted 16 lines
Quoted 4 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +4
-0+/* +* Macro Definition +*/ +#ifndef NULL drivers/net/dsa/motorcomm/switch/yt_types.h line 42
Quoted 10 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +10
-0+#define NULL 0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif Nonsense.
Ans: Acknowledge, will be fixed later.
Quoted 7 lines
drivers/net/dsa/motorcomm/yt92xx.c line 3453
Quoted 5 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+/* Print chipid here since we are interested in lower 16 bits */ +dev_info (dev, +"Motorcomm %s ethernet switch.\n" , + info->name);Stop copy-n-paste.
Ans: Sry for this, i will recheck the code to make sure each line of comments and code meaningful again.
Quoted 11 lines
Please, start with a minimal patch that only marks functions which use different registers/procedures and makes them virtual, and implement them for yt922x in the future.
drivers/net/dsa/motorcomm/yt92xx.c line 5901
Quoted 4 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+ { + .compatible = "motorcomm,yt9215,8bytes", + .data = &yt92xx_chip_info[YT9215_8B], + },Do not change devicetree compatible strings.
Ans: agreed, this will be fixed later.
Quoted 16 lines
include/uapi/linux/if_ether.h line 124
Quoted 12 lines
include/uapi/linux/if_ether.h +1
-1@@ -118,7 +118,7 @@#define ETH_P_QINQ1 0x9100/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ -#define ETH_P_YT921X 0x9988/* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_YT92XX 0x9988/* Motorcomm YT92xx DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_A5PSW 0xE001/* A5PSW Tag Value [ NOT AN OFFICIALLY REGISTERED ID ] */ UAPI stands for User-space API. Do not change it unless there is a very very good reason.
Ans: The default tpid both yt921x and yt922x is 0x9988. I have modified this to allow for simultaneous use in both yt922x and yt921x scenarios.
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/if_ether.h +12
-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 PORT---->| +*|-|<---------RESERVE------------->| +*|<------------------------------->| +*/ +#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1
Quoted 8 lines
include/uapi/linux/if_ether.h
Quoted 6 lines
include/uapi/linux/if_ether.h +6
-0+#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1If yt922x tag format shares no common with yt921x, make a new tag driver.
Ans: thank you for your suggestion, we will consider whether to create a new driver in the new file.
Quoted 9 lines
include/uapi/linux/if_ether.h
Quoted 6 lines
include/uapi/linux/if_ether.h +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
Ans: 4b and 8b dsa tag may have different application scenarios. from my opinion,
1. 4b dsa tag can save 4 bytes of payload
2. 8b dsa tag carry more package info.
Andrew Lunn
maintainerQuoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +7
-0+#define CMM_PARAM_CHK (expr, err_code) \ + do { \ + if ((u32)(expr)) { \ + return err_code; \ + } \ + } while (0) +Quoted 8 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h line 29
Quoted 6 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +6
-0+#define CMM_ERR_CHK (op, ret) \ + do { \ + ret = (op); \ + if (ret != CMM_ERR_OK) \ + return ret; \ + } while (0)Do not use macros like this.
Quoted 1 line
Ans: Acknowledged, i will consider how to optimize them in the future.
It is not about optimization. Hiding a return statement in a macro is very bad style. It will lead to locking bugs, and resource leaks, because nobody knows the return is there.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +8
-0+/* +* Macro Definition +*/ +#ifndef NULL +#define NULL 0 +#endif + +#ifndef FALSE Quoted 8 lines
drivers/net/dsa/motorcomm/switch/yt_types.h line 42
Quoted 6 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +6
-0+#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif Nonsense.
Quoted 1 line
Ans: Acknowledge, will be fixed later.
No. They will be fixed now.
Quoted 9 lines
Quoted 6 lines
drivers/net/dsa/motorcomm/yt92xx.c line 3453
Quoted 4 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+/* Print chipid here since we are interested in lower 16 bits */ +dev_info (dev, +"Motorcomm %s ethernet switch.\n" , + info->name);Stop copy-n-paste.
Ans: Sry for this, i will recheck the code to make sure each line of comments and code meaningful again.
Also, consider the comments. Do the comments add anything useful which is not already obvious from the code. Comments should be about "Why?".
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/if_ether.h +0
-0@@ -118,7 +118,7 @@#define ETH_P_QINQ1 0x9100/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ Quoted 9 lines
include/uapi/linux/if_ether.h line 124
Quoted 5 lines
include/uapi/linux/if_ether.h +1
-1-#define ETH_P_YT921X 0x9988/* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_YT92XX 0x9988/* Motorcomm YT92xx DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_A5PSW 0xE001/* A5PSW Tag Value [ NOT AN OFFICIALLY REGISTERED ID ] */ UAPI stands for User-space API. Do not change it unless there is a very very good reason.
Quoted 2 lines
Ans: The default tpid both yt921x and yt922x is
0x9988. I have modified this to allow for simultaneous use in both yt922x and yt921x scenarios.
As pointed out, this is UAPI. Any changes to this file need a good explanation how it does not change the user API. Do this break backwards compatibility with user space applications? Maybe tcpdump or wireshark has a dissector which expects ETH_P_YT921X and you have just broken it?
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
include/uapi/linux/if_ether.h +4
-0+#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1Quoted 8 lines
include/uapi/linux/if_ether.h
Quoted 6 lines
include/uapi/linux/if_ether.h +6
-0+#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1If yt922x tag format shares no common with yt921x, make a new tag driver.
Quoted 1 line
Ans: thank you for your suggestion, we will consider whether to create a new driver in the new file.
When you look at other tag drivers, you will also notice some drivers implement two taggers in one file. So consider this if there is any shared code.
Quoted 9 lines
Quoted 8 lines
include/uapi/linux/if_ether.h
Quoted 5 lines
include/uapi/linux/if_ether.h +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
Quoted 3 lines
Ans: 4b and 8b dsa tag may have different application scenarios. from my opinion,
1. 4b dsa tag can save 4 bytes of payload
2. 8b dsa tag carry more package info.
How do you plan to swap between the different formats?
The user perspective is that the machine has a collection of interface which are used just as normal, using Linux tools likes like iproute2. If the user enables a feature which requires the 8b tag format, will you change the format from the DSA driver? And swap back to the 4 byte format when the feature is no longer needed?
Andrew
Quoted 16 lines · Andrew Lunn
Quoted 16 lines
Quoted 15 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h line 29
Quoted 13 lines
drivers/net/dsa/motorcomm/switch/yt_cmm.h new file +13
-0+#define CMM_PARAM_CHK (expr, err_code) \ + do { \ + if ((u32)(expr)) { \ + return err_code; \ + } \ + } while (0) + +#define CMM_ERR_CHK (op, ret) \ + do { \ + ret = (op); \ + if (ret != CMM_ERR_OK) \ + return ret; \ + } while (0)Do not use macros like this.
Quoted 6 lines
Quoted 1 line
Ans: Acknowledged, i will consider how to optimize them in the future.
It is not about optimization. Hiding a return statement in a macro is very bad style. It will lead to locking bugs, and resource leaks, because nobody knows the return is there.
Ans: This issue will be fixed before the next patch is sent.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +4
-0+/* +* Macro Definition +*/ +#ifndef NULL drivers/net/dsa/motorcomm/switch/yt_types.h line 42
Quoted 10 lines
drivers/net/dsa/motorcomm/switch/yt_types.h new file +10
-0+#define NULL 0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif Nonsense.
Quoted 4 lines
Quoted 1 line
Ans: Acknowledge, will be fixed later.
No. They will be fixed now.
Ans: This issue will be fixed before the next patch is sent.
Quoted 29 lines
Quoted 9 lines
Quoted 6 lines
drivers/net/dsa/motorcomm/yt92xx.c line 3453
Quoted 4 lines
drivers/net/dsa/motorcomm/yt92xx.c new file +4
-0+/* Print chipid here since we are interested in lower 16 bits */ +dev_info (dev, +"Motorcomm %s ethernet switch.\n" , + info->name);Stop copy-n-paste.
Ans: Sry for this, i will recheck the code to make sure each line of comments and code meaningful again.
Also, consider the comments. Do the comments add anything useful which is not already obvious from the code. Comments should be about "Why?".
Quoted 16 lines
Quoted 15 lines
include/uapi/linux/if_ether.h line 124
Quoted 11 lines
include/uapi/linux/if_ether.h +1
-1@@ -118,7 +118,7 @@#define ETH_P_QINQ1 0x9100/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ -#define ETH_P_YT921X 0x9988/* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_YT92XX 0x9988/* Motorcomm YT92xx DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_A5PSW 0xE001/* A5PSW Tag Value [ NOT AN OFFICIALLY REGISTERED ID ] */ UAPI stands for User-space API. Do not change it unless there is a very very good reason.
Quoted 9 lines
Quoted 2 lines
Ans: The default tpid both yt921x and yt922x is
0x9988. I have modified this to allow for simultaneous use in both yt922x and yt921x scenarios.As pointed out, this is UAPI. Any changes to this file need a good explanation how it does not change the user API. Do this break backwards compatibility with user space applications? Maybe tcpdump or wireshark has a dissector which expects
ETH_P_YT921Xand you have just broken it?
Ans:Now I have a better understanding of the role of the UAPI representative.
If a new dsa driver is added in the subsequent patch, consider adding one instead of modifying the original content.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
include/uapi/linux/if_ether.h
Quoted 10 lines
include/uapi/linux/if_ether.h +10
-0+#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1 +#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1If yt922x tag format shares no common with yt921x, make a new tag driver.
Quoted 6 lines
Quoted 1 line
Ans: thank you for your suggestion, we will consider whether to create a new driver in the new file.
When you look at other tag drivers, you will also notice some drivers implement two taggers in one file. So consider this if there is any shared code.
Ans: ok, the tag driver will refer to the methods of other existing tag drivers.
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines
include/uapi/linux/if_ether.h
Quoted 5 lines
include/uapi/linux/if_ether.h +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
Quoted 3 lines
Ans: 4b and 8b dsa tag may have different application scenarios. from my opinion,
1. 4b dsa tag can save 4 bytes of payload
2. 8b dsa tag carry more package info.
Quoted 8 lines
How do you plan to swap between the different formats?
The user perspective is that the machine has a collection of interface which are used just as normal, using Linux tools likes like iproute2. If the user enables a feature which requires the 8b tag format, will you change the format from the DSA driver? And swap back to the 4 byte format when the feature is no longer needed?
Ans: After considering your and David's comments and suggestion, we will broken this patch into lots of small patches which just include 8bytes tag driver for now.
If the 4bytes tag driver scenario is required later, we will use "change_tag_protocol" mechanism from DSA driver.
As you mentioned "One thing i need to point out. Linux has a long tradition of not
replacing existing code with a new implementation. You take the existing code and step by step improve it. " in another mail before. I want to explain the patch in more detail.
Step 1. We do not attempt to remove the existing driver implementation, and don't change the behavior of existing software, we will retain the implementation of the existing driver software layer, but encapsulate the use of hardware operations into functional interfaces. The advantage of this is that it is easy to maintain and easy to support other motorcomm switch series.
for example: vlan add ops in dsa driver:
Existing code:
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged) {
u64 mask64;
u64 ctrl64;
mask64 = YT921X_VLAN_CTRL_PORTn(port) |
YT921X_VLAN_CTRL_PORTS(priv->cpu_ports_mask);
ctrl64 = mask64;
mask64 |= YT921X_VLAN_CTRL_UNTAG_PORTn(port);
if (untagged)
ctrl64 |= YT921X_VLAN_CTRL_UNTAG_PORTn(port);
return yt921x_reg64_update_bits(priv, YT921X_VLANn_CTRL(vid),
mask64, ctrl64); }
after patch:
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged) {
struct yt_port_mask member;
struct yt_port_mask untag;
member.portsbits[0] = BIT(port) | priv->cpu_ports_mask; if (untagged)
untag.portbits[0] = BIT(port);
return yt_vlan_port_set(priv->unit, vid, member, untag); // Here we use encapsulated interfaces to complete the hardware configuration.
// We can ignore the differences between different motorcomm series, which will be reflected in driver/net/dsa/motorocmm/switch/yt_vlan. c }
Step 2. if Step 1 is accepted, later, the plan may be to replace the hardware configuration involved in the existing dsa driver with the encapsulated interface step by step according to the functional module such as vlan, mirror, lag, etc. Finally, upload the yt922x dsa driver.
Quoted 1 line
Andrew
Andrew Lunn
maintainerQuoted 23 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
include/uapi/linux/if_ether.h line 124
Quoted 8 lines
#define ETH_P_QINQ1 0x9100 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ2 0x9200 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */include/uapi/linux/if_ether.h +1
-1-#define ETH_P_YT921X 0x9988/* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_YT92XX 0x9988/* Motorcomm YT92xx DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_DSA_A5PSW 0xE001/* A5PSW Tag Value [ NOT AN OFFICIALLY REGISTERED ID ] */ UAPI stands for User-space API. Do not change it unless there is a very very good reason.
Quoted 9 lines
Quoted 2 lines
Ans: The default tpid both yt921x and yt922x is
0x9988. I have modified this to allow for simultaneous use in both yt922x and yt921x scenarios.As pointed out, this is UAPI. Any changes to this file need a good explanation how it does not change the user API. Do this break backwards compatibility with user space applications? Maybe tcpdump or wireshark has a dissector which expects
ETH_P_YT921Xand you have just broken it?
Quoted 2 lines
Ans:Now I have a better understanding of the role of the UAPI representative.
If a new dsa driver is added in the subsequent patch, consider adding one instead of modifying the original content.
Or just use ETH_P_YT921X.
Quoted 24 lines
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged){
u64 mask64;
u64 ctrl64;mask64 =
YT921X_VLAN_CTRL_PORTn(port)|
YT921X_VLAN_CTRL_PORTS(priv->cpu_ports_mask);
ctrl64 = mask64;mask64 |=
YT921X_VLAN_CTRL_UNTAG_PORTn(port);
if (untagged)
ctrl64 |=YT921X_VLAN_CTRL_UNTAG_PORTn(port);return yt921x_reg64_update_bits(priv,
YT921X_VLANn_CTRL(vid),mask64, ctrl64); }after patch:
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged){
structyt_port_maskmember;
structyt_port_maskuntag;
Quoted 7 lines
member.portsbits[0] = BIT(port) |
priv->cpu_ports_mask; if (untagged)
untag.portbits[0] = BIT(port);return
yt_vlan_port_set(priv->unit, vid, member, untag); // Here we use encapsulated interfaces to complete the hardware configuration.// We can ignore the differences between different motorcomm series, which will be reflected in driver/net/dsa/motorocmm/switch/yt_vlan. c }
Look at other DSA drivers, e.g. mv88e6xxx, ocelot. They have structures like ocelot_ops and mv88e6xxx_ops which abstract the differences between different families.
Andrew
David Yang
maintainerQuoted 36 lines · Kyle Switch
As you mentioned "One thing i need to point out. Linux has a long tradition of not
replacing existing code with a new implementation. You take the existing code and step by step improve it. " in another mail before. I want to explain the patch in more detail.Step 1. We do not attempt to remove the existing driver implementation, and don't change the behavior of existing software, we will retain the implementation of the existing driver software layer, but encapsulate the use of hardware operations into functional interfaces. The advantage of this is that it is easy to maintain and easy to support other motorcomm switch series.
for example: vlan add ops in dsa driver:
Existing code:
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged){
u64 mask64;
u64 ctrl64;mask64 =
YT921X_VLAN_CTRL_PORTn(port)|
YT921X_VLAN_CTRL_PORTS(priv->cpu_ports_mask);
ctrl64 = mask64;mask64 |=
YT921X_VLAN_CTRL_UNTAG_PORTn(port);
if (untagged)
ctrl64 |=YT921X_VLAN_CTRL_UNTAG_PORTn(port);return yt921x_reg64_update_bits(priv,
YT921X_VLANn_CTRL(vid),mask64, ctrl64); }after patch:
yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged){
structyt_port_maskmember;
structyt_port_maskuntag;
Quoted 7 lines
member.portsbits[0] = BIT(port) |
priv->cpu_ports_mask; if (untagged)
untag.portbits[0] = BIT(port);return
yt_vlan_port_set(priv->unit, vid, member, untag); // Here we use encapsulated interfaces to complete the hardware configuration.// We can ignore the differences between different motorcomm series, which will be reflected in driver/net/dsa/motorocmm/switch/yt_vlan. c }
No for nuking the existing code. Your encapsulated interfaces do everything that no other does
- hardwired to static variables everywhere;
- invented unnecessary types (yt_enable) and struct (yt_port_mask);
- contain lots of unused files and meaningless comments, while;
- incomplete in other parts, for example ACL;
- still require direct register accesses outside your interfaces.
I see no chance that your current interfaces will ever be accepted, unless you come up with something totally different.
Looking at other DSA drivers, please use one of the following approaches wisely:
struct yt921x_ops ...;
// for simple register relocations
res = yt921x_reg_read(priv, priv->ops->some_reg, &val);
// for complex operations, but still reuse the context do_something;priv->ops->some_op(...);do_the_rest;
// for something completely different
struct dsa_switch_ops yt921x_dsa_switch_ops = {
.some_op = yt921x_dsa_some_op,
};
struct dsa_switch_ops yt922x_dsa_switch_ops = {
.some_op = yt922x_dsa_some_op,
};Quoted 2 lines
Step 2. if Step 1 is accepted, later, the plan may be to replace the hardware configuration involved in the existing dsa driver with the encapsulated interface step by step according to the functional module such as vlan, mirror, lag, etc. Finally, upload the yt922x dsa driver.
You upload the driver for yt922x for your first patch.
Take ar9331 as an example, a DSA driver is only required to implement .get_tag_protocol(), .setup(), .phylink_get_caps() and phylink_mac_ops, that's is the "minimal" work for a new chip. So please make changes to these functions (and possibly more, but keep the patch size in a reasonable range), and each of your patches will be an actually usable and testable commit.
David Yang
maintainerQuoted 21 lines · Kyle Switch
Quoted 12 lines
Quoted 12 lines
net/dsa/tag_yt92xx.c new file +12
-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 PORT---->| +*|-|<---------RESERVE------------->| +*|<------------------------------->| +*/ +#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1Quoted 8 lines
net/dsa/tag_yt92xx.c line 273
Quoted 6 lines
net/dsa/tag_yt92xx.c new file +6
-0+#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1If yt922x tag format shares no common with yt921x, make a new tag driver.
Quoted 1 line
Ans: thank you for your suggestion, we will consider whether to create a new driver in the new file.
I'm not an expert in this, but if yt922x tag does support cpu codes and priority, please consider updating yt921x tagger to support it, even if you don't use or test these features for now.
Quoted 10 lines
Quoted 9 lines
net/dsa/tag_yt92xx.c line 371
Quoted 6 lines
net/dsa/tag_yt92xx.c new file +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
Quoted 3 lines
Ans: 4b and 8b dsa tag may have different application scenarios. from my opinion,
1. 4b dsa tag can save 4 bytes of payload
2. 8b dsa tag carry more package info.
We do not support every tag protocol. For DSA switches,
- the conduit interface supports jumbo frames so there is room for
the DSA header, or
- you end up with MTU less than 1500 anyway.
4-byte reduction does not make a practical difference here. An alternative protocol poses 2x work to everyone else, and unnecessarily exposes your driver to interoperability issues, as pointed by Andrew.
As I've commented before, if there is a particular reason to add 4-byte protocol, leave it behind for the moment, and focus on a minimal yt922x_dsa_switch_ops + yt922x_netdev_ops for your first patchset without any offloading supports. This way, others can easily see your changes and move the work forward efficiently.
Quoted 22 lines · David Yang
Quoted 21 lines · Kyle Switch
Quoted 20 lines
Quoted 8 lines
net/dsa/tag_yt92xx.c new file +8
-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 PORT---->| +*|-|<---------RESERVE------------->| +*|<------------------------------->| +*/ net/dsa/tag_yt92xx.c line 273
Quoted 10 lines
net/dsa/tag_yt92xx.c new file +10
-0+#define YT922X_TAG_FORMAT2_NAME "yt922x-8b" +#define YT922X_FORMAT2_TAG_LEN 8 +#define YT922X_PKT_TYPE GENMASK(15, 14) +#define YT922X_8B_CPUTAG_PKT_FROM_CPU 0x1 +#define YT922X_8B_CPUTAG_SRC_PORT GENMASK(6, 2) +#define YT922X_8B_CPUTAG_DST_PORTMASK GENMASK(8, 0) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0 BIT(15) +#define YT922X_8B_CPUTAG_DST_PORTMASK_0_EN 0x1 +#define YT922X_8B_CPUTAG_FORCE_DST BIT(9) +#define YT922X_8B_CPUTAG_FORCE_DST_EN 0x1If yt922x tag format shares no common with yt921x, make a new tag driver.
Quoted 6 lines
Quoted 1 line
Ans: thank you for your suggestion, we will consider whether to create a new driver in the new file.
I'm not an expert in this, but if yt922x tag does support cpu codes and priority, please consider updating yt921x tagger to support it, even if you don't use or test these features for now.
Ans: here "updating yt921x tagger" you mean yt922x tag driver to support cpu code and dscp prio? We consider implementing it in the subsequent patch, but no matter what, when we submit the yt922x dsa driver ,it will support it.
Quoted 22 lines
Quoted 10 lines
Quoted 9 lines
net/dsa/tag_yt92xx.c line 371
Quoted 6 lines
net/dsa/tag_yt92xx.c new file +5
-0+static struct dsa_tag_driver *dsa_tag_driver_array[] = { + &DSA_TAG_DRIVER_NAME (yt921x_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_4b_netdev_ops), + &DSA_TAG_DRIVER_NAME (yt922x_8b_netdev_ops), +};If both are supported by the chip and 4b does nothing more than 8b does, do not bother with it.
Quoted 3 lines
Ans: 4b and 8b dsa tag may have different application scenarios. from my opinion,
1. 4b dsa tag can save 4 bytes of payload
2. 8b dsa tag carry more package info.We do not support every tag protocol. For DSA switches,
- the conduit interface supports jumbo frames so there is room for
the DSA header, or
- you end up with MTU less than 1500 anyway.
4-byte reduction does not make a practical difference here. An alternative protocol poses 2x work to everyone else, and unnecessarily exposes your driver to interoperability issues, as pointed by Andrew.
Quoted 5 lines
As I've commented before, if there is a particular reason to add 4-byte protocol, leave it behind for the moment, and focus on a minimal
yt922x_dsa_switch_ops+yt922x_netdev_opsfor your first patchset without any offloading supports. This way, others can easily see your changes and move the work forward efficiently.
Ans: Thank you for your advise, 8bytes dsa tag driver will be supported firstly.