diff options
Diffstat (limited to 'drivers/misc/mic/vop/vop_main.c')
| -rw-r--r-- | drivers/misc/mic/vop/vop_main.c | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c index 2bfa3a903bf9..744757f541be 100644 --- a/drivers/misc/mic/vop/vop_main.c +++ b/drivers/misc/mic/vop/vop_main.c | |||
| @@ -47,7 +47,8 @@ | |||
| 47 | * @dc: Virtio device control | 47 | * @dc: Virtio device control |
| 48 | * @vpdev: VOP device which is the parent for this virtio device | 48 | * @vpdev: VOP device which is the parent for this virtio device |
| 49 | * @vr: Buffer for accessing the VRING | 49 | * @vr: Buffer for accessing the VRING |
| 50 | * @used: Buffer for used | 50 | * @used_virt: Virtual address of used ring |
| 51 | * @used: DMA address of used ring | ||
| 51 | * @used_size: Size of the used buffer | 52 | * @used_size: Size of the used buffer |
| 52 | * @reset_done: Track whether VOP reset is complete | 53 | * @reset_done: Track whether VOP reset is complete |
| 53 | * @virtio_cookie: Cookie returned upon requesting a interrupt | 54 | * @virtio_cookie: Cookie returned upon requesting a interrupt |
| @@ -61,6 +62,7 @@ struct _vop_vdev { | |||
| 61 | struct mic_device_ctrl __iomem *dc; | 62 | struct mic_device_ctrl __iomem *dc; |
| 62 | struct vop_device *vpdev; | 63 | struct vop_device *vpdev; |
| 63 | void __iomem *vr[VOP_MAX_VRINGS]; | 64 | void __iomem *vr[VOP_MAX_VRINGS]; |
| 65 | void *used_virt[VOP_MAX_VRINGS]; | ||
| 64 | dma_addr_t used[VOP_MAX_VRINGS]; | 66 | dma_addr_t used[VOP_MAX_VRINGS]; |
| 65 | int used_size[VOP_MAX_VRINGS]; | 67 | int used_size[VOP_MAX_VRINGS]; |
| 66 | struct completion reset_done; | 68 | struct completion reset_done; |
| @@ -260,12 +262,12 @@ static bool vop_notify(struct virtqueue *vq) | |||
| 260 | static void vop_del_vq(struct virtqueue *vq, int n) | 262 | static void vop_del_vq(struct virtqueue *vq, int n) |
| 261 | { | 263 | { |
| 262 | struct _vop_vdev *vdev = to_vopvdev(vq->vdev); | 264 | struct _vop_vdev *vdev = to_vopvdev(vq->vdev); |
| 263 | struct vring *vr = (struct vring *)(vq + 1); | ||
| 264 | struct vop_device *vpdev = vdev->vpdev; | 265 | struct vop_device *vpdev = vdev->vpdev; |
| 265 | 266 | ||
| 266 | dma_unmap_single(&vpdev->dev, vdev->used[n], | 267 | dma_unmap_single(&vpdev->dev, vdev->used[n], |
| 267 | vdev->used_size[n], DMA_BIDIRECTIONAL); | 268 | vdev->used_size[n], DMA_BIDIRECTIONAL); |
| 268 | free_pages((unsigned long)vr->used, get_order(vdev->used_size[n])); | 269 | free_pages((unsigned long)vdev->used_virt[n], |
| 270 | get_order(vdev->used_size[n])); | ||
| 269 | vring_del_virtqueue(vq); | 271 | vring_del_virtqueue(vq); |
| 270 | vpdev->hw_ops->iounmap(vpdev, vdev->vr[n]); | 272 | vpdev->hw_ops->iounmap(vpdev, vdev->vr[n]); |
| 271 | vdev->vr[n] = NULL; | 273 | vdev->vr[n] = NULL; |
| @@ -283,6 +285,26 @@ static void vop_del_vqs(struct virtio_device *dev) | |||
| 283 | vop_del_vq(vq, idx++); | 285 | vop_del_vq(vq, idx++); |
| 284 | } | 286 | } |
| 285 | 287 | ||
| 288 | static struct virtqueue *vop_new_virtqueue(unsigned int index, | ||
| 289 | unsigned int num, | ||
| 290 | struct virtio_device *vdev, | ||
| 291 | bool context, | ||
| 292 | void *pages, | ||
| 293 | bool (*notify)(struct virtqueue *vq), | ||
| 294 | void (*callback)(struct virtqueue *vq), | ||
| 295 | const char *name, | ||
| 296 | void *used) | ||
| 297 | { | ||
| 298 | bool weak_barriers = false; | ||
| 299 | struct vring vring; | ||
| 300 | |||
| 301 | vring_init(&vring, num, pages, MIC_VIRTIO_RING_ALIGN); | ||
| 302 | vring.used = used; | ||
| 303 | |||
| 304 | return __vring_new_virtqueue(index, vring, vdev, weak_barriers, context, | ||
| 305 | notify, callback, name); | ||
| 306 | } | ||
| 307 | |||
| 286 | /* | 308 | /* |
| 287 | * This routine will assign vring's allocated in host/io memory. Code in | 309 | * This routine will assign vring's allocated in host/io memory. Code in |
| 288 | * virtio_ring.c however continues to access this io memory as if it were local | 310 | * virtio_ring.c however continues to access this io memory as if it were local |
| @@ -302,7 +324,6 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, | |||
| 302 | struct _mic_vring_info __iomem *info; | 324 | struct _mic_vring_info __iomem *info; |
| 303 | void *used; | 325 | void *used; |
| 304 | int vr_size, _vr_size, err, magic; | 326 | int vr_size, _vr_size, err, magic; |
| 305 | struct vring *vr; | ||
| 306 | u8 type = ioread8(&vdev->desc->type); | 327 | u8 type = ioread8(&vdev->desc->type); |
| 307 | 328 | ||
| 308 | if (index >= ioread8(&vdev->desc->num_vq)) | 329 | if (index >= ioread8(&vdev->desc->num_vq)) |
| @@ -322,17 +343,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, | |||
| 322 | return ERR_PTR(-ENOMEM); | 343 | return ERR_PTR(-ENOMEM); |
| 323 | vdev->vr[index] = va; | 344 | vdev->vr[index] = va; |
| 324 | memset_io(va, 0x0, _vr_size); | 345 | memset_io(va, 0x0, _vr_size); |
| 325 | vq = vring_new_virtqueue( | 346 | |
| 326 | index, | ||
| 327 | le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN, | ||
| 328 | dev, | ||
| 329 | false, | ||
| 330 | ctx, | ||
| 331 | (void __force *)va, vop_notify, callback, name); | ||
| 332 | if (!vq) { | ||
| 333 | err = -ENOMEM; | ||
| 334 | goto unmap; | ||
| 335 | } | ||
| 336 | info = va + _vr_size; | 347 | info = va + _vr_size; |
| 337 | magic = ioread32(&info->magic); | 348 | magic = ioread32(&info->magic); |
| 338 | 349 | ||
| @@ -341,18 +352,27 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, | |||
| 341 | goto unmap; | 352 | goto unmap; |
| 342 | } | 353 | } |
| 343 | 354 | ||
| 344 | /* Allocate and reassign used ring now */ | ||
| 345 | vdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 + | 355 | vdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 + |
| 346 | sizeof(struct vring_used_elem) * | 356 | sizeof(struct vring_used_elem) * |
| 347 | le16_to_cpu(config.num)); | 357 | le16_to_cpu(config.num)); |
| 348 | used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, | 358 | used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 349 | get_order(vdev->used_size[index])); | 359 | get_order(vdev->used_size[index])); |
| 360 | vdev->used_virt[index] = used; | ||
| 350 | if (!used) { | 361 | if (!used) { |
| 351 | err = -ENOMEM; | 362 | err = -ENOMEM; |
| 352 | dev_err(_vop_dev(vdev), "%s %d err %d\n", | 363 | dev_err(_vop_dev(vdev), "%s %d err %d\n", |
| 353 | __func__, __LINE__, err); | 364 | __func__, __LINE__, err); |
| 354 | goto del_vq; | 365 | goto unmap; |
| 366 | } | ||
| 367 | |||
| 368 | vq = vop_new_virtqueue(index, le16_to_cpu(config.num), dev, ctx, | ||
| 369 | (void __force *)va, vop_notify, callback, | ||
| 370 | name, used); | ||
| 371 | if (!vq) { | ||
| 372 | err = -ENOMEM; | ||
| 373 | goto free_used; | ||
| 355 | } | 374 | } |
| 375 | |||
| 356 | vdev->used[index] = dma_map_single(&vpdev->dev, used, | 376 | vdev->used[index] = dma_map_single(&vpdev->dev, used, |
| 357 | vdev->used_size[index], | 377 | vdev->used_size[index], |
| 358 | DMA_BIDIRECTIONAL); | 378 | DMA_BIDIRECTIONAL); |
| @@ -360,26 +380,17 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, | |||
| 360 | err = -ENOMEM; | 380 | err = -ENOMEM; |
| 361 | dev_err(_vop_dev(vdev), "%s %d err %d\n", | 381 | dev_err(_vop_dev(vdev), "%s %d err %d\n", |
| 362 | __func__, __LINE__, err); | 382 | __func__, __LINE__, err); |
| 363 | goto free_used; | 383 | goto del_vq; |
| 364 | } | 384 | } |
| 365 | writeq(vdev->used[index], &vqconfig->used_address); | 385 | writeq(vdev->used[index], &vqconfig->used_address); |
| 366 | /* | ||
| 367 | * To reassign the used ring here we are directly accessing | ||
| 368 | * struct vring_virtqueue which is a private data structure | ||
| 369 | * in virtio_ring.c. At the minimum, a BUILD_BUG_ON() in | ||
| 370 | * vring_new_virtqueue() would ensure that | ||
| 371 | * (&vq->vring == (struct vring *) (&vq->vq + 1)); | ||
| 372 | */ | ||
| 373 | vr = (struct vring *)(vq + 1); | ||
| 374 | vr->used = used; | ||
| 375 | 386 | ||
| 376 | vq->priv = vdev; | 387 | vq->priv = vdev; |
| 377 | return vq; | 388 | return vq; |
| 389 | del_vq: | ||
| 390 | vring_del_virtqueue(vq); | ||
| 378 | free_used: | 391 | free_used: |
| 379 | free_pages((unsigned long)used, | 392 | free_pages((unsigned long)used, |
| 380 | get_order(vdev->used_size[index])); | 393 | get_order(vdev->used_size[index])); |
| 381 | del_vq: | ||
| 382 | vring_del_virtqueue(vq); | ||
| 383 | unmap: | 394 | unmap: |
| 384 | vpdev->hw_ops->iounmap(vpdev, vdev->vr[index]); | 395 | vpdev->hw_ops->iounmap(vpdev, vdev->vr[index]); |
| 385 | return ERR_PTR(err); | 396 | return ERR_PTR(err); |
| @@ -581,6 +592,8 @@ static int _vop_remove_device(struct mic_device_desc __iomem *d, | |||
| 581 | int ret = -1; | 592 | int ret = -1; |
| 582 | 593 | ||
| 583 | if (ioread8(&dc->config_change) == MIC_VIRTIO_PARAM_DEV_REMOVE) { | 594 | if (ioread8(&dc->config_change) == MIC_VIRTIO_PARAM_DEV_REMOVE) { |
| 595 | struct device *dev = get_device(&vdev->vdev.dev); | ||
| 596 | |||
| 584 | dev_dbg(&vpdev->dev, | 597 | dev_dbg(&vpdev->dev, |
| 585 | "%s %d config_change %d type %d vdev %p\n", | 598 | "%s %d config_change %d type %d vdev %p\n", |
| 586 | __func__, __LINE__, | 599 | __func__, __LINE__, |
| @@ -592,7 +605,7 @@ static int _vop_remove_device(struct mic_device_desc __iomem *d, | |||
| 592 | iowrite8(-1, &dc->h2c_vdev_db); | 605 | iowrite8(-1, &dc->h2c_vdev_db); |
| 593 | if (status & VIRTIO_CONFIG_S_DRIVER_OK) | 606 | if (status & VIRTIO_CONFIG_S_DRIVER_OK) |
| 594 | wait_for_completion(&vdev->reset_done); | 607 | wait_for_completion(&vdev->reset_done); |
| 595 | put_device(&vdev->vdev.dev); | 608 | put_device(dev); |
| 596 | iowrite8(1, &dc->guest_ack); | 609 | iowrite8(1, &dc->guest_ack); |
| 597 | dev_dbg(&vpdev->dev, "%s %d guest_ack %d\n", | 610 | dev_dbg(&vpdev->dev, "%s %d guest_ack %d\n", |
| 598 | __func__, __LINE__, ioread8(&dc->guest_ack)); | 611 | __func__, __LINE__, ioread8(&dc->guest_ack)); |
