1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2022 Intel Corporation */
3 #ifndef _QAT_COMP_REQ_H_
4 #define _QAT_COMP_REQ_H_
5
6 #include "icp_qat_fw_comp.h"
7
8 #define QAT_COMP_REQ_SIZE (sizeof(struct icp_qat_fw_comp_req))
9 #define QAT_COMP_CTX_SIZE (QAT_COMP_REQ_SIZE * 2)
10
qat_comp_create_req(void * ctx,void * req,u64 src,u32 slen,u64 dst,u32 dlen,u64 opaque)11 static inline void qat_comp_create_req(void *ctx, void *req, u64 src, u32 slen,
12 u64 dst, u32 dlen, u64 opaque)
13 {
14 struct icp_qat_fw_comp_req *fw_tmpl = ctx;
15 struct icp_qat_fw_comp_req *fw_req = req;
16 struct icp_qat_fw_comp_req_params *req_pars = &fw_req->comp_pars;
17
18 memcpy(fw_req, fw_tmpl, sizeof(*fw_req));
19 fw_req->comn_mid.src_data_addr = src;
20 fw_req->comn_mid.src_length = slen;
21 fw_req->comn_mid.dest_data_addr = dst;
22 fw_req->comn_mid.dst_length = dlen;
23 fw_req->comn_mid.opaque_data = opaque;
24 req_pars->comp_len = slen;
25 req_pars->out_buffer_sz = dlen;
26 }
27
qat_comp_override_dst(void * req,u64 dst,u32 dlen)28 static inline void qat_comp_override_dst(void *req, u64 dst, u32 dlen)
29 {
30 struct icp_qat_fw_comp_req *fw_req = req;
31 struct icp_qat_fw_comp_req_params *req_pars = &fw_req->comp_pars;
32
33 fw_req->comn_mid.dest_data_addr = dst;
34 fw_req->comn_mid.dst_length = dlen;
35 req_pars->out_buffer_sz = dlen;
36 }
37
qat_comp_create_compression_req(void * ctx,void * req,u64 src,u32 slen,u64 dst,u32 dlen,u64 opaque)38 static inline void qat_comp_create_compression_req(void *ctx, void *req,
39 u64 src, u32 slen,
40 u64 dst, u32 dlen,
41 u64 opaque)
42 {
43 qat_comp_create_req(ctx, req, src, slen, dst, dlen, opaque);
44 }
45
qat_comp_create_decompression_req(void * ctx,void * req,u64 src,u32 slen,u64 dst,u32 dlen,u64 opaque)46 static inline void qat_comp_create_decompression_req(void *ctx, void *req,
47 u64 src, u32 slen,
48 u64 dst, u32 dlen,
49 u64 opaque)
50 {
51 struct icp_qat_fw_comp_req *fw_tmpl = ctx;
52
53 fw_tmpl++;
54 qat_comp_create_req(fw_tmpl, req, src, slen, dst, dlen, opaque);
55 }
56
qat_comp_get_consumed_ctr(void * resp)57 static inline u32 qat_comp_get_consumed_ctr(void *resp)
58 {
59 struct icp_qat_fw_comp_resp *qat_resp = resp;
60
61 return qat_resp->comp_resp_pars.input_byte_counter;
62 }
63
qat_comp_get_produced_ctr(void * resp)64 static inline u32 qat_comp_get_produced_ctr(void *resp)
65 {
66 struct icp_qat_fw_comp_resp *qat_resp = resp;
67
68 return qat_resp->comp_resp_pars.output_byte_counter;
69 }
70
qat_comp_get_produced_adler32(void * resp)71 static inline u32 qat_comp_get_produced_adler32(void *resp)
72 {
73 struct icp_qat_fw_comp_resp *qat_resp = resp;
74
75 return qat_resp->comp_resp_pars.crc.legacy.curr_adler_32;
76 }
77
qat_comp_get_opaque(void * resp)78 static inline u64 qat_comp_get_opaque(void *resp)
79 {
80 struct icp_qat_fw_comp_resp *qat_resp = resp;
81
82 return qat_resp->opaque_data;
83 }
84
qat_comp_get_cmp_err(void * resp)85 static inline s8 qat_comp_get_cmp_err(void *resp)
86 {
87 struct icp_qat_fw_comp_resp *qat_resp = resp;
88
89 return qat_resp->comn_resp.comn_error.cmp_err_code;
90 }
91
qat_comp_get_xlt_err(void * resp)92 static inline s8 qat_comp_get_xlt_err(void *resp)
93 {
94 struct icp_qat_fw_comp_resp *qat_resp = resp;
95
96 return qat_resp->comn_resp.comn_error.xlat_err_code;
97 }
98
qat_comp_get_cmp_status(void * resp)99 static inline s8 qat_comp_get_cmp_status(void *resp)
100 {
101 struct icp_qat_fw_comp_resp *qat_resp = resp;
102 u8 stat_filed = qat_resp->comn_resp.comn_status;
103
104 return ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(stat_filed);
105 }
106
qat_comp_get_xlt_status(void * resp)107 static inline s8 qat_comp_get_xlt_status(void *resp)
108 {
109 struct icp_qat_fw_comp_resp *qat_resp = resp;
110 u8 stat_filed = qat_resp->comn_resp.comn_status;
111
112 return ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(stat_filed);
113 }
114
qat_comp_get_cmp_cnv_flag(void * resp)115 static inline u8 qat_comp_get_cmp_cnv_flag(void *resp)
116 {
117 struct icp_qat_fw_comp_resp *qat_resp = resp;
118 u8 flags = qat_resp->comn_resp.hdr_flags;
119
120 return ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(flags);
121 }
122
123 #endif
124