Commit 71c7611c authored by Junxian Huang's avatar Junxian Huang Committed by ZhouJuan
Browse files

RDMA/hns: Add functions to obtain netdev and bus_num from an hr_dev

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: default avatarJunxian Huang <huangjunxian6@hisilicon.com>
parent ff235b9c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
 * SOFTWARE.
 */

#include <linux/pci.h>
#include <rdma/ib_addr.h>
#include <rdma/ib_cache.h>
#include "hnae3.h"
+7 −8
Original line number Diff line number Diff line
@@ -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;
				}
+12 −0
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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)
+11 −11
Original line number Diff line number Diff line
@@ -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;
	}
Loading