xref: /linux/arch/s390/include/asm/cio.h (revision 3bdab16c55f57a24245c97d707241dd9b48d1a91)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Common interface for I/O on S/390
4  */
5 #ifndef _ASM_S390_CIO_H_
6 #define _ASM_S390_CIO_H_
7 
8 #include <linux/spinlock.h>
9 #include <linux/bitops.h>
10 #include <asm/types.h>
11 
12 #define LPM_ANYPATH 0xff
13 #define __MAX_CSSID 0
14 #define __MAX_SUBCHANNEL 65535
15 #define __MAX_SSID 3
16 
17 #include <asm/scsw.h>
18 
19 /**
20  * struct ccw1 - channel command word
21  * @cmd_code: command code
22  * @flags: flags, like IDA addressing, etc.
23  * @count: byte count
24  * @cda: data address
25  *
26  * The ccw is the basic structure to build channel programs that perform
27  * operations with the device or the control unit. Only Format-1 channel
28  * command words are supported.
29  */
30 struct ccw1 {
31 	__u8  cmd_code;
32 	__u8  flags;
33 	__u16 count;
34 	__u32 cda;
35 } __attribute__ ((packed,aligned(8)));
36 
37 /**
38  * struct ccw0 - channel command word
39  * @cmd_code: command code
40  * @cda: data address
41  * @flags: flags, like IDA addressing, etc.
42  * @reserved: will be ignored
43  * @count: byte count
44  *
45  * The format-0 ccw structure.
46  */
47 struct ccw0 {
48 	__u8 cmd_code;
49 	__u32 cda : 24;
50 	__u8  flags;
51 	__u8  reserved;
52 	__u16 count;
53 } __packed __aligned(8);
54 
55 #define CCW_FLAG_DC		0x80
56 #define CCW_FLAG_CC		0x40
57 #define CCW_FLAG_SLI		0x20
58 #define CCW_FLAG_SKIP		0x10
59 #define CCW_FLAG_PCI		0x08
60 #define CCW_FLAG_IDA		0x04
61 #define CCW_FLAG_SUSPEND	0x02
62 
63 #define CCW_CMD_READ_IPL	0x02
64 #define CCW_CMD_NOOP		0x03
65 #define CCW_CMD_BASIC_SENSE	0x04
66 #define CCW_CMD_TIC		0x08
67 #define CCW_CMD_STLCK           0x14
68 #define CCW_CMD_SENSE_PGID	0x34
69 #define CCW_CMD_SUSPEND_RECONN	0x5B
70 #define CCW_CMD_RDC		0x64
71 #define CCW_CMD_RELEASE		0x94
72 #define CCW_CMD_SET_PGID	0xAF
73 #define CCW_CMD_SENSE_ID	0xE4
74 #define CCW_CMD_DCTL		0xF3
75 
76 #define SENSE_MAX_COUNT		0x20
77 
78 /**
79  * struct erw - extended report word
80  * @res0: reserved
81  * @auth: authorization check
82  * @pvrf: path-verification-required flag
83  * @cpt: channel-path timeout
84  * @fsavf: failing storage address validity flag
85  * @cons: concurrent sense
86  * @scavf: secondary ccw address validity flag
87  * @fsaf: failing storage address format
88  * @scnt: sense count, if @cons == %1
89  * @res16: reserved
90  */
91 struct erw {
92 	__u32 res0  : 3;
93 	__u32 auth  : 1;
94 	__u32 pvrf  : 1;
95 	__u32 cpt   : 1;
96 	__u32 fsavf : 1;
97 	__u32 cons  : 1;
98 	__u32 scavf : 1;
99 	__u32 fsaf  : 1;
100 	__u32 scnt  : 6;
101 	__u32 res16 : 16;
102 } __attribute__ ((packed));
103 
104 /**
105  * struct erw_eadm - EADM Subchannel extended report word
106  * @b: aob error
107  * @r: arsb error
108  */
109 struct erw_eadm {
110 	__u32 : 16;
111 	__u32 b : 1;
112 	__u32 r : 1;
113 	__u32  : 14;
114 } __packed;
115 
116 /**
117  * struct sublog - subchannel logout area
118  * @res0: reserved
119  * @esf: extended status flags
120  * @lpum: last path used mask
121  * @arep: ancillary report
122  * @fvf: field-validity flags
123  * @sacc: storage access code
124  * @termc: termination code
125  * @devsc: device-status check
126  * @serr: secondary error
127  * @ioerr: i/o-error alert
128  * @seqc: sequence code
129  */
130 struct sublog {
131 	__u32 res0  : 1;
132 	__u32 esf   : 7;
133 	__u32 lpum  : 8;
134 	__u32 arep  : 1;
135 	__u32 fvf   : 5;
136 	__u32 sacc  : 2;
137 	__u32 termc : 2;
138 	__u32 devsc : 1;
139 	__u32 serr  : 1;
140 	__u32 ioerr : 1;
141 	__u32 seqc  : 3;
142 } __attribute__ ((packed));
143 
144 /**
145  * struct esw0 - Format 0 Extended Status Word (ESW)
146  * @sublog: subchannel logout
147  * @erw: extended report word
148  * @faddr: failing storage address
149  * @saddr: secondary ccw address
150  */
151 struct esw0 {
152 	struct sublog sublog;
153 	struct erw erw;
154 	__u32  faddr[2];
155 	__u32  saddr;
156 } __attribute__ ((packed));
157 
158 /**
159  * struct esw1 - Format 1 Extended Status Word (ESW)
160  * @zero0: reserved zeros
161  * @lpum: last path used mask
162  * @zero16: reserved zeros
163  * @erw: extended report word
164  * @zeros: three fullwords of zeros
165  */
166 struct esw1 {
167 	__u8  zero0;
168 	__u8  lpum;
169 	__u16 zero16;
170 	struct erw erw;
171 	__u32 zeros[3];
172 } __attribute__ ((packed));
173 
174 /**
175  * struct esw2 - Format 2 Extended Status Word (ESW)
176  * @zero0: reserved zeros
177  * @lpum: last path used mask
178  * @dcti: device-connect-time interval
179  * @erw: extended report word
180  * @zeros: three fullwords of zeros
181  */
182 struct esw2 {
183 	__u8  zero0;
184 	__u8  lpum;
185 	__u16 dcti;
186 	struct erw erw;
187 	__u32 zeros[3];
188 } __attribute__ ((packed));
189 
190 /**
191  * struct esw3 - Format 3 Extended Status Word (ESW)
192  * @zero0: reserved zeros
193  * @lpum: last path used mask
194  * @res: reserved
195  * @erw: extended report word
196  * @zeros: three fullwords of zeros
197  */
198 struct esw3 {
199 	__u8  zero0;
200 	__u8  lpum;
201 	__u16 res;
202 	struct erw erw;
203 	__u32 zeros[3];
204 } __attribute__ ((packed));
205 
206 /**
207  * struct esw_eadm - EADM Subchannel Extended Status Word (ESW)
208  * @sublog: subchannel logout
209  * @erw: extended report word
210  */
211 struct esw_eadm {
212 	__u32 sublog;
213 	struct erw_eadm erw;
214 	__u32 : 32;
215 	__u32 : 32;
216 	__u32 : 32;
217 } __packed;
218 
219 /**
220  * struct irb - interruption response block
221  * @scsw: subchannel status word
222  * @esw: extended status word
223  * @ecw: extended control word
224  *
225  * The irb that is handed to the device driver when an interrupt occurs. For
226  * solicited interrupts, the common I/O layer already performs checks whether
227  * a field is valid; a field not being valid is always passed as %0.
228  * If a unit check occurred, @ecw may contain sense data; this is retrieved
229  * by the common I/O layer itself if the device doesn't support concurrent
230  * sense (so that the device driver never needs to perform basic sense itself).
231  * For unsolicited interrupts, the irb is passed as-is (expect for sense data,
232  * if applicable).
233  */
234 struct irb {
235 	union scsw scsw;
236 	union {
237 		struct esw0 esw0;
238 		struct esw1 esw1;
239 		struct esw2 esw2;
240 		struct esw3 esw3;
241 		struct esw_eadm eadm;
242 	} esw;
243 	__u8   ecw[32];
244 } __attribute__ ((packed,aligned(4)));
245 
246 /**
247  * struct ciw - command information word  (CIW) layout
248  * @et: entry type
249  * @reserved: reserved bits
250  * @ct: command type
251  * @cmd: command code
252  * @count: command count
253  */
254 struct ciw {
255 	__u32 et       :  2;
256 	__u32 reserved :  2;
257 	__u32 ct       :  4;
258 	__u32 cmd      :  8;
259 	__u32 count    : 16;
260 } __attribute__ ((packed));
261 
262 #define CIW_TYPE_RCD	0x0    	/* read configuration data */
263 #define CIW_TYPE_SII	0x1    	/* set interface identifier */
264 #define CIW_TYPE_RNI	0x2    	/* read node identifier */
265 
266 /*
267  * Flags used as input parameters for do_IO()
268  */
269 #define DOIO_ALLOW_SUSPEND	 0x0001 /* allow for channel prog. suspend */
270 #define DOIO_DENY_PREFETCH	 0x0002 /* don't allow for CCW prefetch */
271 #define DOIO_SUPPRESS_INTER	 0x0004 /* suppress intermediate inter. */
272 					/* ... for suspended CCWs */
273 /* Device or subchannel gone. */
274 #define CIO_GONE       0x0001
275 /* No path to device. */
276 #define CIO_NO_PATH    0x0002
277 /* Device has appeared. */
278 #define CIO_OPER       0x0004
279 /* Sick revalidation of device. */
280 #define CIO_REVALIDATE 0x0008
281 /* Device did not respond in time. */
282 #define CIO_BOXED      0x0010
283 
284 /**
285  * struct ccw_dev_id - unique identifier for ccw devices
286  * @ssid: subchannel set id
287  * @devno: device number
288  *
289  * This structure is not directly based on any hardware structure. The
290  * hardware identifies a device by its device number and its subchannel,
291  * which is in turn identified by its id. In order to get a unique identifier
292  * for ccw devices across subchannel sets, @struct ccw_dev_id has been
293  * introduced.
294  */
295 struct ccw_dev_id {
296 	u8 ssid;
297 	u16 devno;
298 };
299 
300 /**
301  * ccw_device_id_is_equal() - compare two ccw_dev_ids
302  * @dev_id1: a ccw_dev_id
303  * @dev_id2: another ccw_dev_id
304  * Returns:
305  *  %1 if the two structures are equal field-by-field,
306  *  %0 if not.
307  * Context:
308  *  any
309  */
310 static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,
311 				      struct ccw_dev_id *dev_id2)
312 {
313 	if ((dev_id1->ssid == dev_id2->ssid) &&
314 	    (dev_id1->devno == dev_id2->devno))
315 		return 1;
316 	return 0;
317 }
318 
319 /**
320  * pathmask_to_pos() - find the position of the left-most bit in a pathmask
321  * @mask: pathmask with at least one bit set
322  */
323 static inline u8 pathmask_to_pos(u8 mask)
324 {
325 	return 8 - ffs(mask);
326 }
327 
328 void channel_subsystem_reinit(void);
329 extern void css_schedule_reprobe(void);
330 
331 /* Function from drivers/s390/cio/chsc.c */
332 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta);
333 int chsc_sstpi(void *page, void *result, size_t size);
334 int chsc_sgib(u32 origin);
335 
336 #endif
337