xref: /freebsd/sys/dev/qat/include/qat_ocf_utils.h (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 #ifndef _QAT_OCF_UTILS_H_
5 #define _QAT_OCF_UTILS_H_
6 /* System headers */
7 #include <sys/types.h>
8 #include <sys/mbuf.h>
9 #include <machine/bus_dma.h>
10 
11 /* Cryptodev headers */
12 #include <opencrypto/cryptodev.h>
13 #include <crypto/sha2/sha512.h>
14 
15 /* QAT specific headers */
16 #include "qat_ocf_mem_pool.h"
17 #include "cpa.h"
18 #include "cpa_cy_sym_dp.h"
19 
20 static inline CpaBoolean
21 is_gmac_exception(const struct crypto_session_params *csp)
22 {
23 	if (CSP_MODE_DIGEST == csp->csp_mode)
24 		if (CRYPTO_AES_NIST_GMAC == csp->csp_auth_alg)
25 			return CPA_TRUE;
26 
27 	return CPA_FALSE;
28 }
29 
30 static inline CpaBoolean
31 is_sep_aad_supported(const struct crypto_session_params *csp)
32 {
33 	if (CPA_TRUE == is_gmac_exception(csp))
34 		return CPA_FALSE;
35 
36 	if (CSP_MODE_AEAD == csp->csp_mode)
37 		if (CRYPTO_AES_NIST_GCM_16 == csp->csp_cipher_alg ||
38 		    CRYPTO_AES_NIST_GMAC == csp->csp_cipher_alg)
39 			return CPA_TRUE;
40 
41 	return CPA_FALSE;
42 }
43 
44 static inline CpaBoolean
45 is_use_sep_digest(const struct crypto_session_params *csp)
46 {
47 	/* Use separated digest for all digest/hash operations,
48 	 * including GMAC. ETA and AEAD use separated digest
49 	 * due to FW limitation to specify offset to digest
50 	 * appended to pay-load buffer. */
51 	if (CSP_MODE_DIGEST == csp->csp_mode || CSP_MODE_ETA == csp->csp_mode ||
52 	    CSP_MODE_AEAD == csp->csp_mode)
53 		return CPA_TRUE;
54 
55 	return CPA_FALSE;
56 }
57 
58 int qat_ocf_handle_session_update(struct qat_ocf_dsession *ocf_dsession,
59 				  struct cryptop *crp);
60 
61 CpaStatus qat_ocf_wait_for_session(CpaCySymSessionCtx sessionCtx,
62 				   Cpa32U timeoutMS);
63 
64 #endif /* _QAT_OCF_UTILS_H_ */
65