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