Commit 6480a3b6 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jakub Kicinski
Browse files

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: default avatarLeon Romanovsky <leonro@nvidia.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Reviewed-by: default avatarSridhar Samudrala <sridhar.samudrala@intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 006adbc6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@ void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
	attrs->upspec.sport = ntohs(x->sel.sport);
	attrs->upspec.sport_mask = ntohs(x->sel.sport_mask);
	attrs->upspec.proto = x->sel.proto;
	attrs->mode = x->props.mode;

	mlx5e_ipsec_init_limits(sa_entry, attrs);
}
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ struct mlx5_replay_esn {

struct mlx5_accel_esp_xfrm_attrs {
	u32   spi;
	u32   flags;
	u32   mode;
	struct aes_gcm_keymat aes_gcm;

	union {
+61 −20
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include "lib/fs_chains.h"

#define NUM_IPSEC_FTE BIT(15)
#define MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE 16

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

static int setup_pkt_reformat(struct mlx5_core_dev *mdev,
			      struct mlx5_accel_esp_xfrm_attrs *attrs,
			      struct mlx5_flow_act *flow_act)
static int
setup_pkt_transport_reformat(struct mlx5_accel_esp_xfrm_attrs *attrs,
			     struct mlx5_pkt_reformat_params *reformat_params)
{
	enum mlx5_flow_namespace_type ns_type = MLX5_FLOW_NAMESPACE_EGRESS;
	struct mlx5_pkt_reformat_params reformat_params = {};
	struct mlx5_pkt_reformat *pkt_reformat;
	u8 reformatbf[16] = {};
	u8 *reformatbf;
	__be32 spi;

	if (attrs->dir == XFRM_DEV_OFFLOAD_IN) {
		reformat_params.type = MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT;
		ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
		goto cmd;
	}

	switch (attrs->dir) {
	case XFRM_DEV_OFFLOAD_IN:
		reformat_params->type = MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT;
		break;
	case XFRM_DEV_OFFLOAD_OUT:
		if (attrs->family == AF_INET)
		reformat_params.type =
			reformat_params->type =
				MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV4;
		else
		reformat_params.type =
			reformat_params->type =
				MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV6;

		reformatbf = kzalloc(MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE,
				     GFP_KERNEL);
		if (!reformatbf)
			return -ENOMEM;

		/* convert to network format */
		spi = htonl(attrs->spi);
	memcpy(reformatbf, &spi, 4);
		memcpy(reformatbf, &spi, sizeof(spi));

		reformat_params->param_0 = attrs->authsize;
		reformat_params->size =
			MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE;
		reformat_params->data = reformatbf;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int setup_pkt_reformat(struct mlx5_core_dev *mdev,
			      struct mlx5_accel_esp_xfrm_attrs *attrs,
			      struct mlx5_flow_act *flow_act)
{
	struct mlx5_pkt_reformat_params reformat_params = {};
	struct mlx5_pkt_reformat *pkt_reformat;
	enum mlx5_flow_namespace_type ns_type;
	int ret;

	switch (attrs->dir) {
	case XFRM_DEV_OFFLOAD_IN:
		ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
		break;
	case XFRM_DEV_OFFLOAD_OUT:
		ns_type = MLX5_FLOW_NAMESPACE_EGRESS;
		break;
	default:
		return -EINVAL;
	}

	switch (attrs->mode) {
	case XFRM_MODE_TRANSPORT:
		ret = setup_pkt_transport_reformat(attrs, &reformat_params);
		break;
	default:
		ret = -EINVAL;
	}

	reformat_params.param_0 = attrs->authsize;
	reformat_params.size = sizeof(reformatbf);
	reformat_params.data = &reformatbf;
	if (ret)
		return ret;

cmd:
	pkt_reformat =
		mlx5_packet_reformat_alloc(mdev, &reformat_params, ns_type);
	kfree(reformat_params.data);
	if (IS_ERR(pkt_reformat))
		return PTR_ERR(pkt_reformat);