Skip to content

Commit aac50c0

Browse files
Eli Cohenmstsirkin
authored andcommitted
net/vdpa: Use struct for set/get vq state
For now VQ state involves 16 bit available index value encoded in u64 variable. In the future it will be extended to contain more fields. Use struct to contain the state, now containing only a single u16 for the available index. In the future we can add fields to this struct. Reviewed-by: Parav Pandit <[email protected]> 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 a997448 commit aac50c0

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int ifcvf_config_features(struct ifcvf_hw *hw)
272272
return 0;
273273
}
274274

275-
u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
275+
u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
276276
{
277277
struct ifcvf_lm_cfg __iomem *ifcvf_lm;
278278
void __iomem *avail_idx_addr;
@@ -287,7 +287,7 @@ u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
287287
return last_avail_idx;
288288
}
289289

290-
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u64 num)
290+
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num)
291291
{
292292
struct ifcvf_lm_cfg __iomem *ifcvf_lm;
293293
void __iomem *avail_idx_addr;

drivers/vdpa/ifcvf/ifcvf_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
116116
void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
117117
void ifcvf_reset(struct ifcvf_hw *hw);
118118
u64 ifcvf_get_features(struct ifcvf_hw *hw);
119-
u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
120-
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u64 num);
119+
u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
120+
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
121121
struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
122122
#endif /* _IFCVF_H_ */

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,20 @@ static u16 ifcvf_vdpa_get_vq_num_max(struct vdpa_device *vdpa_dev)
237237
return IFCVF_QUEUE_MAX;
238238
}
239239

240-
static u64 ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid)
240+
static void ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
241+
struct vdpa_vq_state *state)
241242
{
242243
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
243244

244-
return ifcvf_get_vq_state(vf, qid);
245+
state->avail_index = ifcvf_get_vq_state(vf, qid);
245246
}
246247

247248
static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
248-
u64 num)
249+
const struct vdpa_vq_state *state)
249250
{
250251
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
251252

252-
return ifcvf_set_vq_state(vf, qid, num);
253+
return ifcvf_set_vq_state(vf, qid, state->avail_index);
253254
}
254255

255256
static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,26 +450,28 @@ static bool vdpasim_get_vq_ready(struct vdpa_device *vdpa, u16 idx)
450450
return vq->ready;
451451
}
452452

453-
static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx, u64 state)
453+
static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx,
454+
const struct vdpa_vq_state *state)
454455
{
455456
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
456457
struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
457458
struct vringh *vrh = &vq->vring;
458459

459460
spin_lock(&vdpasim->lock);
460-
vrh->last_avail_idx = state;
461+
vrh->last_avail_idx = state->avail_index;
461462
spin_unlock(&vdpasim->lock);
462463

463464
return 0;
464465
}
465466

466-
static u64 vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx)
467+
static void vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
468+
struct vdpa_vq_state *state)
467469
{
468470
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
469471
struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
470472
struct vringh *vrh = &vq->vring;
471473

472-
return vrh->last_avail_idx;
474+
state->avail_index = vrh->last_avail_idx;
473475
}
474476

475477
static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)

drivers/vhost/vdpa.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
349349
{
350350
struct vdpa_device *vdpa = v->vdpa;
351351
const struct vdpa_config_ops *ops = vdpa->config;
352+
struct vdpa_vq_state vq_state;
352353
struct vdpa_callback cb;
353354
struct vhost_virtqueue *vq;
354355
struct vhost_vring_state s;
@@ -374,7 +375,8 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
374375
ops->set_vq_ready(vdpa, idx, s.num);
375376
return 0;
376377
case VHOST_GET_VRING_BASE:
377-
vq->last_avail_idx = ops->get_vq_state(v->vdpa, idx);
378+
ops->get_vq_state(v->vdpa, idx, &vq_state);
379+
vq->last_avail_idx = vq_state.avail_index;
378380
break;
379381
case VHOST_GET_BACKEND_FEATURES:
380382
features = VHOST_VDPA_BACKEND_FEATURES;
@@ -404,7 +406,8 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
404406
break;
405407

406408
case VHOST_SET_VRING_BASE:
407-
if (ops->set_vq_state(vdpa, idx, vq->last_avail_idx))
409+
vq_state.avail_index = vq->last_avail_idx;
410+
if (ops->set_vq_state(vdpa, idx, &vq_state))
408411
r = -EINVAL;
409412
break;
410413

include/linux/vdpa.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ struct vdpa_notification_area {
2727
resource_size_t size;
2828
};
2929

30+
/**
31+
* vDPA vq_state definition
32+
* @avail_index: available index
33+
*/
34+
struct vdpa_vq_state {
35+
u16 avail_index;
36+
};
37+
3038
/**
3139
* vDPA device - representation of a vDPA device
3240
* @dev: underlying device
@@ -80,12 +88,12 @@ struct vdpa_device {
8088
* @set_vq_state: Set the state for a virtqueue
8189
* @vdev: vdpa device
8290
* @idx: virtqueue index
83-
* @state: virtqueue state (last_avail_idx)
91+
* @state: pointer to set virtqueue state (last_avail_idx)
8492
* Returns integer: success (0) or error (< 0)
8593
* @get_vq_state: Get the state for a virtqueue
8694
* @vdev: vdpa device
8795
* @idx: virtqueue index
88-
* Returns virtqueue state (last_avail_idx)
96+
* @state: pointer to returned state (last_avail_idx)
8997
* @get_vq_notification: Get the notification area for a virtqueue
9098
* @vdev: vdpa device
9199
* @idx: virtqueue index
@@ -183,8 +191,10 @@ struct vdpa_config_ops {
183191
struct vdpa_callback *cb);
184192
void (*set_vq_ready)(struct vdpa_device *vdev, u16 idx, bool ready);
185193
bool (*get_vq_ready)(struct vdpa_device *vdev, u16 idx);
186-
int (*set_vq_state)(struct vdpa_device *vdev, u16 idx, u64 state);
187-
u64 (*get_vq_state)(struct vdpa_device *vdev, u16 idx);
194+
int (*set_vq_state)(struct vdpa_device *vdev, u16 idx,
195+
const struct vdpa_vq_state *state);
196+
void (*get_vq_state)(struct vdpa_device *vdev, u16 idx,
197+
struct vdpa_vq_state *state);
188198
struct vdpa_notification_area
189199
(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
190200
/* vq irq is not expected to be changed once DRIVER_OK is set */

0 commit comments

Comments
 (0)