Skip to content

Commit

Permalink
net: mscc: ocelot: track the port pvid using a pointer
Browse files Browse the repository at this point in the history
Now that we have a list of struct ocelot_bridge_vlan entries, we can
rewrite the pvid logic to simply point to one of those structures,
instead of having a separate structure with a "bool valid".
The NULL pointer will represent the lack of a bridge pvid (not to be
confused with the lack of a hardware pvid on the port, that is present
at all times).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
vladimiroltean authored and davem330 committed Oct 21, 2021
1 parent bfbab31 commit d400442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
31 changes: 12 additions & 19 deletions drivers/net/ethernet/mscc/ocelot.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,19 @@ static void ocelot_port_manage_port_tag(struct ocelot *ocelot, int port)

/* Default vlan to clasify for untagged frames (may be zero) */
static void ocelot_port_set_pvid(struct ocelot *ocelot, int port,
struct ocelot_vlan pvid_vlan)
const struct ocelot_bridge_vlan *pvid_vlan)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
u16 pvid = OCELOT_VLAN_UNAWARE_PVID;
u32 val = 0;

ocelot_port->pvid_vlan = pvid_vlan;

if (!ocelot_port->vlan_aware)
pvid_vlan.vid = OCELOT_VLAN_UNAWARE_PVID;
if (ocelot_port->vlan_aware && pvid_vlan)
pvid = pvid_vlan->vid;

ocelot_rmw_gix(ocelot,
ANA_PORT_VLAN_CFG_VLAN_VID(pvid_vlan.vid),
ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
ANA_PORT_VLAN_CFG_VLAN_VID_M,
ANA_PORT_VLAN_CFG, port);

Expand All @@ -280,7 +281,7 @@ static void ocelot_port_set_pvid(struct ocelot *ocelot, int port,
* classified to VLAN 0, but that is always in our RX filter, so it
* would get accepted were it not for this setting.
*/
if (!pvid_vlan.valid && ocelot_port->vlan_aware)
if (!pvid_vlan && ocelot_port->vlan_aware)
val = ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;

Expand Down Expand Up @@ -445,13 +446,9 @@ int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
return err;

/* Default ingress vlan classification */
if (pvid) {
struct ocelot_vlan pvid_vlan;

pvid_vlan.vid = vid;
pvid_vlan.valid = true;
ocelot_port_set_pvid(ocelot, port, pvid_vlan);
}
if (pvid)
ocelot_port_set_pvid(ocelot, port,
ocelot_bridge_vlan_find(ocelot, vid));

/* Untagged egress vlan clasification */
ocelot_port_manage_port_tag(ocelot, port);
Expand All @@ -470,11 +467,8 @@ int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
return err;

/* Ingress */
if (ocelot_port->pvid_vlan.vid == vid) {
struct ocelot_vlan pvid_vlan = {0};

ocelot_port_set_pvid(ocelot, port, pvid_vlan);
}
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
ocelot_port_set_pvid(ocelot, port, NULL);

/* Egress */
ocelot_port_manage_port_tag(ocelot, port);
Expand Down Expand Up @@ -1803,11 +1797,10 @@ void ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
struct net_device *bridge)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
struct ocelot_vlan pvid = {0};

ocelot_port->bridge = NULL;

ocelot_port_set_pvid(ocelot, port, pvid);
ocelot_port_set_pvid(ocelot, port, NULL);
ocelot_port_manage_port_tag(ocelot, port);
ocelot_apply_bridge_fwd_mask(ocelot);
}
Expand Down
7 changes: 1 addition & 6 deletions include/soc/mscc/ocelot.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,6 @@ struct ocelot_vcap_block {
int pol_lpr;
};

struct ocelot_vlan {
bool valid;
u16 vid;
};

struct ocelot_bridge_vlan {
u16 vid;
unsigned long portmask;
Expand Down Expand Up @@ -608,7 +603,7 @@ struct ocelot_port {

bool vlan_aware;
/* VLAN that untagged frames are classified to, on ingress */
struct ocelot_vlan pvid_vlan;
const struct ocelot_bridge_vlan *pvid_vlan;

unsigned int ptp_skbs_in_flight;
u8 ptp_cmd;
Expand Down

0 comments on commit d400442

Please sign in to comment.