1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 /**
5  *****************************************************************************
6  * @file sal_qat_cmn_msg.h
7  *
8  * @defgroup SalQatCmnMessage
9  *
10  * @ingroup SalQatCmnMessage
11  *
12  * Interfaces for populating the common QAT structures for a lookaside
13  * operation.
14  *
15  *****************************************************************************/
16 
17 /*
18 ******************************************************************************
19 * Include public/global header files
20 ******************************************************************************
21 */
22 #include "cpa.h"
23 
24 /*
25 *******************************************************************************
26 * Include private header files
27 *******************************************************************************
28 */
29 #include "qat_utils.h"
30 #include "icp_accel_devices.h"
31 #include "icp_qat_fw_la.h"
32 #include "icp_qat_hw.h"
33 #include "lac_common.h"
34 #include "lac_mem.h"
35 #include "sal_qat_cmn_msg.h"
36 
37 /********************************************************************
38  * @ingroup SalQatMsg_CmnHdrWrite
39  *
40  * @description
41  *      This function fills in all fields in the icp_qat_fw_comn_req_hdr_t
42  *      section of the Request Msg. Build LW0 + LW1 -
43  *      service part of the request
44  *
45  * @param[in]   pMsg            Pointer to 128B Request Msg buffer
46  * @param[in]   serviceType     type of service request
47  * @param[in]   serviceCmdId    id for the type of service request
48  * @param[in]   cmnFlags        common request flags
49  * @param[in]   serviceCmdFlags service command flahgs
50  *
51  * @return
52  *      None
53  *
54  *****************************************/
55 void
56 SalQatMsg_CmnHdrWrite(icp_qat_fw_comn_req_t *pMsg,
57 		      icp_qat_fw_comn_request_id_t serviceType,
58 		      uint8_t serviceCmdId,
59 		      icp_qat_fw_comn_flags cmnFlags,
60 		      icp_qat_fw_serv_specif_flags serviceCmdFlags)
61 {
62 	icp_qat_fw_comn_req_hdr_t *pHeader = &(pMsg->comn_hdr);
63 
64 	/* LW0 */
65 	pHeader->hdr_flags =
66 	    ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET);
67 	pHeader->service_type = (uint8_t)serviceType;
68 	pHeader->service_cmd_id = serviceCmdId;
69 	pHeader->resrvd1 = 0;
70 	/* LW1 */
71 	pHeader->comn_req_flags = cmnFlags;
72 	pHeader->serv_specif_flags = serviceCmdFlags;
73 }
74 
75 /********************************************************************
76  * @ingroup SalQatCmnMessage
77  *
78  * @description
79  *      This function fills in all fields in the icp_qat_fw_comn_req_mid_t
80  *      section of the Request Msg and the corresponding SGL/Flat flag
81  *      in the Hdr.
82  *
83  * @param[in]   pReq            Pointer to 128B Request Msg buffer
84  * @param[in]   pOpaqueData     Pointer to opaque data used by callback
85  * @param[in]   bufferFormat    src and dst Buffers are either SGL or Flat
86  *                              format
87  * @param[in]   pSrcBuffer      Address of source buffer
88  * @param[in]   pDstBuffer      Address of destination buffer
89  * @param[in]   pSrcLength      Length of source buffer
90  * @param[in]   pDstLength      Length of destination buffer
91  *
92 
93  * @assumptions
94  *      All fields in mid section are zero before fn is called
95 
96  * @return
97  *      None
98  *
99  *****************************************/
100 void inline SalQatMsg_CmnMidWrite(icp_qat_fw_la_bulk_req_t *pReq,
101 				  const void *pOpaqueData,
102 				  Cpa8U bufferFormat,
103 				  Cpa64U srcBuffer,
104 				  Cpa64U dstBuffer,
105 				  Cpa32U srcLength,
106 				  Cpa32U dstLength)
107 {
108 	icp_qat_fw_comn_req_mid_t *pMid = &(pReq->comn_mid);
109 
110 	LAC_MEM_SHARED_WRITE_FROM_PTR(pMid->opaque_data, pOpaqueData);
111 	pMid->src_data_addr = srcBuffer;
112 
113 	/* In place */
114 	if (0 == dstBuffer) {
115 		pMid->dest_data_addr = srcBuffer;
116 	}
117 	/* Out of place */
118 	else {
119 		pMid->dest_data_addr = dstBuffer;
120 	}
121 
122 	if (bufferFormat == QAT_COMN_PTR_TYPE_SGL) {
123 		/* Using ScatterGatherLists so set flag in header */
124 		ICP_QAT_FW_COMN_PTR_TYPE_SET(pReq->comn_hdr.comn_req_flags,
125 					     QAT_COMN_PTR_TYPE_SGL);
126 
127 		/* Assumption: No need to set src and dest length in this case
128 		 * as not
129 		 * used */
130 
131 	} else {
132 		/* Using Flat buffers so set flag in header */
133 		ICP_QAT_FW_COMN_PTR_TYPE_SET(pReq->comn_hdr.comn_req_flags,
134 					     QAT_COMN_PTR_TYPE_FLAT);
135 
136 		pMid->src_length = srcLength;
137 		pMid->dst_length = dstLength;
138 	}
139 }
140 
141 /********************************************************************
142  * @ingroup SalQatMsg_ContentDescHdrWrite
143  *
144  * @description
145  *      This function fills in all fields in the
146  *      icp_qat_fw_comn_req_hdr_cd_pars_t section of the Request Msg.
147  *
148  * @param[in]   pMsg             Pointer to 128B Request Msg buffer.
149  * @param[in]   pContentDescInfo content descripter info.
150  *
151  * @return
152  *      none
153  *
154  *****************************************/
155 void
156 SalQatMsg_ContentDescHdrWrite(
157     icp_qat_fw_comn_req_t *pMsg,
158     const sal_qat_content_desc_info_t *pContentDescInfo)
159 {
160 	icp_qat_fw_comn_req_hdr_cd_pars_t *pCd_pars = &(pMsg->cd_pars);
161 
162 	pCd_pars->s.content_desc_addr =
163 	    pContentDescInfo->hardwareSetupBlockPhys;
164 	pCd_pars->s.content_desc_params_sz = pContentDescInfo->hwBlkSzQuadWords;
165 	pCd_pars->s.content_desc_resrvd1 = 0;
166 	pCd_pars->s.content_desc_hdr_resrvd2 = 0;
167 	pCd_pars->s.content_desc_resrvd3 = 0;
168 }
169 
170 /********************************************************************
171  * @ingroup SalQatMsg_CtrlBlkSetToReserved
172  *
173  * @description
174  *      This function sets the whole control block to a reserved state.
175  *
176  * @param[in]   _pMsg            Pointer to 128B Request Msg buffer.
177  *
178  * @return
179  *      none
180  *
181  *****************************************/
182 void
183 SalQatMsg_CtrlBlkSetToReserved(icp_qat_fw_comn_req_t *pMsg)
184 {
185 
186 	icp_qat_fw_comn_req_cd_ctrl_t *pCd_ctrl = &(pMsg->cd_ctrl);
187 
188 	memset(pCd_ctrl, 0, sizeof(icp_qat_fw_comn_req_cd_ctrl_t));
189 }
190 
191 /********************************************************************
192  * @ingroup SalQatMsg_transPutMsg
193  *
194  * @description
195  *
196  *
197  * @param[in]   trans_handle
198  * @param[in]   pqat_msg
199  * @param[in]   size_in_lws
200  * @param[in]   service
201  *
202  * @return
203  *      CpaStatus
204  *
205  *****************************************/
206 CpaStatus
207 SalQatMsg_transPutMsg(icp_comms_trans_handle trans_handle,
208 		      void *pqat_msg,
209 		      Cpa32U size_in_lws,
210 		      Cpa8U service)
211 {
212 	return icp_adf_transPutMsg(trans_handle, pqat_msg, size_in_lws);
213 }
214 
215 void
216 SalQatMsg_updateQueueTail(icp_comms_trans_handle trans_handle)
217 {
218 	icp_adf_updateQueueTail(trans_handle);
219 }
220