1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #include <rte_mempool.h>
7 #include <rte_hexdump.h>
9 #include <rte_bus_pci.h>
10 #include <rte_byteorder.h>
11 #include <rte_memcpy.h>
12 #include <rte_common.h>
13 #include <rte_spinlock.h>
15 #include <rte_malloc.h>
19 #include "qat_comp_pmd.h"
23 qat_comp_build_request(void *in_op, uint8_t *out_msg,
24 void *op_cookie __rte_unused,
25 enum qat_device_gen qat_dev_gen __rte_unused)
27 struct rte_comp_op *op = in_op;
28 struct qat_comp_xform *qat_xform = op->private_xform;
29 const uint8_t *tmpl = (uint8_t *)&qat_xform->qat_comp_req_tmpl;
30 struct icp_qat_fw_comp_req *comp_req =
31 (struct icp_qat_fw_comp_req *)out_msg;
33 if (unlikely(op->op_type != RTE_COMP_OP_STATELESS)) {
34 QAT_DP_LOG(ERR, "QAT PMD only supports stateless compression "
35 "operation requests, op (%p) is not a "
36 "stateless operation.", op);
40 rte_mov128(out_msg, tmpl);
41 comp_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
43 /* common for sgl and flat buffers */
44 comp_req->comp_pars.comp_len = op->src.length;
45 comp_req->comp_pars.out_buffer_sz = rte_pktmbuf_pkt_len(op->m_dst);
48 if (op->m_src->next != NULL || op->m_dst->next != NULL) {
49 QAT_DP_LOG(ERR, "QAT PMD doesn't support scatter gather");
53 ICP_QAT_FW_COMN_PTR_TYPE_SET(comp_req->comn_hdr.comn_req_flags,
54 QAT_COMN_PTR_TYPE_FLAT);
55 comp_req->comn_mid.src_length = rte_pktmbuf_data_len(op->m_src);
56 comp_req->comn_mid.dst_length = rte_pktmbuf_data_len(op->m_dst);
58 comp_req->comn_mid.src_data_addr =
59 rte_pktmbuf_mtophys_offset(op->m_src, op->src.offset);
60 comp_req->comn_mid.dest_data_addr =
61 rte_pktmbuf_mtophys_offset(op->m_dst, op->dst.offset);
64 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
65 QAT_DP_LOG(DEBUG, "Direction: %s",
66 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
67 "decompression" : "compression");
68 QAT_DP_HEXDUMP_LOG(DEBUG, "qat compression message:", comp_req,
69 sizeof(struct icp_qat_fw_comp_req));
75 qat_comp_process_response(void **op, uint8_t *resp)
77 struct icp_qat_fw_comp_resp *resp_msg =
78 (struct icp_qat_fw_comp_resp *)resp;
79 struct rte_comp_op *rx_op = (struct rte_comp_op *)(uintptr_t)
80 (resp_msg->opaque_data);
81 struct qat_comp_xform *qat_xform = (struct qat_comp_xform *)
82 (rx_op->private_xform);
84 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
85 QAT_DP_LOG(DEBUG, "Direction: %s",
86 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
87 "decompression" : "compression");
88 QAT_DP_HEXDUMP_LOG(DEBUG, "qat_response:", (uint8_t *)resp_msg,
89 sizeof(struct icp_qat_fw_comp_resp));
92 if (likely(qat_xform->qat_comp_request_type
93 != QAT_COMP_REQUEST_DECOMPRESS)) {
94 if (unlikely(ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(
95 resp_msg->comn_resp.hdr_flags)
96 == ICP_QAT_FW_COMP_NO_CNV)) {
97 rx_op->status = RTE_COMP_OP_STATUS_ERROR;
98 rx_op->debug_status = ERR_CODE_QAT_COMP_WRONG_FW;
100 QAT_DP_LOG(ERR, "QAT has wrong firmware");
105 if ((ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(resp_msg->comn_resp.comn_status)
106 | ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(
107 resp_msg->comn_resp.comn_status)) !=
108 ICP_QAT_FW_COMN_STATUS_FLAG_OK) {
110 rx_op->status = RTE_COMP_OP_STATUS_ERROR;
111 rx_op->debug_status =
112 *((uint16_t *)(&resp_msg->comn_resp.comn_error));
114 struct qat_comp_xform *qat_xform = rx_op->private_xform;
115 struct icp_qat_fw_resp_comp_pars *comp_resp =
116 (struct icp_qat_fw_resp_comp_pars *)&resp_msg->comp_resp_pars;
118 rx_op->status = RTE_COMP_OP_STATUS_SUCCESS;
119 rx_op->consumed = comp_resp->input_byte_counter;
120 rx_op->produced = comp_resp->output_byte_counter;
122 if (qat_xform->checksum_type != RTE_COMP_CHECKSUM_NONE) {
123 if (qat_xform->checksum_type == RTE_COMP_CHECKSUM_CRC32)
124 rx_op->output_chksum = comp_resp->curr_crc32;
125 else if (qat_xform->checksum_type ==
126 RTE_COMP_CHECKSUM_ADLER32)
127 rx_op->output_chksum = comp_resp->curr_adler_32;
129 rx_op->output_chksum = comp_resp->curr_chksum;
138 qat_comp_xform_size(void)
140 return RTE_ALIGN_CEIL(sizeof(struct qat_comp_xform), 8);
143 static void qat_comp_create_req_hdr(struct icp_qat_fw_comn_req_hdr *header,
144 enum qat_comp_request_type request)
146 if (request == QAT_COMP_REQUEST_FIXED_COMP_STATELESS)
147 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_STATIC;
148 else if (request == QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS)
149 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DYNAMIC;
150 else if (request == QAT_COMP_REQUEST_DECOMPRESS)
151 header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DECOMPRESS;
153 header->service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_COMP;
155 ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET);
157 header->comn_req_flags = ICP_QAT_FW_COMN_FLAGS_BUILD(
158 QAT_COMN_CD_FLD_TYPE_16BYTE_DATA, QAT_COMN_PTR_TYPE_FLAT);
161 static int qat_comp_create_templates(struct qat_comp_xform *qat_xform,
162 const struct rte_memzone *interm_buff_mz __rte_unused,
163 const struct rte_comp_xform *xform)
165 struct icp_qat_fw_comp_req *comp_req;
166 int comp_level, algo;
167 uint32_t req_par_flags;
168 int direction = ICP_QAT_HW_COMPRESSION_DIR_COMPRESS;
170 if (unlikely(qat_xform == NULL)) {
171 QAT_LOG(ERR, "Session was not created for this device");
175 if (qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS) {
176 direction = ICP_QAT_HW_COMPRESSION_DIR_DECOMPRESS;
177 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_1;
178 req_par_flags = ICP_QAT_FW_COMP_REQ_PARAM_FLAGS_BUILD(
179 ICP_QAT_FW_COMP_SOP, ICP_QAT_FW_COMP_EOP,
180 ICP_QAT_FW_COMP_BFINAL, ICP_QAT_FW_COMP_NO_CNV,
181 ICP_QAT_FW_COMP_NO_CNV_RECOVERY);
184 if (xform->compress.level == RTE_COMP_LEVEL_PMD_DEFAULT)
185 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_8;
186 else if (xform->compress.level == 1)
187 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_1;
188 else if (xform->compress.level == 2)
189 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_4;
190 else if (xform->compress.level == 3)
191 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_8;
192 else if (xform->compress.level >= 4 &&
193 xform->compress.level <= 9)
194 comp_level = ICP_QAT_HW_COMPRESSION_DEPTH_16;
196 QAT_LOG(ERR, "compression level not supported");
199 req_par_flags = ICP_QAT_FW_COMP_REQ_PARAM_FLAGS_BUILD(
200 ICP_QAT_FW_COMP_SOP, ICP_QAT_FW_COMP_EOP,
201 ICP_QAT_FW_COMP_BFINAL, ICP_QAT_FW_COMP_CNV,
202 ICP_QAT_FW_COMP_CNV_RECOVERY);
205 switch (xform->compress.algo) {
206 case RTE_COMP_ALGO_DEFLATE:
207 algo = ICP_QAT_HW_COMPRESSION_ALGO_DEFLATE;
209 case RTE_COMP_ALGO_LZS:
212 QAT_LOG(ERR, "compression algorithm not supported");
216 comp_req = &qat_xform->qat_comp_req_tmpl;
218 /* Initialize header */
219 qat_comp_create_req_hdr(&comp_req->comn_hdr,
220 qat_xform->qat_comp_request_type);
222 comp_req->comn_hdr.serv_specif_flags = ICP_QAT_FW_COMP_FLAGS_BUILD(
223 ICP_QAT_FW_COMP_STATELESS_SESSION,
224 ICP_QAT_FW_COMP_NOT_AUTO_SELECT_BEST,
225 ICP_QAT_FW_COMP_NOT_ENH_AUTO_SELECT_BEST,
226 ICP_QAT_FW_COMP_NOT_DISABLE_TYPE0_ENH_AUTO_SELECT_BEST,
227 ICP_QAT_FW_COMP_DISABLE_SECURE_RAM_USED_AS_INTMD_BUF);
229 comp_req->cd_pars.sl.comp_slice_cfg_word[0] =
230 ICP_QAT_HW_COMPRESSION_CONFIG_BUILD(
232 /* In CPM 1.6 only valid mode ! */
233 ICP_QAT_HW_COMPRESSION_DELAYED_MATCH_ENABLED, algo,
234 /* Translate level to depth */
235 comp_level, ICP_QAT_HW_COMPRESSION_FILE_TYPE_0);
237 comp_req->comp_pars.initial_adler = 1;
238 comp_req->comp_pars.initial_crc32 = 0;
239 comp_req->comp_pars.req_par_flags = req_par_flags;
242 if (qat_xform->qat_comp_request_type ==
243 QAT_COMP_REQUEST_FIXED_COMP_STATELESS ||
244 qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS) {
245 ICP_QAT_FW_COMN_NEXT_ID_SET(&comp_req->comp_cd_ctrl,
246 ICP_QAT_FW_SLICE_DRAM_WR);
247 ICP_QAT_FW_COMN_CURR_ID_SET(&comp_req->comp_cd_ctrl,
248 ICP_QAT_FW_SLICE_COMP);
249 } else if (qat_xform->qat_comp_request_type ==
250 QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS) {
252 QAT_LOG(ERR, "Dynamic huffman encoding not supported");
256 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
257 QAT_DP_HEXDUMP_LOG(DEBUG, "qat compression message template:", comp_req,
258 sizeof(struct icp_qat_fw_comp_req));
264 * Create driver private_xform data.
269 * xform data from application
270 * @param private_xform
271 * ptr where handle of pmd's private_xform data should be stored
273 * - if successful returns 0
274 * and valid private_xform handle
275 * - <0 in error cases
276 * - Returns -EINVAL if input parameters are invalid.
277 * - Returns -ENOTSUP if comp device does not support the comp transform.
278 * - Returns -ENOMEM if the private_xform could not be allocated.
281 qat_comp_private_xform_create(struct rte_compressdev *dev,
282 const struct rte_comp_xform *xform,
283 void **private_xform)
285 struct qat_comp_dev_private *qat = dev->data->dev_private;
287 if (unlikely(private_xform == NULL)) {
288 QAT_LOG(ERR, "QAT: private_xform parameter is NULL");
291 if (unlikely(qat->xformpool == NULL)) {
292 QAT_LOG(ERR, "QAT device has no private_xform mempool");
295 if (rte_mempool_get(qat->xformpool, private_xform)) {
296 QAT_LOG(ERR, "Couldn't get object from qat xform mempool");
300 struct qat_comp_xform *qat_xform =
301 (struct qat_comp_xform *)*private_xform;
303 if (xform->type == RTE_COMP_COMPRESS) {
304 if (xform->compress.deflate.huffman ==
305 RTE_COMP_HUFFMAN_DYNAMIC) {
307 "QAT device doesn't support dynamic compression");
311 if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED ||
312 ((xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_DEFAULT)
313 && qat->interm_buff_mz == NULL))
315 qat_xform->qat_comp_request_type =
316 QAT_COMP_REQUEST_FIXED_COMP_STATELESS;
320 qat_xform->qat_comp_request_type = QAT_COMP_REQUEST_DECOMPRESS;
323 qat_xform->checksum_type = xform->compress.chksum;
325 if (qat_comp_create_templates(qat_xform, qat->interm_buff_mz, xform)) {
326 QAT_LOG(ERR, "QAT: Problem with setting compression");
333 * Free driver private_xform data.
337 * @param private_xform
338 * handle of pmd's private_xform data
341 * - <0 in error cases
342 * - Returns -EINVAL if input parameters are invalid.
345 qat_comp_private_xform_free(struct rte_compressdev *dev __rte_unused,
348 struct qat_comp_xform *qat_xform =
349 (struct qat_comp_xform *)private_xform;
352 memset(qat_xform, 0, qat_comp_xform_size());
353 struct rte_mempool *mp = rte_mempool_from_obj(qat_xform);
355 rte_mempool_put(mp, qat_xform);