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/export.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
18 #include <linux/gfp.h>
19 #include <linux/crash_dump.h>
20 #include <linux/debug_locks.h>
24 #include <asm/setup.h>
25 #include <asm/cpcmd.h>
27 #include <asm/ebcdic.h>
28 #include <asm/reset.h>
30 #include <asm/checksum.h>
31 #include <asm/debug.h>
32 #include <asm/os_info.h>
35 #define IPL_PARM_BLOCK_VERSION 0
37 #define IPL_UNKNOWN_STR "unknown"
38 #define IPL_CCW_STR "ccw"
39 #define IPL_FCP_STR "fcp"
40 #define IPL_FCP_DUMP_STR "fcp_dump"
41 #define IPL_NSS_STR "nss"
43 #define DUMP_CCW_STR "ccw"
44 #define DUMP_FCP_STR "fcp"
45 #define DUMP_NONE_STR "none"
48 * Four shutdown trigger types are supported:
55 #define ON_PANIC_STR "on_panic"
56 #define ON_HALT_STR "on_halt"
57 #define ON_POFF_STR "on_poff"
58 #define ON_REIPL_STR "on_reboot"
59 #define ON_RESTART_STR "on_restart"
61 struct shutdown_action
;
62 struct shutdown_trigger
{
64 struct shutdown_action
*action
;
68 * The following shutdown action types are supported:
70 #define SHUTDOWN_ACTION_IPL_STR "ipl"
71 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
72 #define SHUTDOWN_ACTION_DUMP_STR "dump"
73 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
74 #define SHUTDOWN_ACTION_STOP_STR "stop"
75 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
77 struct shutdown_action
{
79 void (*fn
) (struct shutdown_trigger
*trigger
);
84 static char *ipl_type_str(enum ipl_type type
)
91 case IPL_TYPE_FCP_DUMP
:
92 return IPL_FCP_DUMP_STR
;
95 case IPL_TYPE_UNKNOWN
:
97 return IPL_UNKNOWN_STR
;
107 static char *dump_type_str(enum dump_type type
)
111 return DUMP_NONE_STR
;
122 * Must be in data section since the bss section
123 * is not cleared when these are accessed.
125 static u8 ipl_ssid
__section(.data
) = 0;
126 static u16 ipl_devno
__section(.data
) = 0;
127 u32 ipl_flags
__section(.data
) = 0;
130 REIPL_METHOD_CCW_CIO
,
131 REIPL_METHOD_CCW_DIAG
,
133 REIPL_METHOD_FCP_RO_DIAG
,
134 REIPL_METHOD_FCP_RW_DIAG
,
135 REIPL_METHOD_FCP_RO_VM
,
136 REIPL_METHOD_FCP_DUMP
,
138 REIPL_METHOD_NSS_DIAG
,
139 REIPL_METHOD_DEFAULT
,
145 DUMP_METHOD_CCW_DIAG
,
147 DUMP_METHOD_FCP_DIAG
,
150 static int diag308_set_works
= 0;
152 static struct ipl_parameter_block ipl_block
;
154 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
156 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
157 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
158 static struct ipl_parameter_block
*reipl_block_fcp
;
159 static struct ipl_parameter_block
*reipl_block_ccw
;
160 static struct ipl_parameter_block
*reipl_block_nss
;
161 static struct ipl_parameter_block
*reipl_block_actual
;
163 static int dump_capabilities
= DUMP_TYPE_NONE
;
164 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
165 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
166 static struct ipl_parameter_block
*dump_block_fcp
;
167 static struct ipl_parameter_block
*dump_block_ccw
;
169 static struct sclp_ipl_info sclp_ipl_info
;
171 static inline int __diag308(unsigned long subcode
, void *addr
)
173 register unsigned long _addr
asm("0") = (unsigned long) addr
;
174 register unsigned long _rc
asm("1") = 0;
177 " diag %0,%2,0x308\n"
180 : "+d" (_addr
), "+d" (_rc
)
181 : "d" (subcode
) : "cc", "memory");
185 int diag308(unsigned long subcode
, void *addr
)
187 diag_stat_inc(DIAG_STAT_X308
);
188 return __diag308(subcode
, addr
);
190 EXPORT_SYMBOL_GPL(diag308
);
194 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
195 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
196 struct kobj_attribute *attr, \
199 return snprintf(page, PAGE_SIZE, _format, ##args); \
202 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
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 ssid, devno; \
209 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
212 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
215 _ipl_blk.ssid = ssid; \
216 _ipl_blk.devno = devno; \
220 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
221 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
222 _ipl_blk.ssid, _ipl_blk.devno); \
223 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
224 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
225 __ATTR(_name, (S_IRUGO | S_IWUSR), \
226 sys_##_prefix##_##_name##_show, \
227 sys_##_prefix##_##_name##_store) \
229 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
230 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
231 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
232 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
234 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
235 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
236 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
237 struct kobj_attribute *attr, \
238 const char *buf, size_t len) \
240 unsigned long long value; \
241 if (sscanf(buf, _fmt_in, &value) != 1) \
246 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
247 __ATTR(_name,(S_IRUGO | S_IWUSR), \
248 sys_##_prefix##_##_name##_show, \
249 sys_##_prefix##_##_name##_store)
251 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
252 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
253 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
254 struct kobj_attribute *attr, \
255 const char *buf, size_t len) \
257 strncpy(_value, buf, sizeof(_value) - 1); \
261 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
262 __ATTR(_name,(S_IRUGO | S_IWUSR), \
263 sys_##_prefix##_##_name##_show, \
264 sys_##_prefix##_##_name##_store)
266 static void make_attrs_ro(struct attribute
**attrs
)
269 (*attrs
)->mode
= S_IRUGO
;
278 static __init
enum ipl_type
get_ipl_type(void)
280 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
282 if (!(ipl_flags
& IPL_DEVNO_VALID
))
283 return IPL_TYPE_UNKNOWN
;
284 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
286 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
287 return IPL_TYPE_UNKNOWN
;
288 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
289 return IPL_TYPE_UNKNOWN
;
290 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
291 return IPL_TYPE_FCP_DUMP
;
295 struct ipl_info ipl_info
;
296 EXPORT_SYMBOL_GPL(ipl_info
);
298 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
301 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
304 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
306 /* VM IPL PARM routines */
307 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
308 const struct ipl_parameter_block
*ipb
)
312 char has_lowercase
= 0;
315 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
316 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
318 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
319 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
320 /* If at least one character is lowercase, we assume mixed
321 * case; otherwise we convert everything to lowercase.
323 for (i
= 0; i
< len
; i
++)
324 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
325 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
326 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
331 EBC_TOLOWER(dest
, len
);
339 size_t append_ipl_vmparm(char *dest
, size_t size
)
344 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
345 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
351 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
352 struct kobj_attribute
*attr
, char *page
)
354 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
356 append_ipl_vmparm(parm
, sizeof(parm
));
357 return sprintf(page
, "%s\n", parm
);
360 static size_t scpdata_length(const char* buf
, size_t count
)
363 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
370 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
371 const struct ipl_parameter_block
*ipb
)
377 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
378 ipb
->ipl_info
.fcp
.scp_data_len
));
383 for (i
= 0; i
< count
; i
++) {
384 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
388 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
393 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
395 for (i
= 0; i
< count
; i
++)
396 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
402 size_t append_ipl_scpdata(char *dest
, size_t len
)
407 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
408 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
415 static struct kobj_attribute sys_ipl_vm_parm_attr
=
416 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
418 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
419 struct kobj_attribute
*attr
, char *page
)
421 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
423 switch (ipl_info
.type
) {
425 return sprintf(page
, "0.%x.%04x\n", ipl_ssid
, ipl_devno
);
427 case IPL_TYPE_FCP_DUMP
:
428 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
434 static struct kobj_attribute sys_ipl_device_attr
=
435 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
437 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
438 struct bin_attribute
*attr
, char *buf
,
439 loff_t off
, size_t count
)
441 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
444 static struct bin_attribute ipl_parameter_attr
=
445 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
448 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
449 struct bin_attribute
*attr
, char *buf
,
450 loff_t off
, size_t count
)
452 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
453 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
455 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
457 static struct bin_attribute ipl_scp_data_attr
=
458 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
460 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
466 /* FCP ipl device attributes */
468 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
469 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
470 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
471 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
472 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
473 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
474 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
475 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
477 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
478 struct kobj_attribute
*attr
, char *page
)
480 char loadparm
[LOADPARM_LEN
+ 1] = {};
482 if (!sclp_ipl_info
.is_valid
)
483 return sprintf(page
, "#unknown#\n");
484 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
485 EBCASC(loadparm
, LOADPARM_LEN
);
487 return sprintf(page
, "%s\n", loadparm
);
490 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
491 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
493 static struct attribute
*ipl_fcp_attrs
[] = {
494 &sys_ipl_type_attr
.attr
,
495 &sys_ipl_device_attr
.attr
,
496 &sys_ipl_fcp_wwpn_attr
.attr
,
497 &sys_ipl_fcp_lun_attr
.attr
,
498 &sys_ipl_fcp_bootprog_attr
.attr
,
499 &sys_ipl_fcp_br_lba_attr
.attr
,
500 &sys_ipl_ccw_loadparm_attr
.attr
,
504 static struct attribute_group ipl_fcp_attr_group
= {
505 .attrs
= ipl_fcp_attrs
,
506 .bin_attrs
= ipl_fcp_bin_attrs
,
509 /* CCW ipl device attributes */
511 static struct attribute
*ipl_ccw_attrs_vm
[] = {
512 &sys_ipl_type_attr
.attr
,
513 &sys_ipl_device_attr
.attr
,
514 &sys_ipl_ccw_loadparm_attr
.attr
,
515 &sys_ipl_vm_parm_attr
.attr
,
519 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
520 &sys_ipl_type_attr
.attr
,
521 &sys_ipl_device_attr
.attr
,
522 &sys_ipl_ccw_loadparm_attr
.attr
,
526 static struct attribute_group ipl_ccw_attr_group_vm
= {
527 .attrs
= ipl_ccw_attrs_vm
,
530 static struct attribute_group ipl_ccw_attr_group_lpar
= {
531 .attrs
= ipl_ccw_attrs_lpar
534 /* UNKNOWN ipl device attributes */
536 static struct attribute
*ipl_unknown_attrs
[] = {
537 &sys_ipl_type_attr
.attr
,
541 static struct attribute_group ipl_unknown_attr_group
= {
542 .attrs
= ipl_unknown_attrs
,
545 static struct kset
*ipl_kset
;
547 static void __ipl_run(void *unused
)
549 diag308(DIAG308_LOAD_CLEAR
, NULL
);
551 __cpcmd("IPL", NULL
, 0, NULL
);
552 else if (ipl_info
.type
== IPL_TYPE_CCW
)
553 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
556 static void ipl_run(struct shutdown_trigger
*trigger
)
558 smp_call_ipl_cpu(__ipl_run
, NULL
);
561 static int __init
ipl_init(void)
565 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
570 switch (ipl_info
.type
) {
573 rc
= sysfs_create_group(&ipl_kset
->kobj
,
574 &ipl_ccw_attr_group_vm
);
576 rc
= sysfs_create_group(&ipl_kset
->kobj
,
577 &ipl_ccw_attr_group_lpar
);
580 case IPL_TYPE_FCP_DUMP
:
581 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
584 rc
= sysfs_create_group(&ipl_kset
->kobj
,
585 &ipl_unknown_attr_group
);
590 panic("ipl_init failed: rc = %i\n", rc
);
595 static struct shutdown_action __refdata ipl_action
= {
596 .name
= SHUTDOWN_ACTION_IPL_STR
,
602 * reipl shutdown action: Reboot Linux on shutdown.
605 /* VM IPL PARM attributes */
606 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
609 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
611 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
612 return sprintf(page
, "%s\n", vmparm
);
615 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
617 const char *buf
, size_t len
)
621 /* ignore trailing newline */
623 if ((len
> 0) && (buf
[len
- 1] == '\n'))
626 if (ip_len
> vmparm_max
)
629 /* parm is used to store kernel options, check for common chars */
630 for (i
= 0; i
< ip_len
; i
++)
631 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
634 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
635 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
637 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
638 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
639 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
641 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
648 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
649 struct kobj_attribute
*attr
, char *page
)
651 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
654 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
655 struct kobj_attribute
*attr
,
656 const char *buf
, size_t len
)
658 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
662 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
663 struct kobj_attribute
*attr
, char *page
)
665 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
668 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
669 struct kobj_attribute
*attr
,
670 const char *buf
, size_t len
)
672 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
675 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
676 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
677 reipl_nss_vmparm_store
);
678 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
679 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
680 reipl_ccw_vmparm_store
);
682 /* FCP reipl device attributes */
684 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
685 struct bin_attribute
*attr
,
686 char *buf
, loff_t off
, size_t count
)
688 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
689 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
691 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
694 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
695 struct bin_attribute
*attr
,
696 char *buf
, loff_t off
, size_t count
)
698 size_t scpdata_len
= count
;
705 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
, count
);
706 if (scpdata_len
% 8) {
707 padding
= 8 - (scpdata_len
% 8);
708 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
710 scpdata_len
+= padding
;
713 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
714 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
715 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
719 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
720 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
721 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
723 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
724 &sys_reipl_fcp_scp_data_attr
,
728 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
729 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
730 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
731 reipl_block_fcp
->ipl_info
.fcp
.lun
);
732 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
733 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
734 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
735 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
736 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
737 reipl_block_fcp
->ipl_info
.fcp
.devno
);
739 static void reipl_get_ascii_loadparm(char *loadparm
,
740 struct ipl_parameter_block
*ibp
)
742 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
743 EBCASC(loadparm
, LOADPARM_LEN
);
744 loadparm
[LOADPARM_LEN
] = 0;
748 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
751 char buf
[LOADPARM_LEN
+ 1];
753 reipl_get_ascii_loadparm(buf
, ipb
);
754 return sprintf(page
, "%s\n", buf
);
757 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
758 const char *buf
, size_t len
)
762 /* ignore trailing newline */
764 if ((len
> 0) && (buf
[len
- 1] == '\n'))
766 /* loadparm can have max 8 characters and must not start with a blank */
767 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
769 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
770 for (i
= 0; i
< lp_len
; i
++) {
771 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
776 /* initialize loadparm with blanks */
777 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
778 /* copy and convert to ebcdic */
779 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
780 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
785 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
786 struct kobj_attribute
*attr
, char *page
)
788 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
791 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
792 struct kobj_attribute
*attr
,
793 const char *buf
, size_t len
)
795 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
798 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
799 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
800 reipl_fcp_loadparm_store
);
802 static struct attribute
*reipl_fcp_attrs
[] = {
803 &sys_reipl_fcp_device_attr
.attr
,
804 &sys_reipl_fcp_wwpn_attr
.attr
,
805 &sys_reipl_fcp_lun_attr
.attr
,
806 &sys_reipl_fcp_bootprog_attr
.attr
,
807 &sys_reipl_fcp_br_lba_attr
.attr
,
808 &sys_reipl_fcp_loadparm_attr
.attr
,
812 static struct attribute_group reipl_fcp_attr_group
= {
813 .attrs
= reipl_fcp_attrs
,
814 .bin_attrs
= reipl_fcp_bin_attrs
,
817 /* CCW reipl device attributes */
818 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ipl_info
.ccw
);
821 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
822 struct kobj_attribute
*attr
, char *page
)
824 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
827 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
828 struct kobj_attribute
*attr
,
829 const char *buf
, size_t len
)
831 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
835 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
836 struct kobj_attribute
*attr
, char *page
)
838 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
841 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
842 struct kobj_attribute
*attr
,
843 const char *buf
, size_t len
)
845 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
848 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
849 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
850 reipl_ccw_loadparm_store
);
852 static struct attribute
*reipl_ccw_attrs_vm
[] = {
853 &sys_reipl_ccw_device_attr
.attr
,
854 &sys_reipl_ccw_loadparm_attr
.attr
,
855 &sys_reipl_ccw_vmparm_attr
.attr
,
859 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
860 &sys_reipl_ccw_device_attr
.attr
,
861 &sys_reipl_ccw_loadparm_attr
.attr
,
865 static struct attribute_group reipl_ccw_attr_group_vm
= {
867 .attrs
= reipl_ccw_attrs_vm
,
870 static struct attribute_group reipl_ccw_attr_group_lpar
= {
872 .attrs
= reipl_ccw_attrs_lpar
,
876 /* NSS reipl device attributes */
877 static void reipl_get_ascii_nss_name(char *dst
,
878 struct ipl_parameter_block
*ipb
)
880 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
881 EBCASC(dst
, NSS_NAME_SIZE
);
882 dst
[NSS_NAME_SIZE
] = 0;
885 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
886 struct kobj_attribute
*attr
, char *page
)
888 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
890 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
891 return sprintf(page
, "%s\n", nss_name
);
894 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
895 struct kobj_attribute
*attr
,
896 const char *buf
, size_t len
)
900 /* ignore trailing newline */
902 if ((len
> 0) && (buf
[len
- 1] == '\n'))
905 if (nss_len
> NSS_NAME_SIZE
)
908 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
910 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
911 DIAG308_VM_FLAGS_NSS_VALID
;
912 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
913 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
914 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
916 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
917 ~DIAG308_VM_FLAGS_NSS_VALID
;
923 static struct kobj_attribute sys_reipl_nss_name_attr
=
924 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
925 reipl_nss_name_store
);
927 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
928 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
929 reipl_nss_loadparm_store
);
931 static struct attribute
*reipl_nss_attrs
[] = {
932 &sys_reipl_nss_name_attr
.attr
,
933 &sys_reipl_nss_loadparm_attr
.attr
,
934 &sys_reipl_nss_vmparm_attr
.attr
,
938 static struct attribute_group reipl_nss_attr_group
= {
940 .attrs
= reipl_nss_attrs
,
943 static void set_reipl_block_actual(struct ipl_parameter_block
*reipl_block
)
945 reipl_block_actual
= reipl_block
;
946 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
947 reipl_block
->hdr
.len
);
952 static int reipl_set_type(enum ipl_type type
)
954 if (!(reipl_capabilities
& type
))
959 if (diag308_set_works
)
960 reipl_method
= REIPL_METHOD_CCW_DIAG
;
961 else if (MACHINE_IS_VM
)
962 reipl_method
= REIPL_METHOD_CCW_VM
;
964 reipl_method
= REIPL_METHOD_CCW_CIO
;
965 set_reipl_block_actual(reipl_block_ccw
);
968 if (diag308_set_works
)
969 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
970 else if (MACHINE_IS_VM
)
971 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
973 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
974 set_reipl_block_actual(reipl_block_fcp
);
976 case IPL_TYPE_FCP_DUMP
:
977 reipl_method
= REIPL_METHOD_FCP_DUMP
;
980 if (diag308_set_works
)
981 reipl_method
= REIPL_METHOD_NSS_DIAG
;
983 reipl_method
= REIPL_METHOD_NSS
;
984 set_reipl_block_actual(reipl_block_nss
);
986 case IPL_TYPE_UNKNOWN
:
987 reipl_method
= REIPL_METHOD_DEFAULT
;
996 static ssize_t
reipl_type_show(struct kobject
*kobj
,
997 struct kobj_attribute
*attr
, char *page
)
999 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1002 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1003 struct kobj_attribute
*attr
,
1004 const char *buf
, size_t len
)
1008 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1009 rc
= reipl_set_type(IPL_TYPE_CCW
);
1010 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1011 rc
= reipl_set_type(IPL_TYPE_FCP
);
1012 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1013 rc
= reipl_set_type(IPL_TYPE_NSS
);
1014 return (rc
!= 0) ? rc
: len
;
1017 static struct kobj_attribute reipl_type_attr
=
1018 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1020 static struct kset
*reipl_kset
;
1021 static struct kset
*reipl_fcp_kset
;
1023 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1024 const enum ipl_method m
)
1026 char loadparm
[LOADPARM_LEN
+ 1] = {};
1027 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1028 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1031 reipl_get_ascii_loadparm(loadparm
, ipb
);
1032 reipl_get_ascii_nss_name(nss_name
, ipb
);
1033 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1036 case REIPL_METHOD_CCW_VM
:
1037 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1039 case REIPL_METHOD_NSS
:
1040 pos
= sprintf(dst
, "IPL %s", nss_name
);
1045 if (strlen(loadparm
) > 0)
1046 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1047 if (strlen(vmparm
) > 0)
1048 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1051 static void __reipl_run(void *unused
)
1053 struct ccw_dev_id devid
;
1054 static char buf
[128];
1056 switch (reipl_method
) {
1057 case REIPL_METHOD_CCW_CIO
:
1058 devid
.ssid
= reipl_block_ccw
->ipl_info
.ccw
.ssid
;
1059 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1060 reipl_ccw_dev(&devid
);
1062 case REIPL_METHOD_CCW_VM
:
1063 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1064 __cpcmd(buf
, NULL
, 0, NULL
);
1066 case REIPL_METHOD_CCW_DIAG
:
1067 diag308(DIAG308_SET
, reipl_block_ccw
);
1068 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1070 case REIPL_METHOD_FCP_RW_DIAG
:
1071 diag308(DIAG308_SET
, reipl_block_fcp
);
1072 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1074 case REIPL_METHOD_FCP_RO_DIAG
:
1075 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1077 case REIPL_METHOD_FCP_RO_VM
:
1078 __cpcmd("IPL", NULL
, 0, NULL
);
1080 case REIPL_METHOD_NSS_DIAG
:
1081 diag308(DIAG308_SET
, reipl_block_nss
);
1082 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1084 case REIPL_METHOD_NSS
:
1085 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1086 __cpcmd(buf
, NULL
, 0, NULL
);
1088 case REIPL_METHOD_DEFAULT
:
1090 __cpcmd("IPL", NULL
, 0, NULL
);
1091 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1093 case REIPL_METHOD_FCP_DUMP
:
1096 disabled_wait((unsigned long) __builtin_return_address(0));
1099 static void reipl_run(struct shutdown_trigger
*trigger
)
1101 smp_call_ipl_cpu(__reipl_run
, NULL
);
1104 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1106 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1107 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1108 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1109 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1112 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1115 /* check if read scp info worked and set loadparm */
1116 if (sclp_ipl_info
.is_valid
)
1117 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1119 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1120 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
1121 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1124 if (MACHINE_IS_VM
&& diag308_set_works
&&
1125 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1127 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1128 ipb
->ipl_info
.ccw
.vm_parm_len
=
1129 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1130 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1131 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1135 static int __init
reipl_nss_init(void)
1142 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1143 if (!reipl_block_nss
)
1146 if (!diag308_set_works
)
1147 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1149 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1153 reipl_block_ccw_init(reipl_block_nss
);
1154 reipl_capabilities
|= IPL_TYPE_NSS
;
1158 static int __init
reipl_ccw_init(void)
1162 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1163 if (!reipl_block_ccw
)
1166 if (MACHINE_IS_VM
) {
1167 if (!diag308_set_works
)
1168 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1169 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1170 &reipl_ccw_attr_group_vm
);
1172 if(!diag308_set_works
)
1173 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1174 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1175 &reipl_ccw_attr_group_lpar
);
1180 reipl_block_ccw_init(reipl_block_ccw
);
1181 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1182 reipl_block_ccw
->ipl_info
.ccw
.ssid
= ipl_ssid
;
1183 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1184 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1187 reipl_capabilities
|= IPL_TYPE_CCW
;
1191 static int __init
reipl_fcp_init(void)
1195 if (!diag308_set_works
) {
1196 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1197 make_attrs_ro(reipl_fcp_attrs
);
1198 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1203 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1204 if (!reipl_block_fcp
)
1207 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1208 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1210 if (!reipl_fcp_kset
) {
1211 free_page((unsigned long) reipl_block_fcp
);
1215 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1217 kset_unregister(reipl_fcp_kset
);
1218 free_page((unsigned long) reipl_block_fcp
);
1222 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1223 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1225 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1226 * is invalid in the SCSI IPL parameter block, so take it
1227 * always from sclp_ipl_info.
1229 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1232 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1233 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1234 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1235 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1236 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1238 reipl_capabilities
|= IPL_TYPE_FCP
;
1242 static int __init
reipl_type_init(void)
1244 enum ipl_type reipl_type
= ipl_info
.type
;
1245 struct ipl_parameter_block
*reipl_block
;
1248 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1252 * If we have an OS info reipl block, this will be used
1254 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1255 memcpy(reipl_block_fcp
, reipl_block
, size
);
1256 reipl_type
= IPL_TYPE_FCP
;
1257 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1258 memcpy(reipl_block_ccw
, reipl_block
, size
);
1259 reipl_type
= IPL_TYPE_CCW
;
1262 return reipl_set_type(reipl_type
);
1265 static int __init
reipl_init(void)
1269 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1272 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1274 kset_unregister(reipl_kset
);
1277 rc
= reipl_ccw_init();
1280 rc
= reipl_fcp_init();
1283 rc
= reipl_nss_init();
1286 return reipl_type_init();
1289 static struct shutdown_action __refdata reipl_action
= {
1290 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1296 * dump shutdown action: Dump Linux on shutdown.
1299 /* FCP dump device attributes */
1301 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1302 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1303 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1304 dump_block_fcp
->ipl_info
.fcp
.lun
);
1305 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1306 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1307 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1308 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1309 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1310 dump_block_fcp
->ipl_info
.fcp
.devno
);
1312 static struct attribute
*dump_fcp_attrs
[] = {
1313 &sys_dump_fcp_device_attr
.attr
,
1314 &sys_dump_fcp_wwpn_attr
.attr
,
1315 &sys_dump_fcp_lun_attr
.attr
,
1316 &sys_dump_fcp_bootprog_attr
.attr
,
1317 &sys_dump_fcp_br_lba_attr
.attr
,
1321 static struct attribute_group dump_fcp_attr_group
= {
1322 .name
= IPL_FCP_STR
,
1323 .attrs
= dump_fcp_attrs
,
1326 /* CCW dump device attributes */
1327 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ipl_info
.ccw
);
1329 static struct attribute
*dump_ccw_attrs
[] = {
1330 &sys_dump_ccw_device_attr
.attr
,
1334 static struct attribute_group dump_ccw_attr_group
= {
1335 .name
= IPL_CCW_STR
,
1336 .attrs
= dump_ccw_attrs
,
1341 static int dump_set_type(enum dump_type type
)
1343 if (!(dump_capabilities
& type
))
1347 if (diag308_set_works
)
1348 dump_method
= DUMP_METHOD_CCW_DIAG
;
1349 else if (MACHINE_IS_VM
)
1350 dump_method
= DUMP_METHOD_CCW_VM
;
1352 dump_method
= DUMP_METHOD_CCW_CIO
;
1355 dump_method
= DUMP_METHOD_FCP_DIAG
;
1358 dump_method
= DUMP_METHOD_NONE
;
1364 static ssize_t
dump_type_show(struct kobject
*kobj
,
1365 struct kobj_attribute
*attr
, char *page
)
1367 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1370 static ssize_t
dump_type_store(struct kobject
*kobj
,
1371 struct kobj_attribute
*attr
,
1372 const char *buf
, size_t len
)
1376 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1377 rc
= dump_set_type(DUMP_TYPE_NONE
);
1378 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1379 rc
= dump_set_type(DUMP_TYPE_CCW
);
1380 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1381 rc
= dump_set_type(DUMP_TYPE_FCP
);
1382 return (rc
!= 0) ? rc
: len
;
1385 static struct kobj_attribute dump_type_attr
=
1386 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1388 static struct kset
*dump_kset
;
1390 static void diag308_dump(void *dump_block
)
1392 diag308(DIAG308_SET
, dump_block
);
1394 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1396 udelay_simple(USEC_PER_SEC
);
1400 static void __dump_run(void *unused
)
1402 struct ccw_dev_id devid
;
1403 static char buf
[100];
1405 switch (dump_method
) {
1406 case DUMP_METHOD_CCW_CIO
:
1407 devid
.ssid
= dump_block_ccw
->ipl_info
.ccw
.ssid
;
1408 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1409 reipl_ccw_dev(&devid
);
1411 case DUMP_METHOD_CCW_VM
:
1412 sprintf(buf
, "STORE STATUS");
1413 __cpcmd(buf
, NULL
, 0, NULL
);
1414 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1415 __cpcmd(buf
, NULL
, 0, NULL
);
1417 case DUMP_METHOD_CCW_DIAG
:
1418 diag308_dump(dump_block_ccw
);
1420 case DUMP_METHOD_FCP_DIAG
:
1421 diag308_dump(dump_block_fcp
);
1428 static void dump_run(struct shutdown_trigger
*trigger
)
1430 if (dump_method
== DUMP_METHOD_NONE
)
1433 smp_call_ipl_cpu(__dump_run
, NULL
);
1436 static int __init
dump_ccw_init(void)
1440 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1441 if (!dump_block_ccw
)
1443 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1445 free_page((unsigned long)dump_block_ccw
);
1448 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1449 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1450 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1451 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1452 dump_capabilities
|= DUMP_TYPE_CCW
;
1456 static int __init
dump_fcp_init(void)
1460 if (!sclp_ipl_info
.has_dump
)
1461 return 0; /* LDIPL DUMP is not installed */
1462 if (!diag308_set_works
)
1464 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1465 if (!dump_block_fcp
)
1467 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1469 free_page((unsigned long)dump_block_fcp
);
1472 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1473 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1474 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1475 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1476 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1477 dump_capabilities
|= DUMP_TYPE_FCP
;
1481 static int __init
dump_init(void)
1485 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1488 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1490 kset_unregister(dump_kset
);
1493 rc
= dump_ccw_init();
1496 rc
= dump_fcp_init();
1499 dump_set_type(DUMP_TYPE_NONE
);
1503 static struct shutdown_action __refdata dump_action
= {
1504 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1509 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1511 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1514 csum
= (__force
unsigned int)
1515 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1516 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1517 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1521 static int __init
dump_reipl_init(void)
1523 if (!diag308_set_works
)
1529 static struct shutdown_action __refdata dump_reipl_action
= {
1530 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1531 .fn
= dump_reipl_run
,
1532 .init
= dump_reipl_init
,
1536 * vmcmd shutdown action: Trigger vm command on shutdown.
1539 static char vmcmd_on_reboot
[128];
1540 static char vmcmd_on_panic
[128];
1541 static char vmcmd_on_halt
[128];
1542 static char vmcmd_on_poff
[128];
1543 static char vmcmd_on_restart
[128];
1545 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1546 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1547 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1548 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1549 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1551 static struct attribute
*vmcmd_attrs
[] = {
1552 &sys_vmcmd_on_reboot_attr
.attr
,
1553 &sys_vmcmd_on_panic_attr
.attr
,
1554 &sys_vmcmd_on_halt_attr
.attr
,
1555 &sys_vmcmd_on_poff_attr
.attr
,
1556 &sys_vmcmd_on_restart_attr
.attr
,
1560 static struct attribute_group vmcmd_attr_group
= {
1561 .attrs
= vmcmd_attrs
,
1564 static struct kset
*vmcmd_kset
;
1566 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1570 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1571 cmd
= vmcmd_on_reboot
;
1572 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1573 cmd
= vmcmd_on_panic
;
1574 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1575 cmd
= vmcmd_on_halt
;
1576 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1577 cmd
= vmcmd_on_poff
;
1578 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1579 cmd
= vmcmd_on_restart
;
1583 if (strlen(cmd
) == 0)
1585 __cpcmd(cmd
, NULL
, 0, NULL
);
1588 static int vmcmd_init(void)
1592 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1595 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1598 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1599 vmcmd_run
, vmcmd_init
};
1602 * stop shutdown action: Stop Linux on shutdown.
1605 static void stop_run(struct shutdown_trigger
*trigger
)
1607 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1608 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1609 disabled_wait((unsigned long) __builtin_return_address(0));
1613 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1618 static struct shutdown_action
*shutdown_actions_list
[] = {
1619 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1620 &vmcmd_action
, &stop_action
};
1621 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1627 static struct kset
*shutdown_actions_kset
;
1629 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1634 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1635 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1636 if (shutdown_actions_list
[i
]->init_rc
) {
1637 return shutdown_actions_list
[i
]->init_rc
;
1639 trigger
->action
= shutdown_actions_list
[i
];
1649 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1652 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1653 struct kobj_attribute
*attr
, char *page
)
1655 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1658 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1659 struct kobj_attribute
*attr
,
1660 const char *buf
, size_t len
)
1662 return set_trigger(buf
, &on_reboot_trigger
, len
);
1664 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1666 static void do_machine_restart(char *__unused
)
1669 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1672 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1676 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1678 static ssize_t
on_panic_show(struct kobject
*kobj
,
1679 struct kobj_attribute
*attr
, char *page
)
1681 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1684 static ssize_t
on_panic_store(struct kobject
*kobj
,
1685 struct kobj_attribute
*attr
,
1686 const char *buf
, size_t len
)
1688 return set_trigger(buf
, &on_panic_trigger
, len
);
1690 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1692 static void do_panic(void)
1695 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1696 stop_run(&on_panic_trigger
);
1701 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1704 static ssize_t
on_restart_show(struct kobject
*kobj
,
1705 struct kobj_attribute
*attr
, char *page
)
1707 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1710 static ssize_t
on_restart_store(struct kobject
*kobj
,
1711 struct kobj_attribute
*attr
,
1712 const char *buf
, size_t len
)
1714 return set_trigger(buf
, &on_restart_trigger
, len
);
1716 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1718 static void __do_restart(void *ignore
)
1720 __arch_local_irq_stosm(0x04); /* enable DAT */
1722 #ifdef CONFIG_CRASH_DUMP
1725 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1726 stop_run(&on_restart_trigger
);
1729 void do_restart(void)
1734 smp_call_online_cpu(__do_restart
, NULL
);
1739 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1741 static ssize_t
on_halt_show(struct kobject
*kobj
,
1742 struct kobj_attribute
*attr
, char *page
)
1744 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1747 static ssize_t
on_halt_store(struct kobject
*kobj
,
1748 struct kobj_attribute
*attr
,
1749 const char *buf
, size_t len
)
1751 return set_trigger(buf
, &on_halt_trigger
, len
);
1753 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1755 static void do_machine_halt(void)
1758 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1759 stop_run(&on_halt_trigger
);
1761 void (*_machine_halt
)(void) = do_machine_halt
;
1765 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1767 static ssize_t
on_poff_show(struct kobject
*kobj
,
1768 struct kobj_attribute
*attr
, char *page
)
1770 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1773 static ssize_t
on_poff_store(struct kobject
*kobj
,
1774 struct kobj_attribute
*attr
,
1775 const char *buf
, size_t len
)
1777 return set_trigger(buf
, &on_poff_trigger
, len
);
1779 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1781 static void do_machine_power_off(void)
1784 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1785 stop_run(&on_poff_trigger
);
1787 void (*_machine_power_off
)(void) = do_machine_power_off
;
1789 static struct attribute
*shutdown_action_attrs
[] = {
1790 &on_restart_attr
.attr
,
1791 &on_reboot_attr
.attr
,
1792 &on_panic_attr
.attr
,
1798 static struct attribute_group shutdown_action_attr_group
= {
1799 .attrs
= shutdown_action_attrs
,
1802 static void __init
shutdown_triggers_init(void)
1804 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1806 if (!shutdown_actions_kset
)
1808 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1809 &shutdown_action_attr_group
))
1813 panic("shutdown_triggers_init failed\n");
1816 static void __init
shutdown_actions_init(void)
1820 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1821 if (!shutdown_actions_list
[i
]->init
)
1823 shutdown_actions_list
[i
]->init_rc
=
1824 shutdown_actions_list
[i
]->init();
1828 static int __init
s390_ipl_init(void)
1830 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1832 sclp_early_get_ipl_info(&sclp_ipl_info
);
1834 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1835 * returned by read SCP info is invalid (contains EBCDIC blanks)
1836 * when the system has been booted via diag308. In that case we use
1837 * the value from diag308, if available.
1839 * There are also systems where diag308 store does not work in
1840 * case the system is booted from HMC. Fortunately in this case
1841 * READ SCP info provides the correct value.
1843 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 &&
1845 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
,
1847 shutdown_actions_init();
1848 shutdown_triggers_init();
1852 __initcall(s390_ipl_init
);
1854 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1859 for (sx
= 0; src
[sx
] != 0; sx
++) {
1862 dst
[dx
++] = src
[sx
];
1868 static int __init
vmcmd_on_reboot_setup(char *str
)
1872 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1873 vmcmd_on_reboot
[127] = 0;
1874 on_reboot_trigger
.action
= &vmcmd_action
;
1877 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1879 static int __init
vmcmd_on_panic_setup(char *str
)
1883 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1884 vmcmd_on_panic
[127] = 0;
1885 on_panic_trigger
.action
= &vmcmd_action
;
1888 __setup("vmpanic=", vmcmd_on_panic_setup
);
1890 static int __init
vmcmd_on_halt_setup(char *str
)
1894 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1895 vmcmd_on_halt
[127] = 0;
1896 on_halt_trigger
.action
= &vmcmd_action
;
1899 __setup("vmhalt=", vmcmd_on_halt_setup
);
1901 static int __init
vmcmd_on_poff_setup(char *str
)
1905 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1906 vmcmd_on_poff
[127] = 0;
1907 on_poff_trigger
.action
= &vmcmd_action
;
1910 __setup("vmpoff=", vmcmd_on_poff_setup
);
1912 static int on_panic_notify(struct notifier_block
*self
,
1913 unsigned long event
, void *data
)
1919 static struct notifier_block on_panic_nb
= {
1920 .notifier_call
= on_panic_notify
,
1921 .priority
= INT_MIN
,
1924 void __init
setup_ipl(void)
1926 ipl_info
.type
= get_ipl_type();
1927 switch (ipl_info
.type
) {
1929 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_ssid
;
1930 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1933 case IPL_TYPE_FCP_DUMP
:
1934 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1935 ipl_info
.data
.fcp
.dev_id
.devno
=
1936 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1937 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1938 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1941 case IPL_TYPE_UNKNOWN
:
1942 /* We have no info to copy */
1945 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1948 void __init
ipl_update_parameters(void)
1952 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1953 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1954 diag308_set_works
= 1;
1957 void __init
ipl_verify_parameters(void)
1959 struct cio_iplinfo iplinfo
;
1961 if (cio_get_iplinfo(&iplinfo
))
1964 ipl_ssid
= iplinfo
.ssid
;
1965 ipl_devno
= iplinfo
.devno
;
1966 ipl_flags
|= IPL_DEVNO_VALID
;
1967 if (!iplinfo
.is_qdio
)
1969 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1972 static LIST_HEAD(rcall
);
1973 static DEFINE_MUTEX(rcall_mutex
);
1975 void register_reset_call(struct reset_call
*reset
)
1977 mutex_lock(&rcall_mutex
);
1978 list_add(&reset
->list
, &rcall
);
1979 mutex_unlock(&rcall_mutex
);
1981 EXPORT_SYMBOL_GPL(register_reset_call
);
1983 void unregister_reset_call(struct reset_call
*reset
)
1985 mutex_lock(&rcall_mutex
);
1986 list_del(&reset
->list
);
1987 mutex_unlock(&rcall_mutex
);
1989 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1991 static void do_reset_calls(void)
1993 struct reset_call
*reset
;
1995 if (diag308_set_works
) {
1999 list_for_each_entry(reset
, &rcall
, list
)
2003 void s390_reset_system(void)
2007 lc
= (struct lowcore
*)(unsigned long) store_prefix();
2009 /* Stack for interrupt/machine check handler */
2010 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2012 /* Disable prefixing */
2015 /* Disable lowcore protection */
2016 __ctl_clear_bit(0,28);
2018 /* Set new machine check handler */
2019 S390_lowcore
.mcck_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2020 S390_lowcore
.mcck_new_psw
.addr
=
2021 (unsigned long) s390_base_mcck_handler
;
2023 /* Set new program check handler */
2024 S390_lowcore
.program_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2025 S390_lowcore
.program_new_psw
.addr
=
2026 (unsigned long) s390_base_pgm_handler
;