Commit 0493fa79 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: dsa: mv88e6xxx: iterate using dsa_switch_for_each_user_port in mv88e6xxx_port_check_hw_vlan

Avoid a plethora of dsa_to_port() calls (some hidden behind
dsa_is_*_port and some in plain sight) by keeping two struct dsa_port
references: one to the port passed as argument, and another to the other
ports of the switch that we're iterating over.

This isn't called from the DSA initialization path, so there is no risk
that we have user ports without a dp->slave populated. So the combined
checks that a port isn't a DSA port, a CPU port, or doesn't have a slave
net device (therefore is unused), are strictly equivalent to the simple
check that the port is a user port. This is already handled by the DSA
iterator.

i gets replaced by other_dp->index, dsa_is_*_port calls get replaced by
dsa_port_is_*, and dsa_to_port gets replaced by the respective pointer
directly.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 872bb81d
...@@ -1647,12 +1647,13 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) ...@@ -1647,12 +1647,13 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
u16 vid) u16 vid)
{ {
struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
struct mv88e6xxx_vtu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int i, err; int err;
/* DSA and CPU ports have to be members of multiple vlans */ /* DSA and CPU ports have to be members of multiple vlans */
if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp))
return 0; return 0;
err = mv88e6xxx_vtu_get(chip, vid, &vlan); err = mv88e6xxx_vtu_get(chip, vid, &vlan);
...@@ -1662,27 +1663,20 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ...@@ -1662,27 +1663,20 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
if (!vlan.valid) if (!vlan.valid)
return 0; return 0;
for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) { dsa_switch_for_each_user_port(other_dp, ds) {
if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) if (vlan.member[other_dp->index] ==
continue;
if (!dsa_to_port(ds, i)->slave)
continue;
if (vlan.member[i] ==
MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
continue; continue;
if (dsa_to_port(ds, i)->bridge_dev == if (dp->bridge_dev == other_dp->bridge_dev)
dsa_to_port(ds, port)->bridge_dev)
break; /* same bridge, check next VLAN */ break; /* same bridge, check next VLAN */
if (!dsa_to_port(ds, i)->bridge_dev) if (!other_dp->bridge_dev)
continue; continue;
dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n", dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
port, vlan.vid, i, port, vlan.vid, other_dp->index,
netdev_name(dsa_to_port(ds, i)->bridge_dev)); netdev_name(other_dp->bridge_dev));
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment