From patchwork Mon Jul 1 12:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13718040 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D48E146017; Mon, 1 Jul 2024 13:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719838813; cv=none; b=EGgCaHJxS+YpuWwpM5UPt3bvJn8NnDOfXSGJi2wj3UG5Td53OMVOgupEUk0UI/JCISyTZWaPSj8a3w1EfMeJ+VuqETP/BRsIFkL72rvzG9uVjVChKp6kT49L2tObF/vy4Rwemlp+XoFZ4uhaDNqTxzzZg/3wJu1x1rz4NdBJ0Jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719838813; c=relaxed/simple; bh=G/xOlPYe3vF5oKjhIB7GW4ffAy3SSJ2aL4UQN6CovZw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=bDn+4g1V5zs8cwY6+tm0tuBlUE/26OgM2QrwW7kUWgcliMwzi2ZzoYn75SYMp+2jLllYhzKJKb/0RfkdwUrRoNl+OuIk7rbpEFtaM2bdTX74kCa8hWnRL17jtZ9r43flpSZGD9BBSsezfufspIsYuXo/FsvNDyB8QZC5c+T1J7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=eRBolBwC; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="eRBolBwC" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 3B4B820B7004; Mon, 1 Jul 2024 06:00:05 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3B4B820B7004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719838805; bh=zzK5OuTFvzx/ju5sunPw2VL6Q836V9zKxrgDi0Ynufw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRBolBwCEfEP1Uao3huhzX7M3wgtQqVMefS3sT7f7Dy0uxkOz7zR63vNtGwI6DuCq Dj+OYf061lAyHMqXKTbDrYHd4xpJaf1hdw7zEdMXUIH9Tn0Eq3BxhP1ypbjbCXGw2+ Zq6IFAtp4G/DMWw2cvCqyLGEdhwOoz9Hg95DQhvQ= From: Konstantin Taranov To: kotaranov@microsoft.com, pabeni@redhat.com, haiyangz@microsoft.com, kys@microsoft.com, edumazet@google.com, kuba@kernel.org, davem@davemloft.net, decui@microsoft.com, wei.liu@kernel.org, sharmaajay@microsoft.com, longli@microsoft.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 1/2] net: mana: introduce helper to get a master netdev Date: Mon, 1 Jul 2024 05:58:55 -0700 Message-Id: <1719838736-20338-2-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1719838736-20338-1-git-send-email-kotaranov@linux.microsoft.com> References: <1719838736-20338-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Add helper to get a master netdevice for a given port. When mana is used with netvsc, the VF netdev is controlled by an upper netvsc device. In a baremetal case, the VF netdev is the master device. Signed-off-by: Konstantin Taranov --- drivers/net/ethernet/microsoft/mana/mana_en.c | 18 ++++++++++++++++++ include/net/mana/mana.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index d087cf9..b893339 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -2948,3 +2948,21 @@ out: gd->gdma_context = NULL; kfree(ac); } + +/* the caller should hold rcu_read_lock */ +struct net_device *mana_get_master_netdev_rcu(struct mana_context *ac, u32 port_index) +{ + struct net_device *ndev; + + if (port_index >= ac->num_ports) + return NULL; + + /* When mana is used in netvsc, the upper netdevice should be returned. */ + if (ac->ports[port_index]->flags & IFF_SLAVE) + ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]); + else + ndev = ac->ports[port_index]; + + return ndev; +} +EXPORT_SYMBOL_NS(mana_get_master_netdev_rcu, NET_MANA); diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 46f741e..2d3625c 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -797,4 +797,6 @@ void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type, int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id, u32 doorbell_pg_id); void mana_uncfg_vport(struct mana_port_context *apc); + +struct net_device *mana_get_master_netdev_rcu(struct mana_context *ac, u32 port_index); #endif /* _MANA_H */ From patchwork Mon Jul 1 12:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13718039 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D43F12A14C; Mon, 1 Jul 2024 13:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719838812; cv=none; b=ZAzVDfpHqAaTGmlnKP/xIgqCEjhhuLJXPLUM4BxQCO4kjSOqWJvhoLeM4Abf6RAIHS5qU/XhVzlcAw7zqPLBhiXG07SQvf7wB/XBhOUdjY071SelDhvZKqdNXUUB95UFst+wuelOLXVIT1B/onN5oO9rC7N/6vZfmHY2fVPa+f0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719838812; c=relaxed/simple; bh=fvg55UAyCbixNpWDhBwp70HzeuqTEa86y9ptiLaOTe0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=p8WYXBCDaJZMxT/rluHn7acePKHMEuBqz+7zAxdUjmcGcWr1xjp8wxeI1UNW214noSyvFl6GVT//wLUeP11KH/PK98fdhwf7B5P2I+KvdInsqYzaieafOK+ylxYqS2NJGaxZ3HhhorGBQrqw7yc2NAfAXLa5gAdSn2wizw9vjGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=YtxkMS04; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="YtxkMS04" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 5480620B7007; Mon, 1 Jul 2024 06:00:05 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5480620B7007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719838805; bh=L9t7pIPzPufTt4OieYYA15R2jzazJD091E+gG3PzcXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YtxkMS04czy92mDOIpdew7JTqIuD27Bt9N1CmgaVm7c8AquCuQf2g3AE6SjhD4OTD deDiQ3jrjTzSrpOCWlaj4lCjwo20U4lWRWFAbE/3VLt3WgcwgU0ZL7B2d3BtWUrHz0 SNyebq+itERDTDmYD69RRY+eF94deBCVdA3PhlRk= From: Konstantin Taranov To: kotaranov@microsoft.com, pabeni@redhat.com, haiyangz@microsoft.com, kys@microsoft.com, edumazet@google.com, kuba@kernel.org, davem@davemloft.net, decui@microsoft.com, wei.liu@kernel.org, sharmaajay@microsoft.com, longli@microsoft.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 2/2] RDMA/mana_ib: Set correct device into ib Date: Mon, 1 Jul 2024 05:58:56 -0700 Message-Id: <1719838736-20338-3-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1719838736-20338-1-git-send-email-kotaranov@linux.microsoft.com> References: <1719838736-20338-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Use the mana_get_master_netdev_rcu() helper to get a master netdevice for querying network states. The helper allows the mana_ib transparently support baremetal and netvsc deployment cases. Fixes: 8b184e4f1c32 ("RDMA/mana_ib: Enable RoCE on port 1") Signed-off-by: Konstantin Taranov Acked-by: Leon Romanovsky --- drivers/infiniband/hw/mana/device.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c index b07a8e2..ec849ac 100644 --- a/drivers/infiniband/hw/mana/device.c +++ b/drivers/infiniband/hw/mana/device.c @@ -56,7 +56,7 @@ static int mana_ib_probe(struct auxiliary_device *adev, { struct mana_adev *madev = container_of(adev, struct mana_adev, adev); struct gdma_dev *mdev = madev->mdev; - struct net_device *upper_ndev; + struct net_device *ndev; struct mana_context *mc; struct mana_ib_dev *dev; u8 mac_addr[ETH_ALEN]; @@ -84,17 +84,17 @@ static int mana_ib_probe(struct auxiliary_device *adev, dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues; dev->ib_dev.dev.parent = mdev->gdma_context->dev; - rcu_read_lock(); /* required to get upper dev */ - upper_ndev = netdev_master_upper_dev_get_rcu(mc->ports[0]); - if (!upper_ndev) { + rcu_read_lock(); /* required to get master dev */ + ndev = mana_get_master_netdev_rcu(mc, 0); + if (!ndev) { rcu_read_unlock(); ret = -ENODEV; - ibdev_err(&dev->ib_dev, "Failed to get master netdev"); + ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1"); goto free_ib_device; } - ether_addr_copy(mac_addr, upper_ndev->dev_addr); - addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, upper_ndev->dev_addr); - ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1); + ether_addr_copy(mac_addr, ndev->dev_addr); + addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr); + ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1); rcu_read_unlock(); if (ret) { ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);