Skip to content

Commit d6c4f02

Browse files
aviadyeSaeed Mahameed
authored andcommitted
net/mlx5: Refactor accel IPSec code
The current code has one layer that executed FPGA commands and the Ethernet part directly used this code. Since downstream patches introduces support for IPSec in mlx5_ib, we need to provide some abstractions. This patch refactors the accel code into one layer that creates a software IPSec transformation and another one which creates the actual hardware context. The internal command implementation is now hidden in the FPGA core layer. The code also adds the ability to share FPGA hardware contexts. If two contexts are the same, only a reference count is taken. Signed-off-by: Aviad Yehezkel <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent af9fe19 commit d6c4f02

File tree

7 files changed

+668
-225
lines changed

7 files changed

+668
-225
lines changed

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,6 @@
3737
#include "mlx5_core.h"
3838
#include "fpga/ipsec.h"
3939

40-
void *mlx5_accel_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
41-
struct mlx5_accel_ipsec_sa *cmd)
42-
{
43-
int cmd_size;
44-
45-
if (!MLX5_IPSEC_DEV(mdev))
46-
return ERR_PTR(-EOPNOTSUPP);
47-
48-
if (mlx5_accel_ipsec_device_caps(mdev) & MLX5_ACCEL_IPSEC_CAP_V2_CMD)
49-
cmd_size = sizeof(*cmd);
50-
else
51-
cmd_size = sizeof(cmd->ipsec_sa_v1);
52-
53-
return mlx5_fpga_ipsec_sa_cmd_exec(mdev, cmd, cmd_size);
54-
}
55-
56-
int mlx5_accel_ipsec_sa_cmd_wait(void *ctx)
57-
{
58-
return mlx5_fpga_ipsec_sa_cmd_wait(ctx);
59-
}
60-
6140
u32 mlx5_accel_ipsec_device_caps(struct mlx5_core_dev *mdev)
6241
{
6342
return mlx5_fpga_ipsec_device_caps(mdev);
@@ -75,6 +54,21 @@ int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
7554
return mlx5_fpga_ipsec_counters_read(mdev, counters, count);
7655
}
7756

57+
void *mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
58+
struct mlx5_accel_esp_xfrm *xfrm,
59+
const __be32 saddr[4],
60+
const __be32 daddr[4],
61+
const __be32 spi, bool is_ipv6)
62+
{
63+
return mlx5_fpga_ipsec_create_sa_ctx(mdev, xfrm, saddr, daddr,
64+
spi, is_ipv6);
65+
}
66+
67+
void mlx5_accel_esp_free_hw_context(void *context)
68+
{
69+
mlx5_fpga_ipsec_delete_sa_ctx(context);
70+
}
71+
7872
int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev)
7973
{
8074
return mlx5_fpga_ipsec_init(mdev);
@@ -84,3 +78,25 @@ void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev)
8478
{
8579
mlx5_fpga_ipsec_cleanup(mdev);
8680
}
81+
82+
struct mlx5_accel_esp_xfrm *
83+
mlx5_accel_esp_create_xfrm(struct mlx5_core_dev *mdev,
84+
const struct mlx5_accel_esp_xfrm_attrs *attrs,
85+
u32 flags)
86+
{
87+
struct mlx5_accel_esp_xfrm *xfrm;
88+
89+
xfrm = mlx5_fpga_esp_create_xfrm(mdev, attrs, flags);
90+
if (IS_ERR(xfrm))
91+
return xfrm;
92+
93+
xfrm->mdev = mdev;
94+
return xfrm;
95+
}
96+
EXPORT_SYMBOL_GPL(mlx5_accel_esp_create_xfrm);
97+
98+
void mlx5_accel_esp_destroy_xfrm(struct mlx5_accel_esp_xfrm *xfrm)
99+
{
100+
mlx5_fpga_esp_destroy_xfrm(xfrm);
101+
}
102+
EXPORT_SYMBOL_GPL(mlx5_accel_esp_destroy_xfrm);

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

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -39,96 +39,41 @@
3939

4040
#ifdef CONFIG_MLX5_ACCEL
4141

42-
#define MLX5_IPSEC_SADB_IP_AH BIT(7)
43-
#define MLX5_IPSEC_SADB_IP_ESP BIT(6)
44-
#define MLX5_IPSEC_SADB_SA_VALID BIT(5)
45-
#define MLX5_IPSEC_SADB_SPI_EN BIT(4)
46-
#define MLX5_IPSEC_SADB_DIR_SX BIT(3)
47-
#define MLX5_IPSEC_SADB_IPV6 BIT(2)
48-
49-
enum {
50-
MLX5_IPSEC_CMD_ADD_SA = 0,
51-
MLX5_IPSEC_CMD_DEL_SA = 1,
52-
MLX5_IPSEC_CMD_ADD_SA_V2 = 2,
53-
MLX5_IPSEC_CMD_DEL_SA_V2 = 3,
54-
MLX5_IPSEC_CMD_MOD_SA_V2 = 4,
55-
MLX5_IPSEC_CMD_SET_CAP = 5,
56-
};
57-
58-
enum mlx5_accel_ipsec_enc_mode {
59-
MLX5_IPSEC_SADB_MODE_NONE = 0,
60-
MLX5_IPSEC_SADB_MODE_AES_GCM_128_AUTH_128 = 1,
61-
MLX5_IPSEC_SADB_MODE_AES_GCM_256_AUTH_128 = 3,
62-
};
63-
6442
#define MLX5_IPSEC_DEV(mdev) (mlx5_accel_ipsec_device_caps(mdev) & \
6543
MLX5_ACCEL_IPSEC_CAP_DEVICE)
6644

67-
struct mlx5_accel_ipsec_sa_v1 {
68-
__be32 cmd;
69-
u8 key_enc[32];
70-
u8 key_auth[32];
71-
__be32 sip[4];
72-
__be32 dip[4];
73-
union {
74-
struct {
75-
__be32 reserved;
76-
u8 salt_iv[8];
77-
__be32 salt;
78-
} __packed gcm;
79-
struct {
80-
u8 salt[16];
81-
} __packed cbc;
82-
};
83-
__be32 spi;
84-
__be32 sw_sa_handle;
85-
__be16 tfclen;
86-
u8 enc_mode;
87-
u8 reserved1[2];
88-
u8 flags;
89-
u8 reserved2[2];
90-
};
91-
92-
struct mlx5_accel_ipsec_sa {
93-
struct mlx5_accel_ipsec_sa_v1 ipsec_sa_v1;
94-
__be16 udp_sp;
95-
__be16 udp_dp;
96-
u8 reserved1[4];
97-
__be32 esn;
98-
__be16 vid; /* only 12 bits, rest is reserved */
99-
__be16 reserved2;
100-
} __packed;
101-
102-
/**
103-
* mlx5_accel_ipsec_sa_cmd_exec - Execute an IPSec SADB command
104-
* @mdev: mlx5 device
105-
* @cmd: command to execute
106-
* May be called from atomic context. Returns context pointer, or error
107-
* Caller must eventually call mlx5_accel_ipsec_sa_cmd_wait from non-atomic
108-
* context, to cleanup the context pointer
109-
*/
110-
void *mlx5_accel_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
111-
struct mlx5_accel_ipsec_sa *cmd);
112-
113-
/**
114-
* mlx5_accel_ipsec_sa_cmd_wait - Wait for command execution completion
115-
* @context: Context pointer returned from call to mlx5_accel_ipsec_sa_cmd_exec
116-
* Sleeps (killable) until command execution is complete.
117-
* Returns the command result, or -EINTR if killed
118-
*/
119-
int mlx5_accel_ipsec_sa_cmd_wait(void *context);
120-
12145
unsigned int mlx5_accel_ipsec_counters_count(struct mlx5_core_dev *mdev);
12246
int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
12347
unsigned int count);
12448

49+
void *mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
50+
struct mlx5_accel_esp_xfrm *xfrm,
51+
const __be32 saddr[4],
52+
const __be32 daddr[4],
53+
const __be32 spi, bool is_ipv6);
54+
void mlx5_accel_esp_free_hw_context(void *context);
55+
12556
int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev);
12657
void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev);
12758

12859
#else
12960

13061
#define MLX5_IPSEC_DEV(mdev) false
13162

63+
static inline void *
64+
mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
65+
struct mlx5_accel_esp_xfrm *xfrm,
66+
const __be32 saddr[4],
67+
const __be32 daddr[4],
68+
const __be32 spi, bool is_ipv6)
69+
{
70+
return NULL;
71+
}
72+
73+
static inline void mlx5_accel_esp_free_hw_context(void *context)
74+
{
75+
}
76+
13277
static inline int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev)
13378
{
13479
return 0;

0 commit comments

Comments
 (0)