Skip to content

Commit bebb23e

Browse files
ilantayariSaeed Mahameed
authored andcommitted
net/mlx5: Accel, Add IPSec acceleration interface
Add routines for manipulating the hardware IPSec SA database (SADB). In Innova IPSec, a Security Association (SA) is added or deleted via a command message over the SBU connection. The HW then sends a response message over the same connection. Add implementation for Innova IPSec (FPGA-based) hardware. These routines will be used by the IPSec offload support in a later patch However they may also be used by others such as RDMA and RoCE IPSec. mlx5/accel is a middle acceleration layer to allow mlx5e and other ULPs to work directly with mlx5_core rather than Innova FPGA or other mlx5 acceleration providers. In this patchset we add Innova IPSec support and mlx5/accel delegates IPSec offloads to Innova routines. In the future, when IPSec/TLS or any other acceleration gets integrated into ConnectX chip, mlx5/accel layer will provide the integrated acceleration, rather than the Innova one. Signed-off-by: Ilan Tayari <[email protected]> Signed-off-by: Boris Pismenny <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent a9956d3 commit bebb23e

File tree

9 files changed

+772
-1
lines changed

9 files changed

+772
-1
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ config MLX5_CORE
1111
Core driver for low level functionality of the ConnectX-4 and
1212
Connect-IB cards by Mellanox Technologies.
1313

14+
config MLX5_ACCEL
15+
bool
16+
1417
config MLX5_FPGA
1518
bool "Mellanox Technologies Innova support"
1619
depends on MLX5_CORE
20+
select MLX5_ACCEL
1721
---help---
1822
Build support for the Innova family of network cards by Mellanox
1923
Technologies. Innova network cards are comprised of a ConnectX chip

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
66
mad.o transobj.o vport.o sriov.o fs_cmd.o fs_core.o \
77
fs_counters.o rl.o lag.o dev.o lib/gid.o
88

9-
mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o
9+
mlx5_core-$(CONFIG_MLX5_ACCEL) += accel/ipsec.o
10+
11+
mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o \
12+
fpga/ipsec.o
1013

1114
mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o eswitch_offloads.o \
1215
en_main.o en_common.o en_fs.o en_ethtool.o en_tx.o \
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*
32+
*/
33+
34+
#include <linux/mlx5/device.h>
35+
36+
#include "accel/ipsec.h"
37+
#include "mlx5_core.h"
38+
#include "fpga/ipsec.h"
39+
40+
void *mlx5_accel_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
41+
struct mlx5_accel_ipsec_sa *cmd)
42+
{
43+
if (!MLX5_IPSEC_DEV(mdev))
44+
return ERR_PTR(-EOPNOTSUPP);
45+
46+
return mlx5_fpga_ipsec_sa_cmd_exec(mdev, cmd);
47+
}
48+
49+
int mlx5_accel_ipsec_sa_cmd_wait(void *ctx)
50+
{
51+
return mlx5_fpga_ipsec_sa_cmd_wait(ctx);
52+
}
53+
54+
u32 mlx5_accel_ipsec_device_caps(struct mlx5_core_dev *mdev)
55+
{
56+
return mlx5_fpga_ipsec_device_caps(mdev);
57+
}
58+
59+
unsigned int mlx5_accel_ipsec_counters_count(struct mlx5_core_dev *mdev)
60+
{
61+
return mlx5_fpga_ipsec_counters_count(mdev);
62+
}
63+
64+
int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
65+
unsigned int count)
66+
{
67+
return mlx5_fpga_ipsec_counters_read(mdev, counters, count);
68+
}
69+
70+
int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev)
71+
{
72+
return mlx5_fpga_ipsec_init(mdev);
73+
}
74+
75+
void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev)
76+
{
77+
mlx5_fpga_ipsec_cleanup(mdev);
78+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*
32+
*/
33+
34+
#ifndef __MLX5_ACCEL_IPSEC_H__
35+
#define __MLX5_ACCEL_IPSEC_H__
36+
37+
#ifdef CONFIG_MLX5_ACCEL
38+
39+
#include <linux/mlx5/driver.h>
40+
41+
enum {
42+
MLX5_ACCEL_IPSEC_DEVICE = BIT(1),
43+
MLX5_ACCEL_IPSEC_IPV6 = BIT(2),
44+
MLX5_ACCEL_IPSEC_ESP = BIT(3),
45+
MLX5_ACCEL_IPSEC_LSO = BIT(4),
46+
};
47+
48+
#define MLX5_IPSEC_SADB_IP_AH BIT(7)
49+
#define MLX5_IPSEC_SADB_IP_ESP BIT(6)
50+
#define MLX5_IPSEC_SADB_SA_VALID BIT(5)
51+
#define MLX5_IPSEC_SADB_SPI_EN BIT(4)
52+
#define MLX5_IPSEC_SADB_DIR_SX BIT(3)
53+
#define MLX5_IPSEC_SADB_IPV6 BIT(2)
54+
55+
enum {
56+
MLX5_IPSEC_CMD_ADD_SA = 0,
57+
MLX5_IPSEC_CMD_DEL_SA = 1,
58+
};
59+
60+
enum mlx5_accel_ipsec_enc_mode {
61+
MLX5_IPSEC_SADB_MODE_NONE = 0,
62+
MLX5_IPSEC_SADB_MODE_AES_GCM_128_AUTH_128 = 1,
63+
MLX5_IPSEC_SADB_MODE_AES_GCM_256_AUTH_128 = 3,
64+
};
65+
66+
#define MLX5_IPSEC_DEV(mdev) (mlx5_accel_ipsec_device_caps(mdev) & \
67+
MLX5_ACCEL_IPSEC_DEVICE)
68+
69+
struct mlx5_accel_ipsec_sa {
70+
__be32 cmd;
71+
u8 key_enc[32];
72+
u8 key_auth[32];
73+
__be32 sip[4];
74+
__be32 dip[4];
75+
union {
76+
struct {
77+
__be32 reserved;
78+
u8 salt_iv[8];
79+
__be32 salt;
80+
} __packed gcm;
81+
struct {
82+
u8 salt[16];
83+
} __packed cbc;
84+
};
85+
__be32 spi;
86+
__be32 sw_sa_handle;
87+
__be16 tfclen;
88+
u8 enc_mode;
89+
u8 sip_masklen;
90+
u8 dip_masklen;
91+
u8 flags;
92+
u8 reserved[2];
93+
} __packed;
94+
95+
/**
96+
* mlx5_accel_ipsec_sa_cmd_exec - Execute an IPSec SADB command
97+
* @mdev: mlx5 device
98+
* @cmd: command to execute
99+
* May be called from atomic context. Returns context pointer, or error
100+
* Caller must eventually call mlx5_accel_ipsec_sa_cmd_wait from non-atomic
101+
* context, to cleanup the context pointer
102+
*/
103+
void *mlx5_accel_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
104+
struct mlx5_accel_ipsec_sa *cmd);
105+
106+
/**
107+
* mlx5_accel_ipsec_sa_cmd_wait - Wait for command execution completion
108+
* @context: Context pointer returned from call to mlx5_accel_ipsec_sa_cmd_exec
109+
* Sleeps (killable) until command execution is complete.
110+
* Returns the command result, or -EINTR if killed
111+
*/
112+
int mlx5_accel_ipsec_sa_cmd_wait(void *context);
113+
114+
u32 mlx5_accel_ipsec_device_caps(struct mlx5_core_dev *mdev);
115+
116+
unsigned int mlx5_accel_ipsec_counters_count(struct mlx5_core_dev *mdev);
117+
int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
118+
unsigned int count);
119+
120+
int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev);
121+
void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev);
122+
123+
#else
124+
125+
#define MLX5_IPSEC_DEV(mdev) false
126+
127+
static inline int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev)
128+
{
129+
return 0;
130+
}
131+
132+
static inline void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev)
133+
{
134+
}
135+
136+
#endif
137+
138+
#endif /* __MLX5_ACCEL_IPSEC_H__ */

drivers/net/ethernet/mellanox/mlx5/core/fpga/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct mlx5_fpga_device {
5151
struct mlx5_core_mkey mkey;
5252
struct mlx5_uars_page *uar;
5353
} conn_res;
54+
55+
struct mlx5_fpga_ipsec *ipsec;
5456
};
5557

5658
#define mlx5_fpga_dbg(__adev, format, ...) \

0 commit comments

Comments
 (0)