drivers/net/nfb: add timestamp support

Message ID 1560427509-56164-1-git-send-email-cernay@netcope.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series drivers/net/nfb: add timestamp support |

Checks

Context Check Description
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Rastislav Cernay June 13, 2019, 12:05 p.m. UTC
  From: Rastislav Cernay <cernay@netcope.com>

This patch adds timestamping support to nfb driver.

Signed-off-by: Rastislav Cernay <cernay@netcope.com>
---
 config/common_base          |  1 +
 doc/guides/nics/nfb.rst     | 22 ++++++++++++++++++++++
 drivers/net/nfb/Makefile    |  5 +++++
 drivers/net/nfb/meson.build |  4 ++++
 drivers/net/nfb/nfb_rx.h    | 13 +++++++++++++
 5 files changed, 45 insertions(+)
  

Comments

Ferruh Yigit June 27, 2019, 3:45 p.m. UTC | #1
On 6/13/2019 1:05 PM, Rastislav Cernay wrote:
> From: Rastislav Cernay <cernay@netcope.com>
> 
> This patch adds timestamping support to nfb driver.
> 
> Signed-off-by: Rastislav Cernay <cernay@netcope.com>
> ---
>  config/common_base          |  1 +
>  doc/guides/nics/nfb.rst     | 22 ++++++++++++++++++++++
>  drivers/net/nfb/Makefile    |  5 +++++
>  drivers/net/nfb/meson.build |  4 ++++
>  drivers/net/nfb/nfb_rx.h    | 13 +++++++++++++
>  5 files changed, 45 insertions(+)
> 
> diff --git a/config/common_base b/config/common_base
> index 6f19ad5..f533136 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -383,6 +383,7 @@ CONFIG_RTE_LIBRTE_PMD_SZEDATA2=n
>  # Compile software PMD backed by NFB device
>  #
>  CONFIG_RTE_LIBRTE_NFB_PMD=n
> +CONFIG_RTE_LIBRTE_NFB_HW_TIMESTAMP=n
>  
>  #
>  # Compile burst-oriented Cavium Thunderx NICVF PMD driver
> diff --git a/doc/guides/nics/nfb.rst b/doc/guides/nics/nfb.rst
> index 8df76c0..a172f9a 100644
> --- a/doc/guides/nics/nfb.rst
> +++ b/doc/guides/nics/nfb.rst
> @@ -69,6 +69,10 @@ These configuration options can be modified before compilation in the
>  
>     Value **y** enables compilation of nfb PMD.
>  
> +*  ``CONFIG_RTE_LIBRTE_NFB_HW_TIMESTAMP`` default value: **n**
> +
> +   Value **y** enables HW packet timestamping.
> +
>  Using the NFB PMD
>  ----------------------
>  
> @@ -142,3 +146,21 @@ Example output:
>       TX threshold registers: pthresh=0 hthresh=0 wthresh=0
>       TX RS bit threshold=0 - TXQ flags=0x0
>     testpmd>
> +
> +Timestamp
> +----------------
> +
> +Timestamping needs to be enabled during compile time, as there is no way
> +to check whether a timestamping unit is runnig during run time.

Even if this can't be detected on runtime, it should be possible to configure in
runtime with device args so need to compile the PMD again to change the behavior.

In this patch default behavior is no timestamps support, same can be done with
devargs, without any devargs timestamp support disable, but if user provides a
devarg, like "timestamp=1", feature enabled.

What do you think, can it be possible to convert runtime configuration?
  
Jan Remes June 28, 2019, 2:12 p.m. UTC | #2
On Thu, Jun 27, 2019 at 5:45 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 6/13/2019 1:05 PM, Rastislav Cernay wrote:
> > +Timestamping needs to be enabled during compile time, as there is no way
> > +to check whether a timestamping unit is runnig during run time.
>
> Even if this can't be detected on runtime, it should be possible to configure in
> runtime with device args so need to compile the PMD again to change the behavior.
>
> In this patch default behavior is no timestamps support, same can be done with
> devargs, without any devargs timestamp support disable, but if user provides a
> devarg, like "timestamp=1", feature enabled.
>
> What do you think, can it be possible to convert runtime configuration?

This sounds good. We did not explore the devargs option. We will look
into it, and probably rework this patch and send v2.

Thanks,
  Jan
  

Patch

diff --git a/config/common_base b/config/common_base
index 6f19ad5..f533136 100644
--- a/config/common_base
+++ b/config/common_base
@@ -383,6 +383,7 @@  CONFIG_RTE_LIBRTE_PMD_SZEDATA2=n
 # Compile software PMD backed by NFB device
 #
 CONFIG_RTE_LIBRTE_NFB_PMD=n
+CONFIG_RTE_LIBRTE_NFB_HW_TIMESTAMP=n
 
 #
 # Compile burst-oriented Cavium Thunderx NICVF PMD driver
diff --git a/doc/guides/nics/nfb.rst b/doc/guides/nics/nfb.rst
index 8df76c0..a172f9a 100644
--- a/doc/guides/nics/nfb.rst
+++ b/doc/guides/nics/nfb.rst
@@ -69,6 +69,10 @@  These configuration options can be modified before compilation in the
 
    Value **y** enables compilation of nfb PMD.
 
+*  ``CONFIG_RTE_LIBRTE_NFB_HW_TIMESTAMP`` default value: **n**
+
+   Value **y** enables HW packet timestamping.
+
 Using the NFB PMD
 ----------------------
 
@@ -142,3 +146,21 @@  Example output:
      TX threshold registers: pthresh=0 hthresh=0 wthresh=0
      TX RS bit threshold=0 - TXQ flags=0x0
    testpmd>
+
+Timestamp
+----------------
+
+Timestamping needs to be enabled during compile time, as there is no way
+to check whether a timestamping unit is runnig during run time.
+
+While enabled, a validity flag of a timestamp is set and a timestamp data is inserted into a rte_mbuf struct.
+The timestamping unit still needs to be enabled separately according to the documentation of NFB products.
+
+Timestamp is in uint64_t field where upper 32 bits represents nanoseconds and lower 32 bits seconds.
+
+Nanoseconds contains the nanosecond part of the timestamp representing the
+time of frame receipt on physical network interface. It is the number of nanoseconds elapsed
+since the beginning of the second in Timestamp (seconds) field.
+
+Seconds contains the second part of the timestamp representing the time of frame
+receipt on physical network interface.
\ No newline at end of file
diff --git a/drivers/net/nfb/Makefile b/drivers/net/nfb/Makefile
index a84b423..a9c4607 100644
--- a/drivers/net/nfb/Makefile
+++ b/drivers/net/nfb/Makefile
@@ -16,6 +16,11 @@  INCLUDES :=-I$(SRCDIR)
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --cflags netcope-common)
+
+ifeq ($(CONFIG_RTE_LIBRTE_NFB_HW_TIMESTAMP),y)
+    CFLAGS += -DNFB_HW_TIMESTAMP
+endif
+
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
 LDLIBS += -lrte_ethdev -lrte_net
 LDLIBS += -lrte_bus_pci
diff --git a/drivers/net/nfb/meson.build b/drivers/net/nfb/meson.build
index 457955d..c39007a 100644
--- a/drivers/net/nfb/meson.build
+++ b/drivers/net/nfb/meson.build
@@ -13,3 +13,7 @@  ext_deps += dep
 ext_deps += nc
 
 sources = files('nfb_rx.c', 'nfb_tx.c', 'nfb_stats.c', 'nfb_ethdev.c', 'nfb_rxmode.c')
+
+if dpdk_conf.has('RTE_LIBRTE_NFB_HW_TIMESTAMP')
+    cflags += [ '-DNFB_HW_TIMESTAMP' ]
+endif
diff --git a/drivers/net/nfb/nfb_rx.h b/drivers/net/nfb/nfb_rx.h
index 88a0307..1178917 100644
--- a/drivers/net/nfb/nfb_rx.h
+++ b/drivers/net/nfb/nfb_rx.h
@@ -181,6 +181,19 @@  struct ndp_rx_queue {
 
 			mbuf->pkt_len = packet_size;
 			mbuf->port = ndp->in_port;
+			mbuf->ol_flags = 0;
+
+#ifdef NFB_HW_TIMESTAMP
+			/* nanoseconds */
+			mbuf->timestamp = rte_le_to_cpu_32(*((uint32_t *)
+				(packets[i].header + 4)));
+			mbuf->timestamp <<= 32;
+			/* seconds */
+			mbuf->timestamp |= rte_le_to_cpu_32(*((uint32_t *)
+				(packets[i].header + 8)));
+			mbuf->ol_flags |= PKT_RX_TIMESTAMP;
+#endif /* NFB_HW_TIMESTAMP */
+
 			bufs[num_rx++] = mbuf;
 			num_bytes += packet_size;
 		} else {