1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2018 Intel Corporation
5 #include <rte_mempool.h>
7 #include <rte_hexdump.h>
8 #include <rte_crypto_sym.h>
9 #include <rte_bus_pci.h>
10 #include <rte_byteorder.h>
12 #include <openssl/evp.h>
15 #include "qat_sym_session.h"
18 #include "adf_transport_access_macros.h"
19 #include "qat_device.h"
22 /* bpi is only used for partial blocks of DES and AES
23 * so AES block len can be assumed as max len for iv, src and dst
25 #define BPI_MAX_ENCR_IV_LEN ICP_QAT_HW_AES_BLK_SZ
27 /** Encrypt a single partial block
28 * Depends on openssl libcrypto
29 * Uses ECB+XOR to do CFB encryption, same result, more performant
32 bpi_cipher_encrypt(uint8_t *src, uint8_t *dst,
33 uint8_t *iv, int ivlen, int srclen,
36 EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *)bpi_ctx;
38 uint8_t encrypted_iv[BPI_MAX_ENCR_IV_LEN];
39 uint8_t *encr = encrypted_iv;
41 /* ECB method: encrypt the IV, then XOR this with plaintext */
42 if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen, iv, ivlen)
44 goto cipher_encrypt_err;
46 for (; srclen != 0; --srclen, ++dst, ++src, ++encr)
52 PMD_DRV_LOG(ERR, "libcrypto ECB cipher encrypt failed");
56 /** Decrypt a single partial block
57 * Depends on openssl libcrypto
58 * Uses ECB+XOR to do CFB encryption, same result, more performant
61 bpi_cipher_decrypt(uint8_t *src, uint8_t *dst,
62 uint8_t *iv, int ivlen, int srclen,
65 EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *)bpi_ctx;
67 uint8_t encrypted_iv[BPI_MAX_ENCR_IV_LEN];
68 uint8_t *encr = encrypted_iv;
70 /* ECB method: encrypt (not decrypt!) the IV, then XOR with plaintext */
71 if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen, iv, ivlen)
73 goto cipher_decrypt_err;
75 for (; srclen != 0; --srclen, ++dst, ++src, ++encr)
81 PMD_DRV_LOG(ERR, "libcrypto ECB cipher decrypt for BPI IV failed");
85 /** Creates a context in either AES or DES in ECB mode
86 * Depends on openssl libcrypto
89 static inline uint32_t
90 qat_bpicipher_preprocess(struct qat_sym_session *ctx,
91 struct rte_crypto_op *op)
93 int block_len = qat_cipher_get_block_size(ctx->qat_cipher_alg);
94 struct rte_crypto_sym_op *sym_op = op->sym;
95 uint8_t last_block_len = block_len > 0 ?
96 sym_op->cipher.data.length % block_len : 0;
99 ctx->qat_dir == ICP_QAT_HW_CIPHER_DECRYPT) {
101 /* Decrypt last block */
102 uint8_t *last_block, *dst, *iv;
103 uint32_t last_block_offset = sym_op->cipher.data.offset +
104 sym_op->cipher.data.length - last_block_len;
105 last_block = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_src,
106 uint8_t *, last_block_offset);
108 if (unlikely(sym_op->m_dst != NULL))
109 /* out-of-place operation (OOP) */
110 dst = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_dst,
111 uint8_t *, last_block_offset);
115 if (last_block_len < sym_op->cipher.data.length)
116 /* use previous block ciphertext as IV */
117 iv = last_block - block_len;
119 /* runt block, i.e. less than one full block */
120 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
121 ctx->cipher_iv.offset);
123 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
124 rte_hexdump(stdout, "BPI: src before pre-process:", last_block,
126 if (sym_op->m_dst != NULL)
127 rte_hexdump(stdout, "BPI: dst before pre-process:", dst,
130 bpi_cipher_decrypt(last_block, dst, iv, block_len,
131 last_block_len, ctx->bpi_ctx);
132 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
133 rte_hexdump(stdout, "BPI: src after pre-process:", last_block,
135 if (sym_op->m_dst != NULL)
136 rte_hexdump(stdout, "BPI: dst after pre-process:", dst,
141 return sym_op->cipher.data.length - last_block_len;
144 static inline uint32_t
145 qat_bpicipher_postprocess(struct qat_sym_session *ctx,
146 struct rte_crypto_op *op)
148 int block_len = qat_cipher_get_block_size(ctx->qat_cipher_alg);
149 struct rte_crypto_sym_op *sym_op = op->sym;
150 uint8_t last_block_len = block_len > 0 ?
151 sym_op->cipher.data.length % block_len : 0;
153 if (last_block_len > 0 &&
154 ctx->qat_dir == ICP_QAT_HW_CIPHER_ENCRYPT) {
156 /* Encrypt last block */
157 uint8_t *last_block, *dst, *iv;
158 uint32_t last_block_offset;
160 last_block_offset = sym_op->cipher.data.offset +
161 sym_op->cipher.data.length - last_block_len;
162 last_block = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_src,
163 uint8_t *, last_block_offset);
165 if (unlikely(sym_op->m_dst != NULL))
166 /* out-of-place operation (OOP) */
167 dst = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_dst,
168 uint8_t *, last_block_offset);
172 if (last_block_len < sym_op->cipher.data.length)
173 /* use previous block ciphertext as IV */
174 iv = dst - block_len;
176 /* runt block, i.e. less than one full block */
177 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
178 ctx->cipher_iv.offset);
180 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_RX
181 rte_hexdump(stdout, "BPI: src before post-process:", last_block,
183 if (sym_op->m_dst != NULL)
184 rte_hexdump(stdout, "BPI: dst before post-process:",
185 dst, last_block_len);
187 bpi_cipher_encrypt(last_block, dst, iv, block_len,
188 last_block_len, ctx->bpi_ctx);
189 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_RX
190 rte_hexdump(stdout, "BPI: src after post-process:", last_block,
192 if (sym_op->m_dst != NULL)
193 rte_hexdump(stdout, "BPI: dst after post-process:", dst,
197 return sym_op->cipher.data.length - last_block_len;
201 qat_sym_pmd_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
204 return qat_enqueue_op_burst(qp, (void **)ops, nb_ops);
208 qat_sym_process_response(void **op, uint8_t *resp,
209 __rte_unused void *op_cookie,
210 __rte_unused enum qat_device_gen qat_dev_gen)
213 struct icp_qat_fw_comn_resp *resp_msg =
214 (struct icp_qat_fw_comn_resp *)resp;
215 struct rte_crypto_op *rx_op = (struct rte_crypto_op *)(uintptr_t)
216 (resp_msg->opaque_data);
218 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_RX
219 rte_hexdump(stdout, "qat_response:", (uint8_t *)resp_msg,
220 sizeof(struct icp_qat_fw_comn_resp));
223 if (ICP_QAT_FW_COMN_STATUS_FLAG_OK !=
224 ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(
225 resp_msg->comn_hdr.comn_status)) {
227 rx_op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
229 struct qat_sym_session *sess = (struct qat_sym_session *)
230 get_session_private_data(
232 cryptodev_qat_driver_id);
235 qat_bpicipher_postprocess(sess, rx_op);
236 rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
245 qat_sym_pmd_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
248 return qat_dequeue_op_burst(qp, (void **)ops, nb_ops);
252 set_cipher_iv(uint16_t iv_length, uint16_t iv_offset,
253 struct icp_qat_fw_la_cipher_req_params *cipher_param,
254 struct rte_crypto_op *op,
255 struct icp_qat_fw_la_bulk_req *qat_req)
257 /* copy IV into request if it fits */
258 if (iv_length <= sizeof(cipher_param->u.cipher_IV_array)) {
259 rte_memcpy(cipher_param->u.cipher_IV_array,
260 rte_crypto_op_ctod_offset(op, uint8_t *,
264 ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
265 qat_req->comn_hdr.serv_specif_flags,
266 ICP_QAT_FW_CIPH_IV_64BIT_PTR);
267 cipher_param->u.s.cipher_IV_ptr =
268 rte_crypto_op_ctophys_offset(op,
273 /** Set IV for CCM is special case, 0th byte is set to q-1
274 * where q is padding of nonce in 16 byte block
277 set_cipher_iv_ccm(uint16_t iv_length, uint16_t iv_offset,
278 struct icp_qat_fw_la_cipher_req_params *cipher_param,
279 struct rte_crypto_op *op, uint8_t q, uint8_t aad_len_field_sz)
281 rte_memcpy(((uint8_t *)cipher_param->u.cipher_IV_array) +
282 ICP_QAT_HW_CCM_NONCE_OFFSET,
283 rte_crypto_op_ctod_offset(op, uint8_t *,
284 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
286 *(uint8_t *)&cipher_param->u.cipher_IV_array[0] =
287 q - ICP_QAT_HW_CCM_NONCE_OFFSET;
289 if (aad_len_field_sz)
290 rte_memcpy(&op->sym->aead.aad.data[ICP_QAT_HW_CCM_NONCE_OFFSET],
291 rte_crypto_op_ctod_offset(op, uint8_t *,
292 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
298 qat_sym_build_request(void *in_op, uint8_t *out_msg,
299 void *op_cookie, enum qat_device_gen qat_dev_gen)
302 struct qat_sym_session *ctx;
303 struct icp_qat_fw_la_cipher_req_params *cipher_param;
304 struct icp_qat_fw_la_auth_req_params *auth_param;
305 register struct icp_qat_fw_la_bulk_req *qat_req;
306 uint8_t do_auth = 0, do_cipher = 0, do_aead = 0;
307 uint32_t cipher_len = 0, cipher_ofs = 0;
308 uint32_t auth_len = 0, auth_ofs = 0;
309 uint32_t min_ofs = 0;
310 uint64_t src_buf_start = 0, dst_buf_start = 0;
312 struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
313 struct qat_sym_op_cookie *cookie =
314 (struct qat_sym_op_cookie *)op_cookie;
316 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
317 if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
318 PMD_DRV_LOG(ERR, "QAT PMD only supports symmetric crypto "
319 "operation requests, op (%p) is not a "
320 "symmetric operation.", op);
324 if (unlikely(op->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
325 PMD_DRV_LOG(ERR, "QAT PMD only supports session oriented"
326 " requests, op (%p) is sessionless.", op);
330 ctx = (struct qat_sym_session *)get_session_private_data(
331 op->sym->session, cryptodev_qat_driver_id);
333 if (unlikely(ctx == NULL)) {
334 PMD_DRV_LOG(ERR, "Session was not created for this device");
338 if (unlikely(ctx->min_qat_dev_gen > qat_dev_gen)) {
339 PMD_DRV_LOG(ERR, "Session alg not supported on this device gen");
340 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
344 qat_req = (struct icp_qat_fw_la_bulk_req *)out_msg;
345 rte_mov128((uint8_t *)qat_req, (const uint8_t *)&(ctx->fw_req));
346 qat_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
347 cipher_param = (void *)&qat_req->serv_specif_rqpars;
348 auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param));
350 if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_HASH_CIPHER ||
351 ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_HASH) {
352 /* AES-GCM or AES-CCM */
353 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
354 ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64 ||
355 (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128
356 && ctx->qat_mode == ICP_QAT_HW_CIPHER_CTR_MODE
357 && ctx->qat_hash_alg ==
358 ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC)) {
364 } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_AUTH) {
367 } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER) {
374 if (ctx->qat_cipher_alg ==
375 ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ||
376 ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_KASUMI ||
377 ctx->qat_cipher_alg ==
378 ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3) {
381 (cipher_param->cipher_length % BYTE_LENGTH != 0)
382 || (cipher_param->cipher_offset
383 % BYTE_LENGTH != 0))) {
385 "SNOW3G/KASUMI/ZUC in QAT PMD only supports byte aligned values");
386 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
389 cipher_len = op->sym->cipher.data.length >> 3;
390 cipher_ofs = op->sym->cipher.data.offset >> 3;
392 } else if (ctx->bpi_ctx) {
393 /* DOCSIS - only send complete blocks to device
394 * Process any partial block using CFB mode.
395 * Even if 0 complete blocks, still send this to device
396 * to get into rx queue for post-process and dequeuing
398 cipher_len = qat_bpicipher_preprocess(ctx, op);
399 cipher_ofs = op->sym->cipher.data.offset;
401 cipher_len = op->sym->cipher.data.length;
402 cipher_ofs = op->sym->cipher.data.offset;
405 set_cipher_iv(ctx->cipher_iv.length, ctx->cipher_iv.offset,
406 cipher_param, op, qat_req);
407 min_ofs = cipher_ofs;
412 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ||
413 ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 ||
415 ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3) {
416 if (unlikely((auth_param->auth_off % BYTE_LENGTH != 0)
417 || (auth_param->auth_len % BYTE_LENGTH != 0))) {
419 "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
420 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
423 auth_ofs = op->sym->auth.data.offset >> 3;
424 auth_len = op->sym->auth.data.length >> 3;
426 auth_param->u1.aad_adr =
427 rte_crypto_op_ctophys_offset(op,
428 ctx->auth_iv.offset);
430 } else if (ctx->qat_hash_alg ==
431 ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
433 ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
435 set_cipher_iv(ctx->auth_iv.length,
437 cipher_param, op, qat_req);
438 auth_ofs = op->sym->auth.data.offset;
439 auth_len = op->sym->auth.data.length;
441 auth_param->u1.aad_adr = 0;
442 auth_param->u2.aad_sz = 0;
445 * If len(iv)==12B fw computes J0
447 if (ctx->auth_iv.length == 12) {
448 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
449 qat_req->comn_hdr.serv_specif_flags,
450 ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
454 auth_ofs = op->sym->auth.data.offset;
455 auth_len = op->sym->auth.data.length;
460 if (likely(ctx->qat_hash_alg != ICP_QAT_HW_AUTH_ALGO_NULL))
461 auth_param->auth_res_addr =
462 op->sym->auth.digest.phys_addr;
468 * This address may used for setting AAD physical pointer
469 * into IV offset from op
471 rte_iova_t aad_phys_addr_aead = op->sym->aead.aad.phys_addr;
472 if (ctx->qat_hash_alg ==
473 ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
475 ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
477 * If len(iv)==12B fw computes J0
479 if (ctx->cipher_iv.length == 12) {
480 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
481 qat_req->comn_hdr.serv_specif_flags,
482 ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
484 set_cipher_iv(ctx->cipher_iv.length,
485 ctx->cipher_iv.offset,
486 cipher_param, op, qat_req);
488 } else if (ctx->qat_hash_alg ==
489 ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC) {
491 /* In case of AES-CCM this may point to user selected
492 * memory or iv offset in cypto_op
494 uint8_t *aad_data = op->sym->aead.aad.data;
495 /* This is true AAD length, it not includes 18 bytes of
498 uint8_t aad_ccm_real_len = 0;
499 uint8_t aad_len_field_sz = 0;
500 uint32_t msg_len_be =
501 rte_bswap32(op->sym->aead.data.length);
503 if (ctx->aad_len > ICP_QAT_HW_CCM_AAD_DATA_OFFSET) {
504 aad_len_field_sz = ICP_QAT_HW_CCM_AAD_LEN_INFO;
505 aad_ccm_real_len = ctx->aad_len -
506 ICP_QAT_HW_CCM_AAD_B0_LEN -
507 ICP_QAT_HW_CCM_AAD_LEN_INFO;
510 * aad_len not greater than 18, so no actual aad
511 * data, then use IV after op for B0 block
513 aad_data = rte_crypto_op_ctod_offset(op,
515 ctx->cipher_iv.offset);
517 rte_crypto_op_ctophys_offset(op,
518 ctx->cipher_iv.offset);
521 uint8_t q = ICP_QAT_HW_CCM_NQ_CONST -
522 ctx->cipher_iv.length;
524 aad_data[0] = ICP_QAT_HW_CCM_BUILD_B0_FLAGS(
526 ctx->digest_length, q);
528 if (q > ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE) {
529 memcpy(aad_data + ctx->cipher_iv.length +
530 ICP_QAT_HW_CCM_NONCE_OFFSET +
531 (q - ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE),
532 (uint8_t *)&msg_len_be,
533 ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE);
535 memcpy(aad_data + ctx->cipher_iv.length +
536 ICP_QAT_HW_CCM_NONCE_OFFSET,
537 (uint8_t *)&msg_len_be
538 + (ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE
542 if (aad_len_field_sz > 0) {
543 *(uint16_t *)&aad_data[ICP_QAT_HW_CCM_AAD_B0_LEN]
544 = rte_bswap16(aad_ccm_real_len);
546 if ((aad_ccm_real_len + aad_len_field_sz)
547 % ICP_QAT_HW_CCM_AAD_B0_LEN) {
551 pad_len = ICP_QAT_HW_CCM_AAD_B0_LEN -
552 ((aad_ccm_real_len + aad_len_field_sz) %
553 ICP_QAT_HW_CCM_AAD_B0_LEN);
554 pad_idx = ICP_QAT_HW_CCM_AAD_B0_LEN +
555 aad_ccm_real_len + aad_len_field_sz;
556 memset(&aad_data[pad_idx],
562 set_cipher_iv_ccm(ctx->cipher_iv.length,
563 ctx->cipher_iv.offset,
569 cipher_len = op->sym->aead.data.length;
570 cipher_ofs = op->sym->aead.data.offset;
571 auth_len = op->sym->aead.data.length;
572 auth_ofs = op->sym->aead.data.offset;
574 auth_param->u1.aad_adr = aad_phys_addr_aead;
575 auth_param->auth_res_addr = op->sym->aead.digest.phys_addr;
576 min_ofs = op->sym->aead.data.offset;
579 if (op->sym->m_src->next || (op->sym->m_dst && op->sym->m_dst->next))
582 /* adjust for chain case */
583 if (do_cipher && do_auth)
584 min_ofs = cipher_ofs < auth_ofs ? cipher_ofs : auth_ofs;
586 if (unlikely(min_ofs >= rte_pktmbuf_data_len(op->sym->m_src) && do_sgl))
589 if (unlikely(op->sym->m_dst != NULL)) {
590 /* Out-of-place operation (OOP)
591 * Don't align DMA start. DMA the minimum data-set
592 * so as not to overwrite data in dest buffer
595 rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs);
597 rte_pktmbuf_iova_offset(op->sym->m_dst, min_ofs);
600 /* In-place operation
601 * Start DMA at nearest aligned address below min_ofs
604 rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs)
605 & QAT_64_BTYE_ALIGN_MASK;
607 if (unlikely((rte_pktmbuf_iova(op->sym->m_src) -
608 rte_pktmbuf_headroom(op->sym->m_src))
610 /* alignment has pushed addr ahead of start of mbuf
611 * so revert and take the performance hit
614 rte_pktmbuf_iova_offset(op->sym->m_src,
617 dst_buf_start = src_buf_start;
620 if (do_cipher || do_aead) {
621 cipher_param->cipher_offset =
622 (uint32_t)rte_pktmbuf_iova_offset(
623 op->sym->m_src, cipher_ofs) - src_buf_start;
624 cipher_param->cipher_length = cipher_len;
626 cipher_param->cipher_offset = 0;
627 cipher_param->cipher_length = 0;
630 if (do_auth || do_aead) {
631 auth_param->auth_off = (uint32_t)rte_pktmbuf_iova_offset(
632 op->sym->m_src, auth_ofs) - src_buf_start;
633 auth_param->auth_len = auth_len;
635 auth_param->auth_off = 0;
636 auth_param->auth_len = 0;
639 qat_req->comn_mid.dst_length =
640 qat_req->comn_mid.src_length =
641 (cipher_param->cipher_offset + cipher_param->cipher_length)
642 > (auth_param->auth_off + auth_param->auth_len) ?
643 (cipher_param->cipher_offset + cipher_param->cipher_length)
644 : (auth_param->auth_off + auth_param->auth_len);
648 ICP_QAT_FW_COMN_PTR_TYPE_SET(qat_req->comn_hdr.comn_req_flags,
649 QAT_COMN_PTR_TYPE_SGL);
650 ret = qat_sgl_fill_array(op->sym->m_src, src_buf_start,
651 &cookie->qat_sgl_src,
652 qat_req->comn_mid.src_length);
654 PMD_DRV_LOG(ERR, "QAT PMD Cannot fill sgl array");
658 if (likely(op->sym->m_dst == NULL))
659 qat_req->comn_mid.dest_data_addr =
660 qat_req->comn_mid.src_data_addr =
661 cookie->qat_sgl_src_phys_addr;
663 ret = qat_sgl_fill_array(op->sym->m_dst,
665 &cookie->qat_sgl_dst,
666 qat_req->comn_mid.dst_length);
669 PMD_DRV_LOG(ERR, "QAT PMD Cannot "
674 qat_req->comn_mid.src_data_addr =
675 cookie->qat_sgl_src_phys_addr;
676 qat_req->comn_mid.dest_data_addr =
677 cookie->qat_sgl_dst_phys_addr;
680 qat_req->comn_mid.src_data_addr = src_buf_start;
681 qat_req->comn_mid.dest_data_addr = dst_buf_start;
684 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
685 rte_hexdump(stdout, "qat_req:", qat_req,
686 sizeof(struct icp_qat_fw_la_bulk_req));
687 rte_hexdump(stdout, "src_data:",
688 rte_pktmbuf_mtod(op->sym->m_src, uint8_t*),
689 rte_pktmbuf_data_len(op->sym->m_src));
691 uint8_t *cipher_iv_ptr = rte_crypto_op_ctod_offset(op,
693 ctx->cipher_iv.offset);
694 rte_hexdump(stdout, "cipher iv:", cipher_iv_ptr,
695 ctx->cipher_iv.length);
699 if (ctx->auth_iv.length) {
700 uint8_t *auth_iv_ptr = rte_crypto_op_ctod_offset(op,
702 ctx->auth_iv.offset);
703 rte_hexdump(stdout, "auth iv:", auth_iv_ptr,
704 ctx->auth_iv.length);
706 rte_hexdump(stdout, "digest:", op->sym->auth.digest.data,
711 rte_hexdump(stdout, "digest:", op->sym->aead.digest.data,
713 rte_hexdump(stdout, "aad:", op->sym->aead.aad.data,
721 void qat_sym_stats_get(struct rte_cryptodev *dev,
722 struct rte_cryptodev_stats *stats)
725 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
727 PMD_INIT_FUNC_TRACE();
729 PMD_DRV_LOG(ERR, "invalid stats ptr NULL");
732 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
734 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
738 stats->enqueued_count += qp[i]->stats.enqueued_count;
739 stats->dequeued_count += qp[i]->stats.dequeued_count;
740 stats->enqueue_err_count += qp[i]->stats.enqueue_err_count;
741 stats->dequeue_err_count += qp[i]->stats.dequeue_err_count;
745 void qat_sym_stats_reset(struct rte_cryptodev *dev)
748 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
750 PMD_INIT_FUNC_TRACE();
751 for (i = 0; i < dev->data->nb_queue_pairs; i++)
752 memset(&(qp[i]->stats), 0, sizeof(qp[i]->stats));
753 PMD_DRV_LOG(DEBUG, "QAT crypto: stats cleared");
756 int qat_sym_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
758 PMD_DRV_LOG(DEBUG, "Release sym qp %u on device %d",
759 queue_pair_id, dev->data->dev_id);
761 return qat_qp_release((struct qat_qp **)
762 &(dev->data->queue_pairs[queue_pair_id]));
765 int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
766 const struct rte_cryptodev_qp_conf *qp_conf,
767 int socket_id, struct rte_mempool *session_pool __rte_unused)
772 struct qat_qp_config qat_qp_conf;
774 struct qat_qp **qp_addr =
775 (struct qat_qp **)&(dev->data->queue_pairs[qp_id]);
776 struct qat_pmd_private *qat_private = dev->data->dev_private;
777 const struct qat_qp_hw_data *sym_hw_qps =
778 qp_gen_config[qat_private->qat_dev_gen]
779 .qp_hw_data[QAT_SERVICE_SYMMETRIC];
780 const struct qat_qp_hw_data *qp_hw_data = sym_hw_qps + qp_id;
782 /* If qp is already in use free ring memory and qp metadata. */
783 if (*qp_addr != NULL) {
784 ret = qat_sym_qp_release(dev, qp_id);
788 if (qp_id >= qat_qps_per_service(sym_hw_qps, QAT_SERVICE_SYMMETRIC)) {
789 PMD_DRV_LOG(ERR, "qp_id %u invalid for this device", qp_id);
793 qat_qp_conf.hw = qp_hw_data;
794 qat_qp_conf.build_request = qat_sym_build_request;
795 qat_qp_conf.process_response = qat_sym_process_response;
796 qat_qp_conf.cookie_size = sizeof(struct qat_sym_op_cookie);
797 qat_qp_conf.nb_descriptors = qp_conf->nb_descriptors;
798 qat_qp_conf.socket_id = socket_id;
799 qat_qp_conf.service_str = "sym";
801 ret = qat_qp_setup(qat_private, qp_addr, qp_id, &qat_qp_conf);
805 qp = (struct qat_qp *)*qp_addr;
807 for (i = 0; i < qp->nb_descriptors; i++) {
809 struct qat_sym_op_cookie *sql_cookie =
812 sql_cookie->qat_sgl_src_phys_addr =
813 rte_mempool_virt2iova(sql_cookie) +
814 offsetof(struct qat_sym_op_cookie,
817 sql_cookie->qat_sgl_dst_phys_addr =
818 rte_mempool_virt2iova(sql_cookie) +
819 offsetof(struct qat_sym_op_cookie,