From f08d93d4d8659f2d2dc53c9c107758bc724be3c3 Mon Sep 17 00:00:00 2001 From: Alejandro Lucero Date: Fri, 11 Aug 2017 11:25:33 +0100 Subject: [PATCH] net/nfp: write MAC address to configuration bar If not a valid mac present in configuration bar, PMD creates a random one. It needs to be passed to the NIC. Signed-off-by: Alejandro Lucero --- drivers/net/nfp/nfp_net.c | 18 +++++++++++++++++- drivers/net/nfp/nfp_net_pmd.h | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c index 92b03c4cb1..e846eb749e 100644 --- a/drivers/net/nfp/nfp_net.c +++ b/drivers/net/nfp/nfp_net.c @@ -603,6 +603,20 @@ static void nfp_net_read_mac(struct nfp_net_hw *hw) memcpy(&hw->mac_addr[4], &tmp, 2); } +static void +nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac) +{ + uint32_t mac0 = *(uint32_t *)mac; + uint16_t mac1; + + nn_writel(rte_cpu_to_be_32(mac0), hw->ctrl_bar + NFP_NET_CFG_MACADDR); + + mac += 4; + mac1 = *(uint16_t *)mac; + nn_writew(rte_cpu_to_be_16(mac1), + hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6); +} + static int nfp_configure_rx_interrupt(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle) @@ -2539,9 +2553,11 @@ nfp_net_init(struct rte_eth_dev *eth_dev) nfp_net_read_mac(hw); - if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr)) + if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr)) { /* Using random mac addresses for VFs */ eth_random_addr(&hw->mac_addr[0]); + nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr); + } /* Copying mac address to DPDK eth_dev struct */ ether_addr_copy((struct ether_addr *)hw->mac_addr, diff --git a/drivers/net/nfp/nfp_net_pmd.h b/drivers/net/nfp/nfp_net_pmd.h index eec56bc1c8..c6bddaa3a9 100644 --- a/drivers/net/nfp/nfp_net_pmd.h +++ b/drivers/net/nfp/nfp_net_pmd.h @@ -143,6 +143,11 @@ static inline void nn_writel(uint32_t val, volatile void *addr) rte_write32(val, addr); } +static inline void nn_writew(uint16_t val, volatile void *addr) +{ + rte_write16(val, addr); +} + static inline uint64_t nn_readq(volatile void *addr) { const volatile uint32_t *p = addr; -- 2.20.1