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