Skip to content

Commit ad238fc

Browse files
cappe987kuba-moo
authored andcommitted
net: sparx5: Refactor mdb handling according to feedback
- Remove mact_lookup and use new mact_find instead. - Make pgid_read_mask function. - Set PGID arbiter to start searching at PGID_BASE + 8. This is according to feedback on previous patch. https://lore.kernel.org/netdev/20220322081823.wqbx7vud4q7qtjuq@wse-c0155/T/#t Signed-off-by: Casper Andersson <casper.casan@gmail.com> Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 264a9c5 commit ad238fc

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,7 @@ bool sparx5_mact_find(struct sparx5 *sparx5,
212212

213213
mutex_unlock(&sparx5->lock);
214214

215-
return ret == 0;
216-
}
217-
218-
static int sparx5_mact_lookup(struct sparx5 *sparx5,
219-
const unsigned char mac[ETH_ALEN],
220-
u16 vid)
221-
{
222-
u32 pcfg2;
223-
224-
if (sparx5_mact_find(sparx5, mac, vid, &pcfg2))
225-
return 1;
226-
227-
return 0;
215+
return ret;
228216
}
229217

230218
int sparx5_mact_forget(struct sparx5 *sparx5,
@@ -305,9 +293,10 @@ int sparx5_add_mact_entry(struct sparx5 *sparx5,
305293
{
306294
struct sparx5_mact_entry *mact_entry;
307295
int ret;
296+
u32 cfg2;
308297

309-
ret = sparx5_mact_lookup(sparx5, addr, vid);
310-
if (ret)
298+
ret = sparx5_mact_find(sparx5, addr, vid, &cfg2);
299+
if (!ret)
311300
return 0;
312301

313302
/* In case the entry already exists, don't add it again to SW,

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ enum sparx5_vlan_port_type {
6565
#define PGID_IPV6_MC_CTRL (PGID_BASE + 5)
6666
#define PGID_BCAST (PGID_BASE + 6)
6767
#define PGID_CPU (PGID_BASE + 7)
68+
#define PGID_MCAST_START (PGID_BASE + 8)
6869

6970
#define PGID_TABLE_SIZE 3290
7071

71-
#define PGID_MCAST_START 65
7272
#define IFH_LEN 9 /* 36 bytes */
7373
#define NULL_VID 0
7474
#define SPX5_MACT_PULL_DELAY (2 * HZ)
@@ -325,6 +325,7 @@ void sparx5_mact_init(struct sparx5 *sparx5);
325325

326326
/* sparx5_vlan.c */
327327
void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable);
328+
void sparx5_pgid_read_mask(struct sparx5 *sparx5, int pgid, u32 portmask[3]);
328329
void sparx5_update_fwd(struct sparx5 *sparx5);
329330
void sparx5_vlan_init(struct sparx5 *sparx5);
330331
void sparx5_vlan_port_setup(struct sparx5 *sparx5, int portno);

drivers/net/ethernet/microchip/sparx5/sparx5_pgid.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx)
1919
{
2020
int i;
2121

22+
/* The multicast area starts at index 65, but the first 7
23+
* are reserved for flood masks and CPU. Start alloc after that.
24+
*/
2225
for (i = PGID_MCAST_START; i < PGID_TABLE_SIZE; i++) {
2326
if (spx5->pgid_map[i] == SPX5_PGID_FREE) {
2427
spx5->pgid_map[i] = SPX5_PGID_MULTICAST;

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ static int sparx5_handle_port_mdb_add(struct net_device *dev,
406406

407407
res = sparx5_mact_find(spx5, v->addr, vid, &mact_entry);
408408

409-
if (res) {
409+
if (res == 0) {
410410
pgid_idx = LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_ADDR_GET(mact_entry);
411411

412-
/* MC_IDX has an offset of 65 in the PGID table. */
413-
pgid_idx += PGID_MCAST_START;
412+
/* MC_IDX starts after the port masks in the PGID table */
413+
pgid_idx += SPX5_PORTS;
414414
sparx5_pgid_update_mask(port, pgid_idx, true);
415415
} else {
416416
err = sparx5_pgid_alloc_mcast(spx5, &pgid_idx);
@@ -468,17 +468,15 @@ static int sparx5_handle_port_mdb_del(struct net_device *dev,
468468

469469
res = sparx5_mact_find(spx5, v->addr, vid, &mact_entry);
470470

471-
if (res) {
471+
if (res == 0) {
472472
pgid_idx = LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_ADDR_GET(mact_entry);
473473

474-
/* MC_IDX has an offset of 65 in the PGID table. */
475-
pgid_idx += PGID_MCAST_START;
474+
/* MC_IDX starts after the port masks in the PGID table */
475+
pgid_idx += SPX5_PORTS;
476476
sparx5_pgid_update_mask(port, pgid_idx, false);
477477

478-
pgid_entry[0] = spx5_rd(spx5, ANA_AC_PGID_CFG(pgid_idx));
479-
pgid_entry[1] = spx5_rd(spx5, ANA_AC_PGID_CFG1(pgid_idx));
480-
pgid_entry[2] = spx5_rd(spx5, ANA_AC_PGID_CFG2(pgid_idx));
481-
if (pgid_entry[0] == 0 && pgid_entry[1] == 0 && pgid_entry[2] == 0) {
478+
sparx5_pgid_read_mask(spx5, pgid_idx, pgid_entry);
479+
if (bitmap_empty((unsigned long *)pgid_entry, SPX5_PORTS)) {
482480
/* No ports are in MC group. Remove entry */
483481
err = sparx5_mdb_del_entry(dev, spx5, v->addr, vid, pgid_idx);
484482
if (err)

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ void sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable)
138138
}
139139
}
140140

141+
void sparx5_pgid_read_mask(struct sparx5 *spx5, int pgid, u32 portmask[3])
142+
{
143+
portmask[0] = spx5_rd(spx5, ANA_AC_PGID_CFG(pgid));
144+
portmask[1] = spx5_rd(spx5, ANA_AC_PGID_CFG1(pgid));
145+
portmask[2] = spx5_rd(spx5, ANA_AC_PGID_CFG2(pgid));
146+
}
147+
141148
void sparx5_update_fwd(struct sparx5 *sparx5)
142149
{
143150
DECLARE_BITMAP(workmask, SPX5_PORTS);

0 commit comments

Comments
 (0)