diff mbox series

[12/14] net/hns3: uniform common function to check multicast

Message ID 20211022092006.60959-13-humin29@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series refactor MAC handling for hns3 PMD | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

humin (Q) Oct. 22, 2021, 9:20 a.m. UTC
From: Huisong Li <lihuisong@huawei.com>

This patch uniforms a common function to check multicast address validity
for PF and VF.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    | 12 ++++--
 drivers/net/hns3/hns3_ethdev.h    |  4 +-
 drivers/net/hns3/hns3_ethdev_vf.c | 66 +------------------------------
 3 files changed, 12 insertions(+), 70 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index a52cede528..af956854b1 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -1947,13 +1947,15 @@  hns3_remove_mc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
 	return ret;
 }
 
-static int
+int
 hns3_set_mc_addr_chk_param(struct hns3_hw *hw,
 			   struct rte_ether_addr *mc_addr_set,
 			   uint32_t nb_mc_addr)
 {
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
 	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
 	struct rte_ether_addr *addr;
+	uint16_t mac_addrs_capa;
 	uint32_t i;
 	uint32_t j;
 
@@ -1993,12 +1995,14 @@  hns3_set_mc_addr_chk_param(struct hns3_hw *hw,
 		 * Check if there are duplicate addresses between mac_addrs
 		 * and mc_addr_set
 		 */
-		for (j = 0; j < HNS3_UC_MACADDR_NUM; j++) {
+		mac_addrs_capa = hns->is_vf ? HNS3_VF_UC_MACADDR_NUM :
+					      HNS3_UC_MACADDR_NUM;
+		for (j = 0; j < mac_addrs_capa; j++) {
 			if (rte_is_same_ether_addr(addr,
 						   &hw->data->mac_addrs[j])) {
 				hns3_ether_format_addr(mac_str,
-						      RTE_ETHER_ADDR_FMT_SIZE,
-						      addr);
+						       RTE_ETHER_ADDR_FMT_SIZE,
+						       addr);
 				hns3_err(hw, "failed to set mc mac addr, "
 					 "addrs invalid. addrs(%s) has already "
 					 "configured in mac_addr add API",
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index c5b9c17002..762f03124f 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -1061,7 +1061,9 @@  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);
-
+int hns3_set_mc_addr_chk_param(struct hns3_hw *hw,
+			struct rte_ether_addr *mc_addr_set,
+			uint32_t nb_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_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 25300b23fc..484ff24145 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -299,70 +299,6 @@  hns3vf_remove_mc_mac_addr(struct hns3_hw *hw,
 	return ret;
 }
 
-static int
-hns3vf_set_mc_addr_chk_param(struct hns3_hw *hw,
-			     struct rte_ether_addr *mc_addr_set,
-			     uint32_t nb_mc_addr)
-{
-	char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
-	struct rte_ether_addr *addr;
-	uint32_t i;
-	uint32_t j;
-
-	if (nb_mc_addr > HNS3_MC_MACADDR_NUM) {
-		hns3_err(hw, "failed to set mc mac addr, nb_mc_addr(%u) "
-			 "invalid. valid range: 0~%d",
-			 nb_mc_addr, HNS3_MC_MACADDR_NUM);
-		return -EINVAL;
-	}
-
-	/* Check if input mac addresses are valid */
-	for (i = 0; i < nb_mc_addr; i++) {
-		addr = &mc_addr_set[i];
-		if (!rte_is_multicast_ether_addr(addr)) {
-			hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
-					      addr);
-			hns3_err(hw,
-				 "failed to set mc mac addr, addr(%s) invalid.",
-				 mac_str);
-			return -EINVAL;
-		}
-
-		/* Check if there are duplicate addresses */
-		for (j = i + 1; j < nb_mc_addr; j++) {
-			if (rte_is_same_ether_addr(addr, &mc_addr_set[j])) {
-				hns3_ether_format_addr(mac_str,
-						      RTE_ETHER_ADDR_FMT_SIZE,
-						      addr);
-				hns3_err(hw, "failed to set mc mac addr, "
-					 "addrs invalid. two same addrs(%s).",
-					 mac_str);
-				return -EINVAL;
-			}
-		}
-
-		/*
-		 * Check if there are duplicate addresses between mac_addrs
-		 * and mc_addr_set
-		 */
-		for (j = 0; j < HNS3_VF_UC_MACADDR_NUM; j++) {
-			if (rte_is_same_ether_addr(addr,
-						   &hw->data->mac_addrs[j])) {
-				hns3_ether_format_addr(mac_str,
-						      RTE_ETHER_ADDR_FMT_SIZE,
-						      addr);
-				hns3_err(hw, "failed to set mc mac addr, "
-					 "addrs invalid. addrs(%s) has already "
-					 "configured in mac_addr add API",
-					 mac_str);
-				return -EINVAL;
-			}
-		}
-	}
-
-	return 0;
-}
-
 static int
 hns3vf_set_mc_mac_addr_list(struct rte_eth_dev *dev,
 			    struct rte_ether_addr *mc_addr_set,
@@ -376,7 +312,7 @@  hns3vf_set_mc_mac_addr_list(struct rte_eth_dev *dev,
 	int ret;
 	int i;
 
-	ret = hns3vf_set_mc_addr_chk_param(hw, mc_addr_set, nb_mc_addr);
+	ret = hns3_set_mc_addr_chk_param(hw, mc_addr_set, nb_mc_addr);
 	if (ret)
 		return ret;