Add zsda compressdev dequeue datapath.

Signed-off-by: Hanxiao Li <li.hanx...@zte.com.cn>
---
 drivers/common/zsda/zsda_qp.c         |  56 ++++++++++
 drivers/common/zsda/zsda_qp.h         |   1 +
 drivers/common/zsda/zsda_qp_common.h  |   4 +
 drivers/compress/zsda/zsda_comp.c     | 155 ++++++++++++++++++++++++++
 drivers/compress/zsda/zsda_comp.h     |   9 ++
 drivers/compress/zsda/zsda_comp_pmd.c |  11 +-
 6 files changed, 235 insertions(+), 1 deletion(-)

diff --git a/drivers/common/zsda/zsda_qp.c b/drivers/common/zsda/zsda_qp.c
index c85b9ddb75..0ef7cac585 100644
--- a/drivers/common/zsda/zsda_qp.c
+++ b/drivers/common/zsda/zsda_qp.c
@@ -888,3 +888,59 @@ zsda_enqueue_burst(struct zsda_qp *qp, void **ops, const 
uint16_t nb_ops)
 
        return nb_send;
 }
+
+static void
+zsda_dequeue(struct qp_srv *srv, void **ops, const uint16_t nb_ops, uint16_t 
*nb)
+{
+       uint16_t head;
+       struct zsda_cqe *cqe;
+       struct zsda_queue *queue = &srv->rx_q;
+       struct zsda_op_cookie *cookie;
+       head = queue->head;
+
+       while (*nb < nb_ops) {
+               cqe = (struct zsda_cqe *)(
+                       (uint8_t *)queue->base_addr + head * queue->msg_size);
+
+               if (!CQE_VALID(cqe->err1))
+                       break;
+               cookie = srv->op_cookies[cqe->sid];
+
+               ops[*nb] = cookie->op;
+               if (srv->rx_cb(cookie, cqe) == ZSDA_SUCCESS)
+                       srv->stats.dequeued_count++;
+               else {
+                       ZSDA_LOG(ERR,
+                                "ERR! Cqe, opcode 0x%x, sid 0x%x, "
+                                "tx_real_length 0x%x, err0 0x%x, err1 0x%x",
+                                cqe->op_code, cqe->sid, cqe->tx_real_length,
+                                cqe->err0, cqe->err1);
+                       srv->stats.dequeue_err_count++;
+               }
+               (*nb)++;
+               cookie->used = false;
+
+               head = zsda_modulo_16(head + 1, queue->modulo_mask);
+               queue->head = head;
+               WRITE_CSR_CQ_HEAD(queue->io_addr, queue->hw_queue_number, head);
+               memset(cqe, 0x0, sizeof(struct zsda_cqe));
+       }
+}
+
+uint16_t
+zsda_dequeue_burst(struct zsda_qp *qp, void **ops, const uint16_t nb_ops)
+{
+       uint16_t nb = 0;
+       uint32_t type = 0;
+       struct qp_srv *srv;
+
+       for (type = 0; type < ZSDA_SERVICE_INVALID; type++) {
+               if (!qp->srv[type].used)
+                       continue;
+               srv = &qp->srv[type];
+               zsda_dequeue(srv, ops, nb_ops, &nb);
+               if (nb >= nb_ops)
+                       return nb_ops;
+       }
+       return nb;
+}
diff --git a/drivers/common/zsda/zsda_qp.h b/drivers/common/zsda/zsda_qp.h
index 96fc38ea09..45d37a7905 100644
--- a/drivers/common/zsda/zsda_qp.h
+++ b/drivers/common/zsda/zsda_qp.h
@@ -189,5 +189,6 @@ int zsda_task_queue_setup(struct zsda_pci_device 
*zsda_pci_dev,
                        struct zsda_qp *qp, struct task_queue_info 
*task_q_info);
 
 uint16_t zsda_enqueue_burst(struct zsda_qp *qp, void **ops, const uint16_t 
nb_ops);
+uint16_t zsda_dequeue_burst(struct zsda_qp *qp, void **ops, const uint16_t 
nb_ops);
 
 #endif /* _ZSDA_QP_H_ */
diff --git a/drivers/common/zsda/zsda_qp_common.h 
b/drivers/common/zsda/zsda_qp_common.h
index 49d317d007..be18bd60dd 100644
--- a/drivers/common/zsda/zsda_qp_common.h
+++ b/drivers/common/zsda/zsda_qp_common.h
@@ -51,6 +51,10 @@ enum zsda_service_type {
 #define ZSDA_OPC_DECOMP_ZLIB   0x19 /* Decomp inflate-Zlib */
 #define ZSDA_OPC_INVALID               0xff
 
+#define CQE_VALID(value) (value & 0x8000)
+#define CQE_ERR0(value) (value & 0xFFFF)
+#define CQE_ERR1(value) (value & 0x7FFF)
+
 enum wqe_element_type {
        WQE_ELM_TYPE_PHYS_ADDR = 1,
        WQE_ELM_TYPE_LIST,
diff --git a/drivers/compress/zsda/zsda_comp.c 
b/drivers/compress/zsda/zsda_comp.c
index 608c50c49a..af57c237b2 100644
--- a/drivers/compress/zsda/zsda_comp.c
+++ b/drivers/compress/zsda/zsda_comp.c
@@ -10,6 +10,83 @@
 #define GZIP_TRAILER_SIZE 8
 #define CHECKSUM_SIZE 4
 
+#define POLYNOMIAL 0xEDB88320
+static uint32_t crc32_table[8][256];
+static int table_config;
+
+static void
+crc32_table_build(void)
+{
+       for (uint32_t i = 0; i < 256; i++) {
+               uint32_t crc = i;
+               for (uint32_t j = 0; j < 8; j++)
+                       crc = (crc >> 1) ^ ((crc & 1) ? POLYNOMIAL : 0);
+               crc32_table[0][i] = crc;
+       }
+
+       for (int i = 1; i < 8; i++) {
+               for (uint32_t j = 0; j < 256; j++)
+                       crc32_table[i][j] = (crc32_table[i-1][j] >> 8) ^
+                                       crc32_table[0][crc32_table[i-1][j] & 
0xFF];
+       }
+       table_config = 1;
+}
+
+static uint32_t
+zsda_crc32(const uint8_t *data, size_t length)
+{
+       uint32_t crc = 0xFFFFFFFF;
+
+       if (!table_config)
+               crc32_table_build();
+
+       while (length >= 8) {
+               crc ^= *(const uint32_t *)data;
+               crc = crc32_table[7][crc & 0xFF] ^
+                         crc32_table[6][(crc >> 8) & 0xFF] ^
+                         crc32_table[5][(crc >> 16) & 0xFF] ^
+                         crc32_table[4][(crc >> 24) & 0xFF] ^
+                         crc32_table[3][data[4]] ^
+                         crc32_table[2][data[5]] ^
+                         crc32_table[1][data[6]] ^
+                         crc32_table[0][data[7]];
+
+               data += 8;
+               length -= 8;
+       }
+
+       for (size_t i = 0; i < length; i++)
+               crc = (crc >> 8) ^ crc32_table[0][(crc ^ data[i]) & 0xFF];
+
+       return crc ^ 0xFFFFFFFF;
+}
+
+#define MOD_ADLER 65521
+#define NMAX 5552
+static uint32_t
+zsda_adler32(const uint8_t *buf, uint32_t len)
+{
+       uint32_t s1 = 1;
+       uint32_t s2 = 0;
+
+       while (len > 0) {
+               uint32_t k = (len < NMAX) ? len : NMAX;
+               len -= k;
+
+               for (uint32_t i = 0; i < k; i++) {
+                       s1 += buf[i];
+                       s2 += s1;
+               }
+
+               s1 %= MOD_ADLER;
+               s2 %= MOD_ADLER;
+
+               buf += k;
+       }
+
+       return (s2 << 16) | s1;
+}
+
 int
 zsda_comp_match(const void *op_in)
 {
@@ -231,3 +308,81 @@ zsda_decomp_request_build(void *op_in, const struct 
zsda_queue *queue,
 
        return ret;
 }
+
+static uint32_t
+zsda_chksum_read(uint8_t *data_addr, uint8_t op_code, uint32_t produced)
+{
+       uint8_t *chk_addr;
+       uint32_t chksum = 0;
+       int i = 0;
+
+       if (op_code == ZSDA_OPC_COMP_ZLIB) {
+               chk_addr = data_addr + produced - ZLIB_TRAILER_SIZE;
+               for (i = 0; i < CHECKSUM_SIZE; i++) {
+                       chksum = chksum << 8;
+                       chksum |= (*(chk_addr + i));
+               }
+       } else if (op_code == ZSDA_OPC_COMP_GZIP) {
+               chk_addr = data_addr + produced - GZIP_TRAILER_SIZE;
+               for (i = 0; i < CHECKSUM_SIZE; i++)
+                       chksum |= (*(chk_addr + i) << (i * 8));
+       }
+
+       return chksum;
+}
+
+int
+zsda_comp_callback(void *cookie_in, struct zsda_cqe *cqe)
+{
+       struct zsda_op_cookie *tmp_cookie = cookie_in;
+       struct rte_comp_op *tmp_op = tmp_cookie->op;
+       uint8_t *data_addr =
+               (uint8_t *)tmp_op->m_dst->buf_addr + tmp_op->m_dst->data_off;
+       uint32_t chksum = 0;
+       uint16_t head_len;
+       uint16_t tail_len;
+
+       if (tmp_cookie->decomp_no_tail && CQE_ERR0_RIGHT(cqe->err0))
+               cqe->err0 = 0x0000;
+
+       if (!(CQE_ERR0(cqe->err0) || CQE_ERR1(cqe->err1)))
+               tmp_op->status = RTE_COMP_OP_STATUS_SUCCESS;
+       else {
+               tmp_op->status = RTE_COMP_OP_STATUS_ERROR;
+               return ZSDA_FAILED;
+       }
+
+       /* handle chksum */
+       tmp_op->produced = cqe->tx_real_length;
+       if (cqe->op_code == ZSDA_OPC_COMP_ZLIB) {
+               head_len = ZLIB_HEADER_SIZE;
+               tail_len = ZLIB_TRAILER_SIZE;
+               chksum = zsda_chksum_read(data_addr, cqe->op_code,
+                                                 tmp_op->produced - head_len);
+       }
+       if (cqe->op_code == ZSDA_OPC_COMP_GZIP) {
+               head_len = GZIP_HEADER_SIZE;
+               tail_len = GZIP_TRAILER_SIZE;
+               chksum = zsda_chksum_read(data_addr, cqe->op_code,
+                                                 tmp_op->produced - head_len);
+       } else if (cqe->op_code == ZSDA_OPC_DECOMP_ZLIB) {
+               head_len = ZLIB_HEADER_SIZE;
+               tail_len = ZLIB_TRAILER_SIZE;
+               chksum = zsda_adler32(data_addr, tmp_op->produced);
+       } else if (cqe->op_code == ZSDA_OPC_DECOMP_GZIP) {
+               head_len = GZIP_HEADER_SIZE;
+               tail_len = GZIP_TRAILER_SIZE;
+               chksum = zsda_crc32(data_addr, tmp_op->produced);
+       }
+       tmp_op->output_chksum = chksum;
+
+       if (cqe->op_code == ZSDA_OPC_COMP_ZLIB ||
+               cqe->op_code == ZSDA_OPC_COMP_GZIP) {
+               /* remove tail data*/
+               rte_pktmbuf_trim(tmp_op->m_dst, GZIP_TRAILER_SIZE);
+               /* remove head and tail length */
+               tmp_op->produced = tmp_op->produced - (head_len + tail_len);
+       }
+
+       return ZSDA_SUCCESS;
+}
diff --git a/drivers/compress/zsda/zsda_comp.h 
b/drivers/compress/zsda/zsda_comp.h
index f9e8bc4043..5aeb72a245 100644
--- a/drivers/compress/zsda/zsda_comp.h
+++ b/drivers/compress/zsda/zsda_comp.h
@@ -24,6 +24,14 @@ struct __rte_packed_begin zsda_wqe_comp {
        struct compress_cfg cfg;
 } __rte_packed_end;
 
+/* For situations where err0 are reported but the results are correct */
+#define DECOMP_RIGHT_ERR0_0 0xC710
+#define DECOMP_RIGHT_ERR0_1 0xC727
+#define DECOMP_RIGHT_ERR0_2 0xC729
+#define CQE_ERR0_RIGHT(value)                                                  
\
+       (value == DECOMP_RIGHT_ERR0_0 || value == DECOMP_RIGHT_ERR0_1 ||       \
+        value == DECOMP_RIGHT_ERR0_2)
+
 int zsda_comp_match(const void *op_in);
 int zsda_decomp_match(const void *op_in);
 
@@ -32,5 +40,6 @@ int zsda_comp_request_build(void *op_in, const struct 
zsda_queue *queue,
 
 int zsda_decomp_request_build(void *op_in, const struct zsda_queue *queue,
                         void **op_cookies, const uint16_t new_tail);
+int zsda_comp_callback(void *cookie_in, struct zsda_cqe *cqe);
 
 #endif /* _ZSDA_COMP_H_ */
diff --git a/drivers/compress/zsda/zsda_comp_pmd.c 
b/drivers/compress/zsda/zsda_comp_pmd.c
index d9e444972b..dc8b07f5f7 100644
--- a/drivers/compress/zsda/zsda_comp_pmd.c
+++ b/drivers/compress/zsda/zsda_comp_pmd.c
@@ -243,6 +243,7 @@ zsda_comp_qp_setup(struct rte_compressdev *dev, uint16_t 
qp_id,
        task_q_info.nb_des = nb_des;
        task_q_info.socket_id = socket_id;
        task_q_info.qp_id = qp_id;
+       task_q_info.rx_cb = zsda_comp_callback;
 
        task_q_info.type = ZSDA_SERVICE_COMPRESSION;
        task_q_info.service_str = "comp";
@@ -300,6 +301,14 @@ zsda_comp_pmd_enqueue_op_burst(void *qp, struct 
rte_comp_op **ops,
                                     nb_ops);
 }
 
+static uint16_t
+zsda_comp_pmd_dequeue_op_burst(void *qp, struct rte_comp_op **ops,
+                              uint16_t nb_ops)
+{
+       return zsda_dequeue_burst((struct zsda_qp *)qp, (void **)ops,
+                                    nb_ops);
+}
+
 int
 zsda_comp_dev_create(struct zsda_pci_device *zsda_pci_dev)
 {
@@ -338,7 +347,7 @@ zsda_comp_dev_create(struct zsda_pci_device *zsda_pci_dev)
        compressdev->dev_ops = &compress_zsda_ops;
 
        compressdev->enqueue_burst = zsda_comp_pmd_enqueue_op_burst;
-       compressdev->dequeue_burst = NULL;
+       compressdev->dequeue_burst = zsda_comp_pmd_dequeue_op_burst;
 
        compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
 
-- 
2.27.0

Reply via email to