net/nfp: write MAC address to configuration bar
authorAlejandro Lucero <alejandro.lucero@netronome.com>
Fri, 11 Aug 2017 10:25:33 +0000 (11:25 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 6 Oct 2017 00:49:47 +0000 (02:49 +0200)
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 <alejandro.lucero@netronome.com>
drivers/net/nfp/nfp_net.c
drivers/net/nfp/nfp_net_pmd.h

index 92b03c4..e846eb7 100644 (file)
@@ -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,
index eec56bc..c6bddaa 100644 (file)
@@ -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;