net/sfc/base: use transceiver ID when reading info
[dpdk.git] / drivers / compress / qat / qat_comp_pmd.c
index 013ff6e..e34c07b 100644 (file)
@@ -5,6 +5,21 @@
 #include "qat_comp.h"
 #include "qat_comp_pmd.h"
 
+static const struct rte_compressdev_capabilities qat_comp_gen_capabilities[] = {
+       {/* COMPRESSION - deflate */
+        .algo = RTE_COMP_ALGO_DEFLATE,
+        .comp_feature_flags = RTE_COMP_FF_MULTI_PKT_CHECKSUM |
+                               RTE_COMP_FF_CRC32_CHECKSUM |
+                               RTE_COMP_FF_ADLER32_CHECKSUM |
+                               RTE_COMP_FF_CRC32_ADLER32_CHECKSUM |
+                               RTE_COMP_FF_SHAREABLE_PRIV_XFORM |
+                               RTE_COMP_FF_HUFFMAN_FIXED |
+                               RTE_COMP_FF_OOP_SGL_IN_SGL_OUT |
+                               RTE_COMP_FF_OOP_SGL_IN_LB_OUT |
+                               RTE_COMP_FF_OOP_LB_IN_SGL_OUT,
+        .window_size = {.min = 15, .max = 15, .increment = 0} },
+       {RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+
 static void
 qat_comp_stats_get(struct rte_compressdev *dev,
                struct rte_compressdev_stats *stats)
@@ -59,7 +74,9 @@ static int
 qat_comp_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
                  uint32_t max_inflight_ops, int socket_id)
 {
+       struct qat_qp *qp;
        int ret = 0;
+       uint32_t i;
        struct qat_qp_config qat_qp_conf;
 
        struct qat_qp **qp_addr =
@@ -97,6 +114,24 @@ qat_comp_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
        qat_private->qat_dev->qps_in_use[QAT_SERVICE_COMPRESSION][qp_id]
                                                        = *qp_addr;
 
+       qp = (struct qat_qp *)*qp_addr;
+
+       for (i = 0; i < qp->nb_descriptors; i++) {
+
+               struct qat_comp_op_cookie *cookie =
+                               qp->op_cookies[i];
+
+               cookie->qat_sgl_src_phys_addr =
+                               rte_mempool_virt2iova(cookie) +
+                               offsetof(struct qat_comp_op_cookie,
+                               qat_sgl_src);
+
+               cookie->qat_sgl_dst_phys_addr =
+                               rte_mempool_virt2iova(cookie) +
+                               offsetof(struct qat_comp_op_cookie,
+                               qat_sgl_dst);
+       }
+
        return ret;
 }
 
@@ -225,22 +260,76 @@ qat_comp_dev_info_get(struct rte_compressdev *dev,
        }
 }
 
-uint16_t
+static uint16_t
 qat_comp_pmd_enqueue_op_burst(void *qp, struct rte_comp_op **ops,
                uint16_t nb_ops)
 {
        return qat_enqueue_op_burst(qp, (void **)ops, nb_ops);
 }
 
-uint16_t
+static uint16_t
 qat_comp_pmd_dequeue_op_burst(void *qp, struct rte_comp_op **ops,
                              uint16_t nb_ops)
 {
        return qat_dequeue_op_burst(qp, (void **)ops, nb_ops);
 }
 
+static uint16_t
+qat_comp_pmd_enq_deq_dummy_op_burst(void *qp __rte_unused,
+                                   struct rte_comp_op **ops __rte_unused,
+                                   uint16_t nb_ops __rte_unused)
+{
+       QAT_DP_LOG(ERR, "QAT PMD detected wrong FW version !");
+       return 0;
+}
 
-struct rte_compressdev_ops compress_qat_ops = {
+static struct rte_compressdev_ops compress_qat_dummy_ops = {
+
+       /* Device related operations */
+       .dev_configure          = NULL,
+       .dev_start              = NULL,
+       .dev_stop               = qat_comp_dev_stop,
+       .dev_close              = qat_comp_dev_close,
+       .dev_infos_get          = NULL,
+
+       .stats_get              = NULL,
+       .stats_reset            = qat_comp_stats_reset,
+       .queue_pair_setup       = NULL,
+       .queue_pair_release     = qat_comp_qp_release,
+
+       /* Compression related operations */
+       .private_xform_create   = NULL,
+       .private_xform_free     = qat_comp_private_xform_free
+};
+
+static uint16_t
+qat_comp_pmd_dequeue_frst_op_burst(void *qp, struct rte_comp_op **ops,
+                                  uint16_t nb_ops)
+{
+       uint16_t ret = qat_dequeue_op_burst(qp, (void **)ops, nb_ops);
+       struct qat_qp *tmp_qp = (struct qat_qp *)qp;
+
+       if (ret) {
+               if ((*ops)->debug_status ==
+                               (uint64_t)ERR_CODE_QAT_COMP_WRONG_FW) {
+                       tmp_qp->qat_dev->comp_dev->compressdev->enqueue_burst =
+                                       qat_comp_pmd_enq_deq_dummy_op_burst;
+                       tmp_qp->qat_dev->comp_dev->compressdev->dequeue_burst =
+                                       qat_comp_pmd_enq_deq_dummy_op_burst;
+
+                       tmp_qp->qat_dev->comp_dev->compressdev->dev_ops =
+                                       &compress_qat_dummy_ops;
+                       QAT_LOG(ERR, "QAT PMD detected wrong FW version !");
+
+               } else {
+                       tmp_qp->qat_dev->comp_dev->compressdev->dequeue_burst =
+                                       qat_comp_pmd_dequeue_op_burst;
+               }
+       }
+       return ret;
+}
+
+static struct rte_compressdev_ops compress_qat_ops = {
 
        /* Device related operations */
        .dev_configure          = qat_comp_dev_config,
@@ -258,3 +347,99 @@ struct rte_compressdev_ops compress_qat_ops = {
        .private_xform_create   = qat_comp_private_xform_create,
        .private_xform_free     = qat_comp_private_xform_free
 };
+
+/* An rte_driver is needed in the registration of the device with compressdev.
+ * The actual qat pci's rte_driver can't be used as its name represents
+ * the whole pci device with all services. Think of this as a holder for a name
+ * for the compression part of the pci device.
+ */
+static const char qat_comp_drv_name[] = RTE_STR(COMPRESSDEV_NAME_QAT_PMD);
+static const struct rte_driver compdev_qat_driver = {
+       .name = qat_comp_drv_name,
+       .alias = qat_comp_drv_name
+};
+int
+qat_comp_dev_create(struct qat_pci_device *qat_pci_dev)
+{
+       if (qat_pci_dev->qat_dev_gen == QAT_GEN1) {
+               QAT_LOG(ERR, "Compression PMD not supported on QAT dh895xcc");
+               return 0;
+       }
+
+       struct rte_compressdev_pmd_init_params init_params = {
+               .name = "",
+               .socket_id = qat_pci_dev->pci_dev->device.numa_node,
+       };
+       char name[RTE_COMPRESSDEV_NAME_MAX_LEN];
+       struct rte_compressdev *compressdev;
+       struct qat_comp_dev_private *comp_dev;
+
+       snprintf(name, RTE_COMPRESSDEV_NAME_MAX_LEN, "%s_%s",
+                       qat_pci_dev->name, "comp");
+       QAT_LOG(DEBUG, "Creating QAT COMP device %s", name);
+
+       /* Populate subset device to use in compressdev device creation */
+       qat_pci_dev->comp_rte_dev.driver = &compdev_qat_driver;
+       qat_pci_dev->comp_rte_dev.numa_node =
+                                       qat_pci_dev->pci_dev->device.numa_node;
+       qat_pci_dev->comp_rte_dev.devargs = NULL;
+
+       compressdev = rte_compressdev_pmd_create(name,
+                       &(qat_pci_dev->comp_rte_dev),
+                       sizeof(struct qat_comp_dev_private),
+                       &init_params);
+
+       if (compressdev == NULL)
+               return -ENODEV;
+
+       compressdev->dev_ops = &compress_qat_ops;
+
+       compressdev->enqueue_burst = qat_comp_pmd_enqueue_op_burst;
+       compressdev->dequeue_burst = qat_comp_pmd_dequeue_frst_op_burst;
+
+       compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
+
+       comp_dev = compressdev->data->dev_private;
+       comp_dev->qat_dev = qat_pci_dev;
+       comp_dev->compressdev = compressdev;
+       qat_pci_dev->comp_dev = comp_dev;
+
+       switch (qat_pci_dev->qat_dev_gen) {
+       case QAT_GEN1:
+       case QAT_GEN2:
+               comp_dev->qat_dev_capabilities = qat_comp_gen_capabilities;
+               break;
+       default:
+               comp_dev->qat_dev_capabilities = qat_comp_gen_capabilities;
+               QAT_LOG(DEBUG,
+                       "QAT gen %d capabilities unknown, default to GEN1",
+                                       qat_pci_dev->qat_dev_gen);
+               break;
+       }
+
+       QAT_LOG(DEBUG,
+                   "Created QAT COMP device %s as compressdev instance %d",
+                       name, compressdev->data->dev_id);
+       return 0;
+}
+
+int
+qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev)
+{
+       struct qat_comp_dev_private *comp_dev;
+
+       if (qat_pci_dev == NULL)
+               return -ENODEV;
+
+       comp_dev = qat_pci_dev->comp_dev;
+       if (comp_dev == NULL)
+               return 0;
+
+       /* clean up any resources used by the device */
+       qat_comp_dev_close(comp_dev->compressdev);
+
+       rte_compressdev_pmd_destroy(comp_dev->compressdev);
+       qat_pci_dev->comp_dev = NULL;
+
+       return 0;
+}