Merge tag 'driver-core-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / include / linux / vdpa.h
index c0a5083..4700a88 100644 (file)
@@ -68,9 +68,11 @@ struct vdpa_mgmt_dev;
  *                   because core frees it; use driver_set_override() to
  *                   set or clear it.
  * @config: the configuration ops for this device.
- * @cf_mutex: Protects get and set access to configuration layout.
+ * @cf_lock: Protects get and set access to configuration layout.
  * @index: device index
  * @features_valid: were features initialized? for legacy guests
+ * @ngroups: the number of virtqueue groups
+ * @nas: the number of address spaces
  * @use_va: indicate whether virtual address must be used by this device
  * @nvqs: maximum number of supported virtqueues
  * @mdev: management device pointer; caller must setup when registering device as part
@@ -81,12 +83,14 @@ struct vdpa_device {
        struct device *dma_dev;
        const char *driver_override;
        const struct vdpa_config_ops *config;
-       struct mutex cf_mutex; /* Protects get/set config */
+       struct rw_semaphore cf_lock; /* Protects get/set config */
        unsigned int index;
        bool features_valid;
        bool use_va;
        u32 nvqs;
        struct vdpa_mgmt_dev *mdev;
+       unsigned int ngroups;
+       unsigned int nas;
 };
 
 /**
@@ -174,6 +178,10 @@ struct vdpa_map_file {
  *                             for the device
  *                             @vdev: vdpa device
  *                             Returns virtqueue algin requirement
+ * @get_vq_group:              Get the group id for a specific virtqueue
+ *                             @vdev: vdpa device
+ *                             @idx: virtqueue index
+ *                             Returns u32: group id for this virtqueue
  * @get_device_features:       Get virtio features supported by the device
  *                             @vdev: vdpa device
  *                             Returns the virtio features support by the
@@ -234,10 +242,17 @@ struct vdpa_map_file {
  *                             @vdev: vdpa device
  *                             Returns the iova range supported by
  *                             the device.
+ * @set_group_asid:            Set address space identifier for a
+ *                             virtqueue group
+ *                             @vdev: vdpa device
+ *                             @group: virtqueue group
+ *                             @asid: address space id for this group
+ *                             Returns integer: success (0) or error (< 0)
  * @set_map:                   Set device memory mapping (optional)
  *                             Needed for device that using device
  *                             specific DMA translation (on-chip IOMMU)
  *                             @vdev: vdpa device
+ *                             @asid: address space identifier
  *                             @iotlb: vhost memory mapping to be
  *                             used by the vDPA
  *                             Returns integer: success (0) or error (< 0)
@@ -246,6 +261,7 @@ struct vdpa_map_file {
  *                             specific DMA translation (on-chip IOMMU)
  *                             and preferring incremental map.
  *                             @vdev: vdpa device
+ *                             @asid: address space identifier
  *                             @iova: iova to be mapped
  *                             @size: size of the area
  *                             @pa: physical address for the map
@@ -257,6 +273,7 @@ struct vdpa_map_file {
  *                             specific DMA translation (on-chip IOMMU)
  *                             and preferring incremental unmap.
  *                             @vdev: vdpa device
+ *                             @asid: address space identifier
  *                             @iova: iova to be unmapped
  *                             @size: size of the area
  *                             Returns integer: success (0) or error (< 0)
@@ -278,6 +295,9 @@ struct vdpa_config_ops {
                            const struct vdpa_vq_state *state);
        int (*get_vq_state)(struct vdpa_device *vdev, u16 idx,
                            struct vdpa_vq_state *state);
+       int (*get_vendor_vq_stats)(struct vdpa_device *vdev, u16 idx,
+                                  struct sk_buff *msg,
+                                  struct netlink_ext_ack *extack);
        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 */
@@ -285,6 +305,7 @@ struct vdpa_config_ops {
 
        /* Device ops */
        u32 (*get_vq_align)(struct vdpa_device *vdev);
+       u32 (*get_vq_group)(struct vdpa_device *vdev, u16 idx);
        u64 (*get_device_features)(struct vdpa_device *vdev);
        int (*set_driver_features)(struct vdpa_device *vdev, u64 features);
        u64 (*get_driver_features)(struct vdpa_device *vdev);
@@ -306,10 +327,14 @@ struct vdpa_config_ops {
        struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
 
        /* DMA ops */
-       int (*set_map)(struct vdpa_device *vdev, struct vhost_iotlb *iotlb);
-       int (*dma_map)(struct vdpa_device *vdev, u64 iova, u64 size,
-                      u64 pa, u32 perm, void *opaque);
-       int (*dma_unmap)(struct vdpa_device *vdev, u64 iova, u64 size);
+       int (*set_map)(struct vdpa_device *vdev, unsigned int asid,
+                      struct vhost_iotlb *iotlb);
+       int (*dma_map)(struct vdpa_device *vdev, unsigned int asid,
+                      u64 iova, u64 size, u64 pa, u32 perm, void *opaque);
+       int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid,
+                        u64 iova, u64 size);
+       int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group,
+                             unsigned int asid);
 
        /* Free device resources */
        void (*free)(struct vdpa_device *vdev);
@@ -317,6 +342,7 @@ struct vdpa_config_ops {
 
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
                                        const struct vdpa_config_ops *config,
+                                       unsigned int ngroups, unsigned int nas,
                                        size_t size, const char *name,
                                        bool use_va);
 
@@ -327,17 +353,20 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
  * @member: the name of struct vdpa_device within the @dev_struct
  * @parent: the parent device
  * @config: the bus operations that is supported by this device
+ * @ngroups: the number of virtqueue groups supported by this device
+ * @nas: the number of address spaces
  * @name: name of the vdpa device
  * @use_va: indicate whether virtual address must be used by this device
  *
  * Return allocated data structure or ERR_PTR upon error
  */
-#define vdpa_alloc_device(dev_struct, member, parent, config, name, use_va)   \
-                         container_of(__vdpa_alloc_device( \
-                                      parent, config, \
-                                      sizeof(dev_struct) + \
+#define vdpa_alloc_device(dev_struct, member, parent, config, ngroups, nas, \
+                         name, use_va) \
+                         container_of((__vdpa_alloc_device( \
+                                      parent, config, ngroups, nas, \
+                                      (sizeof(dev_struct) + \
                                       BUILD_BUG_ON_ZERO(offsetof( \
-                                      dev_struct, member)), name, use_va), \
+                                      dev_struct, member))), name, use_va)), \
                                       dev_struct, member)
 
 int vdpa_register_device(struct vdpa_device *vdev, u32 nvqs);
@@ -397,10 +426,10 @@ static inline int vdpa_reset(struct vdpa_device *vdev)
        const struct vdpa_config_ops *ops = vdev->config;
        int ret;
 
-       mutex_lock(&vdev->cf_mutex);
+       down_write(&vdev->cf_lock);
        vdev->features_valid = false;
        ret = ops->reset(vdev);
-       mutex_unlock(&vdev->cf_mutex);
+       up_write(&vdev->cf_lock);
        return ret;
 }
 
@@ -419,9 +448,9 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
        int ret;
 
-       mutex_lock(&vdev->cf_mutex);
+       down_write(&vdev->cf_lock);
        ret = vdpa_set_features_unlocked(vdev, features);
-       mutex_unlock(&vdev->cf_mutex);
+       up_write(&vdev->cf_lock);
 
        return ret;
 }
@@ -465,7 +494,7 @@ struct vdpa_mgmtdev_ops {
 struct vdpa_mgmt_dev {
        struct device *device;
        const struct vdpa_mgmtdev_ops *ops;
-       const struct virtio_device_id *id_table;
+       struct virtio_device_id *id_table;
        u64 config_attr_mask;
        struct list_head list;
        u64 supported_features;