Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[sfrench/cifs-2.6.git] / drivers / vdpa / vdpa_sim / vdpa_sim.c
index 2629911c29bbf4e341982434682a8e5975d8c4d0..6a90fdb9cbfc6f8070a43692b858f9349d577f0e 100644 (file)
@@ -38,6 +38,10 @@ static int batch_mapping = 1;
 module_param(batch_mapping, int, 0444);
 MODULE_PARM_DESC(batch_mapping, "Batched mapping 1 -Enable; 0 - Disable");
 
+static char *macaddr;
+module_param(macaddr, charp, 0);
+MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
+
 struct vdpasim_virtqueue {
        struct vringh vring;
        struct vringh_kiov iov;
@@ -60,7 +64,8 @@ struct vdpasim_virtqueue {
 
 static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
                              (1ULL << VIRTIO_F_VERSION_1)  |
-                             (1ULL << VIRTIO_F_ACCESS_PLATFORM);
+                             (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
+                             (1ULL << VIRTIO_NET_F_MAC);
 
 /* State of each vdpasim device */
 struct vdpasim {
@@ -361,7 +366,9 @@ static struct vdpasim *vdpasim_create(void)
        spin_lock_init(&vdpasim->iommu_lock);
 
        dev = &vdpasim->vdpa.dev;
-       dev->coherent_dma_mask = DMA_BIT_MASK(64);
+       dev->dma_mask = &dev->coherent_dma_mask;
+       if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
+               goto err_iommu;
        set_dma_ops(dev, &vdpasim_dma_ops);
 
        vdpasim->iommu = vhost_iotlb_alloc(2048, 0);
@@ -372,7 +379,15 @@ static struct vdpasim *vdpasim_create(void)
        if (!vdpasim->buffer)
                goto err_iommu;
 
-       eth_random_addr(vdpasim->config.mac);
+       if (macaddr) {
+               mac_pton(macaddr, vdpasim->config.mac);
+               if (!is_valid_ether_addr(vdpasim->config.mac)) {
+                       ret = -EADDRNOTAVAIL;
+                       goto err_iommu;
+               }
+       } else {
+               eth_random_addr(vdpasim->config.mac);
+       }
 
        vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
        vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
@@ -574,6 +589,16 @@ static u32 vdpasim_get_generation(struct vdpa_device *vdpa)
        return vdpasim->generation;
 }
 
+static struct vdpa_iova_range vdpasim_get_iova_range(struct vdpa_device *vdpa)
+{
+       struct vdpa_iova_range range = {
+               .first = 0ULL,
+               .last = ULLONG_MAX,
+       };
+
+       return range;
+}
+
 static int vdpasim_set_map(struct vdpa_device *vdpa,
                           struct vhost_iotlb *iotlb)
 {
@@ -657,6 +682,7 @@ static const struct vdpa_config_ops vdpasim_net_config_ops = {
        .get_config             = vdpasim_get_config,
        .set_config             = vdpasim_set_config,
        .get_generation         = vdpasim_get_generation,
+       .get_iova_range         = vdpasim_get_iova_range,
        .dma_map                = vdpasim_dma_map,
        .dma_unmap              = vdpasim_dma_unmap,
        .free                   = vdpasim_free,
@@ -683,6 +709,7 @@ static const struct vdpa_config_ops vdpasim_net_batch_config_ops = {
        .get_config             = vdpasim_get_config,
        .set_config             = vdpasim_set_config,
        .get_generation         = vdpasim_get_generation,
+       .get_iova_range         = vdpasim_get_iova_range,
        .set_map                = vdpasim_set_map,
        .free                   = vdpasim_free,
 };