Skip to content

Commit

Permalink
net/mlx5e: TC, init post meter rules with branching attributes
Browse files Browse the repository at this point in the history
Instantiate the post meter actions with the platform initialized branching
action attributes.

Signed-off-by: Oz Shlomo <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
ozshlomo authored and kuba-moo committed Dec 8, 2022
1 parent 3fcb94e commit 0d8c38d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 34 deletions.
84 changes: 57 additions & 27 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ struct mlx5e_post_meter_priv {
struct mlx5_flow_table *ft;
struct mlx5_flow_group *fg;
struct mlx5_flow_handle *green_rule;
struct mlx5_flow_attr *green_attr;
struct mlx5_flow_handle *red_rule;
struct mlx5_flow_attr *red_attr;
};

struct mlx5_flow_table *
Expand Down Expand Up @@ -81,15 +83,48 @@ mlx5e_post_meter_fg_create(struct mlx5e_priv *priv,
return err;
}

static struct mlx5_flow_handle *
mlx5e_post_meter_add_rule(struct mlx5e_priv *priv,
struct mlx5e_post_meter_priv *post_meter,
struct mlx5_flow_spec *spec,
struct mlx5_flow_attr *attr,
struct mlx5_fc *act_counter,
struct mlx5_fc *drop_counter)
{
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
struct mlx5_flow_handle *ret;

attr->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_DROP)
attr->counter = drop_counter;
else
attr->counter = act_counter;

attr->ft = post_meter->ft;
attr->flags |= MLX5_ATTR_FLAG_NO_IN_PORT;
attr->outer_match_level = MLX5_MATCH_NONE;
attr->chain = 0;
attr->prio = 0;

ret = mlx5_eswitch_add_offloaded_rule(esw, spec, attr);

/* We did not create the counter, so we can't delete it.
* Avoid freeing the counter when the attr is deleted in free_branching_attr
*/
attr->action &= ~MLX5_FLOW_CONTEXT_ACTION_COUNT;

return ret;
}

static int
mlx5e_post_meter_rules_create(struct mlx5e_priv *priv,
struct mlx5e_post_meter_priv *post_meter,
struct mlx5e_post_act *post_act,
struct mlx5_fc *act_counter,
struct mlx5_fc *drop_counter)
struct mlx5_fc *drop_counter,
struct mlx5_flow_attr *green_attr,
struct mlx5_flow_attr *red_attr)
{
struct mlx5_flow_destination dest[2] = {};
struct mlx5_flow_act flow_act = {};
struct mlx5_flow_handle *rule;
struct mlx5_flow_spec *spec;
int err;
Expand All @@ -100,36 +135,28 @@ mlx5e_post_meter_rules_create(struct mlx5e_priv *priv,

mlx5e_tc_match_to_reg_match(spec, PACKET_COLOR_TO_REG,
MLX5_FLOW_METER_COLOR_RED, MLX5_PACKET_COLOR_MASK);
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP |
MLX5_FLOW_CONTEXT_ACTION_COUNT;
flow_act.flags |= FLOW_ACT_IGNORE_FLOW_LEVEL;
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
dest[0].counter_id = mlx5_fc_id(drop_counter);

rule = mlx5_add_flow_rules(post_meter->ft, spec, &flow_act, dest, 1);
rule = mlx5e_post_meter_add_rule(priv, post_meter, spec, red_attr,
act_counter, drop_counter);
if (IS_ERR(rule)) {
mlx5_core_warn(priv->mdev, "Failed to create post_meter flow drop rule\n");
mlx5_core_warn(priv->mdev, "Failed to create post_meter exceed rule\n");
err = PTR_ERR(rule);
goto err_red;
}
post_meter->red_rule = rule;
post_meter->red_attr = red_attr;

mlx5e_tc_match_to_reg_match(spec, PACKET_COLOR_TO_REG,
MLX5_FLOW_METER_COLOR_GREEN, MLX5_PACKET_COLOR_MASK);
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
MLX5_FLOW_CONTEXT_ACTION_COUNT;
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
dest[0].ft = mlx5e_tc_post_act_get_ft(post_act);
dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
dest[1].counter_id = mlx5_fc_id(act_counter);

rule = mlx5_add_flow_rules(post_meter->ft, spec, &flow_act, dest, 2);
rule = mlx5e_post_meter_add_rule(priv, post_meter, spec, green_attr,
act_counter, drop_counter);
if (IS_ERR(rule)) {
mlx5_core_warn(priv->mdev, "Failed to create post_meter flow fwd rule\n");
mlx5_core_warn(priv->mdev, "Failed to create post_meter notexceed rule\n");
err = PTR_ERR(rule);
goto err_green;
}
post_meter->green_rule = rule;
post_meter->green_attr = green_attr;

kvfree(spec);
return 0;
Expand All @@ -142,10 +169,11 @@ mlx5e_post_meter_rules_create(struct mlx5e_priv *priv,
}

static void
mlx5e_post_meter_rules_destroy(struct mlx5e_post_meter_priv *post_meter)
mlx5e_post_meter_rules_destroy(struct mlx5_eswitch *esw,
struct mlx5e_post_meter_priv *post_meter)
{
mlx5_del_flow_rules(post_meter->red_rule);
mlx5_del_flow_rules(post_meter->green_rule);
mlx5_eswitch_del_offloaded_rule(esw, post_meter->red_rule, post_meter->red_attr);
mlx5_eswitch_del_offloaded_rule(esw, post_meter->green_rule, post_meter->green_attr);
}

static void
Expand All @@ -165,7 +193,9 @@ mlx5e_post_meter_init(struct mlx5e_priv *priv,
enum mlx5_flow_namespace_type ns_type,
struct mlx5e_post_act *post_act,
struct mlx5_fc *act_counter,
struct mlx5_fc *drop_counter)
struct mlx5_fc *drop_counter,
struct mlx5_flow_attr *branch_true,
struct mlx5_flow_attr *branch_false)
{
struct mlx5e_post_meter_priv *post_meter;
int err;
Expand All @@ -182,8 +212,8 @@ mlx5e_post_meter_init(struct mlx5e_priv *priv,
if (err)
goto err_fg;

err = mlx5e_post_meter_rules_create(priv, post_meter, post_act,
act_counter, drop_counter);
err = mlx5e_post_meter_rules_create(priv, post_meter, post_act, act_counter,
drop_counter, branch_true, branch_false);
if (err)
goto err_rules;

Expand All @@ -199,9 +229,9 @@ mlx5e_post_meter_init(struct mlx5e_priv *priv,
}

void
mlx5e_post_meter_cleanup(struct mlx5e_post_meter_priv *post_meter)
mlx5e_post_meter_cleanup(struct mlx5_eswitch *esw, struct mlx5e_post_meter_priv *post_meter)
{
mlx5e_post_meter_rules_destroy(post_meter);
mlx5e_post_meter_rules_destroy(esw, post_meter);
mlx5e_post_meter_fg_destroy(post_meter);
mlx5e_post_meter_table_destroy(post_meter);
kfree(post_meter);
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ mlx5e_post_meter_init(struct mlx5e_priv *priv,
enum mlx5_flow_namespace_type ns_type,
struct mlx5e_post_act *post_act,
struct mlx5_fc *act_counter,
struct mlx5_fc *drop_counter);
struct mlx5_fc *drop_counter,
struct mlx5_flow_attr *branch_true,
struct mlx5_flow_attr *branch_false);
void
mlx5e_post_meter_cleanup(struct mlx5e_post_meter_priv *post_meter);
mlx5e_post_meter_cleanup(struct mlx5_eswitch *esw, struct mlx5e_post_meter_priv *post_meter);

#endif /* __MLX5_EN_POST_METER_H__ */
11 changes: 6 additions & 5 deletions drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ mlx5e_tc_add_flow_meter(struct mlx5e_priv *priv,
}

ns_type = mlx5e_tc_meter_get_namespace(meter->flow_meters);
post_meter = mlx5e_post_meter_init(priv, ns_type, post_act, meter->act_counter,
meter->drop_counter);
post_meter = mlx5e_post_meter_init(priv, ns_type, post_act,
meter->act_counter, meter->drop_counter,
attr->branch_true, attr->branch_false);
if (IS_ERR(post_meter)) {
mlx5_core_err(priv->mdev, "Failed to init post meter\n");
goto err_meter_init;
Expand All @@ -442,9 +443,9 @@ mlx5e_tc_add_flow_meter(struct mlx5e_priv *priv,
}

static void
mlx5e_tc_del_flow_meter(struct mlx5_flow_attr *attr)
mlx5e_tc_del_flow_meter(struct mlx5_eswitch *esw, struct mlx5_flow_attr *attr)
{
mlx5e_post_meter_cleanup(attr->meter_attr.post_meter);
mlx5e_post_meter_cleanup(esw, attr->meter_attr.post_meter);
mlx5e_tc_meter_put(attr->meter_attr.meter);
}

Expand Down Expand Up @@ -505,7 +506,7 @@ mlx5e_tc_rule_unoffload(struct mlx5e_priv *priv,
mlx5_eswitch_del_offloaded_rule(esw, rule, attr);

if (attr->meter_attr.meter)
mlx5e_tc_del_flow_meter(attr);
mlx5e_tc_del_flow_meter(esw, attr);
}

int
Expand Down

0 comments on commit 0d8c38d

Please sign in to comment.