1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Helper functions for scsw access.
4  *
5  *    Copyright IBM Corp. 2008, 2012
6  *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
7  */
8 
9 #ifndef _ASM_S390_SCSW_H_
10 #define _ASM_S390_SCSW_H_
11 
12 #include <linux/types.h>
13 #include <asm/css_chars.h>
14 #include <asm/cio.h>
15 
16 /**
17  * struct cmd_scsw - command-mode subchannel status word
18  * @key: subchannel key
19  * @sctl: suspend control
20  * @eswf: esw format
21  * @cc: deferred condition code
22  * @fmt: format
23  * @pfch: prefetch
24  * @isic: initial-status interruption control
25  * @alcc: address-limit checking control
26  * @ssi: suppress-suspended interruption
27  * @zcc: zero condition code
28  * @ectl: extended control
29  * @pno: path not operational
30  * @res: reserved
31  * @fctl: function control
32  * @actl: activity control
33  * @stctl: status control
34  * @cpa: channel program address
35  * @dstat: device status
36  * @cstat: subchannel status
37  * @count: residual count
38  */
39 struct cmd_scsw {
40 	__u32 key  : 4;
41 	__u32 sctl : 1;
42 	__u32 eswf : 1;
43 	__u32 cc   : 2;
44 	__u32 fmt  : 1;
45 	__u32 pfch : 1;
46 	__u32 isic : 1;
47 	__u32 alcc : 1;
48 	__u32 ssi  : 1;
49 	__u32 zcc  : 1;
50 	__u32 ectl : 1;
51 	__u32 pno  : 1;
52 	__u32 res  : 1;
53 	__u32 fctl : 3;
54 	__u32 actl : 7;
55 	__u32 stctl : 5;
56 	__u32 cpa;
57 	__u32 dstat : 8;
58 	__u32 cstat : 8;
59 	__u32 count : 16;
60 } __attribute__ ((packed));
61 
62 /**
63  * struct tm_scsw - transport-mode subchannel status word
64  * @key: subchannel key
65  * @eswf: esw format
66  * @cc: deferred condition code
67  * @fmt: format
68  * @x: IRB-format control
69  * @q: interrogate-complete
70  * @ectl: extended control
71  * @pno: path not operational
72  * @fctl: function control
73  * @actl: activity control
74  * @stctl: status control
75  * @tcw: TCW address
76  * @dstat: device status
77  * @cstat: subchannel status
78  * @fcxs: FCX status
79  * @schxs: subchannel-extended status
80  */
81 struct tm_scsw {
82 	u32 key:4;
83 	u32 :1;
84 	u32 eswf:1;
85 	u32 cc:2;
86 	u32 fmt:3;
87 	u32 x:1;
88 	u32 q:1;
89 	u32 :1;
90 	u32 ectl:1;
91 	u32 pno:1;
92 	u32 :1;
93 	u32 fctl:3;
94 	u32 actl:7;
95 	u32 stctl:5;
96 	u32 tcw;
97 	u32 dstat:8;
98 	u32 cstat:8;
99 	u32 fcxs:8;
100 	u32 ifob:1;
101 	u32 sesq:7;
102 } __attribute__ ((packed));
103 
104 /**
105  * struct eadm_scsw - subchannel status word for eadm subchannels
106  * @key: subchannel key
107  * @eswf: esw format
108  * @cc: deferred condition code
109  * @ectl: extended control
110  * @fctl: function control
111  * @actl: activity control
112  * @stctl: status control
113  * @aob: AOB address
114  * @dstat: device status
115  * @cstat: subchannel status
116  */
117 struct eadm_scsw {
118 	u32 key:4;
119 	u32:1;
120 	u32 eswf:1;
121 	u32 cc:2;
122 	u32:6;
123 	u32 ectl:1;
124 	u32:2;
125 	u32 fctl:3;
126 	u32 actl:7;
127 	u32 stctl:5;
128 	u32 aob;
129 	u32 dstat:8;
130 	u32 cstat:8;
131 	u32:16;
132 } __packed;
133 
134 /**
135  * union scsw - subchannel status word
136  * @cmd: command-mode SCSW
137  * @tm: transport-mode SCSW
138  * @eadm: eadm SCSW
139  */
140 union scsw {
141 	struct cmd_scsw cmd;
142 	struct tm_scsw tm;
143 	struct eadm_scsw eadm;
144 } __packed;
145 
146 #define SCSW_FCTL_CLEAR_FUNC	 0x1
147 #define SCSW_FCTL_HALT_FUNC	 0x2
148 #define SCSW_FCTL_START_FUNC	 0x4
149 
150 #define SCSW_ACTL_SUSPENDED	 0x1
151 #define SCSW_ACTL_DEVACT	 0x2
152 #define SCSW_ACTL_SCHACT	 0x4
153 #define SCSW_ACTL_CLEAR_PEND	 0x8
154 #define SCSW_ACTL_HALT_PEND	 0x10
155 #define SCSW_ACTL_START_PEND	 0x20
156 #define SCSW_ACTL_RESUME_PEND	 0x40
157 
158 #define SCSW_STCTL_STATUS_PEND	 0x1
159 #define SCSW_STCTL_SEC_STATUS	 0x2
160 #define SCSW_STCTL_PRIM_STATUS	 0x4
161 #define SCSW_STCTL_INTER_STATUS	 0x8
162 #define SCSW_STCTL_ALERT_STATUS	 0x10
163 
164 #define DEV_STAT_ATTENTION	 0x80
165 #define DEV_STAT_STAT_MOD	 0x40
166 #define DEV_STAT_CU_END		 0x20
167 #define DEV_STAT_BUSY		 0x10
168 #define DEV_STAT_CHN_END	 0x08
169 #define DEV_STAT_DEV_END	 0x04
170 #define DEV_STAT_UNIT_CHECK	 0x02
171 #define DEV_STAT_UNIT_EXCEP	 0x01
172 
173 #define SCHN_STAT_PCI		 0x80
174 #define SCHN_STAT_INCORR_LEN	 0x40
175 #define SCHN_STAT_PROG_CHECK	 0x20
176 #define SCHN_STAT_PROT_CHECK	 0x10
177 #define SCHN_STAT_CHN_DATA_CHK	 0x08
178 #define SCHN_STAT_CHN_CTRL_CHK	 0x04
179 #define SCHN_STAT_INTF_CTRL_CHK	 0x02
180 #define SCHN_STAT_CHAIN_CHECK	 0x01
181 
182 #define SCSW_SESQ_DEV_NOFCX	 3
183 #define SCSW_SESQ_PATH_NOFCX	 4
184 
185 /*
186  * architectured values for first sense byte
187  */
188 #define SNS0_CMD_REJECT		0x80
189 #define SNS_CMD_REJECT		SNS0_CMD_REJEC
190 #define SNS0_INTERVENTION_REQ	0x40
191 #define SNS0_BUS_OUT_CHECK	0x20
192 #define SNS0_EQUIPMENT_CHECK	0x10
193 #define SNS0_DATA_CHECK		0x08
194 #define SNS0_OVERRUN		0x04
195 #define SNS0_INCOMPL_DOMAIN	0x01
196 
197 /*
198  * architectured values for second sense byte
199  */
200 #define SNS1_PERM_ERR		0x80
201 #define SNS1_INV_TRACK_FORMAT	0x40
202 #define SNS1_EOC		0x20
203 #define SNS1_MESSAGE_TO_OPER	0x10
204 #define SNS1_NO_REC_FOUND	0x08
205 #define SNS1_FILE_PROTECTED	0x04
206 #define SNS1_WRITE_INHIBITED	0x02
207 #define SNS1_INPRECISE_END	0x01
208 
209 /*
210  * architectured values for third sense byte
211  */
212 #define SNS2_REQ_INH_WRITE	0x80
213 #define SNS2_CORRECTABLE	0x40
214 #define SNS2_FIRST_LOG_ERR	0x20
215 #define SNS2_ENV_DATA_PRESENT	0x10
216 #define SNS2_INPRECISE_END	0x04
217 
218 /**
219  * scsw_is_tm - check for transport mode scsw
220  * @scsw: pointer to scsw
221  *
222  * Return non-zero if the specified scsw is a transport mode scsw, zero
223  * otherwise.
224  */
scsw_is_tm(union scsw * scsw)225 static inline int scsw_is_tm(union scsw *scsw)
226 {
227 	return css_general_characteristics.fcx && (scsw->tm.x == 1);
228 }
229 
230 /**
231  * scsw_key - return scsw key field
232  * @scsw: pointer to scsw
233  *
234  * Return the value of the key field of the specified scsw, regardless of
235  * whether it is a transport mode or command mode scsw.
236  */
scsw_key(union scsw * scsw)237 static inline u32 scsw_key(union scsw *scsw)
238 {
239 	if (scsw_is_tm(scsw))
240 		return scsw->tm.key;
241 	else
242 		return scsw->cmd.key;
243 }
244 
245 /**
246  * scsw_eswf - return scsw eswf field
247  * @scsw: pointer to scsw
248  *
249  * Return the value of the eswf field of the specified scsw, regardless of
250  * whether it is a transport mode or command mode scsw.
251  */
scsw_eswf(union scsw * scsw)252 static inline u32 scsw_eswf(union scsw *scsw)
253 {
254 	if (scsw_is_tm(scsw))
255 		return scsw->tm.eswf;
256 	else
257 		return scsw->cmd.eswf;
258 }
259 
260 /**
261  * scsw_cc - return scsw cc field
262  * @scsw: pointer to scsw
263  *
264  * Return the value of the cc field of the specified scsw, regardless of
265  * whether it is a transport mode or command mode scsw.
266  */
scsw_cc(union scsw * scsw)267 static inline u32 scsw_cc(union scsw *scsw)
268 {
269 	if (scsw_is_tm(scsw))
270 		return scsw->tm.cc;
271 	else
272 		return scsw->cmd.cc;
273 }
274 
275 /**
276  * scsw_ectl - return scsw ectl field
277  * @scsw: pointer to scsw
278  *
279  * Return the value of the ectl field of the specified scsw, regardless of
280  * whether it is a transport mode or command mode scsw.
281  */
scsw_ectl(union scsw * scsw)282 static inline u32 scsw_ectl(union scsw *scsw)
283 {
284 	if (scsw_is_tm(scsw))
285 		return scsw->tm.ectl;
286 	else
287 		return scsw->cmd.ectl;
288 }
289 
290 /**
291  * scsw_pno - return scsw pno field
292  * @scsw: pointer to scsw
293  *
294  * Return the value of the pno field of the specified scsw, regardless of
295  * whether it is a transport mode or command mode scsw.
296  */
scsw_pno(union scsw * scsw)297 static inline u32 scsw_pno(union scsw *scsw)
298 {
299 	if (scsw_is_tm(scsw))
300 		return scsw->tm.pno;
301 	else
302 		return scsw->cmd.pno;
303 }
304 
305 /**
306  * scsw_fctl - return scsw fctl field
307  * @scsw: pointer to scsw
308  *
309  * Return the value of the fctl field of the specified scsw, regardless of
310  * whether it is a transport mode or command mode scsw.
311  */
scsw_fctl(union scsw * scsw)312 static inline u32 scsw_fctl(union scsw *scsw)
313 {
314 	if (scsw_is_tm(scsw))
315 		return scsw->tm.fctl;
316 	else
317 		return scsw->cmd.fctl;
318 }
319 
320 /**
321  * scsw_actl - return scsw actl field
322  * @scsw: pointer to scsw
323  *
324  * Return the value of the actl field of the specified scsw, regardless of
325  * whether it is a transport mode or command mode scsw.
326  */
scsw_actl(union scsw * scsw)327 static inline u32 scsw_actl(union scsw *scsw)
328 {
329 	if (scsw_is_tm(scsw))
330 		return scsw->tm.actl;
331 	else
332 		return scsw->cmd.actl;
333 }
334 
335 /**
336  * scsw_stctl - return scsw stctl field
337  * @scsw: pointer to scsw
338  *
339  * Return the value of the stctl field of the specified scsw, regardless of
340  * whether it is a transport mode or command mode scsw.
341  */
scsw_stctl(union scsw * scsw)342 static inline u32 scsw_stctl(union scsw *scsw)
343 {
344 	if (scsw_is_tm(scsw))
345 		return scsw->tm.stctl;
346 	else
347 		return scsw->cmd.stctl;
348 }
349 
350 /**
351  * scsw_dstat - return scsw dstat field
352  * @scsw: pointer to scsw
353  *
354  * Return the value of the dstat field of the specified scsw, regardless of
355  * whether it is a transport mode or command mode scsw.
356  */
scsw_dstat(union scsw * scsw)357 static inline u32 scsw_dstat(union scsw *scsw)
358 {
359 	if (scsw_is_tm(scsw))
360 		return scsw->tm.dstat;
361 	else
362 		return scsw->cmd.dstat;
363 }
364 
365 /**
366  * scsw_cstat - return scsw cstat field
367  * @scsw: pointer to scsw
368  *
369  * Return the value of the cstat field of the specified scsw, regardless of
370  * whether it is a transport mode or command mode scsw.
371  */
scsw_cstat(union scsw * scsw)372 static inline u32 scsw_cstat(union scsw *scsw)
373 {
374 	if (scsw_is_tm(scsw))
375 		return scsw->tm.cstat;
376 	else
377 		return scsw->cmd.cstat;
378 }
379 
380 /**
381  * scsw_cmd_is_valid_key - check key field validity
382  * @scsw: pointer to scsw
383  *
384  * Return non-zero if the key field of the specified command mode scsw is
385  * valid, zero otherwise.
386  */
scsw_cmd_is_valid_key(union scsw * scsw)387 static inline int scsw_cmd_is_valid_key(union scsw *scsw)
388 {
389 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
390 }
391 
392 /**
393  * scsw_cmd_is_valid_sctl - check sctl field validity
394  * @scsw: pointer to scsw
395  *
396  * Return non-zero if the sctl field of the specified command mode scsw is
397  * valid, zero otherwise.
398  */
scsw_cmd_is_valid_sctl(union scsw * scsw)399 static inline int scsw_cmd_is_valid_sctl(union scsw *scsw)
400 {
401 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
402 }
403 
404 /**
405  * scsw_cmd_is_valid_eswf - check eswf field validity
406  * @scsw: pointer to scsw
407  *
408  * Return non-zero if the eswf field of the specified command mode scsw is
409  * valid, zero otherwise.
410  */
scsw_cmd_is_valid_eswf(union scsw * scsw)411 static inline int scsw_cmd_is_valid_eswf(union scsw *scsw)
412 {
413 	return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND);
414 }
415 
416 /**
417  * scsw_cmd_is_valid_cc - check cc field validity
418  * @scsw: pointer to scsw
419  *
420  * Return non-zero if the cc field of the specified command mode scsw is
421  * valid, zero otherwise.
422  */
scsw_cmd_is_valid_cc(union scsw * scsw)423 static inline int scsw_cmd_is_valid_cc(union scsw *scsw)
424 {
425 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) &&
426 	       (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND);
427 }
428 
429 /**
430  * scsw_cmd_is_valid_fmt - check fmt field validity
431  * @scsw: pointer to scsw
432  *
433  * Return non-zero if the fmt field of the specified command mode scsw is
434  * valid, zero otherwise.
435  */
scsw_cmd_is_valid_fmt(union scsw * scsw)436 static inline int scsw_cmd_is_valid_fmt(union scsw *scsw)
437 {
438 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
439 }
440 
441 /**
442  * scsw_cmd_is_valid_pfch - check pfch field validity
443  * @scsw: pointer to scsw
444  *
445  * Return non-zero if the pfch field of the specified command mode scsw is
446  * valid, zero otherwise.
447  */
scsw_cmd_is_valid_pfch(union scsw * scsw)448 static inline int scsw_cmd_is_valid_pfch(union scsw *scsw)
449 {
450 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
451 }
452 
453 /**
454  * scsw_cmd_is_valid_isic - check isic field validity
455  * @scsw: pointer to scsw
456  *
457  * Return non-zero if the isic field of the specified command mode scsw is
458  * valid, zero otherwise.
459  */
scsw_cmd_is_valid_isic(union scsw * scsw)460 static inline int scsw_cmd_is_valid_isic(union scsw *scsw)
461 {
462 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
463 }
464 
465 /**
466  * scsw_cmd_is_valid_alcc - check alcc field validity
467  * @scsw: pointer to scsw
468  *
469  * Return non-zero if the alcc field of the specified command mode scsw is
470  * valid, zero otherwise.
471  */
scsw_cmd_is_valid_alcc(union scsw * scsw)472 static inline int scsw_cmd_is_valid_alcc(union scsw *scsw)
473 {
474 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
475 }
476 
477 /**
478  * scsw_cmd_is_valid_ssi - check ssi field validity
479  * @scsw: pointer to scsw
480  *
481  * Return non-zero if the ssi field of the specified command mode scsw is
482  * valid, zero otherwise.
483  */
scsw_cmd_is_valid_ssi(union scsw * scsw)484 static inline int scsw_cmd_is_valid_ssi(union scsw *scsw)
485 {
486 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
487 }
488 
489 /**
490  * scsw_cmd_is_valid_zcc - check zcc field validity
491  * @scsw: pointer to scsw
492  *
493  * Return non-zero if the zcc field of the specified command mode scsw is
494  * valid, zero otherwise.
495  */
scsw_cmd_is_valid_zcc(union scsw * scsw)496 static inline int scsw_cmd_is_valid_zcc(union scsw *scsw)
497 {
498 	return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) &&
499 	       (scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS);
500 }
501 
502 /**
503  * scsw_cmd_is_valid_ectl - check ectl field validity
504  * @scsw: pointer to scsw
505  *
506  * Return non-zero if the ectl field of the specified command mode scsw is
507  * valid, zero otherwise.
508  */
scsw_cmd_is_valid_ectl(union scsw * scsw)509 static inline int scsw_cmd_is_valid_ectl(union scsw *scsw)
510 {
511 	/* Must be status pending. */
512 	if (!(scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND))
513 		return 0;
514 
515 	/* Must have alert status. */
516 	if (!(scsw->cmd.stctl & SCSW_STCTL_ALERT_STATUS))
517 		return 0;
518 
519 	/* Must be alone or together with primary, secondary or both,
520 	 * => no intermediate status.
521 	 */
522 	if (scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS)
523 		return 0;
524 
525 	return 1;
526 }
527 
528 /**
529  * scsw_cmd_is_valid_pno - check pno field validity
530  * @scsw: pointer to scsw
531  *
532  * Return non-zero if the pno field of the specified command mode scsw is
533  * valid, zero otherwise.
534  */
scsw_cmd_is_valid_pno(union scsw * scsw)535 static inline int scsw_cmd_is_valid_pno(union scsw *scsw)
536 {
537 	/* Must indicate at least one I/O function. */
538 	if (!scsw->cmd.fctl)
539 		return 0;
540 
541 	/* Must be status pending. */
542 	if (!(scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND))
543 		return 0;
544 
545 	/* Can be status pending alone, or with any combination of primary,
546 	 * secondary and alert => no intermediate status.
547 	 */
548 	if (!(scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS))
549 		return 1;
550 
551 	/* If intermediate, must be suspended. */
552 	if (scsw->cmd.actl & SCSW_ACTL_SUSPENDED)
553 		return 1;
554 
555 	return 0;
556 }
557 
558 /**
559  * scsw_cmd_is_valid_fctl - check fctl field validity
560  * @scsw: pointer to scsw
561  *
562  * Return non-zero if the fctl field of the specified command mode scsw is
563  * valid, zero otherwise.
564  */
scsw_cmd_is_valid_fctl(union scsw * scsw)565 static inline int scsw_cmd_is_valid_fctl(union scsw *scsw)
566 {
567 	/* Only valid if pmcw.dnv == 1*/
568 	return 1;
569 }
570 
571 /**
572  * scsw_cmd_is_valid_actl - check actl field validity
573  * @scsw: pointer to scsw
574  *
575  * Return non-zero if the actl field of the specified command mode scsw is
576  * valid, zero otherwise.
577  */
scsw_cmd_is_valid_actl(union scsw * scsw)578 static inline int scsw_cmd_is_valid_actl(union scsw *scsw)
579 {
580 	/* Only valid if pmcw.dnv == 1*/
581 	return 1;
582 }
583 
584 /**
585  * scsw_cmd_is_valid_stctl - check stctl field validity
586  * @scsw: pointer to scsw
587  *
588  * Return non-zero if the stctl field of the specified command mode scsw is
589  * valid, zero otherwise.
590  */
scsw_cmd_is_valid_stctl(union scsw * scsw)591 static inline int scsw_cmd_is_valid_stctl(union scsw *scsw)
592 {
593 	/* Only valid if pmcw.dnv == 1*/
594 	return 1;
595 }
596 
597 /**
598  * scsw_cmd_is_valid_dstat - check dstat field validity
599  * @scsw: pointer to scsw
600  *
601  * Return non-zero if the dstat field of the specified command mode scsw is
602  * valid, zero otherwise.
603  */
scsw_cmd_is_valid_dstat(union scsw * scsw)604 static inline int scsw_cmd_is_valid_dstat(union scsw *scsw)
605 {
606 	return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
607 	       (scsw->cmd.cc != 3);
608 }
609 
610 /**
611  * scsw_cmd_is_valid_cstat - check cstat field validity
612  * @scsw: pointer to scsw
613  *
614  * Return non-zero if the cstat field of the specified command mode scsw is
615  * valid, zero otherwise.
616  */
scsw_cmd_is_valid_cstat(union scsw * scsw)617 static inline int scsw_cmd_is_valid_cstat(union scsw *scsw)
618 {
619 	return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
620 	       (scsw->cmd.cc != 3);
621 }
622 
623 /**
624  * scsw_tm_is_valid_key - check key field validity
625  * @scsw: pointer to scsw
626  *
627  * Return non-zero if the key field of the specified transport mode scsw is
628  * valid, zero otherwise.
629  */
scsw_tm_is_valid_key(union scsw * scsw)630 static inline int scsw_tm_is_valid_key(union scsw *scsw)
631 {
632 	return (scsw->tm.fctl & SCSW_FCTL_START_FUNC);
633 }
634 
635 /**
636  * scsw_tm_is_valid_eswf - check eswf field validity
637  * @scsw: pointer to scsw
638  *
639  * Return non-zero if the eswf field of the specified transport mode scsw is
640  * valid, zero otherwise.
641  */
scsw_tm_is_valid_eswf(union scsw * scsw)642 static inline int scsw_tm_is_valid_eswf(union scsw *scsw)
643 {
644 	return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND);
645 }
646 
647 /**
648  * scsw_tm_is_valid_cc - check cc field validity
649  * @scsw: pointer to scsw
650  *
651  * Return non-zero if the cc field of the specified transport mode scsw is
652  * valid, zero otherwise.
653  */
scsw_tm_is_valid_cc(union scsw * scsw)654 static inline int scsw_tm_is_valid_cc(union scsw *scsw)
655 {
656 	return (scsw->tm.fctl & SCSW_FCTL_START_FUNC) &&
657 	       (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND);
658 }
659 
660 /**
661  * scsw_tm_is_valid_fmt - check fmt field validity
662  * @scsw: pointer to scsw
663  *
664  * Return non-zero if the fmt field of the specified transport mode scsw is
665  * valid, zero otherwise.
666  */
scsw_tm_is_valid_fmt(union scsw * scsw)667 static inline int scsw_tm_is_valid_fmt(union scsw *scsw)
668 {
669 	return 1;
670 }
671 
672 /**
673  * scsw_tm_is_valid_x - check x field validity
674  * @scsw: pointer to scsw
675  *
676  * Return non-zero if the x field of the specified transport mode scsw is
677  * valid, zero otherwise.
678  */
scsw_tm_is_valid_x(union scsw * scsw)679 static inline int scsw_tm_is_valid_x(union scsw *scsw)
680 {
681 	return 1;
682 }
683 
684 /**
685  * scsw_tm_is_valid_q - check q field validity
686  * @scsw: pointer to scsw
687  *
688  * Return non-zero if the q field of the specified transport mode scsw is
689  * valid, zero otherwise.
690  */
scsw_tm_is_valid_q(union scsw * scsw)691 static inline int scsw_tm_is_valid_q(union scsw *scsw)
692 {
693 	return 1;
694 }
695 
696 /**
697  * scsw_tm_is_valid_ectl - check ectl field validity
698  * @scsw: pointer to scsw
699  *
700  * Return non-zero if the ectl field of the specified transport mode scsw is
701  * valid, zero otherwise.
702  */
scsw_tm_is_valid_ectl(union scsw * scsw)703 static inline int scsw_tm_is_valid_ectl(union scsw *scsw)
704 {
705 	/* Must be status pending. */
706 	if (!(scsw->tm.stctl & SCSW_STCTL_STATUS_PEND))
707 		return 0;
708 
709 	/* Must have alert status. */
710 	if (!(scsw->tm.stctl & SCSW_STCTL_ALERT_STATUS))
711 		return 0;
712 
713 	/* Must be alone or together with primary, secondary or both,
714 	 * => no intermediate status.
715 	 */
716 	if (scsw->tm.stctl & SCSW_STCTL_INTER_STATUS)
717 		return 0;
718 
719 	return 1;
720 }
721 
722 /**
723  * scsw_tm_is_valid_pno - check pno field validity
724  * @scsw: pointer to scsw
725  *
726  * Return non-zero if the pno field of the specified transport mode scsw is
727  * valid, zero otherwise.
728  */
scsw_tm_is_valid_pno(union scsw * scsw)729 static inline int scsw_tm_is_valid_pno(union scsw *scsw)
730 {
731 	/* Must indicate at least one I/O function. */
732 	if (!scsw->tm.fctl)
733 		return 0;
734 
735 	/* Must be status pending. */
736 	if (!(scsw->tm.stctl & SCSW_STCTL_STATUS_PEND))
737 		return 0;
738 
739 	/* Can be status pending alone, or with any combination of primary,
740 	 * secondary and alert => no intermediate status.
741 	 */
742 	if (!(scsw->tm.stctl & SCSW_STCTL_INTER_STATUS))
743 		return 1;
744 
745 	/* If intermediate, must be suspended. */
746 	if (scsw->tm.actl & SCSW_ACTL_SUSPENDED)
747 		return 1;
748 
749 	return 0;
750 }
751 
752 /**
753  * scsw_tm_is_valid_fctl - check fctl field validity
754  * @scsw: pointer to scsw
755  *
756  * Return non-zero if the fctl field of the specified transport mode scsw is
757  * valid, zero otherwise.
758  */
scsw_tm_is_valid_fctl(union scsw * scsw)759 static inline int scsw_tm_is_valid_fctl(union scsw *scsw)
760 {
761 	/* Only valid if pmcw.dnv == 1*/
762 	return 1;
763 }
764 
765 /**
766  * scsw_tm_is_valid_actl - check actl field validity
767  * @scsw: pointer to scsw
768  *
769  * Return non-zero if the actl field of the specified transport mode scsw is
770  * valid, zero otherwise.
771  */
scsw_tm_is_valid_actl(union scsw * scsw)772 static inline int scsw_tm_is_valid_actl(union scsw *scsw)
773 {
774 	/* Only valid if pmcw.dnv == 1*/
775 	return 1;
776 }
777 
778 /**
779  * scsw_tm_is_valid_stctl - check stctl field validity
780  * @scsw: pointer to scsw
781  *
782  * Return non-zero if the stctl field of the specified transport mode scsw is
783  * valid, zero otherwise.
784  */
scsw_tm_is_valid_stctl(union scsw * scsw)785 static inline int scsw_tm_is_valid_stctl(union scsw *scsw)
786 {
787 	/* Only valid if pmcw.dnv == 1*/
788 	return 1;
789 }
790 
791 /**
792  * scsw_tm_is_valid_dstat - check dstat field validity
793  * @scsw: pointer to scsw
794  *
795  * Return non-zero if the dstat field of the specified transport mode scsw is
796  * valid, zero otherwise.
797  */
scsw_tm_is_valid_dstat(union scsw * scsw)798 static inline int scsw_tm_is_valid_dstat(union scsw *scsw)
799 {
800 	return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
801 	       (scsw->tm.cc != 3);
802 }
803 
804 /**
805  * scsw_tm_is_valid_cstat - check cstat field validity
806  * @scsw: pointer to scsw
807  *
808  * Return non-zero if the cstat field of the specified transport mode scsw is
809  * valid, zero otherwise.
810  */
scsw_tm_is_valid_cstat(union scsw * scsw)811 static inline int scsw_tm_is_valid_cstat(union scsw *scsw)
812 {
813 	return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
814 	       (scsw->tm.cc != 3);
815 }
816 
817 /**
818  * scsw_tm_is_valid_fcxs - check fcxs field validity
819  * @scsw: pointer to scsw
820  *
821  * Return non-zero if the fcxs field of the specified transport mode scsw is
822  * valid, zero otherwise.
823  */
scsw_tm_is_valid_fcxs(union scsw * scsw)824 static inline int scsw_tm_is_valid_fcxs(union scsw *scsw)
825 {
826 	return 1;
827 }
828 
829 /**
830  * scsw_tm_is_valid_schxs - check schxs field validity
831  * @scsw: pointer to scsw
832  *
833  * Return non-zero if the schxs field of the specified transport mode scsw is
834  * valid, zero otherwise.
835  */
scsw_tm_is_valid_schxs(union scsw * scsw)836 static inline int scsw_tm_is_valid_schxs(union scsw *scsw)
837 {
838 	return (scsw->tm.cstat & (SCHN_STAT_PROG_CHECK |
839 				  SCHN_STAT_INTF_CTRL_CHK |
840 				  SCHN_STAT_PROT_CHECK |
841 				  SCHN_STAT_CHN_DATA_CHK));
842 }
843 
844 /**
845  * scsw_is_valid_actl - check actl field validity
846  * @scsw: pointer to scsw
847  *
848  * Return non-zero if the actl field of the specified scsw is valid,
849  * regardless of whether it is a transport mode or command mode scsw.
850  * Return zero if the field does not contain a valid value.
851  */
scsw_is_valid_actl(union scsw * scsw)852 static inline int scsw_is_valid_actl(union scsw *scsw)
853 {
854 	if (scsw_is_tm(scsw))
855 		return scsw_tm_is_valid_actl(scsw);
856 	else
857 		return scsw_cmd_is_valid_actl(scsw);
858 }
859 
860 /**
861  * scsw_is_valid_cc - check cc field validity
862  * @scsw: pointer to scsw
863  *
864  * Return non-zero if the cc field of the specified scsw is valid,
865  * regardless of whether it is a transport mode or command mode scsw.
866  * Return zero if the field does not contain a valid value.
867  */
scsw_is_valid_cc(union scsw * scsw)868 static inline int scsw_is_valid_cc(union scsw *scsw)
869 {
870 	if (scsw_is_tm(scsw))
871 		return scsw_tm_is_valid_cc(scsw);
872 	else
873 		return scsw_cmd_is_valid_cc(scsw);
874 }
875 
876 /**
877  * scsw_is_valid_cstat - check cstat field validity
878  * @scsw: pointer to scsw
879  *
880  * Return non-zero if the cstat field of the specified scsw is valid,
881  * regardless of whether it is a transport mode or command mode scsw.
882  * Return zero if the field does not contain a valid value.
883  */
scsw_is_valid_cstat(union scsw * scsw)884 static inline int scsw_is_valid_cstat(union scsw *scsw)
885 {
886 	if (scsw_is_tm(scsw))
887 		return scsw_tm_is_valid_cstat(scsw);
888 	else
889 		return scsw_cmd_is_valid_cstat(scsw);
890 }
891 
892 /**
893  * scsw_is_valid_dstat - check dstat field validity
894  * @scsw: pointer to scsw
895  *
896  * Return non-zero if the dstat field of the specified scsw is valid,
897  * regardless of whether it is a transport mode or command mode scsw.
898  * Return zero if the field does not contain a valid value.
899  */
scsw_is_valid_dstat(union scsw * scsw)900 static inline int scsw_is_valid_dstat(union scsw *scsw)
901 {
902 	if (scsw_is_tm(scsw))
903 		return scsw_tm_is_valid_dstat(scsw);
904 	else
905 		return scsw_cmd_is_valid_dstat(scsw);
906 }
907 
908 /**
909  * scsw_is_valid_ectl - check ectl field validity
910  * @scsw: pointer to scsw
911  *
912  * Return non-zero if the ectl field of the specified scsw is valid,
913  * regardless of whether it is a transport mode or command mode scsw.
914  * Return zero if the field does not contain a valid value.
915  */
scsw_is_valid_ectl(union scsw * scsw)916 static inline int scsw_is_valid_ectl(union scsw *scsw)
917 {
918 	if (scsw_is_tm(scsw))
919 		return scsw_tm_is_valid_ectl(scsw);
920 	else
921 		return scsw_cmd_is_valid_ectl(scsw);
922 }
923 
924 /**
925  * scsw_is_valid_eswf - check eswf field validity
926  * @scsw: pointer to scsw
927  *
928  * Return non-zero if the eswf field of the specified scsw is valid,
929  * regardless of whether it is a transport mode or command mode scsw.
930  * Return zero if the field does not contain a valid value.
931  */
scsw_is_valid_eswf(union scsw * scsw)932 static inline int scsw_is_valid_eswf(union scsw *scsw)
933 {
934 	if (scsw_is_tm(scsw))
935 		return scsw_tm_is_valid_eswf(scsw);
936 	else
937 		return scsw_cmd_is_valid_eswf(scsw);
938 }
939 
940 /**
941  * scsw_is_valid_fctl - check fctl field validity
942  * @scsw: pointer to scsw
943  *
944  * Return non-zero if the fctl field of the specified scsw is valid,
945  * regardless of whether it is a transport mode or command mode scsw.
946  * Return zero if the field does not contain a valid value.
947  */
scsw_is_valid_fctl(union scsw * scsw)948 static inline int scsw_is_valid_fctl(union scsw *scsw)
949 {
950 	if (scsw_is_tm(scsw))
951 		return scsw_tm_is_valid_fctl(scsw);
952 	else
953 		return scsw_cmd_is_valid_fctl(scsw);
954 }
955 
956 /**
957  * scsw_is_valid_key - check key field validity
958  * @scsw: pointer to scsw
959  *
960  * Return non-zero if the key field of the specified scsw is valid,
961  * regardless of whether it is a transport mode or command mode scsw.
962  * Return zero if the field does not contain a valid value.
963  */
scsw_is_valid_key(union scsw * scsw)964 static inline int scsw_is_valid_key(union scsw *scsw)
965 {
966 	if (scsw_is_tm(scsw))
967 		return scsw_tm_is_valid_key(scsw);
968 	else
969 		return scsw_cmd_is_valid_key(scsw);
970 }
971 
972 /**
973  * scsw_is_valid_pno - check pno field validity
974  * @scsw: pointer to scsw
975  *
976  * Return non-zero if the pno field of the specified scsw is valid,
977  * regardless of whether it is a transport mode or command mode scsw.
978  * Return zero if the field does not contain a valid value.
979  */
scsw_is_valid_pno(union scsw * scsw)980 static inline int scsw_is_valid_pno(union scsw *scsw)
981 {
982 	if (scsw_is_tm(scsw))
983 		return scsw_tm_is_valid_pno(scsw);
984 	else
985 		return scsw_cmd_is_valid_pno(scsw);
986 }
987 
988 /**
989  * scsw_is_valid_stctl - check stctl field validity
990  * @scsw: pointer to scsw
991  *
992  * Return non-zero if the stctl field of the specified scsw is valid,
993  * regardless of whether it is a transport mode or command mode scsw.
994  * Return zero if the field does not contain a valid value.
995  */
scsw_is_valid_stctl(union scsw * scsw)996 static inline int scsw_is_valid_stctl(union scsw *scsw)
997 {
998 	if (scsw_is_tm(scsw))
999 		return scsw_tm_is_valid_stctl(scsw);
1000 	else
1001 		return scsw_cmd_is_valid_stctl(scsw);
1002 }
1003 
1004 /**
1005  * scsw_cmd_is_solicited - check for solicited scsw
1006  * @scsw: pointer to scsw
1007  *
1008  * Return non-zero if the command mode scsw indicates that the associated
1009  * status condition is solicited, zero if it is unsolicited.
1010  */
scsw_cmd_is_solicited(union scsw * scsw)1011 static inline int scsw_cmd_is_solicited(union scsw *scsw)
1012 {
1013 	return (scsw->cmd.cc != 0) || (scsw->cmd.stctl !=
1014 		(SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS));
1015 }
1016 
1017 /**
1018  * scsw_tm_is_solicited - check for solicited scsw
1019  * @scsw: pointer to scsw
1020  *
1021  * Return non-zero if the transport mode scsw indicates that the associated
1022  * status condition is solicited, zero if it is unsolicited.
1023  */
scsw_tm_is_solicited(union scsw * scsw)1024 static inline int scsw_tm_is_solicited(union scsw *scsw)
1025 {
1026 	return (scsw->tm.cc != 0) || (scsw->tm.stctl !=
1027 		(SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS));
1028 }
1029 
1030 /**
1031  * scsw_is_solicited - check for solicited scsw
1032  * @scsw: pointer to scsw
1033  *
1034  * Return non-zero if the transport or command mode scsw indicates that the
1035  * associated status condition is solicited, zero if it is unsolicited.
1036  */
scsw_is_solicited(union scsw * scsw)1037 static inline int scsw_is_solicited(union scsw *scsw)
1038 {
1039 	if (scsw_is_tm(scsw))
1040 		return scsw_tm_is_solicited(scsw);
1041 	else
1042 		return scsw_cmd_is_solicited(scsw);
1043 }
1044 
1045 #endif /* _ASM_S390_SCSW_H_ */
1046