Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2017 Intel Corporation
3 : : */
4 : : #ifndef TEST_CRYPTODEV_H_
5 : : #define TEST_CRYPTODEV_H_
6 : :
7 : : #include <rte_cryptodev.h>
8 : :
9 : : #define MAX_NUM_OPS_INFLIGHT (4096)
10 : : #define MIN_NUM_OPS_INFLIGHT (128)
11 : : #define DEFAULT_NUM_OPS_INFLIGHT (128)
12 : : #define TEST_STATS_RETRIES (100)
13 : :
14 : : #define DEFAULT_NUM_XFORMS (2)
15 : : #define NUM_MBUFS (8191)
16 : : #define MBUF_CACHE_SIZE (256)
17 : : #define MBUF_DATAPAYLOAD_SIZE (4096 + DIGEST_BYTE_LENGTH_SHA512)
18 : : #define MBUF_SIZE (sizeof(struct rte_mbuf) + \
19 : : RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
20 : : #define LARGE_MBUF_DATAPAYLOAD_SIZE (UINT16_MAX - RTE_PKTMBUF_HEADROOM)
21 : : #define LARGE_MBUF_SIZE (RTE_PKTMBUF_HEADROOM + LARGE_MBUF_DATAPAYLOAD_SIZE)
22 : :
23 : : #define BYTE_LENGTH(x) (x/8)
24 : : /* HASH DIGEST LENGTHS */
25 : : #define DIGEST_BYTE_LENGTH_MD5 (BYTE_LENGTH(128))
26 : : #define DIGEST_BYTE_LENGTH_SHA1 (BYTE_LENGTH(160))
27 : : #define DIGEST_BYTE_LENGTH_SHA224 (BYTE_LENGTH(224))
28 : : #define DIGEST_BYTE_LENGTH_SHA256 (BYTE_LENGTH(256))
29 : : #define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))
30 : : #define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))
31 : : #define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96))
32 : : #define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))
33 : : #define DIGEST_BYTE_LENGTH_KASUMI_F9 (BYTE_LENGTH(32))
34 : : #define AES_XCBC_MAC_KEY_SZ (16)
35 : : #define DIGEST_BYTE_LENGTH_AES_GCM (BYTE_LENGTH(128))
36 : :
37 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
38 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA224 (16)
39 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 (16)
40 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA384 (24)
41 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 (32)
42 : :
43 : : #define MAXIMUM_IV_LENGTH (16)
44 : : #define AES_GCM_J0_LENGTH (16)
45 : :
46 : : #define IV_OFFSET (sizeof(struct rte_crypto_op) + \
47 : : sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \
48 : : sizeof(struct rte_crypto_sym_xform))
49 : :
50 : : #define CRYPTODEV_NAME_NULL_PMD crypto_null
51 : : #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
52 : : #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
53 : : #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
54 : : #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
55 : : #define CRYPTODEV_NAME_QAT_ASYM_PMD crypto_qat_asym
56 : : #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
57 : : #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
58 : : #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
59 : : #define CRYPTODEV_NAME_CHACHA20_POLY1305_PMD crypto_chacha20_poly1305
60 : : #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
61 : : #define CRYPTODEV_NAME_DPAA_SEC_PMD crypto_dpaa_sec
62 : : #define CRYPTODEV_NAME_DPAA2_SEC_PMD crypto_dpaa2_sec
63 : : #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
64 : : #define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam
65 : : #define CRYPTODEV_NAME_CCP_PMD crypto_ccp
66 : : #define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio
67 : : #define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx
68 : : #define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr
69 : : #define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
70 : : #define CRYPTODEV_NAME_BCMFS_PMD crypto_bcmfs
71 : : #define CRYPTODEV_NAME_CN9K_PMD crypto_cn9k
72 : : #define CRYPTODEV_NAME_CN10K_PMD crypto_cn10k
73 : : #define CRYPTODEV_NAME_MLX5_PMD crypto_mlx5
74 : : #define CRYPTODEV_NAME_UADK_PMD crypto_uadk
75 : :
76 : :
77 : : enum cryptodev_api_test_type {
78 : : CRYPTODEV_API_TEST = 0,
79 : : CRYPTODEV_RAW_API_TEST
80 : : };
81 : :
82 : : extern enum cryptodev_api_test_type global_api_test_type;
83 : :
84 : : extern struct crypto_testsuite_params *p_testsuite_params;
85 : : struct crypto_testsuite_params {
86 : : struct rte_mempool *mbuf_pool;
87 : : struct rte_mempool *large_mbuf_pool;
88 : : struct rte_mempool *op_mpool;
89 : : struct rte_mempool *session_mpool;
90 : : struct rte_mempool *session_priv_mpool;
91 : : struct rte_cryptodev_config conf;
92 : : struct rte_cryptodev_qp_conf qp_conf;
93 : :
94 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
95 : : uint8_t valid_dev_count;
96 : : };
97 : :
98 : : /**
99 : : * Write (spread) data from buffer to mbuf data
100 : : *
101 : : * @param mbuf
102 : : * Destination mbuf
103 : : * @param offset
104 : : * Start offset in mbuf
105 : : * @param len
106 : : * Number of bytes to copy
107 : : * @param buffer
108 : : * Continuous source buffer
109 : : */
110 : : static inline void
111 : 150 : pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer)
112 : : {
113 : : int n = len;
114 : : int l;
115 : : struct rte_mbuf *m;
116 : : char *dst;
117 : :
118 [ + - - + ]: 150 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
119 : 0 : offset -= m->data_len;
120 : :
121 : 150 : l = m->data_len - offset;
122 : :
123 : : /* copy data from first segment */
124 : 150 : dst = rte_pktmbuf_mtod_offset(m, char *, offset);
125 [ + + ]: 150 : if (len <= l) {
126 [ + + ]: 132 : rte_memcpy(dst, buffer, len);
127 : 132 : return;
128 : : }
129 : :
130 [ + + ]: 18 : rte_memcpy(dst, buffer, l);
131 : 18 : buffer += l;
132 : 18 : n -= l;
133 : :
134 [ + + ]: 93 : for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
135 : 76 : dst = rte_pktmbuf_mtod(m, char *);
136 : 76 : l = m->data_len;
137 [ + + ]: 76 : if (n < l) {
138 [ - + ]: 1 : rte_memcpy(dst, buffer, n);
139 : 1 : return;
140 : : }
141 [ + + ]: 75 : rte_memcpy(dst, buffer, l);
142 : 75 : buffer += l;
143 : 75 : n -= l;
144 : : }
145 : : }
146 : :
147 : : static inline uint8_t *
148 : 140 : pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset)
149 : : {
150 : : struct rte_mbuf *m;
151 : :
152 [ + - + + ]: 171 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
153 : 31 : offset -= m->data_len;
154 : :
155 [ - + ]: 140 : if (m == NULL) {
156 : : printf("pktmbuf_mtod_offset: offset out of buffer\n");
157 : 0 : return NULL;
158 : : }
159 : 140 : return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
160 : : }
161 : :
162 : : static inline rte_iova_t
163 : 93 : pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset)
164 : : {
165 : : struct rte_mbuf *m;
166 : :
167 [ + - + + ]: 115 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
168 : 22 : offset -= m->data_len;
169 : :
170 [ - + ]: 93 : if (m == NULL) {
171 : : printf("pktmbuf_iova_offset: offset out of buffer\n");
172 : 0 : return 0;
173 : : }
174 : 93 : return rte_pktmbuf_iova_offset(m, offset);
175 : : }
176 : :
177 : : static inline struct rte_mbuf *
178 : 150 : create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
179 : : int nb_segs, uint8_t pattern)
180 : : {
181 : : struct rte_mbuf *m = NULL, *mbuf = NULL;
182 : : int size, t_len, data_len = 0;
183 : : uint8_t *dst;
184 : :
185 [ - + ]: 150 : if (nb_segs < 1) {
186 : : printf("Number of segments must be 1 or more (is %d)\n",
187 : : nb_segs);
188 : 0 : return NULL;
189 : : }
190 : :
191 [ + - ]: 150 : t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
192 : : size = pkt_len;
193 : :
194 : : /* Create chained mbuf_src and fill it generated data */
195 : : do {
196 : :
197 : 226 : m = rte_pktmbuf_alloc(mbuf_pool);
198 [ - + ]: 226 : if (m == NULL) {
199 : : printf("Cannot create segment for source mbuf");
200 : 0 : goto fail;
201 : : }
202 : :
203 [ + + ]: 226 : if (mbuf == NULL)
204 : : mbuf = m;
205 : :
206 : : /* Make sure if tailroom is zeroed */
207 : 226 : memset(m->buf_addr, pattern, m->buf_len);
208 : :
209 : 226 : data_len = size > t_len ? t_len : size;
210 : 226 : dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
211 [ - + ]: 226 : if (dst == NULL) {
212 : : printf("Cannot append %d bytes to the mbuf\n",
213 : : data_len);
214 : 0 : goto fail;
215 : : }
216 : :
217 [ + + ]: 226 : if (mbuf != m)
218 : : rte_pktmbuf_chain(mbuf, m);
219 : :
220 : 226 : size -= data_len;
221 : :
222 [ + + ]: 226 : } while (size > 0);
223 : :
224 : : return mbuf;
225 : :
226 : 0 : fail:
227 : 0 : rte_pktmbuf_free(mbuf);
228 : 0 : return NULL;
229 : : }
230 : :
231 : : static inline struct rte_mbuf *
232 : 0 : create_segmented_mbuf_multi_pool(struct rte_mempool *mbuf_pool_small,
233 : : struct rte_mempool *mbuf_pool_large, int pkt_len, int nb_segs, uint8_t pattern)
234 : : {
235 : : struct rte_mempool *mbuf_pool;
236 : : int max_seg_len, seg_len;
237 : :
238 [ # # ]: 0 : if (nb_segs < 1) {
239 : : printf("Number of segments must be 1 or more (is %d)\n", nb_segs);
240 : 0 : return NULL;
241 : : }
242 : :
243 [ # # ]: 0 : if (pkt_len >= nb_segs)
244 : 0 : seg_len = pkt_len / nb_segs;
245 : : else
246 : : seg_len = 1;
247 : :
248 : : /* Determine max segment length */
249 : 0 : max_seg_len = seg_len + pkt_len % nb_segs;
250 : :
251 [ # # ]: 0 : if (max_seg_len > LARGE_MBUF_DATAPAYLOAD_SIZE) {
252 : : printf("Segment size %d is too big\n", max_seg_len);
253 : 0 : return NULL;
254 : : }
255 : :
256 [ # # ]: 0 : if (max_seg_len > MBUF_DATAPAYLOAD_SIZE)
257 : : mbuf_pool = mbuf_pool_large;
258 : : else
259 : : mbuf_pool = mbuf_pool_small;
260 : :
261 [ # # ]: 0 : if (mbuf_pool == NULL) {
262 : : printf("Invalid mbuf pool\n");
263 : 0 : return NULL;
264 : : }
265 : :
266 : 0 : return create_segmented_mbuf(mbuf_pool, pkt_len, nb_segs, pattern);
267 : : }
268 : :
269 : : int
270 : : process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
271 : : struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
272 : : uint8_t len_in_bits, uint8_t cipher_iv_len);
273 : :
274 : : int
275 : : check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
276 : : uint16_t num_ciphers);
277 : :
278 : : int
279 : : check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
280 : : uint16_t num_auths);
281 : :
282 : : int
283 : : check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
284 : : uint16_t num_aeads);
285 : :
286 : : int
287 : : ut_setup(void);
288 : :
289 : : void
290 : : ut_teardown(void);
291 : :
292 : : #endif /* TEST_CRYPTODEV_H_ */
|