1 // SPDX-License-Identifier: GPL-2.0+ 2 #include "sparx5_main.h" 3 4 void sparx5_pgid_init(struct sparx5 *spx5) 5 { 6 int i; 7 8 for (i = 0; i < PGID_TABLE_SIZE; i++) 9 spx5->pgid_map[i] = SPX5_PGID_FREE; 10 11 /* Reserved for unicast, flood control, broadcast, and CPU. 12 * These cannot be freed. 13 */ 14 for (i = 0; i <= PGID_CPU; i++) 15 spx5->pgid_map[i] = SPX5_PGID_RESERVED; 16 } 17 18 int sparx5_pgid_alloc_glag(struct sparx5 *spx5, u16 *idx) 19 { 20 int i; 21 22 for (i = PGID_GLAG_START; i <= PGID_GLAG_END; i++) 23 if (spx5->pgid_map[i] == SPX5_PGID_FREE) { 24 spx5->pgid_map[i] = SPX5_PGID_GLAG; 25 *idx = i; 26 return 0; 27 } 28 29 return -EBUSY; 30 } 31 32 int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx) 33 { 34 int i; 35 36 for (i = PGID_MCAST_START; i < PGID_TABLE_SIZE; i++) { 37 if (i == PGID_GLAG_START) 38 i = PGID_GLAG_END + 1; 39 40 if (spx5->pgid_map[i] == SPX5_PGID_FREE) { 41 spx5->pgid_map[i] = SPX5_PGID_MULTICAST; 42 *idx = i; 43 return 0; 44 } 45 } 46 47 return -EBUSY; 48 } 49 50 int sparx5_pgid_free(struct sparx5 *spx5, u16 idx) 51 { 52 if (idx <= PGID_CPU || idx >= PGID_TABLE_SIZE) 53 return -EINVAL; 54 55 if (spx5->pgid_map[idx] == SPX5_PGID_FREE) 56 return -EINVAL; 57 58 spx5->pgid_map[idx] = SPX5_PGID_FREE; 59 return 0; 60 } 61