net: dsa: motorcomm: add support yt922x driver
v17 cover net: dsa: motorcomm: add support yt922x driver
This patchset mainly adds support for the yt922x series to the dsa driver. Currently, only the yt9224 in the yt922x series is supported, and the corresponding tag handling for yt922x is added.
At the same time, it optimizes the max ports boundary check in the existing code, and initializes the dsa switch based on the chipid.
changes in v17:
1) Rebase.
changes in v16:
1) Add missing break in switch case to prevent fall-through in yt922x_port_config()
changes in v15:
1) Revert the use of GENMASK_U16() to replace GENMASK(), so as to facilitate adaptation to scenarios with more ports in the future.
2) Group functions with the same functionality together in mdio_bus.c.
3) Remove meaningless code comments.
4) Renaming parameters in yt922x_pcs_get_state().
5) Add neg_mode and advertising handle.
changes in v14:
1) Replace the goto-based skip_extmode_check path with an early conditional in yt921x_chip_detect().
changes in v13:
1) Fix a compilation error in patch1 only.
The change is limited to the yt92xx_register_switch function:
- Replace yt921x_priv with dsa_to_yt921x_priv
- Replace to_device with yt921x_priv_to_device
changes in v12:
1) Rebase the code.
2) Delete origin patch4 and patch5 about MIB init and remove operation.
3) Optimize error message logging.
4) Add documents about yt922x tag.
changes in v11:
1) Initialize ctrl variable inside yt922x_port_up().
2) Update maitainer for new file.
changes in v10:
1) Rebase the code.
changes in v9:
patch 1: 1) Add a dev_err() when chipid mismatch.
patch 3: 1) Using GENMASK_U* to replace GENMASK
changes in v8:
patch 1: 1) Add a lock operation to acquire the chip ID during the probe()
stage.
2) Remove meaningless changes.
patch 3: Modify the changelog description.
patch 6: 1) Remove sds_init() in this patch.
2) Code refactoring, including yt922x_sds_phyaddr_get() and yt921x_needs_extmode_check()
3) In yt921x_intif_ext_write() and yt921x_intif_ext_read(), add a boundary check for phyaddr. The reason is that the phyaddr of the top ext register is 9, so max_ports should be used for the check to include it.
4) In the yt922x driver, added initialization of yt921x_port for exporting priv.
changes in v7:
patch 1: Fix the series_lookup() redundancy issue.
Fix the dsa->priv initialization and the code style issue.
patch 6: Move psc definition to yt921x_port
Fix psc_get_state() and an_restart().
Use the existing yt921x driver interface for the duplicated logic for chip_reset().
Move the yt922x_cpu_port_set() to chip_setup_dsa() to align with yt921x function.
Kyle Switch (5):
net: dsa: motorcomm: initialize dsa_switch based on chipid
net: dsa: motorcomm: use max_ports in series for port bounds checking
net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x
MAINTAINERS | 2 + drivers/net/dsa/motorcomm/Kconfig | 7 +- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 575 ++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 101 +++++ drivers/net/dsa/motorcomm/mdio_bus.c | 48 ++- drivers/net/dsa/motorcomm/mdio_bus.h | 4 + drivers/net/dsa/motorcomm/pcs-922x.c | 282 +++++++++++++ drivers/net/dsa/motorcomm/pcs.h | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 122 ++++++ 13 files changed, 1135 insertions(+), 17 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
PATCH v17 1/5 net: dsa: motorcomm: initialize dsa_switch based on chipid
Replace the hardcoded chip handling in yt92xx_register_switch() with a data-driven loopup based on the chip ID.
--- drivers/net/dsa/motorcomm/chip.c | 73 ++++++++++++++++++++++++++++---- drivers/net/dsa/motorcomm/chip.h | 19 +++++++++ 2 files changed, 84 insertions(+), 8 deletions(-)
drivers/net/dsa/motorcomm/chip.c +65 -8
@@ -2574,6 +2574,67 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static const struct yt92xx_series yt92xx_series_table[] = { + [YT92XX_MODE_YT921X ] = { + .name ="YT921x" , + .max_ports =YT921X_PORT_NUM , + .num_lag_ids =YT921X_LAG_NUM , + .ageing_time_min =1 *5000 , + .ageing_time_max =U16_MAX *5000 , + .dscp_prio_mapping_is_global = true, + .assisted_learning_on_cpu_port = true, + .switch_ops = &yt921x_dsa_switch_ops, + .mac_ops = &yt921x_phylink_mac_ops + }, +}; + +static const struct yt92xx_series *yt92xx_series_lookup (u32 major) +{ +if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) +return &yt92xx_series_table[YT92XX_MODE_YT921X ]; +else +return NULL ; +} + +static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; + +mutex_lock (&priv->reg_lock); + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +mutex_unlock (&priv->reg_lock); +if (res) { +dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +return res; + } + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) { +dev_err (dev,"Undefined series info for the corresponding major\n" ); +return -ENODEV ; + } + priv->series = series; + + ds->assisted_learning_on_cpu_port = + priv->series->assisted_learning_on_cpu_port; + ds->dscp_prio_mapping_is_global = + priv->series->dscp_prio_mapping_is_global; + ds->ageing_time_min = priv->series->ageing_time_min; + ds->ageing_time_max = priv->series->ageing_time_max; + ds->num_lag_ids = priv->series->num_lag_ids; + ds->num_ports = priv->series->max_ports; + ds->ops = priv->series->switch_ops; + ds->phylink_mac_ops = priv->series->mac_ops; + +return 0 ; +} +static void yt921x_mdio_shutdown (struct mdio_device *mdiodev) {struct yt921x_priv *priv =mdiodev_get_drvdata (mdiodev);
@@ -2616,6 +2677,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)struct yt921x_reg_mdio *mdio;struct yt921x_priv *priv;struct dsa_switch *ds; +int res; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -2642,15 +2704,10 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) ds = &priv->ds; ds->dev = dev; - ds->assisted_learning_on_cpu_port = true; - ds->dscp_prio_mapping_is_global = true; ds->priv = priv; - ds->ops = &yt921x_dsa_switch_ops; - ds->ageing_time_min =1 *5000 ; - ds->ageing_time_max =U16_MAX *5000 ; - ds->phylink_mac_ops = &yt921x_phylink_mac_ops; - ds->num_lag_ids =YT921X_LAG_NUM ; - ds->num_ports =YT921X_PORT_NUM ; + res =yt92xx_register_switch (ds); +if (res) +return res;mdiodev_set_drvdata (mdiodev, priv);
drivers/net/dsa/motorcomm/chip.h +19 -0
@@ -503,9 +503,28 @@ static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info)return info->internal_mask | info->xmii_mask | info->serdes_mask; } +enum yt92xx_mode { +YT92XX_MODE_YT921X , +YT92XX_MODE_YT922X , +YT92XX_MODE_MAX , +}; + +struct yt92xx_series { +const char *name; +unsigned int max_ports; +unsigned int num_lag_ids; +unsigned int ageing_time_min; +unsigned int ageing_time_max; +u32 dscp_prio_mapping_is_global; +u32 assisted_learning_on_cpu_port; +const struct dsa_switch_ops *switch_ops; +const struct phylink_mac_ops *mac_ops; +}; +struct yt921x_priv {struct dsa_switch ds; +const struct yt92xx_series *series;const struct yt921x_info *info;unsigned int meter_slot_ns;unsigned int port_shape_slot_ns;
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v17 1/5] net: dsa: motorcomm: initialize dsa_switch based on chipid
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
Quoted 61 lines
drivers/net/dsa/motorcomm/chip.c +54
-0@@ -2574,6 +2574,67 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static const struct yt92xx_series yt92xx_series_table[] = { + [YT92XX_MODE_YT921X ] = { + .name ="YT921x" , + .max_ports =YT921X_PORT_NUM , + .num_lag_ids =YT921X_LAG_NUM , + .ageing_time_min =1 *5000 , + .ageing_time_max =U16_MAX *5000 , + .dscp_prio_mapping_is_global = true, + .assisted_learning_on_cpu_port = true, + .switch_ops = &yt921x_dsa_switch_ops, + .mac_ops = &yt921x_phylink_mac_ops + }, +}; + +static const struct yt92xx_series *yt92xx_series_lookup (u32 major) +{ +if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) +return &yt92xx_series_table[YT92XX_MODE_YT921X ]; +else +return NULL ; +} + +static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; + +mutex_lock (&priv->reg_lock); + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +mutex_unlock (&priv->reg_lock); +if (res) { +dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +return res; + } + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) { +dev_err (dev,"Undefined series info for the corresponding major\n" ); +return -ENODEV ; + } + priv->series = series; + + ds->assisted_learning_on_cpu_port = + priv->series->assisted_learning_on_cpu_port; + ds->dscp_prio_mapping_is_global = + priv->series->dscp_prio_mapping_is_global; + ds->ageing_time_min = priv->series->ageing_time_min; + ds->ageing_time_max = priv->series->ageing_time_max; + ds->num_lag_ids = priv->series->num_lag_ids;
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2640
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +7
-0+ ds->num_ports = priv->series->max_ports; + ds->ops = priv->series->switch_ops; + ds->phylink_mac_ops = priv->series->mac_ops; + +return 0 ; +} +static void yt921x_mdio_shutdown (struct mdio_device *mdiodev) {struct yt921x_priv *priv =mdiodev_get_drvdata (mdiodev);
[Severity: Medium]
If yt921x_reg_read() fails, yt921x_reg_mdio_read() returns before it writes *valp. That leaves chipid as uninitialized stack data when it is passed to dev_err() here.
The message is also misleading. On this path the read failed and the chip ID was never obtained, so "Unexpected chipid" followed by a random value is no help to someone debugging a broken MDIO bus. KMSAN would also report it as an uninit-value use.
Could you print the error code from res here instead? The chip ID can be reported in the !series branch, where it has actually been read and is the value that is unexpected.
The YT922x patch later in the series already moves the message there. Please fold that change into this patch so each commit stands on its own and the series stays bisectable.
Signature · 1 line
pw-bot: cr
PATCH v17 2/5 net: dsa: motorcomm: use max_ports in series for port bounds checking
In reply to Kyle SwitchReplace the hardcoded YT921X_PORT_NUM macro with the per-series max_ports field in port validation. This removes family-specific constants from the common code path and simplifies adding new switch families with different port counts.
No functional change for existing YT921X devices.
--- drivers/net/dsa/motorcomm/mdio_bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/mdio_bus.c +5 -3
@@ -113,7 +113,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg)u16 val;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return U16_MAX ;mutex_lock (&priv->reg_lock);
@@ -131,7 +131,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)struct yt921x_priv *priv = mbus->priv;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return -ENODEV ;mutex_lock (&priv->reg_lock);
@@ -145,6 +145,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) {struct device *dev =yt921x_priv_to_device (priv);struct mii_bus *mbus; +u32 max_ports;int res; mbus =devm_mdiobus_alloc (dev);
@@ -157,7 +158,8 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->read = yt921x_mbus_int_read; mbus->write = yt921x_mbus_int_write; mbus->parent = dev; - mbus->phy_mask = (u32 )~GENMASK (YT921X_PORT_NUM -1 ,0 ); + max_ports = priv->series->max_ports; + mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); res =devm_of_mdiobus_register (dev, mbus, mnp);if (res)
Signature · 1 line
2.25.1
PATCH v17 3/5 net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
In reply to Kyle SwitchSome masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the YT921X_MBUS_CTRL_* masks used by mdio_bus.c to fixed-width helpers.
This is a type cleanup only, with no functional change. Other GENMASK() uses in the driver are intentionally left untouched.
--- drivers/net/dsa/motorcomm/chip.c | 2 +- drivers/net/dsa/motorcomm/mdio_bus.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/motorcomm/chip.c +1 -1
@@ -2285,7 +2285,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)if (res)return res; - ctrl =GENMASK (10 ,0 ); + ctrl =GENMASK_U32 (10 ,0 ); res =yt921x_reg_write (priv,YT921X_FILTER_UNK_UCAST , ctrl);if (res)return res;
drivers/net/dsa/motorcomm/mdio_bus.c +1 -1
@@ -159,7 +159,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->write = yt921x_mbus_int_write; mbus->parent = dev; max_ports = priv->series->max_ports; - mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); + mbus->phy_mask = ~GENMASK_U32 (max_ports -1 ,0 ); res =devm_of_mdiobus_register (dev, mbus, mnp);if (res)
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v17 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
This patch replaces two GENMASK() uses in the motorcomm DSA driver with GENMASK_U32(). One is in yt921x_chip_setup_dsa() in chip.c and the other is in yt921x_mbus_int_init() in mdio_bus.c. It is described as a type cleanup with no functional change.
Quoted 7 lines
Some masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the YT921X_MBUS_CTRL_* masks used by
mdio_bus.cto fixed-width helpers.This is a type cleanup only, with no functional change. Other
GENMASK()uses in the driver are intentionally left untouched.
[Severity: Medium]
Does this description match the diff? The patch doesn't seem to touch the YT921X_MBUS_CTRL_* masks at all. After this patch they are still plain GENMASK() in drivers/net/dsa/motorcomm/mdio_bus.h:
#define YT921X_MBUS_CTRL_PORT_M GENMASK(25, 21) #define YT921X_MBUS_CTRL_REG_M GENMASK(20, 16) #define YT921X_MBUS_CTRL_TYPE_M GENMASK(11, 8) /* wild guess */ #define YT921X_MBUS_CTRL_OP_M GENMASK(3, 2) /* wild guess */
They still feed the u32 mask variables in yt921x_intif_read(), yt921x_intif_write(), yt921x_extif_read() and yt921x_extif_write(), for example:
mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | YT921X_MBUS_CTRL_OP_M;
No later patch in the series converts them either.
The two lines the patch does change are not MBUS_CTRL masks. In yt921x_chip_setup_dsa(), the mask written to YT921X_FILTER_UNK_UCAST and YT921X_FILTER_UNK_MCAST is changed:
ctrl = GENMASK_U32(10, 0);
That seems to contradict "Other GENMASK() uses in the driver are intentionally left untouched".
The other change is the phy_mask calculation in yt921x_mbus_int_init():
mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0);
Also, the message refers to "masks assigned to u16 and u32 fields", but none of the changed lines involve a u16 field.
Both changed lines give the same values as before, so runtime behaviour does not change. Only the description is off.
Could the message be reworded to describe the FILTER_UNK and phy_mask changes, with the "left untouched" sentence dropped? The other option is to convert the YT921X_MBUS_CTRL_* masks in mdio_bus.h as the message says.
David Yang
maintainerRe: [PATCH net-next v17 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
In reply to Kyle Switchdrivers/net/dsa/motorcomm/chip.c static int yt921x_chip_setup_dsa(struct yt921x_priv *priv) · line 2291
Quoted 11 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +1
-1@@ -2285,7 +2285,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)if (res)return res; - ctrl =GENMASK (10 ,0 ); + ctrl =GENMASK_U32 (10 ,0 ); res =yt921x_reg_write (priv,YT921X_FILTER_UNK_UCAST , ctrl);if (res)return res;
Just removing this line of change will work.
PATCH v17 4/5 net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
In reply to Kyle SwitchAdd DSA tag support for Motorcomm YT922x switches. YT922x uses the same ETH_P_YT921X EtherType and the same 8-byte tag length as YT921x, but the tag layout differs, so a separate tag driver is needed instead of extending tag_yt921x.c.
The new driver documents both the to-CPU and from-CPU tag layouts.
Update the co-maintainer for the Motorcomm DSA driver.
--- MAINTAINERS | 2 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 122 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 net/dsa/tag_yt922x.c
MAINTAINERS +2 -0
@@ -18817,11 +18817,13 @@ F: drivers/net/phy/motorcomm.c MOTORCOMM YT921X ETHERNET SWITCH DRIVER M: David Yang <[email protected]> +M: Kyle Switch <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c +F: net/dsa/tag_yt922x.c MOXA SMARTIO/INDUSTIO SERIAL CARD M: Jiri Slaby <[email protected]>
include/net/dsa.h +2 -0
@@ -62,6 +62,7 @@ struct tc_action;#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35#define DSA_TAG_PROTO_KS8995_VALUE 36 +#define DSA_TAG_PROTO_YT922X_VALUE 37enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -101,6 +102,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE ,DSA_TAG_PROTO_KS8995 =DSA_TAG_PROTO_KS8995_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -233,4 +233,10 @@ config NET_DSA_TAG_YT921X Say Y or M if you want to enable support for tagging frames for Motorcomm YT921x switches. +config NET_DSA_TAG_YT922X + tristate "Tag driver for Motorcomm YT922x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT922x switches. + endif
net/dsa/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o +obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v17 5/5 net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchAdd support for Motorcomm YT922X, which is series of ethernet switches developed by Motorcomm Electronic Technology, includes YT9224 and YT9228.
This patch only adds support for the YT9224 variant. YT9228 is not supported yet.
This patch adds basic support for a working DSA switch, includes .port_setup, .setup, .phylink_get_caps, .get_tag_protocol.
--- drivers/net/dsa/motorcomm/Kconfig | 7 +- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 508 ++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 82 +++++ drivers/net/dsa/motorcomm/mdio_bus.c | 40 +++ drivers/net/dsa/motorcomm/mdio_bus.h | 4 + drivers/net/dsa/motorcomm/pcs-922x.c | 282 +++++++++++++++ drivers/net/dsa/motorcomm/pcs.h | 1 + 8 files changed, 916 insertions(+), 9 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c
drivers/net/dsa/motorcomm/Kconfig +4 -3
@@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" + tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support" select NET_DSA_TAG_YT921X + select NET_DSA_TAG_YT922X select NET_IEEE8021Q_HELPERS if DCB help - This enables support for the Motorcomm YT9215 ethernet switch - chip. + This enables support for the Motorcomm YT9215 and YT9224 + ethernet switch chip. config NET_DSA_YT921X_LEDS bool "LED support for Motorcomm YT9215"
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -4,6 +4,7 @@ yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += mdio_bus.o yt921x-objs += mib.o +yt921x-objs += pcs-922x.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o yt921x-objs += tc.o
drivers/net/dsa/motorcomm/chip.c +502 -6
570 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +82 -0
106 lines not on this page · raw message
drivers/net/dsa/motorcomm/mdio_bus.c +40 -0
@@ -107,6 +107,45 @@ yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg,return 1 ; } +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +} +static int yt921x_mbus_int_read (struct mii_bus *mbus,int port,int reg) {struct yt921x_priv *priv = mbus->priv;
@@ -299,3 +338,4 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } +
drivers/net/dsa/motorcomm/mdio_bus.h +4 -0
@@ -35,6 +35,10 @@ struct yt921x_priv;int yt921x_intif_read (struct yt921x_priv *priv,int port,int reg,u16 *valp);int yt921x_intif_write (struct yt921x_priv *priv,int port,int reg,u16 val); +int yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg, +u16 val); +int yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg, +u16 *valp);int yt921x_intif_modify_changed (struct yt921x_priv *priv,int port,int reg,u16 mask,u16 val);
drivers/net/dsa/motorcomm/pcs-922x.c new file +282 -0
282 lines not on this page · raw message
drivers/net/dsa/motorcomm/pcs.h +1 -0
@@ -9,5 +9,6 @@#include <linux/phylink.h> extern const struct phylink_pcs_ops yt921x_phylink_pcs_ops; +extern const struct phylink_pcs_ops yt922x_phylink_pcs_ops;#endif
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v17 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: motorcomm: Add support for Motorcomm YT922x
This commit adds support for the YT9224 member of the Motorcomm YT922x switch family to the existing yt921x DSA driver. It adds a separate set of dsa_switch_ops and phylink_mac_ops for the YT922x series, a new PCS driver in pcs-922x.c, and a "motorcomm,yt9224" OF compatible.
Quoted 3 lines
This patch adds basic support for a working DSA switch, includes .port_setup, .setup, .phylink_get_caps, .get_tag_protocol.
[Severity: Low]
This isn't a bug, but could the commit message cover everything the patch changes? Beyond the four dsa_switch_ops listed, it also adds:
- a full phylink_mac_ops set (mac_config, mac_link_up, mac_link_down, mac_select_pcs)
- a new PCS driver in pcs-922x.c for SGMII, 1000BASE-X, 2500BASE-X and USXGMII
- two new MDIO helpers, yt921x_intif_ext_read() and
yt921x_intif_ext_write()
- YT921X_SPEED_5000 in the shared enum yt921x_speed, plus a SPEED_5000 case in ethtool_speed_to_yt921x() that the YT921x path also uses
- an early return for YT9224 in the shared yt921x_chip_detect(), which skips the CHIP_MODE, EXTMODE and SYS_CLK reads
- removed and reworded error messages in yt92xx_register_switch()
There is also a stray blank line added at the end of mdio_bus.c.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5
-0+static int +yt922x_port_up (struct yt921x_priv *priv,int port,unsigned int mode, +phy_interface_t interface,int speed,int duplex, +bool tx_pause,bool rx_pause) +{
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2681
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8
-0+/* +* Self-negotiation: the LINK/AN bits in ctrl are set based to inband. +* Forced mode: set LINK, keep the AN bit at 0 and clear it via the mask +*/ +if (pp->inband) + ctrl |= (YT922X_PORT_FC_AN |YT922X_PORT_LINK_AN ); +else + ctrl |=YT922X_PORT_LINK ;
[Severity: Medium]
Should YT922X_PORT_FC_AN depend on more than pp->inband?
pp->inband is set in yt922x_pcs_config() from:
bool inband = neg_mode & PHYLINK_PCS_NEG_INBAND;
That is true for both PHYLINK_PCS_NEG_INBAND_ENABLED and PHYLINK_PCS_NEG_INBAND_DISABLED, and permit_pause_to_mac is never looked at.
The SGMII and USXGMII control words don't carry pause bits. In those modes, would the MAC take pause from AN and ignore the tx_pause/rx_pause that phylink resolved from the PHY?
For 1000BASE-X/2500BASE-X with autoneg disabled, yt922x_pcs_config() clears BMCR_ANENABLE. The MAC is still told to take pause from AN, though, and that AN never runs.
The YT921x equivalent in yt921x_serdes_config() uses a narrower condition:
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED && permit_pause_to_mac && interface != PHY_INTERFACE_MODE_SGMII) ctrl |= YT921X_PORT_CTRL_PAUSE_AN;
Is something similar needed here?
[ ... ]
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +4
-0+static int +yt922x_port_config (struct yt921x_priv *priv,int port,unsigned int mode, +phy_interface_t interface) +{
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2745
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +7
-0+switch (interface) { +/* SERDES */ +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_100BASEX : +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : +case PHY_INTERFACE_MODE_USXGMII :
[Severity: High]
Can this hand phylink a PCS that has no ops? yt922x_pcs_setup() only fills in pp->pcs.ops for ports in info->serdes_mask, which on YT9224 is ports 0 and 8. For every other port priv->ports[port].pcs is left zeroed. yt922x_phylink_mac_select_pcs() still returns &priv->ports[dp->index].pcs for SGMII, 1000BASE-X, 2500BASE-X and USXGMII, without checking which port it is asked about.
Suppose the DT gives one of these phy-modes and a fixed-link to an internal PHY port (4-7) or to one of ports 1-3. phylink_create() still succeeds, because the fixed-link and initial validation paths do not treat the -EINVAL from phylink_validate() as fatal.
Then, on phylink_start():
- phylink_mac_initial_config() calls phylink_major_config()
- phylink_major_config() calls mac_select_pcs and gets back the
non-NULL pcs, whose pcs->ops is NULL
- phylink_pcs_neg_mode() dereferences pcs->ops through phylink_pcs_inband_caps(), and phylink_pcs_pre_config() does too
That oopses before yt922x_phylink_mac_config() gets a chance to reject the mode with its "Wrong mode" error.
The YT921x counterpart, yt921x_phylink_mac_select_pcs(), guards against exactly this:
if (!(BIT(port) & info->serdes_mask)) return NULL;
Should yt922x_phylink_mac_select_pcs() check BIT(dp->index) against priv->info->serdes_mask in the same way and return NULL otherwise?
[Severity: Low]
This isn't a bug, but is PHY_INTERFACE_MODE_100BASEX meant to be supported? yt922x_port_config() accepts it here. yt922x_pcs_config() maps it to YT922X_SERDES_MODE_100BASEX, and yt922x_pcs_get_state() has its own 100BASEX branch.
It is never advertised, though:
- yt922x_dsa_phylink_get_caps() leaves it out of
config->supported_interfaces
- yt922x_pcs_setup() leaves it out of pp->pcs.supported_interfaces
- yt922x_phylink_mac_select_pcs() returns NULL for it
So phylink validation rejects 100BASEX, and all of that handling is unreachable. If 100BASEX were later added to the caps without changing mac_select_pcs, mac_config would accept it with no PCS selected, and the SerDes mode would never be programmed.
For comparison, the YT921x path does list 100BASEX in its PCS supported_interfaces.
Should 100BASEX either be added to all four places or dropped from all of them?
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct yt92xx_series yt92xx_series_table[] = { · line 3079
Quoted 12 lines
drivers/net/dsa/motorcomm/chip.c +8
-0@@ -2586,12 +3069,25 @@ static const struct yt92xx_series yt92xx_series_table[] = { .switch_ops = &yt921x_dsa_switch_ops, .mac_ops = &yt921x_phylink_mac_ops }, + [YT92XX_MODE_YT922X] = { + .name = "YT922x", + .max_ports = YT922X_PORT_NUM, + .num_lag_ids = YT922X_LAG_NUM, + .ageing_time_min = 1 * 6000, + .ageing_time_max = U16_MAX * 6000, + .dscp_prio_mapping_is_global = true, + .assisted_learning_on_cpu_port = true,
[Severity: Low]
This isn't a bug, but are these flags intended for YT922x at this stage? yt922x_dsa_switch_ops has no FDB, LAG, bridge or DCB callbacks, yet the series entry sets num_lag_ids, dscp_prio_mapping_is_global and assisted_learning_on_cpu_port.
As far as I can tell nothing goes wrong at runtime. Without .port_bridge_join, dp->bridge stays NULL, and dsa_user_fdb_event() returns before it reads ds->assisted_learning_on_cpu_port:
if (!dp->bridge) return 0;
Even so, could these be left unset until the matching ops are added?
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +3
-0+ .switch_ops = &yt922x_dsa_switch_ops, + .mac_ops = &yt922x_phylink_mac_ops, + }, };
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 3213
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +1
-0@@ -2716,6 +3210,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)static const struct of_device_id yt921x_of_match[] = { { .compatible ="motorcomm,yt9215" }, + { .compatible ="motorcomm,yt9224" },
[Severity: Medium]
Does the binding need to be updated along with this? Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml still only allows:
compatible:
const: motorcomm,yt9215
As a result, any DTS that uses "motorcomm,yt9224" would fail dtbs_check, and checkpatch would warn that the compatible is undocumented.
The binding's text also describes a different layout from the new YT9224 yt921x_infos entry. It lists only YT9213/14/15/18 parts with GbE PHYs on ports 0-7 and GMACs on ports 8-9. Its mdio description says "PHY 0-7 are used for Port 0-7 respectively".
The new entry instead has internal PHYs on ports 4-7 (GENMASK(7, 4)), no xMII ports, SerDes on ports 0 and 8 (BIT(8) | BIT(0)), and nine ports in total.
Quoted 2 lines
drivers/net/dsa/motorcomm/chip.c +0
-0{} };
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +0
-0
[ ... ]
drivers/net/dsa/motorcomm/pcs-922x.c line 20
Quoted 8 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +8
-0+static int yt922x_sds_phyaddr_get (int port, +enum yt922x_phy_reg_type reg_type) +{ +if (reg_type ==YT922X_PHY_REG_TYPE_COMMON_EXT ) +return YT922X_COMMON_EXT_PHYADDR ; + +return port; +}
[Severity: Low]
Is YT922X_PHY_REG_TYPE_SDS_COMMON_EXT supposed to map to the plain port number? Only COMMON_EXT gets special handling, and no caller passes it. That leaves YT922X_COMMON_EXT_PHYADDR and the COMMON_EXT/EXT enum values unused.
yt922x_pcs_config() asks for SDS_COMMON_EXT and uses the per-port address it gets back for both YT922X_PCS_WRITE_PROTECT (0x4be) and YT922X_PORT_SDSn (0x400). YT922X_PORT_SDSn is named as a per-port register but takes no port index.
If those registers are actually in the shared common extended space, the SerDes mode would be written at the wrong MDIO address.
This helper also never returns a negative value, so the addr < 0 checks in all five PCS callbacks can't trigger, and nothing confirms that port is a SerDes port.
[ ... ]
Quoted 2 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +2
-0+static void yt922x_pcs_an_restart (struct phylink_pcs *pcs) +{
[ ... ]
drivers/net/dsa/motorcomm/pcs-922x.c line 110
Quoted 7 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +7
-0+mutex_lock (&priv->reg_lock); + res =yt921x_intif_read (priv, addr,MII_BMCR , &bmcr); +if (res) + goto err; + bmcr |=BMCR_ANRESTART ; + bmcr |=BMCR_RESET ; + res =yt921x_intif_write (priv, addr,MII_BMCR , bmcr);
[Severity: Medium]
Is BMCR_RESET intended here? Under clause 22, a reset puts the control and status registers back to their defaults. Nothing here waits for the self-clearing reset bit to clear, either.
yt922x_pcs_config() reports a change whenever BMCR_ANENABLE flips:
changed |= (bmcr_new != bmcr_old);
When pcs_config returns a positive value, phylink_major_config() calls the an_restart op right away:
phylink_major_config()
phylink_pcs_config() -> yt922x_pcs_config() returns 1 phylink_pcs_an_restart() -> yt922x_pcs_an_restart()
BMCR_RESET
Could that reset undo the ANENABLE setting and the MII_ADVERTISE word that pcs_config just wrote? One example is AN being re-enabled on an outband 2500BASE-X fixed-link CPU port.
With pcs.poll set, could the next yt922x_pcs_get_state() also read the PCS while it is still in reset?
The YT921x yt921x_serdes_config() does the reverse and clears changed when ANENABLE flips, because the PHY restarts negotiation by itself.
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +5
-0+static int yt922x_pcs_config (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac) +{
[ ... ]
drivers/net/dsa/motorcomm/pcs-922x.c line 149
Quoted 6 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +6
-0+mutex_lock (&priv->reg_lock); + +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,YT922X_PCS_WRITE_PROTECT ,0xd ); +if (res) + goto err;
[Severity: Low]
Should YT922X_PCS_WRITE_PROTECT be restored afterwards? 0xd is written here and never put back, on either the success path or the goto err paths. The write also comes before the interface switch, so the -EINVAL default case returns with the protection register already changed.
If 0xd unlocks the space, the SerDes extended registers stay writable from then on. If it locks the space, as the comment says, could the YT922X_PORT_SDSn write that follows be dropped by the hardware even though the driver records success?
Quoted 4 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +4
-0+switch (interface) { +case PHY_INTERFACE_MODE_SGMII : + ctrl =YT922X_SERDES_MODE_SGMII ; +break ;
[ ... ]
David Yang
maintainerRe: [PATCH net-next v17 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchQuoted 8 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +1
-2@@ -2608,15 +3104,13 @@ static int yt92xx_register_switch(struct dsa_switch *ds)mutex_lock (&priv->reg_lock); res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid);mutex_unlock (&priv->reg_lock); -if (res) { -dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +if (res)return res;
drivers/net/dsa/motorcomm/chip.c static int yt92xx_register_switch(struct dsa_switch *ds) · line 3116
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +1
-2- } major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); series =yt92xx_series_lookup (major);if (!series) { -dev_err (dev,"Undefined series info for the corresponding major\n" ); +dev_err (dev,"Chip ID: 0x%x, and Unknown major.\n" , chipid);return -ENODEV ; } priv->series = series;
You are fixing your own code in the same series. Is there any particular reason for this?