xref: /freebsd/sys/dev/qat/qat_api/qat_utils/include/qat_utils.h (revision 25f09d4a9c358c5452435d299e00c1a1bdafff87)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2025 Intel Corporation */
3 #ifndef QAT_UTILS_H
4 #define QAT_UTILS_H
5 
6 #include <sys/param.h>
7 #include <sys/ctype.h>
8 #include <sys/endian.h>
9 #include <sys/lock.h>
10 #include <sys/mutex.h>
11 #include <sys/systm.h>
12 #include <sys/types.h>
13 #include <sys/sema.h>
14 #include <sys/time.h>
15 #include <sys/malloc.h>
16 #include <sys/kernel.h>
17 #include <sys/sysctl.h>
18 #include <sys/limits.h>
19 #include <sys/unistd.h>
20 #include <sys/libkern.h>
21 #ifdef __x86_64__
22 #include <asm/atomic64.h>
23 #else
24 #include <asm/atomic.h>
25 #endif
26 #include <vm/vm.h>
27 #include <vm/pmap.h>
28 
29 #include <sys/md5.h>
30 #include <crypto/sha1.h>
31 #include <crypto/sha2/sha256.h>
32 #include <crypto/sha2/sha224.h>
33 #include <crypto/sha2/sha384.h>
34 #include <crypto/sha2/sha512.h>
35 #include <crypto/rijndael/rijndael-api-fst.h>
36 
37 #include <opencrypto/cryptodev.h>
38 
39 #include "cpa.h"
40 
41 #define QAT_UTILS_LOG(...) printf("QAT: "__VA_ARGS__)
42 
43 #define QAT_UTILS_WAIT_FOREVER (-1)
44 #define QAT_UTILS_WAIT_NONE 0
45 
46 #define QAT_UTILS_HOST_TO_NW_16(uData) QAT_UTILS_OS_HOST_TO_NW_16(uData)
47 #define QAT_UTILS_HOST_TO_NW_32(uData) QAT_UTILS_OS_HOST_TO_NW_32(uData)
48 #define QAT_UTILS_HOST_TO_NW_64(uData) QAT_UTILS_OS_HOST_TO_NW_64(uData)
49 
50 #define QAT_UTILS_NW_TO_HOST_16(uData) QAT_UTILS_OS_NW_TO_HOST_16(uData)
51 #define QAT_UTILS_NW_TO_HOST_32(uData) QAT_UTILS_OS_NW_TO_HOST_32(uData)
52 #define QAT_UTILS_NW_TO_HOST_64(uData) QAT_UTILS_OS_NW_TO_HOST_64(uData)
53 
54 #define QAT_UTILS_UDIV64_32(dividend, divisor)                                 \
55 	QAT_UTILS_OS_UDIV64_32(dividend, divisor)
56 
57 #define QAT_UTILS_UMOD64_32(dividend, divisor)                                 \
58 	QAT_UTILS_OS_UMOD64_32(dividend, divisor)
59 
60 #define ICP_CHECK_FOR_NULL_PARAM(param)                                        \
61 	do {                                                                   \
62 		if (NULL == param) {                                           \
63 			QAT_UTILS_LOG("%s(): invalid param: %s\n",             \
64 				      __FUNCTION__,                            \
65 				      #param);                                 \
66 			return CPA_STATUS_INVALID_PARAM;                       \
67 		}                                                              \
68 	} while (0)
69 
70 #define ICP_CHECK_FOR_NULL_PARAM_VOID(param)                                   \
71 	do {                                                                   \
72 		if (NULL == param) {                                           \
73 			QAT_UTILS_LOG("%s(): invalid param: %s\n",             \
74 				      __FUNCTION__,                            \
75 				      #param);                                 \
76 			return;                                                \
77 		}                                                              \
78 	} while (0)
79 
80 /*Macro for adding an element to the tail of a doubly linked list*/
81 /*The currentptr tracks the tail, and the headptr tracks the head.*/
82 #define ICP_ADD_ELEMENT_TO_END_OF_LIST(elementtoadd, currentptr, headptr)      \
83 	do {                                                                   \
84 		if (NULL == currentptr) {                                      \
85 			currentptr = elementtoadd;                             \
86 			elementtoadd->pNext = NULL;                            \
87 			elementtoadd->pPrev = NULL;                            \
88 			headptr = currentptr;                                  \
89 		} else {                                                       \
90 			elementtoadd->pPrev = currentptr;                      \
91 			currentptr->pNext = elementtoadd;                      \
92 			elementtoadd->pNext = NULL;                            \
93 			currentptr = elementtoadd;                             \
94 		}                                                              \
95 	} while (0)
96 
97 /*currentptr is not used in this case since we don't track the tail. */
98 #define ICP_ADD_ELEMENT_TO_HEAD_OF_LIST(elementtoadd, currentptr, headptr)     \
99 	do {                                                                   \
100 		if (NULL == headptr) {                                         \
101 			elementtoadd->pNext = NULL;                            \
102 			elementtoadd->pPrev = NULL;                            \
103 			headptr = elementtoadd;                                \
104 		} else {                                                       \
105 			elementtoadd->pPrev = NULL;                            \
106 			elementtoadd->pNext = headptr;                         \
107 			headptr->pPrev = elementtoadd;                         \
108 			headptr = elementtoadd;                                \
109 		}                                                              \
110 	} while (0)
111 
112 #define ICP_REMOVE_ELEMENT_FROM_LIST(elementtoremove, currentptr, headptr)     \
113 	do {                                                                   \
114 		/*If the previous pointer is not NULL*/                        \
115 		if (NULL != elementtoremove->pPrev) {                          \
116 			elementtoremove->pPrev->pNext =                        \
117 			    elementtoremove->pNext;                            \
118 			if (elementtoremove->pNext) {                          \
119 				elementtoremove->pNext->pPrev =                \
120 				    elementtoremove->pPrev;                    \
121 			} else {                                               \
122 				/* Move the tail pointer backwards */          \
123 				currentptr = elementtoremove->pPrev;           \
124 			}                                                      \
125 		} else if (NULL != elementtoremove->pNext) {                   \
126 			/*Remove the head pointer.*/                           \
127 			elementtoremove->pNext->pPrev = NULL;                  \
128 			/*Hence move the head forward.*/                       \
129 			headptr = elementtoremove->pNext;                      \
130 		} else {                                                       \
131 			/*Remove the final entry in the list. */               \
132 			currentptr = NULL;                                     \
133 			headptr = NULL;                                        \
134 		}                                                              \
135 	} while (0)
136 
137 MALLOC_DECLARE(M_QAT);
138 
139 #ifdef __x86_64__
140 typedef atomic64_t QatUtilsAtomic;
141 #else
142 typedef atomic_t QatUtilsAtomic;
143 #endif
144 
145 #define QAT_UTILS_OS_NW_TO_HOST_16(uData) be16toh(uData)
146 #define QAT_UTILS_OS_NW_TO_HOST_32(uData) be32toh(uData)
147 #define QAT_UTILS_OS_NW_TO_HOST_64(uData) be64toh(uData)
148 
149 #define QAT_UTILS_OS_HOST_TO_NW_16(uData) htobe16(uData)
150 #define QAT_UTILS_OS_HOST_TO_NW_32(uData) htobe32(uData)
151 #define QAT_UTILS_OS_HOST_TO_NW_64(uData) htobe64(uData)
152 
153 /**
154  * @ingroup QatUtils
155  *
156  * @brief Atomically read the value of atomic variable
157  *
158  * @param  pAtomicVar  IN   - atomic variable
159  *
160  * Atomically reads the value of pAtomicVar to the outValue
161  *
162  * @li Reentrant: yes
163  * @li IRQ safe:  yes
164  *
165  * @return  pAtomicVar value
166  */
167 int64_t qatUtilsAtomicGet(QatUtilsAtomic *pAtomicVar);
168 
169 /**
170  * @ingroup QatUtils
171  *
172  * @brief Atomically set the value of atomic variable
173  *
174  * @param  inValue    IN   -  atomic variable to be set equal to inValue
175  *
176  * @param  pAtomicVar  OUT  - atomic variable
177  *
178  * Atomically sets the value of pAtomicVar to the value given
179  *
180  * @li Reentrant: yes
181  * @li IRQ safe:  yes
182  *
183  * @return none
184  */
185 void qatUtilsAtomicSet(int64_t inValue, QatUtilsAtomic *pAtomicVar);
186 
187 /**
188  * @ingroup QatUtils
189  *
190  * @brief add the value to atomic variable
191  *
192  * @param  inValue (in)   -  value to be added to the atomic variable
193  *
194  * @param  pAtomicVar (in & out)   - atomic variable
195  *
196  * Atomically adds the value of inValue to the pAtomicVar
197  *
198  * @li Reentrant: yes
199  * @li IRQ safe:  yes
200  *
201  * @return pAtomicVar value after the addition
202  */
203 int64_t qatUtilsAtomicAdd(int64_t inValue, QatUtilsAtomic *pAtomicVar);
204 
205 /**
206  * @ingroup QatUtils
207  *
208  * @brief subtract the value from atomic variable
209  *
210  * @param  inValue   IN     -  atomic variable value to be subtracted by value
211  *
212  * @param  pAtomicVar IN/OUT - atomic variable
213  *
214  * Atomically subtracts the value of pAtomicVar by inValue
215  *
216  * @li Reentrant: yes
217  * @li IRQ safe:  yes
218  *
219  * @return pAtomicVar value after the subtraction
220  */
221 int64_t qatUtilsAtomicSub(int64_t inValue, QatUtilsAtomic *pAtomicVar);
222 
223 /**
224  * @ingroup QatUtils
225  *
226  * @brief increment value of atomic variable by 1
227  *
228  * @param  pAtomicVar IN/OUT   - atomic variable
229  *
230  * Atomically increments the value of pAtomicVar by 1.
231  *
232  * @li Reentrant: yes
233  * @li IRQ safe:  yes
234  *
235  * @return pAtomicVar value after the increment
236  */
237 int64_t qatUtilsAtomicInc(QatUtilsAtomic *pAtomicVar);
238 
239 /**
240  * @ingroup QatUtils
241  *
242  * @brief decrement value of atomic variable by 1
243  *
244  * @param  pAtomicVar IN/OUT  - atomic variable
245  *
246  * Atomically decrements the value of pAtomicVar by 1.
247  *
248  * @li Reentrant: yes
249  * @li IRQ safe:  yes
250  *
251  * @return pAtomic value after the decrement
252  */
253 int64_t qatUtilsAtomicDec(QatUtilsAtomic *pAtomicVar);
254 
255 /**
256  * @ingroup QatUtils
257  *
258  * @brief NUMA aware memory allocation; available on Linux OS only.
259  *
260  * @param size - memory size to allocate, in bytes
261  * @param node - node
262  * @param alignment - memory boundary alignment (alignment can not be 0)
263  *
264  * Allocates a memory zone of a given size on the specified node
265  * The returned memory is guaraunteed to be physically contiguous if the
266  * given size is less than 128KB and belonging to the node specified
267  *
268  * @li Reentrant: yes
269  * @li IRQ safe:  no
270  *
271  * @return Pointer to the allocated zone or NULL if the allocation failed
272  */
273 void *qatUtilsMemAllocContiguousNUMA(uint32_t size,
274 				     uint32_t node,
275 				     uint32_t alignment);
276 
277 /**
278  * @ingroup QatUtils
279  *
280  * @brief Frees memory allocated by qatUtilsMemAllocContigousNUMA.
281  *
282  * @param ptr - pointer to the memory zone
283  * @param size - size of the pointer previously allocated
284  *
285  * Frees a previously allocated memory zone
286  *
287  * @li Reentrant: yes
288  * @li IRQ safe:  no
289  *
290  * @return - none
291  */
292 void qatUtilsMemFreeNUMA(void *ptr);
293 
294 /**
295  * @ingroup QatUtils
296  *
297  * @brief virtual to physical address translation
298  *
299  * @param virtAddr - virtual address
300  *
301  * Converts a virtual address into its equivalent MMU-mapped physical address
302  *
303  * @li Reentrant: yes
304  * @li IRQ safe:  yes
305  *
306  * @return Corresponding physical address
307  */
308 #define QAT_UTILS_MMU_VIRT_TO_PHYS(virtAddr)                                   \
309 	((uint64_t)((virtAddr) ? vtophys(virtAddr) : 0))
310 
311 /**
312  * @ingroup QatUtils
313  *
314  * @brief Initializes the SpinLock object
315  *
316  * @param pLock - Spinlock handle
317  *
318  * Initializes the SpinLock object.
319  *
320  * @li Reentrant: yes
321  * @li IRQ safe:  yes
322  *
323  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
324  */
325 CpaStatus qatUtilsLockInit(struct mtx *pLock);
326 
327 /**
328  * @ingroup QatUtils
329  *
330  * @brief Acquires a spin lock
331  *
332  * @param pLock - Spinlock handle
333  *
334  * This routine acquires a spin lock so the
335  * caller can synchronize access to shared data in a
336  * multiprocessor-safe way by raising IRQL.
337  *
338  * @li Reentrant: yes
339  * @li IRQ safe:  yes
340  *
341  * @return - Returns CPA_STATUS_SUCCESS if the spinlock is acquired. Returns
342  * CPA_STATUS_FAIL
343  * if
344  *           spinlock handle is NULL. If spinlock is already acquired by any
345  *           other thread of execution then it tries in busy loop/spins till it
346  *           gets spinlock.
347  */
348 CpaStatus qatUtilsLock(struct mtx *pLock);
349 
350 /**
351  * @ingroup QatUtils
352  *
353  * @brief Releases the spin lock
354  *
355  * @param pLock - Spinlock handle
356  *
357  * This routine releases the spin lock which the thread had acquired
358  *
359  * @li Reentrant: yes
360  * @li IRQ safe:  yes
361  *
362  * @return - return CPA_STATUS_SUCCESS if the spinlock is released. Returns
363  * CPA_STATUS_FAIL
364  * if
365  *           spinlockhandle passed is NULL.
366  */
367 CpaStatus qatUtilsUnlock(struct mtx *pLock);
368 
369 /**
370  * @ingroup QatUtils
371  *
372  * @brief Destroy the spin lock object
373  *
374  * @param pLock - Spinlock handle
375  *
376  * @li Reentrant: yes
377  * @li IRQ safe:  yes
378  *
379  * @return - returns CPA_STATUS_SUCCESS if plock is destroyed.
380  *           returns CPA_STATUS_FAIL if plock is NULL.
381  */
382 CpaStatus qatUtilsLockDestroy(struct mtx *pLock);
383 
384 /**
385  * @ingroup QatUtils
386  *
387  * @brief Initializes a semaphore
388  *
389  * @param pSid - semaphore handle
390  * @param start_value - initial semaphore value
391  *
392  * Initializes a semaphore object
393  * Note: Semaphore initialization qatUtilsSemaphoreInit API must be called
394  * first before using any QAT Utils Semaphore APIs
395  *
396  * @li Reentrant: yes
397  * @li IRQ safe:  no
398  *
399  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
400  */
401 CpaStatus qatUtilsSemaphoreInit(struct sema **pSid, uint32_t start_value);
402 
403 /**
404  * @ingroup QatUtils
405  *
406  * @brief Destroys a semaphore object
407  *
408  * @param pSid - semaphore handle
409  *
410  * Destroys a semaphore object; the caller should ensure that no thread is
411  * blocked on this semaphore. If call made when thread blocked on semaphore the
412  * behaviour is unpredictable
413  *
414  * @li Reentrant: yes
415 ] * @li IRQ safe:  no
416  *
417  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
418  */
419 CpaStatus qatUtilsSemaphoreDestroy(struct sema **pSid);
420 
421 /**
422  * @ingroup QatUtils
423  *
424  * @brief Waits on (decrements) a semaphore
425  *
426  * @param pSid - semaphore handle
427  * @param timeout - timeout, in ms; QAT_UTILS_WAIT_FOREVER (-1) if the thread
428  * is to block indefinitely or QAT_UTILS_WAIT_NONE (0) if the thread is to
429  * return immediately even if the call fails
430  *
431  * Decrements a semaphore, blocking if the semaphore is
432  * unavailable (value is 0).
433  *
434  * @li Reentrant: yes
435  * @li IRQ safe:  no
436  *
437  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
438  */
439 CpaStatus qatUtilsSemaphoreWait(struct sema **pSid, int32_t timeout);
440 
441 /**
442  * @ingroup QatUtils
443  *
444  * @brief Non-blocking wait on semaphore
445  *
446  * @param semaphore - semaphore handle
447  *
448  * Decrements a semaphore, not blocking the calling thread if the semaphore
449  * is unavailable
450  *
451  * @li Reentrant: yes
452  * @li IRQ safe:  no
453  *
454  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
455  */
456 CpaStatus qatUtilsSemaphoreTryWait(struct sema **semaphore);
457 
458 /**
459  * @ingroup QatUtils
460  *
461  * @brief Posts to (increments) a semaphore
462  *
463  * @param pSid - semaphore handle
464  *
465  * Increments a semaphore object
466  *
467  * @li Reentrant: yes
468  * @li IRQ safe:  no
469  *
470  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
471  */
472 CpaStatus qatUtilsSemaphorePost(struct sema **pSid);
473 
474 /**
475  * @ingroup QatUtils
476  *
477  * @brief initializes a pMutex
478  *
479  * @param pMutex - pMutex handle
480  *
481  * Initializes a pMutex object
482  * @note Mutex initialization qatUtilsMutexInit API must be called
483  * first before using any QAT Utils Mutex APIs
484  *
485  * @li Reentrant: yes
486  * @li IRQ safe:  no
487  *
488  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
489  */
490 CpaStatus qatUtilsMutexInit(struct mtx **pMutex);
491 
492 /**
493  * @ingroup QatUtils
494  *
495  * @brief locks a pMutex
496  *
497  * @param pMutex - pMutex handle
498  * @param timeout - timeout in ms; QAT_UTILS_WAIT_FOREVER (-1) to wait forever
499  *                  or QAT_UTILS_WAIT_NONE to return immediately
500  *
501  * Locks a pMutex object
502  *
503  * @li Reentrant: yes
504  * @li IRQ safe:  no
505  *
506  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
507  */
508 CpaStatus qatUtilsMutexLock(struct mtx **pMutex, int32_t timeout);
509 
510 /**
511  * @ingroup QatUtils
512  *
513  * @brief Unlocks a pMutex
514  *
515  * @param pMutex - pMutex handle
516  *
517  * Unlocks a pMutex object
518  *
519  * @li Reentrant: yes
520  * @li IRQ safe:  no
521  *
522  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
523  */
524 CpaStatus qatUtilsMutexUnlock(struct mtx **pMutex);
525 
526 /**
527  * @ingroup QatUtils
528  *
529  * @brief Destroys a pMutex object
530  *
531  * @param pMutex - pMutex handle
532  *
533  * Destroys a pMutex object; the caller should ensure that no thread is
534  * blocked on this pMutex. If call made when thread blocked on pMutex the
535  * behaviour is unpredictable
536  *
537  * @li Reentrant: yes
538  * @li IRQ safe:  no
539  *
540  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
541  */
542 CpaStatus qatUtilsMutexDestroy(struct mtx **pMutex);
543 
544 /**
545  * @ingroup QatUtils
546  *
547  * @brief Non-blocking attempt to lock a pMutex
548  *
549  * @param pMutex - pMutex handle
550  *
551  * Attempts to lock a pMutex object, returning immediately with
552  * CPA_STATUS_SUCCESS if
553  * the lock was successful or CPA_STATUS_FAIL if the lock failed
554  *
555  * @li Reentrant: yes
556  * @li IRQ safe:  no
557  *
558  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
559  */
560 CpaStatus qatUtilsMutexTryLock(struct mtx **pMutex);
561 
562 /**
563  * @ingroup QatUtils
564  *
565  * @brief Yielding sleep for a number of milliseconds
566  *
567  * @param milliseconds - number of milliseconds to sleep
568  *
569  * The calling thread will sleep for the specified number of milliseconds.
570  * This sleep is yielding, hence other tasks will be scheduled by the
571  * operating system during the sleep period. Calling this function with an
572  * argument of 0 will place the thread at the end of the current scheduling
573  * loop.
574  *
575  * @li Reentrant: yes
576  * @li IRQ safe:  no
577  *
578  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
579  */
580 CpaStatus qatUtilsSleep(uint32_t milliseconds);
581 
582 /**
583  * @ingroup QatUtils
584  *
585  * @brief Yields execution of current thread
586  *
587  * Yields the execution of the current thread
588  *
589  * @li Reentrant: yes
590  * @li IRQ safe:  no
591  *
592  * @return - none
593  */
594 void qatUtilsYield(void);
595 
596 /**
597  * @ingroup QatUtils
598  *
599  * @brief  Calculate MD5 transform operation
600  *
601  * @param  in - pointer to data to be processed.
602  *         The buffer needs to be at least md5 block size long as defined in
603  *         rfc1321 (64 bytes)
604  *         out - output pointer for state data after single md5 transform
605  *         operation.
606  *         The buffer needs to be at least md5 state size long as defined in
607  *         rfc1321 (16 bytes)
608  *
609  * @li Reentrant: yes
610  * @li IRQ safe:  yes
611  *
612  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
613  *
614  */
615 CpaStatus qatUtilsHashMD5(uint8_t *in, uint8_t *out);
616 
617 /**
618  * @ingroup QatUtils
619  *
620  * @brief  Calculate MD5 transform operation
621  *
622  * @param  in - pointer to data to be processed.
623  *         The buffer needs to be at least md5 block size long as defined in
624  *         rfc1321 (64 bytes)
625  *         out - output pointer for state data after single md5 transform
626  *         operation.
627  *         The buffer needs to be at least md5 state size long as defined in
628  *         rfc1321 (16 bytes)
629  *         len - Length on the input to be processed.
630  *
631  * @li Reentrant: yes
632  * @li IRQ safe:  yes
633  *
634  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
635  *
636  */
637 CpaStatus qatUtilsHashMD5Full(uint8_t *in, uint8_t *out, uint32_t len);
638 
639 /**
640  * @ingroup QatUtils
641  *
642  * @brief  Calculate SHA1 transform operation
643  *
644  * @param  in - pointer to data to be processed.
645  *         The buffer needs to be at least sha1 block size long as defined in
646  *         rfc3174 (64 bytes)
647  *         out - output pointer for state data after single sha1 transform
648  *         operation.
649  *         The buffer needs to be at least sha1 state size long as defined in
650  *         rfc3174 (20 bytes)
651  *
652  * @li Reentrant: yes
653  * @li IRQ safe:  yes
654  *
655  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
656  *
657  */
658 CpaStatus qatUtilsHashSHA1(uint8_t *in, uint8_t *out);
659 
660 /**
661  * @ingroup QatUtils
662  *
663  * @brief  Calculate SHA1 transform operation
664  *
665  * @param  in - pointer to data to be processed.
666  *         The buffer needs to be at least sha1 block size long as defined in
667  *         rfc3174 (64 bytes)
668  *         out - output pointer for state data after single sha1 transform
669  *         operation.
670  *         The buffer needs to be at least sha1 state size long as defined in
671  *         rfc3174 (20 bytes)
672  *         len - Length on the input to be processed.
673  *
674  * @li Reentrant: yes
675  * @li IRQ safe:  yes
676  *
677  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
678  *
679  */
680 CpaStatus qatUtilsHashSHA1Full(uint8_t *in, uint8_t *out, uint32_t len);
681 
682 /**
683  * @ingroup QatUtils
684  *
685  * @brief  Calculate SHA224 transform operation
686  *
687  * @param  in - pointer to data to be processed.
688  *         The buffer needs to be at least sha224 block size long as defined in
689  *         rfc3874 and rfc4868 (64 bytes)
690  *         out - output pointer for state data after single sha224 transform
691  *         operation.
692  *         The buffer needs to be at least sha224 state size long as defined in
693  *         rfc3874 and rfc4868 (32 bytes)
694  * @li Reentrant: yes
695  * @li IRQ safe:  yes
696  *
697  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
698  *
699  */
700 CpaStatus qatUtilsHashSHA224(uint8_t *in, uint8_t *out);
701 
702 /**
703  * @ingroup QatUtils
704  *
705  * @brief  Calculate SHA256 transform operation
706  *
707  *
708  * @param  in - pointer to data to be processed.
709  *         The buffer needs to be at least sha256 block size long as defined in
710  *         rfc4868 (64 bytes)
711  *         out - output pointer for state data after single sha256 transform
712  *         operation.
713  *         The buffer needs to be at least sha256 state size long as defined in
714  *         rfc4868 (32 bytes)
715  * @li Reentrant: yes
716  * @li IRQ safe:  yes
717  *
718  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
719  *
720  */
721 CpaStatus qatUtilsHashSHA256(uint8_t *in, uint8_t *out);
722 
723 /**
724  * @ingroup QatUtils
725  *
726  * @brief  Calculate SHA256 transform operation
727  *
728  *
729  * @param  in - pointer to data to be processed.
730  *         The buffer needs to be at least sha256 block size long as defined in
731  *         rfc4868 (64 bytes)
732  *         out - output pointer for state data after single sha256 transform
733  *         operation.
734  *         The buffer needs to be at least sha256 state size long as defined in
735  *         rfc4868 (32 bytes)
736  *         len - Length on the input to be processed.
737  * @li Reentrant: yes
738  * @li IRQ safe:  yes
739  *
740  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
741  *
742  */
743 CpaStatus qatUtilsHashSHA256Full(uint8_t *in, uint8_t *out, uint32_t len);
744 
745 /**
746  * @ingroup QatUtils
747  *
748  * @brief  Calculate SHA384 transform operation
749  *
750  * @param  in - pointer to data to be processed.
751  *         The buffer needs to be at least sha384 block size long as defined in
752  *         rfc4868 (128 bytes)
753  *         out - output pointer for state data after single sha384 transform
754  *         operation.
755  *         The buffer needs to be at least sha384 state size long as defined in
756  *         rfc4868 (64 bytes)
757  * @li Reentrant: yes
758  * @li IRQ safe:  yes
759  *
760  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
761  *
762  */
763 CpaStatus qatUtilsHashSHA384(uint8_t *in, uint8_t *out);
764 
765 /**
766  * @ingroup QatUtils
767  *
768  * @brief  Calculate SHA384 transform operation
769  *
770  * @param  in - pointer to data to be processed.
771  *         The buffer needs to be at least sha384 block size long as defined in
772  *         rfc4868 (128 bytes)
773  *         out - output pointer for state data after single sha384 transform
774  *         operation.
775  *         The buffer needs to be at least sha384 state size long as defined in
776  *         rfc4868 (64 bytes)
777  *         len - Length on the input to be processed.
778  * @li Reentrant: yes
779  * @li IRQ safe:  yes
780  *
781  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
782  *
783  */
784 CpaStatus qatUtilsHashSHA384Full(uint8_t *in, uint8_t *out, uint32_t len);
785 
786 /**
787  * @ingroup QatUtils
788  *
789  * @brief  Calculate SHA512 transform operation
790  *
791  * @param  in - pointer to data to be processed.
792  *         The buffer needs to be at least sha512 block size long as defined in
793  *         rfc4868 (128 bytes)
794  *         out - output pointer for state data after single sha512 transform
795  *         operation.
796  *         The buffer needs to be at least sha512 state size long as defined in
797  *         rfc4868 (64 bytes)
798  * @li Reentrant: yes
799  * @li IRQ safe:  yes
800  *
801  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
802  *
803  */
804 CpaStatus qatUtilsHashSHA512(uint8_t *in, uint8_t *out);
805 
806 /**
807  * @ingroup QatUtils
808  *
809  * @brief  Calculate SHA512 transform operation
810  *
811  * @param  in - pointer to data to be processed.
812  *         The buffer needs to be at least sha512 block size long as defined in
813  *         rfc4868 (128 bytes)
814  *         out - output pointer for state data after single sha512 transform
815  *         operation.
816  *         The buffer needs to be at least sha512 state size long as defined in
817  *         rfc4868 (64 bytes)
818  *         len - Length on the input to be processed.
819  * @li Reentrant: yes
820  * @li IRQ safe:  yes
821  *
822  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
823  *
824  */
825 CpaStatus qatUtilsHashSHA512Full(uint8_t *in, uint8_t *out, uint32_t len);
826 
827 /**
828  * @ingroup QatUtils
829  *
830  * @brief  Single block AES encrypt
831  *
832  * @param  key - pointer to symmetric key.
833  *         keyLenInBytes - key length
834  *         in - pointer to data to encrypt
835  *         out - pointer to output buffer for encrypted text
836  *         The in and out buffers need to be at least AES block size long
837  *         as defined in rfc3686 (16 bytes)
838  *
839  * @li Reentrant: yes
840  * @li IRQ safe:  yes
841  *
842  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
843  *
844  */
845 CpaStatus qatUtilsAESEncrypt(uint8_t *key,
846 			     uint32_t keyLenInBytes,
847 			     uint8_t *in,
848 			     uint8_t *out);
849 
850 /**
851  * @ingroup QatUtils
852  *
853  * @brief  Converts AES forward key to reverse key
854  *
855  * @param  key - pointer to symmetric key.
856  *         keyLenInBytes - key length
857  *         out - pointer to output buffer for reversed key
858  *         The in and out buffers need to be at least AES block size long
859  *         as defined in rfc3686 (16 bytes)
860  *
861  * @li Reentrant: yes
862  * @li IRQ safe:  yes
863  *
864  * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL
865  *
866  */
867 CpaStatus qatUtilsAESKeyExpansionForward(uint8_t *key,
868 					 uint32_t keyLenInBytes,
869 					 uint32_t *out);
870 #endif
871