Skip to content

Commit 7a04b9e

Browse files
authored
Merge pull request #1636 from yishaih/mlx5_misc
mlx5: Misc. improvements
2 parents 091ddb5 + ec3d7f5 commit 7a04b9e

File tree

7 files changed

+58
-44
lines changed

7 files changed

+58
-44
lines changed

providers/mlx5/dr_action.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
975975
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
976976
struct mlx5dv_dr_action *actions[],
977977
size_t num_actions,
978-
struct mlx5dv_flow_action_attr *attr,
979-
struct mlx5_flow_action_attr_aux *attr_aux)
978+
struct mlx5dv_flow_action_attr *attr)
980979
{
981980
struct mlx5dv_dr_domain *dmn = matcher->tbl->dmn;
982981
int i;
@@ -1026,8 +1025,8 @@ int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
10261025
attr[i].obj = actions[i]->ctr.devx_obj;
10271026

10281027
if (actions[i]->ctr.offset) {
1029-
attr_aux[i].type = MLX5_FLOW_ACTION_COUNTER_OFFSET;
1030-
attr_aux[i].offset = actions[i]->ctr.offset;
1028+
attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET;
1029+
attr[i].bulk_obj.offset = actions[i]->ctr.offset;
10311030
}
10321031
break;
10331032
case DR_ACTION_TYP_TAG:

providers/mlx5/dr_rule.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,6 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
15521552
struct mlx5dv_dr_action *actions[])
15531553
{
15541554
struct mlx5dv_flow_action_attr *attr;
1555-
struct mlx5_flow_action_attr_aux *attr_aux;
15561555
struct mlx5dv_dr_rule *rule;
15571556
int ret;
15581557

@@ -1570,37 +1569,27 @@ dr_rule_create_rule_root(struct mlx5dv_dr_matcher *matcher,
15701569
goto free_rule;
15711570
}
15721571

1573-
attr_aux = calloc(num_actions, sizeof(*attr_aux));
1574-
if (!attr_aux) {
1575-
errno = ENOMEM;
1576-
goto free_attr;
1577-
}
1578-
1579-
ret = dr_actions_build_attr(matcher, actions, num_actions, attr, attr_aux);
1572+
ret = dr_actions_build_attr(matcher, actions, num_actions, attr);
15801573
if (ret)
1581-
goto free_attr_aux;
1574+
goto free_attr;
15821575

15831576
ret = dr_rule_add_action_members(rule, num_actions, actions);
15841577
if (ret)
1585-
goto free_attr_aux;
1578+
goto free_attr;
15861579

1587-
rule->flow = _mlx5dv_create_flow(matcher->dv_matcher,
1580+
rule->flow = mlx5dv_create_flow(matcher->dv_matcher,
15881581
value,
15891582
num_actions,
1590-
attr,
1591-
attr_aux);
1583+
attr);
15921584
if (!rule->flow)
15931585
goto remove_action_members;
15941586

15951587
free(attr);
1596-
free(attr_aux);
15971588

15981589
return rule;
15991590

16001591
remove_action_members:
16011592
dr_rule_remove_action_members(rule);
1602-
free_attr_aux:
1603-
free(attr_aux);
16041593
free_attr:
16051594
free(attr);
16061595
free_rule:

providers/mlx5/man/mlx5dv_create_flow.3.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct mlx5dv_flow_action_attr {
4646
struct ibv_flow_action *action;
4747
uint32_t tag_value;
4848
struct mlx5dv_devx_obj *obj;
49+
struct {
50+
struct mlx5dv_devx_obj *obj;
51+
uint32_t offset;
52+
} bulk_obj;
4953
};
5054
};
5155
```
@@ -65,6 +69,8 @@ struct mlx5dv_flow_action_attr {
6569
Steer the packet to the default miss destination.
6670
MLX5DV_FLOW_ACTION_DROP
6771
Action is dropping the matched packet.
72+
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET
73+
The DEVX bulk counter object and its counter offset for the matched packets.
6874

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

8086
*obj*
81-
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*.
87+
: DEVX object, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_DEVX* or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX*
88+
or by *MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*.
89+
90+
*offset*
91+
: offset to the target counter within a bulk DEVX object, to be used with *type*
92+
*MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET*
8293

8394
# RETURN VALUE
8495

providers/mlx5/mlx5.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ struct ibv_flow *
962962
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
963963
struct mlx5dv_flow_match_parameters *match_value,
964964
size_t num_actions,
965-
struct mlx5dv_flow_action_attr actions_attr[],
966-
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
965+
struct mlx5dv_flow_action_attr actions_attr[]);
967966

968967
extern int mlx5_stall_num_loop;
969968
extern int mlx5_stall_cq_poll_min;
@@ -1586,11 +1585,11 @@ struct mlx5_dv_context_ops {
15861585
struct mlx5dv_flow_matcher *(*create_flow_matcher)(struct ibv_context *context,
15871586
struct mlx5dv_flow_matcher_attr *attr);
15881587
int (*destroy_flow_matcher)(struct mlx5dv_flow_matcher *flow_matcher);
1589-
struct ibv_flow *(*create_flow)(struct mlx5dv_flow_matcher *flow_matcher,
1590-
struct mlx5dv_flow_match_parameters *match_value,
1591-
size_t num_actions,
1592-
struct mlx5dv_flow_action_attr actions_attr[],
1593-
struct mlx5_flow_action_attr_aux actions_attr_aux[]);
1588+
struct ibv_flow *(*create_flow)(
1589+
struct mlx5dv_flow_matcher *flow_matcher,
1590+
struct mlx5dv_flow_match_parameters *match_value,
1591+
size_t num_actions,
1592+
struct mlx5dv_flow_action_attr actions_attr[]);
15941593

15951594
struct mlx5dv_steering_anchor *(*create_steering_anchor)(struct ibv_context *conterxt,
15961595
struct mlx5dv_steering_anchor_attr *attr);

providers/mlx5/mlx5dv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ enum mlx5dv_flow_action_type {
783783
MLX5DV_FLOW_ACTION_DEST_DEVX,
784784
MLX5DV_FLOW_ACTION_COUNTERS_DEVX,
785785
MLX5DV_FLOW_ACTION_DEFAULT_MISS,
786+
MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET,
786787
};
787788

788789
struct mlx5dv_flow_action_attr {
@@ -793,6 +794,10 @@ struct mlx5dv_flow_action_attr {
793794
struct ibv_flow_action *action;
794795
uint32_t tag_value;
795796
struct mlx5dv_devx_obj *obj;
797+
struct {
798+
struct mlx5dv_devx_obj *obj;
799+
uint32_t offset;
800+
} bulk_obj;
796801
};
797802
};
798803

providers/mlx5/mlx5dv_dr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ int dr_actions_build_ste_arr(struct mlx5dv_dr_matcher *matcher,
691691
int dr_actions_build_attr(struct mlx5dv_dr_matcher *matcher,
692692
struct mlx5dv_dr_action *actions[],
693693
size_t num_actions,
694-
struct mlx5dv_flow_action_attr *attr,
695-
struct mlx5_flow_action_attr_aux *attr_aux);
694+
struct mlx5dv_flow_action_attr *attr);
696695

697696
uint32_t dr_actions_reformat_get_id(struct mlx5dv_dr_action *action);
698697

providers/mlx5/verbs.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static void mlx5_detach_dedicated_uar(struct ibv_context *context, struct mlx5_b
448448

449449
struct ibv_td *mlx5_alloc_td(struct ibv_context *context, struct ibv_td_init_attr *init_attr)
450450
{
451+
struct mlx5_context *ctx = to_mctx(context);
451452
struct mlx5_td *td;
452453

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

464-
td->bf = mlx5_attach_dedicated_uar(context, 0);
465+
/* Check whether BlueFlame is supported on the device */
466+
if (ctx->bf_reg_size)
467+
td->bf = mlx5_attach_dedicated_uar(context, 0);
468+
else
469+
td->bf = ctx->nc_uar;
470+
465471
if (!td->bf) {
466472
free(td);
467473
return NULL;
@@ -481,7 +487,8 @@ int mlx5_dealloc_td(struct ibv_td *ib_td)
481487
if (atomic_load(&td->refcount) > 1)
482488
return EBUSY;
483489

484-
mlx5_detach_dedicated_uar(ib_td->context, td->bf);
490+
if (!td->bf->singleton)
491+
mlx5_detach_dedicated_uar(ib_td->context, td->bf);
485492
free(td);
486493

487494
return 0;
@@ -5615,8 +5622,7 @@ struct ibv_flow *
56155622
_mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56165623
struct mlx5dv_flow_match_parameters *match_value,
56175624
size_t num_actions,
5618-
struct mlx5dv_flow_action_attr actions_attr[],
5619-
struct mlx5_flow_action_attr_aux actions_attr_aux[])
5625+
struct mlx5dv_flow_action_attr actions_attr[])
56205626
{
56215627
uint32_t flow_actions[CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED];
56225628
struct verbs_flow_action *vaction;
@@ -5626,6 +5632,7 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56265632
bool have_dest_devx = false;
56275633
bool have_flow_tag = false;
56285634
bool have_counter = false;
5635+
bool have_bulk_counter = false;
56295636
bool have_default = false;
56305637
bool have_drop = false;
56315638
int ret;
@@ -5695,20 +5702,13 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
56955702
have_flow_tag = true;
56965703
break;
56975704
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX:
5698-
if (have_counter) {
5705+
if (have_counter || have_bulk_counter) {
56995706
errno = EOPNOTSUPP;
57005707
goto err;
57015708
}
57025709
fill_attr_in_objs_arr(cmd,
57035710
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
57045711
&actions_attr[i].obj->handle, 1);
5705-
5706-
if (actions_attr_aux &&
5707-
actions_attr_aux[i].type == MLX5_FLOW_ACTION_COUNTER_OFFSET)
5708-
fill_attr_in_ptr_array(cmd,
5709-
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
5710-
&actions_attr_aux[i].offset, 1);
5711-
57125712
have_counter = true;
57135713
break;
57145714
case MLX5DV_FLOW_ACTION_DEFAULT_MISS:
@@ -5733,6 +5733,19 @@ _mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
57335733
MLX5_IB_ATTR_CREATE_FLOW_FLAGS_DROP);
57345734
have_drop = true;
57355735
break;
5736+
case MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET:
5737+
if (have_counter || have_bulk_counter) {
5738+
errno = EOPNOTSUPP;
5739+
goto err;
5740+
}
5741+
fill_attr_in_objs_arr(cmd,
5742+
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX,
5743+
&actions_attr[i].bulk_obj.obj->handle, 1);
5744+
fill_attr_in_ptr_array(cmd,
5745+
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET,
5746+
&actions_attr[i].bulk_obj.offset, 1);
5747+
have_bulk_counter = true;
5748+
break;
57365749
default:
57375750
errno = EOPNOTSUPP;
57385751
goto err;
@@ -5772,8 +5785,7 @@ mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
57725785
return dvops->create_flow(flow_matcher,
57735786
match_value,
57745787
num_actions,
5775-
actions_attr,
5776-
NULL);
5788+
actions_attr);
57775789
}
57785790

57795791
static struct mlx5dv_steering_anchor *

0 commit comments

Comments
 (0)