2 * Copyright (c) 2019 Mellanox Technologies. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
31 #include <sys/queue.h>
33 #define MLX5E_TLS_TAG_LOCK(tag) mtx_lock(&(tag)->mtx)
34 #define MLX5E_TLS_TAG_UNLOCK(tag) mtx_unlock(&(tag)->mtx)
36 #define MLX5E_TLS_STAT_INC(tag, field, num) \
37 counter_u64_add((tag)->tls->stats.field, num)
41 MLX5E_TLS_FAILURE = 1,
42 MLX5E_TLS_DEFERRED = 2,
43 MLX5E_TLS_CONTINUE = 3,
46 struct mlx5e_tls_tag {
47 struct mlx5e_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;
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;
63 uint32_t dek_index_ok:1;
65 /* parameters needed */
66 uint8_t crypto_params[128] __aligned(4);
67 } __aligned(MLX5E_CACHELINE_SIZE);
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")
76 #define MLX5E_TLS_STATS_NUM (0 MLX5E_TLS_STATS(MLX5E_STATS_COUNT))
78 struct mlx5e_tls_stats {
79 struct sysctl_ctx_list ctx;
81 MLX5E_TLS_STATS(MLX5E_STATS_COUNTER)
85 struct sysctl_ctx_list ctx;
86 struct mlx5e_tls_stats stats;
87 struct workqueue_struct *wq;
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 */
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 **);
99 if_snd_tag_alloc_t mlx5e_tls_snd_tag_alloc;
100 if_snd_tag_modify_t mlx5e_tls_snd_tag_modify;
101 if_snd_tag_query_t mlx5e_tls_snd_tag_query;
102 if_snd_tag_free_t mlx5e_tls_snd_tag_free;
104 #endif /* _MLX5_TLS_H_ */