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