From: Halil Pasic Date: Fri, 26 Apr 2019 20:32:37 +0200 Subject: virtio/s390: DMA support for virtio-ccw Git-commit: f35f54f11f7f96dc6d43fa79c4a7297a9115627f Patch-mainline: v5.2-rc1 References: jsc#SLE-6197 FATE#327012 bsc#1140559 LTC#173150 Currently virtio-ccw devices do not work if the device has VIRTIO_F_IOMMU_PLATFORM. In future we do want to support DMA API with virtio-ccw. Let us do the plumbing, so the feature VIRTIO_F_IOMMU_PLATFORM works with virtio-ccw. Let us also switch from legacy avail/used accessors to the DMA aware ones (even if it isn't strictly necessary), and remove the legacy accessors (we were the last users). Signed-off-by: Halil Pasic Signed-off-by: Michael S. Tsirkin Reviewed-by: Cornelia Huck Acked-by: Petr Tesarik --- drivers/s390/virtio/virtio_ccw.c | 16 +++++++++++++--- include/linux/virtio.h | 17 ----------------- 2 files changed, 13 insertions(+), 20 deletions(-) --- a/drivers/s390/virtio/virtio_ccw.c +++ b/drivers/s390/virtio/virtio_ccw.c @@ -69,6 +69,7 @@ struct virtio_ccw_device { bool device_lost; unsigned int config_ready; void *airq_info; + u64 dma_mask; }; struct vq_info_block_legacy { @@ -542,8 +543,8 @@ static struct virtqueue *virtio_ccw_setu info->info_block->s.desc = queue; info->info_block->s.index = i; info->info_block->s.num = info->num; - info->info_block->s.avail = (__u64)virtqueue_get_avail(vq); - info->info_block->s.used = (__u64)virtqueue_get_used(vq); + info->info_block->s.avail = (__u64)virtqueue_get_avail_addr(vq); + info->info_block->s.used = (__u64)virtqueue_get_used_addr(vq); ccw->count = sizeof(info->info_block->s); } ccw->cmd_code = CCW_CMD_SET_VQ; @@ -1233,6 +1234,16 @@ static int virtio_ccw_online(struct ccw_ ret = -ENOMEM; goto out_free; } + + vcdev->vdev.dev.parent = &cdev->dev; + cdev->dev.dma_mask = &vcdev->dma_mask; + /* we are fine with common virtio infrastructure using 64 bit DMA */ + ret = dma_set_mask_and_coherent(&cdev->dev, DMA_BIT_MASK(64)); + if (ret) { + dev_warn(&cdev->dev, "Failed to enable 64-bit DMA.\n"); + goto out_free; + } + vcdev->config_block = kzalloc(sizeof(*vcdev->config_block), GFP_DMA | GFP_KERNEL); if (!vcdev->config_block) { @@ -1247,7 +1258,6 @@ static int virtio_ccw_online(struct ccw_ vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */ - vcdev->vdev.dev.parent = &cdev->dev; vcdev->vdev.dev.release = virtio_ccw_release_dev; vcdev->vdev.config = &virtio_ccw_config_ops; vcdev->cdev = cdev; --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -89,23 +89,6 @@ dma_addr_t virtqueue_get_desc_addr(struc dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq); dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq); -/* - * Legacy accessors -- in almost all cases, these are the wrong functions - * to use. - */ -static inline void *virtqueue_get_desc(struct virtqueue *vq) -{ - return virtqueue_get_vring(vq)->desc; -} -static inline void *virtqueue_get_avail(struct virtqueue *vq) -{ - return virtqueue_get_vring(vq)->avail; -} -static inline void *virtqueue_get_used(struct virtqueue *vq) -{ - return virtqueue_get_vring(vq)->used; -} - /** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus