Skip to content

Commit 6480a3b

Browse files
rleonkuba-moo
authored andcommitted
net/mlx5e: Prepare IPsec packet reformat code for tunnel mode
Refactor setup_pkt_reformat() function to accommodate future extension to support tunnel mode. Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 006adbc commit 6480a3b

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
297297
attrs->upspec.sport = ntohs(x->sel.sport);
298298
attrs->upspec.sport_mask = ntohs(x->sel.sport_mask);
299299
attrs->upspec.proto = x->sel.proto;
300+
attrs->mode = x->props.mode;
300301

301302
mlx5e_ipsec_init_limits(sa_entry, attrs);
302303
}

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct mlx5_replay_esn {
7777

7878
struct mlx5_accel_esp_xfrm_attrs {
7979
u32 spi;
80-
u32 flags;
80+
u32 mode;
8181
struct aes_gcm_keymat aes_gcm;
8282

8383
union {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "lib/fs_chains.h"
1111

1212
#define NUM_IPSEC_FTE BIT(15)
13+
#define MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE 16
1314

1415
struct mlx5e_ipsec_fc {
1516
struct mlx5_fc *cnt;
@@ -836,40 +837,80 @@ static int setup_modify_header(struct mlx5_core_dev *mdev, u32 val, u8 dir,
836837
return 0;
837838
}
838839

840+
static int
841+
setup_pkt_transport_reformat(struct mlx5_accel_esp_xfrm_attrs *attrs,
842+
struct mlx5_pkt_reformat_params *reformat_params)
843+
{
844+
u8 *reformatbf;
845+
__be32 spi;
846+
847+
switch (attrs->dir) {
848+
case XFRM_DEV_OFFLOAD_IN:
849+
reformat_params->type = MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT;
850+
break;
851+
case XFRM_DEV_OFFLOAD_OUT:
852+
if (attrs->family == AF_INET)
853+
reformat_params->type =
854+
MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV4;
855+
else
856+
reformat_params->type =
857+
MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV6;
858+
859+
reformatbf = kzalloc(MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE,
860+
GFP_KERNEL);
861+
if (!reformatbf)
862+
return -ENOMEM;
863+
864+
/* convert to network format */
865+
spi = htonl(attrs->spi);
866+
memcpy(reformatbf, &spi, sizeof(spi));
867+
868+
reformat_params->param_0 = attrs->authsize;
869+
reformat_params->size =
870+
MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE;
871+
reformat_params->data = reformatbf;
872+
break;
873+
default:
874+
return -EINVAL;
875+
}
876+
877+
return 0;
878+
}
879+
839880
static int setup_pkt_reformat(struct mlx5_core_dev *mdev,
840881
struct mlx5_accel_esp_xfrm_attrs *attrs,
841882
struct mlx5_flow_act *flow_act)
842883
{
843-
enum mlx5_flow_namespace_type ns_type = MLX5_FLOW_NAMESPACE_EGRESS;
844884
struct mlx5_pkt_reformat_params reformat_params = {};
845885
struct mlx5_pkt_reformat *pkt_reformat;
846-
u8 reformatbf[16] = {};
847-
__be32 spi;
886+
enum mlx5_flow_namespace_type ns_type;
887+
int ret;
848888

849-
if (attrs->dir == XFRM_DEV_OFFLOAD_IN) {
850-
reformat_params.type = MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT;
889+
switch (attrs->dir) {
890+
case XFRM_DEV_OFFLOAD_IN:
851891
ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
852-
goto cmd;
892+
break;
893+
case XFRM_DEV_OFFLOAD_OUT:
894+
ns_type = MLX5_FLOW_NAMESPACE_EGRESS;
895+
break;
896+
default:
897+
return -EINVAL;
853898
}
854899

855-
if (attrs->family == AF_INET)
856-
reformat_params.type =
857-
MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV4;
858-
else
859-
reformat_params.type =
860-
MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV6;
861-
862-
/* convert to network format */
863-
spi = htonl(attrs->spi);
864-
memcpy(reformatbf, &spi, 4);
900+
switch (attrs->mode) {
901+
case XFRM_MODE_TRANSPORT:
902+
ret = setup_pkt_transport_reformat(attrs, &reformat_params);
903+
break;
904+
default:
905+
ret = -EINVAL;
906+
}
865907

866-
reformat_params.param_0 = attrs->authsize;
867-
reformat_params.size = sizeof(reformatbf);
868-
reformat_params.data = &reformatbf;
908+
if (ret)
909+
return ret;
869910

870-
cmd:
871911
pkt_reformat =
872912
mlx5_packet_reformat_alloc(mdev, &reformat_params, ns_type);
913+
kfree(reformat_params.data);
873914
if (IS_ERR(pkt_reformat))
874915
return PTR_ERR(pkt_reformat);
875916

0 commit comments

Comments
 (0)