Skip to content

mlx5: Misc. improvements #1636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions providers/mlx5/dr_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
struct mlx5dv_dr_action *actions[],
size_t num_actions,
struct mlx5dv_flow_action_attr *attr,
struct mlx5_flow_action_attr_aux *attr_aux)
struct mlx5dv_flow_action_attr *attr)
{
struct mlx5dv_dr_domain *dmn = matcher->tbl->dmn;
int i;
Expand Down Expand Up @@ -1026,8 +1025,8 @@ int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
attr[i].obj = actions[i]->ctr.devx_obj;

if (actions[i]->ctr.offset) {
attr_aux[i].type = MLX5_FLOW_ACTION_COUNTER_OFFSET;
attr_aux[i].offset = actions[i]->ctr.offset;
attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET;
attr[i].bulk_obj.offset = actions[i]->ctr.offset;
}
break;
case DR_ACTION_TYP_TAG:
Expand Down
21 changes: 5 additions & 16 deletions providers/mlx5/dr_rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,6 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
struct mlx5dv_dr_action *actions[])
{
struct mlx5dv_flow_action_attr *attr;
struct mlx5_flow_action_attr_aux *attr_aux;
struct mlx5dv_dr_rule *rule;
int ret;

Expand All @@ -1570,37 +1569,27 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
goto free_rule;
}

attr_aux = calloc(num_actions, sizeof(*attr_aux));
if (!attr_aux) {
errno = ENOMEM;
goto free_attr;
}

ret = dr_actions_build_attr(matcher, actions, num_actions, attr, attr_aux);
ret = dr_actions_build_attr(matcher, actions, num_actions, attr);
if (ret)
goto free_attr_aux;
goto free_attr;

ret = dr_rule_add_action_members(rule, num_actions, actions);
if (ret)
goto free_attr_aux;
goto free_attr;

rule->flow = _mlx5dv_create_flow(matcher->dv_matcher,
rule->flow = mlx5dv_create_flow(matcher->dv_matcher,
value,
num_actions,
attr,
attr_aux);
attr);
if (!rule->flow)
goto remove_action_members;

free(attr);
free(attr_aux);

return rule;

remove_action_members:
dr_rule_remove_action_members(rule);
free_attr_aux:
free(attr_aux);
free_attr:
free(attr);
free_rule:
Expand Down
13 changes: 12 additions & 1 deletion providers/mlx5/man/mlx5dv_create_flow.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct mlx5dv_flow_action_attr {
struct ibv_flow_action *action;
uint32_t tag_value;
struct mlx5dv_devx_obj *obj;
struct {
struct mlx5dv_devx_obj *obj;
uint32_t offset;
} bulk_obj;
};
};
```
Expand All @@ -65,6 +69,8 @@ struct mlx5dv_flow_action_attr {
Steer the packet to the default miss destination.
MLX5DV_FLOW_ACTION_DROP
Action is dropping the matched packet.
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET
The DEVX bulk counter object and its counter offset for the matched packets.

*qp*
: QP passed, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_IBV_QP*.
Expand All @@ -78,7 +84,12 @@ struct mlx5dv_flow_action_attr {
*MLX5DV_FLOW_ACTION_TAG* see *ibv_create_cq_ex(3)*.

*obj*
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*.
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*
or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*.

*offset*
: offset to the target counter within a bulk DEVX object, to be used with *type*
*MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*

# RETURN VALUE

Expand Down
13 changes: 6 additions & 7 deletions providers/mlx5/mlx5.h
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,7 @@ struct ibv_flow *
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
struct mlx5dv_flow_match_parameters *match_value,
size_t num_actions,
struct mlx5dv_flow_action_attr actions_attr[],
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
struct mlx5dv_flow_action_attr actions_attr[]);

extern int mlx5_stall_num_loop;
extern int mlx5_stall_cq_poll_min;
Expand Down Expand Up @@ -1586,11 +1585,11 @@ struct mlx5_dv_context_ops {
struct mlx5dv_flow_matcher *(*create_flow_matcher)(struct ibv_context *context,
struct mlx5dv_flow_matcher_attr *attr);
int (*destroy_flow_matcher)(struct mlx5dv_flow_matcher *flow_matcher);
struct ibv_flow *(*create_flow)(struct mlx5dv_flow_matcher *flow_matcher,
struct mlx5dv_flow_match_parameters *match_value,
size_t num_actions,
struct mlx5dv_flow_action_attr actions_attr[],
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
struct ibv_flow *(*create_flow)(
struct mlx5dv_flow_matcher *flow_matcher,
struct mlx5dv_flow_match_parameters *match_value,
size_t num_actions,
struct mlx5dv_flow_action_attr actions_attr[]);

struct mlx5dv_steering_anchor *(*create_steering_anchor)(struct ibv_context *conterxt,
struct mlx5dv_steering_anchor_attr *attr);
Expand Down
5 changes: 5 additions & 0 deletions providers/mlx5/mlx5dv.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ enum mlx5dv_flow_action_type {
MLX5DV_FLOW_ACTION_DEST_DEVX,
MLX5DV_FLOW_ACTION_COUNTERS_DEVX,
MLX5DV_FLOW_ACTION_DEFAULT_MISS,
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET,
};

struct mlx5dv_flow_action_attr {
Expand All @@ -793,6 +794,10 @@ struct mlx5dv_flow_action_attr {
struct ibv_flow_action *action;
uint32_t tag_value;
struct mlx5dv_devx_obj *obj;
struct {
struct mlx5dv_devx_obj *obj;
uint32_t offset;
} bulk_obj;
};
};

Expand Down
3 changes: 1 addition & 2 deletions providers/mlx5/mlx5dv_dr.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
struct mlx5dv_dr_action *actions[],
size_t num_actions,
struct mlx5dv_flow_action_attr *attr,
struct mlx5_flow_action_attr_aux *attr_aux);
struct mlx5dv_flow_action_attr *attr);

uint32_t dr_actions_reformat_get_id(struct mlx5dv_dr_action *action);

Expand Down
40 changes: 26 additions & 14 deletions providers/mlx5/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ static void mlx5_detach_dedicated_uar(struct ibv_context *context, struct mlx5_b

struct ibv_td *mlx5_alloc_td(struct ibv_context *context, struct ibv_td_init_attr *init_attr)
{
struct mlx5_context *ctx = to_mctx(context);
struct mlx5_td *td;

if (init_attr->comp_mask) {
Expand All @@ -461,7 +462,12 @@ struct ibv_td *mlx5_alloc_td(struct ibv_context *context, struct ibv_td_init_att
return NULL;
}

td->bf = mlx5_attach_dedicated_uar(context, 0);
/* Check whether BlueFlame is supported on the device */
if (ctx->bf_reg_size)
td->bf = mlx5_attach_dedicated_uar(context, 0);
else
td->bf = ctx->nc_uar;

if (!td->bf) {
free(td);
return NULL;
Expand All @@ -481,7 +487,8 @@ int mlx5_dealloc_td(struct ibv_td *ib_td)
if (atomic_load(&td->refcount) > 1)
return EBUSY;

mlx5_detach_dedicated_uar(ib_td->context, td->bf);
if (!td->bf->singleton)
mlx5_detach_dedicated_uar(ib_td->context, td->bf);
free(td);

return 0;
Expand Down Expand Up @@ -5615,8 +5622,7 @@ struct ibv_flow *
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
struct mlx5dv_flow_match_parameters *match_value,
size_t num_actions,
struct mlx5dv_flow_action_attr actions_attr[],
struct mlx5_flow_action_attr_aux actions_attr_aux[])
struct mlx5dv_flow_action_attr actions_attr[])
{
uint32_t flow_actions[CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED];
struct verbs_flow_action *vaction;
Expand All @@ -5626,6 +5632,7 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
bool have_dest_devx = false;
bool have_flow_tag = false;
bool have_counter = false;
bool have_bulk_counter = false;
bool have_default = false;
bool have_drop = false;
int ret;
Expand Down Expand Up @@ -5695,20 +5702,13 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
have_flow_tag = true;
break;
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX:
if (have_counter) {
if (have_counter || have_bulk_counter) {
errno = EOPNOTSUPP;
goto err;
}
fill_attr_in_objs_arr(cmd,
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
&actions_attr[i].obj->handle, 1);

if (actions_attr_aux &&
actions_attr_aux[i].type == MLX5_FLOW_ACTION_COUNTER_OFFSET)
fill_attr_in_ptr_array(cmd,
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
&actions_attr_aux[i].offset, 1);

have_counter = true;
break;
case MLX5DV_FLOW_ACTION_DEFAULT_MISS:
Expand All @@ -5733,6 +5733,19 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
MLX5_IB_ATTR_CREATE_FLOW_FLAGS_DROP);
have_drop = true;
break;
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET:
if (have_counter || have_bulk_counter) {
errno = EOPNOTSUPP;
goto err;
}
fill_attr_in_objs_arr(cmd,
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
&actions_attr[i].bulk_obj.obj->handle, 1);
fill_attr_in_ptr_array(cmd,
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
&actions_attr[i].bulk_obj.offset, 1);
have_bulk_counter = true;
break;
default:
errno = EOPNOTSUPP;
goto err;
Expand Down Expand Up @@ -5772,8 +5785,7 @@ mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
return dvops->create_flow(flow_matcher,
match_value,
num_actions,
actions_attr,
NULL);
actions_attr);
}

static struct mlx5dv_steering_anchor *
Expand Down