Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jan Glauber | 7441b06 | 2012-11-29 14:35:47 +0100 | [diff] [blame] | 2 | * Copyright IBM Corp. 1999,2012 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 4 | * Author(s): Martin Peschke <mpeschke@de.ibm.com> |
| 5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __SCLP_H__ |
| 9 | #define __SCLP_H__ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/list.h> |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 13 | #include <asm/sclp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/ebcdic.h> |
| 15 | |
| 16 | /* maximum number of pages concerning our own memory management */ |
| 17 | #define MAX_KMEM_PAGES (sizeof(unsigned long) << 3) |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 18 | #define SCLP_CONSOLE_PAGES 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Sebastian Ott | 3fa7ee8 | 2015-11-27 12:33:18 +0100 | [diff] [blame] | 20 | #define SCLP_EVTYP_MASK(T) (1U << (32 - (T))) |
| 21 | |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 22 | #define EVTYP_OPCMD 0x01 |
| 23 | #define EVTYP_MSG 0x02 |
Sebastian Ott | 3fa7ee8 | 2015-11-27 12:33:18 +0100 | [diff] [blame] | 24 | #define EVTYP_CONFMGMDATA 0x04 |
Ralf Hoppe | 8f933b1 | 2013-04-08 09:52:57 +0200 | [diff] [blame] | 25 | #define EVTYP_DIAG_TEST 0x07 |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 26 | #define EVTYP_STATECHANGE 0x08 |
| 27 | #define EVTYP_PMSGCMD 0x09 |
Hans-Joachim Picht | c114728a | 2009-09-11 10:28:47 +0200 | [diff] [blame] | 28 | #define EVTYP_ASYNC 0x0A |
Sebastian Ott | 3fa7ee8 | 2015-11-27 12:33:18 +0100 | [diff] [blame] | 29 | #define EVTYP_CTLPROGIDENT 0x0B |
| 30 | #define EVTYP_ERRNOTIFY 0x18 |
| 31 | #define EVTYP_VT220MSG 0x1A |
| 32 | #define EVTYP_SDIAS 0x1C |
| 33 | #define EVTYP_SIGQUIESCE 0x1D |
Martin Schwidefsky | 7eb9d5b | 2011-05-23 10:24:43 +0200 | [diff] [blame] | 34 | #define EVTYP_OCF 0x1E |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Sebastian Ott | 3fa7ee8 | 2015-11-27 12:33:18 +0100 | [diff] [blame] | 36 | #define EVTYP_OPCMD_MASK SCLP_EVTYP_MASK(EVTYP_OPCMD) |
| 37 | #define EVTYP_MSG_MASK SCLP_EVTYP_MASK(EVTYP_MSG) |
| 38 | #define EVTYP_CONFMGMDATA_MASK SCLP_EVTYP_MASK(EVTYP_CONFMGMDATA) |
| 39 | #define EVTYP_DIAG_TEST_MASK SCLP_EVTYP_MASK(EVTYP_DIAG_TEST) |
| 40 | #define EVTYP_STATECHANGE_MASK SCLP_EVTYP_MASK(EVTYP_STATECHANGE) |
| 41 | #define EVTYP_PMSGCMD_MASK SCLP_EVTYP_MASK(EVTYP_PMSGCMD) |
| 42 | #define EVTYP_ASYNC_MASK SCLP_EVTYP_MASK(EVTYP_ASYNC) |
| 43 | #define EVTYP_CTLPROGIDENT_MASK SCLP_EVTYP_MASK(EVTYP_CTLPROGIDENT) |
| 44 | #define EVTYP_ERRNOTIFY_MASK SCLP_EVTYP_MASK(EVTYP_ERRNOTIFY) |
| 45 | #define EVTYP_VT220MSG_MASK SCLP_EVTYP_MASK(EVTYP_VT220MSG) |
| 46 | #define EVTYP_SDIAS_MASK SCLP_EVTYP_MASK(EVTYP_SDIAS) |
| 47 | #define EVTYP_SIGQUIESCE_MASK SCLP_EVTYP_MASK(EVTYP_SIGQUIESCE) |
| 48 | #define EVTYP_OCF_MASK SCLP_EVTYP_MASK(EVTYP_OCF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 50 | #define GNRLMSGFLGS_DOM 0x8000 |
| 51 | #define GNRLMSGFLGS_SNDALRM 0x4000 |
| 52 | #define GNRLMSGFLGS_HOLDMSG 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 54 | #define LNTPFLGS_CNTLTEXT 0x8000 |
| 55 | #define LNTPFLGS_LABELTEXT 0x4000 |
| 56 | #define LNTPFLGS_DATATEXT 0x2000 |
| 57 | #define LNTPFLGS_ENDTEXT 0x1000 |
| 58 | #define LNTPFLGS_PROMPTTEXT 0x0800 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | typedef unsigned int sclp_cmdw_t; |
| 61 | |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 62 | #define SCLP_CMDW_READ_EVENT_DATA 0x00770005 |
| 63 | #define SCLP_CMDW_WRITE_EVENT_DATA 0x00760005 |
| 64 | #define SCLP_CMDW_WRITE_EVENT_MASK 0x00780005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | #define GDS_ID_MDSMU 0x1310 |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 67 | #define GDS_ID_MDSROUTEINFO 0x1311 |
| 68 | #define GDS_ID_AGUNWRKCORR 0x1549 |
| 69 | #define GDS_ID_SNACONDREPORT 0x1532 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define GDS_ID_CPMSU 0x1212 |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 71 | #define GDS_ID_ROUTTARGINSTR 0x154D |
| 72 | #define GDS_ID_OPREQ 0x8070 |
| 73 | #define GDS_ID_TEXTCMD 0x1320 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 75 | #define GDS_KEY_SELFDEFTEXTMSG 0x31 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 77 | enum sclp_pm_event { |
| 78 | SCLP_PM_EVENT_FREEZE, |
| 79 | SCLP_PM_EVENT_THAW, |
| 80 | SCLP_PM_EVENT_RESTORE, |
| 81 | }; |
| 82 | |
| 83 | #define SCLP_PANIC_PRIO 1 |
| 84 | #define SCLP_PANIC_PRIO_CLIENT 0 |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | typedef u32 sccb_mask_t; /* ATTENTION: assumes 32bit mask !!! */ |
| 87 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 88 | struct sccb_header { |
| 89 | u16 length; |
| 90 | u8 function_code; |
| 91 | u8 control_mask[3]; |
| 92 | u16 response_code; |
| 93 | } __attribute__((packed)); |
| 94 | |
Heinz Graalfs | cd18345 | 2012-06-11 16:06:59 +0200 | [diff] [blame] | 95 | struct init_sccb { |
| 96 | struct sccb_header header; |
| 97 | u16 _reserved; |
| 98 | u16 mask_length; |
| 99 | sccb_mask_t receive_mask; |
| 100 | sccb_mask_t send_mask; |
| 101 | sccb_mask_t sclp_receive_mask; |
| 102 | sccb_mask_t sclp_send_mask; |
| 103 | } __attribute__((packed)); |
| 104 | |
David Hildenbrand | 78335a3 | 2015-05-06 09:17:51 +0200 | [diff] [blame] | 105 | #define SCLP_HAS_CHP_INFO (sclp.facilities & 0x8000000000000000ULL) |
| 106 | #define SCLP_HAS_CHP_RECONFIG (sclp.facilities & 0x2000000000000000ULL) |
| 107 | #define SCLP_HAS_CPU_INFO (sclp.facilities & 0x0800000000000000ULL) |
| 108 | #define SCLP_HAS_CPU_RECONFIG (sclp.facilities & 0x0400000000000000ULL) |
| 109 | #define SCLP_HAS_PCI_RECONFIG (sclp.facilities & 0x0000000040000000ULL) |
Heiko Carstens | 83119ad | 2007-07-10 11:24:10 +0200 | [diff] [blame] | 110 | |
Hans-Joachim Picht | c114728a | 2009-09-11 10:28:47 +0200 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct gds_subvector { |
| 113 | u8 length; |
| 114 | u8 key; |
| 115 | } __attribute__((packed)); |
| 116 | |
| 117 | struct gds_vector { |
| 118 | u16 length; |
| 119 | u16 gds_id; |
| 120 | } __attribute__((packed)); |
| 121 | |
| 122 | struct evbuf_header { |
| 123 | u16 length; |
| 124 | u8 type; |
| 125 | u8 flags; |
| 126 | u16 _reserved; |
| 127 | } __attribute__((packed)); |
| 128 | |
| 129 | struct sclp_req { |
| 130 | struct list_head list; /* list_head for request queueing. */ |
| 131 | sclp_cmdw_t command; /* sclp command to execute */ |
| 132 | void *sccb; /* pointer to the sccb to execute */ |
| 133 | char status; /* status of this request */ |
| 134 | int start_count; /* number of SVCs done for this req */ |
| 135 | /* Callback that is called after reaching final status. */ |
| 136 | void (*callback)(struct sclp_req *, void *data); |
| 137 | void *callback_data; |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 138 | int queue_timeout; /* request queue timeout (sec), set by |
| 139 | caller of sclp_add_request(), if |
| 140 | needed */ |
| 141 | /* Internal fields */ |
| 142 | unsigned long queue_expires; /* request queue timeout (jiffies) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | #define SCLP_REQ_FILLED 0x00 /* request is ready to be processed */ |
| 146 | #define SCLP_REQ_QUEUED 0x01 /* request is queued to be processed */ |
| 147 | #define SCLP_REQ_RUNNING 0x02 /* request is currently running */ |
| 148 | #define SCLP_REQ_DONE 0x03 /* request is completed successfully */ |
| 149 | #define SCLP_REQ_FAILED 0x05 /* request is finally failed */ |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 150 | #define SCLP_REQ_QUEUED_TIMEOUT 0x06 /* request on queue timed out */ |
| 151 | |
| 152 | #define SCLP_QUEUE_INTERVAL 5 /* timeout interval for request queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* function pointers that a high level driver has to use for registration */ |
| 155 | /* of some routines it wants to be called from the low level driver */ |
| 156 | struct sclp_register { |
| 157 | struct list_head list; |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 158 | /* User wants to receive: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | sccb_mask_t receive_mask; |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 160 | /* User wants to send: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | sccb_mask_t send_mask; |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 162 | /* H/W can receive: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | sccb_mask_t sclp_receive_mask; |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 164 | /* H/W can send: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | sccb_mask_t sclp_send_mask; |
| 166 | /* called if event type availability changes */ |
| 167 | void (*state_change_fn)(struct sclp_register *); |
| 168 | /* called for events in cp_receive_mask/sclp_receive_mask */ |
| 169 | void (*receiver_fn)(struct evbuf_header *); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 170 | /* called for power management events */ |
| 171 | void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event); |
| 172 | /* pm event posted flag */ |
| 173 | int pm_event_posted; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /* externals from sclp.c */ |
| 177 | int sclp_add_request(struct sclp_req *req); |
| 178 | void sclp_sync_wait(void); |
| 179 | int sclp_register(struct sclp_register *reg); |
| 180 | void sclp_unregister(struct sclp_register *reg); |
| 181 | int sclp_remove_processed(struct sccb_header *sccb); |
| 182 | int sclp_deactivate(void); |
| 183 | int sclp_reactivate(void); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 184 | int sclp_service_call(sclp_cmdw_t command, void *sccb); |
Michael Holzheu | d475f94 | 2013-06-06 09:52:08 +0200 | [diff] [blame] | 185 | int sclp_sync_request(sclp_cmdw_t command, void *sccb); |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 186 | int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 188 | int sclp_sdias_init(void); |
| 189 | void sclp_sdias_exit(void); |
| 190 | |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 191 | extern int sclp_console_pages; |
| 192 | extern int sclp_console_drop; |
| 193 | extern unsigned long sclp_console_full; |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /* useful inlines */ |
| 196 | |
| 197 | /* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */ |
| 198 | /* translate single character from ASCII to EBCDIC */ |
| 199 | static inline unsigned char |
| 200 | sclp_ascebc(unsigned char ch) |
| 201 | { |
| 202 | return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch]; |
| 203 | } |
| 204 | |
| 205 | /* translate string from EBCDIC to ASCII */ |
| 206 | static inline void |
| 207 | sclp_ebcasc_str(unsigned char *str, int nr) |
| 208 | { |
| 209 | (MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr); |
| 210 | } |
| 211 | |
| 212 | /* translate string from ASCII to EBCDIC */ |
| 213 | static inline void |
| 214 | sclp_ascebc_str(unsigned char *str, int nr) |
| 215 | { |
| 216 | (MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr); |
| 217 | } |
| 218 | |
Martin Schwidefsky | 30c2df5 | 2011-05-23 10:24:42 +0200 | [diff] [blame] | 219 | static inline struct gds_vector * |
| 220 | sclp_find_gds_vector(void *start, void *end, u16 id) |
| 221 | { |
| 222 | struct gds_vector *v; |
| 223 | |
| 224 | for (v = start; (void *) v < end; v = (void *) v + v->length) |
| 225 | if (v->gds_id == id) |
| 226 | return v; |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | static inline struct gds_subvector * |
| 231 | sclp_find_gds_subvector(void *start, void *end, u8 key) |
| 232 | { |
| 233 | struct gds_subvector *sv; |
| 234 | |
| 235 | for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length) |
| 236 | if (sv->key == key) |
| 237 | return sv; |
| 238 | return NULL; |
| 239 | } |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | #endif /* __SCLP_H__ */ |