1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _VFIO_CCW_PRIVATE_H_
14#define _VFIO_CCW_PRIVATE_H_
15
16#include <linux/completion.h>
17#include <linux/eventfd.h>
18#include <linux/workqueue.h>
19#include <linux/vfio_ccw.h>
20#include <linux/vfio.h>
21#include <asm/crw.h>
22#include <asm/debug.h>
23
24#include "css.h"
25#include "vfio_ccw_cp.h"
26
27#define VFIO_CCW_OFFSET_SHIFT 10
28#define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT)
29#define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT)
30#define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1)
31
32
33struct vfio_ccw_private;
34struct vfio_ccw_region;
35
36struct vfio_ccw_regops {
37 ssize_t (*read)(struct vfio_ccw_private *private, char __user *buf,
38 size_t count, loff_t *ppos);
39 ssize_t (*write)(struct vfio_ccw_private *private,
40 const char __user *buf, size_t count, loff_t *ppos);
41 void (*release)(struct vfio_ccw_private *private,
42 struct vfio_ccw_region *region);
43};
44
45struct vfio_ccw_region {
46 u32 type;
47 u32 subtype;
48 const struct vfio_ccw_regops *ops;
49 void *data;
50 size_t size;
51 u32 flags;
52};
53
54int vfio_ccw_register_dev_region(struct vfio_ccw_private *private,
55 unsigned int subtype,
56 const struct vfio_ccw_regops *ops,
57 size_t size, u32 flags, void *data);
58void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private);
59
60int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private);
61int vfio_ccw_register_schib_dev_regions(struct vfio_ccw_private *private);
62int vfio_ccw_register_crw_dev_regions(struct vfio_ccw_private *private);
63
64struct vfio_ccw_crw {
65 struct list_head next;
66 struct crw crw;
67};
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94struct vfio_ccw_private {
95 struct vfio_device vdev;
96 struct subchannel *sch;
97 int state;
98 struct completion *completion;
99 atomic_t avail;
100 struct mdev_device *mdev;
101 struct notifier_block nb;
102 struct ccw_io_region *io_region;
103 struct mutex io_mutex;
104 struct vfio_ccw_region *region;
105 struct ccw_cmd_region *cmd_region;
106 struct ccw_schib_region *schib_region;
107 struct ccw_crw_region *crw_region;
108 int num_regions;
109
110 struct channel_program cp;
111 struct irb irb;
112 union scsw scsw;
113 struct list_head crw;
114
115 struct eventfd_ctx *io_trigger;
116 struct eventfd_ctx *crw_trigger;
117 struct eventfd_ctx *req_trigger;
118 struct work_struct io_work;
119 struct work_struct crw_work;
120} __aligned(8);
121
122extern int vfio_ccw_mdev_reg(struct subchannel *sch);
123extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
124
125extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
126
127extern struct mdev_driver vfio_ccw_mdev_driver;
128
129
130
131
132enum vfio_ccw_state {
133 VFIO_CCW_STATE_NOT_OPER,
134 VFIO_CCW_STATE_STANDBY,
135 VFIO_CCW_STATE_IDLE,
136 VFIO_CCW_STATE_CP_PROCESSING,
137 VFIO_CCW_STATE_CP_PENDING,
138
139 NR_VFIO_CCW_STATES
140};
141
142
143
144
145enum vfio_ccw_event {
146 VFIO_CCW_EVENT_NOT_OPER,
147 VFIO_CCW_EVENT_IO_REQ,
148 VFIO_CCW_EVENT_INTERRUPT,
149 VFIO_CCW_EVENT_ASYNC_REQ,
150
151 NR_VFIO_CCW_EVENTS
152};
153
154
155
156
157typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event);
158extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS];
159
160static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
161 int event)
162{
163 trace_vfio_ccw_fsm_event(private->sch->schid, private->state, event);
164 vfio_ccw_jumptable[private->state][event](private, event);
165}
166
167extern struct workqueue_struct *vfio_ccw_work_q;
168
169
170
171extern debug_info_t *vfio_ccw_debug_msg_id;
172extern debug_info_t *vfio_ccw_debug_trace_id;
173
174#define VFIO_CCW_TRACE_EVENT(imp, txt) \
175 debug_text_event(vfio_ccw_debug_trace_id, imp, txt)
176
177#define VFIO_CCW_MSG_EVENT(imp, args...) \
178 debug_sprintf_event(vfio_ccw_debug_msg_id, imp, ##args)
179
180static inline void VFIO_CCW_HEX_EVENT(int level, void *data, int length)
181{
182 debug_event(vfio_ccw_debug_trace_id, level, data, length);
183}
184
185#endif
186