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 <asm/crw.h>
21#include <asm/debug.h>
22
23#include "css.h"
24#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
32struct vfio_ccw_private;
33struct vfio_ccw_region;
34
35struct 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
44struct 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
53int 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);
57void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private);
58
59int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private);
60int vfio_ccw_register_schib_dev_regions(struct vfio_ccw_private *private);
61int vfio_ccw_register_crw_dev_regions(struct vfio_ccw_private *private);
62
63struct vfio_ccw_crw {
64 struct list_head next;
65 struct crw crw;
66};
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89struct vfio_ccw_private {
90 struct subchannel *sch;
91 int state;
92 struct completion *completion;
93 atomic_t avail;
94 struct mdev_device *mdev;
95 struct notifier_block nb;
96 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;
103
104 struct channel_program cp;
105 struct irb irb;
106 union scsw scsw;
107 struct list_head crw;
108
109 struct eventfd_ctx *io_trigger;
110 struct eventfd_ctx *crw_trigger;
111 struct work_struct io_work;
112 struct work_struct crw_work;
113} __aligned(8);
114
115extern int vfio_ccw_mdev_reg(struct subchannel *sch);
116extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
117
118extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
119
120
121
122
123enum vfio_ccw_state {
124 VFIO_CCW_STATE_NOT_OPER,
125 VFIO_CCW_STATE_STANDBY,
126 VFIO_CCW_STATE_IDLE,
127 VFIO_CCW_STATE_CP_PROCESSING,
128 VFIO_CCW_STATE_CP_PENDING,
129
130 NR_VFIO_CCW_STATES
131};
132
133
134
135
136enum vfio_ccw_event {
137 VFIO_CCW_EVENT_NOT_OPER,
138 VFIO_CCW_EVENT_IO_REQ,
139 VFIO_CCW_EVENT_INTERRUPT,
140 VFIO_CCW_EVENT_ASYNC_REQ,
141
142 NR_VFIO_CCW_EVENTS
143};
144
145
146
147
148typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event);
149extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS];
150
151static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
152 int event)
153{
154 trace_vfio_ccw_fsm_event(private->sch->schid, private->state, event);
155 vfio_ccw_jumptable[private->state][event](private, event);
156}
157
158extern struct workqueue_struct *vfio_ccw_work_q;
159
160
161
162extern debug_info_t *vfio_ccw_debug_msg_id;
163extern 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
171static 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
176#endif
177