Skip to content

Commit bbf6a2d

Browse files
vladimirolteandavem330
authored andcommitted
net: mscc: ocelot: use helpers for port VLAN membership
This is a mostly cosmetic patch that creates some helpers for accessing the VLAN table. These helpers are also a bit more careful in that they do not modify the ocelot->vlan_mask unless the hardware operation succeeded. Not all callers check the return value (the init code doesn't), but anyway. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3b95d1b commit bbf6a2d

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,33 @@ static void ocelot_port_set_pvid(struct ocelot *ocelot, int port,
222222
ANA_PORT_DROP_CFG, port);
223223
}
224224

225+
static int ocelot_vlan_member_set(struct ocelot *ocelot, u32 vlan_mask, u16 vid)
226+
{
227+
int err;
228+
229+
err = ocelot_vlant_set_mask(ocelot, vid, vlan_mask);
230+
if (err)
231+
return err;
232+
233+
ocelot->vlan_mask[vid] = vlan_mask;
234+
235+
return 0;
236+
}
237+
238+
static int ocelot_vlan_member_add(struct ocelot *ocelot, int port, u16 vid)
239+
{
240+
return ocelot_vlan_member_set(ocelot,
241+
ocelot->vlan_mask[vid] | BIT(port),
242+
vid);
243+
}
244+
245+
static int ocelot_vlan_member_del(struct ocelot *ocelot, int port, u16 vid)
246+
{
247+
return ocelot_vlan_member_set(ocelot,
248+
ocelot->vlan_mask[vid] & ~BIT(port),
249+
vid);
250+
}
251+
225252
int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
226253
bool vlan_aware, struct netlink_ext_ack *extack)
227254
{
@@ -278,13 +305,11 @@ EXPORT_SYMBOL(ocelot_vlan_prepare);
278305
int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
279306
bool untagged)
280307
{
281-
int ret;
308+
int err;
282309

283-
/* Make the port a member of the VLAN */
284-
ocelot->vlan_mask[vid] |= BIT(port);
285-
ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
286-
if (ret)
287-
return ret;
310+
err = ocelot_vlan_member_add(ocelot, port, vid);
311+
if (err)
312+
return err;
288313

289314
/* Default ingress vlan classification */
290315
if (pvid) {
@@ -311,13 +336,11 @@ EXPORT_SYMBOL(ocelot_vlan_add);
311336
int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
312337
{
313338
struct ocelot_port *ocelot_port = ocelot->ports[port];
314-
int ret;
339+
int err;
315340

316-
/* Stop the port from being a member of the vlan */
317-
ocelot->vlan_mask[vid] &= ~BIT(port);
318-
ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
319-
if (ret)
320-
return ret;
341+
err = ocelot_vlan_member_del(ocelot, port, vid);
342+
if (err)
343+
return err;
321344

322345
/* Ingress */
323346
if (ocelot_port->pvid_vlan.vid == vid) {
@@ -339,6 +362,7 @@ EXPORT_SYMBOL(ocelot_vlan_del);
339362

340363
static void ocelot_vlan_init(struct ocelot *ocelot)
341364
{
365+
unsigned long all_ports = GENMASK(ocelot->num_phys_ports - 1, 0);
342366
u16 port, vid;
343367

344368
/* Clear VLAN table, by default all ports are members of all VLANs */
@@ -347,23 +371,19 @@ static void ocelot_vlan_init(struct ocelot *ocelot)
347371
ocelot_vlant_wait_for_completion(ocelot);
348372

349373
/* Configure the port VLAN memberships */
350-
for (vid = 1; vid < VLAN_N_VID; vid++) {
351-
ocelot->vlan_mask[vid] = 0;
352-
ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
353-
}
374+
for (vid = 1; vid < VLAN_N_VID; vid++)
375+
ocelot_vlan_member_set(ocelot, 0, vid);
354376

355377
/* Because VLAN filtering is enabled, we need VID 0 to get untagged
356378
* traffic. It is added automatically if 8021q module is loaded, but
357379
* we can't rely on it since module may be not loaded.
358380
*/
359-
ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0);
360-
ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]);
381+
ocelot_vlan_member_set(ocelot, all_ports, 0);
361382

362383
/* Set vlan ingress filter mask to all ports but the CPU port by
363384
* default.
364385
*/
365-
ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
366-
ANA_VLANMASK);
386+
ocelot_write(ocelot, all_ports, ANA_VLANMASK);
367387

368388
for (port = 0; port < ocelot->num_phys_ports; port++) {
369389
ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);

0 commit comments

Comments
 (0)