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 <linux/genalloc.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 /** 22 * struct ccw1 - channel command word 23 * @cmd_code: command code 24 * @flags: flags, like IDA addressing, etc. 25 * @count: byte count 26 * @cda: data address 27 * 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. 31 */ 32 struct ccw1 { 33 __u8 cmd_code; 34 __u8 flags; 35 __u16 count; 36 __u32 cda; 37 } __attribute__ ((packed,aligned(8))); 38 39 /** 40 * struct ccw0 - channel command word 41 * @cmd_code: command code 42 * @cda: data address 43 * @flags: flags, like IDA addressing, etc. 44 * @reserved: will be ignored 45 * @count: byte count 46 * 47 * The format-0 ccw structure. 48 */ 49 struct ccw0 { 50 __u8 cmd_code; 51 __u32 cda : 24; 52 __u8 flags; 53 __u8 reserved; 54 __u16 count; 55 } __packed __aligned(8); 56 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 64 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 77 78 #define SENSE_MAX_COUNT 0x20 79 80 /** 81 * struct erw - extended report word 82 * @res0: reserved 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 91 * @res16: reserved 92 */ 93 struct erw { 94 __u32 res0 : 3; 95 __u32 auth : 1; 96 __u32 pvrf : 1; 97 __u32 cpt : 1; 98 __u32 fsavf : 1; 99 __u32 cons : 1; 100 __u32 scavf : 1; 101 __u32 fsaf : 1; 102 __u32 scnt : 6; 103 __u32 res16 : 16; 104 } __attribute__ ((packed)); 105 106 /** 107 * struct erw_eadm - EADM Subchannel extended report word 108 * @b: aob error 109 * @r: arsb error 110 */ 111 struct erw_eadm { 112 __u32 : 16; 113 __u32 b : 1; 114 __u32 r : 1; 115 __u32 : 14; 116 } __packed; 117 118 /** 119 * struct sublog - subchannel logout area 120 * @res0: reserved 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 131 */ 132 struct sublog { 133 __u32 res0 : 1; 134 __u32 esf : 7; 135 __u32 lpum : 8; 136 __u32 arep : 1; 137 __u32 fvf : 5; 138 __u32 sacc : 2; 139 __u32 termc : 2; 140 __u32 devsc : 1; 141 __u32 serr : 1; 142 __u32 ioerr : 1; 143 __u32 seqc : 3; 144 } __attribute__ ((packed)); 145 146 /** 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 152 */ 153 struct esw0 { 154 struct sublog sublog; 155 struct erw erw; 156 __u32 faddr[2]; 157 __u32 saddr; 158 } __attribute__ ((packed)); 159 160 /** 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 167 */ 168 struct esw1 { 169 __u8 zero0; 170 __u8 lpum; 171 __u16 zero16; 172 struct erw erw; 173 __u32 zeros[3]; 174 } __attribute__ ((packed)); 175 176 /** 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 183 */ 184 struct esw2 { 185 __u8 zero0; 186 __u8 lpum; 187 __u16 dcti; 188 struct erw erw; 189 __u32 zeros[3]; 190 } __attribute__ ((packed)); 191 192 /** 193 * struct esw3 - Format 3 Extended Status Word (ESW) 194 * @zero0: reserved zeros 195 * @lpum: last path used mask 196 * @res: reserved 197 * @erw: extended report word 198 * @zeros: three fullwords of zeros 199 */ 200 struct esw3 { 201 __u8 zero0; 202 __u8 lpum; 203 __u16 res; 204 struct erw erw; 205 __u32 zeros[3]; 206 } __attribute__ ((packed)); 207 208 /** 209 * struct esw_eadm - EADM Subchannel Extended Status Word (ESW) 210 * @sublog: subchannel logout 211 * @erw: extended report word 212 */ 213 struct esw_eadm { 214 __u32 sublog; 215 struct erw_eadm erw; 216 __u32 : 32; 217 __u32 : 32; 218 __u32 : 32; 219 } __packed; 220 221 /** 222 * struct irb - interruption response block 223 * @scsw: subchannel status word 224 * @esw: extended status word 225 * @ecw: extended control word 226 * 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, 234 * if applicable). 235 */ 236 struct irb { 237 union scsw scsw; 238 union { 239 struct esw0 esw0; 240 struct esw1 esw1; 241 struct esw2 esw2; 242 struct esw3 esw3; 243 struct esw_eadm eadm; 244 } esw; 245 __u8 ecw[32]; 246 } __attribute__ ((packed,aligned(4))); 247 248 /** 249 * struct ciw - command information word (CIW) layout 250 * @et: entry type 251 * @reserved: reserved bits 252 * @ct: command type 253 * @cmd: command code 254 * @count: command count 255 */ 256 struct ciw { 257 __u32 et : 2; 258 __u32 reserved : 2; 259 __u32 ct : 4; 260 __u32 cmd : 8; 261 __u32 count : 16; 262 } __attribute__ ((packed)); 263 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 */ 267 268 /* 269 * Node Descriptor as defined in SA22-7204, "Common I/O-Device Commands" 270 */ 271 272 #define ND_VALIDITY_VALID 0 273 #define ND_VALIDITY_OUTDATED 1 274 #define ND_VALIDITY_INVALID 2 275 276 struct node_descriptor { 277 /* Flags. */ 278 union { 279 struct { 280 u32 validity:3; 281 u32 reserved:5; 282 } __packed; 283 u8 byte0; 284 } __packed; 285 286 /* Node parameters. */ 287 u32 params:24; 288 289 /* Node ID. */ 290 char type[6]; 291 char model[3]; 292 char manufacturer[3]; 293 char plant[2]; 294 char seq[12]; 295 u16 tag; 296 } __packed; 297 298 /* 299 * Flags used as input parameters for do_IO() 300 */ 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 315 316 /** 317 * struct ccw_dev_id - unique identifier for ccw devices 318 * @ssid: subchannel set id 319 * @devno: device number 320 * 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 325 * introduced. 326 */ 327 struct ccw_dev_id { 328 u8 ssid; 329 u16 devno; 330 }; 331 332 /** 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 336 * Returns: 337 * %1 if the two structures are equal field-by-field, 338 * %0 if not. 339 * Context: 340 * any 341 */ 342 static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1, 343 struct ccw_dev_id *dev_id2) 344 { 345 if ((dev_id1->ssid == dev_id2->ssid) && 346 (dev_id1->devno == dev_id2->devno)) 347 return 1; 348 return 0; 349 } 350 351 /** 352 * pathmask_to_pos() - find the position of the left-most bit in a pathmask 353 * @mask: pathmask with at least one bit set 354 */ 355 static inline u8 pathmask_to_pos(u8 mask) 356 { 357 return 8 - ffs(mask); 358 } 359 360 extern void css_schedule_reprobe(void); 361 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); 365 366 void *cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev, 367 size_t size); 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); 371 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); 378 379 #endif 380