Add sw zlib pmd support in compressdev driver.
Add device probe and remove support.
Update makefile to build zlib.

Signed-off-by: Sunila Sahu <sunila.s...@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.ve...@caviumnetworks.com>
Signed-off-by: Ashish Gupta <ashish.gu...@caviumnetworks.com>
---
 config/common_base                             |   6 ++
 drivers/compress/Makefile                      |   1 +
 drivers/compress/zlib/Makefile                 |  32 ++++++++
 drivers/compress/zlib/rte_pmd_zlib_version.map |   3 +
 drivers/compress/zlib/zlib_pmd.c               | 106 +++++++++++++++++++++++++
 5 files changed, 148 insertions(+)

diff --git a/config/common_base b/config/common_base
index 28557ed..537e9e4 100644
--- a/config/common_base
+++ b/config/common_base
@@ -586,6 +586,12 @@ CONFIG_RTE_COMPRESSDEV_TEST=n
 CONFIG_RTE_LIBRTE_PMD_ISAL=n
 
 #
+# Compile PMD for ZLIB compression device
+#
+CONFIG_RTE_LIBRTE_PMD_ZLIB=n
+CONFIG_RTE_LIBRTE_PMD_ZLIB_DEBUG=n
+
+#
 # Compile generic event device library
 #
 CONFIG_RTE_LIBRTE_EVENTDEV=y
diff --git a/drivers/compress/Makefile b/drivers/compress/Makefile
index 592497f..1f159a5 100644
--- a/drivers/compress/Makefile
+++ b/drivers/compress/Makefile
@@ -4,5 +4,6 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_ISAL) += isal
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_ZLIB) += zlib
 
 include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/drivers/compress/zlib/Makefile b/drivers/compress/zlib/Makefile
new file mode 100644
index 0000000..e613960
--- /dev/null
+++ b/drivers/compress/zlib/Makefile
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Cavium Networks
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_pmd_zlib.a
+
+# build flags
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
+# library version
+LIBABIVER := 1
+
+# versioning export map
+EXPORT_MAP := rte_pmd_zlib_version.map
+
+# external library dependencies
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring -lz
+LDLIBS += -lrte_compressdev
+LDLIBS += -lrte_bus_vdev
+
+# library source files
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_ZLIB) += zlib_pmd.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_ZLIB) += zlib_pmd_ops.c
+
+# export include files
+SYMLINK-y-include +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/compress/zlib/rte_pmd_zlib_version.map 
b/drivers/compress/zlib/rte_pmd_zlib_version.map
new file mode 100644
index 0000000..33c1b97
--- /dev/null
+++ b/drivers/compress/zlib/rte_pmd_zlib_version.map
@@ -0,0 +1,3 @@
+EXPERIMENTAL {
+       local: *;
+};
diff --git a/drivers/compress/zlib/zlib_pmd.c b/drivers/compress/zlib/zlib_pmd.c
new file mode 100644
index 0000000..bbf49f1
--- /dev/null
+++ b/drivers/compress/zlib/zlib_pmd.c
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017-2018 Cavium Networks
+ */
+
+#include <rte_common.h>
+#include <rte_hexdump.h>
+#include <rte_comp.h>
+#include <rte_compressdev.h>
+#include <rte_compressdev_pmd.h>
+#include <rte_bus_vdev.h>
+#include <rte_malloc.h>
+#include <rte_cpuflags.h>
+#include <rte_byteorder.h>
+
+#include <math.h>
+#include <assert.h>
+#include "zlib_pmd_private.h"
+
+static uint8_t compressdev_driver_id;
+int zlib_logtype_driver;
+
+static int zlib_remove(struct rte_vdev_device *vdev);
+
+static int
+zlib_create(const char *name,
+               struct rte_vdev_device *vdev,
+               struct rte_compressdev_pmd_init_params *init_params)
+{
+       struct rte_compressdev *dev;
+       struct zlib_private *internals;
+
+       dev = rte_compressdev_pmd_create(name, &vdev->device,
+                       sizeof(struct zlib_private), init_params);
+       if (dev == NULL) {
+               ZLIB_LOG_ERR("driver %s: create failed", init_params->name);
+               return -ENODEV;
+       }
+
+       dev->driver_id = compressdev_driver_id;
+       dev->dev_ops = rte_zlib_pmd_ops;
+
+       dev->feature_flags = 0;
+       dev->feature_flags |= RTE_COMP_FF_SHAREABLE_PRIV_XFORM |
+                               RTE_COMP_FF_NONCOMPRESSED_BLOCKS |
+                               RTE_COMP_FF_ADLER32_CHECKSUM;
+
+       internals = dev->data->dev_private;
+       internals->max_nb_queue_pairs = ZLIB_PMD_MAX_NB_QUEUE_PAIRS;
+
+       return 0;
+}
+
+static int
+zlib_probe(struct rte_vdev_device *vdev)
+{
+       struct rte_compressdev_pmd_init_params init_params = {
+               "",
+               rte_socket_id()
+       };
+       const char *name;
+       const char *input_args;
+
+       name = rte_vdev_device_name(vdev);
+
+       if (name == NULL)
+               return -EINVAL;
+       input_args = rte_vdev_device_args(vdev);
+       rte_compressdev_pmd_parse_input_args(&init_params, input_args);
+
+       return zlib_create(name, vdev, &init_params);
+}
+
+static int
+zlib_remove(struct rte_vdev_device *vdev)
+{
+       struct rte_compressdev *compressdev;
+       const char *name;
+
+       name = rte_vdev_device_name(vdev);
+       if (name == NULL)
+               return -EINVAL;
+
+       compressdev = rte_compressdev_pmd_get_named_dev(name);
+       if (compressdev == NULL)
+               return -ENODEV;
+
+       return rte_compressdev_pmd_destroy(compressdev);
+}
+
+static struct rte_vdev_driver zlib_pmd_drv = {
+       .probe = zlib_probe,
+       .remove = zlib_remove
+};
+
+RTE_PMD_REGISTER_VDEV(COMPRESSDEV_NAME_ZLIB_PMD, zlib_pmd_drv);
+RTE_PMD_REGISTER_ALIAS(COMPRESSDEV_NAME_ZLIB_PMD, compressdev_zlib_pmd);
+
+RTE_INIT(zlib_init_log);
+
+static void
+zlib_init_log(void)
+{
+       zlib_logtype_driver = rte_log_register("compress_zlib");
+       if (zlib_logtype_driver >= 0)
+               rte_log_set_level(zlib_logtype_driver, RTE_LOG_INFO);
+}
-- 
2.9.5

Reply via email to