Commit a2a322f4 authored by Leon Romanovsky's avatar Leon Romanovsky

net/mlx5: Refactor HCA capability set flow

Reduce the amount of kzalloc/kfree cycles by allocating
command structure in the parent function and leverage the
knowledge that set_caps() is called for HCA capabilities
only with specific HW structure as parameter to calculate
mailbox size.
Acked-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
parent 333fbaa0
...@@ -407,30 +407,28 @@ int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type) ...@@ -407,30 +407,28 @@ int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type)
return mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_MAX); return mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_MAX);
} }
static int set_caps(struct mlx5_core_dev *dev, void *in, int in_sz, int opmod) static int set_caps(struct mlx5_core_dev *dev, void *in, int opmod)
{ {
u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)] = {0}; u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)] = {};
MLX5_SET(set_hca_cap_in, in, opcode, MLX5_CMD_OP_SET_HCA_CAP); MLX5_SET(set_hca_cap_in, in, opcode, MLX5_CMD_OP_SET_HCA_CAP);
MLX5_SET(set_hca_cap_in, in, op_mod, opmod << 1); MLX5_SET(set_hca_cap_in, in, op_mod, opmod << 1);
return mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out)); return mlx5_cmd_exec(dev, in, MLX5_ST_SZ_BYTES(set_hca_cap_in), out,
sizeof(out));
} }
static int handle_hca_cap_atomic(struct mlx5_core_dev *dev) static int handle_hca_cap_atomic(struct mlx5_core_dev *dev, void *set_ctx)
{ {
void *set_ctx;
void *set_hca_cap; void *set_hca_cap;
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
int req_endianness; int req_endianness;
int err; int err;
if (MLX5_CAP_GEN(dev, atomic)) { if (!MLX5_CAP_GEN(dev, atomic))
return 0;
err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC); err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
if (err) if (err)
return err; return err;
} else {
return 0;
}
req_endianness = req_endianness =
MLX5_CAP_ATOMIC(dev, MLX5_CAP_ATOMIC(dev,
...@@ -439,27 +437,18 @@ static int handle_hca_cap_atomic(struct mlx5_core_dev *dev) ...@@ -439,27 +437,18 @@ static int handle_hca_cap_atomic(struct mlx5_core_dev *dev)
if (req_endianness != MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS) if (req_endianness != MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS)
return 0; return 0;
set_ctx = kzalloc(set_sz, GFP_KERNEL);
if (!set_ctx)
return -ENOMEM;
set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability); set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
/* Set requestor to host endianness */ /* Set requestor to host endianness */
MLX5_SET(atomic_caps, set_hca_cap, atomic_req_8B_endianness_mode, MLX5_SET(atomic_caps, set_hca_cap, atomic_req_8B_endianness_mode,
MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS); MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS);
err = set_caps(dev, set_ctx, set_sz, MLX5_SET_HCA_CAP_OP_MOD_ATOMIC); return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ATOMIC);
kfree(set_ctx);
return err;
} }
static int handle_hca_cap_odp(struct mlx5_core_dev *dev) static int handle_hca_cap_odp(struct mlx5_core_dev *dev, void *set_ctx)
{ {
void *set_hca_cap; void *set_hca_cap;
void *set_ctx;
int set_sz;
bool do_set = false; bool do_set = false;
int err; int err;
...@@ -471,11 +460,6 @@ static int handle_hca_cap_odp(struct mlx5_core_dev *dev) ...@@ -471,11 +460,6 @@ static int handle_hca_cap_odp(struct mlx5_core_dev *dev)
if (err) if (err)
return err; return err;
set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
set_ctx = kzalloc(set_sz, GFP_KERNEL);
if (!set_ctx)
return -ENOMEM;
set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability); set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
memcpy(set_hca_cap, dev->caps.hca_cur[MLX5_CAP_ODP], memcpy(set_hca_cap, dev->caps.hca_cur[MLX5_CAP_ODP],
MLX5_ST_SZ_BYTES(odp_cap)); MLX5_ST_SZ_BYTES(odp_cap));
...@@ -504,30 +488,21 @@ static int handle_hca_cap_odp(struct mlx5_core_dev *dev) ...@@ -504,30 +488,21 @@ static int handle_hca_cap_odp(struct mlx5_core_dev *dev)
ODP_CAP_SET_MAX(dev, dc_odp_caps.read); ODP_CAP_SET_MAX(dev, dc_odp_caps.read);
ODP_CAP_SET_MAX(dev, dc_odp_caps.atomic); ODP_CAP_SET_MAX(dev, dc_odp_caps.atomic);
if (do_set) if (!do_set)
err = set_caps(dev, set_ctx, set_sz, return 0;
MLX5_SET_HCA_CAP_OP_MOD_ODP);
kfree(set_ctx);
return err; return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ODP);
} }
static int handle_hca_cap(struct mlx5_core_dev *dev) static int handle_hca_cap(struct mlx5_core_dev *dev, void *set_ctx)
{ {
void *set_ctx = NULL;
struct mlx5_profile *prof = dev->profile; struct mlx5_profile *prof = dev->profile;
int err = -ENOMEM;
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
void *set_hca_cap; void *set_hca_cap;
int err;
set_ctx = kzalloc(set_sz, GFP_KERNEL);
if (!set_ctx)
goto query_ex;
err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL); err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
if (err) if (err)
goto query_ex; return err;
set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx,
capability); capability);
...@@ -578,37 +553,41 @@ static int handle_hca_cap(struct mlx5_core_dev *dev) ...@@ -578,37 +553,41 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
num_vhca_ports, num_vhca_ports,
MLX5_CAP_GEN_MAX(dev, num_vhca_ports)); MLX5_CAP_GEN_MAX(dev, num_vhca_ports));
err = set_caps(dev, set_ctx, set_sz, return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE);
MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE);
query_ex:
kfree(set_ctx);
return err;
} }
static int set_hca_cap(struct mlx5_core_dev *dev) static int set_hca_cap(struct mlx5_core_dev *dev)
{ {
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
void *set_ctx;
int err; int err;
err = handle_hca_cap(dev); set_ctx = kzalloc(set_sz, GFP_KERNEL);
if (!set_ctx)
return -ENOMEM;
err = handle_hca_cap(dev, set_ctx);
if (err) { if (err) {
mlx5_core_err(dev, "handle_hca_cap failed\n"); mlx5_core_err(dev, "handle_hca_cap failed\n");
goto out; goto out;
} }
err = handle_hca_cap_atomic(dev); memset(set_ctx, 0, set_sz);
err = handle_hca_cap_atomic(dev, set_ctx);
if (err) { if (err) {
mlx5_core_err(dev, "handle_hca_cap_atomic failed\n"); mlx5_core_err(dev, "handle_hca_cap_atomic failed\n");
goto out; goto out;
} }
err = handle_hca_cap_odp(dev); memset(set_ctx, 0, set_sz);
err = handle_hca_cap_odp(dev, set_ctx);
if (err) { if (err) {
mlx5_core_err(dev, "handle_hca_cap_odp failed\n"); mlx5_core_err(dev, "handle_hca_cap_odp failed\n");
goto out; goto out;
} }
out: out:
kfree(set_ctx);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment