[v6,07/15] net/ark: switch user data to dynamic mbuf fields
diff mbox series

Message ID 20201030174441.1076264-8-thomas@monjalon.net
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • remove mbuf userdata
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Oct. 30, 2020, 5:44 p.m. UTC
From: Ed Czeck <ed.czeck@atomicrules.com>

The second field of metadata is reserved for user data
which was using a deprecated mbuf field.
It is moved to dynamic fields in order to allow removal of udata64.

The use of meta data must be enabled with a compile-time flag
RTE_PMD_ARK_{TX,RX}_USERDATA_ENABLE.
User data on Tx and Rx paths can be defined and used separately.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: Ed Czeck <ed.czeck@atomicrules.com>
---
 doc/api/doxy-api-index.md       |   1 +
 doc/api/doxy-api.conf.in        |   1 +
 drivers/net/ark/ark_ethdev.c    |  39 ++++++++++
 drivers/net/ark/ark_ethdev_rx.c |   3 +-
 drivers/net/ark/ark_ethdev_tx.c |   3 +-
 drivers/net/ark/meson.build     |   2 +
 drivers/net/ark/rte_pmd_ark.h   | 125 ++++++++++++++++++++++++++++++++
 drivers/net/ark/version.map     |   7 ++
 8 files changed, 179 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ark/rte_pmd_ark.h

Patch
diff mbox series

diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md
index a9c12d1a2f..b865a51e8c 100644
--- a/doc/api/doxy-api-index.md
+++ b/doc/api/doxy-api-index.md
@@ -41,6 +41,7 @@  The public API headers are grouped by topics:
   [vhost]              (@ref rte_vhost.h),
   [vdpa]               (@ref rte_vdpa.h),
   [KNI]                (@ref rte_kni.h),
+  [ark]                (@ref rte_pmd_ark.h),
   [ixgbe]              (@ref rte_pmd_ixgbe.h),
   [i40e]               (@ref rte_pmd_i40e.h),
   [ice]                (@ref rte_pmd_ice.h),
diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in
index e37f8c2e80..c5b01a1814 100644
--- a/doc/api/doxy-api.conf.in
+++ b/doc/api/doxy-api.conf.in
@@ -8,6 +8,7 @@  INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \
                           @TOPDIR@/drivers/bus/vdev \
                           @TOPDIR@/drivers/crypto/scheduler \
                           @TOPDIR@/drivers/mempool/dpaa2 \
+                          @TOPDIR@/drivers/net/ark \
                           @TOPDIR@/drivers/net/bnxt \
                           @TOPDIR@/drivers/net/bonding \
                           @TOPDIR@/drivers/net/dpaa \
diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c
index 168b3659d6..fa343999a1 100644
--- a/drivers/net/ark/ark_ethdev.c
+++ b/drivers/net/ark/ark_ethdev.c
@@ -10,6 +10,7 @@ 
 #include <rte_ethdev_pci.h>
 #include <rte_kvargs.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_global.h"
 #include "ark_logs.h"
 #include "ark_ethdev_tx.h"
@@ -78,6 +79,9 @@  static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
 #define ARK_TX_MAX_QUEUE (4096 * 4)
 #define ARK_TX_MIN_QUEUE (256)
 
+int rte_pmd_ark_rx_userdata_dynfield_offset = -1;
+int rte_pmd_ark_tx_userdata_dynfield_offset = -1;
+
 static const char * const valid_arguments[] = {
 	ARK_PKTGEN_ARG,
 	ARK_PKTCHKR_ARG,
@@ -245,6 +249,16 @@  eth_ark_dev_init(struct rte_eth_dev *dev)
 	int ret;
 	int port_count = 1;
 	int p;
+	static const struct rte_mbuf_dynfield ark_tx_userdata_dynfield_desc = {
+		.name = RTE_PMD_ARK_TX_USERDATA_DYNFIELD_NAME,
+		.size = sizeof(rte_pmd_ark_tx_userdata_t),
+		.align = __alignof__(rte_pmd_ark_tx_userdata_t),
+	};
+	static const struct rte_mbuf_dynfield ark_rx_userdata_dynfield_desc = {
+		.name = RTE_PMD_ARK_RX_USERDATA_DYNFIELD_NAME,
+		.size = sizeof(rte_pmd_ark_rx_userdata_t),
+		.align = __alignof__(rte_pmd_ark_rx_userdata_t),
+	};
 
 	ark->eth_dev = dev;
 
@@ -254,6 +268,31 @@  eth_ark_dev_init(struct rte_eth_dev *dev)
 	ret = check_for_ext(ark);
 	if (ret)
 		return ret;
+
+	/* Extra mbuf fields for user data */
+	if (RTE_PMD_ARK_TX_USERDATA_ENABLE) {
+		rte_pmd_ark_tx_userdata_dynfield_offset =
+		    rte_mbuf_dynfield_register(&ark_tx_userdata_dynfield_desc);
+		if (rte_pmd_ark_tx_userdata_dynfield_offset < 0) {
+			ARK_PMD_LOG(ERR,
+				    "Failed to register mbuf field for tx userdata\n");
+			return -rte_errno;
+		}
+		ARK_PMD_LOG(INFO, "Registered TX-meta dynamic field at %d\n",
+			    rte_pmd_ark_tx_userdata_dynfield_offset);
+	}
+	if (RTE_PMD_ARK_RX_USERDATA_ENABLE) {
+		rte_pmd_ark_rx_userdata_dynfield_offset =
+		    rte_mbuf_dynfield_register(&ark_rx_userdata_dynfield_desc);
+		if (rte_pmd_ark_rx_userdata_dynfield_offset < 0) {
+			ARK_PMD_LOG(ERR,
+				    "Failed to register mbuf field for rx userdata\n");
+			return -rte_errno;
+		}
+		ARK_PMD_LOG(INFO, "Registered RX-meta dynamic field at %d\n",
+			    rte_pmd_ark_rx_userdata_dynfield_offset);
+	}
+
 	pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	rte_eth_copy_pci_info(dev, pci_dev);
 	dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
diff --git a/drivers/net/ark/ark_ethdev_rx.c b/drivers/net/ark/ark_ethdev_rx.c
index 2f8d05099c..825b4791be 100644
--- a/drivers/net/ark/ark_ethdev_rx.c
+++ b/drivers/net/ark/ark_ethdev_rx.c
@@ -4,6 +4,7 @@ 
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_rx.h"
 #include "ark_global.h"
 #include "ark_logs.h"
@@ -272,7 +273,7 @@  eth_ark_recv_pkts(void *rx_queue,
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
 		mbuf->timestamp = meta->timestamp;
-		mbuf->udata64 = meta->user_data;
+		rte_pmd_ark_mbuf_rx_userdata_set(mbuf, meta->user_data);
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
 			if ((meta->pkt_len > (1024 * 16)) ||
diff --git a/drivers/net/ark/ark_ethdev_tx.c b/drivers/net/ark/ark_ethdev_tx.c
index a0e35af880..612d918e33 100644
--- a/drivers/net/ark/ark_ethdev_tx.c
+++ b/drivers/net/ark/ark_ethdev_tx.c
@@ -4,6 +4,7 @@ 
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_tx.h"
 #include "ark_global.h"
 #include "ark_mpu.h"
@@ -70,7 +71,7 @@  eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->user1 = (uint32_t)mbuf->udata64;
+	meta->user1 = rte_pmd_ark_mbuf_tx_userdata_get(mbuf);
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
diff --git a/drivers/net/ark/meson.build b/drivers/net/ark/meson.build
index 99151bba1d..80bce94e1a 100644
--- a/drivers/net/ark/meson.build
+++ b/drivers/net/ark/meson.build
@@ -1,6 +1,8 @@ 
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
+headers = files('rte_pmd_ark.h')
+
 sources = files('ark_ddm.c',
 	'ark_ethdev.c',
 	'ark_ethdev_rx.c',
diff --git a/drivers/net/ark/rte_pmd_ark.h b/drivers/net/ark/rte_pmd_ark.h
new file mode 100644
index 0000000000..6f26d66b12
--- /dev/null
+++ b/drivers/net/ark/rte_pmd_ark.h
@@ -0,0 +1,125 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Atomic Rules LLC
+ */
+
+#ifndef RTE_PMD_ARK_H
+#define RTE_PMD_ARK_H
+
+/**
+ * @file
+ * ARK driver-specific API
+ */
+
+#include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
+
+#ifndef RTE_PMD_ARK_TX_USERDATA_ENABLE
+#define RTE_PMD_ARK_TX_USERDATA_ENABLE 0
+#endif
+
+#ifndef RTE_PMD_ARK_RX_USERDATA_ENABLE
+#define RTE_PMD_ARK_RX_USERDATA_ENABLE 0
+#endif
+
+typedef uint32_t rte_pmd_ark_tx_userdata_t;
+typedef uint64_t rte_pmd_ark_rx_userdata_t;
+
+extern int rte_pmd_ark_tx_userdata_dynfield_offset;
+extern int rte_pmd_ark_rx_userdata_dynfield_offset;
+
+/** mbuf dynamic field for custom Tx ARK data */
+#define RTE_PMD_ARK_TX_USERDATA_DYNFIELD_NAME "rte_net_ark_dynfield_tx_userdata"
+/** mbuf dynamic field for custom Rx ARK data */
+#define RTE_PMD_ARK_RX_USERDATA_DYNFIELD_NAME "rte_net_ark_dynfield_rx_userdata"
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Read Tx user data from mbuf.
+ *
+ * @param mbuf Structure to read from.
+ * @return user data
+ */
+__rte_experimental
+static inline rte_pmd_ark_tx_userdata_t
+rte_pmd_ark_mbuf_tx_userdata_get(const struct rte_mbuf *mbuf)
+{
+#if RTE_PMD_ARK_TX_USERDATA_ENABLE
+	return *RTE_MBUF_DYNFIELD(mbuf, rte_pmd_ark_tx_userdata_dynfield_offset,
+				  rte_pmd_ark_tx_userdata_t *);
+#else
+	RTE_SET_USED(mbuf);
+	return 0;
+#endif
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Write Tx user data to mbuf.
+ *
+ * @param mbuf Structure to write into.
+ * @param data User data.
+ */
+__rte_experimental
+static inline void
+rte_pmd_ark_mbuf_tx_userdata_set(struct rte_mbuf *mbuf,
+		rte_pmd_ark_tx_userdata_t data)
+{
+#if RTE_PMD_ARK_TX_USERDATA_ENABLE
+	*RTE_MBUF_DYNFIELD(mbuf, rte_pmd_ark_tx_userdata_dynfield_offset,
+			rte_pmd_ark_tx_userdata_t *) = data;
+#else
+	RTE_SET_USED(mbuf);
+	RTE_SET_USED(data);
+#endif
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Read Rx user data from mbuf.
+ *
+ * @param mbuf Structure to read from.
+ * @return user data
+ */
+__rte_experimental
+static inline rte_pmd_ark_rx_userdata_t
+rte_pmd_ark_mbuf_rx_userdata_get(const struct rte_mbuf *mbuf)
+{
+#if RTE_PMD_ARK_RX_USERDATA_ENABLE
+	return *RTE_MBUF_DYNFIELD(mbuf, rte_pmd_ark_rx_userdata_dynfield_offset,
+			rte_pmd_ark_rx_userdata_t *);
+#else
+	RTE_SET_USED(mbuf);
+	return 0;
+#endif
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Write Rx user data to mbuf.
+ *
+ * @param mbuf Structure to write into.
+ * @param data User data.
+ */
+__rte_experimental
+static inline void
+rte_pmd_ark_mbuf_rx_userdata_set(struct rte_mbuf *mbuf,
+		rte_pmd_ark_rx_userdata_t data)
+{
+#if RTE_PMD_ARK_RX_USERDATA_ENABLE
+	*RTE_MBUF_DYNFIELD(mbuf, rte_pmd_ark_rx_userdata_dynfield_offset,
+			rte_pmd_ark_rx_userdata_t *) = data;
+#else
+	RTE_SET_USED(mbuf);
+	RTE_SET_USED(data);
+#endif
+}
+
+#endif /* RTE_PMD_ARK_H */
diff --git a/drivers/net/ark/version.map b/drivers/net/ark/version.map
index 4a76d1d52d..954bea6796 100644
--- a/drivers/net/ark/version.map
+++ b/drivers/net/ark/version.map
@@ -1,3 +1,10 @@ 
 DPDK_21 {
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_pmd_ark_tx_userdata_dynfield_offset;
+	rte_pmd_ark_rx_userdata_dynfield_offset;
+};