1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
6 #include <rte_mempool.h>
8 #include <rte_hexdump.h>
10 #include <rte_bus_pci.h>
11 #include <rte_byteorder.h>
12 #include <rte_memcpy.h>
13 #include <rte_common.h>
14 #include <rte_spinlock.h>
16 #include <rte_malloc.h>
20 #include "qat_comp_pmd.h"
24 qat_comp_build_request(void *in_op, uint8_t *out_msg,
25 void *op_cookie __rte_unused,
26 enum qat_device_gen qat_dev_gen __rte_unused)
28 struct rte_comp_op *op = in_op;
29 struct qat_comp_xform *qat_xform = op->private_xform;
30 const uint8_t *tmpl = (uint8_t *)&qat_xform->qat_comp_req_tmpl;
31 struct icp_qat_fw_comp_req *comp_req =
32 (struct icp_qat_fw_comp_req *)out_msg;
34 if (unlikely(op->op_type != RTE_COMP_OP_STATELESS)) {
35 QAT_DP_LOG(ERR, "QAT PMD only supports stateless compression "
36 "operation requests, op (%p) is not a "
37 "stateless operation.", op);
41 rte_mov128(out_msg, tmpl);
42 comp_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
44 /* common for sgl and flat buffers */
45 comp_req->comp_pars.comp_len = op->src.length;
46 comp_req->comp_pars.out_buffer_sz = rte_pktmbuf_pkt_len(op->m_dst);
49 if (op->m_src->next != NULL || op->m_dst->next != NULL) {
50 QAT_DP_LOG(ERR, "QAT PMD doesn't support scatter gather");
54 ICP_QAT_FW_COMN_PTR_TYPE_SET(comp_req->comn_hdr.comn_req_flags,
55 QAT_COMN_PTR_TYPE_FLAT);
56 comp_req->comn_mid.src_length = rte_pktmbuf_data_len(op->m_src);
57 comp_req->comn_mid.dst_length = rte_pktmbuf_data_len(op->m_dst);
59 comp_req->comn_mid.src_data_addr =
60 rte_pktmbuf_mtophys_offset(op->m_src, op->src.offset);
61 comp_req->comn_mid.dest_data_addr =
62 rte_pktmbuf_mtophys_offset(op->m_dst, op->dst.offset);
65 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
66 QAT_DP_LOG(DEBUG, "Direction: %s",
67 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
68 "decompression" : "compression");
69 QAT_DP_HEXDUMP_LOG(DEBUG, "qat compression message:", comp_req,
70 sizeof(struct icp_qat_fw_comp_req));
76 qat_comp_process_response(void **op, uint8_t *resp)
78 struct icp_qat_fw_comp_resp *resp_msg =
79 (struct icp_qat_fw_comp_resp *)resp;
80 struct rte_comp_op *rx_op = (struct rte_comp_op *)(uintptr_t)
81 (resp_msg->opaque_data);
83 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
84 QAT_DP_LOG(DEBUG, "Direction: %s",
85 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
86 "decompression" : "compression");
87 QAT_DP_HEXDUMP_LOG(DEBUG, "qat_response:", (uint8_t *)resp_msg,
88 sizeof(struct icp_qat_fw_comp_resp));
91 if ((ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(resp_msg->comn_resp.comn_status)
92 | ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(
93 resp_msg->comn_resp.comn_status)) !=
94 ICP_QAT_FW_COMN_STATUS_FLAG_OK) {
96 rx_op->status = RTE_COMP_OP_STATUS_ERROR;
98 *((uint16_t *)(&resp_msg->comn_resp.comn_error));
100 struct qat_comp_xform *qat_xform = rx_op->private_xform;
101 struct icp_qat_fw_resp_comp_pars *comp_resp =
102 (struct icp_qat_fw_resp_comp_pars *)&resp_msg->comp_resp_pars;
104 rx_op->status = RTE_COMP_OP_STATUS_SUCCESS;
105 rx_op->consumed = comp_resp->input_byte_counter;
106 rx_op->produced = comp_resp->output_byte_counter;
108 if (qat_xform->checksum_type != RTE_COMP_CHECKSUM_NONE) {
109 if (qat_xform->checksum_type == RTE_COMP_CHECKSUM_CRC32)
110 rx_op->output_chksum = comp_resp->curr_crc32;
111 else if (qat_xform->checksum_type ==
112 RTE_COMP_CHECKSUM_ADLER32)
113 rx_op->output_chksum = comp_resp->curr_adler_32;
115 rx_op->output_chksum = comp_resp->curr_chksum;
124 qat_comp_xform_size(void)
126 return RTE_ALIGN_CEIL(sizeof(struct qat_comp_xform), 8);
129 static void qat_comp_create_req_hdr(struct icp_qat_fw_comn_req_hdr *header,
130 enum qat_comp_request_type request)
132 if (request == QAT_COMP_REQUEST_FIXED_COMP_STATELESS)
133 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_STATIC;
134 else if (request == QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS)
135 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DYNAMIC;
136 else if (request == QAT_COMP_REQUEST_DECOMPRESS)
137 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DECOMPRESS;
139 header->service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_COMP;
141 ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET);
143 header->comn_req_flags = ICP_QAT_FW_COMN_FLAGS_BUILD(
144 QAT_COMN_CD_FLD_TYPE_16BYTE_DATA, QAT_COMN_PTR_TYPE_FLAT);
147 static int qat_comp_create_templates(struct qat_comp_xform *qat_xform,
148 const struct rte_memzone *interm_buff_mz __rte_unused,
149 const struct rte_comp_xform *xform)
151 struct icp_qat_fw_comp_req *comp_req;
152 int comp_level, algo;
153 uint32_t req_par_flags;
154 int direction = ICP_QAT_HW_COMPRESSION_DIR_COMPRESS;
156 if (unlikely(qat_xform == NULL)) {
157 QAT_LOG(ERR, "Session was not created for this device");
161 if (qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS) {
162 direction = ICP_QAT_HW_COMPRESSION_DIR_DECOMPRESS;
163 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_1;
164 req_par_flags = ICP_QAT_FW_COMP_REQ_PARAM_FLAGS_BUILD(
165 ICP_QAT_FW_COMP_SOP, ICP_QAT_FW_COMP_EOP,
166 ICP_QAT_FW_COMP_BFINAL, ICP_QAT_FW_COMP_NO_CNV,
167 ICP_QAT_FW_COMP_NO_CNV_RECOVERY);
170 if (xform->compress.level == RTE_COMP_LEVEL_PMD_DEFAULT)
171 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_8;
172 else if (xform->compress.level == 1)
173 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_1;
174 else if (xform->compress.level == 2)
175 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_4;
176 else if (xform->compress.level == 3)
177 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_8;
178 else if (xform->compress.level >= 4 &&
179 xform->compress.level <= 9)
180 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_16;
182 QAT_LOG(ERR, "compression level not supported");
185 req_par_flags = ICP_QAT_FW_COMP_REQ_PARAM_FLAGS_BUILD(
186 ICP_QAT_FW_COMP_SOP, ICP_QAT_FW_COMP_EOP,
187 ICP_QAT_FW_COMP_BFINAL, ICP_QAT_FW_COMP_CNV,
188 ICP_QAT_FW_COMP_CNV_RECOVERY);
191 switch (xform->compress.algo) {
192 case RTE_COMP_ALGO_DEFLATE:
193 algo = ICP_QAT_HW_COMPRESSION_ALGO_DEFLATE;
195 case RTE_COMP_ALGO_LZS:
198 QAT_LOG(ERR, "compression algorithm not supported");
202 comp_req = &qat_xform->qat_comp_req_tmpl;
204 /* Initialize header */
205 qat_comp_create_req_hdr(&comp_req->comn_hdr,
206 qat_xform->qat_comp_request_type);
208 comp_req->comn_hdr.serv_specif_flags = ICP_QAT_FW_COMP_FLAGS_BUILD(
209 ICP_QAT_FW_COMP_STATELESS_SESSION,
210 ICP_QAT_FW_COMP_NOT_AUTO_SELECT_BEST,
211 ICP_QAT_FW_COMP_NOT_ENH_AUTO_SELECT_BEST,
212 ICP_QAT_FW_COMP_NOT_DISABLE_TYPE0_ENH_AUTO_SELECT_BEST,
213 ICP_QAT_FW_COMP_DISABLE_SECURE_RAM_USED_AS_INTMD_BUF);
215 comp_req->cd_pars.sl.comp_slice_cfg_word[0] =
216 ICP_QAT_HW_COMPRESSION_CONFIG_BUILD(
218 /* In CPM 1.6 only valid mode ! */
219 ICP_QAT_HW_COMPRESSION_DELAYED_MATCH_ENABLED, algo,
220 /* Translate level to depth */
221 comp_level, ICP_QAT_HW_COMPRESSION_FILE_TYPE_0);
223 comp_req->comp_pars.initial_adler = 1;
224 comp_req->comp_pars.initial_crc32 = 0;
225 comp_req->comp_pars.req_par_flags = req_par_flags;
228 if (qat_xform->qat_comp_request_type ==
229 QAT_COMP_REQUEST_FIXED_COMP_STATELESS ||
230 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS) {
231 ICP_QAT_FW_COMN_NEXT_ID_SET(&comp_req->comp_cd_ctrl,
232 ICP_QAT_FW_SLICE_DRAM_WR);
233 ICP_QAT_FW_COMN_CURR_ID_SET(&comp_req->comp_cd_ctrl,
234 ICP_QAT_FW_SLICE_COMP);
235 } else if (qat_xform->qat_comp_request_type ==
236 QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS) {
238 QAT_LOG(ERR, "Dynamic huffman encoding not supported");
242 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
243 QAT_DP_HEXDUMP_LOG(DEBUG, "qat compression message template:", comp_req,
244 sizeof(struct icp_qat_fw_comp_req));
250 * Create driver private_xform data.
255 * xform data from application
256 * @param private_xform
257 * ptr where handle of pmd's private_xform data should be stored
259 * - if successful returns 0
260 * and valid private_xform handle
261 * - <0 in error cases
262 * - Returns -EINVAL if input parameters are invalid.
263 * - Returns -ENOTSUP if comp device does not support the comp transform.
264 * - Returns -ENOMEM if the private_xform could not be allocated.
267 qat_comp_private_xform_create(struct rte_compressdev *dev,
268 const struct rte_comp_xform *xform,
269 void **private_xform)
271 struct qat_comp_dev_private *qat = dev->data->dev_private;
273 if (unlikely(private_xform == NULL)) {
274 QAT_LOG(ERR, "QAT: private_xform parameter is NULL");
277 if (unlikely(qat->xformpool == NULL)) {
278 QAT_LOG(ERR, "QAT device has no private_xform mempool");
281 if (rte_mempool_get(qat->xformpool, private_xform)) {
282 QAT_LOG(ERR, "Couldn't get object from qat xform mempool");
286 struct qat_comp_xform *qat_xform =
287 (struct qat_comp_xform *)*private_xform;
289 if (xform->type == RTE_COMP_COMPRESS) {
290 if (xform->compress.deflate.huffman ==
291 RTE_COMP_HUFFMAN_DYNAMIC) {
293 "QAT device doesn't support dynamic compression");
297 if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED ||
298 ((xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_DEFAULT)
299 && qat->interm_buff_mz == NULL))
301 qat_xform->qat_comp_request_type =
302 QAT_COMP_REQUEST_FIXED_COMP_STATELESS;
306 qat_xform->qat_comp_request_type = QAT_COMP_REQUEST_DECOMPRESS;
309 qat_xform->checksum_type = xform->compress.chksum;
311 if (qat_comp_create_templates(qat_xform, qat->interm_buff_mz, xform)) {
312 QAT_LOG(ERR, "QAT: Problem with setting compression");
319 * Free driver private_xform data.
323 * @param private_xform
324 * handle of pmd's private_xform data
327 * - <0 in error cases
328 * - Returns -EINVAL if input parameters are invalid.
331 qat_comp_private_xform_free(struct rte_compressdev *dev __rte_unused,
334 struct qat_comp_xform *qat_xform =
335 (struct qat_comp_xform *)private_xform;
338 memset(qat_xform, 0, qat_comp_xform_size());
339 struct rte_mempool *mp = rte_mempool_from_obj(qat_xform);
341 rte_mempool_put(mp, qat_xform);