linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Parav Pandit <parav@mellanox.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Greg KH <gregkh@linuxfoundation.org>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	Dave Ertman <david.m.ertman@intel.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"nhorman@redhat.com" <nhorman@redhat.com>,
	"sassmann@redhat.com" <sassmann@redhat.com>,
	Kiran Patil <kiran.patil@intel.com>
Subject: RE: [net-next 1/1] virtual-bus: Implementation of Virtual Bus
Date: Wed, 13 Nov 2019 01:03:44 +0000	[thread overview]
Message-ID: <AM0PR05MB48662DEDDE4750D399B8181ED1760@AM0PR05MB4866.eurprd05.prod.outlook.com> (raw)
In-Reply-To: <20191113000819.GB19615@ziepe.ca>

Hi Jason,

> From: Jason Gunthorpe <jgg@ziepe.ca>
> Sent: Tuesday, November 12, 2019 6:08 PM
> 
> On Tue, Nov 12, 2019 at 10:28:26PM +0100, Greg KH wrote:
> 
> > > + */
> > > +struct virtbus_device {
> > > +	const char			*name;
> > > +	int				id;
> > > +	const struct virtbus_dev_id	*dev_id;
> > > +	struct device			dev;
> > > +	void				*data;
> > > +};
> > > +
> > > +struct virtbus_driver {
> > > +	int (*probe)(struct virtbus_device *);
> > > +	int (*remove)(struct virtbus_device *);
> > > +	void (*shutdown)(struct virtbus_device *);
> > > +	int (*suspend)(struct virtbus_device *, pm_message_t state);
> > > +	int (*resume)(struct virtbus_device *);
> > > +	struct device_driver driver;
> > > +	const struct virtbus_dev_id *id_table; };
> > > +
> > > +#define virtbus_get_dev_id(vdev)	((vdev)->id_entry)
> > > +#define virtbus_get_devdata(dev)	((dev)->devdata)
> >
> > What are these for?
> 
> As far as I can see, the scheme here, using the language from the most
> recent discussion is:
> 
>    // in core or netdev module
>    int mlx5_core_create()
>    {
>       struct mlx5_core_dev *core = kzalloc(..)
> 
>       [..]
> 
>       core->vdev = virtbus_dev_alloc("mlx5_core", core);
>    }
> 
> 
>    // in rdma module
>    static int mlx5_rdma_probe(struct virtbus_device *dev)
>    {
>         // Get the value passed to virtbus_dev_alloc()
> 	struct mlx5_core_dev *core = virtbus_get_devdata(dev)
> 
> 	// Use the huge API surrounding struct mlx5_core_dev
> 	qp = mlx5_core_create_qp(core, ...);
>    }
> 
>    static struct virtbus_driver mlx5_rdma_driver = {
>       .probe = mlx5_rdma_probe,
>       .match = {"mlx5_core"}
>    }
> 
> Drivers that match "mlx5_core" know that the opaque
> 'virtbus_get_devdata()' is a 'struct mlx5_core_dev *' and use that access the
> core driver.
> 
> A "ice_core" would know it is some 'struct ice_core_dev *' for Intel and uses
> that pointer, etc.
> 
> ie it is just a way to a pass a 'void *' from one module to another while using
> the driver core to manage module autoloading and binding.

A small improvement below, because get_drvdata() and set_drvdata() is supposed to be called by the bus driver, not its creator.
And below data structure achieve strong type checks, no void* casts, and exactly achieves the foo_device example.
Isn't it better?

mlx5_virtbus_device {
	struct virtbus_device dev;
	struct mlx5_core_dev *dev;
};

mlx5_core_create(const struct mlx5_core_dev *coredev)
{
	struct mlx5_virtbus_device *dev;

	dev = virtdev_alloc(sizeof(*dev));
	dev->core = coredev;	/* this should not be stored in drvdata */
	virtdev_register(dev);
}

mlx5_rdma_probe(struct virtbus_device *dev)
{
	struct mlx5_core_dev *coredev;
	struct mlx5_virtdev *virtdev;
	struct mlx5_ib_dev *ibdev;

	virtdev = container_of(virtdev, struct mlx5_virtdev, dev);
	coredev = virtdev->coredev;
	ibdev = ib_alloc_dev();
	if (!bdev)
		return -ENOMEM;
	virtdev_set_drvdata(dev, ibdev);
	/* setup.. */
	return 0;	
}

mlx5_rdma_remove(struct virtbus_device *dev)
{
	struct mlx5_ib_dev *ibdev;

	ibdev = virtdev_get_drvdata(dev);
	/* previous load failed */
	if(!ibdev)
		return;
	[..]
	/* mirror of probe */
}

  reply	other threads:[~2019-11-13  1:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 19:22 [net-next 1/1] virtual-bus: Implementation of Virtual Bus Jeff Kirsher
2019-11-12 20:59 ` Jason Gunthorpe
2019-11-12 21:18   ` Ertman, David M
2019-11-12 21:28 ` Greg KH
2019-11-13  0:08   ` Jason Gunthorpe
2019-11-13  1:03     ` Parav Pandit [this message]
2019-11-13  1:10       ` Jason Gunthorpe
2019-11-13  6:44         ` Parav Pandit
2019-11-13  1:09   ` Ertman, David M
2019-11-13  7:03   ` Parav Pandit
2019-11-15 21:17   ` Ertman, David M

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM0PR05MB48662DEDDE4750D399B8181ED1760@AM0PR05MB4866.eurprd05.prod.outlook.com \
    --to=parav@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=david.m.ertman@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=kiran.patil@intel.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).