From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4D6CDA0487 for ; Tue, 2 Jul 2019 12:33:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 44D151B9AD; Tue, 2 Jul 2019 12:33:05 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 11C971B9AC for ; Tue, 2 Jul 2019 12:33:04 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id u8so410724wmm.1 for ; Tue, 02 Jul 2019 03:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netcope.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u/Rvchmlsp9fceUPYOSw+2D0nbfBL5ypN6Tya0dEUF4=; b=gRLYSoMV3moOyY7ZDFc18P0Y5Q8sIQnIbvNJh9MTPYLIhp7htEjreG7IWH2nToy8vc G5XL75/uwQxY2oemB77tc9pDCtbV05H0i43eZRXM2rHsxZauj6dTbCQplPPP+wQRsoe/ YoOoX7sMgK1bO4hNts0BnSi411DlmUR2uK+RGwwZsFc3LQ//tkIPpxxVgNpR+cP4MGcs fiCWWwi3sHP610DbEJYtipqiixIPEYAYUMyyApMnDOP2+4vaegXniUZRh+aA+M5EvJVX USxfNnG1W0fS9qF1P8uk05jx8R3LqZ/7LshpGQZ/fN/qr7tGIncvgvidkdCmS32xjGas tyrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u/Rvchmlsp9fceUPYOSw+2D0nbfBL5ypN6Tya0dEUF4=; b=Z0DZzT9X45i5XZOg4hwXgUjIhFQTC8ig3Od5t+Bro0PZ7y/u5UAiz63Q2NuKLP/1bv aziHaYxM48xL9br2lg8QS8GBJ6ngODJesuyqpAoiq7Bvdx/z2/vau20ski7Pi8gd1S/E +kbYdtOnkkY3lQAM0JA43XFSd9/pYmy3eH69H2pAJdYZdYQLUypVvbhNLFU3fLCrIYVf bkOqICVSyz5+A8NHPhc4sNYz3d7BekxzYkPDJ4uM/LafMsgiU2AVqk9hcJq/qJH7telI fWQE4W9DnEgruX5kawK27jHtCC1DniI7fntDO2LU7otivM/maVtCJ05KWQCPgjmjnVXJ YPfw== X-Gm-Message-State: APjAAAVdqFi6GXMiMnz34YJ/W5At9A1DMLdO6kHmH0Waymq/JtS88wrJ WZYZZ6a4F2nRzkpjhEg19vdHdbEcPU0= X-Google-Smtp-Source: APXvYqwbiQKvNn/3pr+LDiqWP4JcodkPLOVIim8NaQwCYtlfOOzFmuh2w/5/WCuvWIHG8pNRKEDFiw== X-Received: by 2002:a05:600c:1150:: with SMTP id z16mr2905928wmz.168.1562063583528; Tue, 02 Jul 2019 03:33:03 -0700 (PDT) Received: from ruprecht.int.netcope.com ([185.24.237.70]) by smtp.gmail.com with ESMTPSA id e20sm19778992wrc.9.2019.07.02.03.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:33:02 -0700 (PDT) From: Rastislav Cernay X-Google-Original-From: Rastislav Cernay To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Rastislav Cernay Date: Tue, 2 Jul 2019 12:32:57 +0200 Message-Id: <1562063577-231019-1-git-send-email-cernay@netcope.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560427509-56164-1-git-send-email-cernay@netcope.com> References: <1560427509-56164-1-git-send-email-cernay@netcope.com> Subject: [dpdk-dev] [PATCH v2] drivers/net/nfb: add timestamp support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Rastislav Cernay This patch adds timestamping support to nfb driver. Signed-off-by: Rastislav Cernay --- v2: rewrite timestamp enable to devargs doc/guides/nics/nfb.rst | 19 +++++++++++++++++++ drivers/net/nfb/nfb_rx.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/nfb/nfb_rx.h | 21 +++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/doc/guides/nics/nfb.rst b/doc/guides/nics/nfb.rst index 8df76c0..6258fd7 100644 --- a/doc/guides/nics/nfb.rst +++ b/doc/guides/nics/nfb.rst @@ -142,3 +142,22 @@ Example output: TX threshold registers: pthresh=0 hthresh=0 wthresh=0 TX RS bit threshold=0 - TXQ flags=0x0 testpmd> + +Timestamp +---------------- + +The PMD supports hardware timestamps of frame receipt on physical network interface. In order to use +the timestamps, the hardware timestamping unit must be enabled (follow the documentation of the NFB +products) and the device argument `timestamp=1` must be used. + +.. code-block:: console + + $RTE_TARGET/app/testpmd -w b3:00.0,timestamp=1 -- + +When the timestamps are enabled with the *devarg*, a timestamp validity flag is set in the MBUFs +containing received frames and timestamp is inserted into the `rte_mbuf` struct. + +The timestamp is an `uint64_t` field. Its lower 32 bits represent *seconds* portion of the timestamp +(number of seconds elapsed since 1.1.1970 00:00:00 UTC) and its higher 32 bits represent +*nanosecond* portion of the timestamp (number of nanoseconds elapsed since the beginning of the +second in the *seconds* portion. diff --git a/drivers/net/nfb/nfb_rx.c b/drivers/net/nfb/nfb_rx.c index 9147b00..805d893 100644 --- a/drivers/net/nfb/nfb_rx.c +++ b/drivers/net/nfb/nfb_rx.c @@ -4,9 +4,53 @@ * All rights reserved. */ +#include + #include "nfb_rx.h" #include "nfb.h" + +static int +timestamp_check_handler(__rte_unused const char *key, + const char *value, __rte_unused void *opaque) +{ + if (strcmp(value, "1")) + return -1; + + return 0; +} + + +static int +nfb_check_timestamp(struct rte_devargs *devargs) +{ + struct rte_kvargs *kvlist; + const char *timestamp_key = "timestamp"; + + if (devargs == NULL) + return 0; + + kvlist = rte_kvargs_parse(devargs->args, NULL); + if (kvlist == NULL) + return 0; + + if (!rte_kvargs_count(kvlist, timestamp_key)) { + rte_kvargs_free(kvlist); + return 0; + } + /* Timestamps are enabled when there is + * key-value pair: enable_timestamp=1 + */ + if (rte_kvargs_process(kvlist, timestamp_key, + timestamp_check_handler, NULL) < 0) { + rte_kvargs_free(kvlist); + return 0; + } + rte_kvargs_free(kvlist); + + return 1; +} + int nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id) { @@ -70,6 +114,8 @@ return -ENOMEM; } + rxq->flags = 0; + ret = nfb_eth_rx_queue_init(internals->nfb, rx_queue_id, dev->data->port_id, @@ -81,6 +127,9 @@ else rte_free(rxq); + if (nfb_check_timestamp(dev->device->devargs)) + rxq->flags |= NFB_TIMESTAMP_FLAG; + return ret; } diff --git a/drivers/net/nfb/nfb_rx.h b/drivers/net/nfb/nfb_rx.h index 88a0307..cf3899b 100644 --- a/drivers/net/nfb/nfb_rx.h +++ b/drivers/net/nfb/nfb_rx.h @@ -13,11 +13,14 @@ #include #include +#define NFB_TIMESTAMP_FLAG (1 << 0) + struct ndp_rx_queue { struct nfb_device *nfb; /* nfb dev structure */ struct ndp_queue *queue; /* rx queue */ uint16_t rx_queue_id; /* index */ uint8_t in_port; /* port */ + uint8_t flags; /* setup flags */ struct rte_mempool *mb_pool; /* memory pool to allocate packets */ uint16_t buf_size; /* mbuf size */ @@ -129,6 +132,7 @@ struct ndp_rx_queue { uint16_t nb_pkts) { struct ndp_rx_queue *ndp = queue; + uint8_t timestamping_enabled; uint16_t packet_size; uint64_t num_bytes = 0; uint16_t num_rx; @@ -146,6 +150,8 @@ struct ndp_rx_queue { return 0; } + timestamping_enabled = ndp->flags & NFB_TIMESTAMP_FLAG; + /* returns either all or nothing */ i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts); if (unlikely(i != 0)) @@ -181,6 +187,21 @@ struct ndp_rx_queue { mbuf->pkt_len = packet_size; mbuf->port = ndp->in_port; + mbuf->ol_flags = 0; + + if (timestamping_enabled) { + /* 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; + } + bufs[num_rx++] = mbuf; num_bytes += packet_size; } else { -- 1.8.3.1