xref: /freebsd/sys/dev/mlx5/mlx5_en/en_hw_tls.h (revision 089eb4ead8d22d90100a2ad0923794daee31777d)
1 /*-
2  * Copyright (c) 2019 Mellanox Technologies. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef _MLX5_TLS_H_
29 #define	_MLX5_TLS_H_
30 
31 #define	MLX5E_TLS_TAG_LOCK(tag)		mtx_lock(&(tag)->mtx)
32 #define	MLX5E_TLS_TAG_UNLOCK(tag)	mtx_unlock(&(tag)->mtx)
33 
34 #define	MLX5E_TLS_STAT_INC(tag, field, num) \
35 	counter_u64_add((tag)->tls->stats.field, num)
36 
37 enum {
38       MLX5E_TLS_LOOP = 0,
39       MLX5E_TLS_FAILURE = 1,
40       MLX5E_TLS_DEFERRED = 2,
41       MLX5E_TLS_CONTINUE = 3,
42 };
43 
44 struct mlx5e_tls;
45 struct mlx5e_tls_tag {
46 	struct m_snd_tag tag;
47 	volatile s32 refs;	/* number of pending mbufs */
48 	uint32_t tisn;		/* HW TIS context number */
49 	uint32_t dek_index;	/* HW TLS context number */
50 	struct mlx5e_tls *tls;
51 	struct m_snd_tag *rl_tag;
52 	struct mtx mtx;
53 	uint32_t expected_seq; /* expected TCP sequence number */
54 	uint32_t state;	/* see MLX5E_TLS_ST_XXX */
55 #define	MLX5E_TLS_ST_INIT 0
56 #define	MLX5E_TLS_ST_SETUP 1
57 #define	MLX5E_TLS_ST_TXRDY 2
58 #define	MLX5E_TLS_ST_FREED 3
59 	struct work_struct work;
60 
61 	uint32_t dek_index_ok:1;
62 
63 	/* parameters needed */
64 	uint8_t crypto_params[128] __aligned(4);
65 } __aligned(MLX5E_CACHELINE_SIZE);
66 
67 #define	MLX5E_TLS_STATS(m)					\
68   m(+1, u64, tx_packets, "tx_packets", "Transmitted packets")	\
69   m(+1, u64, tx_bytes, "tx_bytes", "Transmitted bytes")		\
70   m(+1, u64, tx_packets_ooo, "tx_packets_ooo", "Transmitted packets out of order") \
71   m(+1, u64, tx_bytes_ooo, "tx_bytes_ooo", "Transmitted bytes out of order") \
72   m(+1, u64, tx_error, "tx_error", "Transmitted packets with error")
73 
74 #define	MLX5E_TLS_STATS_NUM (0 MLX5E_TLS_STATS(MLX5E_STATS_COUNT))
75 
76 struct mlx5e_tls_stats {
77 	struct	sysctl_ctx_list ctx;
78 	counter_u64_t	arg[0];
79 	MLX5E_TLS_STATS(MLX5E_STATS_COUNTER)
80 };
81 
82 struct mlx5e_tls {
83 	struct sysctl_ctx_list ctx;
84 	struct mlx5e_tls_stats stats;
85 	struct workqueue_struct *wq;
86 	uma_zone_t zone;
87 	uint32_t max_resources;		/* max number of resources */
88 	volatile uint32_t num_resources;	/* current number of resources */
89 	int init;			/* set when ready */
90 	char zname[32];
91 };
92 
93 int mlx5e_tls_init(struct mlx5e_priv *);
94 void mlx5e_tls_cleanup(struct mlx5e_priv *);
95 int mlx5e_sq_tls_xmit(struct mlx5e_sq *, struct mlx5e_xmit_args *, struct mbuf **);
96 
97 if_snd_tag_alloc_t mlx5e_tls_snd_tag_alloc;
98 
99 #endif					/* _MLX5_TLS_H_ */
100