Skip to content

Commit 43f9383

Browse files
hadarhenziondavem330
authored andcommitted
net/mlx5: Check max encap header size capability
Instead of comparing to a const value, check the value of max encap header size capability as reported by the Firmware. Fixes: 575ddf5 ('net/mlx5: Introduce alloc_encap and dealloc_encap commands') Signed-off-by: Hadar Hen Zion <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ae9f83a commit 43f9383

File tree

1 file changed

+16
-10
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,27 +453,32 @@ void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
453453
*bytes = MLX5_GET64(traffic_counter, stats, octets);
454454
}
455455

456-
#define MAX_ENCAP_SIZE (128)
457-
458456
int mlx5_encap_alloc(struct mlx5_core_dev *dev,
459457
int header_type,
460458
size_t size,
461459
void *encap_header,
462460
u32 *encap_id)
463461
{
462+
int max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
464463
u32 out[MLX5_ST_SZ_DW(alloc_encap_header_out)];
465-
u32 in[MLX5_ST_SZ_DW(alloc_encap_header_in) +
466-
(MAX_ENCAP_SIZE / sizeof(u32))];
467-
void *encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in,
468-
encap_header);
469-
void *header = MLX5_ADDR_OF(encap_header_in, encap_header_in,
470-
encap_header);
471-
int inlen = header - (void *)in + size;
464+
void *encap_header_in;
465+
void *header;
466+
int inlen;
472467
int err;
468+
u32 *in;
473469

474-
if (size > MAX_ENCAP_SIZE)
470+
if (size > MLX5_CAP_ESW(dev, max_encap_header_size))
475471
return -EINVAL;
476472

473+
in = kzalloc(MLX5_ST_SZ_BYTES(alloc_encap_header_in) + max_encap_size,
474+
GFP_KERNEL);
475+
if (!in)
476+
return -ENOMEM;
477+
478+
encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in, encap_header);
479+
header = MLX5_ADDR_OF(encap_header_in, encap_header_in, encap_header);
480+
inlen = header - (void *)in + size;
481+
477482
memset(in, 0, inlen);
478483
MLX5_SET(alloc_encap_header_in, in, opcode,
479484
MLX5_CMD_OP_ALLOC_ENCAP_HEADER);
@@ -485,6 +490,7 @@ int mlx5_encap_alloc(struct mlx5_core_dev *dev,
485490
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
486491

487492
*encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id);
493+
kfree(in);
488494
return err;
489495
}
490496

0 commit comments

Comments
 (0)