Skip to content

Commit 96b029b

Browse files
vladimirolteandavem330
authored andcommitted
net: mscc: ocelot: introduce macros for iterating over PGIDs
The current iterators are impossible to understand at first glance without switching back and forth between the definitions and their actual use in the for loops. So introduce some convenience names to help readability. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 209edf9 commit 96b029b

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎drivers/net/ethernet/mscc/ocelot.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,10 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
10641064
int i, port, lag;
10651065

10661066
/* Reset destination and aggregation PGIDS */
1067-
for (port = 0; port < ocelot->num_phys_ports; port++)
1067+
for_each_unicast_dest_pgid(ocelot, port)
10681068
ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
10691069

1070-
for (i = PGID_AGGR; i < PGID_SRC; i++)
1070+
for_each_aggr_pgid(ocelot, i)
10711071
ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
10721072
ANA_PGID_PGID, i);
10731073

@@ -1089,7 +1089,7 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
10891089
aggr_count++;
10901090
}
10911091

1092-
for (i = PGID_AGGR; i < PGID_SRC; i++) {
1092+
for_each_aggr_pgid(ocelot, i) {
10931093
u32 ac;
10941094

10951095
ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
@@ -1451,7 +1451,7 @@ int ocelot_init(struct ocelot *ocelot)
14511451
}
14521452

14531453
/* Allow broadcast MAC frames. */
1454-
for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++) {
1454+
for_each_nonreserved_multicast_dest_pgid(ocelot, i) {
14551455
u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
14561456

14571457
ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);

‎drivers/net/ethernet/mscc/ocelot_net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static void ocelot_set_rx_mode(struct net_device *dev)
422422
* forwarded to the CPU port.
423423
*/
424424
val = GENMASK(ocelot->num_phys_ports - 1, 0);
425-
for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++)
425+
for_each_nonreserved_multicast_dest_pgid(ocelot, i)
426426
ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
427427

428428
__dev_mc_sync(dev, ocelot_mc_sync, ocelot_mc_unsync);

‎include/soc/mscc/ocelot.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@
6565
#define PGID_MCIPV4 62
6666
#define PGID_MCIPV6 63
6767

68+
#define for_each_unicast_dest_pgid(ocelot, pgid) \
69+
for ((pgid) = 0; \
70+
(pgid) < (ocelot)->num_phys_ports; \
71+
(pgid)++)
72+
73+
#define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) \
74+
for ((pgid) = (ocelot)->num_phys_ports + 1; \
75+
(pgid) < PGID_CPU; \
76+
(pgid)++)
77+
78+
#define for_each_aggr_pgid(ocelot, pgid) \
79+
for ((pgid) = PGID_AGGR; \
80+
(pgid) < PGID_SRC; \
81+
(pgid)++)
82+
6883
/* Aggregation PGIDs, one per Link Aggregation Code */
6984
#define PGID_AGGR 64
7085

0 commit comments

Comments
 (0)