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)) {
- if (hns3_find_duplicate_mc_addr(hw, mac_addr)) {
- rte_spinlock_unlock(&hw->lock);
- return -EINVAL;
- }
- ret = hns3vf_add_mc_mac_addr(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)
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)
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)
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",
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);
* 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;
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;
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;
}
.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,