diff mbox series

[v3,61/62] net/cnxk: add multicast filter support

Message ID 20210618103741.26526-62-ndabilpuram@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers show
Series Marvell CNXK Ethdev Driver | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nithin Kumar Dabilpuram June 18, 2021, 10:37 a.m. UTC
From: Sunil Kumar Kori <skori@marvell.com>

Patch adds multicast filter support for cn9k and cn10k platforms.

CGX DMAC filter table(32 entries) is divided among all LMACs
connected to it i.e. if CGX has 4 LMACs then each LMAC can have
up to 8 filters. If CGX has 1 LMAC then it can have up to 32
filters.

Above mentioned filter table is used to install unicast and multicast
DMAC address filters. Unicast filters are installed via
rte_eth_dev_mac_addr_add API while multicast filters are installed
via rte_eth_dev_set_mc_addr_list API.

So in total, supported MAC filters are equal to DMAC filters plus
mcast filters.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 doc/guides/nics/features/cnxk.ini     |  1 +
 doc/guides/nics/features/cnxk_vec.ini |  1 +
 drivers/net/cnxk/cnxk_ethdev.c        |  2 ++
 drivers/net/cnxk/cnxk_ethdev.h        |  4 +++
 drivers/net/cnxk/cnxk_ethdev_ops.c    | 63 +++++++++++++++++++++++++++++++++++
 5 files changed, 71 insertions(+)
diff mbox series

Patch

diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini
index 9945af9..c686ceb 100644
--- a/doc/guides/nics/features/cnxk.ini
+++ b/doc/guides/nics/features/cnxk.ini
@@ -22,6 +22,7 @@  TSO                  = Y
 Promiscuous mode     = Y
 Allmulticast mode    = Y
 Unicast MAC filter   = Y
+Multicast MAC filter = Y
 RSS hash             = Y
 RSS key update       = Y
 RSS reta update      = Y
diff --git a/doc/guides/nics/features/cnxk_vec.ini b/doc/guides/nics/features/cnxk_vec.ini
index b4b1169..4c3f78e 100644
--- a/doc/guides/nics/features/cnxk_vec.ini
+++ b/doc/guides/nics/features/cnxk_vec.ini
@@ -21,6 +21,7 @@  MTU update           = Y
 Promiscuous mode     = Y
 Allmulticast mode    = Y
 Unicast MAC filter   = Y
+Multicast MAC filter = Y
 RSS hash             = Y
 RSS key update       = Y
 RSS reta update      = Y
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index f49c9e6..1edea35 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -1258,6 +1258,7 @@  struct eth_dev_ops cnxk_eth_dev_ops = {
 	.reta_query = cnxk_nix_reta_query,
 	.rss_hash_update = cnxk_nix_rss_hash_update,
 	.rss_hash_conf_get = cnxk_nix_rss_hash_conf_get,
+	.set_mc_addr_list = cnxk_nix_mc_addr_list_configure,
 };
 
 static int
@@ -1322,6 +1323,7 @@  cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
 	}
 
 	dev->max_mac_entries = max_entries;
+	dev->dmac_filter_count = 1;
 
 	/* Get mac address */
 	rc = roc_nix_npc_mac_addr_get(nix, dev->mac_addr);
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index cd08e3a..c07e988 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -162,6 +162,7 @@  struct cnxk_eth_dev {
 	uint8_t configured;
 
 	/* Max macfilter entries */
+	uint8_t dmac_filter_count;
 	uint8_t max_mac_entries;
 	bool dmac_filter_enable;
 
@@ -265,6 +266,9 @@  int cnxk_nix_probe(struct rte_pci_driver *pci_drv,
 		   struct rte_pci_device *pci_dev);
 int cnxk_nix_remove(struct rte_pci_device *pci_dev);
 int cnxk_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu);
+int cnxk_nix_mc_addr_list_configure(struct rte_eth_dev *eth_dev,
+				    struct rte_ether_addr *mc_addr_set,
+				    uint32_t nb_mc_addr);
 int cnxk_nix_mac_addr_add(struct rte_eth_dev *eth_dev,
 			  struct rte_ether_addr *addr, uint32_t index,
 			  uint32_t pool);
diff --git a/drivers/net/cnxk/cnxk_ethdev_ops.c b/drivers/net/cnxk/cnxk_ethdev_ops.c
index 28b49ad..3be678a 100644
--- a/drivers/net/cnxk/cnxk_ethdev_ops.c
+++ b/drivers/net/cnxk/cnxk_ethdev_ops.c
@@ -359,6 +359,7 @@  cnxk_nix_mac_addr_add(struct rte_eth_dev *eth_dev, struct rte_ether_addr *addr,
 	roc_nix_npc_promisc_ena_dis(nix, true);
 	dev->dmac_filter_enable = true;
 	eth_dev->data->promiscuous = false;
+	dev->dmac_filter_count++;
 
 	return 0;
 }
@@ -373,6 +374,8 @@  cnxk_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index)
 	rc = roc_nix_mac_addr_del(nix, index);
 	if (rc)
 		plt_err("Failed to delete mac address, rc=%d", rc);
+
+	dev->dmac_filter_count--;
 }
 
 int
@@ -845,3 +848,63 @@  cnxk_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
 
 	return 0;
 }
+
+int
+cnxk_nix_mc_addr_list_configure(struct rte_eth_dev *eth_dev,
+				struct rte_ether_addr *mc_addr_set,
+				uint32_t nb_mc_addr)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	const struct rte_ether_addr null_mac_addr = {0};
+	struct rte_eth_dev_data *data = eth_dev->data;
+	struct roc_nix *nix = &dev->nix;
+	int rc, index;
+	uint32_t i;
+
+	/* All configured multicast filters should be flushed first */
+	for (i = 0; i < dev->max_mac_entries; i++) {
+		if (rte_is_multicast_ether_addr(&data->mac_addrs[i])) {
+			rc = roc_nix_mac_addr_del(nix, i);
+			if (rc) {
+				plt_err("Failed to flush mcast address, rc=%d",
+					rc);
+				return rc;
+			}
+
+			dev->dmac_filter_count--;
+			/* Update address in NIC data structure */
+			rte_ether_addr_copy(&null_mac_addr,
+					    &data->mac_addrs[i]);
+		}
+	}
+
+	if (!mc_addr_set || !nb_mc_addr)
+		return 0;
+
+	/* Check for available space */
+	if (nb_mc_addr >
+	    ((uint32_t)(dev->max_mac_entries - dev->dmac_filter_count))) {
+		plt_err("No space is available to add multicast filters");
+		return -ENOSPC;
+	}
+
+	/* Multicast addresses are to be installed */
+	for (i = 0; i < nb_mc_addr; i++) {
+		index = roc_nix_mac_addr_add(nix, mc_addr_set[i].addr_bytes);
+		if (index < 0) {
+			plt_err("Failed to add mcast mac address, rc=%d",
+				index);
+			return index;
+		}
+
+		dev->dmac_filter_count++;
+		/* Update address in NIC data structure */
+		rte_ether_addr_copy(&mc_addr_set[i], &data->mac_addrs[index]);
+	}
+
+	roc_nix_npc_promisc_ena_dis(nix, true);
+	dev->dmac_filter_enable = true;
+	eth_dev->data->promiscuous = false;
+
+	return 0;
+}