New upstream version 18.11.1
[deb_dpdk.git] / drivers / compress / qat / qat_comp.c
index 38c8a5b..450cfd6 100644 (file)
@@ -36,6 +36,7 @@ qat_comp_build_request(void *in_op, uint8_t *out_msg,
                QAT_DP_LOG(ERR, "QAT PMD only supports stateless compression "
                                "operation requests, op (%p) is not a "
                                "stateless operation.", op);
+               op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
                return -EINVAL;
        }
 
@@ -61,6 +62,7 @@ qat_comp_build_request(void *in_op, uint8_t *out_msg,
                                RTE_PMD_QAT_COMP_SGL_MAX_SEGMENTS);
                if (ret) {
                        QAT_DP_LOG(ERR, "QAT PMD Cannot fill source sgl array");
+                       op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
                        return ret;
                }
 
@@ -71,6 +73,7 @@ qat_comp_build_request(void *in_op, uint8_t *out_msg,
                                RTE_PMD_QAT_COMP_SGL_MAX_SEGMENTS);
                if (ret) {
                        QAT_DP_LOG(ERR, "QAT PMD Cannot fill dest. sgl array");
+                       op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
                        return ret;
                }
 
@@ -106,7 +109,7 @@ qat_comp_build_request(void *in_op, uint8_t *out_msg,
 }
 
 int
-qat_comp_process_response(void **op, uint8_t *resp)
+qat_comp_process_response(void **op, uint8_t *resp, uint64_t *dequeue_err_count)
 {
        struct icp_qat_fw_comp_resp *resp_msg =
                        (struct icp_qat_fw_comp_resp *)resp;
@@ -114,6 +117,9 @@ qat_comp_process_response(void **op, uint8_t *resp)
                        (resp_msg->opaque_data);
        struct qat_comp_xform *qat_xform = (struct qat_comp_xform *)
                                (rx_op->private_xform);
+       int err = resp_msg->comn_resp.comn_status &
+                       ((1 << QAT_COMN_RESP_CMP_STATUS_BITPOS) |
+                        (1 << QAT_COMN_RESP_XLAT_STATUS_BITPOS));
 
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
        QAT_DP_LOG(DEBUG, "Direction: %s",
@@ -132,20 +138,39 @@ qat_comp_process_response(void **op, uint8_t *resp)
                        rx_op->debug_status = ERR_CODE_QAT_COMP_WRONG_FW;
                        *op = (void *)rx_op;
                        QAT_DP_LOG(ERR, "QAT has wrong firmware");
+                       ++(*dequeue_err_count);
                        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) {
+       if (err) {
+               if (unlikely((err & (1 << QAT_COMN_RESP_XLAT_STATUS_BITPOS))
+                            && (qat_xform->qat_comp_request_type
+                                == QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS))) {
+                       QAT_DP_LOG(ERR, "QAT intermediate buffer may be too "
+                           "small for output, try configuring a larger size");
+               }
+
+               int8_t cmp_err_code =
+                       (int8_t)resp_msg->comn_resp.comn_error.cmp_err_code;
+               int8_t xlat_err_code =
+                       (int8_t)resp_msg->comn_resp.comn_error.xlat_err_code;
+
+               if ((cmp_err_code == ERR_CODE_OVERFLOW_ERROR && !xlat_err_code)
+                               ||
+                   (!cmp_err_code && xlat_err_code == ERR_CODE_OVERFLOW_ERROR)
+                               ||
+                   (cmp_err_code == ERR_CODE_OVERFLOW_ERROR &&
+                    xlat_err_code == ERR_CODE_OVERFLOW_ERROR))
+                       rx_op->status =
+                               RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
+               else
+                       rx_op->status = RTE_COMP_OP_STATUS_ERROR;
 
-               rx_op->status = RTE_COMP_OP_STATUS_ERROR;
+               ++(*dequeue_err_count);
                rx_op->debug_status =
                        *((uint16_t *)(&resp_msg->comn_resp.comn_error));
        } else {
-               struct qat_comp_xform *qat_xform = rx_op->private_xform;
                struct icp_qat_fw_resp_comp_pars *comp_resp =
                  (struct icp_qat_fw_resp_comp_pars *)&resp_msg->comp_resp_pars;
 
@@ -193,7 +218,7 @@ static void qat_comp_create_req_hdr(struct icp_qat_fw_comn_req_hdr *header,
 }
 
 static int qat_comp_create_templates(struct qat_comp_xform *qat_xform,
-                       const struct rte_memzone *interm_buff_mz __rte_unused,
+                       const struct rte_memzone *interm_buff_mz,
                        const struct rte_comp_xform *xform)
 {
        struct icp_qat_fw_comp_req *comp_req;
@@ -281,10 +306,20 @@ static int qat_comp_create_templates(struct qat_comp_xform *qat_xform,
                ICP_QAT_FW_COMN_CURR_ID_SET(&comp_req->comp_cd_ctrl,
                                            ICP_QAT_FW_SLICE_COMP);
        } else if (qat_xform->qat_comp_request_type ==
-                  QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS) {
+                       QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS) {
 
-               QAT_LOG(ERR, "Dynamic huffman encoding not supported");
-               return -EINVAL;
+               ICP_QAT_FW_COMN_NEXT_ID_SET(&comp_req->comp_cd_ctrl,
+                               ICP_QAT_FW_SLICE_XLAT);
+               ICP_QAT_FW_COMN_CURR_ID_SET(&comp_req->comp_cd_ctrl,
+                               ICP_QAT_FW_SLICE_COMP);
+
+               ICP_QAT_FW_COMN_NEXT_ID_SET(&comp_req->u2.xlt_cd_ctrl,
+                               ICP_QAT_FW_SLICE_DRAM_WR);
+               ICP_QAT_FW_COMN_CURR_ID_SET(&comp_req->u2.xlt_cd_ctrl,
+                               ICP_QAT_FW_SLICE_XLAT);
+
+               comp_req->u1.xlt_pars.inter_buff_ptr =
+                               interm_buff_mz->phys_addr;
        }
 
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
@@ -335,27 +370,35 @@ qat_comp_private_xform_create(struct rte_compressdev *dev,
                        (struct qat_comp_xform *)*private_xform;
 
        if (xform->type == RTE_COMP_COMPRESS) {
-               if (xform->compress.deflate.huffman ==
-                               RTE_COMP_HUFFMAN_DYNAMIC) {
-                       QAT_LOG(ERR,
-                       "QAT device doesn't support dynamic compression");
-                       return -ENOTSUP;
-               }
 
                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;
 
+               else if ((xform->compress.deflate.huffman ==
+                               RTE_COMP_HUFFMAN_DYNAMIC ||
+                               xform->compress.deflate.huffman ==
+                                               RTE_COMP_HUFFMAN_DEFAULT) &&
+                               qat->interm_buff_mz != NULL)
+
+                       qat_xform->qat_comp_request_type =
+                                       QAT_COMP_REQUEST_DYNAMIC_COMP_STATELESS;
+
+               else {
+                       QAT_LOG(ERR,
+                                       "IM buffers needed for dynamic deflate. Set size in config file");
+                       return -EINVAL;
+               }
+
+               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;