Skip to contentSkip to conversation

net/axgbe: add additional MAC address support

PATCH In review [email protected] 3 participants 4 messages Feb 28, 2020 – Mar 6, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net/axgbe: add additional MAC address support

From: Chandu Babu N <[email protected]>

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

---
 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(-)
drivers/net/axgbe/axgbe_dev.c +29 -0
index 2e796c0b3..f830b7230 100644
@@ -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;
drivers/net/axgbe/axgbe_ethdev.c +89 -5

132 lines not on this page · raw message

drivers/net/axgbe/axgbe_ethdev.h +3 -1
index a1083b17b..781d170e5 100644
@@ -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_ */
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 net/axgbe: add unicast hash table for mac address

From: Chandu Babu N <[email protected]>

implement eth_dev_ops uc_hash_table_set and uc_all_hash_table_set

---
 drivers/net/axgbe/axgbe_common.h |  2 +
 drivers/net/axgbe/axgbe_dev.c    | 60 ++++++++++++++++++++++++
 drivers/net/axgbe/axgbe_ethdev.c | 79 ++++++++++++++++++++++++++++++++
 drivers/net/axgbe/axgbe_ethdev.h | 10 +++-
 4 files changed, 150 insertions(+), 1 deletion(-)
drivers/net/axgbe/axgbe_common.h +2 -0
index 2ac4d8946..72683aa65 100644
@@ -292,6 +292,8 @@
 #define MAC_MACAHR(i)	(MAC_MACA0HR + ((i) * 8))
 #define MAC_MACALR(i)	(MAC_MACA0LR + ((i) * 8))
 
+#define MAC_HTR(i)	(MAC_HTR0 + ((i) * MAC_HTR_INC))
+
 /* MAC register entry bit positions and sizes */
 #define MAC_HWF0R_ADDMACADRSEL_INDEX	18
 #define MAC_HWF0R_ADDMACADRSEL_WIDTH	5
drivers/net/axgbe/axgbe_dev.c +60 -0

78 lines not on this page · raw message

drivers/net/axgbe/axgbe_ethdev.c +79 -0

109 lines not on this page · raw message

drivers/net/axgbe/axgbe_ethdev.h +9 -1
index 781d170e5..3969317fd 100644
@@ -17,6 +17,7 @@
 #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		32
+#define AXGBE_MAX_HASH_MAC_ADDRS	256
 
 #define AXGBE_RX_BUF_ALIGN		64
 
@@ -83,7 +84,7 @@
 	(((_x) < 1024) ? 0 : ((_x) / AXGMAC_FLOW_CONTROL_UNIT) - 2)
 #define AXGMAC_FLOW_CONTROL_MAX		33280
 
-/* Maximum MAC address hash table size (256 bits = 8 bytes) */
+/* Maximum MAC address hash table size (256 bits = 8 dword) */
 #define AXGBE_MAC_HASH_TABLE_SIZE	8
 
 /* Receive Side Scaling */
@@ -625,6 +626,12 @@ struct axgbe_port {
 	uint32_t rx_csum_enable;
 
 	struct axgbe_mmc_stats mmc_stats;
+
+	/* Hash filtering */
+	unsigned int hash_table_shift;
+	unsigned int hash_table_count;
+	unsigned int uc_hash_mac_addr;
+	unsigned int uc_hash_table[AXGBE_MAC_HASH_TABLE_SIZE];
 };
 
 void axgbe_init_function_ptrs_dev(struct axgbe_hw_if *hw_if);
@@ -633,5 +640,6 @@ 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);
+void axgbe_set_mac_hash_table(struct axgbe_port *pdata, u8 *addr, bool add);
 
 #endif /* RTE_ETH_AXGBE_H_ */
Signature · 1 line
2.17.1
Acked-by on v1 1/2
#2 lore raw
In reply to [email protected]

[AMD Official Use Only - Internal Distribution Only]

For series,

Quoted 198 lines

From: Chandu Babu N <[email protected]>

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

---
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(-)
drivers/net/axgbe/axgbe_dev.c +28 -0
@@ -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

drivers/net/axgbe/axgbe_ethdev.c +14 -0
@@ -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,

drivers/net/axgbe/axgbe_ethdev.c +65 -0
@@ -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;
drivers/net/axgbe/axgbe_ethdev.c +1 -1
-	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 =
drivers/net/axgbe/axgbe_ethdev.c +1 -0
@@ -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;
drivers/net/axgbe/axgbe_ethdev.c +3 -2
-	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,
drivers/net/axgbe/axgbe_ethdev.c +2 -2
-			     "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;
	}
drivers/net/axgbe/axgbe_ethdev.h +3 -2
index a1083b17b..781d170e5 100644
@@ -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

#3 lore raw
Quoted 1 line · On 3/6/2020 9:56 AM, Kumar, Ravi1 wrote:

[AMD Official Use Only - Internal Distribution Only]

<...>

Quoted 9 lines
Quoted 5 lines

From: Chandu Babu N <[email protected]>

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

For series,

Series applied to dpdk-next-net/master, thanks.