[AMD Official Use Only - Internal Distribution Only] For series, Acked-by: Ravi Kumar <ravi1.ku...@amd.com>
>From: Chandu Babu N <cha...@amd.com> > >Supports adding MAC addresses to enable whitelist filtering to accept packets >implement eth_dev_ops mac_addr_set, mac_addr_add, mac_addr_remove and >set_mc_addr_list > >Signed-off-by: Chandu Babu N <cha...@amd.com> >--- > drivers/net/axgbe/axgbe_dev.c | 29 ++++++++++ > drivers/net/axgbe/axgbe_ethdev.c | 94 ++++++++++++++++++++++++++++++-- > drivers/net/axgbe/axgbe_ethdev.h | 4 +- > 3 files changed, 121 insertions(+), 6 deletions(-) > >diff --git a/drivers/net/axgbe/axgbe_dev.c b/drivers/net/axgbe/axgbe_dev.c >index 2e796c0b3..f830b7230 100644 >--- a/drivers/net/axgbe/axgbe_dev.c >+++ b/drivers/net/axgbe/axgbe_dev.c >@@ -1008,6 +1008,35 @@ static void axgbe_enable_mtl_interrupts(struct >axgbe_port *pdata) > } > } > >+void axgbe_set_mac_addn_addr(struct axgbe_port *pdata, u8 *addr, >+uint32_t index) { >+ unsigned int mac_addr_hi, mac_addr_lo; >+ u8 *mac_addr; >+ >+ mac_addr_lo = 0; >+ mac_addr_hi = 0; >+ >+ if (addr) { >+ mac_addr = (u8 *)&mac_addr_lo; >+ mac_addr[0] = addr[0]; >+ mac_addr[1] = addr[1]; >+ mac_addr[2] = addr[2]; >+ mac_addr[3] = addr[3]; >+ mac_addr = (u8 *)&mac_addr_hi; >+ mac_addr[0] = addr[4]; >+ mac_addr[1] = addr[5]; >+ >+ /*Address Enable: Use this Addr for Perfect Filtering */ >+ AXGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1); >+ } >+ >+ PMD_DRV_LOG(DEBUG, "%s mac address at %#x\n", >+ addr ? "set" : "clear", index); >+ >+ AXGMAC_IOWRITE(pdata, MAC_MACAHR(index), mac_addr_hi); >+ AXGMAC_IOWRITE(pdata, MAC_MACALR(index), mac_addr_lo); } >+ > static int axgbe_set_mac_address(struct axgbe_port *pdata, u8 *addr) { > unsigned int mac_addr_hi, mac_addr_lo; diff --git > a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c >index 00974e737..34cc0fbb8 100644 >--- a/drivers/net/axgbe/axgbe_ethdev.c >+++ b/drivers/net/axgbe/axgbe_ethdev.c >@@ -20,6 +20,16 @@ static int axgbe_dev_promiscuous_enable(struct rte_eth_dev >*dev); static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev); >static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev); static int >axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev); >+static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, >+ struct rte_ether_addr *mac_addr); static int >+axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, >+ struct rte_ether_addr *mac_addr, >+ uint32_t index, >+ uint32_t vmdq); >+static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t >+index); static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, >+ struct rte_ether_addr *mc_addr_set, >+ uint32_t nb_mc_addr); > static int axgbe_dev_link_update(struct rte_eth_dev *dev, > int wait_to_complete); > static int axgbe_dev_get_regs(struct rte_eth_dev *dev, @@ -160,6 +170,10 @@ > static const struct eth_dev_ops axgbe_eth_dev_ops = { > .promiscuous_disable = axgbe_dev_promiscuous_disable, > .allmulticast_enable = axgbe_dev_allmulticast_enable, > .allmulticast_disable = axgbe_dev_allmulticast_disable, >+ .mac_addr_set = axgbe_dev_mac_addr_set, >+ .mac_addr_add = axgbe_dev_mac_addr_add, >+ .mac_addr_remove = axgbe_dev_mac_addr_remove, >+ .set_mc_addr_list = axgbe_dev_set_mc_addr_list, > .link_update = axgbe_dev_link_update, > .get_reg = axgbe_dev_get_regs, > .stats_get = axgbe_dev_stats_get, >@@ -370,6 +384,74 @@ axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev) > return 0; > } > >+static int >+axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr >+*mac_addr) { >+ struct axgbe_port *pdata = dev->data->dev_private; >+ >+ /* Set Default MAC Addr */ >+ axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0); >+ >+ return 0; >+} >+ >+static int >+axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr >*mac_addr, >+ uint32_t index, uint32_t pool __rte_unused) { >+ struct axgbe_port *pdata = dev->data->dev_private; >+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat; >+ >+ if (index > hw_feat->addn_mac) { >+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); >+ return -EINVAL; >+ } >+ axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index); >+ return 0; >+} >+ >+static void >+axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) { >+ struct axgbe_port *pdata = dev->data->dev_private; >+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat; >+ >+ if (index > hw_feat->addn_mac) { >+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); >+ return; >+ } >+ axgbe_set_mac_addn_addr(pdata, NULL, index); } >+ >+static int >+axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, >+ struct rte_ether_addr *mc_addr_set, >+ uint32_t nb_mc_addr) >+{ >+ struct axgbe_port *pdata = dev->data->dev_private; >+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat; >+ uint32_t index = 1; /* 0 is always default mac */ >+ uint32_t i; >+ >+ if (nb_mc_addr > hw_feat->addn_mac) { >+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", nb_mc_addr); >+ return -EINVAL; >+ } >+ >+ /* clear unicast addresses */ >+ for (i = 1; i < hw_feat->addn_mac; i++) { >+ if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i])) >+ continue; >+ memset(&dev->data->mac_addrs[i], 0, >+ sizeof(struct rte_ether_addr)); >+ } >+ >+ while (nb_mc_addr--) >+ axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++); >+ >+ return 0; >+} >+ > /* return 0 means link status changed, -1 means not changed */ static int > axgbe_dev_link_update(struct rte_eth_dev *dev, @@ -809,7 +891,7 @@ > axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) > dev_info->max_tx_queues = pdata->tx_ring_count; > dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE; > dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE; >- dev_info->max_mac_addrs = AXGBE_MAX_MAC_ADDRS; >+ dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1; > dev_info->speed_capa = ETH_LINK_SPEED_10G; > > dev_info->rx_offload_capa = >@@ -1044,6 +1126,7 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) > struct axgbe_port *pdata; > struct rte_pci_device *pci_dev; > uint32_t reg, mac_lo, mac_hi; >+ uint32_t len; > int ret; > > eth_dev->dev_ops = &axgbe_eth_dev_ops; @@ -1113,12 +1196,13 @@ > eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) > pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff; > pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8) & 0xff; > >- eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", >- RTE_ETHER_ADDR_LEN, 0); >+ len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS; >+ eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0); >+ > if (!eth_dev->data->mac_addrs) { > PMD_INIT_LOG(ERR, >- "Failed to alloc %u bytes needed to store MAC addr >tbl", >- RTE_ETHER_ADDR_LEN); >+ "Failed to alloc %u bytes needed to " >+ "store MAC addresses", len); > return -ENOMEM; > } > >diff --git a/drivers/net/axgbe/axgbe_ethdev.h >b/drivers/net/axgbe/axgbe_ethdev.h >index a1083b17b..781d170e5 100644 >--- a/drivers/net/axgbe/axgbe_ethdev.h >+++ b/drivers/net/axgbe/axgbe_ethdev.h >@@ -16,7 +16,7 @@ > #define AXGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1)) > #define AXGBE_RX_MAX_BUF_SIZE (0x3fff & ~(64 - 1)) > #define AXGBE_RX_MIN_BUF_SIZE (RTE_ETHER_MAX_LEN + VLAN_HLEN) >-#define AXGBE_MAX_MAC_ADDRS 1 >+#define AXGBE_MAX_MAC_ADDRS 32 > > #define AXGBE_RX_BUF_ALIGN 64 > >@@ -631,5 +631,7 @@ void axgbe_init_function_ptrs_dev(struct axgbe_hw_if >*hw_if); void axgbe_init_function_ptrs_phy(struct axgbe_phy_if *phy_if); >void axgbe_init_function_ptrs_phy_v2(struct axgbe_phy_if *phy_if); void >axgbe_init_function_ptrs_i2c(struct axgbe_i2c_if *i2c_if); >+void axgbe_set_mac_addn_addr(struct axgbe_port *pdata, u8 *addr, >+ uint32_t index); > > #endif /* RTE_ETH_AXGBE_H_ */ >-- >2.17.1 >