Commit e2b2e83e authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: mscc: ocelot: add a "valid" boolean to struct ocelot_vlan

Currently we are checking in some places whether the port has a native
VLAN on egress or not, by comparing the ocelot_port->vid value with zero.

That works, because VID 0 can never be a native VLAN configured by the
bridge, but now we want to make similar checks for the pvid. That won't
work, because there are cases when we do have the pvid set to 0 (not by
the bridge, by ourselves, but still.. it's confusing). And we can't
encode a negative value into an u16, so add a bool to the structure.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c3e58a75
...@@ -153,22 +153,22 @@ static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port, ...@@ -153,22 +153,22 @@ static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
struct ocelot_port *ocelot_port = ocelot->ports[port]; struct ocelot_port *ocelot_port = ocelot->ports[port];
u32 val = 0; u32 val = 0;
if (ocelot_port->native_vlan.vid != native_vlan.vid) { /* Deny changing the native VLAN, but always permit deleting it */
/* Always permit deleting the native VLAN (vid = 0) */ if (ocelot_port->native_vlan.vid != native_vlan.vid &&
if (ocelot_port->native_vlan.vid && native_vlan.vid) { ocelot_port->native_vlan.valid && native_vlan.valid) {
dev_err(ocelot->dev, dev_err(ocelot->dev,
"Port already has a native VLAN: %d\n", "Port already has a native VLAN: %d\n",
ocelot_port->native_vlan.vid); ocelot_port->native_vlan.vid);
return -EBUSY; return -EBUSY;
}
ocelot_port->native_vlan = native_vlan;
} }
ocelot_port->native_vlan = native_vlan;
ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(native_vlan.vid), ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(native_vlan.vid),
REW_PORT_VLAN_CFG_PORT_VID_M, REW_PORT_VLAN_CFG_PORT_VID_M,
REW_PORT_VLAN_CFG, port); REW_PORT_VLAN_CFG, port);
if (ocelot_port->vlan_aware && !ocelot_port->native_vlan.vid) if (ocelot_port->vlan_aware && !ocelot_port->native_vlan.valid)
/* If port is vlan-aware and tagged, drop untagged and priority /* If port is vlan-aware and tagged, drop untagged and priority
* tagged frames. * tagged frames.
*/ */
...@@ -182,7 +182,7 @@ static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port, ...@@ -182,7 +182,7 @@ static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
ANA_PORT_DROP_CFG, port); ANA_PORT_DROP_CFG, port);
if (ocelot_port->vlan_aware) { if (ocelot_port->vlan_aware) {
if (ocelot_port->native_vlan.vid) if (native_vlan.valid)
/* Tag all frames except when VID == DEFAULT_VLAN */ /* Tag all frames except when VID == DEFAULT_VLAN */
val = REW_TAG_CFG_TAG_CFG(1); val = REW_TAG_CFG_TAG_CFG(1);
else else
...@@ -273,6 +273,7 @@ int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, ...@@ -273,6 +273,7 @@ int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
struct ocelot_vlan pvid_vlan; struct ocelot_vlan pvid_vlan;
pvid_vlan.vid = vid; pvid_vlan.vid = vid;
pvid_vlan.valid = true;
ocelot_port_set_pvid(ocelot, port, pvid_vlan); ocelot_port_set_pvid(ocelot, port, pvid_vlan);
} }
...@@ -281,6 +282,7 @@ int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, ...@@ -281,6 +282,7 @@ int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
struct ocelot_vlan native_vlan; struct ocelot_vlan native_vlan;
native_vlan.vid = vid; native_vlan.vid = vid;
native_vlan.valid = true;
ret = ocelot_port_set_native_vlan(ocelot, port, native_vlan); ret = ocelot_port_set_native_vlan(ocelot, port, native_vlan);
if (ret) if (ret)
return ret; return ret;
...@@ -303,9 +305,8 @@ int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) ...@@ -303,9 +305,8 @@ int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
/* Egress */ /* Egress */
if (ocelot_port->native_vlan.vid == vid) { if (ocelot_port->native_vlan.vid == vid) {
struct ocelot_vlan native_vlan; struct ocelot_vlan native_vlan = {0};
native_vlan.vid = 0;
ocelot_port_set_native_vlan(ocelot, port, native_vlan); ocelot_port_set_native_vlan(ocelot, port, native_vlan);
} }
......
...@@ -572,6 +572,7 @@ struct ocelot_vcap_block { ...@@ -572,6 +572,7 @@ struct ocelot_vcap_block {
}; };
struct ocelot_vlan { struct ocelot_vlan {
bool valid;
u16 vid; u16 vid;
}; };
......
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