1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Common interface for I/O on S/390
5 #ifndef _ASM_S390_CIO_H_
6 #define _ASM_S390_CIO_H_
8 #include <linux/spinlock.h>
9 #include <linux/bitops.h>
10 #include <linux/genalloc.h>
11 #include <asm/types.h>
14 #define LPM_ANYPATH 0xff
16 #define __MAX_SUBCHANNEL 65535
22 * struct ccw1 - channel command word
23 * @cmd_code: command code
24 * @flags: flags, like IDA addressing, etc.
28 * The ccw is the basic structure to build channel programs that perform
29 * operations with the device or the control unit. Only Format-1 channel
30 * command words are supported.
37 } __attribute__ ((packed,aligned(8)));
40 * struct ccw0 - channel command word
41 * @cmd_code: command code
43 * @flags: flags, like IDA addressing, etc.
44 * @reserved: will be ignored
47 * The format-0 ccw structure.
55 } __packed __aligned(8);
57 #define CCW_FLAG_DC 0x80
58 #define CCW_FLAG_CC 0x40
59 #define CCW_FLAG_SLI 0x20
60 #define CCW_FLAG_SKIP 0x10
61 #define CCW_FLAG_PCI 0x08
62 #define CCW_FLAG_IDA 0x04
63 #define CCW_FLAG_SUSPEND 0x02
65 #define CCW_CMD_READ_IPL 0x02
66 #define CCW_CMD_NOOP 0x03
67 #define CCW_CMD_BASIC_SENSE 0x04
68 #define CCW_CMD_TIC 0x08
69 #define CCW_CMD_STLCK 0x14
70 #define CCW_CMD_SENSE_PGID 0x34
71 #define CCW_CMD_SUSPEND_RECONN 0x5B
72 #define CCW_CMD_RDC 0x64
73 #define CCW_CMD_RELEASE 0x94
74 #define CCW_CMD_SET_PGID 0xAF
75 #define CCW_CMD_SENSE_ID 0xE4
76 #define CCW_CMD_DCTL 0xF3
78 #define SENSE_MAX_COUNT 0x20
81 * struct erw - extended report word
83 * @auth: authorization check
84 * @pvrf: path-verification-required flag
85 * @cpt: channel-path timeout
86 * @fsavf: failing storage address validity flag
87 * @cons: concurrent sense
88 * @scavf: secondary ccw address validity flag
89 * @fsaf: failing storage address format
90 * @scnt: sense count, if @cons == %1
104 } __attribute__ ((packed));
107 * struct erw_eadm - EADM Subchannel extended report word
119 * struct sublog - subchannel logout area
121 * @esf: extended status flags
122 * @lpum: last path used mask
123 * @arep: ancillary report
124 * @fvf: field-validity flags
125 * @sacc: storage access code
126 * @termc: termination code
127 * @devsc: device-status check
128 * @serr: secondary error
129 * @ioerr: i/o-error alert
130 * @seqc: sequence code
144 } __attribute__ ((packed));
147 * struct esw0 - Format 0 Extended Status Word (ESW)
148 * @sublog: subchannel logout
149 * @erw: extended report word
150 * @faddr: failing storage address
151 * @saddr: secondary ccw address
154 struct sublog sublog;
158 } __attribute__ ((packed));
161 * struct esw1 - Format 1 Extended Status Word (ESW)
162 * @zero0: reserved zeros
163 * @lpum: last path used mask
164 * @zero16: reserved zeros
165 * @erw: extended report word
166 * @zeros: three fullwords of zeros
174 } __attribute__ ((packed));
177 * struct esw2 - Format 2 Extended Status Word (ESW)
178 * @zero0: reserved zeros
179 * @lpum: last path used mask
180 * @dcti: device-connect-time interval
181 * @erw: extended report word
182 * @zeros: three fullwords of zeros
190 } __attribute__ ((packed));
193 * struct esw3 - Format 3 Extended Status Word (ESW)
194 * @zero0: reserved zeros
195 * @lpum: last path used mask
197 * @erw: extended report word
198 * @zeros: three fullwords of zeros
206 } __attribute__ ((packed));
209 * struct esw_eadm - EADM Subchannel Extended Status Word (ESW)
210 * @sublog: subchannel logout
211 * @erw: extended report word
222 * struct irb - interruption response block
223 * @scsw: subchannel status word
224 * @esw: extended status word
225 * @ecw: extended control word
227 * The irb that is handed to the device driver when an interrupt occurs. For
228 * solicited interrupts, the common I/O layer already performs checks whether
229 * a field is valid; a field not being valid is always passed as %0.
230 * If a unit check occurred, @ecw may contain sense data; this is retrieved
231 * by the common I/O layer itself if the device doesn't support concurrent
232 * sense (so that the device driver never needs to perform basic sense itself).
233 * For unsolicited interrupts, the irb is passed as-is (expect for sense data,
243 struct esw_eadm eadm;
246 } __attribute__ ((packed,aligned(4)));
249 * struct ciw - command information word (CIW) layout
251 * @reserved: reserved bits
254 * @count: command count
262 } __attribute__ ((packed));
264 #define CIW_TYPE_RCD 0x0 /* read configuration data */
265 #define CIW_TYPE_SII 0x1 /* set interface identifier */
266 #define CIW_TYPE_RNI 0x2 /* read node identifier */
269 * Node Descriptor as defined in SA22-7204, "Common I/O-Device Commands"
272 #define ND_VALIDITY_VALID 0
273 #define ND_VALIDITY_OUTDATED 1
274 #define ND_VALIDITY_INVALID 2
276 struct node_descriptor {
286 /* Node parameters. */
292 char manufacturer[3];
299 * Flags used as input parameters for do_IO()
301 #define DOIO_ALLOW_SUSPEND 0x0001 /* allow for channel prog. suspend */
302 #define DOIO_DENY_PREFETCH 0x0002 /* don't allow for CCW prefetch */
303 #define DOIO_SUPPRESS_INTER 0x0004 /* suppress intermediate inter. */
304 /* ... for suspended CCWs */
305 /* Device or subchannel gone. */
306 #define CIO_GONE 0x0001
307 /* No path to device. */
308 #define CIO_NO_PATH 0x0002
309 /* Device has appeared. */
310 #define CIO_OPER 0x0004
311 /* Sick revalidation of device. */
312 #define CIO_REVALIDATE 0x0008
313 /* Device did not respond in time. */
314 #define CIO_BOXED 0x0010
317 * struct ccw_dev_id - unique identifier for ccw devices
318 * @ssid: subchannel set id
319 * @devno: device number
321 * This structure is not directly based on any hardware structure. The
322 * hardware identifies a device by its device number and its subchannel,
323 * which is in turn identified by its id. In order to get a unique identifier
324 * for ccw devices across subchannel sets, @struct ccw_dev_id has been
333 * ccw_dev_id_is_equal() - compare two ccw_dev_ids
334 * @dev_id1: a ccw_dev_id
335 * @dev_id2: another ccw_dev_id
337 * %1 if the two structures are equal field-by-field,
342 static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,
343 struct ccw_dev_id *dev_id2)
345 if ((dev_id1->ssid == dev_id2->ssid) &&
346 (dev_id1->devno == dev_id2->devno))
352 * pathmask_to_pos() - find the position of the left-most bit in a pathmask
353 * @mask: pathmask with at least one bit set
355 static inline u8 pathmask_to_pos(u8 mask)
357 return 8 - ffs(mask);
360 extern void css_schedule_reprobe(void);
362 extern void *cio_dma_zalloc(size_t size);
363 extern void cio_dma_free(void *cpu_addr, size_t size);
364 extern struct device *cio_get_dma_css_dev(void);
366 void *cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,
368 void cio_gp_dma_free(struct gen_pool *gp_dma, void *cpu_addr, size_t size);
369 void cio_gp_dma_destroy(struct gen_pool *gp_dma, struct device *dma_dev);
370 struct gen_pool *cio_gp_dma_create(struct device *dma_dev, int nr_pages);
372 /* Function from drivers/s390/cio/chsc.c */
373 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta);
374 int chsc_sstpi(void *page, void *result, size_t size);
375 int chsc_stzi(void *page, void *result, size_t size);
376 int chsc_sgib(u32 origin);
377 int chsc_scud(u16 cu, u64 *esm, u8 *esm_valid);