Skip to content

Commit 0d16cc4

Browse files
jasowangmstsirkin
authored andcommitted
vdpa: introduce map ops
Virtio core allows the transport to provide device or transport specific mapping functions. This patch adds this support to vDPA. We can simply do this by allowing the vDPA parent to register a virtio_map_ops. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Wang <jasowang@redhat.com> Message-Id: <20250924070045.10361-2-jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
1 parent 58aca3d commit 0d16cc4

12 files changed

Lines changed: 29 additions & 15 deletions

File tree

drivers/vdpa/alibaba/eni_vdpa.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
478478
return ret;
479479

480480
eni_vdpa = vdpa_alloc_device(struct eni_vdpa, vdpa,
481-
dev, &eni_vdpa_ops, 1, 1, NULL, false);
481+
dev, &eni_vdpa_ops, NULL,
482+
1, 1, NULL, false);
482483
if (IS_ERR(eni_vdpa)) {
483484
ENI_ERR(pdev, "failed to allocate vDPA structure\n");
484485
return PTR_ERR(eni_vdpa);

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
705705
vf = &ifcvf_mgmt_dev->vf;
706706
pdev = vf->pdev;
707707
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
708-
&pdev->dev, &ifc_vdpa_ops, 1, 1, NULL, false);
708+
&pdev->dev, &ifc_vdpa_ops,
709+
NULL, 1, 1, NULL, false);
709710
if (IS_ERR(adapter)) {
710711
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
711712
return PTR_ERR(adapter);

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3882,7 +3882,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
38823882
}
38833883

38843884
ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mgtdev->vdpa_ops,
3885-
MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
3885+
NULL, MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
38863886
if (IS_ERR(ndev))
38873887
return PTR_ERR(ndev);
38883888

drivers/vdpa/octeon_ep/octep_vdpa_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ static int octep_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
508508
u64 device_features;
509509
int ret;
510510

511-
oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops, 1, 1,
512-
NULL, false);
511+
oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops,
512+
NULL, 1, 1, NULL, false);
513513
if (IS_ERR(oct_vdpa)) {
514514
dev_err(&pdev->dev, "Failed to allocate vDPA structure for octep vdpa device");
515515
return PTR_ERR(oct_vdpa);

drivers/vdpa/pds/vdpa_dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
632632
}
633633

634634
pdsv = vdpa_alloc_device(struct pds_vdpa_device, vdpa_dev,
635-
dev, &pds_vdpa_ops, 1, 1, name, false);
635+
dev, &pds_vdpa_ops, NULL,
636+
1, 1, name, false);
636637
if (IS_ERR(pdsv)) {
637638
dev_err(dev, "Failed to allocate vDPA structure: %pe\n", pdsv);
638639
return PTR_ERR(pdsv);

drivers/vdpa/solidrun/snet_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ static int snet_vdpa_probe_vf(struct pci_dev *pdev)
10081008
}
10091009

10101010
/* Allocate vdpa device */
1011-
snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops, 1, 1, NULL,
1012-
false);
1011+
snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops,
1012+
NULL, 1, 1, NULL, false);
10131013
if (!snet) {
10141014
SNET_ERR(pdev, "Failed to allocate a vdpa device\n");
10151015
ret = -ENOMEM;

drivers/vdpa/vdpa.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static void vdpa_release_dev(struct device *d)
142142
* initialized but before registered.
143143
* @parent: the parent device
144144
* @config: the bus operations that is supported by this device
145+
* @map: the map operations that is supported by this device
145146
* @ngroups: number of groups supported by this device
146147
* @nas: number of address spaces supported by this device
147148
* @size: size of the parent structure that contains private data
@@ -156,6 +157,7 @@ static void vdpa_release_dev(struct device *d)
156157
*/
157158
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
158159
const struct vdpa_config_ops *config,
160+
const struct virtio_map_ops *map,
159161
unsigned int ngroups, unsigned int nas,
160162
size_t size, const char *name,
161163
bool use_va)
@@ -187,6 +189,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
187189
vdev->dev.release = vdpa_release_dev;
188190
vdev->index = err;
189191
vdev->config = config;
192+
vdev->map = map;
190193
vdev->features_valid = false;
191194
vdev->use_va = use_va;
192195
vdev->ngroups = ngroups;

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
215215
else
216216
ops = &vdpasim_config_ops;
217217

218-
vdpa = __vdpa_alloc_device(NULL, ops,
218+
vdpa = __vdpa_alloc_device(NULL, ops, NULL,
219219
dev_attr->ngroups, dev_attr->nas,
220220
dev_attr->alloc_size,
221221
dev_attr->name, use_va);

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,8 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
20092009
return -EEXIST;
20102010

20112011
vdev = vdpa_alloc_device(struct vduse_vdpa, vdpa, dev->dev,
2012-
&vduse_vdpa_config_ops, 1, 1, name, true);
2012+
&vduse_vdpa_config_ops, NULL,
2013+
1, 1, name, true);
20132014
if (IS_ERR(vdev))
20142015
return PTR_ERR(vdev);
20152016

drivers/vdpa/virtio_pci/vp_vdpa.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
511511
int ret, i;
512512

513513
vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
514-
dev, &vp_vdpa_ops, 1, 1, name, false);
514+
dev, &vp_vdpa_ops, NULL,
515+
1, 1, name, false);
515516

516517
if (IS_ERR(vp_vdpa)) {
517518
dev_err(dev, "vp_vdpa: Failed to allocate vDPA structure\n");

0 commit comments

Comments
 (0)