ipl.c 29.0 KB
Newer Older
M
Michael Holzheu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 *  arch/s390/kernel/ipl.c
 *    ipl/reipl/dump support for Linux on s390.
 *
 *    Copyright (C) IBM Corp. 2005,2006
 *    Author(s): Michael Holzheu <holzheu@de.ibm.com>
 *		 Heiko Carstens <heiko.carstens@de.ibm.com>
 *		 Volker Sameske <sameske@de.ibm.com>
 */

#include <linux/types.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/reboot.h>
16
#include <linux/ctype.h>
M
Michael Holzheu 已提交
17
#include <asm/ipl.h>
M
Michael Holzheu 已提交
18 19 20 21
#include <asm/smp.h>
#include <asm/setup.h>
#include <asm/cpcmd.h>
#include <asm/cio.h>
22
#include <asm/ebcdic.h>
23
#include <asm/reset.h>
24
#include <asm/sclp.h>
M
Michael Holzheu 已提交
25 26

#define IPL_PARM_BLOCK_VERSION 0
27

M
Michael Holzheu 已提交
28 29 30 31 32
#define IPL_UNKNOWN_STR		"unknown"
#define IPL_CCW_STR		"ccw"
#define IPL_FCP_STR		"fcp"
#define IPL_FCP_DUMP_STR	"fcp_dump"
#define IPL_NSS_STR		"nss"
33

M
Michael Holzheu 已提交
34 35 36 37 38 39 40
static char *ipl_type_str(enum ipl_type type)
{
	switch (type) {
	case IPL_TYPE_CCW:
		return IPL_CCW_STR;
	case IPL_TYPE_FCP:
		return IPL_FCP_STR;
M
Michael Holzheu 已提交
41 42
	case IPL_TYPE_FCP_DUMP:
		return IPL_FCP_DUMP_STR;
H
Hongjie Yang 已提交
43 44
	case IPL_TYPE_NSS:
		return IPL_NSS_STR;
M
Michael Holzheu 已提交
45 46 47 48 49 50
	case IPL_TYPE_UNKNOWN:
	default:
		return IPL_UNKNOWN_STR;
	}
}

M
Michael Holzheu 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
enum dump_type {
	DUMP_TYPE_NONE	= 1,
	DUMP_TYPE_CCW	= 2,
	DUMP_TYPE_FCP	= 4,
};

#define DUMP_NONE_STR	 "none"
#define DUMP_CCW_STR	 "ccw"
#define DUMP_FCP_STR	 "fcp"

static char *dump_type_str(enum dump_type type)
{
	switch (type) {
	case DUMP_TYPE_NONE:
		return DUMP_NONE_STR;
	case DUMP_TYPE_CCW:
		return DUMP_CCW_STR;
	case DUMP_TYPE_FCP:
		return DUMP_FCP_STR;
	default:
		return NULL;
	}
}

/*
 * Must be in data section since the bss section
 * is not cleared when these are accessed.
 */
static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
u32 ipl_flags __attribute__((__section__(".data"))) = 0;

M
Michael Holzheu 已提交
82
enum ipl_method {
M
Michael Holzheu 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	REIPL_METHOD_CCW_CIO,
	REIPL_METHOD_CCW_DIAG,
	REIPL_METHOD_CCW_VM,
	REIPL_METHOD_FCP_RO_DIAG,
	REIPL_METHOD_FCP_RW_DIAG,
	REIPL_METHOD_FCP_RO_VM,
	REIPL_METHOD_FCP_DUMP,
	REIPL_METHOD_NSS,
	REIPL_METHOD_DEFAULT,
};

enum dump_method {
	DUMP_METHOD_NONE,
	DUMP_METHOD_CCW_CIO,
	DUMP_METHOD_CCW_DIAG,
	DUMP_METHOD_CCW_VM,
	DUMP_METHOD_FCP_DIAG,
M
Michael Holzheu 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
};

enum shutdown_action {
	SHUTDOWN_REIPL,
	SHUTDOWN_DUMP,
	SHUTDOWN_STOP,
};

#define SHUTDOWN_REIPL_STR "reipl"
#define SHUTDOWN_DUMP_STR  "dump"
#define SHUTDOWN_STOP_STR  "stop"

static char *shutdown_action_str(enum shutdown_action action)
{
	switch (action) {
	case SHUTDOWN_REIPL:
		return SHUTDOWN_REIPL_STR;
	case SHUTDOWN_DUMP:
		return SHUTDOWN_DUMP_STR;
	case SHUTDOWN_STOP:
		return SHUTDOWN_STOP_STR;
	default:
M
Michael Holzheu 已提交
122
		return NULL;
M
Michael Holzheu 已提交
123 124 125 126 127 128
	}
}

static int diag308_set_works = 0;

static int reipl_capabilities = IPL_TYPE_UNKNOWN;
H
Hongjie Yang 已提交
129

M
Michael Holzheu 已提交
130
static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
M
Michael Holzheu 已提交
131
static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
M
Michael Holzheu 已提交
132 133 134
static struct ipl_parameter_block *reipl_block_fcp;
static struct ipl_parameter_block *reipl_block_ccw;

H
Hongjie Yang 已提交
135 136
static char reipl_nss_name[NSS_NAME_SIZE + 1];

M
Michael Holzheu 已提交
137 138 139
static int dump_capabilities = DUMP_TYPE_NONE;
static enum dump_type dump_type = DUMP_TYPE_NONE;
static enum dump_method dump_method = DUMP_METHOD_NONE;
M
Michael Holzheu 已提交
140 141 142 143 144
static struct ipl_parameter_block *dump_block_fcp;
static struct ipl_parameter_block *dump_block_ccw;

static enum shutdown_action on_panic_action = SHUTDOWN_STOP;

145 146
static struct sclp_ipl_info sclp_ipl_info;

M
Michael Holzheu 已提交
147
int diag308(unsigned long subcode, void *addr)
M
Michael Holzheu 已提交
148
{
149
	register unsigned long _addr asm("0") = (unsigned long) addr;
M
Michael Holzheu 已提交
150 151
	register unsigned long _rc asm("1") = 0;

152 153 154 155
	asm volatile(
		"	diag	%0,%2,0x308\n"
		"0:\n"
		EX_TABLE(0b,0b)
M
Michael Holzheu 已提交
156
		: "+d" (_addr), "+d" (_rc)
157
		: "d" (subcode) : "cc", "memory");
M
Michael Holzheu 已提交
158 159
	return _rc;
}
M
Michael Holzheu 已提交
160
EXPORT_SYMBOL_GPL(diag308);
M
Michael Holzheu 已提交
161 162 163 164

/* SYSFS */

#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value)		\
165 166
static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj,	\
		struct kobj_attribute *attr,				\
M
Michael Holzheu 已提交
167 168 169 170
		char *page)						\
{									\
	return sprintf(page, _format, _value);				\
}									\
171
static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
M
Michael Holzheu 已提交
172 173 174
	__ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);

#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)	\
175 176
static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj,	\
		struct kobj_attribute *attr,				\
M
Michael Holzheu 已提交
177 178 179 180 181
		char *page)						\
{									\
	return sprintf(page, _fmt_out,					\
			(unsigned long long) _value);			\
}									\
182 183
static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,	\
		struct kobj_attribute *attr,				\
M
Michael Holzheu 已提交
184 185 186 187 188 189 190 191
		const char *buf, size_t len)				\
{									\
	unsigned long long value;					\
	if (sscanf(buf, _fmt_in, &value) != 1)				\
		return -EINVAL;						\
	_value = value;							\
	return len;							\
}									\
192
static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
M
Michael Holzheu 已提交
193 194 195 196
	__ATTR(_name,(S_IRUGO | S_IWUSR),				\
			sys_##_prefix##_##_name##_show,			\
			sys_##_prefix##_##_name##_store);

H
Hongjie Yang 已提交
197
#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
198 199
static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj,	\
		struct kobj_attribute *attr,				\
H
Hongjie Yang 已提交
200 201 202 203
		char *page)						\
{									\
	return sprintf(page, _fmt_out, _value);				\
}									\
204 205
static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,	\
		struct kobj_attribute *attr,				\
H
Hongjie Yang 已提交
206 207 208 209 210 211
		const char *buf, size_t len)				\
{									\
	if (sscanf(buf, _fmt_in, _value) != 1)				\
		return -EINVAL;						\
	return len;							\
}									\
212
static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
H
Hongjie Yang 已提交
213 214 215 216
	__ATTR(_name,(S_IRUGO | S_IWUSR),				\
			sys_##_prefix##_##_name##_show,			\
			sys_##_prefix##_##_name##_store);

M
Michael Holzheu 已提交
217 218 219 220 221 222 223 224 225 226 227 228
static void make_attrs_ro(struct attribute **attrs)
{
	while (*attrs) {
		(*attrs)->mode = S_IRUGO;
		attrs++;
	}
}

/*
 * ipl section
 */

M
Michael Holzheu 已提交
229
static __init enum ipl_type get_ipl_type(void)
M
Michael Holzheu 已提交
230 231 232
{
	struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;

H
Hongjie Yang 已提交
233 234
	if (ipl_flags & IPL_NSS_VALID)
		return IPL_TYPE_NSS;
235
	if (!(ipl_flags & IPL_DEVNO_VALID))
M
Michael Holzheu 已提交
236
		return IPL_TYPE_UNKNOWN;
237
	if (!(ipl_flags & IPL_PARMBLOCK_VALID))
M
Michael Holzheu 已提交
238 239 240 241 242
		return IPL_TYPE_CCW;
	if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
		return IPL_TYPE_UNKNOWN;
	if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
		return IPL_TYPE_UNKNOWN;
M
Michael Holzheu 已提交
243 244
	if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
		return IPL_TYPE_FCP_DUMP;
M
Michael Holzheu 已提交
245 246 247
	return IPL_TYPE_FCP;
}

M
Michael Holzheu 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
void __init setup_ipl_info(void)
{
	ipl_info.type = get_ipl_type();
	switch (ipl_info.type) {
	case IPL_TYPE_CCW:
		ipl_info.data.ccw.dev_id.devno = ipl_devno;
		ipl_info.data.ccw.dev_id.ssid = 0;
		break;
	case IPL_TYPE_FCP:
	case IPL_TYPE_FCP_DUMP:
		ipl_info.data.fcp.dev_id.devno =
			IPL_PARMBLOCK_START->ipl_info.fcp.devno;
		ipl_info.data.fcp.dev_id.ssid = 0;
		ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
		ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
		break;
	case IPL_TYPE_NSS:
		strncpy(ipl_info.data.nss.name, kernel_nss_name,
			sizeof(ipl_info.data.nss.name));
		break;
	case IPL_TYPE_UNKNOWN:
	default:
		/* We have no info to copy */
		break;
	}
}

struct ipl_info ipl_info;
EXPORT_SYMBOL_GPL(ipl_info);

278 279
static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
			     char *page)
M
Michael Holzheu 已提交
280
{
M
Michael Holzheu 已提交
281
	return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
M
Michael Holzheu 已提交
282 283
}

284
static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
M
Michael Holzheu 已提交
285

286 287
static ssize_t sys_ipl_device_show(struct kobject *kobj,
				   struct kobj_attribute *attr, char *page)
M
Michael Holzheu 已提交
288 289 290
{
	struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;

M
Michael Holzheu 已提交
291
	switch (ipl_info.type) {
M
Michael Holzheu 已提交
292 293 294
	case IPL_TYPE_CCW:
		return sprintf(page, "0.0.%04x\n", ipl_devno);
	case IPL_TYPE_FCP:
M
Michael Holzheu 已提交
295
	case IPL_TYPE_FCP_DUMP:
M
Michael Holzheu 已提交
296 297 298 299 300 301
		return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
	default:
		return 0;
	}
}

302
static struct kobj_attribute sys_ipl_device_attr =
M
Michael Holzheu 已提交
303 304
	__ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);

305 306
static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
				  char *buf, loff_t off, size_t count)
M
Michael Holzheu 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
{
	unsigned int size = IPL_PARMBLOCK_SIZE;

	if (off > size)
		return 0;
	if (off + count > size)
		count = size - off;
	memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
	return count;
}

static struct bin_attribute ipl_parameter_attr = {
	.attr = {
		.name = "binary_parameter",
		.mode = S_IRUGO,
	},
	.size = PAGE_SIZE,
	.read = &ipl_parameter_read,
};

327 328
static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
				 char *buf, loff_t off, size_t count)
M
Michael Holzheu 已提交
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
{
	unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
	void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;

	if (off > size)
		return 0;
	if (off + count > size)
		count = size - off;
	memcpy(buf, scp_data + off, count);
	return count;
}

static struct bin_attribute ipl_scp_data_attr = {
	.attr = {
		.name = "scp_data",
		.mode = S_IRUGO,
	},
	.size = PAGE_SIZE,
347
	.read = ipl_scp_data_read,
M
Michael Holzheu 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
};

/* FCP ipl device attributes */

DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
		   IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
		   IPL_PARMBLOCK_START->ipl_info.fcp.lun);
DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
		   IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
		   IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);

static struct attribute *ipl_fcp_attrs[] = {
	&sys_ipl_type_attr.attr,
	&sys_ipl_device_attr.attr,
	&sys_ipl_fcp_wwpn_attr.attr,
	&sys_ipl_fcp_lun_attr.attr,
	&sys_ipl_fcp_bootprog_attr.attr,
	&sys_ipl_fcp_br_lba_attr.attr,
	NULL,
};

static struct attribute_group ipl_fcp_attr_group = {
	.attrs = ipl_fcp_attrs,
};

/* CCW ipl device attributes */

377 378
static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
				     struct kobj_attribute *attr, char *page)
379 380 381
{
	char loadparm[LOADPARM_LEN + 1] = {};

382
	if (!sclp_ipl_info.is_valid)
383
		return sprintf(page, "#unknown#\n");
384
	memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
385 386 387 388 389
	EBCASC(loadparm, LOADPARM_LEN);
	strstrip(loadparm);
	return sprintf(page, "%s\n", loadparm);
}

390
static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
391 392
	__ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);

M
Michael Holzheu 已提交
393 394 395
static struct attribute *ipl_ccw_attrs[] = {
	&sys_ipl_type_attr.attr,
	&sys_ipl_device_attr.attr,
396
	&sys_ipl_ccw_loadparm_attr.attr,
M
Michael Holzheu 已提交
397 398 399 400 401 402 403
	NULL,
};

static struct attribute_group ipl_ccw_attr_group = {
	.attrs = ipl_ccw_attrs,
};

H
Hongjie Yang 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417
/* NSS ipl device attributes */

DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);

static struct attribute *ipl_nss_attrs[] = {
	&sys_ipl_type_attr.attr,
	&sys_ipl_nss_name_attr.attr,
	NULL,
};

static struct attribute_group ipl_nss_attr_group = {
	.attrs = ipl_nss_attrs,
};

M
Michael Holzheu 已提交
418 419 420 421 422 423 424 425 426 427 428
/* UNKNOWN ipl device attributes */

static struct attribute *ipl_unknown_attrs[] = {
	&sys_ipl_type_attr.attr,
	NULL,
};

static struct attribute_group ipl_unknown_attr_group = {
	.attrs = ipl_unknown_attrs,
};

429
static decl_subsys(ipl, NULL);
M
Michael Holzheu 已提交
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

/*
 * reipl section
 */

/* FCP reipl device attributes */

DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
		   reipl_block_fcp->ipl_info.fcp.wwpn);
DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
		   reipl_block_fcp->ipl_info.fcp.lun);
DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
		   reipl_block_fcp->ipl_info.fcp.bootprog);
DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
		   reipl_block_fcp->ipl_info.fcp.br_lba);
DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
		   reipl_block_fcp->ipl_info.fcp.devno);

static struct attribute *reipl_fcp_attrs[] = {
	&sys_reipl_fcp_device_attr.attr,
	&sys_reipl_fcp_wwpn_attr.attr,
	&sys_reipl_fcp_lun_attr.attr,
	&sys_reipl_fcp_bootprog_attr.attr,
	&sys_reipl_fcp_br_lba_attr.attr,
	NULL,
};

static struct attribute_group reipl_fcp_attr_group = {
	.name  = IPL_FCP_STR,
	.attrs = reipl_fcp_attrs,
};

/* CCW reipl device attributes */

DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
	reipl_block_ccw->ipl_info.ccw.devno);

467 468 469 470 471 472 473 474 475
static void reipl_get_ascii_loadparm(char *loadparm)
{
	memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
	       LOADPARM_LEN);
	EBCASC(loadparm, LOADPARM_LEN);
	loadparm[LOADPARM_LEN] = 0;
	strstrip(loadparm);
}

476 477
static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
				       struct kobj_attribute *attr, char *page)
478 479 480 481 482 483 484
{
	char buf[LOADPARM_LEN + 1];

	reipl_get_ascii_loadparm(buf);
	return sprintf(page, "%s\n", buf);
}

485 486
static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
					struct kobj_attribute *attr,
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
					const char *buf, size_t len)
{
	int i, lp_len;

	/* ignore trailing newline */
	lp_len = len;
	if ((len > 0) && (buf[len - 1] == '\n'))
		lp_len--;
	/* loadparm can have max 8 characters and must not start with a blank */
	if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
		return -EINVAL;
	/* loadparm can only contain "a-z,A-Z,0-9,SP,." */
	for (i = 0; i < lp_len; i++) {
		if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
		    (buf[i] == '.'))
			continue;
		return -EINVAL;
	}
	/* initialize loadparm with blanks */
	memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
	/* copy and convert to ebcdic */
	memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
	ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
	return len;
}

513
static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
514 515 516
	__ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
	       reipl_ccw_loadparm_store);

M
Michael Holzheu 已提交
517 518
static struct attribute *reipl_ccw_attrs[] = {
	&sys_reipl_ccw_device_attr.attr,
519
	&sys_reipl_ccw_loadparm_attr.attr,
M
Michael Holzheu 已提交
520 521 522 523 524 525 526 527
	NULL,
};

static struct attribute_group reipl_ccw_attr_group = {
	.name  = IPL_CCW_STR,
	.attrs = reipl_ccw_attrs,
};

H
Hongjie Yang 已提交
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

/* NSS reipl device attributes */

DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);

static struct attribute *reipl_nss_attrs[] = {
	&sys_reipl_nss_name_attr.attr,
	NULL,
};

static struct attribute_group reipl_nss_attr_group = {
	.name  = IPL_NSS_STR,
	.attrs = reipl_nss_attrs,
};

M
Michael Holzheu 已提交
543 544 545 546 547 548 549 550 551 552
/* reipl type */

static int reipl_set_type(enum ipl_type type)
{
	if (!(reipl_capabilities & type))
		return -EINVAL;

	switch(type) {
	case IPL_TYPE_CCW:
		if (MACHINE_IS_VM)
M
Michael Holzheu 已提交
553
			reipl_method = REIPL_METHOD_CCW_VM;
M
Michael Holzheu 已提交
554
		else
M
Michael Holzheu 已提交
555
			reipl_method = REIPL_METHOD_CCW_CIO;
M
Michael Holzheu 已提交
556 557 558
		break;
	case IPL_TYPE_FCP:
		if (diag308_set_works)
M
Michael Holzheu 已提交
559
			reipl_method = REIPL_METHOD_FCP_RW_DIAG;
M
Michael Holzheu 已提交
560
		else if (MACHINE_IS_VM)
M
Michael Holzheu 已提交
561
			reipl_method = REIPL_METHOD_FCP_RO_VM;
M
Michael Holzheu 已提交
562
		else
M
Michael Holzheu 已提交
563 564 565 566
			reipl_method = REIPL_METHOD_FCP_RO_DIAG;
		break;
	case IPL_TYPE_FCP_DUMP:
		reipl_method = REIPL_METHOD_FCP_DUMP;
M
Michael Holzheu 已提交
567
		break;
H
Hongjie Yang 已提交
568
	case IPL_TYPE_NSS:
M
Michael Holzheu 已提交
569 570 571 572
		reipl_method = REIPL_METHOD_NSS;
		break;
	case IPL_TYPE_UNKNOWN:
		reipl_method = REIPL_METHOD_DEFAULT;
H
Hongjie Yang 已提交
573
		break;
M
Michael Holzheu 已提交
574
	default:
M
Michael Holzheu 已提交
575
		BUG();
M
Michael Holzheu 已提交
576 577 578 579 580
	}
	reipl_type = type;
	return 0;
}

581 582
static ssize_t reipl_type_show(struct kobject *kobj,
			       struct kobj_attribute *attr, char *page)
M
Michael Holzheu 已提交
583 584 585 586
{
	return sprintf(page, "%s\n", ipl_type_str(reipl_type));
}

587 588 589
static ssize_t reipl_type_store(struct kobject *kobj,
				struct kobj_attribute *attr,
				const char *buf, size_t len)
M
Michael Holzheu 已提交
590 591 592 593 594 595 596
{
	int rc = -EINVAL;

	if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
		rc = reipl_set_type(IPL_TYPE_CCW);
	else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
		rc = reipl_set_type(IPL_TYPE_FCP);
H
Hongjie Yang 已提交
597 598
	else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
		rc = reipl_set_type(IPL_TYPE_NSS);
M
Michael Holzheu 已提交
599 600 601
	return (rc != 0) ? rc : len;
}

602
static struct kobj_attribute reipl_type_attr =
M
Michael Holzheu 已提交
603 604
		__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);

605
static decl_subsys(reipl, NULL);
M
Michael Holzheu 已提交
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654

/*
 * dump section
 */

/* FCP dump device attributes */

DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
		   dump_block_fcp->ipl_info.fcp.wwpn);
DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
		   dump_block_fcp->ipl_info.fcp.lun);
DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
		   dump_block_fcp->ipl_info.fcp.bootprog);
DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
		   dump_block_fcp->ipl_info.fcp.br_lba);
DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
		   dump_block_fcp->ipl_info.fcp.devno);

static struct attribute *dump_fcp_attrs[] = {
	&sys_dump_fcp_device_attr.attr,
	&sys_dump_fcp_wwpn_attr.attr,
	&sys_dump_fcp_lun_attr.attr,
	&sys_dump_fcp_bootprog_attr.attr,
	&sys_dump_fcp_br_lba_attr.attr,
	NULL,
};

static struct attribute_group dump_fcp_attr_group = {
	.name  = IPL_FCP_STR,
	.attrs = dump_fcp_attrs,
};

/* CCW dump device attributes */

DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
		   dump_block_ccw->ipl_info.ccw.devno);

static struct attribute *dump_ccw_attrs[] = {
	&sys_dump_ccw_device_attr.attr,
	NULL,
};

static struct attribute_group dump_ccw_attr_group = {
	.name  = IPL_CCW_STR,
	.attrs = dump_ccw_attrs,
};

/* dump type */

M
Michael Holzheu 已提交
655
static int dump_set_type(enum dump_type type)
M
Michael Holzheu 已提交
656 657 658 659
{
	if (!(dump_capabilities & type))
		return -EINVAL;
	switch(type) {
M
Michael Holzheu 已提交
660
	case DUMP_TYPE_CCW:
M
Michael Holzheu 已提交
661
		if (MACHINE_IS_VM)
M
Michael Holzheu 已提交
662
			dump_method = DUMP_METHOD_CCW_VM;
663 664
		else if (diag308_set_works)
			dump_method = DUMP_METHOD_CCW_DIAG;
M
Michael Holzheu 已提交
665
		else
M
Michael Holzheu 已提交
666
			dump_method = DUMP_METHOD_CCW_CIO;
M
Michael Holzheu 已提交
667
		break;
M
Michael Holzheu 已提交
668 669
	case DUMP_TYPE_FCP:
		dump_method = DUMP_METHOD_FCP_DIAG;
M
Michael Holzheu 已提交
670 671
		break;
	default:
M
Michael Holzheu 已提交
672
		dump_method = DUMP_METHOD_NONE;
M
Michael Holzheu 已提交
673 674 675 676 677
	}
	dump_type = type;
	return 0;
}

678 679
static ssize_t dump_type_show(struct kobject *kobj,
			      struct kobj_attribute *attr, char *page)
M
Michael Holzheu 已提交
680
{
M
Michael Holzheu 已提交
681
	return sprintf(page, "%s\n", dump_type_str(dump_type));
M
Michael Holzheu 已提交
682 683
}

684 685 686
static ssize_t dump_type_store(struct kobject *kobj,
			       struct kobj_attribute *attr,
			       const char *buf, size_t len)
M
Michael Holzheu 已提交
687 688 689
{
	int rc = -EINVAL;

M
Michael Holzheu 已提交
690 691 692 693 694 695
	if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
		rc = dump_set_type(DUMP_TYPE_NONE);
	else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
		rc = dump_set_type(DUMP_TYPE_CCW);
	else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
		rc = dump_set_type(DUMP_TYPE_FCP);
M
Michael Holzheu 已提交
696 697 698
	return (rc != 0) ? rc : len;
}

699
static struct kobj_attribute dump_type_attr =
M
Michael Holzheu 已提交
700 701
		__ATTR(dump_type, 0644, dump_type_show, dump_type_store);

702
static decl_subsys(dump, NULL);
M
Michael Holzheu 已提交
703 704 705 706 707

/*
 * Shutdown actions section
 */

708
static decl_subsys(shutdown_actions, NULL);
M
Michael Holzheu 已提交
709 710 711

/* on panic */

712 713
static ssize_t on_panic_show(struct kobject *kobj,
			     struct kobj_attribute *attr, char *page)
M
Michael Holzheu 已提交
714 715 716 717
{
	return sprintf(page, "%s\n", shutdown_action_str(on_panic_action));
}

718 719 720
static ssize_t on_panic_store(struct kobject *kobj,
			      struct kobj_attribute *attr,
			      const char *buf, size_t len)
M
Michael Holzheu 已提交
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
{
	if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0)
		on_panic_action = SHUTDOWN_REIPL;
	else if (strncmp(buf, SHUTDOWN_DUMP_STR,
			 strlen(SHUTDOWN_DUMP_STR)) == 0)
		on_panic_action = SHUTDOWN_DUMP;
	else if (strncmp(buf, SHUTDOWN_STOP_STR,
			 strlen(SHUTDOWN_STOP_STR)) == 0)
		on_panic_action = SHUTDOWN_STOP;
	else
		return -EINVAL;

	return len;
}

736
static struct kobj_attribute on_panic_attr =
M
Michael Holzheu 已提交
737 738 739 740 741 742
		__ATTR(on_panic, 0644, on_panic_show, on_panic_store);

void do_reipl(void)
{
	struct ccw_dev_id devid;
	static char buf[100];
743
	char loadparm[LOADPARM_LEN + 1];
M
Michael Holzheu 已提交
744 745

	switch (reipl_method) {
M
Michael Holzheu 已提交
746
	case REIPL_METHOD_CCW_CIO:
M
Michael Holzheu 已提交
747
		devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
M
Michael Holzheu 已提交
748
		if (ipl_info.type == IPL_TYPE_CCW && devid.devno == ipl_devno)
749
			diag308(DIAG308_IPL, NULL);
M
Michael Holzheu 已提交
750 751 752
		devid.ssid  = 0;
		reipl_ccw_dev(&devid);
		break;
M
Michael Holzheu 已提交
753
	case REIPL_METHOD_CCW_VM:
M
Michael Holzheu 已提交
754
		reipl_get_ascii_loadparm(loadparm);
755
		if (strlen(loadparm) == 0)
756
			sprintf(buf, "IPL %X CLEAR",
757 758
				reipl_block_ccw->ipl_info.ccw.devno);
		else
759
			sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
760
				reipl_block_ccw->ipl_info.ccw.devno, loadparm);
761
		__cpcmd(buf, NULL, 0, NULL);
M
Michael Holzheu 已提交
762
		break;
M
Michael Holzheu 已提交
763
	case REIPL_METHOD_CCW_DIAG:
M
Michael Holzheu 已提交
764 765 766
		diag308(DIAG308_SET, reipl_block_ccw);
		diag308(DIAG308_IPL, NULL);
		break;
M
Michael Holzheu 已提交
767
	case REIPL_METHOD_FCP_RW_DIAG:
M
Michael Holzheu 已提交
768 769 770
		diag308(DIAG308_SET, reipl_block_fcp);
		diag308(DIAG308_IPL, NULL);
		break;
M
Michael Holzheu 已提交
771
	case REIPL_METHOD_FCP_RO_DIAG:
M
Michael Holzheu 已提交
772 773
		diag308(DIAG308_IPL, NULL);
		break;
M
Michael Holzheu 已提交
774
	case REIPL_METHOD_FCP_RO_VM:
775
		__cpcmd("IPL", NULL, 0, NULL);
M
Michael Holzheu 已提交
776
		break;
M
Michael Holzheu 已提交
777
	case REIPL_METHOD_NSS:
H
Hongjie Yang 已提交
778 779 780
		sprintf(buf, "IPL %s", reipl_nss_name);
		__cpcmd(buf, NULL, 0, NULL);
		break;
M
Michael Holzheu 已提交
781
	case REIPL_METHOD_DEFAULT:
M
Michael Holzheu 已提交
782
		if (MACHINE_IS_VM)
783
			__cpcmd("IPL", NULL, 0, NULL);
M
Michael Holzheu 已提交
784 785
		diag308(DIAG308_IPL, NULL);
		break;
M
Michael Holzheu 已提交
786 787 788
	case REIPL_METHOD_FCP_DUMP:
	default:
		break;
M
Michael Holzheu 已提交
789
	}
790
	signal_processor(smp_processor_id(), sigp_stop_and_store_status);
M
Michael Holzheu 已提交
791 792 793 794 795 796 797 798
}

static void do_dump(void)
{
	struct ccw_dev_id devid;
	static char buf[100];

	switch (dump_method) {
M
Michael Holzheu 已提交
799
	case DUMP_METHOD_CCW_CIO:
H
Heiko Carstens 已提交
800
		smp_send_stop();
M
Michael Holzheu 已提交
801 802 803 804
		devid.devno = dump_block_ccw->ipl_info.ccw.devno;
		devid.ssid  = 0;
		reipl_ccw_dev(&devid);
		break;
M
Michael Holzheu 已提交
805
	case DUMP_METHOD_CCW_VM:
H
Heiko Carstens 已提交
806
		smp_send_stop();
M
Michael Holzheu 已提交
807
		sprintf(buf, "STORE STATUS");
808
		__cpcmd(buf, NULL, 0, NULL);
M
Michael Holzheu 已提交
809
		sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
810
		__cpcmd(buf, NULL, 0, NULL);
M
Michael Holzheu 已提交
811
		break;
M
Michael Holzheu 已提交
812
	case DUMP_METHOD_CCW_DIAG:
M
Michael Holzheu 已提交
813 814 815
		diag308(DIAG308_SET, dump_block_ccw);
		diag308(DIAG308_DUMP, NULL);
		break;
M
Michael Holzheu 已提交
816
	case DUMP_METHOD_FCP_DIAG:
M
Michael Holzheu 已提交
817 818 819
		diag308(DIAG308_SET, dump_block_fcp);
		diag308(DIAG308_DUMP, NULL);
		break;
M
Michael Holzheu 已提交
820
	case DUMP_METHOD_NONE:
M
Michael Holzheu 已提交
821 822 823 824 825 826 827 828 829 830 831 832
	default:
		return;
	}
	printk(KERN_EMERG "Dump failed!\n");
}

/* init functions */

static int __init ipl_register_fcp_files(void)
{
	int rc;

833
	rc = sysfs_create_group(&ipl_subsys.kobj,
M
Michael Holzheu 已提交
834 835 836
				&ipl_fcp_attr_group);
	if (rc)
		goto out;
837
	rc = sysfs_create_bin_file(&ipl_subsys.kobj,
M
Michael Holzheu 已提交
838 839 840
				   &ipl_parameter_attr);
	if (rc)
		goto out_ipl_parm;
841
	rc = sysfs_create_bin_file(&ipl_subsys.kobj,
M
Michael Holzheu 已提交
842 843 844 845
				   &ipl_scp_data_attr);
	if (!rc)
		goto out;

846
	sysfs_remove_bin_file(&ipl_subsys.kobj, &ipl_parameter_attr);
M
Michael Holzheu 已提交
847 848

out_ipl_parm:
849
	sysfs_remove_group(&ipl_subsys.kobj, &ipl_fcp_attr_group);
M
Michael Holzheu 已提交
850 851 852 853 854 855 856 857 858 859 860
out:
	return rc;
}

static int __init ipl_init(void)
{
	int rc;

	rc = firmware_register(&ipl_subsys);
	if (rc)
		return rc;
M
Michael Holzheu 已提交
861
	switch (ipl_info.type) {
M
Michael Holzheu 已提交
862
	case IPL_TYPE_CCW:
863
		rc = sysfs_create_group(&ipl_subsys.kobj,
M
Michael Holzheu 已提交
864 865 866
					&ipl_ccw_attr_group);
		break;
	case IPL_TYPE_FCP:
M
Michael Holzheu 已提交
867
	case IPL_TYPE_FCP_DUMP:
M
Michael Holzheu 已提交
868 869
		rc = ipl_register_fcp_files();
		break;
H
Hongjie Yang 已提交
870
	case IPL_TYPE_NSS:
871
		rc = sysfs_create_group(&ipl_subsys.kobj,
H
Hongjie Yang 已提交
872 873
					&ipl_nss_attr_group);
		break;
M
Michael Holzheu 已提交
874
	default:
875
		rc = sysfs_create_group(&ipl_subsys.kobj,
M
Michael Holzheu 已提交
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
					&ipl_unknown_attr_group);
		break;
	}
	if (rc)
		firmware_unregister(&ipl_subsys);
	return rc;
}

static void __init reipl_probe(void)
{
	void *buffer;

	buffer = (void *) get_zeroed_page(GFP_KERNEL);
	if (!buffer)
		return;
	if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
		diag308_set_works = 1;
	free_page((unsigned long)buffer);
}

H
Hongjie Yang 已提交
896 897 898 899 900 901
static int __init reipl_nss_init(void)
{
	int rc;

	if (!MACHINE_IS_VM)
		return 0;
902
	rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_nss_attr_group);
H
Hongjie Yang 已提交
903 904 905 906 907 908 909
	if (rc)
		return rc;
	strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
	reipl_capabilities |= IPL_TYPE_NSS;
	return 0;
}

M
Michael Holzheu 已提交
910 911 912 913 914 915 916
static int __init reipl_ccw_init(void)
{
	int rc;

	reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
	if (!reipl_block_ccw)
		return -ENOMEM;
917
	rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_ccw_attr_group);
M
Michael Holzheu 已提交
918 919 920 921 922 923
	if (rc) {
		free_page((unsigned long)reipl_block_ccw);
		return rc;
	}
	reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
	reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
924
	reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
M
Michael Holzheu 已提交
925
	reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
926
	/* check if read scp info worked and set loadparm */
927
	if (sclp_ipl_info.is_valid)
928
		memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
929
		       &sclp_ipl_info.loadparm, LOADPARM_LEN);
930 931 932 933 934 935 936
	else
		/* read scp info failed: set empty loadparm (EBCDIC blanks) */
		memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
		       LOADPARM_LEN);
	/* FIXME: check for diag308_set_works when enabling diag ccw reipl */
	if (!MACHINE_IS_VM)
		sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
M
Michael Holzheu 已提交
937
	if (ipl_info.type == IPL_TYPE_CCW)
M
Michael Holzheu 已提交
938 939 940 941 942 943 944 945 946
		reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
	reipl_capabilities |= IPL_TYPE_CCW;
	return 0;
}

static int __init reipl_fcp_init(void)
{
	int rc;

M
Michael Holzheu 已提交
947
	if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
M
Michael Holzheu 已提交
948
		return 0;
M
Michael Holzheu 已提交
949
	if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
M
Michael Holzheu 已提交
950 951 952 953 954
		make_attrs_ro(reipl_fcp_attrs);

	reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
	if (!reipl_block_fcp)
		return -ENOMEM;
955
	rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_fcp_attr_group);
M
Michael Holzheu 已提交
956 957 958 959
	if (rc) {
		free_page((unsigned long)reipl_block_fcp);
		return rc;
	}
M
Michael Holzheu 已提交
960
	if (ipl_info.type == IPL_TYPE_FCP) {
M
Michael Holzheu 已提交
961 962 963 964
		memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
	} else {
		reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
		reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
965
		reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
M
Michael Holzheu 已提交
966 967 968 969 970 971 972 973 974 975 976 977 978 979
		reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
		reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
	}
	reipl_capabilities |= IPL_TYPE_FCP;
	return 0;
}

static int __init reipl_init(void)
{
	int rc;

	rc = firmware_register(&reipl_subsys);
	if (rc)
		return rc;
980
	rc = sysfs_create_file(&reipl_subsys.kobj, &reipl_type_attr.attr);
M
Michael Holzheu 已提交
981 982 983 984 985 986 987 988
	if (rc) {
		firmware_unregister(&reipl_subsys);
		return rc;
	}
	rc = reipl_ccw_init();
	if (rc)
		return rc;
	rc = reipl_fcp_init();
H
Hongjie Yang 已提交
989 990 991
	if (rc)
		return rc;
	rc = reipl_nss_init();
M
Michael Holzheu 已提交
992 993
	if (rc)
		return rc;
M
Michael Holzheu 已提交
994
	rc = reipl_set_type(ipl_info.type);
M
Michael Holzheu 已提交
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
	if (rc)
		return rc;
	return 0;
}

static int __init dump_ccw_init(void)
{
	int rc;

	dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
	if (!dump_block_ccw)
		return -ENOMEM;
1007
	rc = sysfs_create_group(&dump_subsys.kobj, &dump_ccw_attr_group);
M
Michael Holzheu 已提交
1008 1009 1010 1011 1012 1013
	if (rc) {
		free_page((unsigned long)dump_block_ccw);
		return rc;
	}
	dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
	dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1014
	dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
M
Michael Holzheu 已提交
1015
	dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
M
Michael Holzheu 已提交
1016
	dump_capabilities |= DUMP_TYPE_CCW;
M
Michael Holzheu 已提交
1017 1018 1019 1020 1021 1022 1023
	return 0;
}

static int __init dump_fcp_init(void)
{
	int rc;

1024
	if (!sclp_ipl_info.has_dump)
M
Michael Holzheu 已提交
1025 1026 1027 1028 1029 1030
		return 0; /* LDIPL DUMP is not installed */
	if (!diag308_set_works)
		return 0;
	dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
	if (!dump_block_fcp)
		return -ENOMEM;
1031
	rc = sysfs_create_group(&dump_subsys.kobj, &dump_fcp_attr_group);
M
Michael Holzheu 已提交
1032 1033 1034 1035 1036 1037
	if (rc) {
		free_page((unsigned long)dump_block_fcp);
		return rc;
	}
	dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
	dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1038
	dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
M
Michael Holzheu 已提交
1039 1040
	dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
	dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
M
Michael Holzheu 已提交
1041
	dump_capabilities |= DUMP_TYPE_FCP;
M
Michael Holzheu 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
	return 0;
}

#define SHUTDOWN_ON_PANIC_PRIO 0

static int shutdown_on_panic_notify(struct notifier_block *self,
				    unsigned long event, void *data)
{
	if (on_panic_action == SHUTDOWN_DUMP)
		do_dump();
	else if (on_panic_action == SHUTDOWN_REIPL)
		do_reipl();
	return NOTIFY_OK;
}

static struct notifier_block shutdown_on_panic_nb = {
	.notifier_call = shutdown_on_panic_notify,
	.priority = SHUTDOWN_ON_PANIC_PRIO
};

static int __init dump_init(void)
{
	int rc;

	rc = firmware_register(&dump_subsys);
	if (rc)
		return rc;
1069
	rc = sysfs_create_file(&dump_subsys.kobj, &dump_type_attr.attr);
M
Michael Holzheu 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
	if (rc) {
		firmware_unregister(&dump_subsys);
		return rc;
	}
	rc = dump_ccw_init();
	if (rc)
		return rc;
	rc = dump_fcp_init();
	if (rc)
		return rc;
M
Michael Holzheu 已提交
1080
	dump_set_type(DUMP_TYPE_NONE);
M
Michael Holzheu 已提交
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	return 0;
}

static int __init shutdown_actions_init(void)
{
	int rc;

	rc = firmware_register(&shutdown_actions_subsys);
	if (rc)
		return rc;
1091
	rc = sysfs_create_file(&shutdown_actions_subsys.kobj, &on_panic_attr.attr);
M
Michael Holzheu 已提交
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
	if (rc) {
		firmware_unregister(&shutdown_actions_subsys);
		return rc;
	}
	atomic_notifier_chain_register(&panic_notifier_list,
				       &shutdown_on_panic_nb);
	return 0;
}

static int __init s390_ipl_init(void)
{
	int rc;

1105
	sclp_get_ipl_info(&sclp_ipl_info);
M
Michael Holzheu 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
	reipl_probe();
	rc = ipl_init();
	if (rc)
		return rc;
	rc = reipl_init();
	if (rc)
		return rc;
	rc = dump_init();
	if (rc)
		return rc;
	rc = shutdown_actions_init();
	if (rc)
		return rc;
	return 0;
}

__initcall(s390_ipl_init);
1123

1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
void __init ipl_save_parameters(void)
{
	struct cio_iplinfo iplinfo;
	unsigned int *ipl_ptr;
	void *src, *dst;

	if (cio_get_iplinfo(&iplinfo))
		return;

	ipl_devno = iplinfo.devno;
	ipl_flags |= IPL_DEVNO_VALID;
	if (!iplinfo.is_qdio)
		return;
	ipl_flags |= IPL_PARMBLOCK_VALID;
	ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
	src = (void *)(unsigned long)*ipl_ptr;
	dst = (void *)IPL_PARMBLOCK_ORIGIN;
	memmove(dst, src, PAGE_SIZE);
	*ipl_ptr = IPL_PARMBLOCK_ORIGIN;
}

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
static LIST_HEAD(rcall);
static DEFINE_MUTEX(rcall_mutex);

void register_reset_call(struct reset_call *reset)
{
	mutex_lock(&rcall_mutex);
	list_add(&reset->list, &rcall);
	mutex_unlock(&rcall_mutex);
}
EXPORT_SYMBOL_GPL(register_reset_call);

void unregister_reset_call(struct reset_call *reset)
{
	mutex_lock(&rcall_mutex);
	list_del(&reset->list);
	mutex_unlock(&rcall_mutex);
}
EXPORT_SYMBOL_GPL(unregister_reset_call);

static void do_reset_calls(void)
{
	struct reset_call *reset;

	list_for_each_entry(reset, &rcall, list)
		reset->fn();
}

1172
u32 dump_prefix_page;
1173 1174 1175 1176 1177 1178

void s390_reset_system(void)
{
	struct _lowcore *lc;

	lc = (struct _lowcore *)(unsigned long) store_prefix();
M
Michael Holzheu 已提交
1179 1180

	/* Stack for interrupt/machine check handler */
1181 1182
	lc->panic_stack = S390_lowcore.panic_stack;

1183
	/* Save prefix page address for dump case */
1184
	dump_prefix_page = (u32)(unsigned long) lc;
1185

1186 1187 1188 1189 1190 1191 1192
	/* Disable prefixing */
	set_prefix(0);

	/* Disable lowcore protection */
	__ctl_clear_bit(0,28);

	/* Set new machine check handler */
G
Gerald Schaefer 已提交
1193
	S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1194
	S390_lowcore.mcck_new_psw.addr =
1195
		PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
M
Michael Holzheu 已提交
1196 1197

	/* Set new program check handler */
G
Gerald Schaefer 已提交
1198
	S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
M
Michael Holzheu 已提交
1199
	S390_lowcore.program_new_psw.addr =
1200
		PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
M
Michael Holzheu 已提交
1201

1202 1203
	do_reset_calls();
}