xref: /openbmc/linux/arch/s390/kernel/ipl.c (revision fb799447)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *    ipl/reipl/dump support for Linux on s390.
4  *
5  *    Copyright IBM Corp. 2005, 2012
6  *    Author(s): Michael Holzheu <holzheu@de.ibm.com>
7  *		 Volker Sameske <sameske@de.ibm.com>
8  */
9 
10 #include <linux/types.h>
11 #include <linux/export.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/kstrtox.h>
16 #include <linux/panic_notifier.h>
17 #include <linux/reboot.h>
18 #include <linux/ctype.h>
19 #include <linux/fs.h>
20 #include <linux/gfp.h>
21 #include <linux/crash_dump.h>
22 #include <linux/debug_locks.h>
23 #include <asm/asm-extable.h>
24 #include <asm/diag.h>
25 #include <asm/ipl.h>
26 #include <asm/smp.h>
27 #include <asm/setup.h>
28 #include <asm/cpcmd.h>
29 #include <asm/ebcdic.h>
30 #include <asm/sclp.h>
31 #include <asm/checksum.h>
32 #include <asm/debug.h>
33 #include <asm/abs_lowcore.h>
34 #include <asm/os_info.h>
35 #include <asm/sections.h>
36 #include <asm/boot_data.h>
37 #include "entry.h"
38 
39 #define IPL_PARM_BLOCK_VERSION 0
40 
41 #define IPL_UNKNOWN_STR		"unknown"
42 #define IPL_CCW_STR		"ccw"
43 #define IPL_ECKD_STR		"eckd"
44 #define IPL_ECKD_DUMP_STR	"eckd_dump"
45 #define IPL_FCP_STR		"fcp"
46 #define IPL_FCP_DUMP_STR	"fcp_dump"
47 #define IPL_NVME_STR		"nvme"
48 #define IPL_NVME_DUMP_STR	"nvme_dump"
49 #define IPL_NSS_STR		"nss"
50 
51 #define DUMP_CCW_STR		"ccw"
52 #define DUMP_ECKD_STR		"eckd"
53 #define DUMP_FCP_STR		"fcp"
54 #define DUMP_NVME_STR		"nvme"
55 #define DUMP_NONE_STR		"none"
56 
57 /*
58  * Four shutdown trigger types are supported:
59  * - panic
60  * - halt
61  * - power off
62  * - reipl
63  * - restart
64  */
65 #define ON_PANIC_STR		"on_panic"
66 #define ON_HALT_STR		"on_halt"
67 #define ON_POFF_STR		"on_poff"
68 #define ON_REIPL_STR		"on_reboot"
69 #define ON_RESTART_STR		"on_restart"
70 
71 struct shutdown_action;
72 struct shutdown_trigger {
73 	char *name;
74 	struct shutdown_action *action;
75 };
76 
77 /*
78  * The following shutdown action types are supported:
79  */
80 #define SHUTDOWN_ACTION_IPL_STR		"ipl"
81 #define SHUTDOWN_ACTION_REIPL_STR	"reipl"
82 #define SHUTDOWN_ACTION_DUMP_STR	"dump"
83 #define SHUTDOWN_ACTION_VMCMD_STR	"vmcmd"
84 #define SHUTDOWN_ACTION_STOP_STR	"stop"
85 #define SHUTDOWN_ACTION_DUMP_REIPL_STR	"dump_reipl"
86 
87 struct shutdown_action {
88 	char *name;
89 	void (*fn) (struct shutdown_trigger *trigger);
90 	int (*init) (void);
91 	int init_rc;
92 };
93 
94 static char *ipl_type_str(enum ipl_type type)
95 {
96 	switch (type) {
97 	case IPL_TYPE_CCW:
98 		return IPL_CCW_STR;
99 	case IPL_TYPE_ECKD:
100 		return IPL_ECKD_STR;
101 	case IPL_TYPE_ECKD_DUMP:
102 		return IPL_ECKD_DUMP_STR;
103 	case IPL_TYPE_FCP:
104 		return IPL_FCP_STR;
105 	case IPL_TYPE_FCP_DUMP:
106 		return IPL_FCP_DUMP_STR;
107 	case IPL_TYPE_NSS:
108 		return IPL_NSS_STR;
109 	case IPL_TYPE_NVME:
110 		return IPL_NVME_STR;
111 	case IPL_TYPE_NVME_DUMP:
112 		return IPL_NVME_DUMP_STR;
113 	case IPL_TYPE_UNKNOWN:
114 	default:
115 		return IPL_UNKNOWN_STR;
116 	}
117 }
118 
119 enum dump_type {
120 	DUMP_TYPE_NONE	= 1,
121 	DUMP_TYPE_CCW	= 2,
122 	DUMP_TYPE_FCP	= 4,
123 	DUMP_TYPE_NVME	= 8,
124 	DUMP_TYPE_ECKD	= 16,
125 };
126 
127 static char *dump_type_str(enum dump_type type)
128 {
129 	switch (type) {
130 	case DUMP_TYPE_NONE:
131 		return DUMP_NONE_STR;
132 	case DUMP_TYPE_CCW:
133 		return DUMP_CCW_STR;
134 	case DUMP_TYPE_ECKD:
135 		return DUMP_ECKD_STR;
136 	case DUMP_TYPE_FCP:
137 		return DUMP_FCP_STR;
138 	case DUMP_TYPE_NVME:
139 		return DUMP_NVME_STR;
140 	default:
141 		return NULL;
142 	}
143 }
144 
145 int __bootdata_preserved(ipl_block_valid);
146 struct ipl_parameter_block __bootdata_preserved(ipl_block);
147 int __bootdata_preserved(ipl_secure_flag);
148 
149 unsigned long __bootdata_preserved(ipl_cert_list_addr);
150 unsigned long __bootdata_preserved(ipl_cert_list_size);
151 
152 unsigned long __bootdata(early_ipl_comp_list_addr);
153 unsigned long __bootdata(early_ipl_comp_list_size);
154 
155 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
156 
157 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
158 static struct ipl_parameter_block *reipl_block_fcp;
159 static struct ipl_parameter_block *reipl_block_nvme;
160 static struct ipl_parameter_block *reipl_block_ccw;
161 static struct ipl_parameter_block *reipl_block_eckd;
162 static struct ipl_parameter_block *reipl_block_nss;
163 static struct ipl_parameter_block *reipl_block_actual;
164 
165 static int dump_capabilities = DUMP_TYPE_NONE;
166 static enum dump_type dump_type = DUMP_TYPE_NONE;
167 static struct ipl_parameter_block *dump_block_fcp;
168 static struct ipl_parameter_block *dump_block_nvme;
169 static struct ipl_parameter_block *dump_block_ccw;
170 static struct ipl_parameter_block *dump_block_eckd;
171 
172 static struct sclp_ipl_info sclp_ipl_info;
173 
174 static bool reipl_nvme_clear;
175 static bool reipl_fcp_clear;
176 static bool reipl_ccw_clear;
177 static bool reipl_eckd_clear;
178 
179 static inline int __diag308(unsigned long subcode, void *addr)
180 {
181 	union register_pair r1;
182 
183 	r1.even = (unsigned long) addr;
184 	r1.odd	= 0;
185 	asm volatile(
186 		"	diag	%[r1],%[subcode],0x308\n"
187 		"0:	nopr	%%r7\n"
188 		EX_TABLE(0b,0b)
189 		: [r1] "+&d" (r1.pair)
190 		: [subcode] "d" (subcode)
191 		: "cc", "memory");
192 	return r1.odd;
193 }
194 
195 int diag308(unsigned long subcode, void *addr)
196 {
197 	diag_stat_inc(DIAG_STAT_X308);
198 	return __diag308(subcode, addr);
199 }
200 EXPORT_SYMBOL_GPL(diag308);
201 
202 /* SYSFS */
203 
204 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...)		\
205 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj,	\
206 		struct kobj_attribute *attr,				\
207 		char *page)						\
208 {									\
209 	return scnprintf(page, PAGE_SIZE, _format, ##args);		\
210 }
211 
212 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk)			\
213 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,	\
214 		struct kobj_attribute *attr,				\
215 		const char *buf, size_t len)				\
216 {									\
217 	unsigned long long ssid, devno;					\
218 									\
219 	if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2)		\
220 		return -EINVAL;						\
221 									\
222 	if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL)		\
223 		return -EINVAL;						\
224 									\
225 	_ipl_blk.ssid = ssid;						\
226 	_ipl_blk.devno = devno;						\
227 	return len;							\
228 }
229 
230 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk)		\
231 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n",				\
232 		 _ipl_blk.ssid, _ipl_blk.devno);			\
233 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk);			\
234 static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
235 	__ATTR(_name, 0644,						\
236 	       sys_##_prefix##_##_name##_show,				\
237 	       sys_##_prefix##_##_name##_store)				\
238 
239 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value)		\
240 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value)			\
241 static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
242 	__ATTR(_name, 0444, sys_##_prefix##_##_name##_show, NULL)
243 
244 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)	\
245 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value)	\
246 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,	\
247 		struct kobj_attribute *attr,				\
248 		const char *buf, size_t len)				\
249 {									\
250 	unsigned long long value;					\
251 	if (sscanf(buf, _fmt_in, &value) != 1)				\
252 		return -EINVAL;						\
253 	_value = value;							\
254 	return len;							\
255 }									\
256 static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
257 	__ATTR(_name, 0644,						\
258 			sys_##_prefix##_##_name##_show,			\
259 			sys_##_prefix##_##_name##_store)
260 
261 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
262 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value)			\
263 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,	\
264 		struct kobj_attribute *attr,				\
265 		const char *buf, size_t len)				\
266 {									\
267 	strncpy(_value, buf, sizeof(_value) - 1);			\
268 	strim(_value);							\
269 	return len;							\
270 }									\
271 static struct kobj_attribute sys_##_prefix##_##_name##_attr =		\
272 	__ATTR(_name, 0644,						\
273 			sys_##_prefix##_##_name##_show,			\
274 			sys_##_prefix##_##_name##_store)
275 
276 /*
277  * ipl section
278  */
279 
280 static __init enum ipl_type get_ipl_type(void)
281 {
282 	if (!ipl_block_valid)
283 		return IPL_TYPE_UNKNOWN;
284 
285 	switch (ipl_block.pb0_hdr.pbt) {
286 	case IPL_PBT_CCW:
287 		return IPL_TYPE_CCW;
288 	case IPL_PBT_FCP:
289 		if (ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
290 			return IPL_TYPE_FCP_DUMP;
291 		else
292 			return IPL_TYPE_FCP;
293 	case IPL_PBT_NVME:
294 		if (ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
295 			return IPL_TYPE_NVME_DUMP;
296 		else
297 			return IPL_TYPE_NVME;
298 	case IPL_PBT_ECKD:
299 		if (ipl_block.eckd.opt == IPL_PB0_ECKD_OPT_DUMP)
300 			return IPL_TYPE_ECKD_DUMP;
301 		else
302 			return IPL_TYPE_ECKD;
303 	}
304 	return IPL_TYPE_UNKNOWN;
305 }
306 
307 struct ipl_info ipl_info;
308 EXPORT_SYMBOL_GPL(ipl_info);
309 
310 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
311 			     char *page)
312 {
313 	return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
314 }
315 
316 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
317 
318 static ssize_t ipl_secure_show(struct kobject *kobj,
319 			       struct kobj_attribute *attr, char *page)
320 {
321 	return sprintf(page, "%i\n", !!ipl_secure_flag);
322 }
323 
324 static struct kobj_attribute sys_ipl_secure_attr =
325 	__ATTR(secure, 0444, ipl_secure_show, NULL);
326 
327 static ssize_t ipl_has_secure_show(struct kobject *kobj,
328 				   struct kobj_attribute *attr, char *page)
329 {
330 	return sprintf(page, "%i\n", !!sclp.has_sipl);
331 }
332 
333 static struct kobj_attribute sys_ipl_has_secure_attr =
334 	__ATTR(has_secure, 0444, ipl_has_secure_show, NULL);
335 
336 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
337 				struct kobj_attribute *attr, char *page)
338 {
339 	char parm[DIAG308_VMPARM_SIZE + 1] = {};
340 
341 	if (ipl_block_valid && (ipl_block.pb0_hdr.pbt == IPL_PBT_CCW))
342 		ipl_block_get_ascii_vmparm(parm, sizeof(parm), &ipl_block);
343 	return sprintf(page, "%s\n", parm);
344 }
345 
346 static struct kobj_attribute sys_ipl_vm_parm_attr =
347 	__ATTR(parm, 0444, ipl_vm_parm_show, NULL);
348 
349 static ssize_t sys_ipl_device_show(struct kobject *kobj,
350 				   struct kobj_attribute *attr, char *page)
351 {
352 	switch (ipl_info.type) {
353 	case IPL_TYPE_CCW:
354 		return sprintf(page, "0.%x.%04x\n", ipl_block.ccw.ssid,
355 			       ipl_block.ccw.devno);
356 	case IPL_TYPE_ECKD:
357 	case IPL_TYPE_ECKD_DUMP:
358 		return sprintf(page, "0.%x.%04x\n", ipl_block.eckd.ssid,
359 			       ipl_block.eckd.devno);
360 	case IPL_TYPE_FCP:
361 	case IPL_TYPE_FCP_DUMP:
362 		return sprintf(page, "0.0.%04x\n", ipl_block.fcp.devno);
363 	case IPL_TYPE_NVME:
364 	case IPL_TYPE_NVME_DUMP:
365 		return sprintf(page, "%08ux\n", ipl_block.nvme.fid);
366 	default:
367 		return 0;
368 	}
369 }
370 
371 static struct kobj_attribute sys_ipl_device_attr =
372 	__ATTR(device, 0444, sys_ipl_device_show, NULL);
373 
374 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
375 				  struct bin_attribute *attr, char *buf,
376 				  loff_t off, size_t count)
377 {
378 	return memory_read_from_buffer(buf, count, &off, &ipl_block,
379 				       ipl_block.hdr.len);
380 }
381 static struct bin_attribute ipl_parameter_attr =
382 	__BIN_ATTR(binary_parameter, 0444, ipl_parameter_read, NULL,
383 		   PAGE_SIZE);
384 
385 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
386 				 struct bin_attribute *attr, char *buf,
387 				 loff_t off, size_t count)
388 {
389 	unsigned int size = ipl_block.fcp.scp_data_len;
390 	void *scp_data = &ipl_block.fcp.scp_data;
391 
392 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
393 }
394 
395 static ssize_t ipl_nvme_scp_data_read(struct file *filp, struct kobject *kobj,
396 				 struct bin_attribute *attr, char *buf,
397 				 loff_t off, size_t count)
398 {
399 	unsigned int size = ipl_block.nvme.scp_data_len;
400 	void *scp_data = &ipl_block.nvme.scp_data;
401 
402 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
403 }
404 
405 static ssize_t ipl_eckd_scp_data_read(struct file *filp, struct kobject *kobj,
406 				      struct bin_attribute *attr, char *buf,
407 				      loff_t off, size_t count)
408 {
409 	unsigned int size = ipl_block.eckd.scp_data_len;
410 	void *scp_data = &ipl_block.eckd.scp_data;
411 
412 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
413 }
414 
415 static struct bin_attribute ipl_scp_data_attr =
416 	__BIN_ATTR(scp_data, 0444, ipl_scp_data_read, NULL, PAGE_SIZE);
417 
418 static struct bin_attribute ipl_nvme_scp_data_attr =
419 	__BIN_ATTR(scp_data, 0444, ipl_nvme_scp_data_read, NULL, PAGE_SIZE);
420 
421 static struct bin_attribute ipl_eckd_scp_data_attr =
422 	__BIN_ATTR(scp_data, 0444, ipl_eckd_scp_data_read, NULL, PAGE_SIZE);
423 
424 static struct bin_attribute *ipl_fcp_bin_attrs[] = {
425 	&ipl_parameter_attr,
426 	&ipl_scp_data_attr,
427 	NULL,
428 };
429 
430 static struct bin_attribute *ipl_nvme_bin_attrs[] = {
431 	&ipl_parameter_attr,
432 	&ipl_nvme_scp_data_attr,
433 	NULL,
434 };
435 
436 static struct bin_attribute *ipl_eckd_bin_attrs[] = {
437 	&ipl_parameter_attr,
438 	&ipl_eckd_scp_data_attr,
439 	NULL,
440 };
441 
442 /* FCP ipl device attributes */
443 
444 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n",
445 		   (unsigned long long)ipl_block.fcp.wwpn);
446 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n",
447 		   (unsigned long long)ipl_block.fcp.lun);
448 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n",
449 		   (unsigned long long)ipl_block.fcp.bootprog);
450 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n",
451 		   (unsigned long long)ipl_block.fcp.br_lba);
452 
453 /* NVMe ipl device attributes */
454 DEFINE_IPL_ATTR_RO(ipl_nvme, fid, "0x%08llx\n",
455 		   (unsigned long long)ipl_block.nvme.fid);
456 DEFINE_IPL_ATTR_RO(ipl_nvme, nsid, "0x%08llx\n",
457 		   (unsigned long long)ipl_block.nvme.nsid);
458 DEFINE_IPL_ATTR_RO(ipl_nvme, bootprog, "%lld\n",
459 		   (unsigned long long)ipl_block.nvme.bootprog);
460 DEFINE_IPL_ATTR_RO(ipl_nvme, br_lba, "%lld\n",
461 		   (unsigned long long)ipl_block.nvme.br_lba);
462 
463 /* ECKD ipl device attributes */
464 DEFINE_IPL_ATTR_RO(ipl_eckd, bootprog, "%lld\n",
465 		   (unsigned long long)ipl_block.eckd.bootprog);
466 
467 #define IPL_ATTR_BR_CHR_SHOW_FN(_name, _ipb)				\
468 static ssize_t eckd_##_name##_br_chr_show(struct kobject *kobj,		\
469 					  struct kobj_attribute *attr,	\
470 					  char *buf)			\
471 {									\
472 	struct ipl_pb0_eckd *ipb = &(_ipb);				\
473 									\
474 	if (!ipb->br_chr.cyl &&						\
475 	    !ipb->br_chr.head &&					\
476 	    !ipb->br_chr.record)					\
477 		return sprintf(buf, "auto\n");				\
478 									\
479 	return sprintf(buf, "0x%x,0x%x,0x%x\n",				\
480 			ipb->br_chr.cyl,				\
481 			ipb->br_chr.head,				\
482 			ipb->br_chr.record);				\
483 }
484 
485 #define IPL_ATTR_BR_CHR_STORE_FN(_name, _ipb)				\
486 static ssize_t eckd_##_name##_br_chr_store(struct kobject *kobj,	\
487 					   struct kobj_attribute *attr,	\
488 					   const char *buf, size_t len)	\
489 {									\
490 	struct ipl_pb0_eckd *ipb = &(_ipb);				\
491 	unsigned long args[3] = { 0 };					\
492 	char *p, *p1, *tmp = NULL;					\
493 	int i, rc;							\
494 									\
495 	if (!strncmp(buf, "auto", 4))					\
496 		goto out;						\
497 									\
498 	tmp = kstrdup(buf, GFP_KERNEL);					\
499 	p = tmp;							\
500 	for (i = 0; i < 3; i++) {					\
501 		p1 = strsep(&p, ", ");					\
502 		if (!p1) {						\
503 			rc = -EINVAL;					\
504 			goto err;					\
505 		}							\
506 		rc = kstrtoul(p1, 0, args + i);				\
507 		if (rc)							\
508 			goto err;					\
509 	}								\
510 									\
511 	rc = -EINVAL;							\
512 	if (i != 3)							\
513 		goto err;						\
514 									\
515 	if ((args[0] || args[1]) && !args[2])				\
516 		goto err;						\
517 									\
518 	if (args[0] > UINT_MAX || args[1] > 255 || args[2] > 255)	\
519 		goto err;						\
520 									\
521 out:									\
522 	ipb->br_chr.cyl = args[0];					\
523 	ipb->br_chr.head = args[1];					\
524 	ipb->br_chr.record = args[2];					\
525 	rc = len;							\
526 err:									\
527 	kfree(tmp);							\
528 	return rc;							\
529 }
530 
531 IPL_ATTR_BR_CHR_SHOW_FN(ipl, ipl_block.eckd);
532 static struct kobj_attribute sys_ipl_eckd_br_chr_attr =
533 	__ATTR(br_chr, 0644, eckd_ipl_br_chr_show, NULL);
534 
535 IPL_ATTR_BR_CHR_SHOW_FN(reipl, reipl_block_eckd->eckd);
536 IPL_ATTR_BR_CHR_STORE_FN(reipl, reipl_block_eckd->eckd);
537 
538 static struct kobj_attribute sys_reipl_eckd_br_chr_attr =
539 	__ATTR(br_chr, 0644, eckd_reipl_br_chr_show, eckd_reipl_br_chr_store);
540 
541 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
542 				     struct kobj_attribute *attr, char *page)
543 {
544 	char loadparm[LOADPARM_LEN + 1] = {};
545 
546 	if (!sclp_ipl_info.is_valid)
547 		return sprintf(page, "#unknown#\n");
548 	memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
549 	EBCASC(loadparm, LOADPARM_LEN);
550 	strim(loadparm);
551 	return sprintf(page, "%s\n", loadparm);
552 }
553 
554 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
555 	__ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
556 
557 static struct attribute *ipl_fcp_attrs[] = {
558 	&sys_ipl_type_attr.attr,
559 	&sys_ipl_device_attr.attr,
560 	&sys_ipl_fcp_wwpn_attr.attr,
561 	&sys_ipl_fcp_lun_attr.attr,
562 	&sys_ipl_fcp_bootprog_attr.attr,
563 	&sys_ipl_fcp_br_lba_attr.attr,
564 	&sys_ipl_ccw_loadparm_attr.attr,
565 	&sys_ipl_secure_attr.attr,
566 	&sys_ipl_has_secure_attr.attr,
567 	NULL,
568 };
569 
570 static struct attribute_group ipl_fcp_attr_group = {
571 	.attrs = ipl_fcp_attrs,
572 	.bin_attrs = ipl_fcp_bin_attrs,
573 };
574 
575 static struct attribute *ipl_nvme_attrs[] = {
576 	&sys_ipl_type_attr.attr,
577 	&sys_ipl_nvme_fid_attr.attr,
578 	&sys_ipl_nvme_nsid_attr.attr,
579 	&sys_ipl_nvme_bootprog_attr.attr,
580 	&sys_ipl_nvme_br_lba_attr.attr,
581 	&sys_ipl_ccw_loadparm_attr.attr,
582 	&sys_ipl_secure_attr.attr,
583 	&sys_ipl_has_secure_attr.attr,
584 	NULL,
585 };
586 
587 static struct attribute_group ipl_nvme_attr_group = {
588 	.attrs = ipl_nvme_attrs,
589 	.bin_attrs = ipl_nvme_bin_attrs,
590 };
591 
592 static struct attribute *ipl_eckd_attrs[] = {
593 	&sys_ipl_type_attr.attr,
594 	&sys_ipl_eckd_bootprog_attr.attr,
595 	&sys_ipl_eckd_br_chr_attr.attr,
596 	&sys_ipl_ccw_loadparm_attr.attr,
597 	&sys_ipl_device_attr.attr,
598 	&sys_ipl_secure_attr.attr,
599 	&sys_ipl_has_secure_attr.attr,
600 	NULL,
601 };
602 
603 static struct attribute_group ipl_eckd_attr_group = {
604 	.attrs = ipl_eckd_attrs,
605 	.bin_attrs = ipl_eckd_bin_attrs,
606 };
607 
608 /* CCW ipl device attributes */
609 
610 static struct attribute *ipl_ccw_attrs_vm[] = {
611 	&sys_ipl_type_attr.attr,
612 	&sys_ipl_device_attr.attr,
613 	&sys_ipl_ccw_loadparm_attr.attr,
614 	&sys_ipl_vm_parm_attr.attr,
615 	&sys_ipl_secure_attr.attr,
616 	&sys_ipl_has_secure_attr.attr,
617 	NULL,
618 };
619 
620 static struct attribute *ipl_ccw_attrs_lpar[] = {
621 	&sys_ipl_type_attr.attr,
622 	&sys_ipl_device_attr.attr,
623 	&sys_ipl_ccw_loadparm_attr.attr,
624 	&sys_ipl_secure_attr.attr,
625 	&sys_ipl_has_secure_attr.attr,
626 	NULL,
627 };
628 
629 static struct attribute_group ipl_ccw_attr_group_vm = {
630 	.attrs = ipl_ccw_attrs_vm,
631 };
632 
633 static struct attribute_group ipl_ccw_attr_group_lpar = {
634 	.attrs = ipl_ccw_attrs_lpar
635 };
636 
637 /* UNKNOWN ipl device attributes */
638 
639 static struct attribute *ipl_unknown_attrs[] = {
640 	&sys_ipl_type_attr.attr,
641 	NULL,
642 };
643 
644 static struct attribute_group ipl_unknown_attr_group = {
645 	.attrs = ipl_unknown_attrs,
646 };
647 
648 static struct kset *ipl_kset;
649 
650 static void __ipl_run(void *unused)
651 {
652 	__bpon();
653 	diag308(DIAG308_LOAD_CLEAR, NULL);
654 }
655 
656 static void ipl_run(struct shutdown_trigger *trigger)
657 {
658 	smp_call_ipl_cpu(__ipl_run, NULL);
659 }
660 
661 static int __init ipl_init(void)
662 {
663 	int rc;
664 
665 	ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
666 	if (!ipl_kset) {
667 		rc = -ENOMEM;
668 		goto out;
669 	}
670 	switch (ipl_info.type) {
671 	case IPL_TYPE_CCW:
672 		if (MACHINE_IS_VM)
673 			rc = sysfs_create_group(&ipl_kset->kobj,
674 						&ipl_ccw_attr_group_vm);
675 		else
676 			rc = sysfs_create_group(&ipl_kset->kobj,
677 						&ipl_ccw_attr_group_lpar);
678 		break;
679 	case IPL_TYPE_ECKD:
680 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_eckd_attr_group);
681 		break;
682 	case IPL_TYPE_FCP:
683 	case IPL_TYPE_FCP_DUMP:
684 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
685 		break;
686 	case IPL_TYPE_NVME:
687 	case IPL_TYPE_NVME_DUMP:
688 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nvme_attr_group);
689 		break;
690 	default:
691 		rc = sysfs_create_group(&ipl_kset->kobj,
692 					&ipl_unknown_attr_group);
693 		break;
694 	}
695 out:
696 	if (rc)
697 		panic("ipl_init failed: rc = %i\n", rc);
698 
699 	return 0;
700 }
701 
702 static struct shutdown_action __refdata ipl_action = {
703 	.name	= SHUTDOWN_ACTION_IPL_STR,
704 	.fn	= ipl_run,
705 	.init	= ipl_init,
706 };
707 
708 /*
709  * reipl shutdown action: Reboot Linux on shutdown.
710  */
711 
712 /* VM IPL PARM attributes */
713 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
714 					  char *page)
715 {
716 	char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
717 
718 	ipl_block_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
719 	return sprintf(page, "%s\n", vmparm);
720 }
721 
722 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
723 					  size_t vmparm_max,
724 					  const char *buf, size_t len)
725 {
726 	int i, ip_len;
727 
728 	/* ignore trailing newline */
729 	ip_len = len;
730 	if ((len > 0) && (buf[len - 1] == '\n'))
731 		ip_len--;
732 
733 	if (ip_len > vmparm_max)
734 		return -EINVAL;
735 
736 	/* parm is used to store kernel options, check for common chars */
737 	for (i = 0; i < ip_len; i++)
738 		if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
739 			return -EINVAL;
740 
741 	memset(ipb->ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
742 	ipb->ccw.vm_parm_len = ip_len;
743 	if (ip_len > 0) {
744 		ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
745 		memcpy(ipb->ccw.vm_parm, buf, ip_len);
746 		ASCEBC(ipb->ccw.vm_parm, ip_len);
747 	} else {
748 		ipb->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_VP;
749 	}
750 
751 	return len;
752 }
753 
754 /* NSS wrapper */
755 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
756 				     struct kobj_attribute *attr, char *page)
757 {
758 	return reipl_generic_vmparm_show(reipl_block_nss, page);
759 }
760 
761 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
762 				      struct kobj_attribute *attr,
763 				      const char *buf, size_t len)
764 {
765 	return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
766 }
767 
768 /* CCW wrapper */
769 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
770 				     struct kobj_attribute *attr, char *page)
771 {
772 	return reipl_generic_vmparm_show(reipl_block_ccw, page);
773 }
774 
775 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
776 				      struct kobj_attribute *attr,
777 				      const char *buf, size_t len)
778 {
779 	return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
780 }
781 
782 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
783 	__ATTR(parm, 0644, reipl_nss_vmparm_show,
784 	       reipl_nss_vmparm_store);
785 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
786 	__ATTR(parm, 0644, reipl_ccw_vmparm_show,
787 	       reipl_ccw_vmparm_store);
788 
789 /* FCP reipl device attributes */
790 
791 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
792 				      struct bin_attribute *attr,
793 				      char *buf, loff_t off, size_t count)
794 {
795 	size_t size = reipl_block_fcp->fcp.scp_data_len;
796 	void *scp_data = reipl_block_fcp->fcp.scp_data;
797 
798 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
799 }
800 
801 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
802 				       struct bin_attribute *attr,
803 				       char *buf, loff_t off, size_t count)
804 {
805 	size_t scpdata_len = count;
806 	size_t padding;
807 
808 
809 	if (off)
810 		return -EINVAL;
811 
812 	memcpy(reipl_block_fcp->fcp.scp_data, buf, count);
813 	if (scpdata_len % 8) {
814 		padding = 8 - (scpdata_len % 8);
815 		memset(reipl_block_fcp->fcp.scp_data + scpdata_len,
816 		       0, padding);
817 		scpdata_len += padding;
818 	}
819 
820 	reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
821 	reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN + scpdata_len;
822 	reipl_block_fcp->fcp.scp_data_len = scpdata_len;
823 
824 	return count;
825 }
826 static struct bin_attribute sys_reipl_fcp_scp_data_attr =
827 	__BIN_ATTR(scp_data, 0644, reipl_fcp_scpdata_read,
828 		   reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
829 
830 static struct bin_attribute *reipl_fcp_bin_attrs[] = {
831 	&sys_reipl_fcp_scp_data_attr,
832 	NULL,
833 };
834 
835 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
836 		   reipl_block_fcp->fcp.wwpn);
837 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
838 		   reipl_block_fcp->fcp.lun);
839 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
840 		   reipl_block_fcp->fcp.bootprog);
841 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
842 		   reipl_block_fcp->fcp.br_lba);
843 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
844 		   reipl_block_fcp->fcp.devno);
845 
846 static void reipl_get_ascii_loadparm(char *loadparm,
847 				     struct ipl_parameter_block *ibp)
848 {
849 	memcpy(loadparm, ibp->common.loadparm, LOADPARM_LEN);
850 	EBCASC(loadparm, LOADPARM_LEN);
851 	loadparm[LOADPARM_LEN] = 0;
852 	strim(loadparm);
853 }
854 
855 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
856 					   char *page)
857 {
858 	char buf[LOADPARM_LEN + 1];
859 
860 	reipl_get_ascii_loadparm(buf, ipb);
861 	return sprintf(page, "%s\n", buf);
862 }
863 
864 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
865 					    const char *buf, size_t len)
866 {
867 	int i, lp_len;
868 
869 	/* ignore trailing newline */
870 	lp_len = len;
871 	if ((len > 0) && (buf[len - 1] == '\n'))
872 		lp_len--;
873 	/* loadparm can have max 8 characters and must not start with a blank */
874 	if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
875 		return -EINVAL;
876 	/* loadparm can only contain "a-z,A-Z,0-9,SP,." */
877 	for (i = 0; i < lp_len; i++) {
878 		if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
879 		    (buf[i] == '.'))
880 			continue;
881 		return -EINVAL;
882 	}
883 	/* initialize loadparm with blanks */
884 	memset(ipb->common.loadparm, ' ', LOADPARM_LEN);
885 	/* copy and convert to ebcdic */
886 	memcpy(ipb->common.loadparm, buf, lp_len);
887 	ASCEBC(ipb->common.loadparm, LOADPARM_LEN);
888 	ipb->common.flags |= IPL_PB0_FLAG_LOADPARM;
889 	return len;
890 }
891 
892 #define DEFINE_GENERIC_LOADPARM(name)							\
893 static ssize_t reipl_##name##_loadparm_show(struct kobject *kobj,			\
894 					    struct kobj_attribute *attr, char *page)	\
895 {											\
896 	return reipl_generic_loadparm_show(reipl_block_##name, page);			\
897 }											\
898 static ssize_t reipl_##name##_loadparm_store(struct kobject *kobj,			\
899 					     struct kobj_attribute *attr,		\
900 					     const char *buf, size_t len)		\
901 {											\
902 	return reipl_generic_loadparm_store(reipl_block_##name, buf, len);		\
903 }											\
904 static struct kobj_attribute sys_reipl_##name##_loadparm_attr =				\
905 	__ATTR(loadparm, 0644, reipl_##name##_loadparm_show,				\
906 	       reipl_##name##_loadparm_store)
907 
908 DEFINE_GENERIC_LOADPARM(fcp);
909 DEFINE_GENERIC_LOADPARM(nvme);
910 DEFINE_GENERIC_LOADPARM(ccw);
911 DEFINE_GENERIC_LOADPARM(nss);
912 DEFINE_GENERIC_LOADPARM(eckd);
913 
914 static ssize_t reipl_fcp_clear_show(struct kobject *kobj,
915 				    struct kobj_attribute *attr, char *page)
916 {
917 	return sprintf(page, "%u\n", reipl_fcp_clear);
918 }
919 
920 static ssize_t reipl_fcp_clear_store(struct kobject *kobj,
921 				     struct kobj_attribute *attr,
922 				     const char *buf, size_t len)
923 {
924 	if (kstrtobool(buf, &reipl_fcp_clear) < 0)
925 		return -EINVAL;
926 	return len;
927 }
928 
929 static struct attribute *reipl_fcp_attrs[] = {
930 	&sys_reipl_fcp_device_attr.attr,
931 	&sys_reipl_fcp_wwpn_attr.attr,
932 	&sys_reipl_fcp_lun_attr.attr,
933 	&sys_reipl_fcp_bootprog_attr.attr,
934 	&sys_reipl_fcp_br_lba_attr.attr,
935 	&sys_reipl_fcp_loadparm_attr.attr,
936 	NULL,
937 };
938 
939 static struct attribute_group reipl_fcp_attr_group = {
940 	.attrs = reipl_fcp_attrs,
941 	.bin_attrs = reipl_fcp_bin_attrs,
942 };
943 
944 static struct kobj_attribute sys_reipl_fcp_clear_attr =
945 	__ATTR(clear, 0644, reipl_fcp_clear_show, reipl_fcp_clear_store);
946 
947 /* NVME reipl device attributes */
948 
949 static ssize_t reipl_nvme_scpdata_read(struct file *filp, struct kobject *kobj,
950 				      struct bin_attribute *attr,
951 				      char *buf, loff_t off, size_t count)
952 {
953 	size_t size = reipl_block_nvme->nvme.scp_data_len;
954 	void *scp_data = reipl_block_nvme->nvme.scp_data;
955 
956 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
957 }
958 
959 static ssize_t reipl_nvme_scpdata_write(struct file *filp, struct kobject *kobj,
960 				       struct bin_attribute *attr,
961 				       char *buf, loff_t off, size_t count)
962 {
963 	size_t scpdata_len = count;
964 	size_t padding;
965 
966 	if (off)
967 		return -EINVAL;
968 
969 	memcpy(reipl_block_nvme->nvme.scp_data, buf, count);
970 	if (scpdata_len % 8) {
971 		padding = 8 - (scpdata_len % 8);
972 		memset(reipl_block_nvme->nvme.scp_data + scpdata_len,
973 		       0, padding);
974 		scpdata_len += padding;
975 	}
976 
977 	reipl_block_nvme->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
978 	reipl_block_nvme->nvme.len = IPL_BP0_FCP_LEN + scpdata_len;
979 	reipl_block_nvme->nvme.scp_data_len = scpdata_len;
980 
981 	return count;
982 }
983 
984 static struct bin_attribute sys_reipl_nvme_scp_data_attr =
985 	__BIN_ATTR(scp_data, 0644, reipl_nvme_scpdata_read,
986 		   reipl_nvme_scpdata_write, DIAG308_SCPDATA_SIZE);
987 
988 static struct bin_attribute *reipl_nvme_bin_attrs[] = {
989 	&sys_reipl_nvme_scp_data_attr,
990 	NULL,
991 };
992 
993 DEFINE_IPL_ATTR_RW(reipl_nvme, fid, "0x%08llx\n", "%llx\n",
994 		   reipl_block_nvme->nvme.fid);
995 DEFINE_IPL_ATTR_RW(reipl_nvme, nsid, "0x%08llx\n", "%llx\n",
996 		   reipl_block_nvme->nvme.nsid);
997 DEFINE_IPL_ATTR_RW(reipl_nvme, bootprog, "%lld\n", "%lld\n",
998 		   reipl_block_nvme->nvme.bootprog);
999 DEFINE_IPL_ATTR_RW(reipl_nvme, br_lba, "%lld\n", "%lld\n",
1000 		   reipl_block_nvme->nvme.br_lba);
1001 
1002 static struct attribute *reipl_nvme_attrs[] = {
1003 	&sys_reipl_nvme_fid_attr.attr,
1004 	&sys_reipl_nvme_nsid_attr.attr,
1005 	&sys_reipl_nvme_bootprog_attr.attr,
1006 	&sys_reipl_nvme_br_lba_attr.attr,
1007 	&sys_reipl_nvme_loadparm_attr.attr,
1008 	NULL,
1009 };
1010 
1011 static struct attribute_group reipl_nvme_attr_group = {
1012 	.attrs = reipl_nvme_attrs,
1013 	.bin_attrs = reipl_nvme_bin_attrs
1014 };
1015 
1016 static ssize_t reipl_nvme_clear_show(struct kobject *kobj,
1017 				     struct kobj_attribute *attr, char *page)
1018 {
1019 	return sprintf(page, "%u\n", reipl_nvme_clear);
1020 }
1021 
1022 static ssize_t reipl_nvme_clear_store(struct kobject *kobj,
1023 				      struct kobj_attribute *attr,
1024 				      const char *buf, size_t len)
1025 {
1026 	if (kstrtobool(buf, &reipl_nvme_clear) < 0)
1027 		return -EINVAL;
1028 	return len;
1029 }
1030 
1031 static struct kobj_attribute sys_reipl_nvme_clear_attr =
1032 	__ATTR(clear, 0644, reipl_nvme_clear_show, reipl_nvme_clear_store);
1033 
1034 /* CCW reipl device attributes */
1035 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ccw);
1036 
1037 static ssize_t reipl_ccw_clear_show(struct kobject *kobj,
1038 				    struct kobj_attribute *attr, char *page)
1039 {
1040 	return sprintf(page, "%u\n", reipl_ccw_clear);
1041 }
1042 
1043 static ssize_t reipl_ccw_clear_store(struct kobject *kobj,
1044 				     struct kobj_attribute *attr,
1045 				     const char *buf, size_t len)
1046 {
1047 	if (kstrtobool(buf, &reipl_ccw_clear) < 0)
1048 		return -EINVAL;
1049 	return len;
1050 }
1051 
1052 static struct kobj_attribute sys_reipl_ccw_clear_attr =
1053 	__ATTR(clear, 0644, reipl_ccw_clear_show, reipl_ccw_clear_store);
1054 
1055 static struct attribute *reipl_ccw_attrs_vm[] = {
1056 	&sys_reipl_ccw_device_attr.attr,
1057 	&sys_reipl_ccw_loadparm_attr.attr,
1058 	&sys_reipl_ccw_vmparm_attr.attr,
1059 	&sys_reipl_ccw_clear_attr.attr,
1060 	NULL,
1061 };
1062 
1063 static struct attribute *reipl_ccw_attrs_lpar[] = {
1064 	&sys_reipl_ccw_device_attr.attr,
1065 	&sys_reipl_ccw_loadparm_attr.attr,
1066 	&sys_reipl_ccw_clear_attr.attr,
1067 	NULL,
1068 };
1069 
1070 static struct attribute_group reipl_ccw_attr_group_vm = {
1071 	.name  = IPL_CCW_STR,
1072 	.attrs = reipl_ccw_attrs_vm,
1073 };
1074 
1075 static struct attribute_group reipl_ccw_attr_group_lpar = {
1076 	.name  = IPL_CCW_STR,
1077 	.attrs = reipl_ccw_attrs_lpar,
1078 };
1079 
1080 /* ECKD reipl device attributes */
1081 
1082 static ssize_t reipl_eckd_scpdata_read(struct file *filp, struct kobject *kobj,
1083 				       struct bin_attribute *attr,
1084 				       char *buf, loff_t off, size_t count)
1085 {
1086 	size_t size = reipl_block_eckd->eckd.scp_data_len;
1087 	void *scp_data = reipl_block_eckd->eckd.scp_data;
1088 
1089 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
1090 }
1091 
1092 static ssize_t reipl_eckd_scpdata_write(struct file *filp, struct kobject *kobj,
1093 					struct bin_attribute *attr,
1094 					char *buf, loff_t off, size_t count)
1095 {
1096 	size_t scpdata_len = count;
1097 	size_t padding;
1098 
1099 	if (off)
1100 		return -EINVAL;
1101 
1102 	memcpy(reipl_block_eckd->eckd.scp_data, buf, count);
1103 	if (scpdata_len % 8) {
1104 		padding = 8 - (scpdata_len % 8);
1105 		memset(reipl_block_eckd->eckd.scp_data + scpdata_len,
1106 		       0, padding);
1107 		scpdata_len += padding;
1108 	}
1109 
1110 	reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN + scpdata_len;
1111 	reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN + scpdata_len;
1112 	reipl_block_eckd->eckd.scp_data_len = scpdata_len;
1113 
1114 	return count;
1115 }
1116 
1117 static struct bin_attribute sys_reipl_eckd_scp_data_attr =
1118 	__BIN_ATTR(scp_data, 0644, reipl_eckd_scpdata_read,
1119 		   reipl_eckd_scpdata_write, DIAG308_SCPDATA_SIZE);
1120 
1121 static struct bin_attribute *reipl_eckd_bin_attrs[] = {
1122 	&sys_reipl_eckd_scp_data_attr,
1123 	NULL,
1124 };
1125 
1126 DEFINE_IPL_CCW_ATTR_RW(reipl_eckd, device, reipl_block_eckd->eckd);
1127 DEFINE_IPL_ATTR_RW(reipl_eckd, bootprog, "%lld\n", "%lld\n",
1128 		   reipl_block_eckd->eckd.bootprog);
1129 
1130 static struct attribute *reipl_eckd_attrs[] = {
1131 	&sys_reipl_eckd_device_attr.attr,
1132 	&sys_reipl_eckd_bootprog_attr.attr,
1133 	&sys_reipl_eckd_br_chr_attr.attr,
1134 	&sys_reipl_eckd_loadparm_attr.attr,
1135 	NULL,
1136 };
1137 
1138 static struct attribute_group reipl_eckd_attr_group = {
1139 	.attrs = reipl_eckd_attrs,
1140 	.bin_attrs = reipl_eckd_bin_attrs
1141 };
1142 
1143 static ssize_t reipl_eckd_clear_show(struct kobject *kobj,
1144 				     struct kobj_attribute *attr, char *page)
1145 {
1146 	return sprintf(page, "%u\n", reipl_eckd_clear);
1147 }
1148 
1149 static ssize_t reipl_eckd_clear_store(struct kobject *kobj,
1150 				      struct kobj_attribute *attr,
1151 				      const char *buf, size_t len)
1152 {
1153 	if (kstrtobool(buf, &reipl_eckd_clear) < 0)
1154 		return -EINVAL;
1155 	return len;
1156 }
1157 
1158 static struct kobj_attribute sys_reipl_eckd_clear_attr =
1159 	__ATTR(clear, 0644, reipl_eckd_clear_show, reipl_eckd_clear_store);
1160 
1161 /* NSS reipl device attributes */
1162 static void reipl_get_ascii_nss_name(char *dst,
1163 				     struct ipl_parameter_block *ipb)
1164 {
1165 	memcpy(dst, ipb->ccw.nss_name, NSS_NAME_SIZE);
1166 	EBCASC(dst, NSS_NAME_SIZE);
1167 	dst[NSS_NAME_SIZE] = 0;
1168 }
1169 
1170 static ssize_t reipl_nss_name_show(struct kobject *kobj,
1171 				   struct kobj_attribute *attr, char *page)
1172 {
1173 	char nss_name[NSS_NAME_SIZE + 1] = {};
1174 
1175 	reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
1176 	return sprintf(page, "%s\n", nss_name);
1177 }
1178 
1179 static ssize_t reipl_nss_name_store(struct kobject *kobj,
1180 				    struct kobj_attribute *attr,
1181 				    const char *buf, size_t len)
1182 {
1183 	int nss_len;
1184 
1185 	/* ignore trailing newline */
1186 	nss_len = len;
1187 	if ((len > 0) && (buf[len - 1] == '\n'))
1188 		nss_len--;
1189 
1190 	if (nss_len > NSS_NAME_SIZE)
1191 		return -EINVAL;
1192 
1193 	memset(reipl_block_nss->ccw.nss_name, 0x40, NSS_NAME_SIZE);
1194 	if (nss_len > 0) {
1195 		reipl_block_nss->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_NSS;
1196 		memcpy(reipl_block_nss->ccw.nss_name, buf, nss_len);
1197 		ASCEBC(reipl_block_nss->ccw.nss_name, nss_len);
1198 		EBC_TOUPPER(reipl_block_nss->ccw.nss_name, nss_len);
1199 	} else {
1200 		reipl_block_nss->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_NSS;
1201 	}
1202 
1203 	return len;
1204 }
1205 
1206 static struct kobj_attribute sys_reipl_nss_name_attr =
1207 	__ATTR(name, 0644, reipl_nss_name_show,
1208 	       reipl_nss_name_store);
1209 
1210 static struct attribute *reipl_nss_attrs[] = {
1211 	&sys_reipl_nss_name_attr.attr,
1212 	&sys_reipl_nss_loadparm_attr.attr,
1213 	&sys_reipl_nss_vmparm_attr.attr,
1214 	NULL,
1215 };
1216 
1217 static struct attribute_group reipl_nss_attr_group = {
1218 	.name  = IPL_NSS_STR,
1219 	.attrs = reipl_nss_attrs,
1220 };
1221 
1222 void set_os_info_reipl_block(void)
1223 {
1224 	os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
1225 			  reipl_block_actual->hdr.len);
1226 }
1227 
1228 /* reipl type */
1229 
1230 static int reipl_set_type(enum ipl_type type)
1231 {
1232 	if (!(reipl_capabilities & type))
1233 		return -EINVAL;
1234 
1235 	switch(type) {
1236 	case IPL_TYPE_CCW:
1237 		reipl_block_actual = reipl_block_ccw;
1238 		break;
1239 	case IPL_TYPE_ECKD:
1240 		reipl_block_actual = reipl_block_eckd;
1241 		break;
1242 	case IPL_TYPE_FCP:
1243 		reipl_block_actual = reipl_block_fcp;
1244 		break;
1245 	case IPL_TYPE_NVME:
1246 		reipl_block_actual = reipl_block_nvme;
1247 		break;
1248 	case IPL_TYPE_NSS:
1249 		reipl_block_actual = reipl_block_nss;
1250 		break;
1251 	default:
1252 		break;
1253 	}
1254 	reipl_type = type;
1255 	return 0;
1256 }
1257 
1258 static ssize_t reipl_type_show(struct kobject *kobj,
1259 			       struct kobj_attribute *attr, char *page)
1260 {
1261 	return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1262 }
1263 
1264 static ssize_t reipl_type_store(struct kobject *kobj,
1265 				struct kobj_attribute *attr,
1266 				const char *buf, size_t len)
1267 {
1268 	int rc = -EINVAL;
1269 
1270 	if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1271 		rc = reipl_set_type(IPL_TYPE_CCW);
1272 	else if (strncmp(buf, IPL_ECKD_STR, strlen(IPL_ECKD_STR)) == 0)
1273 		rc = reipl_set_type(IPL_TYPE_ECKD);
1274 	else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1275 		rc = reipl_set_type(IPL_TYPE_FCP);
1276 	else if (strncmp(buf, IPL_NVME_STR, strlen(IPL_NVME_STR)) == 0)
1277 		rc = reipl_set_type(IPL_TYPE_NVME);
1278 	else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1279 		rc = reipl_set_type(IPL_TYPE_NSS);
1280 	return (rc != 0) ? rc : len;
1281 }
1282 
1283 static struct kobj_attribute reipl_type_attr =
1284 	__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1285 
1286 static struct kset *reipl_kset;
1287 static struct kset *reipl_fcp_kset;
1288 static struct kset *reipl_nvme_kset;
1289 static struct kset *reipl_eckd_kset;
1290 
1291 static void __reipl_run(void *unused)
1292 {
1293 	switch (reipl_type) {
1294 	case IPL_TYPE_CCW:
1295 		diag308(DIAG308_SET, reipl_block_ccw);
1296 		if (reipl_ccw_clear)
1297 			diag308(DIAG308_LOAD_CLEAR, NULL);
1298 		else
1299 			diag308(DIAG308_LOAD_NORMAL_DUMP, NULL);
1300 		break;
1301 	case IPL_TYPE_ECKD:
1302 		diag308(DIAG308_SET, reipl_block_eckd);
1303 		if (reipl_eckd_clear)
1304 			diag308(DIAG308_LOAD_CLEAR, NULL);
1305 		else
1306 			diag308(DIAG308_LOAD_NORMAL, NULL);
1307 		break;
1308 	case IPL_TYPE_FCP:
1309 		diag308(DIAG308_SET, reipl_block_fcp);
1310 		if (reipl_fcp_clear)
1311 			diag308(DIAG308_LOAD_CLEAR, NULL);
1312 		else
1313 			diag308(DIAG308_LOAD_NORMAL, NULL);
1314 		break;
1315 	case IPL_TYPE_NVME:
1316 		diag308(DIAG308_SET, reipl_block_nvme);
1317 		if (reipl_nvme_clear)
1318 			diag308(DIAG308_LOAD_CLEAR, NULL);
1319 		else
1320 			diag308(DIAG308_LOAD_NORMAL, NULL);
1321 		break;
1322 	case IPL_TYPE_NSS:
1323 		diag308(DIAG308_SET, reipl_block_nss);
1324 		diag308(DIAG308_LOAD_CLEAR, NULL);
1325 		break;
1326 	case IPL_TYPE_UNKNOWN:
1327 		diag308(DIAG308_LOAD_CLEAR, NULL);
1328 		break;
1329 	case IPL_TYPE_FCP_DUMP:
1330 	case IPL_TYPE_NVME_DUMP:
1331 	case IPL_TYPE_ECKD_DUMP:
1332 		break;
1333 	}
1334 	disabled_wait();
1335 }
1336 
1337 static void reipl_run(struct shutdown_trigger *trigger)
1338 {
1339 	smp_call_ipl_cpu(__reipl_run, NULL);
1340 }
1341 
1342 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1343 {
1344 	ipb->hdr.len = IPL_BP_CCW_LEN;
1345 	ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1346 	ipb->pb0_hdr.len = IPL_BP0_CCW_LEN;
1347 	ipb->pb0_hdr.pbt = IPL_PBT_CCW;
1348 }
1349 
1350 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1351 {
1352 	/* LOADPARM */
1353 	/* check if read scp info worked and set loadparm */
1354 	if (sclp_ipl_info.is_valid)
1355 		memcpy(ipb->ccw.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
1356 	else
1357 		/* read scp info failed: set empty loadparm (EBCDIC blanks) */
1358 		memset(ipb->ccw.loadparm, 0x40, LOADPARM_LEN);
1359 	ipb->ccw.flags = IPL_PB0_FLAG_LOADPARM;
1360 
1361 	/* VM PARM */
1362 	if (MACHINE_IS_VM && ipl_block_valid &&
1363 	    (ipl_block.ccw.vm_flags & IPL_PB0_CCW_VM_FLAG_VP)) {
1364 
1365 		ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
1366 		ipb->ccw.vm_parm_len = ipl_block.ccw.vm_parm_len;
1367 		memcpy(ipb->ccw.vm_parm,
1368 		       ipl_block.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1369 	}
1370 }
1371 
1372 static int __init reipl_nss_init(void)
1373 {
1374 	int rc;
1375 
1376 	if (!MACHINE_IS_VM)
1377 		return 0;
1378 
1379 	reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1380 	if (!reipl_block_nss)
1381 		return -ENOMEM;
1382 
1383 	rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1384 	if (rc)
1385 		return rc;
1386 
1387 	reipl_block_ccw_init(reipl_block_nss);
1388 	reipl_capabilities |= IPL_TYPE_NSS;
1389 	return 0;
1390 }
1391 
1392 static int __init reipl_ccw_init(void)
1393 {
1394 	int rc;
1395 
1396 	reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1397 	if (!reipl_block_ccw)
1398 		return -ENOMEM;
1399 
1400 	rc = sysfs_create_group(&reipl_kset->kobj,
1401 				MACHINE_IS_VM ? &reipl_ccw_attr_group_vm
1402 					      : &reipl_ccw_attr_group_lpar);
1403 	if (rc)
1404 		return rc;
1405 
1406 	reipl_block_ccw_init(reipl_block_ccw);
1407 	if (ipl_info.type == IPL_TYPE_CCW) {
1408 		reipl_block_ccw->ccw.ssid = ipl_block.ccw.ssid;
1409 		reipl_block_ccw->ccw.devno = ipl_block.ccw.devno;
1410 		reipl_block_ccw_fill_parms(reipl_block_ccw);
1411 	}
1412 
1413 	reipl_capabilities |= IPL_TYPE_CCW;
1414 	return 0;
1415 }
1416 
1417 static int __init reipl_fcp_init(void)
1418 {
1419 	int rc;
1420 
1421 	reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1422 	if (!reipl_block_fcp)
1423 		return -ENOMEM;
1424 
1425 	/* sysfs: create fcp kset for mixing attr group and bin attrs */
1426 	reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1427 					     &reipl_kset->kobj);
1428 	if (!reipl_fcp_kset) {
1429 		free_page((unsigned long) reipl_block_fcp);
1430 		return -ENOMEM;
1431 	}
1432 
1433 	rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1434 	if (rc)
1435 		goto out1;
1436 
1437 	if (test_facility(141)) {
1438 		rc = sysfs_create_file(&reipl_fcp_kset->kobj,
1439 				       &sys_reipl_fcp_clear_attr.attr);
1440 		if (rc)
1441 			goto out2;
1442 	} else {
1443 		reipl_fcp_clear = true;
1444 	}
1445 
1446 	if (ipl_info.type == IPL_TYPE_FCP) {
1447 		memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block));
1448 		/*
1449 		 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1450 		 * is invalid in the SCSI IPL parameter block, so take it
1451 		 * always from sclp_ipl_info.
1452 		 */
1453 		memcpy(reipl_block_fcp->fcp.loadparm, sclp_ipl_info.loadparm,
1454 		       LOADPARM_LEN);
1455 	} else {
1456 		reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1457 		reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1458 		reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1459 		reipl_block_fcp->fcp.pbt = IPL_PBT_FCP;
1460 		reipl_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_IPL;
1461 	}
1462 	reipl_capabilities |= IPL_TYPE_FCP;
1463 	return 0;
1464 
1465 out2:
1466 	sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1467 out1:
1468 	kset_unregister(reipl_fcp_kset);
1469 	free_page((unsigned long) reipl_block_fcp);
1470 	return rc;
1471 }
1472 
1473 static int __init reipl_nvme_init(void)
1474 {
1475 	int rc;
1476 
1477 	reipl_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1478 	if (!reipl_block_nvme)
1479 		return -ENOMEM;
1480 
1481 	/* sysfs: create kset for mixing attr group and bin attrs */
1482 	reipl_nvme_kset = kset_create_and_add(IPL_NVME_STR, NULL,
1483 					     &reipl_kset->kobj);
1484 	if (!reipl_nvme_kset) {
1485 		free_page((unsigned long) reipl_block_nvme);
1486 		return -ENOMEM;
1487 	}
1488 
1489 	rc = sysfs_create_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1490 	if (rc)
1491 		goto out1;
1492 
1493 	if (test_facility(141)) {
1494 		rc = sysfs_create_file(&reipl_nvme_kset->kobj,
1495 				       &sys_reipl_nvme_clear_attr.attr);
1496 		if (rc)
1497 			goto out2;
1498 	} else {
1499 		reipl_nvme_clear = true;
1500 	}
1501 
1502 	if (ipl_info.type == IPL_TYPE_NVME) {
1503 		memcpy(reipl_block_nvme, &ipl_block, sizeof(ipl_block));
1504 		/*
1505 		 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1506 		 * is invalid in the IPL parameter block, so take it
1507 		 * always from sclp_ipl_info.
1508 		 */
1509 		memcpy(reipl_block_nvme->nvme.loadparm, sclp_ipl_info.loadparm,
1510 		       LOADPARM_LEN);
1511 	} else {
1512 		reipl_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1513 		reipl_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1514 		reipl_block_nvme->nvme.len = IPL_BP0_NVME_LEN;
1515 		reipl_block_nvme->nvme.pbt = IPL_PBT_NVME;
1516 		reipl_block_nvme->nvme.opt = IPL_PB0_NVME_OPT_IPL;
1517 	}
1518 	reipl_capabilities |= IPL_TYPE_NVME;
1519 	return 0;
1520 
1521 out2:
1522 	sysfs_remove_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1523 out1:
1524 	kset_unregister(reipl_nvme_kset);
1525 	free_page((unsigned long) reipl_block_nvme);
1526 	return rc;
1527 }
1528 
1529 static int __init reipl_eckd_init(void)
1530 {
1531 	int rc;
1532 
1533 	if (!sclp.has_sipl_eckd)
1534 		return 0;
1535 
1536 	reipl_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1537 	if (!reipl_block_eckd)
1538 		return -ENOMEM;
1539 
1540 	/* sysfs: create kset for mixing attr group and bin attrs */
1541 	reipl_eckd_kset = kset_create_and_add(IPL_ECKD_STR, NULL,
1542 					      &reipl_kset->kobj);
1543 	if (!reipl_eckd_kset) {
1544 		free_page((unsigned long)reipl_block_eckd);
1545 		return -ENOMEM;
1546 	}
1547 
1548 	rc = sysfs_create_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1549 	if (rc)
1550 		goto out1;
1551 
1552 	if (test_facility(141)) {
1553 		rc = sysfs_create_file(&reipl_eckd_kset->kobj,
1554 				       &sys_reipl_eckd_clear_attr.attr);
1555 		if (rc)
1556 			goto out2;
1557 	} else {
1558 		reipl_eckd_clear = true;
1559 	}
1560 
1561 	if (ipl_info.type == IPL_TYPE_ECKD) {
1562 		memcpy(reipl_block_eckd, &ipl_block, sizeof(ipl_block));
1563 	} else {
1564 		reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1565 		reipl_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1566 		reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1567 		reipl_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1568 		reipl_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_IPL;
1569 	}
1570 	reipl_capabilities |= IPL_TYPE_ECKD;
1571 	return 0;
1572 
1573 out2:
1574 	sysfs_remove_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1575 out1:
1576 	kset_unregister(reipl_eckd_kset);
1577 	free_page((unsigned long)reipl_block_eckd);
1578 	return rc;
1579 }
1580 
1581 static int __init reipl_type_init(void)
1582 {
1583 	enum ipl_type reipl_type = ipl_info.type;
1584 	struct ipl_parameter_block *reipl_block;
1585 	unsigned long size;
1586 
1587 	reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1588 	if (!reipl_block)
1589 		goto out;
1590 	/*
1591 	 * If we have an OS info reipl block, this will be used
1592 	 */
1593 	if (reipl_block->pb0_hdr.pbt == IPL_PBT_FCP) {
1594 		memcpy(reipl_block_fcp, reipl_block, size);
1595 		reipl_type = IPL_TYPE_FCP;
1596 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_NVME) {
1597 		memcpy(reipl_block_nvme, reipl_block, size);
1598 		reipl_type = IPL_TYPE_NVME;
1599 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_CCW) {
1600 		memcpy(reipl_block_ccw, reipl_block, size);
1601 		reipl_type = IPL_TYPE_CCW;
1602 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_ECKD) {
1603 		memcpy(reipl_block_eckd, reipl_block, size);
1604 		reipl_type = IPL_TYPE_ECKD;
1605 	}
1606 out:
1607 	return reipl_set_type(reipl_type);
1608 }
1609 
1610 static int __init reipl_init(void)
1611 {
1612 	int rc;
1613 
1614 	reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1615 	if (!reipl_kset)
1616 		return -ENOMEM;
1617 	rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1618 	if (rc) {
1619 		kset_unregister(reipl_kset);
1620 		return rc;
1621 	}
1622 	rc = reipl_ccw_init();
1623 	if (rc)
1624 		return rc;
1625 	rc = reipl_eckd_init();
1626 	if (rc)
1627 		return rc;
1628 	rc = reipl_fcp_init();
1629 	if (rc)
1630 		return rc;
1631 	rc = reipl_nvme_init();
1632 	if (rc)
1633 		return rc;
1634 	rc = reipl_nss_init();
1635 	if (rc)
1636 		return rc;
1637 	return reipl_type_init();
1638 }
1639 
1640 static struct shutdown_action __refdata reipl_action = {
1641 	.name	= SHUTDOWN_ACTION_REIPL_STR,
1642 	.fn	= reipl_run,
1643 	.init	= reipl_init,
1644 };
1645 
1646 /*
1647  * dump shutdown action: Dump Linux on shutdown.
1648  */
1649 
1650 /* FCP dump device attributes */
1651 
1652 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
1653 		   dump_block_fcp->fcp.wwpn);
1654 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
1655 		   dump_block_fcp->fcp.lun);
1656 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1657 		   dump_block_fcp->fcp.bootprog);
1658 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1659 		   dump_block_fcp->fcp.br_lba);
1660 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1661 		   dump_block_fcp->fcp.devno);
1662 
1663 static struct attribute *dump_fcp_attrs[] = {
1664 	&sys_dump_fcp_device_attr.attr,
1665 	&sys_dump_fcp_wwpn_attr.attr,
1666 	&sys_dump_fcp_lun_attr.attr,
1667 	&sys_dump_fcp_bootprog_attr.attr,
1668 	&sys_dump_fcp_br_lba_attr.attr,
1669 	NULL,
1670 };
1671 
1672 static struct attribute_group dump_fcp_attr_group = {
1673 	.name  = IPL_FCP_STR,
1674 	.attrs = dump_fcp_attrs,
1675 };
1676 
1677 /* NVME dump device attributes */
1678 DEFINE_IPL_ATTR_RW(dump_nvme, fid, "0x%08llx\n", "%llx\n",
1679 		   dump_block_nvme->nvme.fid);
1680 DEFINE_IPL_ATTR_RW(dump_nvme, nsid, "0x%08llx\n", "%llx\n",
1681 		   dump_block_nvme->nvme.nsid);
1682 DEFINE_IPL_ATTR_RW(dump_nvme, bootprog, "%lld\n", "%llx\n",
1683 		   dump_block_nvme->nvme.bootprog);
1684 DEFINE_IPL_ATTR_RW(dump_nvme, br_lba, "%lld\n", "%llx\n",
1685 		   dump_block_nvme->nvme.br_lba);
1686 
1687 static struct attribute *dump_nvme_attrs[] = {
1688 	&sys_dump_nvme_fid_attr.attr,
1689 	&sys_dump_nvme_nsid_attr.attr,
1690 	&sys_dump_nvme_bootprog_attr.attr,
1691 	&sys_dump_nvme_br_lba_attr.attr,
1692 	NULL,
1693 };
1694 
1695 static struct attribute_group dump_nvme_attr_group = {
1696 	.name  = IPL_NVME_STR,
1697 	.attrs = dump_nvme_attrs,
1698 };
1699 
1700 /* ECKD dump device attributes */
1701 DEFINE_IPL_CCW_ATTR_RW(dump_eckd, device, dump_block_eckd->eckd);
1702 DEFINE_IPL_ATTR_RW(dump_eckd, bootprog, "%lld\n", "%llx\n",
1703 		   dump_block_eckd->eckd.bootprog);
1704 
1705 IPL_ATTR_BR_CHR_SHOW_FN(dump, dump_block_eckd->eckd);
1706 IPL_ATTR_BR_CHR_STORE_FN(dump, dump_block_eckd->eckd);
1707 
1708 static struct kobj_attribute sys_dump_eckd_br_chr_attr =
1709 	__ATTR(br_chr, 0644, eckd_dump_br_chr_show, eckd_dump_br_chr_store);
1710 
1711 static struct attribute *dump_eckd_attrs[] = {
1712 	&sys_dump_eckd_device_attr.attr,
1713 	&sys_dump_eckd_bootprog_attr.attr,
1714 	&sys_dump_eckd_br_chr_attr.attr,
1715 	NULL,
1716 };
1717 
1718 static struct attribute_group dump_eckd_attr_group = {
1719 	.name  = IPL_ECKD_STR,
1720 	.attrs = dump_eckd_attrs,
1721 };
1722 
1723 /* CCW dump device attributes */
1724 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ccw);
1725 
1726 static struct attribute *dump_ccw_attrs[] = {
1727 	&sys_dump_ccw_device_attr.attr,
1728 	NULL,
1729 };
1730 
1731 static struct attribute_group dump_ccw_attr_group = {
1732 	.name  = IPL_CCW_STR,
1733 	.attrs = dump_ccw_attrs,
1734 };
1735 
1736 /* dump type */
1737 
1738 static int dump_set_type(enum dump_type type)
1739 {
1740 	if (!(dump_capabilities & type))
1741 		return -EINVAL;
1742 	dump_type = type;
1743 	return 0;
1744 }
1745 
1746 static ssize_t dump_type_show(struct kobject *kobj,
1747 			      struct kobj_attribute *attr, char *page)
1748 {
1749 	return sprintf(page, "%s\n", dump_type_str(dump_type));
1750 }
1751 
1752 static ssize_t dump_type_store(struct kobject *kobj,
1753 			       struct kobj_attribute *attr,
1754 			       const char *buf, size_t len)
1755 {
1756 	int rc = -EINVAL;
1757 
1758 	if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1759 		rc = dump_set_type(DUMP_TYPE_NONE);
1760 	else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1761 		rc = dump_set_type(DUMP_TYPE_CCW);
1762 	else if (strncmp(buf, DUMP_ECKD_STR, strlen(DUMP_ECKD_STR)) == 0)
1763 		rc = dump_set_type(DUMP_TYPE_ECKD);
1764 	else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1765 		rc = dump_set_type(DUMP_TYPE_FCP);
1766 	else if (strncmp(buf, DUMP_NVME_STR, strlen(DUMP_NVME_STR)) == 0)
1767 		rc = dump_set_type(DUMP_TYPE_NVME);
1768 	return (rc != 0) ? rc : len;
1769 }
1770 
1771 static struct kobj_attribute dump_type_attr =
1772 	__ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1773 
1774 static struct kset *dump_kset;
1775 
1776 static void diag308_dump(void *dump_block)
1777 {
1778 	diag308(DIAG308_SET, dump_block);
1779 	while (1) {
1780 		if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
1781 			break;
1782 		udelay(USEC_PER_SEC);
1783 	}
1784 }
1785 
1786 static void __dump_run(void *unused)
1787 {
1788 	switch (dump_type) {
1789 	case DUMP_TYPE_CCW:
1790 		diag308_dump(dump_block_ccw);
1791 		break;
1792 	case DUMP_TYPE_ECKD:
1793 		diag308_dump(dump_block_eckd);
1794 		break;
1795 	case DUMP_TYPE_FCP:
1796 		diag308_dump(dump_block_fcp);
1797 		break;
1798 	case DUMP_TYPE_NVME:
1799 		diag308_dump(dump_block_nvme);
1800 		break;
1801 	default:
1802 		break;
1803 	}
1804 }
1805 
1806 static void dump_run(struct shutdown_trigger *trigger)
1807 {
1808 	if (dump_type == DUMP_TYPE_NONE)
1809 		return;
1810 	smp_send_stop();
1811 	smp_call_ipl_cpu(__dump_run, NULL);
1812 }
1813 
1814 static int __init dump_ccw_init(void)
1815 {
1816 	int rc;
1817 
1818 	dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1819 	if (!dump_block_ccw)
1820 		return -ENOMEM;
1821 	rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1822 	if (rc) {
1823 		free_page((unsigned long)dump_block_ccw);
1824 		return rc;
1825 	}
1826 	dump_block_ccw->hdr.len = IPL_BP_CCW_LEN;
1827 	dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1828 	dump_block_ccw->ccw.len = IPL_BP0_CCW_LEN;
1829 	dump_block_ccw->ccw.pbt = IPL_PBT_CCW;
1830 	dump_capabilities |= DUMP_TYPE_CCW;
1831 	return 0;
1832 }
1833 
1834 static int __init dump_fcp_init(void)
1835 {
1836 	int rc;
1837 
1838 	if (!sclp_ipl_info.has_dump)
1839 		return 0; /* LDIPL DUMP is not installed */
1840 	dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1841 	if (!dump_block_fcp)
1842 		return -ENOMEM;
1843 	rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1844 	if (rc) {
1845 		free_page((unsigned long)dump_block_fcp);
1846 		return rc;
1847 	}
1848 	dump_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1849 	dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1850 	dump_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1851 	dump_block_fcp->fcp.pbt = IPL_PBT_FCP;
1852 	dump_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_DUMP;
1853 	dump_capabilities |= DUMP_TYPE_FCP;
1854 	return 0;
1855 }
1856 
1857 static int __init dump_nvme_init(void)
1858 {
1859 	int rc;
1860 
1861 	if (!sclp_ipl_info.has_dump)
1862 		return 0; /* LDIPL DUMP is not installed */
1863 	dump_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1864 	if (!dump_block_nvme)
1865 		return -ENOMEM;
1866 	rc = sysfs_create_group(&dump_kset->kobj, &dump_nvme_attr_group);
1867 	if (rc) {
1868 		free_page((unsigned long)dump_block_nvme);
1869 		return rc;
1870 	}
1871 	dump_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1872 	dump_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1873 	dump_block_nvme->fcp.len = IPL_BP0_NVME_LEN;
1874 	dump_block_nvme->fcp.pbt = IPL_PBT_NVME;
1875 	dump_block_nvme->fcp.opt = IPL_PB0_NVME_OPT_DUMP;
1876 	dump_capabilities |= DUMP_TYPE_NVME;
1877 	return 0;
1878 }
1879 
1880 static int __init dump_eckd_init(void)
1881 {
1882 	int rc;
1883 
1884 	if (!sclp_ipl_info.has_dump || !sclp.has_sipl_eckd)
1885 		return 0; /* LDIPL DUMP is not installed */
1886 	dump_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1887 	if (!dump_block_eckd)
1888 		return -ENOMEM;
1889 	rc = sysfs_create_group(&dump_kset->kobj, &dump_eckd_attr_group);
1890 	if (rc) {
1891 		free_page((unsigned long)dump_block_eckd);
1892 		return rc;
1893 	}
1894 	dump_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1895 	dump_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1896 	dump_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1897 	dump_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1898 	dump_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_DUMP;
1899 	dump_capabilities |= DUMP_TYPE_ECKD;
1900 	return 0;
1901 }
1902 
1903 static int __init dump_init(void)
1904 {
1905 	int rc;
1906 
1907 	dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1908 	if (!dump_kset)
1909 		return -ENOMEM;
1910 	rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1911 	if (rc) {
1912 		kset_unregister(dump_kset);
1913 		return rc;
1914 	}
1915 	rc = dump_ccw_init();
1916 	if (rc)
1917 		return rc;
1918 	rc = dump_eckd_init();
1919 	if (rc)
1920 		return rc;
1921 	rc = dump_fcp_init();
1922 	if (rc)
1923 		return rc;
1924 	rc = dump_nvme_init();
1925 	if (rc)
1926 		return rc;
1927 	dump_set_type(DUMP_TYPE_NONE);
1928 	return 0;
1929 }
1930 
1931 static struct shutdown_action __refdata dump_action = {
1932 	.name	= SHUTDOWN_ACTION_DUMP_STR,
1933 	.fn	= dump_run,
1934 	.init	= dump_init,
1935 };
1936 
1937 static void dump_reipl_run(struct shutdown_trigger *trigger)
1938 {
1939 	unsigned long ipib = (unsigned long) reipl_block_actual;
1940 	struct lowcore *abs_lc;
1941 	unsigned int csum;
1942 
1943 	csum = (__force unsigned int)
1944 	       csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1945 	abs_lc = get_abs_lowcore();
1946 	abs_lc->ipib = ipib;
1947 	abs_lc->ipib_checksum = csum;
1948 	put_abs_lowcore(abs_lc);
1949 	dump_run(trigger);
1950 }
1951 
1952 static struct shutdown_action __refdata dump_reipl_action = {
1953 	.name	= SHUTDOWN_ACTION_DUMP_REIPL_STR,
1954 	.fn	= dump_reipl_run,
1955 };
1956 
1957 /*
1958  * vmcmd shutdown action: Trigger vm command on shutdown.
1959  */
1960 
1961 static char vmcmd_on_reboot[128];
1962 static char vmcmd_on_panic[128];
1963 static char vmcmd_on_halt[128];
1964 static char vmcmd_on_poff[128];
1965 static char vmcmd_on_restart[128];
1966 
1967 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1968 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1969 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1970 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1971 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1972 
1973 static struct attribute *vmcmd_attrs[] = {
1974 	&sys_vmcmd_on_reboot_attr.attr,
1975 	&sys_vmcmd_on_panic_attr.attr,
1976 	&sys_vmcmd_on_halt_attr.attr,
1977 	&sys_vmcmd_on_poff_attr.attr,
1978 	&sys_vmcmd_on_restart_attr.attr,
1979 	NULL,
1980 };
1981 
1982 static struct attribute_group vmcmd_attr_group = {
1983 	.attrs = vmcmd_attrs,
1984 };
1985 
1986 static struct kset *vmcmd_kset;
1987 
1988 static void vmcmd_run(struct shutdown_trigger *trigger)
1989 {
1990 	char *cmd;
1991 
1992 	if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1993 		cmd = vmcmd_on_reboot;
1994 	else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1995 		cmd = vmcmd_on_panic;
1996 	else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1997 		cmd = vmcmd_on_halt;
1998 	else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1999 		cmd = vmcmd_on_poff;
2000 	else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
2001 		cmd = vmcmd_on_restart;
2002 	else
2003 		return;
2004 
2005 	if (strlen(cmd) == 0)
2006 		return;
2007 	__cpcmd(cmd, NULL, 0, NULL);
2008 }
2009 
2010 static int vmcmd_init(void)
2011 {
2012 	if (!MACHINE_IS_VM)
2013 		return -EOPNOTSUPP;
2014 	vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
2015 	if (!vmcmd_kset)
2016 		return -ENOMEM;
2017 	return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
2018 }
2019 
2020 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
2021 					      vmcmd_run, vmcmd_init};
2022 
2023 /*
2024  * stop shutdown action: Stop Linux on shutdown.
2025  */
2026 
2027 static void stop_run(struct shutdown_trigger *trigger)
2028 {
2029 	if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
2030 	    strcmp(trigger->name, ON_RESTART_STR) == 0)
2031 		disabled_wait();
2032 	smp_stop_cpu();
2033 }
2034 
2035 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
2036 					     stop_run, NULL};
2037 
2038 /* action list */
2039 
2040 static struct shutdown_action *shutdown_actions_list[] = {
2041 	&ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
2042 	&vmcmd_action, &stop_action};
2043 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
2044 
2045 /*
2046  * Trigger section
2047  */
2048 
2049 static struct kset *shutdown_actions_kset;
2050 
2051 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
2052 		       size_t len)
2053 {
2054 	int i;
2055 
2056 	for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2057 		if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
2058 			if (shutdown_actions_list[i]->init_rc) {
2059 				return shutdown_actions_list[i]->init_rc;
2060 			} else {
2061 				trigger->action = shutdown_actions_list[i];
2062 				return len;
2063 			}
2064 		}
2065 	}
2066 	return -EINVAL;
2067 }
2068 
2069 /* on reipl */
2070 
2071 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
2072 						    &reipl_action};
2073 
2074 static ssize_t on_reboot_show(struct kobject *kobj,
2075 			      struct kobj_attribute *attr, char *page)
2076 {
2077 	return sprintf(page, "%s\n", on_reboot_trigger.action->name);
2078 }
2079 
2080 static ssize_t on_reboot_store(struct kobject *kobj,
2081 			       struct kobj_attribute *attr,
2082 			       const char *buf, size_t len)
2083 {
2084 	return set_trigger(buf, &on_reboot_trigger, len);
2085 }
2086 static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
2087 
2088 static void do_machine_restart(char *__unused)
2089 {
2090 	smp_send_stop();
2091 	on_reboot_trigger.action->fn(&on_reboot_trigger);
2092 	reipl_run(NULL);
2093 }
2094 void (*_machine_restart)(char *command) = do_machine_restart;
2095 
2096 /* on panic */
2097 
2098 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
2099 
2100 static ssize_t on_panic_show(struct kobject *kobj,
2101 			     struct kobj_attribute *attr, char *page)
2102 {
2103 	return sprintf(page, "%s\n", on_panic_trigger.action->name);
2104 }
2105 
2106 static ssize_t on_panic_store(struct kobject *kobj,
2107 			      struct kobj_attribute *attr,
2108 			      const char *buf, size_t len)
2109 {
2110 	return set_trigger(buf, &on_panic_trigger, len);
2111 }
2112 static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
2113 
2114 static void do_panic(void)
2115 {
2116 	lgr_info_log();
2117 	on_panic_trigger.action->fn(&on_panic_trigger);
2118 	stop_run(&on_panic_trigger);
2119 }
2120 
2121 /* on restart */
2122 
2123 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
2124 	&stop_action};
2125 
2126 static ssize_t on_restart_show(struct kobject *kobj,
2127 			       struct kobj_attribute *attr, char *page)
2128 {
2129 	return sprintf(page, "%s\n", on_restart_trigger.action->name);
2130 }
2131 
2132 static ssize_t on_restart_store(struct kobject *kobj,
2133 				struct kobj_attribute *attr,
2134 				const char *buf, size_t len)
2135 {
2136 	return set_trigger(buf, &on_restart_trigger, len);
2137 }
2138 static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
2139 
2140 static void __do_restart(void *ignore)
2141 {
2142 	smp_send_stop();
2143 #ifdef CONFIG_CRASH_DUMP
2144 	crash_kexec(NULL);
2145 #endif
2146 	on_restart_trigger.action->fn(&on_restart_trigger);
2147 	stop_run(&on_restart_trigger);
2148 }
2149 
2150 void do_restart(void *arg)
2151 {
2152 	tracing_off();
2153 	debug_locks_off();
2154 	lgr_info_log();
2155 	smp_call_online_cpu(__do_restart, arg);
2156 }
2157 
2158 /* on halt */
2159 
2160 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
2161 
2162 static ssize_t on_halt_show(struct kobject *kobj,
2163 			    struct kobj_attribute *attr, char *page)
2164 {
2165 	return sprintf(page, "%s\n", on_halt_trigger.action->name);
2166 }
2167 
2168 static ssize_t on_halt_store(struct kobject *kobj,
2169 			     struct kobj_attribute *attr,
2170 			     const char *buf, size_t len)
2171 {
2172 	return set_trigger(buf, &on_halt_trigger, len);
2173 }
2174 static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
2175 
2176 static void do_machine_halt(void)
2177 {
2178 	smp_send_stop();
2179 	on_halt_trigger.action->fn(&on_halt_trigger);
2180 	stop_run(&on_halt_trigger);
2181 }
2182 void (*_machine_halt)(void) = do_machine_halt;
2183 
2184 /* on power off */
2185 
2186 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
2187 
2188 static ssize_t on_poff_show(struct kobject *kobj,
2189 			    struct kobj_attribute *attr, char *page)
2190 {
2191 	return sprintf(page, "%s\n", on_poff_trigger.action->name);
2192 }
2193 
2194 static ssize_t on_poff_store(struct kobject *kobj,
2195 			     struct kobj_attribute *attr,
2196 			     const char *buf, size_t len)
2197 {
2198 	return set_trigger(buf, &on_poff_trigger, len);
2199 }
2200 static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
2201 
2202 static void do_machine_power_off(void)
2203 {
2204 	smp_send_stop();
2205 	on_poff_trigger.action->fn(&on_poff_trigger);
2206 	stop_run(&on_poff_trigger);
2207 }
2208 void (*_machine_power_off)(void) = do_machine_power_off;
2209 
2210 static struct attribute *shutdown_action_attrs[] = {
2211 	&on_restart_attr.attr,
2212 	&on_reboot_attr.attr,
2213 	&on_panic_attr.attr,
2214 	&on_halt_attr.attr,
2215 	&on_poff_attr.attr,
2216 	NULL,
2217 };
2218 
2219 static struct attribute_group shutdown_action_attr_group = {
2220 	.attrs = shutdown_action_attrs,
2221 };
2222 
2223 static void __init shutdown_triggers_init(void)
2224 {
2225 	shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
2226 						    firmware_kobj);
2227 	if (!shutdown_actions_kset)
2228 		goto fail;
2229 	if (sysfs_create_group(&shutdown_actions_kset->kobj,
2230 			       &shutdown_action_attr_group))
2231 		goto fail;
2232 	return;
2233 fail:
2234 	panic("shutdown_triggers_init failed\n");
2235 }
2236 
2237 static void __init shutdown_actions_init(void)
2238 {
2239 	int i;
2240 
2241 	for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2242 		if (!shutdown_actions_list[i]->init)
2243 			continue;
2244 		shutdown_actions_list[i]->init_rc =
2245 			shutdown_actions_list[i]->init();
2246 	}
2247 }
2248 
2249 static int __init s390_ipl_init(void)
2250 {
2251 	char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
2252 
2253 	sclp_early_get_ipl_info(&sclp_ipl_info);
2254 	/*
2255 	 * Fix loadparm: There are systems where the (SCSI) LOADPARM
2256 	 * returned by read SCP info is invalid (contains EBCDIC blanks)
2257 	 * when the system has been booted via diag308. In that case we use
2258 	 * the value from diag308, if available.
2259 	 *
2260 	 * There are also systems where diag308 store does not work in
2261 	 * case the system is booted from HMC. Fortunately in this case
2262 	 * READ SCP info provides the correct value.
2263 	 */
2264 	if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && ipl_block_valid)
2265 		memcpy(sclp_ipl_info.loadparm, ipl_block.ccw.loadparm, LOADPARM_LEN);
2266 	shutdown_actions_init();
2267 	shutdown_triggers_init();
2268 	return 0;
2269 }
2270 
2271 __initcall(s390_ipl_init);
2272 
2273 static void __init strncpy_skip_quote(char *dst, char *src, int n)
2274 {
2275 	int sx, dx;
2276 
2277 	dx = 0;
2278 	for (sx = 0; src[sx] != 0; sx++) {
2279 		if (src[sx] == '"')
2280 			continue;
2281 		dst[dx++] = src[sx];
2282 		if (dx >= n)
2283 			break;
2284 	}
2285 }
2286 
2287 static int __init vmcmd_on_reboot_setup(char *str)
2288 {
2289 	if (!MACHINE_IS_VM)
2290 		return 1;
2291 	strncpy_skip_quote(vmcmd_on_reboot, str, 127);
2292 	vmcmd_on_reboot[127] = 0;
2293 	on_reboot_trigger.action = &vmcmd_action;
2294 	return 1;
2295 }
2296 __setup("vmreboot=", vmcmd_on_reboot_setup);
2297 
2298 static int __init vmcmd_on_panic_setup(char *str)
2299 {
2300 	if (!MACHINE_IS_VM)
2301 		return 1;
2302 	strncpy_skip_quote(vmcmd_on_panic, str, 127);
2303 	vmcmd_on_panic[127] = 0;
2304 	on_panic_trigger.action = &vmcmd_action;
2305 	return 1;
2306 }
2307 __setup("vmpanic=", vmcmd_on_panic_setup);
2308 
2309 static int __init vmcmd_on_halt_setup(char *str)
2310 {
2311 	if (!MACHINE_IS_VM)
2312 		return 1;
2313 	strncpy_skip_quote(vmcmd_on_halt, str, 127);
2314 	vmcmd_on_halt[127] = 0;
2315 	on_halt_trigger.action = &vmcmd_action;
2316 	return 1;
2317 }
2318 __setup("vmhalt=", vmcmd_on_halt_setup);
2319 
2320 static int __init vmcmd_on_poff_setup(char *str)
2321 {
2322 	if (!MACHINE_IS_VM)
2323 		return 1;
2324 	strncpy_skip_quote(vmcmd_on_poff, str, 127);
2325 	vmcmd_on_poff[127] = 0;
2326 	on_poff_trigger.action = &vmcmd_action;
2327 	return 1;
2328 }
2329 __setup("vmpoff=", vmcmd_on_poff_setup);
2330 
2331 static int on_panic_notify(struct notifier_block *self,
2332 			   unsigned long event, void *data)
2333 {
2334 	do_panic();
2335 	return NOTIFY_OK;
2336 }
2337 
2338 static struct notifier_block on_panic_nb = {
2339 	.notifier_call = on_panic_notify,
2340 	.priority = INT_MIN,
2341 };
2342 
2343 void __init setup_ipl(void)
2344 {
2345 	BUILD_BUG_ON(sizeof(struct ipl_parameter_block) != PAGE_SIZE);
2346 
2347 	ipl_info.type = get_ipl_type();
2348 	switch (ipl_info.type) {
2349 	case IPL_TYPE_CCW:
2350 		ipl_info.data.ccw.dev_id.ssid = ipl_block.ccw.ssid;
2351 		ipl_info.data.ccw.dev_id.devno = ipl_block.ccw.devno;
2352 		break;
2353 	case IPL_TYPE_ECKD:
2354 	case IPL_TYPE_ECKD_DUMP:
2355 		ipl_info.data.eckd.dev_id.ssid = ipl_block.eckd.ssid;
2356 		ipl_info.data.eckd.dev_id.devno = ipl_block.eckd.devno;
2357 		break;
2358 	case IPL_TYPE_FCP:
2359 	case IPL_TYPE_FCP_DUMP:
2360 		ipl_info.data.fcp.dev_id.ssid = 0;
2361 		ipl_info.data.fcp.dev_id.devno = ipl_block.fcp.devno;
2362 		ipl_info.data.fcp.wwpn = ipl_block.fcp.wwpn;
2363 		ipl_info.data.fcp.lun = ipl_block.fcp.lun;
2364 		break;
2365 	case IPL_TYPE_NVME:
2366 	case IPL_TYPE_NVME_DUMP:
2367 		ipl_info.data.nvme.fid = ipl_block.nvme.fid;
2368 		ipl_info.data.nvme.nsid = ipl_block.nvme.nsid;
2369 		break;
2370 	case IPL_TYPE_NSS:
2371 	case IPL_TYPE_UNKNOWN:
2372 		/* We have no info to copy */
2373 		break;
2374 	}
2375 	atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
2376 }
2377 
2378 void s390_reset_system(void)
2379 {
2380 	/* Disable prefixing */
2381 	set_prefix(0);
2382 
2383 	/* Disable lowcore protection */
2384 	__ctl_clear_bit(0, 28);
2385 	diag_amode31_ops.diag308_reset();
2386 }
2387 
2388 #ifdef CONFIG_KEXEC_FILE
2389 
2390 int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
2391 			     unsigned char flags, unsigned short cert)
2392 {
2393 	struct ipl_report_component *comp;
2394 
2395 	comp = vzalloc(sizeof(*comp));
2396 	if (!comp)
2397 		return -ENOMEM;
2398 	list_add_tail(&comp->list, &report->components);
2399 
2400 	comp->entry.addr = kbuf->mem;
2401 	comp->entry.len = kbuf->memsz;
2402 	comp->entry.flags = flags;
2403 	comp->entry.certificate_index = cert;
2404 
2405 	report->size += sizeof(comp->entry);
2406 
2407 	return 0;
2408 }
2409 
2410 int ipl_report_add_certificate(struct ipl_report *report, void *key,
2411 			       unsigned long addr, unsigned long len)
2412 {
2413 	struct ipl_report_certificate *cert;
2414 
2415 	cert = vzalloc(sizeof(*cert));
2416 	if (!cert)
2417 		return -ENOMEM;
2418 	list_add_tail(&cert->list, &report->certificates);
2419 
2420 	cert->entry.addr = addr;
2421 	cert->entry.len = len;
2422 	cert->key = key;
2423 
2424 	report->size += sizeof(cert->entry);
2425 	report->size += cert->entry.len;
2426 
2427 	return 0;
2428 }
2429 
2430 struct ipl_report *ipl_report_init(struct ipl_parameter_block *ipib)
2431 {
2432 	struct ipl_report *report;
2433 
2434 	report = vzalloc(sizeof(*report));
2435 	if (!report)
2436 		return ERR_PTR(-ENOMEM);
2437 
2438 	report->ipib = ipib;
2439 	INIT_LIST_HEAD(&report->components);
2440 	INIT_LIST_HEAD(&report->certificates);
2441 
2442 	report->size = ALIGN(ipib->hdr.len, 8);
2443 	report->size += sizeof(struct ipl_rl_hdr);
2444 	report->size += sizeof(struct ipl_rb_components);
2445 	report->size += sizeof(struct ipl_rb_certificates);
2446 
2447 	return report;
2448 }
2449 
2450 void *ipl_report_finish(struct ipl_report *report)
2451 {
2452 	struct ipl_report_certificate *cert;
2453 	struct ipl_report_component *comp;
2454 	struct ipl_rb_certificates *certs;
2455 	struct ipl_parameter_block *ipib;
2456 	struct ipl_rb_components *comps;
2457 	struct ipl_rl_hdr *rl_hdr;
2458 	void *buf, *ptr;
2459 
2460 	buf = vzalloc(report->size);
2461 	if (!buf)
2462 		goto out;
2463 	ptr = buf;
2464 
2465 	memcpy(ptr, report->ipib, report->ipib->hdr.len);
2466 	ipib = ptr;
2467 	if (ipl_secure_flag)
2468 		ipib->hdr.flags |= IPL_PL_FLAG_SIPL;
2469 	ipib->hdr.flags |= IPL_PL_FLAG_IPLSR;
2470 	ptr += report->ipib->hdr.len;
2471 	ptr = PTR_ALIGN(ptr, 8);
2472 
2473 	rl_hdr = ptr;
2474 	ptr += sizeof(*rl_hdr);
2475 
2476 	comps = ptr;
2477 	comps->rbt = IPL_RBT_COMPONENTS;
2478 	ptr += sizeof(*comps);
2479 	list_for_each_entry(comp, &report->components, list) {
2480 		memcpy(ptr, &comp->entry, sizeof(comp->entry));
2481 		ptr += sizeof(comp->entry);
2482 	}
2483 	comps->len = ptr - (void *)comps;
2484 
2485 	certs = ptr;
2486 	certs->rbt = IPL_RBT_CERTIFICATES;
2487 	ptr += sizeof(*certs);
2488 	list_for_each_entry(cert, &report->certificates, list) {
2489 		memcpy(ptr, &cert->entry, sizeof(cert->entry));
2490 		ptr += sizeof(cert->entry);
2491 	}
2492 	certs->len = ptr - (void *)certs;
2493 	rl_hdr->len = ptr - (void *)rl_hdr;
2494 
2495 	list_for_each_entry(cert, &report->certificates, list) {
2496 		memcpy(ptr, cert->key, cert->entry.len);
2497 		ptr += cert->entry.len;
2498 	}
2499 
2500 	BUG_ON(ptr > buf + report->size);
2501 out:
2502 	return buf;
2503 }
2504 
2505 int ipl_report_free(struct ipl_report *report)
2506 {
2507 	struct ipl_report_component *comp, *ncomp;
2508 	struct ipl_report_certificate *cert, *ncert;
2509 
2510 	list_for_each_entry_safe(comp, ncomp, &report->components, list)
2511 		vfree(comp);
2512 
2513 	list_for_each_entry_safe(cert, ncert, &report->certificates, list)
2514 		vfree(cert);
2515 
2516 	vfree(report);
2517 
2518 	return 0;
2519 }
2520 
2521 #endif
2522