1 /*
2 * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33 #ifndef __MLX5E_TLS_H__
34 #define __MLX5E_TLS_H__
35
36 #include "accel/tls.h"
37 #include "en_accel/ktls.h"
38
39 #ifdef CONFIG_MLX5_EN_TLS
40 #include <net/tls.h>
41 #include "en.h"
42
43 struct mlx5e_tls_sw_stats {
44 atomic64_t tx_tls_ctx;
45 atomic64_t tx_tls_drop_metadata;
46 atomic64_t tx_tls_drop_resync_alloc;
47 atomic64_t tx_tls_drop_no_sync_data;
48 atomic64_t tx_tls_drop_bypass_required;
49 atomic64_t rx_tls_ctx;
50 atomic64_t rx_tls_del;
51 atomic64_t rx_tls_drop_resync_request;
52 atomic64_t rx_tls_resync_request;
53 atomic64_t rx_tls_resync_reply;
54 atomic64_t rx_tls_auth_fail;
55 };
56
57 struct mlx5e_tls {
58 struct mlx5e_tls_sw_stats sw_stats;
59 struct workqueue_struct *rx_wq;
60 };
61
62 struct mlx5e_tls_offload_context_tx {
63 struct tls_offload_context_tx base;
64 u32 expected_seq;
65 __be32 swid;
66 };
67
68 static inline struct mlx5e_tls_offload_context_tx *
mlx5e_get_tls_tx_context(struct tls_context * tls_ctx)69 mlx5e_get_tls_tx_context(struct tls_context *tls_ctx)
70 {
71 BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_tx) >
72 TLS_OFFLOAD_CONTEXT_SIZE_TX);
73 return container_of(tls_offload_ctx_tx(tls_ctx),
74 struct mlx5e_tls_offload_context_tx,
75 base);
76 }
77
78 struct mlx5e_tls_offload_context_rx {
79 struct tls_offload_context_rx base;
80 __be32 handle;
81 };
82
83 static inline struct mlx5e_tls_offload_context_rx *
mlx5e_get_tls_rx_context(struct tls_context * tls_ctx)84 mlx5e_get_tls_rx_context(struct tls_context *tls_ctx)
85 {
86 BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_rx) >
87 TLS_OFFLOAD_CONTEXT_SIZE_RX);
88 return container_of(tls_offload_ctx_rx(tls_ctx),
89 struct mlx5e_tls_offload_context_rx,
90 base);
91 }
92
mlx5e_is_tls_on(struct mlx5e_priv * priv)93 static inline bool mlx5e_is_tls_on(struct mlx5e_priv *priv)
94 {
95 return priv->tls;
96 }
97
98 void mlx5e_tls_build_netdev(struct mlx5e_priv *priv);
99 int mlx5e_tls_init(struct mlx5e_priv *priv);
100 void mlx5e_tls_cleanup(struct mlx5e_priv *priv);
101
102 int mlx5e_tls_get_count(struct mlx5e_priv *priv);
103 int mlx5e_tls_get_strings(struct mlx5e_priv *priv, uint8_t *data);
104 int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data);
105
106 #else
107
mlx5e_tls_build_netdev(struct mlx5e_priv * priv)108 static inline void mlx5e_tls_build_netdev(struct mlx5e_priv *priv)
109 {
110 if (mlx5_accel_is_ktls_device(priv->mdev))
111 mlx5e_ktls_build_netdev(priv);
112 }
113
mlx5e_is_tls_on(struct mlx5e_priv * priv)114 static inline bool mlx5e_is_tls_on(struct mlx5e_priv *priv) { return false; }
mlx5e_tls_init(struct mlx5e_priv * priv)115 static inline int mlx5e_tls_init(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_cleanup(struct mlx5e_priv * priv)116 static inline void mlx5e_tls_cleanup(struct mlx5e_priv *priv) { }
mlx5e_tls_get_count(struct mlx5e_priv * priv)117 static inline int mlx5e_tls_get_count(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_get_strings(struct mlx5e_priv * priv,uint8_t * data)118 static inline int mlx5e_tls_get_strings(struct mlx5e_priv *priv, uint8_t *data) { return 0; }
mlx5e_tls_get_stats(struct mlx5e_priv * priv,u64 * data)119 static inline int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data) { return 0; }
120
121 #endif
122
123 #endif /* __MLX5E_TLS_H__ */
124