]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2017 Cavium, Inc | |
11fdf7f2 TL |
3 | */ |
4 | ||
5 | #ifndef _RTE_ARMV8_PMD_PRIVATE_H_ | |
6 | #define _RTE_ARMV8_PMD_PRIVATE_H_ | |
7 | ||
9f95a23c TL |
8 | #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8 |
9 | /**< ARMv8 Crypto PMD device name */ | |
10 | ||
11fdf7f2 TL |
11 | #define ARMV8_CRYPTO_LOG_ERR(fmt, args...) \ |
12 | RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \ | |
13 | RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \ | |
14 | __func__, __LINE__, ## args) | |
15 | ||
16 | #ifdef RTE_LIBRTE_ARMV8_CRYPTO_DEBUG | |
17 | #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \ | |
18 | RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \ | |
19 | RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \ | |
20 | __func__, __LINE__, ## args) | |
21 | ||
22 | #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \ | |
23 | RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \ | |
24 | RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \ | |
25 | __func__, __LINE__, ## args) | |
26 | ||
27 | #define ARMV8_CRYPTO_ASSERT(con) \ | |
28 | do { \ | |
29 | if (!(con)) { \ | |
30 | rte_panic("%s(): " \ | |
31 | con "condition failed, line %u", __func__); \ | |
32 | } \ | |
33 | } while (0) | |
34 | ||
35 | #else | |
36 | #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) | |
37 | #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) | |
38 | #define ARMV8_CRYPTO_ASSERT(con) | |
39 | #endif | |
40 | ||
41 | #define NBBY 8 /* Number of bits in a byte */ | |
42 | #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */ | |
43 | ||
9f95a23c TL |
44 | /* Maximum length for digest (SHA-256 needs 32 bytes) */ |
45 | #define DIGEST_LENGTH_MAX 32 | |
46 | ||
11fdf7f2 TL |
47 | /** ARMv8 operation order mode enumerator */ |
48 | enum armv8_crypto_chain_order { | |
49 | ARMV8_CRYPTO_CHAIN_CIPHER_AUTH, | |
50 | ARMV8_CRYPTO_CHAIN_AUTH_CIPHER, | |
51 | ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED, | |
52 | ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED | |
53 | }; | |
54 | ||
55 | /** ARMv8 cipher operation enumerator */ | |
56 | enum armv8_crypto_cipher_operation { | |
57 | ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT, | |
58 | ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT, | |
59 | ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED, | |
60 | ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED | |
61 | }; | |
62 | ||
63 | enum armv8_crypto_cipher_keylen { | |
64 | ARMV8_CRYPTO_CIPHER_KEYLEN_128, | |
65 | ARMV8_CRYPTO_CIPHER_KEYLEN_192, | |
66 | ARMV8_CRYPTO_CIPHER_KEYLEN_256, | |
67 | ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED, | |
68 | ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END = | |
69 | ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED | |
70 | }; | |
71 | ||
72 | /** ARMv8 auth mode enumerator */ | |
73 | enum armv8_crypto_auth_mode { | |
74 | ARMV8_CRYPTO_AUTH_AS_AUTH, | |
75 | ARMV8_CRYPTO_AUTH_AS_HMAC, | |
76 | ARMV8_CRYPTO_AUTH_AS_CIPHER, | |
77 | ARMV8_CRYPTO_AUTH_NOT_SUPPORTED, | |
78 | ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED | |
79 | }; | |
80 | ||
81 | #define CRYPTO_ORDER_MAX ARMV8_CRYPTO_CHAIN_LIST_END | |
82 | #define CRYPTO_CIPHER_OP_MAX ARMV8_CRYPTO_CIPHER_OP_LIST_END | |
83 | #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END | |
84 | #define CRYPTO_CIPHER_MAX RTE_CRYPTO_CIPHER_LIST_END | |
85 | #define CRYPTO_AUTH_MAX RTE_CRYPTO_AUTH_LIST_END | |
86 | ||
87 | #define HMAC_IPAD_VALUE (0x36) | |
88 | #define HMAC_OPAD_VALUE (0x5C) | |
89 | ||
90 | #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256)) | |
91 | #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512)) | |
92 | ||
93 | #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160)) | |
94 | #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512)) | |
95 | ||
96 | #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH | |
97 | #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE | |
98 | ||
99 | typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t, | |
100 | uint8_t *, uint8_t *, uint64_t, | |
101 | crypto_arg_t *); | |
102 | ||
103 | typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *); | |
104 | ||
105 | /** private data structure for each ARMv8 crypto device */ | |
106 | struct armv8_crypto_private { | |
107 | unsigned int max_nb_qpairs; | |
108 | /**< Max number of queue pairs */ | |
11fdf7f2 TL |
109 | }; |
110 | ||
111 | /** ARMv8 crypto queue pair */ | |
112 | struct armv8_crypto_qp { | |
113 | uint16_t id; | |
114 | /**< Queue Pair Identifier */ | |
115 | struct rte_ring *processed_ops; | |
116 | /**< Ring for placing process packets */ | |
117 | struct rte_mempool *sess_mp; | |
118 | /**< Session Mempool */ | |
9f95a23c TL |
119 | struct rte_mempool *sess_mp_priv; |
120 | /**< Session Private Data Mempool */ | |
11fdf7f2 TL |
121 | struct rte_cryptodev_stats stats; |
122 | /**< Queue pair statistics */ | |
9f95a23c | 123 | char name[RTE_CRYPTODEV_NAME_MAX_LEN]; |
11fdf7f2 | 124 | /**< Unique Queue Pair Name */ |
9f95a23c TL |
125 | uint8_t temp_digest[DIGEST_LENGTH_MAX]; |
126 | /**< Buffer used to store the digest generated | |
127 | * by the driver when verifying a digest provided | |
128 | * by the user (using authentication verify operation) | |
129 | */ | |
11fdf7f2 TL |
130 | } __rte_cache_aligned; |
131 | ||
132 | /** ARMv8 crypto private session structure */ | |
133 | struct armv8_crypto_session { | |
134 | enum armv8_crypto_chain_order chain_order; | |
135 | /**< chain order mode */ | |
136 | crypto_func_t crypto_func; | |
137 | /**< cryptographic function to use for this session */ | |
138 | ||
139 | /** Cipher Parameters */ | |
140 | struct { | |
141 | enum rte_crypto_cipher_operation direction; | |
142 | /**< cipher operation direction */ | |
143 | enum rte_crypto_cipher_algorithm algo; | |
144 | /**< cipher algorithm */ | |
9f95a23c TL |
145 | struct { |
146 | uint16_t length; | |
147 | uint16_t offset; | |
148 | } iv; | |
149 | /**< IV parameters */ | |
11fdf7f2 TL |
150 | |
151 | struct { | |
152 | uint8_t data[256]; | |
153 | /**< key data */ | |
154 | size_t length; | |
155 | /**< key length in bytes */ | |
156 | } key; | |
157 | ||
158 | crypto_key_sched_t key_sched; | |
159 | /**< Key schedule function */ | |
160 | } cipher; | |
161 | ||
162 | /** Authentication Parameters */ | |
163 | struct { | |
164 | enum rte_crypto_auth_operation operation; | |
165 | /**< auth operation generate or verify */ | |
166 | enum armv8_crypto_auth_mode mode; | |
167 | /**< auth operation mode */ | |
168 | ||
169 | union { | |
170 | struct { | |
171 | /* Add data if needed */ | |
172 | } auth; | |
173 | ||
174 | struct { | |
175 | uint8_t i_key_pad[SHA_BLOCK_MAX] | |
176 | __rte_cache_aligned; | |
177 | /**< inner pad (max supported block length) */ | |
178 | uint8_t o_key_pad[SHA_BLOCK_MAX] | |
179 | __rte_cache_aligned; | |
180 | /**< outer pad (max supported block length) */ | |
9f95a23c TL |
181 | uint8_t key[SHA_BLOCK_MAX]; |
182 | /**< HMAC key (max supported block length)*/ | |
11fdf7f2 TL |
183 | } hmac; |
184 | }; | |
9f95a23c TL |
185 | uint16_t digest_length; |
186 | /* Digest length */ | |
11fdf7f2 TL |
187 | } auth; |
188 | ||
189 | } __rte_cache_aligned; | |
190 | ||
191 | /** Set and validate ARMv8 crypto session parameters */ | |
192 | extern int armv8_crypto_set_session_parameters( | |
193 | struct armv8_crypto_session *sess, | |
194 | const struct rte_crypto_sym_xform *xform); | |
195 | ||
196 | /** device specific operations function pointer structure */ | |
197 | extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops; | |
198 | ||
199 | #endif /* _RTE_ARMV8_PMD_PRIVATE_H_ */ |