xref: /freebsd/sys/dev/mlx5/mlx5_en/en_hw_tls.h (revision 43a5ec4eb41567cc92586503212743d89686d78f)
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 #include <sys/queue.h>
32 
33 #define	MLX5E_TLS_TAG_LOCK(tag)		mtx_lock(&(tag)->mtx)
34 #define	MLX5E_TLS_TAG_UNLOCK(tag)	mtx_unlock(&(tag)->mtx)
35 
36 #define	MLX5E_TLS_STAT_INC(tag, field, num) \
37 	counter_u64_add((tag)->tls->stats.field, num)
38 
39 enum {
40       MLX5E_TLS_LOOP = 0,
41       MLX5E_TLS_FAILURE = 1,
42       MLX5E_TLS_DEFERRED = 2,
43       MLX5E_TLS_CONTINUE = 3,
44 };
45 
46 struct mlx5e_tls_tag {
47 	struct m_snd_tag tag;
48 	STAILQ_ENTRY(mlx5e_tls_tag) entry;
49 	volatile s32 refs;	/* number of pending mbufs */
50 	uint32_t tisn;		/* HW TIS context number */
51 	uint32_t dek_index;	/* HW TLS context number */
52 	struct mlx5e_tls *tls;
53 	struct m_snd_tag *rl_tag;
54 	struct mtx mtx;
55 	uint32_t expected_seq; /* expected TCP sequence number */
56 	uint32_t state;	/* see MLX5E_TLS_ST_XXX */
57 #define	MLX5E_TLS_ST_INIT 0
58 #define	MLX5E_TLS_ST_SETUP 1
59 #define	MLX5E_TLS_ST_TXRDY 2
60 #define	MLX5E_TLS_ST_FREED 3
61 	struct work_struct work;
62 
63 	uint32_t dek_index_ok:1;
64 
65 	/* parameters needed */
66 	uint8_t crypto_params[128] __aligned(4);
67 } __aligned(MLX5E_CACHELINE_SIZE);
68 
69 #define	MLX5E_TLS_STATS(m)					\
70   m(+1, u64, tx_packets, "tx_packets", "Transmitted packets")	\
71   m(+1, u64, tx_bytes, "tx_bytes", "Transmitted bytes")		\
72   m(+1, u64, tx_packets_ooo, "tx_packets_ooo", "Transmitted packets out of order") \
73   m(+1, u64, tx_bytes_ooo, "tx_bytes_ooo", "Transmitted bytes out of order") \
74   m(+1, u64, tx_error, "tx_error", "Transmitted packets with error")
75 
76 #define	MLX5E_TLS_STATS_NUM (0 MLX5E_TLS_STATS(MLX5E_STATS_COUNT))
77 
78 struct mlx5e_tls_stats {
79 	struct	sysctl_ctx_list ctx;
80 	counter_u64_t	arg[0];
81 	MLX5E_TLS_STATS(MLX5E_STATS_COUNTER)
82 };
83 
84 struct mlx5e_tls {
85 	struct sysctl_ctx_list ctx;
86 	struct mlx5e_tls_stats stats;
87 	struct workqueue_struct *wq;
88 	uma_zone_t zone;
89 	uint32_t max_resources;		/* max number of resources */
90 	volatile uint32_t num_resources;	/* current number of resources */
91 	int init;			/* set when ready */
92 	char zname[32];
93 };
94 
95 int mlx5e_tls_init(struct mlx5e_priv *);
96 void mlx5e_tls_cleanup(struct mlx5e_priv *);
97 int mlx5e_sq_tls_xmit(struct mlx5e_sq *, struct mlx5e_xmit_args *, struct mbuf **);
98 
99 if_snd_tag_alloc_t mlx5e_tls_snd_tag_alloc;
100 
101 #endif					/* _MLX5_TLS_H_ */
102