common/qat: add headers for asymmetric crypto
[dpdk.git] / drivers / common / qat / qat_adf / icp_qat_fw_pke.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 /**
6  * @file icp_qat_fw_pke.h
7  * @defgroup icp_qat_fw_pke ICP QAT FW PKE Processing Definitions
8  * @ingroup icp_qat_fw
9  * Revision: 0.1
10  * @brief
11  *      This file documents the external interfaces that the QAT FW running
12  *      on the QAT Acceleration Engine provides to clients wanting to
13  *      accelerate crypto assymetric applications
14  */
15
16 #ifndef _ICP_QAT_FW_PKE_H_
17 #define _ICP_QAT_FW_PKE_H_
18
19 /*
20  * Keep all dpdk-specific changes in this section
21  */
22
23 #include <stdint.h>
24
25 typedef uint8_t u8;
26 typedef uint16_t u16;
27 typedef uint32_t u32;
28 typedef uint64_t u64;
29
30 /* End of DPDK-specific section
31  * Don't modify below this.
32  */
33
34 /*
35  ****************************************************************************
36  * Include local header files
37  ****************************************************************************
38  */
39 #include "icp_qat_fw.h"
40
41 /**
42  *****************************************************************************
43  *
44  * @ingroup icp_qat_fw_pke
45  *
46  * @brief
47  *      PKE response status field structure contained
48  *      within LW1, comprising the common error codes and
49  *      the response flags.
50  *
51  *****************************************************************************/
52 struct icp_qat_fw_pke_resp_status {
53         u8 comn_err_code;
54         /**< 8 bit common error code */
55
56         u8 pke_resp_flags;
57         /**< 8-bit PKE response flags  */
58 };
59
60 /**
61  *****************************************************************************
62  * @ingroup icp_qat_fw_pke
63  *      Definition of the QAT FW PKE request header pars field.
64  *
65  * @description
66  *      PKE request message header pars structure
67  *
68  *****************************************************************************/
69 struct icp_qat_fw_req_hdr_pke_cd_pars {
70         /**< LWs 2-3 */
71         u64 content_desc_addr;
72         /**< Content descriptor pointer */
73
74         /**< LW 4 */
75         u32 content_desc_resrvd;
76         /**< Content descriptor reserved field */
77
78         /**< LW 5 */
79         u32 func_id;
80         /**< MMP functionality Id */
81 };
82
83 /**
84  *****************************************************************************
85  * @ingroup icp_qat_fw_pke
86  *      Definition of the QAT FW PKE request header mid section.
87  *
88  * @description
89  *      PKE request message header middle structure
90  *
91  *****************************************************************************/
92 struct icp_qat_fw_req_pke_mid {
93         /**< LWs 6-11 */
94         u64 opaque;
95         /**< Opaque data passed unmodified from the request to response messages
96          * by firmware (fw)
97          */
98
99         u64 src_data_addr;
100         /**< Generic definition of the source data supplied to the QAT AE. The
101          * common flags are used to further describe the attributes of this
102          * field
103          */
104
105         u64 dest_data_addr;
106         /**< Generic definition of the destination data supplied to the QAT AE.
107          * The common flags are used to further describe the attributes of this
108          * field
109          */
110 };
111
112 /**
113  *****************************************************************************
114  * @ingroup icp_qat_fw_pke
115  *      Definition of the QAT FW PKE request header.
116  *
117  * @description
118  *      PKE request message header structure
119  *
120  *****************************************************************************/
121 struct icp_qat_fw_req_pke_hdr {
122         /**< LW0 */
123         u8 resrvd1;
124         /**< reserved field */
125
126         u8 resrvd2;
127         /**< reserved field */
128
129         u8 service_type;
130         /**< Service type */
131
132         u8 hdr_flags;
133         /**< This represents a flags field for the Service Request.
134          * The most significant bit is the 'valid' flag and the only
135          * one used. All remaining bit positions are unused and
136          * are therefore reserved and need to be set to 0.
137          */
138
139         /**< LW1 */
140         u16 comn_req_flags;
141         /**< Common Request flags must indicate flat buffer
142          * Common Request flags - PKE slice flags no longer used - slice
143          * allocated to a threadstrand.
144          */
145
146         u8 kpt_mask;
147         /** < KPT input parameters array mask, indicate which node in array is
148          *encrypted
149          */
150
151         u8 kpt_rn_mask;
152         /**< KPT random node(RN) mask - indicate which node is RN that QAT
153          * should generate itself.
154          */
155
156         /**< LWs 2-5 */
157         struct icp_qat_fw_req_hdr_pke_cd_pars cd_pars;
158         /**< PKE request message header pars structure */
159 };
160
161 /**
162  ***************************************************************************
163  *
164  * @ingroup icp_qat_fw_pke
165  *
166  * @brief
167  *      PKE request message structure (64 bytes)
168  *
169  *****************************************************************************/
170 struct icp_qat_fw_pke_request {
171         /**< LWs 0-5 */
172         struct icp_qat_fw_req_pke_hdr pke_hdr;
173         /**< Request header for PKE - CD Header/Param size  must be zero */
174
175         /**< LWs 6-11 */
176         struct icp_qat_fw_req_pke_mid pke_mid;
177         /**< Request middle section for PKE */
178
179         /**< LW 12 */
180         u8 output_param_count;
181         /**< Number of output large integers for request */
182
183         u8 input_param_count;
184         /**< Number of input large integers for request */
185
186         u16 resrvd1;
187         /** Reserved **/
188
189         /**< LW 13 */
190         u32 resrvd2;
191         /**< Reserved */
192
193         /**< LWs 14-15 */
194         u64 next_req_adr;
195         /** < PKE - next request address */
196 };
197
198 /**
199  *****************************************************************************
200  *
201  * @ingroup icp_qat_fw_pke
202  *
203  * @brief
204  *      PKE response message header structure
205  *
206  *****************************************************************************/
207 struct icp_qat_fw_resp_pke_hdr {
208         /**< LW0 */
209         u8 resrvd1;
210         /**< Reserved */
211
212         u8 resrvd2;
213         /**< Reserved */
214
215         u8 response_type;
216         /**< Response type - copied from the request to the response message */
217
218         u8 hdr_flags;
219         /**< This represents a flags field for the Response.
220          * The most significant bit is the 'valid' flag and the only
221          * one used. All remaining bit positions are unused and
222          * are therefore reserved
223          */
224
225         /**< LW1 */
226         struct icp_qat_fw_pke_resp_status resp_status;
227
228         u16 resrvd4;
229         /**< Set to zero. */
230 };
231
232 /**
233  *****************************************************************************
234  *
235  * @ingroup icp_qat_fw_pke
236  *
237  * @brief
238  *      PKE response message structure (32 bytes)
239  *
240  *****************************************************************************/
241 struct icp_qat_fw_pke_resp {
242         /**< LWs 0-1 */
243         struct icp_qat_fw_resp_pke_hdr pke_resp_hdr;
244         /**< Response header for PKE */
245
246         /**< LWs 2-3 */
247         u64 opaque;
248         /**< Opaque data passed from the request to the response message */
249
250         /**< LWs 4-5 */
251         u64 src_data_addr;
252         /**< Generic definition of the source data supplied to the QAT AE. The
253          * common flags are used to further describe the attributes of this
254          * field
255          */
256
257         /**< LWs 6-7 */
258         u64 dest_data_addr;
259         /**< Generic definition of the destination data supplied to the QAT AE.
260          * The common flags are used to further describe the attributes of this
261          * field
262          */
263 };
264
265 /* ========================================================================= */
266 /* MACRO DEFINITIONS                                                         */
267 /* ========================================================================= */
268
269 /**< @ingroup icp_qat_fw_pke
270  * Macro defining the bit position and mask of the 'valid' flag, within the
271  * hdr_flags field of LW0 (service request and response) of the PKE request
272  */
273 #define ICP_QAT_FW_PKE_HDR_VALID_FLAG_BITPOS 7
274 #define ICP_QAT_FW_PKE_HDR_VALID_FLAG_MASK 0x1
275
276 /**< @ingroup icp_qat_fw_pke
277  * Macro defining the bit position and mask of the PKE status flag, within the
278  * status field LW1 of a PKE response message
279  */
280 #define QAT_COMN_RESP_PKE_STATUS_BITPOS 6
281 /**< @ingroup icp_qat_fw_pke
282  * Starting bit position indicating the PKE status flag within the PKE response
283  * pke_resp_flags byte.
284  */
285
286 #define QAT_COMN_RESP_PKE_STATUS_MASK 0x1
287 /**< @ingroup icp_qat_fw_pke
288  * One bit mask used to determine PKE status mask
289  */
290
291 /*
292  *  < @ingroup icp_qat_fw_pke
293  *  *** PKE Response Status Field Definition ***
294  *  The PKE response follows the CPM 1.5 message format. The status field is
295  *  16 bits wide, where the status flags are contained within the most
296  *  significant byte of the icp_qat_fw_pke_resp_status structure.
297  *  The lower 8 bits of this word now contain the common error codes,
298  *  which are defined in the common header file(*).
299  */
300 /*  +=====+-----+----+-----+-----+-----+-----+-----+-----+---------------------+
301  *  | Bit |  15 | 14 | 13  | 12  | 11  | 10  |  9  |  8  |    [7....0]         |
302  *  +=====+-----+----+-----+-----+-----+-----+-----+-----+---------------------+
303  *  |Flags|Rsrvd|Pke |Rsrvd|Rsrvd|Rsrvd|Rsrvd|Rsrvd|Rsrvd|Common error codes(*)|
304  *  +=====+-----+----+-----+-----+-----+-----+-----+-----+---------------------+
305  */
306
307 /**
308  ******************************************************************************
309  * @ingroup icp_qat_fw_pke
310  *
311  * @description
312  *     Macro for extraction of the PKE bit from the 16-bit status field
313  *     particular to a PKE response. The status flags are contained within
314  *     the most significant byte of the word. The lower 8 bits of this status
315  *     word now contain the common error codes, which are defined in the common
316  *     header file. The appropriate macro definition to extract the PKE status
317  *     lag from the PKE response assumes that a single byte i.e. pke_resp_flags
318  *     is passed to the macro.
319  *
320  * @param status
321  *     Status to extract the PKE status bit
322  *
323  *****************************************************************************/
324 #define ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(flags)                                \
325         QAT_FIELD_GET((flags), QAT_COMN_RESP_PKE_STATUS_BITPOS,                \
326                       QAT_COMN_RESP_PKE_STATUS_MASK)
327
328 /**
329  ******************************************************************************
330  * @ingroup icp_qat_fw_pke
331  *
332  * @description
333  *      Extract the valid flag from the PKE Request's header flags. Note that
334  *      this invokes the common macro which may be used by either the request
335  *      or the response.
336  *
337  * @param icp_qat_fw_req_pke_hdr    Structure passed to extract the valid bit
338  *                                  from the 'hdr_flags' field.
339  *
340  *****************************************************************************/
341 #define ICP_QAT_FW_PKE_RQ_VALID_FLAG_GET(icp_qat_fw_req_pke_hdr)               \
342         ICP_QAT_FW_PKE_HDR_VALID_FLAG_GET(icp_qat_fw_req_pke_hdr)
343
344 /**
345  ******************************************************************************
346  * @ingroup icp_qat_fw_pke
347  *
348  * @description
349  *      Set the valid bit in the PKE Request's header flags. Note that
350  *      this invokes the common macro which may be used by either the request
351  *      or the response.
352  *
353  * @param icp_qat_fw_req_pke_hdr    Structure passed to set the valid bit.
354  * @param val    Value of the valid bit flag.
355  *
356  *****************************************************************************/
357 #define ICP_QAT_FW_PKE_RQ_VALID_FLAG_SET(icp_qat_fw_req_pke_hdr, val)          \
358         ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(icp_qat_fw_req_pke_hdr, val)
359
360 /**
361  ******************************************************************************
362  * @ingroup icp_qat_fw_pke
363  *
364  * @description
365  *      Extract the valid flag from the PKE Response's header flags. Note that
366  *      invokes the common macro which may be used by either the request
367  *      or the response.
368  *
369  * @param icp_qat_fw_resp_pke_hdr    Structure to extract the valid bit
370  *                                   from the 'hdr_flags' field.
371  *
372  *****************************************************************************/
373 #define ICP_QAT_FW_PKE_RESP_VALID_FLAG_GET(icp_qat_fw_resp_pke_hdr)            \
374         ICP_QAT_FW_PKE_HDR_VALID_FLAG_GET(icp_qat_fw_resp_pke_hdr)
375
376 /**
377  ******************************************************************************
378  * @ingroup icp_qat_fw_pke
379  *
380  * @description
381  *      Set the valid bit in the PKE Response's header flags. Note that
382  *      this invokes the common macro which may be used by either the
383  *      request or the response.
384  *
385  * @param icp_qat_fw_resp_pke_hdr    Structure to set the valid bit
386  * @param val    Value of the valid bit flag.
387  *
388  *****************************************************************************/
389 #define ICP_QAT_FW_PKE_RESP_VALID_FLAG_SET(icp_qat_fw_resp_pke_hdr, val)       \
390         ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(icp_qat_fw_resp_pke_hdr, val)
391
392 /**
393  ******************************************************************************
394  * @ingroup icp_qat_fw_pke
395  *
396  * @description
397  *      Common macro to extract the valid flag from the header flags field
398  *      within the header structure (request or response).
399  *
400  * @param hdr    Structure (request or response) to extract the
401  *               valid bit from the 'hdr_flags' field.
402  *
403  *****************************************************************************/
404 #define ICP_QAT_FW_PKE_HDR_VALID_FLAG_GET(hdr)                                 \
405         QAT_FIELD_GET(hdr.hdr_flags, ICP_QAT_FW_PKE_HDR_VALID_FLAG_BITPOS,     \
406                       ICP_QAT_FW_PKE_HDR_VALID_FLAG_MASK)
407
408 /**
409  ******************************************************************************
410  * @ingroup icp_qat_fw_pke
411  *
412  * @description
413  *      Common macro to set the valid bit in the header flags field within
414  *      the header structure (request or response).
415  *
416  * @param hdr    Structure (request or response) containing the header
417  *               flags field, to allow the valid bit to be set.
418  * @param val    Value of the valid bit flag.
419  *
420  *****************************************************************************/
421 #define ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(hdr, val)                            \
422         QAT_FIELD_SET((hdr.hdr_flags), (val),                                  \
423                       ICP_QAT_FW_PKE_HDR_VALID_FLAG_BITPOS,                    \
424                       ICP_QAT_FW_PKE_HDR_VALID_FLAG_MASK)
425
426 #endif /* _ICP_QAT_FW_PKE_H_ */