cio.h 9.0 KB

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