1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 
5 /**
6  *****************************************************************************
7  * @file lac_sym_qat.h
8  *
9  * @defgroup LacSymQat  Symmetric QAT
10  *
11  * @ingroup LacSym
12  *
13  * Interfaces for populating the qat structures for a symmetric operation
14  *
15  * @lld_start
16  *
17  * @lld_overview
18  * This file documents the interfaces for populating the qat structures
19  * that are common for all symmetric operations.
20  *
21  * @lld_dependencies
22  * - \ref LacSymQatHash "Hash QAT Comms" Sym Qat commons for Hash
23  * - \ref LacSymQat_Cipher "Cipher QAT Comms" Sym Qat commons for Cipher
24  * - OSAL: logging
25  * - \ref LacMem "Memory" - Inline memory functions
26  *
27  * @lld_initialisation
28  * This component is initialied during the LAC initialisation sequence. It
29  * is called by the Symmetric Initialisation function.
30  *
31  * @lld_module_algorithms
32  *
33  * @lld_process_context
34  * Refer to \ref LacHash "Hash" and \ref LacCipher "Cipher" for sequence
35  * diagrams to see their interactions with this code.
36  *
37  *
38  * @lld_end
39  *
40  *****************************************************************************/
41 
42 /*****************************************************************************/
43 
44 #ifndef LAC_SYM_QAT_H
45 #define LAC_SYM_QAT_H
46 
47 /*
48 ******************************************************************************
49 * Include public/global header files
50 ******************************************************************************
51 */
52 
53 #include "cpa.h"
54 #include "cpa_cy_sym.h"
55 #include "icp_accel_devices.h"
56 #include "icp_qat_fw_la.h"
57 #include "icp_qat_hw.h"
58 #include "lac_session.h"
59 #include "sal_qat_cmn_msg.h"
60 #include "lac_common.h"
61 
62 /*
63 *******************************************************************************
64 * Include private header files
65 *******************************************************************************
66 */
67 
68 #define LAC_SYM_DEFAULT_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_SGL
69 #define LAC_SYM_DP_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_FLAT
70 #define LAC_SYM_KEY_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_FLAT
71 /**< @ingroup LacSymQat
72  * LAC SYM Source & Destination buffer type (FLAT/SGL) */
73 
74 #define LAC_QAT_SYM_REQ_SZ_LW 32
75 #define SYM_TX_MSG_SIZE (LAC_QAT_SYM_REQ_SZ_LW * LAC_LONG_WORD_IN_BYTES)
76 #define NRBG_TX_MSG_SIZE (LAC_QAT_SYM_REQ_SZ_LW * LAC_LONG_WORD_IN_BYTES)
77 
78 #define LAC_QAT_SYM_RESP_SZ_LW 8
79 #define SYM_RX_MSG_SIZE (LAC_QAT_SYM_RESP_SZ_LW * LAC_LONG_WORD_IN_BYTES)
80 #define NRBG_RX_MSG_SIZE (LAC_QAT_SYM_RESP_SZ_LW * LAC_LONG_WORD_IN_BYTES)
81 
82 /**
83  *******************************************************************************
84  * @ingroup LacSymQat
85  *      Symmetric crypto response handler
86  *
87  * @description
88  *      This function handles the symmetric crypto response
89  *
90  * @param[in] trans_handle          transport handle (if ICP_QAT_DBG set)
91  * @param[in] instanceHandle        void* pRespMsg
92  *
93  *
94  *****************************************************************************/
95 void LacSymQat_SymRespHandler(void *pRespMsg);
96 
97 /**
98  *******************************************************************************
99  * @ingroup LacSymQat
100  *      Initialise the Symmetric QAT code
101  *
102  * @description
103  *      This function initialises the symmetric QAT code
104  *
105  * @param[in] device                Pointer to the acceleration device
106  *                                  structure
107  * @param[in] instanceHandle        Instance handle
108  * @param[in] numSymRequests        Number of concurrent requests a pair
109  *                                  (tx and rx) need to support
110  *
111  * @return CPA_STATUS_SUCCESS       Operation successful
112  * @return CPA_STATUS_FAIL          Initialisation Failed
113  *
114  *****************************************************************************/
115 CpaStatus LacSymQat_Init(CpaInstanceHandle instanceHandle);
116 
117 /**
118  *******************************************************************************
119  * @ingroup LacSymQat
120  *      Register a response handler function for a symmetric command ID
121  *
122  * @description
123  *      This function registers a response handler function for a symmetric
124  *      operation.
125  *
126  *      Note: This operation should only be performed once by the init function
127  *      of a component. There is no corresponding deregister function, but
128  *      registering a NULL function pointer will have the same effect. There
129  *      MUST not be any requests in flight when calling this function.
130  *
131  * @param[in] lacCmdId          Command Id of operation
132  * @param[in] pCbHandler        callback handler function
133  *
134  * @return None
135  *
136  *****************************************************************************/
137 void LacSymQat_RespHandlerRegister(icp_qat_fw_la_cmd_id_t lacCmdId,
138 				   sal_qat_resp_handler_func_t pCbHandler);
139 
140 /**
141  ******************************************************************************
142  * @ingroup LacSymQat
143  *      get the QAT packet type
144  *
145  * @description
146  *      This function returns the QAT packet type for a LAC packet type. The
147  *      LAC packet type does not indicate a first partial. therefore for a
148  *      partial request, the previous packet type needs to be looked at to
149  *      figure out if the current partial request is a first partial.
150  *
151  *
152  * @param[in] packetType          LAC Packet type
153  * @param[in] packetState         LAC Previous Packet state
154  * @param[out] pQatPacketType     Packet type using the QAT macros
155  *
156  * @return none
157  *
158  *****************************************************************************/
159 void LacSymQat_packetTypeGet(CpaCySymPacketType packetType,
160 			     CpaCySymPacketType packetState,
161 			     Cpa32U *pQatPacketType);
162 
163 /**
164  ******************************************************************************
165  * @ingroup LacSymQat
166  *      Populate the command flags based on the packet type
167  *
168  * @description
169  *      This function populates the following flags in the Symmetric Crypto
170  *      service_specif_flags field of the common header of the request:
171  *          - LA_PARTIAL
172  *          - UPDATE_STATE
173  *          - RET_AUTH_RES
174  *          - CMP_AUTH_RES
175  *          based on looking at the input params listed below.
176  *
177  * @param[in] qatPacketType          Packet type
178  * @param[in] cmdId                  Command Id
179  * @param[in] cipherAlgorithm        Cipher Algorithm
180  * @param[out] pLaCommandFlags       Command Flags
181  *
182  * @return none
183  *
184  *****************************************************************************/
185 void LacSymQat_LaPacketCommandFlagSet(Cpa32U qatPacketType,
186 				      icp_qat_fw_la_cmd_id_t laCmdId,
187 				      CpaCySymCipherAlgorithm cipherAlgorithm,
188 				      Cpa16U *pLaCommandFlags,
189 				      Cpa32U ivLenInBytes);
190 
191 /**
192  ******************************************************************************
193  * @ingroup LacSymQat
194  *
195  *
196  * @description
197  *             defaults the common request service specific flags
198  *
199  * @param[in] laCmdFlags          Common request service specific flags
200  * @param[in] symOp               Type of operation performed e.g hash or cipher
201  *
202  * @return none
203  *
204  *****************************************************************************/
205 
206 void LacSymQat_LaSetDefaultFlags(icp_qat_fw_serv_specif_flags *laCmdFlags,
207 				 CpaCySymOp symOp);
208 
209 /**
210  ******************************************************************************
211  * @ingroup LacSymQat
212  *
213  *
214  * @description
215  *      this function defines whether the shared constants table can be used
216  *      for a particular cipher and hash algorithm
217  *
218  * @param[in]   ptr to session
219 
220  * @param[in]   ptr to return offset into table for cipher config
221 
222  * @param[in]   ptr to return offset into table for hash config
223  *
224  * @return CPA_TRUE if Constants table is available for use, CPA_FALSE if it's
225  *         not.
226  *
227  *****************************************************************************/
228 CpaBoolean LacSymQat_UseSymConstantsTable(lac_session_desc_t *pSession,
229 					  Cpa8U *cipherOffset,
230 					  Cpa8U *hashOffset);
231 
232 /**
233  ******************************************************************************
234  * @ingroup LacSymQat
235  *
236  *
237  * @description
238  *      this function calculates whether the optimized content descriptor can
239  *      be used for a particular chained cipher and hash algorithm
240  *
241  * @param[in]   ptr to session
242  *
243  * @return CPA_TRUE if optimized CD can be used, CPA_FALSE if it's not.
244  *
245  *****************************************************************************/
246 CpaBoolean LacSymQat_UseOptimisedContentDesc(lac_session_desc_t *pSession);
247 
248 #endif /* LAC_SYM_QAT_H */
249