Commit 91bafc63 authored by Jianbo Liu's avatar Jianbo Liu Committed by Jakub Kicinski
Browse files

net/mlx5e: Handle IPsec offload for RX datapath in switchdev mode



Reuse tun opts bits in reg c1, to pass IPsec obj id to datapath.
As this is only for RX SA and there are only 11 bits, xarray is used
to map IPsec obj id to an index, which is between 1 and 0x7ff, and
replace obj id to write to reg c1.

Signed-off-by: default avatarJianbo Liu <jianbol@nvidia.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/43d60fbcc9cd672a97d7e2a2f7fe6a3d9e9a776d.1690802064.git.leon@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1762f132
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -715,9 +715,20 @@ void mlx5e_rep_tc_receive(struct mlx5_cqe64 *cqe, struct mlx5e_rq *rq,
	uplink_priv = &uplink_rpriv->uplink_priv;
	ct_priv = uplink_priv->ct_priv;

	if (!mlx5_ipsec_is_rx_flow(cqe) &&
	    !mlx5e_tc_update_skb(cqe, skb, mapping_ctx, reg_c0, ct_priv, zone_restore_id, tunnel_id,
				 &tc_priv))
#ifdef CONFIG_MLX5_EN_IPSEC
	if (!(tunnel_id >> ESW_TUN_OPTS_BITS)) {
		u32 mapped_id;
		u32 metadata;

		mapped_id = tunnel_id & ESW_IPSEC_RX_MAPPED_ID_MASK;
		if (mapped_id &&
		    !mlx5_esw_ipsec_rx_make_metadata(priv, mapped_id, &metadata))
			mlx5e_ipsec_offload_handle_rx_skb(priv->netdev, skb, metadata);
	}
#endif

	if (!mlx5e_tc_update_skb(cqe, skb, mapping_ctx, reg_c0, ct_priv,
				 zone_restore_id, tunnel_id, &tc_priv))
		goto free_skb;

forward:
+2 −0
Original line number Diff line number Diff line
@@ -210,6 +210,7 @@ struct mlx5e_ipsec_rx {
	struct mlx5e_ipsec_fc *fc;
	struct mlx5_fs_chains *chains;
	u8 allow_tunnel_mode : 1;
	struct xarray ipsec_obj_id_map;
};

struct mlx5e_ipsec {
@@ -256,6 +257,7 @@ struct mlx5e_ipsec_sa_entry {
	struct mlx5e_ipsec_work *work;
	struct mlx5e_ipsec_dwork *dwork;
	struct mlx5e_ipsec_limits limits;
	u32 rx_mapped_id;
};

struct mlx5_accel_pol_xfrm_attrs {
+7 −0
Original line number Diff line number Diff line
@@ -1153,6 +1153,9 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
		err = setup_modify_header(ipsec, attrs->type,
					  sa_entry->ipsec_obj_id | BIT(31),
					  XFRM_DEV_OFFLOAD_IN, &flow_act);
	else
		err = mlx5_esw_ipsec_rx_setup_modify_header(sa_entry, &flow_act);

	if (err)
		goto err_mod_header;

@@ -1641,6 +1644,7 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
	}

	mlx5_modify_header_dealloc(mdev, ipsec_rule->modify_hdr);
	mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
	rx_ft_put(sa_entry->ipsec, sa_entry->attrs.family, sa_entry->attrs.type);
}

@@ -1693,6 +1697,8 @@ void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec)
	kfree(ipsec->rx_ipv6);

	if (ipsec->is_uplink_rep) {
		xa_destroy(&ipsec->rx_esw->ipsec_obj_id_map);

		mutex_destroy(&ipsec->tx_esw->ft.mutex);
		WARN_ON(ipsec->tx_esw->ft.refcnt);
		kfree(ipsec->tx_esw);
@@ -1753,6 +1759,7 @@ int mlx5e_accel_ipsec_fs_init(struct mlx5e_ipsec *ipsec)
		mutex_init(&ipsec->tx_esw->ft.mutex);
		mutex_init(&ipsec->rx_esw->ft.mutex);
		ipsec->tx_esw->ns = ns_esw;
		xa_init_flags(&ipsec->rx_esw->ipsec_obj_id_map, XA_FLAGS_ALLOC1);
	} else if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_ROCE) {
		ipsec->roce = mlx5_ipsec_fs_roce_init(mdev);
	}
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include "ipsec.h"
#include "ipsec_rxtx.h"
#include "en.h"
#include "esw/ipsec_fs.h"

enum {
	MLX5E_IPSEC_TX_SYNDROME_OFFLOAD = 0x8,
@@ -355,3 +356,24 @@ void mlx5e_ipsec_offload_handle_rx_skb(struct net_device *netdev,
		atomic64_inc(&ipsec->sw_stats.ipsec_rx_drop_syndrome);
	}
}

int mlx5_esw_ipsec_rx_make_metadata(struct mlx5e_priv *priv, u32 id, u32 *metadata)
{
	struct mlx5e_ipsec *ipsec = priv->ipsec;
	u32 ipsec_obj_id;
	int err;

	if (!ipsec || !ipsec->is_uplink_rep)
		return -EINVAL;

	err = mlx5_esw_ipsec_rx_ipsec_obj_id_search(priv, id, &ipsec_obj_id);
	if (err) {
		atomic64_inc(&ipsec->sw_stats.ipsec_rx_drop_sadb_miss);
		return err;
	}

	*metadata = MLX5_IPSEC_METADATA_CREATE(ipsec_obj_id,
					       MLX5E_IPSEC_OFFLOAD_RX_SYNDROME_DECRYPTED);

	return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#define MLX5_IPSEC_METADATA_MARKER(metadata)  (((metadata) >> 31) & 0x1)
#define MLX5_IPSEC_METADATA_SYNDROM(metadata) (((metadata) >> 24) & GENMASK(5, 0))
#define MLX5_IPSEC_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(23, 0))
#define MLX5_IPSEC_METADATA_CREATE(id, syndrome) ((id) | ((syndrome) << 24))

struct mlx5e_accel_tx_ipsec_state {
	struct xfrm_offload *xo;
@@ -67,6 +68,7 @@ void mlx5e_ipsec_handle_tx_wqe(struct mlx5e_tx_wqe *wqe,
void mlx5e_ipsec_offload_handle_rx_skb(struct net_device *netdev,
				       struct sk_buff *skb,
				       u32 ipsec_meta_data);
int mlx5_esw_ipsec_rx_make_metadata(struct mlx5e_priv *priv, u32 id, u32 *metadata);
static inline unsigned int mlx5e_ipsec_tx_ids_len(struct mlx5e_accel_tx_ipsec_state *ipsec_st)
{
	return ipsec_st->tailen;
Loading