Skip to content

Commit 7d0d0d8

Browse files
Tariq ToukanSaeed Mahameed
authored andcommitted
net/mlx5e: kTLS, Improve TLS feature modularity
Better separate the code into c/h files, so that kTLS internals are exposed to the corresponding non-accel flow as follows: - Necessary datapath functions are exposed via ktls_txrx.h. - Necessary caps and configuration functions are exposed via ktls.h, which became very small. In addition, kTLS internal code sharing is done via ktls_utils.h, which is not exposed to any non-accel file. Add explicit WQE structures for the TLS static and progress params, breaking the union of the static with UMR, and the progress with PSV. Generalize the API as a preparation for TLS RX offload support. Move kTLS TX-specific code to the proper file. Remove the inline tag for function in C files, let the compiler decide. Use kzalloc/kfree for the priv_tx context. Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Maxim Mikityanskiy <[email protected]>
1 parent 5229a96 commit 7d0d0d8

File tree

13 files changed

+376
-288
lines changed

13 files changed

+376
-288
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ mlx5_core-$(CONFIG_MLX5_EN_IPSEC) += en_accel/ipsec.o en_accel/ipsec_rxtx.o \
7474
en_accel/ipsec_stats.o
7575

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

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

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,8 @@ static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
191191

192192
struct mlx5e_tx_wqe {
193193
struct mlx5_wqe_ctrl_seg ctrl;
194-
union {
195-
struct {
196-
struct mlx5_wqe_eth_seg eth;
197-
struct mlx5_wqe_data_seg data[0];
198-
};
199-
u8 tls_progress_params_ctx[0];
200-
};
194+
struct mlx5_wqe_eth_seg eth;
195+
struct mlx5_wqe_data_seg data[0];
201196
};
202197

203198
struct mlx5e_rx_wqe_ll {
@@ -213,10 +208,7 @@ struct mlx5e_umr_wqe {
213208
struct mlx5_wqe_ctrl_seg ctrl;
214209
struct mlx5_wqe_umr_ctrl_seg uctrl;
215210
struct mlx5_mkey_seg mkc;
216-
union {
217-
struct mlx5_mtt inline_mtts[0];
218-
u8 tls_static_params_ctx[0];
219-
};
211+
struct mlx5_mtt inline_mtts[0];
220212
};
221213

222214
extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];

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

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,14 @@
33

44
#include "en.h"
55
#include "en_accel/ktls.h"
6-
7-
u16 mlx5e_ktls_get_stop_room(struct mlx5e_txqsq *sq)
8-
{
9-
u16 num_dumps, stop_room = 0;
10-
11-
num_dumps = mlx5e_ktls_dumps_num_wqes(sq, MAX_SKB_FRAGS, TLS_MAX_PAYLOAD_SIZE);
12-
13-
stop_room += mlx5e_stop_room_for_wqe(MLX5E_KTLS_STATIC_WQEBBS);
14-
stop_room += mlx5e_stop_room_for_wqe(MLX5E_KTLS_PROGRESS_WQEBBS);
15-
stop_room += num_dumps * mlx5e_stop_room_for_wqe(MLX5E_KTLS_DUMP_WQEBBS);
16-
17-
return stop_room;
18-
}
19-
20-
static int mlx5e_ktls_create_tis(struct mlx5_core_dev *mdev, u32 *tisn)
21-
{
22-
u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {};
23-
void *tisc;
24-
25-
tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
26-
27-
MLX5_SET(tisc, tisc, tls_en, 1);
28-
29-
return mlx5e_create_tis(mdev, in, tisn);
30-
}
6+
#include "en_accel/ktls_utils.h"
317

328
static int mlx5e_ktls_add(struct net_device *netdev, struct sock *sk,
339
enum tls_offload_ctx_dir direction,
3410
struct tls_crypto_info *crypto_info,
3511
u32 start_offload_tcp_sn)
3612
{
3713
struct mlx5e_priv *priv = netdev_priv(netdev);
38-
struct mlx5e_ktls_offload_context_tx *tx_priv;
39-
struct tls_context *tls_ctx = tls_get_ctx(sk);
4014
struct mlx5_core_dev *mdev = priv->mdev;
4115
int err;
4216

@@ -46,45 +20,19 @@ static int mlx5e_ktls_add(struct net_device *netdev, struct sock *sk,
4620
if (WARN_ON(!mlx5e_ktls_type_check(mdev, crypto_info)))
4721
return -EOPNOTSUPP;
4822

49-
tx_priv = kvzalloc(sizeof(*tx_priv), GFP_KERNEL);
50-
if (!tx_priv)
51-
return -ENOMEM;
52-
53-
tx_priv->expected_seq = start_offload_tcp_sn;
54-
tx_priv->crypto_info = *(struct tls12_crypto_info_aes_gcm_128 *)crypto_info;
55-
mlx5e_set_ktls_tx_priv_ctx(tls_ctx, tx_priv);
56-
57-
/* tc and underlay_qpn values are not in use for tls tis */
58-
err = mlx5e_ktls_create_tis(mdev, &tx_priv->tisn);
59-
if (err)
60-
goto create_tis_fail;
61-
62-
err = mlx5_ktls_create_key(mdev, crypto_info, &tx_priv->key_id);
63-
if (err)
64-
goto encryption_key_create_fail;
23+
err = mlx5e_ktls_add_tx(netdev, sk, crypto_info, start_offload_tcp_sn);
6524

66-
mlx5e_ktls_tx_offload_set_pending(tx_priv);
67-
68-
return 0;
69-
70-
encryption_key_create_fail:
71-
mlx5e_destroy_tis(priv->mdev, tx_priv->tisn);
72-
create_tis_fail:
73-
kvfree(tx_priv);
7425
return err;
7526
}
7627

7728
static void mlx5e_ktls_del(struct net_device *netdev,
7829
struct tls_context *tls_ctx,
7930
enum tls_offload_ctx_dir direction)
8031
{
81-
struct mlx5e_priv *priv = netdev_priv(netdev);
82-
struct mlx5e_ktls_offload_context_tx *tx_priv =
83-
mlx5e_get_ktls_tx_priv_ctx(tls_ctx);
32+
if (direction != TLS_OFFLOAD_CTX_DIR_TX)
33+
return;
8434

85-
mlx5e_destroy_tis(priv->mdev, tx_priv->tisn);
86-
mlx5_ktls_destroy_key(priv->mdev, tx_priv->key_id);
87-
kvfree(tx_priv);
35+
mlx5e_ktls_del_tx(netdev, tls_ctx);
8836
}
8937

9038
static const struct tlsdev_ops mlx5e_ktls_ops = {

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

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -7,122 +7,15 @@
77
#include "en.h"
88

99
#ifdef CONFIG_MLX5_EN_TLS
10-
#include <net/tls.h>
11-
#include "accel/tls.h"
12-
#include "en_accel/tls_rxtx.h"
13-
14-
#define MLX5E_KTLS_STATIC_UMR_WQE_SZ \
15-
(offsetof(struct mlx5e_umr_wqe, tls_static_params_ctx) + \
16-
MLX5_ST_SZ_BYTES(tls_static_params))
17-
#define MLX5E_KTLS_STATIC_WQEBBS \
18-
(DIV_ROUND_UP(MLX5E_KTLS_STATIC_UMR_WQE_SZ, MLX5_SEND_WQE_BB))
19-
20-
#define MLX5E_KTLS_PROGRESS_WQE_SZ \
21-
(offsetof(struct mlx5e_tx_wqe, tls_progress_params_ctx) + \
22-
sizeof(struct mlx5_wqe_tls_progress_params_seg))
23-
#define MLX5E_KTLS_PROGRESS_WQEBBS \
24-
(DIV_ROUND_UP(MLX5E_KTLS_PROGRESS_WQE_SZ, MLX5_SEND_WQE_BB))
25-
26-
struct mlx5e_dump_wqe {
27-
struct mlx5_wqe_ctrl_seg ctrl;
28-
struct mlx5_wqe_data_seg data;
29-
};
30-
31-
#define MLX5E_TLS_FETCH_UMR_WQE(sq, pi) \
32-
((struct mlx5e_umr_wqe *)mlx5e_fetch_wqe(&(sq)->wq, pi, MLX5E_KTLS_STATIC_UMR_WQE_SZ))
33-
#define MLX5E_TLS_FETCH_PROGRESS_WQE(sq, pi) \
34-
((struct mlx5e_tx_wqe *)mlx5e_fetch_wqe(&(sq)->wq, pi, MLX5E_KTLS_PROGRESS_WQE_SZ))
35-
#define MLX5E_TLS_FETCH_DUMP_WQE(sq, pi) \
36-
((struct mlx5e_dump_wqe *)mlx5e_fetch_wqe(&(sq)->wq, pi, \
37-
sizeof(struct mlx5e_dump_wqe)))
38-
39-
#define MLX5E_KTLS_DUMP_WQEBBS \
40-
(DIV_ROUND_UP(sizeof(struct mlx5e_dump_wqe), MLX5_SEND_WQE_BB))
41-
42-
enum {
43-
MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD = 0,
44-
MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_OFFLOAD = 1,
45-
MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_AUTHENTICATION = 2,
46-
};
47-
48-
enum {
49-
MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_START = 0,
50-
MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_TRACKING = 1,
51-
MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_SEARCHING = 2,
52-
};
53-
54-
struct mlx5e_ktls_offload_context_tx {
55-
struct tls_offload_context_tx *tx_ctx;
56-
struct tls12_crypto_info_aes_gcm_128 crypto_info;
57-
u32 expected_seq;
58-
u32 tisn;
59-
u32 key_id;
60-
bool ctx_post_pending;
61-
};
62-
63-
struct mlx5e_ktls_offload_context_tx_shadow {
64-
struct tls_offload_context_tx tx_ctx;
65-
struct mlx5e_ktls_offload_context_tx *priv_tx;
66-
};
67-
68-
static inline void
69-
mlx5e_set_ktls_tx_priv_ctx(struct tls_context *tls_ctx,
70-
struct mlx5e_ktls_offload_context_tx *priv_tx)
71-
{
72-
struct tls_offload_context_tx *tx_ctx = tls_offload_ctx_tx(tls_ctx);
73-
struct mlx5e_ktls_offload_context_tx_shadow *shadow;
74-
75-
BUILD_BUG_ON(sizeof(*shadow) > TLS_OFFLOAD_CONTEXT_SIZE_TX);
76-
77-
shadow = (struct mlx5e_ktls_offload_context_tx_shadow *)tx_ctx;
78-
79-
shadow->priv_tx = priv_tx;
80-
priv_tx->tx_ctx = tx_ctx;
81-
}
82-
83-
static inline struct mlx5e_ktls_offload_context_tx *
84-
mlx5e_get_ktls_tx_priv_ctx(struct tls_context *tls_ctx)
85-
{
86-
struct tls_offload_context_tx *tx_ctx = tls_offload_ctx_tx(tls_ctx);
87-
struct mlx5e_ktls_offload_context_tx_shadow *shadow;
88-
89-
BUILD_BUG_ON(sizeof(*shadow) > TLS_OFFLOAD_CONTEXT_SIZE_TX);
90-
91-
shadow = (struct mlx5e_ktls_offload_context_tx_shadow *)tx_ctx;
92-
93-
return shadow->priv_tx;
94-
}
9510

9611
void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv);
97-
void mlx5e_ktls_tx_offload_set_pending(struct mlx5e_ktls_offload_context_tx *priv_tx);
9812

99-
bool mlx5e_ktls_handle_tx_skb(struct tls_context *tls_ctx, struct mlx5e_txqsq *sq,
100-
struct sk_buff *skb, int datalen,
101-
struct mlx5e_accel_tx_tls_state *state);
102-
void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
103-
struct mlx5e_tx_wqe_info *wi,
104-
u32 *dma_fifo_cc);
105-
u16 mlx5e_ktls_get_stop_room(struct mlx5e_txqsq *sq);
106-
107-
static inline u8
108-
mlx5e_ktls_dumps_num_wqes(struct mlx5e_txqsq *sq, unsigned int nfrags,
109-
unsigned int sync_len)
110-
{
111-
/* Given the MTU and sync_len, calculates an upper bound for the
112-
* number of DUMP WQEs needed for the TX resync of a record.
113-
*/
114-
return nfrags + DIV_ROUND_UP(sync_len, sq->hw_mtu);
115-
}
11613
#else
11714

11815
static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)
11916
{
12017
}
12118

122-
static inline void
123-
mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
124-
struct mlx5e_tx_wqe_info *wi,
125-
u32 *dma_fifo_cc) {}
12619
#endif
12720

12821
#endif /* __MLX5E_TLS_H__ */

0 commit comments

Comments
 (0)