blob: 196333013e5435fb42ad7aa03d8dc6c938bf27b2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Jan Glauber7441b062012-11-29 14:35:47 +01003 * Copyright IBM Corp. 1999,2012
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Michael Holzheu62b749422009-06-16 10:30:40 +02005 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#ifndef __SCLP_H__
10#define __SCLP_H__
11
12#include <linux/types.h>
13#include <linux/list.h>
Heiko Carstensab14de62007-02-05 21:18:37 +010014#include <asm/sclp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/ebcdic.h>
16
17/* maximum number of pages concerning our own memory management */
18#define MAX_KMEM_PAGES (sizeof(unsigned long) << 3)
Martin Schwidefsky25b41a72013-05-24 12:30:03 +020019#define SCLP_CONSOLE_PAGES 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Claudio Imbrenda0ee5f8d2018-01-23 15:07:09 +010021#define SCLP_EVTYP_MASK(T) (1UL << (sizeof(sccb_mask_t) * BITS_PER_BYTE - (T)))
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010022
Stefan Haberland6d4740c2007-04-27 16:01:53 +020023#define EVTYP_OPCMD 0x01
24#define EVTYP_MSG 0x02
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010025#define EVTYP_CONFMGMDATA 0x04
Ralf Hoppe8f933b12013-04-08 09:52:57 +020026#define EVTYP_DIAG_TEST 0x07
Stefan Haberland6d4740c2007-04-27 16:01:53 +020027#define EVTYP_STATECHANGE 0x08
28#define EVTYP_PMSGCMD 0x09
Hans-Joachim Pichtc114728a2009-09-11 10:28:47 +020029#define EVTYP_ASYNC 0x0A
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010030#define EVTYP_CTLPROGIDENT 0x0B
Peter Oberparleiter66aec642017-02-13 13:38:17 +010031#define EVTYP_STORE_DATA 0x0C
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010032#define EVTYP_ERRNOTIFY 0x18
33#define EVTYP_VT220MSG 0x1A
34#define EVTYP_SDIAS 0x1C
35#define EVTYP_SIGQUIESCE 0x1D
Martin Schwidefsky7eb9d5b2011-05-23 10:24:43 +020036#define EVTYP_OCF 0x1E
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010038#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)
Peter Oberparleiter66aec642017-02-13 13:38:17 +010046#define EVTYP_STORE_DATA_MASK SCLP_EVTYP_MASK(EVTYP_STORE_DATA)
Sebastian Ott3fa7ee82015-11-27 12:33:18 +010047#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Stefan Haberland6d4740c2007-04-27 16:01:53 +020053#define GNRLMSGFLGS_DOM 0x8000
54#define GNRLMSGFLGS_SNDALRM 0x4000
55#define GNRLMSGFLGS_HOLDMSG 0x2000
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Stefan Haberland6d4740c2007-04-27 16:01:53 +020057#define LNTPFLGS_CNTLTEXT 0x8000
58#define LNTPFLGS_LABELTEXT 0x4000
59#define LNTPFLGS_DATATEXT 0x2000
60#define LNTPFLGS_ENDTEXT 0x1000
61#define LNTPFLGS_PROMPTTEXT 0x0800
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63typedef unsigned int sclp_cmdw_t;
64
Heiko Carstensaf51160e2016-12-03 09:48:01 +010065#define SCLP_CMDW_READ_CPU_INFO 0x00010001
Vasily Gorbik17aacfbf2018-05-23 11:07:13 +020066#define SCLP_CMDW_READ_SCP_INFO 0x00020001
Vasily Gorbikfddbaa52018-04-11 18:42:37 +020067#define SCLP_CMDW_READ_STORAGE_INFO 0x00040001
Vasily Gorbik17aacfbf2018-05-23 11:07:13 +020068#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
Heiko Carstensab14de62007-02-05 21:18:37 +010069#define SCLP_CMDW_READ_EVENT_DATA 0x00770005
70#define SCLP_CMDW_WRITE_EVENT_DATA 0x00760005
71#define SCLP_CMDW_WRITE_EVENT_MASK 0x00780005
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73#define GDS_ID_MDSMU 0x1310
Stefan Haberland6d4740c2007-04-27 16:01:53 +020074#define GDS_ID_MDSROUTEINFO 0x1311
75#define GDS_ID_AGUNWRKCORR 0x1549
76#define GDS_ID_SNACONDREPORT 0x1532
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define GDS_ID_CPMSU 0x1212
Stefan Haberland6d4740c2007-04-27 16:01:53 +020078#define GDS_ID_ROUTTARGINSTR 0x154D
79#define GDS_ID_OPREQ 0x8070
80#define GDS_ID_TEXTCMD 0x1320
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Stefan Haberland6d4740c2007-04-27 16:01:53 +020082#define GDS_KEY_SELFDEFTEXTMSG 0x31
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Michael Holzheu62b749422009-06-16 10:30:40 +020084enum sclp_pm_event {
85 SCLP_PM_EVENT_FREEZE,
86 SCLP_PM_EVENT_THAW,
87 SCLP_PM_EVENT_RESTORE,
88};
89
90#define SCLP_PANIC_PRIO 1
91#define SCLP_PANIC_PRIO_CLIENT 0
92
Claudio Imbrendaf8f6e272018-01-23 16:54:11 +010093typedef u64 sccb_mask_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Heiko Carstens05dd2532007-07-10 11:24:09 +020095struct sccb_header {
96 u16 length;
97 u8 function_code;
98 u8 control_mask[3];
99 u16 response_code;
100} __attribute__((packed));
101
Heinz Graalfscd183452012-06-11 16:06:59 +0200102struct init_sccb {
103 struct sccb_header header;
104 u16 _reserved;
105 u16 mask_length;
Claudio Imbrendab8435632018-01-23 16:41:38 +0100106 u8 masks[4 * 1021]; /* variable length */
107 /*
108 * u8 receive_mask[mask_length];
109 * u8 send_mask[mask_length];
110 * u8 sclp_receive_mask[mask_length];
111 * u8 sclp_send_mask[mask_length];
112 */
Heinz Graalfscd183452012-06-11 16:06:59 +0200113} __attribute__((packed));
114
Claudio Imbrenda0b0d1172018-01-23 16:50:43 +0100115#define SCLP_MASK_SIZE_COMPAT 4
116
Claudio Imbrendab8435632018-01-23 16:41:38 +0100117static inline sccb_mask_t sccb_get_mask(u8 *masks, size_t len, int i)
118{
119 sccb_mask_t res = 0;
120
121 memcpy(&res, masks + i * len, min(sizeof(res), len));
122 return res;
123}
124
125static inline void sccb_set_mask(u8 *masks, size_t len, int i, sccb_mask_t val)
126{
127 memset(masks + i * len, 0, len);
128 memcpy(masks + i * len, &val, min(sizeof(val), len));
129}
130
131#define sccb_get_generic_mask(sccb, i) \
132({ \
133 __typeof__(sccb) __sccb = sccb; \
134 \
135 sccb_get_mask(__sccb->masks, __sccb->mask_length, i); \
136})
137#define sccb_get_recv_mask(sccb) sccb_get_generic_mask(sccb, 0)
138#define sccb_get_send_mask(sccb) sccb_get_generic_mask(sccb, 1)
139#define sccb_get_sclp_recv_mask(sccb) sccb_get_generic_mask(sccb, 2)
140#define sccb_get_sclp_send_mask(sccb) sccb_get_generic_mask(sccb, 3)
141
142#define sccb_set_generic_mask(sccb, i, val) \
143({ \
144 __typeof__(sccb) __sccb = sccb; \
145 \
146 sccb_set_mask(__sccb->masks, __sccb->mask_length, i, val); \
147})
148#define sccb_set_recv_mask(sccb, val) sccb_set_generic_mask(sccb, 0, val)
149#define sccb_set_send_mask(sccb, val) sccb_set_generic_mask(sccb, 1, val)
150#define sccb_set_sclp_recv_mask(sccb, val) sccb_set_generic_mask(sccb, 2, val)
151#define sccb_set_sclp_send_mask(sccb, val) sccb_set_generic_mask(sccb, 3, val)
152
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100153struct read_cpu_info_sccb {
154 struct sccb_header header;
155 u16 nr_configured;
156 u16 offset_configured;
157 u16 nr_standby;
158 u16 offset_standby;
159 u8 reserved[4096 - 16];
160} __attribute__((packed, aligned(PAGE_SIZE)));
161
Vasily Gorbik17aacfbf2018-05-23 11:07:13 +0200162struct read_info_sccb {
163 struct sccb_header header; /* 0-7 */
164 u16 rnmax; /* 8-9 */
165 u8 rnsize; /* 10 */
166 u8 _pad_11[16 - 11]; /* 11-15 */
167 u16 ncpurl; /* 16-17 */
168 u16 cpuoff; /* 18-19 */
169 u8 _pad_20[24 - 20]; /* 20-23 */
170 u8 loadparm[8]; /* 24-31 */
171 u8 _pad_32[42 - 32]; /* 32-41 */
172 u8 fac42; /* 42 */
173 u8 fac43; /* 43 */
174 u8 _pad_44[48 - 44]; /* 44-47 */
175 u64 facilities; /* 48-55 */
176 u8 _pad_56[66 - 56]; /* 56-65 */
177 u8 fac66; /* 66 */
178 u8 _pad_67[76 - 67]; /* 67-83 */
179 u32 ibc; /* 76-79 */
180 u8 _pad80[84 - 80]; /* 80-83 */
181 u8 fac84; /* 84 */
182 u8 fac85; /* 85 */
183 u8 _pad_86[91 - 86]; /* 86-90 */
184 u8 fac91; /* 91 */
185 u8 _pad_92[98 - 92]; /* 92-97 */
186 u8 fac98; /* 98 */
187 u8 hamaxpow; /* 99 */
188 u32 rnsize2; /* 100-103 */
189 u64 rnmax2; /* 104-111 */
190 u32 hsa_size; /* 112-115 */
191 u8 fac116; /* 116 */
192 u8 fac117; /* 117 */
193 u8 fac118; /* 118 */
194 u8 fac119; /* 119 */
195 u16 hcpua; /* 120-121 */
196 u8 _pad_122[124 - 122]; /* 122-123 */
197 u32 hmfai; /* 124-127 */
Collin Walling4ad78b82018-12-06 17:30:04 -0500198 u8 _pad_128[134 - 128]; /* 128-133 */
199 u8 byte_134; /* 134 */
Sebastian Ott0a9fddf2019-02-12 12:37:50 +0100200 u8 cpudirq; /* 135 */
Philipp Rudoc9896ac2019-04-08 14:24:08 +0200201 u16 cbl; /* 136-137 */
202 u8 _pad_138[4096 - 138]; /* 138-4095 */
Vasily Gorbik17aacfbf2018-05-23 11:07:13 +0200203} __packed __aligned(PAGE_SIZE);
204
Vasily Gorbikfddbaa52018-04-11 18:42:37 +0200205struct read_storage_sccb {
206 struct sccb_header header;
207 u16 max_id;
208 u16 assigned;
209 u16 standby;
210 u16 :16;
211 u32 entries[0];
212} __packed;
213
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100214static inline void sclp_fill_core_info(struct sclp_core_info *info,
215 struct read_cpu_info_sccb *sccb)
216{
217 char *page = (char *) sccb;
218
219 memset(info, 0, sizeof(*info));
220 info->configured = sccb->nr_configured;
221 info->standby = sccb->nr_standby;
222 info->combined = sccb->nr_configured + sccb->nr_standby;
223 memcpy(&info->core, page + sccb->offset_configured,
224 info->combined * sizeof(struct sclp_core_entry));
225}
226
David Hildenbrand78335a32015-05-06 09:17:51 +0200227#define SCLP_HAS_CHP_INFO (sclp.facilities & 0x8000000000000000ULL)
228#define SCLP_HAS_CHP_RECONFIG (sclp.facilities & 0x2000000000000000ULL)
229#define SCLP_HAS_CPU_INFO (sclp.facilities & 0x0800000000000000ULL)
230#define SCLP_HAS_CPU_RECONFIG (sclp.facilities & 0x0400000000000000ULL)
231#define SCLP_HAS_PCI_RECONFIG (sclp.facilities & 0x0000000040000000ULL)
Heiko Carstens83119ad2007-07-10 11:24:10 +0200232
Hans-Joachim Pichtc114728a2009-09-11 10:28:47 +0200233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234struct gds_subvector {
235 u8 length;
236 u8 key;
237} __attribute__((packed));
238
239struct gds_vector {
240 u16 length;
241 u16 gds_id;
242} __attribute__((packed));
243
244struct evbuf_header {
245 u16 length;
246 u8 type;
247 u8 flags;
248 u16 _reserved;
249} __attribute__((packed));
250
251struct sclp_req {
252 struct list_head list; /* list_head for request queueing. */
253 sclp_cmdw_t command; /* sclp command to execute */
254 void *sccb; /* pointer to the sccb to execute */
255 char status; /* status of this request */
256 int start_count; /* number of SVCs done for this req */
257 /* Callback that is called after reaching final status. */
258 void (*callback)(struct sclp_req *, void *data);
259 void *callback_data;
Gerald Schaefer9f0128f2014-03-31 16:18:29 +0200260 int queue_timeout; /* request queue timeout (sec), set by
261 caller of sclp_add_request(), if
262 needed */
263 /* Internal fields */
264 unsigned long queue_expires; /* request queue timeout (jiffies) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
266
267#define SCLP_REQ_FILLED 0x00 /* request is ready to be processed */
268#define SCLP_REQ_QUEUED 0x01 /* request is queued to be processed */
269#define SCLP_REQ_RUNNING 0x02 /* request is currently running */
270#define SCLP_REQ_DONE 0x03 /* request is completed successfully */
271#define SCLP_REQ_FAILED 0x05 /* request is finally failed */
Gerald Schaefer9f0128f2014-03-31 16:18:29 +0200272#define SCLP_REQ_QUEUED_TIMEOUT 0x06 /* request on queue timed out */
273
274#define SCLP_QUEUE_INTERVAL 5 /* timeout interval for request queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276/* function pointers that a high level driver has to use for registration */
277/* of some routines it wants to be called from the low level driver */
278struct sclp_register {
279 struct list_head list;
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100280 /* User wants to receive: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 sccb_mask_t receive_mask;
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100282 /* User wants to send: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 sccb_mask_t send_mask;
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100284 /* H/W can receive: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 sccb_mask_t sclp_receive_mask;
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100286 /* H/W can send: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 sccb_mask_t sclp_send_mask;
288 /* called if event type availability changes */
289 void (*state_change_fn)(struct sclp_register *);
290 /* called for events in cp_receive_mask/sclp_receive_mask */
291 void (*receiver_fn)(struct evbuf_header *);
Michael Holzheu62b749422009-06-16 10:30:40 +0200292 /* called for power management events */
293 void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event);
294 /* pm event posted flag */
295 int pm_event_posted;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296};
297
298/* externals from sclp.c */
299int sclp_add_request(struct sclp_req *req);
300void sclp_sync_wait(void);
301int sclp_register(struct sclp_register *reg);
302void sclp_unregister(struct sclp_register *reg);
303int sclp_remove_processed(struct sccb_header *sccb);
304int sclp_deactivate(void);
305int sclp_reactivate(void);
Michael Holzheud475f942013-06-06 09:52:08 +0200306int sclp_sync_request(sclp_cmdw_t command, void *sccb);
Gerald Schaefer9f0128f2014-03-31 16:18:29 +0200307int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Heiko Carstens763968e2007-05-10 15:45:46 +0200309int sclp_sdias_init(void);
310void sclp_sdias_exit(void);
311
Heiko Carstens76fdf142017-01-27 15:54:57 +0100312enum {
313 sclp_init_state_uninitialized,
314 sclp_init_state_initializing,
315 sclp_init_state_initialized
316};
317
318extern int sclp_init_state;
Martin Schwidefsky25b41a72013-05-24 12:30:03 +0200319extern int sclp_console_pages;
320extern int sclp_console_drop;
321extern unsigned long sclp_console_full;
Claudio Imbrenda0b0d1172018-01-23 16:50:43 +0100322extern bool sclp_mask_compat_mode;
Martin Schwidefsky25b41a72013-05-24 12:30:03 +0200323
Gerald Schaefer087c4d72019-04-08 12:49:58 +0200324extern char *sclp_early_sccb;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100325
326void sclp_early_wait_irq(void);
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100327int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb);
328unsigned int sclp_early_con_check_linemode(struct init_sccb *sccb);
Claudio Imbrendab8435632018-01-23 16:41:38 +0100329unsigned int sclp_early_con_check_vt220(struct init_sccb *sccb);
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100330int sclp_early_set_event_mask(struct init_sccb *sccb,
Claudio Imbrenda0ee5f8d2018-01-23 15:07:09 +0100331 sccb_mask_t receive_mask,
332 sccb_mask_t send_mask);
Vasily Gorbik17aacfbf2018-05-23 11:07:13 +0200333int sclp_early_get_info(struct read_info_sccb *info);
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/* useful inlines */
336
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100337/* Perform service call. Return 0 on success, non-zero otherwise. */
338static inline int sclp_service_call(sclp_cmdw_t command, void *sccb)
339{
340 int cc = 4; /* Initialize for program check handling */
341
342 asm volatile(
343 "0: .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
344 "1: ipm %0\n"
345 " srl %0,28\n"
346 "2:\n"
347 EX_TABLE(0b, 2b)
348 EX_TABLE(1b, 2b)
349 : "+&d" (cc) : "d" (command), "a" ((unsigned long)sccb)
350 : "cc", "memory");
351 if (cc == 4)
352 return -EINVAL;
353 if (cc == 3)
354 return -EIO;
355 if (cc == 2)
356 return -EBUSY;
357 return 0;
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360/* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */
361/* translate single character from ASCII to EBCDIC */
362static inline unsigned char
363sclp_ascebc(unsigned char ch)
364{
365 return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch];
366}
367
368/* translate string from EBCDIC to ASCII */
369static inline void
Arnd Bergmann4ae98782019-04-15 10:35:54 +0200370sclp_ebcasc_str(char *str, int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 (MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
373}
374
375/* translate string from ASCII to EBCDIC */
376static inline void
Arnd Bergmann4ae98782019-04-15 10:35:54 +0200377sclp_ascebc_str(char *str, int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 (MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
380}
381
Martin Schwidefsky30c2df52011-05-23 10:24:42 +0200382static inline struct gds_vector *
383sclp_find_gds_vector(void *start, void *end, u16 id)
384{
385 struct gds_vector *v;
386
387 for (v = start; (void *) v < end; v = (void *) v + v->length)
388 if (v->gds_id == id)
389 return v;
390 return NULL;
391}
392
393static inline struct gds_subvector *
394sclp_find_gds_subvector(void *start, void *end, u8 key)
395{
396 struct gds_subvector *sv;
397
398 for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length)
399 if (sv->key == key)
400 return sv;
401 return NULL;
402}
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#endif /* __SCLP_H__ */