crypto/aesni_mb: call buffer manager allocation
[dpdk.git] / drivers / crypto / aesni_mb / rte_aesni_mb_pmd_private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2016 Intel Corporation
3  */
4
5 #ifndef _RTE_AESNI_MB_PMD_PRIVATE_H_
6 #define _RTE_AESNI_MB_PMD_PRIVATE_H_
7
8 #include "aesni_mb_ops.h"
9
10 #define CRYPTODEV_NAME_AESNI_MB_PMD     crypto_aesni_mb
11 /**< AES-NI Multi buffer PMD device name */
12
13 /** AESNI_MB PMD LOGTYPE DRIVER */
14 int aesni_mb_logtype_driver;
15
16 #define AESNI_MB_LOG(level, fmt, ...)  \
17         rte_log(RTE_LOG_ ## level, aesni_mb_logtype_driver,  \
18                         "%s() line %u: " fmt "\n", __func__, __LINE__,  \
19                                         ## __VA_ARGS__)
20
21
22 #define HMAC_IPAD_VALUE                 (0x36)
23 #define HMAC_OPAD_VALUE                 (0x5C)
24
25 /* Maximum length for digest (SHA-512 truncated needs 32 bytes) */
26 #define DIGEST_LENGTH_MAX 32
27 static const unsigned auth_blocksize[] = {
28                 [MD5]           = 64,
29                 [SHA1]          = 64,
30                 [SHA_224]       = 64,
31                 [SHA_256]       = 64,
32                 [SHA_384]       = 128,
33                 [SHA_512]       = 128,
34                 [AES_XCBC]      = 16,
35                 [AES_CCM]       = 16,
36 };
37
38 /**
39  * Get the blocksize in bytes for a specified authentication algorithm
40  *
41  * @Note: this function will not return a valid value for a non-valid
42  * authentication algorithm
43  */
44 static inline unsigned
45 get_auth_algo_blocksize(JOB_HASH_ALG algo)
46 {
47         return auth_blocksize[algo];
48 }
49
50 static const unsigned auth_truncated_digest_byte_lengths[] = {
51                 [MD5]           = 12,
52                 [SHA1]          = 12,
53                 [SHA_224]       = 14,
54                 [SHA_256]       = 16,
55                 [SHA_384]       = 24,
56                 [SHA_512]       = 32,
57                 [AES_XCBC]      = 12,
58                 [AES_CMAC]      = 16,
59                 [AES_CCM]       = 8,
60                 [NULL_HASH]     = 0
61 };
62
63 /**
64  * Get the IPsec specified truncated length in bytes of the HMAC digest for a
65  * specified authentication algorithm
66  *
67  * @Note: this function will not return a valid value for a non-valid
68  * authentication algorithm
69  */
70 static inline unsigned
71 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
72 {
73         return auth_truncated_digest_byte_lengths[algo];
74 }
75
76 static const unsigned auth_digest_byte_lengths[] = {
77                 [MD5]           = 16,
78                 [SHA1]          = 20,
79                 [SHA_224]       = 28,
80                 [SHA_256]       = 32,
81                 [SHA_384]       = 48,
82                 [SHA_512]       = 64,
83                 [AES_XCBC]      = 16,
84                 [AES_CMAC]      = 16,
85                 [NULL_HASH]             = 0
86 };
87
88 /**
89  * Get the output digest size in bytes for a specified authentication algorithm
90  *
91  * @Note: this function will not return a valid value for a non-valid
92  * authentication algorithm
93  */
94 static inline unsigned
95 get_digest_byte_length(JOB_HASH_ALG algo)
96 {
97         return auth_digest_byte_lengths[algo];
98 }
99
100 enum aesni_mb_operation {
101         AESNI_MB_OP_HASH_CIPHER,
102         AESNI_MB_OP_CIPHER_HASH,
103         AESNI_MB_OP_HASH_ONLY,
104         AESNI_MB_OP_CIPHER_ONLY,
105         AESNI_MB_OP_AEAD_HASH_CIPHER,
106         AESNI_MB_OP_AEAD_CIPHER_HASH,
107         AESNI_MB_OP_NOT_SUPPORTED
108 };
109
110 /** private data structure for each virtual AESNI device */
111 struct aesni_mb_private {
112         enum aesni_mb_vector_mode vector_mode;
113         /**< CPU vector instruction set mode */
114         unsigned max_nb_queue_pairs;
115         /**< Max number of queue pairs supported by device */
116 };
117
118 /** AESNI Multi buffer queue pair */
119 struct aesni_mb_qp {
120         uint16_t id;
121         /**< Queue Pair Identifier */
122         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
123         /**< Unique Queue Pair Name */
124         const struct aesni_mb_op_fns *op_fns;
125         /**< Vector mode dependent pointer table of the multi-buffer APIs */
126         MB_MGR *mb_mgr;
127         /**< Multi-buffer instance */
128         struct rte_ring *ingress_queue;
129        /**< Ring for placing operations ready for processing */
130         struct rte_mempool *sess_mp;
131         /**< Session Mempool */
132         struct rte_cryptodev_stats stats;
133         /**< Queue pair statistics */
134         uint8_t digest_idx;
135         /**< Index of the next slot to be used in temp_digests,
136          * to store the digest for a given operation
137          */
138         uint8_t temp_digests[MAX_JOBS][DIGEST_LENGTH_MAX];
139         /**< Buffers used to store the digest generated
140          * by the driver when verifying a digest provided
141          * by the user (using authentication verify operation)
142          */
143 } __rte_cache_aligned;
144
145 /** AES-NI multi-buffer private session structure */
146 struct aesni_mb_session {
147         JOB_CHAIN_ORDER chain_order;
148         struct {
149                 uint16_t length;
150                 uint16_t offset;
151         } iv;
152         /**< IV parameters */
153
154         /** Cipher Parameters */
155         struct {
156                 /** Cipher direction - encrypt / decrypt */
157                 JOB_CIPHER_DIRECTION direction;
158                 /** Cipher mode - CBC / Counter */
159                 JOB_CIPHER_MODE mode;
160
161                 uint64_t key_length_in_bytes;
162
163                 struct {
164                         uint32_t encode[60] __rte_aligned(16);
165                         /**< encode key */
166                         uint32_t decode[60] __rte_aligned(16);
167                         /**< decode key */
168                 } expanded_aes_keys;
169                 /**< Expanded AES keys - Allocating space to
170                  * contain the maximum expanded key size which
171                  * is 240 bytes for 256 bit AES, calculate by:
172                  * ((key size (bytes)) *
173                  * ((number of rounds) + 1))
174                  */
175         } cipher;
176
177         /** Authentication Parameters */
178         struct {
179                 JOB_HASH_ALG algo; /**< Authentication Algorithm */
180                 enum rte_crypto_auth_operation operation;
181                 /**< auth operation generate or verify */
182                 union {
183                         struct {
184                                 uint8_t inner[128] __rte_aligned(16);
185                                 /**< inner pad */
186                                 uint8_t outer[128] __rte_aligned(16);
187                                 /**< outer pad */
188                         } pads;
189                         /**< HMAC Authentication pads -
190                          * allocating space for the maximum pad
191                          * size supported which is 128 bytes for
192                          * SHA512
193                          */
194
195                         struct {
196                             uint32_t k1_expanded[44] __rte_aligned(16);
197                             /**< k1 (expanded key). */
198                             uint8_t k2[16] __rte_aligned(16);
199                             /**< k2. */
200                             uint8_t k3[16] __rte_aligned(16);
201                             /**< k3. */
202                         } xcbc;
203
204                         struct {
205                                 uint32_t expkey[60] __rte_aligned(16);
206                                                     /**< k1 (expanded key). */
207                                 uint32_t skey1[4] __rte_aligned(16);
208                                                     /**< k2. */
209                                 uint32_t skey2[4] __rte_aligned(16);
210                                                     /**< k3. */
211                         } cmac;
212                         /**< Expanded XCBC authentication keys */
213                 };
214         /** digest size */
215         uint16_t digest_len;
216
217         } auth;
218         struct {
219                 /** AAD data length */
220                 uint16_t aad_len;
221         } aead;
222 } __rte_cache_aligned;
223
224
225 /**
226  *
227  */
228 extern int
229 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
230                 struct aesni_mb_session *sess,
231                 const struct rte_crypto_sym_xform *xform);
232
233
234 /** device specific operations function pointer structure */
235 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
236
237
238
239 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */