2 * ipl/reipl/dump support for Linux on s390.
4 * Copyright IBM Corp. 2005, 2012
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 * Volker Sameske <sameske@de.ibm.com>
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <linux/ctype.h>
17 #include <linux/gfp.h>
18 #include <linux/crash_dump.h>
19 #include <linux/debug_locks.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
28 #include <asm/checksum.h>
29 #include <asm/debug.h>
30 #include <asm/os_info.h>
33 #define IPL_PARM_BLOCK_VERSION 0
35 #define IPL_UNKNOWN_STR "unknown"
36 #define IPL_CCW_STR "ccw"
37 #define IPL_FCP_STR "fcp"
38 #define IPL_FCP_DUMP_STR "fcp_dump"
39 #define IPL_NSS_STR "nss"
41 #define DUMP_CCW_STR "ccw"
42 #define DUMP_FCP_STR "fcp"
43 #define DUMP_NONE_STR "none"
46 * Four shutdown trigger types are supported:
53 #define ON_PANIC_STR "on_panic"
54 #define ON_HALT_STR "on_halt"
55 #define ON_POFF_STR "on_poff"
56 #define ON_REIPL_STR "on_reboot"
57 #define ON_RESTART_STR "on_restart"
59 struct shutdown_action
;
60 struct shutdown_trigger
{
62 struct shutdown_action
*action
;
66 * The following shutdown action types are supported:
68 #define SHUTDOWN_ACTION_IPL_STR "ipl"
69 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
70 #define SHUTDOWN_ACTION_DUMP_STR "dump"
71 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72 #define SHUTDOWN_ACTION_STOP_STR "stop"
73 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
75 struct shutdown_action
{
77 void (*fn
) (struct shutdown_trigger
*trigger
);
82 static char *ipl_type_str(enum ipl_type type
)
89 case IPL_TYPE_FCP_DUMP
:
90 return IPL_FCP_DUMP_STR
;
93 case IPL_TYPE_UNKNOWN
:
95 return IPL_UNKNOWN_STR
;
105 static char *dump_type_str(enum dump_type type
)
109 return DUMP_NONE_STR
;
120 * Must be in data section since the bss section
121 * is not cleared when these are accessed.
123 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
124 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
127 REIPL_METHOD_CCW_CIO
,
128 REIPL_METHOD_CCW_DIAG
,
130 REIPL_METHOD_FCP_RO_DIAG
,
131 REIPL_METHOD_FCP_RW_DIAG
,
132 REIPL_METHOD_FCP_RO_VM
,
133 REIPL_METHOD_FCP_DUMP
,
135 REIPL_METHOD_NSS_DIAG
,
136 REIPL_METHOD_DEFAULT
,
142 DUMP_METHOD_CCW_DIAG
,
144 DUMP_METHOD_FCP_DIAG
,
147 static int diag308_set_works
= 0;
149 static struct ipl_parameter_block ipl_block
;
151 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
153 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
154 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
155 static struct ipl_parameter_block
*reipl_block_fcp
;
156 static struct ipl_parameter_block
*reipl_block_ccw
;
157 static struct ipl_parameter_block
*reipl_block_nss
;
158 static struct ipl_parameter_block
*reipl_block_actual
;
160 static int dump_capabilities
= DUMP_TYPE_NONE
;
161 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
162 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
163 static struct ipl_parameter_block
*dump_block_fcp
;
164 static struct ipl_parameter_block
*dump_block_ccw
;
166 static struct sclp_ipl_info sclp_ipl_info
;
168 int diag308(unsigned long subcode
, void *addr
)
170 register unsigned long _addr
asm("0") = (unsigned long) addr
;
171 register unsigned long _rc
asm("1") = 0;
174 " diag %0,%2,0x308\n"
177 : "+d" (_addr
), "+d" (_rc
)
178 : "d" (subcode
) : "cc", "memory");
181 EXPORT_SYMBOL_GPL(diag308
);
185 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
190 return snprintf(page, PAGE_SIZE, _format, ##args); \
193 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
194 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
195 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
196 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
198 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
199 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
200 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
201 struct kobj_attribute *attr, \
202 const char *buf, size_t len) \
204 unsigned long long value; \
205 if (sscanf(buf, _fmt_in, &value) != 1) \
210 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
211 __ATTR(_name,(S_IRUGO | S_IWUSR), \
212 sys_##_prefix##_##_name##_show, \
213 sys_##_prefix##_##_name##_store)
215 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
216 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
217 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
218 struct kobj_attribute *attr, \
219 const char *buf, size_t len) \
221 strncpy(_value, buf, sizeof(_value) - 1); \
225 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
226 __ATTR(_name,(S_IRUGO | S_IWUSR), \
227 sys_##_prefix##_##_name##_show, \
228 sys_##_prefix##_##_name##_store)
230 static void make_attrs_ro(struct attribute
**attrs
)
233 (*attrs
)->mode
= S_IRUGO
;
242 static __init
enum ipl_type
get_ipl_type(void)
244 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
246 if (ipl_flags
& IPL_NSS_VALID
)
248 if (!(ipl_flags
& IPL_DEVNO_VALID
))
249 return IPL_TYPE_UNKNOWN
;
250 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
252 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
253 return IPL_TYPE_UNKNOWN
;
254 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
255 return IPL_TYPE_UNKNOWN
;
256 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
257 return IPL_TYPE_FCP_DUMP
;
261 struct ipl_info ipl_info
;
262 EXPORT_SYMBOL_GPL(ipl_info
);
264 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
267 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
270 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
272 /* VM IPL PARM routines */
273 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
274 const struct ipl_parameter_block
*ipb
)
278 char has_lowercase
= 0;
281 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
282 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
284 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
285 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
286 /* If at least one character is lowercase, we assume mixed
287 * case; otherwise we convert everything to lowercase.
289 for (i
= 0; i
< len
; i
++)
290 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
291 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
292 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
297 EBC_TOLOWER(dest
, len
);
305 size_t append_ipl_vmparm(char *dest
, size_t size
)
310 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
311 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
317 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
318 struct kobj_attribute
*attr
, char *page
)
320 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
322 append_ipl_vmparm(parm
, sizeof(parm
));
323 return sprintf(page
, "%s\n", parm
);
326 static size_t scpdata_length(const char* buf
, size_t count
)
329 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
336 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
337 const struct ipl_parameter_block
*ipb
)
343 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
344 ipb
->ipl_info
.fcp
.scp_data_len
));
349 for (i
= 0; i
< count
; i
++) {
350 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
354 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
359 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
361 for (i
= 0; i
< count
; i
++)
362 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
368 size_t append_ipl_scpdata(char *dest
, size_t len
)
373 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
374 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
381 static struct kobj_attribute sys_ipl_vm_parm_attr
=
382 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
384 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
385 struct kobj_attribute
*attr
, char *page
)
387 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
389 switch (ipl_info
.type
) {
391 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
393 case IPL_TYPE_FCP_DUMP
:
394 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
400 static struct kobj_attribute sys_ipl_device_attr
=
401 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
403 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
404 struct bin_attribute
*attr
, char *buf
,
405 loff_t off
, size_t count
)
407 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
410 static struct bin_attribute ipl_parameter_attr
=
411 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
414 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
415 struct bin_attribute
*attr
, char *buf
,
416 loff_t off
, size_t count
)
418 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
419 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
421 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
423 static struct bin_attribute ipl_scp_data_attr
=
424 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
426 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
432 /* FCP ipl device attributes */
434 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
435 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
436 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
437 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
438 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
439 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
440 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
441 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
443 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
444 struct kobj_attribute
*attr
, char *page
)
446 char loadparm
[LOADPARM_LEN
+ 1] = {};
448 if (!sclp_ipl_info
.is_valid
)
449 return sprintf(page
, "#unknown#\n");
450 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
451 EBCASC(loadparm
, LOADPARM_LEN
);
453 return sprintf(page
, "%s\n", loadparm
);
456 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
457 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
459 static struct attribute
*ipl_fcp_attrs
[] = {
460 &sys_ipl_type_attr
.attr
,
461 &sys_ipl_device_attr
.attr
,
462 &sys_ipl_fcp_wwpn_attr
.attr
,
463 &sys_ipl_fcp_lun_attr
.attr
,
464 &sys_ipl_fcp_bootprog_attr
.attr
,
465 &sys_ipl_fcp_br_lba_attr
.attr
,
466 &sys_ipl_ccw_loadparm_attr
.attr
,
470 static struct attribute_group ipl_fcp_attr_group
= {
471 .attrs
= ipl_fcp_attrs
,
472 .bin_attrs
= ipl_fcp_bin_attrs
,
475 /* CCW ipl device attributes */
477 static struct attribute
*ipl_ccw_attrs_vm
[] = {
478 &sys_ipl_type_attr
.attr
,
479 &sys_ipl_device_attr
.attr
,
480 &sys_ipl_ccw_loadparm_attr
.attr
,
481 &sys_ipl_vm_parm_attr
.attr
,
485 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
486 &sys_ipl_type_attr
.attr
,
487 &sys_ipl_device_attr
.attr
,
488 &sys_ipl_ccw_loadparm_attr
.attr
,
492 static struct attribute_group ipl_ccw_attr_group_vm
= {
493 .attrs
= ipl_ccw_attrs_vm
,
496 static struct attribute_group ipl_ccw_attr_group_lpar
= {
497 .attrs
= ipl_ccw_attrs_lpar
500 /* NSS ipl device attributes */
502 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
504 static struct attribute
*ipl_nss_attrs
[] = {
505 &sys_ipl_type_attr
.attr
,
506 &sys_ipl_nss_name_attr
.attr
,
507 &sys_ipl_ccw_loadparm_attr
.attr
,
508 &sys_ipl_vm_parm_attr
.attr
,
512 static struct attribute_group ipl_nss_attr_group
= {
513 .attrs
= ipl_nss_attrs
,
516 /* UNKNOWN ipl device attributes */
518 static struct attribute
*ipl_unknown_attrs
[] = {
519 &sys_ipl_type_attr
.attr
,
523 static struct attribute_group ipl_unknown_attr_group
= {
524 .attrs
= ipl_unknown_attrs
,
527 static struct kset
*ipl_kset
;
529 static void __ipl_run(void *unused
)
531 diag308(DIAG308_IPL
, NULL
);
533 __cpcmd("IPL", NULL
, 0, NULL
);
534 else if (ipl_info
.type
== IPL_TYPE_CCW
)
535 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
538 static void ipl_run(struct shutdown_trigger
*trigger
)
540 smp_call_ipl_cpu(__ipl_run
, NULL
);
543 static int __init
ipl_init(void)
547 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
552 switch (ipl_info
.type
) {
555 rc
= sysfs_create_group(&ipl_kset
->kobj
,
556 &ipl_ccw_attr_group_vm
);
558 rc
= sysfs_create_group(&ipl_kset
->kobj
,
559 &ipl_ccw_attr_group_lpar
);
562 case IPL_TYPE_FCP_DUMP
:
563 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
566 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
569 rc
= sysfs_create_group(&ipl_kset
->kobj
,
570 &ipl_unknown_attr_group
);
575 panic("ipl_init failed: rc = %i\n", rc
);
580 static struct shutdown_action __refdata ipl_action
= {
581 .name
= SHUTDOWN_ACTION_IPL_STR
,
587 * reipl shutdown action: Reboot Linux on shutdown.
590 /* VM IPL PARM attributes */
591 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
594 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
596 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
597 return sprintf(page
, "%s\n", vmparm
);
600 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
602 const char *buf
, size_t len
)
606 /* ignore trailing newline */
608 if ((len
> 0) && (buf
[len
- 1] == '\n'))
611 if (ip_len
> vmparm_max
)
614 /* parm is used to store kernel options, check for common chars */
615 for (i
= 0; i
< ip_len
; i
++)
616 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
619 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
620 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
622 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
623 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
624 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
626 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
633 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
634 struct kobj_attribute
*attr
, char *page
)
636 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
639 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
640 struct kobj_attribute
*attr
,
641 const char *buf
, size_t len
)
643 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
647 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
648 struct kobj_attribute
*attr
, char *page
)
650 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
653 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
654 struct kobj_attribute
*attr
,
655 const char *buf
, size_t len
)
657 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
660 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
661 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
662 reipl_nss_vmparm_store
);
663 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
664 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
665 reipl_ccw_vmparm_store
);
667 /* FCP reipl device attributes */
669 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
670 struct bin_attribute
*attr
,
671 char *buf
, loff_t off
, size_t count
)
673 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
674 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
676 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
679 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
680 struct bin_attribute
*attr
,
681 char *buf
, loff_t off
, size_t count
)
689 if (off
>= DIAG308_SCPDATA_SIZE
)
692 if (count
> DIAG308_SCPDATA_SIZE
- off
)
693 count
= DIAG308_SCPDATA_SIZE
- off
;
695 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
696 scpdata_len
= off
+ count
;
698 if (scpdata_len
% 8) {
699 padding
= 8 - (scpdata_len
% 8);
700 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
702 scpdata_len
+= padding
;
705 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
706 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
707 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
711 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
712 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
713 reipl_fcp_scpdata_write
, PAGE_SIZE
);
715 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
716 &sys_reipl_fcp_scp_data_attr
,
720 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
721 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
722 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
723 reipl_block_fcp
->ipl_info
.fcp
.lun
);
724 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
725 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
726 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
727 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
728 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
729 reipl_block_fcp
->ipl_info
.fcp
.devno
);
731 static void reipl_get_ascii_loadparm(char *loadparm
,
732 struct ipl_parameter_block
*ibp
)
734 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
735 EBCASC(loadparm
, LOADPARM_LEN
);
736 loadparm
[LOADPARM_LEN
] = 0;
740 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
743 char buf
[LOADPARM_LEN
+ 1];
745 reipl_get_ascii_loadparm(buf
, ipb
);
746 return sprintf(page
, "%s\n", buf
);
749 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
750 const char *buf
, size_t len
)
754 /* ignore trailing newline */
756 if ((len
> 0) && (buf
[len
- 1] == '\n'))
758 /* loadparm can have max 8 characters and must not start with a blank */
759 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
761 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
762 for (i
= 0; i
< lp_len
; i
++) {
763 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
768 /* initialize loadparm with blanks */
769 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
770 /* copy and convert to ebcdic */
771 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
772 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
777 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
778 struct kobj_attribute
*attr
, char *page
)
780 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
783 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
784 struct kobj_attribute
*attr
,
785 const char *buf
, size_t len
)
787 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
790 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
791 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
792 reipl_fcp_loadparm_store
);
794 static struct attribute
*reipl_fcp_attrs
[] = {
795 &sys_reipl_fcp_device_attr
.attr
,
796 &sys_reipl_fcp_wwpn_attr
.attr
,
797 &sys_reipl_fcp_lun_attr
.attr
,
798 &sys_reipl_fcp_bootprog_attr
.attr
,
799 &sys_reipl_fcp_br_lba_attr
.attr
,
800 &sys_reipl_fcp_loadparm_attr
.attr
,
804 static struct attribute_group reipl_fcp_attr_group
= {
805 .attrs
= reipl_fcp_attrs
,
806 .bin_attrs
= reipl_fcp_bin_attrs
,
809 /* CCW reipl device attributes */
811 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
812 reipl_block_ccw
->ipl_info
.ccw
.devno
);
815 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
816 struct kobj_attribute
*attr
, char *page
)
818 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
821 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
822 struct kobj_attribute
*attr
,
823 const char *buf
, size_t len
)
825 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
829 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
830 struct kobj_attribute
*attr
, char *page
)
832 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
835 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
836 struct kobj_attribute
*attr
,
837 const char *buf
, size_t len
)
839 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
842 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
843 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
844 reipl_ccw_loadparm_store
);
846 static struct attribute
*reipl_ccw_attrs_vm
[] = {
847 &sys_reipl_ccw_device_attr
.attr
,
848 &sys_reipl_ccw_loadparm_attr
.attr
,
849 &sys_reipl_ccw_vmparm_attr
.attr
,
853 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
854 &sys_reipl_ccw_device_attr
.attr
,
855 &sys_reipl_ccw_loadparm_attr
.attr
,
859 static struct attribute_group reipl_ccw_attr_group_vm
= {
861 .attrs
= reipl_ccw_attrs_vm
,
864 static struct attribute_group reipl_ccw_attr_group_lpar
= {
866 .attrs
= reipl_ccw_attrs_lpar
,
870 /* NSS reipl device attributes */
871 static void reipl_get_ascii_nss_name(char *dst
,
872 struct ipl_parameter_block
*ipb
)
874 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
875 EBCASC(dst
, NSS_NAME_SIZE
);
876 dst
[NSS_NAME_SIZE
] = 0;
879 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
880 struct kobj_attribute
*attr
, char *page
)
882 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
884 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
885 return sprintf(page
, "%s\n", nss_name
);
888 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
889 struct kobj_attribute
*attr
,
890 const char *buf
, size_t len
)
894 /* ignore trailing newline */
896 if ((len
> 0) && (buf
[len
- 1] == '\n'))
899 if (nss_len
> NSS_NAME_SIZE
)
902 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
904 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
905 DIAG308_VM_FLAGS_NSS_VALID
;
906 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
907 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
908 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
910 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
911 ~DIAG308_VM_FLAGS_NSS_VALID
;
917 static struct kobj_attribute sys_reipl_nss_name_attr
=
918 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
919 reipl_nss_name_store
);
921 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
922 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
923 reipl_nss_loadparm_store
);
925 static struct attribute
*reipl_nss_attrs
[] = {
926 &sys_reipl_nss_name_attr
.attr
,
927 &sys_reipl_nss_loadparm_attr
.attr
,
928 &sys_reipl_nss_vmparm_attr
.attr
,
932 static struct attribute_group reipl_nss_attr_group
= {
934 .attrs
= reipl_nss_attrs
,
937 static void set_reipl_block_actual(struct ipl_parameter_block
*reipl_block
)
939 reipl_block_actual
= reipl_block
;
940 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
941 reipl_block
->hdr
.len
);
946 static int reipl_set_type(enum ipl_type type
)
948 if (!(reipl_capabilities
& type
))
953 if (diag308_set_works
)
954 reipl_method
= REIPL_METHOD_CCW_DIAG
;
955 else if (MACHINE_IS_VM
)
956 reipl_method
= REIPL_METHOD_CCW_VM
;
958 reipl_method
= REIPL_METHOD_CCW_CIO
;
959 set_reipl_block_actual(reipl_block_ccw
);
962 if (diag308_set_works
)
963 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
964 else if (MACHINE_IS_VM
)
965 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
967 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
968 set_reipl_block_actual(reipl_block_fcp
);
970 case IPL_TYPE_FCP_DUMP
:
971 reipl_method
= REIPL_METHOD_FCP_DUMP
;
974 if (diag308_set_works
)
975 reipl_method
= REIPL_METHOD_NSS_DIAG
;
977 reipl_method
= REIPL_METHOD_NSS
;
978 set_reipl_block_actual(reipl_block_nss
);
980 case IPL_TYPE_UNKNOWN
:
981 reipl_method
= REIPL_METHOD_DEFAULT
;
990 static ssize_t
reipl_type_show(struct kobject
*kobj
,
991 struct kobj_attribute
*attr
, char *page
)
993 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
996 static ssize_t
reipl_type_store(struct kobject
*kobj
,
997 struct kobj_attribute
*attr
,
998 const char *buf
, size_t len
)
1002 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1003 rc
= reipl_set_type(IPL_TYPE_CCW
);
1004 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1005 rc
= reipl_set_type(IPL_TYPE_FCP
);
1006 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1007 rc
= reipl_set_type(IPL_TYPE_NSS
);
1008 return (rc
!= 0) ? rc
: len
;
1011 static struct kobj_attribute reipl_type_attr
=
1012 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1014 static struct kset
*reipl_kset
;
1015 static struct kset
*reipl_fcp_kset
;
1017 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1018 const enum ipl_method m
)
1020 char loadparm
[LOADPARM_LEN
+ 1] = {};
1021 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1022 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1025 reipl_get_ascii_loadparm(loadparm
, ipb
);
1026 reipl_get_ascii_nss_name(nss_name
, ipb
);
1027 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1030 case REIPL_METHOD_CCW_VM
:
1031 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1033 case REIPL_METHOD_NSS
:
1034 pos
= sprintf(dst
, "IPL %s", nss_name
);
1039 if (strlen(loadparm
) > 0)
1040 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1041 if (strlen(vmparm
) > 0)
1042 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1045 static void __reipl_run(void *unused
)
1047 struct ccw_dev_id devid
;
1048 static char buf
[128];
1050 switch (reipl_method
) {
1051 case REIPL_METHOD_CCW_CIO
:
1052 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1054 reipl_ccw_dev(&devid
);
1056 case REIPL_METHOD_CCW_VM
:
1057 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1058 __cpcmd(buf
, NULL
, 0, NULL
);
1060 case REIPL_METHOD_CCW_DIAG
:
1061 diag308(DIAG308_SET
, reipl_block_ccw
);
1062 diag308(DIAG308_IPL
, NULL
);
1064 case REIPL_METHOD_FCP_RW_DIAG
:
1065 diag308(DIAG308_SET
, reipl_block_fcp
);
1066 diag308(DIAG308_IPL
, NULL
);
1068 case REIPL_METHOD_FCP_RO_DIAG
:
1069 diag308(DIAG308_IPL
, NULL
);
1071 case REIPL_METHOD_FCP_RO_VM
:
1072 __cpcmd("IPL", NULL
, 0, NULL
);
1074 case REIPL_METHOD_NSS_DIAG
:
1075 diag308(DIAG308_SET
, reipl_block_nss
);
1076 diag308(DIAG308_IPL
, NULL
);
1078 case REIPL_METHOD_NSS
:
1079 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1080 __cpcmd(buf
, NULL
, 0, NULL
);
1082 case REIPL_METHOD_DEFAULT
:
1084 __cpcmd("IPL", NULL
, 0, NULL
);
1085 diag308(DIAG308_IPL
, NULL
);
1087 case REIPL_METHOD_FCP_DUMP
:
1090 disabled_wait((unsigned long) __builtin_return_address(0));
1093 static void reipl_run(struct shutdown_trigger
*trigger
)
1095 smp_call_ipl_cpu(__reipl_run
, NULL
);
1098 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1100 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1101 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1102 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1103 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1106 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1109 /* check if read scp info worked and set loadparm */
1110 if (sclp_ipl_info
.is_valid
)
1111 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1113 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1114 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
1115 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1118 if (MACHINE_IS_VM
&& diag308_set_works
&&
1119 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1121 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1122 ipb
->ipl_info
.ccw
.vm_parm_len
=
1123 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1124 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1125 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1129 static int __init
reipl_nss_init(void)
1136 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1137 if (!reipl_block_nss
)
1140 if (!diag308_set_works
)
1141 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1143 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1147 reipl_block_ccw_init(reipl_block_nss
);
1148 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1149 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1150 ' ', NSS_NAME_SIZE
);
1151 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1152 kernel_nss_name
, strlen(kernel_nss_name
));
1153 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1154 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1155 DIAG308_VM_FLAGS_NSS_VALID
;
1157 reipl_block_ccw_fill_parms(reipl_block_nss
);
1160 reipl_capabilities
|= IPL_TYPE_NSS
;
1164 static int __init
reipl_ccw_init(void)
1168 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1169 if (!reipl_block_ccw
)
1172 if (MACHINE_IS_VM
) {
1173 if (!diag308_set_works
)
1174 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1175 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1176 &reipl_ccw_attr_group_vm
);
1178 if(!diag308_set_works
)
1179 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1180 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1181 &reipl_ccw_attr_group_lpar
);
1186 reipl_block_ccw_init(reipl_block_ccw
);
1187 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1188 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1189 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1192 reipl_capabilities
|= IPL_TYPE_CCW
;
1196 static int __init
reipl_fcp_init(void)
1200 if (!diag308_set_works
) {
1201 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1202 make_attrs_ro(reipl_fcp_attrs
);
1203 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1208 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1209 if (!reipl_block_fcp
)
1212 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1213 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1215 if (!reipl_fcp_kset
) {
1216 free_page((unsigned long) reipl_block_fcp
);
1220 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1222 kset_unregister(reipl_fcp_kset
);
1223 free_page((unsigned long) reipl_block_fcp
);
1227 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1228 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1230 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1231 * is invalid in the SCSI IPL parameter block, so take it
1232 * always from sclp_ipl_info.
1234 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1237 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1238 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1239 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1240 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1241 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1243 reipl_capabilities
|= IPL_TYPE_FCP
;
1247 static int __init
reipl_type_init(void)
1249 enum ipl_type reipl_type
= ipl_info
.type
;
1250 struct ipl_parameter_block
*reipl_block
;
1253 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1257 * If we have an OS info reipl block, this will be used
1259 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1260 memcpy(reipl_block_fcp
, reipl_block
, size
);
1261 reipl_type
= IPL_TYPE_FCP
;
1262 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1263 memcpy(reipl_block_ccw
, reipl_block
, size
);
1264 reipl_type
= IPL_TYPE_CCW
;
1267 return reipl_set_type(reipl_type
);
1270 static int __init
reipl_init(void)
1274 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1277 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1279 kset_unregister(reipl_kset
);
1282 rc
= reipl_ccw_init();
1285 rc
= reipl_fcp_init();
1288 rc
= reipl_nss_init();
1291 return reipl_type_init();
1294 static struct shutdown_action __refdata reipl_action
= {
1295 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1301 * dump shutdown action: Dump Linux on shutdown.
1304 /* FCP dump device attributes */
1306 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1307 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1308 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1309 dump_block_fcp
->ipl_info
.fcp
.lun
);
1310 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1311 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1312 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1313 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1314 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1315 dump_block_fcp
->ipl_info
.fcp
.devno
);
1317 static struct attribute
*dump_fcp_attrs
[] = {
1318 &sys_dump_fcp_device_attr
.attr
,
1319 &sys_dump_fcp_wwpn_attr
.attr
,
1320 &sys_dump_fcp_lun_attr
.attr
,
1321 &sys_dump_fcp_bootprog_attr
.attr
,
1322 &sys_dump_fcp_br_lba_attr
.attr
,
1326 static struct attribute_group dump_fcp_attr_group
= {
1327 .name
= IPL_FCP_STR
,
1328 .attrs
= dump_fcp_attrs
,
1331 /* CCW dump device attributes */
1333 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1334 dump_block_ccw
->ipl_info
.ccw
.devno
);
1336 static struct attribute
*dump_ccw_attrs
[] = {
1337 &sys_dump_ccw_device_attr
.attr
,
1341 static struct attribute_group dump_ccw_attr_group
= {
1342 .name
= IPL_CCW_STR
,
1343 .attrs
= dump_ccw_attrs
,
1348 static int dump_set_type(enum dump_type type
)
1350 if (!(dump_capabilities
& type
))
1354 if (diag308_set_works
)
1355 dump_method
= DUMP_METHOD_CCW_DIAG
;
1356 else if (MACHINE_IS_VM
)
1357 dump_method
= DUMP_METHOD_CCW_VM
;
1359 dump_method
= DUMP_METHOD_CCW_CIO
;
1362 dump_method
= DUMP_METHOD_FCP_DIAG
;
1365 dump_method
= DUMP_METHOD_NONE
;
1371 static ssize_t
dump_type_show(struct kobject
*kobj
,
1372 struct kobj_attribute
*attr
, char *page
)
1374 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1377 static ssize_t
dump_type_store(struct kobject
*kobj
,
1378 struct kobj_attribute
*attr
,
1379 const char *buf
, size_t len
)
1383 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1384 rc
= dump_set_type(DUMP_TYPE_NONE
);
1385 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1386 rc
= dump_set_type(DUMP_TYPE_CCW
);
1387 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1388 rc
= dump_set_type(DUMP_TYPE_FCP
);
1389 return (rc
!= 0) ? rc
: len
;
1392 static struct kobj_attribute dump_type_attr
=
1393 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1395 static struct kset
*dump_kset
;
1397 static void diag308_dump(void *dump_block
)
1399 diag308(DIAG308_SET
, dump_block
);
1401 if (diag308(DIAG308_DUMP
, NULL
) != 0x302)
1403 udelay_simple(USEC_PER_SEC
);
1407 static void __dump_run(void *unused
)
1409 struct ccw_dev_id devid
;
1410 static char buf
[100];
1412 switch (dump_method
) {
1413 case DUMP_METHOD_CCW_CIO
:
1414 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1416 reipl_ccw_dev(&devid
);
1418 case DUMP_METHOD_CCW_VM
:
1419 sprintf(buf
, "STORE STATUS");
1420 __cpcmd(buf
, NULL
, 0, NULL
);
1421 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1422 __cpcmd(buf
, NULL
, 0, NULL
);
1424 case DUMP_METHOD_CCW_DIAG
:
1425 diag308_dump(dump_block_ccw
);
1427 case DUMP_METHOD_FCP_DIAG
:
1428 diag308_dump(dump_block_fcp
);
1435 static void dump_run(struct shutdown_trigger
*trigger
)
1437 if (dump_method
== DUMP_METHOD_NONE
)
1440 smp_call_ipl_cpu(__dump_run
, NULL
);
1443 static int __init
dump_ccw_init(void)
1447 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1448 if (!dump_block_ccw
)
1450 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1452 free_page((unsigned long)dump_block_ccw
);
1455 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1456 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1457 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1458 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1459 dump_capabilities
|= DUMP_TYPE_CCW
;
1463 static int __init
dump_fcp_init(void)
1467 if (!sclp_ipl_info
.has_dump
)
1468 return 0; /* LDIPL DUMP is not installed */
1469 if (!diag308_set_works
)
1471 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1472 if (!dump_block_fcp
)
1474 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1476 free_page((unsigned long)dump_block_fcp
);
1479 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1480 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1481 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1482 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1483 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1484 dump_capabilities
|= DUMP_TYPE_FCP
;
1488 static int __init
dump_init(void)
1492 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1495 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1497 kset_unregister(dump_kset
);
1500 rc
= dump_ccw_init();
1503 rc
= dump_fcp_init();
1506 dump_set_type(DUMP_TYPE_NONE
);
1510 static struct shutdown_action __refdata dump_action
= {
1511 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1516 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1518 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1521 csum
= csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1522 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1523 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1527 static int __init
dump_reipl_init(void)
1529 if (!diag308_set_works
)
1535 static struct shutdown_action __refdata dump_reipl_action
= {
1536 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1537 .fn
= dump_reipl_run
,
1538 .init
= dump_reipl_init
,
1542 * vmcmd shutdown action: Trigger vm command on shutdown.
1545 static char vmcmd_on_reboot
[128];
1546 static char vmcmd_on_panic
[128];
1547 static char vmcmd_on_halt
[128];
1548 static char vmcmd_on_poff
[128];
1549 static char vmcmd_on_restart
[128];
1551 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1552 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1553 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1554 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1555 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1557 static struct attribute
*vmcmd_attrs
[] = {
1558 &sys_vmcmd_on_reboot_attr
.attr
,
1559 &sys_vmcmd_on_panic_attr
.attr
,
1560 &sys_vmcmd_on_halt_attr
.attr
,
1561 &sys_vmcmd_on_poff_attr
.attr
,
1562 &sys_vmcmd_on_restart_attr
.attr
,
1566 static struct attribute_group vmcmd_attr_group
= {
1567 .attrs
= vmcmd_attrs
,
1570 static struct kset
*vmcmd_kset
;
1572 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1576 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1577 cmd
= vmcmd_on_reboot
;
1578 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1579 cmd
= vmcmd_on_panic
;
1580 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1581 cmd
= vmcmd_on_halt
;
1582 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1583 cmd
= vmcmd_on_poff
;
1584 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1585 cmd
= vmcmd_on_restart
;
1589 if (strlen(cmd
) == 0)
1591 __cpcmd(cmd
, NULL
, 0, NULL
);
1594 static int vmcmd_init(void)
1598 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1601 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1604 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1605 vmcmd_run
, vmcmd_init
};
1608 * stop shutdown action: Stop Linux on shutdown.
1611 static void stop_run(struct shutdown_trigger
*trigger
)
1613 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1614 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1615 disabled_wait((unsigned long) __builtin_return_address(0));
1619 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1624 static struct shutdown_action
*shutdown_actions_list
[] = {
1625 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1626 &vmcmd_action
, &stop_action
};
1627 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1633 static struct kset
*shutdown_actions_kset
;
1635 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1640 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1641 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1642 if (shutdown_actions_list
[i
]->init_rc
) {
1643 return shutdown_actions_list
[i
]->init_rc
;
1645 trigger
->action
= shutdown_actions_list
[i
];
1655 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1658 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1659 struct kobj_attribute
*attr
, char *page
)
1661 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1664 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1665 struct kobj_attribute
*attr
,
1666 const char *buf
, size_t len
)
1668 return set_trigger(buf
, &on_reboot_trigger
, len
);
1670 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1672 static void do_machine_restart(char *__unused
)
1675 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1678 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1682 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1684 static ssize_t
on_panic_show(struct kobject
*kobj
,
1685 struct kobj_attribute
*attr
, char *page
)
1687 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1690 static ssize_t
on_panic_store(struct kobject
*kobj
,
1691 struct kobj_attribute
*attr
,
1692 const char *buf
, size_t len
)
1694 return set_trigger(buf
, &on_panic_trigger
, len
);
1696 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1698 static void do_panic(void)
1701 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1702 stop_run(&on_panic_trigger
);
1707 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1710 static ssize_t
on_restart_show(struct kobject
*kobj
,
1711 struct kobj_attribute
*attr
, char *page
)
1713 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1716 static ssize_t
on_restart_store(struct kobject
*kobj
,
1717 struct kobj_attribute
*attr
,
1718 const char *buf
, size_t len
)
1720 return set_trigger(buf
, &on_restart_trigger
, len
);
1722 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1724 static void __do_restart(void *ignore
)
1726 __arch_local_irq_stosm(0x04); /* enable DAT */
1728 #ifdef CONFIG_CRASH_DUMP
1731 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1732 stop_run(&on_restart_trigger
);
1735 void do_restart(void)
1740 smp_call_online_cpu(__do_restart
, NULL
);
1745 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1747 static ssize_t
on_halt_show(struct kobject
*kobj
,
1748 struct kobj_attribute
*attr
, char *page
)
1750 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1753 static ssize_t
on_halt_store(struct kobject
*kobj
,
1754 struct kobj_attribute
*attr
,
1755 const char *buf
, size_t len
)
1757 return set_trigger(buf
, &on_halt_trigger
, len
);
1759 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1761 static void do_machine_halt(void)
1764 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1765 stop_run(&on_halt_trigger
);
1767 void (*_machine_halt
)(void) = do_machine_halt
;
1771 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1773 static ssize_t
on_poff_show(struct kobject
*kobj
,
1774 struct kobj_attribute
*attr
, char *page
)
1776 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1779 static ssize_t
on_poff_store(struct kobject
*kobj
,
1780 struct kobj_attribute
*attr
,
1781 const char *buf
, size_t len
)
1783 return set_trigger(buf
, &on_poff_trigger
, len
);
1785 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1787 static void do_machine_power_off(void)
1790 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1791 stop_run(&on_poff_trigger
);
1793 void (*_machine_power_off
)(void) = do_machine_power_off
;
1795 static struct attribute
*shutdown_action_attrs
[] = {
1796 &on_restart_attr
.attr
,
1797 &on_reboot_attr
.attr
,
1798 &on_panic_attr
.attr
,
1804 static struct attribute_group shutdown_action_attr_group
= {
1805 .attrs
= shutdown_action_attrs
,
1808 static void __init
shutdown_triggers_init(void)
1810 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1812 if (!shutdown_actions_kset
)
1814 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1815 &shutdown_action_attr_group
))
1819 panic("shutdown_triggers_init failed\n");
1822 static void __init
shutdown_actions_init(void)
1826 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1827 if (!shutdown_actions_list
[i
]->init
)
1829 shutdown_actions_list
[i
]->init_rc
=
1830 shutdown_actions_list
[i
]->init();
1834 static int __init
s390_ipl_init(void)
1836 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1838 sclp_get_ipl_info(&sclp_ipl_info
);
1840 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1841 * returned by read SCP info is invalid (contains EBCDIC blanks)
1842 * when the system has been booted via diag308. In that case we use
1843 * the value from diag308, if available.
1845 * There are also systems where diag308 store does not work in
1846 * case the system is booted from HMC. Fortunately in this case
1847 * READ SCP info provides the correct value.
1849 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 &&
1851 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
,
1853 shutdown_actions_init();
1854 shutdown_triggers_init();
1858 __initcall(s390_ipl_init
);
1860 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1865 for (sx
= 0; src
[sx
] != 0; sx
++) {
1868 dst
[dx
++] = src
[sx
];
1874 static int __init
vmcmd_on_reboot_setup(char *str
)
1878 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1879 vmcmd_on_reboot
[127] = 0;
1880 on_reboot_trigger
.action
= &vmcmd_action
;
1883 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1885 static int __init
vmcmd_on_panic_setup(char *str
)
1889 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1890 vmcmd_on_panic
[127] = 0;
1891 on_panic_trigger
.action
= &vmcmd_action
;
1894 __setup("vmpanic=", vmcmd_on_panic_setup
);
1896 static int __init
vmcmd_on_halt_setup(char *str
)
1900 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1901 vmcmd_on_halt
[127] = 0;
1902 on_halt_trigger
.action
= &vmcmd_action
;
1905 __setup("vmhalt=", vmcmd_on_halt_setup
);
1907 static int __init
vmcmd_on_poff_setup(char *str
)
1911 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1912 vmcmd_on_poff
[127] = 0;
1913 on_poff_trigger
.action
= &vmcmd_action
;
1916 __setup("vmpoff=", vmcmd_on_poff_setup
);
1918 static int on_panic_notify(struct notifier_block
*self
,
1919 unsigned long event
, void *data
)
1925 static struct notifier_block on_panic_nb
= {
1926 .notifier_call
= on_panic_notify
,
1927 .priority
= INT_MIN
,
1930 void __init
setup_ipl(void)
1932 ipl_info
.type
= get_ipl_type();
1933 switch (ipl_info
.type
) {
1935 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1936 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1939 case IPL_TYPE_FCP_DUMP
:
1940 ipl_info
.data
.fcp
.dev_id
.devno
=
1941 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1942 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1943 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1944 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1947 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1948 sizeof(ipl_info
.data
.nss
.name
));
1950 case IPL_TYPE_UNKNOWN
:
1951 /* We have no info to copy */
1954 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1957 void __init
ipl_update_parameters(void)
1961 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1962 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1963 diag308_set_works
= 1;
1966 void __init
ipl_save_parameters(void)
1968 struct cio_iplinfo iplinfo
;
1971 if (cio_get_iplinfo(&iplinfo
))
1974 ipl_devno
= iplinfo
.devno
;
1975 ipl_flags
|= IPL_DEVNO_VALID
;
1976 if (!iplinfo
.is_qdio
)
1978 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1979 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1980 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1981 memmove(dst
, src
, PAGE_SIZE
);
1982 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1985 static LIST_HEAD(rcall
);
1986 static DEFINE_MUTEX(rcall_mutex
);
1988 void register_reset_call(struct reset_call
*reset
)
1990 mutex_lock(&rcall_mutex
);
1991 list_add(&reset
->list
, &rcall
);
1992 mutex_unlock(&rcall_mutex
);
1994 EXPORT_SYMBOL_GPL(register_reset_call
);
1996 void unregister_reset_call(struct reset_call
*reset
)
1998 mutex_lock(&rcall_mutex
);
1999 list_del(&reset
->list
);
2000 mutex_unlock(&rcall_mutex
);
2002 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2004 static void do_reset_calls(void)
2006 struct reset_call
*reset
;
2008 if (diag308_set_works
) {
2012 list_for_each_entry(reset
, &rcall
, list
)
2016 u32 dump_prefix_page
;
2018 void s390_reset_system(void (*fn_pre
)(void),
2019 void (*fn_post
)(void *), void *data
)
2021 struct _lowcore
*lc
;
2023 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
2025 /* Stack for interrupt/machine check handler */
2026 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2028 /* Save prefix page address for dump case */
2029 dump_prefix_page
= (u32
)(unsigned long) lc
;
2031 /* Disable prefixing */
2034 /* Disable lowcore protection */
2035 __ctl_clear_bit(0,28);
2037 /* Set new machine check handler */
2038 S390_lowcore
.mcck_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2039 S390_lowcore
.mcck_new_psw
.addr
=
2040 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
2042 /* Set new program check handler */
2043 S390_lowcore
.program_new_psw
.mask
= PSW_KERNEL_BITS
| PSW_MASK_DAT
;
2044 S390_lowcore
.program_new_psw
.addr
=
2045 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;
2048 * Clear subchannel ID and number to signal new kernel that no CCW or
2049 * SCSI IPL has been done (for kexec and kdump)
2051 S390_lowcore
.subchannel_id
= 0;
2052 S390_lowcore
.subchannel_nr
= 0;
2054 /* Store status at absolute zero */
2057 /* Call function before reset */
2061 /* Call function after reset */