Skip to content

Commit e7e2519

Browse files
maorgottliebSaeed Mahameed
authored andcommitted
net/mlx5: Add support to create match definer
Introduce new APIs to create and destroy flow matcher for given format id. Flow match definer object is used for defining the fields and mask used for the hash calculation. User should mask the desired fields like done in the match criteria. This object is assigned to flow group of type hash. In this flow group type, packets lookup is done based on the hash result. This patch also adds the required bits to create such flow group. Signed-off-by: Maor Gottlieb <maorg@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent 425a563 commit e7e2519

File tree

7 files changed

+380
-27
lines changed

7 files changed

+380
-27
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master,
185185
return mlx5_cmd_exec(slave, in, sizeof(in), out, sizeof(out));
186186
}
187187

188+
static int
189+
mlx5_cmd_stub_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
190+
int definer_id)
191+
{
192+
return 0;
193+
}
194+
195+
static int
196+
mlx5_cmd_stub_create_match_definer(struct mlx5_flow_root_namespace *ns,
197+
u16 format_id, u32 *match_mask)
198+
{
199+
return 0;
200+
}
201+
188202
static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
189203
struct mlx5_flow_table *ft, u32 underlay_qpn,
190204
bool disconnect)
@@ -909,6 +923,45 @@ static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
909923
mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in);
910924
}
911925

926+
static int mlx5_cmd_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
927+
int definer_id)
928+
{
929+
u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {};
930+
u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
931+
932+
MLX5_SET(general_obj_in_cmd_hdr, in, opcode,
933+
MLX5_CMD_OP_DESTROY_GENERAL_OBJECT);
934+
MLX5_SET(general_obj_in_cmd_hdr, in, obj_type,
935+
MLX5_OBJ_TYPE_MATCH_DEFINER);
936+
MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, definer_id);
937+
938+
return mlx5_cmd_exec(ns->dev, in, sizeof(in), out, sizeof(out));
939+
}
940+
941+
static int mlx5_cmd_create_match_definer(struct mlx5_flow_root_namespace *ns,
942+
u16 format_id, u32 *match_mask)
943+
{
944+
u32 out[MLX5_ST_SZ_DW(create_match_definer_out)] = {};
945+
u32 in[MLX5_ST_SZ_DW(create_match_definer_in)] = {};
946+
struct mlx5_core_dev *dev = ns->dev;
947+
void *ptr;
948+
int err;
949+
950+
MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.opcode,
951+
MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
952+
MLX5_SET(create_match_definer_in, in, general_obj_in_cmd_hdr.obj_type,
953+
MLX5_OBJ_TYPE_MATCH_DEFINER);
954+
955+
ptr = MLX5_ADDR_OF(create_match_definer_in, in, obj_context);
956+
MLX5_SET(match_definer, ptr, format_id, format_id);
957+
958+
ptr = MLX5_ADDR_OF(match_definer, ptr, match_mask);
959+
memcpy(ptr, match_mask, MLX5_FLD_SZ_BYTES(match_definer, match_mask));
960+
961+
err = mlx5_cmd_exec_inout(dev, create_match_definer, in, out);
962+
return err ? err : MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
963+
}
964+
912965
static const struct mlx5_flow_cmds mlx5_flow_cmds = {
913966
.create_flow_table = mlx5_cmd_create_flow_table,
914967
.destroy_flow_table = mlx5_cmd_destroy_flow_table,
@@ -923,6 +976,8 @@ static const struct mlx5_flow_cmds mlx5_flow_cmds = {
923976
.packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
924977
.modify_header_alloc = mlx5_cmd_modify_header_alloc,
925978
.modify_header_dealloc = mlx5_cmd_modify_header_dealloc,
979+
.create_match_definer = mlx5_cmd_create_match_definer,
980+
.destroy_match_definer = mlx5_cmd_destroy_match_definer,
926981
.set_peer = mlx5_cmd_stub_set_peer,
927982
.create_ns = mlx5_cmd_stub_create_ns,
928983
.destroy_ns = mlx5_cmd_stub_destroy_ns,
@@ -942,6 +997,8 @@ static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
942997
.packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
943998
.modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
944999
.modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc,
1000+
.create_match_definer = mlx5_cmd_stub_create_match_definer,
1001+
.destroy_match_definer = mlx5_cmd_stub_destroy_match_definer,
9451002
.set_peer = mlx5_cmd_stub_set_peer,
9461003
.create_ns = mlx5_cmd_stub_create_ns,
9471004
.destroy_ns = mlx5_cmd_stub_destroy_ns,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ struct mlx5_flow_cmds {
9797

9898
int (*create_ns)(struct mlx5_flow_root_namespace *ns);
9999
int (*destroy_ns)(struct mlx5_flow_root_namespace *ns);
100+
int (*create_match_definer)(struct mlx5_flow_root_namespace *ns,
101+
u16 format_id, u32 *match_mask);
102+
int (*destroy_match_definer)(struct mlx5_flow_root_namespace *ns,
103+
int definer_id);
100104
};
101105

102106
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id);

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,52 @@ void mlx5_packet_reformat_dealloc(struct mlx5_core_dev *dev,
32503250
}
32513251
EXPORT_SYMBOL(mlx5_packet_reformat_dealloc);
32523252

3253+
int mlx5_get_match_definer_id(struct mlx5_flow_definer *definer)
3254+
{
3255+
return definer->id;
3256+
}
3257+
3258+
struct mlx5_flow_definer *
3259+
mlx5_create_match_definer(struct mlx5_core_dev *dev,
3260+
enum mlx5_flow_namespace_type ns_type, u16 format_id,
3261+
u32 *match_mask)
3262+
{
3263+
struct mlx5_flow_root_namespace *root;
3264+
struct mlx5_flow_definer *definer;
3265+
int id;
3266+
3267+
root = get_root_namespace(dev, ns_type);
3268+
if (!root)
3269+
return ERR_PTR(-EOPNOTSUPP);
3270+
3271+
definer = kzalloc(sizeof(*definer), GFP_KERNEL);
3272+
if (!definer)
3273+
return ERR_PTR(-ENOMEM);
3274+
3275+
definer->ns_type = ns_type;
3276+
id = root->cmds->create_match_definer(root, format_id, match_mask);
3277+
if (id < 0) {
3278+
mlx5_core_warn(root->dev, "Failed to create match definer (%d)\n", id);
3279+
kfree(definer);
3280+
return ERR_PTR(id);
3281+
}
3282+
definer->id = id;
3283+
return definer;
3284+
}
3285+
3286+
void mlx5_destroy_match_definer(struct mlx5_core_dev *dev,
3287+
struct mlx5_flow_definer *definer)
3288+
{
3289+
struct mlx5_flow_root_namespace *root;
3290+
3291+
root = get_root_namespace(dev, definer->ns_type);
3292+
if (WARN_ON(!root))
3293+
return;
3294+
3295+
root->cmds->destroy_match_definer(root, definer->id);
3296+
kfree(definer);
3297+
}
3298+
32533299
int mlx5_flow_namespace_set_peer(struct mlx5_flow_root_namespace *ns,
32543300
struct mlx5_flow_root_namespace *peer_ns)
32553301
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
#define FDB_TC_MAX_PRIO 16
5050
#define FDB_TC_LEVELS_PER_PRIO 2
5151

52+
struct mlx5_flow_definer {
53+
enum mlx5_flow_namespace_type ns_type;
54+
u32 id;
55+
};
56+
5257
struct mlx5_modify_hdr {
5358
enum mlx5_flow_namespace_type ns_type;
5459
union {

drivers/net/ethernet/mellanox/mlx5/core/steering/fs_dr.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,19 @@ static void mlx5_cmd_dr_modify_header_dealloc(struct mlx5_flow_root_namespace *n
625625
mlx5dr_action_destroy(modify_hdr->action.dr_action);
626626
}
627627

628+
static int
629+
mlx5_cmd_dr_destroy_match_definer(struct mlx5_flow_root_namespace *ns,
630+
int definer_id)
631+
{
632+
return -EOPNOTSUPP;
633+
}
634+
635+
static int mlx5_cmd_dr_create_match_definer(struct mlx5_flow_root_namespace *ns,
636+
u16 format_id, u32 *match_mask)
637+
{
638+
return -EOPNOTSUPP;
639+
}
640+
628641
static int mlx5_cmd_dr_delete_fte(struct mlx5_flow_root_namespace *ns,
629642
struct mlx5_flow_table *ft,
630643
struct fs_fte *fte)
@@ -727,6 +740,8 @@ static const struct mlx5_flow_cmds mlx5_flow_cmds_dr = {
727740
.packet_reformat_dealloc = mlx5_cmd_dr_packet_reformat_dealloc,
728741
.modify_header_alloc = mlx5_cmd_dr_modify_header_alloc,
729742
.modify_header_dealloc = mlx5_cmd_dr_modify_header_dealloc,
743+
.create_match_definer = mlx5_cmd_dr_create_match_definer,
744+
.destroy_match_definer = mlx5_cmd_dr_destroy_match_definer,
730745
.set_peer = mlx5_cmd_dr_set_peer,
731746
.create_ns = mlx5_cmd_dr_create_ns,
732747
.destroy_ns = mlx5_cmd_dr_destroy_ns,

include/linux/mlx5/fs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ enum {
9898

9999
struct mlx5_pkt_reformat;
100100
struct mlx5_modify_hdr;
101+
struct mlx5_flow_definer;
101102
struct mlx5_flow_table;
102103
struct mlx5_flow_group;
103104
struct mlx5_flow_namespace;
@@ -258,6 +259,13 @@ struct mlx5_modify_hdr *mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
258259
void *modify_actions);
259260
void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev,
260261
struct mlx5_modify_hdr *modify_hdr);
262+
struct mlx5_flow_definer *
263+
mlx5_create_match_definer(struct mlx5_core_dev *dev,
264+
enum mlx5_flow_namespace_type ns_type, u16 format_id,
265+
u32 *match_mask);
266+
void mlx5_destroy_match_definer(struct mlx5_core_dev *dev,
267+
struct mlx5_flow_definer *definer);
268+
int mlx5_get_match_definer_id(struct mlx5_flow_definer *definer);
261269

262270
struct mlx5_pkt_reformat_params {
263271
int type;

0 commit comments

Comments
 (0)