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