DPDK patches and discussions
 help / color / mirror / Atom feed
From: spinler@cesnet.cz
To: dev@dpdk.org
Cc: Martin Spinler <spinler@cesnet.cz>
Subject: [PATCH v2 5/5] net/nfb: add support for more MAC addresses
Date: Tue, 15 Feb 2022 13:55:43 +0100	[thread overview]
Message-ID: <20220215125543.142108-6-spinler@cesnet.cz> (raw)
In-Reply-To: <20220215125543.142108-1-spinler@cesnet.cz>

From: Martin Spinler <spinler@cesnet.cz>

Extend the eth_dev_ops by add/remove MAC address functions.

Signed-off-by: Martin Spinler <spinler@cesnet.cz>
---
 drivers/net/nfb/nfb_ethdev.c | 90 ++++++++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 13 deletions(-)

diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
index 5d503e131a..defd118bd0 100644
--- a/drivers/net/nfb/nfb_ethdev.c
+++ b/drivers/net/nfb/nfb_ethdev.c
@@ -202,6 +202,30 @@ nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
 	return 0;
 }
 
+static uint32_t
+nfb_eth_get_max_mac_address_count(struct rte_eth_dev *dev)
+{
+	uint16_t i;
+	uint32_t c;
+	uint32_t ret = (uint32_t)-1;
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	/*
+	 * Go through all RX MAC components in firmware and find
+	 * the minimal indicated space size for MAC addresses.
+	 */
+	for (i = 0; i < internals->max_rxmac; i++) {
+		c = nc_rxmac_mac_address_count(internals->rxmac[i]);
+		ret = RTE_MIN(c, ret);
+	}
+
+	/* The driver must support at least 1 MAC address, pretend that */
+	if (internals->max_rxmac == 0 || ret == 0)
+		ret = 1;
+
+	return ret;
+}
+
 /**
  * DPDK callback to get information about the device.
  *
@@ -214,7 +238,8 @@ static int
 nfb_eth_dev_info(struct rte_eth_dev *dev,
 	struct rte_eth_dev_info *dev_info)
 {
-	dev_info->max_mac_addrs = 1;
+	dev_info->max_mac_addrs = nfb_eth_get_max_mac_address_count(dev);
+
 	dev_info->max_rx_pktlen = (uint32_t)-1;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
@@ -376,6 +401,18 @@ nfb_eth_dev_set_link_down(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static uint64_t
+nfb_eth_mac_addr_conv(struct rte_ether_addr *mac_addr)
+{
+	int i;
+	uint64_t res = 0;
+	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) {
+		res <<= 8;
+		res |= mac_addr->addr_bytes[i] & 0xFF;
+	}
+	return res;
+}
+
 /**
  * DPDK callback to set primary MAC address.
  *
@@ -392,26 +429,48 @@ nfb_eth_mac_addr_set(struct rte_eth_dev *dev,
 	struct rte_ether_addr *mac_addr)
 {
 	unsigned int i;
-	uint64_t mac = 0;
+	uint64_t mac;
 	struct rte_eth_dev_data *data = dev->data;
 	struct pmd_internals *internals = (struct pmd_internals *)
 		data->dev_private;
 
-	if (!rte_is_valid_assigned_ether_addr(mac_addr))
-		return -EINVAL;
+	mac = nfb_eth_mac_addr_conv(mac_addr);
+	/* Until no real multi-port support, configure all RX MACs the same */
+	for (i = 0; i < internals->max_rxmac; ++i)
+		nc_rxmac_set_mac(internals->rxmac[i], 0, mac, 1);
 
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) {
-		mac <<= 8;
-		mac |= mac_addr->addr_bytes[i] & 0xFF;
-	}
+	return 0;
+}
 
+static int
+nfb_eth_mac_addr_add(struct rte_eth_dev *dev,
+	struct rte_ether_addr *mac_addr, uint32_t index, uint32_t pool __rte_unused)
+{
+	unsigned int i;
+	uint64_t mac;
+	struct rte_eth_dev_data *data = dev->data;
+	struct pmd_internals *internals = (struct pmd_internals *)
+		data->dev_private;
+
+	mac = nfb_eth_mac_addr_conv(mac_addr);
 	for (i = 0; i < internals->max_rxmac; ++i)
-		nc_rxmac_set_mac(internals->rxmac[i], 0, mac, 1);
+		nc_rxmac_set_mac(internals->rxmac[i], index, mac, 1);
 
-	rte_ether_addr_copy(mac_addr, data->mac_addrs);
 	return 0;
 }
 
+static void
+nfb_eth_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+{
+	unsigned int i;
+	struct rte_eth_dev_data *data = dev->data;
+	struct pmd_internals *internals = (struct pmd_internals *)
+		data->dev_private;
+
+	for (i = 0; i < internals->max_rxmac; ++i)
+		nc_rxmac_set_mac(internals->rxmac[i], index, 0, 0);
+}
+
 static const struct eth_dev_ops ops = {
 	.dev_start = nfb_eth_dev_start,
 	.dev_stop = nfb_eth_dev_stop,
@@ -436,6 +495,8 @@ static const struct eth_dev_ops ops = {
 	.stats_get = nfb_eth_stats_get,
 	.stats_reset = nfb_eth_stats_reset,
 	.mac_addr_set = nfb_eth_mac_addr_set,
+	.mac_addr_add = nfb_eth_mac_addr_add,
+	.mac_addr_remove = nfb_eth_mac_addr_remove,
 };
 
 /**
@@ -450,6 +511,7 @@ static const struct eth_dev_ops ops = {
 static int
 nfb_eth_dev_init(struct rte_eth_dev *dev)
 {
+	uint32_t mac_count;
 	struct rte_eth_dev_data *data = dev->data;
 	struct pmd_internals *internals = (struct pmd_internals *)
 		data->dev_private;
@@ -516,9 +578,10 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
 	/* Get link state */
 	nfb_eth_link_update(dev, 0);
 
-	/* Allocate space for one mac address */
-	data->mac_addrs = rte_zmalloc(data->name, sizeof(struct rte_ether_addr),
-		RTE_CACHE_LINE_SIZE);
+	/* Allocate space for MAC addresses */
+	mac_count = nfb_eth_get_max_mac_address_count(dev);
+	data->mac_addrs = rte_zmalloc(data->name,
+		sizeof(struct rte_ether_addr) * mac_count, RTE_CACHE_LINE_SIZE);
 	if (data->mac_addrs == NULL) {
 		RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
 		nfb_close(internals->nfb);
@@ -531,6 +594,7 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
 	eth_addr_init.addr_bytes[2] = eth_addr.addr_bytes[2];
 
 	nfb_eth_mac_addr_set(dev, &eth_addr_init);
+	rte_ether_addr_copy(&eth_addr_init, &dev->data->mac_addrs[0]);
 
 	data->promiscuous = nfb_eth_promiscuous_get(dev);
 	data->all_multicast = nfb_eth_allmulticast_get(dev);
-- 
2.35.1


  parent reply	other threads:[~2022-02-15 12:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14 11:25 [PATCH 1/6] net/nfb: add missing libfdt dependency for build spinler
2022-02-14 11:25 ` [PATCH 2/6] drivers/nfb: fix array indexes in deinit functions spinler
2022-02-14 13:34   ` Ferruh Yigit
2022-02-14 16:52     ` Martin Spinler
2022-02-14 11:25 ` [PATCH 3/6] drivers/nfb: do not report zero-sized TX burst spinler
2022-02-14 13:35   ` Ferruh Yigit
2022-02-14 16:53     ` Martin Spinler
2022-02-14 17:34       ` Ferruh Yigit
2022-02-14 11:25 ` [PATCH 4/6] drivers/nfb: use RTE_ETH_RX_OFFLOAD_TIMESTAMP flag spinler
2022-02-14 11:25 ` [PATCH 5/6] drivers/nfb: fix multicast/promiscuous mode switching spinler
2022-02-14 13:36   ` Ferruh Yigit
2022-02-14 16:53     ` Martin Spinler
2022-02-14 11:25 ` [PATCH 6/6] drivers/nfb: add support for more MAC addresses spinler
2022-02-14 13:37   ` Ferruh Yigit
2022-02-14 16:53     ` Martin Spinler
2022-02-14 17:54       ` Ferruh Yigit
2022-02-15 13:02         ` Martin Spinler
2022-02-14 13:36 ` [PATCH 1/6] net/nfb: add missing libfdt dependency for build Ferruh Yigit
2022-02-14 16:53   ` Martin Spinler
2022-02-15 12:55 ` [PATCH v2 0/5] " spinler
2022-02-15 12:55   ` [PATCH v2 1/5] net/nfb: fix array indexes in deinit functions spinler
2022-02-15 12:55   ` [PATCH v2 2/5] net/nfb: do not report zero-sized TX burst spinler
2022-02-15 12:55   ` [PATCH v2 3/5] net/nfb: use RTE_ETH_RX_OFFLOAD_TIMESTAMP flag spinler
2022-02-15 12:55   ` [PATCH v2 4/5] net/nfb: fix multicast/promiscuous mode switching spinler
2022-02-15 12:55   ` spinler [this message]
2022-02-15 13:55   ` [PATCH v2 0/5] net/nfb: add missing libfdt dependency for build Ferruh Yigit
2022-02-15 13:57     ` Martin Spinler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220215125543.142108-6-spinler@cesnet.cz \
    --to=spinler@cesnet.cz \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).