2 * ipl/reipl/dump support for Linux on s390.
4 * Copyright IBM Corp. 2005, 2012
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 * Volker Sameske <sameske@de.ibm.com>
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <linux/ctype.h>
17 #include <linux/gfp.h>
18 #include <linux/crash_dump.h>
19 #include <linux/debug_locks.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
28 #include <asm/checksum.h>
29 #include <asm/debug.h>
30 #include <asm/os_info.h>
33 #define IPL_PARM_BLOCK_VERSION 0
35 #define IPL_UNKNOWN_STR "unknown"
36 #define IPL_CCW_STR "ccw"
37 #define IPL_FCP_STR "fcp"
38 #define IPL_FCP_DUMP_STR "fcp_dump"
39 #define IPL_NSS_STR "nss"
41 #define DUMP_CCW_STR "ccw"
42 #define DUMP_FCP_STR "fcp"
43 #define DUMP_NONE_STR "none"
46 * Four shutdown trigger types are supported:
53 #define ON_PANIC_STR "on_panic"
54 #define ON_HALT_STR "on_halt"
55 #define ON_POFF_STR "on_poff"
56 #define ON_REIPL_STR "on_reboot"
57 #define ON_RESTART_STR "on_restart"
59 struct shutdown_action
;
60 struct shutdown_trigger
{
62 struct shutdown_action
*action
;
66 * The following shutdown action types are supported:
68 #define SHUTDOWN_ACTION_IPL_STR "ipl"
69 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
70 #define SHUTDOWN_ACTION_DUMP_STR "dump"
71 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72 #define SHUTDOWN_ACTION_STOP_STR "stop"
73 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
75 struct shutdown_action
{
77 void (*fn
) (struct shutdown_trigger
*trigger
);
82 static char *ipl_type_str(enum ipl_type type
)
89 case IPL_TYPE_FCP_DUMP
:
90 return IPL_FCP_DUMP_STR
;
93 case IPL_TYPE_UNKNOWN
:
95 return IPL_UNKNOWN_STR
;
105 static char *dump_type_str(enum dump_type type
)
109 return DUMP_NONE_STR
;
120 * Must be in data section since the bss section
121 * is not cleared when these are accessed.
123 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
124 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
127 REIPL_METHOD_CCW_CIO
,
128 REIPL_METHOD_CCW_DIAG
,
130 REIPL_METHOD_FCP_RO_DIAG
,
131 REIPL_METHOD_FCP_RW_DIAG
,
132 REIPL_METHOD_FCP_RO_VM
,
133 REIPL_METHOD_FCP_DUMP
,
135 REIPL_METHOD_NSS_DIAG
,
136 REIPL_METHOD_DEFAULT
,
142 DUMP_METHOD_CCW_DIAG
,
144 DUMP_METHOD_FCP_DIAG
,
147 static int diag308_set_works
= 0;
149 static struct ipl_parameter_block ipl_block
;
151 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
153 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
154 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
155 static struct ipl_parameter_block
*reipl_block_fcp
;
156 static struct ipl_parameter_block
*reipl_block_ccw
;
157 static struct ipl_parameter_block
*reipl_block_nss
;
158 static struct ipl_parameter_block
*reipl_block_actual
;
160 static int dump_capabilities
= DUMP_TYPE_NONE
;
161 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
162 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
163 static struct ipl_parameter_block
*dump_block_fcp
;
164 static struct ipl_parameter_block
*dump_block_ccw
;
166 static struct sclp_ipl_info sclp_ipl_info
;
168 int diag308(unsigned long subcode
, void *addr
)
170 register unsigned long _addr
asm("0") = (unsigned long) addr
;
171 register unsigned long _rc
asm("1") = 0;
174 " diag %0,%2,0x308\n"
177 : "+d" (_addr
), "+d" (_rc
)
178 : "d" (subcode
) : "cc", "memory");
181 EXPORT_SYMBOL_GPL(diag308
);
185 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
190 return sprintf(page, _format, _value); \
192 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
193 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
195 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
196 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
200 return sprintf(page, _fmt_out, \
201 (unsigned long long) _value); \
203 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
204 struct kobj_attribute *attr, \
205 const char *buf, size_t len) \
207 unsigned long long value; \
208 if (sscanf(buf, _fmt_in, &value) != 1) \
213 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
214 __ATTR(_name,(S_IRUGO | S_IWUSR), \
215 sys_##_prefix##_##_name##_show, \
216 sys_##_prefix##_##_name##_store);
218 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
219 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
223 return sprintf(page, _fmt_out, _value); \
225 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
226 struct kobj_attribute *attr, \
227 const char *buf, size_t len) \
229 strncpy(_value, buf, sizeof(_value) - 1); \
233 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
234 __ATTR(_name,(S_IRUGO | S_IWUSR), \
235 sys_##_prefix##_##_name##_show, \
236 sys_##_prefix##_##_name##_store);
238 static void make_attrs_ro(struct attribute
**attrs
)
241 (*attrs
)->mode
= S_IRUGO
;
250 static __init
enum ipl_type
get_ipl_type(void)
252 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
254 if (ipl_flags
& IPL_NSS_VALID
)
256 if (!(ipl_flags
& IPL_DEVNO_VALID
))
257 return IPL_TYPE_UNKNOWN
;
258 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
260 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
261 return IPL_TYPE_UNKNOWN
;
262 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
263 return IPL_TYPE_UNKNOWN
;
264 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
265 return IPL_TYPE_FCP_DUMP
;
269 struct ipl_info ipl_info
;
270 EXPORT_SYMBOL_GPL(ipl_info
);
272 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
275 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
278 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
280 /* VM IPL PARM routines */
281 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
282 const struct ipl_parameter_block
*ipb
)
286 char has_lowercase
= 0;
289 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
290 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
292 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
293 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
294 /* If at least one character is lowercase, we assume mixed
295 * case; otherwise we convert everything to lowercase.
297 for (i
= 0; i
< len
; i
++)
298 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
299 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
300 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
305 EBC_TOLOWER(dest
, len
);
313 size_t append_ipl_vmparm(char *dest
, size_t size
)
318 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
319 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
325 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
326 struct kobj_attribute
*attr
, char *page
)
328 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
330 append_ipl_vmparm(parm
, sizeof(parm
));
331 return sprintf(page
, "%s\n", parm
);
334 static size_t scpdata_length(const char* buf
, size_t count
)
337 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
344 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
345 const struct ipl_parameter_block
*ipb
)
351 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
352 ipb
->ipl_info
.fcp
.scp_data_len
));
357 for (i
= 0; i
< count
; i
++) {
358 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
362 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
367 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
369 for (i
= 0; i
< count
; i
++)
370 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
376 size_t append_ipl_scpdata(char *dest
, size_t len
)
381 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
382 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
389 static struct kobj_attribute sys_ipl_vm_parm_attr
=
390 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
392 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
393 struct kobj_attribute
*attr
, char *page
)
395 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
397 switch (ipl_info
.type
) {
399 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
401 case IPL_TYPE_FCP_DUMP
:
402 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
408 static struct kobj_attribute sys_ipl_device_attr
=
409 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
411 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
412 struct bin_attribute
*attr
, char *buf
,
413 loff_t off
, size_t count
)
415 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
419 static struct bin_attribute ipl_parameter_attr
= {
421 .name
= "binary_parameter",
425 .read
= &ipl_parameter_read
,
428 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
429 struct bin_attribute
*attr
, char *buf
,
430 loff_t off
, size_t count
)
432 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
433 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
435 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
438 static struct bin_attribute ipl_scp_data_attr
= {
444 .read
= ipl_scp_data_read
,
447 /* FCP ipl device attributes */
449 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
451 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
452 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
453 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
455 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
456 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
458 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
459 struct kobj_attribute
*attr
, char *page
)
461 char loadparm
[LOADPARM_LEN
+ 1] = {};
463 if (!sclp_ipl_info
.is_valid
)
464 return sprintf(page
, "#unknown#\n");
465 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
466 EBCASC(loadparm
, LOADPARM_LEN
);
468 return sprintf(page
, "%s\n", loadparm
);
471 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
472 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
474 static struct attribute
*ipl_fcp_attrs
[] = {
475 &sys_ipl_type_attr
.attr
,
476 &sys_ipl_device_attr
.attr
,
477 &sys_ipl_fcp_wwpn_attr
.attr
,
478 &sys_ipl_fcp_lun_attr
.attr
,
479 &sys_ipl_fcp_bootprog_attr
.attr
,
480 &sys_ipl_fcp_br_lba_attr
.attr
,
481 &sys_ipl_ccw_loadparm_attr
.attr
,
485 static struct attribute_group ipl_fcp_attr_group
= {
486 .attrs
= ipl_fcp_attrs
,
489 /* CCW ipl device attributes */
491 static struct attribute
*ipl_ccw_attrs_vm
[] = {
492 &sys_ipl_type_attr
.attr
,
493 &sys_ipl_device_attr
.attr
,
494 &sys_ipl_ccw_loadparm_attr
.attr
,
495 &sys_ipl_vm_parm_attr
.attr
,
499 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
500 &sys_ipl_type_attr
.attr
,
501 &sys_ipl_device_attr
.attr
,
502 &sys_ipl_ccw_loadparm_attr
.attr
,
506 static struct attribute_group ipl_ccw_attr_group_vm
= {
507 .attrs
= ipl_ccw_attrs_vm
,
510 static struct attribute_group ipl_ccw_attr_group_lpar
= {
511 .attrs
= ipl_ccw_attrs_lpar
514 /* NSS ipl device attributes */
516 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
518 static struct attribute
*ipl_nss_attrs
[] = {
519 &sys_ipl_type_attr
.attr
,
520 &sys_ipl_nss_name_attr
.attr
,
521 &sys_ipl_ccw_loadparm_attr
.attr
,
522 &sys_ipl_vm_parm_attr
.attr
,
526 static struct attribute_group ipl_nss_attr_group
= {
527 .attrs
= ipl_nss_attrs
,
530 /* UNKNOWN ipl device attributes */
532 static struct attribute
*ipl_unknown_attrs
[] = {
533 &sys_ipl_type_attr
.attr
,
537 static struct attribute_group ipl_unknown_attr_group
= {
538 .attrs
= ipl_unknown_attrs
,
541 static struct kset
*ipl_kset
;
543 static int __init
ipl_register_fcp_files(void)
547 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
550 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
553 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
557 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
560 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
565 static void __ipl_run(void *unused
)
567 diag308(DIAG308_IPL
, NULL
);
569 __cpcmd("IPL", NULL
, 0, NULL
);
570 else if (ipl_info
.type
== IPL_TYPE_CCW
)
571 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
574 static void ipl_run(struct shutdown_trigger
*trigger
)
576 smp_call_ipl_cpu(__ipl_run
, NULL
);
579 static int __init
ipl_init(void)
583 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
588 switch (ipl_info
.type
) {
591 rc
= sysfs_create_group(&ipl_kset
->kobj
,
592 &ipl_ccw_attr_group_vm
);
594 rc
= sysfs_create_group(&ipl_kset
->kobj
,
595 &ipl_ccw_attr_group_lpar
);
598 case IPL_TYPE_FCP_DUMP
:
599 rc
= ipl_register_fcp_files();
602 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
605 rc
= sysfs_create_group(&ipl_kset
->kobj
,
606 &ipl_unknown_attr_group
);
611 panic("ipl_init failed: rc = %i\n", rc
);
616 static struct shutdown_action __refdata ipl_action
= {
617 .name
= SHUTDOWN_ACTION_IPL_STR
,
623 * reipl shutdown action: Reboot Linux on shutdown.
626 /* VM IPL PARM attributes */
627 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
630 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
632 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
633 return sprintf(page
, "%s\n", vmparm
);
636 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
638 const char *buf
, size_t len
)
642 /* ignore trailing newline */
644 if ((len
> 0) && (buf
[len
- 1] == '\n'))
647 if (ip_len
> vmparm_max
)
650 /* parm is used to store kernel options, check for common chars */
651 for (i
= 0; i
< ip_len
; i
++)
652 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
655 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
656 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
658 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
659 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
660 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
662 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
669 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
670 struct kobj_attribute
*attr
, char *page
)
672 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
675 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
676 struct kobj_attribute
*attr
,
677 const char *buf
, size_t len
)
679 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
683 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
684 struct kobj_attribute
*attr
, char *page
)
686 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
689 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
690 struct kobj_attribute
*attr
,
691 const char *buf
, size_t len
)
693 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
696 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
697 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
698 reipl_nss_vmparm_store
);
699 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
700 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
701 reipl_ccw_vmparm_store
);
703 /* FCP reipl device attributes */
705 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
706 struct bin_attribute
*attr
,
707 char *buf
, loff_t off
, size_t count
)
709 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
710 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
712 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
715 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
716 struct bin_attribute
*attr
,
717 char *buf
, loff_t off
, size_t count
)
725 if (off
>= DIAG308_SCPDATA_SIZE
)
728 if (count
> DIAG308_SCPDATA_SIZE
- off
)
729 count
= DIAG308_SCPDATA_SIZE
- off
;
731 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
732 scpdata_len
= off
+ count
;
734 if (scpdata_len
% 8) {
735 padding
= 8 - (scpdata_len
% 8);
736 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
738 scpdata_len
+= padding
;
741 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
742 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
743 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
748 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
751 .mode
= S_IRUGO
| S_IWUSR
,
754 .read
= reipl_fcp_scpdata_read
,
755 .write
= reipl_fcp_scpdata_write
,
758 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
759 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
760 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
761 reipl_block_fcp
->ipl_info
.fcp
.lun
);
762 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
763 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
764 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
765 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
766 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
767 reipl_block_fcp
->ipl_info
.fcp
.devno
);
769 static void reipl_get_ascii_loadparm(char *loadparm
,
770 struct ipl_parameter_block
*ibp
)
772 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
773 EBCASC(loadparm
, LOADPARM_LEN
);
774 loadparm
[LOADPARM_LEN
] = 0;
778 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
781 char buf
[LOADPARM_LEN
+ 1];
783 reipl_get_ascii_loadparm(buf
, ipb
);
784 return sprintf(page
, "%s\n", buf
);
787 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
788 const char *buf
, size_t len
)
792 /* ignore trailing newline */
794 if ((len
> 0) && (buf
[len
- 1] == '\n'))
796 /* loadparm can have max 8 characters and must not start with a blank */
797 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
799 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
800 for (i
= 0; i
< lp_len
; i
++) {
801 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
806 /* initialize loadparm with blanks */
807 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
808 /* copy and convert to ebcdic */
809 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
810 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
815 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
816 struct kobj_attribute
*attr
, char *page
)
818 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
821 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
822 struct kobj_attribute
*attr
,
823 const char *buf
, size_t len
)
825 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
828 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
829 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
830 reipl_fcp_loadparm_store
);
832 static struct attribute
*reipl_fcp_attrs
[] = {
833 &sys_reipl_fcp_device_attr
.attr
,
834 &sys_reipl_fcp_wwpn_attr
.attr
,
835 &sys_reipl_fcp_lun_attr
.attr
,
836 &sys_reipl_fcp_bootprog_attr
.attr
,
837 &sys_reipl_fcp_br_lba_attr
.attr
,
838 &sys_reipl_fcp_loadparm_attr
.attr
,
842 static struct attribute_group reipl_fcp_attr_group
= {
843 .attrs
= reipl_fcp_attrs
,
846 /* CCW reipl device attributes */
848 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
849 reipl_block_ccw
->ipl_info
.ccw
.devno
);
852 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
853 struct kobj_attribute
*attr
, char *page
)
855 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
858 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
859 struct kobj_attribute
*attr
,
860 const char *buf
, size_t len
)
862 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
866 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
867 struct kobj_attribute
*attr
, char *page
)
869 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
872 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
873 struct kobj_attribute
*attr
,
874 const char *buf
, size_t len
)
876 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
879 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
880 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
881 reipl_ccw_loadparm_store
);
883 static struct attribute
*reipl_ccw_attrs_vm
[] = {
884 &sys_reipl_ccw_device_attr
.attr
,
885 &sys_reipl_ccw_loadparm_attr
.attr
,
886 &sys_reipl_ccw_vmparm_attr
.attr
,
890 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
891 &sys_reipl_ccw_device_attr
.attr
,
892 &sys_reipl_ccw_loadparm_attr
.attr
,
896 static struct attribute_group reipl_ccw_attr_group_vm
= {
898 .attrs
= reipl_ccw_attrs_vm
,
901 static struct attribute_group reipl_ccw_attr_group_lpar
= {
903 .attrs
= reipl_ccw_attrs_lpar
,
907 /* NSS reipl device attributes */
908 static void reipl_get_ascii_nss_name(char *dst
,
909 struct ipl_parameter_block
*ipb
)
911 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
912 EBCASC(dst
, NSS_NAME_SIZE
);
913 dst
[NSS_NAME_SIZE
] = 0;
916 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
917 struct kobj_attribute
*attr
, char *page
)
919 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
921 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
922 return sprintf(page
, "%s\n", nss_name
);
925 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
926 struct kobj_attribute
*attr
,
927 const char *buf
, size_t len
)
931 /* ignore trailing newline */
933 if ((len
> 0) && (buf
[len
- 1] == '\n'))
936 if (nss_len
> NSS_NAME_SIZE
)
939 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
941 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
942 DIAG308_VM_FLAGS_NSS_VALID
;
943 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
944 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
945 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
947 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
948 ~DIAG308_VM_FLAGS_NSS_VALID
;
954 static struct kobj_attribute sys_reipl_nss_name_attr
=
955 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
956 reipl_nss_name_store
);
958 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
959 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
960 reipl_nss_loadparm_store
);
962 static struct attribute
*reipl_nss_attrs
[] = {
963 &sys_reipl_nss_name_attr
.attr
,
964 &sys_reipl_nss_loadparm_attr
.attr
,
965 &sys_reipl_nss_vmparm_attr
.attr
,
969 static struct attribute_group reipl_nss_attr_group
= {
971 .attrs
= reipl_nss_attrs
,
974 static void set_reipl_block_actual(struct ipl_parameter_block
*reipl_block
)
976 reipl_block_actual
= reipl_block
;
977 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
978 reipl_block
->hdr
.len
);
983 static int reipl_set_type(enum ipl_type type
)
985 if (!(reipl_capabilities
& type
))
990 if (diag308_set_works
)
991 reipl_method
= REIPL_METHOD_CCW_DIAG
;
992 else if (MACHINE_IS_VM
)
993 reipl_method
= REIPL_METHOD_CCW_VM
;
995 reipl_method
= REIPL_METHOD_CCW_CIO
;
996 set_reipl_block_actual(reipl_block_ccw
);
999 if (diag308_set_works
)
1000 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
1001 else if (MACHINE_IS_VM
)
1002 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
1004 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
1005 set_reipl_block_actual(reipl_block_fcp
);
1007 case IPL_TYPE_FCP_DUMP
:
1008 reipl_method
= REIPL_METHOD_FCP_DUMP
;
1011 if (diag308_set_works
)
1012 reipl_method
= REIPL_METHOD_NSS_DIAG
;
1014 reipl_method
= REIPL_METHOD_NSS
;
1015 set_reipl_block_actual(reipl_block_nss
);
1017 case IPL_TYPE_UNKNOWN
:
1018 reipl_method
= REIPL_METHOD_DEFAULT
;
1027 static ssize_t
reipl_type_show(struct kobject
*kobj
,
1028 struct kobj_attribute
*attr
, char *page
)
1030 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1033 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1034 struct kobj_attribute
*attr
,
1035 const char *buf
, size_t len
)
1039 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1040 rc
= reipl_set_type(IPL_TYPE_CCW
);
1041 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1042 rc
= reipl_set_type(IPL_TYPE_FCP
);
1043 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1044 rc
= reipl_set_type(IPL_TYPE_NSS
);
1045 return (rc
!= 0) ? rc
: len
;
1048 static struct kobj_attribute reipl_type_attr
=
1049 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1051 static struct kset
*reipl_kset
;
1052 static struct kset
*reipl_fcp_kset
;
1054 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1055 const enum ipl_method m
)
1057 char loadparm
[LOADPARM_LEN
+ 1] = {};
1058 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1059 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1062 reipl_get_ascii_loadparm(loadparm
, ipb
);
1063 reipl_get_ascii_nss_name(nss_name
, ipb
);
1064 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1067 case REIPL_METHOD_CCW_VM
:
1068 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1070 case REIPL_METHOD_NSS
:
1071 pos
= sprintf(dst
, "IPL %s", nss_name
);
1076 if (strlen(loadparm
) > 0)
1077 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1078 if (strlen(vmparm
) > 0)
1079 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1082 static void __reipl_run(void *unused
)
1084 struct ccw_dev_id devid
;
1085 static char buf
[128];
1087 switch (reipl_method
) {
1088 case REIPL_METHOD_CCW_CIO
:
1089 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1091 reipl_ccw_dev(&devid
);
1093 case REIPL_METHOD_CCW_VM
:
1094 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1095 __cpcmd(buf
, NULL
, 0, NULL
);
1097 case REIPL_METHOD_CCW_DIAG
:
1098 diag308(DIAG308_SET
, reipl_block_ccw
);
1099 diag308(DIAG308_IPL
, NULL
);
1101 case REIPL_METHOD_FCP_RW_DIAG
:
1102 diag308(DIAG308_SET
, reipl_block_fcp
);
1103 diag308(DIAG308_IPL
, NULL
);
1105 case REIPL_METHOD_FCP_RO_DIAG
:
1106 diag308(DIAG308_IPL
, NULL
);
1108 case REIPL_METHOD_FCP_RO_VM
:
1109 __cpcmd("IPL", NULL
, 0, NULL
);
1111 case REIPL_METHOD_NSS_DIAG
:
1112 diag308(DIAG308_SET
, reipl_block_nss
);
1113 diag308(DIAG308_IPL
, NULL
);
1115 case REIPL_METHOD_NSS
:
1116 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1117 __cpcmd(buf
, NULL
, 0, NULL
);
1119 case REIPL_METHOD_DEFAULT
:
1121 __cpcmd("IPL", NULL
, 0, NULL
);
1122 diag308(DIAG308_IPL
, NULL
);
1124 case REIPL_METHOD_FCP_DUMP
:
1127 disabled_wait((unsigned long) __builtin_return_address(0));
1130 static void reipl_run(struct shutdown_trigger
*trigger
)
1132 smp_call_ipl_cpu(__reipl_run
, NULL
);
1135 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1137 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1138 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1139 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1140 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1143 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1146 /* check if read scp info worked and set loadparm */
1147 if (sclp_ipl_info
.is_valid
)
1148 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1150 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1151 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
1152 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1155 if (MACHINE_IS_VM
&& diag308_set_works
&&
1156 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1158 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1159 ipb
->ipl_info
.ccw
.vm_parm_len
=
1160 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1161 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1162 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1166 static int __init
reipl_nss_init(void)
1173 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1174 if (!reipl_block_nss
)
1177 if (!diag308_set_works
)
1178 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1180 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1184 reipl_block_ccw_init(reipl_block_nss
);
1185 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1186 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1187 ' ', NSS_NAME_SIZE
);
1188 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1189 kernel_nss_name
, strlen(kernel_nss_name
));
1190 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1191 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1192 DIAG308_VM_FLAGS_NSS_VALID
;
1194 reipl_block_ccw_fill_parms(reipl_block_nss
);
1197 reipl_capabilities
|= IPL_TYPE_NSS
;
1201 static int __init
reipl_ccw_init(void)
1205 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1206 if (!reipl_block_ccw
)
1209 if (MACHINE_IS_VM
) {
1210 if (!diag308_set_works
)
1211 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1212 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1213 &reipl_ccw_attr_group_vm
);
1215 if(!diag308_set_works
)
1216 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1217 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1218 &reipl_ccw_attr_group_lpar
);
1223 reipl_block_ccw_init(reipl_block_ccw
);
1224 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1225 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1226 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1229 reipl_capabilities
|= IPL_TYPE_CCW
;
1233 static int __init
reipl_fcp_init(void)
1237 if (!diag308_set_works
) {
1238 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1239 make_attrs_ro(reipl_fcp_attrs
);
1240 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1245 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1246 if (!reipl_block_fcp
)
1249 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1250 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1252 if (!reipl_fcp_kset
) {
1253 free_page((unsigned long) reipl_block_fcp
);
1257 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1259 kset_unregister(reipl_fcp_kset
);
1260 free_page((unsigned long) reipl_block_fcp
);
1264 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1265 &sys_reipl_fcp_scp_data_attr
);
1267 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1268 kset_unregister(reipl_fcp_kset
);
1269 free_page((unsigned long) reipl_block_fcp
);
1273 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1274 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1276 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1277 * is invalid in the SCSI IPL parameter block, so take it
1278 * always from sclp_ipl_info.
1280 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1283 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1284 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1285 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1286 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1287 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1289 reipl_capabilities
|= IPL_TYPE_FCP
;
1293 static int __init
reipl_type_init(void)
1295 enum ipl_type reipl_type
= ipl_info
.type
;
1296 struct ipl_parameter_block
*reipl_block
;
1299 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1303 * If we have an OS info reipl block, this will be used
1305 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1306 memcpy(reipl_block_fcp
, reipl_block
, size
);
1307 reipl_type
= IPL_TYPE_FCP
;
1308 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1309 memcpy(reipl_block_ccw
, reipl_block
, size
);
1310 reipl_type
= IPL_TYPE_CCW
;
1313 return reipl_set_type(reipl_type
);
1316 static int __init
reipl_init(void)
1320 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1323 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1325 kset_unregister(reipl_kset
);
1328 rc
= reipl_ccw_init();
1331 rc
= reipl_fcp_init();
1334 rc
= reipl_nss_init();
1337 return reipl_type_init();
1340 static struct shutdown_action __refdata reipl_action
= {
1341 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1347 * dump shutdown action: Dump Linux on shutdown.
1350 /* FCP dump device attributes */
1352 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1353 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1354 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1355 dump_block_fcp
->ipl_info
.fcp
.lun
);
1356 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1357 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1358 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1359 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1360 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1361 dump_block_fcp
->ipl_info
.fcp
.devno
);
1363 static struct attribute
*dump_fcp_attrs
[] = {
1364 &sys_dump_fcp_device_attr
.attr
,
1365 &sys_dump_fcp_wwpn_attr
.attr
,
1366 &sys_dump_fcp_lun_attr
.attr
,
1367 &sys_dump_fcp_bootprog_attr
.attr
,
1368 &sys_dump_fcp_br_lba_attr
.attr
,
1372 static struct attribute_group dump_fcp_attr_group
= {
1373 .name
= IPL_FCP_STR
,
1374 .attrs
= dump_fcp_attrs
,
1377 /* CCW dump device attributes */
1379 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1380 dump_block_ccw
->ipl_info
.ccw
.devno
);
1382 static struct attribute
*dump_ccw_attrs
[] = {
1383 &sys_dump_ccw_device_attr
.attr
,
1387 static struct attribute_group dump_ccw_attr_group
= {
1388 .name
= IPL_CCW_STR
,
1389 .attrs
= dump_ccw_attrs
,
1394 static int dump_set_type(enum dump_type type
)
1396 if (!(dump_capabilities
& type
))
1400 if (diag308_set_works
)
1401 dump_method
= DUMP_METHOD_CCW_DIAG
;
1402 else if (MACHINE_IS_VM
)
1403 dump_method
= DUMP_METHOD_CCW_VM
;
1405 dump_method
= DUMP_METHOD_CCW_CIO
;
1408 dump_method
= DUMP_METHOD_FCP_DIAG
;
1411 dump_method
= DUMP_METHOD_NONE
;
1417 static ssize_t
dump_type_show(struct kobject
*kobj
,
1418 struct kobj_attribute
*attr
, char *page
)
1420 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1423 static ssize_t
dump_type_store(struct kobject
*kobj
,
1424 struct kobj_attribute
*attr
,
1425 const char *buf
, size_t len
)
1429 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1430 rc
= dump_set_type(DUMP_TYPE_NONE
);
1431 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1432 rc
= dump_set_type(DUMP_TYPE_CCW
);
1433 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1434 rc
= dump_set_type(DUMP_TYPE_FCP
);
1435 return (rc
!= 0) ? rc
: len
;
1438 static struct kobj_attribute dump_type_attr
=
1439 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1441 static struct kset
*dump_kset
;
1443 static void diag308_dump(void *dump_block
)
1445 diag308(DIAG308_SET
, dump_block
);
1447 if (diag308(DIAG308_DUMP
, NULL
) != 0x302)
1449 udelay_simple(USEC_PER_SEC
);
1453 static void __dump_run(void *unused
)
1455 struct ccw_dev_id devid
;
1456 static char buf
[100];
1458 switch (dump_method
) {
1459 case DUMP_METHOD_CCW_CIO
:
1460 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1462 reipl_ccw_dev(&devid
);
1464 case DUMP_METHOD_CCW_VM
:
1465 sprintf(buf
, "STORE STATUS");
1466 __cpcmd(buf
, NULL
, 0, NULL
);
1467 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1468 __cpcmd(buf
, NULL
, 0, NULL
);
1470 case DUMP_METHOD_CCW_DIAG
:
1471 diag308_dump(dump_block_ccw
);
1473 case DUMP_METHOD_FCP_DIAG
:
1474 diag308_dump(dump_block_fcp
);
1481 static void dump_run(struct shutdown_trigger
*trigger
)
1483 if (dump_method
== DUMP_METHOD_NONE
)
1486 smp_call_ipl_cpu(__dump_run
, NULL
);
1489 static int __init
dump_ccw_init(void)
1493 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1494 if (!dump_block_ccw
)
1496 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1498 free_page((unsigned long)dump_block_ccw
);
1501 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1502 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1503 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1504 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1505 dump_capabilities
|= DUMP_TYPE_CCW
;
1509 static int __init
dump_fcp_init(void)
1513 if (!sclp_ipl_info
.has_dump
)
1514 return 0; /* LDIPL DUMP is not installed */
1515 if (!diag308_set_works
)
1517 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1518 if (!dump_block_fcp
)
1520 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1522 free_page((unsigned long)dump_block_fcp
);
1525 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1526 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1527 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1528 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1529 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1530 dump_capabilities
|= DUMP_TYPE_FCP
;
1534 static int __init
dump_init(void)
1538 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1541 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1543 kset_unregister(dump_kset
);
1546 rc
= dump_ccw_init();
1549 rc
= dump_fcp_init();
1552 dump_set_type(DUMP_TYPE_NONE
);
1556 static struct shutdown_action __refdata dump_action
= {
1557 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1562 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1564 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1567 csum
= csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1568 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1569 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1573 static int __init
dump_reipl_init(void)
1575 if (!diag308_set_works
)
1581 static struct shutdown_action __refdata dump_reipl_action
= {
1582 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1583 .fn
= dump_reipl_run
,
1584 .init
= dump_reipl_init
,
1588 * vmcmd shutdown action: Trigger vm command on shutdown.
1591 static char vmcmd_on_reboot
[128];
1592 static char vmcmd_on_panic
[128];
1593 static char vmcmd_on_halt
[128];
1594 static char vmcmd_on_poff
[128];
1595 static char vmcmd_on_restart
[128];
1597 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1598 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1599 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1600 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1601 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1603 static struct attribute
*vmcmd_attrs
[] = {
1604 &sys_vmcmd_on_reboot_attr
.attr
,
1605 &sys_vmcmd_on_panic_attr
.attr
,
1606 &sys_vmcmd_on_halt_attr
.attr
,
1607 &sys_vmcmd_on_poff_attr
.attr
,
1608 &sys_vmcmd_on_restart_attr
.attr
,
1612 static struct attribute_group vmcmd_attr_group
= {
1613 .attrs
= vmcmd_attrs
,
1616 static struct kset
*vmcmd_kset
;
1618 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1622 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1623 cmd
= vmcmd_on_reboot
;
1624 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1625 cmd
= vmcmd_on_panic
;
1626 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1627 cmd
= vmcmd_on_halt
;
1628 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1629 cmd
= vmcmd_on_poff
;
1630 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1631 cmd
= vmcmd_on_restart
;
1635 if (strlen(cmd
) == 0)
1637 __cpcmd(cmd
, NULL
, 0, NULL
);
1640 static int vmcmd_init(void)
1644 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1647 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1650 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1651 vmcmd_run
, vmcmd_init
};
1654 * stop shutdown action: Stop Linux on shutdown.
1657 static void stop_run(struct shutdown_trigger
*trigger
)
1659 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1660 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1661 disabled_wait((unsigned long) __builtin_return_address(0));
1665 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1670 static struct shutdown_action
*shutdown_actions_list
[] = {
1671 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1672 &vmcmd_action
, &stop_action
};
1673 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1679 static struct kset
*shutdown_actions_kset
;
1681 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1686 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1687 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1688 if (shutdown_actions_list
[i
]->init_rc
) {
1689 return shutdown_actions_list
[i
]->init_rc
;
1691 trigger
->action
= shutdown_actions_list
[i
];
1701 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1704 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1705 struct kobj_attribute
*attr
, char *page
)
1707 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1710 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1711 struct kobj_attribute
*attr
,
1712 const char *buf
, size_t len
)
1714 return set_trigger(buf
, &on_reboot_trigger
, len
);
1717 static struct kobj_attribute on_reboot_attr
=
1718 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1720 static void do_machine_restart(char *__unused
)
1723 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1726 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1730 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1732 static ssize_t
on_panic_show(struct kobject
*kobj
,
1733 struct kobj_attribute
*attr
, char *page
)
1735 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1738 static ssize_t
on_panic_store(struct kobject
*kobj
,
1739 struct kobj_attribute
*attr
,
1740 const char *buf
, size_t len
)
1742 return set_trigger(buf
, &on_panic_trigger
, len
);
1745 static struct kobj_attribute on_panic_attr
=
1746 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1748 static void do_panic(void)
1751 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1752 stop_run(&on_panic_trigger
);
1757 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1760 static ssize_t
on_restart_show(struct kobject
*kobj
,
1761 struct kobj_attribute
*attr
, char *page
)
1763 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1766 static ssize_t
on_restart_store(struct kobject
*kobj
,
1767 struct kobj_attribute
*attr
,
1768 const char *buf
, size_t len
)
1770 return set_trigger(buf
, &on_restart_trigger
, len
);
1773 static struct kobj_attribute on_restart_attr
=
1774 __ATTR(on_restart
, 0644, on_restart_show
, on_restart_store
);
1776 static void __do_restart(void *ignore
)
1778 __arch_local_irq_stosm(0x04); /* enable DAT */
1780 #ifdef CONFIG_CRASH_DUMP
1783 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1784 stop_run(&on_restart_trigger
);
1787 void do_restart(void)
1792 smp_call_online_cpu(__do_restart
, NULL
);
1797 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1799 static ssize_t
on_halt_show(struct kobject
*kobj
,
1800 struct kobj_attribute
*attr
, char *page
)
1802 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1805 static ssize_t
on_halt_store(struct kobject
*kobj
,
1806 struct kobj_attribute
*attr
,
1807 const char *buf
, size_t len
)
1809 return set_trigger(buf
, &on_halt_trigger
, len
);
1812 static struct kobj_attribute on_halt_attr
=
1813 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1816 static void do_machine_halt(void)
1819 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1820 stop_run(&on_halt_trigger
);
1822 void (*_machine_halt
)(void) = do_machine_halt
;
1826 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1828 static ssize_t
on_poff_show(struct kobject
*kobj
,
1829 struct kobj_attribute
*attr
, char *page
)
1831 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1834 static ssize_t
on_poff_store(struct kobject
*kobj
,
1835 struct kobj_attribute
*attr
,
1836 const char *buf
, size_t len
)
1838 return set_trigger(buf
, &on_poff_trigger
, len
);
1841 static struct kobj_attribute on_poff_attr
=
1842 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1845 static void do_machine_power_off(void)
1848 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1849 stop_run(&on_poff_trigger
);
1851 void (*_machine_power_off
)(void) = do_machine_power_off
;
1853 static void __init
shutdown_triggers_init(void)
1855 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1857 if (!shutdown_actions_kset
)
1859 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1860 &on_reboot_attr
.attr
))
1862 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1863 &on_panic_attr
.attr
))
1865 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1866 &on_halt_attr
.attr
))
1868 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1869 &on_poff_attr
.attr
))
1871 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1872 &on_restart_attr
.attr
))
1876 panic("shutdown_triggers_init failed\n");
1879 static void __init
shutdown_actions_init(void)
1883 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1884 if (!shutdown_actions_list
[i
]->init
)
1886 shutdown_actions_list
[i
]->init_rc
=
1887 shutdown_actions_list
[i
]->init();
1891 static int __init
s390_ipl_init(void)
1893 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1895 sclp_get_ipl_info(&sclp_ipl_info
);
1897 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1898 * returned by read SCP info is invalid (contains EBCDIC blanks)
1899 * when the system has been booted via diag308. In that case we use
1900 * the value from diag308, if available.
1902 * There are also systems where diag308 store does not work in
1903 * case the system is booted from HMC. Fortunately in this case
1904 * READ SCP info provides the correct value.
1906 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 &&
1908 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
,
1910 shutdown_actions_init();
1911 shutdown_triggers_init();
1915 __initcall(s390_ipl_init
);
1917 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1922 for (sx
= 0; src
[sx
] != 0; sx
++) {
1925 dst
[dx
++] = src
[sx
];
1931 static int __init
vmcmd_on_reboot_setup(char *str
)
1935 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1936 vmcmd_on_reboot
[127] = 0;
1937 on_reboot_trigger
.action
= &vmcmd_action
;
1940 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1942 static int __init
vmcmd_on_panic_setup(char *str
)
1946 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1947 vmcmd_on_panic
[127] = 0;
1948 on_panic_trigger
.action
= &vmcmd_action
;
1951 __setup("vmpanic=", vmcmd_on_panic_setup
);
1953 static int __init
vmcmd_on_halt_setup(char *str
)
1957 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1958 vmcmd_on_halt
[127] = 0;
1959 on_halt_trigger
.action
= &vmcmd_action
;
1962 __setup("vmhalt=", vmcmd_on_halt_setup
);
1964 static int __init
vmcmd_on_poff_setup(char *str
)
1968 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1969 vmcmd_on_poff
[127] = 0;
1970 on_poff_trigger
.action
= &vmcmd_action
;
1973 __setup("vmpoff=", vmcmd_on_poff_setup
);
1975 static int on_panic_notify(struct notifier_block
*self
,
1976 unsigned long event
, void *data
)
1982 static struct notifier_block on_panic_nb
= {
1983 .notifier_call
= on_panic_notify
,
1984 .priority
= INT_MIN
,
1987 void __init
setup_ipl(void)
1989 ipl_info
.type
= get_ipl_type();
1990 switch (ipl_info
.type
) {
1992 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1993 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1996 case IPL_TYPE_FCP_DUMP
:
1997 ipl_info
.data
.fcp
.dev_id
.devno
=
1998 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1999 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
2000 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
2001 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
2004 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
2005 sizeof(ipl_info
.data
.nss
.name
));
2007 case IPL_TYPE_UNKNOWN
:
2008 /* We have no info to copy */
2011 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
2014 void __init
ipl_update_parameters(void)
2018 rc
= diag308(DIAG308_STORE
, &ipl_block
);
2019 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
2020 diag308_set_works
= 1;
2023 void __init
ipl_save_parameters(void)
2025 struct cio_iplinfo iplinfo
;
2028 if (cio_get_iplinfo(&iplinfo
))
2031 ipl_devno
= iplinfo
.devno
;
2032 ipl_flags
|= IPL_DEVNO_VALID
;
2033 if (!iplinfo
.is_qdio
)
2035 ipl_flags
|= IPL_PARMBLOCK_VALID
;
2036 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
2037 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
2038 memmove(dst
, src
, PAGE_SIZE
);
2039 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
2042 static LIST_HEAD(rcall
);
2043 static DEFINE_MUTEX(rcall_mutex
);
2045 void register_reset_call(struct reset_call
*reset
)
2047 mutex_lock(&rcall_mutex
);
2048 list_add(&reset
->list
, &rcall
);
2049 mutex_unlock(&rcall_mutex
);
2051 EXPORT_SYMBOL_GPL(register_reset_call
);
2053 void unregister_reset_call(struct reset_call
*reset
)
2055 mutex_lock(&rcall_mutex
);
2056 list_del(&reset
->list
);
2057 mutex_unlock(&rcall_mutex
);
2059 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2061 static void do_reset_calls(void)
2063 struct reset_call
*reset
;
2066 if (diag308_set_works
) {
2071 list_for_each_entry(reset
, &rcall
, list
)
2075 u32 dump_prefix_page
;
2077 void s390_reset_system(void (*func
)(void *), void *data
)
2079 struct _lowcore
*lc
;
2081 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
2083 /* Stack for interrupt/machine check handler */
2084 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2086 /* Save prefix page address for dump case */
2087 dump_prefix_page
= (u32
)(unsigned long) lc
;
2089 /* Disable prefixing */
2092 /* Disable lowcore protection */
2093 __ctl_clear_bit(0,28);
2095 /* Set new machine check handler */
2096 S390_lowcore
.mcck_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2097 S390_lowcore
.mcck_new_psw
.addr
=
2098 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
2100 /* Set new program check handler */
2101 S390_lowcore
.program_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2102 S390_lowcore
.program_new_psw
.addr
=
2103 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;
2106 * Clear subchannel ID and number to signal new kernel that no CCW or
2107 * SCSI IPL has been done (for kexec and kdump)
2109 S390_lowcore
.subchannel_id
= 0;
2110 S390_lowcore
.subchannel_nr
= 0;
2112 /* Store status at absolute zero */