[v5,09/15] net/nfb: switch timestamp to dynamic mbuf field
diff mbox series

Message ID 20201030172940.1073558-10-thomas@monjalon.net
State Superseded, archived
Headers show
Series
  • remove mbuf userdata
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Thomas Monjalon Oct. 30, 2020, 5:29 p.m. UTC
The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field.
The related mbuf flag is also replaced.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/nfb/nfb_rx.c | 23 ++++++++++++++++++++++-
 drivers/net/nfb/nfb_rx.h | 18 ++++++++++++++----
 2 files changed, 36 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/nfb/nfb_rx.c b/drivers/net/nfb/nfb_rx.c
index d97179f818..1f90357522 100644
--- a/drivers/net/nfb/nfb_rx.c
+++ b/drivers/net/nfb/nfb_rx.c
@@ -5,10 +5,14 @@ 
  */
 
 #include <rte_kvargs.h>
+#include <rte_bitops.h>
 
 #include "nfb_rx.h"
 #include "nfb.h"
 
+uint64_t nfb_timestamp_rx_dynflag;
+int nfb_timestamp_dynfield_offset = -1;
+
 static int
 timestamp_check_handler(__rte_unused const char *key,
 	const char *value, __rte_unused void *opaque)
@@ -23,6 +27,7 @@  timestamp_check_handler(__rte_unused const char *key,
 static int
 nfb_check_timestamp(struct rte_devargs *devargs)
 {
+	int timestamp_rx_dynflag_offset;
 	struct rte_kvargs *kvlist;
 
 	if (devargs == NULL)
@@ -38,6 +43,7 @@  nfb_check_timestamp(struct rte_devargs *devargs)
 	}
 	/* Timestamps are enabled when there is
 	 * key-value pair: enable_timestamp=1
+	 * TODO: timestamp should be enabled with DEV_RX_OFFLOAD_TIMESTAMP
 	 */
 	if (rte_kvargs_process(kvlist, TIMESTAMP_ARG,
 		timestamp_check_handler, NULL) < 0) {
@@ -46,6 +52,21 @@  nfb_check_timestamp(struct rte_devargs *devargs)
 	}
 	rte_kvargs_free(kvlist);
 
+	nfb_timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+			RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+	if (nfb_timestamp_dynfield_offset < 0) {
+		RTE_LOG(ERR, PMD, "Cannot lookup timestamp field\n");
+		return -rte_errno;
+	}
+	timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
+	if (timestamp_rx_dynflag_offset < 0) {
+		RTE_LOG(ERR, PMD, "Cannot lookup Rx timestamp flag\n");
+		return -rte_errno;
+	}
+	nfb_timestamp_rx_dynflag =
+		RTE_BIT64(timestamp_rx_dynflag_offset);
+
 	return 1;
 }
 
@@ -125,7 +146,7 @@  nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
 	else
 		rte_free(rxq);
 
-	if (nfb_check_timestamp(dev->device->devargs))
+	if (nfb_check_timestamp(dev->device->devargs) > 0)
 		rxq->flags |= NFB_TIMESTAMP_FLAG;
 
 	return ret;
diff --git a/drivers/net/nfb/nfb_rx.h b/drivers/net/nfb/nfb_rx.h
index cf3899b2fb..e548226e0f 100644
--- a/drivers/net/nfb/nfb_rx.h
+++ b/drivers/net/nfb/nfb_rx.h
@@ -15,6 +15,16 @@ 
 
 #define NFB_TIMESTAMP_FLAG (1 << 0)
 
+extern uint64_t nfb_timestamp_rx_dynflag;
+extern int nfb_timestamp_dynfield_offset;
+
+static inline rte_mbuf_timestamp_t *
+nfb_timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		nfb_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 struct ndp_rx_queue {
 	struct nfb_device *nfb;	     /* nfb dev structure */
 	struct ndp_queue *queue;     /* rx queue */
@@ -191,15 +201,15 @@  nfb_eth_ndp_rx(void *queue,
 
 			if (timestamping_enabled) {
 				/* nanoseconds */
-				mbuf->timestamp =
+				*nfb_timestamp_dynfield(mbuf) =
 					rte_le_to_cpu_32(*((uint32_t *)
 					(packets[i].header + 4)));
-				mbuf->timestamp <<= 32;
+				*nfb_timestamp_dynfield(mbuf) <<= 32;
 				/* seconds */
-				mbuf->timestamp |=
+				*nfb_timestamp_dynfield(mbuf) |=
 					rte_le_to_cpu_32(*((uint32_t *)
 					(packets[i].header + 8)));
-				mbuf->ol_flags |= PKT_RX_TIMESTAMP;
+				mbuf->ol_flags |= nfb_timestamp_rx_dynflag;
 			}
 
 			bufs[num_rx++] = mbuf;