Skip to content

Commit 1182f36

Browse files
Tariq ToukanSaeed Mahameed
authored andcommitted
net/mlx5e: kTLS, Add kTLS RX HW offload support
Implement driver support for the kTLS RX HW offload feature. Resync support is added in a downstream patch. New offload contexts post their static/progress params WQEs over the per-channel async ICOSQ, protected under a spin-lock. The Channel/RQ is selected according to the socket's rxq index. Feature is OFF by default. Can be turned on by: $ ethtool -K <if> tls-hw-rx-offload on A new TLS-RX workqueue is used to allow asynchronous addition of steering rules, out of the NAPI context. It will be also used in a downstream patch in the resync procedure. Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent df8d866 commit 1182f36

File tree

19 files changed

+529
-32
lines changed

19 files changed

+529
-32
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ config MLX5_TLS
173173
config MLX5_EN_TLS
174174
bool "TLS cryptography-offload accelaration"
175175
depends on MLX5_CORE_EN
176+
depends on XPS
176177
depends on MLX5_FPGA_TLS || MLX5_TLS
177178
default y
178179
help

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mlx5_core-$(CONFIG_MLX5_EN_IPSEC) += en_accel/ipsec.o en_accel/ipsec_rxtx.o \
7575

7676
mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/tls.o en_accel/tls_rxtx.o en_accel/tls_stats.o \
7777
en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \
78-
en_accel/ktls_tx.o
78+
en_accel/ktls_tx.o en_accel/ktls_rx.o
7979

8080
mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o \
8181
steering/dr_matcher.o steering/dr_rule.o \

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,20 @@ int mlx5_ktls_create_key(struct mlx5_core_dev *mdev,
4343
u32 *p_key_id);
4444
void mlx5_ktls_destroy_key(struct mlx5_core_dev *mdev, u32 key_id);
4545

46+
static inline bool mlx5_accel_is_ktls_tx(struct mlx5_core_dev *mdev)
47+
{
48+
return MLX5_CAP_GEN(mdev, tls_tx);
49+
}
50+
51+
static inline bool mlx5_accel_is_ktls_rx(struct mlx5_core_dev *mdev)
52+
{
53+
return MLX5_CAP_GEN(mdev, tls_rx);
54+
}
55+
4656
static inline bool mlx5_accel_is_ktls_device(struct mlx5_core_dev *mdev)
4757
{
48-
if (!MLX5_CAP_GEN(mdev, tls_tx))
58+
if (!mlx5_accel_is_ktls_tx(mdev) &&
59+
!mlx5_accel_is_ktls_rx(mdev))
4960
return false;
5061

5162
if (!MLX5_CAP_GEN(mdev, log_max_dek))
@@ -67,6 +78,12 @@ static inline bool mlx5e_ktls_type_check(struct mlx5_core_dev *mdev,
6778
return false;
6879
}
6980
#else
81+
static inline bool mlx5_accel_is_ktls_tx(struct mlx5_core_dev *mdev)
82+
{ return false; }
83+
84+
static inline bool mlx5_accel_is_ktls_rx(struct mlx5_core_dev *mdev)
85+
{ return false; }
86+
7087
static inline int
7188
mlx5_ktls_create_key(struct mlx5_core_dev *mdev,
7289
struct tls_crypto_info *crypto_info,

drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
enum mlx5e_icosq_wqe_type {
1212
MLX5E_ICOSQ_WQE_NOP,
1313
MLX5E_ICOSQ_WQE_UMR_RX,
14+
#ifdef CONFIG_MLX5_EN_TLS
15+
MLX5E_ICOSQ_WQE_UMR_TLS,
16+
MLX5E_ICOSQ_WQE_SET_PSV_TLS,
17+
#endif
1418
};
1519

1620
static inline bool
@@ -114,9 +118,16 @@ struct mlx5e_icosq_wqe_info {
114118
struct {
115119
struct mlx5e_rq *rq;
116120
} umr;
121+
#ifdef CONFIG_MLX5_EN_TLS
122+
struct {
123+
struct mlx5e_ktls_offload_context_rx *priv_rx;
124+
} tls_set_params;
125+
#endif
117126
};
118127
};
119128

129+
void mlx5e_free_icosq_descs(struct mlx5e_icosq *sq);
130+
120131
static inline u16 mlx5e_icosq_get_next_pi(struct mlx5e_icosq *sq, u16 size)
121132
{
122133
struct mlx5_wq_cyc *wq = &sq->wq;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/skbuff.h>
3838
#include <linux/netdevice.h>
3939
#include "en_accel/ipsec_rxtx.h"
40+
#include "en_accel/tls.h"
4041
#include "en_accel/tls_rxtx.h"
4142
#include "en.h"
4243
#include "en/txrx.h"
@@ -147,4 +148,23 @@ static inline bool mlx5e_accel_tx_finish(struct mlx5e_priv *priv,
147148
return true;
148149
}
149150

151+
static inline int mlx5e_accel_sk_get_rxq(struct sock *sk)
152+
{
153+
int rxq = sk_rx_queue_get(sk);
154+
155+
if (unlikely(rxq == -1))
156+
rxq = 0;
157+
158+
return rxq;
159+
}
160+
161+
static inline int mlx5e_accel_init_rx(struct mlx5e_priv *priv)
162+
{
163+
return mlx5e_ktls_init_rx(priv);
164+
}
165+
166+
static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)
167+
{
168+
mlx5e_ktls_cleanup_rx(priv);
169+
}
150170
#endif /* __MLX5E_EN_ACCEL_H__ */

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

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "en.h"
55
#include "en_accel/ktls.h"
66
#include "en_accel/ktls_utils.h"
7+
#include "en_accel/fs_tcp.h"
78

89
static int mlx5e_ktls_add(struct net_device *netdev, struct sock *sk,
910
enum tls_offload_ctx_dir direction,
@@ -14,13 +15,13 @@ static int mlx5e_ktls_add(struct net_device *netdev, struct sock *sk,
1415
struct mlx5_core_dev *mdev = priv->mdev;
1516
int err;
1617

17-
if (WARN_ON(direction != TLS_OFFLOAD_CTX_DIR_TX))
18-
return -EINVAL;
19-
2018
if (WARN_ON(!mlx5e_ktls_type_check(mdev, crypto_info)))
2119
return -EOPNOTSUPP;
2220

23-
err = mlx5e_ktls_add_tx(netdev, sk, crypto_info, start_offload_tcp_sn);
21+
if (direction == TLS_OFFLOAD_CTX_DIR_TX)
22+
err = mlx5e_ktls_add_tx(netdev, sk, crypto_info, start_offload_tcp_sn);
23+
else
24+
err = mlx5e_ktls_add_rx(netdev, sk, crypto_info, start_offload_tcp_sn);
2425

2526
return err;
2627
}
@@ -29,26 +30,71 @@ static void mlx5e_ktls_del(struct net_device *netdev,
2930
struct tls_context *tls_ctx,
3031
enum tls_offload_ctx_dir direction)
3132
{
32-
if (direction != TLS_OFFLOAD_CTX_DIR_TX)
33-
return;
33+
if (direction == TLS_OFFLOAD_CTX_DIR_TX)
34+
mlx5e_ktls_del_tx(netdev, tls_ctx);
35+
else
36+
mlx5e_ktls_del_rx(netdev, tls_ctx);
37+
}
3438

35-
mlx5e_ktls_del_tx(netdev, tls_ctx);
39+
static int mlx5e_ktls_resync(struct net_device *netdev,
40+
struct sock *sk, u32 seq, u8 *rcd_sn,
41+
enum tls_offload_ctx_dir direction)
42+
{
43+
return -EOPNOTSUPP;
3644
}
3745

3846
static const struct tlsdev_ops mlx5e_ktls_ops = {
3947
.tls_dev_add = mlx5e_ktls_add,
4048
.tls_dev_del = mlx5e_ktls_del,
49+
.tls_dev_resync = mlx5e_ktls_resync,
4150
};
4251

4352
void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)
4453
{
4554
struct net_device *netdev = priv->netdev;
55+
struct mlx5_core_dev *mdev = priv->mdev;
4656

47-
if (!mlx5_accel_is_ktls_device(priv->mdev))
57+
if (!mlx5_accel_is_ktls_device(mdev))
4858
return;
4959

50-
netdev->hw_features |= NETIF_F_HW_TLS_TX;
51-
netdev->features |= NETIF_F_HW_TLS_TX;
60+
if (mlx5_accel_is_ktls_tx(mdev)) {
61+
netdev->hw_features |= NETIF_F_HW_TLS_TX;
62+
netdev->features |= NETIF_F_HW_TLS_TX;
63+
}
64+
65+
if (mlx5_accel_is_ktls_rx(mdev))
66+
netdev->hw_features |= NETIF_F_HW_TLS_RX;
5267

5368
netdev->tlsdev_ops = &mlx5e_ktls_ops;
5469
}
70+
71+
int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
72+
{
73+
struct mlx5e_priv *priv = netdev_priv(netdev);
74+
int err = 0;
75+
76+
mutex_lock(&priv->state_lock);
77+
if (enable)
78+
err = mlx5e_accel_fs_tcp_create(priv);
79+
else
80+
mlx5e_accel_fs_tcp_destroy(priv);
81+
mutex_unlock(&priv->state_lock);
82+
83+
return err;
84+
}
85+
86+
int mlx5e_ktls_init_rx(struct mlx5e_priv *priv)
87+
{
88+
int err = 0;
89+
90+
if (priv->netdev->features & NETIF_F_HW_TLS_RX)
91+
err = mlx5e_accel_fs_tcp_create(priv);
92+
93+
return err;
94+
}
95+
96+
void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv)
97+
{
98+
if (priv->netdev->features & NETIF_F_HW_TLS_RX)
99+
mlx5e_accel_fs_tcp_destroy(priv);
100+
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,30 @@
99
#ifdef CONFIG_MLX5_EN_TLS
1010

1111
void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv);
12-
12+
int mlx5e_ktls_init_rx(struct mlx5e_priv *priv);
13+
void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv);
14+
int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable);
1315
#else
1416

1517
static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)
1618
{
1719
}
1820

21+
static inline int mlx5e_ktls_init_rx(struct mlx5e_priv *priv)
22+
{
23+
return 0;
24+
}
25+
26+
static inline void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv)
27+
{
28+
}
29+
30+
static inline int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
31+
{
32+
netdev_warn(netdev, "kTLS is not supported\n");
33+
return -EOPNOTSUPP;
34+
}
35+
1936
#endif
2037

2138
#endif /* __MLX5E_TLS_H__ */

0 commit comments

Comments
 (0)