Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 #include "sparx5_main.h"
0003 
0004 void sparx5_pgid_init(struct sparx5 *spx5)
0005 {
0006     int i;
0007 
0008     for (i = 0; i < PGID_TABLE_SIZE; i++)
0009         spx5->pgid_map[i] = SPX5_PGID_FREE;
0010 
0011     /* Reserved for unicast, flood control, broadcast, and CPU.
0012      * These cannot be freed.
0013      */
0014     for (i = 0; i <= PGID_CPU; i++)
0015         spx5->pgid_map[i] = SPX5_PGID_RESERVED;
0016 }
0017 
0018 int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx)
0019 {
0020     int i;
0021 
0022     /* The multicast area starts at index 65, but the first 7
0023      * are reserved for flood masks and CPU. Start alloc after that.
0024      */
0025     for (i = PGID_MCAST_START; i < PGID_TABLE_SIZE; i++) {
0026         if (spx5->pgid_map[i] == SPX5_PGID_FREE) {
0027             spx5->pgid_map[i] = SPX5_PGID_MULTICAST;
0028             *idx = i;
0029             return 0;
0030         }
0031     }
0032 
0033     return -EBUSY;
0034 }
0035 
0036 int sparx5_pgid_free(struct sparx5 *spx5, u16 idx)
0037 {
0038     if (idx <= PGID_CPU || idx >= PGID_TABLE_SIZE)
0039         return -EINVAL;
0040 
0041     if (spx5->pgid_map[idx] == SPX5_PGID_FREE)
0042         return -EINVAL;
0043 
0044     spx5->pgid_map[idx] = SPX5_PGID_FREE;
0045     return 0;
0046 }