Branch data Line data Source code
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 : : #define MLX5_CRYPTO_GCM_MAX_AAD 64 27 : : #define MLX5_CRYPTO_GCM_MAX_DIGEST 16 28 : : #define MLX5_CRYPTO_GCM_IPSEC_IV_SIZE 16 29 : : 30 : : enum mlx5_crypto_mode { 31 : : MLX5_CRYPTO_FULL_CAPABLE, 32 : : MLX5_CRYPTO_IPSEC_OPT, 33 : : }; 34 : : 35 : : struct __rte_packed_begin mlx5_crypto_ipsec_mem { 36 : : uint8_t mem[MLX5_CRYPTO_GCM_IPSEC_IV_SIZE]; 37 : : } __rte_packed_end; 38 : : 39 : : struct mlx5_crypto_priv { 40 : : TAILQ_ENTRY(mlx5_crypto_priv) next; 41 : : struct mlx5_common_device *cdev; /* Backend mlx5 device. */ 42 : : struct rte_cryptodev *crypto_dev; 43 : : struct mlx5_uar uar; /* User Access Region. */ 44 : : uint32_t max_segs_num; /* Maximum supported data segs. */ 45 : : uint32_t max_klm_num; /* Maximum supported klm. */ 46 : : struct mlx5_hlist *dek_hlist; /* Dek hash list. */ 47 : : const struct rte_cryptodev_capabilities *caps; 48 : : struct rte_cryptodev_config dev_config; 49 : : struct mlx5_devx_obj *login_obj; 50 : : uint64_t keytag; 51 : : uint16_t wqe_set_size; 52 : : uint16_t umr_wqe_size; 53 : : uint16_t umr_wqe_stride; 54 : : uint16_t max_rdmar_ds; 55 : : uint32_t is_wrapped_mode:1; 56 : : enum mlx5_crypto_mode crypto_mode; 57 : : }; 58 : : 59 : : struct mlx5_crypto_qp { 60 : : struct mlx5_crypto_priv *priv; 61 : : struct mlx5_devx_cq cq_obj; 62 : : struct mlx5_devx_qp qp_obj; 63 : : struct mlx5_devx_qp umr_qp_obj; 64 : : struct rte_cryptodev_stats stats; 65 : : struct rte_crypto_op **ops; 66 : : struct mlx5_devx_obj **mkey; /* WQE's indirect mekys. */ 67 : : struct mlx5_klm *klm_array; 68 : : union mlx5_gga_crypto_opaque *opaque_addr; 69 : : struct mlx5_crypto_ipsec_mem *ipsec_mem; 70 : : struct mlx5_mr_ctrl mr_ctrl; 71 : : struct mlx5_pmd_mr mr; 72 : : /* Crypto QP. */ 73 : : uint8_t *wqe; 74 : : uint16_t entries_n; 75 : : uint16_t cq_entries_n; 76 : : uint16_t reported_ci; 77 : : uint16_t qp_ci; 78 : : uint16_t cq_ci; 79 : : uint16_t pi; 80 : : uint16_t ci; 81 : : uint16_t db_pi; 82 : : /* UMR QP. */ 83 : : uint8_t *umr_wqe; 84 : : uint16_t umr_wqbbs; 85 : : uint16_t umr_pi; 86 : : uint16_t umr_ci; 87 : : uint32_t umr_errors; 88 : : uint16_t last_gga_pi; 89 : : bool has_umr; 90 : : uint16_t cpy_tag_op; 91 : : }; 92 : : 93 : : struct __rte_cache_aligned mlx5_crypto_dek { 94 : : struct mlx5_list_entry entry; /* Pointer to DEK hash list entry. */ 95 : : struct mlx5_devx_obj *obj; /* Pointer to DEK DevX object. */ 96 : : uint8_t data[MLX5_CRYPTO_KEY_LENGTH]; /* DEK key data. */ 97 : : uint32_t size; /* key+keytag size. */ 98 : : }; 99 : : 100 : : struct mlx5_crypto_devarg_params { 101 : : bool login_devarg; 102 : : struct mlx5_devx_crypto_login_attr login_attr; 103 : : uint64_t keytag; 104 : : uint32_t max_segs_num; 105 : : uint32_t is_aes_gcm:1; 106 : : enum mlx5_crypto_mode crypto_mode; 107 : : }; 108 : : 109 : : struct __rte_packed_begin mlx5_crypto_session { 110 : : union { 111 : : /**< AES-XTS configuration. */ 112 : : struct { 113 : : uint32_t bs_bpt_eo_es; 114 : : /**< bsf_size, bsf_p_type, encryption_order and encryption standard, 115 : : * saved in big endian format. 116 : : */ 117 : : uint32_t bsp_res; 118 : : /**< crypto_block_size_pointer and reserved 24 bits saved in big 119 : : * endian format. 120 : : */ 121 : : }; 122 : : /**< AES-GCM configuration. */ 123 : : struct { 124 : : uint32_t mmo_ctrl; 125 : : /**< Crypto control fields with algo type and op type in big 126 : : * endian format. 127 : : */ 128 : : uint32_t wqe_aad_len; 129 : : /**< Crypto AAD length field in big endian format. */ 130 : : uint32_t wqe_tag_len; 131 : : /**< Crypto tag length field in big endian format. */ 132 : : uint16_t tag_len; 133 : : /**< AES-GCM crypto digest size in bytes. */ 134 : : uint16_t aad_len; 135 : : /**< The length of the additional authenticated data (AAD) in bytes. */ 136 : : uint32_t op_type; 137 : : /**< Operation type. */ 138 : : }; 139 : : }; 140 : : uint32_t iv_offset:16; 141 : : /**< Starting point for Initialisation Vector. */ 142 : : uint32_t iv_len; 143 : : /**< Initialisation Vector length. */ 144 : : struct mlx5_crypto_dek *dek; /**< Pointer to dek struct. */ 145 : : uint32_t dek_id; /**< DEK ID */ 146 : : } __rte_packed_end; 147 : : 148 : : struct mlx5_crypto_dek_ctx { 149 : : struct rte_crypto_sym_xform *xform; 150 : : struct mlx5_crypto_priv *priv; 151 : : }; 152 : : 153 : : static __rte_always_inline bool 154 : : mlx5_crypto_is_ipsec_opt(struct mlx5_crypto_priv *priv) 155 : : { 156 [ # # # # : 0 : return priv->crypto_mode == MLX5_CRYPTO_IPSEC_OPT; # # # # ] 157 : : } 158 : : 159 : : typedef void *(*mlx5_crypto_mkey_update_t)(struct mlx5_crypto_priv *priv, 160 : : struct mlx5_crypto_qp *qp, 161 : : uint32_t idx); 162 : : 163 : : void 164 : : mlx5_crypto_indirect_mkeys_release(struct mlx5_crypto_qp *qp, 165 : : uint16_t n); 166 : : 167 : : int 168 : : mlx5_crypto_indirect_mkeys_prepare(struct mlx5_crypto_priv *priv, 169 : : struct mlx5_crypto_qp *qp, 170 : : struct mlx5_devx_mkey_attr *attr, 171 : : mlx5_crypto_mkey_update_t update_cb); 172 : : 173 : : int 174 : : mlx5_crypto_dek_destroy(struct mlx5_crypto_priv *priv, 175 : : struct mlx5_crypto_dek *dek); 176 : : 177 : : struct mlx5_crypto_dek * 178 : : mlx5_crypto_dek_prepare(struct mlx5_crypto_priv *priv, 179 : : struct rte_crypto_sym_xform *xform); 180 : : 181 : : int 182 : : mlx5_crypto_dek_setup(struct mlx5_crypto_priv *priv); 183 : : 184 : : void 185 : : mlx5_crypto_dek_unset(struct mlx5_crypto_priv *priv); 186 : : 187 : : int 188 : : mlx5_crypto_xts_init(struct mlx5_crypto_priv *priv); 189 : : 190 : : int 191 : : mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv); 192 : : 193 : : int 194 : : mlx5_crypto_dek_fill_xts_attr(struct mlx5_crypto_dek *dek, 195 : : struct mlx5_devx_dek_attr *dek_attr, 196 : : void *cb_ctx); 197 : : 198 : : int 199 : : mlx5_crypto_dek_fill_gcm_attr(struct mlx5_crypto_dek *dek, 200 : : struct mlx5_devx_dek_attr *dek_attr, 201 : : void *cb_ctx); 202 : : 203 : : #endif /* MLX5_CRYPTO_H_ */