xref: /openbmc/linux/drivers/s390/char/sclp.h (revision 249592bf)
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_SCP_INFO		0x00020001
67 #define SCLP_CMDW_READ_STORAGE_INFO	0x00040001
68 #define SCLP_CMDW_READ_SCP_INFO_FORCED	0x00120001
69 #define SCLP_CMDW_READ_EVENT_DATA	0x00770005
70 #define SCLP_CMDW_WRITE_EVENT_DATA	0x00760005
71 #define SCLP_CMDW_WRITE_EVENT_MASK	0x00780005
72 
73 #define GDS_ID_MDSMU		0x1310
74 #define GDS_ID_MDSROUTEINFO	0x1311
75 #define GDS_ID_AGUNWRKCORR	0x1549
76 #define GDS_ID_SNACONDREPORT	0x1532
77 #define GDS_ID_CPMSU		0x1212
78 #define GDS_ID_ROUTTARGINSTR	0x154D
79 #define GDS_ID_OPREQ		0x8070
80 #define GDS_ID_TEXTCMD		0x1320
81 
82 #define GDS_KEY_SELFDEFTEXTMSG	0x31
83 
84 enum 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 
93 typedef u64 sccb_mask_t;
94 
95 struct sccb_header {
96 	u16	length;
97 	u8	function_code;
98 	u8	control_mask[3];
99 	u16	response_code;
100 } __attribute__((packed));
101 
102 struct init_sccb {
103 	struct sccb_header header;
104 	u16 _reserved;
105 	u16 mask_length;
106 	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 	 */
113 } __attribute__((packed));
114 
115 #define SCLP_MASK_SIZE_COMPAT 4
116 
117 static 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 
125 static 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 
153 struct 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 	/*
160 	 * Without ext sccb, struct size is PAGE_SIZE.
161 	 * With ext sccb, struct size is EXT_SCCB_READ_CPU.
162 	 */
163 	u8	reserved[];
164 } __attribute__((packed, aligned(PAGE_SIZE)));
165 
166 struct read_info_sccb {
167 	struct	sccb_header header;	/* 0-7 */
168 	u16	rnmax;			/* 8-9 */
169 	u8	rnsize;			/* 10 */
170 	u8	_pad_11[16 - 11];	/* 11-15 */
171 	u16	ncpurl;			/* 16-17 */
172 	u16	cpuoff;			/* 18-19 */
173 	u8	_pad_20[24 - 20];	/* 20-23 */
174 	u8	loadparm[8];		/* 24-31 */
175 	u8	_pad_32[42 - 32];	/* 32-41 */
176 	u8	fac42;			/* 42 */
177 	u8	fac43;			/* 43 */
178 	u8	_pad_44[48 - 44];	/* 44-47 */
179 	u64	facilities;		/* 48-55 */
180 	u8	_pad_56[66 - 56];	/* 56-65 */
181 	u8	fac66;			/* 66 */
182 	u8	_pad_67[76 - 67];	/* 67-83 */
183 	u32	ibc;			/* 76-79 */
184 	u8	_pad80[84 - 80];	/* 80-83 */
185 	u8	fac84;			/* 84 */
186 	u8	fac85;			/* 85 */
187 	u8	_pad_86[91 - 86];	/* 86-90 */
188 	u8	fac91;			/* 91 */
189 	u8	_pad_92[98 - 92];	/* 92-97 */
190 	u8	fac98;			/* 98 */
191 	u8	hamaxpow;		/* 99 */
192 	u32	rnsize2;		/* 100-103 */
193 	u64	rnmax2;			/* 104-111 */
194 	u32	hsa_size;		/* 112-115 */
195 	u8	fac116;			/* 116 */
196 	u8	fac117;			/* 117 */
197 	u8	fac118;			/* 118 */
198 	u8	fac119;			/* 119 */
199 	u16	hcpua;			/* 120-121 */
200 	u8	_pad_122[124 - 122];	/* 122-123 */
201 	u32	hmfai;			/* 124-127 */
202 	u8	_pad_128[134 - 128];	/* 128-133 */
203 	u8	byte_134;			/* 134 */
204 	u8	cpudirq;		/* 135 */
205 	u16	cbl;			/* 136-137 */
206 	u8	_pad_138[EXT_SCCB_READ_SCP - 138];
207 } __packed __aligned(PAGE_SIZE);
208 
209 struct read_storage_sccb {
210 	struct sccb_header header;
211 	u16 max_id;
212 	u16 assigned;
213 	u16 standby;
214 	u16 :16;
215 	u32 entries[0];
216 } __packed;
217 
218 static inline void sclp_fill_core_info(struct sclp_core_info *info,
219 				       struct read_cpu_info_sccb *sccb)
220 {
221 	char *page = (char *) sccb;
222 
223 	memset(info, 0, sizeof(*info));
224 	info->configured = sccb->nr_configured;
225 	info->standby = sccb->nr_standby;
226 	info->combined = sccb->nr_configured + sccb->nr_standby;
227 	memcpy(&info->core, page + sccb->offset_configured,
228 	       info->combined * sizeof(struct sclp_core_entry));
229 }
230 
231 #define SCLP_HAS_CHP_INFO	(sclp.facilities & 0x8000000000000000ULL)
232 #define SCLP_HAS_CHP_RECONFIG	(sclp.facilities & 0x2000000000000000ULL)
233 #define SCLP_HAS_CPU_INFO	(sclp.facilities & 0x0800000000000000ULL)
234 #define SCLP_HAS_CPU_RECONFIG	(sclp.facilities & 0x0400000000000000ULL)
235 #define SCLP_HAS_PCI_RECONFIG	(sclp.facilities & 0x0000000040000000ULL)
236 #define SCLP_HAS_AP_RECONFIG	(sclp.facilities & 0x0000000100000000ULL)
237 
238 struct gds_subvector {
239 	u8	length;
240 	u8	key;
241 } __attribute__((packed));
242 
243 struct gds_vector {
244 	u16	length;
245 	u16	gds_id;
246 } __attribute__((packed));
247 
248 struct evbuf_header {
249 	u16	length;
250 	u8	type;
251 	u8	flags;
252 	u16	_reserved;
253 } __attribute__((packed));
254 
255 struct sclp_req {
256 	struct list_head list;		/* list_head for request queueing. */
257 	sclp_cmdw_t command;		/* sclp command to execute */
258 	void	*sccb;			/* pointer to the sccb to execute */
259 	char	status;			/* status of this request */
260 	int     start_count;		/* number of SVCs done for this req */
261 	/* Callback that is called after reaching final status. */
262 	void (*callback)(struct sclp_req *, void *data);
263 	void *callback_data;
264 	int queue_timeout;		/* request queue timeout (sec), set by
265 					   caller of sclp_add_request(), if
266 					   needed */
267 	/* Internal fields */
268 	unsigned long queue_expires;	/* request queue timeout (jiffies) */
269 };
270 
271 #define SCLP_REQ_FILLED	  0x00	/* request is ready to be processed */
272 #define SCLP_REQ_QUEUED	  0x01	/* request is queued to be processed */
273 #define SCLP_REQ_RUNNING  0x02	/* request is currently running */
274 #define SCLP_REQ_DONE	  0x03	/* request is completed successfully */
275 #define SCLP_REQ_FAILED	  0x05	/* request is finally failed */
276 #define SCLP_REQ_QUEUED_TIMEOUT 0x06	/* request on queue timed out */
277 
278 #define SCLP_QUEUE_INTERVAL 5	/* timeout interval for request queue */
279 
280 /* function pointers that a high level driver has to use for registration */
281 /* of some routines it wants to be called from the low level driver */
282 struct sclp_register {
283 	struct list_head list;
284 	/* User wants to receive: */
285 	sccb_mask_t receive_mask;
286 	/* User wants to send: */
287 	sccb_mask_t send_mask;
288 	/* H/W can receive: */
289 	sccb_mask_t sclp_receive_mask;
290 	/* H/W can send: */
291 	sccb_mask_t sclp_send_mask;
292 	/* called if event type availability changes */
293 	void (*state_change_fn)(struct sclp_register *);
294 	/* called for events in cp_receive_mask/sclp_receive_mask */
295 	void (*receiver_fn)(struct evbuf_header *);
296 	/* called for power management events */
297 	void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event);
298 	/* pm event posted flag */
299 	int pm_event_posted;
300 };
301 
302 /* externals from sclp.c */
303 int sclp_add_request(struct sclp_req *req);
304 void sclp_sync_wait(void);
305 int sclp_register(struct sclp_register *reg);
306 void sclp_unregister(struct sclp_register *reg);
307 int sclp_remove_processed(struct sccb_header *sccb);
308 int sclp_deactivate(void);
309 int sclp_reactivate(void);
310 int sclp_sync_request(sclp_cmdw_t command, void *sccb);
311 int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout);
312 int sclp_sdias_init(void);
313 
314 enum {
315 	sclp_init_state_uninitialized,
316 	sclp_init_state_initializing,
317 	sclp_init_state_initialized
318 };
319 
320 extern int sclp_init_state;
321 extern int sclp_console_pages;
322 extern int sclp_console_drop;
323 extern unsigned long sclp_console_full;
324 extern bool sclp_mask_compat_mode;
325 
326 extern char *sclp_early_sccb;
327 
328 void sclp_early_wait_irq(void);
329 int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb);
330 unsigned int sclp_early_con_check_linemode(struct init_sccb *sccb);
331 unsigned int sclp_early_con_check_vt220(struct init_sccb *sccb);
332 int sclp_early_set_event_mask(struct init_sccb *sccb,
333 			      sccb_mask_t receive_mask,
334 			      sccb_mask_t send_mask);
335 struct read_info_sccb * __init sclp_early_get_info(void);
336 
337 /* useful inlines */
338 
339 /* Perform service call. Return 0 on success, non-zero otherwise. */
340 static inline int sclp_service_call(sclp_cmdw_t command, void *sccb)
341 {
342 	int cc = 4; /* Initialize for program check handling */
343 
344 	asm volatile(
345 		"0:	.insn	rre,0xb2200000,%1,%2\n"	 /* servc %1,%2 */
346 		"1:	ipm	%0\n"
347 		"	srl	%0,28\n"
348 		"2:\n"
349 		EX_TABLE(0b, 2b)
350 		EX_TABLE(1b, 2b)
351 		: "+&d" (cc) : "d" (command), "a" ((unsigned long)sccb)
352 		: "cc", "memory");
353 	if (cc == 4)
354 		return -EINVAL;
355 	if (cc == 3)
356 		return -EIO;
357 	if (cc == 2)
358 		return -EBUSY;
359 	return 0;
360 }
361 
362 /* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */
363 /* translate single character from ASCII to EBCDIC */
364 static inline unsigned char
365 sclp_ascebc(unsigned char ch)
366 {
367 	return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch];
368 }
369 
370 /* translate string from EBCDIC to ASCII */
371 static inline void
372 sclp_ebcasc_str(char *str, int nr)
373 {
374 	(MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
375 }
376 
377 /* translate string from ASCII to EBCDIC */
378 static inline void
379 sclp_ascebc_str(char *str, int nr)
380 {
381 	(MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
382 }
383 
384 static inline struct gds_vector *
385 sclp_find_gds_vector(void *start, void *end, u16 id)
386 {
387 	struct gds_vector *v;
388 
389 	for (v = start; (void *) v < end; v = (void *) v + v->length)
390 		if (v->gds_id == id)
391 			return v;
392 	return NULL;
393 }
394 
395 static inline struct gds_subvector *
396 sclp_find_gds_subvector(void *start, void *end, u8 key)
397 {
398 	struct gds_subvector *sv;
399 
400 	for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length)
401 		if (sv->key == key)
402 			return sv;
403 	return NULL;
404 }
405 
406 #endif	 /* __SCLP_H__ */
407