net: dsa: motorcomm: add support yt922x driver
v6 cover net: dsa: motorcomm: add support yt922x driver
This patch series adds support for Motorcomm YT9224 dsa driver. The YT9224 is a member of the YT922x family, featuring a flexible port configuration with four 2.5G UTP and two serdes.
changes in v6:
patch 1: remove compatible info and fix variable naming issues. patch 4: move mib stop from remove() to teardown() patch 5: modify the way dst port is filled in the tag to handle multi-port scenario.
Kyle Switch (6):
net: dsa: motorcomm: initialize dsa_switch based on chipid
net: dsa: motorcomm: use max_ports in series for port bounds checking
net: dsa: motorcomm: move mib start from probe() to dsa_setup()
net: dsa: motorcomm: move mib stop from remove() to teardown()
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x
drivers/net/dsa/motorcomm/Kconfig | 1 + drivers/net/dsa/motorcomm/chip.c | 968 +++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 123 ++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 ++++ 7 files changed, 1183 insertions(+), 29 deletions(-) create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
PATCH v6 1/6 net: dsa: motorcomm: initialize dsa_switch based on chipid
Introduce yt92xx_series structure to hold private data for different switch families, replacing hardcoded logic in probe(). This makes the driver more extensible for future switch support.
--- drivers/net/dsa/motorcomm/chip.c | 81 +++++++++++++++++++++++++++----- drivers/net/dsa/motorcomm/chip.h | 20 ++++++++ 2 files changed, 90 insertions(+), 11 deletions(-)
drivers/net/dsa/motorcomm/chip.c +70 -11
@@ -4679,6 +4679,68 @@ 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 ] = { + .mode =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) +{ +enum yt92xx_mode mode =YT92XX_MODE_MAX ; +int i; + +if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) + mode =YT92XX_MODE_YT921X ; + +for (i =0 ; i <ARRAY_SIZE (yt92xx_series_table); ++i) +if (yt92xx_series_table[i].mode == mode) +return &yt92xx_series_table[i]; + +return NULL ; +} + +static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; + + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +if (res) +return res; + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) +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);
@@ -4727,6 +4789,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)
@@ -4754,15 +4817,9 @@ 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);
@@ -4770,8 +4827,10 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) }static const struct of_device_id yt921x_of_match[] = { - { .compatible ="motorcomm,yt9215" }, - {} + { + .compatible ="motorcomm,yt9215" , + }, + {/* sentinel */ } };MODULE_DEVICE_TABLE (of, yt921x_of_match);
drivers/net/dsa/motorcomm/chip.h +20 -0
@@ -960,9 +960,29 @@ struct yt921x_reg_ops {int (*write)(void *context,u32 reg,u32 val); }; +enum yt92xx_mode { +YT92XX_MODE_YT921X , +YT92XX_MODE_YT922X , +YT92XX_MODE_MAX , +}; + +struct yt92xx_series { +enum yt92xx_mode mode; +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
David Yang
maintainerRe: [PATCH net-next v6 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4707
Quoted 6 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +6
-0+if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) + mode =YT92XX_MODE_YT921X ; + +for (i =0 ; i <ARRAY_SIZE (yt92xx_series_table); ++i) +if (yt92xx_series_table[i].mode == mode) +return &yt92xx_series_table[i];
Still redundant lookups here.
Quoted 1 line
-
ds->priv= priv;
ds->priv is gone in the new register.
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4833
Quoted 7 lines
static const struct
of_device_idyt921x_of_match[] = {drivers/net/dsa/motorcomm/chip.c +4
-2- { .compatible = "motorcomm,yt9215" }, - {} + { + .compatible = "motorcomm,yt9215", + }, + {/* sentinel */ }
Leftovers.
Re: [PATCH net-next v6 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
Quoted 8 lines · David Yang
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4707
Quoted 6 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +6
-0+if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) + mode =YT92XX_MODE_YT921X ; + +for (i =0 ; i <ARRAY_SIZE (yt92xx_series_table); ++i) +if (yt92xx_series_table[i].mode == mode) +return &yt92xx_series_table[i];Still redundant lookups here.
Ans: will be fixed in next patch.
Quoted 2 lines
Quoted 1 line
-
ds->priv= priv;
ds->privis gone in the new register.
Ans: will be fixed in next version.
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4833
Quoted 7 lines
static const struct of_device_id yt921x_of_match[] = {drivers/net/dsa/motorcomm/chip.c +4
-2- { .compatible = "motorcomm,yt9215" }, - {} + { + .compatible = "motorcomm,yt9215", + }, + {/* sentinel */ }Leftovers.
Ans: will be fixed in next version
PATCH v6 2/6 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/chip.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/chip.c +5 -3
@@ -357,7 +357,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);
@@ -375,7 +375,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);
@@ -390,6 +390,7 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) {struct device *dev =to_device (priv);struct mii_bus *mbus; +u32 max_ports;int res; mbus =devm_mdiobus_alloc (dev);
@@ -402,7 +403,8 @@ 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 v6 3/6 net: dsa: motorcomm: move mib start from probe() to dsa_setup()
In reply to Kyle SwitchMove MIB polling start from probe() to dsa_setup().so that it can be enabled based on the actual switch family support.
--- drivers/net/dsa/motorcomm/chip.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/dsa/motorcomm/chip.c +8 -7
@@ -4553,6 +4553,14 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)struct device_node *child;int res; +/* mib polling init */ +for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { +struct yt921x_port *pp = &priv->ports[i]; + + pp->index = i; +INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); + } +mutex_lock (&priv->reg_lock); res =yt921x_chip_reset (priv);mutex_unlock (&priv->reg_lock);
@@ -4810,13 +4818,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) priv->reg_ops = &yt921x_reg_ops_mdio; priv->reg_ctx = mdio; -for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { -struct yt921x_port *pp = &priv->ports[i]; - - pp->index = i; -INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); - } - ds = &priv->ds; ds->dev = dev; res =yt92xx_register_switch (ds);
Signature · 1 line
2.25.1
PATCH v6 4/6 net: dsa: motorcomm: move mib stop from remove() to teardown()
In reply to Kyle SwitchThis change ensures symmetry with the MIB start operation, which is already invoked in the setup(). Additionally, it consolidates per-switch operation into the appropriate DSA ops, improving code organization and maintainability.
--- drivers/net/dsa/motorcomm/chip.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/dsa/motorcomm/chip.c +5 -6
@@ -4233,6 +4233,11 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds)#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS )yt921x_leds_remove (priv);#endif +for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) { +struct yt921x_port *pp = &priv->ports[i]; + +disable_delayed_work_sync (&pp->mib_read); + } }static int yt921x_chip_detect (struct yt921x_priv *priv)
@@ -4768,12 +4773,6 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; -for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) { -struct yt921x_port *pp = &priv->ports[i]; - -disable_delayed_work_sync (&pp->mib_read); - } -dsa_unregister_switch (&priv->ds);for (unsigned int i =0 ; i <ARRAY_SIZE (priv->acl_blks); i++) {
Signature · 1 line
2.25.1
PATCH v6 5/6 net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
In reply to Kyle SwitchAdd support for Motorcomm YT922x tags with 8bytes. which includes ethertype field (default to 0x9988).
--- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 net/dsa/tag_yt922x.c
include/net/dsa.h +2 -0
@@ -61,6 +61,7 @@ struct tc_action;#define DSA_TAG_PROTO_NETC_VALUE 33#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35 +#define DSA_TAG_PROTO_YT922X_VALUE 36enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -99,6 +100,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE ,DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -227,4 +227,10 @@ config NET_DSA_TAG_YT921X Say Y or M if you want to enable support for tagging frames for Motorcomm YT921x switches. +config NET_DSA_TAG_YT922X + tristate "Tag driver for Motorcomm YT922x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT922x switches. + endif
net/dsa/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o +obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 6/6 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 adds basic support for a working DSA switch.
--- drivers/net/dsa/motorcomm/Kconfig | 1 + drivers/net/dsa/motorcomm/chip.c | 853 +++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 103 ++++ 3 files changed, 955 insertions(+), 2 deletions(-)
drivers/net/dsa/motorcomm/Kconfig +1 -0
@@ -2,6 +2,7 @@ config NET_DSA_YT921X tristate "Motorcomm YT9215 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
drivers/net/dsa/motorcomm/chip.c +851 -2
901 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +103 -0
133 lines not on this page · raw message
Signature · 1 line
2.25.1
David Yang
maintainerRe: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 7 lines · Kyle Switch
config
NET_DSA_YT921X
tristate "Motorcomm YT9215 ethernet switch chip support" selectNET_DSA_TAG_YT921X
+ selectNET_DSA_TAG_YT922X
selectNET_IEEE8021Q_HELPERSif DCB
help
This enables support for the Motorcomm YT9215 ethernet switch
Not sure, but might be better with NET_DSA_TAG_YT921X || NET_DSA_TAG_YT922X if that does not cause an error.
Quoted 157 lines
drivers/net/dsa/motorcomm/chip.c +157
-0+/** +* Initialize serdes configuration based on interface mode. +*/ +static int yt922x_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + } +/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x43d ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43c ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3032 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x6 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + } +/* VCO */ + res =yt921x_intif_ext_write (priv, addr,0x439 ,0xC0 ); +if (res) +return res; +/* Vdac */ + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x491 ,0x7f ); +if (res) +return res; +/* Eye */ + res =yt921x_intif_ext_write (priv, addr,0x454 ,0xf14 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x497 ,0xa44 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4cd ,0x0 ); +if (res) +return res; + + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e3 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x48a ,0xfff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x408 ,0x7c00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4d6 ,0x7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x44f ,0xff08 ); +if (res) +return res; +/* FFE */ + res =yt921x_intif_ext_write (priv, addr,0x48e ,0x7d00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0xd ,0x60f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x4b0 ,0x804 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4b1 ,0x7774 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e7 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x3 ,0x5603 ); +if (res) +return res; + +msleep (20 ); + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7fff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x40 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x0 ); +if (res) +return res; + +if (interface ==PHY_INTERFACE_MODE_SGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x1042 ,0x48c ); +if (res) +return res; + } +/* soft reset */ + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_USXGMII ); +if (addr <0 ) +return res;
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5058
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + +return 0 ; +}
No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
Quoted 18 lines
drivers/net/dsa/motorcomm/chip.c +18
-0+static void +yt922x_dsa_phylink_get_caps (struct dsa_switch *ds,int port, +struct phylink_config *config) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +const struct yt921x_info *info = priv->info; + + config->mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ; + +if (info->internal_mask &BIT (port)) { +if (port >=4 && port <=7 ) { +/* port 4 to port 7, internal utp */ +__set_bit (PHY_INTERFACE_MODE_INTERNAL , + config->supported_interfaces); + config->mac_capabilities |=MAC_2500FD ; + }else { + __set_bit(PHY_INTERFACE_MODE_SGMII,
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5252
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ config->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_100BASEX , + config->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_1000BASEX , + config->supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_2500BASEX , + config->supported_interfaces); + config->mac_capabilities |=MAC_2500FD ; +__set_bit (PHY_INTERFACE_MODE_USXGMII , + config->supported_interfaces);
By definition internal_mask is PHY_INTERFACE_MODE_INTERNAL only. Move other modes into external_mask.
Quoted 1 line
+
config->mac_capabilities|=MAC_2500FD;
Duplicated config->mac_capabilities |= MAC_2500FD;
Quoted 50 lines
drivers/net/dsa/motorcomm/chip.c +50
-0+static int yt922x_chip_detect (struct yt921x_priv *priv) +{ +struct device *dev =to_device (priv); +const struct yt921x_info *info; +u32 chipid; +u32 major; +int res; + + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +if (res) +return res; + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); +for (info = yt921x_infos; info->name; info++) +if (info->major == major) +break ; +if (!info->name) { +dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +return -ENODEV ; + } + priv->info = info; + +return 0 ; +} + +static int yt922x_chip_reset (struct yt921x_priv *priv) +{ +struct device *dev =to_device (priv); +u16 eth_p_tag; +u32 val; +int res; + + res =yt922x_chip_detect (priv); +if (res) +return res; + +/* Reset */ + res =yt921x_reg_write (priv,YT921X_RST ,YT921X_RST_HW ); +if (res) +return res; + +fsleep (YT921X_RST_DELAY_US ); + + val =0 ; + res =yt921x_reg_wait (priv,YT921X_RST , ~0 , &val); +if (res) +return res; + +/* TPID check */ + res =yt921x_reg_read (priv,YT921X_CPU_TAG_TPID , &val); +if (res)
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5362
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+return res; + eth_p_tag =FIELD_GET (YT921X_CPU_TAG_TPID_TPID_M , val); +if (eth_p_tag !=ETH_P_YT921X ) { +dev_err (dev,"Tag type 0x%x != 0x%x\n" , eth_p_tag, +ETH_P_YT921X ); +return -EINVAL ; + } + +return 0 ; +}
Isn't it just yt921x_chip_reset? Please reuse existing functions.
Quoted 17 lines
drivers/net/dsa/motorcomm/chip.c +17
-0+static int yt922x_cpu_port_set (struct yt921x_priv *priv) +{ +struct dsa_switch *ds = &priv->ds; +u32 ctrl; +int res; + +/* cpu tag mode */ + res =yt922x_cpu_tag_mode_set_8b (priv); +if (res) +return res; + +/* Enable DSA */ + priv->cpu_ports_mask =dsa_cpu_ports (ds); + ctrl =YT921X_EXT_CPU_PORT_TAG_EN |YT921X_EXT_CPU_PORT_PORT_EN | +YT921X_EXT_CPU_PORT_PORT (__ffs (priv->cpu_ports_mask)); + res =yt921x_reg_write (priv,YT921X_EXT_CPU_PORT , ctrl); +if (res)
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5463
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+return res; + +/* Setup software switch */ + ctrl =YT922X_CPU_COPY_TO_EXT_CPU ; + res =yt921x_reg_write (priv,YT922X_CPU_COPY , ctrl); +if (res) +return res; + +return res; +}
Move this into chip_setup_dsa() to align with existing yt921x functions.
drivers/net/dsa/motorcomm/chip.h struct yt921x_priv { · line 1113
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.h +2
-0@@ -1007,6 +1108,8 @@ struct yt921x_priv {u8 acl_masks[YT921X_ACL_BLK_NUM ];struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM ]; +struct yt922x_pcs pcs_port_0; +struct yt922x_pcs pcs_port_8; };
More reasonable if pre-port "struct phylink_pcs yt921x_port::pcs".
Andrew Lunn
maintainerRe: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 162 lines
Quoted 162 lines
drivers/net/dsa/motorcomm/chip.c +162
-0+/** +* Initialize serdes configuration based on interface mode. +*/ +static int yt922x_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + } +/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x43d ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43c ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3032 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x6 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + } +/* VCO */ + res =yt921x_intif_ext_write (priv, addr,0x439 ,0xC0 ); +if (res) +return res; +/* Vdac */ + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x491 ,0x7f ); +if (res) +return res; +/* Eye */ + res =yt921x_intif_ext_write (priv, addr,0x454 ,0xf14 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x497 ,0xa44 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4cd ,0x0 ); +if (res) +return res; + + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e3 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x48a ,0xfff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x408 ,0x7c00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4d6 ,0x7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x44f ,0xff08 ); +if (res) +return res; +/* FFE */ + res =yt921x_intif_ext_write (priv, addr,0x48e ,0x7d00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0xd ,0x60f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x4b0 ,0x804 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4b1 ,0x7774 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e7 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x3 ,0x5603 ); +if (res) +return res; + +msleep (20 ); + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7fff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x40 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x0 ); +if (res) +return res; + +if (interface ==PHY_INTERFACE_MODE_SGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x1042 ,0x48c ); +if (res) +return res; + } +/* soft reset */ + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_USXGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data);
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4732
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5
-0+if (res) +return res; + +return 0 ; +}No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
There also appears to be similar magic in the PHY driver. Can this be consolidated?
Andrew
Re: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 169 lines · Andrew Lunn
Quoted 161 lines
Quoted 161 lines
drivers/net/dsa/motorcomm/chip.c +161
-0+/** +* Initialize serdes configuration based on interface mode. +*/ +static int yt922x_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + } +/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x43d ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43c ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3032 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x6 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + } +/* VCO */ + res =yt921x_intif_ext_write (priv, addr,0x439 ,0xC0 ); +if (res) +return res; +/* Vdac */ + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x491 ,0x7f ); +if (res) +return res; +/* Eye */ + res =yt921x_intif_ext_write (priv, addr,0x454 ,0xf14 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x497 ,0xa44 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4cd ,0x0 ); +if (res) +return res; + + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e3 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x48a ,0xfff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x408 ,0x7c00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4d6 ,0x7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x44f ,0xff08 ); +if (res) +return res; +/* FFE */ + res =yt921x_intif_ext_write (priv, addr,0x48e ,0x7d00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0xd ,0x60f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x4b0 ,0x804 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4b1 ,0x7774 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e7 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x3 ,0x5603 ); +if (res) +return res; + +msleep (20 ); + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7fff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x40 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x0 ); +if (res) +return res; + +if (interface ==PHY_INTERFACE_MODE_SGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x1042 ,0x48c ); +if (res) +return res; + } +/* soft reset */ + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_USXGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ;Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5058
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +6
-0+ res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + +return 0 ; +}No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
Quoted 2 lines
There also appears to be similar magic in the PHY driver. Can this be consolidated?
Ans: This part of the initialization is for the switch SerDes, so from my
side it may be hard to consolidate.As mentioned in David's email,
if we're not considering switch SerDes performance for now and are
only concerned with DSA driver functionality, we can temporarily
remove this part of the initialization configuration.
Quoted 1 line
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
There also appears to be similar magic in the PHY driver. Can this be consolidated?
Ans: This part of the initialization is for the switch SerDes, so from my
side it may be hard to consolidate.
Is it the same IP? Same configuration? Or totally different?
Andrew
Re: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 8 lines · Andrew Lunn
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
There also appears to be similar magic in the PHY driver. Can this be consolidated?
Ans: This part of the initialization is for the switch SerDes, so from my
side it may be hard to consolidate.
Is it the same IP? Same configuration? Or totally different?
Ans: They are the same IP, but there are the following differences:
1. phy8824 only supports usxgmii_multiport mode.
yt922x has 4utp+2serdes. These two serdes support more modes,
such as usxgmii_singleport, bx1000, sgmii, etc., which results in more
initialization configurations for the switch serdes.
2. Another point that I think is difficult to integrate is that the phyID
of the switch serdes (defined in USXGMII reg space mii 0x2, 0x3) is
inconsistent with the phyID of phy8824 (defined in UTP reg space mii 0x2, 0x3),
so phy8824 cannot be matched, and therefore two sets of initialization
configurations are required.
Quoted 1 line
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next v6 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 14 lines · Kyle Switch
Quoted 8 lines · Andrew Lunn
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No one else, except you, can maintain this stuff. Drop it for now and discuss it later.
There also appears to be similar magic in the PHY driver. Can this be consolidated?
Ans: This part of the initialization is for the switch SerDes, so from my
side it may be hard to consolidate.
Is it the same IP? Same configuration? Or totally different?
Ans: They are the same IP, but there are the following differences:
2. Another point that I think is difficult to integrate is that the phyID
Quoted 8 lines
of the switch serdes (defined in USXGMII reg space mii
0x2,0x3) isinconsistent with the phyID of phy8824 (defined in UTP reg space mii
0x2,0x3),so phy8824 cannot be matched, and therefore two sets of initialization
configurations are required.
Having different IDs is good, because they are different, as you pointed out. But the shared USXGMII part should really be shared.
For the switch you are going to write a PCS driver, which might live in drivers/net/pcs. You can split that into a library for the usxgmii and a driver wrapped around it. The PHY driver can also use the library.
Does the switch have the same horrible paging design? I really hope that is changed in the next generation of the IP.
Andrew