Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
63f1934d DJS |
2 | /* |
3 | * Private stuff for vfio_ccw driver | |
4 | * | |
5 | * Copyright IBM Corp. 2017 | |
db8e5d17 | 6 | * Copyright Red Hat, Inc. 2019 |
63f1934d DJS |
7 | * |
8 | * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> | |
9 | * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com> | |
db8e5d17 | 10 | * Cornelia Huck <cohuck@redhat.com> |
63f1934d DJS |
11 | */ |
12 | ||
13 | #ifndef _VFIO_CCW_PRIVATE_H_ | |
14 | #define _VFIO_CCW_PRIVATE_H_ | |
15 | ||
4e149e43 | 16 | #include <linux/completion.h> |
120e214e | 17 | #include <linux/eventfd.h> |
e5f84dba | 18 | #include <linux/workqueue.h> |
060d2b5a | 19 | #include <linux/vfio_ccw.h> |
3bf1311f | 20 | #include <linux/vfio.h> |
89345d51 | 21 | #include <linux/mdev.h> |
3f02cb2f | 22 | #include <asm/crw.h> |
60e05d1c | 23 | #include <asm/debug.h> |
060d2b5a | 24 | |
63f1934d | 25 | #include "css.h" |
4e149e43 | 26 | #include "vfio_ccw_cp.h" |
63f1934d | 27 | |
db8e5d17 CH |
28 | #define VFIO_CCW_OFFSET_SHIFT 10 |
29 | #define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT) | |
30 | #define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT) | |
31 | #define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1) | |
32 | ||
33 | /* capability chain handling similar to vfio-pci */ | |
34 | struct vfio_ccw_private; | |
35 | struct vfio_ccw_region; | |
36 | ||
37 | struct vfio_ccw_regops { | |
38 | ssize_t (*read)(struct vfio_ccw_private *private, char __user *buf, | |
39 | size_t count, loff_t *ppos); | |
40 | ssize_t (*write)(struct vfio_ccw_private *private, | |
41 | const char __user *buf, size_t count, loff_t *ppos); | |
42 | void (*release)(struct vfio_ccw_private *private, | |
43 | struct vfio_ccw_region *region); | |
44 | }; | |
45 | ||
46 | struct vfio_ccw_region { | |
47 | u32 type; | |
48 | u32 subtype; | |
49 | const struct vfio_ccw_regops *ops; | |
50 | void *data; | |
51 | size_t size; | |
52 | u32 flags; | |
53 | }; | |
54 | ||
55 | int vfio_ccw_register_dev_region(struct vfio_ccw_private *private, | |
56 | unsigned int subtype, | |
57 | const struct vfio_ccw_regops *ops, | |
58 | size_t size, u32 flags, void *data); | |
600279b5 | 59 | void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private); |
db8e5d17 | 60 | |
d5afd5d1 | 61 | int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private); |
24c98674 | 62 | int vfio_ccw_register_schib_dev_regions(struct vfio_ccw_private *private); |
d8cac29b | 63 | int vfio_ccw_register_crw_dev_regions(struct vfio_ccw_private *private); |
d5afd5d1 | 64 | |
3f02cb2f FA |
65 | struct vfio_ccw_crw { |
66 | struct list_head next; | |
67 | struct crw crw; | |
68 | }; | |
69 | ||
9e6f07cd EF |
70 | /** |
71 | * struct vfio_ccw_parent | |
72 | * | |
73 | * @dev: embedded device struct | |
74 | * @parent: parent data structures for mdevs created | |
75 | * @mdev_type(s): identifying information for mdevs created | |
76 | */ | |
77 | struct vfio_ccw_parent { | |
78 | struct device dev; | |
79 | ||
80 | struct mdev_parent parent; | |
81 | struct mdev_type mdev_type; | |
5dd42419 | 82 | struct mdev_type *mdev_types[]; |
9e6f07cd EF |
83 | }; |
84 | ||
63f1934d DJS |
85 | /** |
86 | * struct vfio_ccw_private | |
3bf1311f | 87 | * @vdev: Embedded VFIO device |
bbe37e4c | 88 | * @state: internal state of the device |
63f1934d | 89 | * @completion: synchronization helper of the I/O completion |
060d2b5a | 90 | * @io_region: MMIO region to input/output I/O arguments/results |
4f766173 | 91 | * @io_mutex: protect against concurrent update of I/O regions |
db8e5d17 | 92 | * @region: additional regions for other subchannel operations |
d5afd5d1 | 93 | * @cmd_region: MMIO region for asynchronous I/O commands other than START |
24c98674 | 94 | * @schib_region: MMIO region for SCHIB information |
d8cac29b | 95 | * @crw_region: MMIO region for getting channel report words |
db8e5d17 | 96 | * @num_regions: number of additional regions |
4e149e43 DJS |
97 | * @cp: channel program for the current I/O operation |
98 | * @irb: irb info received from interrupt | |
99 | * @scsw: scsw info | |
120e214e | 100 | * @io_trigger: eventfd ctx for signaling userspace I/O results |
bccce80b EF |
101 | * @crw_trigger: eventfd ctx for signaling userspace CRW information |
102 | * @req_trigger: eventfd ctx for signaling userspace to return device | |
e5f84dba | 103 | * @io_work: work for deferral process of I/O handling |
bccce80b | 104 | * @crw_work: work for deferral process of CRW handling |
63f1934d DJS |
105 | */ |
106 | struct vfio_ccw_private { | |
3bf1311f | 107 | struct vfio_device vdev; |
bbe37e4c | 108 | int state; |
63f1934d | 109 | struct completion *completion; |
c98e16b2 | 110 | struct ccw_io_region *io_region; |
4f766173 | 111 | struct mutex io_mutex; |
db8e5d17 | 112 | struct vfio_ccw_region *region; |
d5afd5d1 | 113 | struct ccw_cmd_region *cmd_region; |
24c98674 | 114 | struct ccw_schib_region *schib_region; |
d8cac29b | 115 | struct ccw_crw_region *crw_region; |
db8e5d17 | 116 | int num_regions; |
4e149e43 | 117 | |
4e149e43 DJS |
118 | struct channel_program cp; |
119 | struct irb irb; | |
120 | union scsw scsw; | |
3f02cb2f | 121 | struct list_head crw; |
120e214e DJS |
122 | |
123 | struct eventfd_ctx *io_trigger; | |
d8cac29b | 124 | struct eventfd_ctx *crw_trigger; |
bccce80b | 125 | struct eventfd_ctx *req_trigger; |
e5f84dba | 126 | struct work_struct io_work; |
3f02cb2f | 127 | struct work_struct crw_work; |
63f1934d DJS |
128 | } __aligned(8); |
129 | ||
d1877e63 | 130 | int vfio_ccw_sch_quiesce(struct subchannel *sch); |
06caaa27 EF |
131 | void vfio_ccw_sch_io_todo(struct work_struct *work); |
132 | void vfio_ccw_crw_todo(struct work_struct *work); | |
bbe37e4c | 133 | |
3bf1311f JG |
134 | extern struct mdev_driver vfio_ccw_mdev_driver; |
135 | ||
bbe37e4c DJS |
136 | /* |
137 | * States of the device statemachine. | |
138 | */ | |
139 | enum vfio_ccw_state { | |
140 | VFIO_CCW_STATE_NOT_OPER, | |
141 | VFIO_CCW_STATE_STANDBY, | |
142 | VFIO_CCW_STATE_IDLE, | |
690f6a15 CH |
143 | VFIO_CCW_STATE_CP_PROCESSING, |
144 | VFIO_CCW_STATE_CP_PENDING, | |
bbe37e4c DJS |
145 | /* last element! */ |
146 | NR_VFIO_CCW_STATES | |
147 | }; | |
148 | ||
149 | /* | |
150 | * Asynchronous events of the device statemachine. | |
151 | */ | |
152 | enum vfio_ccw_event { | |
153 | VFIO_CCW_EVENT_NOT_OPER, | |
154 | VFIO_CCW_EVENT_IO_REQ, | |
155 | VFIO_CCW_EVENT_INTERRUPT, | |
d5afd5d1 | 156 | VFIO_CCW_EVENT_ASYNC_REQ, |
62ec0d49 | 157 | VFIO_CCW_EVENT_OPEN, |
f4b4ed44 | 158 | VFIO_CCW_EVENT_CLOSE, |
bbe37e4c DJS |
159 | /* last element! */ |
160 | NR_VFIO_CCW_EVENTS | |
161 | }; | |
162 | ||
163 | /* | |
164 | * Action called through jumptable. | |
165 | */ | |
166 | typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event); | |
167 | extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS]; | |
168 | ||
169 | static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private, | |
8557d73b | 170 | enum vfio_ccw_event event) |
bbe37e4c | 171 | { |
008a011d EF |
172 | struct subchannel *sch = to_subchannel(private->vdev.dev->parent); |
173 | ||
174 | if (sch) | |
175 | trace_vfio_ccw_fsm_event(sch->schid, private->state, event); | |
bbe37e4c DJS |
176 | vfio_ccw_jumptable[private->state][event](private, event); |
177 | } | |
178 | ||
179 | extern struct workqueue_struct *vfio_ccw_work_q; | |
06caaa27 EF |
180 | extern struct kmem_cache *vfio_ccw_io_region; |
181 | extern struct kmem_cache *vfio_ccw_cmd_region; | |
182 | extern struct kmem_cache *vfio_ccw_schib_region; | |
183 | extern struct kmem_cache *vfio_ccw_crw_region; | |
60e05d1c CH |
184 | |
185 | /* s390 debug feature, similar to base cio */ | |
186 | extern debug_info_t *vfio_ccw_debug_msg_id; | |
187 | extern debug_info_t *vfio_ccw_debug_trace_id; | |
188 | ||
189 | #define VFIO_CCW_TRACE_EVENT(imp, txt) \ | |
190 | debug_text_event(vfio_ccw_debug_trace_id, imp, txt) | |
191 | ||
192 | #define VFIO_CCW_MSG_EVENT(imp, args...) \ | |
193 | debug_sprintf_event(vfio_ccw_debug_msg_id, imp, ##args) | |
194 | ||
195 | static inline void VFIO_CCW_HEX_EVENT(int level, void *data, int length) | |
196 | { | |
197 | debug_event(vfio_ccw_debug_trace_id, level, data, length); | |
198 | } | |
199 | ||
63f1934d | 200 | #endif |