Lines Matching +full:add +full:- +full:pmem
1 // SPDX-License-Identifier: GPL-2.0
3 * virtio_pmem.c: Virtio pmem Driver
15 struct virtio_pmem *vpmem = vq->vdev->priv; in virtio_pmem_host_ack()
20 spin_lock_irqsave(&vpmem->pmem_lock, flags); in virtio_pmem_host_ack()
22 req_data->done = true; in virtio_pmem_host_ack()
23 wake_up(&req_data->host_acked); in virtio_pmem_host_ack()
25 if (!list_empty(&vpmem->req_list)) { in virtio_pmem_host_ack()
26 req_buf = list_first_entry(&vpmem->req_list, in virtio_pmem_host_ack()
28 req_buf->wq_buf_avail = true; in virtio_pmem_host_ack()
29 wake_up(&req_buf->wq_buf); in virtio_pmem_host_ack()
30 list_del(&req_buf->list); in virtio_pmem_host_ack()
33 spin_unlock_irqrestore(&vpmem->pmem_lock, flags); in virtio_pmem_host_ack()
40 struct virtio_device *vdev = nd_region->provider_data; in virtio_pmem_flush()
41 struct virtio_pmem *vpmem = vdev->priv; in virtio_pmem_flush()
50 return -ENOMEM; in virtio_pmem_flush()
52 req_data->done = false; in virtio_pmem_flush()
53 init_waitqueue_head(&req_data->host_acked); in virtio_pmem_flush()
54 init_waitqueue_head(&req_data->wq_buf); in virtio_pmem_flush()
55 INIT_LIST_HEAD(&req_data->list); in virtio_pmem_flush()
56 req_data->req.type = cpu_to_le32(VIRTIO_PMEM_REQ_TYPE_FLUSH); in virtio_pmem_flush()
57 sg_init_one(&sg, &req_data->req, sizeof(req_data->req)); in virtio_pmem_flush()
59 sg_init_one(&ret, &req_data->resp.ret, sizeof(req_data->resp)); in virtio_pmem_flush()
62 spin_lock_irqsave(&vpmem->pmem_lock, flags); in virtio_pmem_flush()
64 * If virtqueue_add_sgs returns -ENOSPC then req_vq virtual in virtio_pmem_flush()
65 * queue does not have free descriptor. We add the request in virtio_pmem_flush()
69 while ((err = virtqueue_add_sgs(vpmem->req_vq, sgs, 1, 1, req_data, in virtio_pmem_flush()
70 GFP_ATOMIC)) == -ENOSPC) { in virtio_pmem_flush()
72 …dev_info(&vdev->dev, "failed to send command to virtio pmem device, no free slots in the virtqueue… in virtio_pmem_flush()
73 req_data->wq_buf_avail = false; in virtio_pmem_flush()
74 list_add_tail(&req_data->list, &vpmem->req_list); in virtio_pmem_flush()
75 spin_unlock_irqrestore(&vpmem->pmem_lock, flags); in virtio_pmem_flush()
78 wait_event(req_data->wq_buf, req_data->wq_buf_avail); in virtio_pmem_flush()
79 spin_lock_irqsave(&vpmem->pmem_lock, flags); in virtio_pmem_flush()
81 err1 = virtqueue_kick(vpmem->req_vq); in virtio_pmem_flush()
82 spin_unlock_irqrestore(&vpmem->pmem_lock, flags); in virtio_pmem_flush()
84 * virtqueue_add_sgs failed with error different than -ENOSPC, we can't in virtio_pmem_flush()
88 dev_info(&vdev->dev, "failed to send command to virtio pmem device\n"); in virtio_pmem_flush()
89 err = -EIO; in virtio_pmem_flush()
92 wait_event(req_data->host_acked, req_data->done); in virtio_pmem_flush()
93 err = le32_to_cpu(req_data->resp.ret); in virtio_pmem_flush()
107 if (bio && bio->bi_iter.bi_sector != -1) { in async_pmem_flush()
108 struct bio *child = bio_alloc(bio->bi_bdev, 0, in async_pmem_flush()
113 return -ENOMEM; in async_pmem_flush()
115 child->bi_iter.bi_sector = -1; in async_pmem_flush()
121 return -EIO; in async_pmem_flush()