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