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