[dpdk-dev] [PATCH] net/nfp: free HW rings memzone on queue release

2022-01-19 Thread heinrich . kuhn
From: Heinrich Kuhn 

During rx/tx queue setup, memory is reserved for the hardware rings.
This memory zone should subsequently be freed in the queue release
logic. This commit also adds a call to the release logic in the
dev_close() callback so that the ring memzone may be freed during port
close too.

Fixes: b812daadad0d ("nfp: add Rx and Tx")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_ethdev.c| 2 ++
 drivers/net/nfp/nfp_ethdev_vf.c | 2 ++
 drivers/net/nfp/nfp_rxtx.c  | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 8e81cc498f..9166f65da3 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -302,11 +302,13 @@ nfp_net_close(struct rte_eth_dev *dev)
for (i = 0; i < dev->data->nb_tx_queues; i++) {
this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
nfp_net_reset_tx_queue(this_tx_q);
+   nfp_net_tx_queue_release(dev, i);
}
 
for (i = 0; i < dev->data->nb_rx_queues; i++) {
this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
nfp_net_reset_rx_queue(this_rx_q);
+   nfp_net_rx_queue_release(dev, i);
}
 
/* Cancel possible impending LSC work here before releasing the port*/
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 303ef72b1b..0034d68ea6 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -219,11 +219,13 @@ nfp_netvf_close(struct rte_eth_dev *dev)
for (i = 0; i < dev->data->nb_tx_queues; i++) {
this_tx_q =  (struct nfp_net_txq *)dev->data->tx_queues[i];
nfp_net_reset_tx_queue(this_tx_q);
+   nfp_net_tx_queue_release(dev, i);
}
 
for (i = 0; i < dev->data->nb_rx_queues; i++) {
this_rx_q =  (struct nfp_net_rxq *)dev->data->rx_queues[i];
nfp_net_reset_rx_queue(this_rx_q);
+   nfp_net_rx_queue_release(dev, i);
}
 
rte_intr_disable(pci_dev->intr_handle);
diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c
index 0fe1415596..335a90b2c9 100644
--- a/drivers/net/nfp/nfp_rxtx.c
+++ b/drivers/net/nfp/nfp_rxtx.c
@@ -470,6 +470,7 @@ nfp_net_rx_queue_release(struct rte_eth_dev *dev, uint16_t 
queue_idx)
 
if (rxq) {
nfp_net_rx_queue_release_mbufs(rxq);
+   rte_eth_dma_zone_free(dev, "rx_ring", queue_idx);
rte_free(rxq->rxbufs);
rte_free(rxq);
}
@@ -660,6 +661,7 @@ nfp_net_tx_queue_release(struct rte_eth_dev *dev, uint16_t 
queue_idx)
 
if (txq) {
nfp_net_tx_queue_release_mbufs(txq);
+   rte_eth_dma_zone_free(dev, "tx_ring", queue_idx);
rte_free(txq->txbufs);
rte_free(txq);
}
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH 0/7] Refactor the NFP PMD

2021-07-16 Thread Heinrich Kuhn
This patch set restructures the NFP PMD, aligning it more with the
common layout adopted by most other PMD's. Although the changes look
fairly large, functionally nothing is added or removed from the driver
and the existing code is mostly just reorganized into the familiar
structure seen in other PMD's. Apart form adopting the common PMD layout
this change should also aid in future feature development to the NFP
PMD. The previous layout where most of the logic resided in a single
file (nfp_net.c) would have become tedious to support going forward.

Heinrich Kuhn (7):
  net/nfp: split rxtx headers into separate file
  net/nfp: move rxtx functions to their own file
  net/nfp: move CPP bridge to a separate file
  net/nfp: prototype common functions in header file
  net/nfp: move VF functions into new file
  net/nfp: move PF functions into new file
  net/nfp: batch file rename for consistency

 drivers/net/nfp/meson.build   |6 +-
 drivers/net/nfp/nfp_common.c  | 1322 ++
 drivers/net/nfp/nfp_common.h  |  413 ++
 drivers/net/nfp/nfp_cpp_bridge.c  |  392 ++
 drivers/net/nfp/nfp_cpp_bridge.h  |   36 +
 .../net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}|6 +-
 drivers/net/nfp/nfp_ethdev.c  | 1099 +
 drivers/net/nfp/nfp_ethdev_vf.c   |  504 +++
 .../net/nfp/{nfp_net_logs.h => nfp_logs.h}|6 +-
 drivers/net/nfp/nfp_net.c | 3921 -
 drivers/net/nfp/nfp_rxtx.c| 1002 +
 drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} |  279 +-
 12 files changed, 4815 insertions(+), 4171 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_common.c
 create mode 100644 drivers/net/nfp/nfp_common.h
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)
 delete mode 100644 drivers/net/nfp/nfp_net.c
 create mode 100644 drivers/net/nfp/nfp_rxtx.c
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} (54%)

-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH 1/7] net/nfp: split rxtx headers into separate file

2021-07-16 Thread Heinrich Kuhn
This change splits out the rx/tx specific structs and defines from the
main nfp_net_pmd header file and into their own header file.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/nfp_net.c |   1 +
 drivers/net/nfp/nfp_net_pmd.h | 248 --
 drivers/net/nfp/nfp_rxtx.h| 276 ++
 3 files changed, 277 insertions(+), 248 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.h

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index b18edd8c7b..67288abeff 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -38,6 +38,7 @@
 #include "nfpcore/nfp_nsp.h"
 
 #include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
 #include "nfp_net_logs.h"
 #include "nfp_net_ctrl.h"
 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h
index 212f9ef162..a3a3ba32d6 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_net_pmd.h
@@ -23,19 +23,6 @@
 /* Forward declaration */
 struct nfp_net_adapter;
 
-/*
- * The maximum number of descriptors is limited by design as
- * DPDK uses uint16_t variables for these values
- */
-#define NFP_NET_MAX_TX_DESC (32 * 1024)
-#define NFP_NET_MIN_TX_DESC 64
-
-#define NFP_NET_MAX_RX_DESC (32 * 1024)
-#define NFP_NET_MIN_RX_DESC 64
-
-/* Descriptor alignment */
-#define NFP_ALIGN_RING_DESC 128
-
 #define NFP_TX_MAX_SEG UINT8_MAX
 #define NFP_TX_MAX_MTU_SEG 8
 
@@ -150,241 +137,6 @@ static inline void nn_writeq(uint64_t val, volatile void 
*addr)
nn_writel(val, addr);
 }
 
-/* TX descriptor format */
-#define PCIE_DESC_TX_EOP(1 << 7)
-#define PCIE_DESC_TX_OFFSET_MASK(0x7f)
-
-/* Flags in the host TX descriptor */
-#define PCIE_DESC_TX_CSUM   (1 << 7)
-#define PCIE_DESC_TX_IP4_CSUM   (1 << 6)
-#define PCIE_DESC_TX_TCP_CSUM   (1 << 5)
-#define PCIE_DESC_TX_UDP_CSUM   (1 << 4)
-#define PCIE_DESC_TX_VLAN   (1 << 3)
-#define PCIE_DESC_TX_LSO(1 << 2)
-#define PCIE_DESC_TX_ENCAP_NONE (0)
-#define PCIE_DESC_TX_ENCAP_VXLAN(1 << 1)
-#define PCIE_DESC_TX_ENCAP_GRE  (1 << 0)
-
-struct nfp_net_tx_desc {
-   union {
-   struct {
-   uint8_t dma_addr_hi; /* High bits of host buf address */
-   __le16 dma_len; /* Length to DMA for this desc */
-   uint8_t offset_eop; /* Offset in buf where pkt starts +
-* highest bit is eop flag.
-*/
-   __le32 dma_addr_lo; /* Low 32bit of host buf addr */
-
-   __le16 mss; /* MSS to be used for LSO */
-   uint8_t lso_hdrlen; /* LSO, where the data starts */
-   uint8_t flags;  /* TX Flags, see @PCIE_DESC_TX_* */
-
-   union {
-   struct {
-   /*
-* L3 and L4 header offsets required
-* for TSOv2
-*/
-   uint8_t l3_offset;
-   uint8_t l4_offset;
-   };
-   __le16 vlan; /* VLAN tag to add if indicated */
-   };
-   __le16 data_len;/* Length of frame + meta data */
-   } __rte_packed;
-   __le32 vals[4];
-   };
-};
-
-struct nfp_net_txq {
-   struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
-
-   /*
-* Queue information: @qidx is the queue index from Linux's
-* perspective.  @tx_qcidx is the index of the Queue
-* Controller Peripheral queue relative to the TX queue BAR.
-* @cnt is the size of the queue in number of
-* descriptors. @qcp_q is a pointer to the base of the queue
-* structure on the NFP
-*/
-   uint8_t *qcp_q;
-
-   /*
-* Read and Write pointers.  @wr_p and @rd_p are host side pointer,
-* they are free running and have little relation to the QCP pointers *
-* @qcp_rd_p is a local copy queue controller peripheral read pointer
-*/
-
-   uint32_t wr_p;
-   uint32_t rd_p;
-
-   uint32_t tx_count;
-
-   uint32_t tx_free_thresh;
-
-   /*
-* For each descriptor keep a reference to the mbuf and
-* DMA address used until completion is signalled.
-*/
-   struct {
-   struct rte_mbuf *mbuf;
-   } *txbufs;
-
-   /*
-* Information about the host side queue location. @txds is
-* the virtual address for the queue, @dma is the DMA address
-* of the queue and @size is 

[dpdk-dev] [PATCH 2/7] net/nfp: move rxtx functions to their own file

2021-07-16 Thread Heinrich Kuhn
Create a new rxtx file and move the Rx/Tx functions to this file. This
commit will also move the needed shared functions to the nfp_net_pmd.h
file as needed.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/meson.build   |1 +
 drivers/net/nfp/nfp_net.c | 1090 -
 drivers/net/nfp/nfp_net_pmd.h |  184 --
 drivers/net/nfp/nfp_rxtx.c| 1002 ++
 drivers/net/nfp/nfp_rxtx.h|   27 +
 5 files changed, 1173 insertions(+), 1131 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b51e2e5f20..1b289e2354 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -19,4 +19,5 @@ sources = files(
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
+'nfp_rxtx.c',
 )
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 67288abeff..5bfc23ba04 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -66,29 +66,11 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
 static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq);
-static uint32_t nfp_net_rx_queue_count(struct rte_eth_dev *dev,
-  uint16_t queue_idx);
-static uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
- uint16_t nb_pkts);
-static void nfp_net_rx_queue_release(void *rxq);
-static int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_rxconf *rx_conf,
- struct rte_mempool *mp);
-static int nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
-static void nfp_net_tx_queue_release(void *txq);
-static int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_txconf *tx_conf);
 static int nfp_net_start(struct rte_eth_dev *dev);
 static int nfp_net_stats_get(struct rte_eth_dev *dev,
  struct rte_eth_stats *stats);
 static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static uint16_t nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
- uint16_t nb_pkts);
-
 static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
   struct rte_eth_rss_conf *rss_conf);
@@ -106,184 +88,6 @@ static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_eth_table *nfp_eth_table,
struct nfp_hwinfo *hwinfo);
 
-
-/* The offset of the queue controller queues in the PCIe Target */
-#define NFP_PCIE_QUEUE(_q) (0x8 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
-
-/* Maximum value which can be added to a queue with one transaction */
-#define NFP_QCP_MAX_ADD0x7f
-
-#define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
-   (uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM)
-
-/* nfp_qcp_ptr - Read or Write Pointer of a queue */
-enum nfp_qcp_ptr {
-   NFP_QCP_READ_PTR = 0,
-   NFP_QCP_WRITE_PTR
-};
-
-/*
- * nfp_qcp_ptr_add - Add the value to the selected pointer of a queue
- * @q: Base address for queue structure
- * @ptr: Add to the Read or Write pointer
- * @val: Value to add to the queue pointer
- *
- * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
- */
-static inline void
-nfp_qcp_ptr_add(uint8_t *q, enum nfp_qcp_ptr ptr, uint32_t val)
-{
-   uint32_t off;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_ADD_RPTR;
-   else
-   off = NFP_QCP_QUEUE_ADD_WPTR;
-
-   while (val > NFP_QCP_MAX_ADD) {
-   nn_writel(rte_cpu_to_le_32(NFP_QCP_MAX_ADD), q + off);
-   val -= NFP_QCP_MAX_ADD;
-   }
-
-   nn_writel(rte_cpu_to_le_32(val), q + off);
-}
-
-/*
- * nfp_qcp_read - Read the current Read/Write pointer value for a queue
- * @q:  Base address for queue structure
- * @ptr: Read or Write pointer
- */
-static inline uint32_t
-nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr)
-{
-   uint32_t off;
-   uint32_t val;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_STS_LO;
-   else
-   off = NFP_QCP_QUEUE_STS_HI;
-
-   val = rte_cpu_to_le_32(nn_readl(q + off));
-
-   if (ptr == NFP_QCP_READ_PTR)
-   return val & NFP_QCP_QUEUE_STS_LO

[dpdk-dev] [PATCH 3/7] net/nfp: move CPP bridge to a separate file

2021-07-16 Thread Heinrich Kuhn
This commit moves the CPP bridge logic to a separate file. A new
corresponding header file is also created.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/meson.build  |   1 +
 drivers/net/nfp/nfp_cpp_bridge.c | 392 +++
 drivers/net/nfp/nfp_cpp_bridge.h |  36 +++
 drivers/net/nfp/nfp_net.c| 367 +
 4 files changed, 430 insertions(+), 366 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 1b289e2354..b46ac2d40f 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -20,4 +20,5 @@ sources = files(
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
 'nfp_rxtx.c',
+'nfp_cpp_bridge.c',
 )
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
new file mode 100644
index 00..d916793338
--- /dev/null
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_cpp_bridge.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: CPP Bridge
+ */
+
+#include 
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_logs.h"
+#include "nfp_cpp_bridge.h"
+
+#include 
+
+/* Prototypes */
+static int nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp);
+
+void nfp_register_cpp_service(struct nfp_cpp *cpp)
+{
+   uint32_t *cpp_service_id = NULL;
+   struct rte_service_spec service;
+
+   memset(&service, 0, sizeof(struct rte_service_spec));
+   snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+   service.callback = nfp_cpp_bridge_service_func;
+   service.callback_userdata = (void *)cpp;
+
+   if (rte_service_component_register(&service,
+  cpp_service_id))
+   RTE_LOG(WARNING, PMD, "NFP CPP bridge service register() 
failed");
+   else
+   RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+}
+
+/*
+ * Serving a write request to NFP from host programs. The request
+ * sends the write size and the CPP target. The bridge makes use
+ * of CPP interface handler configured by the PMD setup.
+ */
+static int
+nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp)
+{
+   struct nfp_cpp_area *area;
+   off_t offset, nfp_offset;
+   uint32_t cpp_id, pos, len;
+   uint32_t tmpbuf[16];
+   size_t count, curlen, totlen = 0;
+   int err = 0;
+
+   PMD_CPP_LOG(DEBUG, "%s: offset size %zu, count_size: %zu\n", __func__,
+   sizeof(off_t), sizeof(size_t));
+
+   /* Reading the count param */
+   err = recv(sockfd, &count, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   curlen = count;
+
+   /* Reading the offset param */
+   err = recv(sockfd, &offset, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   /* Obtain target's CPP ID and offset in target */
+   cpp_id = (offset >> 40) << 8;
+   nfp_offset = offset & ((1ull << 40) - 1);
+
+   PMD_CPP_LOG(DEBUG, "%s: count %zu and offset %jd\n", __func__, count,
+   offset);
+   PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %jd\n", __func__,
+   cpp_id, nfp_offset);
+
+   /* Adjust length if not aligned */
+   if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
+   (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
+   curlen = NFP_CPP_MEMIO_BOUNDARY -
+   (nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
+   }
+
+   while (count > 0) {
+   /* configure a CPP PCIe2CPP BAR for mapping the CPP target */
+   area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
+   nfp_offset, curlen);
+   if (!area) {
+   RTE_LOG(ERR, PMD, "%s: area alloc fail\n", __func__);
+   return -EIO;
+   }
+
+   /* mapping the target */
+   err = nfp_cpp_area_acquire(area);
+   if (err < 0) {
+   RTE_LOG(ERR, PMD, "area acquire failed\n");
+ 

[dpdk-dev] [PATCH 4/7] net/nfp: prototype common functions in header file

2021-07-16 Thread Heinrich Kuhn
The majority of "ethdev" type functions are used for both PF devices and
VF devices. Prototype these functions in the nfp_net_pmd header file in
preparation of splitting PF and VF specific functions.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/nfp_net.c | 87 +--
 drivers/net/nfp/nfp_net_pmd.h | 49 
 2 files changed, 81 insertions(+), 55 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index d79c70c5b7..da35bba4ef 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -53,35 +53,12 @@
 
 /* Prototypes */
 static int nfp_net_close(struct rte_eth_dev *dev);
-static int nfp_net_configure(struct rte_eth_dev *dev);
-static void nfp_net_dev_interrupt_handler(void *param);
-static void nfp_net_dev_interrupt_delayed_handler(void *param);
-static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
-static int nfp_net_infos_get(struct rte_eth_dev *dev,
-struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_pci_device *pci_dev);
 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
-static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
-static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
-static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_start(struct rte_eth_dev *dev);
-static int nfp_net_stats_get(struct rte_eth_dev *dev,
- struct rte_eth_stats *stats);
-static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
-static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
-  struct rte_eth_rss_conf *rss_conf);
-static int nfp_net_rss_reta_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_reta_entry64 *reta_conf,
-   uint16_t reta_size);
-static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_conf *rss_conf);
-static int nfp_set_mac_addr(struct rte_eth_dev *dev,
-struct rte_ether_addr *mac_addr);
 static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_cpp *cpp,
struct nfp_eth_table *nfp_eth_table,
@@ -136,7 +113,7 @@ __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
  * Write the update word to the BAR and ping the reconfig queue. Then poll
  * until the firmware has acknowledged the update by zeroing the update word.
  */
-static int
+int
 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
 {
uint32_t err;
@@ -172,7 +149,7 @@ nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, 
uint32_t update)
  * before any other function in the Ethernet API. This function can
  * also be re-invoked when a device is in the stopped state.
  */
-static int
+int
 nfp_net_configure(struct rte_eth_dev *dev)
 {
struct rte_eth_conf *dev_conf;
@@ -215,7 +192,7 @@ nfp_net_configure(struct rte_eth_dev *dev)
return 0;
 }
 
-static void
+void
 nfp_net_enable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -239,7 +216,7 @@ nfp_net_enable_queues(struct rte_eth_dev *dev)
nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
 }
 
-static void
+void
 nfp_net_disable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -264,14 +241,14 @@ nfp_net_disable_queues(struct rte_eth_dev *dev)
hw->ctrl = new_ctrl;
 }
 
-static void
+void
 nfp_net_params_setup(struct nfp_net_hw *hw)
 {
nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
 }
 
-static void
+void
 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 {
hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
@@ -279,7 +256,7 @@ nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 
 #define ETH_ADDR_LEN   6
 
-static void
+void
 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
 {
int i;
@@ -318,7 +295,7 @@ nfp_net_vf_read_mac(struct nfp_net_hw *hw)
memcpy(&hw->mac_addr[4], &tmp, 2);
 }
 
-static void
+void
 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
 {
uint32_t mac0 = *(uint32_t *)mac;
@@ -366,7 +343,7 @@ nfp_set_mac_addr(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac_addr)
return 0;
 }
 
-static int
+int
 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
   struct rte_intr_handle *intr_handle)
 {
@@ -410,7 +387,7 @@ nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
return 0;
 }
 
-static uint32_t
+uint32_t
 nfp_check_offloads(struct rte_eth_dev *dev)
 {

[dpdk-dev] [PATCH 5/7] net/nfp: move VF functions into new file

2021-07-16 Thread Heinrich Kuhn
Move any ethdev functionality specific to VF devices into a new file
called nfp_ethdev_vf.c.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/meson.build |   1 +
 drivers/net/nfp/nfp_ethdev_vf.c | 504 
 drivers/net/nfp/nfp_net.c   |  42 +--
 3 files changed, 506 insertions(+), 41 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b46ac2d40f..34f4054b3c 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -21,4 +21,5 @@ sources = files(
 'nfp_net.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
+'nfp_ethdev_vf.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
new file mode 100644
index 00..223142c0ed
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -0,0 +1,504 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev_vf.c
+ *
+ * Netronome vNIC  VF DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+
+static void nfp_netvf_read_mac(struct nfp_net_hw *hw);
+static int nfp_netvf_start(struct rte_eth_dev *dev);
+static int nfp_netvf_stop(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_up(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_down(struct rte_eth_dev *dev);
+static int nfp_netvf_close(struct rte_eth_dev *dev);
+static int nfp_netvf_init(struct rte_eth_dev *eth_dev);
+static int nfp_vf_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_vf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *pci_dev);
+static int eth_nfp_vf_pci_remove(struct rte_pci_device *pci_dev);
+
+static void
+nfp_netvf_read_mac(struct nfp_net_hw *hw)
+{
+   uint32_t tmp;
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
+   memcpy(&hw->mac_addr[0], &tmp, 4);
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
+   memcpy(&hw->mac_addr[4], &tmp, 2);
+}
+
+static int
+nfp_netvf_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.
+* Unregistering LSC interrupt handler
+*/
+   rte_intr_callback_unregister(&pci_dev->intr_handle,
+   nfp_net_dev_interrupt_handler, (void *)dev);
+
+   if (dev->data->nb_rx_queues > 1) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt only "
+"supports 1 queue with UIO");
+   return -EIO;
+   }
+   }
+   intr_vector = dev->data->nb_rx_queues;
+   if (rte_intr_efd_enable(intr_handle, intr_vector))
+   return -1;
+
+   nfp_configure_rx_interrupt(dev, intr_handle);
+   update = NFP_NET_CFG_UPDATE_MSIX;
+   }
+
+   rte_intr_enable(intr_handle);
+
+   new_ctrl = nfp_check_offloads(dev);
+
+   /* Writing configuration parameters in the device */
+   nfp_net_params_setup(hw);
+
+   dev_conf = &dev->data->dev_conf;
+   rxmode = &dev_conf->rxmode;
+
+   if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
+   nfp_net_rss_config_default(dev);
+   update |= NFP_NET_CFG_UPDATE_RSS;
+   new_ctrl |= NFP_NET_CFG_CTRL_RSS;
+   }
+
+   /* Enable device */
+   new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
+
+   update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET

[dpdk-dev] [PATCH 6/7] net/nfp: move PF functions into new file

2021-07-16 Thread Heinrich Kuhn
Similar to the last commit, this changeset moves all the PF specific
functions to a new file called nfp_ethdev.c.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/meson.build  |1 +
 drivers/net/nfp/nfp_ethdev.c | 1099 ++
 drivers/net/nfp/nfp_net.c| 1088 +
 3 files changed, 1103 insertions(+), 1085 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 34f4054b3c..ab64d0cac3 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -22,4 +22,5 @@ sources = files(
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
+'nfp_ethdev.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
new file mode 100644
index 00..ab08906704
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -0,0 +1,1099 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_nffw.h"
+#include "nfpcore/nfp_hwinfo.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+#include "nfp_cpp_bridge.h"
+
+
+static int nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port);
+static int nfp_net_start(struct rte_eth_dev *dev);
+static int nfp_net_stop(struct rte_eth_dev *dev);
+static int nfp_net_set_link_up(struct rte_eth_dev *dev);
+static int nfp_net_set_link_down(struct rte_eth_dev *dev);
+static int nfp_net_close(struct rte_eth_dev *dev);
+static int nfp_net_init(struct rte_eth_dev *eth_dev);
+static int nfp_fw_upload(struct rte_pci_device *dev,
+struct nfp_nsp *nsp, char *card);
+static int nfp_fw_setup(struct rte_pci_device *dev,
+   struct nfp_cpp *cpp,
+   struct nfp_eth_table *nfp_eth_table,
+   struct nfp_hwinfo *hwinfo);
+static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
+static int nfp_pf_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *dev);
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev);
+
+static int
+nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
+{
+   struct nfp_eth_table *nfp_eth_table;
+   struct nfp_net_hw *hw = NULL;
+
+   /* Grab a pointer to the correct physical port */
+   hw = pf_dev->ports[port];
+
+   nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
+
+   nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
+(uint8_t *)&nfp_eth_table->ports[port].mac_addr);
+
+   free(nfp_eth_table);
+   return 0;
+}
+
+static int
+nfp_net_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct nfp_pf_dev *pf_dev;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (pf_dev->multiport) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
+ "with NFP multiport PF");
+   return -EINVAL;
+   }
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.
+* Unregistering LSC interrupt handler
+  

[dpdk-dev] [PATCH 7/7] net/nfp: batch file rename for consistency

2021-07-16 Thread Heinrich Kuhn
Rename the nfp_net.c file to nfp_common as it now contains functions
common to VF and PF functionality. Rename the header file too to be
consistent. Also remove the "net" naming from the _ctrl and _logs files
for consistency across the PMD.

Signed-off-by: Heinrich Kuhn 
---
 drivers/net/nfp/meson.build | 2 +-
 drivers/net/nfp/{nfp_net.c => nfp_common.c} | 4 ++--
 drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} | 6 +++---
 drivers/net/nfp/nfp_cpp_bridge.c| 2 +-
 drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}  | 6 +++---
 drivers/net/nfp/nfp_ethdev.c| 6 +++---
 drivers/net/nfp/nfp_ethdev_vf.c | 6 +++---
 drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h}  | 6 +++---
 drivers/net/nfp/nfp_rxtx.c  | 6 +++---
 9 files changed, 22 insertions(+), 22 deletions(-)
 rename drivers/net/nfp/{nfp_net.c => nfp_common.c} (99%)
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} (99%)
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index ab64d0cac3..810f02ae5b 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -18,7 +18,7 @@ sources = files(
 'nfpcore/nfp_mutex.c',
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
-'nfp_net.c',
+'nfp_common.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_common.c
similarity index 99%
rename from drivers/net/nfp/nfp_net.c
rename to drivers/net/nfp/nfp_common.c
index a6097eaab0..87e8f5f333 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -8,9 +8,9 @@
 /*
  * vim:shiftwidth=8:noexpandtab
  *
- * @file dpdk/pmd/nfp_net.c
+ * @file dpdk/pmd/nfp_common.c
  *
- * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ * Netronome vNIC DPDK Poll-Mode Driver: Common files
  */
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_common.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_pmd.h
rename to drivers/net/nfp/nfp_common.h
index dc05e888df..54ac937bd2 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -11,8 +11,8 @@
  * Netronome NFP_NET PMD driver
  */
 
-#ifndef _NFP_NET_PMD_H_
-#define _NFP_NET_PMD_H_
+#ifndef _NFP_COMMON_H_
+#define _NFP_COMMON_H_
 
 #define NFP_NET_PMD_VERSION "0.1"
 #define PCI_VENDOR_ID_NETRONOME 0x19ee
@@ -404,7 +404,7 @@ int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 #define NFP_NET_DEV_PRIVATE_TO_PF(dev_priv)\
(((struct nfp_net_hw *)dev_priv)->pf_dev)
 
-#endif /* _NFP_NET_PMD_H_ */
+#endif /* _NFP_COMMON_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
index d916793338..74a0eacb3f 100644
--- a/drivers/net/nfp/nfp_cpp_bridge.c
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -19,7 +19,7 @@
 #include "nfpcore/nfp_mip.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_logs.h"
+#include "nfp_logs.h"
 #include "nfp_cpp_bridge.h"
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_ctrl.h
rename to drivers/net/nfp/nfp_ctrl.h
index 4f26ccf483..4dd62ef194 100644
--- a/drivers/net/nfp/nfp_net_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -8,8 +8,8 @@
  *
  * Netronome network device driver: Control BAR layout
  */
-#ifndef _NFP_NET_CTRL_H_
-#define _NFP_NET_CTRL_H_
+#ifndef _NFP_CTRL_H_
+#define _NFP_CTRL_H_
 
 /*
  * Configuration BAR size.
@@ -317,7 +317,7 @@
 /* PF multiport offset */
 #define NFP_PF_CSR_SLICE_SIZE  (32 * 1024)
 
-#endif /* _NFP_NET_CTRL_H_ */
+#endif /* _NFP_CTRL_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index ab08906704..29e6bb128a 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -30,10 +30,10 @@
 #include "nfpcore/nfp_rtsym.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_pmd.h"
+#include "nfp_common.h"
 #include "nfp_rxtx.h"
-#include "nfp_net_logs.h"
-#include "nfp_net_ctrl.h"
+#include "nfp_logs.h"
+#include "nfp_ctrl.h"
 #include "nfp_cpp_bridge.h"
 
 
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 223142c0ed..b697b55865 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -16,10 +16,10 @@
 #include "nfpcore/nfp_mip.h"
 #include "nfpcore/nfp_rtsym.h"

[dpdk-dev] [PATCH v2 0/7] Refactor the NFP PMD

2021-07-16 Thread Heinrich Kuhn
This patch set restructures the NFP PMD, aligning it more with the
common layout adopted by most other PMD's. Although the changes look
fairly large, functionally nothing is added or removed from the driver
and the existing code is mostly just reorganized into the familiar
structure seen in other PMD's. Apart form adopting the common PMD layout
this change should also aid in future feature development to the NFP
PMD. The previous layout where most of the logic resided in a single
file (nfp_net.c) would have become tedious to support going forward.

v2:
* Added missing sign-off's

Heinrich Kuhn (7):
  net/nfp: split rxtx headers into separate file
  net/nfp: move rxtx functions to their own file
  net/nfp: move CPP bridge to a separate file
  net/nfp: prototype common functions in header file
  net/nfp: move VF functions into new file
  net/nfp: move PF functions into new file
  net/nfp: batch file rename for consistency

 drivers/net/nfp/meson.build   |6 +-
 drivers/net/nfp/nfp_common.c  | 1322 ++
 drivers/net/nfp/nfp_common.h  |  413 ++
 drivers/net/nfp/nfp_cpp_bridge.c  |  392 ++
 drivers/net/nfp/nfp_cpp_bridge.h  |   36 +
 .../net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}|6 +-
 drivers/net/nfp/nfp_ethdev.c  | 1099 +
 drivers/net/nfp/nfp_ethdev_vf.c   |  504 +++
 .../net/nfp/{nfp_net_logs.h => nfp_logs.h}|6 +-
 drivers/net/nfp/nfp_net.c | 3921 -
 drivers/net/nfp/nfp_rxtx.c| 1002 +
 drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} |  279 +-
 12 files changed, 4815 insertions(+), 4171 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_common.c
 create mode 100644 drivers/net/nfp/nfp_common.h
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)
 delete mode 100644 drivers/net/nfp/nfp_net.c
 create mode 100644 drivers/net/nfp/nfp_rxtx.c
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} (54%)

-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH v2 1/7] net/nfp: split rxtx headers into separate file

2021-07-16 Thread Heinrich Kuhn
This change splits out the rx/tx specific structs and defines from the
main nfp_net_pmd header file and into their own header file.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c |   1 +
 drivers/net/nfp/nfp_net_pmd.h | 248 --
 drivers/net/nfp/nfp_rxtx.h| 276 ++
 3 files changed, 277 insertions(+), 248 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.h

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index b18edd8c7b..67288abeff 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -38,6 +38,7 @@
 #include "nfpcore/nfp_nsp.h"
 
 #include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
 #include "nfp_net_logs.h"
 #include "nfp_net_ctrl.h"
 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h
index 212f9ef162..a3a3ba32d6 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_net_pmd.h
@@ -23,19 +23,6 @@
 /* Forward declaration */
 struct nfp_net_adapter;
 
-/*
- * The maximum number of descriptors is limited by design as
- * DPDK uses uint16_t variables for these values
- */
-#define NFP_NET_MAX_TX_DESC (32 * 1024)
-#define NFP_NET_MIN_TX_DESC 64
-
-#define NFP_NET_MAX_RX_DESC (32 * 1024)
-#define NFP_NET_MIN_RX_DESC 64
-
-/* Descriptor alignment */
-#define NFP_ALIGN_RING_DESC 128
-
 #define NFP_TX_MAX_SEG UINT8_MAX
 #define NFP_TX_MAX_MTU_SEG 8
 
@@ -150,241 +137,6 @@ static inline void nn_writeq(uint64_t val, volatile void 
*addr)
nn_writel(val, addr);
 }
 
-/* TX descriptor format */
-#define PCIE_DESC_TX_EOP(1 << 7)
-#define PCIE_DESC_TX_OFFSET_MASK(0x7f)
-
-/* Flags in the host TX descriptor */
-#define PCIE_DESC_TX_CSUM   (1 << 7)
-#define PCIE_DESC_TX_IP4_CSUM   (1 << 6)
-#define PCIE_DESC_TX_TCP_CSUM   (1 << 5)
-#define PCIE_DESC_TX_UDP_CSUM   (1 << 4)
-#define PCIE_DESC_TX_VLAN   (1 << 3)
-#define PCIE_DESC_TX_LSO(1 << 2)
-#define PCIE_DESC_TX_ENCAP_NONE (0)
-#define PCIE_DESC_TX_ENCAP_VXLAN(1 << 1)
-#define PCIE_DESC_TX_ENCAP_GRE  (1 << 0)
-
-struct nfp_net_tx_desc {
-   union {
-   struct {
-   uint8_t dma_addr_hi; /* High bits of host buf address */
-   __le16 dma_len; /* Length to DMA for this desc */
-   uint8_t offset_eop; /* Offset in buf where pkt starts +
-* highest bit is eop flag.
-*/
-   __le32 dma_addr_lo; /* Low 32bit of host buf addr */
-
-   __le16 mss; /* MSS to be used for LSO */
-   uint8_t lso_hdrlen; /* LSO, where the data starts */
-   uint8_t flags;  /* TX Flags, see @PCIE_DESC_TX_* */
-
-   union {
-   struct {
-   /*
-* L3 and L4 header offsets required
-* for TSOv2
-*/
-   uint8_t l3_offset;
-   uint8_t l4_offset;
-   };
-   __le16 vlan; /* VLAN tag to add if indicated */
-   };
-   __le16 data_len;/* Length of frame + meta data */
-   } __rte_packed;
-   __le32 vals[4];
-   };
-};
-
-struct nfp_net_txq {
-   struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
-
-   /*
-* Queue information: @qidx is the queue index from Linux's
-* perspective.  @tx_qcidx is the index of the Queue
-* Controller Peripheral queue relative to the TX queue BAR.
-* @cnt is the size of the queue in number of
-* descriptors. @qcp_q is a pointer to the base of the queue
-* structure on the NFP
-*/
-   uint8_t *qcp_q;
-
-   /*
-* Read and Write pointers.  @wr_p and @rd_p are host side pointer,
-* they are free running and have little relation to the QCP pointers *
-* @qcp_rd_p is a local copy queue controller peripheral read pointer
-*/
-
-   uint32_t wr_p;
-   uint32_t rd_p;
-
-   uint32_t tx_count;
-
-   uint32_t tx_free_thresh;
-
-   /*
-* For each descriptor keep a reference to the mbuf and
-* DMA address used until completion is signalled.
-*/
-   struct {
-   struct rte_mbuf *mbuf;
-   } *txbufs;
-
-   /*
-* Information about the host side queue location. @txds is
-* the virtual address for the queue, @dma is the

[dpdk-dev] [PATCH v2 2/7] net/nfp: move rxtx functions to their own file

2021-07-16 Thread Heinrich Kuhn
Create a new rxtx file and move the Rx/Tx functions to this file. This
commit will also move the needed shared functions to the nfp_net_pmd.h
file as needed.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build   |1 +
 drivers/net/nfp/nfp_net.c | 1090 -
 drivers/net/nfp/nfp_net_pmd.h |  184 --
 drivers/net/nfp/nfp_rxtx.c| 1002 ++
 drivers/net/nfp/nfp_rxtx.h|   27 +
 5 files changed, 1173 insertions(+), 1131 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b51e2e5f20..1b289e2354 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -19,4 +19,5 @@ sources = files(
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
+'nfp_rxtx.c',
 )
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 67288abeff..5bfc23ba04 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -66,29 +66,11 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
 static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq);
-static uint32_t nfp_net_rx_queue_count(struct rte_eth_dev *dev,
-  uint16_t queue_idx);
-static uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
- uint16_t nb_pkts);
-static void nfp_net_rx_queue_release(void *rxq);
-static int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_rxconf *rx_conf,
- struct rte_mempool *mp);
-static int nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
-static void nfp_net_tx_queue_release(void *txq);
-static int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_txconf *tx_conf);
 static int nfp_net_start(struct rte_eth_dev *dev);
 static int nfp_net_stats_get(struct rte_eth_dev *dev,
  struct rte_eth_stats *stats);
 static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static uint16_t nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
- uint16_t nb_pkts);
-
 static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
   struct rte_eth_rss_conf *rss_conf);
@@ -106,184 +88,6 @@ static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_eth_table *nfp_eth_table,
struct nfp_hwinfo *hwinfo);
 
-
-/* The offset of the queue controller queues in the PCIe Target */
-#define NFP_PCIE_QUEUE(_q) (0x8 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
-
-/* Maximum value which can be added to a queue with one transaction */
-#define NFP_QCP_MAX_ADD0x7f
-
-#define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
-   (uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM)
-
-/* nfp_qcp_ptr - Read or Write Pointer of a queue */
-enum nfp_qcp_ptr {
-   NFP_QCP_READ_PTR = 0,
-   NFP_QCP_WRITE_PTR
-};
-
-/*
- * nfp_qcp_ptr_add - Add the value to the selected pointer of a queue
- * @q: Base address for queue structure
- * @ptr: Add to the Read or Write pointer
- * @val: Value to add to the queue pointer
- *
- * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
- */
-static inline void
-nfp_qcp_ptr_add(uint8_t *q, enum nfp_qcp_ptr ptr, uint32_t val)
-{
-   uint32_t off;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_ADD_RPTR;
-   else
-   off = NFP_QCP_QUEUE_ADD_WPTR;
-
-   while (val > NFP_QCP_MAX_ADD) {
-   nn_writel(rte_cpu_to_le_32(NFP_QCP_MAX_ADD), q + off);
-   val -= NFP_QCP_MAX_ADD;
-   }
-
-   nn_writel(rte_cpu_to_le_32(val), q + off);
-}
-
-/*
- * nfp_qcp_read - Read the current Read/Write pointer value for a queue
- * @q:  Base address for queue structure
- * @ptr: Read or Write pointer
- */
-static inline uint32_t
-nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr)
-{
-   uint32_t off;
-   uint32_t val;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_STS_LO;
-   else
-   off = NFP_QCP_QUEUE_STS_HI;
-
-   val = rte_cpu_to_le_32(nn_readl(q + off));
-
-   if (ptr == NFP_QCP_READ_PTR)
-   return val

[dpdk-dev] [PATCH v2 3/7] net/nfp: move CPP bridge to a separate file

2021-07-16 Thread Heinrich Kuhn
This commit moves the CPP bridge logic to a separate file. A new
corresponding header file is also created.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build  |   1 +
 drivers/net/nfp/nfp_cpp_bridge.c | 392 +++
 drivers/net/nfp/nfp_cpp_bridge.h |  36 +++
 drivers/net/nfp/nfp_net.c| 367 +
 4 files changed, 430 insertions(+), 366 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 1b289e2354..b46ac2d40f 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -20,4 +20,5 @@ sources = files(
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
 'nfp_rxtx.c',
+'nfp_cpp_bridge.c',
 )
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
new file mode 100644
index 00..d916793338
--- /dev/null
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_cpp_bridge.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: CPP Bridge
+ */
+
+#include 
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_logs.h"
+#include "nfp_cpp_bridge.h"
+
+#include 
+
+/* Prototypes */
+static int nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp);
+
+void nfp_register_cpp_service(struct nfp_cpp *cpp)
+{
+   uint32_t *cpp_service_id = NULL;
+   struct rte_service_spec service;
+
+   memset(&service, 0, sizeof(struct rte_service_spec));
+   snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+   service.callback = nfp_cpp_bridge_service_func;
+   service.callback_userdata = (void *)cpp;
+
+   if (rte_service_component_register(&service,
+  cpp_service_id))
+   RTE_LOG(WARNING, PMD, "NFP CPP bridge service register() 
failed");
+   else
+   RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+}
+
+/*
+ * Serving a write request to NFP from host programs. The request
+ * sends the write size and the CPP target. The bridge makes use
+ * of CPP interface handler configured by the PMD setup.
+ */
+static int
+nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp)
+{
+   struct nfp_cpp_area *area;
+   off_t offset, nfp_offset;
+   uint32_t cpp_id, pos, len;
+   uint32_t tmpbuf[16];
+   size_t count, curlen, totlen = 0;
+   int err = 0;
+
+   PMD_CPP_LOG(DEBUG, "%s: offset size %zu, count_size: %zu\n", __func__,
+   sizeof(off_t), sizeof(size_t));
+
+   /* Reading the count param */
+   err = recv(sockfd, &count, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   curlen = count;
+
+   /* Reading the offset param */
+   err = recv(sockfd, &offset, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   /* Obtain target's CPP ID and offset in target */
+   cpp_id = (offset >> 40) << 8;
+   nfp_offset = offset & ((1ull << 40) - 1);
+
+   PMD_CPP_LOG(DEBUG, "%s: count %zu and offset %jd\n", __func__, count,
+   offset);
+   PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %jd\n", __func__,
+   cpp_id, nfp_offset);
+
+   /* Adjust length if not aligned */
+   if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
+   (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
+   curlen = NFP_CPP_MEMIO_BOUNDARY -
+   (nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
+   }
+
+   while (count > 0) {
+   /* configure a CPP PCIe2CPP BAR for mapping the CPP target */
+   area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
+   nfp_offset, curlen);
+   if (!area) {
+   RTE_LOG(ERR, PMD, "%s: area alloc fail\n", __func__);
+   return -EIO;
+   }
+
+   /* mapping the target */
+   err = nfp_cpp_area_acquire(area);
+   if (err < 0) {
+   RTE_LOG(ERR, PMD, "area acquire failed\n&q

[dpdk-dev] [PATCH v2 4/7] net/nfp: prototype common functions in header file

2021-07-16 Thread Heinrich Kuhn
The majority of "ethdev" type functions are used for both PF devices and
VF devices. Prototype these functions in the nfp_net_pmd header file in
preparation of splitting PF and VF specific functions.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 87 +--
 drivers/net/nfp/nfp_net_pmd.h | 49 
 2 files changed, 81 insertions(+), 55 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index d79c70c5b7..da35bba4ef 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -53,35 +53,12 @@
 
 /* Prototypes */
 static int nfp_net_close(struct rte_eth_dev *dev);
-static int nfp_net_configure(struct rte_eth_dev *dev);
-static void nfp_net_dev_interrupt_handler(void *param);
-static void nfp_net_dev_interrupt_delayed_handler(void *param);
-static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
-static int nfp_net_infos_get(struct rte_eth_dev *dev,
-struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_pci_device *pci_dev);
 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
-static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
-static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
-static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_start(struct rte_eth_dev *dev);
-static int nfp_net_stats_get(struct rte_eth_dev *dev,
- struct rte_eth_stats *stats);
-static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
-static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
-  struct rte_eth_rss_conf *rss_conf);
-static int nfp_net_rss_reta_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_reta_entry64 *reta_conf,
-   uint16_t reta_size);
-static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_conf *rss_conf);
-static int nfp_set_mac_addr(struct rte_eth_dev *dev,
-struct rte_ether_addr *mac_addr);
 static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_cpp *cpp,
struct nfp_eth_table *nfp_eth_table,
@@ -136,7 +113,7 @@ __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
  * Write the update word to the BAR and ping the reconfig queue. Then poll
  * until the firmware has acknowledged the update by zeroing the update word.
  */
-static int
+int
 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
 {
uint32_t err;
@@ -172,7 +149,7 @@ nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, 
uint32_t update)
  * before any other function in the Ethernet API. This function can
  * also be re-invoked when a device is in the stopped state.
  */
-static int
+int
 nfp_net_configure(struct rte_eth_dev *dev)
 {
struct rte_eth_conf *dev_conf;
@@ -215,7 +192,7 @@ nfp_net_configure(struct rte_eth_dev *dev)
return 0;
 }
 
-static void
+void
 nfp_net_enable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -239,7 +216,7 @@ nfp_net_enable_queues(struct rte_eth_dev *dev)
nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
 }
 
-static void
+void
 nfp_net_disable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -264,14 +241,14 @@ nfp_net_disable_queues(struct rte_eth_dev *dev)
hw->ctrl = new_ctrl;
 }
 
-static void
+void
 nfp_net_params_setup(struct nfp_net_hw *hw)
 {
nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
 }
 
-static void
+void
 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 {
hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
@@ -279,7 +256,7 @@ nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 
 #define ETH_ADDR_LEN   6
 
-static void
+void
 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
 {
int i;
@@ -318,7 +295,7 @@ nfp_net_vf_read_mac(struct nfp_net_hw *hw)
memcpy(&hw->mac_addr[4], &tmp, 2);
 }
 
-static void
+void
 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
 {
uint32_t mac0 = *(uint32_t *)mac;
@@ -366,7 +343,7 @@ nfp_set_mac_addr(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac_addr)
return 0;
 }
 
-static int
+int
 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
   struct rte_intr_handle *intr_handle)
 {
@@ -410,7 +387,7 @@ nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
return 0;
 }
 
-static uint32_t
+uint32_t
 nfp_check_offloads(struct

[dpdk-dev] [PATCH v2 5/7] net/nfp: move VF functions into new file

2021-07-16 Thread Heinrich Kuhn
Move any ethdev functionality specific to VF devices into a new file
called nfp_ethdev_vf.c.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build |   1 +
 drivers/net/nfp/nfp_ethdev_vf.c | 504 
 drivers/net/nfp/nfp_net.c   |  42 +--
 3 files changed, 506 insertions(+), 41 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b46ac2d40f..34f4054b3c 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -21,4 +21,5 @@ sources = files(
 'nfp_net.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
+'nfp_ethdev_vf.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
new file mode 100644
index 00..223142c0ed
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -0,0 +1,504 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev_vf.c
+ *
+ * Netronome vNIC  VF DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+
+static void nfp_netvf_read_mac(struct nfp_net_hw *hw);
+static int nfp_netvf_start(struct rte_eth_dev *dev);
+static int nfp_netvf_stop(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_up(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_down(struct rte_eth_dev *dev);
+static int nfp_netvf_close(struct rte_eth_dev *dev);
+static int nfp_netvf_init(struct rte_eth_dev *eth_dev);
+static int nfp_vf_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_vf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *pci_dev);
+static int eth_nfp_vf_pci_remove(struct rte_pci_device *pci_dev);
+
+static void
+nfp_netvf_read_mac(struct nfp_net_hw *hw)
+{
+   uint32_t tmp;
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
+   memcpy(&hw->mac_addr[0], &tmp, 4);
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
+   memcpy(&hw->mac_addr[4], &tmp, 2);
+}
+
+static int
+nfp_netvf_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.
+* Unregistering LSC interrupt handler
+*/
+   rte_intr_callback_unregister(&pci_dev->intr_handle,
+   nfp_net_dev_interrupt_handler, (void *)dev);
+
+   if (dev->data->nb_rx_queues > 1) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt only "
+"supports 1 queue with UIO");
+   return -EIO;
+   }
+   }
+   intr_vector = dev->data->nb_rx_queues;
+   if (rte_intr_efd_enable(intr_handle, intr_vector))
+   return -1;
+
+   nfp_configure_rx_interrupt(dev, intr_handle);
+   update = NFP_NET_CFG_UPDATE_MSIX;
+   }
+
+   rte_intr_enable(intr_handle);
+
+   new_ctrl = nfp_check_offloads(dev);
+
+   /* Writing configuration parameters in the device */
+   nfp_net_params_setup(hw);
+
+   dev_conf = &dev->data->dev_conf;
+   rxmode = &dev_conf->rxmode;
+
+   if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
+   nfp_net_rss_config_default(dev);
+   update |= NFP_NET_CFG_UPDATE_RSS;
+   new_ctrl |= NFP_NET_CFG_CTRL_RSS;
+   }
+
+   /* Enable device */
+   new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
+
+   update |= N

[dpdk-dev] [PATCH v2 6/7] net/nfp: move PF functions into new file

2021-07-16 Thread Heinrich Kuhn
Similar to the last commit, this changeset moves all the PF specific
functions to a new file called nfp_ethdev.c.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build  |1 +
 drivers/net/nfp/nfp_ethdev.c | 1099 ++
 drivers/net/nfp/nfp_net.c| 1088 +
 3 files changed, 1103 insertions(+), 1085 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 34f4054b3c..ab64d0cac3 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -22,4 +22,5 @@ sources = files(
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
+'nfp_ethdev.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
new file mode 100644
index 00..ab08906704
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -0,0 +1,1099 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_nffw.h"
+#include "nfpcore/nfp_hwinfo.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+#include "nfp_cpp_bridge.h"
+
+
+static int nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port);
+static int nfp_net_start(struct rte_eth_dev *dev);
+static int nfp_net_stop(struct rte_eth_dev *dev);
+static int nfp_net_set_link_up(struct rte_eth_dev *dev);
+static int nfp_net_set_link_down(struct rte_eth_dev *dev);
+static int nfp_net_close(struct rte_eth_dev *dev);
+static int nfp_net_init(struct rte_eth_dev *eth_dev);
+static int nfp_fw_upload(struct rte_pci_device *dev,
+struct nfp_nsp *nsp, char *card);
+static int nfp_fw_setup(struct rte_pci_device *dev,
+   struct nfp_cpp *cpp,
+   struct nfp_eth_table *nfp_eth_table,
+   struct nfp_hwinfo *hwinfo);
+static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
+static int nfp_pf_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *dev);
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev);
+
+static int
+nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
+{
+   struct nfp_eth_table *nfp_eth_table;
+   struct nfp_net_hw *hw = NULL;
+
+   /* Grab a pointer to the correct physical port */
+   hw = pf_dev->ports[port];
+
+   nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
+
+   nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
+(uint8_t *)&nfp_eth_table->ports[port].mac_addr);
+
+   free(nfp_eth_table);
+   return 0;
+}
+
+static int
+nfp_net_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct nfp_pf_dev *pf_dev;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (pf_dev->multiport) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
+ "with NFP multiport PF");
+   return -EINVAL;
+   }
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.
+* Unregistering LSC interru

[dpdk-dev] [PATCH v2 7/7] net/nfp: batch file rename for consistency

2021-07-16 Thread Heinrich Kuhn
Rename the nfp_net.c file to nfp_common as it now contains functions
common to VF and PF functionality. Rename the header file too to be
consistent. Also remove the "net" naming from the _ctrl and _logs files
for consistency across the PMD.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build | 2 +-
 drivers/net/nfp/{nfp_net.c => nfp_common.c} | 4 ++--
 drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} | 6 +++---
 drivers/net/nfp/nfp_cpp_bridge.c| 2 +-
 drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}  | 6 +++---
 drivers/net/nfp/nfp_ethdev.c| 6 +++---
 drivers/net/nfp/nfp_ethdev_vf.c | 6 +++---
 drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h}  | 6 +++---
 drivers/net/nfp/nfp_rxtx.c  | 6 +++---
 9 files changed, 22 insertions(+), 22 deletions(-)
 rename drivers/net/nfp/{nfp_net.c => nfp_common.c} (99%)
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} (99%)
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index ab64d0cac3..810f02ae5b 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -18,7 +18,7 @@ sources = files(
 'nfpcore/nfp_mutex.c',
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
-'nfp_net.c',
+'nfp_common.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_common.c
similarity index 99%
rename from drivers/net/nfp/nfp_net.c
rename to drivers/net/nfp/nfp_common.c
index a6097eaab0..87e8f5f333 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -8,9 +8,9 @@
 /*
  * vim:shiftwidth=8:noexpandtab
  *
- * @file dpdk/pmd/nfp_net.c
+ * @file dpdk/pmd/nfp_common.c
  *
- * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ * Netronome vNIC DPDK Poll-Mode Driver: Common files
  */
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_common.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_pmd.h
rename to drivers/net/nfp/nfp_common.h
index dc05e888df..54ac937bd2 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -11,8 +11,8 @@
  * Netronome NFP_NET PMD driver
  */
 
-#ifndef _NFP_NET_PMD_H_
-#define _NFP_NET_PMD_H_
+#ifndef _NFP_COMMON_H_
+#define _NFP_COMMON_H_
 
 #define NFP_NET_PMD_VERSION "0.1"
 #define PCI_VENDOR_ID_NETRONOME 0x19ee
@@ -404,7 +404,7 @@ int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 #define NFP_NET_DEV_PRIVATE_TO_PF(dev_priv)\
(((struct nfp_net_hw *)dev_priv)->pf_dev)
 
-#endif /* _NFP_NET_PMD_H_ */
+#endif /* _NFP_COMMON_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
index d916793338..74a0eacb3f 100644
--- a/drivers/net/nfp/nfp_cpp_bridge.c
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -19,7 +19,7 @@
 #include "nfpcore/nfp_mip.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_logs.h"
+#include "nfp_logs.h"
 #include "nfp_cpp_bridge.h"
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_ctrl.h
rename to drivers/net/nfp/nfp_ctrl.h
index 4f26ccf483..4dd62ef194 100644
--- a/drivers/net/nfp/nfp_net_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -8,8 +8,8 @@
  *
  * Netronome network device driver: Control BAR layout
  */
-#ifndef _NFP_NET_CTRL_H_
-#define _NFP_NET_CTRL_H_
+#ifndef _NFP_CTRL_H_
+#define _NFP_CTRL_H_
 
 /*
  * Configuration BAR size.
@@ -317,7 +317,7 @@
 /* PF multiport offset */
 #define NFP_PF_CSR_SLICE_SIZE  (32 * 1024)
 
-#endif /* _NFP_NET_CTRL_H_ */
+#endif /* _NFP_CTRL_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index ab08906704..29e6bb128a 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -30,10 +30,10 @@
 #include "nfpcore/nfp_rtsym.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_pmd.h"
+#include "nfp_common.h"
 #include "nfp_rxtx.h"
-#include "nfp_net_logs.h"
-#include "nfp_net_ctrl.h"
+#include "nfp_logs.h"
+#include "nfp_ctrl.h"
 #include "nfp_cpp_bridge.h"
 
 
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 223142c0ed..b697b55865 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -16,10 +16,10 @@
 #include "nfpcore/nfp_mip.h"
 #include "n

Re: [dpdk-dev] [PATCH] net/nfp: remove compile time log

2021-07-29 Thread Heinrich Kuhn



On 2021/07/23 16:14, Thomas Monjalon wrote:
> Please review.
> 
> 28/06/2021 13:13, Andrew Rybchenko:
>> Hi Heinrich,
>>
>> could you take a look at the patch?
>>
>> Thanks,
>> Andrew.
>>
>> On 5/18/21 1:41 PM, Ferruh Yigit wrote:
>>> Logging should be converted to dynamic log.
>>>
>>> Signed-off-by: Ferruh Yigit 
>>> ---
>>>   drivers/net/nfp/nfp_net_logs.h | 7 ---
>>>   1 file changed, 7 deletions(-)
>>>
>>> diff --git a/drivers/net/nfp/nfp_net_logs.h b/drivers/net/nfp/nfp_net_logs.h
>>> index 27dd87611b94..76cc94cb6565 100644
>>> --- a/drivers/net/nfp/nfp_net_logs.h
>>> +++ b/drivers/net/nfp/nfp_net_logs.h
>>> @@ -30,14 +30,7 @@ extern int nfp_logtype_init;
>>>   #define ASSERT(x) do { } while (0)
>>>   #endif
>>>   
>>> -#define RTE_LIBRTE_NFP_NET_DEBUG_CPP
>>> -
>>> -#ifdef RTE_LIBRTE_NFP_NET_DEBUG_CPP
>>> -#define PMD_CPP_LOG(level, fmt, args...) \
>>> -   RTE_LOG(level, PMD, "%s(): " fmt "\n", __func__, ## args)
>>> -#else
>>>   #define PMD_CPP_LOG(level, fmt, args...) do { } while (0)
>>> -#endif
>>>   
>>>   extern int nfp_logtype_driver;
>>>   #define PMD_DRV_LOG(level, fmt, args...) \
> 
> 
> 
Hi Andrew,

Apologies for the delay, looks good thanks

Reviewed-by: Heinrich Kuhn 


[dpdk-dev] [PATCH v3 0/7] Refactor the NFP PMD

2021-07-29 Thread Heinrich Kuhn
This patch set restructures the NFP PMD, aligning it more with the
common layout adopted by most other PMD's. Although the changes look
fairly large, functionally nothing is added or removed from the driver
and the existing code is mostly just reorganized into the familiar
structure seen in other PMD's. Apart form adopting the common PMD layout
this change should also aid in future feature development to the NFP
PMD. The previous layout where most of the logic resided in a single
file (nfp_net.c) would have become tedious to support going forward.

v3:
* Avoid squashing the new firmware loader helper added in: 
  https://git.dpdk.org/dpdk/commit/?id=40edb9c0d36b781
* Add dependency to patch-93299

v2:
* Added missing sign-off's

---
Depends-on: patch-93299 ("net/nfp: remove compile time log")

Heinrich Kuhn (7):
  net/nfp: split rxtx headers into separate file
  net/nfp: move rxtx functions to their own file
  net/nfp: move CPP bridge to a separate file
  net/nfp: prototype common functions in header file
  net/nfp: move VF functions into new file
  net/nfp: move PF functions into new file
  net/nfp: batch file rename for consistency

 drivers/net/nfp/meson.build   |6 +-
 drivers/net/nfp/nfp_common.c  | 1322 ++
 drivers/net/nfp/nfp_common.h  |  413 ++
 drivers/net/nfp/nfp_cpp_bridge.c  |  392 ++
 drivers/net/nfp/nfp_cpp_bridge.h  |   36 +
 .../net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}|6 +-
 drivers/net/nfp/nfp_ethdev.c  | 1067 +
 drivers/net/nfp/nfp_ethdev_vf.c   |  504 +++
 .../net/nfp/{nfp_net_logs.h => nfp_logs.h}|6 +-
 drivers/net/nfp/nfp_net.c | 3889 -
 drivers/net/nfp/nfp_rxtx.c| 1002 +
 drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} |  279 +-
 12 files changed, 4783 insertions(+), 4139 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_common.c
 create mode 100644 drivers/net/nfp/nfp_common.h
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)
 delete mode 100644 drivers/net/nfp/nfp_net.c
 create mode 100644 drivers/net/nfp/nfp_rxtx.c
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_rxtx.h} (54%)

-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH v3 1/7] net/nfp: split rxtx headers into separate file

2021-07-29 Thread Heinrich Kuhn
This change splits out the rx/tx specific structs and defines from the
main nfp_net_pmd header file and into their own header file.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c |   1 +
 drivers/net/nfp/nfp_net_pmd.h | 248 --
 drivers/net/nfp/nfp_rxtx.h| 276 ++
 3 files changed, 277 insertions(+), 248 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.h

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index a30e78db16..29eb8c84ad 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -40,6 +40,7 @@
 #include "nfpcore/nfp_nsp.h"
 
 #include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
 #include "nfp_net_logs.h"
 #include "nfp_net_ctrl.h"
 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h
index 212f9ef162..a3a3ba32d6 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_net_pmd.h
@@ -23,19 +23,6 @@
 /* Forward declaration */
 struct nfp_net_adapter;
 
-/*
- * The maximum number of descriptors is limited by design as
- * DPDK uses uint16_t variables for these values
- */
-#define NFP_NET_MAX_TX_DESC (32 * 1024)
-#define NFP_NET_MIN_TX_DESC 64
-
-#define NFP_NET_MAX_RX_DESC (32 * 1024)
-#define NFP_NET_MIN_RX_DESC 64
-
-/* Descriptor alignment */
-#define NFP_ALIGN_RING_DESC 128
-
 #define NFP_TX_MAX_SEG UINT8_MAX
 #define NFP_TX_MAX_MTU_SEG 8
 
@@ -150,241 +137,6 @@ static inline void nn_writeq(uint64_t val, volatile void 
*addr)
nn_writel(val, addr);
 }
 
-/* TX descriptor format */
-#define PCIE_DESC_TX_EOP(1 << 7)
-#define PCIE_DESC_TX_OFFSET_MASK(0x7f)
-
-/* Flags in the host TX descriptor */
-#define PCIE_DESC_TX_CSUM   (1 << 7)
-#define PCIE_DESC_TX_IP4_CSUM   (1 << 6)
-#define PCIE_DESC_TX_TCP_CSUM   (1 << 5)
-#define PCIE_DESC_TX_UDP_CSUM   (1 << 4)
-#define PCIE_DESC_TX_VLAN   (1 << 3)
-#define PCIE_DESC_TX_LSO(1 << 2)
-#define PCIE_DESC_TX_ENCAP_NONE (0)
-#define PCIE_DESC_TX_ENCAP_VXLAN(1 << 1)
-#define PCIE_DESC_TX_ENCAP_GRE  (1 << 0)
-
-struct nfp_net_tx_desc {
-   union {
-   struct {
-   uint8_t dma_addr_hi; /* High bits of host buf address */
-   __le16 dma_len; /* Length to DMA for this desc */
-   uint8_t offset_eop; /* Offset in buf where pkt starts +
-* highest bit is eop flag.
-*/
-   __le32 dma_addr_lo; /* Low 32bit of host buf addr */
-
-   __le16 mss; /* MSS to be used for LSO */
-   uint8_t lso_hdrlen; /* LSO, where the data starts */
-   uint8_t flags;  /* TX Flags, see @PCIE_DESC_TX_* */
-
-   union {
-   struct {
-   /*
-* L3 and L4 header offsets required
-* for TSOv2
-*/
-   uint8_t l3_offset;
-   uint8_t l4_offset;
-   };
-   __le16 vlan; /* VLAN tag to add if indicated */
-   };
-   __le16 data_len;/* Length of frame + meta data */
-   } __rte_packed;
-   __le32 vals[4];
-   };
-};
-
-struct nfp_net_txq {
-   struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
-
-   /*
-* Queue information: @qidx is the queue index from Linux's
-* perspective.  @tx_qcidx is the index of the Queue
-* Controller Peripheral queue relative to the TX queue BAR.
-* @cnt is the size of the queue in number of
-* descriptors. @qcp_q is a pointer to the base of the queue
-* structure on the NFP
-*/
-   uint8_t *qcp_q;
-
-   /*
-* Read and Write pointers.  @wr_p and @rd_p are host side pointer,
-* they are free running and have little relation to the QCP pointers *
-* @qcp_rd_p is a local copy queue controller peripheral read pointer
-*/
-
-   uint32_t wr_p;
-   uint32_t rd_p;
-
-   uint32_t tx_count;
-
-   uint32_t tx_free_thresh;
-
-   /*
-* For each descriptor keep a reference to the mbuf and
-* DMA address used until completion is signalled.
-*/
-   struct {
-   struct rte_mbuf *mbuf;
-   } *txbufs;
-
-   /*
-* Information about the host side queue location. @txds is
-* the virtual address for the queue, @dma is the

[dpdk-dev] [PATCH v3 2/7] net/nfp: move rxtx functions to their own file

2021-07-29 Thread Heinrich Kuhn
Create a new rxtx file and move the Rx/Tx functions to this file. This
commit will also move the needed shared functions to the nfp_net_pmd.h
file as needed.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build   |1 +
 drivers/net/nfp/nfp_net.c | 1090 -
 drivers/net/nfp/nfp_net_pmd.h |  184 --
 drivers/net/nfp/nfp_rxtx.c| 1002 ++
 drivers/net/nfp/nfp_rxtx.h|   27 +
 5 files changed, 1173 insertions(+), 1131 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_rxtx.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b51e2e5f20..1b289e2354 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -19,4 +19,5 @@ sources = files(
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
+'nfp_rxtx.c',
 )
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 29eb8c84ad..de0de808f4 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -68,29 +68,11 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
 static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq);
-static uint32_t nfp_net_rx_queue_count(struct rte_eth_dev *dev,
-  uint16_t queue_idx);
-static uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
- uint16_t nb_pkts);
-static void nfp_net_rx_queue_release(void *rxq);
-static int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_rxconf *rx_conf,
- struct rte_mempool *mp);
-static int nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
-static void nfp_net_tx_queue_release(void *txq);
-static int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
- uint16_t nb_desc, unsigned int socket_id,
- const struct rte_eth_txconf *tx_conf);
 static int nfp_net_start(struct rte_eth_dev *dev);
 static int nfp_net_stats_get(struct rte_eth_dev *dev,
  struct rte_eth_stats *stats);
 static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static uint16_t nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
- uint16_t nb_pkts);
-
 static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
   struct rte_eth_rss_conf *rss_conf);
@@ -108,184 +90,6 @@ static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_eth_table *nfp_eth_table,
struct nfp_hwinfo *hwinfo);
 
-
-/* The offset of the queue controller queues in the PCIe Target */
-#define NFP_PCIE_QUEUE(_q) (0x8 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
-
-/* Maximum value which can be added to a queue with one transaction */
-#define NFP_QCP_MAX_ADD0x7f
-
-#define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
-   (uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM)
-
-/* nfp_qcp_ptr - Read or Write Pointer of a queue */
-enum nfp_qcp_ptr {
-   NFP_QCP_READ_PTR = 0,
-   NFP_QCP_WRITE_PTR
-};
-
-/*
- * nfp_qcp_ptr_add - Add the value to the selected pointer of a queue
- * @q: Base address for queue structure
- * @ptr: Add to the Read or Write pointer
- * @val: Value to add to the queue pointer
- *
- * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
- */
-static inline void
-nfp_qcp_ptr_add(uint8_t *q, enum nfp_qcp_ptr ptr, uint32_t val)
-{
-   uint32_t off;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_ADD_RPTR;
-   else
-   off = NFP_QCP_QUEUE_ADD_WPTR;
-
-   while (val > NFP_QCP_MAX_ADD) {
-   nn_writel(rte_cpu_to_le_32(NFP_QCP_MAX_ADD), q + off);
-   val -= NFP_QCP_MAX_ADD;
-   }
-
-   nn_writel(rte_cpu_to_le_32(val), q + off);
-}
-
-/*
- * nfp_qcp_read - Read the current Read/Write pointer value for a queue
- * @q:  Base address for queue structure
- * @ptr: Read or Write pointer
- */
-static inline uint32_t
-nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr)
-{
-   uint32_t off;
-   uint32_t val;
-
-   if (ptr == NFP_QCP_READ_PTR)
-   off = NFP_QCP_QUEUE_STS_LO;
-   else
-   off = NFP_QCP_QUEUE_STS_HI;
-
-   val = rte_cpu_to_le_32(nn_readl(q + off));
-
-   if (ptr == NFP_QCP_READ_PTR)
-   return val

[dpdk-dev] [PATCH v3 3/7] net/nfp: move CPP bridge to a separate file

2021-07-29 Thread Heinrich Kuhn
This commit moves the CPP bridge logic to a separate file. A new
corresponding header file is also created.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build  |   1 +
 drivers/net/nfp/nfp_cpp_bridge.c | 392 +++
 drivers/net/nfp/nfp_cpp_bridge.h |  36 +++
 drivers/net/nfp/nfp_net.c| 367 +
 4 files changed, 430 insertions(+), 366 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.c
 create mode 100644 drivers/net/nfp/nfp_cpp_bridge.h

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 1b289e2354..b46ac2d40f 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -20,4 +20,5 @@ sources = files(
 'nfpcore/nfp_hwinfo.c',
 'nfp_net.c',
 'nfp_rxtx.c',
+'nfp_cpp_bridge.c',
 )
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
new file mode 100644
index 00..d916793338
--- /dev/null
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_cpp_bridge.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: CPP Bridge
+ */
+
+#include 
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_logs.h"
+#include "nfp_cpp_bridge.h"
+
+#include 
+
+/* Prototypes */
+static int nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp);
+static int nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp);
+
+void nfp_register_cpp_service(struct nfp_cpp *cpp)
+{
+   uint32_t *cpp_service_id = NULL;
+   struct rte_service_spec service;
+
+   memset(&service, 0, sizeof(struct rte_service_spec));
+   snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+   service.callback = nfp_cpp_bridge_service_func;
+   service.callback_userdata = (void *)cpp;
+
+   if (rte_service_component_register(&service,
+  cpp_service_id))
+   RTE_LOG(WARNING, PMD, "NFP CPP bridge service register() 
failed");
+   else
+   RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+}
+
+/*
+ * Serving a write request to NFP from host programs. The request
+ * sends the write size and the CPP target. The bridge makes use
+ * of CPP interface handler configured by the PMD setup.
+ */
+static int
+nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp)
+{
+   struct nfp_cpp_area *area;
+   off_t offset, nfp_offset;
+   uint32_t cpp_id, pos, len;
+   uint32_t tmpbuf[16];
+   size_t count, curlen, totlen = 0;
+   int err = 0;
+
+   PMD_CPP_LOG(DEBUG, "%s: offset size %zu, count_size: %zu\n", __func__,
+   sizeof(off_t), sizeof(size_t));
+
+   /* Reading the count param */
+   err = recv(sockfd, &count, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   curlen = count;
+
+   /* Reading the offset param */
+   err = recv(sockfd, &offset, sizeof(off_t), 0);
+   if (err != sizeof(off_t))
+   return -EINVAL;
+
+   /* Obtain target's CPP ID and offset in target */
+   cpp_id = (offset >> 40) << 8;
+   nfp_offset = offset & ((1ull << 40) - 1);
+
+   PMD_CPP_LOG(DEBUG, "%s: count %zu and offset %jd\n", __func__, count,
+   offset);
+   PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %jd\n", __func__,
+   cpp_id, nfp_offset);
+
+   /* Adjust length if not aligned */
+   if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
+   (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
+   curlen = NFP_CPP_MEMIO_BOUNDARY -
+   (nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
+   }
+
+   while (count > 0) {
+   /* configure a CPP PCIe2CPP BAR for mapping the CPP target */
+   area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
+   nfp_offset, curlen);
+   if (!area) {
+   RTE_LOG(ERR, PMD, "%s: area alloc fail\n", __func__);
+   return -EIO;
+   }
+
+   /* mapping the target */
+   err = nfp_cpp_area_acquire(area);
+   if (err < 0) {
+   RTE_LOG(ERR, PMD, "area acquire failed\n&q

[dpdk-dev] [PATCH v3 4/7] net/nfp: prototype common functions in header file

2021-07-29 Thread Heinrich Kuhn
The majority of "ethdev" type functions are used for both PF devices and
VF devices. Prototype these functions in the nfp_net_pmd header file in
preparation of splitting PF and VF specific functions.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 87 +--
 drivers/net/nfp/nfp_net_pmd.h | 49 
 2 files changed, 81 insertions(+), 55 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index af94219729..d42d267c6a 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -55,35 +55,12 @@
 
 /* Prototypes */
 static int nfp_net_close(struct rte_eth_dev *dev);
-static int nfp_net_configure(struct rte_eth_dev *dev);
-static void nfp_net_dev_interrupt_handler(void *param);
-static void nfp_net_dev_interrupt_delayed_handler(void *param);
-static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
-static int nfp_net_infos_get(struct rte_eth_dev *dev,
-struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_pci_device *pci_dev);
 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
-static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
-static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
-static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
-static int nfp_net_start(struct rte_eth_dev *dev);
-static int nfp_net_stats_get(struct rte_eth_dev *dev,
- struct rte_eth_stats *stats);
-static int nfp_net_stats_reset(struct rte_eth_dev *dev);
 static int nfp_net_stop(struct rte_eth_dev *dev);
-static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
-static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
-  struct rte_eth_rss_conf *rss_conf);
-static int nfp_net_rss_reta_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_reta_entry64 *reta_conf,
-   uint16_t reta_size);
-static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
-   struct rte_eth_rss_conf *rss_conf);
-static int nfp_set_mac_addr(struct rte_eth_dev *dev,
-struct rte_ether_addr *mac_addr);
 static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_cpp *cpp,
struct nfp_eth_table *nfp_eth_table,
@@ -138,7 +115,7 @@ __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
  * Write the update word to the BAR and ping the reconfig queue. Then poll
  * until the firmware has acknowledged the update by zeroing the update word.
  */
-static int
+int
 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
 {
uint32_t err;
@@ -174,7 +151,7 @@ nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, 
uint32_t update)
  * before any other function in the Ethernet API. This function can
  * also be re-invoked when a device is in the stopped state.
  */
-static int
+int
 nfp_net_configure(struct rte_eth_dev *dev)
 {
struct rte_eth_conf *dev_conf;
@@ -217,7 +194,7 @@ nfp_net_configure(struct rte_eth_dev *dev)
return 0;
 }
 
-static void
+void
 nfp_net_enable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -241,7 +218,7 @@ nfp_net_enable_queues(struct rte_eth_dev *dev)
nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
 }
 
-static void
+void
 nfp_net_disable_queues(struct rte_eth_dev *dev)
 {
struct nfp_net_hw *hw;
@@ -266,14 +243,14 @@ nfp_net_disable_queues(struct rte_eth_dev *dev)
hw->ctrl = new_ctrl;
 }
 
-static void
+void
 nfp_net_params_setup(struct nfp_net_hw *hw)
 {
nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
 }
 
-static void
+void
 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 {
hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
@@ -281,7 +258,7 @@ nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 
 #define ETH_ADDR_LEN   6
 
-static void
+void
 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
 {
int i;
@@ -320,7 +297,7 @@ nfp_net_vf_read_mac(struct nfp_net_hw *hw)
memcpy(&hw->mac_addr[4], &tmp, 2);
 }
 
-static void
+void
 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
 {
uint32_t mac0 = *(uint32_t *)mac;
@@ -368,7 +345,7 @@ nfp_set_mac_addr(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac_addr)
return 0;
 }
 
-static int
+int
 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
   struct rte_intr_handle *intr_handle)
 {
@@ -412,7 +389,7 @@ nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
return 0;
 }
 
-static uint32_t
+uint32_t
 nfp_check_offloads(struct

[dpdk-dev] [PATCH v3 5/7] net/nfp: move VF functions into new file

2021-07-29 Thread Heinrich Kuhn
Move any ethdev functionality specific to VF devices into a new file
called nfp_ethdev_vf.c.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build |   1 +
 drivers/net/nfp/nfp_ethdev_vf.c | 504 
 drivers/net/nfp/nfp_net.c   |  42 +--
 3 files changed, 506 insertions(+), 41 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev_vf.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index b46ac2d40f..34f4054b3c 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -21,4 +21,5 @@ sources = files(
 'nfp_net.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
+'nfp_ethdev_vf.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
new file mode 100644
index 00..223142c0ed
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -0,0 +1,504 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev_vf.c
+ *
+ * Netronome vNIC  VF DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+
+static void nfp_netvf_read_mac(struct nfp_net_hw *hw);
+static int nfp_netvf_start(struct rte_eth_dev *dev);
+static int nfp_netvf_stop(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_up(struct rte_eth_dev *dev);
+static int nfp_netvf_set_link_down(struct rte_eth_dev *dev);
+static int nfp_netvf_close(struct rte_eth_dev *dev);
+static int nfp_netvf_init(struct rte_eth_dev *eth_dev);
+static int nfp_vf_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_vf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *pci_dev);
+static int eth_nfp_vf_pci_remove(struct rte_pci_device *pci_dev);
+
+static void
+nfp_netvf_read_mac(struct nfp_net_hw *hw)
+{
+   uint32_t tmp;
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
+   memcpy(&hw->mac_addr[0], &tmp, 4);
+
+   tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
+   memcpy(&hw->mac_addr[4], &tmp, 2);
+}
+
+static int
+nfp_netvf_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.
+* Unregistering LSC interrupt handler
+*/
+   rte_intr_callback_unregister(&pci_dev->intr_handle,
+   nfp_net_dev_interrupt_handler, (void *)dev);
+
+   if (dev->data->nb_rx_queues > 1) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt only "
+"supports 1 queue with UIO");
+   return -EIO;
+   }
+   }
+   intr_vector = dev->data->nb_rx_queues;
+   if (rte_intr_efd_enable(intr_handle, intr_vector))
+   return -1;
+
+   nfp_configure_rx_interrupt(dev, intr_handle);
+   update = NFP_NET_CFG_UPDATE_MSIX;
+   }
+
+   rte_intr_enable(intr_handle);
+
+   new_ctrl = nfp_check_offloads(dev);
+
+   /* Writing configuration parameters in the device */
+   nfp_net_params_setup(hw);
+
+   dev_conf = &dev->data->dev_conf;
+   rxmode = &dev_conf->rxmode;
+
+   if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
+   nfp_net_rss_config_default(dev);
+   update |= NFP_NET_CFG_UPDATE_RSS;
+   new_ctrl |= NFP_NET_CFG_CTRL_RSS;
+   }
+
+   /* Enable device */
+   new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
+
+   update |= N

[dpdk-dev] [PATCH v3 6/7] net/nfp: move PF functions into new file

2021-07-29 Thread Heinrich Kuhn
Similar to the last commit, this changeset moves all the PF specific
functions to a new file called nfp_ethdev.c.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build  |1 +
 drivers/net/nfp/nfp_ethdev.c | 1067 ++
 drivers/net/nfp/nfp_net.c| 1056 +
 3 files changed, 1071 insertions(+), 1053 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_ethdev.c

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index 34f4054b3c..ab64d0cac3 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -22,4 +22,5 @@ sources = files(
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
+'nfp_ethdev.c',
 )
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
new file mode 100644
index 00..056d962306
--- /dev/null
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -0,0 +1,1067 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2014-2021 Netronome Systems, Inc.
+ * All rights reserved.
+ *
+ * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
+ */
+
+/*
+ * vim:shiftwidth=8:noexpandtab
+ *
+ * @file dpdk/pmd/nfp_ethdev.c
+ *
+ * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "eal_firmware.h"
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfpcore/nfp_nffw.h"
+#include "nfpcore/nfp_hwinfo.h"
+#include "nfpcore/nfp_mip.h"
+#include "nfpcore/nfp_rtsym.h"
+#include "nfpcore/nfp_nsp.h"
+
+#include "nfp_net_pmd.h"
+#include "nfp_rxtx.h"
+#include "nfp_net_logs.h"
+#include "nfp_net_ctrl.h"
+#include "nfp_cpp_bridge.h"
+
+
+static int nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port);
+static int nfp_net_start(struct rte_eth_dev *dev);
+static int nfp_net_stop(struct rte_eth_dev *dev);
+static int nfp_net_set_link_up(struct rte_eth_dev *dev);
+static int nfp_net_set_link_down(struct rte_eth_dev *dev);
+static int nfp_net_close(struct rte_eth_dev *dev);
+static int nfp_net_init(struct rte_eth_dev *eth_dev);
+static int nfp_fw_upload(struct rte_pci_device *dev,
+struct nfp_nsp *nsp, char *card);
+static int nfp_fw_setup(struct rte_pci_device *dev,
+   struct nfp_cpp *cpp,
+   struct nfp_eth_table *nfp_eth_table,
+   struct nfp_hwinfo *hwinfo);
+static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
+static int nfp_pf_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+   struct rte_pci_device *dev);
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
+static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev);
+
+static int
+nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
+{
+   struct nfp_eth_table *nfp_eth_table;
+   struct nfp_net_hw *hw = NULL;
+
+   /* Grab a pointer to the correct physical port */
+   hw = pf_dev->ports[port];
+
+   nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
+
+   nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
+(uint8_t *)&nfp_eth_table->ports[port].mac_addr);
+
+   free(nfp_eth_table);
+   return 0;
+}
+
+static int
+nfp_net_start(struct rte_eth_dev *dev)
+{
+   struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+   struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+   uint32_t new_ctrl, update = 0;
+   struct nfp_net_hw *hw;
+   struct nfp_pf_dev *pf_dev;
+   struct rte_eth_conf *dev_conf;
+   struct rte_eth_rxmode *rxmode;
+   uint32_t intr_vector;
+   int ret;
+
+   hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+   PMD_INIT_LOG(DEBUG, "Start");
+
+   /* Disabling queues just in case... */
+   nfp_net_disable_queues(dev);
+
+   /* Enabling the required queues in the device */
+   nfp_net_enable_queues(dev);
+
+   /* check and configure queue intr-vector mapping */
+   if (dev->data->dev_conf.intr_conf.rxq != 0) {
+   if (pf_dev->multiport) {
+   PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
+ "with NFP multiport PF");
+   return -EINVAL;
+   }
+   if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
+   /*
+* Better not to share LSC with RX interrupts.

[dpdk-dev] [PATCH v3 7/7] net/nfp: batch file rename for consistency

2021-07-29 Thread Heinrich Kuhn
Rename the nfp_net.c file to nfp_common as it now contains functions
common to VF and PF functionality. Rename the header file too to be
consistent. Also remove the "net" naming from the _ctrl and _logs files
for consistency across the PMD.

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/meson.build | 2 +-
 drivers/net/nfp/{nfp_net.c => nfp_common.c} | 4 ++--
 drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} | 6 +++---
 drivers/net/nfp/nfp_cpp_bridge.c| 2 +-
 drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h}  | 6 +++---
 drivers/net/nfp/nfp_ethdev.c| 6 +++---
 drivers/net/nfp/nfp_ethdev_vf.c | 6 +++---
 drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h}  | 6 +++---
 drivers/net/nfp/nfp_rxtx.c  | 6 +++---
 9 files changed, 22 insertions(+), 22 deletions(-)
 rename drivers/net/nfp/{nfp_net.c => nfp_common.c} (99%)
 rename drivers/net/nfp/{nfp_net_pmd.h => nfp_common.h} (99%)
 rename drivers/net/nfp/{nfp_net_ctrl.h => nfp_ctrl.h} (99%)
 rename drivers/net/nfp/{nfp_net_logs.h => nfp_logs.h} (94%)

diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build
index ab64d0cac3..810f02ae5b 100644
--- a/drivers/net/nfp/meson.build
+++ b/drivers/net/nfp/meson.build
@@ -18,7 +18,7 @@ sources = files(
 'nfpcore/nfp_mutex.c',
 'nfpcore/nfp_nsp_eth.c',
 'nfpcore/nfp_hwinfo.c',
-'nfp_net.c',
+'nfp_common.c',
 'nfp_rxtx.c',
 'nfp_cpp_bridge.c',
 'nfp_ethdev_vf.c',
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_common.c
similarity index 99%
rename from drivers/net/nfp/nfp_net.c
rename to drivers/net/nfp/nfp_common.c
index a6097eaab0..87e8f5f333 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -8,9 +8,9 @@
 /*
  * vim:shiftwidth=8:noexpandtab
  *
- * @file dpdk/pmd/nfp_net.c
+ * @file dpdk/pmd/nfp_common.c
  *
- * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
+ * Netronome vNIC DPDK Poll-Mode Driver: Common files
  */
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_common.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_pmd.h
rename to drivers/net/nfp/nfp_common.h
index dc05e888df..54ac937bd2 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -11,8 +11,8 @@
  * Netronome NFP_NET PMD driver
  */
 
-#ifndef _NFP_NET_PMD_H_
-#define _NFP_NET_PMD_H_
+#ifndef _NFP_COMMON_H_
+#define _NFP_COMMON_H_
 
 #define NFP_NET_PMD_VERSION "0.1"
 #define PCI_VENDOR_ID_NETRONOME 0x19ee
@@ -404,7 +404,7 @@ int nfp_net_rss_config_default(struct rte_eth_dev *dev);
 #define NFP_NET_DEV_PRIVATE_TO_PF(dev_priv)\
(((struct nfp_net_hw *)dev_priv)->pf_dev)
 
-#endif /* _NFP_NET_PMD_H_ */
+#endif /* _NFP_COMMON_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c
index d916793338..74a0eacb3f 100644
--- a/drivers/net/nfp/nfp_cpp_bridge.c
+++ b/drivers/net/nfp/nfp_cpp_bridge.c
@@ -19,7 +19,7 @@
 #include "nfpcore/nfp_mip.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_logs.h"
+#include "nfp_logs.h"
 #include "nfp_cpp_bridge.h"
 
 #include 
diff --git a/drivers/net/nfp/nfp_net_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
similarity index 99%
rename from drivers/net/nfp/nfp_net_ctrl.h
rename to drivers/net/nfp/nfp_ctrl.h
index 4f26ccf483..4dd62ef194 100644
--- a/drivers/net/nfp/nfp_net_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -8,8 +8,8 @@
  *
  * Netronome network device driver: Control BAR layout
  */
-#ifndef _NFP_NET_CTRL_H_
-#define _NFP_NET_CTRL_H_
+#ifndef _NFP_CTRL_H_
+#define _NFP_CTRL_H_
 
 /*
  * Configuration BAR size.
@@ -317,7 +317,7 @@
 /* PF multiport offset */
 #define NFP_PF_CSR_SLICE_SIZE  (32 * 1024)
 
-#endif /* _NFP_NET_CTRL_H_ */
+#endif /* _NFP_CTRL_H_ */
 /*
  * Local variables:
  * c-file-style: "Linux"
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 056d962306..dbdac413ae 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -31,10 +31,10 @@
 #include "nfpcore/nfp_rtsym.h"
 #include "nfpcore/nfp_nsp.h"
 
-#include "nfp_net_pmd.h"
+#include "nfp_common.h"
 #include "nfp_rxtx.h"
-#include "nfp_net_logs.h"
-#include "nfp_net_ctrl.h"
+#include "nfp_logs.h"
+#include "nfp_ctrl.h"
 #include "nfp_cpp_bridge.h"
 
 
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 223142c0ed..b697b55865 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -16,10 +16,10 @@
 #include "nfpcore/nfp_mip.h"
 #include "n

Re: [dpdk-dev] [PATCH v2 0/7] Refactor the NFP PMD

2021-07-29 Thread Heinrich Kuhn



On 2021/07/23 11:18, Thomas Monjalon wrote:
> 16/07/2021 10:35, Heinrich Kuhn:
>> This patch set restructures the NFP PMD, aligning it more with the
>> common layout adopted by most other PMD's. Although the changes look
>> fairly large, functionally nothing is added or removed from the driver
>> and the existing code is mostly just reorganized into the familiar
>> structure seen in other PMD's.
> 
> It seems this refactoring is destroying this firmware improvement:
>   https://git.dpdk.org/dpdk/commit/?id=40edb9c0d36b781
> 
> Please rebase carefully, keeping the behaviour really intact.
> 
>> Apart form adopting the common PMD layout
>> this change should also aid in future feature development to the NFP
>> PMD. The previous layout where most of the logic resided in a single
>> file (nfp_net.c) would have become tedious to support going forward.
> 
> Thanks Thomas, I actually finished this work earlier in the month and
just missed your firmware helper addition. I posted v3 of this rework


[dpdk-dev] [PATCH] net/nfp: read chip model from PluDevice register

2021-01-25 Thread Heinrich Kuhn
For newer smartNIC NVRAM versions the chip model should be read from the
PluDevice register as it provides the authoritative chip model/revision.
This method of reading the chip model is backwards compatible with
legacy NVRAM versions too.

Since the model number is purely used for reporting purposes, follow the
hardware team convention of subtracting 0x10 from the PluDevice register
to obtain the chip model/revision number.

Fixes: c7e9729da ("net/nfp: support CPP")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Reviewed-by: Louis Peens 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfpcore/nfp_cpp.h |  2 +-
 drivers/net/nfp/nfpcore/nfp_cppcore.c | 49 ---
 2 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h 
b/drivers/net/nfp/nfpcore/nfp_cpp.h
index 1427954c1..08d656da1 100644
--- a/drivers/net/nfp/nfpcore/nfp_cpp.h
+++ b/drivers/net/nfp/nfpcore/nfp_cpp.h
@@ -170,7 +170,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp);
  */
 void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area);
 
-uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp);
+uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model);
 
 /*
  * NFP CPP core interface for CPP clients.
diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c 
b/drivers/net/nfp/nfpcore/nfp_cppcore.c
index dec4a8b6d..6d629430d 100644
--- a/drivers/net/nfp/nfpcore/nfp_cppcore.c
+++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c
@@ -22,8 +22,9 @@
 
 #define NFP_PL_DEVICE_ID0x0004
 #define NFP_PL_DEVICE_ID_MASK   0xff
-
-#define NFP6000_ARM_GCSR_SOFTMODEL0 0x00400144
+#define NFP_PL_DEVICE_PART_MASK 0x
+#define NFP_PL_DEVICE_MODEL_MASK   (NFP_PL_DEVICE_PART_MASK | \
+   NFP_PL_DEVICE_ID_MASK)
 
 void
 nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv)
@@ -46,13 +47,18 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model)
 uint32_t
 nfp_cpp_model(struct nfp_cpp *cpp)
 {
+   int err;
+   uint32_t model;
+
if (!cpp)
return NFP_CPP_MODEL_INVALID;
 
-   if (cpp->model == 0)
-   cpp->model = __nfp_cpp_model_autodetect(cpp);
+   err = __nfp_cpp_model_autodetect(cpp, &model);
 
-   return cpp->model;
+   if (err < 0)
+   return err;
+
+   return model;
 }
 
 void
@@ -389,9 +395,6 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr)
uint32_t xpb;
int island;
 
-   if (!NFP_CPP_MODEL_IS_6000(cpp->model))
-   return 0;
-
xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0);
 
/*
@@ -796,29 +799,21 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned 
long offset,
  * as those are model-specific
  */
 uint32_t
-__nfp_cpp_model_autodetect(struct nfp_cpp *cpp)
+__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model)
 {
-   uint32_t arm_id = NFP_CPP_ID(NFP_CPP_TARGET_ARM, 0, 0);
-   uint32_t model = 0;
-
-   if (nfp_cpp_readl(cpp, arm_id, NFP6000_ARM_GCSR_SOFTMODEL0, &model))
-   return 0;
-
-   if (NFP_CPP_MODEL_IS_6000(model)) {
-   uint32_t tmp;
-
-   nfp_cpp_model_set(cpp, model);
+   uint32_t reg;
+   int err;
 
-   /* The PL's PluDeviceID revision code is authoratative */
-   model &= ~0xff;
-   if (nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) +
-  NFP_PL_DEVICE_ID, &tmp))
-   return 0;
+   err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID,
+   ®);
+   if (err < 0)
+   return err;
 
-   model |= (NFP_PL_DEVICE_ID_MASK & tmp) - 0x10;
-   }
+   *model = reg & NFP_PL_DEVICE_MODEL_MASK;
+   if (*model & NFP_PL_DEVICE_ID_MASK)
+   *model -= 0x10;
 
-   return model;
+   return 0;
 }
 
 /*
-- 
2.30.0



[dpdk-dev] [PATCH] maintainers: update for nfp

2021-01-31 Thread Heinrich Kuhn
Release-on-close has been implemented for the NFP PMD. Remove the
UNMAINTAINED flag.

Signed-off-by: Heinrich Kuhn 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 77a2273c1..68c5ce6e5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -815,7 +815,7 @@ F: drivers/net/nfb/
 F: doc/guides/nics/nfb.rst
 F: doc/guides/nics/features/nfb.ini
 
-Netronome nfp - UNMAINTAINED
+Netronome nfp
 M: Heinrich Kuhn 
 F: drivers/net/nfp/
 F: doc/guides/nics/nfp.rst
-- 
2.30.0



[dpdk-dev] [PATCH] doc: fix nfp multiport syntax

2021-02-25 Thread Heinrich Kuhn
From: "Chaoyong.He" 

1. Fixup the suffix of the PCI ID to be consistent with the code.
2. Add specification of using MAC address to identify port.

Fixes: 979f2bae0 ("doc: improve multiport PF in nfp guide")
Cc: sta...@dpdk.org

Signed-off-by: Chaoyong.He 
Signed-off-by: Heinrich Kuhn 
---
 doc/guides/nics/nfp.rst | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/doc/guides/nics/nfp.rst b/doc/guides/nics/nfp.rst
index fef99973b..2b170539d 100644
--- a/doc/guides/nics/nfp.rst
+++ b/doc/guides/nics/nfp.rst
@@ -117,15 +117,19 @@ although once they are created, DPDK apps should be able 
to use them as normal
 PCI ports.
 
 NFP ports belonging to same PF can be seen inside PMD initialization with a
-suffix added to the PCI ID: :xx:yy.z_port_n. For example, a PF with PCI ID
+suffix added to the PCI ID: :xx:yy.z_portn. For example, a PF with PCI ID
 :03:00.0 and four ports is seen by the PMD code as:
 
.. code-block:: console
 
-  :03:00.0_port_0
-  :03:00.0_port_1
-  :03:00.0_port_2
-  :03:00.0_port_3
+  :03:00.0_port0
+  :03:00.0_port1
+  :03:00.0_port2
+  :03:00.0_port3
+
+Some dpdk applications can choose to use the MAC address to identify ports,
+OVS-DPDK is one such example, please refer to:
+https://docs.openvswitch.org/en/latest/howto/dpdk/
 
.. Note::
 
-- 
2.30.0



[dpdk-dev] [PATCH] net/nfp: cancel delayed LSC work in port close logic

2021-10-05 Thread heinrich . kuhn
From: Heinrich Kuhn 

The link state change interrupt handler of the NFP PMD will delay the
actual LSC work for a short period to ensure the link is stable. If the
link of the port changes state and the port is closed immediately after
the link event then a segmentation fault will occur. This happens
because the delayed LSC work eventually triggers and this logic will try
to access private port data that had been released when the port was
closed.

Fixes: 6c53f87b3497 ("nfp: add link status interrupt")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_common.c| 2 +-
 drivers/net/nfp/nfp_common.h| 1 +
 drivers/net/nfp/nfp_ethdev.c| 5 +
 drivers/net/nfp/nfp_ethdev_vf.c | 6 ++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 1b4bc33593..4395a09c59 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -898,7 +898,7 @@ nfp_net_irq_unmask(struct rte_eth_dev *dev)
  *
  * @return  void
  */
-static void
+void
 nfp_net_dev_interrupt_delayed_handler(void *param)
 {
struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index 1fbf3d7cd6..3556c9cd17 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -376,6 +376,7 @@ void nfp_net_params_setup(struct nfp_net_hw *hw);
 void nfp_net_cfg_queue_setup(struct nfp_net_hw *hw);
 void nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src);
 void nfp_net_dev_interrupt_handler(void *param);
+void nfp_net_dev_interrupt_delayed_handler(void *param);
 int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
 int nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask);
 int nfp_net_reta_update(struct rte_eth_dev *dev,
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 6ba3c27f7f..1169ea77a8 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "eal_firmware.h"
 
 #include "nfpcore/nfp_cpp.h"
@@ -307,6 +308,10 @@ nfp_net_close(struct rte_eth_dev *dev)
nfp_net_reset_rx_queue(this_rx_q);
}
 
+   /* Cancel possible impending LSC work here before releasing the port*/
+   rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler,
+(void *)dev);
+
/* Only free PF resources after all physical ports have been closed */
/* Mark this port as unused and free device priv resources*/
nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index b697b55865..62cb3536e0 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -13,6 +13,8 @@
  * Netronome vNIC  VF DPDK Poll-Mode Driver: Main entry point
  */
 
+#include 
+
 #include "nfpcore/nfp_mip.h"
 #include "nfpcore/nfp_rtsym.h"
 
@@ -230,6 +232,10 @@ nfp_netvf_close(struct rte_eth_dev *dev)
 nfp_net_dev_interrupt_handler,
 (void *)dev);
 
+   /* Cancel possible impending LSC work here before releasing the port*/
+   rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler,
+(void *)dev);
+
/*
 * The ixgbe PMD driver disables the pcie master on the
 * device. The i40e does not...
-- 
2.30.1 (Apple Git-130)



Re: [dpdk-dev] [PATCH v3 0/7] Refactor the NFP PMD

2021-08-13 Thread Heinrich Kuhn



On 2021/07/29 15:47, Heinrich Kuhn wrote:
> This patch set restructures the NFP PMD, aligning it more with the
> common layout adopted by most other PMD's. Although the changes look
> fairly large, functionally nothing is added or removed from the driver
> and the existing code is mostly just reorganized into the familiar
> structure seen in other PMD's. Apart form adopting the common PMD layout
> this change should also aid in future feature development to the NFP
> PMD. The previous layout where most of the logic resided in a single
> file (nfp_net.c) would have become tedious to support going forward.
> 
> v3:
> * Avoid squashing the new firmware loader helper added in: 
>   https://git.dpdk.org/dpdk/commit/?id=40edb9c0d36b781
> * Add dependency to patch-93299
> 
> v2:
> * Added missing sign-off's
> 
> ---

I think this refactor is a step in the right direction for the NFP PMD.
I do have a question/concern regarding future bug fixes. If this is
merged, back-porting any bug fixes will require a little bit more effort
since the code base will differ quite substantially for some time.

If there is a strong preference to avoid a situation like this we can
certainly live without this refactor

Regards,
Heinrich


[dpdk-dev] [PATCH] net/nfp: fix minimum descriptor sizes

2021-08-23 Thread heinrich . kuhn
From: Heinrich Kuhn 

The NFP4000/6000 supports a minimum of 256 Tx/Rx descriptors and not 64.
Before this patch when a DPDK application configured < 256 Tx
descriptors the hardware read/write pointers would be unmasked and not
wrapped at the expected size of the ring. The PMD logic to determine the
amount of free space in the Tx ring is incompatible with the unmasked
hwqueue pointers and this will result in the PMD not updating the
read pointer at all.The knock-on effect is that under high load the
PMD will potentially re-use a Tx descriptor before the hw has had a
chance to process that particular descriptor. This issue can manifest as
a DMA error when the hardware tries to perform a DMA with info from a
partially populated descriptor.

Fixes: defb9a5dd156 ("nfp: introduce driver initialization")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_rxtx.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h
index d2d0f3f175..b0a8bf81b0 100644
--- a/drivers/net/nfp/nfp_rxtx.h
+++ b/drivers/net/nfp/nfp_rxtx.h
@@ -30,10 +30,10 @@
  * DPDK uses uint16_t variables for these values
  */
 #define NFP_NET_MAX_TX_DESC (32 * 1024)
-#define NFP_NET_MIN_TX_DESC 64
+#define NFP_NET_MIN_TX_DESC 256
 
 #define NFP_NET_MAX_RX_DESC (32 * 1024)
-#define NFP_NET_MIN_RX_DESC 64
+#define NFP_NET_MIN_RX_DESC 256
 
 /* Descriptor alignment */
 #define NFP_ALIGN_RING_DESC 128
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH] maintainers: update for NFP

2021-08-23 Thread heinrich . kuhn
From: Heinrich Kuhn 

Some of Netronome's activities and people have moved over to Corigine,
including NFP PMD maintenance and myself.

Signed-off-by: Heinrich Kuhn 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8013ba1f14..ba2c66adc5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -840,7 +840,7 @@ F: doc/guides/nics/nfb.rst
 F: doc/guides/nics/features/nfb.ini
 
 Netronome nfp
-M: Heinrich Kuhn 
+M: Heinrich Kuhn 
 F: drivers/net/nfp/
 F: doc/guides/nics/nfp.rst
 F: doc/guides/nics/features/nfp*.ini
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH] maintainers: update for NFP

2022-03-25 Thread heinrich . kuhn
From: Heinrich Kuhn 

Niklas has been appointed the new maintainer for the NFP PMD. Update the
MAINTAINERS file to reflect this

Signed-off-by: Heinrich Kuhn 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index fdea1c623f..2ae2f8ffb4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -835,7 +835,7 @@ F: doc/guides/nics/nfb.rst
 F: doc/guides/nics/features/nfb.ini
 
 Netronome nfp
-M: Heinrich Kuhn 
+M: Niklas Soderlund 
 F: drivers/net/nfp/
 F: doc/guides/nics/nfp.rst
 F: doc/guides/nics/features/nfp*.ini
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH] net/nfp: fix reporting of RSS capabilities

2021-05-10 Thread Heinrich Kuhn
Before this change the dev_infos callback always reported RSS
capabilities regardless of whether the capability is supported by the
device or not. First check the capabilities field in the BAR of the
device and advertise RSS functionality accordingly.

Fixes: 8b945a7f7d ("drivers/net: update Rx RSS hash offload capabilities")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 888324cd2..887807dbd 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -1257,9 +1257,6 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct 
rte_eth_dev_info *dev_info)
 DEV_RX_OFFLOAD_UDP_CKSUM |
 DEV_RX_OFFLOAD_TCP_CKSUM;
 
-   dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME |
-DEV_RX_OFFLOAD_RSS_HASH;
-
if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
 
@@ -1308,15 +1305,22 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct 
rte_eth_dev_info *dev_info)
.nb_mtu_seg_max = NFP_TX_MAX_MTU_SEG,
};
 
-   dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
-  ETH_RSS_NONFRAG_IPV4_TCP |
-  ETH_RSS_NONFRAG_IPV4_UDP |
-  ETH_RSS_IPV6 |
-  ETH_RSS_NONFRAG_IPV6_TCP |
-  ETH_RSS_NONFRAG_IPV6_UDP;
+   /* All NFP devices support jumbo frames */
+   dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+
+   if (hw->cap & NFP_NET_CFG_CTRL_RSS) {
+   dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_RSS_HASH;
 
-   dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
-   dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
+   dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
+  ETH_RSS_NONFRAG_IPV4_TCP |
+  ETH_RSS_NONFRAG_IPV4_UDP |
+  ETH_RSS_IPV6 |
+  ETH_RSS_NONFRAG_IPV6_TCP |
+  ETH_RSS_NONFRAG_IPV6_UDP;
+
+   dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
+   dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
+   }
 
dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
   ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH] examples/l3fwd: change mq-mode on single queue devices

2021-05-10 Thread Heinrich Kuhn
From: "Chaoyong.He" 

Set the Rx multi-queue mode to NONE when configuring a port that is
associated with hardware that only supports a single Rx queue.

Signed-off-by: Chaoyong He 
Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 examples/l3fwd/main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index bb49e5faf..87b638ac0 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -953,6 +953,10 @@ l3fwd_poll_resource_setup(void)
 
local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
dev_info.flow_type_rss_offloads;
+
+   if (dev_info.max_rx_queues == 1)
+   local_port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
+
if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
port_conf.rx_adv_conf.rss_conf.rss_hf) {
printf("Port %u modified RSS hash function based on 
hardware support,"
-- 
2.30.1 (Apple Git-130)



[dpdk-dev] [PATCH] net/nfp: fix internal NFP port addressing

2021-05-14 Thread Heinrich Kuhn
Depending on the breakout mode of the physical ports the internal NFP
port number might differ from the actual physical port number. Prior to
this patch the physical port number was used when making configuration
changes to the physical ports (enable, admin up etc). After this change
the internal port number is now correctly used for configuration
changes.

Fixes: 5e15e799d ("net/nfp: create separate entity for PF device")

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 38 +++
 drivers/net/nfp/nfp_net_pmd.h |  3 +++
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 888324cd2..05370767b 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -769,10 +769,10 @@ nfp_net_start(struct rte_eth_dev *dev)
if (hw->is_phyport) {
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
/* Configure the physical port up */
-   nfp_eth_set_configured(hw->cpp, hw->idx, 1);
+   nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
else
nfp_eth_set_configured(dev->process_private,
-  hw->idx, 1);
+  hw->nfp_idx, 1);
}
 
hw->ctrl = new_ctrl;
@@ -825,10 +825,10 @@ nfp_net_stop(struct rte_eth_dev *dev)
if (hw->is_phyport) {
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
/* Configure the physical port down */
-   nfp_eth_set_configured(hw->cpp, hw->idx, 0);
+   nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
else
nfp_eth_set_configured(dev->process_private,
-  hw->idx, 0);
+  hw->nfp_idx, 0);
}
 
return 0;
@@ -849,10 +849,10 @@ nfp_net_set_link_up(struct rte_eth_dev *dev)
 
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
/* Configure the physical port down */
-   return nfp_eth_set_configured(hw->cpp, hw->idx, 1);
+   return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
else
return nfp_eth_set_configured(dev->process_private,
- hw->idx, 1);
+ hw->nfp_idx, 1);
 }
 
 /* Set the link down. */
@@ -870,10 +870,10 @@ nfp_net_set_link_down(struct rte_eth_dev *dev)
 
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
/* Configure the physical port down */
-   return nfp_eth_set_configured(hw->cpp, hw->idx, 0);
+   return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
else
return nfp_eth_set_configured(dev->process_private,
- hw->idx, 0);
+ hw->nfp_idx, 0);
 }
 
 /* Reset and stop device. The device can not be restarted. */
@@ -2806,15 +2806,15 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
return -ENODEV;
}
 
-   /* This points to the specific port private data */
-   PMD_INIT_LOG(DEBUG, "Working with physical port number %d",
-   port);
-
/* Use PF array of physical ports to get pointer to
 * this specific port
 */
hw = pf_dev->ports[port];
 
+   PMD_INIT_LOG(DEBUG, "Working with physical port number: %d, "
+   "NFP internal port number: %d",
+   port, hw->nfp_idx);
+
} else {
hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
}
@@ -3493,9 +3493,17 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
 {
struct nfp_net_hw *hw;
struct rte_eth_dev *eth_dev;
+   struct nfp_eth_table *nfp_eth_table = NULL;
int ret = 0;
int i;
 
+   nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
+   if (!nfp_eth_table) {
+   PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
+   ret = -EIO;
+   goto error;
+   }
+
/* Loop through all physical ports on PF */
for (i = 0; i < pf_dev->total_phyports; i++) {
const unsigned int numa_node = rte_socket_id();
@@ -3551,6 +3559,7 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
hw->cpp = pf_dev->cpp;
hw->eth_dev = eth_dev;
hw->idx = i;
+   h

[dpdk-dev] [PATCH 1/2] net/nfp: improve PF probing logic

2021-06-09 Thread Heinrich Kuhn
When using rte_eth_dev_pci_generic_probe() during probing a
rte_eth_dev will be created with the name field corresponding to the PCI
address of the device. NFP4000/6000 devices only have a single PF (but
potentially multiple physical ports). This means that in a simple two
port example the rte_eth_devices[] array will be populated with two
devices: :02:00.0 and :02:00.0_port1. This is inconsistent and
not ideal. It will also cause issues when a secondary process tries to
attach to these ports.

This patch removes the use of rte_eth_dev_pci_generic_probe() and
allocates eth_dev's for each physical port during PF initialization,
giving them more consistent names.

Fixes: 5e15e799d697 ("net/nfp: create separate entity for PF device")

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 31 ---
 drivers/net/nfp/nfp_net_pmd.h |  3 ---
 2 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 2ee88fbfc7..d94c8dc727 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -58,7 +58,7 @@ static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, 
uint16_t mtu);
 static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
-static int nfp_pf_init(struct rte_eth_dev *eth_dev);
+static int nfp_pf_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
@@ -3530,20 +3530,14 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
goto nfp_net_init;
}
 
-   /* First port has already been initialized */
-   if (i == 0) {
-   eth_dev = pf_dev->eth_dev;
-   goto skip_dev_alloc;
-   }
-
-   /* Allocate a eth_dev for remaining ports */
+   /* Allocate a eth_dev for this phyport */
eth_dev = rte_eth_dev_allocate(port_name);
if (!eth_dev) {
ret = -ENODEV;
goto port_cleanup;
}
 
-   /* Allocate memory for remaining ports */
+   /* Allocate memory for this phyport */
eth_dev->data->dev_private =
rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
   RTE_CACHE_LINE_SIZE, numa_node);
@@ -3553,7 +3547,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
goto port_cleanup;
}
 
-skip_dev_alloc:
hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 
/* Add this device to the PF's array of physical ports */
@@ -3600,24 +3593,20 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
return ret;
 }
 
-static int nfp_pf_init(struct rte_eth_dev *eth_dev)
+static int nfp_pf_init(struct rte_pci_device *pci_dev)
 {
-   struct rte_pci_device *pci_dev;
-   struct nfp_net_hw *hw = NULL;
struct nfp_pf_dev *pf_dev = NULL;
struct nfp_cpp *cpp;
struct nfp_hwinfo *hwinfo;
struct nfp_rtsym_table *sym_tbl;
struct nfp_eth_table *nfp_eth_table = NULL;
struct rte_service_spec service;
+   uint32_t *nfp_cpp_service_id = NULL;
char name[RTE_ETH_NAME_MAX_LEN];
int total_ports;
int ret = -ENODEV;
int err;
 
-   pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-   hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev);
-
if (!pci_dev)
return ret;
 
@@ -3685,7 +3674,7 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
goto sym_tbl_cleanup;
}
/* Allocate memory for the PF "device" */
-   snprintf(name, sizeof(name), "nfp_pf%d", eth_dev->data->port_id);
+   snprintf(name, sizeof(name), "nfp_pf%d", 0);
pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
if (!pf_dev) {
ret = -ENOMEM;
@@ -3703,9 +3692,6 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
 
pf_dev->pci_dev = pci_dev;
 
-   /* The first eth_dev is part of the PF struct */
-   pf_dev->eth_dev = eth_dev;
-
/* Map the symbol table */
pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
 pf_dev->total_phyports * 32768,
@@ -3754,7 +3740,7 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
service.callback_userdata = (void *)cpp;
 
if (rte_service_component_register(&service,
-  &hw->nfp_cpp_service_id))
+ 

[dpdk-dev] [PATCH 2/2] net/nfp: fix PF secondary process probing

2021-06-09 Thread Heinrich Kuhn
This patch creates a new function for handling PF probing of a secondary
process. A CPP handle is obtained for the CPP bridge service and the
service itself is also registered during secondary process
initialization. DPDK services aren't shared between processes so it is
not enough to only have the primary register the service if it is also
needed in a secondary process. This implies that both the primary and
secondary will have their own copy of the bridge service.

Fixes: 5e15e799d697 ("net/nfp: create separate entity for PF device")

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 147 +++---
 1 file changed, 105 insertions(+), 42 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index d94c8dc727..353412c502 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -59,6 +59,7 @@ static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
@@ -98,6 +99,7 @@ static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
 static int nfp_set_mac_addr(struct rte_eth_dev *dev,
 struct rte_ether_addr *mac_addr);
 static int32_t nfp_cpp_bridge_service_func(void *args);
+static void nfp_register_cpp_service(struct nfp_cpp *cpp);
 static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_cpp *cpp,
struct nfp_eth_table *nfp_eth_table,
@@ -3516,20 +3518,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
snprintf(port_name, sizeof(port_name), "%s_port%d",
 pf_dev->pci_dev->device.name, i);
 
-   if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
-   eth_dev = rte_eth_dev_attach_secondary(port_name);
-   if (!eth_dev) {
-   RTE_LOG(ERR, EAL,
-   "secondary process attach failed, "
-   "ethdev doesn't exist");
-   ret = -ENODEV;
-   goto error;
-   }
-
-   eth_dev->process_private = pf_dev->cpp;
-   goto nfp_net_init;
-   }
-
/* Allocate a eth_dev for this phyport */
eth_dev = rte_eth_dev_allocate(port_name);
if (!eth_dev) {
@@ -3559,7 +3547,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
hw->nfp_idx = nfp_eth_table->ports[i].index;
hw->is_phyport = true;
 
-nfp_net_init:
eth_dev->device = &pf_dev->pci_dev->device;
 
/* ctrl/tx/rx BAR mappings and remaining init happens in
@@ -3593,6 +3580,23 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
return ret;
 }
 
+static void nfp_register_cpp_service(struct nfp_cpp *cpp)
+{
+   uint32_t *cpp_service_id = NULL;
+   struct rte_service_spec service;
+
+   memset(&service, 0, sizeof(struct rte_service_spec));
+   snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+   service.callback = nfp_cpp_bridge_service_func;
+   service.callback_userdata = (void *)cpp;
+
+   if (rte_service_component_register(&service,
+  cpp_service_id))
+   RTE_LOG(WARNING, PMD, "NFP CPP bridge service register() 
failed");
+   else
+   RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+}
+
 static int nfp_pf_init(struct rte_pci_device *pci_dev)
 {
struct nfp_pf_dev *pf_dev = NULL;
@@ -3600,8 +3604,6 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
struct nfp_hwinfo *hwinfo;
struct nfp_rtsym_table *sym_tbl;
struct nfp_eth_table *nfp_eth_table = NULL;
-   struct rte_service_spec service;
-   uint32_t *nfp_cpp_service_id = NULL;
char name[RTE_ETH_NAME_MAX_LEN];
int total_ports;
int ret = -ENODEV;
@@ -3642,12 +3644,10 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
goto hwinfo_cleanup;
}
 
-   if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-   if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
-   PMD_INIT_LOG(ERR, "Error when uploading firmware");
-   ret = -EIO;
-   goto eth_table_cleanup;
- 

[dpdk-dev] [PATCH v2 1/2] net/nfp: improve PF probing logic

2021-06-09 Thread Heinrich Kuhn
When using rte_eth_dev_pci_generic_probe() during probing a
rte_eth_dev will be created with the name field corresponding to the PCI
address of the device. NFP4000/6000 devices only have a single PF (but
potentially multiple physical ports). This means that in a simple two
port example the rte_eth_devices[] array will be populated with two
devices: :02:00.0 and :02:00.0_port1. This is inconsistent and
not ideal. It will also cause issues when a secondary process tries to
attach to these ports.

This patch removes the use of rte_eth_dev_pci_generic_probe() and
allocates eth_dev's for each physical port during PF initialization,
giving them more consistent names.

Fixes: 5e15e799d697 ("net/nfp: create separate entity for PF device")

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 31 ---
 drivers/net/nfp/nfp_net_pmd.h |  3 ---
 2 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 2ee88fbfc7..d94c8dc727 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -58,7 +58,7 @@ static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, 
uint16_t mtu);
 static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
-static int nfp_pf_init(struct rte_eth_dev *eth_dev);
+static int nfp_pf_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
@@ -3530,20 +3530,14 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
goto nfp_net_init;
}
 
-   /* First port has already been initialized */
-   if (i == 0) {
-   eth_dev = pf_dev->eth_dev;
-   goto skip_dev_alloc;
-   }
-
-   /* Allocate a eth_dev for remaining ports */
+   /* Allocate a eth_dev for this phyport */
eth_dev = rte_eth_dev_allocate(port_name);
if (!eth_dev) {
ret = -ENODEV;
goto port_cleanup;
}
 
-   /* Allocate memory for remaining ports */
+   /* Allocate memory for this phyport */
eth_dev->data->dev_private =
rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
   RTE_CACHE_LINE_SIZE, numa_node);
@@ -3553,7 +3547,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
goto port_cleanup;
}
 
-skip_dev_alloc:
hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 
/* Add this device to the PF's array of physical ports */
@@ -3600,24 +3593,20 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
return ret;
 }
 
-static int nfp_pf_init(struct rte_eth_dev *eth_dev)
+static int nfp_pf_init(struct rte_pci_device *pci_dev)
 {
-   struct rte_pci_device *pci_dev;
-   struct nfp_net_hw *hw = NULL;
struct nfp_pf_dev *pf_dev = NULL;
struct nfp_cpp *cpp;
struct nfp_hwinfo *hwinfo;
struct nfp_rtsym_table *sym_tbl;
struct nfp_eth_table *nfp_eth_table = NULL;
struct rte_service_spec service;
+   uint32_t *nfp_cpp_service_id = NULL;
char name[RTE_ETH_NAME_MAX_LEN];
int total_ports;
int ret = -ENODEV;
int err;
 
-   pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-   hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev);
-
if (!pci_dev)
return ret;
 
@@ -3685,7 +3674,7 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
goto sym_tbl_cleanup;
}
/* Allocate memory for the PF "device" */
-   snprintf(name, sizeof(name), "nfp_pf%d", eth_dev->data->port_id);
+   snprintf(name, sizeof(name), "nfp_pf%d", 0);
pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
if (!pf_dev) {
ret = -ENOMEM;
@@ -3703,9 +3692,6 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
 
pf_dev->pci_dev = pci_dev;
 
-   /* The first eth_dev is part of the PF struct */
-   pf_dev->eth_dev = eth_dev;
-
/* Map the symbol table */
pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
 pf_dev->total_phyports * 32768,
@@ -3754,7 +3740,7 @@ static int nfp_pf_init(struct rte_eth_dev *eth_dev)
service.callback_userdata = (void *)cpp;
 
if (rte_service_component_register(&service,
-  &hw->nfp_cpp_service_id))
+ 

[dpdk-dev] [PATCH v2 2/2] net/nfp: fix PF secondary process probing

2021-06-09 Thread Heinrich Kuhn
This patch creates a new function for handling PF probing of a secondary
process. A CPP handle is obtained for the CPP bridge service and the
service itself is also registered during secondary process
initialization. DPDK services aren't shared between processes so it is
not enough to only have the primary register the service if it is also
needed in a secondary process. This implies that both the primary and
secondary will have their own copy of the bridge service.

Fixes: 5e15e799d697 ("net/nfp: create separate entity for PF device")

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 147 +++---
 1 file changed, 105 insertions(+), 42 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index d94c8dc727..b18edd8c7b 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -59,6 +59,7 @@ static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_pci_device *pci_dev);
+static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
@@ -98,6 +99,7 @@ static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
 static int nfp_set_mac_addr(struct rte_eth_dev *dev,
 struct rte_ether_addr *mac_addr);
 static int32_t nfp_cpp_bridge_service_func(void *args);
+static void nfp_register_cpp_service(struct nfp_cpp *cpp);
 static int nfp_fw_setup(struct rte_pci_device *dev,
struct nfp_cpp *cpp,
struct nfp_eth_table *nfp_eth_table,
@@ -3516,20 +3518,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
snprintf(port_name, sizeof(port_name), "%s_port%d",
 pf_dev->pci_dev->device.name, i);
 
-   if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
-   eth_dev = rte_eth_dev_attach_secondary(port_name);
-   if (!eth_dev) {
-   RTE_LOG(ERR, EAL,
-   "secondary process attach failed, "
-   "ethdev doesn't exist");
-   ret = -ENODEV;
-   goto error;
-   }
-
-   eth_dev->process_private = pf_dev->cpp;
-   goto nfp_net_init;
-   }
-
/* Allocate a eth_dev for this phyport */
eth_dev = rte_eth_dev_allocate(port_name);
if (!eth_dev) {
@@ -3559,7 +3547,6 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
hw->nfp_idx = nfp_eth_table->ports[i].index;
hw->is_phyport = true;
 
-nfp_net_init:
eth_dev->device = &pf_dev->pci_dev->device;
 
/* ctrl/tx/rx BAR mappings and remaining init happens in
@@ -3593,6 +3580,23 @@ static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
return ret;
 }
 
+static void nfp_register_cpp_service(struct nfp_cpp *cpp)
+{
+   uint32_t *cpp_service_id = NULL;
+   struct rte_service_spec service;
+
+   memset(&service, 0, sizeof(struct rte_service_spec));
+   snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+   service.callback = nfp_cpp_bridge_service_func;
+   service.callback_userdata = (void *)cpp;
+
+   if (rte_service_component_register(&service,
+  cpp_service_id))
+   RTE_LOG(WARNING, PMD, "NFP CPP bridge service register() 
failed");
+   else
+   RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+}
+
 static int nfp_pf_init(struct rte_pci_device *pci_dev)
 {
struct nfp_pf_dev *pf_dev = NULL;
@@ -3600,8 +3604,6 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
struct nfp_hwinfo *hwinfo;
struct nfp_rtsym_table *sym_tbl;
struct nfp_eth_table *nfp_eth_table = NULL;
-   struct rte_service_spec service;
-   uint32_t *nfp_cpp_service_id = NULL;
char name[RTE_ETH_NAME_MAX_LEN];
int total_ports;
int ret = -ENODEV;
@@ -3642,12 +3644,10 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
goto hwinfo_cleanup;
}
 
-   if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-   if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
-   PMD_INIT_LOG(ERR, "Error when uploading firmware");
-   ret = -EIO;
-   goto eth_table_cleanup;
- 

Re: [dpdk-dev] [PATCH] net/nfp: use macro PCI_PRI_FMT for PCI log format

2020-01-16 Thread Heinrich Kuhn


> Use PCI_PRI_FMT instead of "%04d:%02d:%02d:%d" print format.
> 
> Signed-off-by: Yunjian Wang 
> ---
>  drivers/net/nfp/nfp_net.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
> index 3aafa7f80..64d9d218d 100644
> --- a/drivers/net/nfp/nfp_net.c
> +++ b/drivers/net/nfp/nfp_net.c
> @@ -1377,9 +1377,9 @@ nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
>   PMD_DRV_LOG(INFO, " Port %d: Link Down",
>   dev->data->port_id);
>  
> - PMD_DRV_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
> - pci_dev->addr.domain, pci_dev->addr.bus,
> - pci_dev->addr.devid, pci_dev->addr.function);
> + PMD_DRV_LOG(INFO, "PCI Address: " PCI_PRI_FMT,
> + pci_dev->addr.domain, pci_dev->addr.bus,
> +     pci_dev->addr.devid, pci_dev->addr.function);
>  }
>  
>  /* Interrupt configuration and handling */
> 

Acked-by: Heinrich Kuhn 


[dpdk-dev] [PATCH] net/nfp: fix RSS hash configuration reporting

2020-07-10 Thread Heinrich Kuhn
Prior to this fix the NFP PMD implementation of the .rss_hash_conf_get
callback did not propagate the current hardware state of rss_hf back up
to the caller. Users of the hash_conf_get callback would receive an
incorrect representation of what the RSS configuration currently is in
hardware.

Fixes: 934e4c60fbff ("nfp: add RSS")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 88e3f01d6..f47200cc4 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -2626,6 +2626,9 @@ nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6)
rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
 
+   /* Propagate current RSS hash functions to caller */
+   rss_conf->rss_hf = rss_hf;
+
/* Reading the key size */
rss_conf->rss_key_len = nn_cfg_readl(hw, NFP_NET_CFG_RSS_KEY_SZ);
 
-- 
2.26.2



Re: [dpdk-dev] [PATCH] net/nfp: fix log format specifiers

2020-04-07 Thread Heinrich Kuhn



On 2020/03/03 15:36, Ferruh Yigit wrote:
> Changing format specifier for the 'size_t' as '%z' and for 'off_t' as
> '%jd'.
> 
> Also this fix enables compiling PMD for 32bit architecture.
> 
> Fixes: 29a62d1476b6 ("net/nfp: add CPP bridge as service")
> Cc: sta...@dpdk.org
> 
> Signed-off-by: Ferruh Yigit 
> ---

Acked-by: Heinrich Kuhn 


Re: [dpdk-dev] [PATCH v1] net/nfp: fix dangling pointer on failure

2020-04-07 Thread Heinrich Kuhn



On 2020/04/07 13:37, wangyunjian wrote:
> From: Yunjian Wang 
> 
> When nfp_pf_create_dev() is cleaning up, it does not correctly set
> the dev_private variable to NULL, which will lead to a double free.
> 
> Fixes: ef28aa96e53b ("net/nfp: support multiprocess")
> CC: sta...@dpdk.org
> 
> Signed-off-by: Yunjian Wang 

Thanks Yunjian

Acked-by: Heinrich Kuhn 


[dpdk-dev] [PATCH] maintainers: update for NFP

2020-02-11 Thread Heinrich Kuhn
Jan is no longer with Netronome. Remove him as maintainer for the
Netronome PMD

Signed-off-by: Heinrich Kuhn 
---
 MAINTAINERS | 1 -
 1 file changed, 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index bc98b9167..3d5e8d110 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -784,7 +784,6 @@ F: doc/guides/nics/features/nfb.ini
 
 Netronome nfp
 M: Heinrich Kuhn 
-M: Jan Gutter 
 F: drivers/net/nfp/
 F: doc/guides/nics/nfp.rst
 F: doc/guides/nics/features/nfp*.ini
-- 
2.20.1



[dpdk-dev] [PATCH] maintainers: update maintainers for nfp PMD

2019-11-27 Thread Heinrich Kuhn
As Alejandro is no longer with Netronome we appointed two new
maintainers for the Netronome PMD

Signed-off-by: Heinrich Kuhn 
---
 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4a0c9a47e..6bac90c25 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -774,7 +774,8 @@ F: doc/guides/nics/nfb.rst
 F: doc/guides/nics/features/nfb.ini
 
 Netronome nfp
-M: Alejandro Lucero 
+M: Heinrich Kuhn 
+M: Jan Gutter 
 F: drivers/net/nfp/
 F: doc/guides/nics/nfp.rst
 F: doc/guides/nics/features/nfp*.ini
-- 
2.17.1



Re: [dpdk-dev] [PATCH] MAINTAINERS: resign from NFP PMD maintainer

2019-11-27 Thread Heinrich Kuhn
On 2019/11/25 20:52, thomas at monjalon.net (Thomas Monjalon) wrote:
> 13/11/2019 14:05, Alejandro Lucero:
>> On Wed, Nov 13, 2019 at 12:55 PM Ferruh Yigit 
>> wrote:
>>> On 11/13/2019 12:47 PM, Alejandro Lucero wrote:
[...]
>>> Can it be possible to nominate someone?
>>> It would be good to have an owner of the PMD,
>>> preferably technical owner of it, but at worst,
>>> if we have nothing, a point of contact for the PMD.
[...]
> Netronome, is there someone to be responsible of this PMD?
> Community, is there a volunteer outside of Netronome?
> 
> If the PMD is not maintained, I am not sure how long we will keep it.
> 
Hi Thomas,

Jan Gutter and myself will be taking over from Alejandro and we will be
co-maintaining the nfp PMD for Netronome. I am very new to the DPDK
community but I have access to Netronome expertise and hardware to
help with testing.

Looking forward to working with everyone on this project going forward.


Re: [dpdk-dev] [PATCH] net/nfp: replace license text with SPDX tag

2019-11-27 Thread Heinrich Kuhn
On 2019/09/27 10:33, hemant.agrawal at nxp.com (Hemant Agrawal) wrote:
> Signed-off-by: Hemant Agrawal 

Acked-by: Heinrich Kuhn 


[dpdk-dev] [PATCH 0/2] free port private data in dev_close callback

2021-01-19 Thread Heinrich Kuhn
The first patch in this series prepares the NFP PMD for the new expected
behavior of the .dev_close() callback function, most recently described
in commit fbd191356148 ("ethdev: remove old close behaviour"). Patch one
makes the needed infrastructure changes to make this possible.

The second patch in the series makes the changes in nfp_net_close to
free the private data of a given port. PF resources are only freed once
all other ports under the PF has also been cleaned up.

Heinrich Kuhn (2):
  net/nfp: create a separate entity for a NFP PF device
  net/nfp: free port private data in dev close callback

 drivers/net/nfp/nfp_net.c | 604 ++
 drivers/net/nfp/nfp_net_pmd.h |  67 +++-
 2 files changed, 390 insertions(+), 281 deletions(-)

-- 
2.30.0



[dpdk-dev] [PATCH 1/2] net/nfp: create a separate entity for a NFP PF device

2021-01-19 Thread Heinrich Kuhn
Before this change memory for the private data of all physical ports
where allocated with single rte_zmalloc() call. Specific port private
data was accessed by means of an offset into this memory. This scheme is
problematic when attempting to free only one port's private data at a
time.

To address this, a new entity is created called struct nfp_pf_dev. This
struct represents the PF device. It has a number of PF specific members.
Notably it has a pointer of type rte_eth_dev that points to the eth_dev
associated with the first physical port of the device. It also has an
array of nfp_net_hw's containing pointers to all the physical ports
under the PF.

Memory is first allocated for the PF and PF specific initialization is
attempted. Next, all the physical ports under the PF is iterated and
memory is allocated separately for the private data of each port. Port 0
is skipped during this phase because memory has already been allocated
and an eth_dev already exits for the 0th port.

Signed-off-by: Heinrich Kuhn 
Reviewed-by: Louis Peens 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 545 +-
 drivers/net/nfp/nfp_net_pmd.h |  67 -
 2 files changed, 340 insertions(+), 272 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 1608bf5ea..9b9bd9e3d 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -58,6 +58,8 @@ static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, 
uint16_t mtu);
 static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
+static int nfp_pf_init(struct rte_eth_dev *eth_dev);
+static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
 static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
@@ -94,6 +96,12 @@ static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
struct rte_eth_rss_conf *rss_conf);
 static int nfp_set_mac_addr(struct rte_eth_dev *dev,
 struct rte_ether_addr *mac_addr);
+static int32_t nfp_cpp_bridge_service_func(void *args);
+static int nfp_fw_setup(struct rte_pci_device *dev,
+   struct nfp_cpp *cpp,
+   struct nfp_eth_table *nfp_eth_table,
+   struct nfp_hwinfo *hwinfo);
+
 
 /* The offset of the queue controller queues in the PCIe Target */
 #define NFP_PCIE_QUEUE(_q) (0x8 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
@@ -486,16 +494,16 @@ nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
 }
 
 static int
-nfp_net_pf_read_mac(struct nfp_net_hw *hw, int port)
+nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
 {
struct nfp_eth_table *nfp_eth_table;
+   struct nfp_net_hw *hw = NULL;
+
+   /* Grab a pointer to the correct physical port */
+   hw = pf_dev->ports[port];
+
+   nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
 
-   nfp_eth_table = nfp_eth_read_ports(hw->cpp);
-   /*
-* hw points to port0 private data. We need hw now pointing to
-* right port.
-*/
-   hw += port;
nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
 
@@ -674,12 +682,14 @@ nfp_net_start(struct rte_eth_dev *dev)
struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
uint32_t new_ctrl, update = 0;
struct nfp_net_hw *hw;
+   struct nfp_pf_dev *pf_dev;
struct rte_eth_conf *dev_conf;
struct rte_eth_rxmode *rxmode;
uint32_t intr_vector;
int ret;
 
hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+   pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 
PMD_INIT_LOG(DEBUG, "Start");
 
@@ -691,7 +701,7 @@ nfp_net_start(struct rte_eth_dev *dev)
 
/* check and configure queue intr-vector mapping */
if (dev->data->dev_conf.intr_conf.rxq != 0) {
-   if (hw->pf_multiport_enabled) {
+   if (pf_dev->multiport) {
PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
  "with NFP multiport PF");
return -EINVAL;
@@ -755,13 +765,13 @@ nfp_net_start(struct rte_eth_dev *dev)
goto error;
}
 
-   if (hw->is_pf) {
+   if (hw->is_phyport) {
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
/* Configure the physical port up */
-   nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 1);
+   nfp_eth_set_configured(hw->cpp, hw->idx, 1);
else
  

[dpdk-dev] [PATCH 2/2] net/nfp: free port private data in dev close callback

2021-01-19 Thread Heinrich Kuhn
Free the private data of a port when the .dev_close() callback is
invoked. For NFP6000/4000 devices multiple ports may exist under a
single PF device. In this situation the PF resources will only be freed
when all the ports associated with the PF has been freed too.

PF hot plugging isn't explicitly supported for NFP6000/4000 devices but
all the private data of all the ports under the PF in question will be
freed upon device removal.

Signed-off-by: Heinrich Kuhn 
Reviewed-by: Louis Peens 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 63 ---
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 9b9bd9e3d..b2cebf3e7 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -59,6 +59,7 @@ static int nfp_net_infos_get(struct rte_eth_dev *dev,
 struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_eth_dev *eth_dev);
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
@@ -909,8 +910,34 @@ nfp_net_close(struct rte_eth_dev *dev)
(struct nfp_net_rxq *)dev->data->rx_queues[i]);
}
 
+   /* Only free PF resources after all physical ports have been closed */
+   if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
+   pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
+   struct nfp_pf_dev *pf_dev;
+   pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+   /* Mark this port as unused and free device priv resources*/
+   nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
+   pf_dev->ports[hw->idx] = NULL;
+   rte_eth_dev_release_port(dev);
+
+   for (i = 0; i < pf_dev->total_phyports; i++) {
+   /* Check to see if ports are still in use */
+   if (pf_dev->ports[i])
+   return 0;
+   }
+
+   /* Now it is safe to free all PF resources */
+   PMD_INIT_LOG(INFO, "Freeing PF resources");
+   nfp_cpp_area_free(pf_dev->ctrl_area);
+   nfp_cpp_area_free(pf_dev->hwqueues_area);
+   free(pf_dev->hwinfo);
+   free(pf_dev->sym_tbl);
+   nfp_cpp_free(pf_dev->cpp);
+   rte_free(pf_dev);
+   }
+
rte_intr_disable(&pci_dev->intr_handle);
-   nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
 
/* unregister callback func from eal lib */
rte_intr_callback_unregister(&pci_dev->intr_handle,
@@ -3765,6 +3792,29 @@ static const struct rte_pci_id pci_id_nfp_vf_net_map[] = 
{
},
 };
 
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev)
+{
+   struct rte_pci_device *pci_dev;
+   uint16_t port_id;
+
+   pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+   if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
+   pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
+   /* Free up all physical ports under PF */
+   RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
+   rte_eth_dev_close(port_id);
+   /*
+* Ports can be closed and freed but hotplugging is not
+* currently supported
+*/
+   return -ENOTSUP;
+   }
+
+   /* VF cleanup, just free private port data */
+   return nfp_net_close(eth_dev);
+}
+
 static int eth_nfp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
struct rte_pci_device *pci_dev)
 {
@@ -3774,16 +3824,7 @@ static int eth_nfp_pci_probe(struct rte_pci_driver 
*pci_drv __rte_unused,
 
 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
 {
-   struct rte_eth_dev *eth_dev;
-
-   eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
-   if (eth_dev == NULL)
-   return 0; /* port already released */
-   if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
-   (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC))
-   return -ENOTSUP;
-
-   return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
+   return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
 }
 
 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
-- 
2.30.0



[dpdk-dev] [PATCH] net/nfp: expand dev_infos_get callback function

2020-09-02 Thread Heinrich Kuhn
Report Rx and Tx descriptor related limitations in the nfp dev_info_get
callback function. This commit also adds NFP_ALIGN_RING_DESC to replace
a static integer value used during rx/tx queue setups to validate
descriptor alignment.

Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 drivers/net/nfp/nfp_net.c | 30 --
 drivers/net/nfp/nfp_net_pmd.h |  6 ++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 99946279d..0dd594992 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -1250,6 +1250,20 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct 
rte_eth_dev_info *dev_info)
.tx_rs_thresh = DEFAULT_TX_RSBIT_THRESH,
};
 
+   dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
+   .nb_max = NFP_NET_MAX_RX_DESC,
+   .nb_min = NFP_NET_MIN_RX_DESC,
+   .nb_align = NFP_ALIGN_RING_DESC,
+   };
+
+   dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
+   .nb_max = NFP_NET_MAX_TX_DESC,
+   .nb_min = NFP_NET_MIN_TX_DESC,
+   .nb_align = NFP_ALIGN_RING_DESC,
+   .nb_seg_max = NFP_TX_MAX_SEG,
+   .nb_mtu_seg_max = NFP_TX_MAX_MTU_SEG,
+   };
+
dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
   ETH_RSS_NONFRAG_IPV4_TCP |
   ETH_RSS_NONFRAG_IPV4_UDP |
@@ -1513,15 +1527,17 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
const struct rte_memzone *tz;
struct nfp_net_rxq *rxq;
struct nfp_net_hw *hw;
+   uint32_t rx_desc_sz;
 
hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
PMD_INIT_FUNC_TRACE();
 
/* Validating number of descriptors */
-   if (((nb_desc * sizeof(struct nfp_net_rx_desc)) % 128) != 0 ||
-   (nb_desc > NFP_NET_MAX_RX_DESC) ||
-   (nb_desc < NFP_NET_MIN_RX_DESC)) {
+   rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc);
+   if (rx_desc_sz % NFP_ALIGN_RING_DESC != 0 ||
+   nb_desc > NFP_NET_MAX_RX_DESC ||
+   nb_desc < NFP_NET_MIN_RX_DESC) {
PMD_DRV_LOG(ERR, "Wrong nb_desc value");
return -EINVAL;
}
@@ -1660,15 +1676,17 @@ nfp_net_tx_queue_setup(struct rte_eth_dev *dev, 
uint16_t queue_idx,
struct nfp_net_txq *txq;
uint16_t tx_free_thresh;
struct nfp_net_hw *hw;
+   uint32_t tx_desc_sz;
 
hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
PMD_INIT_FUNC_TRACE();
 
/* Validating number of descriptors */
-   if (((nb_desc * sizeof(struct nfp_net_tx_desc)) % 128) != 0 ||
-   (nb_desc > NFP_NET_MAX_TX_DESC) ||
-   (nb_desc < NFP_NET_MIN_TX_DESC)) {
+   tx_desc_sz = nb_desc * sizeof(struct nfp_net_tx_desc);
+   if (tx_desc_sz % NFP_ALIGN_RING_DESC != 0 ||
+   nb_desc > NFP_NET_MAX_TX_DESC ||
+   nb_desc < NFP_NET_MIN_TX_DESC) {
PMD_DRV_LOG(ERR, "Wrong nb_desc value");
return -EINVAL;
}
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h
index cb2d19afe..1295c5959 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_net_pmd.h
@@ -33,6 +33,12 @@ struct nfp_net_adapter;
 #define NFP_NET_MAX_RX_DESC (32 * 1024)
 #define NFP_NET_MIN_RX_DESC 64
 
+/* Descriptor alignment */
+#define NFP_ALIGN_RING_DESC 128
+
+#define NFP_TX_MAX_SEG UINT8_MAX
+#define NFP_TX_MAX_MTU_SEG 8
+
 /* Bar allocation */
 #define NFP_NET_CRTL_BAR0
 #define NFP_NET_TX_BAR  2
-- 
2.26.2



[dpdk-dev] [PATCH] doc: improve NFP PMD multiport PF documentation

2020-09-03 Thread Heinrich Kuhn
The Agilio CX family of smartNIC's generally have a 1:many mapping of PF
to physical ports. Elaborate on this mapping in the PF multiport section
of the NFP PMD documentation.

Fixes: d625beafc8be ("doc: update NFP with PF support information")
Cc: sta...@dpdk.org

Signed-off-by: Heinrich Kuhn 
Signed-off-by: Simon Horman 
---
 doc/guides/nics/nfp.rst | 37 +++--
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/doc/guides/nics/nfp.rst b/doc/guides/nics/nfp.rst
index 5f2a0698f..020e37d13 100644
--- a/doc/guides/nics/nfp.rst
+++ b/doc/guides/nics/nfp.rst
@@ -102,22 +102,39 @@ directory per firmware application. Options 1 and 2 for 
firmware filenames allow
 more than one SmartNIC, same type of SmartNIC or different ones, and to upload 
a
 different firmware to each SmartNIC.
 
+   .. Note::
+  Currently the NFP PMD supports using the PF with Agilio Basic Firmware. 
See
+  https://help.netronome.com/support/solutions for more information on the
+  various firmwares supported by the Netronome Agilio CX smartNIC.
 
 PF multiport support
 
 
-Some NFP cards support several physical ports with just one single PCI device.
-The DPDK core is designed with a 1:1 relationship between PCI devices and DPDK
-ports, so NFP PMD PF support requires handling the multiport case specifically.
-During NFP PF initialization, the PMD will extract the information about the
-number of PF ports from the firmware and will create as many DPDK ports as
-needed.
+The NFP PMD can work with up to 8 ports on the same PF device. The number of
+available ports is firmware and hardware dependent, and the driver looks for a
+firmware symbol during initialization to know how many can be used.
 
-Because the unusual relationship between a single PCI device and several DPDK
-ports, there are some limitations when using more than one PF DPDK port: there
-is no support for RX interrupts and it is not possible either to use those PF
-ports with the device hotplug functionality.
+DPDK apps work with ports, and a port is usually a PF or a VF PCI device.
+However, with the NFP PF multiport there is just one PF PCI device. Supporting
+this particular configuration requires the PMD to create ports in a special 
way,
+although once they are created, DPDK apps should be able to use them as normal
+PCI ports.
 
+NFP ports belonging to same PF can be seen inside PMD initialization with a
+suffix added to the PCI ID: :xx:yy.z_port_n. For example, a PF with PCI ID
+:03:00.0 and four ports is seen by the PMD code as:
+
+   .. code-block:: console
+
+  :03:00.0_port_0
+  :03:00.0_port_1
+  :03:00.0_port_2
+  :03:00.0_port_3
+
+   .. Note::
+
+  There are some limitations with multiport support: RX interrupts and
+  device hot-plugging are not supported.
 
 PF multiprocess support
 ---
-- 
2.26.2