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_del;
46 atomic64_t tx_tls_drop_metadata;
47 atomic64_t tx_tls_drop_resync_alloc;
48 atomic64_t tx_tls_drop_no_sync_data;
49 atomic64_t tx_tls_drop_bypass_required;
50 atomic64_t rx_tls_ctx;
51 atomic64_t rx_tls_del;
52 atomic64_t rx_tls_drop_resync_request;
53 atomic64_t rx_tls_resync_request;
54 atomic64_t rx_tls_resync_reply;
55 atomic64_t rx_tls_auth_fail;
56 };
57
58 struct mlx5e_tls {
59 struct mlx5e_tls_sw_stats sw_stats;
60 struct workqueue_struct *rx_wq;
61 };
62
63 struct mlx5e_tls_offload_context_tx {
64 struct tls_offload_context_tx base;
65 u32 expected_seq;
66 __be32 swid;
67 };
68
69 static inline struct mlx5e_tls_offload_context_tx *
mlx5e_get_tls_tx_context(struct tls_context * tls_ctx)70 mlx5e_get_tls_tx_context(struct tls_context *tls_ctx)
71 {
72 BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_tx) >
73 TLS_OFFLOAD_CONTEXT_SIZE_TX);
74 return container_of(tls_offload_ctx_tx(tls_ctx),
75 struct mlx5e_tls_offload_context_tx,
76 base);
77 }
78
79 struct mlx5e_tls_offload_context_rx {
80 struct tls_offload_context_rx base;
81 __be32 handle;
82 };
83
84 static inline struct mlx5e_tls_offload_context_rx *
mlx5e_get_tls_rx_context(struct tls_context * tls_ctx)85 mlx5e_get_tls_rx_context(struct tls_context *tls_ctx)
86 {
87 BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_rx) >
88 TLS_OFFLOAD_CONTEXT_SIZE_RX);
89 return container_of(tls_offload_ctx_rx(tls_ctx),
90 struct mlx5e_tls_offload_context_rx,
91 base);
92 }
93
mlx5e_is_tls_on(struct mlx5e_priv * priv)94 static inline bool mlx5e_is_tls_on(struct mlx5e_priv *priv)
95 {
96 return priv->tls;
97 }
98
99 void mlx5e_tls_build_netdev(struct mlx5e_priv *priv);
100 int mlx5e_tls_init(struct mlx5e_priv *priv);
101 void mlx5e_tls_cleanup(struct mlx5e_priv *priv);
102
103 int mlx5e_tls_get_count(struct mlx5e_priv *priv);
104 int mlx5e_tls_get_strings(struct mlx5e_priv *priv, uint8_t *data);
105 int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data);
106
mlx5e_accel_is_tls_device(struct mlx5_core_dev * mdev)107 static inline bool mlx5e_accel_is_tls_device(struct mlx5_core_dev *mdev)
108 {
109 return !is_kdump_kernel() &&
110 mlx5_accel_is_tls_device(mdev);
111 }
112
113 #else
114
mlx5e_tls_build_netdev(struct mlx5e_priv * priv)115 static inline void mlx5e_tls_build_netdev(struct mlx5e_priv *priv)
116 {
117 if (!is_kdump_kernel() &&
118 mlx5_accel_is_ktls_device(priv->mdev))
119 mlx5e_ktls_build_netdev(priv);
120 }
121
mlx5e_is_tls_on(struct mlx5e_priv * priv)122 static inline bool mlx5e_is_tls_on(struct mlx5e_priv *priv) { return false; }
mlx5e_tls_init(struct mlx5e_priv * priv)123 static inline int mlx5e_tls_init(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_cleanup(struct mlx5e_priv * priv)124 static inline void mlx5e_tls_cleanup(struct mlx5e_priv *priv) { }
mlx5e_tls_get_count(struct mlx5e_priv * priv)125 static inline int mlx5e_tls_get_count(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_get_strings(struct mlx5e_priv * priv,uint8_t * data)126 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)127 static inline int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data) { return 0; }
mlx5e_accel_is_tls_device(struct mlx5_core_dev * mdev)128 static inline bool mlx5e_accel_is_tls_device(struct mlx5_core_dev *mdev) { return false; }
129
130 #endif
131
132 #endif /* __MLX5E_TLS_H__ */
133