X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fhns3%2Fhns3_ethdev_vf.c;h=675db44e854cb87cb1cf8758fb1818450a8ad326;hb=d6e5056ab38cfe0c27d7a7a631cdf259a7880111;hp=c0c1f1c4c1071c06b2762b864e5ee8ee1cc2cb20;hpb=295968d1740760337e16b0d7914875c5cac52850;p=dpdk.git diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index c0c1f1c4c1..675db44e85 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -204,98 +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]; - struct rte_ether_addr *addr; - int ret; - int i; - - for (i = 0; i < hw->mc_addrs_num; i++) { - addr = &hw->mc_addrs[i]; - /* Check if there are duplicate addresses */ - if (rte_is_same_ether_addr(addr, mac_addr)) { - hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, - addr); - hns3_err(hw, "failed to add mc mac addr, same addrs" - "(%s) is added by the set_mc_mac_addr_list " - "API", mac_str); - 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) @@ -349,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) @@ -424,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) @@ -1956,7 +1690,7 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev) hns3vf_clear_event_cause(hw, 0); - ret = rte_intr_callback_register(&pci_dev->intr_handle, + ret = rte_intr_callback_register(pci_dev->intr_handle, hns3vf_interrupt_handler, eth_dev); if (ret) { PMD_INIT_LOG(ERR, "Failed to register intr: %d", ret); @@ -1964,7 +1698,7 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev) } /* Enable interrupt */ - rte_intr_enable(&pci_dev->intr_handle); + rte_intr_enable(pci_dev->intr_handle); hns3vf_enable_irq0(hw); /* Get configuration from PF */ @@ -2016,8 +1750,8 @@ err_set_tc_queue: err_get_config: hns3vf_disable_irq0(hw); - rte_intr_disable(&pci_dev->intr_handle); - hns3_intr_unregister(&pci_dev->intr_handle, hns3vf_interrupt_handler, + rte_intr_disable(pci_dev->intr_handle); + hns3_intr_unregister(pci_dev->intr_handle, hns3vf_interrupt_handler, eth_dev); err_intr_callback_register: err_cmd_init: @@ -2045,8 +1779,8 @@ hns3vf_uninit_vf(struct rte_eth_dev *eth_dev) hns3_flow_uninit(eth_dev); hns3_tqp_stats_uninit(hw); hns3vf_disable_irq0(hw); - rte_intr_disable(&pci_dev->intr_handle); - hns3_intr_unregister(&pci_dev->intr_handle, hns3vf_interrupt_handler, + rte_intr_disable(pci_dev->intr_handle); + hns3_intr_unregister(pci_dev->intr_handle, hns3vf_interrupt_handler, eth_dev); hns3_cmd_uninit(hw); hns3_cmd_destroy_queue(hw); @@ -2073,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", @@ -2089,7 +1823,7 @@ hns3vf_unmap_rx_interrupt(struct rte_eth_dev *dev) { struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; uint8_t base = RTE_INTR_VEC_ZERO_OFFSET; uint8_t vec = RTE_INTR_VEC_ZERO_OFFSET; uint16_t q_id; @@ -2107,16 +1841,16 @@ hns3vf_unmap_rx_interrupt(struct rte_eth_dev *dev) (void)hns3vf_bind_ring_with_vector(hw, vec, false, HNS3_RING_TYPE_RX, q_id); - if (vec < base + intr_handle->nb_efd - 1) + if (vec < base + rte_intr_nb_efd_get(intr_handle) + - 1) vec++; } } /* Clean datapath event and queue/vec mapping */ rte_intr_efd_disable(intr_handle); - if (intr_handle->intr_vec) { - rte_free(intr_handle->intr_vec); - intr_handle->intr_vec = NULL; - } + + /* Cleanup vector list */ + rte_intr_vec_list_free(intr_handle); } static int @@ -2168,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); @@ -2272,7 +2006,7 @@ static int hns3vf_map_rx_interrupt(struct rte_eth_dev *dev) { struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); uint8_t base = RTE_INTR_VEC_ZERO_OFFSET; uint8_t vec = RTE_INTR_VEC_ZERO_OFFSET; @@ -2295,16 +2029,13 @@ hns3vf_map_rx_interrupt(struct rte_eth_dev *dev) if (rte_intr_efd_enable(intr_handle, intr_vector)) return -EINVAL; - if (intr_handle->intr_vec == NULL) { - intr_handle->intr_vec = - rte_zmalloc("intr_vec", - hw->used_rx_queues * sizeof(int), 0); - if (intr_handle->intr_vec == NULL) { - hns3_err(hw, "Failed to allocate %u rx_queues" - " intr_vec", hw->used_rx_queues); - ret = -ENOMEM; - goto vf_alloc_intr_vec_error; - } + /* Allocate vector list */ + if (rte_intr_vec_list_alloc(intr_handle, "intr_vec", + hw->used_rx_queues)) { + hns3_err(hw, "Failed to allocate %u rx_queues" + " intr_vec", hw->used_rx_queues); + ret = -ENOMEM; + goto vf_alloc_intr_vec_error; } if (rte_intr_allow_others(intr_handle)) { @@ -2317,20 +2048,22 @@ hns3vf_map_rx_interrupt(struct rte_eth_dev *dev) HNS3_RING_TYPE_RX, q_id); if (ret) goto vf_bind_vector_error; - intr_handle->intr_vec[q_id] = vec; + + if (rte_intr_vec_list_index_set(intr_handle, q_id, vec)) + goto vf_bind_vector_error; + /* * If there are not enough efds (e.g. not enough interrupt), * remaining queues will be bond to the last interrupt. */ - if (vec < base + intr_handle->nb_efd - 1) + if (vec < base + rte_intr_nb_efd_get(intr_handle) - 1) vec++; } rte_intr_enable(intr_handle); return 0; vf_bind_vector_error: - rte_free(intr_handle->intr_vec); - intr_handle->intr_vec = NULL; + rte_intr_vec_list_free(intr_handle); vf_alloc_intr_vec_error: rte_intr_efd_disable(intr_handle); return ret; @@ -2341,7 +2074,7 @@ hns3vf_restore_rx_interrupt(struct hns3_hw *hw) { struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id]; struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; uint16_t q_id; int ret; @@ -2351,8 +2084,9 @@ hns3vf_restore_rx_interrupt(struct hns3_hw *hw) if (rte_intr_dp_is_en(intr_handle)) { for (q_id = 0; q_id < hw->used_rx_queues; q_id++) { ret = hns3vf_bind_ring_with_vector(hw, - intr_handle->intr_vec[q_id], true, - HNS3_RING_TYPE_RX, q_id); + rte_intr_vec_list_index_get(intr_handle, + q_id), + true, HNS3_RING_TYPE_RX, q_id); if (ret) return ret; } @@ -2597,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; @@ -2683,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; @@ -2728,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; } @@ -2816,7 +2550,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns) int ret; if (hw->reset.level == HNS3_VF_FULL_RESET) { - rte_intr_disable(&pci_dev->intr_handle); + rte_intr_disable(pci_dev->intr_handle); ret = hns3vf_set_bus_master(pci_dev, true); if (ret < 0) { hns3_err(hw, "failed to set pci bus, ret = %d", ret); @@ -2842,7 +2576,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns) hns3_err(hw, "Failed to enable msix"); } - rte_intr_enable(&pci_dev->intr_handle); + rte_intr_enable(pci_dev->intr_handle); } ret = hns3_reset_all_tqps(hns); @@ -2893,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, @@ -2920,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) { @@ -2964,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);