Commit b87bde80 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum_trap: Do not hard code "thin" policer identifier

As explained in commit e6125230 ("mlxsw: spectrum_trap: Introduce
dummy group with thin policer"), the purpose of the "thin" policer is to
pass as less packets as possible to the CPU.

The identifier of this policer is currently set according to the maximum
number of used trap groups, but this is fragile: On Spectrum-1 the
maximum number of policers is less than the maximum number of trap
groups, which might result in an invalid policer identifier in case the
number of used trap groups grows beyond the policer limit.

Solve this by dynamically allocating the policer identifier.
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 03cb0ce0
...@@ -441,8 +441,6 @@ static const struct mlxsw_sp_trap_item mlxsw_sp_trap_items_arr[] = { ...@@ -441,8 +441,6 @@ static const struct mlxsw_sp_trap_item mlxsw_sp_trap_items_arr[] = {
}, },
}; };
#define MLXSW_SP_THIN_POLICER_ID (MLXSW_REG_HTGT_TRAP_GROUP_MAX + 1)
static struct mlxsw_sp_trap_policer_item * static struct mlxsw_sp_trap_policer_item *
mlxsw_sp_trap_policer_item_lookup(struct mlxsw_sp *mlxsw_sp, u32 id) mlxsw_sp_trap_policer_item_lookup(struct mlxsw_sp *mlxsw_sp, u32 id)
{ {
...@@ -487,14 +485,21 @@ mlxsw_sp_trap_item_lookup(struct mlxsw_sp *mlxsw_sp, u16 id) ...@@ -487,14 +485,21 @@ mlxsw_sp_trap_item_lookup(struct mlxsw_sp *mlxsw_sp, u16 id)
static int mlxsw_sp_trap_cpu_policers_set(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_trap_cpu_policers_set(struct mlxsw_sp *mlxsw_sp)
{ {
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
char qpcr_pl[MLXSW_REG_QPCR_LEN]; char qpcr_pl[MLXSW_REG_QPCR_LEN];
u16 hw_id;
/* The purpose of "thin" policer is to drop as many packets /* The purpose of "thin" policer is to drop as many packets
* as possible. The dummy group is using it. * as possible. The dummy group is using it.
*/ */
__set_bit(MLXSW_SP_THIN_POLICER_ID, mlxsw_sp->trap->policers_usage); hw_id = find_first_zero_bit(trap->policers_usage, trap->max_policers);
mlxsw_reg_qpcr_pack(qpcr_pl, MLXSW_SP_THIN_POLICER_ID, if (WARN_ON(hw_id == trap->max_policers))
MLXSW_REG_QPCR_IR_UNITS_M, false, 1, 4); return -ENOBUFS;
__set_bit(hw_id, trap->policers_usage);
trap->thin_policer_hw_id = hw_id;
mlxsw_reg_qpcr_pack(qpcr_pl, hw_id, MLXSW_REG_QPCR_IR_UNITS_M,
false, 1, 4);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qpcr), qpcr_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qpcr), qpcr_pl);
} }
...@@ -503,7 +508,7 @@ static int mlxsw_sp_trap_dummy_group_init(struct mlxsw_sp *mlxsw_sp) ...@@ -503,7 +508,7 @@ static int mlxsw_sp_trap_dummy_group_init(struct mlxsw_sp *mlxsw_sp)
char htgt_pl[MLXSW_REG_HTGT_LEN]; char htgt_pl[MLXSW_REG_HTGT_LEN];
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_SP_DUMMY, mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_SP_DUMMY,
MLXSW_SP_THIN_POLICER_ID, 0, 1); mlxsw_sp->trap->thin_policer_hw_id, 0, 1);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(htgt), htgt_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(htgt), htgt_pl);
} }
......
...@@ -17,6 +17,8 @@ struct mlxsw_sp_trap { ...@@ -17,6 +17,8 @@ struct mlxsw_sp_trap {
struct mlxsw_sp_trap_item *trap_items_arr; struct mlxsw_sp_trap_item *trap_items_arr;
u64 traps_count; /* Number of registered traps */ u64 traps_count; /* Number of registered traps */
u16 thin_policer_hw_id;
u64 max_policers; u64 max_policers;
unsigned long policers_usage[]; /* Usage bitmap */ unsigned long policers_usage[]; /* Usage bitmap */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment