DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/3] Introduce UADK compression driver
@ 2024-04-22 14:30 Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 1/3] compress/uadk: " Zhangfei Gao
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Zhangfei Gao @ 2024-04-22 14:30 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Ashish Gupta; +Cc: dev, Zhangfei Gao

Introduce a new compress PMD for hardware accelerators based on UADK [1].

UADK is a framework for user applications to access hardware accelerators.
UADK relies on IOMMU SVA (Shared Virtual Address) feature, which share
the same page table between IOMMU and MMU.
Thereby user application can directly use virtual address for device dma,
which enhances the performance as well as easy usability.

Besides, crypto PMD is under drivers/crypto/uadk/

[1] https://github.com/Linaro/uadk

Test:
sudo dpdk-test --vdev=compress_uadk
RTE>>compressdev_autotest
RTE>>quit

dd if=/dev/random of=data bs=1M count=1;
sudo dpdk-test-compress-perf -l 1,2 --vdev compress_uadk \
	-- --driver-name compress_uadk --input-file data


Zhangfei Gao (3):
  compress/uadk: Introduce UADK compression driver
  compress/uadk: support basic operations
  compress/uadk: support burst enqueue/dequeue

 MAINTAINERS                                   |   6 +
 doc/guides/compressdevs/features/uadk.ini     |  11 +
 doc/guides/compressdevs/index.rst             |   1 +
 doc/guides/compressdevs/uadk.rst              |  98 ++++
 doc/guides/rel_notes/release_24_07.rst        |   5 +
 drivers/compress/meson.build                  |   1 +
 drivers/compress/uadk/meson.build             |  30 ++
 drivers/compress/uadk/uadk_compress_pmd.c     | 476 ++++++++++++++++++
 .../compress/uadk/uadk_compress_pmd_private.h |  36 ++
 9 files changed, 664 insertions(+)
 create mode 100644 doc/guides/compressdevs/features/uadk.ini
 create mode 100644 doc/guides/compressdevs/uadk.rst
 create mode 100644 drivers/compress/uadk/meson.build
 create mode 100644 drivers/compress/uadk/uadk_compress_pmd.c
 create mode 100644 drivers/compress/uadk/uadk_compress_pmd_private.h

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] compress/uadk: Introduce UADK compression driver
  2024-04-22 14:30 [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
@ 2024-04-22 14:31 ` Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 2/3] compress/uadk: support basic operations Zhangfei Gao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Zhangfei Gao @ 2024-04-22 14:31 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Ashish Gupta; +Cc: dev, Zhangfei Gao

Introduce a new compression & decompression PMD for hardware accelerators
based on UADK [1].

UADK is a framework for user applications to access hardware accelerators.
UADK relies on IOMMU SVA (Shared Virtual Address) feature, which shares
the same page table between IOMMU and MMU.
Thereby user application can directly use the virtual address for the
device DMA, which enhances the performance as well as easy usability.

This patch adds the basic framework.

Test:
sudo dpdk-test --vdev=compress_uadk
RTE>>compressdev_autotest
RTE>>quit

[1] https://github.com/Linaro/uadk

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
 MAINTAINERS                                   |  6 ++
 doc/guides/compressdevs/features/uadk.ini     | 11 +++
 doc/guides/compressdevs/index.rst             |  1 +
 doc/guides/compressdevs/uadk.rst              | 98 +++++++++++++++++++
 doc/guides/rel_notes/release_24_07.rst        |  5 +
 drivers/compress/meson.build                  |  1 +
 drivers/compress/uadk/meson.build             | 30 ++++++
 drivers/compress/uadk/uadk_compress_pmd.c     | 89 +++++++++++++++++
 .../compress/uadk/uadk_compress_pmd_private.h | 20 ++++
 9 files changed, 261 insertions(+)
 create mode 100644 doc/guides/compressdevs/features/uadk.ini
 create mode 100644 doc/guides/compressdevs/uadk.rst
 create mode 100644 drivers/compress/uadk/meson.build
 create mode 100644 drivers/compress/uadk/uadk_compress_pmd.c
 create mode 100644 drivers/compress/uadk/uadk_compress_pmd_private.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 7abb3aee49..4f1f640004 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1212,6 +1212,12 @@ F: drivers/compress/octeontx/
 F: doc/guides/compressdevs/octeontx.rst
 F: doc/guides/compressdevs/features/octeontx.ini
 
+HiSilicon UADK compress
+M: Zhangfei Gao <zhangfei.gao@linaro.org>
+F: drivers/compress/uadk/
+F: doc/guides/compressdevs/uadk.rst
+F: doc/guides/compressdevs/features/uadk.ini
+
 Intel QuickAssist
 M: Kai Ji <kai.ji@intel.com>
 F: drivers/compress/qat/
diff --git a/doc/guides/compressdevs/features/uadk.ini b/doc/guides/compressdevs/features/uadk.ini
new file mode 100644
index 0000000000..0bbdb6c5cf
--- /dev/null
+++ b/doc/guides/compressdevs/features/uadk.ini
@@ -0,0 +1,11 @@
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+; Supported features of 'uadk' compression driver.
+;
+[Features]
+HW Accelerated = Y
+Deflate        = Y
+Crc32          = N
+Fixed          = Y
+Dynamic        = Y
diff --git a/doc/guides/compressdevs/index.rst b/doc/guides/compressdevs/index.rst
index 849f211688..87ed4f72a4 100644
--- a/doc/guides/compressdevs/index.rst
+++ b/doc/guides/compressdevs/index.rst
@@ -15,4 +15,5 @@ Compression Device Drivers
     nitrox
     octeontx
     qat_comp
+    uadk
     zlib
diff --git a/doc/guides/compressdevs/uadk.rst b/doc/guides/compressdevs/uadk.rst
new file mode 100644
index 0000000000..7e7f9f2548
--- /dev/null
+++ b/doc/guides/compressdevs/uadk.rst
@@ -0,0 +1,98 @@
+.. SPDX-License-Identifier: BSD-3-Clause
+   Copyright 2024-2025 Huawei Technologies Co.,Ltd. All rights reserved.
+   Copyright 2024-2025 Linaro ltd.
+
+UADK Compression Poll Mode Driver
+=================================
+
+UADK compression PMD provides poll mode compression & decompression driver
+All compression operations are using UADK library compression API, which is
+algorithm-level API, abstracting accelerators' low-level implementations.
+
+UADK compression PMD relies on `UADK library <https://github.com/Linaro/uadk>`_.
+
+UADK is a framework for user applications to access hardware accelerators.
+UADK relies on IOMMU SVA (Shared Virtual Address) feature,
+which shares the same page table between IOMMU and MMU.
+As a result, the user application can directly use the virtual address for
+device DMA, which enhances performance as well as easy usability.
+
+
+Features
+--------
+
+UADK compression PMD has support for:
+
+Compression/Decompression algorithm:
+
+    * DEFLATE - using Fixed and Dynamic Huffman encoding
+
+Window size support:
+
+    * 32K
+
+
+Test steps
+----------
+
+#. Build UADK
+
+   .. code-block:: console
+
+      git clone https://github.com/Linaro/uadk.git
+      cd uadk
+      mkdir build
+      ./autogen.sh
+      ./configure --prefix=$PWD/build
+      make
+      make install
+
+   .. note::
+
+      Without ``--prefix``, UADK will be installed to ``/usr/local/lib`` by default.
+
+   .. note::
+
+      If get error: "cannot find -lnuma", please install the libnuma-dev.
+
+#. Run pkg-config libwd to ensure env is setup correctly
+
+   .. code-block:: console
+
+      export PKG_CONFIG_PATH=$PWD/build/lib/pkgconfig
+      pkg-config libwd --cflags --libs -I/usr/local/include -L/usr/local/lib -lwd
+
+   .. note::
+
+      export ``PKG_CONFIG_PATH`` is required on demand,
+      not needed if UADK is installed to ``/usr/local/lib``.
+
+#. Build DPDK
+
+   .. code-block:: console
+
+      cd dpdk
+      mkdir build
+      meson setup build (--reconfigure)
+      cd build
+      ninja
+      sudo ninja install
+
+#. Prepare hugepages for DPDK (see also :doc:`../tools/hugepages`)
+
+   .. code-block:: console
+
+      echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
+      echo 1024 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages
+      echo 1024 > /sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
+      echo 1024 > /sys/devices/system/node/node3/hugepages/hugepages-2048kB/nr_hugepages
+      mkdir -p /mnt/huge_2mb
+      mount -t hugetlbfs none /mnt/huge_2mb -o pagesize=2MB
+
+#. Run test app
+
+   .. code-block:: console
+
+	sudo dpdk-test --vdev=compress_uadk
+	RTE>>compressdev_autotest
+	RTE>>quit
diff --git a/doc/guides/rel_notes/release_24_07.rst b/doc/guides/rel_notes/release_24_07.rst
index a69f24cf99..a7574045f0 100644
--- a/doc/guides/rel_notes/release_24_07.rst
+++ b/doc/guides/rel_notes/release_24_07.rst
@@ -24,6 +24,11 @@ DPDK Release 24.07
 New Features
 ------------
 
+* **Added UADK compress driver.**
+
+  Added a new compress driver for the UADK library. See the
+  :doc:`../compressdevs/uadk` guide for more details on this new driver.
+
 .. This section should contain new features added in this release.
    Sample format:
 
diff --git a/drivers/compress/meson.build b/drivers/compress/meson.build
index b91195b27d..91d7800a4a 100644
--- a/drivers/compress/meson.build
+++ b/drivers/compress/meson.build
@@ -10,6 +10,7 @@ drivers = [
         'mlx5',
         'nitrox',
         'octeontx',
+        'uadk',
         'zlib',
 ]
 
diff --git a/drivers/compress/uadk/meson.build b/drivers/compress/uadk/meson.build
new file mode 100644
index 0000000000..704833bbcf
--- /dev/null
+++ b/drivers/compress/uadk/meson.build
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2024-2025 Huawei Technologies Co.,Ltd. All rights reserved.
+# Copyright 2024-2025 Linaro ltd.
+
+if not is_linux
+    build = false
+    reason = 'only supported on Linux'
+    subdir_done()
+endif
+
+sources = files(
+        'uadk_compress_pmd.c',
+)
+
+deps += 'bus_vdev'
+dep = dependency('libwd_comp', required: false, method: 'pkg-config')
+if not dep.found()
+	build = false
+	reason = 'missing dependency, "libwd_comp"'
+else
+	ext_deps += dep
+endif
+
+dep = dependency('libwd', required: false, method: 'pkg-config')
+if not dep.found()
+    build = false
+    reason = 'missing dependency, "libwd"'
+else
+    ext_deps += dep
+endif
diff --git a/drivers/compress/uadk/uadk_compress_pmd.c b/drivers/compress/uadk/uadk_compress_pmd.c
new file mode 100644
index 0000000000..d73524ce84
--- /dev/null
+++ b/drivers/compress/uadk/uadk_compress_pmd.c
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024-2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ * Copyright 2024-2025 Linaro ltd.
+ */
+
+#include <bus_vdev_driver.h>
+#include <rte_compressdev_pmd.h>
+#include <rte_malloc.h>
+
+#include <uadk/wd_comp.h>
+#include <uadk/wd_sched.h>
+
+#include "uadk_compress_pmd_private.h"
+
+static struct rte_compressdev_ops uadk_compress_pmd_ops = {
+		.dev_configure		= NULL,
+		.dev_start		= NULL,
+		.dev_stop		= NULL,
+		.dev_close		= NULL,
+		.stats_get		= NULL,
+		.stats_reset		= NULL,
+		.dev_infos_get		= NULL,
+		.queue_pair_setup	= NULL,
+		.queue_pair_release	= NULL,
+		.private_xform_create	= NULL,
+		.private_xform_free	= NULL,
+		.stream_create		= NULL,
+		.stream_free		= NULL,
+};
+
+static int
+uadk_compress_probe(struct rte_vdev_device *vdev)
+{
+	struct rte_compressdev_pmd_init_params init_params = {
+		"",
+		rte_socket_id(),
+	};
+	struct rte_compressdev *compressdev;
+	struct uacce_dev *udev;
+	const char *name;
+
+	udev = wd_get_accel_dev("deflate");
+	if (!udev)
+		return -ENODEV;
+
+	name = rte_vdev_device_name(vdev);
+	if (name == NULL)
+		return -EINVAL;
+
+	compressdev = rte_compressdev_pmd_create(name, &vdev->device,
+			sizeof(struct uadk_compress_priv), &init_params);
+	if (compressdev == NULL) {
+		UADK_LOG(ERR, "driver %s: create failed", init_params.name);
+		return -ENODEV;
+	}
+
+	compressdev->dev_ops = &uadk_compress_pmd_ops;
+	compressdev->dequeue_burst = NULL;
+	compressdev->enqueue_burst = NULL;
+	compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
+
+	return 0;
+}
+
+static int
+uadk_compress_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 uadk_compress_pmd = {
+	.probe = uadk_compress_probe,
+	.remove = uadk_compress_remove,
+};
+
+#define UADK_COMPRESS_DRIVER_NAME compress_uadk
+RTE_PMD_REGISTER_VDEV(UADK_COMPRESS_DRIVER_NAME, uadk_compress_pmd);
+RTE_LOG_REGISTER_DEFAULT(uadk_compress_logtype, INFO);
diff --git a/drivers/compress/uadk/uadk_compress_pmd_private.h b/drivers/compress/uadk/uadk_compress_pmd_private.h
new file mode 100644
index 0000000000..a96aea7c73
--- /dev/null
+++ b/drivers/compress/uadk/uadk_compress_pmd_private.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024-2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ * Copyright 2024-2025 Linaro ltd.
+ */
+
+#ifndef _UADK_COMPRESS_PMD_PRIVATE_H_
+#define _UADK_COMPRESS_PMD_PRIVATE_H_
+
+struct uadk_compress_priv {
+	struct rte_mempool *mp;
+};
+
+extern int uadk_compress_logtype;
+
+#define UADK_LOG(level, fmt, ...)  \
+	rte_log(RTE_LOG_ ## level, uadk_compress_logtype,  \
+		"%s() line %u: " fmt "\n", __func__, __LINE__,  \
+		## __VA_ARGS__)
+
+#endif /* _UADK_COMPRESS_PMD_PRIVATE_H_ */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] compress/uadk: support basic operations
  2024-04-22 14:30 [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 1/3] compress/uadk: " Zhangfei Gao
@ 2024-04-22 14:31 ` Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 3/3] compress/uadk: support burst enqueue/dequeue Zhangfei Gao
  2024-05-11  3:05 ` [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
  3 siblings, 0 replies; 5+ messages in thread
From: Zhangfei Gao @ 2024-04-22 14:31 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Ashish Gupta; +Cc: dev, Zhangfei Gao

Support the basic dev control operations: configure, close,
start, stop, infos_get, and queue pairs operations, etc.

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
 drivers/compress/uadk/uadk_compress_pmd.c     | 325 +++++++++++++++++-
 .../compress/uadk/uadk_compress_pmd_private.h |  16 +
 2 files changed, 330 insertions(+), 11 deletions(-)

diff --git a/drivers/compress/uadk/uadk_compress_pmd.c b/drivers/compress/uadk/uadk_compress_pmd.c
index d73524ce84..25858855e6 100644
--- a/drivers/compress/uadk/uadk_compress_pmd.c
+++ b/drivers/compress/uadk/uadk_compress_pmd.c
@@ -12,18 +12,321 @@
 
 #include "uadk_compress_pmd_private.h"
 
+static const struct
+rte_compressdev_capabilities uadk_compress_pmd_capabilities[] = {
+	{   /* Deflate */
+		.algo = RTE_COMP_ALGO_DEFLATE,
+		.comp_feature_flags = RTE_COMP_FF_SHAREABLE_PRIV_XFORM |
+				      RTE_COMP_FF_HUFFMAN_FIXED |
+				      RTE_COMP_FF_HUFFMAN_DYNAMIC,
+	},
+
+	RTE_COMP_END_OF_CAPABILITIES_LIST()
+};
+
+static int
+uadk_compress_pmd_config(struct rte_compressdev *dev,
+			 struct rte_compressdev_config *config)
+{
+	char mp_name[RTE_MEMPOOL_NAMESIZE];
+	struct uadk_compress_priv *priv;
+	struct rte_mempool *mp;
+	int ret;
+
+	if (dev == NULL || config == NULL)
+		return -EINVAL;
+
+	snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
+		 "stream_mp_%u", dev->data->dev_id);
+	priv = dev->data->dev_private;
+
+	/* alloc resources */
+	ret = wd_comp_env_init(NULL);
+	if (ret < 0)
+		return -EINVAL;
+
+	mp = priv->mp;
+	if (mp == NULL) {
+		mp = rte_mempool_create(mp_name,
+					config->max_nb_priv_xforms +
+					config->max_nb_streams,
+					sizeof(struct uadk_stream),
+					0, 0, NULL, NULL, NULL,
+					NULL, config->socket_id, 0);
+		if (mp == NULL) {
+			UADK_LOG(ERR, "Cannot create private xform pool on socket %d\n",
+				 config->socket_id);
+			ret = -ENOMEM;
+			goto err_mempool;
+		}
+		priv->mp = mp;
+	}
+
+	return 0;
+
+err_mempool:
+	wd_comp_env_uninit();
+	return ret;
+}
+
+static int
+uadk_compress_pmd_start(struct rte_compressdev *dev __rte_unused)
+{
+	return 0;
+}
+
+static void
+uadk_compress_pmd_stop(struct rte_compressdev *dev __rte_unused)
+{
+}
+
+static int
+uadk_compress_pmd_close(struct rte_compressdev *dev)
+{
+	struct uadk_compress_priv *priv =
+		(struct uadk_compress_priv *)dev->data->dev_private;
+
+	/* free resources */
+	rte_mempool_free(priv->mp);
+	priv->mp = NULL;
+	wd_comp_env_uninit();
+
+	return 0;
+}
+
+static void
+uadk_compress_pmd_stats_get(struct rte_compressdev *dev,
+			    struct rte_compressdev_stats *stats)
+{
+	int qp_id;
+
+	for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
+		struct uadk_qp *qp = dev->data->queue_pairs[qp_id];
+
+		stats->enqueued_count += qp->qp_stats.enqueued_count;
+		stats->dequeued_count += qp->qp_stats.dequeued_count;
+		stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
+		stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
+	}
+}
+
+static void
+uadk_compress_pmd_stats_reset(struct rte_compressdev *dev)
+{
+	int qp_id;
+
+	for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
+		struct uadk_qp *qp = dev->data->queue_pairs[qp_id];
+
+		memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
+	}
+}
+
+static void
+uadk_compress_pmd_info_get(struct rte_compressdev *dev,
+			   struct rte_compressdev_info *dev_info)
+{
+	if (dev_info != NULL) {
+		dev_info->driver_name = dev->device->driver->name;
+		dev_info->feature_flags = dev->feature_flags;
+		dev_info->capabilities = uadk_compress_pmd_capabilities;
+	}
+}
+
+static int
+uadk_compress_pmd_qp_release(struct rte_compressdev *dev, uint16_t qp_id)
+{
+	struct uadk_qp *qp = dev->data->queue_pairs[qp_id];
+
+	if (qp != NULL) {
+		rte_ring_free(qp->processed_pkts);
+		rte_free(qp);
+		dev->data->queue_pairs[qp_id] = NULL;
+	}
+
+	return 0;
+}
+
+static int
+uadk_pmd_qp_set_unique_name(struct rte_compressdev *dev,
+			    struct uadk_qp *qp)
+{
+	unsigned int n = snprintf(qp->name, sizeof(qp->name),
+				 "uadk_pmd_%u_qp_%u",
+				 dev->data->dev_id, qp->id);
+
+	if (n >= sizeof(qp->name))
+		return -EINVAL;
+
+	return 0;
+}
+
+static struct rte_ring *
+uadk_pmd_qp_create_processed_pkts_ring(struct uadk_qp *qp,
+				       unsigned int ring_size, int socket_id)
+{
+	struct rte_ring *r = qp->processed_pkts;
+
+	if (r) {
+		if (rte_ring_get_size(r) >= ring_size) {
+			UADK_LOG(INFO, "Reusing existing ring %s for processed packets",
+				 qp->name);
+			return r;
+		}
+
+		UADK_LOG(ERR, "Unable to reuse existing ring %s for processed packets",
+			 qp->name);
+		return NULL;
+	}
+
+	return rte_ring_create(qp->name, ring_size, socket_id,
+			       RING_F_EXACT_SZ);
+}
+
+static int
+uadk_compress_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
+			   uint32_t max_inflight_ops, int socket_id)
+{
+	struct uadk_qp *qp = NULL;
+
+	/* Free memory prior to re-allocation if needed. */
+	if (dev->data->queue_pairs[qp_id] != NULL)
+		uadk_compress_pmd_qp_release(dev, qp_id);
+
+	/* Allocate the queue pair data structure. */
+	qp = rte_zmalloc_socket("uadk PMD Queue Pair", sizeof(*qp),
+				RTE_CACHE_LINE_SIZE, socket_id);
+	if (qp == NULL)
+		return (-ENOMEM);
+
+	qp->id = qp_id;
+	dev->data->queue_pairs[qp_id] = qp;
+
+	if (uadk_pmd_qp_set_unique_name(dev, qp))
+		goto qp_setup_cleanup;
+
+	qp->processed_pkts = uadk_pmd_qp_create_processed_pkts_ring(qp,
+						max_inflight_ops, socket_id);
+	if (qp->processed_pkts == NULL)
+		goto qp_setup_cleanup;
+
+	memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
+
+	return 0;
+
+qp_setup_cleanup:
+	if (qp) {
+		rte_free(qp);
+		qp = NULL;
+	}
+	return -EINVAL;
+}
+
+static int
+uadk_compress_pmd_xform_create(struct rte_compressdev *dev,
+			       const struct rte_comp_xform *xform,
+			       void **private_xform)
+{
+	struct uadk_compress_priv *priv = dev->data->dev_private;
+	struct wd_comp_sess_setup setup = {0};
+	struct sched_params param = {0};
+	struct uadk_stream *stream;
+	handle_t handle;
+
+	if (xform == NULL) {
+		UADK_LOG(ERR, "invalid xform struct");
+		return -EINVAL;
+	}
+
+	if (rte_mempool_get(priv->mp, private_xform)) {
+		UADK_LOG(ERR, "Couldn't get object from session mempool");
+		return -ENOMEM;
+	}
+
+	stream = *((struct uadk_stream **)private_xform);
+
+	switch (xform->type) {
+	case RTE_COMP_COMPRESS:
+		switch (xform->compress.algo) {
+		case RTE_COMP_ALGO_NULL:
+			break;
+		case RTE_COMP_ALGO_DEFLATE:
+			setup.alg_type = WD_DEFLATE;
+			setup.win_sz = WD_COMP_WS_8K;
+			setup.comp_lv = WD_COMP_L8;
+			setup.op_type = WD_DIR_COMPRESS;
+			param.type = setup.op_type;
+			param.numa_id = -1;	/* choose nearby numa node */
+			setup.sched_param = &param;
+			break;
+		default:
+			goto err;
+		}
+		break;
+	case RTE_COMP_DECOMPRESS:
+		switch (xform->decompress.algo) {
+		case RTE_COMP_ALGO_NULL:
+			break;
+		case RTE_COMP_ALGO_DEFLATE:
+			setup.alg_type = WD_DEFLATE;
+			setup.comp_lv = WD_COMP_L8;
+			setup.op_type = WD_DIR_DECOMPRESS;
+			param.type = setup.op_type;
+			param.numa_id = -1;	/* choose nearby numa node */
+			setup.sched_param = &param;
+			break;
+		default:
+			goto err;
+		}
+		break;
+	default:
+		UADK_LOG(ERR, "Algorithm %u is not supported.", xform->type);
+		goto err;
+	}
+
+	handle = wd_comp_alloc_sess(&setup);
+	if (!handle)
+		goto err;
+
+	stream->handle = handle;
+	stream->type = xform->type;
+
+	return 0;
+
+err:
+	rte_mempool_put(priv->mp, private_xform);
+	return -EINVAL;
+}
+
+static int
+uadk_compress_pmd_xform_free(struct rte_compressdev *dev __rte_unused, void *private_xform)
+{
+	struct uadk_stream *stream = (struct uadk_stream *)private_xform;
+	struct rte_mempool *mp;
+
+	if (!stream)
+		return -EINVAL;
+
+	wd_comp_free_sess(stream->handle);
+	memset(stream, 0, sizeof(struct uadk_stream));
+	mp = rte_mempool_from_obj(stream);
+	rte_mempool_put(mp, stream);
+
+	return 0;
+}
+
 static struct rte_compressdev_ops uadk_compress_pmd_ops = {
-		.dev_configure		= NULL,
-		.dev_start		= NULL,
-		.dev_stop		= NULL,
-		.dev_close		= NULL,
-		.stats_get		= NULL,
-		.stats_reset		= NULL,
-		.dev_infos_get		= NULL,
-		.queue_pair_setup	= NULL,
-		.queue_pair_release	= NULL,
-		.private_xform_create	= NULL,
-		.private_xform_free	= NULL,
+		.dev_configure		= uadk_compress_pmd_config,
+		.dev_start		= uadk_compress_pmd_start,
+		.dev_stop		= uadk_compress_pmd_stop,
+		.dev_close		= uadk_compress_pmd_close,
+		.stats_get		= uadk_compress_pmd_stats_get,
+		.stats_reset		= uadk_compress_pmd_stats_reset,
+		.dev_infos_get		= uadk_compress_pmd_info_get,
+		.queue_pair_setup	= uadk_compress_pmd_qp_setup,
+		.queue_pair_release	= uadk_compress_pmd_qp_release,
+		.private_xform_create	= uadk_compress_pmd_xform_create,
+		.private_xform_free	= uadk_compress_pmd_xform_free,
 		.stream_create		= NULL,
 		.stream_free		= NULL,
 };
diff --git a/drivers/compress/uadk/uadk_compress_pmd_private.h b/drivers/compress/uadk/uadk_compress_pmd_private.h
index a96aea7c73..97a921316e 100644
--- a/drivers/compress/uadk/uadk_compress_pmd_private.h
+++ b/drivers/compress/uadk/uadk_compress_pmd_private.h
@@ -10,6 +10,22 @@ struct uadk_compress_priv {
 	struct rte_mempool *mp;
 };
 
+struct __rte_cache_aligned uadk_qp {
+	/* Ring for placing process packets */
+	struct rte_ring *processed_pkts;
+	/* Queue pair statistics */
+	struct rte_compressdev_stats qp_stats;
+	/* Queue Pair Identifier */
+	uint16_t id;
+	/* Unique Queue Pair Name */
+	char name[RTE_COMPRESSDEV_NAME_MAX_LEN];
+};
+
+struct __rte_cache_aligned uadk_stream {
+	handle_t handle;
+	enum rte_comp_xform_type type;
+};
+
 extern int uadk_compress_logtype;
 
 #define UADK_LOG(level, fmt, ...)  \
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] compress/uadk: support burst enqueue/dequeue
  2024-04-22 14:30 [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 1/3] compress/uadk: " Zhangfei Gao
  2024-04-22 14:31 ` [PATCH 2/3] compress/uadk: support basic operations Zhangfei Gao
@ 2024-04-22 14:31 ` Zhangfei Gao
  2024-05-11  3:05 ` [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
  3 siblings, 0 replies; 5+ messages in thread
From: Zhangfei Gao @ 2024-04-22 14:31 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Ashish Gupta; +Cc: dev, Zhangfei Gao

This commit adds the burst enqueue and dequeue operations.

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
 drivers/compress/uadk/uadk_compress_pmd.c | 88 ++++++++++++++++++++++-
 1 file changed, 86 insertions(+), 2 deletions(-)

diff --git a/drivers/compress/uadk/uadk_compress_pmd.c b/drivers/compress/uadk/uadk_compress_pmd.c
index 25858855e6..312aa5c744 100644
--- a/drivers/compress/uadk/uadk_compress_pmd.c
+++ b/drivers/compress/uadk/uadk_compress_pmd.c
@@ -331,6 +331,90 @@ static struct rte_compressdev_ops uadk_compress_pmd_ops = {
 		.stream_free		= NULL,
 };
 
+static uint16_t
+uadk_compress_pmd_enqueue_burst_sync(void *queue_pair,
+				     struct rte_comp_op **ops, uint16_t nb_ops)
+{
+	struct uadk_qp *qp = queue_pair;
+	struct uadk_stream *stream;
+	struct rte_comp_op *op;
+	uint16_t enqd = 0;
+	int i, ret = 0;
+
+	for (i = 0; i < nb_ops; i++) {
+		op = ops[i];
+
+		if (op->op_type == RTE_COMP_OP_STATEFUL) {
+			op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
+		} else {
+			/* process stateless ops */
+			stream = (struct uadk_stream *)op->private_xform;
+			if (stream) {
+				struct wd_comp_req req = {0};
+				uint16_t dst_len = rte_pktmbuf_data_len(op->m_dst);
+
+				req.src = rte_pktmbuf_mtod(op->m_src, uint8_t *);
+				req.src_len = op->src.length;
+				req.dst = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
+				req.dst_len = dst_len;
+				req.op_type = (enum wd_comp_op_type)stream->type;
+				req.cb = NULL;
+				req.data_fmt = WD_FLAT_BUF;
+				do {
+					ret = wd_do_comp_sync(stream->handle, &req);
+				} while (ret == -WD_EBUSY);
+
+				op->consumed += req.src_len;
+
+				if (req.dst_len <= dst_len) {
+					op->produced += req.dst_len;
+					op->status = RTE_COMP_OP_STATUS_SUCCESS;
+				} else  {
+					op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
+				}
+
+				if (ret) {
+					op->status = RTE_COMP_OP_STATUS_ERROR;
+					break;
+				}
+			} else {
+				op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
+			}
+		}
+
+		/* Whatever is out of op, put it into completion queue with
+		 * its status
+		 */
+		if (!ret)
+			ret = rte_ring_enqueue(qp->processed_pkts, (void *)op);
+
+		if (unlikely(ret)) {
+			/* increment count if failed to enqueue op */
+			qp->qp_stats.enqueue_err_count++;
+		} else {
+			qp->qp_stats.enqueued_count++;
+			enqd++;
+		}
+	}
+
+	return enqd;
+}
+
+static uint16_t
+uadk_compress_pmd_dequeue_burst_sync(void *queue_pair,
+				     struct rte_comp_op **ops,
+				     uint16_t nb_ops)
+{
+	struct uadk_qp *qp = queue_pair;
+	unsigned int nb_dequeued = 0;
+
+	nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
+			(void **)ops, nb_ops, NULL);
+	qp->qp_stats.dequeued_count += nb_dequeued;
+
+	return nb_dequeued;
+}
+
 static int
 uadk_compress_probe(struct rte_vdev_device *vdev)
 {
@@ -358,8 +442,8 @@ uadk_compress_probe(struct rte_vdev_device *vdev)
 	}
 
 	compressdev->dev_ops = &uadk_compress_pmd_ops;
-	compressdev->dequeue_burst = NULL;
-	compressdev->enqueue_burst = NULL;
+	compressdev->dequeue_burst = uadk_compress_pmd_dequeue_burst_sync;
+	compressdev->enqueue_burst = uadk_compress_pmd_enqueue_burst_sync;
 	compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
 
 	return 0;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Introduce UADK compression driver
  2024-04-22 14:30 [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
                   ` (2 preceding siblings ...)
  2024-04-22 14:31 ` [PATCH 3/3] compress/uadk: support burst enqueue/dequeue Zhangfei Gao
@ 2024-05-11  3:05 ` Zhangfei Gao
  3 siblings, 0 replies; 5+ messages in thread
From: Zhangfei Gao @ 2024-05-11  3:05 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Ashish Gupta, Ashish Gupta, Fan Zhang; +Cc: dev

On Mon, 22 Apr 2024 at 22:31, Zhangfei Gao <zhangfei.gao@linaro.org> wrote:
>
> Introduce a new compress PMD for hardware accelerators based on UADK [1].
>
> UADK is a framework for user applications to access hardware accelerators.
> UADK relies on IOMMU SVA (Shared Virtual Address) feature, which share
> the same page table between IOMMU and MMU.
> Thereby user application can directly use virtual address for device dma,
> which enhances the performance as well as easy usability.
>
> Besides, crypto PMD is under drivers/crypto/uadk/
>
> [1] https://github.com/Linaro/uadk
>
> Test:
> sudo dpdk-test --vdev=compress_uadk
> RTE>>compressdev_autotest
> RTE>>quit
>
> dd if=/dev/random of=data bs=1M count=1;
> sudo dpdk-test-compress-perf -l 1,2 --vdev compress_uadk \
>         -- --driver-name compress_uadk --input-file data
>
>

> Zhangfei Gao (3):
>   compress/uadk: Introduce UADK compression driver
>   compress/uadk: support basic operations
>   compress/uadk: support burst enqueue/dequeue


Any comments?

Thanks

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-11  3:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 14:30 [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao
2024-04-22 14:31 ` [PATCH 1/3] compress/uadk: " Zhangfei Gao
2024-04-22 14:31 ` [PATCH 2/3] compress/uadk: support basic operations Zhangfei Gao
2024-04-22 14:31 ` [PATCH 3/3] compress/uadk: support burst enqueue/dequeue Zhangfei Gao
2024-05-11  3:05 ` [PATCH 0/3] Introduce UADK compression driver Zhangfei Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).