mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-26 02:25:00 -05:00
vdpa: Extend routine to accept vdpa device name
In a subsequent patch, when user initiated command creates a vdpa device, the user chooses the name of the vdpa device. To support it, extend the device allocation API to consider this name specified by the caller driver. Signed-off-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Eli Cohen <elic@nvidia.com> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/20210105103203.82508-3-parav@nvidia.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
4379441260
commit
fd70a406a3
5 changed files with 38 additions and 11 deletions
|
@ -432,7 +432,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
||||||
|
|
||||||
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
|
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
|
||||||
dev, &ifc_vdpa_ops,
|
dev, &ifc_vdpa_ops,
|
||||||
IFCVF_MAX_QUEUE_PAIRS * 2);
|
IFCVF_MAX_QUEUE_PAIRS * 2, NULL);
|
||||||
if (adapter == NULL) {
|
if (adapter == NULL) {
|
||||||
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
|
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
@ -1982,7 +1982,7 @@ static int mlx5v_probe(struct auxiliary_device *adev,
|
||||||
max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS);
|
max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS);
|
||||||
|
|
||||||
ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops,
|
ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops,
|
||||||
2 * mlx5_vdpa_max_qps(max_vqs));
|
2 * mlx5_vdpa_max_qps(max_vqs), NULL);
|
||||||
if (IS_ERR(ndev))
|
if (IS_ERR(ndev))
|
||||||
return PTR_ERR(ndev);
|
return PTR_ERR(ndev);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/vdpa.h>
|
#include <linux/vdpa.h>
|
||||||
|
|
||||||
|
/* A global mutex that protects vdpa management device and device level operations. */
|
||||||
|
static DEFINE_MUTEX(vdpa_dev_mutex);
|
||||||
static DEFINE_IDA(vdpa_index_ida);
|
static DEFINE_IDA(vdpa_index_ida);
|
||||||
|
|
||||||
static int vdpa_dev_probe(struct device *d)
|
static int vdpa_dev_probe(struct device *d)
|
||||||
|
@ -63,6 +65,7 @@ static void vdpa_release_dev(struct device *d)
|
||||||
* @config: the bus operations that is supported by this device
|
* @config: the bus operations that is supported by this device
|
||||||
* @nvqs: number of virtqueues supported by this device
|
* @nvqs: number of virtqueues supported by this device
|
||||||
* @size: size of the parent structure that contains private data
|
* @size: size of the parent structure that contains private data
|
||||||
|
* @name: name of the vdpa device; optional.
|
||||||
*
|
*
|
||||||
* Driver should use vdpa_alloc_device() wrapper macro instead of
|
* Driver should use vdpa_alloc_device() wrapper macro instead of
|
||||||
* using this directly.
|
* using this directly.
|
||||||
|
@ -72,8 +75,7 @@ static void vdpa_release_dev(struct device *d)
|
||||||
*/
|
*/
|
||||||
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
|
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
|
||||||
const struct vdpa_config_ops *config,
|
const struct vdpa_config_ops *config,
|
||||||
int nvqs,
|
int nvqs, size_t size, const char *name)
|
||||||
size_t size)
|
|
||||||
{
|
{
|
||||||
struct vdpa_device *vdev;
|
struct vdpa_device *vdev;
|
||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
|
@ -101,7 +103,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
|
||||||
vdev->features_valid = false;
|
vdev->features_valid = false;
|
||||||
vdev->nvqs = nvqs;
|
vdev->nvqs = nvqs;
|
||||||
|
|
||||||
err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index);
|
if (name)
|
||||||
|
err = dev_set_name(&vdev->dev, "%s", name);
|
||||||
|
else
|
||||||
|
err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_name;
|
goto err_name;
|
||||||
|
|
||||||
|
@ -118,6 +123,13 @@ err:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__vdpa_alloc_device);
|
EXPORT_SYMBOL_GPL(__vdpa_alloc_device);
|
||||||
|
|
||||||
|
static int vdpa_name_match(struct device *dev, const void *data)
|
||||||
|
{
|
||||||
|
struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);
|
||||||
|
|
||||||
|
return (strcmp(dev_name(&vdev->dev), data) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vdpa_register_device - register a vDPA device
|
* vdpa_register_device - register a vDPA device
|
||||||
* Callers must have a succeed call of vdpa_alloc_device() before.
|
* Callers must have a succeed call of vdpa_alloc_device() before.
|
||||||
|
@ -127,7 +139,21 @@ EXPORT_SYMBOL_GPL(__vdpa_alloc_device);
|
||||||
*/
|
*/
|
||||||
int vdpa_register_device(struct vdpa_device *vdev)
|
int vdpa_register_device(struct vdpa_device *vdev)
|
||||||
{
|
{
|
||||||
return device_add(&vdev->dev);
|
struct device *dev;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
mutex_lock(&vdpa_dev_mutex);
|
||||||
|
dev = bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_match);
|
||||||
|
if (dev) {
|
||||||
|
put_device(dev);
|
||||||
|
err = -EEXIST;
|
||||||
|
goto name_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = device_add(&vdev->dev);
|
||||||
|
name_err:
|
||||||
|
mutex_unlock(&vdpa_dev_mutex);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vdpa_register_device);
|
EXPORT_SYMBOL_GPL(vdpa_register_device);
|
||||||
|
|
||||||
|
@ -137,7 +163,9 @@ EXPORT_SYMBOL_GPL(vdpa_register_device);
|
||||||
*/
|
*/
|
||||||
void vdpa_unregister_device(struct vdpa_device *vdev)
|
void vdpa_unregister_device(struct vdpa_device *vdev)
|
||||||
{
|
{
|
||||||
|
mutex_lock(&vdpa_dev_mutex);
|
||||||
device_unregister(&vdev->dev);
|
device_unregister(&vdev->dev);
|
||||||
|
mutex_unlock(&vdpa_dev_mutex);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vdpa_unregister_device);
|
EXPORT_SYMBOL_GPL(vdpa_unregister_device);
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
|
||||||
ops = &vdpasim_config_ops;
|
ops = &vdpasim_config_ops;
|
||||||
|
|
||||||
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
|
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
|
||||||
dev_attr->nvqs);
|
dev_attr->nvqs, NULL);
|
||||||
if (!vdpasim)
|
if (!vdpasim)
|
||||||
goto err_alloc;
|
goto err_alloc;
|
||||||
|
|
||||||
|
|
|
@ -245,15 +245,14 @@ struct vdpa_config_ops {
|
||||||
|
|
||||||
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
|
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
|
||||||
const struct vdpa_config_ops *config,
|
const struct vdpa_config_ops *config,
|
||||||
int nvqs,
|
int nvqs, size_t size, const char *name);
|
||||||
size_t size);
|
|
||||||
|
|
||||||
#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs) \
|
#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs, name) \
|
||||||
container_of(__vdpa_alloc_device( \
|
container_of(__vdpa_alloc_device( \
|
||||||
parent, config, nvqs, \
|
parent, config, nvqs, \
|
||||||
sizeof(dev_struct) + \
|
sizeof(dev_struct) + \
|
||||||
BUILD_BUG_ON_ZERO(offsetof( \
|
BUILD_BUG_ON_ZERO(offsetof( \
|
||||||
dev_struct, member))), \
|
dev_struct, member)), name), \
|
||||||
dev_struct, member)
|
dev_struct, member)
|
||||||
|
|
||||||
int vdpa_register_device(struct vdpa_device *vdev);
|
int vdpa_register_device(struct vdpa_device *vdev);
|
||||||
|
|
Loading…
Add table
Reference in a new issue