Skip to content

Commit 9148e7c

Browse files
Nogah Frankeldavem330
authored andcommitted
mlxsw: spectrum: Add policers for trap groups
Configure policers and connect them to trap groups. While many trap groups share policer's configuration they don't share the actual policer because each trap group represents a different flow / protocol and we don't want one of them to be able to exceed its rate on behalf of another. For example, if STP and LLDP gets to send 128 packets/sec each, if we put them in one 256 packets/sec policer, one can send 200 packets while the other only 50. Note that IP2ME covers lots of flows, so it's limit is set to match the cpu ability to handle data. Signed-off-by: Nogah Frankel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 76a4c7d commit 9148e7c

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,20 +2767,82 @@ static const struct mlxsw_listener mlxsw_sp_listener[] = {
27672767
MLXSW_SP_RXL_NO_MARK(BGP_IPV4, TRAP_TO_CPU, BGP_IPV4, false),
27682768
};
27692769

2770+
static int mlxsw_sp_cpu_policers_set(struct mlxsw_core *mlxsw_core)
2771+
{
2772+
char qpcr_pl[MLXSW_REG_QPCR_LEN];
2773+
enum mlxsw_reg_qpcr_ir_units ir_units;
2774+
int max_cpu_policers;
2775+
bool is_bytes;
2776+
u8 burst_size;
2777+
u32 rate;
2778+
int i, err;
2779+
2780+
if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_CPU_POLICERS))
2781+
return -EIO;
2782+
2783+
max_cpu_policers = MLXSW_CORE_RES_GET(mlxsw_core, MAX_CPU_POLICERS);
2784+
2785+
ir_units = MLXSW_REG_QPCR_IR_UNITS_M;
2786+
for (i = 0; i < max_cpu_policers; i++) {
2787+
is_bytes = false;
2788+
switch (i) {
2789+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_STP:
2790+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP:
2791+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP:
2792+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF:
2793+
rate = 128;
2794+
burst_size = 7;
2795+
break;
2796+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_IGMP:
2797+
rate = 16 * 1024;
2798+
burst_size = 10;
2799+
break;
2800+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP_IPV4:
2801+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP:
2802+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP:
2803+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP_MISS:
2804+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP:
2805+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_REMOTE_ROUTE:
2806+
rate = 1024;
2807+
burst_size = 7;
2808+
break;
2809+
case MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME:
2810+
is_bytes = true;
2811+
rate = 4 * 1024;
2812+
burst_size = 4;
2813+
break;
2814+
default:
2815+
continue;
2816+
}
2817+
2818+
mlxsw_reg_qpcr_pack(qpcr_pl, i, ir_units, is_bytes, rate,
2819+
burst_size);
2820+
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(qpcr), qpcr_pl);
2821+
if (err)
2822+
return err;
2823+
}
2824+
2825+
return 0;
2826+
}
2827+
27702828
static int mlxsw_sp_trap_groups_set(struct mlxsw_core *mlxsw_core)
27712829
{
27722830
char htgt_pl[MLXSW_REG_HTGT_LEN];
27732831
enum mlxsw_reg_htgt_trap_group i;
2832+
int max_cpu_policers;
27742833
int max_trap_groups;
27752834
u8 priority, tc;
2835+
u16 policer_id;
27762836
int err;
27772837

27782838
if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_TRAP_GROUPS))
27792839
return -EIO;
27802840

27812841
max_trap_groups = MLXSW_CORE_RES_GET(mlxsw_core, MAX_TRAP_GROUPS);
2842+
max_cpu_policers = MLXSW_CORE_RES_GET(mlxsw_core, MAX_CPU_POLICERS);
27822843

27832844
for (i = 0; i < max_trap_groups; i++) {
2845+
policer_id = i;
27842846
switch (i) {
27852847
case MLXSW_REG_HTGT_TRAP_GROUP_SP_STP:
27862848
case MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP:
@@ -2812,13 +2874,17 @@ static int mlxsw_sp_trap_groups_set(struct mlxsw_core *mlxsw_core)
28122874
case MLXSW_REG_HTGT_TRAP_GROUP_SP_EVENT:
28132875
priority = MLXSW_REG_HTGT_DEFAULT_PRIORITY;
28142876
tc = MLXSW_REG_HTGT_DEFAULT_TC;
2877+
policer_id = MLXSW_REG_HTGT_INVALID_POLICER;
28152878
break;
28162879
default:
28172880
continue;
28182881
}
28192882

2820-
mlxsw_reg_htgt_pack(htgt_pl, i, MLXSW_REG_HTGT_INVALID_POLICER,
2821-
priority, tc);
2883+
if (max_cpu_policers <= policer_id &&
2884+
policer_id != MLXSW_REG_HTGT_INVALID_POLICER)
2885+
return -EIO;
2886+
2887+
mlxsw_reg_htgt_pack(htgt_pl, i, policer_id, priority, tc);
28222888
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
28232889
if (err)
28242890
return err;
@@ -2832,6 +2898,10 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
28322898
int i;
28332899
int err;
28342900

2901+
err = mlxsw_sp_cpu_policers_set(mlxsw_sp->core);
2902+
if (err)
2903+
return err;
2904+
28352905
err = mlxsw_sp_trap_groups_set(mlxsw_sp->core);
28362906
if (err)
28372907
return err;

0 commit comments

Comments
 (0)