net/hns3: unify multicast address check

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>
This commit is contained in:
Huisong Li 2021-10-22 17:20:03 +08:00 committed by Ferruh Yigit
parent f634872542
commit 5022ab5cab
3 changed files with 12 additions and 70 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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;