xref: /spdk/include/spdk_internal/mlx5.h (revision 12fbe739a31b09aff0d05f354d4f3bbef99afc55)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES.
3  *   All rights reserved.
4  */
5 
6 #ifndef SPDK_MLX5_H
7 #define SPDK_MLX5_H
8 
9 #include <infiniband/mlx5dv.h>
10 
11 struct spdk_mlx5_crypto_dek;
12 struct spdk_mlx5_crypto_keytag;
13 
14 struct spdk_mlx5_crypto_dek_create_attr {
15 	/* Data Encryption Key in binary form */
16 	char *dek;
17 	/* Length of the dek */
18 	size_t dek_len;
19 };
20 
21 /**
22  * Return a NULL terminated array of devices which support crypto operation on Nvidia NICs
23  *
24  * \param dev_num The size of the array or 0
25  * \return Array of contexts. This array must be released with \b spdk_mlx5_crypto_devs_release
26  */
27 struct ibv_context **spdk_mlx5_crypto_devs_get(int *dev_num);
28 
29 /**
30  * Releases array of devices allocated by \b spdk_mlx5_crypto_devs_get
31  *
32  * \param rdma_devs Array of device to be released
33  */
34 void spdk_mlx5_crypto_devs_release(struct ibv_context **rdma_devs);
35 
36 /**
37  * Create a keytag which contains DEKs per each crypto device in the system
38  *
39  * \param attr Crypto attributes
40  * \param out Keytag
41  * \return 0 on success, negated errno of failure
42  */
43 int spdk_mlx5_crypto_keytag_create(struct spdk_mlx5_crypto_dek_create_attr *attr,
44 				   struct spdk_mlx5_crypto_keytag **out);
45 
46 /**
47  * Destroy a keytag created using \b spdk_mlx5_crypto_keytag_create
48  *
49  * \param keytag Keytag pointer
50  */
51 void spdk_mlx5_crypto_keytag_destroy(struct spdk_mlx5_crypto_keytag *keytag);
52 
53 /**
54  * Fills attributes used to register UMR with crypto operation
55  *
56  * \param attr_out Configured UMR attributes
57  * \param keytag Keytag with DEKs
58  * \param pd Protection Domain which is going to be used to register UMR. This function will find a DEK in \b keytag with the same PD
59  * \param block_size Logical block size
60  * \param iv Initialization vector or tweak. Usually that is logical block address
61  * \param encrypt_on_tx If set, memory data will be encrypted during TX and wire data will be decrypted during RX. If not set, memory data will be decrypted during TX and wire data will be encrypted during RX.
62  * \return 0 on success, negated errno on failure
63  */
64 int spdk_mlx5_crypto_set_attr(struct mlx5dv_crypto_attr *attr_out,
65 			      struct spdk_mlx5_crypto_keytag *keytag, struct ibv_pd *pd,
66 			      uint32_t block_size, uint64_t iv, bool encrypt_on_tx);
67 
68 
69 #endif /* SPDK_MLX5_H */
70