mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
net/mlx5: Use vport helper for IPsec eswitch set caps
Use mlx5_vport_set_other_func_cap() and mlx5_vport_set_other_func_general_cap() in the IPsec eswitch functions instead of open-coding the SET_HCA_CAP command. This removes redundant buffer allocation and boilerplate, and also enables vhca_id based addressing when supported. Signed-off-by: Moshe Shemesh <moshe@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20260518071356.345723-8-tariqt@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
fa2852a28c
commit
d7ec361003
|
|
@ -81,38 +81,25 @@ int mlx5_esw_ipsec_vf_offload_get(struct mlx5_core_dev *dev, struct mlx5_vport *
|
|||
static int esw_ipsec_vf_set_generic(struct mlx5_core_dev *dev, u16 vport_num, bool ipsec_ofld)
|
||||
{
|
||||
int query_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
|
||||
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
|
||||
void *hca_cap, *query_cap, *cap;
|
||||
void *query_cap, *hca_caps;
|
||||
int ret;
|
||||
|
||||
if (!MLX5_CAP_GEN(dev, vhca_resource_manager))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
query_cap = kvzalloc(query_sz, GFP_KERNEL);
|
||||
hca_cap = kvzalloc(set_sz, GFP_KERNEL);
|
||||
if (!hca_cap || !query_cap) {
|
||||
ret = -ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
if (!query_cap)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = mlx5_vport_get_other_func_general_cap(dev, vport_num, query_cap);
|
||||
if (ret)
|
||||
goto free;
|
||||
|
||||
cap = MLX5_ADDR_OF(set_hca_cap_in, hca_cap, capability);
|
||||
memcpy(cap, MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability),
|
||||
MLX5_UN_SZ_BYTES(hca_cap_union));
|
||||
MLX5_SET(cmd_hca_cap, cap, ipsec_offload, ipsec_ofld);
|
||||
hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability);
|
||||
MLX5_SET(cmd_hca_cap, hca_caps, ipsec_offload, ipsec_ofld);
|
||||
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, opcode, MLX5_CMD_OP_SET_HCA_CAP);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, other_function, 1);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, function_id, vport_num);
|
||||
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, op_mod,
|
||||
MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1);
|
||||
ret = mlx5_cmd_exec_in(dev, set_hca_cap, hca_cap);
|
||||
ret = mlx5_vport_set_other_func_general_cap(dev, hca_caps, vport_num);
|
||||
free:
|
||||
kvfree(hca_cap);
|
||||
kvfree(query_cap);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -121,49 +108,37 @@ static int esw_ipsec_vf_set_bytype(struct mlx5_core_dev *dev, struct mlx5_vport
|
|||
bool enable, enum esw_vport_ipsec_offload type)
|
||||
{
|
||||
int query_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
|
||||
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
|
||||
void *hca_cap, *query_cap, *cap;
|
||||
void *query_cap, *hca_caps;
|
||||
int ret;
|
||||
|
||||
if (!MLX5_CAP_GEN(dev, vhca_resource_manager))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
query_cap = kvzalloc(query_sz, GFP_KERNEL);
|
||||
hca_cap = kvzalloc(set_sz, GFP_KERNEL);
|
||||
if (!hca_cap || !query_cap) {
|
||||
ret = -ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
if (!query_cap)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = mlx5_vport_get_other_func_cap(dev, vport->vport, query_cap, MLX5_CAP_IPSEC);
|
||||
if (ret)
|
||||
goto free;
|
||||
|
||||
cap = MLX5_ADDR_OF(set_hca_cap_in, hca_cap, capability);
|
||||
memcpy(cap, MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability),
|
||||
MLX5_UN_SZ_BYTES(hca_cap_union));
|
||||
hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability);
|
||||
|
||||
switch (type) {
|
||||
case MLX5_ESW_VPORT_IPSEC_CRYPTO_OFFLOAD:
|
||||
MLX5_SET(ipsec_cap, cap, ipsec_crypto_offload, enable);
|
||||
MLX5_SET(ipsec_cap, hca_caps, ipsec_crypto_offload, enable);
|
||||
break;
|
||||
case MLX5_ESW_VPORT_IPSEC_PACKET_OFFLOAD:
|
||||
MLX5_SET(ipsec_cap, cap, ipsec_full_offload, enable);
|
||||
MLX5_SET(ipsec_cap, hca_caps, ipsec_full_offload, enable);
|
||||
break;
|
||||
default:
|
||||
ret = -EOPNOTSUPP;
|
||||
goto free;
|
||||
}
|
||||
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, opcode, MLX5_CMD_OP_SET_HCA_CAP);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, other_function, 1);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, function_id, vport->vport);
|
||||
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, op_mod,
|
||||
MLX5_SET_HCA_CAP_OP_MOD_IPSEC << 1);
|
||||
ret = mlx5_cmd_exec_in(dev, set_hca_cap, hca_cap);
|
||||
ret = mlx5_vport_set_other_func_cap(dev, hca_caps, vport->vport,
|
||||
MLX5_SET_HCA_CAP_OP_MOD_IPSEC);
|
||||
free:
|
||||
kvfree(hca_cap);
|
||||
kvfree(query_cap);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -171,34 +146,24 @@ static int esw_ipsec_vf_set_bytype(struct mlx5_core_dev *dev, struct mlx5_vport
|
|||
static int esw_ipsec_vf_crypto_aux_caps_set(struct mlx5_core_dev *dev, u16 vport_num, bool enable)
|
||||
{
|
||||
int query_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
|
||||
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
|
||||
struct mlx5_eswitch *esw = dev->priv.eswitch;
|
||||
void *hca_cap, *query_cap, *cap;
|
||||
void *query_cap, *hca_caps;
|
||||
int ret;
|
||||
|
||||
query_cap = kvzalloc(query_sz, GFP_KERNEL);
|
||||
hca_cap = kvzalloc(set_sz, GFP_KERNEL);
|
||||
if (!hca_cap || !query_cap) {
|
||||
ret = -ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
if (!query_cap)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = mlx5_vport_get_other_func_cap(dev, vport_num, query_cap, MLX5_CAP_ETHERNET_OFFLOADS);
|
||||
if (ret)
|
||||
goto free;
|
||||
|
||||
cap = MLX5_ADDR_OF(set_hca_cap_in, hca_cap, capability);
|
||||
memcpy(cap, MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability),
|
||||
MLX5_UN_SZ_BYTES(hca_cap_union));
|
||||
MLX5_SET(per_protocol_networking_offload_caps, cap, insert_trailer, enable);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, opcode, MLX5_CMD_OP_SET_HCA_CAP);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, other_function, 1);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, function_id, vport_num);
|
||||
MLX5_SET(set_hca_cap_in, hca_cap, op_mod,
|
||||
MLX5_SET_HCA_CAP_OP_MOD_ETHERNET_OFFLOADS << 1);
|
||||
ret = mlx5_cmd_exec_in(esw->dev, set_hca_cap, hca_cap);
|
||||
hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_cap, capability);
|
||||
MLX5_SET(per_protocol_networking_offload_caps, hca_caps,
|
||||
insert_trailer, enable);
|
||||
|
||||
ret = mlx5_vport_set_other_func_cap(dev, hca_caps, vport_num,
|
||||
MLX5_SET_HCA_CAP_OP_MOD_ETHERNET_OFFLOADS);
|
||||
free:
|
||||
kvfree(hca_cap);
|
||||
kvfree(query_cap);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user