1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 
5 /**
6  ***************************************************************************
7  * @file lac_sal_types_crypto.h
8  *
9  * @ingroup SalCtrl
10  *
11  * Generic crypto instance type definition
12  *
13  ***************************************************************************/
14 
15 #ifndef LAC_SAL_TYPES_CRYPTO_H_
16 #define LAC_SAL_TYPES_CRYPTO_H_
17 
18 #include "lac_sym_qat_hash_defs_lookup.h"
19 #include "lac_sym_key.h"
20 #include "cpa_cy_sym_dp.h"
21 
22 #include "icp_adf_debug.h"
23 #include "lac_sal_types.h"
24 #include "icp_adf_transport.h"
25 #include "lac_mem_pools.h"
26 
27 #define LAC_PKE_FLOW_ID_TAG 0xFFFFFFFC
28 #define LAC_PKE_ACCEL_ID_BIT_POS 1
29 #define LAC_PKE_SLICE_ID_BIT_POS 0
30 
31 /**
32  *****************************************************************************
33  * @ingroup SalCtrl
34  *      Crypto specific Service Container
35  *
36  * @description
37  *      Contains information required per crypto service instance.
38  *
39  *****************************************************************************/
40 typedef struct sal_crypto_service_s {
41 	sal_service_t generic_service_info;
42 	/**< An instance of the Generic Service Container */
43 
44 	lac_memory_pool_id_t lac_sym_cookie_pool;
45 	/**< Memory pool ID used for symmetric operations */
46 	lac_memory_pool_id_t lac_ec_pool;
47 	/**< Memory pool ID used for asymmetric operations */
48 	lac_memory_pool_id_t lac_prime_pool;
49 	/**< Memory pool ID used for asymmetric operations */
50 	lac_memory_pool_id_t lac_pke_req_pool;
51 	/**< Memory pool ID used for asymmetric operations */
52 	lac_memory_pool_id_t lac_pke_align_pool;
53 	/**< Memory pool ID used for asymmetric operations */
54 
55 	QatUtilsAtomic *pLacSymStatsArr;
56 	/**< pointer to an array of atomic stats for symmetric */
57 
58 	QatUtilsAtomic *pLacKeyStats;
59 	/**< pointer to an array of atomic stats for key */
60 
61 	QatUtilsAtomic *pLacDhStatsArr;
62 	/**< pointer to an array of atomic stats for DH */
63 
64 	QatUtilsAtomic *pLacDsaStatsArr;
65 	/**< pointer to an array of atomic stats for Dsa */
66 
67 	QatUtilsAtomic *pLacRsaStatsArr;
68 	/**< pointer to an array of atomic stats for Rsa */
69 
70 	QatUtilsAtomic *pLacEcStatsArr;
71 	/**< pointer to an array of atomic stats for Ecc */
72 
73 	QatUtilsAtomic *pLacEcdhStatsArr;
74 	/**< pointer to an array of atomic stats for Ecc DH */
75 
76 	QatUtilsAtomic *pLacEcdsaStatsArr;
77 	/**< pointer to an array of atomic stats for Ecc DSA */
78 
79 	QatUtilsAtomic *pLacPrimeStatsArr;
80 	/**< pointer to an array of atomic stats for prime */
81 
82 	QatUtilsAtomic *pLacLnStatsArr;
83 	/**< pointer to an array of atomic stats for large number */
84 
85 	QatUtilsAtomic *pLacDrbgStatsArr;
86 	/**< pointer to an array of atomic stats for DRBG */
87 
88 	Cpa32U pkeFlowId;
89 	/**< Flow ID for all pke requests from this instance - identifies
90 	 accelerator
91 	 and execution engine to use */
92 
93 	icp_comms_trans_handle trans_handle_sym_tx;
94 	icp_comms_trans_handle trans_handle_sym_rx;
95 
96 	icp_comms_trans_handle trans_handle_asym_tx;
97 	icp_comms_trans_handle trans_handle_asym_rx;
98 
99 	icp_comms_trans_handle trans_handle_nrbg_tx;
100 	icp_comms_trans_handle trans_handle_nrbg_rx;
101 
102 	Cpa32U maxNumSymReqBatch;
103 	/**< Maximum number of requests that can be placed on the sym tx ring
104 	      for any one batch request (DP api) */
105 
106 	Cpa16U acceleratorNum;
107 	Cpa16U bankNum;
108 	Cpa16U pkgID;
109 	Cpa8U isPolled;
110 	Cpa8U executionEngine;
111 	Cpa32U coreAffinity;
112 	Cpa32U nodeAffinity;
113 	/**< Config Info */
114 
115 	CpaCySymDpCbFunc pSymDpCb;
116 	/**< Sym DP Callback */
117 
118 	lac_sym_qat_hash_defs_t **pLacHashLookupDefs;
119 	/**< table of pointers to standard defined information for all hash
120 	     algorithms. We support an extra hash algo that is not exported by
121 	     cy api which is why we need the extra +1 */
122 	Cpa8U **ppHmacContentDesc;
123 	/**< table of pointers to CD for Hmac precomputes - used at session init
124 	 */
125 
126 	Cpa8U *pSslLabel;
127 	/**< pointer to memory holding the standard SSL label ABBCCC.. */
128 
129 	lac_sym_key_tls_labels_t *pTlsLabel;
130 	/**< pointer to memory holding the 4 standard TLS labels */
131 
132 	QatUtilsAtomic drbgErrorState;
133 	/**< DRBG related variables */
134 
135 	lac_sym_key_tls_hkdf_sub_labels_t *pTlsHKDFSubLabel;
136 	/**< pointer to memory holding the 4 HKDFLabels sublabels */
137 
138 	debug_file_info_t *debug_file;
139 /**< Statistics handler */
140 } sal_crypto_service_t;
141 
142 /*************************************************************************
143  * @ingroup cpaCyCommon
144  * @description
145  *  This function returns a valid asym/sym/crypto instance handle for the
146  *  system if it exists. When requesting an instance handle of type sym or
147  *  asym, if either is not found then a crypto instance handle is returned
148  *  if found, since a crypto handle supports both sym and asym services.
149  *  Similarly when requesting a crypto instance handle, if it is not found
150  *  then an asym or sym crypto instance handle is returned.
151  *
152  *  @performance
153  *    To avoid calling this function the user of the QA api should not use
154  *    instanceHandle = CPA_INSTANCE_HANDLE_SINGLE.
155  *
156  * @context
157  *    This function is called whenever instanceHandle =
158  *CPA_INSTANCE_HANDLE_SINGLE
159  *    at the QA Cy api.
160  *
161  * @assumptions
162  *      None
163  * @sideEffects
164  *      None
165  * @reentrant
166  *      No
167  * @threadSafe
168  *      Yes
169  *
170  * @param[in]  svc_type        Type of crypto service requested.
171  *
172  * @retval   Pointer to first crypto instance handle or NULL if no crypto
173  *           instances in the system.
174  *
175  *************************************************************************/
176 
177 CpaInstanceHandle Lac_GetFirstHandle(sal_service_type_t svc_type);
178 
179 #endif /*LAC_SAL_TYPES_CRYPTO_H_*/
180