sclp.h 10.1 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2
/*
3
 * Copyright IBM Corp. 1999,2012
L
Linus Torvalds 已提交
4
 *
5 6
 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
 *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
L
Linus Torvalds 已提交
7 8 9 10 11 12 13
 */

#ifndef __SCLP_H__
#define __SCLP_H__

#include <linux/types.h>
#include <linux/list.h>
14
#include <asm/sclp.h>
L
Linus Torvalds 已提交
15 16 17 18
#include <asm/ebcdic.h>

/* maximum number of pages concerning our own memory management */
#define MAX_KMEM_PAGES (sizeof(unsigned long) << 3)
19
#define SCLP_CONSOLE_PAGES	6
L
Linus Torvalds 已提交
20

21
#define SCLP_EVTYP_MASK(T) (1UL << (sizeof(sccb_mask_t) * BITS_PER_BYTE - (T)))
22

23 24
#define EVTYP_OPCMD		0x01
#define EVTYP_MSG		0x02
25
#define EVTYP_CONFMGMDATA	0x04
26
#define EVTYP_DIAG_TEST		0x07
27 28
#define EVTYP_STATECHANGE	0x08
#define EVTYP_PMSGCMD		0x09
29 30
#define EVTYP_ASYNC		0x0A
#define EVTYP_CTLPROGIDENT	0x0B
31
#define EVTYP_STORE_DATA	0x0C
32
#define EVTYP_ERRNOTIFY		0x18
33 34
#define EVTYP_VT220MSG		0x1A
#define EVTYP_SDIAS		0x1C
35
#define EVTYP_SIGQUIESCE	0x1D
M
Martin Schwidefsky 已提交
36
#define EVTYP_OCF		0x1E
37

38 39 40 41 42 43 44 45
#define EVTYP_OPCMD_MASK	SCLP_EVTYP_MASK(EVTYP_OPCMD)
#define EVTYP_MSG_MASK		SCLP_EVTYP_MASK(EVTYP_MSG)
#define EVTYP_CONFMGMDATA_MASK	SCLP_EVTYP_MASK(EVTYP_CONFMGMDATA)
#define EVTYP_DIAG_TEST_MASK	SCLP_EVTYP_MASK(EVTYP_DIAG_TEST)
#define EVTYP_STATECHANGE_MASK	SCLP_EVTYP_MASK(EVTYP_STATECHANGE)
#define EVTYP_PMSGCMD_MASK	SCLP_EVTYP_MASK(EVTYP_PMSGCMD)
#define EVTYP_ASYNC_MASK	SCLP_EVTYP_MASK(EVTYP_ASYNC)
#define EVTYP_CTLPROGIDENT_MASK	SCLP_EVTYP_MASK(EVTYP_CTLPROGIDENT)
46
#define EVTYP_STORE_DATA_MASK	SCLP_EVTYP_MASK(EVTYP_STORE_DATA)
47 48 49 50 51
#define EVTYP_ERRNOTIFY_MASK	SCLP_EVTYP_MASK(EVTYP_ERRNOTIFY)
#define EVTYP_VT220MSG_MASK	SCLP_EVTYP_MASK(EVTYP_VT220MSG)
#define EVTYP_SDIAS_MASK	SCLP_EVTYP_MASK(EVTYP_SDIAS)
#define EVTYP_SIGQUIESCE_MASK	SCLP_EVTYP_MASK(EVTYP_SIGQUIESCE)
#define EVTYP_OCF_MASK		SCLP_EVTYP_MASK(EVTYP_OCF)
52 53 54 55 56 57 58 59 60 61

#define GNRLMSGFLGS_DOM		0x8000
#define GNRLMSGFLGS_SNDALRM	0x4000
#define GNRLMSGFLGS_HOLDMSG	0x2000

#define LNTPFLGS_CNTLTEXT	0x8000
#define LNTPFLGS_LABELTEXT	0x4000
#define LNTPFLGS_DATATEXT	0x2000
#define LNTPFLGS_ENDTEXT	0x1000
#define LNTPFLGS_PROMPTTEXT	0x0800
L
Linus Torvalds 已提交
62 63 64

typedef unsigned int sclp_cmdw_t;

65
#define SCLP_CMDW_READ_CPU_INFO		0x00010001
66 67 68
#define SCLP_CMDW_READ_EVENT_DATA	0x00770005
#define SCLP_CMDW_WRITE_EVENT_DATA	0x00760005
#define SCLP_CMDW_WRITE_EVENT_MASK	0x00780005
L
Linus Torvalds 已提交
69 70

#define GDS_ID_MDSMU		0x1310
71 72 73
#define GDS_ID_MDSROUTEINFO	0x1311
#define GDS_ID_AGUNWRKCORR	0x1549
#define GDS_ID_SNACONDREPORT	0x1532
L
Linus Torvalds 已提交
74
#define GDS_ID_CPMSU		0x1212
75 76 77
#define GDS_ID_ROUTTARGINSTR	0x154D
#define GDS_ID_OPREQ		0x8070
#define GDS_ID_TEXTCMD		0x1320
L
Linus Torvalds 已提交
78

79
#define GDS_KEY_SELFDEFTEXTMSG	0x31
L
Linus Torvalds 已提交
80

81 82 83 84 85 86 87 88 89
enum sclp_pm_event {
	SCLP_PM_EVENT_FREEZE,
	SCLP_PM_EVENT_THAW,
	SCLP_PM_EVENT_RESTORE,
};

#define SCLP_PANIC_PRIO		1
#define SCLP_PANIC_PRIO_CLIENT	0

C
Claudio Imbrenda 已提交
90
typedef u64 sccb_mask_t;
L
Linus Torvalds 已提交
91

92 93 94 95 96 97 98
struct sccb_header {
	u16	length;
	u8	function_code;
	u8	control_mask[3];
	u16	response_code;
} __attribute__((packed));

99 100 101 102
struct init_sccb {
	struct sccb_header header;
	u16 _reserved;
	u16 mask_length;
103 104 105 106 107 108 109
	u8 masks[4 * 1021];	/* variable length */
	/*
	 * u8 receive_mask[mask_length];
	 * u8 send_mask[mask_length];
	 * u8 sclp_receive_mask[mask_length];
	 * u8 sclp_send_mask[mask_length];
	 */
110 111
} __attribute__((packed));

112 113
#define SCLP_MASK_SIZE_COMPAT 4

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
static inline sccb_mask_t sccb_get_mask(u8 *masks, size_t len, int i)
{
	sccb_mask_t res = 0;

	memcpy(&res, masks + i * len, min(sizeof(res), len));
	return res;
}

static inline void sccb_set_mask(u8 *masks, size_t len, int i, sccb_mask_t val)
{
	memset(masks + i * len, 0, len);
	memcpy(masks + i * len, &val, min(sizeof(val), len));
}

#define sccb_get_generic_mask(sccb, i)					\
({									\
	__typeof__(sccb) __sccb = sccb;					\
									\
	sccb_get_mask(__sccb->masks, __sccb->mask_length, i);		\
})
#define sccb_get_recv_mask(sccb)	sccb_get_generic_mask(sccb, 0)
#define sccb_get_send_mask(sccb)	sccb_get_generic_mask(sccb, 1)
#define sccb_get_sclp_recv_mask(sccb)	sccb_get_generic_mask(sccb, 2)
#define sccb_get_sclp_send_mask(sccb)	sccb_get_generic_mask(sccb, 3)

#define sccb_set_generic_mask(sccb, i, val)				\
({									\
	__typeof__(sccb) __sccb = sccb;					\
									\
	sccb_set_mask(__sccb->masks, __sccb->mask_length, i, val);	\
})
#define sccb_set_recv_mask(sccb, val)	    sccb_set_generic_mask(sccb, 0, val)
#define sccb_set_send_mask(sccb, val)	    sccb_set_generic_mask(sccb, 1, val)
#define sccb_set_sclp_recv_mask(sccb, val)  sccb_set_generic_mask(sccb, 2, val)
#define sccb_set_sclp_send_mask(sccb, val)  sccb_set_generic_mask(sccb, 3, val)

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
struct read_cpu_info_sccb {
	struct	sccb_header header;
	u16	nr_configured;
	u16	offset_configured;
	u16	nr_standby;
	u16	offset_standby;
	u8	reserved[4096 - 16];
} __attribute__((packed, aligned(PAGE_SIZE)));

static inline void sclp_fill_core_info(struct sclp_core_info *info,
				       struct read_cpu_info_sccb *sccb)
{
	char *page = (char *) sccb;

	memset(info, 0, sizeof(*info));
	info->configured = sccb->nr_configured;
	info->standby = sccb->nr_standby;
	info->combined = sccb->nr_configured + sccb->nr_standby;
	memcpy(&info->core, page + sccb->offset_configured,
	       info->combined * sizeof(struct sclp_core_entry));
}

172 173 174 175 176
#define SCLP_HAS_CHP_INFO	(sclp.facilities & 0x8000000000000000ULL)
#define SCLP_HAS_CHP_RECONFIG	(sclp.facilities & 0x2000000000000000ULL)
#define SCLP_HAS_CPU_INFO	(sclp.facilities & 0x0800000000000000ULL)
#define SCLP_HAS_CPU_RECONFIG	(sclp.facilities & 0x0400000000000000ULL)
#define SCLP_HAS_PCI_RECONFIG	(sclp.facilities & 0x0000000040000000ULL)
177

178

L
Linus Torvalds 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
struct gds_subvector {
	u8	length;
	u8	key;
} __attribute__((packed));

struct gds_vector {
	u16	length;
	u16	gds_id;
} __attribute__((packed));

struct evbuf_header {
	u16	length;
	u8	type;
	u8	flags;
	u16	_reserved;
} __attribute__((packed));

struct sclp_req {
	struct list_head list;		/* list_head for request queueing. */
	sclp_cmdw_t command;		/* sclp command to execute */
	void	*sccb;			/* pointer to the sccb to execute */
	char	status;			/* status of this request */
	int     start_count;		/* number of SVCs done for this req */
	/* Callback that is called after reaching final status. */
	void (*callback)(struct sclp_req *, void *data);
	void *callback_data;
205 206 207 208 209
	int queue_timeout;		/* request queue timeout (sec), set by
					   caller of sclp_add_request(), if
					   needed */
	/* Internal fields */
	unsigned long queue_expires;	/* request queue timeout (jiffies) */
L
Linus Torvalds 已提交
210 211 212 213 214 215 216
};

#define SCLP_REQ_FILLED	  0x00	/* request is ready to be processed */
#define SCLP_REQ_QUEUED	  0x01	/* request is queued to be processed */
#define SCLP_REQ_RUNNING  0x02	/* request is currently running */
#define SCLP_REQ_DONE	  0x03	/* request is completed successfully */
#define SCLP_REQ_FAILED	  0x05	/* request is finally failed */
217 218 219
#define SCLP_REQ_QUEUED_TIMEOUT 0x06	/* request on queue timed out */

#define SCLP_QUEUE_INTERVAL 5	/* timeout interval for request queue */
L
Linus Torvalds 已提交
220 221 222 223 224

/* function pointers that a high level driver has to use for registration */
/* of some routines it wants to be called from the low level driver */
struct sclp_register {
	struct list_head list;
225
	/* User wants to receive: */
L
Linus Torvalds 已提交
226
	sccb_mask_t receive_mask;
227
	/* User wants to send: */
L
Linus Torvalds 已提交
228
	sccb_mask_t send_mask;
229
	/* H/W can receive: */
L
Linus Torvalds 已提交
230
	sccb_mask_t sclp_receive_mask;
231
	/* H/W can send: */
L
Linus Torvalds 已提交
232 233 234 235 236
	sccb_mask_t sclp_send_mask;
	/* called if event type availability changes */
	void (*state_change_fn)(struct sclp_register *);
	/* called for events in cp_receive_mask/sclp_receive_mask */
	void (*receiver_fn)(struct evbuf_header *);
237 238 239 240
	/* called for power management events */
	void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event);
	/* pm event posted flag */
	int pm_event_posted;
L
Linus Torvalds 已提交
241 242 243 244 245 246 247 248 249 250
};

/* externals from sclp.c */
int sclp_add_request(struct sclp_req *req);
void sclp_sync_wait(void);
int sclp_register(struct sclp_register *reg);
void sclp_unregister(struct sclp_register *reg);
int sclp_remove_processed(struct sccb_header *sccb);
int sclp_deactivate(void);
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);
L
Linus Torvalds 已提交
253

H
Heiko Carstens 已提交
254 255 256
int sclp_sdias_init(void);
void sclp_sdias_exit(void);

257 258 259 260 261 262 263
enum {
	sclp_init_state_uninitialized,
	sclp_init_state_initializing,
	sclp_init_state_initialized
};

extern int sclp_init_state;
264 265 266
extern int sclp_console_pages;
extern int sclp_console_drop;
extern unsigned long sclp_console_full;
267
extern bool sclp_mask_compat_mode;
268

269 270 271 272 273
extern char sclp_early_sccb[PAGE_SIZE];

void sclp_early_wait_irq(void);
int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb);
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 277
			      sccb_mask_t receive_mask,
			      sccb_mask_t send_mask);
278

L
Linus Torvalds 已提交
279 280
/* useful inlines */

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
/* Perform service call. Return 0 on success, non-zero otherwise. */
static inline int sclp_service_call(sclp_cmdw_t command, void *sccb)
{
	int cc = 4; /* Initialize for program check handling */

	asm volatile(
		"0:	.insn	rre,0xb2200000,%1,%2\n"	 /* servc %1,%2 */
		"1:	ipm	%0\n"
		"	srl	%0,28\n"
		"2:\n"
		EX_TABLE(0b, 2b)
		EX_TABLE(1b, 2b)
		: "+&d" (cc) : "d" (command), "a" ((unsigned long)sccb)
		: "cc", "memory");
	if (cc == 4)
		return -EINVAL;
	if (cc == 3)
		return -EIO;
	if (cc == 2)
		return -EBUSY;
	return 0;
}

L
Linus Torvalds 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
/* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */
/* translate single character from ASCII to EBCDIC */
static inline unsigned char
sclp_ascebc(unsigned char ch)
{
	return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch];
}

/* translate string from EBCDIC to ASCII */
static inline void
sclp_ebcasc_str(unsigned char *str, int nr)
{
	(MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
}

/* translate string from ASCII to EBCDIC */
static inline void
sclp_ascebc_str(unsigned char *str, int nr)
{
	(MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
}

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
static inline struct gds_vector *
sclp_find_gds_vector(void *start, void *end, u16 id)
{
	struct gds_vector *v;

	for (v = start; (void *) v < end; v = (void *) v + v->length)
		if (v->gds_id == id)
			return v;
	return NULL;
}

static inline struct gds_subvector *
sclp_find_gds_subvector(void *start, void *end, u8 key)
{
	struct gds_subvector *sv;

	for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length)
		if (sv->key == key)
			return sv;
	return NULL;
}

L
Linus Torvalds 已提交
348
#endif	 /* __SCLP_H__ */