From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/I8LY0D
--------------------------------------------------------------------------
Extract linking check and unlinking check into 2 functions from check_bond_support() to improve readability.
Fixes: 6ba084e0f031 ("RDMA/hns: add constraints for bonding-unsupported situations") Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- drivers/infiniband/hw/hns/hns_roce_bond.c | 94 +++++++++++++++-------- 1 file changed, 60 insertions(+), 34 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_bond.c b/drivers/infiniband/hw/hns/hns_roce_bond.c index 849e2388d181..060b07bfeb3d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_bond.c +++ b/drivers/infiniband/hw/hns/hns_roce_bond.c @@ -783,18 +783,71 @@ static struct hns_roce_bond_group *hns_roce_alloc_bond_grp(struct hns_roce_dev * return bond_grp; }
+static bool is_dev_bond_supported(struct hns_roce_dev *hr_dev, int *bus_num) +{ + if (!hr_dev) + return false; + + if (hr_dev->is_vf || pci_num_vf(hr_dev->pci_dev) > 0) + return false; + + if (bus_num != get_hr_bus_num(hr_dev)) + return false; + + return true; +} + +static bool check_unlinking_bond_support(struct hns_roce_bond_group *bond_grp) +{ + struct net_device *net_dev; + u8 slave_num = 0; + + rcu_read_lock(); + for_each_netdev_in_bond_rcu(bond_grp->upper_dev, net_dev) { + if (get_netdev_bond_slave_id(net_dev, bond_grp) >= 0) + slave_num++; + } + rcu_read_unlock(); + + return (slave_num > 1); +} + +static bool check_linking_bond_support(struct netdev_lag_upper_info *bond_info, + struct net_device *upper_dev, + int bus_num) +{ + struct hns_roce_dev *hr_dev; + struct net_device *net_dev; + u8 slave_num = 0; + + if (!hns_roce_bond_mode_is_supported(bond_info->tx_type)) + return false; + + rcu_read_lock(); + for_each_netdev_in_bond_rcu(upper_dev, net_dev) { + hr_dev = hns_roce_get_hrdev_by_netdev(net_dev); + if (is_dev_bond_supported(hr_dev, bus_num)) { + slave_num++; + } else { + rcu_read_unlock(); + return false; + } + } + rcu_read_unlock(); + + return (slave_num > 1 && slave_num <= ROCE_BOND_FUNC_MAX); +} + static enum bond_support_type check_bond_support(struct hns_roce_dev *hr_dev, struct net_device **upper_dev, struct netdev_notifier_changeupper_info *info) { struct net_device *net_dev = get_hr_netdev(hr_dev, 0); - struct netdev_lag_upper_info *bond_upper_info = NULL; struct hns_roce_bond_group *bond_grp; int bus_num = get_hr_bus_num(hr_dev); bool bond_grp_exist = false; - bool support = true; - u8 slave_num = 0; + bool support;
*upper_dev = info->upper_dev; bond_grp = hns_roce_get_bond_grp(net_dev, bus_num); @@ -805,37 +858,10 @@ static enum bond_support_type return BOND_NOT_SUPPORT;
if (info->linking) - bond_upper_info = info->upper_info; - - if (bond_upper_info && - !hns_roce_bond_mode_is_supported(bond_upper_info->tx_type)) - return BOND_NOT_SUPPORT; - - bus_num = -1; - rcu_read_lock(); - for_each_netdev_in_bond_rcu(*upper_dev, net_dev) { - if (!info->linking && bond_grp_exist) { - if (get_netdev_bond_slave_id(net_dev, bond_grp) >= 0) - slave_num++; - } else { - hr_dev = hns_roce_get_hrdev_by_netdev(net_dev); - if (hr_dev) { - slave_num++; - if (bus_num == -1) - bus_num = get_hr_bus_num(hr_dev); - if (hr_dev->is_vf || - pci_num_vf(hr_dev->pci_dev) > 0 || - bus_num != get_hr_bus_num(hr_dev)) { - support = false; - break; - } - } - } - } - rcu_read_unlock(); - - if (slave_num <= 1 || slave_num > ROCE_BOND_FUNC_MAX) - support = false; + support = check_linking_bond_support(info->upper_info, + *upper_dev, bus_num); + else + support = check_unlinking_bond_support(bond_grp); if (support) return BOND_SUPPORT;