Files
linux/drivers/net/ethernet/microchip/sparx5/sparx5_pgid.c
Casper Andersson af9b45d08e net: sparx5: Add arbiter for managing PGID table
The PGID (Port Group ID) table holds port masks
for different purposes. The first 72 are reserved
for port destination masks, flood masks, and CPU
forwarding. The rest are shared between multicast,
link aggregation, and virtualization profiles. The
GLAG area is reserved to not be used by anything
else, since it is a subset of the MCAST area.

The arbiter keeps track of which entries are in
use. You can ask for a free ID or give back one
you are done using.

Signed-off-by: Casper Andersson <casper.casan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-21 13:24:28 +00:00

61 lines
1.2 KiB
C

// SPDX-License-Identifier: GPL-2.0+
#include "sparx5_main.h"
void sparx5_pgid_init(struct sparx5 *spx5)
{
int i;
for (i = 0; i < PGID_TABLE_SIZE; i++)
spx5->pgid_map[i] = SPX5_PGID_FREE;
/* Reserved for unicast, flood control, broadcast, and CPU.
* These cannot be freed.
*/
for (i = 0; i <= PGID_CPU; i++)
spx5->pgid_map[i] = SPX5_PGID_RESERVED;
}
int sparx5_pgid_alloc_glag(struct sparx5 *spx5, u16 *idx)
{
int i;
for (i = PGID_GLAG_START; i <= PGID_GLAG_END; i++)
if (spx5->pgid_map[i] == SPX5_PGID_FREE) {
spx5->pgid_map[i] = SPX5_PGID_GLAG;
*idx = i;
return 0;
}
return -EBUSY;
}
int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx)
{
int i;
for (i = PGID_MCAST_START; i < PGID_TABLE_SIZE; i++) {
if (i == PGID_GLAG_START)
i = PGID_GLAG_END + 1;
if (spx5->pgid_map[i] == SPX5_PGID_FREE) {
spx5->pgid_map[i] = SPX5_PGID_MULTICAST;
*idx = i;
return 0;
}
}
return -EBUSY;
}
int sparx5_pgid_free(struct sparx5 *spx5, u16 idx)
{
if (idx <= PGID_CPU || idx >= PGID_TABLE_SIZE)
return -EINVAL;
if (spx5->pgid_map[idx] == SPX5_PGID_FREE)
return -EINVAL;
spx5->pgid_map[idx] = SPX5_PGID_FREE;
return 0;
}