diff mbox series

[rdma-next,v3,4/6] RDMA/mana_ib: enable RoCE on port 1

Message ID 1712738551-22075-5-git-send-email-kotaranov@linux.microsoft.com (mailing list archive)
State Accepted
Headers show
Series RDMA/mana_ib: Enable RNIC adapter and populate it with GIDs | expand

Commit Message

Konstantin Taranov April 10, 2024, 8:42 a.m. UTC
From: Konstantin Taranov <kotaranov@microsoft.com>

Set netdev and RoCEv2 flag to enable GID population on port 1.
Use GIDs of the master netdev. As mc->ports[] stores slave devices,
use a helper to get the master netdev.

Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
---
 drivers/infiniband/hw/mana/device.c | 15 +++++++++++++++
 drivers/infiniband/hw/mana/main.c   | 15 +++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

Comments

Nathan Chancellor April 22, 2024, 7:37 p.m. UTC | #1
Hi Konstantin,

On Wed, Apr 10, 2024 at 01:42:29AM -0700, Konstantin Taranov wrote:
> From: Konstantin Taranov <kotaranov@microsoft.com>
> 
> Set netdev and RoCEv2 flag to enable GID population on port 1.
> Use GIDs of the master netdev. As mc->ports[] stores slave devices,
> use a helper to get the master netdev.
> 
> Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
> ---
>  drivers/infiniband/hw/mana/device.c | 15 +++++++++++++++
>  drivers/infiniband/hw/mana/main.c   | 15 +++++++++++----
>  2 files changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
> index 47547a962b19..e7981301d10b 100644
> --- a/drivers/infiniband/hw/mana/device.c
> +++ b/drivers/infiniband/hw/mana/device.c
> @@ -53,6 +53,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 mana_context *mc;
>  	struct mana_ib_dev *dev;
>  	int ret;
> @@ -79,6 +80,20 @@ static int mana_ib_probe(struct auxiliary_device *adev,
>  	dev->ib_dev.num_comp_vectors = 1;
>  	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_unlock();
> +		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
> +		goto free_ib_device;
> +	}

Clang now warns (or errors with CONFIG_WERROR):

  drivers/infiniband/hw/mana/device.c:88:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
     88 |         if (!upper_ndev) {
        |             ^~~~~~~~~~~
  drivers/infiniband/hw/mana/device.c:150:9: note: uninitialized use occurs here
    150 |         return ret;
        |                ^~~
  drivers/infiniband/hw/mana/device.c:88:2: note: remove the 'if' if its condition is always false
     88 |         if (!upper_ndev) {
        |         ^~~~~~~~~~~~~~~~~~
     89 |                 rcu_read_unlock();
        |                 ~~~~~~~~~~~~~~~~~~
     90 |                 ibdev_err(&dev->ib_dev, "Failed to get master netdev");
        |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     91 |                 goto free_ib_device;
        |                 ~~~~~~~~~~~~~~~~~~~~
     92 |         }
        |         ~
  drivers/infiniband/hw/mana/device.c:62:9: note: initialize the variable 'ret' to silence this warning
     62 |         int ret;
        |                ^
        |                 = 0
  1 error generated.

I could not really find a consistent return code for when
netdev_master_upper_dev_get_rcu() fails. -ENODEV?

Cheers,
Nathan

> +	ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1);
> +	rcu_read_unlock();
> +	if (ret) {
> +		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
> +		goto free_ib_device;
> +	}
> +
>  	ret = mana_gd_register_device(&mdev->gdma_context->mana_ib);
>  	if (ret) {
>  		ibdev_err(&dev->ib_dev, "Failed to register device, ret %d",
> diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
> index 29550f2173ff..7a9d7e13b7b1 100644
> --- a/drivers/infiniband/hw/mana/main.c
> +++ b/drivers/infiniband/hw/mana/main.c
> @@ -527,11 +527,18 @@ int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma)
>  int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num,
>  			       struct ib_port_immutable *immutable)
>  {
> -	/*
> -	 * This version only support RAW_PACKET
> -	 * other values need to be filled for other types
> -	 */
> +	struct ib_port_attr attr;
> +	int err;
> +
> +	err = ib_query_port(ibdev, port_num, &attr);
> +	if (err)
> +		return err;
> +
> +	immutable->pkey_tbl_len = attr.pkey_tbl_len;
> +	immutable->gid_tbl_len = attr.gid_tbl_len;
>  	immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET;
> +	if (port_num == 1)
> +		immutable->core_cap_flags |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
>  
>  	return 0;
>  }
> -- 
> 2.43.0
>
Konstantin Taranov April 23, 2024, 7:15 a.m. UTC | #2
> Hi Konstantin,
> 
> On Wed, Apr 10, 2024 at 01:42:29AM -0700, Konstantin Taranov wrote:
> > From: Konstantin Taranov <kotaranov@microsoft.com>
> >
> > Set netdev and RoCEv2 flag to enable GID population on port 1.
> > Use GIDs of the master netdev. As mc->ports[] stores slave devices,
> > use a helper to get the master netdev.
> >
> > Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
> > ---
> >  drivers/infiniband/hw/mana/device.c | 15 +++++++++++++++
> >  drivers/infiniband/hw/mana/main.c   | 15 +++++++++++----
> >  2 files changed, 26 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/mana/device.c
> > b/drivers/infiniband/hw/mana/device.c
> > index 47547a962b19..e7981301d10b 100644
> > --- a/drivers/infiniband/hw/mana/device.c
> > +++ b/drivers/infiniband/hw/mana/device.c
> > @@ -53,6 +53,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 mana_context *mc;
> >  	struct mana_ib_dev *dev;
> >  	int ret;
> > @@ -79,6 +80,20 @@ static int mana_ib_probe(struct auxiliary_device
> *adev,
> >  	dev->ib_dev.num_comp_vectors = 1;
> >  	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_unlock();
> > +		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
> > +		goto free_ib_device;
> > +	}
> 
> Clang now warns (or errors with CONFIG_WERROR):
> 
>   drivers/infiniband/hw/mana/device.c:88:6: error: variable 'ret' is used
> uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-
> uninitialized]
>      88 |         if (!upper_ndev) {
>         |             ^~~~~~~~~~~
>   drivers/infiniband/hw/mana/device.c:150:9: note: uninitialized use occurs
> here
>     150 |         return ret;
>         |                ^~~
>   drivers/infiniband/hw/mana/device.c:88:2: note: remove the 'if' if its
> condition is always false
>      88 |         if (!upper_ndev) {
>         |         ^~~~~~~~~~~~~~~~~~
>      89 |                 rcu_read_unlock();
>         |                 ~~~~~~~~~~~~~~~~~~
>      90 |                 ibdev_err(&dev->ib_dev, "Failed to get master netdev");
>         |
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>      91 |                 goto free_ib_device;
>         |                 ~~~~~~~~~~~~~~~~~~~~
>      92 |         }
>         |         ~
>   drivers/infiniband/hw/mana/device.c:62:9: note: initialize the variable 'ret'
> to silence this warning
>      62 |         int ret;
>         |                ^
>         |                 = 0
>   1 error generated.
> 
> I could not really find a consistent return code for when
> netdev_master_upper_dev_get_rcu() fails. -ENODEV?

Thanks for catching this! Yes, I think ret = -ENODEV; is appropriate fix.
Should I send a patch to rdma-next? Or what should I do now to fix this?

Konstantin

> 
> Cheers,
> Nathan
>
Jason Gunthorpe April 23, 2024, 11:44 a.m. UTC | #3
On Tue, Apr 23, 2024 at 07:15:41AM +0000, Konstantin Taranov wrote:
> > I could not really find a consistent return code for when
> > netdev_master_upper_dev_get_rcu() fails. -ENODEV?
> 
> Thanks for catching this! Yes, I think ret = -ENODEV; is appropriate fix.
> Should I send a patch to rdma-next? Or what should I do now to fix
> this?

Send a patch

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
index 47547a962b19..e7981301d10b 100644
--- a/drivers/infiniband/hw/mana/device.c
+++ b/drivers/infiniband/hw/mana/device.c
@@ -53,6 +53,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 mana_context *mc;
 	struct mana_ib_dev *dev;
 	int ret;
@@ -79,6 +80,20 @@  static int mana_ib_probe(struct auxiliary_device *adev,
 	dev->ib_dev.num_comp_vectors = 1;
 	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_unlock();
+		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
+		goto free_ib_device;
+	}
+	ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1);
+	rcu_read_unlock();
+	if (ret) {
+		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
+		goto free_ib_device;
+	}
+
 	ret = mana_gd_register_device(&mdev->gdma_context->mana_ib);
 	if (ret) {
 		ibdev_err(&dev->ib_dev, "Failed to register device, ret %d",
diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 29550f2173ff..7a9d7e13b7b1 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -527,11 +527,18 @@  int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma)
 int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num,
 			       struct ib_port_immutable *immutable)
 {
-	/*
-	 * This version only support RAW_PACKET
-	 * other values need to be filled for other types
-	 */
+	struct ib_port_attr attr;
+	int err;
+
+	err = ib_query_port(ibdev, port_num, &attr);
+	if (err)
+		return err;
+
+	immutable->pkey_tbl_len = attr.pkey_tbl_len;
+	immutable->gid_tbl_len = attr.gid_tbl_len;
 	immutable->core_cap_flags = RDMA_CORE_PORT_RAW_PACKET;
+	if (port_num == 1)
+		immutable->core_cap_flags |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
 
 	return 0;
 }