Add zsda compressdev dequeue datapath.<br /> <br />Signed-off-by: Hanxiao Li <li.hanxiao@zte.com.cn> <br />---<br /> drivers/common/zsda/zsda_qp.c         |  55 +++++++++<br /> drivers/common/zsda/zsda_qp.h         |   1 +<br /> drivers/common/zsda/zsda_qp_common.h  |   4 +<br /> drivers/compress/zsda/zsda_comp.c     | 155 ++++++++++++++++++++++++++<br /> drivers/compress/zsda/zsda_comp.h     |   9 ++<br /> drivers/compress/zsda/zsda_comp_pmd.c |  14 ++-<br /> 6 files changed, 235 insertions(+), 3 deletions(-)<br /> <br />diff --git a/drivers/common/zsda/zsda_qp.c b/drivers/common/zsda/zsda_qp.c<br />index c2a7d9b28b..fd45558868 100644<br />--- a/drivers/common/zsda/zsda_qp.c<br />+++ b/drivers/common/zsda/zsda_qp.c<br />@@ -878,3 +878,58 @@ zsda_enqueue_op_burst(struct zsda_qp *qp, void **ops, const uint16_t nb_ops)<br />     return nb_send;<br /> }<br />  <br />+static void<br />+zsda_dequeue(struct qp_srv *srv, void **ops, const uint16_t nb_ops, uint16_t *nb)<br />+{<br />+    uint16_t head;<br />+    struct zsda_cqe *cqe;<br />+    struct zsda_queue *queue = &srv->rx_q;<br />+    struct zsda_op_cookie *cookie;<br />+    head = queue->head;<br />+<br />+    while (*nb < nb_ops) {<br />+        cqe = (struct zsda_cqe *)(<br />+            (uint8_t *)queue->base_addr + head * queue->msg_size);<br />+<br />+        if (!CQE_VALID(cqe->err1))<br />+            break;<br />+        cookie = srv->op_cookies[cqe->sid];<br />+<br />+        ops[*nb] = cookie->op;<br />+        if (srv->rx_cb(cookie, cqe) == ZSDA_SUCCESS)<br />+            srv->stats.dequeued_count++;<br />+        else {<br />+            ZSDA_LOG(ERR,<br />+                 "ERR! Cqe, opcode 0x%x, sid 0x%x, " <br />+                 "tx_real_length 0x%x, err0 0x%x, err1 0x%x",<br />+                 cqe->op_code, cqe->sid, cqe->tx_real_length,<br />+                 cqe->err0, cqe->err1);<br />+            srv->stats.dequeue_err_count++;<br />+        }<br />+        (*nb)++;<br />+        cookie->used = false;<br />+<br />+        head = zsda_modulo_16(head + 1, queue->modulo_mask);<br />+        queue->head = head;<br />+        WRITE_CSR_CQ_HEAD(queue->io_addr, queue->hw_queue_number, head);<br />+        memset(cqe, 0x0, sizeof(struct zsda_cqe));<br />+    }<br />+}<br />+<br />+uint16_t<br />+zsda_dequeue_op_burst(struct zsda_qp *qp, void **ops, const uint16_t nb_ops)<br />+{<br />+    uint16_t nb = 0;<br />+    uint32_t type = 0;<br />+    struct qp_srv *srv;<br />+<br />+    for (type = 0; type < ZSDA_SERVICE_INVALID; type++) {<br />+        if (!qp->srv[type].used)<br />+            continue;<br />+        srv = &qp->srv[type];<br />+        zsda_dequeue(srv, ops, nb_ops, &nb);<br />+        if (nb >= nb_ops)<br />+            return nb_ops;<br />+    }<br />+    return nb;<br />+}<br />diff --git a/drivers/common/zsda/zsda_qp.h b/drivers/common/zsda/zsda_qp.h<br />index 012ed19c62..931953b61c 100644<br />--- a/drivers/common/zsda/zsda_qp.h<br />+++ b/drivers/common/zsda/zsda_qp.h<br />@@ -177,5 +177,6 @@ int zsda_common_setup_qp(uint32_t dev_id, struct zsda_qp **qp_addr,<br />         const uint16_t queue_pair_id, const struct zsda_qp_config *conf);<br />  <br /> uint16_t zsda_enqueue_op_burst(struct zsda_qp *qp, void **ops, const uint16_t nb_ops);<br />+uint16_t zsda_dequeue_op_burst(struct zsda_qp *qp, void **ops, const uint16_t nb_ops);<br />  <br /> #endif /* _ZSDA_QP_H_ */<br />diff --git a/drivers/common/zsda/zsda_qp_common.h b/drivers/common/zsda/zsda_qp_common.h<br />index c67de6b04d..2fd1f9e7fd 100644<br />--- a/drivers/common/zsda/zsda_qp_common.h<br />+++ b/drivers/common/zsda/zsda_qp_common.h<br />@@ -47,6 +47,10 @@ enum zsda_service_type {<br /> #define ZSDA_OPC_DECOMP_ZLIB    0x19 /* Decompinfalte-Zlib */<br /> #define ZSDA_OPC_INVALID        0xff<br />  <br />+#define CQE_VALID(value) (value & 0x8000)<br />+#define CQE_ERR0(value) (value & 0xFFFF)<br />+#define CQE_ERR1(value) (value & 0x7FFF)<br />+<br /> enum wqe_element_type {<br />     WQE_ELM_TYPE_PHYS_ADDR = 1,<br />     WQE_ELM_TYPE_LIST,<br />diff --git a/drivers/compress/zsda/zsda_comp.c b/drivers/compress/zsda/zsda_comp.c<br />index c00e0c2a4b..c22d690e5e 100644<br />--- a/drivers/compress/zsda/zsda_comp.c<br />+++ b/drivers/compress/zsda/zsda_comp.c<br />@@ -10,6 +10,83 @@<br /> #define GZIP_TRAILER_SIZE 8<br /> #define CHECKSUM_SIZE 4<br />  <br />+#define POLYNOMIAL 0xEDB88320<br />+static uint32_t crc32_table[8][256];<br />+static int table_config;<br />+<br />+static void<br />+build_crc32_table(void)<br />+{<br />+    for (uint32_t i = 0; i < 256; i++) {<br />+        uint32_t crc = i;<br />+        for (uint32_t j = 0; j < 8; j++)<br />+            crc = (crc >> 1) ^ ((crc & 1) ? POLYNOMIAL : 0);<br />+        crc32_table[0][i] = crc;<br />+    }<br />+<br />+    for (int i = 1; i < 8; i++) {<br />+        for (uint32_t j = 0; j < 256; j++)<br />+            crc32_table[i][j] = (crc32_table[i-1][j] >> 8) ^<br />+                    crc32_table[0][crc32_table[i-1][j] & 0xFF];<br />+    }<br />+    table_config = 1;<br />+}<br />+<br />+static uint32_t<br />+zsda_crc32(const uint8_t *data, size_t length)<br />+{<br />+    uint32_t crc = 0xFFFFFFFF;<br />+<br />+    if (!table_config)<br />+        build_crc32_table();<br />+<br />+    while (length >= 8) {<br />+        crc ^= *(const uint32_t *)data;<br />+        crc = crc32_table[7][crc & 0xFF] ^<br />+              crc32_table[6][(crc >> 8) & 0xFF] ^<br />+              crc32_table[5][(crc >> 16) & 0xFF] ^<br />+              crc32_table[4][(crc >> 24) & 0xFF] ^<br />+              crc32_table[3][data[4]] ^<br />+              crc32_table[2][data[5]] ^<br />+              crc32_table[1][data[6]] ^<br />+              crc32_table[0][data[7]];<br />+<br />+        data += 8;<br />+        length -= 8;<br />+    }<br />+<br />+    for (size_t i = 0; i < length; i++)<br />+        crc = (crc >> 8) ^ crc32_table[0][(crc ^ data[i]) & 0xFF];<br />+<br />+    return crc ^ 0xFFFFFFFF;<br />+}<br />+<br />+#define MOD_ADLER 65521<br />+#define NMAX 5552<br />+static uint32_t<br />+zsda_adler32(const uint8_t *buf, uint32_t len)<br />+{<br />+    uint32_t s1 = 1;<br />+    uint32_t s2 = 0;<br />+<br />+    while (len > 0) {<br />+        uint32_t k = (len < NMAX) ? len : NMAX;<br />+        len -= k;<br />+<br />+        for (uint32_t i = 0; i < k; i++) {<br />+            s1 += buf[i];<br />+            s2 += s1;<br />+        }<br />+<br />+        s1 %= MOD_ADLER;<br />+        s2 %= MOD_ADLER;<br />+<br />+        buf += k;<br />+    }<br />+<br />+    return (s2 << 16) | s1;<br />+}<br />+<br /> int<br /> zsda_comp_match(const void *op_in)<br /> {<br />@@ -231,3 +308,81 @@ zsda_build_decomp_request(void *op_in, const struct zsda_queue *queue,<br />  <br />     return ret;<br /> }<br />+<br />+static uint32_t<br />+zsda_read_chksum(uint8_t *data_addr, uint8_t op_code, uint32_t produced)<br />+{<br />+    uint8_t *chk_addr;<br />+    uint32_t chksum = 0;<br />+    int i = 0;<br />+<br />+    if (op_code == ZSDA_OPC_COMP_ZLIB) {<br />+        chk_addr = data_addr + produced - ZLIB_TRAILER_SIZE;<br />+        for (i = 0; i < CHECKSUM_SIZE; i++) {<br />+            chksum = chksum << 8;<br />+            chksum |= (*(chk_addr + i));<br />+        }<br />+    } else if (op_code == ZSDA_OPC_COMP_GZIP) {<br />+        chk_addr = data_addr + produced - GZIP_TRAILER_SIZE;<br />+        for (i = 0; i < CHECKSUM_SIZE; i++)<br />+            chksum |= (*(chk_addr + i) << (i * 8));<br />+    }<br />+<br />+    return chksum;<br />+}<br />+<br />+int<br />+zsda_comp_callback(void *cookie_in, struct zsda_cqe *cqe)<br />+{<br />+    struct zsda_op_cookie *tmp_cookie = cookie_in;<br />+    struct rte_comp_op *tmp_op = tmp_cookie->op;<br />+    uint8_t *data_addr =<br />+        (uint8_t *)tmp_op->m_dst->buf_addr + tmp_op->m_dst->data_off;<br />+    uint32_t chksum = 0;<br />+    uint16_t head_len;<br />+    uint16_t tail_len;<br />+<br />+    if (tmp_cookie->decomp_no_tail && CQE_ERR0_RIGHT(cqe->err0))<br />+        cqe->err0 = 0x0000;<br />+<br />+    if (!(CQE_ERR0(cqe->err0) || CQE_ERR1(cqe->err1)))<br />+        tmp_op->status = RTE_COMP_OP_STATUS_SUCCESS;<br />+    else {<br />+        tmp_op->status = RTE_COMP_OP_STATUS_ERROR;<br />+        return ZSDA_FAILED;<br />+    }<br />+<br />+    /* handle chksum */<br />+    tmp_op->produced = cqe->tx_real_length;<br />+    if (cqe->op_code == ZSDA_OPC_COMP_ZLIB) {<br />+        head_len = ZLIB_HEADER_SIZE;<br />+        tail_len = ZLIB_TRAILER_SIZE;<br />+        chksum = zsda_read_chksum(data_addr, cqe->op_code,<br />+                          tmp_op->produced - head_len);<br />+    }<br />+    if (cqe->op_code == ZSDA_OPC_COMP_GZIP) {<br />+        head_len = GZIP_HEADER_SIZE;<br />+        tail_len = GZIP_TRAILER_SIZE;<br />+        chksum = zsda_read_chksum(data_addr, cqe->op_code,<br />+                          tmp_op->produced - head_len);<br />+    } else if (cqe->op_code == ZSDA_OPC_DECOMP_ZLIB) {<br />+        head_len = ZLIB_HEADER_SIZE;<br />+        tail_len = ZLIB_TRAILER_SIZE;<br />+        chksum = zsda_adler32(data_addr, tmp_op->produced);<br />+    } else if (cqe->op_code == ZSDA_OPC_DECOMP_GZIP) {<br />+        head_len = GZIP_HEADER_SIZE;<br />+        tail_len = GZIP_TRAILER_SIZE;<br />+        chksum = zsda_crc32(data_addr, tmp_op->produced);<br />+    }<br />+    tmp_op->output_chksum = chksum;<br />+<br />+    if (cqe->op_code == ZSDA_OPC_COMP_ZLIB ||<br />+        cqe->op_code == ZSDA_OPC_COMP_GZIP) {<br />+        /* remove tail data*/<br />+        rte_pktmbuf_trim(tmp_op->m_dst, GZIP_TRAILER_SIZE);<br />+        /* remove head and tail length */<br />+        tmp_op->produced = tmp_op->produced - (head_len + tail_len);<br />+    }<br />+<br />+    return ZSDA_SUCCESS;<br />+}<br />diff --git a/drivers/compress/zsda/zsda_comp.h b/drivers/compress/zsda/zsda_comp.h<br />index e7dea7e5a4..bb2feecb31 100644<br />--- a/drivers/compress/zsda/zsda_comp.h<br />+++ b/drivers/compress/zsda/zsda_comp.h<br />@@ -24,6 +24,14 @@ struct zsda_wqe_comp {<br />     struct compress_cfg cfg;<br /> } __rte_packed;<br />  <br />+/* For situations where err0 are reported but the results are correct */<br />+#define DECOMP_RIGHT_ERR0_0 0xC710<br />+#define DECOMP_RIGHT_ERR0_1 0xC727<br />+#define DECOMP_RIGHT_ERR0_2 0xC729<br />+#define CQE_ERR0_RIGHT(value)                                                  \<br />+    (value == DECOMP_RIGHT_ERR0_0 || value == DECOMP_RIGHT_ERR0_1 ||       \<br />+     value == DECOMP_RIGHT_ERR0_2)<br />+<br /> int zsda_comp_match(const void *op_in);<br /> int zsda_decomp_match(const void *op_in);<br />  <br />@@ -32,5 +40,6 @@ int zsda_build_comp_request(void *op_in, const struct zsda_queue *queue,<br />  <br /> int zsda_build_decomp_request(void *op_in, const struct zsda_queue *queue,<br />              void **op_cookies, const uint16_t new_tail);<br />+int zsda_comp_callback(void *cookie_in, struct zsda_cqe *cqe);<br />  <br /> #endif /* _ZSDA_COMP_H_ */<br />diff --git a/drivers/compress/zsda/zsda_comp_pmd.c b/drivers/compress/zsda/zsda_comp_pmd.c<br />index 9cb2169d68..ea3de2f505 100644<br />--- a/drivers/compress/zsda/zsda_comp_pmd.c<br />+++ b/drivers/compress/zsda/zsda_comp_pmd.c<br />@@ -229,7 +229,7 @@ zsda_setup_comp_queue(struct zsda_pci_device *zsda_pci_dev, const uint16_t qp_id<br />     conf.service_str = "comp";<br />  <br />     ret = zsda_common_setup_qp(zsda_pci_dev->zsda_dev_id, &qp, qp_id, &conf);<br />-    qp->srv[type].rx_cb = NULL;<br />+    qp->srv[type].rx_cb = zsda_comp_callback;<br />     qp->srv[type].tx_cb = zsda_build_comp_request;<br />     qp->srv[type].match = zsda_comp_match;<br />  <br />@@ -254,7 +254,7 @@ zsda_setup_decomp_queue(struct zsda_pci_device *zsda_pci_dev, const uint16_t qp_<br />     conf.service_str = "decomp";<br />  <br />     ret = zsda_common_setup_qp(zsda_pci_dev->zsda_dev_id, &qp, qp_id, &conf);<br />-    qp->srv[type].rx_cb = NULL;<br />+    qp->srv[type].rx_cb = zsda_comp_callback;<br />     qp->srv[type].tx_cb = zsda_build_decomp_request;<br />     qp->srv[type].match = zsda_decomp_match;<br />  <br />@@ -348,6 +348,14 @@ zsda_comp_pmd_enqueue_op_burst(void *qp, struct rte_comp_op **ops,<br />                      nb_ops);<br /> }<br />  <br />+static uint16_t<br />+zsda_comp_pmd_dequeue_op_burst(void *qp, struct rte_comp_op **ops,<br />+                   uint16_t nb_ops)<br />+{<br />+    return zsda_dequeue_op_burst((struct zsda_qp *)qp, (void **)ops,<br />+                     nb_ops);<br />+}<br />+<br /> int<br /> zsda_comp_dev_create(struct zsda_pci_device *zsda_pci_dev)<br /> {<br />@@ -386,7 +394,7 @@ zsda_comp_dev_create(struct zsda_pci_device *zsda_pci_dev)<br />     compressdev->dev_ops = &compress_zsda_ops;<br />  <br />     compressdev->enqueue_burst = zsda_comp_pmd_enqueue_op_burst;<br />-    compressdev->dequeue_burst = NULL;<br />+    compressdev->dequeue_burst = zsda_comp_pmd_dequeue_op_burst;<br />  <br />     compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;<br />  <br />--  <br />2.27.0<br />