summaryrefslogtreecommitdiff
path: root/drivers/crypto/intel/qat/qat_common/qat_comp_req.h
blob: 404e32c5e77838df5dc94b22d33fb3b2e3ef0462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright(c) 2022 Intel Corporation */
#ifndef _QAT_COMP_REQ_H_
#define _QAT_COMP_REQ_H_

#include "icp_qat_fw_comp.h"

#define QAT_COMP_REQ_SIZE (sizeof(struct icp_qat_fw_comp_req))
#define QAT_COMP_CTX_SIZE (QAT_COMP_REQ_SIZE * 2)

static inline void qat_comp_create_req(void *ctx, void *req, u64 src, u32 slen,
				       u64 dst, u32 dlen, u64 opaque)
{
	struct icp_qat_fw_comp_req *fw_tmpl = ctx;
	struct icp_qat_fw_comp_req *fw_req = req;
	struct icp_qat_fw_comp_req_params *req_pars = &fw_req->comp_pars;

	memcpy(fw_req, fw_tmpl, sizeof(*fw_req));
	fw_req->comn_mid.src_data_addr = src;
	fw_req->comn_mid.src_length = slen;
	fw_req->comn_mid.dest_data_addr = dst;
	fw_req->comn_mid.dst_length = dlen;
	fw_req->comn_mid.opaque_data = opaque;
	req_pars->comp_len = slen;
	req_pars->out_buffer_sz = dlen;
}

static inline void qat_comp_override_dst(void *req, u64 dst, u32 dlen)
{
	struct icp_qat_fw_comp_req *fw_req = req;
	struct icp_qat_fw_comp_req_params *req_pars = &fw_req->comp_pars;

	fw_req->comn_mid.dest_data_addr = dst;
	fw_req->comn_mid.dst_length = dlen;
	req_pars->out_buffer_sz = dlen;
}

static inline void qat_comp_create_compression_req(void *ctx, void *req,
						   u64 src, u32 slen,
						   u64 dst, u32 dlen,
						   u64 opaque)
{
	qat_comp_create_req(ctx, req, src, slen, dst, dlen, opaque);
}

static inline void qat_comp_create_decompression_req(void *ctx, void *req,
						     u64 src, u32 slen,
						     u64 dst, u32 dlen,
						     u64 opaque)
{
	struct icp_qat_fw_comp_req *fw_tmpl = ctx;

	fw_tmpl++;
	qat_comp_create_req(fw_tmpl, req, src, slen, dst, dlen, opaque);
}

static inline u32 qat_comp_get_consumed_ctr(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->comp_resp_pars.input_byte_counter;
}

static inline u32 qat_comp_get_produced_ctr(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->comp_resp_pars.output_byte_counter;
}

static inline u32 qat_comp_get_produced_adler32(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->comp_resp_pars.crc.legacy.curr_adler_32;
}

static inline u64 qat_comp_get_opaque(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->opaque_data;
}

static inline s8 qat_comp_get_cmp_err(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->comn_resp.comn_error.cmp_err_code;
}

static inline s8 qat_comp_get_xlt_err(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;

	return qat_resp->comn_resp.comn_error.xlat_err_code;
}

static inline s8 qat_comp_get_cmp_status(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;
	u8 stat_filed = qat_resp->comn_resp.comn_status;

	return ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(stat_filed);
}

static inline s8 qat_comp_get_xlt_status(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;
	u8 stat_filed = qat_resp->comn_resp.comn_status;

	return ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(stat_filed);
}

static inline u8 qat_comp_get_cmp_cnv_flag(void *resp)
{
	struct icp_qat_fw_comp_resp *qat_resp = resp;
	u8 flags = qat_resp->comn_resp.hdr_flags;

	return ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(flags);
}

#endif