From patchwork Thu Aug 24 16:20:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Lucero X-Patchwork-Id: 27900 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id F1F1E9119; Thu, 24 Aug 2017 18:20:55 +0200 (CEST) Received: from netronome.com (host-79-78-33-110.static.as9105.net [79.78.33.110]) by dpdk.org (Postfix) with ESMTP id 71F7D7D24 for ; Thu, 24 Aug 2017 18:20:36 +0200 (CEST) Received: from netronome.com (localhost [127.0.0.1]) by netronome.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id v7OGKQCJ016353 for ; Thu, 24 Aug 2017 17:20:26 +0100 Received: (from alucero@localhost) by netronome.com (8.14.4/8.14.4/Submit) id v7OGKQMf016352 for dev@dpdk.org; Thu, 24 Aug 2017 17:20:26 +0100 From: Alejandro Lucero To: dev@dpdk.org Date: Thu, 24 Aug 2017 17:20:21 +0100 Message-Id: <1503591622-16232-16-git-send-email-alejandro.lucero@netronome.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1503591622-16232-1-git-send-email-alejandro.lucero@netronome.com> References: <1503591622-16232-1-git-send-email-alejandro.lucero@netronome.com> Subject: [dpdk-dev] [PATCH 15/16] nfp: read pf port mac addr using nsp X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 aa611e1..9496b63 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; @@ -2672,6 +2720,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) { @@ -2732,7 +2784,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 29325e6..36f2b30 100644 --- a/drivers/net/nfp/nfp_nspu.c +++ b/drivers/net/nfp/nfp_nspu.c @@ -11,7 +11,6 @@ #include #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 +#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);