Commit d25b8f6e authored by Ido Schimmel's avatar Ido Schimmel Committed by Jakub Kicinski

mlxsw: core_acl_flex_actions: Work around hardware limitation

In the policy engine, each ACL rule points to an action block where the
ACL actions are stored. Each action block consists of one or more action
sets. Each action set holds one or more individual actions, up to a
maximum queried from the device. For example:

                        Action set #1               Action set #2

+----------+          +--------------+            +--------------+
| ACL rule +---------->  Action #1   |      +----->  Action #4   |
+----------+          +--------------+      |     +--------------+
                      |  Action #2   |      |     |  Action #5   |
                      +--------------+      |     +--------------+
                      |  Action #3   +------+     |              |
                      +--------------+            +--------------+

                      <---------+ Action block +----------------->

The hardware has a limitation that prevents a policing action
(MLXSW_AFA_POLCNT_CODE when used with a policer, not a counter) from
being configured in the same action set with a trap action (i.e.,
MLXSW_AFA_TRAP_CODE or MLXSW_AFA_TRAPWU_CODE). Note that the latter used
to implement multiple actions: 'trap', 'mirred', 'drop'.

Work around this limitation by teaching mlxsw_afa_block_append_action()
to create a new action set not only when there is no more room left in
the current set, but also when there is a conflict between previously
mentioned actions.
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarPetr Machata <petrm@mellanox.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bf038f03
...@@ -88,9 +88,11 @@ struct mlxsw_afa_set { ...@@ -88,9 +88,11 @@ struct mlxsw_afa_set {
struct rhash_head ht_node; struct rhash_head ht_node;
struct mlxsw_afa_set_ht_key ht_key; struct mlxsw_afa_set_ht_key ht_key;
u32 kvdl_index; u32 kvdl_index;
bool shared; /* Inserted in hashtable (doesn't mean that u8 shared:1, /* Inserted in hashtable (doesn't mean that
* kvdl_index is valid). * kvdl_index is valid).
*/ */
has_trap:1,
has_police:1;
unsigned int ref_count; unsigned int ref_count;
struct mlxsw_afa_set *next; /* Pointer to the next set. */ struct mlxsw_afa_set *next; /* Pointer to the next set. */
struct mlxsw_afa_set *prev; /* Pointer to the previous set, struct mlxsw_afa_set *prev; /* Pointer to the previous set,
...@@ -839,16 +841,38 @@ mlxsw_afa_cookie_ref_create(struct mlxsw_afa_block *block, ...@@ -839,16 +841,38 @@ mlxsw_afa_cookie_ref_create(struct mlxsw_afa_block *block,
#define MLXSW_AFA_ONE_ACTION_LEN 32 #define MLXSW_AFA_ONE_ACTION_LEN 32
#define MLXSW_AFA_PAYLOAD_OFFSET 4 #define MLXSW_AFA_PAYLOAD_OFFSET 4
static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block, enum mlxsw_afa_action_type {
u8 action_code, u8 action_size) MLXSW_AFA_ACTION_TYPE_TRAP,
MLXSW_AFA_ACTION_TYPE_POLICE,
MLXSW_AFA_ACTION_TYPE_OTHER,
};
static bool
mlxsw_afa_block_need_split(const struct mlxsw_afa_block *block,
enum mlxsw_afa_action_type type)
{
struct mlxsw_afa_set *cur_set = block->cur_set;
/* Due to a hardware limitation, police action cannot be in the same
* action set with MLXSW_AFA_TRAP_CODE or MLXSW_AFA_TRAPWU_CODE
* actions. Work around this limitation by creating a new action set
* and place the new action there.
*/
return (cur_set->has_trap && type == MLXSW_AFA_ACTION_TYPE_POLICE) ||
(cur_set->has_police && type == MLXSW_AFA_ACTION_TYPE_TRAP);
}
static char *mlxsw_afa_block_append_action_ext(struct mlxsw_afa_block *block,
u8 action_code, u8 action_size,
enum mlxsw_afa_action_type type)
{ {
char *oneact; char *oneact;
char *actions; char *actions;
if (block->finished) if (block->finished)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
if (block->cur_act_index + action_size > if (block->cur_act_index + action_size > block->afa->max_acts_per_set ||
block->afa->max_acts_per_set) { mlxsw_afa_block_need_split(block, type)) {
struct mlxsw_afa_set *set; struct mlxsw_afa_set *set;
/* The appended action won't fit into the current action set, /* The appended action won't fit into the current action set,
...@@ -863,6 +887,17 @@ static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block, ...@@ -863,6 +887,17 @@ static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block,
block->cur_set = set; block->cur_set = set;
} }
switch (type) {
case MLXSW_AFA_ACTION_TYPE_TRAP:
block->cur_set->has_trap = true;
break;
case MLXSW_AFA_ACTION_TYPE_POLICE:
block->cur_set->has_police = true;
break;
default:
break;
}
actions = block->cur_set->ht_key.enc_actions; actions = block->cur_set->ht_key.enc_actions;
oneact = actions + block->cur_act_index * MLXSW_AFA_ONE_ACTION_LEN; oneact = actions + block->cur_act_index * MLXSW_AFA_ONE_ACTION_LEN;
block->cur_act_index += action_size; block->cur_act_index += action_size;
...@@ -870,6 +905,14 @@ static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block, ...@@ -870,6 +905,14 @@ static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block,
return oneact + MLXSW_AFA_PAYLOAD_OFFSET; return oneact + MLXSW_AFA_PAYLOAD_OFFSET;
} }
static char *mlxsw_afa_block_append_action(struct mlxsw_afa_block *block,
u8 action_code, u8 action_size)
{
return mlxsw_afa_block_append_action_ext(block, action_code,
action_size,
MLXSW_AFA_ACTION_TYPE_OTHER);
}
/* VLAN Action /* VLAN Action
* ----------- * -----------
* VLAN action is used for manipulating VLANs. It can be used to implement QinQ, * VLAN action is used for manipulating VLANs. It can be used to implement QinQ,
...@@ -1048,10 +1091,19 @@ mlxsw_afa_trap_mirror_pack(char *payload, bool mirror_enable, ...@@ -1048,10 +1091,19 @@ mlxsw_afa_trap_mirror_pack(char *payload, bool mirror_enable,
mlxsw_afa_trap_mirror_agent_set(payload, mirror_agent); mlxsw_afa_trap_mirror_agent_set(payload, mirror_agent);
} }
static char *mlxsw_afa_block_append_action_trap(struct mlxsw_afa_block *block,
u8 action_code, u8 action_size)
{
return mlxsw_afa_block_append_action_ext(block, action_code,
action_size,
MLXSW_AFA_ACTION_TYPE_TRAP);
}
static int mlxsw_afa_block_append_drop_plain(struct mlxsw_afa_block *block, static int mlxsw_afa_block_append_drop_plain(struct mlxsw_afa_block *block,
bool ingress) bool ingress)
{ {
char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAP_CODE, char *act = mlxsw_afa_block_append_action_trap(block,
MLXSW_AFA_TRAP_CODE,
MLXSW_AFA_TRAP_SIZE); MLXSW_AFA_TRAP_SIZE);
if (IS_ERR(act)) if (IS_ERR(act))
...@@ -1081,7 +1133,7 @@ mlxsw_afa_block_append_drop_with_cookie(struct mlxsw_afa_block *block, ...@@ -1081,7 +1133,7 @@ mlxsw_afa_block_append_drop_with_cookie(struct mlxsw_afa_block *block,
} }
cookie_index = cookie_ref->cookie->cookie_index; cookie_index = cookie_ref->cookie->cookie_index;
act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAPWU_CODE, act = mlxsw_afa_block_append_action_trap(block, MLXSW_AFA_TRAPWU_CODE,
MLXSW_AFA_TRAPWU_SIZE); MLXSW_AFA_TRAPWU_SIZE);
if (IS_ERR(act)) { if (IS_ERR(act)) {
NL_SET_ERR_MSG_MOD(extack, "Cannot append drop with cookie action"); NL_SET_ERR_MSG_MOD(extack, "Cannot append drop with cookie action");
...@@ -1113,7 +1165,8 @@ EXPORT_SYMBOL(mlxsw_afa_block_append_drop); ...@@ -1113,7 +1165,8 @@ EXPORT_SYMBOL(mlxsw_afa_block_append_drop);
int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id) int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id)
{ {
char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAP_CODE, char *act = mlxsw_afa_block_append_action_trap(block,
MLXSW_AFA_TRAP_CODE,
MLXSW_AFA_TRAP_SIZE); MLXSW_AFA_TRAP_SIZE);
if (IS_ERR(act)) if (IS_ERR(act))
...@@ -1127,7 +1180,8 @@ EXPORT_SYMBOL(mlxsw_afa_block_append_trap); ...@@ -1127,7 +1180,8 @@ EXPORT_SYMBOL(mlxsw_afa_block_append_trap);
int mlxsw_afa_block_append_trap_and_forward(struct mlxsw_afa_block *block, int mlxsw_afa_block_append_trap_and_forward(struct mlxsw_afa_block *block,
u16 trap_id) u16 trap_id)
{ {
char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAP_CODE, char *act = mlxsw_afa_block_append_action_trap(block,
MLXSW_AFA_TRAP_CODE,
MLXSW_AFA_TRAP_SIZE); MLXSW_AFA_TRAP_SIZE);
if (IS_ERR(act)) if (IS_ERR(act))
...@@ -1199,9 +1253,10 @@ static int ...@@ -1199,9 +1253,10 @@ static int
mlxsw_afa_block_append_allocated_mirror(struct mlxsw_afa_block *block, mlxsw_afa_block_append_allocated_mirror(struct mlxsw_afa_block *block,
u8 mirror_agent) u8 mirror_agent)
{ {
char *act = mlxsw_afa_block_append_action(block, char *act = mlxsw_afa_block_append_action_trap(block,
MLXSW_AFA_TRAP_CODE, MLXSW_AFA_TRAP_CODE,
MLXSW_AFA_TRAP_SIZE); MLXSW_AFA_TRAP_SIZE);
if (IS_ERR(act)) if (IS_ERR(act))
return PTR_ERR(act); return PTR_ERR(act);
mlxsw_afa_trap_pack(act, MLXSW_AFA_TRAP_TRAP_ACTION_NOP, mlxsw_afa_trap_pack(act, MLXSW_AFA_TRAP_TRAP_ACTION_NOP,
......
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