net/mlx5: support new flow counter API
[dpdk.git] / drivers / compress / qat / qat_comp.c
index cb2005a..b9336f3 100644 (file)
@@ -2,7 +2,6 @@
  * Copyright(c) 2018 Intel Corporation
  */
 
-
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_hexdump.h>
 #include "qat_comp.h"
 #include "qat_comp_pmd.h"
 
+
+int
+qat_comp_build_request(void *in_op, uint8_t *out_msg,
+                      void *op_cookie,
+                      enum qat_device_gen qat_dev_gen __rte_unused)
+{
+       struct rte_comp_op *op = in_op;
+       struct qat_comp_op_cookie *cookie =
+                       (struct qat_comp_op_cookie *)op_cookie;
+       struct qat_comp_xform *qat_xform = op->private_xform;
+       const uint8_t *tmpl = (uint8_t *)&qat_xform->qat_comp_req_tmpl;
+       struct icp_qat_fw_comp_req *comp_req =
+           (struct icp_qat_fw_comp_req *)out_msg;
+
+       if (unlikely(op->op_type != RTE_COMP_OP_STATELESS)) {
+               QAT_DP_LOG(ERR, "QAT PMD only supports stateless compression "
+                               "operation requests, op (%p) is not a "
+                               "stateless operation.", op);
+               return -EINVAL;
+       }
+
+       rte_mov128(out_msg, tmpl);
+       comp_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
+
+       /* common for sgl and flat buffers */
+       comp_req->comp_pars.comp_len = op->src.length;
+       comp_req->comp_pars.out_buffer_sz = rte_pktmbuf_pkt_len(op->m_dst) -
+                       op->dst.offset;
+
+       if (op->m_src->next != NULL || op->m_dst->next != NULL) {
+               /* sgl */
+               int ret = 0;
+
+               ICP_QAT_FW_COMN_PTR_TYPE_SET(comp_req->comn_hdr.comn_req_flags,
+                               QAT_COMN_PTR_TYPE_SGL);
+
+               ret = qat_sgl_fill_array(op->m_src,
+                               op->src.offset,
+                               &cookie->qat_sgl_src,
+                               op->src.length,
+                               RTE_PMD_QAT_COMP_SGL_MAX_SEGMENTS);
+               if (ret) {
+                       QAT_DP_LOG(ERR, "QAT PMD Cannot fill source sgl array");
+                       return ret;
+               }
+
+               ret = qat_sgl_fill_array(op->m_dst,
+                               op->dst.offset,
+                               &cookie->qat_sgl_dst,
+                               comp_req->comp_pars.out_buffer_sz,
+                               RTE_PMD_QAT_COMP_SGL_MAX_SEGMENTS);
+               if (ret) {
+                       QAT_DP_LOG(ERR, "QAT PMD Cannot fill dest. sgl array");
+                       return ret;
+               }
+
+               comp_req->comn_mid.src_data_addr =
+                               cookie->qat_sgl_src_phys_addr;
+               comp_req->comn_mid.dest_data_addr =
+                               cookie->qat_sgl_dst_phys_addr;
+               comp_req->comn_mid.src_length = 0;
+               comp_req->comn_mid.dst_length = 0;
+
+       } else {
+               /* flat aka linear buffer */
+               ICP_QAT_FW_COMN_PTR_TYPE_SET(comp_req->comn_hdr.comn_req_flags,
+                               QAT_COMN_PTR_TYPE_FLAT);
+               comp_req->comn_mid.src_length = op->src.length;
+               comp_req->comn_mid.dst_length =
+                               comp_req->comp_pars.out_buffer_sz;
+
+               comp_req->comn_mid.src_data_addr =
+                   rte_pktmbuf_mtophys_offset(op->m_src, op->src.offset);
+               comp_req->comn_mid.dest_data_addr =
+                   rte_pktmbuf_mtophys_offset(op->m_dst, op->dst.offset);
+       }
+
+#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
+       QAT_DP_LOG(DEBUG, "Direction: %s",
+           qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
+                           "decompression" : "compression");
+       QAT_DP_HEXDUMP_LOG(DEBUG, "qat compression message:", comp_req,
+                   sizeof(struct icp_qat_fw_comp_req));
+#endif
+       return 0;
+}
+
+int
+qat_comp_process_response(void **op, uint8_t *resp)
+{
+       struct icp_qat_fw_comp_resp *resp_msg =
+                       (struct icp_qat_fw_comp_resp *)resp;
+       struct rte_comp_op *rx_op = (struct rte_comp_op *)(uintptr_t)
+                       (resp_msg->opaque_data);
+       struct qat_comp_xform *qat_xform = (struct qat_comp_xform *)
+                               (rx_op->private_xform);
+
+#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
+       QAT_DP_LOG(DEBUG, "Direction: %s",
+           qat_xform->qat_comp_request_type == QAT_COMP_REQUEST_DECOMPRESS ?
+           "decompression" : "compression");
+       QAT_DP_HEXDUMP_LOG(DEBUG,  "qat_response:", (uint8_t *)resp_msg,
+                       sizeof(struct icp_qat_fw_comp_resp));
+#endif
+
+       if (likely(qat_xform->qat_comp_request_type
+                       != QAT_COMP_REQUEST_DECOMPRESS)) {
+               if (unlikely(ICP_QAT_FW_COMN_HDR_CNV_FLAG_GET(
+                               resp_msg->comn_resp.hdr_flags)
+                                       == ICP_QAT_FW_COMP_NO_CNV)) {
+                       rx_op->status = RTE_COMP_OP_STATUS_ERROR;
+                       rx_op->debug_status = ERR_CODE_QAT_COMP_WRONG_FW;
+                       *op = (void *)rx_op;
+                       QAT_DP_LOG(ERR, "QAT has wrong firmware");
+                       return 0;
+               }
+       }
+
+       if ((ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(resp_msg->comn_resp.comn_status)
+               | ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(
+                               resp_msg->comn_resp.comn_status)) !=
+                               ICP_QAT_FW_COMN_STATUS_FLAG_OK) {
+
+               rx_op->status = RTE_COMP_OP_STATUS_ERROR;
+               rx_op->debug_status =
+                       *((uint16_t *)(&resp_msg->comn_resp.comn_error));
+       } else {
+               struct icp_qat_fw_resp_comp_pars *comp_resp =
+                 (struct icp_qat_fw_resp_comp_pars *)&resp_msg->comp_resp_pars;
+
+               rx_op->status = RTE_COMP_OP_STATUS_SUCCESS;
+               rx_op->consumed = comp_resp->input_byte_counter;
+               rx_op->produced = comp_resp->output_byte_counter;
+
+               if (qat_xform->checksum_type != RTE_COMP_CHECKSUM_NONE) {
+                       if (qat_xform->checksum_type == RTE_COMP_CHECKSUM_CRC32)
+                               rx_op->output_chksum = comp_resp->curr_crc32;
+                       else if (qat_xform->checksum_type ==
+                                       RTE_COMP_CHECKSUM_ADLER32)
+                               rx_op->output_chksum = comp_resp->curr_adler_32;
+                       else
+                               rx_op->output_chksum = comp_resp->curr_chksum;
+               }
+       }
+       *op = (void *)rx_op;
+
+       return 0;
+}
+
 unsigned int
 qat_comp_xform_size(void)
 {
@@ -196,17 +344,16 @@ qat_comp_private_xform_create(struct rte_compressdev *dev,
                if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED ||
                  ((xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_DEFAULT)
                                   && qat->interm_buff_mz == NULL))
-
                        qat_xform->qat_comp_request_type =
                                        QAT_COMP_REQUEST_FIXED_COMP_STATELESS;
 
+               qat_xform->checksum_type = xform->compress.chksum;
 
        } else {
                qat_xform->qat_comp_request_type = QAT_COMP_REQUEST_DECOMPRESS;
+               qat_xform->checksum_type = xform->decompress.chksum;
        }
 
-       qat_xform->checksum_type = xform->compress.chksum;
-
        if (qat_comp_create_templates(qat_xform, qat->interm_buff_mz, xform)) {
                QAT_LOG(ERR, "QAT: Problem with setting compression");
                return -EINVAL;