hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/s390/cio/vfio_ccw_private.h
....@@ -3,9 +3,11 @@
33 * Private stuff for vfio_ccw driver
44 *
55 * Copyright IBM Corp. 2017
6
+ * Copyright Red Hat, Inc. 2019
67 *
78 * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
89 * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
10
+ * Cornelia Huck <cohuck@redhat.com>
911 */
1012
1113 #ifndef _VFIO_CCW_PRIVATE_H_
....@@ -15,9 +17,53 @@
1517 #include <linux/eventfd.h>
1618 #include <linux/workqueue.h>
1719 #include <linux/vfio_ccw.h>
20
+#include <asm/crw.h>
21
+#include <asm/debug.h>
1822
1923 #include "css.h"
2024 #include "vfio_ccw_cp.h"
25
+
26
+#define VFIO_CCW_OFFSET_SHIFT 10
27
+#define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT)
28
+#define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT)
29
+#define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1)
30
+
31
+/* capability chain handling similar to vfio-pci */
32
+struct vfio_ccw_private;
33
+struct vfio_ccw_region;
34
+
35
+struct vfio_ccw_regops {
36
+ ssize_t (*read)(struct vfio_ccw_private *private, char __user *buf,
37
+ size_t count, loff_t *ppos);
38
+ ssize_t (*write)(struct vfio_ccw_private *private,
39
+ const char __user *buf, size_t count, loff_t *ppos);
40
+ void (*release)(struct vfio_ccw_private *private,
41
+ struct vfio_ccw_region *region);
42
+};
43
+
44
+struct vfio_ccw_region {
45
+ u32 type;
46
+ u32 subtype;
47
+ const struct vfio_ccw_regops *ops;
48
+ void *data;
49
+ size_t size;
50
+ u32 flags;
51
+};
52
+
53
+int vfio_ccw_register_dev_region(struct vfio_ccw_private *private,
54
+ unsigned int subtype,
55
+ const struct vfio_ccw_regops *ops,
56
+ size_t size, u32 flags, void *data);
57
+void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private);
58
+
59
+int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private);
60
+int vfio_ccw_register_schib_dev_regions(struct vfio_ccw_private *private);
61
+int vfio_ccw_register_crw_dev_regions(struct vfio_ccw_private *private);
62
+
63
+struct vfio_ccw_crw {
64
+ struct list_head next;
65
+ struct crw crw;
66
+};
2167
2268 /**
2369 * struct vfio_ccw_private
....@@ -28,6 +74,12 @@
2874 * @mdev: pointer to the mediated device
2975 * @nb: notifier for vfio events
3076 * @io_region: MMIO region to input/output I/O arguments/results
77
+ * @io_mutex: protect against concurrent update of I/O regions
78
+ * @region: additional regions for other subchannel operations
79
+ * @cmd_region: MMIO region for asynchronous I/O commands other than START
80
+ * @schib_region: MMIO region for SCHIB information
81
+ * @crw_region: MMIO region for getting channel report words
82
+ * @num_regions: number of additional regions
3183 * @cp: channel program for the current I/O operation
3284 * @irb: irb info received from interrupt
3385 * @scsw: scsw info
....@@ -42,13 +94,22 @@
4294 struct mdev_device *mdev;
4395 struct notifier_block nb;
4496 struct ccw_io_region *io_region;
97
+ struct mutex io_mutex;
98
+ struct vfio_ccw_region *region;
99
+ struct ccw_cmd_region *cmd_region;
100
+ struct ccw_schib_region *schib_region;
101
+ struct ccw_crw_region *crw_region;
102
+ int num_regions;
45103
46104 struct channel_program cp;
47105 struct irb irb;
48106 union scsw scsw;
107
+ struct list_head crw;
49108
50109 struct eventfd_ctx *io_trigger;
110
+ struct eventfd_ctx *crw_trigger;
51111 struct work_struct io_work;
112
+ struct work_struct crw_work;
52113 } __aligned(8);
53114
54115 extern int vfio_ccw_mdev_reg(struct subchannel *sch);
....@@ -63,8 +124,8 @@
63124 VFIO_CCW_STATE_NOT_OPER,
64125 VFIO_CCW_STATE_STANDBY,
65126 VFIO_CCW_STATE_IDLE,
66
- VFIO_CCW_STATE_BOXED,
67
- VFIO_CCW_STATE_BUSY,
127
+ VFIO_CCW_STATE_CP_PROCESSING,
128
+ VFIO_CCW_STATE_CP_PENDING,
68129 /* last element! */
69130 NR_VFIO_CCW_STATES
70131 };
....@@ -76,6 +137,7 @@
76137 VFIO_CCW_EVENT_NOT_OPER,
77138 VFIO_CCW_EVENT_IO_REQ,
78139 VFIO_CCW_EVENT_INTERRUPT,
140
+ VFIO_CCW_EVENT_ASYNC_REQ,
79141 /* last element! */
80142 NR_VFIO_CCW_EVENTS
81143 };
....@@ -89,9 +151,26 @@
89151 static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
90152 int event)
91153 {
154
+ trace_vfio_ccw_fsm_event(private->sch->schid, private->state, event);
92155 vfio_ccw_jumptable[private->state][event](private, event);
93156 }
94157
95158 extern struct workqueue_struct *vfio_ccw_work_q;
96159
160
+
161
+/* s390 debug feature, similar to base cio */
162
+extern debug_info_t *vfio_ccw_debug_msg_id;
163
+extern debug_info_t *vfio_ccw_debug_trace_id;
164
+
165
+#define VFIO_CCW_TRACE_EVENT(imp, txt) \
166
+ debug_text_event(vfio_ccw_debug_trace_id, imp, txt)
167
+
168
+#define VFIO_CCW_MSG_EVENT(imp, args...) \
169
+ debug_sprintf_event(vfio_ccw_debug_msg_id, imp, ##args)
170
+
171
+static inline void VFIO_CCW_HEX_EVENT(int level, void *data, int length)
172
+{
173
+ debug_event(vfio_ccw_debug_trace_id, level, data, length);
174
+}
175
+
97176 #endif