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