xref: /openbmc/linux/arch/s390/kernel/ipl.c (revision 89df62c3)
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, unsigned long addr)
180 {
181 	union register_pair r1;
182 
183 	r1.even = 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 ? virt_to_phys(addr) : 0);
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 	diag308(DIAG308_LOAD_CLEAR, NULL);
653 }
654 
655 static void ipl_run(struct shutdown_trigger *trigger)
656 {
657 	smp_call_ipl_cpu(__ipl_run, NULL);
658 }
659 
660 static int __init ipl_init(void)
661 {
662 	int rc;
663 
664 	ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
665 	if (!ipl_kset) {
666 		rc = -ENOMEM;
667 		goto out;
668 	}
669 	switch (ipl_info.type) {
670 	case IPL_TYPE_CCW:
671 		if (MACHINE_IS_VM)
672 			rc = sysfs_create_group(&ipl_kset->kobj,
673 						&ipl_ccw_attr_group_vm);
674 		else
675 			rc = sysfs_create_group(&ipl_kset->kobj,
676 						&ipl_ccw_attr_group_lpar);
677 		break;
678 	case IPL_TYPE_ECKD:
679 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_eckd_attr_group);
680 		break;
681 	case IPL_TYPE_FCP:
682 	case IPL_TYPE_FCP_DUMP:
683 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
684 		break;
685 	case IPL_TYPE_NVME:
686 	case IPL_TYPE_NVME_DUMP:
687 		rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nvme_attr_group);
688 		break;
689 	default:
690 		rc = sysfs_create_group(&ipl_kset->kobj,
691 					&ipl_unknown_attr_group);
692 		break;
693 	}
694 out:
695 	if (rc)
696 		panic("ipl_init failed: rc = %i\n", rc);
697 
698 	return 0;
699 }
700 
701 static struct shutdown_action __refdata ipl_action = {
702 	.name	= SHUTDOWN_ACTION_IPL_STR,
703 	.fn	= ipl_run,
704 	.init	= ipl_init,
705 };
706 
707 /*
708  * reipl shutdown action: Reboot Linux on shutdown.
709  */
710 
711 /* VM IPL PARM attributes */
712 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
713 					  char *page)
714 {
715 	char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
716 
717 	ipl_block_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
718 	return sprintf(page, "%s\n", vmparm);
719 }
720 
721 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
722 					  size_t vmparm_max,
723 					  const char *buf, size_t len)
724 {
725 	int i, ip_len;
726 
727 	/* ignore trailing newline */
728 	ip_len = len;
729 	if ((len > 0) && (buf[len - 1] == '\n'))
730 		ip_len--;
731 
732 	if (ip_len > vmparm_max)
733 		return -EINVAL;
734 
735 	/* parm is used to store kernel options, check for common chars */
736 	for (i = 0; i < ip_len; i++)
737 		if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
738 			return -EINVAL;
739 
740 	memset(ipb->ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
741 	ipb->ccw.vm_parm_len = ip_len;
742 	if (ip_len > 0) {
743 		ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
744 		memcpy(ipb->ccw.vm_parm, buf, ip_len);
745 		ASCEBC(ipb->ccw.vm_parm, ip_len);
746 	} else {
747 		ipb->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_VP;
748 	}
749 
750 	return len;
751 }
752 
753 /* NSS wrapper */
754 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
755 				     struct kobj_attribute *attr, char *page)
756 {
757 	return reipl_generic_vmparm_show(reipl_block_nss, page);
758 }
759 
760 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
761 				      struct kobj_attribute *attr,
762 				      const char *buf, size_t len)
763 {
764 	return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
765 }
766 
767 /* CCW wrapper */
768 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
769 				     struct kobj_attribute *attr, char *page)
770 {
771 	return reipl_generic_vmparm_show(reipl_block_ccw, page);
772 }
773 
774 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
775 				      struct kobj_attribute *attr,
776 				      const char *buf, size_t len)
777 {
778 	return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
779 }
780 
781 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
782 	__ATTR(parm, 0644, reipl_nss_vmparm_show,
783 	       reipl_nss_vmparm_store);
784 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
785 	__ATTR(parm, 0644, reipl_ccw_vmparm_show,
786 	       reipl_ccw_vmparm_store);
787 
788 /* FCP reipl device attributes */
789 
790 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
791 				      struct bin_attribute *attr,
792 				      char *buf, loff_t off, size_t count)
793 {
794 	size_t size = reipl_block_fcp->fcp.scp_data_len;
795 	void *scp_data = reipl_block_fcp->fcp.scp_data;
796 
797 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
798 }
799 
800 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
801 				       struct bin_attribute *attr,
802 				       char *buf, loff_t off, size_t count)
803 {
804 	size_t scpdata_len = count;
805 	size_t padding;
806 
807 
808 	if (off)
809 		return -EINVAL;
810 
811 	memcpy(reipl_block_fcp->fcp.scp_data, buf, count);
812 	if (scpdata_len % 8) {
813 		padding = 8 - (scpdata_len % 8);
814 		memset(reipl_block_fcp->fcp.scp_data + scpdata_len,
815 		       0, padding);
816 		scpdata_len += padding;
817 	}
818 
819 	reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
820 	reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN + scpdata_len;
821 	reipl_block_fcp->fcp.scp_data_len = scpdata_len;
822 
823 	return count;
824 }
825 static struct bin_attribute sys_reipl_fcp_scp_data_attr =
826 	__BIN_ATTR(scp_data, 0644, reipl_fcp_scpdata_read,
827 		   reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
828 
829 static struct bin_attribute *reipl_fcp_bin_attrs[] = {
830 	&sys_reipl_fcp_scp_data_attr,
831 	NULL,
832 };
833 
834 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
835 		   reipl_block_fcp->fcp.wwpn);
836 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
837 		   reipl_block_fcp->fcp.lun);
838 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
839 		   reipl_block_fcp->fcp.bootprog);
840 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
841 		   reipl_block_fcp->fcp.br_lba);
842 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
843 		   reipl_block_fcp->fcp.devno);
844 
845 static void reipl_get_ascii_loadparm(char *loadparm,
846 				     struct ipl_parameter_block *ibp)
847 {
848 	memcpy(loadparm, ibp->common.loadparm, LOADPARM_LEN);
849 	EBCASC(loadparm, LOADPARM_LEN);
850 	loadparm[LOADPARM_LEN] = 0;
851 	strim(loadparm);
852 }
853 
854 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
855 					   char *page)
856 {
857 	char buf[LOADPARM_LEN + 1];
858 
859 	reipl_get_ascii_loadparm(buf, ipb);
860 	return sprintf(page, "%s\n", buf);
861 }
862 
863 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
864 					    const char *buf, size_t len)
865 {
866 	int i, lp_len;
867 
868 	/* ignore trailing newline */
869 	lp_len = len;
870 	if ((len > 0) && (buf[len - 1] == '\n'))
871 		lp_len--;
872 	/* loadparm can have max 8 characters and must not start with a blank */
873 	if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
874 		return -EINVAL;
875 	/* loadparm can only contain "a-z,A-Z,0-9,SP,." */
876 	for (i = 0; i < lp_len; i++) {
877 		if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
878 		    (buf[i] == '.'))
879 			continue;
880 		return -EINVAL;
881 	}
882 	/* initialize loadparm with blanks */
883 	memset(ipb->common.loadparm, ' ', LOADPARM_LEN);
884 	/* copy and convert to ebcdic */
885 	memcpy(ipb->common.loadparm, buf, lp_len);
886 	ASCEBC(ipb->common.loadparm, LOADPARM_LEN);
887 	ipb->common.flags |= IPL_PB0_FLAG_LOADPARM;
888 	return len;
889 }
890 
891 #define DEFINE_GENERIC_LOADPARM(name)							\
892 static ssize_t reipl_##name##_loadparm_show(struct kobject *kobj,			\
893 					    struct kobj_attribute *attr, char *page)	\
894 {											\
895 	return reipl_generic_loadparm_show(reipl_block_##name, page);			\
896 }											\
897 static ssize_t reipl_##name##_loadparm_store(struct kobject *kobj,			\
898 					     struct kobj_attribute *attr,		\
899 					     const char *buf, size_t len)		\
900 {											\
901 	return reipl_generic_loadparm_store(reipl_block_##name, buf, len);		\
902 }											\
903 static struct kobj_attribute sys_reipl_##name##_loadparm_attr =				\
904 	__ATTR(loadparm, 0644, reipl_##name##_loadparm_show,				\
905 	       reipl_##name##_loadparm_store)
906 
907 DEFINE_GENERIC_LOADPARM(fcp);
908 DEFINE_GENERIC_LOADPARM(nvme);
909 DEFINE_GENERIC_LOADPARM(ccw);
910 DEFINE_GENERIC_LOADPARM(nss);
911 DEFINE_GENERIC_LOADPARM(eckd);
912 
913 static ssize_t reipl_fcp_clear_show(struct kobject *kobj,
914 				    struct kobj_attribute *attr, char *page)
915 {
916 	return sprintf(page, "%u\n", reipl_fcp_clear);
917 }
918 
919 static ssize_t reipl_fcp_clear_store(struct kobject *kobj,
920 				     struct kobj_attribute *attr,
921 				     const char *buf, size_t len)
922 {
923 	if (kstrtobool(buf, &reipl_fcp_clear) < 0)
924 		return -EINVAL;
925 	return len;
926 }
927 
928 static struct attribute *reipl_fcp_attrs[] = {
929 	&sys_reipl_fcp_device_attr.attr,
930 	&sys_reipl_fcp_wwpn_attr.attr,
931 	&sys_reipl_fcp_lun_attr.attr,
932 	&sys_reipl_fcp_bootprog_attr.attr,
933 	&sys_reipl_fcp_br_lba_attr.attr,
934 	&sys_reipl_fcp_loadparm_attr.attr,
935 	NULL,
936 };
937 
938 static struct attribute_group reipl_fcp_attr_group = {
939 	.attrs = reipl_fcp_attrs,
940 	.bin_attrs = reipl_fcp_bin_attrs,
941 };
942 
943 static struct kobj_attribute sys_reipl_fcp_clear_attr =
944 	__ATTR(clear, 0644, reipl_fcp_clear_show, reipl_fcp_clear_store);
945 
946 /* NVME reipl device attributes */
947 
948 static ssize_t reipl_nvme_scpdata_read(struct file *filp, struct kobject *kobj,
949 				      struct bin_attribute *attr,
950 				      char *buf, loff_t off, size_t count)
951 {
952 	size_t size = reipl_block_nvme->nvme.scp_data_len;
953 	void *scp_data = reipl_block_nvme->nvme.scp_data;
954 
955 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
956 }
957 
958 static ssize_t reipl_nvme_scpdata_write(struct file *filp, struct kobject *kobj,
959 				       struct bin_attribute *attr,
960 				       char *buf, loff_t off, size_t count)
961 {
962 	size_t scpdata_len = count;
963 	size_t padding;
964 
965 	if (off)
966 		return -EINVAL;
967 
968 	memcpy(reipl_block_nvme->nvme.scp_data, buf, count);
969 	if (scpdata_len % 8) {
970 		padding = 8 - (scpdata_len % 8);
971 		memset(reipl_block_nvme->nvme.scp_data + scpdata_len,
972 		       0, padding);
973 		scpdata_len += padding;
974 	}
975 
976 	reipl_block_nvme->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
977 	reipl_block_nvme->nvme.len = IPL_BP0_FCP_LEN + scpdata_len;
978 	reipl_block_nvme->nvme.scp_data_len = scpdata_len;
979 
980 	return count;
981 }
982 
983 static struct bin_attribute sys_reipl_nvme_scp_data_attr =
984 	__BIN_ATTR(scp_data, 0644, reipl_nvme_scpdata_read,
985 		   reipl_nvme_scpdata_write, DIAG308_SCPDATA_SIZE);
986 
987 static struct bin_attribute *reipl_nvme_bin_attrs[] = {
988 	&sys_reipl_nvme_scp_data_attr,
989 	NULL,
990 };
991 
992 DEFINE_IPL_ATTR_RW(reipl_nvme, fid, "0x%08llx\n", "%llx\n",
993 		   reipl_block_nvme->nvme.fid);
994 DEFINE_IPL_ATTR_RW(reipl_nvme, nsid, "0x%08llx\n", "%llx\n",
995 		   reipl_block_nvme->nvme.nsid);
996 DEFINE_IPL_ATTR_RW(reipl_nvme, bootprog, "%lld\n", "%lld\n",
997 		   reipl_block_nvme->nvme.bootprog);
998 DEFINE_IPL_ATTR_RW(reipl_nvme, br_lba, "%lld\n", "%lld\n",
999 		   reipl_block_nvme->nvme.br_lba);
1000 
1001 static struct attribute *reipl_nvme_attrs[] = {
1002 	&sys_reipl_nvme_fid_attr.attr,
1003 	&sys_reipl_nvme_nsid_attr.attr,
1004 	&sys_reipl_nvme_bootprog_attr.attr,
1005 	&sys_reipl_nvme_br_lba_attr.attr,
1006 	&sys_reipl_nvme_loadparm_attr.attr,
1007 	NULL,
1008 };
1009 
1010 static struct attribute_group reipl_nvme_attr_group = {
1011 	.attrs = reipl_nvme_attrs,
1012 	.bin_attrs = reipl_nvme_bin_attrs
1013 };
1014 
1015 static ssize_t reipl_nvme_clear_show(struct kobject *kobj,
1016 				     struct kobj_attribute *attr, char *page)
1017 {
1018 	return sprintf(page, "%u\n", reipl_nvme_clear);
1019 }
1020 
1021 static ssize_t reipl_nvme_clear_store(struct kobject *kobj,
1022 				      struct kobj_attribute *attr,
1023 				      const char *buf, size_t len)
1024 {
1025 	if (kstrtobool(buf, &reipl_nvme_clear) < 0)
1026 		return -EINVAL;
1027 	return len;
1028 }
1029 
1030 static struct kobj_attribute sys_reipl_nvme_clear_attr =
1031 	__ATTR(clear, 0644, reipl_nvme_clear_show, reipl_nvme_clear_store);
1032 
1033 /* CCW reipl device attributes */
1034 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ccw);
1035 
1036 static ssize_t reipl_ccw_clear_show(struct kobject *kobj,
1037 				    struct kobj_attribute *attr, char *page)
1038 {
1039 	return sprintf(page, "%u\n", reipl_ccw_clear);
1040 }
1041 
1042 static ssize_t reipl_ccw_clear_store(struct kobject *kobj,
1043 				     struct kobj_attribute *attr,
1044 				     const char *buf, size_t len)
1045 {
1046 	if (kstrtobool(buf, &reipl_ccw_clear) < 0)
1047 		return -EINVAL;
1048 	return len;
1049 }
1050 
1051 static struct kobj_attribute sys_reipl_ccw_clear_attr =
1052 	__ATTR(clear, 0644, reipl_ccw_clear_show, reipl_ccw_clear_store);
1053 
1054 static struct attribute *reipl_ccw_attrs_vm[] = {
1055 	&sys_reipl_ccw_device_attr.attr,
1056 	&sys_reipl_ccw_loadparm_attr.attr,
1057 	&sys_reipl_ccw_vmparm_attr.attr,
1058 	&sys_reipl_ccw_clear_attr.attr,
1059 	NULL,
1060 };
1061 
1062 static struct attribute *reipl_ccw_attrs_lpar[] = {
1063 	&sys_reipl_ccw_device_attr.attr,
1064 	&sys_reipl_ccw_loadparm_attr.attr,
1065 	&sys_reipl_ccw_clear_attr.attr,
1066 	NULL,
1067 };
1068 
1069 static struct attribute_group reipl_ccw_attr_group_vm = {
1070 	.name  = IPL_CCW_STR,
1071 	.attrs = reipl_ccw_attrs_vm,
1072 };
1073 
1074 static struct attribute_group reipl_ccw_attr_group_lpar = {
1075 	.name  = IPL_CCW_STR,
1076 	.attrs = reipl_ccw_attrs_lpar,
1077 };
1078 
1079 /* ECKD reipl device attributes */
1080 
1081 static ssize_t reipl_eckd_scpdata_read(struct file *filp, struct kobject *kobj,
1082 				       struct bin_attribute *attr,
1083 				       char *buf, loff_t off, size_t count)
1084 {
1085 	size_t size = reipl_block_eckd->eckd.scp_data_len;
1086 	void *scp_data = reipl_block_eckd->eckd.scp_data;
1087 
1088 	return memory_read_from_buffer(buf, count, &off, scp_data, size);
1089 }
1090 
1091 static ssize_t reipl_eckd_scpdata_write(struct file *filp, struct kobject *kobj,
1092 					struct bin_attribute *attr,
1093 					char *buf, loff_t off, size_t count)
1094 {
1095 	size_t scpdata_len = count;
1096 	size_t padding;
1097 
1098 	if (off)
1099 		return -EINVAL;
1100 
1101 	memcpy(reipl_block_eckd->eckd.scp_data, buf, count);
1102 	if (scpdata_len % 8) {
1103 		padding = 8 - (scpdata_len % 8);
1104 		memset(reipl_block_eckd->eckd.scp_data + scpdata_len,
1105 		       0, padding);
1106 		scpdata_len += padding;
1107 	}
1108 
1109 	reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN + scpdata_len;
1110 	reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN + scpdata_len;
1111 	reipl_block_eckd->eckd.scp_data_len = scpdata_len;
1112 
1113 	return count;
1114 }
1115 
1116 static struct bin_attribute sys_reipl_eckd_scp_data_attr =
1117 	__BIN_ATTR(scp_data, 0644, reipl_eckd_scpdata_read,
1118 		   reipl_eckd_scpdata_write, DIAG308_SCPDATA_SIZE);
1119 
1120 static struct bin_attribute *reipl_eckd_bin_attrs[] = {
1121 	&sys_reipl_eckd_scp_data_attr,
1122 	NULL,
1123 };
1124 
1125 DEFINE_IPL_CCW_ATTR_RW(reipl_eckd, device, reipl_block_eckd->eckd);
1126 DEFINE_IPL_ATTR_RW(reipl_eckd, bootprog, "%lld\n", "%lld\n",
1127 		   reipl_block_eckd->eckd.bootprog);
1128 
1129 static struct attribute *reipl_eckd_attrs[] = {
1130 	&sys_reipl_eckd_device_attr.attr,
1131 	&sys_reipl_eckd_bootprog_attr.attr,
1132 	&sys_reipl_eckd_br_chr_attr.attr,
1133 	&sys_reipl_eckd_loadparm_attr.attr,
1134 	NULL,
1135 };
1136 
1137 static struct attribute_group reipl_eckd_attr_group = {
1138 	.attrs = reipl_eckd_attrs,
1139 	.bin_attrs = reipl_eckd_bin_attrs
1140 };
1141 
1142 static ssize_t reipl_eckd_clear_show(struct kobject *kobj,
1143 				     struct kobj_attribute *attr, char *page)
1144 {
1145 	return sprintf(page, "%u\n", reipl_eckd_clear);
1146 }
1147 
1148 static ssize_t reipl_eckd_clear_store(struct kobject *kobj,
1149 				      struct kobj_attribute *attr,
1150 				      const char *buf, size_t len)
1151 {
1152 	if (kstrtobool(buf, &reipl_eckd_clear) < 0)
1153 		return -EINVAL;
1154 	return len;
1155 }
1156 
1157 static struct kobj_attribute sys_reipl_eckd_clear_attr =
1158 	__ATTR(clear, 0644, reipl_eckd_clear_show, reipl_eckd_clear_store);
1159 
1160 /* NSS reipl device attributes */
1161 static void reipl_get_ascii_nss_name(char *dst,
1162 				     struct ipl_parameter_block *ipb)
1163 {
1164 	memcpy(dst, ipb->ccw.nss_name, NSS_NAME_SIZE);
1165 	EBCASC(dst, NSS_NAME_SIZE);
1166 	dst[NSS_NAME_SIZE] = 0;
1167 }
1168 
1169 static ssize_t reipl_nss_name_show(struct kobject *kobj,
1170 				   struct kobj_attribute *attr, char *page)
1171 {
1172 	char nss_name[NSS_NAME_SIZE + 1] = {};
1173 
1174 	reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
1175 	return sprintf(page, "%s\n", nss_name);
1176 }
1177 
1178 static ssize_t reipl_nss_name_store(struct kobject *kobj,
1179 				    struct kobj_attribute *attr,
1180 				    const char *buf, size_t len)
1181 {
1182 	int nss_len;
1183 
1184 	/* ignore trailing newline */
1185 	nss_len = len;
1186 	if ((len > 0) && (buf[len - 1] == '\n'))
1187 		nss_len--;
1188 
1189 	if (nss_len > NSS_NAME_SIZE)
1190 		return -EINVAL;
1191 
1192 	memset(reipl_block_nss->ccw.nss_name, 0x40, NSS_NAME_SIZE);
1193 	if (nss_len > 0) {
1194 		reipl_block_nss->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_NSS;
1195 		memcpy(reipl_block_nss->ccw.nss_name, buf, nss_len);
1196 		ASCEBC(reipl_block_nss->ccw.nss_name, nss_len);
1197 		EBC_TOUPPER(reipl_block_nss->ccw.nss_name, nss_len);
1198 	} else {
1199 		reipl_block_nss->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_NSS;
1200 	}
1201 
1202 	return len;
1203 }
1204 
1205 static struct kobj_attribute sys_reipl_nss_name_attr =
1206 	__ATTR(name, 0644, reipl_nss_name_show,
1207 	       reipl_nss_name_store);
1208 
1209 static struct attribute *reipl_nss_attrs[] = {
1210 	&sys_reipl_nss_name_attr.attr,
1211 	&sys_reipl_nss_loadparm_attr.attr,
1212 	&sys_reipl_nss_vmparm_attr.attr,
1213 	NULL,
1214 };
1215 
1216 static struct attribute_group reipl_nss_attr_group = {
1217 	.name  = IPL_NSS_STR,
1218 	.attrs = reipl_nss_attrs,
1219 };
1220 
1221 void set_os_info_reipl_block(void)
1222 {
1223 	os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
1224 			  reipl_block_actual->hdr.len);
1225 }
1226 
1227 /* reipl type */
1228 
1229 static int reipl_set_type(enum ipl_type type)
1230 {
1231 	if (!(reipl_capabilities & type))
1232 		return -EINVAL;
1233 
1234 	switch(type) {
1235 	case IPL_TYPE_CCW:
1236 		reipl_block_actual = reipl_block_ccw;
1237 		break;
1238 	case IPL_TYPE_ECKD:
1239 		reipl_block_actual = reipl_block_eckd;
1240 		break;
1241 	case IPL_TYPE_FCP:
1242 		reipl_block_actual = reipl_block_fcp;
1243 		break;
1244 	case IPL_TYPE_NVME:
1245 		reipl_block_actual = reipl_block_nvme;
1246 		break;
1247 	case IPL_TYPE_NSS:
1248 		reipl_block_actual = reipl_block_nss;
1249 		break;
1250 	default:
1251 		break;
1252 	}
1253 	reipl_type = type;
1254 	return 0;
1255 }
1256 
1257 static ssize_t reipl_type_show(struct kobject *kobj,
1258 			       struct kobj_attribute *attr, char *page)
1259 {
1260 	return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1261 }
1262 
1263 static ssize_t reipl_type_store(struct kobject *kobj,
1264 				struct kobj_attribute *attr,
1265 				const char *buf, size_t len)
1266 {
1267 	int rc = -EINVAL;
1268 
1269 	if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1270 		rc = reipl_set_type(IPL_TYPE_CCW);
1271 	else if (strncmp(buf, IPL_ECKD_STR, strlen(IPL_ECKD_STR)) == 0)
1272 		rc = reipl_set_type(IPL_TYPE_ECKD);
1273 	else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1274 		rc = reipl_set_type(IPL_TYPE_FCP);
1275 	else if (strncmp(buf, IPL_NVME_STR, strlen(IPL_NVME_STR)) == 0)
1276 		rc = reipl_set_type(IPL_TYPE_NVME);
1277 	else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1278 		rc = reipl_set_type(IPL_TYPE_NSS);
1279 	return (rc != 0) ? rc : len;
1280 }
1281 
1282 static struct kobj_attribute reipl_type_attr =
1283 	__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1284 
1285 static struct kset *reipl_kset;
1286 static struct kset *reipl_fcp_kset;
1287 static struct kset *reipl_nvme_kset;
1288 static struct kset *reipl_eckd_kset;
1289 
1290 static void __reipl_run(void *unused)
1291 {
1292 	switch (reipl_type) {
1293 	case IPL_TYPE_CCW:
1294 		diag308(DIAG308_SET, reipl_block_ccw);
1295 		if (reipl_ccw_clear)
1296 			diag308(DIAG308_LOAD_CLEAR, NULL);
1297 		else
1298 			diag308(DIAG308_LOAD_NORMAL_DUMP, NULL);
1299 		break;
1300 	case IPL_TYPE_ECKD:
1301 		diag308(DIAG308_SET, reipl_block_eckd);
1302 		if (reipl_eckd_clear)
1303 			diag308(DIAG308_LOAD_CLEAR, NULL);
1304 		else
1305 			diag308(DIAG308_LOAD_NORMAL, NULL);
1306 		break;
1307 	case IPL_TYPE_FCP:
1308 		diag308(DIAG308_SET, reipl_block_fcp);
1309 		if (reipl_fcp_clear)
1310 			diag308(DIAG308_LOAD_CLEAR, NULL);
1311 		else
1312 			diag308(DIAG308_LOAD_NORMAL, NULL);
1313 		break;
1314 	case IPL_TYPE_NVME:
1315 		diag308(DIAG308_SET, reipl_block_nvme);
1316 		if (reipl_nvme_clear)
1317 			diag308(DIAG308_LOAD_CLEAR, NULL);
1318 		else
1319 			diag308(DIAG308_LOAD_NORMAL, NULL);
1320 		break;
1321 	case IPL_TYPE_NSS:
1322 		diag308(DIAG308_SET, reipl_block_nss);
1323 		diag308(DIAG308_LOAD_CLEAR, NULL);
1324 		break;
1325 	case IPL_TYPE_UNKNOWN:
1326 		diag308(DIAG308_LOAD_CLEAR, NULL);
1327 		break;
1328 	case IPL_TYPE_FCP_DUMP:
1329 	case IPL_TYPE_NVME_DUMP:
1330 	case IPL_TYPE_ECKD_DUMP:
1331 		break;
1332 	}
1333 	disabled_wait();
1334 }
1335 
1336 static void reipl_run(struct shutdown_trigger *trigger)
1337 {
1338 	smp_call_ipl_cpu(__reipl_run, NULL);
1339 }
1340 
1341 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1342 {
1343 	ipb->hdr.len = IPL_BP_CCW_LEN;
1344 	ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1345 	ipb->pb0_hdr.len = IPL_BP0_CCW_LEN;
1346 	ipb->pb0_hdr.pbt = IPL_PBT_CCW;
1347 }
1348 
1349 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1350 {
1351 	/* LOADPARM */
1352 	/* check if read scp info worked and set loadparm */
1353 	if (sclp_ipl_info.is_valid)
1354 		memcpy(ipb->ccw.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
1355 	else
1356 		/* read scp info failed: set empty loadparm (EBCDIC blanks) */
1357 		memset(ipb->ccw.loadparm, 0x40, LOADPARM_LEN);
1358 	ipb->ccw.flags = IPL_PB0_FLAG_LOADPARM;
1359 
1360 	/* VM PARM */
1361 	if (MACHINE_IS_VM && ipl_block_valid &&
1362 	    (ipl_block.ccw.vm_flags & IPL_PB0_CCW_VM_FLAG_VP)) {
1363 
1364 		ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
1365 		ipb->ccw.vm_parm_len = ipl_block.ccw.vm_parm_len;
1366 		memcpy(ipb->ccw.vm_parm,
1367 		       ipl_block.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1368 	}
1369 }
1370 
1371 static int __init reipl_nss_init(void)
1372 {
1373 	int rc;
1374 
1375 	if (!MACHINE_IS_VM)
1376 		return 0;
1377 
1378 	reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1379 	if (!reipl_block_nss)
1380 		return -ENOMEM;
1381 
1382 	rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1383 	if (rc)
1384 		return rc;
1385 
1386 	reipl_block_ccw_init(reipl_block_nss);
1387 	reipl_capabilities |= IPL_TYPE_NSS;
1388 	return 0;
1389 }
1390 
1391 static int __init reipl_ccw_init(void)
1392 {
1393 	int rc;
1394 
1395 	reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1396 	if (!reipl_block_ccw)
1397 		return -ENOMEM;
1398 
1399 	rc = sysfs_create_group(&reipl_kset->kobj,
1400 				MACHINE_IS_VM ? &reipl_ccw_attr_group_vm
1401 					      : &reipl_ccw_attr_group_lpar);
1402 	if (rc)
1403 		return rc;
1404 
1405 	reipl_block_ccw_init(reipl_block_ccw);
1406 	if (ipl_info.type == IPL_TYPE_CCW) {
1407 		reipl_block_ccw->ccw.ssid = ipl_block.ccw.ssid;
1408 		reipl_block_ccw->ccw.devno = ipl_block.ccw.devno;
1409 		reipl_block_ccw_fill_parms(reipl_block_ccw);
1410 	}
1411 
1412 	reipl_capabilities |= IPL_TYPE_CCW;
1413 	return 0;
1414 }
1415 
1416 static int __init reipl_fcp_init(void)
1417 {
1418 	int rc;
1419 
1420 	reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1421 	if (!reipl_block_fcp)
1422 		return -ENOMEM;
1423 
1424 	/* sysfs: create fcp kset for mixing attr group and bin attrs */
1425 	reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1426 					     &reipl_kset->kobj);
1427 	if (!reipl_fcp_kset) {
1428 		free_page((unsigned long) reipl_block_fcp);
1429 		return -ENOMEM;
1430 	}
1431 
1432 	rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1433 	if (rc)
1434 		goto out1;
1435 
1436 	if (test_facility(141)) {
1437 		rc = sysfs_create_file(&reipl_fcp_kset->kobj,
1438 				       &sys_reipl_fcp_clear_attr.attr);
1439 		if (rc)
1440 			goto out2;
1441 	} else {
1442 		reipl_fcp_clear = true;
1443 	}
1444 
1445 	if (ipl_info.type == IPL_TYPE_FCP) {
1446 		memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block));
1447 		/*
1448 		 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1449 		 * is invalid in the SCSI IPL parameter block, so take it
1450 		 * always from sclp_ipl_info.
1451 		 */
1452 		memcpy(reipl_block_fcp->fcp.loadparm, sclp_ipl_info.loadparm,
1453 		       LOADPARM_LEN);
1454 	} else {
1455 		reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1456 		reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1457 		reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1458 		reipl_block_fcp->fcp.pbt = IPL_PBT_FCP;
1459 		reipl_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_IPL;
1460 	}
1461 	reipl_capabilities |= IPL_TYPE_FCP;
1462 	return 0;
1463 
1464 out2:
1465 	sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1466 out1:
1467 	kset_unregister(reipl_fcp_kset);
1468 	free_page((unsigned long) reipl_block_fcp);
1469 	return rc;
1470 }
1471 
1472 static int __init reipl_nvme_init(void)
1473 {
1474 	int rc;
1475 
1476 	reipl_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1477 	if (!reipl_block_nvme)
1478 		return -ENOMEM;
1479 
1480 	/* sysfs: create kset for mixing attr group and bin attrs */
1481 	reipl_nvme_kset = kset_create_and_add(IPL_NVME_STR, NULL,
1482 					     &reipl_kset->kobj);
1483 	if (!reipl_nvme_kset) {
1484 		free_page((unsigned long) reipl_block_nvme);
1485 		return -ENOMEM;
1486 	}
1487 
1488 	rc = sysfs_create_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1489 	if (rc)
1490 		goto out1;
1491 
1492 	if (test_facility(141)) {
1493 		rc = sysfs_create_file(&reipl_nvme_kset->kobj,
1494 				       &sys_reipl_nvme_clear_attr.attr);
1495 		if (rc)
1496 			goto out2;
1497 	} else {
1498 		reipl_nvme_clear = true;
1499 	}
1500 
1501 	if (ipl_info.type == IPL_TYPE_NVME) {
1502 		memcpy(reipl_block_nvme, &ipl_block, sizeof(ipl_block));
1503 		/*
1504 		 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1505 		 * is invalid in the IPL parameter block, so take it
1506 		 * always from sclp_ipl_info.
1507 		 */
1508 		memcpy(reipl_block_nvme->nvme.loadparm, sclp_ipl_info.loadparm,
1509 		       LOADPARM_LEN);
1510 	} else {
1511 		reipl_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1512 		reipl_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1513 		reipl_block_nvme->nvme.len = IPL_BP0_NVME_LEN;
1514 		reipl_block_nvme->nvme.pbt = IPL_PBT_NVME;
1515 		reipl_block_nvme->nvme.opt = IPL_PB0_NVME_OPT_IPL;
1516 	}
1517 	reipl_capabilities |= IPL_TYPE_NVME;
1518 	return 0;
1519 
1520 out2:
1521 	sysfs_remove_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1522 out1:
1523 	kset_unregister(reipl_nvme_kset);
1524 	free_page((unsigned long) reipl_block_nvme);
1525 	return rc;
1526 }
1527 
1528 static int __init reipl_eckd_init(void)
1529 {
1530 	int rc;
1531 
1532 	if (!sclp.has_sipl_eckd)
1533 		return 0;
1534 
1535 	reipl_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1536 	if (!reipl_block_eckd)
1537 		return -ENOMEM;
1538 
1539 	/* sysfs: create kset for mixing attr group and bin attrs */
1540 	reipl_eckd_kset = kset_create_and_add(IPL_ECKD_STR, NULL,
1541 					      &reipl_kset->kobj);
1542 	if (!reipl_eckd_kset) {
1543 		free_page((unsigned long)reipl_block_eckd);
1544 		return -ENOMEM;
1545 	}
1546 
1547 	rc = sysfs_create_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1548 	if (rc)
1549 		goto out1;
1550 
1551 	if (test_facility(141)) {
1552 		rc = sysfs_create_file(&reipl_eckd_kset->kobj,
1553 				       &sys_reipl_eckd_clear_attr.attr);
1554 		if (rc)
1555 			goto out2;
1556 	} else {
1557 		reipl_eckd_clear = true;
1558 	}
1559 
1560 	if (ipl_info.type == IPL_TYPE_ECKD) {
1561 		memcpy(reipl_block_eckd, &ipl_block, sizeof(ipl_block));
1562 	} else {
1563 		reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1564 		reipl_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1565 		reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1566 		reipl_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1567 		reipl_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_IPL;
1568 	}
1569 	reipl_capabilities |= IPL_TYPE_ECKD;
1570 	return 0;
1571 
1572 out2:
1573 	sysfs_remove_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1574 out1:
1575 	kset_unregister(reipl_eckd_kset);
1576 	free_page((unsigned long)reipl_block_eckd);
1577 	return rc;
1578 }
1579 
1580 static int __init reipl_type_init(void)
1581 {
1582 	enum ipl_type reipl_type = ipl_info.type;
1583 	struct ipl_parameter_block *reipl_block;
1584 	unsigned long size;
1585 
1586 	reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1587 	if (!reipl_block)
1588 		goto out;
1589 	/*
1590 	 * If we have an OS info reipl block, this will be used
1591 	 */
1592 	if (reipl_block->pb0_hdr.pbt == IPL_PBT_FCP) {
1593 		memcpy(reipl_block_fcp, reipl_block, size);
1594 		reipl_type = IPL_TYPE_FCP;
1595 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_NVME) {
1596 		memcpy(reipl_block_nvme, reipl_block, size);
1597 		reipl_type = IPL_TYPE_NVME;
1598 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_CCW) {
1599 		memcpy(reipl_block_ccw, reipl_block, size);
1600 		reipl_type = IPL_TYPE_CCW;
1601 	} else if (reipl_block->pb0_hdr.pbt == IPL_PBT_ECKD) {
1602 		memcpy(reipl_block_eckd, reipl_block, size);
1603 		reipl_type = IPL_TYPE_ECKD;
1604 	}
1605 out:
1606 	return reipl_set_type(reipl_type);
1607 }
1608 
1609 static int __init reipl_init(void)
1610 {
1611 	int rc;
1612 
1613 	reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1614 	if (!reipl_kset)
1615 		return -ENOMEM;
1616 	rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1617 	if (rc) {
1618 		kset_unregister(reipl_kset);
1619 		return rc;
1620 	}
1621 	rc = reipl_ccw_init();
1622 	if (rc)
1623 		return rc;
1624 	rc = reipl_eckd_init();
1625 	if (rc)
1626 		return rc;
1627 	rc = reipl_fcp_init();
1628 	if (rc)
1629 		return rc;
1630 	rc = reipl_nvme_init();
1631 	if (rc)
1632 		return rc;
1633 	rc = reipl_nss_init();
1634 	if (rc)
1635 		return rc;
1636 	return reipl_type_init();
1637 }
1638 
1639 static struct shutdown_action __refdata reipl_action = {
1640 	.name	= SHUTDOWN_ACTION_REIPL_STR,
1641 	.fn	= reipl_run,
1642 	.init	= reipl_init,
1643 };
1644 
1645 /*
1646  * dump shutdown action: Dump Linux on shutdown.
1647  */
1648 
1649 /* FCP dump device attributes */
1650 
1651 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
1652 		   dump_block_fcp->fcp.wwpn);
1653 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
1654 		   dump_block_fcp->fcp.lun);
1655 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1656 		   dump_block_fcp->fcp.bootprog);
1657 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1658 		   dump_block_fcp->fcp.br_lba);
1659 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1660 		   dump_block_fcp->fcp.devno);
1661 
1662 static struct attribute *dump_fcp_attrs[] = {
1663 	&sys_dump_fcp_device_attr.attr,
1664 	&sys_dump_fcp_wwpn_attr.attr,
1665 	&sys_dump_fcp_lun_attr.attr,
1666 	&sys_dump_fcp_bootprog_attr.attr,
1667 	&sys_dump_fcp_br_lba_attr.attr,
1668 	NULL,
1669 };
1670 
1671 static struct attribute_group dump_fcp_attr_group = {
1672 	.name  = IPL_FCP_STR,
1673 	.attrs = dump_fcp_attrs,
1674 };
1675 
1676 /* NVME dump device attributes */
1677 DEFINE_IPL_ATTR_RW(dump_nvme, fid, "0x%08llx\n", "%llx\n",
1678 		   dump_block_nvme->nvme.fid);
1679 DEFINE_IPL_ATTR_RW(dump_nvme, nsid, "0x%08llx\n", "%llx\n",
1680 		   dump_block_nvme->nvme.nsid);
1681 DEFINE_IPL_ATTR_RW(dump_nvme, bootprog, "%lld\n", "%llx\n",
1682 		   dump_block_nvme->nvme.bootprog);
1683 DEFINE_IPL_ATTR_RW(dump_nvme, br_lba, "%lld\n", "%llx\n",
1684 		   dump_block_nvme->nvme.br_lba);
1685 
1686 static struct attribute *dump_nvme_attrs[] = {
1687 	&sys_dump_nvme_fid_attr.attr,
1688 	&sys_dump_nvme_nsid_attr.attr,
1689 	&sys_dump_nvme_bootprog_attr.attr,
1690 	&sys_dump_nvme_br_lba_attr.attr,
1691 	NULL,
1692 };
1693 
1694 static struct attribute_group dump_nvme_attr_group = {
1695 	.name  = IPL_NVME_STR,
1696 	.attrs = dump_nvme_attrs,
1697 };
1698 
1699 /* ECKD dump device attributes */
1700 DEFINE_IPL_CCW_ATTR_RW(dump_eckd, device, dump_block_eckd->eckd);
1701 DEFINE_IPL_ATTR_RW(dump_eckd, bootprog, "%lld\n", "%llx\n",
1702 		   dump_block_eckd->eckd.bootprog);
1703 
1704 IPL_ATTR_BR_CHR_SHOW_FN(dump, dump_block_eckd->eckd);
1705 IPL_ATTR_BR_CHR_STORE_FN(dump, dump_block_eckd->eckd);
1706 
1707 static struct kobj_attribute sys_dump_eckd_br_chr_attr =
1708 	__ATTR(br_chr, 0644, eckd_dump_br_chr_show, eckd_dump_br_chr_store);
1709 
1710 static struct attribute *dump_eckd_attrs[] = {
1711 	&sys_dump_eckd_device_attr.attr,
1712 	&sys_dump_eckd_bootprog_attr.attr,
1713 	&sys_dump_eckd_br_chr_attr.attr,
1714 	NULL,
1715 };
1716 
1717 static struct attribute_group dump_eckd_attr_group = {
1718 	.name  = IPL_ECKD_STR,
1719 	.attrs = dump_eckd_attrs,
1720 };
1721 
1722 /* CCW dump device attributes */
1723 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ccw);
1724 
1725 static struct attribute *dump_ccw_attrs[] = {
1726 	&sys_dump_ccw_device_attr.attr,
1727 	NULL,
1728 };
1729 
1730 static struct attribute_group dump_ccw_attr_group = {
1731 	.name  = IPL_CCW_STR,
1732 	.attrs = dump_ccw_attrs,
1733 };
1734 
1735 /* dump type */
1736 
1737 static int dump_set_type(enum dump_type type)
1738 {
1739 	if (!(dump_capabilities & type))
1740 		return -EINVAL;
1741 	dump_type = type;
1742 	return 0;
1743 }
1744 
1745 static ssize_t dump_type_show(struct kobject *kobj,
1746 			      struct kobj_attribute *attr, char *page)
1747 {
1748 	return sprintf(page, "%s\n", dump_type_str(dump_type));
1749 }
1750 
1751 static ssize_t dump_type_store(struct kobject *kobj,
1752 			       struct kobj_attribute *attr,
1753 			       const char *buf, size_t len)
1754 {
1755 	int rc = -EINVAL;
1756 
1757 	if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1758 		rc = dump_set_type(DUMP_TYPE_NONE);
1759 	else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1760 		rc = dump_set_type(DUMP_TYPE_CCW);
1761 	else if (strncmp(buf, DUMP_ECKD_STR, strlen(DUMP_ECKD_STR)) == 0)
1762 		rc = dump_set_type(DUMP_TYPE_ECKD);
1763 	else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1764 		rc = dump_set_type(DUMP_TYPE_FCP);
1765 	else if (strncmp(buf, DUMP_NVME_STR, strlen(DUMP_NVME_STR)) == 0)
1766 		rc = dump_set_type(DUMP_TYPE_NVME);
1767 	return (rc != 0) ? rc : len;
1768 }
1769 
1770 static struct kobj_attribute dump_type_attr =
1771 	__ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1772 
1773 static struct kset *dump_kset;
1774 
1775 static void diag308_dump(void *dump_block)
1776 {
1777 	diag308(DIAG308_SET, dump_block);
1778 	while (1) {
1779 		if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
1780 			break;
1781 		udelay(USEC_PER_SEC);
1782 	}
1783 }
1784 
1785 static void __dump_run(void *unused)
1786 {
1787 	switch (dump_type) {
1788 	case DUMP_TYPE_CCW:
1789 		diag308_dump(dump_block_ccw);
1790 		break;
1791 	case DUMP_TYPE_ECKD:
1792 		diag308_dump(dump_block_eckd);
1793 		break;
1794 	case DUMP_TYPE_FCP:
1795 		diag308_dump(dump_block_fcp);
1796 		break;
1797 	case DUMP_TYPE_NVME:
1798 		diag308_dump(dump_block_nvme);
1799 		break;
1800 	default:
1801 		break;
1802 	}
1803 }
1804 
1805 static void dump_run(struct shutdown_trigger *trigger)
1806 {
1807 	if (dump_type == DUMP_TYPE_NONE)
1808 		return;
1809 	smp_send_stop();
1810 	smp_call_ipl_cpu(__dump_run, NULL);
1811 }
1812 
1813 static int __init dump_ccw_init(void)
1814 {
1815 	int rc;
1816 
1817 	dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1818 	if (!dump_block_ccw)
1819 		return -ENOMEM;
1820 	rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1821 	if (rc) {
1822 		free_page((unsigned long)dump_block_ccw);
1823 		return rc;
1824 	}
1825 	dump_block_ccw->hdr.len = IPL_BP_CCW_LEN;
1826 	dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1827 	dump_block_ccw->ccw.len = IPL_BP0_CCW_LEN;
1828 	dump_block_ccw->ccw.pbt = IPL_PBT_CCW;
1829 	dump_capabilities |= DUMP_TYPE_CCW;
1830 	return 0;
1831 }
1832 
1833 static int __init dump_fcp_init(void)
1834 {
1835 	int rc;
1836 
1837 	if (!sclp_ipl_info.has_dump)
1838 		return 0; /* LDIPL DUMP is not installed */
1839 	dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1840 	if (!dump_block_fcp)
1841 		return -ENOMEM;
1842 	rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1843 	if (rc) {
1844 		free_page((unsigned long)dump_block_fcp);
1845 		return rc;
1846 	}
1847 	dump_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1848 	dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1849 	dump_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1850 	dump_block_fcp->fcp.pbt = IPL_PBT_FCP;
1851 	dump_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_DUMP;
1852 	dump_capabilities |= DUMP_TYPE_FCP;
1853 	return 0;
1854 }
1855 
1856 static int __init dump_nvme_init(void)
1857 {
1858 	int rc;
1859 
1860 	if (!sclp_ipl_info.has_dump)
1861 		return 0; /* LDIPL DUMP is not installed */
1862 	dump_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1863 	if (!dump_block_nvme)
1864 		return -ENOMEM;
1865 	rc = sysfs_create_group(&dump_kset->kobj, &dump_nvme_attr_group);
1866 	if (rc) {
1867 		free_page((unsigned long)dump_block_nvme);
1868 		return rc;
1869 	}
1870 	dump_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1871 	dump_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1872 	dump_block_nvme->fcp.len = IPL_BP0_NVME_LEN;
1873 	dump_block_nvme->fcp.pbt = IPL_PBT_NVME;
1874 	dump_block_nvme->fcp.opt = IPL_PB0_NVME_OPT_DUMP;
1875 	dump_capabilities |= DUMP_TYPE_NVME;
1876 	return 0;
1877 }
1878 
1879 static int __init dump_eckd_init(void)
1880 {
1881 	int rc;
1882 
1883 	if (!sclp_ipl_info.has_dump || !sclp.has_sipl_eckd)
1884 		return 0; /* LDIPL DUMP is not installed */
1885 	dump_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1886 	if (!dump_block_eckd)
1887 		return -ENOMEM;
1888 	rc = sysfs_create_group(&dump_kset->kobj, &dump_eckd_attr_group);
1889 	if (rc) {
1890 		free_page((unsigned long)dump_block_eckd);
1891 		return rc;
1892 	}
1893 	dump_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1894 	dump_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1895 	dump_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1896 	dump_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1897 	dump_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_DUMP;
1898 	dump_capabilities |= DUMP_TYPE_ECKD;
1899 	return 0;
1900 }
1901 
1902 static int __init dump_init(void)
1903 {
1904 	int rc;
1905 
1906 	dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1907 	if (!dump_kset)
1908 		return -ENOMEM;
1909 	rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1910 	if (rc) {
1911 		kset_unregister(dump_kset);
1912 		return rc;
1913 	}
1914 	rc = dump_ccw_init();
1915 	if (rc)
1916 		return rc;
1917 	rc = dump_eckd_init();
1918 	if (rc)
1919 		return rc;
1920 	rc = dump_fcp_init();
1921 	if (rc)
1922 		return rc;
1923 	rc = dump_nvme_init();
1924 	if (rc)
1925 		return rc;
1926 	dump_set_type(DUMP_TYPE_NONE);
1927 	return 0;
1928 }
1929 
1930 static struct shutdown_action __refdata dump_action = {
1931 	.name	= SHUTDOWN_ACTION_DUMP_STR,
1932 	.fn	= dump_run,
1933 	.init	= dump_init,
1934 };
1935 
1936 static void dump_reipl_run(struct shutdown_trigger *trigger)
1937 {
1938 	unsigned long ipib = (unsigned long) reipl_block_actual;
1939 	struct lowcore *abs_lc;
1940 	unsigned int csum;
1941 
1942 	csum = (__force unsigned int)
1943 	       csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1944 	abs_lc = get_abs_lowcore();
1945 	abs_lc->ipib = ipib;
1946 	abs_lc->ipib_checksum = csum;
1947 	put_abs_lowcore(abs_lc);
1948 	dump_run(trigger);
1949 }
1950 
1951 static struct shutdown_action __refdata dump_reipl_action = {
1952 	.name	= SHUTDOWN_ACTION_DUMP_REIPL_STR,
1953 	.fn	= dump_reipl_run,
1954 };
1955 
1956 /*
1957  * vmcmd shutdown action: Trigger vm command on shutdown.
1958  */
1959 
1960 static char vmcmd_on_reboot[128];
1961 static char vmcmd_on_panic[128];
1962 static char vmcmd_on_halt[128];
1963 static char vmcmd_on_poff[128];
1964 static char vmcmd_on_restart[128];
1965 
1966 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1967 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1968 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1969 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1970 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1971 
1972 static struct attribute *vmcmd_attrs[] = {
1973 	&sys_vmcmd_on_reboot_attr.attr,
1974 	&sys_vmcmd_on_panic_attr.attr,
1975 	&sys_vmcmd_on_halt_attr.attr,
1976 	&sys_vmcmd_on_poff_attr.attr,
1977 	&sys_vmcmd_on_restart_attr.attr,
1978 	NULL,
1979 };
1980 
1981 static struct attribute_group vmcmd_attr_group = {
1982 	.attrs = vmcmd_attrs,
1983 };
1984 
1985 static struct kset *vmcmd_kset;
1986 
1987 static void vmcmd_run(struct shutdown_trigger *trigger)
1988 {
1989 	char *cmd;
1990 
1991 	if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1992 		cmd = vmcmd_on_reboot;
1993 	else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1994 		cmd = vmcmd_on_panic;
1995 	else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1996 		cmd = vmcmd_on_halt;
1997 	else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1998 		cmd = vmcmd_on_poff;
1999 	else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
2000 		cmd = vmcmd_on_restart;
2001 	else
2002 		return;
2003 
2004 	if (strlen(cmd) == 0)
2005 		return;
2006 	__cpcmd(cmd, NULL, 0, NULL);
2007 }
2008 
2009 static int vmcmd_init(void)
2010 {
2011 	if (!MACHINE_IS_VM)
2012 		return -EOPNOTSUPP;
2013 	vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
2014 	if (!vmcmd_kset)
2015 		return -ENOMEM;
2016 	return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
2017 }
2018 
2019 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
2020 					      vmcmd_run, vmcmd_init};
2021 
2022 /*
2023  * stop shutdown action: Stop Linux on shutdown.
2024  */
2025 
2026 static void stop_run(struct shutdown_trigger *trigger)
2027 {
2028 	if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
2029 	    strcmp(trigger->name, ON_RESTART_STR) == 0)
2030 		disabled_wait();
2031 	smp_stop_cpu();
2032 }
2033 
2034 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
2035 					     stop_run, NULL};
2036 
2037 /* action list */
2038 
2039 static struct shutdown_action *shutdown_actions_list[] = {
2040 	&ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
2041 	&vmcmd_action, &stop_action};
2042 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
2043 
2044 /*
2045  * Trigger section
2046  */
2047 
2048 static struct kset *shutdown_actions_kset;
2049 
2050 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
2051 		       size_t len)
2052 {
2053 	int i;
2054 
2055 	for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2056 		if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
2057 			if (shutdown_actions_list[i]->init_rc) {
2058 				return shutdown_actions_list[i]->init_rc;
2059 			} else {
2060 				trigger->action = shutdown_actions_list[i];
2061 				return len;
2062 			}
2063 		}
2064 	}
2065 	return -EINVAL;
2066 }
2067 
2068 /* on reipl */
2069 
2070 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
2071 						    &reipl_action};
2072 
2073 static ssize_t on_reboot_show(struct kobject *kobj,
2074 			      struct kobj_attribute *attr, char *page)
2075 {
2076 	return sprintf(page, "%s\n", on_reboot_trigger.action->name);
2077 }
2078 
2079 static ssize_t on_reboot_store(struct kobject *kobj,
2080 			       struct kobj_attribute *attr,
2081 			       const char *buf, size_t len)
2082 {
2083 	return set_trigger(buf, &on_reboot_trigger, len);
2084 }
2085 static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
2086 
2087 static void do_machine_restart(char *__unused)
2088 {
2089 	smp_send_stop();
2090 	on_reboot_trigger.action->fn(&on_reboot_trigger);
2091 	reipl_run(NULL);
2092 }
2093 void (*_machine_restart)(char *command) = do_machine_restart;
2094 
2095 /* on panic */
2096 
2097 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
2098 
2099 static ssize_t on_panic_show(struct kobject *kobj,
2100 			     struct kobj_attribute *attr, char *page)
2101 {
2102 	return sprintf(page, "%s\n", on_panic_trigger.action->name);
2103 }
2104 
2105 static ssize_t on_panic_store(struct kobject *kobj,
2106 			      struct kobj_attribute *attr,
2107 			      const char *buf, size_t len)
2108 {
2109 	return set_trigger(buf, &on_panic_trigger, len);
2110 }
2111 static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
2112 
2113 static void do_panic(void)
2114 {
2115 	lgr_info_log();
2116 	on_panic_trigger.action->fn(&on_panic_trigger);
2117 	stop_run(&on_panic_trigger);
2118 }
2119 
2120 /* on restart */
2121 
2122 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
2123 	&stop_action};
2124 
2125 static ssize_t on_restart_show(struct kobject *kobj,
2126 			       struct kobj_attribute *attr, char *page)
2127 {
2128 	return sprintf(page, "%s\n", on_restart_trigger.action->name);
2129 }
2130 
2131 static ssize_t on_restart_store(struct kobject *kobj,
2132 				struct kobj_attribute *attr,
2133 				const char *buf, size_t len)
2134 {
2135 	return set_trigger(buf, &on_restart_trigger, len);
2136 }
2137 static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
2138 
2139 static void __do_restart(void *ignore)
2140 {
2141 	smp_send_stop();
2142 #ifdef CONFIG_CRASH_DUMP
2143 	crash_kexec(NULL);
2144 #endif
2145 	on_restart_trigger.action->fn(&on_restart_trigger);
2146 	stop_run(&on_restart_trigger);
2147 }
2148 
2149 void do_restart(void *arg)
2150 {
2151 	tracing_off();
2152 	debug_locks_off();
2153 	lgr_info_log();
2154 	smp_call_online_cpu(__do_restart, arg);
2155 }
2156 
2157 /* on halt */
2158 
2159 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
2160 
2161 static ssize_t on_halt_show(struct kobject *kobj,
2162 			    struct kobj_attribute *attr, char *page)
2163 {
2164 	return sprintf(page, "%s\n", on_halt_trigger.action->name);
2165 }
2166 
2167 static ssize_t on_halt_store(struct kobject *kobj,
2168 			     struct kobj_attribute *attr,
2169 			     const char *buf, size_t len)
2170 {
2171 	return set_trigger(buf, &on_halt_trigger, len);
2172 }
2173 static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
2174 
2175 static void do_machine_halt(void)
2176 {
2177 	smp_send_stop();
2178 	on_halt_trigger.action->fn(&on_halt_trigger);
2179 	stop_run(&on_halt_trigger);
2180 }
2181 void (*_machine_halt)(void) = do_machine_halt;
2182 
2183 /* on power off */
2184 
2185 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
2186 
2187 static ssize_t on_poff_show(struct kobject *kobj,
2188 			    struct kobj_attribute *attr, char *page)
2189 {
2190 	return sprintf(page, "%s\n", on_poff_trigger.action->name);
2191 }
2192 
2193 static ssize_t on_poff_store(struct kobject *kobj,
2194 			     struct kobj_attribute *attr,
2195 			     const char *buf, size_t len)
2196 {
2197 	return set_trigger(buf, &on_poff_trigger, len);
2198 }
2199 static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
2200 
2201 static void do_machine_power_off(void)
2202 {
2203 	smp_send_stop();
2204 	on_poff_trigger.action->fn(&on_poff_trigger);
2205 	stop_run(&on_poff_trigger);
2206 }
2207 void (*_machine_power_off)(void) = do_machine_power_off;
2208 
2209 static struct attribute *shutdown_action_attrs[] = {
2210 	&on_restart_attr.attr,
2211 	&on_reboot_attr.attr,
2212 	&on_panic_attr.attr,
2213 	&on_halt_attr.attr,
2214 	&on_poff_attr.attr,
2215 	NULL,
2216 };
2217 
2218 static struct attribute_group shutdown_action_attr_group = {
2219 	.attrs = shutdown_action_attrs,
2220 };
2221 
2222 static void __init shutdown_triggers_init(void)
2223 {
2224 	shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
2225 						    firmware_kobj);
2226 	if (!shutdown_actions_kset)
2227 		goto fail;
2228 	if (sysfs_create_group(&shutdown_actions_kset->kobj,
2229 			       &shutdown_action_attr_group))
2230 		goto fail;
2231 	return;
2232 fail:
2233 	panic("shutdown_triggers_init failed\n");
2234 }
2235 
2236 static void __init shutdown_actions_init(void)
2237 {
2238 	int i;
2239 
2240 	for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2241 		if (!shutdown_actions_list[i]->init)
2242 			continue;
2243 		shutdown_actions_list[i]->init_rc =
2244 			shutdown_actions_list[i]->init();
2245 	}
2246 }
2247 
2248 static int __init s390_ipl_init(void)
2249 {
2250 	char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
2251 
2252 	sclp_early_get_ipl_info(&sclp_ipl_info);
2253 	/*
2254 	 * Fix loadparm: There are systems where the (SCSI) LOADPARM
2255 	 * returned by read SCP info is invalid (contains EBCDIC blanks)
2256 	 * when the system has been booted via diag308. In that case we use
2257 	 * the value from diag308, if available.
2258 	 *
2259 	 * There are also systems where diag308 store does not work in
2260 	 * case the system is booted from HMC. Fortunately in this case
2261 	 * READ SCP info provides the correct value.
2262 	 */
2263 	if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && ipl_block_valid)
2264 		memcpy(sclp_ipl_info.loadparm, ipl_block.ccw.loadparm, LOADPARM_LEN);
2265 	shutdown_actions_init();
2266 	shutdown_triggers_init();
2267 	return 0;
2268 }
2269 
2270 __initcall(s390_ipl_init);
2271 
2272 static void __init strncpy_skip_quote(char *dst, char *src, int n)
2273 {
2274 	int sx, dx;
2275 
2276 	dx = 0;
2277 	for (sx = 0; src[sx] != 0; sx++) {
2278 		if (src[sx] == '"')
2279 			continue;
2280 		dst[dx++] = src[sx];
2281 		if (dx >= n)
2282 			break;
2283 	}
2284 }
2285 
2286 static int __init vmcmd_on_reboot_setup(char *str)
2287 {
2288 	if (!MACHINE_IS_VM)
2289 		return 1;
2290 	strncpy_skip_quote(vmcmd_on_reboot, str, 127);
2291 	vmcmd_on_reboot[127] = 0;
2292 	on_reboot_trigger.action = &vmcmd_action;
2293 	return 1;
2294 }
2295 __setup("vmreboot=", vmcmd_on_reboot_setup);
2296 
2297 static int __init vmcmd_on_panic_setup(char *str)
2298 {
2299 	if (!MACHINE_IS_VM)
2300 		return 1;
2301 	strncpy_skip_quote(vmcmd_on_panic, str, 127);
2302 	vmcmd_on_panic[127] = 0;
2303 	on_panic_trigger.action = &vmcmd_action;
2304 	return 1;
2305 }
2306 __setup("vmpanic=", vmcmd_on_panic_setup);
2307 
2308 static int __init vmcmd_on_halt_setup(char *str)
2309 {
2310 	if (!MACHINE_IS_VM)
2311 		return 1;
2312 	strncpy_skip_quote(vmcmd_on_halt, str, 127);
2313 	vmcmd_on_halt[127] = 0;
2314 	on_halt_trigger.action = &vmcmd_action;
2315 	return 1;
2316 }
2317 __setup("vmhalt=", vmcmd_on_halt_setup);
2318 
2319 static int __init vmcmd_on_poff_setup(char *str)
2320 {
2321 	if (!MACHINE_IS_VM)
2322 		return 1;
2323 	strncpy_skip_quote(vmcmd_on_poff, str, 127);
2324 	vmcmd_on_poff[127] = 0;
2325 	on_poff_trigger.action = &vmcmd_action;
2326 	return 1;
2327 }
2328 __setup("vmpoff=", vmcmd_on_poff_setup);
2329 
2330 static int on_panic_notify(struct notifier_block *self,
2331 			   unsigned long event, void *data)
2332 {
2333 	do_panic();
2334 	return NOTIFY_OK;
2335 }
2336 
2337 static struct notifier_block on_panic_nb = {
2338 	.notifier_call = on_panic_notify,
2339 	.priority = INT_MIN,
2340 };
2341 
2342 void __init setup_ipl(void)
2343 {
2344 	BUILD_BUG_ON(sizeof(struct ipl_parameter_block) != PAGE_SIZE);
2345 
2346 	ipl_info.type = get_ipl_type();
2347 	switch (ipl_info.type) {
2348 	case IPL_TYPE_CCW:
2349 		ipl_info.data.ccw.dev_id.ssid = ipl_block.ccw.ssid;
2350 		ipl_info.data.ccw.dev_id.devno = ipl_block.ccw.devno;
2351 		break;
2352 	case IPL_TYPE_ECKD:
2353 	case IPL_TYPE_ECKD_DUMP:
2354 		ipl_info.data.eckd.dev_id.ssid = ipl_block.eckd.ssid;
2355 		ipl_info.data.eckd.dev_id.devno = ipl_block.eckd.devno;
2356 		break;
2357 	case IPL_TYPE_FCP:
2358 	case IPL_TYPE_FCP_DUMP:
2359 		ipl_info.data.fcp.dev_id.ssid = 0;
2360 		ipl_info.data.fcp.dev_id.devno = ipl_block.fcp.devno;
2361 		ipl_info.data.fcp.wwpn = ipl_block.fcp.wwpn;
2362 		ipl_info.data.fcp.lun = ipl_block.fcp.lun;
2363 		break;
2364 	case IPL_TYPE_NVME:
2365 	case IPL_TYPE_NVME_DUMP:
2366 		ipl_info.data.nvme.fid = ipl_block.nvme.fid;
2367 		ipl_info.data.nvme.nsid = ipl_block.nvme.nsid;
2368 		break;
2369 	case IPL_TYPE_NSS:
2370 	case IPL_TYPE_UNKNOWN:
2371 		/* We have no info to copy */
2372 		break;
2373 	}
2374 	atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
2375 }
2376 
2377 void s390_reset_system(void)
2378 {
2379 	/* Disable prefixing */
2380 	set_prefix(0);
2381 
2382 	/* Disable lowcore protection */
2383 	__ctl_clear_bit(0, 28);
2384 	diag_amode31_ops.diag308_reset();
2385 }
2386 
2387 #ifdef CONFIG_KEXEC_FILE
2388 
2389 int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
2390 			     unsigned char flags, unsigned short cert)
2391 {
2392 	struct ipl_report_component *comp;
2393 
2394 	comp = vzalloc(sizeof(*comp));
2395 	if (!comp)
2396 		return -ENOMEM;
2397 	list_add_tail(&comp->list, &report->components);
2398 
2399 	comp->entry.addr = kbuf->mem;
2400 	comp->entry.len = kbuf->memsz;
2401 	comp->entry.flags = flags;
2402 	comp->entry.certificate_index = cert;
2403 
2404 	report->size += sizeof(comp->entry);
2405 
2406 	return 0;
2407 }
2408 
2409 int ipl_report_add_certificate(struct ipl_report *report, void *key,
2410 			       unsigned long addr, unsigned long len)
2411 {
2412 	struct ipl_report_certificate *cert;
2413 
2414 	cert = vzalloc(sizeof(*cert));
2415 	if (!cert)
2416 		return -ENOMEM;
2417 	list_add_tail(&cert->list, &report->certificates);
2418 
2419 	cert->entry.addr = addr;
2420 	cert->entry.len = len;
2421 	cert->key = key;
2422 
2423 	report->size += sizeof(cert->entry);
2424 	report->size += cert->entry.len;
2425 
2426 	return 0;
2427 }
2428 
2429 struct ipl_report *ipl_report_init(struct ipl_parameter_block *ipib)
2430 {
2431 	struct ipl_report *report;
2432 
2433 	report = vzalloc(sizeof(*report));
2434 	if (!report)
2435 		return ERR_PTR(-ENOMEM);
2436 
2437 	report->ipib = ipib;
2438 	INIT_LIST_HEAD(&report->components);
2439 	INIT_LIST_HEAD(&report->certificates);
2440 
2441 	report->size = ALIGN(ipib->hdr.len, 8);
2442 	report->size += sizeof(struct ipl_rl_hdr);
2443 	report->size += sizeof(struct ipl_rb_components);
2444 	report->size += sizeof(struct ipl_rb_certificates);
2445 
2446 	return report;
2447 }
2448 
2449 void *ipl_report_finish(struct ipl_report *report)
2450 {
2451 	struct ipl_report_certificate *cert;
2452 	struct ipl_report_component *comp;
2453 	struct ipl_rb_certificates *certs;
2454 	struct ipl_parameter_block *ipib;
2455 	struct ipl_rb_components *comps;
2456 	struct ipl_rl_hdr *rl_hdr;
2457 	void *buf, *ptr;
2458 
2459 	buf = vzalloc(report->size);
2460 	if (!buf)
2461 		goto out;
2462 	ptr = buf;
2463 
2464 	memcpy(ptr, report->ipib, report->ipib->hdr.len);
2465 	ipib = ptr;
2466 	if (ipl_secure_flag)
2467 		ipib->hdr.flags |= IPL_PL_FLAG_SIPL;
2468 	ipib->hdr.flags |= IPL_PL_FLAG_IPLSR;
2469 	ptr += report->ipib->hdr.len;
2470 	ptr = PTR_ALIGN(ptr, 8);
2471 
2472 	rl_hdr = ptr;
2473 	ptr += sizeof(*rl_hdr);
2474 
2475 	comps = ptr;
2476 	comps->rbt = IPL_RBT_COMPONENTS;
2477 	ptr += sizeof(*comps);
2478 	list_for_each_entry(comp, &report->components, list) {
2479 		memcpy(ptr, &comp->entry, sizeof(comp->entry));
2480 		ptr += sizeof(comp->entry);
2481 	}
2482 	comps->len = ptr - (void *)comps;
2483 
2484 	certs = ptr;
2485 	certs->rbt = IPL_RBT_CERTIFICATES;
2486 	ptr += sizeof(*certs);
2487 	list_for_each_entry(cert, &report->certificates, list) {
2488 		memcpy(ptr, &cert->entry, sizeof(cert->entry));
2489 		ptr += sizeof(cert->entry);
2490 	}
2491 	certs->len = ptr - (void *)certs;
2492 	rl_hdr->len = ptr - (void *)rl_hdr;
2493 
2494 	list_for_each_entry(cert, &report->certificates, list) {
2495 		memcpy(ptr, cert->key, cert->entry.len);
2496 		ptr += cert->entry.len;
2497 	}
2498 
2499 	BUG_ON(ptr > buf + report->size);
2500 out:
2501 	return buf;
2502 }
2503 
2504 int ipl_report_free(struct ipl_report *report)
2505 {
2506 	struct ipl_report_component *comp, *ncomp;
2507 	struct ipl_report_certificate *cert, *ncert;
2508 
2509 	list_for_each_entry_safe(comp, ncomp, &report->components, list)
2510 		vfree(comp);
2511 
2512 	list_for_each_entry_safe(cert, ncert, &report->certificates, list)
2513 		vfree(cert);
2514 
2515 	vfree(report);
2516 
2517 	return 0;
2518 }
2519 
2520 #endif
2521