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 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 fw_req->u3.asb_threshold.asb_value *= slen >> 4; 27 } 28 29 static inline void qat_comp_create_compression_req(void *ctx, void *req, 30 u64 src, u32 slen, 31 u64 dst, u32 dlen, 32 u64 opaque) 33 { 34 qat_comp_create_req(ctx, req, src, slen, dst, dlen, opaque); 35 } 36 37 static inline void qat_comp_create_decompression_req(void *ctx, void *req, 38 u64 src, u32 slen, 39 u64 dst, u32 dlen, 40 u64 opaque) 41 { 42 struct icp_qat_fw_comp_req *fw_tmpl = ctx; 43 44 fw_tmpl++; 45 qat_comp_create_req(fw_tmpl, req, src, slen, dst, dlen, opaque); 46 } 47 48 static inline u32 qat_comp_get_consumed_ctr(void *resp) 49 { 50 struct icp_qat_fw_comp_resp *qat_resp = resp; 51 52 return qat_resp->comp_resp_pars.input_byte_counter; 53 } 54 55 static inline u32 qat_comp_get_produced_ctr(void *resp) 56 { 57 struct icp_qat_fw_comp_resp *qat_resp = resp; 58 59 return qat_resp->comp_resp_pars.output_byte_counter; 60 } 61 62 static inline u32 qat_comp_get_produced_adler32(void *resp) 63 { 64 struct icp_qat_fw_comp_resp *qat_resp = resp; 65 66 return qat_resp->comp_resp_pars.crc.legacy.curr_adler_32; 67 } 68 69 static inline u64 qat_comp_get_opaque(void *resp) 70 { 71 struct icp_qat_fw_comp_resp *qat_resp = resp; 72 73 return qat_resp->opaque_data; 74 } 75 76 static inline s8 qat_comp_get_cmp_err(void *resp) 77 { 78 struct icp_qat_fw_comp_resp *qat_resp = resp; 79 80 return qat_resp->comn_resp.comn_error.cmp_err_code; 81 } 82 83 static inline s8 qat_comp_get_xlt_err(void *resp) 84 { 85 struct icp_qat_fw_comp_resp *qat_resp = resp; 86 87 return qat_resp->comn_resp.comn_error.xlat_err_code; 88 } 89 90 static inline s8 qat_comp_get_cmp_status(void *resp) 91 { 92 struct icp_qat_fw_comp_resp *qat_resp = resp; 93 u8 stat_filed = qat_resp->comn_resp.comn_status; 94 95 return ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(stat_filed); 96 } 97 98 static inline s8 qat_comp_get_xlt_status(void *resp) 99 { 100 struct icp_qat_fw_comp_resp *qat_resp = resp; 101 u8 stat_filed = qat_resp->comn_resp.comn_status; 102 103 return ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(stat_filed); 104 } 105 106 static inline u8 qat_comp_get_cmp_cnv_flag(void *resp) 107 { 108 struct icp_qat_fw_comp_resp *qat_resp = resp; 109 u8 flags = qat_resp->comn_resp.hdr_flags; 110 111 return ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(flags); 112 } 113 114 static inline u8 qat_comp_get_cmp_uncomp_flag(void *resp) 115 { 116 struct icp_qat_fw_comp_resp *qat_resp = resp; 117 u8 flags = qat_resp->comn_resp.hdr_flags; 118 119 return ICP_QAT_FW_COMN_HDR_ST_BLK_FLAG_GET(flags); 120 } 121 122 #endif 123