xref: /dpdk/drivers/crypto/mlx5/mlx5_crypto.h (revision f8dbaebbf1c9efcbb2e2354b341ed62175466a57)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2021 NVIDIA Corporation & Affiliates
3  */
4 
5 #ifndef MLX5_CRYPTO_H_
6 #define MLX5_CRYPTO_H_
7 
8 #include <stdbool.h>
9 
10 #include <rte_cryptodev.h>
11 #include <cryptodev_pmd.h>
12 
13 #include <mlx5_common_utils.h>
14 #include <mlx5_common_devx.h>
15 #include <mlx5_common_mr.h>
16 
17 #define MLX5_CRYPTO_DEK_HTABLE_SZ (1 << 11)
18 #define MLX5_CRYPTO_KEY_LENGTH 80
19 #define MLX5_CRYPTO_UMR_WQE_STATIC_SIZE (sizeof(struct mlx5_wqe_cseg) +\
20 					sizeof(struct mlx5_wqe_umr_cseg) +\
21 					sizeof(struct mlx5_wqe_mkey_cseg) +\
22 					sizeof(struct mlx5_wqe_umr_bsf_seg))
23 #define MLX5_CRYPTO_KLM_SEGS_NUM(umr_wqe_sz) ((umr_wqe_sz -\
24 					MLX5_CRYPTO_UMR_WQE_STATIC_SIZE) /\
25 					MLX5_WSEG_SIZE)
26 
27 struct mlx5_crypto_priv {
28 	TAILQ_ENTRY(mlx5_crypto_priv) next;
29 	struct mlx5_common_device *cdev; /* Backend mlx5 device. */
30 	struct rte_cryptodev *crypto_dev;
31 	struct mlx5_uar uar; /* User Access Region. */
32 	uint32_t max_segs_num; /* Maximum supported data segs. */
33 	struct mlx5_hlist *dek_hlist; /* Dek hash list. */
34 	struct rte_cryptodev_config dev_config;
35 	struct mlx5_devx_obj *login_obj;
36 	uint64_t keytag;
37 	uint16_t wqe_set_size;
38 	uint16_t umr_wqe_size;
39 	uint16_t umr_wqe_stride;
40 	uint16_t max_rdmar_ds;
41 };
42 
43 struct mlx5_crypto_qp {
44 	struct mlx5_crypto_priv *priv;
45 	struct mlx5_devx_cq cq_obj;
46 	struct mlx5_devx_qp qp_obj;
47 	struct rte_cryptodev_stats stats;
48 	struct rte_crypto_op **ops;
49 	struct mlx5_devx_obj **mkey; /* WQE's indirect mekys. */
50 	struct mlx5_mr_ctrl mr_ctrl;
51 	uint8_t *wqe;
52 	uint16_t entries_n;
53 	uint16_t pi;
54 	uint16_t ci;
55 	uint16_t db_pi;
56 };
57 
58 struct mlx5_crypto_dek {
59 	struct mlx5_list_entry entry; /* Pointer to DEK hash list entry. */
60 	struct mlx5_devx_obj *obj; /* Pointer to DEK DevX object. */
61 	uint8_t data[MLX5_CRYPTO_KEY_LENGTH]; /* DEK key data. */
62 	bool size_is_48; /* Whether the key\data size is 48 bytes or not. */
63 } __rte_cache_aligned;
64 
65 struct mlx5_crypto_devarg_params {
66 	bool login_devarg;
67 	struct mlx5_devx_crypto_login_attr login_attr;
68 	uint64_t keytag;
69 	uint32_t max_segs_num;
70 };
71 
72 int
73 mlx5_crypto_dek_destroy(struct mlx5_crypto_priv *priv,
74 			struct mlx5_crypto_dek *dek);
75 
76 struct mlx5_crypto_dek *
77 mlx5_crypto_dek_prepare(struct mlx5_crypto_priv *priv,
78 			struct rte_crypto_cipher_xform *cipher);
79 
80 int
81 mlx5_crypto_dek_setup(struct mlx5_crypto_priv *priv);
82 
83 void
84 mlx5_crypto_dek_unset(struct mlx5_crypto_priv *priv);
85 
86 #endif /* MLX5_CRYPTO_H_ */
87