X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fhns3%2Fhns3_ethdev_vf.c;h=675db44e854cb87cb1cf8758fb1818450a8ad326;hb=d6e5056ab38cfe0c27d7a7a631cdf259a7880111;hp=d3b082bd81847bc069c66f7ba6d6b0b896a3b847;hpb=3d491e5531a1d631f464ab31e139132d0e531198;p=dpdk.git diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index d3b082bd81..675db44e85 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -204,86 +204,6 @@ hns3vf_remove_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr) return ret; } -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]; - int ret; - - if (hns3_find_duplicate_mc_addr(hw, mac_addr)) - return -EINVAL; - - ret = hns3vf_add_mc_mac_addr(hw, mac_addr); - if (ret) { - hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, - mac_addr); - hns3_err(hw, "failed to add mc mac addr(%s), ret = %d", - mac_str, ret); - } - return ret; -} - -static int -hns3vf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, - __rte_unused uint32_t idx, - __rte_unused uint32_t pool) -{ - struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); - char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; - int ret; - - rte_spinlock_lock(&hw->lock); - - /* - * In hns3 network engine adding UC and MC mac address with different - * commands with firmware. We need to determine whether the input - * address is a UC or a MC address to call different commands. - * By the way, it is recommended calling the API function named - * rte_eth_dev_set_mc_addr_list to set the MC mac address, because - * using the rte_eth_dev_mac_addr_add API function to set MC mac address - * may affect the specifications of UC mac addresses. - */ - if (rte_is_multicast_ether_addr(mac_addr)) - ret = hns3vf_add_mc_addr_common(hw, mac_addr); - else - ret = hns3vf_add_uc_mac_addr(hw, mac_addr); - - rte_spinlock_unlock(&hw->lock); - if (ret) { - hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, - mac_addr); - hns3_err(hw, "failed to add mac addr(%s), ret = %d", mac_str, - ret); - } - - return ret; -} - -static void -hns3vf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx) -{ - struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); - /* index will be checked by upper level rte interface */ - struct rte_ether_addr *mac_addr = &dev->data->mac_addrs[idx]; - char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; - int ret; - - rte_spinlock_lock(&hw->lock); - - if (rte_is_multicast_ether_addr(mac_addr)) - ret = hns3vf_remove_mc_mac_addr(hw, mac_addr); - else - ret = hns3vf_remove_uc_mac_addr(hw, mac_addr); - - rte_spinlock_unlock(&hw->lock); - if (ret) { - hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, - mac_addr); - hns3_err(hw, "failed to remove mac addr(%s), ret = %d", - mac_str, ret); - } -} - static int hns3vf_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) @@ -337,39 +257,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) -{ - struct hns3_hw *hw = &hns->hw; - struct rte_ether_addr *addr; - char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; - 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 ? hns3vf_remove_mc_mac_addr(hw, addr) : - hns3vf_add_mc_mac_addr(hw, addr); - else - ret = del ? hns3vf_remove_uc_mac_addr(hw, addr) : - hns3vf_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) @@ -412,147 +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, - uint32_t nb_mc_addr) -{ - struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct rte_ether_addr *addr; - int cur_addr_num; - int set_addr_num; - int num; - int ret; - int i; - - ret = hns3vf_set_mc_addr_chk_param(hw, mc_addr_set, nb_mc_addr); - if (ret) - return ret; - - rte_spinlock_lock(&hw->lock); - cur_addr_num = hw->mc_addrs_num; - for (i = 0; i < cur_addr_num; i++) { - num = cur_addr_num - i - 1; - addr = &hw->mc_addrs[num]; - ret = hns3vf_remove_mc_mac_addr(hw, addr); - if (ret) { - rte_spinlock_unlock(&hw->lock); - return ret; - } - - hw->mc_addrs_num--; - } - - set_addr_num = (int)nb_mc_addr; - for (i = 0; i < set_addr_num; i++) { - addr = &mc_addr_set[i]; - ret = hns3vf_add_mc_mac_addr(hw, addr); - if (ret) { - rte_spinlock_unlock(&hw->lock); - return ret; - } - - rte_ether_addr_copy(addr, &hw->mc_addrs[hw->mc_addrs_num]); - hw->mc_addrs_num++; - } - rte_spinlock_unlock(&hw->lock); - - 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 = hns3vf_remove_mc_mac_addr(hw, addr); - else - ret = hns3vf_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) @@ -2061,7 +1807,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", @@ -2156,7 +1902,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); @@ -2585,7 +2331,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; @@ -2671,11 +2417,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; @@ -2716,9 +2462,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; } @@ -2881,10 +2627,10 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .txq_info_get = hns3_txq_info_get, .rx_burst_mode_get = hns3_rx_burst_mode_get, .tx_burst_mode_get = hns3_tx_burst_mode_get, - .mac_addr_add = hns3vf_add_mac_addr, - .mac_addr_remove = hns3vf_remove_mac_addr, + .mac_addr_add = hns3_add_mac_addr, + .mac_addr_remove = hns3_remove_mac_addr, .mac_addr_set = hns3vf_set_default_mac_addr, - .set_mc_addr_list = hns3vf_set_mc_mac_addr_list, + .set_mc_addr_list = hns3_set_mc_mac_addr_list, .link_update = hns3vf_dev_link_update, .rss_hash_update = hns3_dev_rss_hash_update, .rss_hash_conf_get = hns3_dev_rss_hash_conf_get, @@ -2908,6 +2654,15 @@ static const struct hns3_reset_ops hns3vf_reset_ops = { .start_service = hns3vf_start_service, }; +static void +hns3vf_init_hw_ops(struct hns3_hw *hw) +{ + hw->ops.add_mc_mac_addr = hns3vf_add_mc_mac_addr; + hw->ops.del_mc_mac_addr = hns3vf_remove_mc_mac_addr; + hw->ops.add_uc_mac_addr = hns3vf_add_uc_mac_addr; + hw->ops.del_uc_mac_addr = hns3vf_remove_uc_mac_addr; +} + static int hns3vf_dev_init(struct rte_eth_dev *eth_dev) { @@ -2952,6 +2707,7 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) goto err_init_reset; hw->reset.ops = &hns3vf_reset_ops; + hns3vf_init_hw_ops(hw); ret = hns3vf_init_vf(eth_dev); if (ret) { PMD_INIT_LOG(ERR, "Failed to init vf: %d", ret);