]> git.droids-corp.org - dpdk.git/commitdiff
net/hns3: unify MAC address add and remove
authorHuisong Li <lihuisong@huawei.com>
Fri, 22 Oct 2021 09:20:02 +0000 (17:20 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 1 Nov 2021 17:31:07 +0000 (18:31 +0100)
The code logic of adding and removing MAC address in PF and VF is the
same.
This patch extracts two common interfaces to add and remove them
separately.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
drivers/net/hns3/hns3_ethdev.c
drivers/net/hns3/hns3_ethdev.h
drivers/net/hns3/hns3_ethdev_vf.c

index 7dcc701b1c89caa03944dca1395dc36405b00648..9ace36531fbb56a1eb16ccbcefe7275da854568a 100644 (file)
@@ -1609,7 +1609,7 @@ hns3_add_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
        return ret;
 }
 
-bool
+static bool
 hns3_find_duplicate_mc_addr(struct hns3_hw *hw, struct rte_ether_addr *mc_addr)
 {
        char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
@@ -1632,7 +1632,7 @@ hns3_find_duplicate_mc_addr(struct hns3_hw *hw, struct rte_ether_addr *mc_addr)
        return false;
 }
 
-static int
+int
 hns3_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
                  __rte_unused uint32_t idx, __rte_unused uint32_t pool)
 {
@@ -1660,17 +1660,14 @@ hns3_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
        } else {
                ret = hw->ops.add_uc_mac_addr(hw, mac_addr);
        }
+       rte_spinlock_unlock(&hw->lock);
        if (ret) {
-               rte_spinlock_unlock(&hw->lock);
                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;
        }
 
-       rte_spinlock_unlock(&hw->lock);
-
        return ret;
 }
 
@@ -1702,7 +1699,7 @@ hns3_remove_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
        return ret;
 }
 
-static void
+void
 hns3_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 a07de6b6413084a409a97bd80791060353573807..1b6092a146ac8f707b964525f65063c85a283289 100644 (file)
@@ -1062,10 +1062,11 @@ void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status,
 void hns3_parse_devargs(struct rte_eth_dev *dev);
 void hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported);
 
-bool hns3_find_duplicate_mc_addr(struct hns3_hw *hw,
-                               struct rte_ether_addr *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,
+               __rte_unused uint32_t idx, __rte_unused uint32_t pool);
+void hns3_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx);
 
 int hns3_restore_ptp(struct hns3_adapter *hns);
 int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
index 6af55f439746893b54a766388babb9e53342e86d..b48175077556ebc3e3a59bc2618e9ee3f3d39ef8 100644 (file)
@@ -204,72 +204,6 @@ hns3vf_remove_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
        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 = hw->ops.add_mc_mac_addr(hw, mac_addr);
-       } else {
-               ret = hw->ops.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 = hw->ops.del_mc_mac_addr(hw, mac_addr);
-       else
-               ret = hw->ops.del_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)
@@ -2805,8 +2739,8 @@ 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,
        .link_update        = hns3vf_dev_link_update,