Skip to content

Commit 575ddf5

Browse files
Ilya Lesokhinrleon
authored andcommitted
net/mlx5: Introduce alloc_encap and dealloc_encap commands
Implement low-level commands to support vxlan encapsulation. Signed-off-by: Ilya Lesokhin <[email protected]> Signed-off-by: Hadar Hen Zion <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 7adbde2 commit 575ddf5

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-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
@@ -301,6 +301,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
301301
case MLX5_CMD_OP_MODIFY_FLOW_TABLE:
302302
case MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY:
303303
case MLX5_CMD_OP_SET_FLOW_TABLE_ROOT:
304+
case MLX5_CMD_OP_DEALLOC_ENCAP_HEADER:
304305
return MLX5_CMD_STAT_OK;
305306

306307
case MLX5_CMD_OP_QUERY_HCA_CAP:
@@ -402,6 +403,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
402403
case MLX5_CMD_OP_QUERY_FLOW_TABLE_ENTRY:
403404
case MLX5_CMD_OP_ALLOC_FLOW_COUNTER:
404405
case MLX5_CMD_OP_QUERY_FLOW_COUNTER:
406+
case MLX5_CMD_OP_ALLOC_ENCAP_HEADER:
405407
*status = MLX5_DRIVER_STATUS_ABORTED;
406408
*synd = MLX5_DRIVER_SYND;
407409
return -EIO;
@@ -550,6 +552,8 @@ const char *mlx5_command_str(int command)
550552
MLX5_COMMAND_STR_CASE(DEALLOC_FLOW_COUNTER);
551553
MLX5_COMMAND_STR_CASE(QUERY_FLOW_COUNTER);
552554
MLX5_COMMAND_STR_CASE(MODIFY_FLOW_TABLE);
555+
MLX5_COMMAND_STR_CASE(ALLOC_ENCAP_HEADER);
556+
MLX5_COMMAND_STR_CASE(DEALLOC_ENCAP_HEADER);
553557
default: return "unknown command opcode";
554558
}
555559
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,51 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
424424
*packets = MLX5_GET64(traffic_counter, stats, packets);
425425
*bytes = MLX5_GET64(traffic_counter, stats, octets);
426426
}
427+
428+
#define MAX_ENCAP_SIZE (128)
429+
430+
int mlx5_cmd_alloc_encap(struct mlx5_core_dev *dev,
431+
int header_type,
432+
size_t size,
433+
void *encap_header,
434+
u32 *encap_id)
435+
{
436+
u32 out[MLX5_ST_SZ_DW(alloc_encap_header_out)];
437+
u32 in[MLX5_ST_SZ_DW(alloc_encap_header_in) +
438+
(MAX_ENCAP_SIZE / sizeof(u32))];
439+
void *encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in,
440+
encap_header);
441+
void *header = MLX5_ADDR_OF(encap_header_in, encap_header_in,
442+
encap_header);
443+
int inlen = header - (void *)in + size;
444+
int err;
445+
446+
if (size > MAX_ENCAP_SIZE)
447+
return -EINVAL;
448+
449+
memset(in, 0, inlen);
450+
MLX5_SET(alloc_encap_header_in, in, opcode,
451+
MLX5_CMD_OP_ALLOC_ENCAP_HEADER);
452+
MLX5_SET(encap_header_in, encap_header_in, encap_header_size, size);
453+
MLX5_SET(encap_header_in, encap_header_in, header_type, header_type);
454+
memcpy(header, encap_header, size);
455+
456+
memset(out, 0, sizeof(out));
457+
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
458+
459+
*encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id);
460+
return err;
461+
}
462+
463+
void mlx5_cmd_dealloc_encap(struct mlx5_core_dev *dev, u32 encap_id)
464+
{
465+
u32 in[MLX5_ST_SZ_DW(dealloc_encap_header_in)];
466+
u32 out[MLX5_ST_SZ_DW(dealloc_encap_header_out)];
467+
468+
memset(in, 0, sizeof(in));
469+
MLX5_SET(dealloc_encap_header_in, in, opcode,
470+
MLX5_CMD_OP_DEALLOC_ENCAP_HEADER);
471+
MLX5_SET(dealloc_encap_header_in, in, encap_id, encap_id);
472+
473+
mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
474+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,11 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
8888
struct mlx5_cmd_fc_bulk *b, u16 id,
8989
u64 *packets, u64 *bytes);
9090

91+
int mlx5_cmd_alloc_encap(struct mlx5_core_dev *dev,
92+
int header_type,
93+
size_t size,
94+
void *encap_header,
95+
u32 *encap_id);
96+
void mlx5_cmd_dealloc_encap(struct mlx5_core_dev *dev, u32 encap_id);
97+
9198
#endif

0 commit comments

Comments
 (0)