summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/drivers/net/nfb
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/spdk/dpdk/drivers/net/nfb
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/dpdk/drivers/net/nfb')
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/Makefile40
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/meson.build11
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb.h57
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_ethdev.c604
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_rx.c174
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_rx.h223
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.c111
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.h77
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_stats.c79
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_stats.h41
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_tx.c113
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/nfb_tx.h194
-rw-r--r--src/spdk/dpdk/drivers/net/nfb/rte_pmd_nfb_version.map3
13 files changed, 1727 insertions, 0 deletions
diff --git a/src/spdk/dpdk/drivers/net/nfb/Makefile b/src/spdk/dpdk/drivers/net/nfb/Makefile
new file mode 100644
index 000000000..e92d29dcd
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/Makefile
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Cesnet
+# Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+# All rights reserved.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_nfb.a
+
+INCLUDES :=-I$(SRCDIR)
+
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+CFLAGS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --cflags netcope-common)
+LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_kvargs
+LDLIBS += -lrte_ethdev -lrte_net
+LDLIBS += -lrte_bus_pci
+LDLIBS += $(shell command -v pkg-config > /dev/null 2>&1 && pkg-config --libs netcope-common)
+
+EXPORT_MAP := rte_pmd_nfb_version.map
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_NFB_PMD) += nfb_ethdev.c
+SRCS-$(CONFIG_RTE_LIBRTE_NFB_PMD) += nfb_rx.c
+SRCS-$(CONFIG_RTE_LIBRTE_NFB_PMD) += nfb_tx.c
+SRCS-$(CONFIG_RTE_LIBRTE_NFB_PMD) += nfb_stats.c
+SRCS-$(CONFIG_RTE_LIBRTE_NFB_PMD) += nfb_rxmode.c
+
+#
+# Export include files
+#
+SYMLINK-y-include +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/src/spdk/dpdk/drivers/net/nfb/meson.build b/src/spdk/dpdk/drivers/net/nfb/meson.build
new file mode 100644
index 000000000..d53e8eca7
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/meson.build
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Cesnet
+# Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+# All rights reserved.
+
+dep = dependency('netcope-common', required: false)
+reason = 'missing dependency, "libnfb"'
+build = dep.found()
+ext_deps += dep
+
+sources = files('nfb_rx.c', 'nfb_tx.c', 'nfb_stats.c', 'nfb_ethdev.c', 'nfb_rxmode.c')
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb.h b/src/spdk/dpdk/drivers/net/nfb/nfb.h
new file mode 100644
index 000000000..59d3ab498
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#ifndef _NFB_H_
+#define _NFB_H_
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+#include <netcope/rxmac.h>
+#include <netcope/txmac.h>
+
+#include "nfb_rx.h"
+#include "nfb_tx.h"
+
+/* PCI Vendor ID */
+#define PCI_VENDOR_ID_NETCOPE 0x1b26
+#define PCI_VENDOR_ID_SILICOM 0x1c2c
+
+/* PCI Device IDs */
+#define PCI_DEVICE_ID_NFB_40G2 0xcb80
+#define PCI_DEVICE_ID_NFB_100G2 0xc2c1
+#define PCI_DEVICE_ID_NFB_200G2QL 0xc250
+#define PCI_DEVICE_ID_FB2CGG3 0x00d0
+#define PCI_DEVICE_ID_FB2CGG3D 0xc240
+
+/* Max index of ndp rx/tx queues */
+#define RTE_ETH_NDP_MAX_RX_QUEUES 32
+#define RTE_ETH_NDP_MAX_TX_QUEUES 32
+
+/* Max index of rx/tx dmas */
+#define RTE_MAX_NC_RXMAC 256
+#define RTE_MAX_NC_TXMAC 256
+
+#define RTE_NFB_DRIVER_NAME net_nfb
+
+/* Device arguments */
+#define TIMESTAMP_ARG "timestamp"
+static const char * const VALID_KEYS[] = {TIMESTAMP_ARG, NULL};
+
+struct pmd_internals {
+ uint16_t max_rxmac;
+ uint16_t max_txmac;
+ struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC];
+ struct nc_txmac *txmac[RTE_MAX_NC_TXMAC];
+
+ char nfb_dev[PATH_MAX];
+ struct nfb_device *nfb;
+ /* Place to remember if filter was promiscuous or filtering by table,
+ * when disabling allmulticast
+ */
+ enum nc_rxmac_mac_filter rx_filter_original;
+};
+
+#endif /* _NFB_H_ */
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_ethdev.c b/src/spdk/dpdk/drivers/net/nfb/nfb_ethdev.c
new file mode 100644
index 000000000..b039ab6fc
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_ethdev.c
@@ -0,0 +1,604 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+#include <netcope/rxmac.h>
+#include <netcope/txmac.h>
+
+#include <rte_ethdev_pci.h>
+#include <rte_kvargs.h>
+
+#include "nfb_stats.h"
+#include "nfb_rx.h"
+#include "nfb_tx.h"
+#include "nfb_rxmode.h"
+#include "nfb.h"
+
+/**
+ * Default MAC addr
+ */
+static const struct rte_ether_addr eth_addr = {
+ .addr_bytes = { 0x00, 0x11, 0x17, 0x00, 0x00, 0x00 }
+};
+
+/**
+ * Open all RX DMA queues
+ *
+ * @param dev
+ * Pointer to nfb device.
+ * @param[out] rxmac
+ * Pointer to output array of nc_rxmac
+ * @param[out] max_rxmac
+ * Pointer to output max index of rxmac
+ */
+static void
+nfb_nc_rxmac_init(struct nfb_device *nfb,
+ struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC],
+ uint16_t *max_rxmac)
+{
+ *max_rxmac = 0;
+ while ((rxmac[*max_rxmac] = nc_rxmac_open_index(nfb, *max_rxmac)))
+ ++(*max_rxmac);
+}
+
+/**
+ * Open all TX DMA queues
+ *
+ * @param dev
+ * Pointer to nfb device.
+ * @param[out] txmac
+ * Pointer to output array of nc_txmac
+ * @param[out] max_rxmac
+ * Pointer to output max index of txmac
+ */
+static void
+nfb_nc_txmac_init(struct nfb_device *nfb,
+ struct nc_txmac *txmac[RTE_MAX_NC_TXMAC],
+ uint16_t *max_txmac)
+{
+ *max_txmac = 0;
+ while ((txmac[*max_txmac] = nc_txmac_open_index(nfb, *max_txmac)))
+ ++(*max_txmac);
+}
+
+/**
+ * Close all RX DMA queues
+ *
+ * @param rxmac
+ * Pointer to array of nc_rxmac
+ * @param max_rxmac
+ * Maximum index of rxmac
+ */
+static void
+nfb_nc_rxmac_deinit(struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC],
+ uint16_t max_rxmac)
+{
+ for (; max_rxmac > 0; --max_rxmac) {
+ nc_rxmac_close(rxmac[max_rxmac]);
+ rxmac[max_rxmac] = NULL;
+ }
+}
+
+/**
+ * Close all TX DMA queues
+ *
+ * @param txmac
+ * Pointer to array of nc_txmac
+ * @param max_txmac
+ * Maximum index of txmac
+ */
+static void
+nfb_nc_txmac_deinit(struct nc_txmac *txmac[RTE_MAX_NC_TXMAC],
+ uint16_t max_txmac)
+{
+ for (; max_txmac > 0; --max_txmac) {
+ nc_txmac_close(txmac[max_txmac]);
+ txmac[max_txmac] = NULL;
+ }
+}
+
+/**
+ * DPDK callback to start the device.
+ *
+ * Start device by starting all configured queues.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_start(struct rte_eth_dev *dev)
+{
+ int ret;
+ uint16_t i;
+ uint16_t nb_rx = dev->data->nb_rx_queues;
+ uint16_t nb_tx = dev->data->nb_tx_queues;
+
+ for (i = 0; i < nb_rx; i++) {
+ ret = nfb_eth_rx_queue_start(dev, i);
+ if (ret != 0)
+ goto err_rx;
+ }
+
+ for (i = 0; i < nb_tx; i++) {
+ ret = nfb_eth_tx_queue_start(dev, i);
+ if (ret != 0)
+ goto err_tx;
+ }
+
+ return 0;
+
+err_tx:
+ for (i = 0; i < nb_tx; i++)
+ nfb_eth_tx_queue_stop(dev, i);
+err_rx:
+ for (i = 0; i < nb_rx; i++)
+ nfb_eth_rx_queue_stop(dev, i);
+ return ret;
+}
+
+/**
+ * DPDK callback to stop the device.
+ *
+ * Stop device by stopping all configured queues.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ */
+static void
+nfb_eth_dev_stop(struct rte_eth_dev *dev)
+{
+ uint16_t i;
+ uint16_t nb_rx = dev->data->nb_rx_queues;
+ uint16_t nb_tx = dev->data->nb_tx_queues;
+
+ for (i = 0; i < nb_tx; i++)
+ nfb_eth_tx_queue_stop(dev, i);
+
+ for (i = 0; i < nb_rx; i++)
+ nfb_eth_rx_queue_stop(dev, i);
+}
+
+/**
+ * DPDK callback for Ethernet device configuration.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
+{
+ return 0;
+}
+
+/**
+ * DPDK callback to get information about the device.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param[out] info
+ * Info structure output buffer.
+ */
+static int
+nfb_eth_dev_info(struct rte_eth_dev *dev,
+ struct rte_eth_dev_info *dev_info)
+{
+ dev_info->max_mac_addrs = 1;
+ dev_info->max_rx_pktlen = (uint32_t)-1;
+ dev_info->max_rx_queues = dev->data->nb_rx_queues;
+ dev_info->max_tx_queues = dev->data->nb_tx_queues;
+ dev_info->speed_capa = ETH_LINK_SPEED_100G;
+
+ return 0;
+}
+
+/**
+ * DPDK callback to close the device.
+ *
+ * Destroy all queues and objects, free memory.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ */
+static void
+nfb_eth_dev_close(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = dev->data->dev_private;
+ uint16_t i;
+ uint16_t nb_rx = dev->data->nb_rx_queues;
+ uint16_t nb_tx = dev->data->nb_tx_queues;
+
+ nfb_eth_dev_stop(dev);
+
+ nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
+ nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+
+ for (i = 0; i < nb_rx; i++) {
+ nfb_eth_rx_queue_release(dev->data->rx_queues[i]);
+ dev->data->rx_queues[i] = NULL;
+ }
+ dev->data->nb_rx_queues = 0;
+ for (i = 0; i < nb_tx; i++) {
+ nfb_eth_tx_queue_release(dev->data->tx_queues[i]);
+ dev->data->tx_queues[i] = NULL;
+ }
+ dev->data->nb_tx_queues = 0;
+
+ rte_free(dev->data->mac_addrs);
+ dev->data->mac_addrs = NULL;
+}
+
+/**
+ * DPDK callback to retrieve physical link information.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param[out] link
+ * Storage for current link status.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_link_update(struct rte_eth_dev *dev,
+ int wait_to_complete __rte_unused)
+{
+ uint16_t i;
+ struct nc_rxmac_status status;
+ struct rte_eth_link link;
+ memset(&link, 0, sizeof(link));
+
+ struct pmd_internals *internals = dev->data->dev_private;
+
+ status.speed = MAC_SPEED_UNKNOWN;
+
+ link.link_speed = ETH_SPEED_NUM_NONE;
+ link.link_status = ETH_LINK_DOWN;
+ link.link_duplex = ETH_LINK_FULL_DUPLEX;
+ link.link_autoneg = ETH_LINK_SPEED_FIXED;
+
+ if (internals->rxmac[0] != NULL) {
+ nc_rxmac_read_status(internals->rxmac[0], &status);
+
+ switch (status.speed) {
+ case MAC_SPEED_10G:
+ link.link_speed = ETH_SPEED_NUM_10G;
+ break;
+ case MAC_SPEED_40G:
+ link.link_speed = ETH_SPEED_NUM_40G;
+ break;
+ case MAC_SPEED_100G:
+ link.link_speed = ETH_SPEED_NUM_100G;
+ break;
+ default:
+ link.link_speed = ETH_SPEED_NUM_NONE;
+ break;
+ }
+ }
+
+ for (i = 0; i < internals->max_rxmac; ++i) {
+ nc_rxmac_read_status(internals->rxmac[i], &status);
+
+ if (status.enabled && status.link_up) {
+ link.link_status = ETH_LINK_UP;
+ break;
+ }
+ }
+
+ rte_eth_linkstatus_set(dev, &link);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to bring the link UP.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_set_link_up(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ uint16_t i;
+ for (i = 0; i < internals->max_rxmac; ++i)
+ nc_rxmac_enable(internals->rxmac[i]);
+
+ for (i = 0; i < internals->max_txmac; ++i)
+ nc_txmac_enable(internals->txmac[i]);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to bring the link DOWN.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_set_link_down(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ uint16_t i;
+ for (i = 0; i < internals->max_rxmac; ++i)
+ nc_rxmac_disable(internals->rxmac[i]);
+
+ for (i = 0; i < internals->max_txmac; ++i)
+ nc_txmac_disable(internals->txmac[i]);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to set primary MAC address.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param mac_addr
+ * MAC address to register.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_mac_addr_set(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mac_addr)
+{
+ unsigned int i;
+ uint64_t mac = 0;
+ struct rte_eth_dev_data *data = dev->data;
+ struct pmd_internals *internals = (struct pmd_internals *)
+ data->dev_private;
+
+ if (!rte_is_valid_assigned_ether_addr(mac_addr))
+ return -EINVAL;
+
+ for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) {
+ mac <<= 8;
+ mac |= mac_addr->addr_bytes[i] & 0xFF;
+ }
+
+ for (i = 0; i < internals->max_rxmac; ++i)
+ nc_rxmac_set_mac(internals->rxmac[i], 0, mac, 1);
+
+ rte_ether_addr_copy(mac_addr, data->mac_addrs);
+ return 0;
+}
+
+static const struct eth_dev_ops ops = {
+ .dev_start = nfb_eth_dev_start,
+ .dev_stop = nfb_eth_dev_stop,
+ .dev_set_link_up = nfb_eth_dev_set_link_up,
+ .dev_set_link_down = nfb_eth_dev_set_link_down,
+ .dev_close = nfb_eth_dev_close,
+ .dev_configure = nfb_eth_dev_configure,
+ .dev_infos_get = nfb_eth_dev_info,
+ .promiscuous_enable = nfb_eth_promiscuous_enable,
+ .promiscuous_disable = nfb_eth_promiscuous_disable,
+ .allmulticast_enable = nfb_eth_allmulticast_enable,
+ .allmulticast_disable = nfb_eth_allmulticast_disable,
+ .rx_queue_start = nfb_eth_rx_queue_start,
+ .rx_queue_stop = nfb_eth_rx_queue_stop,
+ .tx_queue_start = nfb_eth_tx_queue_start,
+ .tx_queue_stop = nfb_eth_tx_queue_stop,
+ .rx_queue_setup = nfb_eth_rx_queue_setup,
+ .tx_queue_setup = nfb_eth_tx_queue_setup,
+ .rx_queue_release = nfb_eth_rx_queue_release,
+ .tx_queue_release = nfb_eth_tx_queue_release,
+ .link_update = nfb_eth_link_update,
+ .stats_get = nfb_eth_stats_get,
+ .stats_reset = nfb_eth_stats_reset,
+ .mac_addr_set = nfb_eth_mac_addr_set,
+};
+
+/**
+ * DPDK callback to initialize an ethernet device
+ *
+ * @param dev
+ * Pointer to ethernet device structure
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_init(struct rte_eth_dev *dev)
+{
+ struct rte_eth_dev_data *data = dev->data;
+ struct pmd_internals *internals = (struct pmd_internals *)
+ data->dev_private;
+ struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+ struct rte_pci_addr *pci_addr = &pci_dev->addr;
+ struct rte_ether_addr eth_addr_init;
+ struct rte_kvargs *kvlist;
+
+ RTE_LOG(INFO, PMD, "Initializing NFB device (" PCI_PRI_FMT ")\n",
+ pci_addr->domain, pci_addr->bus, pci_addr->devid,
+ pci_addr->function);
+
+ snprintf(internals->nfb_dev, PATH_MAX,
+ "/dev/nfb/by-pci-slot/" PCI_PRI_FMT,
+ pci_addr->domain, pci_addr->bus, pci_addr->devid,
+ pci_addr->function);
+
+ /* Check validity of device args */
+ if (dev->device->devargs != NULL &&
+ dev->device->devargs->args != NULL &&
+ strlen(dev->device->devargs->args) > 0) {
+ kvlist = rte_kvargs_parse(dev->device->devargs->args,
+ VALID_KEYS);
+ if (kvlist == NULL) {
+ RTE_LOG(ERR, PMD, "Failed to parse device arguments %s",
+ dev->device->devargs->args);
+ rte_kvargs_free(kvlist);
+ return -EINVAL;
+ }
+ rte_kvargs_free(kvlist);
+ }
+
+ /* Let rte_eth_dev_close() release the port resources */
+ dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
+ /*
+ * Get number of available DMA RX and TX queues, which is maximum
+ * number of queues that can be created and store it in private device
+ * data structure.
+ */
+ internals->nfb = nfb_open(internals->nfb_dev);
+ if (internals->nfb == NULL) {
+ RTE_LOG(ERR, PMD, "nfb_open(): failed to open %s",
+ internals->nfb_dev);
+ return -EINVAL;
+ }
+ data->nb_rx_queues = ndp_get_rx_queue_available_count(internals->nfb);
+ data->nb_tx_queues = ndp_get_tx_queue_available_count(internals->nfb);
+
+ RTE_LOG(INFO, PMD, "Available NDP queues RX: %u TX: %u\n",
+ data->nb_rx_queues, data->nb_tx_queues);
+
+ nfb_nc_rxmac_init(internals->nfb,
+ internals->rxmac,
+ &internals->max_rxmac);
+ nfb_nc_txmac_init(internals->nfb,
+ internals->txmac,
+ &internals->max_txmac);
+
+ /* Set rx, tx burst functions */
+ dev->rx_pkt_burst = nfb_eth_ndp_rx;
+ dev->tx_pkt_burst = nfb_eth_ndp_tx;
+
+ /* Set function callbacks for Ethernet API */
+ dev->dev_ops = &ops;
+
+ /* Get link state */
+ nfb_eth_link_update(dev, 0);
+
+ /* Allocate space for one mac address */
+ data->mac_addrs = rte_zmalloc(data->name, sizeof(struct rte_ether_addr),
+ RTE_CACHE_LINE_SIZE);
+ if (data->mac_addrs == NULL) {
+ RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
+ nfb_close(internals->nfb);
+ return -EINVAL;
+ }
+
+ rte_eth_random_addr(eth_addr_init.addr_bytes);
+ eth_addr_init.addr_bytes[0] = eth_addr.addr_bytes[0];
+ eth_addr_init.addr_bytes[1] = eth_addr.addr_bytes[1];
+ eth_addr_init.addr_bytes[2] = eth_addr.addr_bytes[2];
+
+ nfb_eth_mac_addr_set(dev, &eth_addr_init);
+
+ data->promiscuous = nfb_eth_promiscuous_get(dev);
+ data->all_multicast = nfb_eth_allmulticast_get(dev);
+ internals->rx_filter_original = data->promiscuous;
+
+ RTE_LOG(INFO, PMD, "NFB device ("
+ PCI_PRI_FMT ") successfully initialized\n",
+ pci_addr->domain, pci_addr->bus, pci_addr->devid,
+ pci_addr->function);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to uninitialize an ethernet device
+ *
+ * @param dev
+ * Pointer to ethernet device structure
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_dev_uninit(struct rte_eth_dev *dev)
+{
+ struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+ struct rte_pci_addr *pci_addr = &pci_dev->addr;
+
+ nfb_eth_dev_close(dev);
+
+ RTE_LOG(INFO, PMD, "NFB device ("
+ PCI_PRI_FMT ") successfully uninitialized\n",
+ pci_addr->domain, pci_addr->bus, pci_addr->devid,
+ pci_addr->function);
+
+ return 0;
+}
+
+static const struct rte_pci_id nfb_pci_id_table[] = {
+ { RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE, PCI_DEVICE_ID_NFB_40G2) },
+ { RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE, PCI_DEVICE_ID_NFB_100G2) },
+ { RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE, PCI_DEVICE_ID_NFB_200G2QL) },
+ { RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM, PCI_DEVICE_ID_FB2CGG3) },
+ { RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM, PCI_DEVICE_ID_FB2CGG3D) },
+ { .vendor_id = 0, }
+};
+
+/**
+ * DPDK callback to register a PCI device.
+ *
+ * This function spawns Ethernet devices out of a given PCI device.
+ *
+ * @param[in] pci_drv
+ * PCI driver structure (nfb_driver).
+ * @param[in] pci_dev
+ * PCI device information.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+static int
+nfb_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
+{
+ return rte_eth_dev_pci_generic_probe(pci_dev,
+ sizeof(struct pmd_internals), nfb_eth_dev_init);
+}
+
+/**
+ * DPDK callback to remove a PCI device.
+ *
+ * This function removes all Ethernet devices belong to a given PCI device.
+ *
+ * @param[in] pci_dev
+ * Pointer to the PCI device.
+ *
+ * @return
+ * 0 on success, the function cannot fail.
+ */
+static int
+nfb_eth_pci_remove(struct rte_pci_device *pci_dev)
+{
+ return rte_eth_dev_pci_generic_remove(pci_dev, nfb_eth_dev_uninit);
+}
+
+static struct rte_pci_driver nfb_eth_driver = {
+ .id_table = nfb_pci_id_table,
+ .probe = nfb_eth_pci_probe,
+ .remove = nfb_eth_pci_remove,
+};
+
+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>");
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_rx.c b/src/spdk/dpdk/drivers/net/nfb/nfb_rx.c
new file mode 100644
index 000000000..d97179f81
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_rx.c
@@ -0,0 +1,174 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#include <rte_kvargs.h>
+
+#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;
+
+ 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
+ */
+ if (rte_kvargs_process(kvlist, TIMESTAMP_ARG,
+ 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)
+{
+ struct ndp_rx_queue *rxq = dev->data->rx_queues[rxq_id];
+ int ret;
+
+ if (rxq->queue == NULL) {
+ RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
+ return -EINVAL;
+ }
+
+ ret = ndp_queue_start(rxq->queue);
+ if (ret != 0)
+ goto err;
+ dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STARTED;
+ return 0;
+
+err:
+ return -EINVAL;
+}
+
+int
+nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id)
+{
+ struct ndp_rx_queue *rxq = dev->data->rx_queues[rxq_id];
+ int ret;
+
+ if (rxq->queue == NULL) {
+ RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
+ return -EINVAL;
+ }
+
+ ret = ndp_queue_stop(rxq->queue);
+ if (ret != 0)
+ return -EINVAL;
+
+ dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
+ return 0;
+}
+
+int
+nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
+ uint16_t rx_queue_id,
+ uint16_t nb_rx_desc __rte_unused,
+ unsigned int socket_id,
+ const struct rte_eth_rxconf *rx_conf __rte_unused,
+ struct rte_mempool *mb_pool)
+{
+ struct pmd_internals *internals = dev->data->dev_private;
+
+ struct ndp_rx_queue *rxq;
+ int ret;
+
+ rxq = rte_zmalloc_socket("ndp rx queue",
+ sizeof(struct ndp_rx_queue),
+ RTE_CACHE_LINE_SIZE, socket_id);
+
+ if (rxq == NULL) {
+ RTE_LOG(ERR, PMD, "rte_zmalloc_socket() failed for rx queue id "
+ "%" PRIu16 "!\n", rx_queue_id);
+ return -ENOMEM;
+ }
+
+ rxq->flags = 0;
+
+ ret = nfb_eth_rx_queue_init(internals->nfb,
+ rx_queue_id,
+ dev->data->port_id,
+ mb_pool,
+ rxq);
+
+ if (ret == 0)
+ dev->data->rx_queues[rx_queue_id] = rxq;
+ else
+ rte_free(rxq);
+
+ if (nfb_check_timestamp(dev->device->devargs))
+ rxq->flags |= NFB_TIMESTAMP_FLAG;
+
+ return ret;
+}
+
+int
+nfb_eth_rx_queue_init(struct nfb_device *nfb,
+ uint16_t rx_queue_id,
+ uint16_t port_id,
+ struct rte_mempool *mb_pool,
+ struct ndp_rx_queue *rxq)
+{
+ const struct rte_pktmbuf_pool_private *mbp_priv =
+ rte_mempool_get_priv(mb_pool);
+
+ if (nfb == NULL)
+ return -EINVAL;
+
+ rxq->queue = ndp_open_rx_queue(nfb, rx_queue_id);
+ if (rxq->queue == NULL)
+ return -EINVAL;
+
+ rxq->nfb = nfb;
+ rxq->rx_queue_id = rx_queue_id;
+ rxq->in_port = port_id;
+ rxq->mb_pool = mb_pool;
+ rxq->buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
+ RTE_PKTMBUF_HEADROOM);
+
+ rxq->rx_pkts = 0;
+ rxq->rx_bytes = 0;
+ rxq->err_pkts = 0;
+
+ return 0;
+}
+
+void
+nfb_eth_rx_queue_release(void *q)
+{
+ struct ndp_rx_queue *rxq = (struct ndp_rx_queue *)q;
+ if (rxq->queue != NULL) {
+ ndp_close_rx_queue(rxq->queue);
+ rte_free(rxq);
+ rxq->queue = NULL;
+ }
+}
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_rx.h b/src/spdk/dpdk/drivers/net/nfb/nfb_rx.h
new file mode 100644
index 000000000..cf3899b2f
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_rx.h
@@ -0,0 +1,223 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#ifndef _NFB_RX_H_
+#define _NFB_RX_H_
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+
+#include <rte_mbuf.h>
+#include <rte_ethdev.h>
+
+#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 */
+
+ volatile uint64_t rx_pkts; /* packets read */
+ volatile uint64_t rx_bytes; /* bytes read */
+ volatile uint64_t err_pkts; /* erroneous packets */
+};
+
+/**
+ * Initialize ndp_rx_queue structure
+ *
+ * @param nfb
+ * Pointer to nfb device structure.
+ * @param rx_queue_id
+ * RX queue index.
+ * @param port_id
+ * Device [external] port identifier.
+ * @param mb_pool
+ * Memory pool for buffer allocations.
+ * @param[out] rxq
+ * Pointer to ndp_rx_queue output structure
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_rx_queue_init(struct nfb_device *nfb,
+ uint16_t rx_queue_id,
+ uint16_t port_id,
+ struct rte_mempool *mb_pool,
+ struct ndp_rx_queue *rxq);
+
+/**
+ * DPDK callback to setup a RX queue for use.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param idx
+ * RX queue index.
+ * @param desc
+ * Number of descriptors to configure in queue.
+ * @param socket
+ * NUMA socket on which memory must be allocated.
+ * @param[in] conf
+ * Thresholds parameters.
+ * @param mb_pool
+ * Memory pool for buffer allocations.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
+ uint16_t rx_queue_id,
+ uint16_t nb_rx_desc __rte_unused,
+ unsigned int socket_id,
+ const struct rte_eth_rxconf *rx_conf __rte_unused,
+ struct rte_mempool *mb_pool);
+
+/**
+ * DPDK callback to release a RX queue.
+ *
+ * @param dpdk_rxq
+ * Generic RX queue pointer.
+ */
+void
+nfb_eth_rx_queue_release(void *q);
+
+/**
+ * Start traffic on Rx queue.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param txq_id
+ * RX queue index.
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
+
+/**
+ * Stop traffic on Rx queue.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param txq_id
+ * RX queue index.
+ */
+int
+nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
+
+/**
+ * DPDK callback for RX.
+ *
+ * @param dpdk_rxq
+ * Generic pointer to RX queue structure.
+ * @param[out] bufs
+ * Array to store received packets.
+ * @param nb_pkts
+ * Maximum number of packets in array.
+ *
+ * @return
+ * Number of packets successfully received (<= nb_pkts).
+ */
+static __rte_always_inline uint16_t
+nfb_eth_ndp_rx(void *queue,
+ struct rte_mbuf **bufs,
+ 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;
+ unsigned int i;
+
+ const uint16_t buf_size = ndp->buf_size;
+
+ struct rte_mbuf *mbuf;
+ struct ndp_packet packets[nb_pkts];
+
+ struct rte_mbuf *mbufs[nb_pkts];
+
+ if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
+ RTE_LOG(ERR, PMD, "RX invalid arguments!\n");
+ 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))
+ return 0;
+
+ num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
+
+ if (unlikely(num_rx != nb_pkts)) {
+ for (i = num_rx; i < nb_pkts; i++)
+ rte_pktmbuf_free(mbufs[i]);
+ }
+
+ nb_pkts = num_rx;
+
+ num_rx = 0;
+ /*
+ * Reads the given number of packets from NDP queue given
+ * by queue and copies the packet data into a newly allocated mbuf
+ * to return.
+ */
+ for (i = 0; i < nb_pkts; ++i) {
+ mbuf = mbufs[i];
+
+ /* get the space available for data in the mbuf */
+ packet_size = packets[i].data_length;
+
+ if (likely(packet_size <= buf_size)) {
+ /* NDP packet will fit in one mbuf, go ahead and copy */
+ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
+ packets[i].data, packet_size);
+
+ mbuf->data_len = (uint16_t)packet_size;
+
+ 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 {
+ /*
+ * NDP packet will not fit in one mbuf,
+ * scattered mode is not enabled, drop packet
+ */
+ rte_pktmbuf_free(mbuf);
+ }
+ }
+
+ ndp_rx_burst_put(ndp->queue);
+
+ ndp->rx_pkts += num_rx;
+ ndp->rx_bytes += num_bytes;
+ return num_rx;
+}
+
+#endif /* _NFB_RX_H_ */
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.c b/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.c
new file mode 100644
index 000000000..2d0b613d2
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.c
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#include "nfb_rxmode.h"
+#include "nfb.h"
+
+int
+nfb_eth_promiscuous_enable(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+ uint16_t i;
+
+ internals->rx_filter_original = RXMAC_MAC_FILTER_PROMISCUOUS;
+
+ for (i = 0; i < internals->max_rxmac; ++i) {
+ nc_rxmac_mac_filter_enable(internals->rxmac[i],
+ RXMAC_MAC_FILTER_PROMISCUOUS);
+ }
+
+ return 0;
+}
+
+int
+nfb_eth_promiscuous_disable(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+ uint16_t i;
+
+ internals->rx_filter_original = RXMAC_MAC_FILTER_TABLE;
+
+ /* if promisc is not enabled, do nothing */
+ if (!nfb_eth_promiscuous_get(dev))
+ return 0;
+
+ for (i = 0; i < internals->max_rxmac; ++i) {
+ nc_rxmac_mac_filter_enable(internals->rxmac[i],
+ RXMAC_MAC_FILTER_TABLE);
+ }
+
+ return 0;
+}
+
+int
+nfb_eth_promiscuous_get(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ struct nc_rxmac_status status;
+ status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
+
+ if (internals->max_rxmac > 0)
+ nc_rxmac_read_status(internals->rxmac[0], &status);
+
+ return (status.mac_filter == RXMAC_MAC_FILTER_PROMISCUOUS);
+}
+
+int
+nfb_eth_allmulticast_enable(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ uint16_t i;
+ for (i = 0; i < internals->max_rxmac; ++i) {
+ nc_rxmac_mac_filter_enable(internals->rxmac[i],
+ RXMAC_MAC_FILTER_TABLE_BCAST_MCAST);
+ }
+
+ return 0;
+}
+
+int
+nfb_eth_allmulticast_disable(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ uint16_t i;
+
+ /* if multicast is not enabled do nothing */
+ if (!nfb_eth_allmulticast_get(dev))
+ return 0;
+
+ for (i = 0; i < internals->max_rxmac; ++i) {
+ nc_rxmac_mac_filter_enable(internals->rxmac[i],
+ internals->rx_filter_original);
+ }
+
+ return 0;
+}
+
+int
+nfb_eth_allmulticast_get(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *internals = (struct pmd_internals *)
+ dev->data->dev_private;
+
+ struct nc_rxmac_status status;
+ status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
+
+ if (internals->max_rxmac > 0)
+ nc_rxmac_read_status(internals->rxmac[0], &status);
+
+ return (status.mac_filter == RXMAC_MAC_FILTER_TABLE_BCAST_MCAST);
+}
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.h b/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.h
new file mode 100644
index 000000000..5a29e5ffe
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_rxmode.h
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#ifndef _NFB_RXMODE_H_
+#define _NFB_RXMODE_H_
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+
+#include <rte_ethdev.h>
+
+/**
+ * Getter for promiscuous mode
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @return 1 if enabled 0 otherwise
+ */
+int
+nfb_eth_promiscuous_get(struct rte_eth_dev *dev);
+
+/**
+ * DPDK callback to enable promiscuous mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return always 0
+ */
+int
+nfb_eth_promiscuous_enable(struct rte_eth_dev *dev);
+
+/**
+ * DPDK callback to disable promiscuous mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return always 0
+ */
+int
+nfb_eth_promiscuous_disable(struct rte_eth_dev *dev);
+
+/**
+ * Getter for allmulticast mode
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @return 1 if enabled 0 otherwise
+ */
+int
+nfb_eth_allmulticast_get(struct rte_eth_dev *dev);
+
+/**
+ * DPDK callback to enable allmulticast mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return always 0
+ */
+int
+nfb_eth_allmulticast_enable(struct rte_eth_dev *dev);
+
+/**
+ * DPDK callback to disable allmulticast mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return always 0
+ */
+int
+nfb_eth_allmulticast_disable(struct rte_eth_dev *dev);
+
+#endif /* _NFB_RXMODE_H_ */
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_stats.c b/src/spdk/dpdk/drivers/net/nfb/nfb_stats.c
new file mode 100644
index 000000000..e107dff4b
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_stats.c
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#include "nfb_stats.h"
+#include "nfb.h"
+
+int
+nfb_eth_stats_get(struct rte_eth_dev *dev,
+ struct rte_eth_stats *stats)
+{
+ uint16_t i;
+ uint16_t nb_rx = dev->data->nb_rx_queues;
+ uint16_t nb_tx = dev->data->nb_tx_queues;
+ uint64_t rx_total = 0;
+ uint64_t tx_total = 0;
+ uint64_t tx_err_total = 0;
+ uint64_t rx_total_bytes = 0;
+ uint64_t tx_total_bytes = 0;
+
+ struct ndp_rx_queue *rx_queue = *((struct ndp_rx_queue **)
+ dev->data->rx_queues);
+ struct ndp_tx_queue *tx_queue = *((struct ndp_tx_queue **)
+ dev->data->tx_queues);
+
+ for (i = 0; i < nb_rx; i++) {
+ if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ stats->q_ipackets[i] = rx_queue[i].rx_pkts;
+ stats->q_ibytes[i] = rx_queue[i].rx_bytes;
+ }
+ rx_total += rx_queue[i].rx_pkts;
+ rx_total_bytes += rx_queue[i].rx_bytes;
+ }
+
+ for (i = 0; i < nb_tx; i++) {
+ if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ stats->q_opackets[i] = tx_queue[i].tx_pkts;
+ stats->q_obytes[i] = tx_queue[i].tx_bytes;
+ }
+ tx_total += tx_queue[i].tx_pkts;
+ tx_total_bytes += tx_queue[i].tx_bytes;
+ tx_err_total += tx_queue[i].err_pkts;
+ }
+
+ stats->ipackets = rx_total;
+ stats->opackets = tx_total;
+ stats->ibytes = rx_total_bytes;
+ stats->obytes = tx_total_bytes;
+ stats->oerrors = tx_err_total;
+ return 0;
+}
+
+int
+nfb_eth_stats_reset(struct rte_eth_dev *dev)
+{
+ uint16_t i;
+ uint16_t nb_rx = dev->data->nb_rx_queues;
+ uint16_t nb_tx = dev->data->nb_tx_queues;
+
+ struct ndp_rx_queue *rx_queue = *((struct ndp_rx_queue **)
+ dev->data->rx_queues);
+ struct ndp_tx_queue *tx_queue = *((struct ndp_tx_queue **)
+ dev->data->tx_queues);
+
+ for (i = 0; i < nb_rx; i++) {
+ rx_queue[i].rx_pkts = 0;
+ rx_queue[i].rx_bytes = 0;
+ rx_queue[i].err_pkts = 0;
+ }
+ for (i = 0; i < nb_tx; i++) {
+ tx_queue[i].tx_pkts = 0;
+ tx_queue[i].tx_bytes = 0;
+ tx_queue[i].err_pkts = 0;
+ }
+
+ return 0;
+}
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_stats.h b/src/spdk/dpdk/drivers/net/nfb/nfb_stats.h
new file mode 100644
index 000000000..ad96ea29b
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_stats.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#ifndef _NFB_STATS_H_
+#define _NFB_STATS_H_
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+
+#include <rte_ethdev.h>
+
+/**
+ * DPDK callback to get device statistics.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param[out] stats
+ * Stats structure output buffer.
+ *
+ * @return
+ * 0 on success and stats is filled, negative errno value otherwise.
+ */
+int
+nfb_eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
+
+/**
+ * DPDK callback to clear device statistics.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success, negative errno value otherwise.
+ */
+int
+nfb_eth_stats_reset(struct rte_eth_dev *dev);
+
+#endif /* _NFB_STATS_H_ */
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_tx.c b/src/spdk/dpdk/drivers/net/nfb/nfb_tx.c
new file mode 100644
index 000000000..9b912feb1
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_tx.c
@@ -0,0 +1,113 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#include "nfb_tx.h"
+#include "nfb.h"
+
+int
+nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id)
+{
+ struct ndp_tx_queue *txq = dev->data->tx_queues[txq_id];
+ int ret;
+
+ if (txq->queue == NULL) {
+ RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
+ return -EINVAL;
+ }
+
+ ret = ndp_queue_start(txq->queue);
+ if (ret != 0)
+ goto err;
+ dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STARTED;
+ return 0;
+
+err:
+ return -EINVAL;
+}
+
+int
+nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id)
+{
+ struct ndp_tx_queue *txq = dev->data->tx_queues[txq_id];
+ int ret;
+
+ if (txq->queue == NULL) {
+ RTE_LOG(ERR, PMD, "TX NDP queue is NULL!\n");
+ return -EINVAL;
+ }
+
+ ret = ndp_queue_stop(txq->queue);
+ if (ret != 0)
+ return -EINVAL;
+ dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
+ return 0;
+}
+
+int
+nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
+ uint16_t tx_queue_id,
+ uint16_t nb_tx_desc __rte_unused,
+ unsigned int socket_id,
+ const struct rte_eth_txconf *tx_conf __rte_unused)
+{
+ struct pmd_internals *internals = dev->data->dev_private;
+ int ret;
+ struct ndp_tx_queue *txq;
+
+ txq = rte_zmalloc_socket("ndp tx queue",
+ sizeof(struct ndp_tx_queue),
+ RTE_CACHE_LINE_SIZE, socket_id);
+
+ if (txq == NULL) {
+ RTE_LOG(ERR, PMD, "rte_zmalloc_socket() failed for tx queue id "
+ "%" PRIu16 "!\n", tx_queue_id);
+ return -ENOMEM;
+ }
+
+ ret = nfb_eth_tx_queue_init(internals->nfb,
+ tx_queue_id,
+ txq);
+
+ if (ret == 0)
+ dev->data->tx_queues[tx_queue_id] = txq;
+ else
+ rte_free(txq);
+
+ return ret;
+}
+
+int
+nfb_eth_tx_queue_init(struct nfb_device *nfb,
+ uint16_t tx_queue_id,
+ struct ndp_tx_queue *txq)
+{
+ if (nfb == NULL)
+ return -EINVAL;
+
+ txq->queue = ndp_open_tx_queue(nfb, tx_queue_id);
+ if (txq->queue == NULL)
+ return -EINVAL;
+
+ txq->nfb = nfb;
+ txq->tx_queue_id = tx_queue_id;
+
+ txq->tx_pkts = 0;
+ txq->tx_bytes = 0;
+ txq->err_pkts = 0;
+
+ return 0;
+}
+
+void
+nfb_eth_tx_queue_release(void *q)
+{
+ struct ndp_tx_queue *txq = (struct ndp_tx_queue *)q;
+ if (txq->queue != NULL) {
+ ndp_close_tx_queue(txq->queue);
+ rte_free(txq);
+ txq->queue = NULL;
+ }
+}
diff --git a/src/spdk/dpdk/drivers/net/nfb/nfb_tx.h b/src/spdk/dpdk/drivers/net/nfb/nfb_tx.h
new file mode 100644
index 000000000..b6578cc38
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/nfb_tx.h
@@ -0,0 +1,194 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Cesnet
+ * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
+ * All rights reserved.
+ */
+
+#ifndef _NFB_TX_H_
+#define _NFB_TX_H_
+
+#include <nfb/nfb.h>
+#include <nfb/ndp.h>
+
+#include <rte_ethdev_driver.h>
+#include <rte_ethdev.h>
+#include <rte_malloc.h>
+
+struct ndp_tx_queue {
+ struct nfb_device *nfb; /* nfb dev structure */
+ struct ndp_queue *queue; /* tx queue */
+ uint16_t tx_queue_id; /* index */
+ volatile uint64_t tx_pkts; /* packets transmitted */
+ volatile uint64_t tx_bytes; /* bytes transmitted */
+ volatile uint64_t err_pkts; /* erroneous packets */
+};
+
+/**
+ * DPDK callback to setup a TX queue for use.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param idx
+ * RX queue index.
+ * @param desc
+ * Number of descriptors to configure in queue.
+ * @param socket
+ * NUMA socket on which memory must be allocated.
+ * @param[in] conf
+ * Thresholds parameters.
+ * @param mp
+ * Memory pool for buffer allocations.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
+ uint16_t tx_queue_id,
+ uint16_t nb_tx_desc __rte_unused,
+ unsigned int socket_id,
+ const struct rte_eth_txconf *tx_conf __rte_unused);
+
+/**
+ * Initialize ndp_tx_queue structure
+ *
+ * @param nfb
+ * Pointer to nfb device structure.
+ * @param tx_queue_id
+ * TX queue index.
+ * @param[out] txq
+ * Pointer to ndp_tx_queue output structure
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_tx_queue_init(struct nfb_device *nfb,
+ uint16_t tx_queue_id,
+ struct ndp_tx_queue *txq);
+
+/**
+ * DPDK callback to release a RX queue.
+ *
+ * @param dpdk_rxq
+ * Generic RX queue pointer.
+ */
+void
+nfb_eth_tx_queue_release(void *q);
+
+/**
+ * Start traffic on Tx queue.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param txq_id
+ * TX queue index.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id);
+
+/**
+ * Stop traffic on Tx queue.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param txq_id
+ * TX queue index.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise.
+ */
+int
+nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id);
+
+/**
+ * DPDK callback for TX.
+ *
+ * @param dpdk_txq
+ * Generic pointer to TX queue structure.
+ * @param bufs
+ * Packets to transmit.
+ * @param nb_pkts
+ * Number of packets in array.
+ *
+ * @return
+ * Number of packets successfully transmitted (<= nb_pkts).
+ */
+static __rte_always_inline uint16_t
+nfb_eth_ndp_tx(void *queue,
+ struct rte_mbuf **bufs,
+ uint16_t nb_pkts)
+{
+ int i;
+ struct rte_mbuf *mbuf;
+ struct ndp_tx_queue *ndp = queue;
+ uint16_t num_tx = 0;
+ uint64_t num_bytes = 0;
+
+ void *dst;
+ uint32_t pkt_len;
+ uint8_t mbuf_segs;
+
+ struct ndp_packet packets[nb_pkts];
+
+ if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
+ RTE_LOG(ERR, PMD, "TX invalid arguments!\n");
+ return 0;
+ }
+
+ for (i = 0; i < nb_pkts; i++) {
+ packets[i].data_length = bufs[i]->pkt_len;
+ packets[i].header_length = 0;
+ }
+
+ num_tx = ndp_tx_burst_get(ndp->queue, packets, nb_pkts);
+
+ if (unlikely(num_tx != nb_pkts))
+ return 0;
+
+ for (i = 0; i < nb_pkts; ++i) {
+ mbuf = bufs[i];
+
+ pkt_len = mbuf->pkt_len;
+ mbuf_segs = mbuf->nb_segs;
+
+ num_bytes += pkt_len;
+ if (mbuf_segs == 1) {
+ /*
+ * non-scattered packet,
+ * transmit from one mbuf
+ */
+ rte_memcpy(packets[i].data,
+ rte_pktmbuf_mtod(mbuf, const void *),
+ pkt_len);
+ } else {
+ /* scattered packet, transmit from more mbufs */
+ struct rte_mbuf *m = mbuf;
+ while (m) {
+ dst = packets[i].data;
+
+ rte_memcpy(dst,
+ rte_pktmbuf_mtod(m,
+ const void *),
+ m->data_len);
+ dst = ((uint8_t *)(dst)) +
+ m->data_len;
+ m = m->next;
+ }
+ }
+
+ rte_pktmbuf_free(mbuf);
+ }
+
+ ndp_tx_burst_flush(ndp->queue);
+
+ ndp->tx_pkts += num_tx;
+ ndp->err_pkts += nb_pkts - num_tx;
+ ndp->tx_bytes += num_bytes;
+ return num_tx;
+}
+
+#endif /* _NFB_TX_H_ */
diff --git a/src/spdk/dpdk/drivers/net/nfb/rte_pmd_nfb_version.map b/src/spdk/dpdk/drivers/net/nfb/rte_pmd_nfb_version.map
new file mode 100644
index 000000000..f9f17e4f6
--- /dev/null
+++ b/src/spdk/dpdk/drivers/net/nfb/rte_pmd_nfb_version.map
@@ -0,0 +1,3 @@
+DPDK_20.0 {
+ local: *;
+};