1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2026 Intel Corporation */
3
4 /**
5 ***************************************************************************
6 * @file lac_sym_dp.c
7 * Implementation of the symmetric data plane API
8 *
9 * @ingroup cpaCySymDp
10 ***************************************************************************/
11
12 /*
13 *******************************************************************************
14 * Include public/global header files
15 *******************************************************************************
16 */
17
18 #include "cpa.h"
19 #include "cpa_cy_sym.h"
20 #include "cpa_cy_sym_dp.h"
21
22 /*
23 *******************************************************************************
24 * Include private header files
25 *******************************************************************************
26 */
27
28 #include "icp_accel_devices.h"
29 #include "icp_adf_init.h"
30 #include "icp_adf_transport.h"
31 #include "icp_adf_transport_dp.h"
32 #include "icp_adf_debug.h"
33 #include "icp_sal_poll.h"
34
35 #include "qat_utils.h"
36
37 #include "lac_list.h"
38 #include "lac_log.h"
39 #include "lac_mem.h"
40 #include "lac_sal_types_crypto.h"
41 #include "lac_sym.h"
42 #include "lac_sym_cipher.h"
43 #include "lac_sym_auth_enc.h"
44 #include "lac_sym_qat_cipher.h"
45 #include "sal_service_state.h"
46 #include "sal_hw_gen.h"
47
48 typedef void (*write_ringMsgFunc_t)(CpaCySymDpOpData *pRequest,
49 icp_qat_fw_la_bulk_req_t *pCurrentQatMsg);
50
51 /**
52 *****************************************************************************
53 * @ingroup cpaCySymDp
54 * Check that the operation data is valid
55 *
56 * @description
57 * Check that all the parameters defined in the operation data are valid
58 *
59 * @param[in] pRequest Pointer to an operation data for crypto
60 * data plane API
61 *
62 * @retval CPA_STATUS_SUCCESS Function executed successfully
63 * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in
64 *
65 *****************************************************************************/
66 static CpaStatus
LacDp_EnqueueParamCheck(const CpaCySymDpOpData * pRequest)67 LacDp_EnqueueParamCheck(const CpaCySymDpOpData *pRequest)
68 {
69 lac_session_desc_t *pSessionDesc = NULL;
70 CpaCySymCipherAlgorithm cipher = 0;
71 CpaCySymHashAlgorithm hash = 0;
72 Cpa32U capabilitiesMask = 0;
73
74 LAC_CHECK_NULL_PARAM(pRequest);
75 LAC_CHECK_NULL_PARAM(pRequest->instanceHandle);
76 LAC_CHECK_NULL_PARAM(pRequest->sessionCtx);
77
78 /* Ensure this is a crypto instance */
79 SAL_CHECK_INSTANCE_TYPE(pRequest->instanceHandle,
80 (SAL_SERVICE_TYPE_CRYPTO |
81 SAL_SERVICE_TYPE_CRYPTO_SYM));
82
83 pSessionDesc = LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequest->sessionCtx);
84 if (NULL == pSessionDesc) {
85 do {
86 qatUtilsSleep(500);
87 pSessionDesc = LAC_SYM_SESSION_DESC_FROM_CTX_GET(
88 pRequest->sessionCtx);
89 } while (NULL == pSessionDesc);
90 }
91 if (NULL == pSessionDesc) {
92 LAC_INVALID_PARAM_LOG("Session context not as expected");
93 return CPA_STATUS_INVALID_PARAM;
94 }
95
96 if (CPA_FALSE == pSessionDesc->isDPSession) {
97 LAC_INVALID_PARAM_LOG(
98 "Session not initialised for data plane API");
99 return CPA_STATUS_INVALID_PARAM;
100 }
101
102 /*check whether Payload size is zero for CHACHA-POLY */
103 if ((CPA_CY_SYM_CIPHER_CHACHA == pSessionDesc->cipherAlgorithm) &&
104 (CPA_CY_SYM_HASH_POLY == pSessionDesc->hashAlgorithm) &&
105 (CPA_CY_SYM_OP_ALGORITHM_CHAINING == pSessionDesc->symOperation)) {
106 if (!pRequest->messageLenToCipherInBytes) {
107 LAC_INVALID_PARAM_LOG(
108 "Invalid messageLenToCipherInBytes for CHACHA-POLY");
109 return CPA_STATUS_INVALID_PARAM;
110 }
111 }
112
113 if (0 == pRequest->srcBuffer) {
114 LAC_INVALID_PARAM_LOG("Invalid srcBuffer");
115 return CPA_STATUS_INVALID_PARAM;
116 }
117 if (0 == pRequest->dstBuffer) {
118 LAC_INVALID_PARAM_LOG("Invalid destBuffer");
119 return CPA_STATUS_INVALID_PARAM;
120 }
121 if (0 == pRequest->thisPhys) {
122 LAC_INVALID_PARAM_LOG("Invalid thisPhys");
123 return CPA_STATUS_INVALID_PARAM;
124 }
125
126 /* Check that src buffer Len = dst buffer Len
127 Note this also checks that they are of the same type */
128 if (pRequest->srcBufferLen != pRequest->dstBufferLen) {
129 LAC_INVALID_PARAM_LOG(
130 "Source and Destination buffer lengths need to be equal");
131 return CPA_STATUS_INVALID_PARAM;
132 }
133
134 /* digestVerify and digestIsAppended on Hash-Only operation not
135 * supported */
136 if (pSessionDesc->digestIsAppended && pSessionDesc->digestVerify &&
137 (pSessionDesc->symOperation == CPA_CY_SYM_OP_HASH)) {
138 LAC_INVALID_PARAM_LOG(
139 "digestVerify and digestIsAppended set "
140 "on Hash-Only operation is not supported");
141 return CPA_STATUS_INVALID_PARAM;
142 }
143
144 /* Cipher specific tests */
145 if (CPA_CY_SYM_OP_HASH != pSessionDesc->symOperation) {
146 /* Perform IV check */
147 switch (pSessionDesc->cipherAlgorithm) {
148 case CPA_CY_SYM_CIPHER_AES_CTR:
149 case CPA_CY_SYM_CIPHER_3DES_CTR:
150 case CPA_CY_SYM_CIPHER_SM4_CTR:
151 case CPA_CY_SYM_CIPHER_AES_GCM:
152 case CPA_CY_SYM_CIPHER_CHACHA:
153 case CPA_CY_SYM_CIPHER_AES_CBC:
154 case CPA_CY_SYM_CIPHER_DES_CBC:
155 case CPA_CY_SYM_CIPHER_3DES_CBC:
156 case CPA_CY_SYM_CIPHER_SM4_CBC:
157 case CPA_CY_SYM_CIPHER_AES_F8: {
158 Cpa32U ivLenInBytes = LacSymQat_CipherIvSizeBytesGet(
159 pSessionDesc->cipherAlgorithm);
160 if (pRequest->ivLenInBytes != ivLenInBytes) {
161 if (!(/* GCM with 12 byte IV is OK */
162 (LAC_CIPHER_IS_GCM(
163 pSessionDesc->cipherAlgorithm) &&
164 pRequest->ivLenInBytes ==
165 LAC_CIPHER_IV_SIZE_GCM_12))) {
166 LAC_INVALID_PARAM_LOG(
167 "invalid cipher IV size");
168 return CPA_STATUS_INVALID_PARAM;
169 }
170 }
171 if (0 == pRequest->iv) {
172 LAC_INVALID_PARAM_LOG("invalid iv of 0");
173 return CPA_STATUS_INVALID_PARAM;
174 }
175 /* pRequest->pIv is only used for CCM so is not checked
176 * here */
177 } break;
178 case CPA_CY_SYM_CIPHER_KASUMI_F8: {
179 if (LAC_CIPHER_KASUMI_F8_IV_LENGTH !=
180 pRequest->ivLenInBytes) {
181 LAC_INVALID_PARAM_LOG("invalid cipher IV size");
182 return CPA_STATUS_INVALID_PARAM;
183 }
184 if (0 == pRequest->iv) {
185 LAC_INVALID_PARAM_LOG("invalid iv of 0");
186 return CPA_STATUS_INVALID_PARAM;
187 }
188 } break;
189 case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: {
190 if (ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ !=
191 pRequest->ivLenInBytes) {
192 LAC_INVALID_PARAM_LOG("invalid cipher IV size");
193 return CPA_STATUS_INVALID_PARAM;
194 }
195 if (0 == pRequest->iv) {
196 LAC_INVALID_PARAM_LOG("invalid iv of 0");
197 return CPA_STATUS_INVALID_PARAM;
198 }
199 } break;
200 case CPA_CY_SYM_CIPHER_ZUC_EEA3: {
201 if (ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ !=
202 pRequest->ivLenInBytes) {
203 LAC_INVALID_PARAM_LOG("invalid cipher IV size");
204 return CPA_STATUS_INVALID_PARAM;
205 }
206 if (0 == pRequest->iv) {
207 LAC_INVALID_PARAM_LOG("invalid iv of 0");
208 return CPA_STATUS_INVALID_PARAM;
209 }
210 } break;
211 case CPA_CY_SYM_CIPHER_AES_CCM: {
212 if (CPA_STATUS_SUCCESS !=
213 LacSymAlgChain_CheckCCMData(
214 pRequest->pAdditionalAuthData,
215 pRequest->pIv,
216 pRequest->messageLenToCipherInBytes,
217 pRequest->ivLenInBytes)) {
218 return CPA_STATUS_INVALID_PARAM;
219 }
220 } break;
221 default:
222 break;
223 }
224 /* Perform algorithm-specific checks */
225 switch (pSessionDesc->cipherAlgorithm) {
226 case CPA_CY_SYM_CIPHER_ARC4:
227 case CPA_CY_SYM_CIPHER_AES_CTR:
228 case CPA_CY_SYM_CIPHER_3DES_CTR:
229 case CPA_CY_SYM_CIPHER_SM4_CTR:
230 case CPA_CY_SYM_CIPHER_AES_CCM:
231 case CPA_CY_SYM_CIPHER_AES_GCM:
232 case CPA_CY_SYM_CIPHER_CHACHA:
233 case CPA_CY_SYM_CIPHER_KASUMI_F8:
234 case CPA_CY_SYM_CIPHER_AES_F8:
235 case CPA_CY_SYM_CIPHER_SNOW3G_UEA2:
236 case CPA_CY_SYM_CIPHER_ZUC_EEA3:
237 /* No action needed */
238 break;
239 default: {
240 /* Mask & check below is based on assumption that block
241 * size is a power of 2. If data size is not a multiple
242 * of the block size, the "remainder" bits selected by
243 * the mask be non-zero
244 */
245 if (pRequest->messageLenToCipherInBytes &
246 (LacSymQat_CipherBlockSizeBytesGet(
247 pSessionDesc->cipherAlgorithm) -
248 1)) {
249 LAC_INVALID_PARAM_LOG(
250 "Data size must be block size"
251 " multiple");
252 return CPA_STATUS_INVALID_PARAM;
253 }
254 }
255 }
256
257 cipher = pSessionDesc->cipherAlgorithm;
258 hash = pSessionDesc->hashAlgorithm;
259 capabilitiesMask =
260 ((sal_crypto_service_t *)pRequest->instanceHandle)
261 ->generic_service_info.capabilitiesMask;
262 if (LAC_CIPHER_IS_SPC(cipher, hash, capabilitiesMask) &&
263 (LAC_CIPHER_SPC_IV_SIZE == pRequest->ivLenInBytes)) {
264 /* For CHACHA and AES-GCM there is an AAD buffer if
265 * aadLenInBytes is nonzero. For CCM there is always an
266 * AAD buffer, even if aadLenInBytes is zero, as the
267 * first 16 bytes are needed for B0. In case of
268 * AES-GMAC, no AAD buffer is needed as the AAD is
269 * passed in the src buffer.
270 */
271 if ((0 < pSessionDesc->aadLenInBytes) &&
272 (CPA_CY_SYM_HASH_AES_GMAC !=
273 pSessionDesc->hashAlgorithm)) {
274 LAC_CHECK_NULL_PARAM(
275 pRequest->pAdditionalAuthData);
276 }
277
278 /* Ensure AAD length for AES_GMAC spc */
279 if ((CPA_CY_SYM_HASH_AES_GMAC == hash) &&
280 (ICP_QAT_FW_SPC_AAD_SZ_MAX <
281 pRequest->messageLenToHashInBytes)) {
282 LAC_INVALID_PARAM_LOG(
283 "aadLenInBytes for AES_GMAC");
284 return CPA_STATUS_INVALID_PARAM;
285 }
286 }
287 }
288
289 /* Hash specific tests */
290 if (CPA_CY_SYM_OP_CIPHER != pSessionDesc->symOperation) {
291 /* For CCM, snow3G and ZUC there is always an AAD buffer
292 For GCM there is an AAD buffer if aadLenInBytes is
293 nonzero */
294 if ((CPA_CY_SYM_HASH_AES_CCM == pSessionDesc->hashAlgorithm) ||
295 (CPA_CY_SYM_HASH_AES_GCM == pSessionDesc->hashAlgorithm &&
296 (0 != pSessionDesc->aadLenInBytes))) {
297 LAC_CHECK_NULL_PARAM(pRequest->pAdditionalAuthData);
298 if (0 == pRequest->additionalAuthData) {
299 LAC_INVALID_PARAM_LOG(
300 "Invalid additionalAuthData");
301 return CPA_STATUS_INVALID_PARAM;
302 }
303 } else if (CPA_CY_SYM_HASH_SNOW3G_UIA2 ==
304 pSessionDesc->hashAlgorithm ||
305 CPA_CY_SYM_HASH_ZUC_EIA3 ==
306 pSessionDesc->hashAlgorithm) {
307 if (0 == pRequest->additionalAuthData) {
308 LAC_INVALID_PARAM_LOG(
309 "Invalid additionalAuthData");
310 return CPA_STATUS_INVALID_PARAM;
311 }
312 }
313
314 if ((CPA_CY_SYM_HASH_AES_CCM != pSessionDesc->hashAlgorithm) &&
315 (!pSessionDesc->digestIsAppended) &&
316 (0 == pRequest->digestResult)) {
317 LAC_INVALID_PARAM_LOG("Invalid digestResult");
318 return CPA_STATUS_INVALID_PARAM;
319 }
320
321 if (CPA_CY_SYM_HASH_AES_CCM == pSessionDesc->hashAlgorithm) {
322 if ((pRequest->cryptoStartSrcOffsetInBytes +
323 pRequest->messageLenToCipherInBytes +
324 pSessionDesc->hashResultSize) >
325 pRequest->dstBufferLen) {
326 LAC_INVALID_PARAM_LOG(
327 "CCM - Not enough room for"
328 " digest in destination buffer");
329 return CPA_STATUS_INVALID_PARAM;
330 }
331 } else if (CPA_TRUE == pSessionDesc->digestIsAppended) {
332 if (CPA_CY_SYM_HASH_AES_GMAC ==
333 pSessionDesc->hashAlgorithm) {
334 if ((pRequest->hashStartSrcOffsetInBytes +
335 pRequest->messageLenToHashInBytes +
336 pSessionDesc->hashResultSize) >
337 pRequest->dstBufferLen) {
338 LAC_INVALID_PARAM_LOG(
339 "Append Digest - Not enough room for"
340 " digest in destination buffer for "
341 "AES GMAC algorithm");
342 return CPA_STATUS_INVALID_PARAM;
343 }
344 }
345 if (CPA_CY_SYM_HASH_AES_GCM ==
346 pSessionDesc->hashAlgorithm) {
347 if ((pRequest->cryptoStartSrcOffsetInBytes +
348 pRequest->messageLenToCipherInBytes +
349 pSessionDesc->hashResultSize) >
350 pRequest->dstBufferLen) {
351 LAC_INVALID_PARAM_LOG(
352 "Append Digest - Not enough room "
353 "for digest in destination buffer"
354 " for GCM algorithm");
355 return CPA_STATUS_INVALID_PARAM;
356 }
357 }
358
359 if ((pRequest->hashStartSrcOffsetInBytes +
360 pRequest->messageLenToHashInBytes +
361 pSessionDesc->hashResultSize) >
362 pRequest->dstBufferLen) {
363 LAC_INVALID_PARAM_LOG(
364 "Append Digest - Not enough room for"
365 " digest in destination buffer");
366 return CPA_STATUS_INVALID_PARAM;
367 }
368 }
369 if (CPA_CY_SYM_HASH_AES_GMAC == pSessionDesc->hashAlgorithm) {
370 if (pRequest->messageLenToHashInBytes == 0 ||
371 pRequest->pAdditionalAuthData != NULL) {
372 LAC_INVALID_PARAM_LOG(
373 "For AES_GMAC, AAD Length "
374 "(messageLenToHashInBytes) must be "
375 "non zero and pAdditionalAuthData "
376 "must be NULL");
377 return CPA_STATUS_INVALID_PARAM;
378 }
379 }
380 }
381
382 if (CPA_DP_BUFLIST != pRequest->srcBufferLen) {
383 if ((CPA_CY_SYM_OP_HASH != pSessionDesc->symOperation) &&
384 ((pRequest->messageLenToCipherInBytes +
385 pRequest->cryptoStartSrcOffsetInBytes) >
386 pRequest->srcBufferLen)) {
387 LAC_INVALID_PARAM_LOG(
388 "cipher len + offset greater than "
389 "srcBufferLen");
390 return CPA_STATUS_INVALID_PARAM;
391 } else if ((CPA_CY_SYM_OP_CIPHER !=
392 pSessionDesc->symOperation) &&
393 (CPA_CY_SYM_HASH_AES_CCM !=
394 pSessionDesc->hashAlgorithm) &&
395 (CPA_CY_SYM_HASH_AES_GCM !=
396 pSessionDesc->hashAlgorithm) &&
397 (CPA_CY_SYM_HASH_AES_GMAC !=
398 pSessionDesc->hashAlgorithm) &&
399 ((pRequest->messageLenToHashInBytes +
400 pRequest->hashStartSrcOffsetInBytes) >
401 pRequest->srcBufferLen)) {
402 LAC_INVALID_PARAM_LOG(
403 "hash len + offset greater than srcBufferLen");
404 return CPA_STATUS_INVALID_PARAM;
405 }
406 } else {
407 LAC_CHECK_8_BYTE_ALIGNMENT(pRequest->srcBuffer);
408 LAC_CHECK_8_BYTE_ALIGNMENT(pRequest->dstBuffer);
409 }
410
411 LAC_CHECK_8_BYTE_ALIGNMENT(pRequest->thisPhys);
412
413 return CPA_STATUS_SUCCESS;
414 }
415
416 /**
417 *****************************************************************************
418 * @ingroup cpaCySymDp
419 * Write Message on the ring and write request params
420 * This is the optimized version, which should not be used for
421 * algorithm of CCM, GCM, CHACHA and RC4
422 *
423 * @description
424 * Write Message on the ring and write request params
425 *
426 * @param[in/out] pRequest Pointer to operation data for crypto
427 * data plane API
428 * @param[in/out] pCurrentQatMsg Pointer to ring memory where msg will
429 * be written
430 *
431 * @retval none
432 *
433 *****************************************************************************/
434
435 void
LacDp_WriteRingMsgOpt(CpaCySymDpOpData * pRequest,icp_qat_fw_la_bulk_req_t * pCurrentQatMsg)436 LacDp_WriteRingMsgOpt(CpaCySymDpOpData *pRequest,
437 icp_qat_fw_la_bulk_req_t *pCurrentQatMsg)
438 {
439 lac_session_desc_t *pSessionDesc =
440 LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequest->sessionCtx);
441 Cpa8U *pMsgDummy = NULL;
442 Cpa8U *pCacheDummyHdr = NULL;
443 Cpa8U *pCacheDummyFtr = NULL;
444
445 pMsgDummy = (Cpa8U *)pCurrentQatMsg;
446 /* Write Request */
447 /*
448 * Fill in the header and footer bytes of the ET ring message - cached
449 * from the session descriptor.
450 */
451 if (!pSessionDesc->useSymConstantsTable) {
452 pCacheDummyHdr = (Cpa8U *)&(pSessionDesc->reqCacheHdr);
453 pCacheDummyFtr = (Cpa8U *)&(pSessionDesc->reqCacheFtr);
454 } else {
455 pCacheDummyHdr = (Cpa8U *)&(pSessionDesc->shramReqCacheHdr);
456 pCacheDummyFtr = (Cpa8U *)&(pSessionDesc->shramReqCacheFtr);
457 }
458 memcpy(pMsgDummy,
459 pCacheDummyHdr,
460 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_HDR_IN_LW));
461 memset((pMsgDummy +
462 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_HDR_IN_LW)),
463 0,
464 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_TO_CLEAR_IN_LW));
465 memcpy(pMsgDummy +
466 (LAC_LONG_WORD_IN_BYTES * LAC_START_OF_CACHE_FTR_IN_LW),
467 pCacheDummyFtr,
468 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_FTR_IN_LW));
469
470 SalQatMsg_CmnMidWrite(pCurrentQatMsg,
471 pRequest,
472 (CPA_DP_BUFLIST == pRequest->srcBufferLen ?
473 QAT_COMN_PTR_TYPE_SGL :
474 QAT_COMN_PTR_TYPE_FLAT),
475 pRequest->srcBuffer,
476 pRequest->dstBuffer,
477 pRequest->srcBufferLen,
478 pRequest->dstBufferLen);
479
480 /* Write Request Params */
481 if (pSessionDesc->isCipher) {
482
483 LacSymQat_CipherRequestParamsPopulate(
484 pSessionDesc,
485 pCurrentQatMsg,
486 pRequest->cryptoStartSrcOffsetInBytes,
487 pRequest->messageLenToCipherInBytes,
488 pRequest->iv,
489 pRequest->pIv);
490 }
491
492 if (pSessionDesc->isAuth) {
493 lac_sym_qat_hash_state_buffer_info_t *pHashStateBufferInfo =
494 &(pSessionDesc->hashStateBufferInfo);
495 icp_qat_fw_la_auth_req_params_t *pAuthReqPars =
496 (icp_qat_fw_la_auth_req_params_t
497 *)((Cpa8U *)&(pCurrentQatMsg->serv_specif_rqpars) +
498 ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
499
500 if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 !=
501 pSessionDesc->hashAlgorithm &&
502 CPA_CY_SYM_HASH_AES_CCM != pSessionDesc->hashAlgorithm &&
503 CPA_CY_SYM_HASH_AES_GCM != pSessionDesc->hashAlgorithm &&
504 CPA_CY_SYM_HASH_AES_GMAC != pSessionDesc->hashAlgorithm &&
505 CPA_CY_SYM_HASH_ZUC_EIA3 != pSessionDesc->hashAlgorithm) &&
506 (pHashStateBufferInfo->prefixAadSzQuadWords > 0)) {
507 /* prefixAadSzQuadWords > 0 when there is prefix data
508 - i.e. nested hash or HMAC no precompute cases
509 Note partials not supported on DP api so we do not need
510 dynamic hash state in this case */
511 pRequest->additionalAuthData =
512 pHashStateBufferInfo->pDataPhys +
513 LAC_QUADWORDS_TO_BYTES(
514 pHashStateBufferInfo->stateStorageSzQuadWords);
515 }
516
517 /* The first 24 bytes in icp_qat_fw_la_auth_req_params_t can be
518 * copied directly from the op request data because they share a
519 * corresponding layout. The remaining 4 bytes are taken
520 * from the session message template and use values
521 * preconfigured at sessionInit (updated per request for some
522 * specific cases below)
523 */
524
525 /* We force a specific compiler optimisation here. The length
526 * to be copied turns out to be always 16, and by coding a
527 * memcpy with a literal value the compiler will compile inline
528 * code (in fact, only two vector instructions) to effect the
529 * copy. This gives us a huge performance increase.
530 */
531 unsigned long cplen =
532 (unsigned long)&(pAuthReqPars->u2.inner_prefix_sz) -
533 (unsigned long)pAuthReqPars;
534 if (cplen == 16)
535 memcpy(pAuthReqPars,
536 (Cpa32U *)&(pRequest->hashStartSrcOffsetInBytes),
537 16);
538 else
539 memcpy(pAuthReqPars,
540 (Cpa32U *)&(pRequest->hashStartSrcOffsetInBytes),
541 cplen);
542
543 if (CPA_TRUE == pSessionDesc->isAuthEncryptOp) {
544 pAuthReqPars->hash_state_sz =
545 LAC_BYTES_TO_QUADWORDS(pAuthReqPars->u2.aad_sz);
546 } else if (CPA_CY_SYM_HASH_SNOW3G_UIA2 ==
547 pSessionDesc->hashAlgorithm ||
548 CPA_CY_SYM_HASH_ZUC_EIA3 ==
549 pSessionDesc->hashAlgorithm) {
550 pAuthReqPars->hash_state_sz =
551 LAC_BYTES_TO_QUADWORDS(pSessionDesc->aadLenInBytes);
552 }
553 }
554
555 }
556
557 /**
558 *****************************************************************************
559 * @ingroup cpaCySymDp
560 * Write Message on the ring and write request params
561 *
562 * @description
563 * Write Message on the ring and write request params
564 *
565 * @param[in/out] pRequest Pointer to operation data for crypto
566 * data plane API
567 * @param[in/out] pCurrentQatMsg Pointer to ring memory where msg will
568 * be written
569 *
570 * @retval none
571 *
572 *****************************************************************************/
573
574 void
LacDp_WriteRingMsgFull(CpaCySymDpOpData * pRequest,icp_qat_fw_la_bulk_req_t * pCurrentQatMsg)575 LacDp_WriteRingMsgFull(CpaCySymDpOpData *pRequest,
576 icp_qat_fw_la_bulk_req_t *pCurrentQatMsg)
577 {
578 lac_session_desc_t *pSessionDesc =
579 LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequest->sessionCtx);
580 Cpa8U *pMsgDummy = NULL;
581 Cpa8U *pCacheDummyHdr = NULL;
582 Cpa8U *pCacheDummyFtr = NULL;
583 sal_qat_content_desc_info_t *pCdInfo = NULL;
584 Cpa8U *pHwBlockBaseInDRAM = NULL;
585 Cpa32U hwBlockOffsetInDRAM = 0;
586 Cpa32U sizeInBytes = 0;
587 CpaCySymCipherAlgorithm cipher = pSessionDesc->cipherAlgorithm;
588 CpaCySymHashAlgorithm hash = pSessionDesc->hashAlgorithm;
589 sal_crypto_service_t *pService =
590 (sal_crypto_service_t *)pRequest->instanceHandle;
591 Cpa32U capabilitiesMask =
592 ((sal_crypto_service_t *)pRequest->instanceHandle)
593 ->generic_service_info.capabilitiesMask;
594
595 CpaBoolean isSpCcm = LAC_CIPHER_IS_CCM(cipher) &&
596 LAC_CIPHER_IS_SPC(cipher, hash, capabilitiesMask);
597
598 Cpa8U paddingLen = 0;
599 Cpa32U aadLenInBytes = 0;
600
601 pMsgDummy = (Cpa8U *)pCurrentQatMsg;
602 /* Write Request */
603 /*
604 * Fill in the header and footer bytes of the ET ring message - cached
605 * from the session descriptor.
606 */
607
608 if ((NON_SPC != pSessionDesc->singlePassState) &&
609 (isSpCcm || (LAC_CIPHER_SPC_IV_SIZE == pRequest->ivLenInBytes))) {
610 pSessionDesc->singlePassState = SPC;
611 pSessionDesc->isCipher = CPA_TRUE;
612 pSessionDesc->isAuthEncryptOp = CPA_FALSE;
613 pSessionDesc->isAuth = CPA_FALSE;
614 pSessionDesc->symOperation = CPA_CY_SYM_OP_CIPHER;
615 pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_CIPHER;
616 if (CPA_CY_SYM_HASH_AES_GMAC == pSessionDesc->hashAlgorithm) {
617 pSessionDesc->aadLenInBytes =
618 pRequest->messageLenToHashInBytes;
619 }
620 /* New bit position (13) for SINGLE PASS.
621 * The FW provides a specific macro to use to set the proto flag
622 */
623 ICP_QAT_FW_LA_SINGLE_PASS_PROTO_FLAG_SET(
624 pSessionDesc->laCmdFlags, ICP_QAT_FW_LA_SINGLE_PASS_PROTO);
625 if (isCyGen2x(pService))
626 ICP_QAT_FW_LA_PROTO_SET(pSessionDesc->laCmdFlags, 0);
627
628 pCdInfo = &(pSessionDesc->contentDescInfo);
629 pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData;
630 if (CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT ==
631 pSessionDesc->cipherDirection) {
632 if (LAC_CIPHER_IS_GCM(cipher))
633 hwBlockOffsetInDRAM = LAC_QUADWORDS_TO_BYTES(
634 LAC_SYM_QAT_CIPHER_GCM_SPC_OFFSET_IN_DRAM);
635 else if (LAC_CIPHER_IS_CHACHA(cipher))
636 hwBlockOffsetInDRAM = LAC_QUADWORDS_TO_BYTES(
637 LAC_SYM_QAT_CIPHER_CHACHA_SPC_OFFSET_IN_DRAM);
638 } else if (isSpCcm) {
639 hwBlockOffsetInDRAM = LAC_QUADWORDS_TO_BYTES(
640 LAC_SYM_QAT_CIPHER_CCM_SPC_OFFSET_IN_DRAM);
641 }
642
643 /* Update slice type, as used algos changed */
644 pSessionDesc->cipherSliceType =
645 LacCipher_GetCipherSliceType(pService, cipher, hash);
646
647 ICP_QAT_FW_LA_SLICE_TYPE_SET(pSessionDesc->laCmdFlags,
648 pSessionDesc->cipherSliceType);
649
650 /* construct cipherConfig in CD in DRAM */
651 LacSymQat_CipherHwBlockPopulateCfgData(pSessionDesc,
652 pHwBlockBaseInDRAM +
653 hwBlockOffsetInDRAM,
654 &sizeInBytes);
655 SalQatMsg_CmnHdrWrite((icp_qat_fw_comn_req_t *)&(
656 pSessionDesc->reqSpcCacheHdr),
657 ICP_QAT_FW_COMN_REQ_CPM_FW_LA,
658 pSessionDesc->laCmdId,
659 pSessionDesc->cmnRequestFlags,
660 pSessionDesc->laCmdFlags);
661 } else if ((SPC == pSessionDesc->singlePassState) &&
662 (LAC_CIPHER_SPC_IV_SIZE != pRequest->ivLenInBytes)) {
663 pSessionDesc->symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING;
664 pSessionDesc->singlePassState = LIKELY_SPC;
665 pSessionDesc->isCipher = CPA_TRUE;
666 pSessionDesc->isAuthEncryptOp = CPA_TRUE;
667 pSessionDesc->isAuth = CPA_TRUE;
668 pCdInfo = &(pSessionDesc->contentDescInfo);
669 pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData;
670
671 if (CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT ==
672 pSessionDesc->cipherDirection) {
673 pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_CIPHER_HASH;
674 } else {
675 pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_HASH_CIPHER;
676 }
677
678 ICP_QAT_FW_LA_SINGLE_PASS_PROTO_FLAG_SET(
679 pSessionDesc->laCmdFlags, 0);
680 ICP_QAT_FW_LA_PROTO_SET(pSessionDesc->laCmdFlags,
681 ICP_QAT_FW_LA_GCM_PROTO);
682
683 LacSymQat_CipherHwBlockPopulateCfgData(pSessionDesc,
684 pHwBlockBaseInDRAM +
685 hwBlockOffsetInDRAM,
686 &sizeInBytes);
687 SalQatMsg_CmnHdrWrite((icp_qat_fw_comn_req_t *)&(
688 pSessionDesc->reqCacheHdr),
689 ICP_QAT_FW_COMN_REQ_CPM_FW_LA,
690 pSessionDesc->laCmdId,
691 pSessionDesc->cmnRequestFlags,
692 pSessionDesc->laCmdFlags);
693 } else if (CPA_CY_SYM_HASH_AES_GMAC == pSessionDesc->hashAlgorithm) {
694 pSessionDesc->aadLenInBytes = pRequest->messageLenToHashInBytes;
695 }
696 if (SPC == pSessionDesc->singlePassState) {
697 pCacheDummyHdr = (Cpa8U *)&(pSessionDesc->reqSpcCacheHdr);
698 pCacheDummyFtr = (Cpa8U *)&(pSessionDesc->reqSpcCacheFtr);
699 } else {
700 if (!pSessionDesc->useSymConstantsTable) {
701 pCacheDummyHdr = (Cpa8U *)&(pSessionDesc->reqCacheHdr);
702 pCacheDummyFtr = (Cpa8U *)&(pSessionDesc->reqCacheFtr);
703 } else {
704 pCacheDummyHdr =
705 (Cpa8U *)&(pSessionDesc->shramReqCacheHdr);
706 pCacheDummyFtr =
707 (Cpa8U *)&(pSessionDesc->shramReqCacheFtr);
708 }
709 }
710 memcpy(pMsgDummy,
711 pCacheDummyHdr,
712 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_HDR_IN_LW));
713 memset((pMsgDummy +
714 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_HDR_IN_LW)),
715 0,
716 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_TO_CLEAR_IN_LW));
717 memcpy(pMsgDummy +
718 (LAC_LONG_WORD_IN_BYTES * LAC_START_OF_CACHE_FTR_IN_LW),
719 pCacheDummyFtr,
720 (LAC_LONG_WORD_IN_BYTES * LAC_SIZE_OF_CACHE_FTR_IN_LW));
721
722 SalQatMsg_CmnMidWrite(pCurrentQatMsg,
723 pRequest,
724 (CPA_DP_BUFLIST == pRequest->srcBufferLen ?
725 QAT_COMN_PTR_TYPE_SGL :
726 QAT_COMN_PTR_TYPE_FLAT),
727 pRequest->srcBuffer,
728 pRequest->dstBuffer,
729 pRequest->srcBufferLen,
730 pRequest->dstBufferLen);
731
732 if ((CPA_CY_SYM_HASH_AES_CCM == pSessionDesc->hashAlgorithm &&
733 pSessionDesc->isAuth == CPA_TRUE) ||
734 isSpCcm) {
735 /* prepare IV and AAD for CCM */
736 LacSymAlgChain_PrepareCCMData(
737 pSessionDesc,
738 pRequest->pAdditionalAuthData,
739 pRequest->pIv,
740 pRequest->messageLenToCipherInBytes,
741 pRequest->ivLenInBytes);
742
743 /* According to the API, for CCM and GCM,
744 * messageLenToHashInBytes and hashStartSrcOffsetInBytes are not
745 * initialized by the user and must be set by the driver
746 */
747 pRequest->hashStartSrcOffsetInBytes =
748 pRequest->cryptoStartSrcOffsetInBytes;
749 pRequest->messageLenToHashInBytes =
750 pRequest->messageLenToCipherInBytes;
751 } else if ((SPC != pSessionDesc->singlePassState) &&
752 (CPA_CY_SYM_HASH_AES_GCM == pSessionDesc->hashAlgorithm ||
753 CPA_CY_SYM_HASH_AES_GMAC == pSessionDesc->hashAlgorithm)) {
754 /* GCM case */
755 if (CPA_CY_SYM_HASH_AES_GMAC != pSessionDesc->hashAlgorithm) {
756 /* According to the API, for CCM and GCM,
757 * messageLenToHashInBytes and hashStartSrcOffsetInBytes
758 * are not initialized by the user and must be set
759 * by the driver
760 */
761 pRequest->hashStartSrcOffsetInBytes =
762 pRequest->cryptoStartSrcOffsetInBytes;
763 pRequest->messageLenToHashInBytes =
764 pRequest->messageLenToCipherInBytes;
765
766 LacSymAlgChain_PrepareGCMData(
767 pSessionDesc, pRequest->pAdditionalAuthData);
768 }
769
770 if (LAC_CIPHER_IV_SIZE_GCM_12 == pRequest->ivLenInBytes) {
771 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
772 pCurrentQatMsg->comn_hdr.serv_specif_flags,
773 ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
774 }
775 }
776
777 /* Write Request Params */
778 if (pSessionDesc->isCipher) {
779 if (CPA_CY_SYM_CIPHER_ARC4 == pSessionDesc->cipherAlgorithm) {
780 /* ARC4 does not have an IV but the field is used to
781 * store the initial state */
782 pRequest->iv =
783 pSessionDesc->cipherARC4InitialStatePhysAddr;
784 }
785
786 ICP_QAT_FW_LA_SLICE_TYPE_SET(
787 pCurrentQatMsg->comn_hdr.serv_specif_flags,
788 pSessionDesc->cipherSliceType);
789
790 LacSymQat_CipherRequestParamsPopulate(
791 pSessionDesc,
792 pCurrentQatMsg,
793 pRequest->cryptoStartSrcOffsetInBytes,
794 pRequest->messageLenToCipherInBytes,
795 pRequest->iv,
796 pRequest->pIv);
797 if (SPC == pSessionDesc->singlePassState) {
798 icp_qat_fw_la_cipher_req_params_t *pCipherReqParams =
799 (icp_qat_fw_la_cipher_req_params_t
800 *)((Cpa8U *)&(
801 pCurrentQatMsg->serv_specif_rqpars) +
802 ICP_QAT_FW_CIPHER_REQUEST_PARAMETERS_OFFSET);
803
804 icp_qat_fw_la_cipher_20_req_params_t *pCipher20ReqParams =
805 (void
806 *)((Cpa8U *)&(
807 pCurrentQatMsg->serv_specif_rqpars) +
808 ICP_QAT_FW_CIPHER_REQUEST_PARAMETERS_OFFSET);
809
810 if (isCyGen4x(pService)) {
811 pCipher20ReqParams->spc_aad_addr =
812 (uint64_t)pRequest->additionalAuthData;
813 pCipher20ReqParams->spc_aad_sz =
814 pSessionDesc->aadLenInBytes;
815 pCipher20ReqParams->spc_aad_offset = 0;
816
817 if (isSpCcm)
818 pCipher20ReqParams->spc_aad_sz +=
819 LAC_CIPHER_CCM_AAD_OFFSET;
820
821 pCipher20ReqParams->spc_auth_res_addr =
822 (uint64_t)pRequest->digestResult;
823 pCipher20ReqParams->spc_auth_res_sz =
824 (Cpa8U)pSessionDesc->hashResultSize;
825 } else {
826 pCipherReqParams->spc_aad_addr =
827 (uint64_t)pRequest->additionalAuthData;
828 pCipherReqParams->spc_aad_sz =
829 (Cpa16U)pSessionDesc->aadLenInBytes;
830
831 pCipherReqParams->spc_auth_res_addr =
832 (uint64_t)pRequest->digestResult;
833 pCipherReqParams->spc_auth_res_sz =
834 (Cpa8U)pSessionDesc->hashResultSize;
835 }
836
837 /* Pad the AAD buffer to a blocklen multiple.
838 * For ChaChaPoly and AES-GCM there is an AAD buffer if
839 * aadLenInBytes is nonzero. For CCM there is always an
840 * AAD buffer, even if aadLenInBytes is zero, as the
841 * first 16 bytes are needed for B0, but padding is only
842 * needed if aadLen > 0. In case of AES-GMAC, there's no
843 * AAD buffer as the AAD is passed in the src buffer, so
844 * no padding needed.
845 */
846 if (0 < pSessionDesc->aadLenInBytes &&
847 CPA_CY_SYM_HASH_AES_GMAC !=
848 pSessionDesc->hashAlgorithm) {
849 aadLenInBytes = pSessionDesc->aadLenInBytes;
850
851 /* In case of AES_CCM, start padding after B0
852 * block size plus 2 bytes of AAD len encoding
853 * plus AAD data len.
854 */
855 if (isSpCcm)
856 aadLenInBytes +=
857 LAC_CIPHER_CCM_AAD_OFFSET;
858
859 if (aadLenInBytes % LAC_SYM_CIPHER_AAD_PADLEN !=
860 0) {
861 paddingLen = LAC_SYM_CIPHER_AAD_PADLEN -
862 (aadLenInBytes %
863 LAC_SYM_CIPHER_AAD_PADLEN);
864 memset(&pRequest->pAdditionalAuthData
865 [aadLenInBytes],
866 0,
867 paddingLen);
868 }
869 }
870 }
871 }
872
873 if (pSessionDesc->isAuth) {
874 lac_sym_qat_hash_state_buffer_info_t *pHashStateBufferInfo =
875 &(pSessionDesc->hashStateBufferInfo);
876 icp_qat_fw_la_auth_req_params_t *pAuthReqPars =
877 (icp_qat_fw_la_auth_req_params_t
878 *)((Cpa8U *)&(pCurrentQatMsg->serv_specif_rqpars) +
879 ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
880
881 if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 !=
882 pSessionDesc->hashAlgorithm &&
883 CPA_CY_SYM_HASH_AES_CCM != pSessionDesc->hashAlgorithm &&
884 CPA_CY_SYM_HASH_AES_GCM != pSessionDesc->hashAlgorithm &&
885 CPA_CY_SYM_HASH_AES_GMAC != pSessionDesc->hashAlgorithm &&
886 CPA_CY_SYM_HASH_ZUC_EIA3 != pSessionDesc->hashAlgorithm) &&
887 (pHashStateBufferInfo->prefixAadSzQuadWords > 0)) {
888 /* prefixAadSzQuadWords > 0 when there is prefix data
889 - i.e. nested hash or HMAC no precompute cases
890 Note partials not supported on DP api so we do not need
891 dynamic hash state in this case */
892 pRequest->additionalAuthData =
893 pHashStateBufferInfo->pDataPhys +
894 LAC_QUADWORDS_TO_BYTES(
895 pHashStateBufferInfo->stateStorageSzQuadWords);
896 }
897
898 /* The first 24 bytes in icp_qat_fw_la_auth_req_params_t can be
899 * copied directly from the op request data because they share a
900 * corresponding layout. The remaining 4 bytes are taken
901 * from the session message template and use values
902 * preconfigured at sessionInit (updated per request for some
903 * specific cases below)
904 */
905 memcpy(pAuthReqPars,
906 (Cpa32U *)&(pRequest->hashStartSrcOffsetInBytes),
907 ((uintptr_t) &
908 (pAuthReqPars->u2.inner_prefix_sz) -
909 (uintptr_t)pAuthReqPars));
910
911 if (CPA_TRUE == pSessionDesc->isAuthEncryptOp) {
912 pAuthReqPars->hash_state_sz =
913 LAC_BYTES_TO_QUADWORDS(pAuthReqPars->u2.aad_sz);
914 } else if (CPA_CY_SYM_HASH_SNOW3G_UIA2 ==
915 pSessionDesc->hashAlgorithm ||
916 CPA_CY_SYM_HASH_ZUC_EIA3 ==
917 pSessionDesc->hashAlgorithm) {
918 pAuthReqPars->hash_state_sz =
919 LAC_BYTES_TO_QUADWORDS(pSessionDesc->aadLenInBytes);
920 }
921 }
922
923 }
924
925 CpaStatus
cpaCySymDpSessionCtxGetSize(const CpaInstanceHandle instanceHandle,const CpaCySymSessionSetupData * pSessionSetupData,Cpa32U * pSessionCtxSizeInBytes)926 cpaCySymDpSessionCtxGetSize(const CpaInstanceHandle instanceHandle,
927 const CpaCySymSessionSetupData *pSessionSetupData,
928 Cpa32U *pSessionCtxSizeInBytes)
929 {
930 CpaStatus status = CPA_STATUS_SUCCESS;
931
932 /* CPA_INSTANCE_HANDLE_SINGLE is not supported on DP apis */
933 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
934 /* All other param checks are common with trad api */
935 /* Check for valid pointers */
936 LAC_CHECK_NULL_PARAM(pSessionCtxSizeInBytes);
937 status = cpaCySymSessionCtxGetSize(instanceHandle,
938 pSessionSetupData,
939 pSessionCtxSizeInBytes);
940
941 return status;
942 }
943
944 CpaStatus
cpaCySymDpSessionCtxGetDynamicSize(const CpaInstanceHandle instanceHandle,const CpaCySymSessionSetupData * pSessionSetupData,Cpa32U * pSessionCtxSizeInBytes)945 cpaCySymDpSessionCtxGetDynamicSize(
946 const CpaInstanceHandle instanceHandle,
947 const CpaCySymSessionSetupData *pSessionSetupData,
948 Cpa32U *pSessionCtxSizeInBytes)
949 {
950 CpaStatus status = CPA_STATUS_SUCCESS;
951
952 /* CPA_INSTANCE_HANDLE_SINGLE is not supported on DP apis */
953 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
954 /* All other param checks are common with trad api */
955 /* Check for valid pointers */
956 LAC_CHECK_NULL_PARAM(pSessionCtxSizeInBytes);
957 status = cpaCySymSessionCtxGetDynamicSize(instanceHandle,
958 pSessionSetupData,
959 pSessionCtxSizeInBytes);
960
961 return status;
962 }
963
964 /** @ingroup cpaCySymDp */
965 CpaStatus
cpaCySymDpInitSession(CpaInstanceHandle instanceHandle,const CpaCySymSessionSetupData * pSessionSetupData,CpaCySymDpSessionCtx sessionCtx)966 cpaCySymDpInitSession(CpaInstanceHandle instanceHandle,
967 const CpaCySymSessionSetupData *pSessionSetupData,
968 CpaCySymDpSessionCtx sessionCtx)
969 {
970 CpaStatus status = CPA_STATUS_FAIL;
971 sal_service_t *pService = NULL;
972
973 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
974 SAL_CHECK_INSTANCE_TYPE(instanceHandle,
975 (SAL_SERVICE_TYPE_CRYPTO |
976 SAL_SERVICE_TYPE_CRYPTO_SYM));
977 LAC_CHECK_NULL_PARAM(pSessionSetupData);
978 pService = (sal_service_t *)instanceHandle;
979
980 /* Check crypto service is running otherwise return an error */
981 SAL_RUNNING_CHECK(pService);
982
983 status = LacSym_InitSession(instanceHandle,
984 NULL, /* Callback */
985 pSessionSetupData,
986 CPA_TRUE, /* isDPSession */
987 sessionCtx);
988 return status;
989 }
990
991 CpaStatus
cpaCySymDpRemoveSession(const CpaInstanceHandle instanceHandle,CpaCySymDpSessionCtx sessionCtx)992 cpaCySymDpRemoveSession(const CpaInstanceHandle instanceHandle,
993 CpaCySymDpSessionCtx sessionCtx)
994 {
995
996 /* CPA_INSTANCE_HANDLE_SINGLE is not supported on DP apis */
997 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
998 /* All other param checks are common with trad api */
999
1000 return cpaCySymRemoveSession(instanceHandle, sessionCtx);
1001 }
1002
1003 CpaStatus
cpaCySymDpRegCbFunc(const CpaInstanceHandle instanceHandle,const CpaCySymDpCbFunc pSymDpCb)1004 cpaCySymDpRegCbFunc(const CpaInstanceHandle instanceHandle,
1005 const CpaCySymDpCbFunc pSymDpCb)
1006 {
1007 sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
1008
1009 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
1010 SAL_CHECK_INSTANCE_TYPE(instanceHandle,
1011 (SAL_SERVICE_TYPE_CRYPTO |
1012 SAL_SERVICE_TYPE_CRYPTO_SYM));
1013 LAC_CHECK_NULL_PARAM(pSymDpCb);
1014 SAL_RUNNING_CHECK(instanceHandle);
1015 pService->pSymDpCb = pSymDpCb;
1016
1017 return CPA_STATUS_SUCCESS;
1018 }
1019
1020 CpaStatus
cpaCySymDpEnqueueOp(CpaCySymDpOpData * pRequest,const CpaBoolean performOpNow)1021 cpaCySymDpEnqueueOp(CpaCySymDpOpData *pRequest, const CpaBoolean performOpNow)
1022 {
1023 icp_qat_fw_la_bulk_req_t *pCurrentQatMsg = NULL;
1024 icp_comms_trans_handle trans_handle = NULL;
1025 lac_session_desc_t *pSessionDesc = NULL;
1026 write_ringMsgFunc_t callFunc;
1027
1028 CpaStatus status = CPA_STATUS_SUCCESS;
1029
1030 LAC_CHECK_NULL_PARAM(pRequest);
1031 status = LacDp_EnqueueParamCheck(pRequest);
1032 if (CPA_STATUS_SUCCESS != status) {
1033 return status;
1034 }
1035
1036 /* Check if SAL is running in crypto data plane otherwise return an
1037 * error */
1038 SAL_RUNNING_CHECK(pRequest->instanceHandle);
1039
1040 trans_handle = ((sal_crypto_service_t *)pRequest->instanceHandle)
1041 ->trans_handle_sym_tx;
1042
1043 pSessionDesc = LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequest->sessionCtx);
1044 icp_adf_getSingleQueueAddr(trans_handle, (void **)&pCurrentQatMsg);
1045 if (NULL == pCurrentQatMsg) {
1046 /*
1047 * No space is available on the queue.
1048 */
1049 return CPA_STATUS_RETRY;
1050 }
1051
1052 callFunc = (write_ringMsgFunc_t)pSessionDesc->writeRingMsgFunc;
1053
1054 LAC_CHECK_NULL_PARAM(callFunc);
1055
1056 callFunc(pRequest, pCurrentQatMsg);
1057
1058 qatUtilsAtomicInc(&(pSessionDesc->u.pendingDpCbCount));
1059
1060 if (CPA_TRUE == performOpNow) {
1061 SalQatMsg_updateQueueTail(trans_handle);
1062 }
1063
1064 return CPA_STATUS_SUCCESS;
1065 }
1066
1067 CpaStatus
cpaCySymDpPerformOpNow(const CpaInstanceHandle instanceHandle)1068 cpaCySymDpPerformOpNow(const CpaInstanceHandle instanceHandle)
1069 {
1070 icp_comms_trans_handle trans_handle = NULL;
1071
1072 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
1073 SAL_CHECK_INSTANCE_TYPE(instanceHandle,
1074 (SAL_SERVICE_TYPE_CRYPTO |
1075 SAL_SERVICE_TYPE_CRYPTO_SYM));
1076
1077 /* Check if SAL is initialised otherwise return an error */
1078 SAL_RUNNING_CHECK(instanceHandle);
1079
1080 trans_handle =
1081 ((sal_crypto_service_t *)instanceHandle)->trans_handle_sym_tx;
1082
1083 if (CPA_TRUE == icp_adf_queueDataToSend(trans_handle)) {
1084 SalQatMsg_updateQueueTail(trans_handle);
1085 }
1086
1087 return CPA_STATUS_SUCCESS;
1088 }
1089
1090 CpaStatus
cpaCySymDpEnqueueOpBatch(const Cpa32U numberRequests,CpaCySymDpOpData * pRequests[],const CpaBoolean performOpNow)1091 cpaCySymDpEnqueueOpBatch(const Cpa32U numberRequests,
1092 CpaCySymDpOpData *pRequests[],
1093 const CpaBoolean performOpNow)
1094 {
1095 icp_qat_fw_la_bulk_req_t *pCurrentQatMsg = NULL;
1096 icp_comms_trans_handle trans_handle = NULL;
1097 lac_session_desc_t *pSessionDesc = NULL;
1098 write_ringMsgFunc_t callFunc;
1099 Cpa32U i = 0;
1100
1101 CpaStatus status = CPA_STATUS_SUCCESS;
1102 sal_crypto_service_t *pService = NULL;
1103
1104 LAC_CHECK_NULL_PARAM(pRequests);
1105 LAC_CHECK_NULL_PARAM(pRequests[0]);
1106 LAC_CHECK_NULL_PARAM(pRequests[0]->instanceHandle);
1107
1108 pService = (sal_crypto_service_t *)(pRequests[0]->instanceHandle);
1109
1110 if ((0 == numberRequests) ||
1111 (numberRequests > pService->maxNumSymReqBatch)) {
1112 LAC_INVALID_PARAM_LOG1(
1113 "The number of requests needs to be between 1 "
1114 "and %d",
1115 pService->maxNumSymReqBatch);
1116 return CPA_STATUS_INVALID_PARAM;
1117 }
1118
1119 for (i = 0; i < numberRequests; i++) {
1120 status = LacDp_EnqueueParamCheck(pRequests[i]);
1121 if (CPA_STATUS_SUCCESS != status) {
1122 return status;
1123 }
1124
1125 /* Check that all instance handles are the same */
1126 if (pRequests[i]->instanceHandle !=
1127 pRequests[0]->instanceHandle) {
1128 LAC_INVALID_PARAM_LOG(
1129 "All instance handles should be the same "
1130 "in the requests");
1131 return CPA_STATUS_INVALID_PARAM;
1132 }
1133 }
1134
1135 /* Check if SAL is running in crypto data plane otherwise return an
1136 * error */
1137 SAL_RUNNING_CHECK(pRequests[0]->instanceHandle);
1138
1139 trans_handle = ((sal_crypto_service_t *)pRequests[0]->instanceHandle)
1140 ->trans_handle_sym_tx;
1141 pSessionDesc =
1142 LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequests[0]->sessionCtx);
1143 icp_adf_getQueueMemory(trans_handle,
1144 numberRequests,
1145 (void **)&pCurrentQatMsg);
1146 if (NULL == pCurrentQatMsg) {
1147 /*
1148 * No space is available on the queue.
1149 */
1150 return CPA_STATUS_RETRY;
1151 }
1152
1153 for (i = 0; i < numberRequests; i++) {
1154 pSessionDesc =
1155 LAC_SYM_SESSION_DESC_FROM_CTX_GET(pRequests[i]->sessionCtx);
1156 callFunc = (write_ringMsgFunc_t)pSessionDesc->writeRingMsgFunc;
1157 callFunc(pRequests[i], pCurrentQatMsg);
1158 icp_adf_getQueueNext(trans_handle, (void **)&pCurrentQatMsg);
1159 qatUtilsAtomicAdd(1, &(pSessionDesc->u.pendingDpCbCount));
1160 }
1161
1162 if (CPA_TRUE == performOpNow) {
1163 SalQatMsg_updateQueueTail(trans_handle);
1164 }
1165
1166 return CPA_STATUS_SUCCESS;
1167 }
1168
1169 CpaStatus
icp_sal_CyPollDpInstance(const CpaInstanceHandle instanceHandle,const Cpa32U responseQuota)1170 icp_sal_CyPollDpInstance(const CpaInstanceHandle instanceHandle,
1171 const Cpa32U responseQuota)
1172 {
1173 icp_comms_trans_handle trans_handle = NULL;
1174
1175 LAC_CHECK_INSTANCE_HANDLE(instanceHandle);
1176 SAL_CHECK_INSTANCE_TYPE(instanceHandle,
1177 (SAL_SERVICE_TYPE_CRYPTO |
1178 SAL_SERVICE_TYPE_CRYPTO_SYM));
1179
1180 /* Check if SAL is initialised otherwise return an error */
1181 SAL_RUNNING_CHECK(instanceHandle);
1182
1183 trans_handle =
1184 ((sal_crypto_service_t *)instanceHandle)->trans_handle_sym_rx;
1185
1186 return icp_adf_pollQueue(trans_handle, responseQuota);
1187 }
1188