Skip to content

Commit 2de24fe

Browse files
ogerlitzSaeed Mahameed
authored andcommitted
net/mlx5: Introduce alloc/dealloc modify header context commands
Implement the low-level commands to support packet header re-write. Signed-off-by: Or Gerlitz <[email protected]> Reviewed-by: Hadar Hen Zion <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 2a69cb9 commit 2de24fe

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
307307
case MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY:
308308
case MLX5_CMD_OP_SET_FLOW_TABLE_ROOT:
309309
case MLX5_CMD_OP_DEALLOC_ENCAP_HEADER:
310+
case MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT:
310311
return MLX5_CMD_STAT_OK;
311312

312313
case MLX5_CMD_OP_QUERY_HCA_CAP:
@@ -418,6 +419,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
418419
case MLX5_CMD_OP_ALLOC_FLOW_COUNTER:
419420
case MLX5_CMD_OP_QUERY_FLOW_COUNTER:
420421
case MLX5_CMD_OP_ALLOC_ENCAP_HEADER:
422+
case MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT:
421423
*status = MLX5_DRIVER_STATUS_ABORTED;
422424
*synd = MLX5_DRIVER_SYND;
423425
return -EIO;
@@ -582,6 +584,8 @@ const char *mlx5_command_str(int command)
582584
MLX5_COMMAND_STR_CASE(MODIFY_FLOW_TABLE);
583585
MLX5_COMMAND_STR_CASE(ALLOC_ENCAP_HEADER);
584586
MLX5_COMMAND_STR_CASE(DEALLOC_ENCAP_HEADER);
587+
MLX5_COMMAND_STR_CASE(ALLOC_MODIFY_HEADER_CONTEXT);
588+
MLX5_COMMAND_STR_CASE(DEALLOC_MODIFY_HEADER_CONTEXT);
585589
default: return "unknown command opcode";
586590
}
587591
}

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,69 @@ void mlx5_encap_dealloc(struct mlx5_core_dev *dev, u32 encap_id)
516516

517517
mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
518518
}
519+
520+
int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
521+
u8 namespace, u8 num_actions,
522+
void *modify_actions, u32 *modify_header_id)
523+
{
524+
u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)];
525+
int max_actions, actions_size, inlen, err;
526+
void *actions_in;
527+
u8 table_type;
528+
u32 *in;
529+
530+
switch (namespace) {
531+
case MLX5_FLOW_NAMESPACE_FDB:
532+
max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, max_modify_header_actions);
533+
table_type = FS_FT_FDB;
534+
break;
535+
case MLX5_FLOW_NAMESPACE_KERNEL:
536+
max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
537+
table_type = FS_FT_NIC_RX;
538+
break;
539+
default:
540+
return -EOPNOTSUPP;
541+
}
542+
543+
if (num_actions > max_actions) {
544+
mlx5_core_warn(dev, "too many modify header actions %d, max supported %d\n",
545+
num_actions, max_actions);
546+
return -EOPNOTSUPP;
547+
}
548+
549+
actions_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto) * num_actions;
550+
inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
551+
552+
in = kzalloc(inlen, GFP_KERNEL);
553+
if (!in)
554+
return -ENOMEM;
555+
556+
MLX5_SET(alloc_modify_header_context_in, in, opcode,
557+
MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT);
558+
MLX5_SET(alloc_modify_header_context_in, in, table_type, table_type);
559+
MLX5_SET(alloc_modify_header_context_in, in, num_of_actions, num_actions);
560+
561+
actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
562+
memcpy(actions_in, modify_actions, actions_size);
563+
564+
memset(out, 0, sizeof(out));
565+
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
566+
567+
*modify_header_id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
568+
kfree(in);
569+
return err;
570+
}
571+
572+
void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id)
573+
{
574+
u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)];
575+
u32 out[MLX5_ST_SZ_DW(dealloc_modify_header_context_out)];
576+
577+
memset(in, 0, sizeof(in));
578+
MLX5_SET(dealloc_modify_header_context_in, in, opcode,
579+
MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
580+
MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
581+
modify_header_id);
582+
583+
mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
584+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ int mlx5_encap_alloc(struct mlx5_core_dev *dev,
141141
u32 *encap_id);
142142
void mlx5_encap_dealloc(struct mlx5_core_dev *dev, u32 encap_id);
143143

144+
int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
145+
u8 namespace, u8 num_actions,
146+
void *modify_actions, u32 *modify_header_id);
147+
void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id);
148+
144149
bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv);
145150

146151
int mlx5_query_mtpps(struct mlx5_core_dev *dev, u32 *mtpps, u32 mtpps_size);

0 commit comments

Comments
 (0)