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