DPDK patches and discussions
 help / color / mirror / Atom feed
From: Alejandro Lucero <alejandro.lucero@netronome.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 15/18] net/nfp: read PF port MAC addr using NSP
Date: Fri,  1 Sep 2017 15:12:18 +0100	[thread overview]
Message-ID: <1504275141-35448-16-git-send-email-alejandro.lucero@netronome.com> (raw)
In-Reply-To: <1504275141-35448-1-git-send-email-alejandro.lucero@netronome.com>

During initialization, mac address is read from configuration bar. This is
the default option when using VFs.

This patch adds support for reading the mac address using the NSPU
interface when PMD works with the PF.

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 drivers/net/nfp/nfp_net.c     | 59 +++++++++++++++++++++++++++++++++++++++++--
 drivers/net/nfp/nfp_net_pmd.h |  1 +
 drivers/net/nfp/nfp_nspu.c    | 22 +++++++++++++++-
 drivers/net/nfp/nfp_nspu.h    |  2 ++
 4 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 251a1c6..5d35ce1 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -593,7 +593,55 @@ enum nfp_qcp_ptr {
 	hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
 }
 
-static void nfp_net_read_mac(struct nfp_net_hw *hw)
+#define ETH_ADDR_LEN	6
+
+static void
+nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src)
+{
+	int i;
+
+	for (i = 0; i < ETH_ADDR_LEN; i++)
+		dst[ETH_ADDR_LEN - i - 1] = src[i];
+}
+
+static int
+nfp_net_pf_read_mac(struct nfp_net_hw *hw, int port)
+{
+	union eth_table_entry *entry;
+	int idx, i;
+
+	idx = port;
+	entry = hw->eth_table;
+
+	/* Reading NFP ethernet table obtained before */
+	for (i = 0; i < NSP_ETH_MAX_COUNT; i++) {
+		if (!(entry->port & NSP_ETH_PORT_LANES_MASK)) {
+			/* port not in use */
+			entry++;
+			continue;
+		}
+		if (idx == 0)
+			break;
+		idx--;
+		entry++;
+	}
+
+	if (i == NSP_ETH_MAX_COUNT)
+		return -EINVAL;
+
+	/*
+	 * hw points to port0 private data. We need hw now pointing to
+	 * right port.
+	 */
+	hw += port;
+	nfp_eth_copy_mac_reverse((uint8_t *)&hw->mac_addr,
+				 (uint8_t *)&entry->mac_addr);
+
+	return 0;
+}
+
+static void
+nfp_net_vf_read_mac(struct nfp_net_hw *hw)
 {
 	uint32_t tmp;
 
@@ -2676,6 +2724,10 @@ uint32_t nfp_net_txq_full(struct nfp_net_txq *txq)
 
 		/* vNIC PF tx/rx BARs are a subset of PF PCI device */
 		hwport0->hw_queues += bar_offset;
+
+		/* Lets seize the chance to read eth table from hw */
+		if (nfp_nsp_eth_read_table(nspu_desc, &hw->eth_table))
+			return -ENODEV;
 	}
 
 	if (hw->is_pf) {
@@ -2736,7 +2788,10 @@ uint32_t nfp_net_txq_full(struct nfp_net_txq *txq)
 		return -ENOMEM;
 	}
 
-	nfp_net_read_mac(hw);
+	if (hw->is_pf)
+		nfp_net_pf_read_mac(hwport0, port);
+	else
+		nfp_net_vf_read_mac(hw);
 
 	if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr)) {
 		/* Using random mac addresses for VFs */
diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h
index d7e38d4..20ade1a 100644
--- a/drivers/net/nfp/nfp_net_pmd.h
+++ b/drivers/net/nfp/nfp_net_pmd.h
@@ -441,6 +441,7 @@ struct nfp_net_hw {
 	uint8_t is_pf;
 	uint8_t pf_port_idx;
 	uint8_t pf_multiport_enabled;
+	union eth_table_entry *eth_table;
 	nspu_desc_t *nspu_desc;
 	nfpu_desc_t *nfpu_desc;
 };
diff --git a/drivers/net/nfp/nfp_nspu.c b/drivers/net/nfp/nfp_nspu.c
index 2f5632d..6ba940c 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -11,7 +11,6 @@
 #include <rte_byteorder.h>
 
 #include "nfp_nfpu.h"
-#include "nfp_net_eth.h"
 
 #define CFG_EXP_BAR_ADDR_SZ     1
 #define CFG_EXP_BAR_MAP_TYPE	1
@@ -601,3 +600,24 @@
 	rte_spinlock_unlock(&desc->nsp_lock);
 	return ret;
 }
+
+int
+nfp_nsp_eth_read_table(nspu_desc_t *desc, union eth_table_entry **table)
+{
+	int ret;
+
+	RTE_LOG(INFO, PMD, "Reading hw ethernet table...\n");
+	/* port 0 allocates the eth table and read it using NSPU */
+	*table = malloc(NSP_ETH_TABLE_SIZE);
+	if (!table)
+		return -ENOMEM;
+
+	ret = nspu_command(desc, NSP_CMD_READ_ETH_TABLE, 1, 0, *table,
+			   NSP_ETH_TABLE_SIZE, 0);
+	if (ret)
+		return ret;
+
+	RTE_LOG(INFO, PMD, "Done\n");
+
+	return 0;
+}
diff --git a/drivers/net/nfp/nfp_nspu.h b/drivers/net/nfp/nfp_nspu.h
index 4e58986..8c33835 100644
--- a/drivers/net/nfp/nfp_nspu.h
+++ b/drivers/net/nfp/nfp_nspu.h
@@ -58,6 +58,7 @@
  */
 
 #include <rte_spinlock.h>
+#include "nfp_net_eth.h"
 
 typedef struct {
 	int nfp;        /* NFP device */
@@ -79,3 +80,4 @@ int nfp_nspu_init(nspu_desc_t *desc, int nfp, int pcie_bar, size_t pcie_barsz,
 int nfp_nsp_map_ctrl_bar(nspu_desc_t *desc, uint64_t *pcie_offset);
 void nfp_nsp_map_queues_bar(nspu_desc_t *desc, uint64_t *pcie_offset);
 int nfp_nsp_eth_config(nspu_desc_t *desc, int port, int up);
+int nfp_nsp_eth_read_table(nspu_desc_t *desc, union eth_table_entry **table);
-- 
1.9.1

  parent reply	other threads:[~2017-09-01 14:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 14:12 [dpdk-dev] [PATCH v2 00/18] net/nfp: add PF support Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 01/18] net/nfp: add NSP user space interface Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 02/18] net/nfp: add specific PF probe function Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 03/18] net/nfp: add support for new PCI id Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 04/18] net/nfp: add NSP support for commands Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 05/18] net/nfp: add NSP FW upload command Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 06/18] net/nfp: add NSP symbol resolution command Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 07/18] net/nfp: add FW upload logic Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 08/18] net/nfp: add support for vnic config bar mapping Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 09/18] net/nfp: add support for vNIC Rx/Tx bar mappings Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 10/18] net/nfp: support PF devices inside PMD initialization Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 11/18] net/nfp: allocate ethernet device from PF probe function Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 12/18] net/nfp: support PF multiport Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 13/18] net/nfp: add NSP support for HW link configuration Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 14/18] net/nfp: add support for HW port " Alejandro Lucero
2017-09-01 14:12 ` Alejandro Lucero [this message]
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 16/18] doc: update NFP with PF support information Alejandro Lucero
2017-09-04 14:20   ` Mcnamara, John
2017-09-04 16:03     ` Alejandro Lucero
2017-09-06  9:53       ` Ferruh Yigit
2017-09-06 10:43         ` Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 17/18] doc: update release notes with NFP PF support Alejandro Lucero
2017-09-04 16:12   ` Mcnamara, John
2017-09-19  9:53   ` Ferruh Yigit
2017-09-19 10:49     ` Alejandro Lucero
2017-09-01 14:12 ` [dpdk-dev] [PATCH v2 18/18] doc: create different features files for NFP drivers Alejandro Lucero
2017-09-04 16:29   ` Mcnamara, John
2017-09-06 16:15 ` [dpdk-dev] [PATCH v2 00/18] net/nfp: add PF support Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504275141-35448-16-git-send-email-alejandro.lucero@netronome.com \
    --to=alejandro.lucero@netronome.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).