Skip to content

Commit a64917b

Browse files
elic307imstsirkin
authored andcommitted
vdpa: Provide interface to read driver features
Provide an interface to read the negotiated features. This is needed when building the netlink message in vdpa_dev_net_config_fill(). Also fix the implementation of vdpa_dev_net_config_fill() to use the negotiated features instead of the device features. To make APIs clearer, make the following name changes to struct vdpa_config_ops so they better describe their operations: get_features -> get_device_features set_features -> set_driver_features Finally, add get_driver_features to return the negotiated features and add implementation to all the upstream drivers. Acked-by: Jason Wang <[email protected]> Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 870aaff commit a64917b

File tree

10 files changed

+87
-34
lines changed

10 files changed

+87
-34
lines changed

drivers/vdpa/alibaba/eni_vdpa.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
5858
return &eni_vdpa->ldev;
5959
}
6060

61-
static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
61+
static u64 eni_vdpa_get_device_features(struct vdpa_device *vdpa)
6262
{
6363
struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
6464
u64 features = vp_legacy_get_features(ldev);
@@ -69,7 +69,7 @@ static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
6969
return features;
7070
}
7171

72-
static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
72+
static int eni_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features)
7373
{
7474
struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
7575

@@ -84,6 +84,13 @@ static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
8484
return 0;
8585
}
8686

87+
static u64 eni_vdpa_get_driver_features(struct vdpa_device *vdpa)
88+
{
89+
struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
90+
91+
return vp_legacy_get_driver_features(ldev);
92+
}
93+
8794
static u8 eni_vdpa_get_status(struct vdpa_device *vdpa)
8895
{
8996
struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
@@ -401,8 +408,9 @@ static void eni_vdpa_set_config_cb(struct vdpa_device *vdpa,
401408
}
402409

403410
static const struct vdpa_config_ops eni_vdpa_ops = {
404-
.get_features = eni_vdpa_get_features,
405-
.set_features = eni_vdpa_set_features,
411+
.get_device_features = eni_vdpa_get_device_features,
412+
.set_driver_features = eni_vdpa_set_driver_features,
413+
.get_driver_features = eni_vdpa_get_driver_features,
406414
.get_status = eni_vdpa_get_status,
407415
.set_status = eni_vdpa_set_status,
408416
.reset = eni_vdpa_reset,

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static struct ifcvf_hw *vdpa_to_vf(struct vdpa_device *vdpa_dev)
169169
return &adapter->vf;
170170
}
171171

172-
static u64 ifcvf_vdpa_get_features(struct vdpa_device *vdpa_dev)
172+
static u64 ifcvf_vdpa_get_device_features(struct vdpa_device *vdpa_dev)
173173
{
174174
struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev);
175175
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
@@ -187,7 +187,7 @@ static u64 ifcvf_vdpa_get_features(struct vdpa_device *vdpa_dev)
187187
return features;
188188
}
189189

190-
static int ifcvf_vdpa_set_features(struct vdpa_device *vdpa_dev, u64 features)
190+
static int ifcvf_vdpa_set_driver_features(struct vdpa_device *vdpa_dev, u64 features)
191191
{
192192
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
193193
int ret;
@@ -201,6 +201,13 @@ static int ifcvf_vdpa_set_features(struct vdpa_device *vdpa_dev, u64 features)
201201
return 0;
202202
}
203203

204+
static u64 ifcvf_vdpa_get_driver_features(struct vdpa_device *vdpa_dev)
205+
{
206+
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
207+
208+
return vf->req_features;
209+
}
210+
204211
static u8 ifcvf_vdpa_get_status(struct vdpa_device *vdpa_dev)
205212
{
206213
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
@@ -426,8 +433,9 @@ static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_devic
426433
* implemented set_map()/dma_map()/dma_unmap()
427434
*/
428435
static const struct vdpa_config_ops ifc_vdpa_ops = {
429-
.get_features = ifcvf_vdpa_get_features,
430-
.set_features = ifcvf_vdpa_set_features,
436+
.get_device_features = ifcvf_vdpa_get_device_features,
437+
.set_driver_features = ifcvf_vdpa_set_driver_features,
438+
.get_driver_features = ifcvf_vdpa_get_driver_features,
431439
.get_status = ifcvf_vdpa_get_status,
432440
.set_status = ifcvf_vdpa_set_status,
433441
.reset = ifcvf_vdpa_reset,

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ static u64 mlx_to_vritio_features(u16 dev_features)
18781878
return result;
18791879
}
18801880

1881-
static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
1881+
static u64 mlx5_vdpa_get_device_features(struct vdpa_device *vdev)
18821882
{
18831883
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
18841884
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
@@ -1971,7 +1971,7 @@ static void update_cvq_info(struct mlx5_vdpa_dev *mvdev)
19711971
}
19721972
}
19731973

1974-
static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
1974+
static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features)
19751975
{
19761976
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
19771977
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
@@ -2338,6 +2338,13 @@ static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx)
23382338
return -EOPNOTSUPP;
23392339
}
23402340

2341+
static u64 mlx5_vdpa_get_driver_features(struct vdpa_device *vdev)
2342+
{
2343+
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
2344+
2345+
return mvdev->actual_features;
2346+
}
2347+
23412348
static const struct vdpa_config_ops mlx5_vdpa_ops = {
23422349
.set_vq_address = mlx5_vdpa_set_vq_address,
23432350
.set_vq_num = mlx5_vdpa_set_vq_num,
@@ -2350,8 +2357,9 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
23502357
.get_vq_notification = mlx5_get_vq_notification,
23512358
.get_vq_irq = mlx5_get_vq_irq,
23522359
.get_vq_align = mlx5_vdpa_get_vq_align,
2353-
.get_features = mlx5_vdpa_get_features,
2354-
.set_features = mlx5_vdpa_set_features,
2360+
.get_device_features = mlx5_vdpa_get_device_features,
2361+
.set_driver_features = mlx5_vdpa_set_driver_features,
2362+
.get_driver_features = mlx5_vdpa_get_driver_features,
23552363
.set_config_cb = mlx5_vdpa_set_config_cb,
23562364
.get_vq_num_max = mlx5_vdpa_get_vq_num_max,
23572365
.get_device_id = mlx5_vdpa_get_device_id,

drivers/vdpa/vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
808808
if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
809809
return -EMSGSIZE;
810810

811-
features = vdev->config->get_features(vdev);
811+
features = vdev->config->get_driver_features(vdev);
812812

813813
return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config);
814814
}

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
399399
return VDPASIM_QUEUE_ALIGN;
400400
}
401401

402-
static u64 vdpasim_get_features(struct vdpa_device *vdpa)
402+
static u64 vdpasim_get_device_features(struct vdpa_device *vdpa)
403403
{
404404
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
405405

406406
return vdpasim->dev_attr.supported_features;
407407
}
408408

409-
static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
409+
static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 features)
410410
{
411411
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
412412

@@ -419,6 +419,13 @@ static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
419419
return 0;
420420
}
421421

422+
static u64 vdpasim_get_driver_features(struct vdpa_device *vdpa)
423+
{
424+
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
425+
426+
return vdpasim->features;
427+
}
428+
422429
static void vdpasim_set_config_cb(struct vdpa_device *vdpa,
423430
struct vdpa_callback *cb)
424431
{
@@ -613,8 +620,9 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
613620
.set_vq_state = vdpasim_set_vq_state,
614621
.get_vq_state = vdpasim_get_vq_state,
615622
.get_vq_align = vdpasim_get_vq_align,
616-
.get_features = vdpasim_get_features,
617-
.set_features = vdpasim_set_features,
623+
.get_device_features = vdpasim_get_device_features,
624+
.set_driver_features = vdpasim_set_driver_features,
625+
.get_driver_features = vdpasim_get_driver_features,
618626
.set_config_cb = vdpasim_set_config_cb,
619627
.get_vq_num_max = vdpasim_get_vq_num_max,
620628
.get_device_id = vdpasim_get_device_id,
@@ -642,8 +650,9 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
642650
.set_vq_state = vdpasim_set_vq_state,
643651
.get_vq_state = vdpasim_get_vq_state,
644652
.get_vq_align = vdpasim_get_vq_align,
645-
.get_features = vdpasim_get_features,
646-
.set_features = vdpasim_set_features,
653+
.get_device_features = vdpasim_get_device_features,
654+
.set_driver_features = vdpasim_set_driver_features,
655+
.get_driver_features = vdpasim_get_driver_features,
647656
.set_config_cb = vdpasim_set_config_cb,
648657
.get_vq_num_max = vdpasim_get_vq_num_max,
649658
.get_device_id = vdpasim_get_device_id,

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,21 +573,28 @@ static u32 vduse_vdpa_get_vq_align(struct vdpa_device *vdpa)
573573
return dev->vq_align;
574574
}
575575

576-
static u64 vduse_vdpa_get_features(struct vdpa_device *vdpa)
576+
static u64 vduse_vdpa_get_device_features(struct vdpa_device *vdpa)
577577
{
578578
struct vduse_dev *dev = vdpa_to_vduse(vdpa);
579579

580580
return dev->device_features;
581581
}
582582

583-
static int vduse_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
583+
static int vduse_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features)
584584
{
585585
struct vduse_dev *dev = vdpa_to_vduse(vdpa);
586586

587587
dev->driver_features = features;
588588
return 0;
589589
}
590590

591+
static u64 vduse_vdpa_get_driver_features(struct vdpa_device *vdpa)
592+
{
593+
struct vduse_dev *dev = vdpa_to_vduse(vdpa);
594+
595+
return dev->driver_features;
596+
}
597+
591598
static void vduse_vdpa_set_config_cb(struct vdpa_device *vdpa,
592599
struct vdpa_callback *cb)
593600
{
@@ -721,8 +728,9 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = {
721728
.set_vq_state = vduse_vdpa_set_vq_state,
722729
.get_vq_state = vduse_vdpa_get_vq_state,
723730
.get_vq_align = vduse_vdpa_get_vq_align,
724-
.get_features = vduse_vdpa_get_features,
725-
.set_features = vduse_vdpa_set_features,
731+
.get_device_features = vduse_vdpa_get_device_features,
732+
.set_driver_features = vduse_vdpa_set_driver_features,
733+
.get_driver_features = vduse_vdpa_get_driver_features,
726734
.set_config_cb = vduse_vdpa_set_config_cb,
727735
.get_vq_num_max = vduse_vdpa_get_vq_num_max,
728736
.get_device_id = vduse_vdpa_get_device_id,

drivers/vdpa/virtio_pci/vp_vdpa.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ static struct virtio_pci_modern_device *vdpa_to_mdev(struct vdpa_device *vdpa)
5353
return &vp_vdpa->mdev;
5454
}
5555

56-
static u64 vp_vdpa_get_features(struct vdpa_device *vdpa)
56+
static u64 vp_vdpa_get_device_features(struct vdpa_device *vdpa)
5757
{
5858
struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
5959

6060
return vp_modern_get_features(mdev);
6161
}
6262

63-
static int vp_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
63+
static int vp_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features)
6464
{
6565
struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
6666

@@ -69,6 +69,13 @@ static int vp_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
6969
return 0;
7070
}
7171

72+
static u64 vp_vdpa_get_driver_features(struct vdpa_device *vdpa)
73+
{
74+
struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
75+
76+
return vp_modern_get_driver_features(mdev);
77+
}
78+
7279
static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
7380
{
7481
struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
@@ -415,8 +422,9 @@ vp_vdpa_get_vq_notification(struct vdpa_device *vdpa, u16 qid)
415422
}
416423

417424
static const struct vdpa_config_ops vp_vdpa_ops = {
418-
.get_features = vp_vdpa_get_features,
419-
.set_features = vp_vdpa_set_features,
425+
.get_device_features = vp_vdpa_get_device_features,
426+
.set_driver_features = vp_vdpa_set_driver_features,
427+
.get_driver_features = vp_vdpa_get_driver_features,
420428
.get_status = vp_vdpa_get_status,
421429
.set_status = vp_vdpa_set_status,
422430
.reset = vp_vdpa_reset,

drivers/vhost/vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep)
262262
const struct vdpa_config_ops *ops = vdpa->config;
263263
u64 features;
264264

265-
features = ops->get_features(vdpa);
265+
features = ops->get_device_features(vdpa);
266266

267267
if (copy_to_user(featurep, &features, sizeof(features)))
268268
return -EFAULT;

drivers/virtio/virtio_vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static u64 virtio_vdpa_get_features(struct virtio_device *vdev)
308308
struct vdpa_device *vdpa = vd_get_vdpa(vdev);
309309
const struct vdpa_config_ops *ops = vdpa->config;
310310

311-
return ops->get_features(vdpa);
311+
return ops->get_device_features(vdpa);
312312
}
313313

314314
static int virtio_vdpa_finalize_features(struct virtio_device *vdev)

include/linux/vdpa.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,17 @@ struct vdpa_map_file {
171171
* for the device
172172
* @vdev: vdpa device
173173
* Returns virtqueue algin requirement
174-
* @get_features: Get virtio features supported by the device
174+
* @get_device_features: Get virtio features supported by the device
175175
* @vdev: vdpa device
176176
* Returns the virtio features support by the
177177
* device
178-
* @set_features: Set virtio features supported by the driver
178+
* @set_driver_features: Set virtio features supported by the driver
179179
* @vdev: vdpa device
180180
* @features: feature support by the driver
181181
* Returns integer: success (0) or error (< 0)
182+
* @get_driver_features: Get the virtio driver features in action
183+
* @vdev: vdpa device
184+
* Returns the virtio features accepted
182185
* @set_config_cb: Set the config interrupt callback
183186
* @vdev: vdpa device
184187
* @cb: virtio-vdev interrupt callback structure
@@ -278,8 +281,9 @@ struct vdpa_config_ops {
278281

279282
/* Device ops */
280283
u32 (*get_vq_align)(struct vdpa_device *vdev);
281-
u64 (*get_features)(struct vdpa_device *vdev);
282-
int (*set_features)(struct vdpa_device *vdev, u64 features);
284+
u64 (*get_device_features)(struct vdpa_device *vdev);
285+
int (*set_driver_features)(struct vdpa_device *vdev, u64 features);
286+
u64 (*get_driver_features)(struct vdpa_device *vdev);
283287
void (*set_config_cb)(struct vdpa_device *vdev,
284288
struct vdpa_callback *cb);
285289
u16 (*get_vq_num_max)(struct vdpa_device *vdev);
@@ -397,7 +401,7 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features)
397401
const struct vdpa_config_ops *ops = vdev->config;
398402

399403
vdev->features_valid = true;
400-
return ops->set_features(vdev, features);
404+
return ops->set_driver_features(vdev, features);
401405
}
402406

403407
void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,

0 commit comments

Comments
 (0)