net/nfb: use timestamp offload flag

Rewrite the RX timestamp setup code to use standard offload flag.

Signed-off-by: Martin Spinler <spinler@cesnet.cz>
This commit is contained in:
Martin Spinler 2022-02-15 13:55:41 +01:00 committed by Ferruh Yigit
parent f95a6c34bb
commit 1b4081870e
5 changed files with 22 additions and 68 deletions

View File

@ -59,13 +59,9 @@ Timestamps
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.
products). The standard `RTE_ETH_RX_OFFLOAD_TIMESTAMP` flag can be used for this feature.
.. code-block:: console
./<build_dir>/app/dpdk-testpmd -a b3:00.0,timestamp=1 <other EAL params> -- <testpmd params>
When the timestamps are enabled with the *devarg*, a timestamp validity flag is set in the MBUFs
When the timestamps are enabled, 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

View File

@ -37,8 +37,7 @@
#define RTE_NFB_DRIVER_NAME net_nfb
/* Device arguments */
#define TIMESTAMP_ARG "timestamp"
static const char * const VALID_KEYS[] = {TIMESTAMP_ARG, NULL};
static const char * const VALID_KEYS[] = {NULL};
struct pmd_internals {
uint16_t max_rxmac;

View File

@ -183,6 +183,22 @@ nfb_eth_dev_stop(struct rte_eth_dev *dev)
static int
nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
{
int ret;
struct pmd_internals *internals = dev->data->dev_private;
struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
ret = rte_mbuf_dyn_rx_timestamp_register
(&nfb_timestamp_dynfield_offset,
&nfb_timestamp_rx_dynflag);
if (ret != 0) {
RTE_LOG(ERR, PMD, "Cannot register Rx timestamp"
" field/flag %d\n", ret);
nfb_close(internals->nfb);
return -rte_errno;
}
}
return 0;
}
@ -203,6 +219,8 @@ nfb_eth_dev_info(struct rte_eth_dev *dev,
dev_info->max_rx_queues = dev->data->nb_rx_queues;
dev_info->max_tx_queues = dev->data->nb_tx_queues;
dev_info->speed_capa = RTE_ETH_LINK_SPEED_100G;
dev_info->rx_offload_capa =
RTE_ETH_RX_OFFLOAD_TIMESTAMP;
return 0;
}
@ -609,4 +627,3 @@ static struct rte_pci_driver nfb_eth_driver = {
RTE_PMD_REGISTER_PCI(RTE_NFB_DRIVER_NAME, nfb_eth_driver);
RTE_PMD_REGISTER_PCI_TABLE(RTE_NFB_DRIVER_NAME, nfb_pci_id_table);
RTE_PMD_REGISTER_KMOD_DEP(RTE_NFB_DRIVER_NAME, "* nfb");
RTE_PMD_REGISTER_PARAM_STRING(RTE_NFB_DRIVER_NAME, TIMESTAMP_ARG "=<0|1>");

View File

@ -12,56 +12,6 @@
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)
{
if (strcmp(value, "1"))
return -1;
return 0;
}
static int
nfb_check_timestamp(struct rte_devargs *devargs)
{
struct rte_kvargs *kvlist;
int ret;
if (devargs == NULL)
return 0;
kvlist = rte_kvargs_parse(devargs->args, NULL);
if (kvlist == NULL)
return 0;
if (!rte_kvargs_count(kvlist, TIMESTAMP_ARG)) {
rte_kvargs_free(kvlist);
return 0;
}
/* Timestamps are enabled when there is
* key-value pair: enable_timestamp=1
* TODO: timestamp should be enabled with RTE_ETH_RX_OFFLOAD_TIMESTAMP
*/
if (rte_kvargs_process(kvlist, TIMESTAMP_ARG,
timestamp_check_handler, NULL) < 0) {
rte_kvargs_free(kvlist);
return 0;
}
rte_kvargs_free(kvlist);
ret = rte_mbuf_dyn_rx_timestamp_register(
&nfb_timestamp_dynfield_offset,
&nfb_timestamp_rx_dynflag);
if (ret != 0) {
RTE_LOG(ERR, PMD, "Cannot register Rx timestamp field/flag\n");
return -rte_errno;
}
return 1;
}
int
nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id)
{
@ -138,9 +88,6 @@ nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
else
rte_free(rxq);
if (nfb_check_timestamp(dev->device->devargs) > 0)
rxq->flags |= NFB_TIMESTAMP_FLAG;
return ret;
}

View File

@ -14,8 +14,6 @@
#include <rte_mbuf_dyn.h>
#include <rte_ethdev.h>
#define NFB_TIMESTAMP_FLAG (1 << 0)
extern uint64_t nfb_timestamp_rx_dynflag;
extern int nfb_timestamp_dynfield_offset;
@ -145,7 +143,6 @@ nfb_eth_ndp_rx(void *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;
@ -163,8 +160,6 @@ nfb_eth_ndp_rx(void *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))
@ -202,7 +197,7 @@ nfb_eth_ndp_rx(void *queue,
mbuf->port = ndp->in_port;
mbuf->ol_flags = 0;
if (timestamping_enabled) {
if (nfb_timestamp_dynfield_offset >= 0) {
rte_mbuf_timestamp_t timestamp;
/* nanoseconds */