sclp.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 1999,2012
  4. *
  5. * Author(s): Martin Peschke <mpeschke@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. */
  8. #ifndef __SCLP_H__
  9. #define __SCLP_H__
  10. #include <linux/types.h>
  11. #include <linux/list.h>
  12. #include <asm/sclp.h>
  13. #include <asm/ebcdic.h>
  14. /* maximum number of pages concerning our own memory management */
  15. #define MAX_KMEM_PAGES (sizeof(unsigned long) << 3)
  16. #define SCLP_CONSOLE_PAGES 6
  17. #define SCLP_EVTYP_MASK(T) (1U << (32 - (T)))
  18. #define EVTYP_OPCMD 0x01
  19. #define EVTYP_MSG 0x02
  20. #define EVTYP_CONFMGMDATA 0x04
  21. #define EVTYP_DIAG_TEST 0x07
  22. #define EVTYP_STATECHANGE 0x08
  23. #define EVTYP_PMSGCMD 0x09
  24. #define EVTYP_ASYNC 0x0A
  25. #define EVTYP_CTLPROGIDENT 0x0B
  26. #define EVTYP_ERRNOTIFY 0x18
  27. #define EVTYP_VT220MSG 0x1A
  28. #define EVTYP_SDIAS 0x1C
  29. #define EVTYP_SIGQUIESCE 0x1D
  30. #define EVTYP_OCF 0x1E
  31. #define EVTYP_OPCMD_MASK SCLP_EVTYP_MASK(EVTYP_OPCMD)
  32. #define EVTYP_MSG_MASK SCLP_EVTYP_MASK(EVTYP_MSG)
  33. #define EVTYP_CONFMGMDATA_MASK SCLP_EVTYP_MASK(EVTYP_CONFMGMDATA)
  34. #define EVTYP_DIAG_TEST_MASK SCLP_EVTYP_MASK(EVTYP_DIAG_TEST)
  35. #define EVTYP_STATECHANGE_MASK SCLP_EVTYP_MASK(EVTYP_STATECHANGE)
  36. #define EVTYP_PMSGCMD_MASK SCLP_EVTYP_MASK(EVTYP_PMSGCMD)
  37. #define EVTYP_ASYNC_MASK SCLP_EVTYP_MASK(EVTYP_ASYNC)
  38. #define EVTYP_CTLPROGIDENT_MASK SCLP_EVTYP_MASK(EVTYP_CTLPROGIDENT)
  39. #define EVTYP_ERRNOTIFY_MASK SCLP_EVTYP_MASK(EVTYP_ERRNOTIFY)
  40. #define EVTYP_VT220MSG_MASK SCLP_EVTYP_MASK(EVTYP_VT220MSG)
  41. #define EVTYP_SDIAS_MASK SCLP_EVTYP_MASK(EVTYP_SDIAS)
  42. #define EVTYP_SIGQUIESCE_MASK SCLP_EVTYP_MASK(EVTYP_SIGQUIESCE)
  43. #define EVTYP_OCF_MASK SCLP_EVTYP_MASK(EVTYP_OCF)
  44. #define GNRLMSGFLGS_DOM 0x8000
  45. #define GNRLMSGFLGS_SNDALRM 0x4000
  46. #define GNRLMSGFLGS_HOLDMSG 0x2000
  47. #define LNTPFLGS_CNTLTEXT 0x8000
  48. #define LNTPFLGS_LABELTEXT 0x4000
  49. #define LNTPFLGS_DATATEXT 0x2000
  50. #define LNTPFLGS_ENDTEXT 0x1000
  51. #define LNTPFLGS_PROMPTTEXT 0x0800
  52. typedef unsigned int sclp_cmdw_t;
  53. #define SCLP_CMDW_READ_CPU_INFO 0x00010001
  54. #define SCLP_CMDW_READ_EVENT_DATA 0x00770005
  55. #define SCLP_CMDW_WRITE_EVENT_DATA 0x00760005
  56. #define SCLP_CMDW_WRITE_EVENT_MASK 0x00780005
  57. #define GDS_ID_MDSMU 0x1310
  58. #define GDS_ID_MDSROUTEINFO 0x1311
  59. #define GDS_ID_AGUNWRKCORR 0x1549
  60. #define GDS_ID_SNACONDREPORT 0x1532
  61. #define GDS_ID_CPMSU 0x1212
  62. #define GDS_ID_ROUTTARGINSTR 0x154D
  63. #define GDS_ID_OPREQ 0x8070
  64. #define GDS_ID_TEXTCMD 0x1320
  65. #define GDS_KEY_SELFDEFTEXTMSG 0x31
  66. enum sclp_pm_event {
  67. SCLP_PM_EVENT_FREEZE,
  68. SCLP_PM_EVENT_THAW,
  69. SCLP_PM_EVENT_RESTORE,
  70. };
  71. #define SCLP_PANIC_PRIO 1
  72. #define SCLP_PANIC_PRIO_CLIENT 0
  73. typedef u32 sccb_mask_t; /* ATTENTION: assumes 32bit mask !!! */
  74. struct sccb_header {
  75. u16 length;
  76. u8 function_code;
  77. u8 control_mask[3];
  78. u16 response_code;
  79. } __attribute__((packed));
  80. struct init_sccb {
  81. struct sccb_header header;
  82. u16 _reserved;
  83. u16 mask_length;
  84. sccb_mask_t receive_mask;
  85. sccb_mask_t send_mask;
  86. sccb_mask_t sclp_receive_mask;
  87. sccb_mask_t sclp_send_mask;
  88. } __attribute__((packed));
  89. struct read_cpu_info_sccb {
  90. struct sccb_header header;
  91. u16 nr_configured;
  92. u16 offset_configured;
  93. u16 nr_standby;
  94. u16 offset_standby;
  95. u8 reserved[4096 - 16];
  96. } __attribute__((packed, aligned(PAGE_SIZE)));
  97. static inline void sclp_fill_core_info(struct sclp_core_info *info,
  98. struct read_cpu_info_sccb *sccb)
  99. {
  100. char *page = (char *) sccb;
  101. memset(info, 0, sizeof(*info));
  102. info->configured = sccb->nr_configured;
  103. info->standby = sccb->nr_standby;
  104. info->combined = sccb->nr_configured + sccb->nr_standby;
  105. memcpy(&info->core, page + sccb->offset_configured,
  106. info->combined * sizeof(struct sclp_core_entry));
  107. }
  108. #define SCLP_HAS_CHP_INFO (sclp.facilities & 0x8000000000000000ULL)
  109. #define SCLP_HAS_CHP_RECONFIG (sclp.facilities & 0x2000000000000000ULL)
  110. #define SCLP_HAS_CPU_INFO (sclp.facilities & 0x0800000000000000ULL)
  111. #define SCLP_HAS_CPU_RECONFIG (sclp.facilities & 0x0400000000000000ULL)
  112. #define SCLP_HAS_PCI_RECONFIG (sclp.facilities & 0x0000000040000000ULL)
  113. struct gds_subvector {
  114. u8 length;
  115. u8 key;
  116. } __attribute__((packed));
  117. struct gds_vector {
  118. u16 length;
  119. u16 gds_id;
  120. } __attribute__((packed));
  121. struct evbuf_header {
  122. u16 length;
  123. u8 type;
  124. u8 flags;
  125. u16 _reserved;
  126. } __attribute__((packed));
  127. struct sclp_req {
  128. struct list_head list; /* list_head for request queueing. */
  129. sclp_cmdw_t command; /* sclp command to execute */
  130. void *sccb; /* pointer to the sccb to execute */
  131. char status; /* status of this request */
  132. int start_count; /* number of SVCs done for this req */
  133. /* Callback that is called after reaching final status. */
  134. void (*callback)(struct sclp_req *, void *data);
  135. void *callback_data;
  136. int queue_timeout; /* request queue timeout (sec), set by
  137. caller of sclp_add_request(), if
  138. needed */
  139. /* Internal fields */
  140. unsigned long queue_expires; /* request queue timeout (jiffies) */
  141. };
  142. #define SCLP_REQ_FILLED 0x00 /* request is ready to be processed */
  143. #define SCLP_REQ_QUEUED 0x01 /* request is queued to be processed */
  144. #define SCLP_REQ_RUNNING 0x02 /* request is currently running */
  145. #define SCLP_REQ_DONE 0x03 /* request is completed successfully */
  146. #define SCLP_REQ_FAILED 0x05 /* request is finally failed */
  147. #define SCLP_REQ_QUEUED_TIMEOUT 0x06 /* request on queue timed out */
  148. #define SCLP_QUEUE_INTERVAL 5 /* timeout interval for request queue */
  149. /* function pointers that a high level driver has to use for registration */
  150. /* of some routines it wants to be called from the low level driver */
  151. struct sclp_register {
  152. struct list_head list;
  153. /* User wants to receive: */
  154. sccb_mask_t receive_mask;
  155. /* User wants to send: */
  156. sccb_mask_t send_mask;
  157. /* H/W can receive: */
  158. sccb_mask_t sclp_receive_mask;
  159. /* H/W can send: */
  160. sccb_mask_t sclp_send_mask;
  161. /* called if event type availability changes */
  162. void (*state_change_fn)(struct sclp_register *);
  163. /* called for events in cp_receive_mask/sclp_receive_mask */
  164. void (*receiver_fn)(struct evbuf_header *);
  165. /* called for power management events */
  166. void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event);
  167. /* pm event posted flag */
  168. int pm_event_posted;
  169. };
  170. /* externals from sclp.c */
  171. int sclp_add_request(struct sclp_req *req);
  172. void sclp_sync_wait(void);
  173. int sclp_register(struct sclp_register *reg);
  174. void sclp_unregister(struct sclp_register *reg);
  175. int sclp_remove_processed(struct sccb_header *sccb);
  176. int sclp_deactivate(void);
  177. int sclp_reactivate(void);
  178. int sclp_sync_request(sclp_cmdw_t command, void *sccb);
  179. int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout);
  180. int sclp_sdias_init(void);
  181. void sclp_sdias_exit(void);
  182. enum {
  183. sclp_init_state_uninitialized,
  184. sclp_init_state_initializing,
  185. sclp_init_state_initialized
  186. };
  187. extern int sclp_init_state;
  188. extern int sclp_console_pages;
  189. extern int sclp_console_drop;
  190. extern unsigned long sclp_console_full;
  191. extern char sclp_early_sccb[PAGE_SIZE];
  192. void sclp_early_wait_irq(void);
  193. int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb);
  194. unsigned int sclp_early_con_check_linemode(struct init_sccb *sccb);
  195. int sclp_early_set_event_mask(struct init_sccb *sccb,
  196. unsigned long receive_mask,
  197. unsigned long send_mask);
  198. /* useful inlines */
  199. /* Perform service call. Return 0 on success, non-zero otherwise. */
  200. static inline int sclp_service_call(sclp_cmdw_t command, void *sccb)
  201. {
  202. int cc = 4; /* Initialize for program check handling */
  203. asm volatile(
  204. "0: .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
  205. "1: ipm %0\n"
  206. " srl %0,28\n"
  207. "2:\n"
  208. EX_TABLE(0b, 2b)
  209. EX_TABLE(1b, 2b)
  210. : "+&d" (cc) : "d" (command), "a" ((unsigned long)sccb)
  211. : "cc", "memory");
  212. if (cc == 4)
  213. return -EINVAL;
  214. if (cc == 3)
  215. return -EIO;
  216. if (cc == 2)
  217. return -EBUSY;
  218. return 0;
  219. }
  220. /* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */
  221. /* translate single character from ASCII to EBCDIC */
  222. static inline unsigned char
  223. sclp_ascebc(unsigned char ch)
  224. {
  225. return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch];
  226. }
  227. /* translate string from EBCDIC to ASCII */
  228. static inline void
  229. sclp_ebcasc_str(unsigned char *str, int nr)
  230. {
  231. (MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
  232. }
  233. /* translate string from ASCII to EBCDIC */
  234. static inline void
  235. sclp_ascebc_str(unsigned char *str, int nr)
  236. {
  237. (MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
  238. }
  239. static inline struct gds_vector *
  240. sclp_find_gds_vector(void *start, void *end, u16 id)
  241. {
  242. struct gds_vector *v;
  243. for (v = start; (void *) v < end; v = (void *) v + v->length)
  244. if (v->gds_id == id)
  245. return v;
  246. return NULL;
  247. }
  248. static inline struct gds_subvector *
  249. sclp_find_gds_subvector(void *start, void *end, u8 key)
  250. {
  251. struct gds_subvector *sv;
  252. for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length)
  253. if (sv->key == key)
  254. return sv;
  255. return NULL;
  256. }
  257. #endif /* __SCLP_H__ */