[RFC PATCH net-next 4/4] net: dsa: b53: express b53_for_each_port in terms of dsa_switch_for_each_port
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: 2021-08-09 19:03:54
Subsystem:
broadcom b53/sf2 ethernet switch driver, networking drivers, networking [dsa], the rest · Maintainers:
Florian Fainelli, Jonas Gorski, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn, Vladimir Oltean, Linus Torvalds
Merging the two allows us to remove the open-coded "dev->enabled_ports & BIT(i)" check from b53_br_join and b53_br_leave, while still avoiding a quadratic iteration through the switch's ports. Sadly I don't know if it's possible to completely get rid of b53_for_each_port and replace it with dsa_switch_for_each_available_port, especially for the platforms that use pdata and not OF bindings. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> --- drivers/net/dsa/b53/b53_common.c | 20 ++++++++++---------- drivers/net/dsa/b53/b53_priv.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index ccd93147d994..5351d1f65ed9 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c@@ -498,6 +498,7 @@ static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) { struct b53_device *dev = ds->priv; + struct dsa_port *dp; unsigned int i; u16 pvlan;
@@ -505,7 +506,9 @@ void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) * on a per-port basis such that we only have Port i and IMP in * the same VLAN. */ - b53_for_each_port(dev, i) { + b53_for_each_port(dp, dev) { + i = dp->index; + b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); pvlan |= BIT(cpu_port); b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
@@ -739,6 +742,7 @@ int b53_configure_vlan(struct dsa_switch *ds) { struct b53_device *dev = ds->priv; struct b53_vlan vl = { 0 }; + struct dsa_port *dp; struct b53_vlan *v; int i, def_vid; u16 vid;
@@ -761,7 +765,9 @@ int b53_configure_vlan(struct dsa_switch *ds) * entry. Do this only when the tagging protocol is not * DSA_TAG_PROTO_NONE */ - b53_for_each_port(dev, i) { + b53_for_each_port(dp, dev) { + i = dp->index; + v = &dev->vlans[def_vid]; v->members |= BIT(i); if (!b53_vlan_port_needs_forced_tagged(ds, i))
@@ -1874,12 +1880,9 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); - dsa_switch_for_each_port(dp, ds) { + b53_for_each_port(dp, dev) { i = dp->index; - if (!(dev->enabled_ports & BIT(i))) - continue; - if (dp->bridge_dev != br) continue;
@@ -1915,12 +1918,9 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); - dsa_switch_for_each_port(dp, ds) { + b53_for_each_port(dp, dev) { i = dp->index; - if (!(dev->enabled_ports & BIT(i))) - continue; - /* Don't touch the remaining ports */ if (dp->bridge_dev != br) continue;
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index 9bf8319342b0..aec4b1176be9 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h@@ -145,10 +145,10 @@ struct b53_device { struct b53_port *ports; }; -#define b53_for_each_port(dev, i) \ - for (i = 0; i < B53_N_PORTS; i++) \ - if (dev->enabled_ports & BIT(i)) +#define b53_for_each_port(_dp, _dev) \ + dsa_switch_for_each_port((_dp), (_dev)->ds) \ + if ((_dev)->enabled_ports & BIT((_dp)->index)) static inline int is5325(struct b53_device *dev) {
--
2.25.1