xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_utils.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */
3 
4 #ifndef __MLX5E_KTLS_UTILS_H__
5 #define __MLX5E_KTLS_UTILS_H__
6 
7 #include <net/tls.h>
8 #include "en.h"
9 
10 enum {
11 	MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD     = 0,
12 	MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_OFFLOAD        = 1,
13 	MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_AUTHENTICATION = 2,
14 };
15 
16 enum {
17 	MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_START     = 0,
18 	MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_TRACKING  = 1,
19 	MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_SEARCHING = 2,
20 };
21 
22 int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk,
23 		      struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn);
24 void mlx5e_ktls_del_tx(struct net_device *netdev, struct tls_context *tls_ctx);
25 int mlx5e_ktls_add_rx(struct net_device *netdev, struct sock *sk,
26 		      struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn);
27 void mlx5e_ktls_del_rx(struct net_device *netdev, struct tls_context *tls_ctx);
28 void mlx5e_ktls_rx_resync(struct net_device *netdev, struct sock *sk, u32 seq, u8 *rcd_sn);
29 
30 union mlx5e_crypto_info {
31 	struct tls_crypto_info crypto_info;
32 	struct tls12_crypto_info_aes_gcm_128 crypto_info_128;
33 	struct tls12_crypto_info_aes_gcm_256 crypto_info_256;
34 };
35 
36 struct mlx5e_set_tls_static_params_wqe {
37 	struct mlx5_wqe_ctrl_seg ctrl;
38 	struct mlx5_wqe_umr_ctrl_seg uctrl;
39 	struct mlx5_mkey_seg mkc;
40 	struct mlx5_wqe_tls_static_params_seg params;
41 };
42 
43 struct mlx5e_set_tls_progress_params_wqe {
44 	struct mlx5_wqe_ctrl_seg ctrl;
45 	struct mlx5_wqe_tls_progress_params_seg params;
46 };
47 
48 struct mlx5e_get_tls_progress_params_wqe {
49 	struct mlx5_wqe_ctrl_seg ctrl;
50 	struct mlx5_seg_get_psv  psv;
51 };
52 
53 #define MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS \
54 	(DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_static_params_wqe), MLX5_SEND_WQE_BB))
55 
56 #define MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS \
57 	(DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_progress_params_wqe), MLX5_SEND_WQE_BB))
58 
59 #define MLX5E_KTLS_GET_PROGRESS_WQEBBS \
60 	(DIV_ROUND_UP(sizeof(struct mlx5e_get_tls_progress_params_wqe), MLX5_SEND_WQE_BB))
61 
62 #define MLX5E_TLS_FETCH_SET_STATIC_PARAMS_WQE(sq, pi) \
63 	((struct mlx5e_set_tls_static_params_wqe *)\
64 	 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_static_params_wqe)))
65 
66 #define MLX5E_TLS_FETCH_SET_PROGRESS_PARAMS_WQE(sq, pi) \
67 	((struct mlx5e_set_tls_progress_params_wqe *)\
68 	 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_progress_params_wqe)))
69 
70 #define MLX5E_TLS_FETCH_GET_PROGRESS_PARAMS_WQE(sq, pi) \
71 	((struct mlx5e_get_tls_progress_params_wqe *)\
72 	 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_get_tls_progress_params_wqe)))
73 
74 #define MLX5E_TLS_FETCH_DUMP_WQE(sq, pi) \
75 	((struct mlx5e_dump_wqe *)\
76 	 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_dump_wqe)))
77 
78 void
79 mlx5e_ktls_build_static_params(struct mlx5e_set_tls_static_params_wqe *wqe,
80 			       u16 pc, u32 sqn,
81 			       union mlx5e_crypto_info *crypto_info,
82 			       u32 tis_tir_num, u32 key_id, u32 resync_tcp_sn,
83 			       bool fence, enum tls_offload_ctx_dir direction);
84 void
85 mlx5e_ktls_build_progress_params(struct mlx5e_set_tls_progress_params_wqe *wqe,
86 				 u16 pc, u32 sqn,
87 				 u32 tis_tir_num, bool fence,
88 				 u32 next_record_tcp_sn,
89 				 enum tls_offload_ctx_dir direction);
90 
91 #endif /* __MLX5E_TLS_UTILS_H__ */
92