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_NSS_VALID
)
284 if (!(ipl_flags
& IPL_DEVNO_VALID
))
285 return IPL_TYPE_UNKNOWN
;
286 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
288 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
289 return IPL_TYPE_UNKNOWN
;
290 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
291 return IPL_TYPE_UNKNOWN
;
292 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
293 return IPL_TYPE_FCP_DUMP
;
297 struct ipl_info ipl_info
;
298 EXPORT_SYMBOL_GPL(ipl_info
);
300 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
303 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
306 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
308 /* VM IPL PARM routines */
309 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
310 const struct ipl_parameter_block
*ipb
)
314 char has_lowercase
= 0;
317 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
318 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
320 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
321 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
322 /* If at least one character is lowercase, we assume mixed
323 * case; otherwise we convert everything to lowercase.
325 for (i
= 0; i
< len
; i
++)
326 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
327 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
328 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
333 EBC_TOLOWER(dest
, len
);
341 size_t append_ipl_vmparm(char *dest
, size_t size
)
346 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
347 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
353 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
354 struct kobj_attribute
*attr
, char *page
)
356 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
358 append_ipl_vmparm(parm
, sizeof(parm
));
359 return sprintf(page
, "%s\n", parm
);
362 static size_t scpdata_length(const char* buf
, size_t count
)
365 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
372 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
373 const struct ipl_parameter_block
*ipb
)
379 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
380 ipb
->ipl_info
.fcp
.scp_data_len
));
385 for (i
= 0; i
< count
; i
++) {
386 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
390 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
395 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
397 for (i
= 0; i
< count
; i
++)
398 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
404 size_t append_ipl_scpdata(char *dest
, size_t len
)
409 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
410 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
417 static struct kobj_attribute sys_ipl_vm_parm_attr
=
418 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
420 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
421 struct kobj_attribute
*attr
, char *page
)
423 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
425 switch (ipl_info
.type
) {
427 return sprintf(page
, "0.%x.%04x\n", ipl_ssid
, ipl_devno
);
429 case IPL_TYPE_FCP_DUMP
:
430 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
436 static struct kobj_attribute sys_ipl_device_attr
=
437 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
439 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
440 struct bin_attribute
*attr
, char *buf
,
441 loff_t off
, size_t count
)
443 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
446 static struct bin_attribute ipl_parameter_attr
=
447 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
450 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
451 struct bin_attribute
*attr
, char *buf
,
452 loff_t off
, size_t count
)
454 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
455 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
457 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
459 static struct bin_attribute ipl_scp_data_attr
=
460 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
462 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
468 /* FCP ipl device attributes */
470 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
471 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
472 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
473 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
474 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
475 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
476 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
477 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
479 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
480 struct kobj_attribute
*attr
, char *page
)
482 char loadparm
[LOADPARM_LEN
+ 1] = {};
484 if (!sclp_ipl_info
.is_valid
)
485 return sprintf(page
, "#unknown#\n");
486 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
487 EBCASC(loadparm
, LOADPARM_LEN
);
489 return sprintf(page
, "%s\n", loadparm
);
492 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
493 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
495 static struct attribute
*ipl_fcp_attrs
[] = {
496 &sys_ipl_type_attr
.attr
,
497 &sys_ipl_device_attr
.attr
,
498 &sys_ipl_fcp_wwpn_attr
.attr
,
499 &sys_ipl_fcp_lun_attr
.attr
,
500 &sys_ipl_fcp_bootprog_attr
.attr
,
501 &sys_ipl_fcp_br_lba_attr
.attr
,
502 &sys_ipl_ccw_loadparm_attr
.attr
,
506 static struct attribute_group ipl_fcp_attr_group
= {
507 .attrs
= ipl_fcp_attrs
,
508 .bin_attrs
= ipl_fcp_bin_attrs
,
511 /* CCW ipl device attributes */
513 static struct attribute
*ipl_ccw_attrs_vm
[] = {
514 &sys_ipl_type_attr
.attr
,
515 &sys_ipl_device_attr
.attr
,
516 &sys_ipl_ccw_loadparm_attr
.attr
,
517 &sys_ipl_vm_parm_attr
.attr
,
521 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
522 &sys_ipl_type_attr
.attr
,
523 &sys_ipl_device_attr
.attr
,
524 &sys_ipl_ccw_loadparm_attr
.attr
,
528 static struct attribute_group ipl_ccw_attr_group_vm
= {
529 .attrs
= ipl_ccw_attrs_vm
,
532 static struct attribute_group ipl_ccw_attr_group_lpar
= {
533 .attrs
= ipl_ccw_attrs_lpar
536 /* NSS ipl device attributes */
538 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
540 static struct attribute
*ipl_nss_attrs
[] = {
541 &sys_ipl_type_attr
.attr
,
542 &sys_ipl_nss_name_attr
.attr
,
543 &sys_ipl_ccw_loadparm_attr
.attr
,
544 &sys_ipl_vm_parm_attr
.attr
,
548 static struct attribute_group ipl_nss_attr_group
= {
549 .attrs
= ipl_nss_attrs
,
552 /* UNKNOWN ipl device attributes */
554 static struct attribute
*ipl_unknown_attrs
[] = {
555 &sys_ipl_type_attr
.attr
,
559 static struct attribute_group ipl_unknown_attr_group
= {
560 .attrs
= ipl_unknown_attrs
,
563 static struct kset
*ipl_kset
;
565 static void __ipl_run(void *unused
)
568 diag308(DIAG308_LOAD_CLEAR
, NULL
);
570 __cpcmd("IPL", NULL
, 0, NULL
);
571 else if (ipl_info
.type
== IPL_TYPE_CCW
)
572 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
575 static void ipl_run(struct shutdown_trigger
*trigger
)
577 smp_call_ipl_cpu(__ipl_run
, NULL
);
580 static int __init
ipl_init(void)
584 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
589 switch (ipl_info
.type
) {
592 rc
= sysfs_create_group(&ipl_kset
->kobj
,
593 &ipl_ccw_attr_group_vm
);
595 rc
= sysfs_create_group(&ipl_kset
->kobj
,
596 &ipl_ccw_attr_group_lpar
);
599 case IPL_TYPE_FCP_DUMP
:
600 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
603 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
606 rc
= sysfs_create_group(&ipl_kset
->kobj
,
607 &ipl_unknown_attr_group
);
612 panic("ipl_init failed: rc = %i\n", rc
);
617 static struct shutdown_action __refdata ipl_action
= {
618 .name
= SHUTDOWN_ACTION_IPL_STR
,
624 * reipl shutdown action: Reboot Linux on shutdown.
627 /* VM IPL PARM attributes */
628 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
631 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
633 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
634 return sprintf(page
, "%s\n", vmparm
);
637 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
639 const char *buf
, size_t len
)
643 /* ignore trailing newline */
645 if ((len
> 0) && (buf
[len
- 1] == '\n'))
648 if (ip_len
> vmparm_max
)
651 /* parm is used to store kernel options, check for common chars */
652 for (i
= 0; i
< ip_len
; i
++)
653 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
656 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
657 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
659 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
660 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
661 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
663 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
670 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
671 struct kobj_attribute
*attr
, char *page
)
673 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
676 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
677 struct kobj_attribute
*attr
,
678 const char *buf
, size_t len
)
680 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
684 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
685 struct kobj_attribute
*attr
, char *page
)
687 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
690 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
691 struct kobj_attribute
*attr
,
692 const char *buf
, size_t len
)
694 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
697 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
698 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
699 reipl_nss_vmparm_store
);
700 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
701 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
702 reipl_ccw_vmparm_store
);
704 /* FCP reipl device attributes */
706 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
707 struct bin_attribute
*attr
,
708 char *buf
, loff_t off
, size_t count
)
710 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
711 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
713 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
716 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
717 struct bin_attribute
*attr
,
718 char *buf
, loff_t off
, size_t count
)
720 size_t scpdata_len
= count
;
727 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
, count
);
728 if (scpdata_len
% 8) {
729 padding
= 8 - (scpdata_len
% 8);
730 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
732 scpdata_len
+= padding
;
735 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
736 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
737 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
741 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
742 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
743 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
745 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
746 &sys_reipl_fcp_scp_data_attr
,
750 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
751 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
752 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
753 reipl_block_fcp
->ipl_info
.fcp
.lun
);
754 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
755 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
756 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
757 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
758 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
759 reipl_block_fcp
->ipl_info
.fcp
.devno
);
761 static void reipl_get_ascii_loadparm(char *loadparm
,
762 struct ipl_parameter_block
*ibp
)
764 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
765 EBCASC(loadparm
, LOADPARM_LEN
);
766 loadparm
[LOADPARM_LEN
] = 0;
770 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
773 char buf
[LOADPARM_LEN
+ 1];
775 reipl_get_ascii_loadparm(buf
, ipb
);
776 return sprintf(page
, "%s\n", buf
);
779 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
780 const char *buf
, size_t len
)
784 /* ignore trailing newline */
786 if ((len
> 0) && (buf
[len
- 1] == '\n'))
788 /* loadparm can have max 8 characters and must not start with a blank */
789 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
791 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
792 for (i
= 0; i
< lp_len
; i
++) {
793 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
798 /* initialize loadparm with blanks */
799 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
800 /* copy and convert to ebcdic */
801 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
802 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
803 ipb
->hdr
.flags
|= DIAG308_FLAGS_LP_VALID
;
808 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
809 struct kobj_attribute
*attr
, char *page
)
811 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
814 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
815 struct kobj_attribute
*attr
,
816 const char *buf
, size_t len
)
818 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
821 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
822 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
823 reipl_fcp_loadparm_store
);
825 static struct attribute
*reipl_fcp_attrs
[] = {
826 &sys_reipl_fcp_device_attr
.attr
,
827 &sys_reipl_fcp_wwpn_attr
.attr
,
828 &sys_reipl_fcp_lun_attr
.attr
,
829 &sys_reipl_fcp_bootprog_attr
.attr
,
830 &sys_reipl_fcp_br_lba_attr
.attr
,
831 &sys_reipl_fcp_loadparm_attr
.attr
,
835 static struct attribute_group reipl_fcp_attr_group
= {
836 .attrs
= reipl_fcp_attrs
,
837 .bin_attrs
= reipl_fcp_bin_attrs
,
840 /* CCW reipl device attributes */
841 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ipl_info
.ccw
);
844 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
845 struct kobj_attribute
*attr
, char *page
)
847 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
850 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
851 struct kobj_attribute
*attr
,
852 const char *buf
, size_t len
)
854 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
858 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
859 struct kobj_attribute
*attr
, char *page
)
861 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
864 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
865 struct kobj_attribute
*attr
,
866 const char *buf
, size_t len
)
868 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
871 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
872 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
873 reipl_ccw_loadparm_store
);
875 static struct attribute
*reipl_ccw_attrs_vm
[] = {
876 &sys_reipl_ccw_device_attr
.attr
,
877 &sys_reipl_ccw_loadparm_attr
.attr
,
878 &sys_reipl_ccw_vmparm_attr
.attr
,
882 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
883 &sys_reipl_ccw_device_attr
.attr
,
884 &sys_reipl_ccw_loadparm_attr
.attr
,
888 static struct attribute_group reipl_ccw_attr_group_vm
= {
890 .attrs
= reipl_ccw_attrs_vm
,
893 static struct attribute_group reipl_ccw_attr_group_lpar
= {
895 .attrs
= reipl_ccw_attrs_lpar
,
899 /* NSS reipl device attributes */
900 static void reipl_get_ascii_nss_name(char *dst
,
901 struct ipl_parameter_block
*ipb
)
903 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
904 EBCASC(dst
, NSS_NAME_SIZE
);
905 dst
[NSS_NAME_SIZE
] = 0;
908 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
909 struct kobj_attribute
*attr
, char *page
)
911 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
913 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
914 return sprintf(page
, "%s\n", nss_name
);
917 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
918 struct kobj_attribute
*attr
,
919 const char *buf
, size_t len
)
923 /* ignore trailing newline */
925 if ((len
> 0) && (buf
[len
- 1] == '\n'))
928 if (nss_len
> NSS_NAME_SIZE
)
931 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
933 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
934 DIAG308_VM_FLAGS_NSS_VALID
;
935 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
936 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
937 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
939 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
940 ~DIAG308_VM_FLAGS_NSS_VALID
;
946 static struct kobj_attribute sys_reipl_nss_name_attr
=
947 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
948 reipl_nss_name_store
);
950 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
951 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
952 reipl_nss_loadparm_store
);
954 static struct attribute
*reipl_nss_attrs
[] = {
955 &sys_reipl_nss_name_attr
.attr
,
956 &sys_reipl_nss_loadparm_attr
.attr
,
957 &sys_reipl_nss_vmparm_attr
.attr
,
961 static struct attribute_group reipl_nss_attr_group
= {
963 .attrs
= reipl_nss_attrs
,
966 static void set_reipl_block_actual(struct ipl_parameter_block
*reipl_block
)
968 reipl_block_actual
= reipl_block
;
969 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
970 reipl_block
->hdr
.len
);
975 static int reipl_set_type(enum ipl_type type
)
977 if (!(reipl_capabilities
& type
))
982 if (diag308_set_works
)
983 reipl_method
= REIPL_METHOD_CCW_DIAG
;
984 else if (MACHINE_IS_VM
)
985 reipl_method
= REIPL_METHOD_CCW_VM
;
987 reipl_method
= REIPL_METHOD_CCW_CIO
;
988 set_reipl_block_actual(reipl_block_ccw
);
991 if (diag308_set_works
)
992 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
993 else if (MACHINE_IS_VM
)
994 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
996 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
997 set_reipl_block_actual(reipl_block_fcp
);
999 case IPL_TYPE_FCP_DUMP
:
1000 reipl_method
= REIPL_METHOD_FCP_DUMP
;
1003 if (diag308_set_works
)
1004 reipl_method
= REIPL_METHOD_NSS_DIAG
;
1006 reipl_method
= REIPL_METHOD_NSS
;
1007 set_reipl_block_actual(reipl_block_nss
);
1009 case IPL_TYPE_UNKNOWN
:
1010 reipl_method
= REIPL_METHOD_DEFAULT
;
1019 static ssize_t
reipl_type_show(struct kobject
*kobj
,
1020 struct kobj_attribute
*attr
, char *page
)
1022 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1025 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1026 struct kobj_attribute
*attr
,
1027 const char *buf
, size_t len
)
1031 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1032 rc
= reipl_set_type(IPL_TYPE_CCW
);
1033 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1034 rc
= reipl_set_type(IPL_TYPE_FCP
);
1035 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1036 rc
= reipl_set_type(IPL_TYPE_NSS
);
1037 return (rc
!= 0) ? rc
: len
;
1040 static struct kobj_attribute reipl_type_attr
=
1041 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1043 static struct kset
*reipl_kset
;
1044 static struct kset
*reipl_fcp_kset
;
1046 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1047 const enum ipl_method m
)
1049 char loadparm
[LOADPARM_LEN
+ 1] = {};
1050 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1051 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1054 reipl_get_ascii_loadparm(loadparm
, ipb
);
1055 reipl_get_ascii_nss_name(nss_name
, ipb
);
1056 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1059 case REIPL_METHOD_CCW_VM
:
1060 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1062 case REIPL_METHOD_NSS
:
1063 pos
= sprintf(dst
, "IPL %s", nss_name
);
1068 if (strlen(loadparm
) > 0)
1069 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1070 if (strlen(vmparm
) > 0)
1071 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1074 static void __reipl_run(void *unused
)
1076 struct ccw_dev_id devid
;
1077 static char buf
[128];
1079 switch (reipl_method
) {
1080 case REIPL_METHOD_CCW_CIO
:
1081 devid
.ssid
= reipl_block_ccw
->ipl_info
.ccw
.ssid
;
1082 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1083 reipl_ccw_dev(&devid
);
1085 case REIPL_METHOD_CCW_VM
:
1086 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1087 __cpcmd(buf
, NULL
, 0, NULL
);
1089 case REIPL_METHOD_CCW_DIAG
:
1090 diag308(DIAG308_SET
, reipl_block_ccw
);
1091 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1093 case REIPL_METHOD_FCP_RW_DIAG
:
1094 diag308(DIAG308_SET
, reipl_block_fcp
);
1095 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1097 case REIPL_METHOD_FCP_RO_DIAG
:
1098 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1100 case REIPL_METHOD_FCP_RO_VM
:
1101 __cpcmd("IPL", NULL
, 0, NULL
);
1103 case REIPL_METHOD_NSS_DIAG
:
1104 diag308(DIAG308_SET
, reipl_block_nss
);
1105 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1107 case REIPL_METHOD_NSS
:
1108 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1109 __cpcmd(buf
, NULL
, 0, NULL
);
1111 case REIPL_METHOD_DEFAULT
:
1113 __cpcmd("IPL", NULL
, 0, NULL
);
1114 diag308(DIAG308_LOAD_CLEAR
, NULL
);
1116 case REIPL_METHOD_FCP_DUMP
:
1119 disabled_wait((unsigned long) __builtin_return_address(0));
1122 static void reipl_run(struct shutdown_trigger
*trigger
)
1124 smp_call_ipl_cpu(__reipl_run
, NULL
);
1127 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1129 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1130 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1131 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1132 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1135 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1138 /* check if read scp info worked and set loadparm */
1139 if (sclp_ipl_info
.is_valid
)
1140 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1142 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1143 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
1144 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1147 if (MACHINE_IS_VM
&& diag308_set_works
&&
1148 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1150 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1151 ipb
->ipl_info
.ccw
.vm_parm_len
=
1152 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1153 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1154 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1158 static int __init
reipl_nss_init(void)
1165 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1166 if (!reipl_block_nss
)
1169 if (!diag308_set_works
)
1170 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1172 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1176 reipl_block_ccw_init(reipl_block_nss
);
1177 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1178 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1179 ' ', NSS_NAME_SIZE
);
1180 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1181 kernel_nss_name
, strlen(kernel_nss_name
));
1182 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1183 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1184 DIAG308_VM_FLAGS_NSS_VALID
;
1186 reipl_block_ccw_fill_parms(reipl_block_nss
);
1189 reipl_capabilities
|= IPL_TYPE_NSS
;
1193 static int __init
reipl_ccw_init(void)
1197 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1198 if (!reipl_block_ccw
)
1201 if (MACHINE_IS_VM
) {
1202 if (!diag308_set_works
)
1203 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1204 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1205 &reipl_ccw_attr_group_vm
);
1207 if(!diag308_set_works
)
1208 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1209 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1210 &reipl_ccw_attr_group_lpar
);
1215 reipl_block_ccw_init(reipl_block_ccw
);
1216 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1217 reipl_block_ccw
->ipl_info
.ccw
.ssid
= ipl_ssid
;
1218 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1219 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1222 reipl_capabilities
|= IPL_TYPE_CCW
;
1226 static int __init
reipl_fcp_init(void)
1230 if (!diag308_set_works
) {
1231 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1232 make_attrs_ro(reipl_fcp_attrs
);
1233 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1238 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1239 if (!reipl_block_fcp
)
1242 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1243 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1245 if (!reipl_fcp_kset
) {
1246 free_page((unsigned long) reipl_block_fcp
);
1250 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1252 kset_unregister(reipl_fcp_kset
);
1253 free_page((unsigned long) reipl_block_fcp
);
1257 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1258 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1260 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1261 * is invalid in the SCSI IPL parameter block, so take it
1262 * always from sclp_ipl_info.
1264 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1267 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1268 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1269 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1270 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1271 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1273 reipl_capabilities
|= IPL_TYPE_FCP
;
1277 static int __init
reipl_type_init(void)
1279 enum ipl_type reipl_type
= ipl_info
.type
;
1280 struct ipl_parameter_block
*reipl_block
;
1283 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1287 * If we have an OS info reipl block, this will be used
1289 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1290 memcpy(reipl_block_fcp
, reipl_block
, size
);
1291 reipl_type
= IPL_TYPE_FCP
;
1292 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1293 memcpy(reipl_block_ccw
, reipl_block
, size
);
1294 reipl_type
= IPL_TYPE_CCW
;
1297 return reipl_set_type(reipl_type
);
1300 static int __init
reipl_init(void)
1304 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1307 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1309 kset_unregister(reipl_kset
);
1312 rc
= reipl_ccw_init();
1315 rc
= reipl_fcp_init();
1318 rc
= reipl_nss_init();
1321 return reipl_type_init();
1324 static struct shutdown_action __refdata reipl_action
= {
1325 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1331 * dump shutdown action: Dump Linux on shutdown.
1334 /* FCP dump device attributes */
1336 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1337 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1338 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1339 dump_block_fcp
->ipl_info
.fcp
.lun
);
1340 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1341 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1342 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1343 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1344 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1345 dump_block_fcp
->ipl_info
.fcp
.devno
);
1347 static struct attribute
*dump_fcp_attrs
[] = {
1348 &sys_dump_fcp_device_attr
.attr
,
1349 &sys_dump_fcp_wwpn_attr
.attr
,
1350 &sys_dump_fcp_lun_attr
.attr
,
1351 &sys_dump_fcp_bootprog_attr
.attr
,
1352 &sys_dump_fcp_br_lba_attr
.attr
,
1356 static struct attribute_group dump_fcp_attr_group
= {
1357 .name
= IPL_FCP_STR
,
1358 .attrs
= dump_fcp_attrs
,
1361 /* CCW dump device attributes */
1362 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ipl_info
.ccw
);
1364 static struct attribute
*dump_ccw_attrs
[] = {
1365 &sys_dump_ccw_device_attr
.attr
,
1369 static struct attribute_group dump_ccw_attr_group
= {
1370 .name
= IPL_CCW_STR
,
1371 .attrs
= dump_ccw_attrs
,
1376 static int dump_set_type(enum dump_type type
)
1378 if (!(dump_capabilities
& type
))
1382 if (diag308_set_works
)
1383 dump_method
= DUMP_METHOD_CCW_DIAG
;
1384 else if (MACHINE_IS_VM
)
1385 dump_method
= DUMP_METHOD_CCW_VM
;
1387 dump_method
= DUMP_METHOD_CCW_CIO
;
1390 dump_method
= DUMP_METHOD_FCP_DIAG
;
1393 dump_method
= DUMP_METHOD_NONE
;
1399 static ssize_t
dump_type_show(struct kobject
*kobj
,
1400 struct kobj_attribute
*attr
, char *page
)
1402 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1405 static ssize_t
dump_type_store(struct kobject
*kobj
,
1406 struct kobj_attribute
*attr
,
1407 const char *buf
, size_t len
)
1411 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1412 rc
= dump_set_type(DUMP_TYPE_NONE
);
1413 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1414 rc
= dump_set_type(DUMP_TYPE_CCW
);
1415 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1416 rc
= dump_set_type(DUMP_TYPE_FCP
);
1417 return (rc
!= 0) ? rc
: len
;
1420 static struct kobj_attribute dump_type_attr
=
1421 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1423 static struct kset
*dump_kset
;
1425 static void diag308_dump(void *dump_block
)
1427 diag308(DIAG308_SET
, dump_block
);
1429 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1431 udelay_simple(USEC_PER_SEC
);
1435 static void __dump_run(void *unused
)
1437 struct ccw_dev_id devid
;
1438 static char buf
[100];
1440 switch (dump_method
) {
1441 case DUMP_METHOD_CCW_CIO
:
1442 devid
.ssid
= dump_block_ccw
->ipl_info
.ccw
.ssid
;
1443 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1444 reipl_ccw_dev(&devid
);
1446 case DUMP_METHOD_CCW_VM
:
1447 sprintf(buf
, "STORE STATUS");
1448 __cpcmd(buf
, NULL
, 0, NULL
);
1449 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1450 __cpcmd(buf
, NULL
, 0, NULL
);
1452 case DUMP_METHOD_CCW_DIAG
:
1453 diag308_dump(dump_block_ccw
);
1455 case DUMP_METHOD_FCP_DIAG
:
1456 diag308_dump(dump_block_fcp
);
1463 static void dump_run(struct shutdown_trigger
*trigger
)
1465 if (dump_method
== DUMP_METHOD_NONE
)
1468 smp_call_ipl_cpu(__dump_run
, NULL
);
1471 static int __init
dump_ccw_init(void)
1475 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1476 if (!dump_block_ccw
)
1478 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1480 free_page((unsigned long)dump_block_ccw
);
1483 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1484 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1485 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1486 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1487 dump_capabilities
|= DUMP_TYPE_CCW
;
1491 static int __init
dump_fcp_init(void)
1495 if (!sclp_ipl_info
.has_dump
)
1496 return 0; /* LDIPL DUMP is not installed */
1497 if (!diag308_set_works
)
1499 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1500 if (!dump_block_fcp
)
1502 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1504 free_page((unsigned long)dump_block_fcp
);
1507 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1508 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1509 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1510 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1511 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1512 dump_capabilities
|= DUMP_TYPE_FCP
;
1516 static int __init
dump_init(void)
1520 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1523 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1525 kset_unregister(dump_kset
);
1528 rc
= dump_ccw_init();
1531 rc
= dump_fcp_init();
1534 dump_set_type(DUMP_TYPE_NONE
);
1538 static struct shutdown_action __refdata dump_action
= {
1539 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1544 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1546 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1549 csum
= (__force
unsigned int)
1550 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1551 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1552 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1556 static int __init
dump_reipl_init(void)
1558 if (!diag308_set_works
)
1564 static struct shutdown_action __refdata dump_reipl_action
= {
1565 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1566 .fn
= dump_reipl_run
,
1567 .init
= dump_reipl_init
,
1571 * vmcmd shutdown action: Trigger vm command on shutdown.
1574 static char vmcmd_on_reboot
[128];
1575 static char vmcmd_on_panic
[128];
1576 static char vmcmd_on_halt
[128];
1577 static char vmcmd_on_poff
[128];
1578 static char vmcmd_on_restart
[128];
1580 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1581 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1582 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1583 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1584 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1586 static struct attribute
*vmcmd_attrs
[] = {
1587 &sys_vmcmd_on_reboot_attr
.attr
,
1588 &sys_vmcmd_on_panic_attr
.attr
,
1589 &sys_vmcmd_on_halt_attr
.attr
,
1590 &sys_vmcmd_on_poff_attr
.attr
,
1591 &sys_vmcmd_on_restart_attr
.attr
,
1595 static struct attribute_group vmcmd_attr_group
= {
1596 .attrs
= vmcmd_attrs
,
1599 static struct kset
*vmcmd_kset
;
1601 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1605 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1606 cmd
= vmcmd_on_reboot
;
1607 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1608 cmd
= vmcmd_on_panic
;
1609 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1610 cmd
= vmcmd_on_halt
;
1611 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1612 cmd
= vmcmd_on_poff
;
1613 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1614 cmd
= vmcmd_on_restart
;
1618 if (strlen(cmd
) == 0)
1620 __cpcmd(cmd
, NULL
, 0, NULL
);
1623 static int vmcmd_init(void)
1627 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1630 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1633 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1634 vmcmd_run
, vmcmd_init
};
1637 * stop shutdown action: Stop Linux on shutdown.
1640 static void stop_run(struct shutdown_trigger
*trigger
)
1642 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1643 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1644 disabled_wait((unsigned long) __builtin_return_address(0));
1648 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1653 static struct shutdown_action
*shutdown_actions_list
[] = {
1654 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1655 &vmcmd_action
, &stop_action
};
1656 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1662 static struct kset
*shutdown_actions_kset
;
1664 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1669 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1670 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1671 if (shutdown_actions_list
[i
]->init_rc
) {
1672 return shutdown_actions_list
[i
]->init_rc
;
1674 trigger
->action
= shutdown_actions_list
[i
];
1684 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1687 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1688 struct kobj_attribute
*attr
, char *page
)
1690 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1693 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1694 struct kobj_attribute
*attr
,
1695 const char *buf
, size_t len
)
1697 return set_trigger(buf
, &on_reboot_trigger
, len
);
1699 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1701 static void do_machine_restart(char *__unused
)
1704 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1707 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1711 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1713 static ssize_t
on_panic_show(struct kobject
*kobj
,
1714 struct kobj_attribute
*attr
, char *page
)
1716 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1719 static ssize_t
on_panic_store(struct kobject
*kobj
,
1720 struct kobj_attribute
*attr
,
1721 const char *buf
, size_t len
)
1723 return set_trigger(buf
, &on_panic_trigger
, len
);
1725 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1727 static void do_panic(void)
1730 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1731 stop_run(&on_panic_trigger
);
1736 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1739 static ssize_t
on_restart_show(struct kobject
*kobj
,
1740 struct kobj_attribute
*attr
, char *page
)
1742 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1745 static ssize_t
on_restart_store(struct kobject
*kobj
,
1746 struct kobj_attribute
*attr
,
1747 const char *buf
, size_t len
)
1749 return set_trigger(buf
, &on_restart_trigger
, len
);
1751 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1753 static void __do_restart(void *ignore
)
1755 __arch_local_irq_stosm(0x04); /* enable DAT */
1757 #ifdef CONFIG_CRASH_DUMP
1760 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1761 stop_run(&on_restart_trigger
);
1764 void do_restart(void)
1769 smp_call_online_cpu(__do_restart
, NULL
);
1774 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1776 static ssize_t
on_halt_show(struct kobject
*kobj
,
1777 struct kobj_attribute
*attr
, char *page
)
1779 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1782 static ssize_t
on_halt_store(struct kobject
*kobj
,
1783 struct kobj_attribute
*attr
,
1784 const char *buf
, size_t len
)
1786 return set_trigger(buf
, &on_halt_trigger
, len
);
1788 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1790 static void do_machine_halt(void)
1793 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1794 stop_run(&on_halt_trigger
);
1796 void (*_machine_halt
)(void) = do_machine_halt
;
1800 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1802 static ssize_t
on_poff_show(struct kobject
*kobj
,
1803 struct kobj_attribute
*attr
, char *page
)
1805 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1808 static ssize_t
on_poff_store(struct kobject
*kobj
,
1809 struct kobj_attribute
*attr
,
1810 const char *buf
, size_t len
)
1812 return set_trigger(buf
, &on_poff_trigger
, len
);
1814 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1816 static void do_machine_power_off(void)
1819 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1820 stop_run(&on_poff_trigger
);
1822 void (*_machine_power_off
)(void) = do_machine_power_off
;
1824 static struct attribute
*shutdown_action_attrs
[] = {
1825 &on_restart_attr
.attr
,
1826 &on_reboot_attr
.attr
,
1827 &on_panic_attr
.attr
,
1833 static struct attribute_group shutdown_action_attr_group
= {
1834 .attrs
= shutdown_action_attrs
,
1837 static void __init
shutdown_triggers_init(void)
1839 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1841 if (!shutdown_actions_kset
)
1843 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1844 &shutdown_action_attr_group
))
1848 panic("shutdown_triggers_init failed\n");
1851 static void __init
shutdown_actions_init(void)
1855 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1856 if (!shutdown_actions_list
[i
]->init
)
1858 shutdown_actions_list
[i
]->init_rc
=
1859 shutdown_actions_list
[i
]->init();
1863 static int __init
s390_ipl_init(void)
1865 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1867 sclp_early_get_ipl_info(&sclp_ipl_info
);
1869 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1870 * returned by read SCP info is invalid (contains EBCDIC blanks)
1871 * when the system has been booted via diag308. In that case we use
1872 * the value from diag308, if available.
1874 * There are also systems where diag308 store does not work in
1875 * case the system is booted from HMC. Fortunately in this case
1876 * READ SCP info provides the correct value.
1878 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 &&
1880 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
,
1882 shutdown_actions_init();
1883 shutdown_triggers_init();
1887 __initcall(s390_ipl_init
);
1889 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1894 for (sx
= 0; src
[sx
] != 0; sx
++) {
1897 dst
[dx
++] = src
[sx
];
1903 static int __init
vmcmd_on_reboot_setup(char *str
)
1907 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1908 vmcmd_on_reboot
[127] = 0;
1909 on_reboot_trigger
.action
= &vmcmd_action
;
1912 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1914 static int __init
vmcmd_on_panic_setup(char *str
)
1918 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1919 vmcmd_on_panic
[127] = 0;
1920 on_panic_trigger
.action
= &vmcmd_action
;
1923 __setup("vmpanic=", vmcmd_on_panic_setup
);
1925 static int __init
vmcmd_on_halt_setup(char *str
)
1929 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1930 vmcmd_on_halt
[127] = 0;
1931 on_halt_trigger
.action
= &vmcmd_action
;
1934 __setup("vmhalt=", vmcmd_on_halt_setup
);
1936 static int __init
vmcmd_on_poff_setup(char *str
)
1940 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1941 vmcmd_on_poff
[127] = 0;
1942 on_poff_trigger
.action
= &vmcmd_action
;
1945 __setup("vmpoff=", vmcmd_on_poff_setup
);
1947 static int on_panic_notify(struct notifier_block
*self
,
1948 unsigned long event
, void *data
)
1954 static struct notifier_block on_panic_nb
= {
1955 .notifier_call
= on_panic_notify
,
1956 .priority
= INT_MIN
,
1959 void __init
setup_ipl(void)
1961 ipl_info
.type
= get_ipl_type();
1962 switch (ipl_info
.type
) {
1964 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_ssid
;
1965 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1968 case IPL_TYPE_FCP_DUMP
:
1969 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1970 ipl_info
.data
.fcp
.dev_id
.devno
=
1971 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1972 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1973 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1976 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1977 sizeof(ipl_info
.data
.nss
.name
));
1979 case IPL_TYPE_UNKNOWN
:
1980 /* We have no info to copy */
1983 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1986 void __init
ipl_update_parameters(void)
1990 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1991 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1992 diag308_set_works
= 1;
1995 void __init
ipl_verify_parameters(void)
1997 struct cio_iplinfo iplinfo
;
1999 if (cio_get_iplinfo(&iplinfo
))
2002 ipl_ssid
= iplinfo
.ssid
;
2003 ipl_devno
= iplinfo
.devno
;
2004 ipl_flags
|= IPL_DEVNO_VALID
;
2005 if (!iplinfo
.is_qdio
)
2007 ipl_flags
|= IPL_PARMBLOCK_VALID
;
2010 static LIST_HEAD(rcall
);
2011 static DEFINE_MUTEX(rcall_mutex
);
2013 void register_reset_call(struct reset_call
*reset
)
2015 mutex_lock(&rcall_mutex
);
2016 list_add(&reset
->list
, &rcall
);
2017 mutex_unlock(&rcall_mutex
);
2019 EXPORT_SYMBOL_GPL(register_reset_call
);
2021 void unregister_reset_call(struct reset_call
*reset
)
2023 mutex_lock(&rcall_mutex
);
2024 list_del(&reset
->list
);
2025 mutex_unlock(&rcall_mutex
);
2027 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2029 static void do_reset_calls(void)
2031 struct reset_call
*reset
;
2033 if (diag308_set_works
) {
2037 list_for_each_entry(reset
, &rcall
, list
)
2041 void s390_reset_system(void)
2045 lc
= (struct lowcore
*)(unsigned long) store_prefix();
2047 /* Stack for interrupt/machine check handler */
2048 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2050 /* Disable prefixing */
2053 /* Disable lowcore protection */
2054 __ctl_clear_bit(0,28);
2056 /* Set new machine check handler */
2057 S390_lowcore
.mcck_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2058 S390_lowcore
.mcck_new_psw
.addr
=
2059 (unsigned long) s390_base_mcck_handler
;
2061 /* Set new program check handler */
2062 S390_lowcore
.program_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2063 S390_lowcore
.program_new_psw
.addr
=
2064 (unsigned long) s390_base_pgm_handler
;