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_TXRX_H__
5 #define __MLX5E_KTLS_TXRX_H__
6 
7 #ifdef CONFIG_MLX5_EN_TLS
8 
9 #include <net/tls.h>
10 #include "en.h"
11 #include "en/txrx.h"
12 
13 struct mlx5e_accel_tx_tls_state {
14 	u32 tls_tisn;
15 };
16 
17 u16 mlx5e_ktls_get_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
18 
19 bool mlx5e_ktls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq,
20 			      struct sk_buff *skb,
21 			      struct mlx5e_accel_tx_tls_state *state);
22 void mlx5e_ktls_handle_rx_skb(struct mlx5e_rq *rq, struct sk_buff *skb,
23 			      struct mlx5_cqe64 *cqe, u32 *cqe_bcnt);
24 
25 void mlx5e_ktls_handle_ctx_completion(struct mlx5e_icosq_wqe_info *wi);
26 void mlx5e_ktls_handle_get_psv_completion(struct mlx5e_icosq_wqe_info *wi,
27 					  struct mlx5e_icosq *sq);
28 
29 void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
30 					   struct mlx5e_tx_wqe_info *wi,
31 					   u32 *dma_fifo_cc);
32 static inline bool
mlx5e_ktls_tx_try_handle_resync_dump_comp(struct mlx5e_txqsq * sq,struct mlx5e_tx_wqe_info * wi,u32 * dma_fifo_cc)33 mlx5e_ktls_tx_try_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
34 					  struct mlx5e_tx_wqe_info *wi,
35 					  u32 *dma_fifo_cc)
36 {
37 	if (unlikely(wi->resync_dump_frag_page)) {
38 		mlx5e_ktls_tx_handle_resync_dump_comp(sq, wi, dma_fifo_cc);
39 		return true;
40 	}
41 	return false;
42 }
43 
44 bool mlx5e_ktls_rx_handle_resync_list(struct mlx5e_channel *c, int budget);
45 
46 static inline bool
mlx5e_ktls_rx_pending_resync_list(struct mlx5e_channel * c,int budget)47 mlx5e_ktls_rx_pending_resync_list(struct mlx5e_channel *c, int budget)
48 {
49 	return budget && test_bit(MLX5E_SQ_STATE_PENDING_TLS_RX_RESYNC, &c->async_icosq.state);
50 }
51 
mlx5e_ktls_skb_offloaded(struct sk_buff * skb)52 static inline bool mlx5e_ktls_skb_offloaded(struct sk_buff *skb)
53 {
54 	return skb->sk && tls_is_sk_tx_device_offloaded(skb->sk);
55 }
56 
57 static inline void
mlx5e_ktls_handle_tx_wqe(struct mlx5_wqe_ctrl_seg * cseg,struct mlx5e_accel_tx_tls_state * state)58 mlx5e_ktls_handle_tx_wqe(struct mlx5_wqe_ctrl_seg *cseg,
59 			 struct mlx5e_accel_tx_tls_state *state)
60 {
61 	cseg->tis_tir_num = cpu_to_be32(state->tls_tisn << 8);
62 }
63 #else
64 static inline bool
mlx5e_ktls_tx_try_handle_resync_dump_comp(struct mlx5e_txqsq * sq,struct mlx5e_tx_wqe_info * wi,u32 * dma_fifo_cc)65 mlx5e_ktls_tx_try_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
66 					  struct mlx5e_tx_wqe_info *wi,
67 					  u32 *dma_fifo_cc)
68 {
69 	return false;
70 }
71 
72 static inline bool
mlx5e_ktls_rx_handle_resync_list(struct mlx5e_channel * c,int budget)73 mlx5e_ktls_rx_handle_resync_list(struct mlx5e_channel *c, int budget)
74 {
75 	return false;
76 }
77 
78 static inline bool
mlx5e_ktls_rx_pending_resync_list(struct mlx5e_channel * c,int budget)79 mlx5e_ktls_rx_pending_resync_list(struct mlx5e_channel *c, int budget)
80 {
81 	return false;
82 }
83 
mlx5e_ktls_get_stop_room(struct mlx5_core_dev * mdev,struct mlx5e_params * params)84 static inline u16 mlx5e_ktls_get_stop_room(struct mlx5_core_dev *mdev,
85 					   struct mlx5e_params *params)
86 {
87 	return 0;
88 }
89 
mlx5e_ktls_handle_rx_skb(struct mlx5e_rq * rq,struct sk_buff * skb,struct mlx5_cqe64 * cqe,u32 * cqe_bcnt)90 static inline void mlx5e_ktls_handle_rx_skb(struct mlx5e_rq *rq,
91 					    struct sk_buff *skb,
92 					    struct mlx5_cqe64 *cqe,
93 					    u32 *cqe_bcnt)
94 {
95 }
96 #endif /* CONFIG_MLX5_EN_TLS */
97 
98 #endif /* __MLX5E_TLS_TXRX_H__ */
99