net/vdpa: Use struct for set/get vq state
authorEli Cohen <eli@mellanox.com>
Tue, 4 Aug 2020 16:20:43 +0000 (19:20 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 5 Aug 2020 22:39:19 +0000 (18:39 -0400)
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 <parav@mellanox.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Eli Cohen <eli@mellanox.com>
Link: https://lore.kernel.org/r/20200804162048.22587-8-eli@mellanox.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/ifcvf/ifcvf_base.c
drivers/vdpa/ifcvf/ifcvf_base.h
drivers/vdpa/ifcvf/ifcvf_main.c
drivers/vdpa/vdpa_sim/vdpa_sim.c
drivers/vhost/vdpa.c
include/linux/vdpa.h

index 94bf0328b68d6c96fea45152ae7e02cfe9c0c77c..f2a128e56de5f3d9e0105d419f5e562ccbcee588 100644 (file)
@@ -272,7 +272,7 @@ static int ifcvf_config_features(struct ifcvf_hw *hw)
        return 0;
 }
 
-u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
+u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
 {
        struct ifcvf_lm_cfg __iomem *ifcvf_lm;
        void __iomem *avail_idx_addr;
@@ -287,7 +287,7 @@ u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
        return last_avail_idx;
 }
 
-int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u64 num)
+int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num)
 {
        struct ifcvf_lm_cfg __iomem *ifcvf_lm;
        void __iomem *avail_idx_addr;
index 24af422b5a3eeeb97e0eedcd45cbc0c0deedc268..08f267a2aafec962fc89f1f6d3cd0b2a26bc478d 100644 (file)
@@ -116,7 +116,7 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
 void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
 void ifcvf_reset(struct ifcvf_hw *hw);
 u64 ifcvf_get_features(struct ifcvf_hw *hw);
-u64 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
-int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u64 num);
+u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
+int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
 #endif /* _IFCVF_H_ */
index 7c93225367dbf8eca75641a16707e598bb347ef9..dc311e972b9e424ed673143ca34ff4ae47d0369c 100644 (file)
@@ -237,19 +237,20 @@ static u16 ifcvf_vdpa_get_vq_num_max(struct vdpa_device *vdpa_dev)
        return IFCVF_QUEUE_MAX;
 }
 
-static u64 ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid)
+static void ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
+                                   struct vdpa_vq_state *state)
 {
        struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-       return ifcvf_get_vq_state(vf, qid);
+       state->avail_index = ifcvf_get_vq_state(vf, qid);
 }
 
 static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
-                                  u64 num)
+                                  const struct vdpa_vq_state *state)
 {
        struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-       return ifcvf_set_vq_state(vf, qid, num);
+       return ifcvf_set_vq_state(vf, qid, state->avail_index);
 }
 
 static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,
index 58baff89cc2922a00d9c2fa70877000a12ed1aee..c93126ad09d1a91d3ef61b6dbb98e34a86399e96 100644 (file)
@@ -450,26 +450,28 @@ static bool vdpasim_get_vq_ready(struct vdpa_device *vdpa, u16 idx)
        return vq->ready;
 }
 
-static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx, u64 state)
+static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx,
+                               const struct vdpa_vq_state *state)
 {
        struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
        struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
        struct vringh *vrh = &vq->vring;
 
        spin_lock(&vdpasim->lock);
-       vrh->last_avail_idx = state;
+       vrh->last_avail_idx = state->avail_index;
        spin_unlock(&vdpasim->lock);
 
        return 0;
 }
 
-static u64 vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx)
+static void vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
+                                struct vdpa_vq_state *state)
 {
        struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
        struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
        struct vringh *vrh = &vq->vring;
 
-       return vrh->last_avail_idx;
+       state->avail_index = vrh->last_avail_idx;
 }
 
 static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
index 2d8c950ad3a827c402ec26bd1013a7088962cbb5..066b165c17b1e77083f8a6002d6cfaf03171993e 100644 (file)
@@ -349,6 +349,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 {
        struct vdpa_device *vdpa = v->vdpa;
        const struct vdpa_config_ops *ops = vdpa->config;
+       struct vdpa_vq_state vq_state;
        struct vdpa_callback cb;
        struct vhost_virtqueue *vq;
        struct vhost_vring_state s;
@@ -374,7 +375,8 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
                ops->set_vq_ready(vdpa, idx, s.num);
                return 0;
        case VHOST_GET_VRING_BASE:
-               vq->last_avail_idx = ops->get_vq_state(v->vdpa, idx);
+               ops->get_vq_state(v->vdpa, idx, &vq_state);
+               vq->last_avail_idx = vq_state.avail_index;
                break;
        case VHOST_GET_BACKEND_FEATURES:
                features = VHOST_VDPA_BACKEND_FEATURES;
@@ -404,7 +406,8 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
                break;
 
        case VHOST_SET_VRING_BASE:
-               if (ops->set_vq_state(vdpa, idx, vq->last_avail_idx))
+               vq_state.avail_index = vq->last_avail_idx;
+               if (ops->set_vq_state(vdpa, idx, &vq_state))
                        r = -EINVAL;
                break;
 
index b5901cde73e07ed5ffa9f445fc9566c320266fa8..d7399c98373474fc71c19b9ea439292422a0b5c3 100644 (file)
@@ -27,6 +27,14 @@ struct vdpa_notification_area {
        resource_size_t size;
 };
 
+/**
+ * vDPA vq_state definition
+ * @avail_index: available index
+ */
+struct vdpa_vq_state {
+       u16     avail_index;
+};
+
 /**
  * vDPA device - representation of a vDPA device
  * @dev: underlying device
@@ -80,12 +88,12 @@ struct vdpa_device {
  * @set_vq_state:              Set the state for a virtqueue
  *                             @vdev: vdpa device
  *                             @idx: virtqueue index
- *                             @state: virtqueue state (last_avail_idx)
+ *                             @state: pointer to set virtqueue state (last_avail_idx)
  *                             Returns integer: success (0) or error (< 0)
  * @get_vq_state:              Get the state for a virtqueue
  *                             @vdev: vdpa device
  *                             @idx: virtqueue index
- *                             Returns virtqueue state (last_avail_idx)
+ *                             @state: pointer to returned state (last_avail_idx)
  * @get_vq_notification:       Get the notification area for a virtqueue
  *                             @vdev: vdpa device
  *                             @idx: virtqueue index
@@ -183,8 +191,10 @@ struct vdpa_config_ops {
                          struct vdpa_callback *cb);
        void (*set_vq_ready)(struct vdpa_device *vdev, u16 idx, bool ready);
        bool (*get_vq_ready)(struct vdpa_device *vdev, u16 idx);
-       int (*set_vq_state)(struct vdpa_device *vdev, u16 idx, u64 state);
-       u64 (*get_vq_state)(struct vdpa_device *vdev, u16 idx);
+       int (*set_vq_state)(struct vdpa_device *vdev, u16 idx,
+                           const struct vdpa_vq_state *state);
+       void (*get_vq_state)(struct vdpa_device *vdev, u16 idx,
+                            struct vdpa_vq_state *state);
        struct vdpa_notification_area
        (*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
        /* vq irq is not expected to be changed once DRIVER_OK is set */