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 #ifdef CONFIG_MLX5_EN_TLS
37 
38 #include <net/tls.h>
39 #include "en.h"
40 
41 struct mlx5e_tls_sw_stats {
42 	atomic64_t tx_tls_drop_metadata;
43 	atomic64_t tx_tls_drop_resync_alloc;
44 	atomic64_t tx_tls_drop_no_sync_data;
45 	atomic64_t tx_tls_drop_bypass_required;
46 	atomic64_t rx_tls_drop_resync_request;
47 	atomic64_t rx_tls_resync_request;
48 	atomic64_t rx_tls_resync_reply;
49 	atomic64_t rx_tls_auth_fail;
50 };
51 
52 struct mlx5e_tls {
53 	struct mlx5e_tls_sw_stats sw_stats;
54 };
55 
56 struct mlx5e_tls_offload_context_tx {
57 	struct tls_offload_context_tx base;
58 	u32 expected_seq;
59 	__be32 swid;
60 };
61 
62 static inline struct mlx5e_tls_offload_context_tx *
mlx5e_get_tls_tx_context(struct tls_context * tls_ctx)63 mlx5e_get_tls_tx_context(struct tls_context *tls_ctx)
64 {
65 	BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_tx) >
66 		     TLS_OFFLOAD_CONTEXT_SIZE_TX);
67 	return container_of(tls_offload_ctx_tx(tls_ctx),
68 			    struct mlx5e_tls_offload_context_tx,
69 			    base);
70 }
71 
72 struct mlx5e_tls_offload_context_rx {
73 	struct tls_offload_context_rx base;
74 	__be32 handle;
75 };
76 
77 static inline struct mlx5e_tls_offload_context_rx *
mlx5e_get_tls_rx_context(struct tls_context * tls_ctx)78 mlx5e_get_tls_rx_context(struct tls_context *tls_ctx)
79 {
80 	BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context_rx) >
81 		     TLS_OFFLOAD_CONTEXT_SIZE_RX);
82 	return container_of(tls_offload_ctx_rx(tls_ctx),
83 			    struct mlx5e_tls_offload_context_rx,
84 			    base);
85 }
86 
87 void mlx5e_tls_build_netdev(struct mlx5e_priv *priv);
88 int mlx5e_tls_init(struct mlx5e_priv *priv);
89 void mlx5e_tls_cleanup(struct mlx5e_priv *priv);
90 
91 int mlx5e_tls_get_count(struct mlx5e_priv *priv);
92 int mlx5e_tls_get_strings(struct mlx5e_priv *priv, uint8_t *data);
93 int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data);
94 
95 #else
96 
mlx5e_tls_build_netdev(struct mlx5e_priv * priv)97 static inline void mlx5e_tls_build_netdev(struct mlx5e_priv *priv) { }
mlx5e_tls_init(struct mlx5e_priv * priv)98 static inline int mlx5e_tls_init(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_cleanup(struct mlx5e_priv * priv)99 static inline void mlx5e_tls_cleanup(struct mlx5e_priv *priv) { }
mlx5e_tls_get_count(struct mlx5e_priv * priv)100 static inline int mlx5e_tls_get_count(struct mlx5e_priv *priv) { return 0; }
mlx5e_tls_get_strings(struct mlx5e_priv * priv,uint8_t * data)101 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)102 static inline int mlx5e_tls_get_stats(struct mlx5e_priv *priv, u64 *data) { return 0; }
103 
104 #endif
105 
106 #endif /* __MLX5E_TLS_H__ */
107