cio.h 8.9 KB

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