net: dsa: motorcomm: MIB fixup
David Yang
maintainercover net: dsa: motorcomm: MIB fixup
Fix (theoretical) MIB inconsistency. No new features are introduced.
David Yang (4):
net: dsa: motorcomm: Split MIB module
net: dsa: motorcomm: Split MIB buffers
net: dsa: motorcomm: Use u64_stats_t for MIB stats
net: dsa: motorcomm: Use safe 64-bit counter reader
drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 408 +++------------------------ drivers/net/dsa/motorcomm/chip.h | 126 +-------- drivers/net/dsa/motorcomm/mib.c | 430 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/mib.h | 167 +++++++++++ drivers/net/dsa/motorcomm/smi.c | 30 ++ drivers/net/dsa/motorcomm/smi.h | 2 + 7 files changed, 670 insertions(+), 494 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/mib.c create mode 100644 drivers/net/dsa/motorcomm/mib.h
Signature · 1 line
2.53.0
David Yang
maintainerPATCH 1/4 net: dsa: motorcomm: Split MIB module
yt922x is going to use a different MIB scheme, split it to reduce the length of chip.c.
--- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 366 +--------------------------- drivers/net/dsa/motorcomm/chip.h | 63 ----- drivers/net/dsa/motorcomm/mib.c | 373 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/mib.h | 98 ++++++++ 5 files changed, 474 insertions(+), 427 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/mib.c create mode 100644 drivers/net/dsa/motorcomm/mib.h
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -2,4 +2,5 @@ obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o +yt921x-objs += mib.o yt921x-objs += smi.o
drivers/net/dsa/motorcomm/chip.c +2 -364
392 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +0 -63
69 lines not on this page · raw message
drivers/net/dsa/motorcomm/mib.c new file +373 -0
373 lines not on this page · raw message
drivers/net/dsa/motorcomm/mib.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH 2/4 net: dsa: motorcomm: Split MIB buffers
In reply to David YangWith MIB improvement introduced later, struct yt921x_priv will be over 20k which is not very good for a single kmalloc(). Dynamically allocate the MIB structures to reduce the size of struct yt921x_priv, and do not waste memory on dummy ports.
--- drivers/net/dsa/motorcomm/chip.c | 42 +++++++++++++++---- drivers/net/dsa/motorcomm/chip.h | 63 ++-------------------------- drivers/net/dsa/motorcomm/mib.c | 70 ++++++++++++++++++++++++-------- drivers/net/dsa/motorcomm/mib.h | 61 ++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 86 deletions(-)
drivers/net/dsa/motorcomm/chip.c +33 -9
@@ -3591,11 +3591,14 @@ yt921x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, {struct dsa_port *dp =dsa_phylink_to_port (config);struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_mib *pm;int port = dp->index;int res;/* No need to sync; port control block is hold until device remove */ -cancel_delayed_work (&priv->ports[port].mib_read); + pm = priv->ports[port].mib; +if (pm) +cancel_delayed_work (&pm->work);mutex_lock (&priv->reg_lock); res =yt921x_port_down (priv, port);
@@ -3614,6 +3617,7 @@ yt921x_phylink_mac_link_up(struct phylink_config *config, {struct dsa_port *dp =dsa_phylink_to_port (config);struct yt921x_priv *priv =to_yt921x_priv (dp->ds); +struct yt921x_mib *pm;int port = dp->index;int res;
@@ -3626,7 +3630,9 @@ yt921x_phylink_mac_link_up(struct phylink_config *config,dev_err (dp->ds->dev,"Failed to %s port %d: %i\n" ,"bring up" , port, res); -schedule_delayed_work (&priv->ports[port].mib_read,0 ); + pm = priv->ports[port].mib; +if (pm) +schedule_delayed_work (&pm->work,0 ); } static void
@@ -3746,11 +3752,35 @@ yt921x_dsa_get_tag_protocol(struct dsa_switch *ds, int port,return DSA_TAG_PROTO_YT921X ; } +static void yt921x_dsa_port_teardown (struct dsa_switch *ds,int port) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_port *pp = &priv->ports[port]; +struct yt921x_mib *pm = pp->mib; + +if (pm) +disable_delayed_work_sync (&pm->work); +} +static int yt921x_dsa_port_setup (struct dsa_switch *ds,int port) {struct yt921x_priv *priv =to_yt921x_priv (ds); +struct yt921x_port *pp = &priv->ports[port]; +struct device *dev =to_device (priv); +struct yt921x_mib *pm = pp->mib;int res; +if (!pm && !(BIT (port) & (priv->info->internal_mask | + priv->info->external_mask))) { + pm =devm_kzalloc (dev,sizeof (*pm),GFP_KERNEL ); +if (!pm) +return -ENOMEM ; + pp->mib = pm; + + pm->port = pp; +INIT_DELAYED_WORK (&pm->work, yt921x_mib_poll); + } +mutex_lock (&priv->reg_lock); res =yt921x_port_setup (priv, port);mutex_unlock (&priv->reg_lock);
@@ -4305,6 +4335,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {/* port */ .get_tag_protocol = yt921x_dsa_get_tag_protocol, .phylink_get_caps = yt921x_dsa_phylink_get_caps, + .port_teardown = yt921x_dsa_port_teardown, .port_setup = yt921x_dsa_port_setup,#if IS_ENABLED (CONFIG_DCB )/* dscp */
@@ -4334,12 +4365,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++) {
@@ -4387,7 +4412,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)struct yt921x_port *pp = &priv->ports[i]; pp->index = i; -INIT_DELAYED_WORK (&pp->mib_read, yt921x_mib_poll); } ds = &priv->ds;
drivers/net/dsa/motorcomm/chip.h +4 -59
81 lines not on this page · raw message
drivers/net/dsa/motorcomm/mib.c +52 -18
150 lines not on this page · raw message
drivers/net/dsa/motorcomm/mib.h +61 -0
67 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH 3/4 net: dsa: motorcomm: Use u64_stats_t for MIB stats
In reply to David Yang64-bit variables might not be atomic on 32-bit architectures, and could lead to load/store tearing. Use u64_stats_t to ensure consistency.
--- drivers/net/dsa/motorcomm/chip.c | 2 + drivers/net/dsa/motorcomm/mib.c | 196 +++++++++++++++++-------------- drivers/net/dsa/motorcomm/mib.h | 110 +++++++++-------- 3 files changed, 172 insertions(+), 136 deletions(-)
drivers/net/dsa/motorcomm/chip.c +2 -0
@@ -19,6 +19,7 @@#include <linux/of_mdio.h> #include <linux/of_net.h> #include <linux/sort.h> +#include <linux/u64_stats_sync.h> #include <net/dsa.h> #include <net/dscp.h>
@@ -3778,6 +3779,7 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) pp->mib = pm; pm->port = pp; +u64_stats_init (&pm->syncp);INIT_DELAYED_WORK (&pm->work, yt921x_mib_poll); }
drivers/net/dsa/motorcomm/mib.c +111 -85
301 lines not on this page · raw message
drivers/net/dsa/motorcomm/mib.h +59 -51
129 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH 4/4 net: dsa: motorcomm: Use safe 64-bit counter reader
In reply to David Yang64-bit counter registers are read as two separate 32-bit transactions. If the low word wraps from about 0xffffffff to a small value while the high word increments between the two transactions, the recombined value becomes ((new_high << 32) | old_low), producing a spurious ~4 GiB jump.
Use a safe counter reader for this.
--- drivers/net/dsa/motorcomm/mib.c | 21 +++++++++------------ drivers/net/dsa/motorcomm/smi.c | 30 ++++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/smi.h | 2 ++ 3 files changed, 41 insertions(+), 12 deletions(-)
drivers/net/dsa/motorcomm/mib.c +9 -12
@@ -101,29 +101,26 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port)for (size_t i =0 ; i <ARRAY_SIZE (yt921x_mib_descs); i++) {const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i];u32 reg =YT921X_MIBn_DATA0 (port) + desc->offset; -u32 val0; -u64 val; - - res =yt921x_reg_read (priv, reg, &val0); -if (res) -break ;if (desc->size <=1 ) {u64 old_val = buf[i]; +u32 val0; +u64 val; + + res =yt921x_reg_read (priv, reg, &val0); +if (res) +break ; val = (old_val & ~(u64 )U32_MAX ) | val0;if (val < old_val) val +=1ull <<32 ; - }else { -u32 val1; - res =yt921x_reg_read (priv, reg +4 , &val1); + buf[i] = val; + }else { + res =yt921x_counter_read (priv, reg, &buf[i]);if (res)break ; - val = ((u64 )val1 <<32 ) | val0; } - - buf[i] = val; }u64_stats_update_begin (&pm->syncp);
drivers/net/dsa/motorcomm/smi.c +30 -0
@@ -63,6 +63,36 @@ int yt921x_reg_update_bits(struct yt921x_priv *priv, u32 reg, u32 mask, u32 val)return yt921x_reg_write (priv, reg, u); } +/* Reliably read a 64bit counter */ +int yt921x_counter_read (struct yt921x_priv *priv,u32 reg,u64 *valp) +{ +u32 old_lo; +int res; +u32 hi; +u32 lo; + + res =yt921x_reg_read (priv, reg, &old_lo); +if (res) +return res; + +for (int i =0 ; i <16 ; i++) { + res =yt921x_reg_read (priv, reg +4 , &hi); +if (res) +return res; + res =yt921x_reg_read (priv, reg, &lo); +if (res) +return res; + +if (lo >= old_lo) { + *valp = ((u64 )hi <<32 ) | lo; +return 0 ; + } + old_lo = lo; + } + +return -ETIMEDOUT ; +} +static int yt921x_regs_read (struct yt921x_priv *priv,u32 reg,u32 *vals,unsigned int num_regs)
drivers/net/dsa/motorcomm/smi.h +2 -0
@@ -35,6 +35,8 @@ yt921x_reg_toggle_bits(struct yt921x_priv *priv, u32 reg, u32 mask, bool set)return yt921x_reg_update_bits (priv, reg, mask, !set ?0 : mask); } +int yt921x_counter_read (struct yt921x_priv *priv,u32 reg,u64 *valp); +/* Some multi-word registers, like VLANn_CTRL, should be treated as a single * long register. More specifically, writes to parts of its words won't become * visible, until the last word is written.
Signature · 1 line
2.53.0
Andrew Lunn
maintainerRe: [PATCH net-next 1/4] net: dsa: motorcomm: Split MIB module
In reply to David Yangdrivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4390
Quoted 6 lines · David Yang
yt922x is going to use a different MIB scheme, split it to reduce the length of
chip.c.drivers/net/dsa/motorcomm/chip.c +1
-1pp->index = i; -INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); +INIT_DELAYED_WORK (&pp->mib_read, yt921x_mib_poll);
This suggests the change is not purely moving code around, but also a rename? I then ask myself, do i need to review the code in detail?
Please try to make patches which move code only move code. Then add patches which do renames.
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerRe: [PATCH net-next 2/4] net: dsa: motorcomm: Split MIB buffers
In reply to David YangQuoted 4 lines · David Yang
With MIB improvement introduced later, struct
yt921x_privwill be over 20k which is not very good for a singlekmalloc(). Dynamically allocate the MIB structures to reduce the size of structyt921x_priv, and do not waste memory on dummy ports.
When you read this....
drivers/net/dsa/motorcomm/chip.h enum yt921x_fdb_entry_status {
Quoted 13 lines
drivers/net/dsa/motorcomm/chip.h +5
-6-struct yt921x_mib { -u64 rx_broadcast; -u64 rx_pause; -u64 rx_multicast; -u64 rx_crc_errors; - +struct yt921x_mib_stats { +u64 rx_broadcast; +u64 rx_pause; +u64 rx_multicast; +u64 rx_crc_errors;
It does not explain "Why?" this structure got renamed.
drivers/net/dsa/motorcomm/mib.h line 133
Quoted 8 lines
drivers/net/dsa/motorcomm/mib.h +8
-0+struct yt921x_mib { +struct yt921x_port *port; + +struct delayed_work work; +struct yt921x_mib_stats stats; +u64 rx_frames; +u64 tx_frames; +};
And the old structure gets new contents.
I find this confusing, and not easy to review.
Maybe avoid the rename, and call this new structure something else?
Maybe break this up into a number of patches, do things one step at a time, making it easier to review, lots of small changes which are obviously correct?
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 3/4] net: dsa: motorcomm: Use u64_stats_t for MIB stats
In reply to David YangQuoted 2 lines · David Yang
64-bit variables might not be atomic on 32-bit architectures, and could lead to load/store tearing. Use
u64_stats_tto ensure consistency.
Can this patch also be broken up. It should be possible to use u64_stats_read() without changing the locking? So one patch which only does u64_stats_read(). You should then be able to add the syncp code. And lastly the mutex changes. That then allows you to explain why the mutex changes are safe in the commit message.
Andrew
David Yang
maintainerRe: [PATCH net-next 3/4] net: dsa: motorcomm: Use u64_stats_t for MIB stats
Quoted 5 lines · Andrew Lunn
Quoted 2 lines · David Yang
64-bit variables might not be atomic on 32-bit architectures, and could lead to load/store tearing. Use
u64_stats_tto ensure consistency.
Quoted 7 lines
Can this patch also be broken up. It should be possible to use
u64_stats_read()without changing the locking? So one patch which only doesu64_stats_read(). You should then be able to add the syncp code. And lastly the mutex changes. That then allows you to explain why the mutex changes are safe in the commit message.Andrew
u64_stats_read are meant to be used with syncp. This sounds like an incorrect partial patch, works only because of the internal implementation of u64_stats_t.
Andrew Lunn
maintainerRe: [PATCH net-next 3/4] net: dsa: motorcomm: Use u64_stats_t for MIB stats
Quoted 12 lines · David Yang
Quoted 11 lines · Andrew Lunn
Quoted 2 lines · David Yang
64-bit variables might not be atomic on 32-bit architectures, and could lead to load/store tearing. Use
u64_stats_tto ensure consistency.Can this patch also be broken up. It should be possible to use
u64_stats_read()without changing the locking? So one patch which only doesu64_stats_read(). You should then be able to add the syncp code. And lastly the mutex changes. That then allows you to explain why the mutex changes are safe in the commit message.
Quoted 5 lines
Quoted 1 line
Andrew
u64_stats_readare meant to be used with syncp. This sounds like an incorrect partial patch, works only because of the internal implementation ofu64_stats_t.
What is making the current code correct? The mutex? So long as you have the mutex, the code is still correct?
You can say in the commit message this is an intermediary step doing the mechanical work of introducing u64_stats_t. The following patches will then change the locking to be more efficient.
Andrew