From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7WHE3
--------------------------------------------------------------------------
Add 2 inline functions to obtain netdev and bus_num from an hr_dev to improve readability.
Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- drivers/infiniband/hw/hns/hns_roce_ah.c | 1 - drivers/infiniband/hw/hns/hns_roce_bond.c | 15 +++++++------- drivers/infiniband/hw/hns/hns_roce_device.h | 12 +++++++++++ drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- drivers/infiniband/hw/hns/hns_roce_main.c | 22 ++++++++++----------- drivers/infiniband/hw/hns/hns_roce_pd.c | 1 - drivers/infiniband/hw/hns/hns_roce_qp.c | 5 +++-- drivers/infiniband/hw/hns/hns_roce_srq.c | 1 - 8 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c index c92179da38bd..f4ceaeba5601 100644 --- a/drivers/infiniband/hw/hns/hns_roce_ah.c +++ b/drivers/infiniband/hw/hns/hns_roce_ah.c @@ -30,7 +30,6 @@ * SOFTWARE. */
-#include <linux/pci.h> #include <rdma/ib_addr.h> #include <rdma/ib_cache.h> #include "hnae3.h" diff --git a/drivers/infiniband/hw/hns/hns_roce_bond.c b/drivers/infiniband/hw/hns/hns_roce_bond.c index 95b8988ff72e..ec4da46b7ba3 100644 --- a/drivers/infiniband/hw/hns/hns_roce_bond.c +++ b/drivers/infiniband/hw/hns/hns_roce_bond.c @@ -3,7 +3,6 @@ * Copyright (c) 2022 Hisilicon Limited. */
-#include <linux/pci.h> #include "hnae3.h" #include "hns_roce_device.h" #include "hns_roce_hw_v2.h" @@ -64,7 +63,7 @@ static bool is_hrdev_bond_slave(struct hns_roce_dev *hr_dev, if (!netif_is_lag_master(upper_dev)) return false;
- if (upper_dev == get_upper_dev_from_ndev(hr_dev->iboe.netdevs[0])) + if (upper_dev == get_upper_dev_from_ndev(get_hr_netdev(hr_dev, 0))) return true;
bond_grp = hns_roce_get_bond_grp(hr_dev); @@ -77,7 +76,8 @@ static bool is_hrdev_bond_slave(struct hns_roce_dev *hr_dev, struct hns_roce_bond_group *hns_roce_get_bond_grp(struct hns_roce_dev *hr_dev) { struct hns_roce_die_info *die_info = - xa_load(&roce_bond_xa, hr_dev->pci_dev->bus->number); + xa_load(&roce_bond_xa, get_hr_bus_num(hr_dev)); + struct net_device *net_dev = get_hr_netdev(hr_dev, 0); struct hns_roce_bond_group *bond_grp; int i;
@@ -88,9 +88,8 @@ struct hns_roce_bond_group *hns_roce_get_bond_grp(struct hns_roce_dev *hr_dev) bond_grp = die_info->bgrps[i]; if (!bond_grp) continue; - if (is_netdev_bond_slave(hr_dev->iboe.netdevs[0], bond_grp) || - bond_grp->upper_dev == - get_upper_dev_from_ndev(hr_dev->iboe.netdevs[0])) + if (is_netdev_bond_slave(net_dev, bond_grp) || + (bond_grp->upper_dev == get_upper_dev_from_ndev(net_dev))) return bond_grp; }
@@ -697,10 +696,10 @@ static enum bond_support_type if (hr_dev) { slave_num++; if (bus_num == -1) - bus_num = hr_dev->pci_dev->bus->number; + bus_num = get_hr_bus_num(hr_dev); if (hr_dev->is_vf || pci_num_vf(hr_dev->pci_dev) > 0 || - bus_num != hr_dev->pci_dev->bus->number) { + bus_num != get_hr_bus_num(hr_dev)) { support = false; break; } diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 6df342ae34e3..bd07775f0856 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -33,6 +33,7 @@ #ifndef _HNS_ROCE_DEVICE_H #define _HNS_ROCE_DEVICE_H
+#include <linux/pci.h> #include <rdma/ib_verbs.h> #include <rdma/hns-abi.h> #include "hns_roce_bond.h" @@ -1269,6 +1270,17 @@ static inline enum ib_port_state get_port_state(struct net_device *net_dev) IB_PORT_ACTIVE : IB_PORT_DOWN; }
+static inline struct net_device *get_hr_netdev(struct hns_roce_dev *hr_dev, + u8 port) +{ + return hr_dev->iboe.netdevs[port]; +} + +static inline u8 get_hr_bus_num(struct hns_roce_dev *hr_dev) +{ + return hr_dev->pci_dev->bus->number; +} + void hns_roce_init_uar_table(struct hns_roce_dev *dev); int hns_roce_uar_alloc(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 10488d1f9beb..1dadb7a3031c 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -7526,7 +7526,7 @@ static void hns_roce_hw_v2_link_status_change(struct hnae3_handle *handle, return;
for (phy_port = 0; phy_port < hr_dev->caps.num_ports; phy_port++) - if (netdev == hr_dev->iboe.netdevs[phy_port]) + if (netdev == get_hr_netdev(hr_dev, phy_port)) break;
if (phy_port == hr_dev->caps.num_ports) diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 1dc747454e00..8f60395be9f7 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -32,7 +32,6 @@ */ #include <linux/acpi.h> #include <linux/module.h> -#include <linux/pci.h> #include <rdma/ib_addr.h> #include <rdma/ib_smi.h> #include <rdma/ib_user_verbs.h> @@ -61,7 +60,7 @@ static struct net_device *hns_roce_get_netdev(struct ib_device *ib_dev, rcu_read_lock();
if (!ndev) - ndev = hr_dev->iboe.netdevs[port_num - 1]; + ndev = get_hr_netdev(hr_dev, port_num - 1);
if (ndev) dev_hold(ndev); @@ -217,14 +216,14 @@ static int hns_roce_netdev_event(struct notifier_block *self,
static int hns_roce_setup_mtu_mac(struct hns_roce_dev *hr_dev) { + struct net_device *net_dev; int ret; u8 i;
for (i = 0; i < hr_dev->caps.num_ports; i++) { hr_dev->iboe.port_state[i] = IB_PORT_DOWN; - - ret = hns_roce_set_mac(hr_dev, i, - hr_dev->iboe.netdevs[i]->dev_addr); + net_dev = get_hr_netdev(hr_dev, i); + ret = hns_roce_set_mac(hr_dev, i, net_dev->dev_addr); if (ret) return ret; } @@ -310,7 +309,7 @@ static int hns_roce_query_port(struct ib_device *ib_dev, u8 port_num,
net_dev = hr_dev->hw->get_bond_netdev(hr_dev); if (!net_dev) - net_dev = hr_dev->iboe.netdevs[port]; + net_dev = get_hr_netdev(hr_dev, port); if (!net_dev) { spin_unlock_irqrestore(&hr_dev->iboe.lock, flags); dev_err(dev, "Find netdev %u failed!\n", port); @@ -961,11 +960,12 @@ static const struct ib_device_ops hns_roce_dev_restrack_ops = {
static int hns_roce_register_device(struct hns_roce_dev *hr_dev) { - int ret; struct hns_roce_ib_iboe *iboe = NULL; - struct ib_device *ib_dev = NULL; struct device *dev = hr_dev->dev; + struct ib_device *ib_dev = NULL; + struct net_device *net_dev; unsigned int i; + int ret;
iboe = &hr_dev->iboe; spin_lock_init(&iboe->lock); @@ -1049,11 +1049,11 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev) ib_dev->driver_def = hns_roce_uapi_defs;
for (i = 0; i < hr_dev->caps.num_ports; i++) { - if (!hr_dev->iboe.netdevs[i]) + net_dev = get_hr_netdev(hr_dev, i); + if (!net_dev) continue;
- ret = ib_device_set_netdev(ib_dev, hr_dev->iboe.netdevs[i], - i + 1); + ret = ib_device_set_netdev(ib_dev, net_dev, i + 1); if (ret) return ret; } diff --git a/drivers/infiniband/hw/hns/hns_roce_pd.c b/drivers/infiniband/hw/hns/hns_roce_pd.c index 7399963dc294..6c69e095aa01 100644 --- a/drivers/infiniband/hw/hns/hns_roce_pd.c +++ b/drivers/infiniband/hw/hns/hns_roce_pd.c @@ -30,7 +30,6 @@ * SOFTWARE. */
-#include <linux/pci.h> #include "hns_roce_device.h"
void hns_roce_init_pd_table(struct hns_roce_dev *hr_dev) diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index 4d0c9332f896..00f82f4b19f6 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -31,7 +31,6 @@ * SOFTWARE. */
-#include <linux/pci.h> #include <rdma/ib_addr.h> #include <rdma/ib_umem.h> #include <rdma/uverbs_ioctl.h> @@ -1410,11 +1409,13 @@ static int check_mtu_validate(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, struct ib_qp_attr *attr, int attr_mask) { + struct net_device *net_dev; enum ib_mtu active_mtu; int p;
p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port; - active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu); + net_dev = get_hr_netdev(hr_dev, p); + active_mtu = iboe_get_mtu(net_dev->mtu);
if ((hr_dev->caps.max_mtu >= IB_MTU_2048 && attr->path_mtu > hr_dev->caps.max_mtu) || diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c index 320aaa24be01..511e0f79e9d7 100644 --- a/drivers/infiniband/hw/hns/hns_roce_srq.c +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c @@ -3,7 +3,6 @@ * Copyright (c) 2018 Hisilicon Limited. */
-#include <linux/pci.h> #include <rdma/ib_umem.h> #include "hns_roce_device.h" #include "hns_roce_cmd.h"