Revert "mlx5 updates 2023-12-20"
[linux-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_accel / ktls.h
CommitLineData
d2ead1f3
TT
1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2/* Copyright (c) 2019 Mellanox Technologies. */
3
4#ifndef __MLX5E_KTLS_H__
5#define __MLX5E_KTLS_H__
6
0fedee1a 7#include <linux/debugfs.h>
691f17b9 8#include <linux/tls.h>
943aa7bd 9#include <net/tls.h>
d2ead1f3
TT
10#include "en.h"
11
12#ifdef CONFIG_MLX5_EN_TLS
f741db1a
JL
13#include "lib/crypto.h"
14
15struct mlx5_crypto_dek *mlx5_ktls_create_key(struct mlx5_crypto_dek_pool *dek_pool,
16 struct tls_crypto_info *crypto_info);
17void mlx5_ktls_destroy_key(struct mlx5_crypto_dek_pool *dek_pool,
18 struct mlx5_crypto_dek *dek);
691f17b9 19
7a9104ea 20static inline bool mlx5e_is_ktls_device(struct mlx5_core_dev *mdev)
691f17b9 21{
7a9104ea
LR
22 if (is_kdump_kernel())
23 return false;
24
691f17b9
LR
25 if (!MLX5_CAP_GEN(mdev, tls_tx) && !MLX5_CAP_GEN(mdev, tls_rx))
26 return false;
27
28 if (!MLX5_CAP_GEN(mdev, log_max_dek))
29 return false;
30
4960c414
GP
31 return (MLX5_CAP_TLS(mdev, tls_1_2_aes_gcm_128) ||
32 MLX5_CAP_TLS(mdev, tls_1_2_aes_gcm_256));
691f17b9
LR
33}
34
35static inline bool mlx5e_ktls_type_check(struct mlx5_core_dev *mdev,
36 struct tls_crypto_info *crypto_info)
37{
38 switch (crypto_info->cipher_type) {
39 case TLS_CIPHER_AES_GCM_128:
40 if (crypto_info->version == TLS_1_2_VERSION)
41 return MLX5_CAP_TLS(mdev, tls_1_2_aes_gcm_128);
42 break;
4960c414
GP
43 case TLS_CIPHER_AES_GCM_256:
44 if (crypto_info->version == TLS_1_2_VERSION)
45 return MLX5_CAP_TLS(mdev, tls_1_2_aes_gcm_256);
46 break;
691f17b9
LR
47 }
48
49 return false;
50}
d2ead1f3
TT
51
52void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv);
c4dfe704
TT
53int mlx5e_ktls_init_tx(struct mlx5e_priv *priv);
54void mlx5e_ktls_cleanup_tx(struct mlx5e_priv *priv);
1182f365
TT
55int mlx5e_ktls_init_rx(struct mlx5e_priv *priv);
56void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv);
57int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable);
e9ce991b
TT
58struct mlx5e_ktls_resync_resp *
59mlx5e_ktls_rx_resync_create_resp_list(void);
60void mlx5e_ktls_rx_resync_destroy_resp_list(struct mlx5e_ktls_resync_resp *resp_list);
39e8cc6d 61
7a9104ea 62static inline bool mlx5e_is_ktls_tx(struct mlx5_core_dev *mdev)
39e8cc6d 63{
3fbf6120 64 return !is_kdump_kernel() && MLX5_CAP_GEN(mdev, tls_tx);
39e8cc6d
AH
65}
66
4c78782e 67bool mlx5e_is_ktls_rx(struct mlx5_core_dev *mdev);
39e8cc6d 68
943aa7bd
LR
69struct mlx5e_tls_sw_stats {
70 atomic64_t tx_tls_ctx;
71 atomic64_t tx_tls_del;
c4dfe704
TT
72 atomic64_t tx_tls_pool_alloc;
73 atomic64_t tx_tls_pool_free;
943aa7bd
LR
74 atomic64_t rx_tls_ctx;
75 atomic64_t rx_tls_del;
76};
77
0fedee1a
TT
78struct mlx5e_tls_debugfs {
79 struct dentry *dfs;
80 struct dentry *dfs_tx;
81};
82
943aa7bd 83struct mlx5e_tls {
0fedee1a 84 struct mlx5_core_dev *mdev;
943aa7bd
LR
85 struct mlx5e_tls_sw_stats sw_stats;
86 struct workqueue_struct *rx_wq;
c4dfe704 87 struct mlx5e_tls_tx_pool *tx_pool;
f741db1a 88 struct mlx5_crypto_dek_pool *dek_pool;
0fedee1a 89 struct mlx5e_tls_debugfs debugfs;
943aa7bd
LR
90};
91
92int mlx5e_ktls_init(struct mlx5e_priv *priv);
93void mlx5e_ktls_cleanup(struct mlx5e_priv *priv);
94
95int mlx5e_ktls_get_count(struct mlx5e_priv *priv);
96int mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t *data);
97int mlx5e_ktls_get_stats(struct mlx5e_priv *priv, u64 *data);
98
d2ead1f3 99#else
d2ead1f3
TT
100static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)
101{
102}
103
c4dfe704
TT
104static inline int mlx5e_ktls_init_tx(struct mlx5e_priv *priv)
105{
106 return 0;
107}
108
109static inline void mlx5e_ktls_cleanup_tx(struct mlx5e_priv *priv)
110{
111}
112
1182f365
TT
113static inline int mlx5e_ktls_init_rx(struct mlx5e_priv *priv)
114{
115 return 0;
116}
117
118static inline void mlx5e_ktls_cleanup_rx(struct mlx5e_priv *priv)
119{
120}
121
122static inline int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
123{
124 netdev_warn(netdev, "kTLS is not supported\n");
125 return -EOPNOTSUPP;
126}
127
e9ce991b
TT
128static inline struct mlx5e_ktls_resync_resp *
129mlx5e_ktls_rx_resync_create_resp_list(void)
130{
131 return ERR_PTR(-EOPNOTSUPP);
132}
133
134static inline void
135mlx5e_ktls_rx_resync_destroy_resp_list(struct mlx5e_ktls_resync_resp *resp_list) {}
39e8cc6d 136
7a9104ea
LR
137static inline bool mlx5e_is_ktls_rx(struct mlx5_core_dev *mdev)
138{
139 return false;
140}
39e8cc6d 141
943aa7bd
LR
142static inline int mlx5e_ktls_init(struct mlx5e_priv *priv) { return 0; }
143static inline void mlx5e_ktls_cleanup(struct mlx5e_priv *priv) { }
144static inline int mlx5e_ktls_get_count(struct mlx5e_priv *priv) { return 0; }
145static inline int mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t *data)
146{
147 return 0;
148}
149
150static inline int mlx5e_ktls_get_stats(struct mlx5e_priv *priv, u64 *data)
151{
152 return 0;
153}
d2ead1f3
TT
154#endif
155
156#endif /* __MLX5E_TLS_H__ */