Skip to content

Commit 95f68e0

Browse files
mosheshemesh2kuba-moo
authored andcommitted
net/mlx5: fs, add counter object to flow destination
Currently mlx5_flow_destination includes counter_id which is assigned in case we use flow counter on the flow steering rule. However, counter_id is not enough data in case of using HW Steering. Thus, have mlx5_fc object as part of mlx5_flow_destination instead of counter_id and assign it where needed. In case counter_id is received from user space, create a local counter object to represent it. Signed-off-by: Moshe Shemesh <[email protected]> Reviewed-by: Yevgeny Kliteynik <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 60d01cc commit 95f68e0

File tree

15 files changed

+117
-44
lines changed

15 files changed

+117
-44
lines changed

drivers/infiniband/hw/mlx5/fs.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ int mlx5_ib_fs_add_op_fc(struct mlx5_ib_dev *dev, u32 port_num,
943943
}
944944

945945
dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
946-
dst.counter_id = mlx5_fc_id(opfc->fc);
946+
dst.counter = opfc->fc;
947947

948948
flow_act.action =
949949
MLX5_FLOW_CONTEXT_ACTION_COUNT | MLX5_FLOW_CONTEXT_ACTION_ALLOW;
@@ -1113,8 +1113,8 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
11131113
handler->ibcounters = flow_act.counters;
11141114
dest_arr[dest_num].type =
11151115
MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1116-
dest_arr[dest_num].counter_id =
1117-
mlx5_fc_id(mcounters->hw_cntrs_hndl);
1116+
dest_arr[dest_num].counter =
1117+
mcounters->hw_cntrs_hndl;
11181118
dest_num++;
11191119
}
11201120

@@ -1603,7 +1603,7 @@ static bool raw_fs_is_multicast(struct mlx5_ib_flow_matcher *fs_matcher,
16031603
static struct mlx5_ib_flow_handler *raw_fs_rule_add(
16041604
struct mlx5_ib_dev *dev, struct mlx5_ib_flow_matcher *fs_matcher,
16051605
struct mlx5_flow_context *flow_context, struct mlx5_flow_act *flow_act,
1606-
u32 counter_id, void *cmd_in, int inlen, int dest_id, int dest_type)
1606+
struct mlx5_fc *counter, void *cmd_in, int inlen, int dest_id, int dest_type)
16071607
{
16081608
struct mlx5_flow_destination *dst;
16091609
struct mlx5_ib_flow_prio *ft_prio;
@@ -1652,8 +1652,12 @@ static struct mlx5_ib_flow_handler *raw_fs_rule_add(
16521652
}
16531653

16541654
if (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
1655+
if (WARN_ON(!counter)) {
1656+
err = -EINVAL;
1657+
goto unlock;
1658+
}
16551659
dst[dst_num].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1656-
dst[dst_num].counter_id = counter_id;
1660+
dst[dst_num].counter = counter;
16571661
dst_num++;
16581662
}
16591663

@@ -1878,7 +1882,8 @@ static int get_dests(struct uverbs_attr_bundle *attrs,
18781882
return 0;
18791883
}
18801884

1881-
static bool is_flow_counter(void *obj, u32 offset, u32 *counter_id)
1885+
static bool
1886+
is_flow_counter(void *obj, u32 offset, u32 *counter_id, u32 *fc_bulk_size)
18821887
{
18831888
struct devx_obj *devx_obj = obj;
18841889
u16 opcode = MLX5_GET(general_obj_in_cmd_hdr, devx_obj->dinbox, opcode);
@@ -1888,6 +1893,7 @@ static bool is_flow_counter(void *obj, u32 offset, u32 *counter_id)
18881893
if (offset && offset >= devx_obj->flow_counter_bulk_size)
18891894
return false;
18901895

1896+
*fc_bulk_size = devx_obj->flow_counter_bulk_size;
18911897
*counter_id = MLX5_GET(dealloc_flow_counter_in,
18921898
devx_obj->dinbox,
18931899
flow_counter_id);
@@ -1904,13 +1910,13 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
19041910
{
19051911
struct mlx5_flow_context flow_context = {.flow_tag =
19061912
MLX5_FS_DEFAULT_FLOW_TAG};
1907-
u32 *offset_attr, offset = 0, counter_id = 0;
19081913
int dest_id, dest_type = -1, inlen, len, ret, i;
19091914
struct mlx5_ib_flow_handler *flow_handler;
19101915
struct mlx5_ib_flow_matcher *fs_matcher;
19111916
struct ib_uobject **arr_flow_actions;
19121917
struct ib_uflow_resources *uflow_res;
19131918
struct mlx5_flow_act flow_act = {};
1919+
struct mlx5_fc *counter = NULL;
19141920
struct ib_qp *qp = NULL;
19151921
void *devx_obj, *cmd_in;
19161922
struct ib_uobject *uobj;
@@ -1937,6 +1943,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
19371943
len = uverbs_attr_get_uobjs_arr(attrs,
19381944
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX, &arr_flow_actions);
19391945
if (len) {
1946+
u32 *offset_attr, fc_bulk_size, offset = 0, counter_id = 0;
19401947
devx_obj = arr_flow_actions[0]->object;
19411948

19421949
if (uverbs_attr_is_valid(attrs,
@@ -1956,8 +1963,11 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
19561963
offset = *offset_attr;
19571964
}
19581965

1959-
if (!is_flow_counter(devx_obj, offset, &counter_id))
1966+
if (!is_flow_counter(devx_obj, offset, &counter_id, &fc_bulk_size))
19601967
return -EINVAL;
1968+
counter = mlx5_fc_local_create(counter_id, offset, fc_bulk_size);
1969+
if (IS_ERR(counter))
1970+
return PTR_ERR(counter);
19611971

19621972
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
19631973
}
@@ -1968,8 +1978,10 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
19681978
MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);
19691979

19701980
uflow_res = flow_resources_alloc(MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS);
1971-
if (!uflow_res)
1972-
return -ENOMEM;
1981+
if (!uflow_res) {
1982+
ret = -ENOMEM;
1983+
goto destroy_counter;
1984+
}
19731985

19741986
len = uverbs_attr_get_uobjs_arr(attrs,
19751987
MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS, &arr_flow_actions);
@@ -1996,7 +2008,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
19962008

19972009
flow_handler =
19982010
raw_fs_rule_add(dev, fs_matcher, &flow_context, &flow_act,
1999-
counter_id, cmd_in, inlen, dest_id, dest_type);
2011+
counter, cmd_in, inlen, dest_id, dest_type);
20002012
if (IS_ERR(flow_handler)) {
20012013
ret = PTR_ERR(flow_handler);
20022014
goto err_out;
@@ -2007,6 +2019,9 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
20072019
return 0;
20082020
err_out:
20092021
ib_uverbs_flow_resources_free(uflow_res);
2022+
destroy_counter:
2023+
if (counter)
2024+
mlx5_fc_local_destroy(counter);
20102025
return ret;
20112026
}
20122027

drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ TRACE_EVENT(mlx5_fs_add_rule,
292292
if (rule->dest_attr.type &
293293
MLX5_FLOW_DESTINATION_TYPE_COUNTER)
294294
__entry->counter_id =
295-
rule->dest_attr.counter_id;
295+
mlx5_fc_id(rule->dest_attr.counter);
296296
),
297297
TP_printk("rule=%p fte=%p index=%u sw_action=<%s> [dst] %s\n",
298298
__entry->rule, __entry->fte, __entry->index,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int rx_add_rule_drop_auth_trailer(struct mlx5e_ipsec_sa_entry *sa_entry,
194194
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT;
195195
flow_act.flags = FLOW_ACT_NO_APPEND;
196196
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
197-
dest.counter_id = mlx5_fc_id(flow_counter);
197+
dest.counter = flow_counter;
198198
if (rx == ipsec->rx_esw)
199199
spec->flow_context.flow_source = MLX5_FLOW_CONTEXT_FLOW_SOURCE_UPLINK;
200200

@@ -223,7 +223,7 @@ static int rx_add_rule_drop_auth_trailer(struct mlx5e_ipsec_sa_entry *sa_entry,
223223
}
224224
sa_entry->ipsec_rule.trailer.fc = flow_counter;
225225

226-
dest.counter_id = mlx5_fc_id(flow_counter);
226+
dest.counter = flow_counter;
227227
MLX5_SET(fte_match_param, spec->match_value, misc_parameters_2.ipsec_syndrome, 2);
228228
rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
229229
if (IS_ERR(rule)) {
@@ -275,7 +275,7 @@ static int rx_add_rule_drop_replay(struct mlx5e_ipsec_sa_entry *sa_entry, struct
275275
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT;
276276
flow_act.flags = FLOW_ACT_NO_APPEND;
277277
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
278-
dest.counter_id = mlx5_fc_id(flow_counter);
278+
dest.counter = flow_counter;
279279
if (rx == ipsec->rx_esw)
280280
spec->flow_context.flow_source = MLX5_FLOW_CONTEXT_FLOW_SOURCE_UPLINK;
281281

@@ -348,7 +348,7 @@ static int ipsec_rx_status_drop_all_create(struct mlx5e_ipsec *ipsec,
348348

349349
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT;
350350
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
351-
dest.counter_id = mlx5_fc_id(flow_counter);
351+
dest.counter = flow_counter;
352352
if (rx == ipsec->rx_esw)
353353
spec->flow_context.flow_source = MLX5_FLOW_CONTEXT_FLOW_SOURCE_UPLINK;
354354
rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
@@ -686,7 +686,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
686686
rx->ft.status = ft;
687687

688688
dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
689-
dest[1].counter_id = mlx5_fc_id(rx->fc->cnt);
689+
dest[1].counter = rx->fc->cnt;
690690
err = mlx5_ipsec_rx_status_create(ipsec, rx, dest);
691691
if (err)
692692
goto err_add;
@@ -873,7 +873,7 @@ static int ipsec_counter_rule_tx(struct mlx5_core_dev *mdev, struct mlx5e_ipsec_
873873
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_ALLOW |
874874
MLX5_FLOW_CONTEXT_ACTION_COUNT;
875875
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
876-
dest.counter_id = mlx5_fc_id(tx->fc->cnt);
876+
dest.counter = tx->fc->cnt;
877877
fte = mlx5_add_flow_rules(tx->ft.status, spec, &flow_act, &dest, 1);
878878
if (IS_ERR(fte)) {
879879
err = PTR_ERR(fte);
@@ -1649,7 +1649,7 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
16491649
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
16501650
dest[0].ft = rx->ft.status;
16511651
dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1652-
dest[1].counter_id = mlx5_fc_id(counter);
1652+
dest[1].counter = counter;
16531653
rule = mlx5_add_flow_rules(rx->ft.sa, spec, &flow_act, dest, 2);
16541654
if (IS_ERR(rule)) {
16551655
err = PTR_ERR(rule);
@@ -1762,7 +1762,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
17621762
dest[0].ft = tx->ft.status;
17631763
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
17641764
dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1765-
dest[1].counter_id = mlx5_fc_id(counter);
1765+
dest[1].counter = counter;
17661766
rule = mlx5_add_flow_rules(tx->ft.sa, spec, &flow_act, dest, 2);
17671767
if (IS_ERR(rule)) {
17681768
err = PTR_ERR(rule);
@@ -1835,7 +1835,7 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
18351835
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_DROP |
18361836
MLX5_FLOW_CONTEXT_ACTION_COUNT;
18371837
dest[dstn].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1838-
dest[dstn].counter_id = mlx5_fc_id(tx->fc->drop);
1838+
dest[dstn].counter = tx->fc->drop;
18391839
dstn++;
18401840
break;
18411841
default:
@@ -1913,7 +1913,7 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
19131913
case XFRM_POLICY_BLOCK:
19141914
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT;
19151915
dest[dstn].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1916-
dest[dstn].counter_id = mlx5_fc_id(rx->fc->drop);
1916+
dest[dstn].counter = rx->fc->drop;
19171917
dstn++;
19181918
break;
19191919
default:

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ mlx5e_add_offloaded_nic_rule(struct mlx5e_priv *priv,
12821282

12831283
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
12841284
dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1285-
dest[dest_ix].counter_id = mlx5_fc_id(attr->counter);
1285+
dest[dest_ix].counter = attr->counter;
12861286
dest_ix++;
12871287
}
12881288

drivers/net/ethernet/mellanox/mlx5/core/esw/acl/egress_lgcy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int esw_acl_egress_lgcy_setup(struct mlx5_eswitch *esw,
135135
if (drop_counter) {
136136
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
137137
drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
138-
drop_ctr_dst.counter_id = mlx5_fc_id(drop_counter);
138+
drop_ctr_dst.counter = drop_counter;
139139
dst = &drop_ctr_dst;
140140
dest_num++;
141141
}

drivers/net/ethernet/mellanox/mlx5/core/esw/acl/ingress_lgcy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int esw_acl_ingress_lgcy_setup(struct mlx5_eswitch *esw,
260260
if (counter) {
261261
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
262262
drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
263-
drop_ctr_dst.counter_id = mlx5_fc_id(counter);
263+
drop_ctr_dst.counter = counter;
264264
dst = &drop_ctr_dst;
265265
dest_num++;
266266
}

drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ mlx5_esw_bridge_egress_table_cleanup(struct mlx5_esw_bridge *bridge)
570570

571571
static struct mlx5_flow_handle *
572572
mlx5_esw_bridge_ingress_flow_with_esw_create(u16 vport_num, const unsigned char *addr,
573-
struct mlx5_esw_bridge_vlan *vlan, u32 counter_id,
573+
struct mlx5_esw_bridge_vlan *vlan,
574+
struct mlx5_fc *counter,
574575
struct mlx5_esw_bridge *bridge,
575576
struct mlx5_eswitch *esw)
576577
{
@@ -628,7 +629,7 @@ mlx5_esw_bridge_ingress_flow_with_esw_create(u16 vport_num, const unsigned char
628629
dests[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
629630
dests[0].ft = bridge->egress_ft;
630631
dests[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
631-
dests[1].counter_id = counter_id;
632+
dests[1].counter = counter;
632633

633634
handle = mlx5_add_flow_rules(br_offloads->ingress_ft, rule_spec, &flow_act, dests,
634635
ARRAY_SIZE(dests));
@@ -639,17 +640,19 @@ mlx5_esw_bridge_ingress_flow_with_esw_create(u16 vport_num, const unsigned char
639640

640641
static struct mlx5_flow_handle *
641642
mlx5_esw_bridge_ingress_flow_create(u16 vport_num, const unsigned char *addr,
642-
struct mlx5_esw_bridge_vlan *vlan, u32 counter_id,
643+
struct mlx5_esw_bridge_vlan *vlan,
644+
struct mlx5_fc *counter,
643645
struct mlx5_esw_bridge *bridge)
644646
{
645-
return mlx5_esw_bridge_ingress_flow_with_esw_create(vport_num, addr, vlan, counter_id,
647+
return mlx5_esw_bridge_ingress_flow_with_esw_create(vport_num, addr, vlan, counter,
646648
bridge, bridge->br_offloads->esw);
647649
}
648650

649651
static struct mlx5_flow_handle *
650652
mlx5_esw_bridge_ingress_flow_peer_create(u16 vport_num, u16 esw_owner_vhca_id,
651653
const unsigned char *addr,
652-
struct mlx5_esw_bridge_vlan *vlan, u32 counter_id,
654+
struct mlx5_esw_bridge_vlan *vlan,
655+
struct mlx5_fc *counter,
653656
struct mlx5_esw_bridge *bridge)
654657
{
655658
struct mlx5_devcom_comp_dev *devcom = bridge->br_offloads->esw->devcom, *pos;
@@ -671,7 +674,7 @@ mlx5_esw_bridge_ingress_flow_peer_create(u16 vport_num, u16 esw_owner_vhca_id,
671674
goto out;
672675
}
673676

674-
handle = mlx5_esw_bridge_ingress_flow_with_esw_create(vport_num, addr, vlan, counter_id,
677+
handle = mlx5_esw_bridge_ingress_flow_with_esw_create(vport_num, addr, vlan, counter,
675678
bridge, peer_esw);
676679

677680
out:
@@ -1385,10 +1388,9 @@ mlx5_esw_bridge_fdb_entry_init(struct net_device *dev, u16 vport_num, u16 esw_ow
13851388

13861389
handle = peer ?
13871390
mlx5_esw_bridge_ingress_flow_peer_create(vport_num, esw_owner_vhca_id,
1388-
addr, vlan, mlx5_fc_id(counter),
1389-
bridge) :
1391+
addr, vlan, counter, bridge) :
13901392
mlx5_esw_bridge_ingress_flow_create(vport_num, addr, vlan,
1391-
mlx5_fc_id(counter), bridge);
1393+
counter, bridge);
13921394
if (IS_ERR(handle)) {
13931395
err = PTR_ERR(handle);
13941396
esw_warn(esw->dev, "Failed to create ingress flow(vport=%u,err=%d,peer=%d)\n",

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
724724

725725
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
726726
dest[i].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
727-
dest[i].counter_id = mlx5_fc_id(attr->counter);
727+
dest[i].counter = attr->counter;
728728
i++;
729729
}
730730

drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
718718
continue;
719719

720720
MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
721-
dst->dest_attr.counter_id);
721+
mlx5_fc_id(dst->dest_attr.counter));
722722
in_dests += dst_cnt_size;
723723
list_size++;
724724
}

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ static void del_sw_hw_rule(struct fs_node *node)
658658
BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_ACTION) |
659659
BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_FLOW_COUNTERS);
660660
fte->act_dests.action.action &= ~MLX5_FLOW_CONTEXT_ACTION_COUNT;
661+
mlx5_fc_local_destroy(rule->dest_attr.counter);
661662
goto out;
662663
}
663664

0 commit comments

Comments
 (0)