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