DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@intel.com>, <thomas@monjalon.net>
Subject: [dpdk-dev] [PATCH 04/14] net/hns3: extract a common interface to check duplicates
Date: Fri, 22 Oct 2021 17:19:55 +0800	[thread overview]
Message-ID: <20211022092006.60959-5-humin29@huawei.com> (raw)
In-Reply-To: <20211022092006.60959-1-humin29@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

Extract a common interface for PF and VF to check whether the configured
multicast MAC address from rte_eth_dev_mac_addr_add() is the same as the
multicast MAC address from rte_eth_dev_set_mc_addr_list().

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    | 25 ++++++++++++++++++-------
 drivers/net/hns3/hns3_ethdev.h    |  4 ++++
 drivers/net/hns3/hns3_ethdev_vf.c | 16 ++--------------
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 2d80b8454c..1650ec77bb 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -1609,27 +1609,38 @@ hns3_add_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
 	return ret;
 }
 
-static int
-hns3_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
+bool
+hns3_find_duplicate_mc_addr(struct hns3_hw *hw, struct rte_ether_addr *mc_addr)
 {
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
 	struct rte_ether_addr *addr;
-	int ret;
 	int i;
 
 	for (i = 0; i < hw->mc_addrs_num; i++) {
 		addr = &hw->mc_addrs[i];
-		/* Check if there are duplicate addresses */
-		if (rte_is_same_ether_addr(addr, mac_addr)) {
+		/* Check if there are duplicate addresses in mc_addrs[] */
+		if (rte_is_same_ether_addr(addr, mc_addr)) {
 			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
+					       addr);
 			hns3_err(hw, "failed to add mc mac addr, same addrs"
 				 "(%s) is added by the set_mc_mac_addr_list "
 				 "API", mac_str);
-			return -EINVAL;
+			return true;
 		}
 	}
 
+	return false;
+}
+
+static int
+hns3_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
+{
+	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
+	int ret;
+
+	if (hns3_find_duplicate_mc_addr(hw, mac_addr))
+		return -EINVAL;
+
 	ret = hns3_add_mc_mac_addr(hw, mac_addr);
 	if (ret) {
 		hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index fa08fadc94..20999ce7ab 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -1048,6 +1048,10 @@ void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status,
 			  uint32_t link_speed, uint8_t link_duplex);
 void hns3_parse_devargs(struct rte_eth_dev *dev);
 void hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported);
+
+bool hns3_find_duplicate_mc_addr(struct hns3_hw *hw,
+				struct rte_ether_addr *mc_addr);
+
 int hns3_restore_ptp(struct hns3_adapter *hns);
 int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
 				    struct rte_eth_conf *conf);
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 8e5df05aa2..61489a537f 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -208,22 +208,10 @@ static int
 hns3vf_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
 {
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
-	struct rte_ether_addr *addr;
 	int ret;
-	int i;
 
-	for (i = 0; i < hw->mc_addrs_num; i++) {
-		addr = &hw->mc_addrs[i];
-		/* Check if there are duplicate addresses */
-		if (rte_is_same_ether_addr(addr, mac_addr)) {
-			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
-			hns3_err(hw, "failed to add mc mac addr, same addrs"
-				 "(%s) is added by the set_mc_mac_addr_list "
-				 "API", mac_str);
-			return -EINVAL;
-		}
-	}
+	if (hns3_find_duplicate_mc_addr(hw, mac_addr))
+		return -EINVAL;
 
 	ret = hns3vf_add_mc_mac_addr(hw, mac_addr);
 	if (ret) {
-- 
2.33.0


  parent reply	other threads:[~2021-10-22  9:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  9:19 [dpdk-dev] [PATCH 00/14] refactor MAC handling for hns3 PMD Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 01/14] net/hns3: rename adding multicast address function in PF Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 02/14] net/hns3: rename adding unicast " Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 03/14] net/hns3: rename removing multicast " Min Hu (Connor)
2021-10-22  9:19 ` Min Hu (Connor) [this message]
2021-10-22  9:19 ` [dpdk-dev] [PATCH 05/14] net/hns3: remove redundant adding multicast MAC interface Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 06/14] net/hns3: rename removing unicast address function in PF Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 07/14] net/hns3: remove redundant multicast operation interface Min Hu (Connor)
2021-10-22  9:19 ` [dpdk-dev] [PATCH 08/14] net/hns3: add hns3 HW ops structure to operate hardware Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 09/14] net/hns3: use APIs in hns3 HW ops to config MAC features Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 10/14] net/hns3: uniform to config all MAC and MC address Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 11/14] net/hns3: uniform adding and removing MAC address API Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 12/14] net/hns3: uniform common function to check multicast Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 13/14] net/hns3: refactor hns3 set MC MAC addr list API for PF Min Hu (Connor)
2021-10-22  9:20 ` [dpdk-dev] [PATCH 14/14] net/hns3: replace set MC MAC addr list API in VF Min Hu (Connor)
2021-11-01 17:45 ` [dpdk-dev] [PATCH 00/14] refactor MAC handling for hns3 PMD Ferruh Yigit

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=20211022092006.60959-5-humin29@huawei.com \
    --to=humin29@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=thomas@monjalon.net \
    /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).