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 10/14] net/hns3: uniform to config all MAC and MC address
Date: Fri, 22 Oct 2021 17:20:01 +0800	[thread overview]
Message-ID: <20211022092006.60959-11-humin29@huawei.com> (raw)
In-Reply-To: <20211022092006.60959-1-humin29@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

Currently, the interface logic for adding and deleting all MAC address and
multicast address in PF and VF driver is the same. This patch extracts two
common interfaces to configure them separately.

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

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index dcdbb962eb..0431091f49 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -1790,17 +1790,20 @@ hns3_set_default_mac_addr(struct rte_eth_dev *dev,
 	return ret;
 }
 
-static int
+int
 hns3_configure_all_mac_addr(struct hns3_adapter *hns, bool del)
 {
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
 	struct hns3_hw *hw = &hns->hw;
+	struct hns3_hw_ops *ops = &hw->ops;
 	struct rte_ether_addr *addr;
-	int err = 0;
-	int ret;
+	uint16_t mac_addrs_capa;
+	int ret = 0;
 	int i;
 
-	for (i = 0; i < HNS3_UC_MACADDR_NUM; i++) {
+	mac_addrs_capa =
+		hns->is_vf ? HNS3_VF_UC_MACADDR_NUM : HNS3_UC_MACADDR_NUM;
+	for (i = 0; i < mac_addrs_capa; i++) {
 		addr = &hw->data->mac_addrs[i];
 		if (rte_is_zero_ether_addr(addr))
 			continue;
@@ -1812,15 +1815,14 @@ hns3_configure_all_mac_addr(struct hns3_adapter *hns, bool del)
 			      ops->add_uc_mac_addr(hw, addr);
 
 		if (ret) {
-			err = ret;
 			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
-			hns3_err(hw, "failed to %s mac addr(%s) index:%d "
-				 "ret = %d.", del ? "remove" : "restore",
-				 mac_str, i, ret);
+					       addr);
+			hns3_err(hw, "failed to %s mac addr(%s) index:%d ret = %d.",
+				 del ? "remove" : "restore", mac_str, i, ret);
 		}
 	}
-	return err;
+
+	return ret;
 }
 
 static void
@@ -2151,14 +2153,13 @@ hns3_set_mc_mac_addr_list(struct rte_eth_dev *dev,
 	return 0;
 }
 
-static int
+int
 hns3_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del)
 {
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
 	struct hns3_hw *hw = &hns->hw;
 	struct rte_ether_addr *addr;
-	int err = 0;
-	int ret;
+	int ret = 0;
 	int i;
 
 	for (i = 0; i < hw->mc_addrs_num; i++) {
@@ -2170,14 +2171,13 @@ hns3_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del)
 		else
 			ret = hw->ops.add_mc_mac_addr(hw, addr);
 		if (ret) {
-			err = ret;
 			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
 					      addr);
-			hns3_dbg(hw, "%s mc mac addr: %s failed for pf: ret = %d",
+			hns3_dbg(hw, "failed to %s mc mac addr: %s ret = %d",
 				 del ? "Remove" : "Restore", mac_str, ret);
 		}
 	}
-	return err;
+	return ret;
 }
 
 static int
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index 9d0a060720..0a58db5bc6 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -1064,6 +1064,8 @@ 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_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del);
+int hns3_configure_all_mac_addr(struct hns3_adapter *hns, bool del);
 
 int hns3_restore_ptp(struct hns3_adapter *hns);
 int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 616b3ed6db..7034434530 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -323,40 +323,6 @@ hns3vf_set_default_mac_addr(struct rte_eth_dev *dev,
 	return ret;
 }
 
-static int
-hns3vf_configure_mac_addr(struct hns3_adapter *hns, bool del)
-{
-	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
-	struct hns3_hw *hw = &hns->hw;
-	struct hns3_hw_ops *ops = &hw->ops;
-	struct rte_ether_addr *addr;
-	int err = 0;
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_VF_UC_MACADDR_NUM; i++) {
-		addr = &hw->data->mac_addrs[i];
-		if (rte_is_zero_ether_addr(addr))
-			continue;
-		if (rte_is_multicast_ether_addr(addr))
-			ret = del ? ops->del_mc_mac_addr(hw, addr) :
-			      ops->add_mc_mac_addr(hw, addr);
-		else
-			ret = del ? ops->del_uc_mac_addr(hw, addr) :
-			      ops->add_uc_mac_addr(hw, addr);
-
-		if (ret) {
-			err = ret;
-			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
-			hns3_err(hw, "failed to %s mac addr(%s) index:%d "
-				 "ret = %d.", del ? "remove" : "restore",
-				 mac_str, i, ret);
-		}
-	}
-	return err;
-}
-
 static int
 hns3vf_add_mc_mac_addr(struct hns3_hw *hw,
 		       struct rte_ether_addr *mac_addr)
@@ -511,35 +477,6 @@ hns3vf_set_mc_mac_addr_list(struct rte_eth_dev *dev,
 	return 0;
 }
 
-static int
-hns3vf_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del)
-{
-	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
-	struct hns3_hw *hw = &hns->hw;
-	struct rte_ether_addr *addr;
-	int err = 0;
-	int ret;
-	int i;
-
-	for (i = 0; i < hw->mc_addrs_num; i++) {
-		addr = &hw->mc_addrs[i];
-		if (!rte_is_multicast_ether_addr(addr))
-			continue;
-		if (del)
-			ret = hw->ops.del_mc_mac_addr(hw, addr);
-		else
-			ret = hw->ops.add_mc_mac_addr(hw, addr);
-		if (ret) {
-			err = ret;
-			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
-			hns3_err(hw, "Failed to %s mc mac addr: %s for vf: %d",
-				 del ? "Remove" : "Restore", mac_str, ret);
-		}
-	}
-	return err;
-}
-
 static int
 hns3vf_set_promisc_mode(struct hns3_hw *hw, bool en_bc_pmc,
 			bool en_uc_pmc, bool en_mc_pmc)
@@ -2048,7 +1985,7 @@ hns3vf_do_stop(struct hns3_adapter *hns)
 		hns3_dev_release_mbufs(hns);
 
 	if (__atomic_load_n(&hw->reset.disable_cmd, __ATOMIC_RELAXED) == 0) {
-		hns3vf_configure_mac_addr(hns, true);
+		hns3_configure_all_mac_addr(hns, true);
 		ret = hns3_reset_all_tqps(hns);
 		if (ret) {
 			hns3_err(hw, "failed to reset all queues ret = %d",
@@ -2143,7 +2080,7 @@ hns3vf_dev_close(struct rte_eth_dev *eth_dev)
 	hns3_reset_abort(hns);
 	hw->adapter_state = HNS3_NIC_CLOSED;
 	rte_eal_alarm_cancel(hns3vf_keep_alive_handler, eth_dev);
-	hns3vf_configure_all_mc_mac_addr(hns, true);
+	hns3_configure_all_mc_mac_addr(hns, true);
 	hns3vf_remove_all_vlan_table(hns);
 	hns3vf_uninit_vf(eth_dev);
 	hns3_free_all_queues(eth_dev);
@@ -2572,7 +2509,7 @@ hns3vf_stop_service(struct hns3_adapter *hns)
 	 * required to delete the entries.
 	 */
 	if (__atomic_load_n(&hw->reset.disable_cmd, __ATOMIC_RELAXED) == 0)
-		hns3vf_configure_all_mc_mac_addr(hns, true);
+		hns3_configure_all_mc_mac_addr(hns, true);
 	rte_spinlock_unlock(&hw->lock);
 
 	return 0;
@@ -2658,11 +2595,11 @@ hns3vf_restore_conf(struct hns3_adapter *hns)
 	if (ret)
 		return ret;
 
-	ret = hns3vf_configure_mac_addr(hns, false);
+	ret = hns3_configure_all_mac_addr(hns, false);
 	if (ret)
 		return ret;
 
-	ret = hns3vf_configure_all_mc_mac_addr(hns, false);
+	ret = hns3_configure_all_mc_mac_addr(hns, false);
 	if (ret)
 		goto err_mc_mac;
 
@@ -2703,9 +2640,9 @@ hns3vf_restore_conf(struct hns3_adapter *hns)
 	return 0;
 
 err_vlan_table:
-	hns3vf_configure_all_mc_mac_addr(hns, true);
+	hns3_configure_all_mc_mac_addr(hns, true);
 err_mc_mac:
-	hns3vf_configure_mac_addr(hns, true);
+	hns3_configure_all_mac_addr(hns, true);
 	return ret;
 }
 
-- 
2.33.0


  parent reply	other threads:[~2021-10-22  9:23 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 ` [dpdk-dev] [PATCH 04/14] net/hns3: extract a common interface to check duplicates Min Hu (Connor)
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 ` Min Hu (Connor) [this message]
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-11-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).