Commit b06e7de8 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Doug Ledford

net/mlx5_core: Refactor device capability function

Device capability function was called similar in all places.
It was called twice for every queried parameter, while the
difference between calls was in HCA capability mode only.

The change proposed unify these calls into one function.
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Reviewed-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 91d9ed84
...@@ -98,88 +98,49 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev) ...@@ -98,88 +98,49 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev)
{ {
int err; int err;
err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_CUR); err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
if (MLX5_CAP_GEN(dev, eth_net_offloads)) { if (MLX5_CAP_GEN(dev, eth_net_offloads)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS, err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, pg)) { if (MLX5_CAP_GEN(dev, pg)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ODP, err = mlx5_core_get_caps(dev, MLX5_CAP_ODP);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ODP,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, atomic)) { if (MLX5_CAP_GEN(dev, atomic)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, roce)) { if (MLX5_CAP_GEN(dev, roce)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE, err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, nic_flow_table)) { if (MLX5_CAP_GEN(dev, nic_flow_table)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE, err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, vport_group_manager) && if (MLX5_CAP_GEN(dev, vport_group_manager) &&
MLX5_CAP_GEN(dev, eswitch_flow_table)) { MLX5_CAP_GEN(dev, eswitch_flow_table)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE, err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
if (MLX5_CAP_GEN(dev, eswitch_flow_table)) { if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH, err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} }
......
...@@ -341,8 +341,9 @@ static u16 to_fw_pkey_sz(u32 size) ...@@ -341,8 +341,9 @@ static u16 to_fw_pkey_sz(u32 size)
} }
} }
int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, static int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev,
enum mlx5_cap_mode cap_mode) enum mlx5_cap_type cap_type,
enum mlx5_cap_mode cap_mode)
{ {
u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)]; u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)];
int out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out); int out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
...@@ -392,6 +393,16 @@ int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, ...@@ -392,6 +393,16 @@ int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type,
return err; return err;
} }
int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type)
{
int ret;
ret = mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_CUR);
if (ret)
return ret;
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 in_sz, int opmod)
{ {
u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)]; u32 out[MLX5_ST_SZ_DW(set_hca_cap_out)];
...@@ -419,12 +430,7 @@ static int handle_hca_cap_atomic(struct mlx5_core_dev *dev) ...@@ -419,12 +430,7 @@ static int handle_hca_cap_atomic(struct mlx5_core_dev *dev)
int err; int err;
if (MLX5_CAP_GEN(dev, atomic)) { if (MLX5_CAP_GEN(dev, atomic)) {
err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
HCA_CAP_OPMOD_GET_CUR);
if (err)
return err;
err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC,
HCA_CAP_OPMOD_GET_MAX);
if (err) if (err)
return err; return err;
} else { } else {
...@@ -466,11 +472,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev) ...@@ -466,11 +472,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
if (!set_ctx) if (!set_ctx)
goto query_ex; goto query_ex;
err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_MAX); err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
if (err)
goto query_ex;
err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_CUR);
if (err) if (err)
goto query_ex; goto query_ex;
......
...@@ -706,8 +706,7 @@ void mlx5_cmd_use_events(struct mlx5_core_dev *dev); ...@@ -706,8 +706,7 @@ void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
void mlx5_cmd_use_polling(struct mlx5_core_dev *dev); void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr); int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
int mlx5_cmd_status_to_err_v2(void *ptr); int mlx5_cmd_status_to_err_v2(void *ptr);
int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
enum mlx5_cap_mode cap_mode);
int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
int out_size); int out_size);
int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size, int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
......
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