xref: /linux/drivers/nvdimm/virtio_pmem.h (revision 7f063b2f17eaba2a35e251aa53627f2a70d536e2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * virtio_pmem.h: virtio pmem Driver
4  *
5  * Discovers persistent memory range information
6  * from host and provides a virtio based flushing
7  * interface.
8  **/
9 
10 #ifndef _LINUX_VIRTIO_PMEM_H
11 #define _LINUX_VIRTIO_PMEM_H
12 
13 #include <linux/dma-mapping.h>
14 #include <linux/module.h>
15 #include <uapi/linux/virtio_pmem.h>
16 #include <linux/kref.h>
17 #include <linux/libnvdimm.h>
18 #include <linux/mutex.h>
19 #include <linux/spinlock.h>
20 #include <linux/workqueue.h>
21 
22 struct virtio_pmem_request {
23 	struct kref kref;
24 
25 	/* Wait queue to process deferred work after ack from host */
26 	wait_queue_head_t host_acked;
27 	bool done;
28 
29 	/* Wait queue to process deferred work after virt queue buffer avail */
30 	wait_queue_head_t wq_buf;
31 	bool wq_buf_avail;
32 	struct list_head list;
33 
34 	struct virtio_pmem_req req;
35 	__dma_from_device_group_begin(resp);
36 	struct virtio_pmem_resp resp;
37 	__dma_from_device_group_end(resp);
38 };
39 
40 struct virtio_pmem {
41 	struct virtio_device *vdev;
42 
43 	/* Virtio pmem request queue */
44 	struct virtqueue *req_vq;
45 
46 	/* Serialize flush requests to the device. */
47 	struct mutex flush_lock;
48 
49 	/* Complete asynchronous FUA flushes outside the submit path. */
50 	struct workqueue_struct *flush_wq;
51 
52 	/* nvdimm bus registers virtio pmem device */
53 	struct nvdimm_bus *nvdimm_bus;
54 	struct nvdimm_bus_descriptor nd_desc;
55 
56 	/* List to store deferred work if virtqueue is full */
57 	struct list_head req_list;
58 
59 	/* Request currently owned by the virtqueue. */
60 	struct virtio_pmem_request *req_inflight;
61 
62 	/* Fail fast and wake waiters if the request virtqueue is broken. */
63 	bool broken;
64 
65 	/* Synchronize virtqueue data */
66 	spinlock_t pmem_lock;
67 
68 	/* Memory region information */
69 	__u64 start;
70 	__u64 size;
71 };
72 
73 void virtio_pmem_host_ack(struct virtqueue *vq);
74 void virtio_pmem_mark_broken(struct virtio_pmem *vpmem);
75 void virtio_pmem_drain(struct virtio_pmem *vpmem);
76 int async_pmem_flush(struct nd_region *nd_region, struct bio *bio);
77 #endif
78