1 // SPDX-License-Identifier: GPL-2.0
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005, 2012
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Volker Sameske <sameske@de.ibm.com>
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>
20 #include <linux/gfp.h>
21 #include <linux/crash_dump.h>
22 #include <linux/debug_locks.h>
23 #include <asm/asm-extable.h>
27 #include <asm/setup.h>
28 #include <asm/cpcmd.h>
29 #include <asm/ebcdic.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>
39 #define IPL_PARM_BLOCK_VERSION 0
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"
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"
58 * Four shutdown trigger types are supported:
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"
71 struct shutdown_action;
72 struct shutdown_trigger {
74 struct shutdown_action *action;
78 * The following shutdown action types are supported:
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"
87 struct shutdown_action {
89 void (*fn) (struct shutdown_trigger *trigger);
94 static char *ipl_type_str(enum ipl_type type)
101 case IPL_TYPE_ECKD_DUMP:
102 return IPL_ECKD_DUMP_STR;
105 case IPL_TYPE_FCP_DUMP:
106 return IPL_FCP_DUMP_STR;
111 case IPL_TYPE_NVME_DUMP:
112 return IPL_NVME_DUMP_STR;
113 case IPL_TYPE_UNKNOWN:
115 return IPL_UNKNOWN_STR;
127 static char *dump_type_str(enum dump_type type)
131 return DUMP_NONE_STR;
135 return DUMP_ECKD_STR;
139 return DUMP_NVME_STR;
145 int __bootdata_preserved(ipl_block_valid);
146 struct ipl_parameter_block __bootdata_preserved(ipl_block);
147 int __bootdata_preserved(ipl_secure_flag);
149 unsigned long __bootdata_preserved(ipl_cert_list_addr);
150 unsigned long __bootdata_preserved(ipl_cert_list_size);
152 unsigned long __bootdata(early_ipl_comp_list_addr);
153 unsigned long __bootdata(early_ipl_comp_list_size);
155 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
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;
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;
172 static struct sclp_ipl_info sclp_ipl_info;
174 static bool reipl_nvme_clear;
175 static bool reipl_fcp_clear;
176 static bool reipl_ccw_clear;
177 static bool reipl_eckd_clear;
179 static unsigned long os_info_flags;
181 static inline int __diag308(unsigned long subcode, unsigned long addr)
183 union register_pair r1;
188 " diag %[r1],%[subcode],0x308\n"
191 : [r1] "+&d" (r1.pair)
192 : [subcode] "d" (subcode)
197 int diag308(unsigned long subcode, void *addr)
199 diag_stat_inc(DIAG_STAT_X308);
200 return __diag308(subcode, addr ? virt_to_phys(addr) : 0);
202 EXPORT_SYMBOL_GPL(diag308);
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, \
211 return scnprintf(page, PAGE_SIZE, _format, ##args); \
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) \
219 unsigned long long ssid, devno; \
221 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
224 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
227 _ipl_blk.ssid = ssid; \
228 _ipl_blk.devno = devno; \
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) \
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)
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) \
252 unsigned long long value; \
253 if (sscanf(buf, _fmt_in, &value) != 1) \
258 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
259 __ATTR(_name, 0644, \
260 sys_##_prefix##_##_name##_show, \
261 sys_##_prefix##_##_name##_store)
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) \
269 strscpy(_value, buf, sizeof(_value)); \
273 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
274 __ATTR(_name, 0644, \
275 sys_##_prefix##_##_name##_show, \
276 sys_##_prefix##_##_name##_store)
282 static __init enum ipl_type get_ipl_type(void)
284 if (!ipl_block_valid)
285 return IPL_TYPE_UNKNOWN;
287 switch (ipl_block.pb0_hdr.pbt) {
291 if (ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
292 return IPL_TYPE_FCP_DUMP;
296 if (ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
297 return IPL_TYPE_NVME_DUMP;
299 return IPL_TYPE_NVME;
301 if (ipl_block.eckd.opt == IPL_PB0_ECKD_OPT_DUMP)
302 return IPL_TYPE_ECKD_DUMP;
304 return IPL_TYPE_ECKD;
306 return IPL_TYPE_UNKNOWN;
309 struct ipl_info ipl_info;
310 EXPORT_SYMBOL_GPL(ipl_info);
312 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
315 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
318 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
320 static ssize_t ipl_secure_show(struct kobject *kobj,
321 struct kobj_attribute *attr, char *page)
323 return sprintf(page, "%i\n", !!ipl_secure_flag);
326 static struct kobj_attribute sys_ipl_secure_attr =
327 __ATTR(secure, 0444, ipl_secure_show, NULL);
329 static ssize_t ipl_has_secure_show(struct kobject *kobj,
330 struct kobj_attribute *attr, char *page)
332 return sprintf(page, "%i\n", !!sclp.has_sipl);
335 static struct kobj_attribute sys_ipl_has_secure_attr =
336 __ATTR(has_secure, 0444, ipl_has_secure_show, NULL);
338 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
339 struct kobj_attribute *attr, char *page)
341 char parm[DIAG308_VMPARM_SIZE + 1] = {};
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);
348 static struct kobj_attribute sys_ipl_vm_parm_attr =
349 __ATTR(parm, 0444, ipl_vm_parm_show, NULL);
351 static ssize_t sys_ipl_device_show(struct kobject *kobj,
352 struct kobj_attribute *attr, char *page)
354 switch (ipl_info.type) {
356 return sprintf(page, "0.%x.%04x\n", ipl_block.ccw.ssid,
357 ipl_block.ccw.devno);
359 case IPL_TYPE_ECKD_DUMP:
360 return sprintf(page, "0.%x.%04x\n", ipl_block.eckd.ssid,
361 ipl_block.eckd.devno);
363 case IPL_TYPE_FCP_DUMP:
364 return sprintf(page, "0.0.%04x\n", ipl_block.fcp.devno);
366 case IPL_TYPE_NVME_DUMP:
367 return sprintf(page, "%08ux\n", ipl_block.nvme.fid);
373 static struct kobj_attribute sys_ipl_device_attr =
374 __ATTR(device, 0444, sys_ipl_device_show, NULL);
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)
380 return memory_read_from_buffer(buf, count, &off, &ipl_block,
383 static struct bin_attribute ipl_parameter_attr =
384 __BIN_ATTR(binary_parameter, 0444, ipl_parameter_read, NULL,
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)
391 unsigned int size = ipl_block.fcp.scp_data_len;
392 void *scp_data = &ipl_block.fcp.scp_data;
394 return memory_read_from_buffer(buf, count, &off, scp_data, size);
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)
401 unsigned int size = ipl_block.nvme.scp_data_len;
402 void *scp_data = &ipl_block.nvme.scp_data;
404 return memory_read_from_buffer(buf, count, &off, scp_data, size);
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)
411 unsigned int size = ipl_block.eckd.scp_data_len;
412 void *scp_data = &ipl_block.eckd.scp_data;
414 return memory_read_from_buffer(buf, count, &off, scp_data, size);
417 static struct bin_attribute ipl_scp_data_attr =
418 __BIN_ATTR(scp_data, 0444, ipl_scp_data_read, NULL, PAGE_SIZE);
420 static struct bin_attribute ipl_nvme_scp_data_attr =
421 __BIN_ATTR(scp_data, 0444, ipl_nvme_scp_data_read, NULL, PAGE_SIZE);
423 static struct bin_attribute ipl_eckd_scp_data_attr =
424 __BIN_ATTR(scp_data, 0444, ipl_eckd_scp_data_read, NULL, PAGE_SIZE);
426 static struct bin_attribute *ipl_fcp_bin_attrs[] = {
432 static struct bin_attribute *ipl_nvme_bin_attrs[] = {
434 &ipl_nvme_scp_data_attr,
438 static struct bin_attribute *ipl_eckd_bin_attrs[] = {
440 &ipl_eckd_scp_data_attr,
444 /* FCP ipl device attributes */
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);
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);
465 /* ECKD ipl device attributes */
466 DEFINE_IPL_ATTR_RO(ipl_eckd, bootprog, "%lld\n",
467 (unsigned long long)ipl_block.eckd.bootprog);
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, \
474 struct ipl_pb0_eckd *ipb = &(_ipb); \
476 if (!ipb->br_chr.cyl && \
477 !ipb->br_chr.head && \
478 !ipb->br_chr.record) \
479 return sprintf(buf, "auto\n"); \
481 return sprintf(buf, "0x%x,0x%x,0x%x\n", \
484 ipb->br_chr.record); \
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) \
492 struct ipl_pb0_eckd *ipb = &(_ipb); \
493 unsigned long args[3] = { 0 }; \
494 char *p, *p1, *tmp = NULL; \
497 if (!strncmp(buf, "auto", 4)) \
500 tmp = kstrdup(buf, GFP_KERNEL); \
502 for (i = 0; i < 3; i++) { \
503 p1 = strsep(&p, ", "); \
508 rc = kstrtoul(p1, 0, args + i); \
517 if ((args[0] || args[1]) && !args[2]) \
520 if (args[0] > UINT_MAX || args[1] > 255 || args[2] > 255) \
524 ipb->br_chr.cyl = args[0]; \
525 ipb->br_chr.head = args[1]; \
526 ipb->br_chr.record = args[2]; \
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);
537 IPL_ATTR_BR_CHR_SHOW_FN(reipl, reipl_block_eckd->eckd);
538 IPL_ATTR_BR_CHR_STORE_FN(reipl, reipl_block_eckd->eckd);
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);
543 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
544 struct kobj_attribute *attr, char *page)
546 char loadparm[LOADPARM_LEN + 1] = {};
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);
553 return sprintf(page, "%s\n", loadparm);
556 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
557 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
559 static struct attribute *ipl_fcp_attrs[] = {
560 &sys_ipl_device_attr.attr,
561 &sys_ipl_fcp_wwpn_attr.attr,
562 &sys_ipl_fcp_lun_attr.attr,
563 &sys_ipl_fcp_bootprog_attr.attr,
564 &sys_ipl_fcp_br_lba_attr.attr,
565 &sys_ipl_ccw_loadparm_attr.attr,
569 static struct attribute_group ipl_fcp_attr_group = {
570 .attrs = ipl_fcp_attrs,
571 .bin_attrs = ipl_fcp_bin_attrs,
574 static struct attribute *ipl_nvme_attrs[] = {
575 &sys_ipl_nvme_fid_attr.attr,
576 &sys_ipl_nvme_nsid_attr.attr,
577 &sys_ipl_nvme_bootprog_attr.attr,
578 &sys_ipl_nvme_br_lba_attr.attr,
579 &sys_ipl_ccw_loadparm_attr.attr,
583 static struct attribute_group ipl_nvme_attr_group = {
584 .attrs = ipl_nvme_attrs,
585 .bin_attrs = ipl_nvme_bin_attrs,
588 static struct attribute *ipl_eckd_attrs[] = {
589 &sys_ipl_eckd_bootprog_attr.attr,
590 &sys_ipl_eckd_br_chr_attr.attr,
591 &sys_ipl_ccw_loadparm_attr.attr,
592 &sys_ipl_device_attr.attr,
596 static struct attribute_group ipl_eckd_attr_group = {
597 .attrs = ipl_eckd_attrs,
598 .bin_attrs = ipl_eckd_bin_attrs,
601 /* CCW ipl device attributes */
603 static struct attribute *ipl_ccw_attrs_vm[] = {
604 &sys_ipl_device_attr.attr,
605 &sys_ipl_ccw_loadparm_attr.attr,
606 &sys_ipl_vm_parm_attr.attr,
610 static struct attribute *ipl_ccw_attrs_lpar[] = {
611 &sys_ipl_device_attr.attr,
612 &sys_ipl_ccw_loadparm_attr.attr,
616 static struct attribute_group ipl_ccw_attr_group_vm = {
617 .attrs = ipl_ccw_attrs_vm,
620 static struct attribute_group ipl_ccw_attr_group_lpar = {
621 .attrs = ipl_ccw_attrs_lpar
624 static struct attribute *ipl_common_attrs[] = {
625 &sys_ipl_type_attr.attr,
626 &sys_ipl_secure_attr.attr,
627 &sys_ipl_has_secure_attr.attr,
631 static struct attribute_group ipl_common_attr_group = {
632 .attrs = ipl_common_attrs,
635 static struct kset *ipl_kset;
637 static void __ipl_run(void *unused)
639 diag308(DIAG308_LOAD_CLEAR, NULL);
642 static void ipl_run(struct shutdown_trigger *trigger)
644 smp_call_ipl_cpu(__ipl_run, NULL);
647 static int __init ipl_init(void)
651 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
656 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_common_attr_group);
659 switch (ipl_info.type) {
662 rc = sysfs_create_group(&ipl_kset->kobj,
663 &ipl_ccw_attr_group_vm);
665 rc = sysfs_create_group(&ipl_kset->kobj,
666 &ipl_ccw_attr_group_lpar);
669 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_eckd_attr_group);
672 case IPL_TYPE_FCP_DUMP:
673 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
676 case IPL_TYPE_NVME_DUMP:
677 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nvme_attr_group);
684 panic("ipl_init failed: rc = %i\n", rc);
689 static struct shutdown_action __refdata ipl_action = {
690 .name = SHUTDOWN_ACTION_IPL_STR,
696 * reipl shutdown action: Reboot Linux on shutdown.
699 /* VM IPL PARM attributes */
700 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
703 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
705 ipl_block_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
706 return sprintf(page, "%s\n", vmparm);
709 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
711 const char *buf, size_t len)
715 /* ignore trailing newline */
717 if ((len > 0) && (buf[len - 1] == '\n'))
720 if (ip_len > vmparm_max)
723 /* parm is used to store kernel options, check for common chars */
724 for (i = 0; i < ip_len; i++)
725 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
728 memset(ipb->ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
729 ipb->ccw.vm_parm_len = ip_len;
731 ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
732 memcpy(ipb->ccw.vm_parm, buf, ip_len);
733 ASCEBC(ipb->ccw.vm_parm, ip_len);
735 ipb->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_VP;
742 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
743 struct kobj_attribute *attr, char *page)
745 return reipl_generic_vmparm_show(reipl_block_nss, page);
748 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
749 struct kobj_attribute *attr,
750 const char *buf, size_t len)
752 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
756 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
757 struct kobj_attribute *attr, char *page)
759 return reipl_generic_vmparm_show(reipl_block_ccw, page);
762 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
763 struct kobj_attribute *attr,
764 const char *buf, size_t len)
766 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
769 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
770 __ATTR(parm, 0644, reipl_nss_vmparm_show,
771 reipl_nss_vmparm_store);
772 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
773 __ATTR(parm, 0644, reipl_ccw_vmparm_show,
774 reipl_ccw_vmparm_store);
776 /* FCP reipl device attributes */
778 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
779 struct bin_attribute *attr,
780 char *buf, loff_t off, size_t count)
782 size_t size = reipl_block_fcp->fcp.scp_data_len;
783 void *scp_data = reipl_block_fcp->fcp.scp_data;
785 return memory_read_from_buffer(buf, count, &off, scp_data, size);
788 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
789 struct bin_attribute *attr,
790 char *buf, loff_t off, size_t count)
792 size_t scpdata_len = count;
799 memcpy(reipl_block_fcp->fcp.scp_data, buf, count);
800 if (scpdata_len % 8) {
801 padding = 8 - (scpdata_len % 8);
802 memset(reipl_block_fcp->fcp.scp_data + scpdata_len,
804 scpdata_len += padding;
807 reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
808 reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN + scpdata_len;
809 reipl_block_fcp->fcp.scp_data_len = scpdata_len;
813 static struct bin_attribute sys_reipl_fcp_scp_data_attr =
814 __BIN_ATTR(scp_data, 0644, reipl_fcp_scpdata_read,
815 reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
817 static struct bin_attribute *reipl_fcp_bin_attrs[] = {
818 &sys_reipl_fcp_scp_data_attr,
822 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
823 reipl_block_fcp->fcp.wwpn);
824 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
825 reipl_block_fcp->fcp.lun);
826 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
827 reipl_block_fcp->fcp.bootprog);
828 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
829 reipl_block_fcp->fcp.br_lba);
830 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
831 reipl_block_fcp->fcp.devno);
833 static void reipl_get_ascii_loadparm(char *loadparm,
834 struct ipl_parameter_block *ibp)
836 memcpy(loadparm, ibp->common.loadparm, LOADPARM_LEN);
837 EBCASC(loadparm, LOADPARM_LEN);
838 loadparm[LOADPARM_LEN] = 0;
842 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
845 char buf[LOADPARM_LEN + 1];
847 reipl_get_ascii_loadparm(buf, ipb);
848 return sprintf(page, "%s\n", buf);
851 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
852 const char *buf, size_t len)
856 /* ignore trailing newline */
858 if ((len > 0) && (buf[len - 1] == '\n'))
860 /* loadparm can have max 8 characters and must not start with a blank */
861 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
863 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
864 for (i = 0; i < lp_len; i++) {
865 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
870 /* initialize loadparm with blanks */
871 memset(ipb->common.loadparm, ' ', LOADPARM_LEN);
872 /* copy and convert to ebcdic */
873 memcpy(ipb->common.loadparm, buf, lp_len);
874 ASCEBC(ipb->common.loadparm, LOADPARM_LEN);
875 ipb->common.flags |= IPL_PB0_FLAG_LOADPARM;
879 #define DEFINE_GENERIC_LOADPARM(name) \
880 static ssize_t reipl_##name##_loadparm_show(struct kobject *kobj, \
881 struct kobj_attribute *attr, char *page) \
883 return reipl_generic_loadparm_show(reipl_block_##name, page); \
885 static ssize_t reipl_##name##_loadparm_store(struct kobject *kobj, \
886 struct kobj_attribute *attr, \
887 const char *buf, size_t len) \
889 return reipl_generic_loadparm_store(reipl_block_##name, buf, len); \
891 static struct kobj_attribute sys_reipl_##name##_loadparm_attr = \
892 __ATTR(loadparm, 0644, reipl_##name##_loadparm_show, \
893 reipl_##name##_loadparm_store)
895 DEFINE_GENERIC_LOADPARM(fcp);
896 DEFINE_GENERIC_LOADPARM(nvme);
897 DEFINE_GENERIC_LOADPARM(ccw);
898 DEFINE_GENERIC_LOADPARM(nss);
899 DEFINE_GENERIC_LOADPARM(eckd);
901 static ssize_t reipl_fcp_clear_show(struct kobject *kobj,
902 struct kobj_attribute *attr, char *page)
904 return sprintf(page, "%u\n", reipl_fcp_clear);
907 static ssize_t reipl_fcp_clear_store(struct kobject *kobj,
908 struct kobj_attribute *attr,
909 const char *buf, size_t len)
911 if (kstrtobool(buf, &reipl_fcp_clear) < 0)
916 static struct attribute *reipl_fcp_attrs[] = {
917 &sys_reipl_fcp_device_attr.attr,
918 &sys_reipl_fcp_wwpn_attr.attr,
919 &sys_reipl_fcp_lun_attr.attr,
920 &sys_reipl_fcp_bootprog_attr.attr,
921 &sys_reipl_fcp_br_lba_attr.attr,
922 &sys_reipl_fcp_loadparm_attr.attr,
926 static struct attribute_group reipl_fcp_attr_group = {
927 .attrs = reipl_fcp_attrs,
928 .bin_attrs = reipl_fcp_bin_attrs,
931 static struct kobj_attribute sys_reipl_fcp_clear_attr =
932 __ATTR(clear, 0644, reipl_fcp_clear_show, reipl_fcp_clear_store);
934 /* NVME reipl device attributes */
936 static ssize_t reipl_nvme_scpdata_read(struct file *filp, struct kobject *kobj,
937 struct bin_attribute *attr,
938 char *buf, loff_t off, size_t count)
940 size_t size = reipl_block_nvme->nvme.scp_data_len;
941 void *scp_data = reipl_block_nvme->nvme.scp_data;
943 return memory_read_from_buffer(buf, count, &off, scp_data, size);
946 static ssize_t reipl_nvme_scpdata_write(struct file *filp, struct kobject *kobj,
947 struct bin_attribute *attr,
948 char *buf, loff_t off, size_t count)
950 size_t scpdata_len = count;
956 memcpy(reipl_block_nvme->nvme.scp_data, buf, count);
957 if (scpdata_len % 8) {
958 padding = 8 - (scpdata_len % 8);
959 memset(reipl_block_nvme->nvme.scp_data + scpdata_len,
961 scpdata_len += padding;
964 reipl_block_nvme->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
965 reipl_block_nvme->nvme.len = IPL_BP0_FCP_LEN + scpdata_len;
966 reipl_block_nvme->nvme.scp_data_len = scpdata_len;
971 static struct bin_attribute sys_reipl_nvme_scp_data_attr =
972 __BIN_ATTR(scp_data, 0644, reipl_nvme_scpdata_read,
973 reipl_nvme_scpdata_write, DIAG308_SCPDATA_SIZE);
975 static struct bin_attribute *reipl_nvme_bin_attrs[] = {
976 &sys_reipl_nvme_scp_data_attr,
980 DEFINE_IPL_ATTR_RW(reipl_nvme, fid, "0x%08llx\n", "%llx\n",
981 reipl_block_nvme->nvme.fid);
982 DEFINE_IPL_ATTR_RW(reipl_nvme, nsid, "0x%08llx\n", "%llx\n",
983 reipl_block_nvme->nvme.nsid);
984 DEFINE_IPL_ATTR_RW(reipl_nvme, bootprog, "%lld\n", "%lld\n",
985 reipl_block_nvme->nvme.bootprog);
986 DEFINE_IPL_ATTR_RW(reipl_nvme, br_lba, "%lld\n", "%lld\n",
987 reipl_block_nvme->nvme.br_lba);
989 static struct attribute *reipl_nvme_attrs[] = {
990 &sys_reipl_nvme_fid_attr.attr,
991 &sys_reipl_nvme_nsid_attr.attr,
992 &sys_reipl_nvme_bootprog_attr.attr,
993 &sys_reipl_nvme_br_lba_attr.attr,
994 &sys_reipl_nvme_loadparm_attr.attr,
998 static struct attribute_group reipl_nvme_attr_group = {
999 .attrs = reipl_nvme_attrs,
1000 .bin_attrs = reipl_nvme_bin_attrs
1003 static ssize_t reipl_nvme_clear_show(struct kobject *kobj,
1004 struct kobj_attribute *attr, char *page)
1006 return sprintf(page, "%u\n", reipl_nvme_clear);
1009 static ssize_t reipl_nvme_clear_store(struct kobject *kobj,
1010 struct kobj_attribute *attr,
1011 const char *buf, size_t len)
1013 if (kstrtobool(buf, &reipl_nvme_clear) < 0)
1018 static struct kobj_attribute sys_reipl_nvme_clear_attr =
1019 __ATTR(clear, 0644, reipl_nvme_clear_show, reipl_nvme_clear_store);
1021 /* CCW reipl device attributes */
1022 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ccw);
1024 static ssize_t reipl_ccw_clear_show(struct kobject *kobj,
1025 struct kobj_attribute *attr, char *page)
1027 return sprintf(page, "%u\n", reipl_ccw_clear);
1030 static ssize_t reipl_ccw_clear_store(struct kobject *kobj,
1031 struct kobj_attribute *attr,
1032 const char *buf, size_t len)
1034 if (kstrtobool(buf, &reipl_ccw_clear) < 0)
1039 static struct kobj_attribute sys_reipl_ccw_clear_attr =
1040 __ATTR(clear, 0644, reipl_ccw_clear_show, reipl_ccw_clear_store);
1042 static struct attribute *reipl_ccw_attrs_vm[] = {
1043 &sys_reipl_ccw_device_attr.attr,
1044 &sys_reipl_ccw_loadparm_attr.attr,
1045 &sys_reipl_ccw_vmparm_attr.attr,
1046 &sys_reipl_ccw_clear_attr.attr,
1050 static struct attribute *reipl_ccw_attrs_lpar[] = {
1051 &sys_reipl_ccw_device_attr.attr,
1052 &sys_reipl_ccw_loadparm_attr.attr,
1053 &sys_reipl_ccw_clear_attr.attr,
1057 static struct attribute_group reipl_ccw_attr_group_vm = {
1058 .name = IPL_CCW_STR,
1059 .attrs = reipl_ccw_attrs_vm,
1062 static struct attribute_group reipl_ccw_attr_group_lpar = {
1063 .name = IPL_CCW_STR,
1064 .attrs = reipl_ccw_attrs_lpar,
1067 /* ECKD reipl device attributes */
1069 static ssize_t reipl_eckd_scpdata_read(struct file *filp, struct kobject *kobj,
1070 struct bin_attribute *attr,
1071 char *buf, loff_t off, size_t count)
1073 size_t size = reipl_block_eckd->eckd.scp_data_len;
1074 void *scp_data = reipl_block_eckd->eckd.scp_data;
1076 return memory_read_from_buffer(buf, count, &off, scp_data, size);
1079 static ssize_t reipl_eckd_scpdata_write(struct file *filp, struct kobject *kobj,
1080 struct bin_attribute *attr,
1081 char *buf, loff_t off, size_t count)
1083 size_t scpdata_len = count;
1089 memcpy(reipl_block_eckd->eckd.scp_data, buf, count);
1090 if (scpdata_len % 8) {
1091 padding = 8 - (scpdata_len % 8);
1092 memset(reipl_block_eckd->eckd.scp_data + scpdata_len,
1094 scpdata_len += padding;
1097 reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN + scpdata_len;
1098 reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN + scpdata_len;
1099 reipl_block_eckd->eckd.scp_data_len = scpdata_len;
1104 static struct bin_attribute sys_reipl_eckd_scp_data_attr =
1105 __BIN_ATTR(scp_data, 0644, reipl_eckd_scpdata_read,
1106 reipl_eckd_scpdata_write, DIAG308_SCPDATA_SIZE);
1108 static struct bin_attribute *reipl_eckd_bin_attrs[] = {
1109 &sys_reipl_eckd_scp_data_attr,
1113 DEFINE_IPL_CCW_ATTR_RW(reipl_eckd, device, reipl_block_eckd->eckd);
1114 DEFINE_IPL_ATTR_RW(reipl_eckd, bootprog, "%lld\n", "%lld\n",
1115 reipl_block_eckd->eckd.bootprog);
1117 static struct attribute *reipl_eckd_attrs[] = {
1118 &sys_reipl_eckd_device_attr.attr,
1119 &sys_reipl_eckd_bootprog_attr.attr,
1120 &sys_reipl_eckd_br_chr_attr.attr,
1121 &sys_reipl_eckd_loadparm_attr.attr,
1125 static struct attribute_group reipl_eckd_attr_group = {
1126 .attrs = reipl_eckd_attrs,
1127 .bin_attrs = reipl_eckd_bin_attrs
1130 static ssize_t reipl_eckd_clear_show(struct kobject *kobj,
1131 struct kobj_attribute *attr, char *page)
1133 return sprintf(page, "%u\n", reipl_eckd_clear);
1136 static ssize_t reipl_eckd_clear_store(struct kobject *kobj,
1137 struct kobj_attribute *attr,
1138 const char *buf, size_t len)
1140 if (kstrtobool(buf, &reipl_eckd_clear) < 0)
1145 static struct kobj_attribute sys_reipl_eckd_clear_attr =
1146 __ATTR(clear, 0644, reipl_eckd_clear_show, reipl_eckd_clear_store);
1148 /* NSS reipl device attributes */
1149 static void reipl_get_ascii_nss_name(char *dst,
1150 struct ipl_parameter_block *ipb)
1152 memcpy(dst, ipb->ccw.nss_name, NSS_NAME_SIZE);
1153 EBCASC(dst, NSS_NAME_SIZE);
1154 dst[NSS_NAME_SIZE] = 0;
1157 static ssize_t reipl_nss_name_show(struct kobject *kobj,
1158 struct kobj_attribute *attr, char *page)
1160 char nss_name[NSS_NAME_SIZE + 1] = {};
1162 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
1163 return sprintf(page, "%s\n", nss_name);
1166 static ssize_t reipl_nss_name_store(struct kobject *kobj,
1167 struct kobj_attribute *attr,
1168 const char *buf, size_t len)
1172 /* ignore trailing newline */
1174 if ((len > 0) && (buf[len - 1] == '\n'))
1177 if (nss_len > NSS_NAME_SIZE)
1180 memset(reipl_block_nss->ccw.nss_name, 0x40, NSS_NAME_SIZE);
1182 reipl_block_nss->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_NSS;
1183 memcpy(reipl_block_nss->ccw.nss_name, buf, nss_len);
1184 ASCEBC(reipl_block_nss->ccw.nss_name, nss_len);
1185 EBC_TOUPPER(reipl_block_nss->ccw.nss_name, nss_len);
1187 reipl_block_nss->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_NSS;
1193 static struct kobj_attribute sys_reipl_nss_name_attr =
1194 __ATTR(name, 0644, reipl_nss_name_show,
1195 reipl_nss_name_store);
1197 static struct attribute *reipl_nss_attrs[] = {
1198 &sys_reipl_nss_name_attr.attr,
1199 &sys_reipl_nss_loadparm_attr.attr,
1200 &sys_reipl_nss_vmparm_attr.attr,
1204 static struct attribute_group reipl_nss_attr_group = {
1205 .name = IPL_NSS_STR,
1206 .attrs = reipl_nss_attrs,
1209 void set_os_info_reipl_block(void)
1211 os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
1212 reipl_block_actual->hdr.len);
1217 static int reipl_set_type(enum ipl_type type)
1219 if (!(reipl_capabilities & type))
1224 reipl_block_actual = reipl_block_ccw;
1227 reipl_block_actual = reipl_block_eckd;
1230 reipl_block_actual = reipl_block_fcp;
1233 reipl_block_actual = reipl_block_nvme;
1236 reipl_block_actual = reipl_block_nss;
1245 static ssize_t reipl_type_show(struct kobject *kobj,
1246 struct kobj_attribute *attr, char *page)
1248 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1251 static ssize_t reipl_type_store(struct kobject *kobj,
1252 struct kobj_attribute *attr,
1253 const char *buf, size_t len)
1257 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1258 rc = reipl_set_type(IPL_TYPE_CCW);
1259 else if (strncmp(buf, IPL_ECKD_STR, strlen(IPL_ECKD_STR)) == 0)
1260 rc = reipl_set_type(IPL_TYPE_ECKD);
1261 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1262 rc = reipl_set_type(IPL_TYPE_FCP);
1263 else if (strncmp(buf, IPL_NVME_STR, strlen(IPL_NVME_STR)) == 0)
1264 rc = reipl_set_type(IPL_TYPE_NVME);
1265 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1266 rc = reipl_set_type(IPL_TYPE_NSS);
1267 return (rc != 0) ? rc : len;
1270 static struct kobj_attribute reipl_type_attr =
1271 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1273 static struct kset *reipl_kset;
1274 static struct kset *reipl_fcp_kset;
1275 static struct kset *reipl_nvme_kset;
1276 static struct kset *reipl_eckd_kset;
1278 static void __reipl_run(void *unused)
1280 switch (reipl_type) {
1282 diag308(DIAG308_SET, reipl_block_ccw);
1283 if (reipl_ccw_clear)
1284 diag308(DIAG308_LOAD_CLEAR, NULL);
1286 diag308(DIAG308_LOAD_NORMAL_DUMP, NULL);
1289 diag308(DIAG308_SET, reipl_block_eckd);
1290 if (reipl_eckd_clear)
1291 diag308(DIAG308_LOAD_CLEAR, NULL);
1293 diag308(DIAG308_LOAD_NORMAL, NULL);
1296 diag308(DIAG308_SET, reipl_block_fcp);
1297 if (reipl_fcp_clear)
1298 diag308(DIAG308_LOAD_CLEAR, NULL);
1300 diag308(DIAG308_LOAD_NORMAL, NULL);
1303 diag308(DIAG308_SET, reipl_block_nvme);
1304 if (reipl_nvme_clear)
1305 diag308(DIAG308_LOAD_CLEAR, NULL);
1307 diag308(DIAG308_LOAD_NORMAL, NULL);
1310 diag308(DIAG308_SET, reipl_block_nss);
1311 diag308(DIAG308_LOAD_CLEAR, NULL);
1313 case IPL_TYPE_UNKNOWN:
1314 diag308(DIAG308_LOAD_CLEAR, NULL);
1316 case IPL_TYPE_FCP_DUMP:
1317 case IPL_TYPE_NVME_DUMP:
1318 case IPL_TYPE_ECKD_DUMP:
1324 static void reipl_run(struct shutdown_trigger *trigger)
1326 smp_call_ipl_cpu(__reipl_run, NULL);
1329 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1331 ipb->hdr.len = IPL_BP_CCW_LEN;
1332 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1333 ipb->pb0_hdr.len = IPL_BP0_CCW_LEN;
1334 ipb->pb0_hdr.pbt = IPL_PBT_CCW;
1337 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1340 /* check if read scp info worked and set loadparm */
1341 if (sclp_ipl_info.is_valid)
1342 memcpy(ipb->ccw.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
1344 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1345 memset(ipb->ccw.loadparm, 0x40, LOADPARM_LEN);
1346 ipb->ccw.flags = IPL_PB0_FLAG_LOADPARM;
1349 if (MACHINE_IS_VM && ipl_block_valid &&
1350 (ipl_block.ccw.vm_flags & IPL_PB0_CCW_VM_FLAG_VP)) {
1352 ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
1353 ipb->ccw.vm_parm_len = ipl_block.ccw.vm_parm_len;
1354 memcpy(ipb->ccw.vm_parm,
1355 ipl_block.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1359 static int __init reipl_nss_init(void)
1366 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1367 if (!reipl_block_nss)
1370 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1374 reipl_block_ccw_init(reipl_block_nss);
1375 reipl_capabilities |= IPL_TYPE_NSS;
1379 static int __init reipl_ccw_init(void)
1383 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1384 if (!reipl_block_ccw)
1387 rc = sysfs_create_group(&reipl_kset->kobj,
1388 MACHINE_IS_VM ? &reipl_ccw_attr_group_vm
1389 : &reipl_ccw_attr_group_lpar);
1393 reipl_block_ccw_init(reipl_block_ccw);
1394 if (ipl_info.type == IPL_TYPE_CCW) {
1395 reipl_block_ccw->ccw.ssid = ipl_block.ccw.ssid;
1396 reipl_block_ccw->ccw.devno = ipl_block.ccw.devno;
1397 reipl_block_ccw_fill_parms(reipl_block_ccw);
1400 reipl_capabilities |= IPL_TYPE_CCW;
1404 static int __init reipl_fcp_init(void)
1408 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1409 if (!reipl_block_fcp)
1412 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1413 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1415 if (!reipl_fcp_kset) {
1416 free_page((unsigned long) reipl_block_fcp);
1420 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1424 if (test_facility(141)) {
1425 rc = sysfs_create_file(&reipl_fcp_kset->kobj,
1426 &sys_reipl_fcp_clear_attr.attr);
1430 reipl_fcp_clear = true;
1433 if (ipl_info.type == IPL_TYPE_FCP) {
1434 memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block));
1436 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1437 * is invalid in the SCSI IPL parameter block, so take it
1438 * always from sclp_ipl_info.
1440 memcpy(reipl_block_fcp->fcp.loadparm, sclp_ipl_info.loadparm,
1443 reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1444 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1445 reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1446 reipl_block_fcp->fcp.pbt = IPL_PBT_FCP;
1447 reipl_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_IPL;
1449 reipl_capabilities |= IPL_TYPE_FCP;
1453 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1455 kset_unregister(reipl_fcp_kset);
1456 free_page((unsigned long) reipl_block_fcp);
1460 static int __init reipl_nvme_init(void)
1464 reipl_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1465 if (!reipl_block_nvme)
1468 /* sysfs: create kset for mixing attr group and bin attrs */
1469 reipl_nvme_kset = kset_create_and_add(IPL_NVME_STR, NULL,
1471 if (!reipl_nvme_kset) {
1472 free_page((unsigned long) reipl_block_nvme);
1476 rc = sysfs_create_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1480 if (test_facility(141)) {
1481 rc = sysfs_create_file(&reipl_nvme_kset->kobj,
1482 &sys_reipl_nvme_clear_attr.attr);
1486 reipl_nvme_clear = true;
1489 if (ipl_info.type == IPL_TYPE_NVME) {
1490 memcpy(reipl_block_nvme, &ipl_block, sizeof(ipl_block));
1492 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1493 * is invalid in the IPL parameter block, so take it
1494 * always from sclp_ipl_info.
1496 memcpy(reipl_block_nvme->nvme.loadparm, sclp_ipl_info.loadparm,
1499 reipl_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1500 reipl_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1501 reipl_block_nvme->nvme.len = IPL_BP0_NVME_LEN;
1502 reipl_block_nvme->nvme.pbt = IPL_PBT_NVME;
1503 reipl_block_nvme->nvme.opt = IPL_PB0_NVME_OPT_IPL;
1505 reipl_capabilities |= IPL_TYPE_NVME;
1509 sysfs_remove_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1511 kset_unregister(reipl_nvme_kset);
1512 free_page((unsigned long) reipl_block_nvme);
1516 static int __init reipl_eckd_init(void)
1520 if (!sclp.has_sipl_eckd)
1523 reipl_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1524 if (!reipl_block_eckd)
1527 /* sysfs: create kset for mixing attr group and bin attrs */
1528 reipl_eckd_kset = kset_create_and_add(IPL_ECKD_STR, NULL,
1530 if (!reipl_eckd_kset) {
1531 free_page((unsigned long)reipl_block_eckd);
1535 rc = sysfs_create_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1539 if (test_facility(141)) {
1540 rc = sysfs_create_file(&reipl_eckd_kset->kobj,
1541 &sys_reipl_eckd_clear_attr.attr);
1545 reipl_eckd_clear = true;
1548 if (ipl_info.type == IPL_TYPE_ECKD) {
1549 memcpy(reipl_block_eckd, &ipl_block, sizeof(ipl_block));
1551 reipl_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1552 reipl_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1553 reipl_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1554 reipl_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1555 reipl_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_IPL;
1557 reipl_capabilities |= IPL_TYPE_ECKD;
1561 sysfs_remove_group(&reipl_eckd_kset->kobj, &reipl_eckd_attr_group);
1563 kset_unregister(reipl_eckd_kset);
1564 free_page((unsigned long)reipl_block_eckd);
1568 static int __init reipl_type_init(void)
1570 enum ipl_type reipl_type = ipl_info.type;
1571 struct ipl_parameter_block *reipl_block;
1574 reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1578 * If we have an OS info reipl block, this will be used
1580 if (reipl_block->pb0_hdr.pbt == IPL_PBT_FCP) {
1581 memcpy(reipl_block_fcp, reipl_block, size);
1582 reipl_type = IPL_TYPE_FCP;
1583 } else if (reipl_block->pb0_hdr.pbt == IPL_PBT_NVME) {
1584 memcpy(reipl_block_nvme, reipl_block, size);
1585 reipl_type = IPL_TYPE_NVME;
1586 } else if (reipl_block->pb0_hdr.pbt == IPL_PBT_CCW) {
1587 memcpy(reipl_block_ccw, reipl_block, size);
1588 reipl_type = IPL_TYPE_CCW;
1589 } else if (reipl_block->pb0_hdr.pbt == IPL_PBT_ECKD) {
1590 memcpy(reipl_block_eckd, reipl_block, size);
1591 reipl_type = IPL_TYPE_ECKD;
1594 return reipl_set_type(reipl_type);
1597 static int __init reipl_init(void)
1601 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1604 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1606 kset_unregister(reipl_kset);
1609 rc = reipl_ccw_init();
1612 rc = reipl_eckd_init();
1615 rc = reipl_fcp_init();
1618 rc = reipl_nvme_init();
1621 rc = reipl_nss_init();
1624 return reipl_type_init();
1627 static struct shutdown_action __refdata reipl_action = {
1628 .name = SHUTDOWN_ACTION_REIPL_STR,
1634 * dump shutdown action: Dump Linux on shutdown.
1637 /* FCP dump device attributes */
1639 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
1640 dump_block_fcp->fcp.wwpn);
1641 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
1642 dump_block_fcp->fcp.lun);
1643 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1644 dump_block_fcp->fcp.bootprog);
1645 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1646 dump_block_fcp->fcp.br_lba);
1647 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1648 dump_block_fcp->fcp.devno);
1650 static struct attribute *dump_fcp_attrs[] = {
1651 &sys_dump_fcp_device_attr.attr,
1652 &sys_dump_fcp_wwpn_attr.attr,
1653 &sys_dump_fcp_lun_attr.attr,
1654 &sys_dump_fcp_bootprog_attr.attr,
1655 &sys_dump_fcp_br_lba_attr.attr,
1659 static struct attribute_group dump_fcp_attr_group = {
1660 .name = IPL_FCP_STR,
1661 .attrs = dump_fcp_attrs,
1664 /* NVME dump device attributes */
1665 DEFINE_IPL_ATTR_RW(dump_nvme, fid, "0x%08llx\n", "%llx\n",
1666 dump_block_nvme->nvme.fid);
1667 DEFINE_IPL_ATTR_RW(dump_nvme, nsid, "0x%08llx\n", "%llx\n",
1668 dump_block_nvme->nvme.nsid);
1669 DEFINE_IPL_ATTR_RW(dump_nvme, bootprog, "%lld\n", "%llx\n",
1670 dump_block_nvme->nvme.bootprog);
1671 DEFINE_IPL_ATTR_RW(dump_nvme, br_lba, "%lld\n", "%llx\n",
1672 dump_block_nvme->nvme.br_lba);
1674 static struct attribute *dump_nvme_attrs[] = {
1675 &sys_dump_nvme_fid_attr.attr,
1676 &sys_dump_nvme_nsid_attr.attr,
1677 &sys_dump_nvme_bootprog_attr.attr,
1678 &sys_dump_nvme_br_lba_attr.attr,
1682 static struct attribute_group dump_nvme_attr_group = {
1683 .name = IPL_NVME_STR,
1684 .attrs = dump_nvme_attrs,
1687 /* ECKD dump device attributes */
1688 DEFINE_IPL_CCW_ATTR_RW(dump_eckd, device, dump_block_eckd->eckd);
1689 DEFINE_IPL_ATTR_RW(dump_eckd, bootprog, "%lld\n", "%llx\n",
1690 dump_block_eckd->eckd.bootprog);
1692 IPL_ATTR_BR_CHR_SHOW_FN(dump, dump_block_eckd->eckd);
1693 IPL_ATTR_BR_CHR_STORE_FN(dump, dump_block_eckd->eckd);
1695 static struct kobj_attribute sys_dump_eckd_br_chr_attr =
1696 __ATTR(br_chr, 0644, eckd_dump_br_chr_show, eckd_dump_br_chr_store);
1698 static struct attribute *dump_eckd_attrs[] = {
1699 &sys_dump_eckd_device_attr.attr,
1700 &sys_dump_eckd_bootprog_attr.attr,
1701 &sys_dump_eckd_br_chr_attr.attr,
1705 static struct attribute_group dump_eckd_attr_group = {
1706 .name = IPL_ECKD_STR,
1707 .attrs = dump_eckd_attrs,
1710 /* CCW dump device attributes */
1711 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ccw);
1713 static struct attribute *dump_ccw_attrs[] = {
1714 &sys_dump_ccw_device_attr.attr,
1718 static struct attribute_group dump_ccw_attr_group = {
1719 .name = IPL_CCW_STR,
1720 .attrs = dump_ccw_attrs,
1725 static int dump_set_type(enum dump_type type)
1727 if (!(dump_capabilities & type))
1733 static ssize_t dump_type_show(struct kobject *kobj,
1734 struct kobj_attribute *attr, char *page)
1736 return sprintf(page, "%s\n", dump_type_str(dump_type));
1739 static ssize_t dump_type_store(struct kobject *kobj,
1740 struct kobj_attribute *attr,
1741 const char *buf, size_t len)
1745 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1746 rc = dump_set_type(DUMP_TYPE_NONE);
1747 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1748 rc = dump_set_type(DUMP_TYPE_CCW);
1749 else if (strncmp(buf, DUMP_ECKD_STR, strlen(DUMP_ECKD_STR)) == 0)
1750 rc = dump_set_type(DUMP_TYPE_ECKD);
1751 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1752 rc = dump_set_type(DUMP_TYPE_FCP);
1753 else if (strncmp(buf, DUMP_NVME_STR, strlen(DUMP_NVME_STR)) == 0)
1754 rc = dump_set_type(DUMP_TYPE_NVME);
1755 return (rc != 0) ? rc : len;
1758 static struct kobj_attribute dump_type_attr =
1759 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1761 static struct kset *dump_kset;
1763 static void diag308_dump(void *dump_block)
1765 diag308(DIAG308_SET, dump_block);
1767 if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
1769 udelay(USEC_PER_SEC);
1773 static void __dump_run(void *unused)
1775 switch (dump_type) {
1777 diag308_dump(dump_block_ccw);
1779 case DUMP_TYPE_ECKD:
1780 diag308_dump(dump_block_eckd);
1783 diag308_dump(dump_block_fcp);
1785 case DUMP_TYPE_NVME:
1786 diag308_dump(dump_block_nvme);
1793 static void dump_run(struct shutdown_trigger *trigger)
1795 if (dump_type == DUMP_TYPE_NONE)
1798 smp_call_ipl_cpu(__dump_run, NULL);
1801 static int __init dump_ccw_init(void)
1805 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1806 if (!dump_block_ccw)
1808 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1810 free_page((unsigned long)dump_block_ccw);
1813 dump_block_ccw->hdr.len = IPL_BP_CCW_LEN;
1814 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1815 dump_block_ccw->ccw.len = IPL_BP0_CCW_LEN;
1816 dump_block_ccw->ccw.pbt = IPL_PBT_CCW;
1817 dump_capabilities |= DUMP_TYPE_CCW;
1821 static int __init dump_fcp_init(void)
1825 if (!sclp_ipl_info.has_dump)
1826 return 0; /* LDIPL DUMP is not installed */
1827 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1828 if (!dump_block_fcp)
1830 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1832 free_page((unsigned long)dump_block_fcp);
1835 dump_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1836 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1837 dump_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1838 dump_block_fcp->fcp.pbt = IPL_PBT_FCP;
1839 dump_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_DUMP;
1840 dump_capabilities |= DUMP_TYPE_FCP;
1844 static int __init dump_nvme_init(void)
1848 if (!sclp_ipl_info.has_dump)
1849 return 0; /* LDIPL DUMP is not installed */
1850 dump_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1851 if (!dump_block_nvme)
1853 rc = sysfs_create_group(&dump_kset->kobj, &dump_nvme_attr_group);
1855 free_page((unsigned long)dump_block_nvme);
1858 dump_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1859 dump_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1860 dump_block_nvme->fcp.len = IPL_BP0_NVME_LEN;
1861 dump_block_nvme->fcp.pbt = IPL_PBT_NVME;
1862 dump_block_nvme->fcp.opt = IPL_PB0_NVME_OPT_DUMP;
1863 dump_capabilities |= DUMP_TYPE_NVME;
1867 static int __init dump_eckd_init(void)
1871 if (!sclp_ipl_info.has_dump || !sclp.has_sipl_eckd)
1872 return 0; /* LDIPL DUMP is not installed */
1873 dump_block_eckd = (void *)get_zeroed_page(GFP_KERNEL);
1874 if (!dump_block_eckd)
1876 rc = sysfs_create_group(&dump_kset->kobj, &dump_eckd_attr_group);
1878 free_page((unsigned long)dump_block_eckd);
1881 dump_block_eckd->hdr.len = IPL_BP_ECKD_LEN;
1882 dump_block_eckd->hdr.version = IPL_PARM_BLOCK_VERSION;
1883 dump_block_eckd->eckd.len = IPL_BP0_ECKD_LEN;
1884 dump_block_eckd->eckd.pbt = IPL_PBT_ECKD;
1885 dump_block_eckd->eckd.opt = IPL_PB0_ECKD_OPT_DUMP;
1886 dump_capabilities |= DUMP_TYPE_ECKD;
1890 static int __init dump_init(void)
1894 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1897 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1899 kset_unregister(dump_kset);
1902 rc = dump_ccw_init();
1905 rc = dump_eckd_init();
1908 rc = dump_fcp_init();
1911 rc = dump_nvme_init();
1914 dump_set_type(DUMP_TYPE_NONE);
1918 static struct shutdown_action __refdata dump_action = {
1919 .name = SHUTDOWN_ACTION_DUMP_STR,
1924 static void dump_reipl_run(struct shutdown_trigger *trigger)
1926 struct lowcore *abs_lc;
1930 * Set REIPL_CLEAR flag in os_info flags entry indicating
1931 * 'clear' sysfs attribute has been set on the panicked system
1932 * for specified reipl type.
1933 * Always set for IPL_TYPE_NSS and IPL_TYPE_UNKNOWN.
1935 if ((reipl_type == IPL_TYPE_CCW && reipl_ccw_clear) ||
1936 (reipl_type == IPL_TYPE_ECKD && reipl_eckd_clear) ||
1937 (reipl_type == IPL_TYPE_FCP && reipl_fcp_clear) ||
1938 (reipl_type == IPL_TYPE_NVME && reipl_nvme_clear) ||
1939 reipl_type == IPL_TYPE_NSS ||
1940 reipl_type == IPL_TYPE_UNKNOWN)
1941 os_info_flags |= OS_INFO_FLAG_REIPL_CLEAR;
1942 os_info_entry_add(OS_INFO_FLAGS_ENTRY, &os_info_flags, sizeof(os_info_flags));
1943 csum = (__force unsigned int)
1944 csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1945 abs_lc = get_abs_lowcore();
1946 abs_lc->ipib = __pa(reipl_block_actual);
1947 abs_lc->ipib_checksum = csum;
1948 put_abs_lowcore(abs_lc);
1952 static struct shutdown_action __refdata dump_reipl_action = {
1953 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1954 .fn = dump_reipl_run,
1958 * vmcmd shutdown action: Trigger vm command on shutdown.
1961 static char vmcmd_on_reboot[128];
1962 static char vmcmd_on_panic[128];
1963 static char vmcmd_on_halt[128];
1964 static char vmcmd_on_poff[128];
1965 static char vmcmd_on_restart[128];
1967 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1968 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1969 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1970 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1971 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1973 static struct attribute *vmcmd_attrs[] = {
1974 &sys_vmcmd_on_reboot_attr.attr,
1975 &sys_vmcmd_on_panic_attr.attr,
1976 &sys_vmcmd_on_halt_attr.attr,
1977 &sys_vmcmd_on_poff_attr.attr,
1978 &sys_vmcmd_on_restart_attr.attr,
1982 static struct attribute_group vmcmd_attr_group = {
1983 .attrs = vmcmd_attrs,
1986 static struct kset *vmcmd_kset;
1988 static void vmcmd_run(struct shutdown_trigger *trigger)
1992 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1993 cmd = vmcmd_on_reboot;
1994 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1995 cmd = vmcmd_on_panic;
1996 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1997 cmd = vmcmd_on_halt;
1998 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1999 cmd = vmcmd_on_poff;
2000 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
2001 cmd = vmcmd_on_restart;
2005 if (strlen(cmd) == 0)
2007 __cpcmd(cmd, NULL, 0, NULL);
2010 static int vmcmd_init(void)
2014 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
2017 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
2020 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
2021 vmcmd_run, vmcmd_init};
2024 * stop shutdown action: Stop Linux on shutdown.
2027 static void stop_run(struct shutdown_trigger *trigger)
2029 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
2030 strcmp(trigger->name, ON_RESTART_STR) == 0)
2035 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
2040 static struct shutdown_action *shutdown_actions_list[] = {
2041 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
2042 &vmcmd_action, &stop_action};
2043 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
2049 static struct kset *shutdown_actions_kset;
2051 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
2056 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2057 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
2058 if (shutdown_actions_list[i]->init_rc) {
2059 return shutdown_actions_list[i]->init_rc;
2061 trigger->action = shutdown_actions_list[i];
2071 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
2074 static ssize_t on_reboot_show(struct kobject *kobj,
2075 struct kobj_attribute *attr, char *page)
2077 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
2080 static ssize_t on_reboot_store(struct kobject *kobj,
2081 struct kobj_attribute *attr,
2082 const char *buf, size_t len)
2084 return set_trigger(buf, &on_reboot_trigger, len);
2086 static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
2088 static void do_machine_restart(char *__unused)
2091 on_reboot_trigger.action->fn(&on_reboot_trigger);
2094 void (*_machine_restart)(char *command) = do_machine_restart;
2098 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
2100 static ssize_t on_panic_show(struct kobject *kobj,
2101 struct kobj_attribute *attr, char *page)
2103 return sprintf(page, "%s\n", on_panic_trigger.action->name);
2106 static ssize_t on_panic_store(struct kobject *kobj,
2107 struct kobj_attribute *attr,
2108 const char *buf, size_t len)
2110 return set_trigger(buf, &on_panic_trigger, len);
2112 static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
2114 static void do_panic(void)
2117 on_panic_trigger.action->fn(&on_panic_trigger);
2118 stop_run(&on_panic_trigger);
2123 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
2126 static ssize_t on_restart_show(struct kobject *kobj,
2127 struct kobj_attribute *attr, char *page)
2129 return sprintf(page, "%s\n", on_restart_trigger.action->name);
2132 static ssize_t on_restart_store(struct kobject *kobj,
2133 struct kobj_attribute *attr,
2134 const char *buf, size_t len)
2136 return set_trigger(buf, &on_restart_trigger, len);
2138 static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
2140 static void __do_restart(void *ignore)
2143 #ifdef CONFIG_CRASH_DUMP
2146 on_restart_trigger.action->fn(&on_restart_trigger);
2147 stop_run(&on_restart_trigger);
2150 void do_restart(void *arg)
2155 smp_call_online_cpu(__do_restart, arg);
2160 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
2162 static ssize_t on_halt_show(struct kobject *kobj,
2163 struct kobj_attribute *attr, char *page)
2165 return sprintf(page, "%s\n", on_halt_trigger.action->name);
2168 static ssize_t on_halt_store(struct kobject *kobj,
2169 struct kobj_attribute *attr,
2170 const char *buf, size_t len)
2172 return set_trigger(buf, &on_halt_trigger, len);
2174 static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
2176 static void do_machine_halt(void)
2179 on_halt_trigger.action->fn(&on_halt_trigger);
2180 stop_run(&on_halt_trigger);
2182 void (*_machine_halt)(void) = do_machine_halt;
2186 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
2188 static ssize_t on_poff_show(struct kobject *kobj,
2189 struct kobj_attribute *attr, char *page)
2191 return sprintf(page, "%s\n", on_poff_trigger.action->name);
2194 static ssize_t on_poff_store(struct kobject *kobj,
2195 struct kobj_attribute *attr,
2196 const char *buf, size_t len)
2198 return set_trigger(buf, &on_poff_trigger, len);
2200 static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
2202 static void do_machine_power_off(void)
2205 on_poff_trigger.action->fn(&on_poff_trigger);
2206 stop_run(&on_poff_trigger);
2208 void (*_machine_power_off)(void) = do_machine_power_off;
2210 static struct attribute *shutdown_action_attrs[] = {
2211 &on_restart_attr.attr,
2212 &on_reboot_attr.attr,
2213 &on_panic_attr.attr,
2219 static struct attribute_group shutdown_action_attr_group = {
2220 .attrs = shutdown_action_attrs,
2223 static void __init shutdown_triggers_init(void)
2225 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
2227 if (!shutdown_actions_kset)
2229 if (sysfs_create_group(&shutdown_actions_kset->kobj,
2230 &shutdown_action_attr_group))
2234 panic("shutdown_triggers_init failed\n");
2237 static void __init shutdown_actions_init(void)
2241 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
2242 if (!shutdown_actions_list[i]->init)
2244 shutdown_actions_list[i]->init_rc =
2245 shutdown_actions_list[i]->init();
2249 static int __init s390_ipl_init(void)
2251 char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
2253 sclp_early_get_ipl_info(&sclp_ipl_info);
2255 * Fix loadparm: There are systems where the (SCSI) LOADPARM
2256 * returned by read SCP info is invalid (contains EBCDIC blanks)
2257 * when the system has been booted via diag308. In that case we use
2258 * the value from diag308, if available.
2260 * There are also systems where diag308 store does not work in
2261 * case the system is booted from HMC. Fortunately in this case
2262 * READ SCP info provides the correct value.
2264 if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && ipl_block_valid)
2265 memcpy(sclp_ipl_info.loadparm, ipl_block.ccw.loadparm, LOADPARM_LEN);
2266 shutdown_actions_init();
2267 shutdown_triggers_init();
2271 __initcall(s390_ipl_init);
2273 static void __init strncpy_skip_quote(char *dst, char *src, int n)
2278 for (sx = 0; src[sx] != 0; sx++) {
2281 dst[dx++] = src[sx];
2287 static int __init vmcmd_on_reboot_setup(char *str)
2291 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
2292 vmcmd_on_reboot[127] = 0;
2293 on_reboot_trigger.action = &vmcmd_action;
2296 __setup("vmreboot=", vmcmd_on_reboot_setup);
2298 static int __init vmcmd_on_panic_setup(char *str)
2302 strncpy_skip_quote(vmcmd_on_panic, str, 127);
2303 vmcmd_on_panic[127] = 0;
2304 on_panic_trigger.action = &vmcmd_action;
2307 __setup("vmpanic=", vmcmd_on_panic_setup);
2309 static int __init vmcmd_on_halt_setup(char *str)
2313 strncpy_skip_quote(vmcmd_on_halt, str, 127);
2314 vmcmd_on_halt[127] = 0;
2315 on_halt_trigger.action = &vmcmd_action;
2318 __setup("vmhalt=", vmcmd_on_halt_setup);
2320 static int __init vmcmd_on_poff_setup(char *str)
2324 strncpy_skip_quote(vmcmd_on_poff, str, 127);
2325 vmcmd_on_poff[127] = 0;
2326 on_poff_trigger.action = &vmcmd_action;
2329 __setup("vmpoff=", vmcmd_on_poff_setup);
2331 static int on_panic_notify(struct notifier_block *self,
2332 unsigned long event, void *data)
2338 static struct notifier_block on_panic_nb = {
2339 .notifier_call = on_panic_notify,
2340 .priority = INT_MIN,
2343 void __init setup_ipl(void)
2345 BUILD_BUG_ON(sizeof(struct ipl_parameter_block) != PAGE_SIZE);
2347 ipl_info.type = get_ipl_type();
2348 switch (ipl_info.type) {
2350 ipl_info.data.ccw.dev_id.ssid = ipl_block.ccw.ssid;
2351 ipl_info.data.ccw.dev_id.devno = ipl_block.ccw.devno;
2354 case IPL_TYPE_ECKD_DUMP:
2355 ipl_info.data.eckd.dev_id.ssid = ipl_block.eckd.ssid;
2356 ipl_info.data.eckd.dev_id.devno = ipl_block.eckd.devno;
2359 case IPL_TYPE_FCP_DUMP:
2360 ipl_info.data.fcp.dev_id.ssid = 0;
2361 ipl_info.data.fcp.dev_id.devno = ipl_block.fcp.devno;
2362 ipl_info.data.fcp.wwpn = ipl_block.fcp.wwpn;
2363 ipl_info.data.fcp.lun = ipl_block.fcp.lun;
2366 case IPL_TYPE_NVME_DUMP:
2367 ipl_info.data.nvme.fid = ipl_block.nvme.fid;
2368 ipl_info.data.nvme.nsid = ipl_block.nvme.nsid;
2371 case IPL_TYPE_UNKNOWN:
2372 /* We have no info to copy */
2375 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
2378 void s390_reset_system(void)
2380 /* Disable prefixing */
2383 /* Disable lowcore protection */
2384 __ctl_clear_bit(0, 28);
2385 diag_amode31_ops.diag308_reset();
2388 #ifdef CONFIG_KEXEC_FILE
2390 int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
2391 unsigned char flags, unsigned short cert)
2393 struct ipl_report_component *comp;
2395 comp = vzalloc(sizeof(*comp));
2398 list_add_tail(&comp->list, &report->components);
2400 comp->entry.addr = kbuf->mem;
2401 comp->entry.len = kbuf->memsz;
2402 comp->entry.flags = flags;
2403 comp->entry.certificate_index = cert;
2405 report->size += sizeof(comp->entry);
2410 int ipl_report_add_certificate(struct ipl_report *report, void *key,
2411 unsigned long addr, unsigned long len)
2413 struct ipl_report_certificate *cert;
2415 cert = vzalloc(sizeof(*cert));
2418 list_add_tail(&cert->list, &report->certificates);
2420 cert->entry.addr = addr;
2421 cert->entry.len = len;
2424 report->size += sizeof(cert->entry);
2425 report->size += cert->entry.len;
2430 struct ipl_report *ipl_report_init(struct ipl_parameter_block *ipib)
2432 struct ipl_report *report;
2434 report = vzalloc(sizeof(*report));
2436 return ERR_PTR(-ENOMEM);
2438 report->ipib = ipib;
2439 INIT_LIST_HEAD(&report->components);
2440 INIT_LIST_HEAD(&report->certificates);
2442 report->size = ALIGN(ipib->hdr.len, 8);
2443 report->size += sizeof(struct ipl_rl_hdr);
2444 report->size += sizeof(struct ipl_rb_components);
2445 report->size += sizeof(struct ipl_rb_certificates);
2450 void *ipl_report_finish(struct ipl_report *report)
2452 struct ipl_report_certificate *cert;
2453 struct ipl_report_component *comp;
2454 struct ipl_rb_certificates *certs;
2455 struct ipl_parameter_block *ipib;
2456 struct ipl_rb_components *comps;
2457 struct ipl_rl_hdr *rl_hdr;
2460 buf = vzalloc(report->size);
2465 memcpy(ptr, report->ipib, report->ipib->hdr.len);
2467 if (ipl_secure_flag)
2468 ipib->hdr.flags |= IPL_PL_FLAG_SIPL;
2469 ipib->hdr.flags |= IPL_PL_FLAG_IPLSR;
2470 ptr += report->ipib->hdr.len;
2471 ptr = PTR_ALIGN(ptr, 8);
2474 ptr += sizeof(*rl_hdr);
2477 comps->rbt = IPL_RBT_COMPONENTS;
2478 ptr += sizeof(*comps);
2479 list_for_each_entry(comp, &report->components, list) {
2480 memcpy(ptr, &comp->entry, sizeof(comp->entry));
2481 ptr += sizeof(comp->entry);
2483 comps->len = ptr - (void *)comps;
2486 certs->rbt = IPL_RBT_CERTIFICATES;
2487 ptr += sizeof(*certs);
2488 list_for_each_entry(cert, &report->certificates, list) {
2489 memcpy(ptr, &cert->entry, sizeof(cert->entry));
2490 ptr += sizeof(cert->entry);
2492 certs->len = ptr - (void *)certs;
2493 rl_hdr->len = ptr - (void *)rl_hdr;
2495 list_for_each_entry(cert, &report->certificates, list) {
2496 memcpy(ptr, cert->key, cert->entry.len);
2497 ptr += cert->entry.len;
2500 BUG_ON(ptr > buf + report->size);
2505 int ipl_report_free(struct ipl_report *report)
2507 struct ipl_report_component *comp, *ncomp;
2508 struct ipl_report_certificate *cert, *ncert;
2510 list_for_each_entry_safe(comp, ncomp, &report->components, list)
2513 list_for_each_entry_safe(cert, ncert, &report->certificates, list)