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 #include "accel/tls.h" 10 11 enum { 12 MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD = 0, 13 MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_OFFLOAD = 1, 14 MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_AUTHENTICATION = 2, 15 }; 16 17 enum { 18 MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_START = 0, 19 MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_TRACKING = 1, 20 MLX5E_TLS_PROGRESS_PARAMS_RECORD_TRACKER_STATE_SEARCHING = 2, 21 }; 22 23 int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk, 24 struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn); 25 void mlx5e_ktls_del_tx(struct net_device *netdev, struct tls_context *tls_ctx); 26 int mlx5e_ktls_add_rx(struct net_device *netdev, struct sock *sk, 27 struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn); 28 void mlx5e_ktls_del_rx(struct net_device *netdev, struct tls_context *tls_ctx); 29 void mlx5e_ktls_rx_resync(struct net_device *netdev, struct sock *sk, u32 seq, u8 *rcd_sn); 30 31 struct mlx5e_set_tls_static_params_wqe { 32 struct mlx5_wqe_ctrl_seg ctrl; 33 struct mlx5_wqe_umr_ctrl_seg uctrl; 34 struct mlx5_mkey_seg mkc; 35 struct mlx5_wqe_tls_static_params_seg params; 36 }; 37 38 struct mlx5e_set_tls_progress_params_wqe { 39 struct mlx5_wqe_ctrl_seg ctrl; 40 struct mlx5_wqe_tls_progress_params_seg params; 41 }; 42 43 struct mlx5e_get_tls_progress_params_wqe { 44 struct mlx5_wqe_ctrl_seg ctrl; 45 struct mlx5_seg_get_psv psv; 46 }; 47 48 #define MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS \ 49 (DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_static_params_wqe), MLX5_SEND_WQE_BB)) 50 51 #define MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS \ 52 (DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_progress_params_wqe), MLX5_SEND_WQE_BB)) 53 54 #define MLX5E_KTLS_GET_PROGRESS_WQEBBS \ 55 (DIV_ROUND_UP(sizeof(struct mlx5e_get_tls_progress_params_wqe), MLX5_SEND_WQE_BB)) 56 57 #define MLX5E_TLS_FETCH_SET_STATIC_PARAMS_WQE(sq, pi) \ 58 ((struct mlx5e_set_tls_static_params_wqe *)\ 59 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_static_params_wqe))) 60 61 #define MLX5E_TLS_FETCH_SET_PROGRESS_PARAMS_WQE(sq, pi) \ 62 ((struct mlx5e_set_tls_progress_params_wqe *)\ 63 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_progress_params_wqe))) 64 65 #define MLX5E_TLS_FETCH_GET_PROGRESS_PARAMS_WQE(sq, pi) \ 66 ((struct mlx5e_get_tls_progress_params_wqe *)\ 67 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_get_tls_progress_params_wqe))) 68 69 #define MLX5E_TLS_FETCH_DUMP_WQE(sq, pi) \ 70 ((struct mlx5e_dump_wqe *)\ 71 mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_dump_wqe))) 72 73 void 74 mlx5e_ktls_build_static_params(struct mlx5e_set_tls_static_params_wqe *wqe, 75 u16 pc, u32 sqn, 76 struct tls12_crypto_info_aes_gcm_128 *info, 77 u32 tis_tir_num, u32 key_id, u32 resync_tcp_sn, 78 bool fence, enum tls_offload_ctx_dir direction); 79 void 80 mlx5e_ktls_build_progress_params(struct mlx5e_set_tls_progress_params_wqe *wqe, 81 u16 pc, u32 sqn, 82 u32 tis_tir_num, bool fence, 83 u32 next_record_tcp_sn, 84 enum tls_offload_ctx_dir direction); 85 86 #endif /* __MLX5E_TLS_UTILS_H__ */ 87