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