Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1 | /* |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 2 | * ipl/reipl/dump support for Linux on s390. |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2005, 2012 |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 5 | * Author(s): Michael Holzheu <holzheu@de.ibm.com> |
| 6 | * Heiko Carstens <heiko.carstens@de.ibm.com> |
| 7 | * Volker Sameske <sameske@de.ibm.com> |
| 8 | */ |
| 9 | |
| 10 | #include <linux/types.h> |
Paul Gortmaker | 3994a52 | 2017-02-09 15:20:23 -0500 | [diff] [blame] | 11 | #include <linux/export.h> |
| 12 | #include <linux/init.h> |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 13 | #include <linux/device.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/reboot.h> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 16 | #include <linux/ctype.h> |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 17 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/gfp.h> |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 19 | #include <linux/crash_dump.h> |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 20 | #include <linux/debug_locks.h> |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 21 | #include <asm/diag.h> |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 22 | #include <asm/ipl.h> |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 23 | #include <asm/smp.h> |
| 24 | #include <asm/setup.h> |
| 25 | #include <asm/cpcmd.h> |
| 26 | #include <asm/cio.h> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 27 | #include <asm/ebcdic.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 28 | #include <asm/reset.h> |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 29 | #include <asm/sclp.h> |
Frank Munzert | 159d1ff | 2009-03-26 15:24:45 +0100 | [diff] [blame] | 30 | #include <asm/checksum.h> |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 31 | #include <asm/debug.h> |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 32 | #include <asm/os_info.h> |
Martin Schwidefsky | 638ad34 | 2011-10-30 15:17:13 +0100 | [diff] [blame] | 33 | #include "entry.h" |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 34 | |
| 35 | #define IPL_PARM_BLOCK_VERSION 0 |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 36 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 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" |
Heiko Carstens | 615b04b | 2007-02-21 10:55:37 +0100 | [diff] [blame] | 42 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 43 | #define DUMP_CCW_STR "ccw" |
| 44 | #define DUMP_FCP_STR "fcp" |
| 45 | #define DUMP_NONE_STR "none" |
| 46 | |
| 47 | /* |
| 48 | * Four shutdown trigger types are supported: |
| 49 | * - panic |
| 50 | * - halt |
| 51 | * - power off |
| 52 | * - reipl |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 53 | * - restart |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 54 | */ |
| 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" |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 59 | #define ON_RESTART_STR "on_restart" |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 60 | |
| 61 | struct shutdown_action; |
| 62 | struct shutdown_trigger { |
| 63 | char *name; |
| 64 | struct shutdown_action *action; |
| 65 | }; |
| 66 | |
| 67 | /* |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 68 | * The following shutdown action types are supported: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 69 | */ |
| 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" |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 75 | #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl" |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 76 | |
| 77 | struct shutdown_action { |
| 78 | char *name; |
| 79 | void (*fn) (struct shutdown_trigger *trigger); |
| 80 | int (*init) (void); |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 81 | int init_rc; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 84 | static char *ipl_type_str(enum ipl_type type) |
| 85 | { |
| 86 | switch (type) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 87 | case IPL_TYPE_CCW: |
| 88 | return IPL_CCW_STR; |
| 89 | case IPL_TYPE_FCP: |
| 90 | return IPL_FCP_STR; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 91 | case IPL_TYPE_FCP_DUMP: |
| 92 | return IPL_FCP_DUMP_STR; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 93 | case IPL_TYPE_NSS: |
| 94 | return IPL_NSS_STR; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 95 | case IPL_TYPE_UNKNOWN: |
| 96 | default: |
| 97 | return IPL_UNKNOWN_STR; |
| 98 | } |
| 99 | } |
| 100 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 101 | enum dump_type { |
| 102 | DUMP_TYPE_NONE = 1, |
| 103 | DUMP_TYPE_CCW = 2, |
| 104 | DUMP_TYPE_FCP = 4, |
| 105 | }; |
| 106 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 107 | static char *dump_type_str(enum dump_type type) |
| 108 | { |
| 109 | switch (type) { |
| 110 | case DUMP_TYPE_NONE: |
| 111 | return DUMP_NONE_STR; |
| 112 | case DUMP_TYPE_CCW: |
| 113 | return DUMP_CCW_STR; |
| 114 | case DUMP_TYPE_FCP: |
| 115 | return DUMP_FCP_STR; |
| 116 | default: |
| 117 | return NULL; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Must be in data section since the bss section |
| 123 | * is not cleared when these are accessed. |
| 124 | */ |
Heiko Carstens | 72a9b02 | 2016-06-07 10:23:07 +0200 | [diff] [blame] | 125 | static u8 ipl_ssid __section(.data) = 0; |
| 126 | static u16 ipl_devno __section(.data) = 0; |
| 127 | u32 ipl_flags __section(.data) = 0; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 128 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 129 | enum ipl_method { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 130 | REIPL_METHOD_CCW_CIO, |
| 131 | REIPL_METHOD_CCW_DIAG, |
| 132 | REIPL_METHOD_CCW_VM, |
| 133 | REIPL_METHOD_FCP_RO_DIAG, |
| 134 | REIPL_METHOD_FCP_RW_DIAG, |
| 135 | REIPL_METHOD_FCP_RO_VM, |
| 136 | REIPL_METHOD_FCP_DUMP, |
| 137 | REIPL_METHOD_NSS, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 138 | REIPL_METHOD_NSS_DIAG, |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 139 | REIPL_METHOD_DEFAULT, |
| 140 | }; |
| 141 | |
| 142 | enum dump_method { |
| 143 | DUMP_METHOD_NONE, |
| 144 | DUMP_METHOD_CCW_CIO, |
| 145 | DUMP_METHOD_CCW_DIAG, |
| 146 | DUMP_METHOD_CCW_VM, |
| 147 | DUMP_METHOD_FCP_DIAG, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 150 | static int diag308_set_works = 0; |
| 151 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 152 | static struct ipl_parameter_block ipl_block; |
| 153 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 154 | static int reipl_capabilities = IPL_TYPE_UNKNOWN; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 155 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 156 | static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 157 | static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 158 | static struct ipl_parameter_block *reipl_block_fcp; |
| 159 | static struct ipl_parameter_block *reipl_block_ccw; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 160 | static struct ipl_parameter_block *reipl_block_nss; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 161 | static struct ipl_parameter_block *reipl_block_actual; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 162 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 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; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 166 | static struct ipl_parameter_block *dump_block_fcp; |
| 167 | static struct ipl_parameter_block *dump_block_ccw; |
| 168 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 169 | static struct sclp_ipl_info sclp_ipl_info; |
| 170 | |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 171 | static inline int __diag308(unsigned long subcode, void *addr) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 172 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 173 | register unsigned long _addr asm("0") = (unsigned long) addr; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 174 | register unsigned long _rc asm("1") = 0; |
| 175 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 176 | asm volatile( |
| 177 | " diag %0,%2,0x308\n" |
Heiko Carstens | 6c22c98 | 2016-06-10 09:57:05 +0200 | [diff] [blame] | 178 | "0: nopr %%r7\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 179 | EX_TABLE(0b,0b) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 180 | : "+d" (_addr), "+d" (_rc) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 181 | : "d" (subcode) : "cc", "memory"); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 182 | return _rc; |
| 183 | } |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 184 | |
| 185 | int diag308(unsigned long subcode, void *addr) |
| 186 | { |
| 187 | diag_stat_inc(DIAG_STAT_X308); |
| 188 | return __diag308(subcode, addr); |
| 189 | } |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 190 | EXPORT_SYMBOL_GPL(diag308); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 191 | |
| 192 | /* SYSFS */ |
| 193 | |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 194 | #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 195 | static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ |
| 196 | struct kobj_attribute *attr, \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 197 | char *page) \ |
| 198 | { \ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 199 | return snprintf(page, PAGE_SIZE, _format, ##args); \ |
| 200 | } |
| 201 | |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 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) \ |
| 206 | { \ |
| 207 | unsigned long long ssid, devno; \ |
| 208 | \ |
| 209 | if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \ |
| 210 | return -EINVAL; \ |
| 211 | \ |
| 212 | if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \ |
| 213 | return -EINVAL; \ |
| 214 | \ |
| 215 | _ipl_blk.ssid = ssid; \ |
| 216 | _ipl_blk.devno = devno; \ |
| 217 | return len; \ |
| 218 | } |
| 219 | |
| 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) \ |
| 228 | |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 229 | #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ |
| 230 | IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 231 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 232 | __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 233 | |
| 234 | #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 235 | IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 236 | static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ |
| 237 | struct kobj_attribute *attr, \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 238 | const char *buf, size_t len) \ |
| 239 | { \ |
| 240 | unsigned long long value; \ |
| 241 | if (sscanf(buf, _fmt_in, &value) != 1) \ |
| 242 | return -EINVAL; \ |
| 243 | _value = value; \ |
| 244 | return len; \ |
| 245 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 246 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 247 | __ATTR(_name,(S_IRUGO | S_IWUSR), \ |
| 248 | sys_##_prefix##_##_name##_show, \ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 249 | sys_##_prefix##_##_name##_store) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 250 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 251 | #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 252 | IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 253 | static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ |
| 254 | struct kobj_attribute *attr, \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 255 | const char *buf, size_t len) \ |
| 256 | { \ |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 257 | strncpy(_value, buf, sizeof(_value) - 1); \ |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 258 | strim(_value); \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 259 | return len; \ |
| 260 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 261 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 262 | __ATTR(_name,(S_IRUGO | S_IWUSR), \ |
| 263 | sys_##_prefix##_##_name##_show, \ |
Sebastian Ott | 3be7ae6 | 2015-03-17 10:36:14 +0100 | [diff] [blame] | 264 | sys_##_prefix##_##_name##_store) |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 265 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 266 | static void make_attrs_ro(struct attribute **attrs) |
| 267 | { |
| 268 | while (*attrs) { |
| 269 | (*attrs)->mode = S_IRUGO; |
| 270 | attrs++; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * ipl section |
| 276 | */ |
| 277 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 278 | static __init enum ipl_type get_ipl_type(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 279 | { |
| 280 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 281 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 282 | if (ipl_flags & IPL_NSS_VALID) |
| 283 | return IPL_TYPE_NSS; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 284 | if (!(ipl_flags & IPL_DEVNO_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 285 | return IPL_TYPE_UNKNOWN; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 286 | if (!(ipl_flags & IPL_PARMBLOCK_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 287 | return IPL_TYPE_CCW; |
| 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; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 292 | if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP) |
| 293 | return IPL_TYPE_FCP_DUMP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 294 | return IPL_TYPE_FCP; |
| 295 | } |
| 296 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 297 | struct ipl_info ipl_info; |
| 298 | EXPORT_SYMBOL_GPL(ipl_info); |
| 299 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 300 | static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 301 | char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 302 | { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 303 | return sprintf(page, "%s\n", ipl_type_str(ipl_info.type)); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 306 | static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 307 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 308 | /* VM IPL PARM routines */ |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 309 | static size_t reipl_get_ascii_vmparm(char *dest, size_t size, |
| 310 | const struct ipl_parameter_block *ipb) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 311 | { |
| 312 | int i; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 313 | size_t len; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 314 | char has_lowercase = 0; |
| 315 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 316 | len = 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 317 | if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) && |
| 318 | (ipb->ipl_info.ccw.vm_parm_len > 0)) { |
| 319 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 320 | len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 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. |
| 324 | */ |
| 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 */ |
| 329 | has_lowercase = 1; |
| 330 | break; |
| 331 | } |
| 332 | if (!has_lowercase) |
| 333 | EBC_TOLOWER(dest, len); |
| 334 | EBCASC(dest, len); |
| 335 | } |
| 336 | dest[len] = 0; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 337 | |
| 338 | return len; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 341 | size_t append_ipl_vmparm(char *dest, size_t size) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 342 | { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 343 | size_t rc; |
| 344 | |
| 345 | rc = 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 346 | if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW)) |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 347 | rc = reipl_get_ascii_vmparm(dest, size, &ipl_block); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 348 | else |
| 349 | dest[0] = 0; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 350 | return rc; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static ssize_t ipl_vm_parm_show(struct kobject *kobj, |
| 354 | struct kobj_attribute *attr, char *page) |
| 355 | { |
| 356 | char parm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 357 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 358 | append_ipl_vmparm(parm, sizeof(parm)); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 359 | return sprintf(page, "%s\n", parm); |
| 360 | } |
| 361 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 362 | static size_t scpdata_length(const char* buf, size_t count) |
| 363 | { |
| 364 | while (count) { |
| 365 | if (buf[count - 1] != '\0' && buf[count - 1] != ' ') |
| 366 | break; |
| 367 | count--; |
| 368 | } |
| 369 | return count; |
| 370 | } |
| 371 | |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 372 | static size_t reipl_append_ascii_scpdata(char *dest, size_t size, |
| 373 | const struct ipl_parameter_block *ipb) |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 374 | { |
| 375 | size_t count; |
| 376 | size_t i; |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 377 | int has_lowercase; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 378 | |
| 379 | count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data, |
| 380 | ipb->ipl_info.fcp.scp_data_len)); |
| 381 | if (!count) |
| 382 | goto out; |
| 383 | |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 384 | has_lowercase = 0; |
| 385 | for (i = 0; i < count; i++) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 386 | if (!isascii(ipb->ipl_info.fcp.scp_data[i])) { |
| 387 | count = 0; |
| 388 | goto out; |
| 389 | } |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 390 | if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i])) |
| 391 | has_lowercase = 1; |
| 392 | } |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 393 | |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 394 | if (has_lowercase) |
| 395 | memcpy(dest, ipb->ipl_info.fcp.scp_data, count); |
| 396 | else |
| 397 | for (i = 0; i < count; i++) |
| 398 | dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 399 | out: |
| 400 | dest[count] = '\0'; |
| 401 | return count; |
| 402 | } |
| 403 | |
| 404 | size_t append_ipl_scpdata(char *dest, size_t len) |
| 405 | { |
| 406 | size_t rc; |
| 407 | |
| 408 | rc = 0; |
| 409 | if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP) |
| 410 | rc = reipl_append_ascii_scpdata(dest, len, &ipl_block); |
| 411 | else |
| 412 | dest[0] = 0; |
| 413 | return rc; |
| 414 | } |
| 415 | |
| 416 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 417 | static struct kobj_attribute sys_ipl_vm_parm_attr = |
| 418 | __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL); |
| 419 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 420 | static ssize_t sys_ipl_device_show(struct kobject *kobj, |
| 421 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 422 | { |
| 423 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 424 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 425 | switch (ipl_info.type) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 426 | case IPL_TYPE_CCW: |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 427 | return sprintf(page, "0.%x.%04x\n", ipl_ssid, ipl_devno); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 428 | case IPL_TYPE_FCP: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 429 | case IPL_TYPE_FCP_DUMP: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 430 | return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno); |
| 431 | default: |
| 432 | return 0; |
| 433 | } |
| 434 | } |
| 435 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 436 | static struct kobj_attribute sys_ipl_device_attr = |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 437 | __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); |
| 438 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 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) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 442 | { |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 443 | return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START, |
| 444 | IPL_PARMBLOCK_SIZE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 445 | } |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 446 | static struct bin_attribute ipl_parameter_attr = |
| 447 | __BIN_ATTR(binary_parameter, S_IRUGO, ipl_parameter_read, NULL, |
| 448 | PAGE_SIZE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 449 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 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) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 453 | { |
| 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; |
| 456 | |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 457 | return memory_read_from_buffer(buf, count, &off, scp_data, size); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 458 | } |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 459 | static struct bin_attribute ipl_scp_data_attr = |
| 460 | __BIN_ATTR(scp_data, S_IRUGO, ipl_scp_data_read, NULL, PAGE_SIZE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 461 | |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 462 | static struct bin_attribute *ipl_fcp_bin_attrs[] = { |
| 463 | &ipl_parameter_attr, |
| 464 | &ipl_scp_data_attr, |
| 465 | NULL, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 466 | }; |
| 467 | |
| 468 | /* FCP ipl device attributes */ |
| 469 | |
| 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); |
| 478 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 479 | static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj, |
| 480 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 481 | { |
| 482 | char loadparm[LOADPARM_LEN + 1] = {}; |
| 483 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 484 | if (!sclp_ipl_info.is_valid) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 485 | return sprintf(page, "#unknown#\n"); |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 486 | memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 487 | EBCASC(loadparm, LOADPARM_LEN); |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 488 | strim(loadparm); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 489 | return sprintf(page, "%s\n", loadparm); |
| 490 | } |
| 491 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 492 | static struct kobj_attribute sys_ipl_ccw_loadparm_attr = |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 493 | __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); |
| 494 | |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 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, |
| 503 | NULL, |
| 504 | }; |
| 505 | |
| 506 | static struct attribute_group ipl_fcp_attr_group = { |
| 507 | .attrs = ipl_fcp_attrs, |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 508 | .bin_attrs = ipl_fcp_bin_attrs, |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | /* CCW ipl device attributes */ |
| 512 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 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, |
| 518 | NULL, |
| 519 | }; |
| 520 | |
| 521 | static struct attribute *ipl_ccw_attrs_lpar[] = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 522 | &sys_ipl_type_attr.attr, |
| 523 | &sys_ipl_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 524 | &sys_ipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 525 | NULL, |
| 526 | }; |
| 527 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 528 | static struct attribute_group ipl_ccw_attr_group_vm = { |
| 529 | .attrs = ipl_ccw_attrs_vm, |
| 530 | }; |
| 531 | |
| 532 | static struct attribute_group ipl_ccw_attr_group_lpar = { |
| 533 | .attrs = ipl_ccw_attrs_lpar |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 534 | }; |
| 535 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 536 | /* NSS ipl device attributes */ |
| 537 | |
| 538 | DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name); |
| 539 | |
| 540 | static struct attribute *ipl_nss_attrs[] = { |
| 541 | &sys_ipl_type_attr.attr, |
| 542 | &sys_ipl_nss_name_attr.attr, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 543 | &sys_ipl_ccw_loadparm_attr.attr, |
| 544 | &sys_ipl_vm_parm_attr.attr, |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 545 | NULL, |
| 546 | }; |
| 547 | |
| 548 | static struct attribute_group ipl_nss_attr_group = { |
| 549 | .attrs = ipl_nss_attrs, |
| 550 | }; |
| 551 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 552 | /* UNKNOWN ipl device attributes */ |
| 553 | |
| 554 | static struct attribute *ipl_unknown_attrs[] = { |
| 555 | &sys_ipl_type_attr.attr, |
| 556 | NULL, |
| 557 | }; |
| 558 | |
| 559 | static struct attribute_group ipl_unknown_attr_group = { |
| 560 | .attrs = ipl_unknown_attrs, |
| 561 | }; |
| 562 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 563 | static struct kset *ipl_kset; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 564 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 565 | static void __ipl_run(void *unused) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 566 | { |
Heiko Carstens | 7afbeb6 | 2017-02-24 12:56:12 +0100 | [diff] [blame] | 567 | if (MACHINE_IS_LPAR && ipl_info.type == IPL_TYPE_CCW) |
| 568 | diag308(DIAG308_LOAD_NORMAL_DUMP, NULL); |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 569 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 570 | if (MACHINE_IS_VM) |
| 571 | __cpcmd("IPL", NULL, 0, NULL); |
| 572 | else if (ipl_info.type == IPL_TYPE_CCW) |
| 573 | reipl_ccw_dev(&ipl_info.data.ccw.dev_id); |
| 574 | } |
| 575 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 576 | static void ipl_run(struct shutdown_trigger *trigger) |
| 577 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 578 | smp_call_ipl_cpu(__ipl_run, NULL); |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 581 | static int __init ipl_init(void) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 582 | { |
| 583 | int rc; |
| 584 | |
| 585 | ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj); |
| 586 | if (!ipl_kset) { |
| 587 | rc = -ENOMEM; |
| 588 | goto out; |
| 589 | } |
| 590 | switch (ipl_info.type) { |
| 591 | case IPL_TYPE_CCW: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 592 | if (MACHINE_IS_VM) |
| 593 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 594 | &ipl_ccw_attr_group_vm); |
| 595 | else |
| 596 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 597 | &ipl_ccw_attr_group_lpar); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 598 | break; |
| 599 | case IPL_TYPE_FCP: |
| 600 | case IPL_TYPE_FCP_DUMP: |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 601 | rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 602 | break; |
| 603 | case IPL_TYPE_NSS: |
| 604 | rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group); |
| 605 | break; |
| 606 | default: |
| 607 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 608 | &ipl_unknown_attr_group); |
| 609 | break; |
| 610 | } |
| 611 | out: |
| 612 | if (rc) |
| 613 | panic("ipl_init failed: rc = %i\n", rc); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 618 | static struct shutdown_action __refdata ipl_action = { |
| 619 | .name = SHUTDOWN_ACTION_IPL_STR, |
| 620 | .fn = ipl_run, |
| 621 | .init = ipl_init, |
| 622 | }; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 623 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 624 | /* |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 625 | * reipl shutdown action: Reboot Linux on shutdown. |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 626 | */ |
| 627 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 628 | /* VM IPL PARM attributes */ |
| 629 | static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb, |
| 630 | char *page) |
| 631 | { |
| 632 | char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 633 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 634 | reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 635 | return sprintf(page, "%s\n", vmparm); |
| 636 | } |
| 637 | |
| 638 | static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb, |
| 639 | size_t vmparm_max, |
| 640 | const char *buf, size_t len) |
| 641 | { |
| 642 | int i, ip_len; |
| 643 | |
| 644 | /* ignore trailing newline */ |
| 645 | ip_len = len; |
| 646 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 647 | ip_len--; |
| 648 | |
| 649 | if (ip_len > vmparm_max) |
| 650 | return -EINVAL; |
| 651 | |
| 652 | /* parm is used to store kernel options, check for common chars */ |
| 653 | for (i = 0; i < ip_len; i++) |
| 654 | if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i]))) |
| 655 | return -EINVAL; |
| 656 | |
| 657 | memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE); |
| 658 | ipb->ipl_info.ccw.vm_parm_len = ip_len; |
| 659 | if (ip_len > 0) { |
| 660 | ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; |
| 661 | memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len); |
| 662 | ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len); |
| 663 | } else { |
| 664 | ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID; |
| 665 | } |
| 666 | |
| 667 | return len; |
| 668 | } |
| 669 | |
| 670 | /* NSS wrapper */ |
| 671 | static ssize_t reipl_nss_vmparm_show(struct kobject *kobj, |
| 672 | struct kobj_attribute *attr, char *page) |
| 673 | { |
| 674 | return reipl_generic_vmparm_show(reipl_block_nss, page); |
| 675 | } |
| 676 | |
| 677 | static ssize_t reipl_nss_vmparm_store(struct kobject *kobj, |
| 678 | struct kobj_attribute *attr, |
| 679 | const char *buf, size_t len) |
| 680 | { |
| 681 | return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len); |
| 682 | } |
| 683 | |
| 684 | /* CCW wrapper */ |
| 685 | static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj, |
| 686 | struct kobj_attribute *attr, char *page) |
| 687 | { |
| 688 | return reipl_generic_vmparm_show(reipl_block_ccw, page); |
| 689 | } |
| 690 | |
| 691 | static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj, |
| 692 | struct kobj_attribute *attr, |
| 693 | const char *buf, size_t len) |
| 694 | { |
| 695 | return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len); |
| 696 | } |
| 697 | |
| 698 | static struct kobj_attribute sys_reipl_nss_vmparm_attr = |
| 699 | __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show, |
| 700 | reipl_nss_vmparm_store); |
| 701 | static struct kobj_attribute sys_reipl_ccw_vmparm_attr = |
| 702 | __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show, |
| 703 | reipl_ccw_vmparm_store); |
| 704 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 705 | /* FCP reipl device attributes */ |
| 706 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 707 | static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj, |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 708 | struct bin_attribute *attr, |
| 709 | char *buf, loff_t off, size_t count) |
| 710 | { |
| 711 | size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len; |
| 712 | void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data; |
| 713 | |
| 714 | return memory_read_from_buffer(buf, count, &off, scp_data, size); |
| 715 | } |
| 716 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 717 | static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj, |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 718 | struct bin_attribute *attr, |
| 719 | char *buf, loff_t off, size_t count) |
| 720 | { |
Sebastian Ott | e0bedad | 2015-11-06 09:58:06 +0100 | [diff] [blame] | 721 | size_t scpdata_len = count; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 722 | size_t padding; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 723 | |
Sebastian Ott | e0bedad | 2015-11-06 09:58:06 +0100 | [diff] [blame] | 724 | |
| 725 | if (off) |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 726 | return -EINVAL; |
| 727 | |
Sebastian Ott | e0bedad | 2015-11-06 09:58:06 +0100 | [diff] [blame] | 728 | memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf, count); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 729 | if (scpdata_len % 8) { |
| 730 | padding = 8 - (scpdata_len % 8); |
| 731 | memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len, |
| 732 | 0, padding); |
| 733 | scpdata_len += padding; |
| 734 | } |
| 735 | |
| 736 | reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len; |
| 737 | reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len; |
| 738 | reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len; |
| 739 | |
| 740 | return count; |
| 741 | } |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 742 | static struct bin_attribute sys_reipl_fcp_scp_data_attr = |
| 743 | __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_fcp_scpdata_read, |
Sebastian Ott | e0bedad | 2015-11-06 09:58:06 +0100 | [diff] [blame] | 744 | reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 745 | |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 746 | static struct bin_attribute *reipl_fcp_bin_attrs[] = { |
| 747 | &sys_reipl_fcp_scp_data_attr, |
| 748 | NULL, |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 749 | }; |
| 750 | |
Michael Holzheu | eda4ddf | 2013-06-21 13:21:30 +0200 | [diff] [blame] | 751 | DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n", |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 752 | reipl_block_fcp->ipl_info.fcp.wwpn); |
Michael Holzheu | eda4ddf | 2013-06-21 13:21:30 +0200 | [diff] [blame] | 753 | DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n", |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 754 | reipl_block_fcp->ipl_info.fcp.lun); |
| 755 | DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n", |
| 756 | reipl_block_fcp->ipl_info.fcp.bootprog); |
| 757 | DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n", |
| 758 | reipl_block_fcp->ipl_info.fcp.br_lba); |
| 759 | DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 760 | reipl_block_fcp->ipl_info.fcp.devno); |
| 761 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 762 | static void reipl_get_ascii_loadparm(char *loadparm, |
| 763 | struct ipl_parameter_block *ibp) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 764 | { |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 765 | memcpy(loadparm, ibp->hdr.loadparm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 766 | EBCASC(loadparm, LOADPARM_LEN); |
| 767 | loadparm[LOADPARM_LEN] = 0; |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 768 | strim(loadparm); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 769 | } |
| 770 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 771 | static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb, |
| 772 | char *page) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 773 | { |
| 774 | char buf[LOADPARM_LEN + 1]; |
| 775 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 776 | reipl_get_ascii_loadparm(buf, ipb); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 777 | return sprintf(page, "%s\n", buf); |
| 778 | } |
| 779 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 780 | static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb, |
| 781 | const char *buf, size_t len) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 782 | { |
| 783 | int i, lp_len; |
| 784 | |
| 785 | /* ignore trailing newline */ |
| 786 | lp_len = len; |
| 787 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 788 | lp_len--; |
| 789 | /* loadparm can have max 8 characters and must not start with a blank */ |
| 790 | if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' '))) |
| 791 | return -EINVAL; |
| 792 | /* loadparm can only contain "a-z,A-Z,0-9,SP,." */ |
| 793 | for (i = 0; i < lp_len; i++) { |
| 794 | if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') || |
| 795 | (buf[i] == '.')) |
| 796 | continue; |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | /* initialize loadparm with blanks */ |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 800 | memset(ipb->hdr.loadparm, ' ', LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 801 | /* copy and convert to ebcdic */ |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 802 | memcpy(ipb->hdr.loadparm, buf, lp_len); |
| 803 | ASCEBC(ipb->hdr.loadparm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 804 | return len; |
| 805 | } |
| 806 | |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 807 | /* FCP wrapper */ |
| 808 | static ssize_t reipl_fcp_loadparm_show(struct kobject *kobj, |
| 809 | struct kobj_attribute *attr, char *page) |
| 810 | { |
| 811 | return reipl_generic_loadparm_show(reipl_block_fcp, page); |
| 812 | } |
| 813 | |
| 814 | static ssize_t reipl_fcp_loadparm_store(struct kobject *kobj, |
| 815 | struct kobj_attribute *attr, |
| 816 | const char *buf, size_t len) |
| 817 | { |
| 818 | return reipl_generic_loadparm_store(reipl_block_fcp, buf, len); |
| 819 | } |
| 820 | |
| 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); |
| 824 | |
| 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, |
| 832 | NULL, |
| 833 | }; |
| 834 | |
| 835 | static struct attribute_group reipl_fcp_attr_group = { |
| 836 | .attrs = reipl_fcp_attrs, |
Sebastian Ott | 22d557a | 2015-03-17 10:25:16 +0100 | [diff] [blame] | 837 | .bin_attrs = reipl_fcp_bin_attrs, |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 838 | }; |
| 839 | |
| 840 | /* CCW reipl device attributes */ |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 841 | DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ipl_info.ccw); |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 842 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 843 | /* NSS wrapper */ |
| 844 | static ssize_t reipl_nss_loadparm_show(struct kobject *kobj, |
| 845 | struct kobj_attribute *attr, char *page) |
| 846 | { |
| 847 | return reipl_generic_loadparm_show(reipl_block_nss, page); |
| 848 | } |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 849 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 850 | static ssize_t reipl_nss_loadparm_store(struct kobject *kobj, |
| 851 | struct kobj_attribute *attr, |
| 852 | const char *buf, size_t len) |
| 853 | { |
| 854 | return reipl_generic_loadparm_store(reipl_block_nss, buf, len); |
| 855 | } |
| 856 | |
| 857 | /* CCW wrapper */ |
| 858 | static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj, |
| 859 | struct kobj_attribute *attr, char *page) |
| 860 | { |
| 861 | return reipl_generic_loadparm_show(reipl_block_ccw, page); |
| 862 | } |
| 863 | |
| 864 | static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj, |
| 865 | struct kobj_attribute *attr, |
| 866 | const char *buf, size_t len) |
| 867 | { |
| 868 | return reipl_generic_loadparm_store(reipl_block_ccw, buf, len); |
| 869 | } |
| 870 | |
| 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); |
| 874 | |
| 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, |
| 879 | NULL, |
| 880 | }; |
| 881 | |
| 882 | static struct attribute *reipl_ccw_attrs_lpar[] = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 883 | &sys_reipl_ccw_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 884 | &sys_reipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 885 | NULL, |
| 886 | }; |
| 887 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 888 | static struct attribute_group reipl_ccw_attr_group_vm = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 889 | .name = IPL_CCW_STR, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 890 | .attrs = reipl_ccw_attrs_vm, |
| 891 | }; |
| 892 | |
| 893 | static struct attribute_group reipl_ccw_attr_group_lpar = { |
| 894 | .name = IPL_CCW_STR, |
| 895 | .attrs = reipl_ccw_attrs_lpar, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 896 | }; |
| 897 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 898 | |
| 899 | /* NSS reipl device attributes */ |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 900 | static void reipl_get_ascii_nss_name(char *dst, |
| 901 | struct ipl_parameter_block *ipb) |
| 902 | { |
| 903 | memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE); |
| 904 | EBCASC(dst, NSS_NAME_SIZE); |
| 905 | dst[NSS_NAME_SIZE] = 0; |
| 906 | } |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 907 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 908 | static ssize_t reipl_nss_name_show(struct kobject *kobj, |
| 909 | struct kobj_attribute *attr, char *page) |
| 910 | { |
| 911 | char nss_name[NSS_NAME_SIZE + 1] = {}; |
| 912 | |
| 913 | reipl_get_ascii_nss_name(nss_name, reipl_block_nss); |
| 914 | return sprintf(page, "%s\n", nss_name); |
| 915 | } |
| 916 | |
| 917 | static ssize_t reipl_nss_name_store(struct kobject *kobj, |
| 918 | struct kobj_attribute *attr, |
| 919 | const char *buf, size_t len) |
| 920 | { |
| 921 | int nss_len; |
| 922 | |
| 923 | /* ignore trailing newline */ |
| 924 | nss_len = len; |
| 925 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 926 | nss_len--; |
| 927 | |
| 928 | if (nss_len > NSS_NAME_SIZE) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE); |
| 932 | if (nss_len > 0) { |
| 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); |
| 938 | } else { |
| 939 | reipl_block_nss->ipl_info.ccw.vm_flags &= |
| 940 | ~DIAG308_VM_FLAGS_NSS_VALID; |
| 941 | } |
| 942 | |
| 943 | return len; |
| 944 | } |
| 945 | |
| 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); |
| 949 | |
| 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); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 953 | |
| 954 | static struct attribute *reipl_nss_attrs[] = { |
| 955 | &sys_reipl_nss_name_attr.attr, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 956 | &sys_reipl_nss_loadparm_attr.attr, |
| 957 | &sys_reipl_nss_vmparm_attr.attr, |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 958 | NULL, |
| 959 | }; |
| 960 | |
| 961 | static struct attribute_group reipl_nss_attr_group = { |
| 962 | .name = IPL_NSS_STR, |
| 963 | .attrs = reipl_nss_attrs, |
| 964 | }; |
| 965 | |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 966 | static void set_reipl_block_actual(struct ipl_parameter_block *reipl_block) |
| 967 | { |
| 968 | reipl_block_actual = reipl_block; |
| 969 | os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual, |
| 970 | reipl_block->hdr.len); |
| 971 | } |
| 972 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 973 | /* reipl type */ |
| 974 | |
| 975 | static int reipl_set_type(enum ipl_type type) |
| 976 | { |
| 977 | if (!(reipl_capabilities & type)) |
| 978 | return -EINVAL; |
| 979 | |
| 980 | switch(type) { |
| 981 | case IPL_TYPE_CCW: |
Michael Holzheu | 48657d2 | 2008-01-26 14:11:17 +0100 | [diff] [blame] | 982 | if (diag308_set_works) |
| 983 | reipl_method = REIPL_METHOD_CCW_DIAG; |
| 984 | else if (MACHINE_IS_VM) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 985 | reipl_method = REIPL_METHOD_CCW_VM; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 986 | else |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 987 | reipl_method = REIPL_METHOD_CCW_CIO; |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 988 | set_reipl_block_actual(reipl_block_ccw); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 989 | break; |
| 990 | case IPL_TYPE_FCP: |
| 991 | if (diag308_set_works) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 992 | reipl_method = REIPL_METHOD_FCP_RW_DIAG; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 993 | else if (MACHINE_IS_VM) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 994 | reipl_method = REIPL_METHOD_FCP_RO_VM; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 995 | else |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 996 | reipl_method = REIPL_METHOD_FCP_RO_DIAG; |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 997 | set_reipl_block_actual(reipl_block_fcp); |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 998 | break; |
| 999 | case IPL_TYPE_FCP_DUMP: |
| 1000 | reipl_method = REIPL_METHOD_FCP_DUMP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1001 | break; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1002 | case IPL_TYPE_NSS: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1003 | if (diag308_set_works) |
| 1004 | reipl_method = REIPL_METHOD_NSS_DIAG; |
| 1005 | else |
| 1006 | reipl_method = REIPL_METHOD_NSS; |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 1007 | set_reipl_block_actual(reipl_block_nss); |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1008 | break; |
| 1009 | case IPL_TYPE_UNKNOWN: |
| 1010 | reipl_method = REIPL_METHOD_DEFAULT; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1011 | break; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1012 | default: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1013 | BUG(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1014 | } |
| 1015 | reipl_type = type; |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1019 | static ssize_t reipl_type_show(struct kobject *kobj, |
| 1020 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1021 | { |
| 1022 | return sprintf(page, "%s\n", ipl_type_str(reipl_type)); |
| 1023 | } |
| 1024 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1025 | static ssize_t reipl_type_store(struct kobject *kobj, |
| 1026 | struct kobj_attribute *attr, |
| 1027 | const char *buf, size_t len) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1028 | { |
| 1029 | int rc = -EINVAL; |
| 1030 | |
| 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); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1035 | else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0) |
| 1036 | rc = reipl_set_type(IPL_TYPE_NSS); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1037 | return (rc != 0) ? rc : len; |
| 1038 | } |
| 1039 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1040 | static struct kobj_attribute reipl_type_attr = |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1041 | __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1042 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1043 | static struct kset *reipl_kset; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1044 | static struct kset *reipl_fcp_kset; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1045 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1046 | static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb, |
| 1047 | const enum ipl_method m) |
| 1048 | { |
| 1049 | char loadparm[LOADPARM_LEN + 1] = {}; |
| 1050 | char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 1051 | char nss_name[NSS_NAME_SIZE + 1] = {}; |
| 1052 | size_t pos = 0; |
| 1053 | |
| 1054 | reipl_get_ascii_loadparm(loadparm, ipb); |
| 1055 | reipl_get_ascii_nss_name(nss_name, ipb); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1056 | reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1057 | |
| 1058 | switch (m) { |
| 1059 | case REIPL_METHOD_CCW_VM: |
| 1060 | pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno); |
| 1061 | break; |
| 1062 | case REIPL_METHOD_NSS: |
| 1063 | pos = sprintf(dst, "IPL %s", nss_name); |
| 1064 | break; |
| 1065 | default: |
| 1066 | break; |
| 1067 | } |
| 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); |
| 1072 | } |
| 1073 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1074 | static void __reipl_run(void *unused) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1075 | { |
| 1076 | struct ccw_dev_id devid; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1077 | static char buf[128]; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1078 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1079 | switch (reipl_method) { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1080 | case REIPL_METHOD_CCW_CIO: |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1081 | devid.ssid = reipl_block_ccw->ipl_info.ccw.ssid; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1082 | devid.devno = reipl_block_ccw->ipl_info.ccw.devno; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1083 | reipl_ccw_dev(&devid); |
| 1084 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1085 | case REIPL_METHOD_CCW_VM: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1086 | get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM); |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1087 | __cpcmd(buf, NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1088 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1089 | case REIPL_METHOD_CCW_DIAG: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1090 | diag308(DIAG308_SET, reipl_block_ccw); |
Heiko Carstens | 0f7451f | 2016-06-10 12:36:50 +0200 | [diff] [blame] | 1091 | if (MACHINE_IS_LPAR) |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1092 | diag308(DIAG308_LOAD_NORMAL_DUMP, NULL); |
Heiko Carstens | 0f7451f | 2016-06-10 12:36:50 +0200 | [diff] [blame] | 1093 | else |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1094 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1095 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1096 | case REIPL_METHOD_FCP_RW_DIAG: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1097 | diag308(DIAG308_SET, reipl_block_fcp); |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1098 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1099 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1100 | case REIPL_METHOD_FCP_RO_DIAG: |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1101 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1102 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1103 | case REIPL_METHOD_FCP_RO_VM: |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1104 | __cpcmd("IPL", NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1105 | break; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1106 | case REIPL_METHOD_NSS_DIAG: |
| 1107 | diag308(DIAG308_SET, reipl_block_nss); |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1108 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1109 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1110 | case REIPL_METHOD_NSS: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1111 | get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1112 | __cpcmd(buf, NULL, 0, NULL); |
| 1113 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1114 | case REIPL_METHOD_DEFAULT: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1115 | if (MACHINE_IS_VM) |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1116 | __cpcmd("IPL", NULL, 0, NULL); |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1117 | diag308(DIAG308_LOAD_CLEAR, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1118 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1119 | case REIPL_METHOD_FCP_DUMP: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1120 | break; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1121 | } |
Michael Holzheu | 208e559 | 2008-03-05 12:37:15 +0100 | [diff] [blame] | 1122 | disabled_wait((unsigned long) __builtin_return_address(0)); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1125 | static void reipl_run(struct shutdown_trigger *trigger) |
| 1126 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1127 | smp_call_ipl_cpu(__reipl_run, NULL); |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1130 | static void reipl_block_ccw_init(struct ipl_parameter_block *ipb) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1131 | { |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1132 | ipb->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 1133 | ipb->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 1134 | ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; |
| 1135 | ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
| 1136 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1137 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1138 | static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb) |
| 1139 | { |
| 1140 | /* LOADPARM */ |
| 1141 | /* check if read scp info worked and set loadparm */ |
| 1142 | if (sclp_ipl_info.is_valid) |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1143 | memcpy(ipb->hdr.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1144 | else |
| 1145 | /* read scp info failed: set empty loadparm (EBCDIC blanks) */ |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1146 | memset(ipb->hdr.loadparm, 0x40, LOADPARM_LEN); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1147 | ipb->hdr.flags = DIAG308_FLAGS_LP_VALID; |
| 1148 | |
| 1149 | /* VM PARM */ |
| 1150 | if (MACHINE_IS_VM && diag308_set_works && |
| 1151 | (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) { |
| 1152 | |
| 1153 | ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; |
| 1154 | ipb->ipl_info.ccw.vm_parm_len = |
| 1155 | ipl_block.ipl_info.ccw.vm_parm_len; |
| 1156 | memcpy(ipb->ipl_info.ccw.vm_parm, |
| 1157 | ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE); |
| 1158 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1159 | } |
| 1160 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1161 | static int __init reipl_nss_init(void) |
| 1162 | { |
| 1163 | int rc; |
| 1164 | |
| 1165 | if (!MACHINE_IS_VM) |
| 1166 | return 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1167 | |
| 1168 | reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL); |
| 1169 | if (!reipl_block_nss) |
| 1170 | return -ENOMEM; |
| 1171 | |
| 1172 | if (!diag308_set_works) |
| 1173 | sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO; |
| 1174 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1175 | rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1176 | if (rc) |
| 1177 | return rc; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1178 | |
| 1179 | reipl_block_ccw_init(reipl_block_nss); |
| 1180 | if (ipl_info.type == IPL_TYPE_NSS) { |
| 1181 | memset(reipl_block_nss->ipl_info.ccw.nss_name, |
| 1182 | ' ', NSS_NAME_SIZE); |
| 1183 | memcpy(reipl_block_nss->ipl_info.ccw.nss_name, |
| 1184 | kernel_nss_name, strlen(kernel_nss_name)); |
| 1185 | ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE); |
| 1186 | reipl_block_nss->ipl_info.ccw.vm_flags |= |
| 1187 | DIAG308_VM_FLAGS_NSS_VALID; |
| 1188 | |
| 1189 | reipl_block_ccw_fill_parms(reipl_block_nss); |
| 1190 | } |
| 1191 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1192 | reipl_capabilities |= IPL_TYPE_NSS; |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1196 | static int __init reipl_ccw_init(void) |
| 1197 | { |
| 1198 | int rc; |
| 1199 | |
| 1200 | reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 1201 | if (!reipl_block_ccw) |
| 1202 | return -ENOMEM; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1203 | |
| 1204 | if (MACHINE_IS_VM) { |
| 1205 | if (!diag308_set_works) |
| 1206 | sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO; |
| 1207 | rc = sysfs_create_group(&reipl_kset->kobj, |
| 1208 | &reipl_ccw_attr_group_vm); |
| 1209 | } else { |
| 1210 | if(!diag308_set_works) |
| 1211 | sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO; |
| 1212 | rc = sysfs_create_group(&reipl_kset->kobj, |
| 1213 | &reipl_ccw_attr_group_lpar); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1214 | } |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1215 | if (rc) |
| 1216 | return rc; |
| 1217 | |
| 1218 | reipl_block_ccw_init(reipl_block_ccw); |
| 1219 | if (ipl_info.type == IPL_TYPE_CCW) { |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1220 | reipl_block_ccw->ipl_info.ccw.ssid = ipl_ssid; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1221 | reipl_block_ccw->ipl_info.ccw.devno = ipl_devno; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1222 | reipl_block_ccw_fill_parms(reipl_block_ccw); |
| 1223 | } |
| 1224 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1225 | reipl_capabilities |= IPL_TYPE_CCW; |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static int __init reipl_fcp_init(void) |
| 1230 | { |
| 1231 | int rc; |
| 1232 | |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1233 | if (!diag308_set_works) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1234 | if (ipl_info.type == IPL_TYPE_FCP) { |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1235 | make_attrs_ro(reipl_fcp_attrs); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1236 | sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO; |
| 1237 | } else |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1238 | return 0; |
| 1239 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1240 | |
| 1241 | reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 1242 | if (!reipl_block_fcp) |
| 1243 | return -ENOMEM; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1244 | |
| 1245 | /* sysfs: create fcp kset for mixing attr group and bin attrs */ |
| 1246 | reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL, |
| 1247 | &reipl_kset->kobj); |
Julia Lawall | 798620f | 2011-08-24 17:15:11 +0200 | [diff] [blame] | 1248 | if (!reipl_fcp_kset) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1249 | free_page((unsigned long) reipl_block_fcp); |
| 1250 | return -ENOMEM; |
| 1251 | } |
| 1252 | |
| 1253 | rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1254 | if (rc) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1255 | kset_unregister(reipl_fcp_kset); |
| 1256 | free_page((unsigned long) reipl_block_fcp); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1257 | return rc; |
| 1258 | } |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1259 | |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1260 | if (ipl_info.type == IPL_TYPE_FCP) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1261 | memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE); |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1262 | /* |
| 1263 | * Fix loadparm: There are systems where the (SCSI) LOADPARM |
| 1264 | * is invalid in the SCSI IPL parameter block, so take it |
| 1265 | * always from sclp_ipl_info. |
| 1266 | */ |
| 1267 | memcpy(reipl_block_fcp->hdr.loadparm, sclp_ipl_info.loadparm, |
| 1268 | LOADPARM_LEN); |
| 1269 | } else { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1270 | reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 1271 | reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1272 | reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1273 | reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 1274 | reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL; |
| 1275 | } |
| 1276 | reipl_capabilities |= IPL_TYPE_FCP; |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 1280 | static int __init reipl_type_init(void) |
| 1281 | { |
| 1282 | enum ipl_type reipl_type = ipl_info.type; |
| 1283 | struct ipl_parameter_block *reipl_block; |
| 1284 | unsigned long size; |
| 1285 | |
| 1286 | reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size); |
| 1287 | if (!reipl_block) |
| 1288 | goto out; |
| 1289 | /* |
| 1290 | * If we have an OS info reipl block, this will be used |
| 1291 | */ |
| 1292 | if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) { |
| 1293 | memcpy(reipl_block_fcp, reipl_block, size); |
| 1294 | reipl_type = IPL_TYPE_FCP; |
| 1295 | } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) { |
| 1296 | memcpy(reipl_block_ccw, reipl_block, size); |
| 1297 | reipl_type = IPL_TYPE_CCW; |
| 1298 | } |
| 1299 | out: |
| 1300 | return reipl_set_type(reipl_type); |
| 1301 | } |
| 1302 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1303 | static int __init reipl_init(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1304 | { |
| 1305 | int rc; |
| 1306 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1307 | reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1308 | if (!reipl_kset) |
| 1309 | return -ENOMEM; |
| 1310 | rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1311 | if (rc) { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1312 | kset_unregister(reipl_kset); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1313 | return rc; |
| 1314 | } |
| 1315 | rc = reipl_ccw_init(); |
| 1316 | if (rc) |
| 1317 | return rc; |
| 1318 | rc = reipl_fcp_init(); |
| 1319 | if (rc) |
| 1320 | return rc; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1321 | rc = reipl_nss_init(); |
| 1322 | if (rc) |
| 1323 | return rc; |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame] | 1324 | return reipl_type_init(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1327 | static struct shutdown_action __refdata reipl_action = { |
| 1328 | .name = SHUTDOWN_ACTION_REIPL_STR, |
| 1329 | .fn = reipl_run, |
| 1330 | .init = reipl_init, |
| 1331 | }; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1332 | |
| 1333 | /* |
| 1334 | * dump shutdown action: Dump Linux on shutdown. |
| 1335 | */ |
| 1336 | |
| 1337 | /* FCP dump device attributes */ |
| 1338 | |
Michael Holzheu | eda4ddf | 2013-06-21 13:21:30 +0200 | [diff] [blame] | 1339 | DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n", |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1340 | dump_block_fcp->ipl_info.fcp.wwpn); |
Michael Holzheu | eda4ddf | 2013-06-21 13:21:30 +0200 | [diff] [blame] | 1341 | DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n", |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1342 | dump_block_fcp->ipl_info.fcp.lun); |
| 1343 | DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n", |
| 1344 | dump_block_fcp->ipl_info.fcp.bootprog); |
| 1345 | DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n", |
| 1346 | dump_block_fcp->ipl_info.fcp.br_lba); |
| 1347 | DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 1348 | dump_block_fcp->ipl_info.fcp.devno); |
| 1349 | |
| 1350 | static struct attribute *dump_fcp_attrs[] = { |
| 1351 | &sys_dump_fcp_device_attr.attr, |
| 1352 | &sys_dump_fcp_wwpn_attr.attr, |
| 1353 | &sys_dump_fcp_lun_attr.attr, |
| 1354 | &sys_dump_fcp_bootprog_attr.attr, |
| 1355 | &sys_dump_fcp_br_lba_attr.attr, |
| 1356 | NULL, |
| 1357 | }; |
| 1358 | |
| 1359 | static struct attribute_group dump_fcp_attr_group = { |
| 1360 | .name = IPL_FCP_STR, |
| 1361 | .attrs = dump_fcp_attrs, |
| 1362 | }; |
| 1363 | |
| 1364 | /* CCW dump device attributes */ |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1365 | DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ipl_info.ccw); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1366 | |
| 1367 | static struct attribute *dump_ccw_attrs[] = { |
| 1368 | &sys_dump_ccw_device_attr.attr, |
| 1369 | NULL, |
| 1370 | }; |
| 1371 | |
| 1372 | static struct attribute_group dump_ccw_attr_group = { |
| 1373 | .name = IPL_CCW_STR, |
| 1374 | .attrs = dump_ccw_attrs, |
| 1375 | }; |
| 1376 | |
| 1377 | /* dump type */ |
| 1378 | |
| 1379 | static int dump_set_type(enum dump_type type) |
| 1380 | { |
| 1381 | if (!(dump_capabilities & type)) |
| 1382 | return -EINVAL; |
| 1383 | switch (type) { |
| 1384 | case DUMP_TYPE_CCW: |
Michael Holzheu | 48657d2 | 2008-01-26 14:11:17 +0100 | [diff] [blame] | 1385 | if (diag308_set_works) |
| 1386 | dump_method = DUMP_METHOD_CCW_DIAG; |
| 1387 | else if (MACHINE_IS_VM) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1388 | dump_method = DUMP_METHOD_CCW_VM; |
| 1389 | else |
| 1390 | dump_method = DUMP_METHOD_CCW_CIO; |
| 1391 | break; |
| 1392 | case DUMP_TYPE_FCP: |
| 1393 | dump_method = DUMP_METHOD_FCP_DIAG; |
| 1394 | break; |
| 1395 | default: |
| 1396 | dump_method = DUMP_METHOD_NONE; |
| 1397 | } |
| 1398 | dump_type = type; |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
| 1402 | static ssize_t dump_type_show(struct kobject *kobj, |
| 1403 | struct kobj_attribute *attr, char *page) |
| 1404 | { |
| 1405 | return sprintf(page, "%s\n", dump_type_str(dump_type)); |
| 1406 | } |
| 1407 | |
| 1408 | static ssize_t dump_type_store(struct kobject *kobj, |
| 1409 | struct kobj_attribute *attr, |
| 1410 | const char *buf, size_t len) |
| 1411 | { |
| 1412 | int rc = -EINVAL; |
| 1413 | |
| 1414 | if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0) |
| 1415 | rc = dump_set_type(DUMP_TYPE_NONE); |
| 1416 | else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0) |
| 1417 | rc = dump_set_type(DUMP_TYPE_CCW); |
| 1418 | else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0) |
| 1419 | rc = dump_set_type(DUMP_TYPE_FCP); |
| 1420 | return (rc != 0) ? rc : len; |
| 1421 | } |
| 1422 | |
| 1423 | static struct kobj_attribute dump_type_attr = |
| 1424 | __ATTR(dump_type, 0644, dump_type_show, dump_type_store); |
| 1425 | |
| 1426 | static struct kset *dump_kset; |
| 1427 | |
Michael Holzheu | 0894b3ae | 2013-01-21 18:35:15 +0100 | [diff] [blame] | 1428 | static void diag308_dump(void *dump_block) |
| 1429 | { |
| 1430 | diag308(DIAG308_SET, dump_block); |
| 1431 | while (1) { |
Heiko Carstens | 0599eea | 2016-06-11 11:24:27 +0200 | [diff] [blame] | 1432 | if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302) |
Michael Holzheu | 0894b3ae | 2013-01-21 18:35:15 +0100 | [diff] [blame] | 1433 | break; |
| 1434 | udelay_simple(USEC_PER_SEC); |
| 1435 | } |
| 1436 | } |
| 1437 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1438 | static void __dump_run(void *unused) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1439 | { |
| 1440 | struct ccw_dev_id devid; |
| 1441 | static char buf[100]; |
| 1442 | |
| 1443 | switch (dump_method) { |
| 1444 | case DUMP_METHOD_CCW_CIO: |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1445 | devid.ssid = dump_block_ccw->ipl_info.ccw.ssid; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1446 | devid.devno = dump_block_ccw->ipl_info.ccw.devno; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1447 | reipl_ccw_dev(&devid); |
| 1448 | break; |
| 1449 | case DUMP_METHOD_CCW_VM: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1450 | sprintf(buf, "STORE STATUS"); |
| 1451 | __cpcmd(buf, NULL, 0, NULL); |
| 1452 | sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno); |
| 1453 | __cpcmd(buf, NULL, 0, NULL); |
| 1454 | break; |
| 1455 | case DUMP_METHOD_CCW_DIAG: |
Michael Holzheu | 0894b3ae | 2013-01-21 18:35:15 +0100 | [diff] [blame] | 1456 | diag308_dump(dump_block_ccw); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1457 | break; |
| 1458 | case DUMP_METHOD_FCP_DIAG: |
Michael Holzheu | 0894b3ae | 2013-01-21 18:35:15 +0100 | [diff] [blame] | 1459 | diag308_dump(dump_block_fcp); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1460 | break; |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1461 | default: |
| 1462 | break; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1463 | } |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | static void dump_run(struct shutdown_trigger *trigger) |
| 1467 | { |
| 1468 | if (dump_method == DUMP_METHOD_NONE) |
| 1469 | return; |
| 1470 | smp_send_stop(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1471 | smp_call_ipl_cpu(__dump_run, NULL); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1472 | } |
| 1473 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1474 | static int __init dump_ccw_init(void) |
| 1475 | { |
| 1476 | int rc; |
| 1477 | |
| 1478 | dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 1479 | if (!dump_block_ccw) |
| 1480 | return -ENOMEM; |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1481 | rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1482 | if (rc) { |
| 1483 | free_page((unsigned long)dump_block_ccw); |
| 1484 | return rc; |
| 1485 | } |
| 1486 | dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 1487 | dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1488 | dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1489 | dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1490 | dump_capabilities |= DUMP_TYPE_CCW; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1491 | return 0; |
| 1492 | } |
| 1493 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1494 | static int __init dump_fcp_init(void) |
| 1495 | { |
| 1496 | int rc; |
| 1497 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 1498 | if (!sclp_ipl_info.has_dump) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1499 | return 0; /* LDIPL DUMP is not installed */ |
| 1500 | if (!diag308_set_works) |
| 1501 | return 0; |
| 1502 | dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 1503 | if (!dump_block_fcp) |
| 1504 | return -ENOMEM; |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1505 | rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1506 | if (rc) { |
| 1507 | free_page((unsigned long)dump_block_fcp); |
| 1508 | return rc; |
| 1509 | } |
| 1510 | dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 1511 | dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1512 | dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1513 | dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 1514 | dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1515 | dump_capabilities |= DUMP_TYPE_FCP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1516 | return 0; |
| 1517 | } |
| 1518 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1519 | static int __init dump_init(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1520 | { |
| 1521 | int rc; |
| 1522 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1523 | dump_kset = kset_create_and_add("dump", NULL, firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1524 | if (!dump_kset) |
| 1525 | return -ENOMEM; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1526 | rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1527 | if (rc) { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1528 | kset_unregister(dump_kset); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1529 | return rc; |
| 1530 | } |
| 1531 | rc = dump_ccw_init(); |
| 1532 | if (rc) |
| 1533 | return rc; |
| 1534 | rc = dump_fcp_init(); |
| 1535 | if (rc) |
| 1536 | return rc; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1537 | dump_set_type(DUMP_TYPE_NONE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1538 | return 0; |
| 1539 | } |
| 1540 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1541 | static struct shutdown_action __refdata dump_action = { |
| 1542 | .name = SHUTDOWN_ACTION_DUMP_STR, |
| 1543 | .fn = dump_run, |
| 1544 | .init = dump_init, |
| 1545 | }; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1546 | |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1547 | static void dump_reipl_run(struct shutdown_trigger *trigger) |
| 1548 | { |
Michael Holzheu | a7df7a9 | 2012-06-27 14:43:31 +0200 | [diff] [blame] | 1549 | unsigned long ipib = (unsigned long) reipl_block_actual; |
Heiko Carstens | fbe7656 | 2012-06-05 09:59:52 +0200 | [diff] [blame] | 1550 | unsigned int csum; |
Michael Holzheu | b43445ff | 2012-03-11 11:59:28 -0400 | [diff] [blame] | 1551 | |
Heiko Carstens | 90b3baa | 2016-12-20 16:08:05 +0100 | [diff] [blame] | 1552 | csum = (__force unsigned int) |
| 1553 | csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0); |
Heiko Carstens | fbe7656 | 2012-06-05 09:59:52 +0200 | [diff] [blame] | 1554 | mem_assign_absolute(S390_lowcore.ipib, ipib); |
| 1555 | mem_assign_absolute(S390_lowcore.ipib_checksum, csum); |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1556 | dump_run(trigger); |
| 1557 | } |
| 1558 | |
| 1559 | static int __init dump_reipl_init(void) |
| 1560 | { |
| 1561 | if (!diag308_set_works) |
| 1562 | return -EOPNOTSUPP; |
| 1563 | else |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | static struct shutdown_action __refdata dump_reipl_action = { |
| 1568 | .name = SHUTDOWN_ACTION_DUMP_REIPL_STR, |
| 1569 | .fn = dump_reipl_run, |
| 1570 | .init = dump_reipl_init, |
| 1571 | }; |
| 1572 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1573 | /* |
| 1574 | * vmcmd shutdown action: Trigger vm command on shutdown. |
| 1575 | */ |
| 1576 | |
| 1577 | static char vmcmd_on_reboot[128]; |
| 1578 | static char vmcmd_on_panic[128]; |
| 1579 | static char vmcmd_on_halt[128]; |
| 1580 | static char vmcmd_on_poff[128]; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1581 | static char vmcmd_on_restart[128]; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1582 | |
| 1583 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot); |
| 1584 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic); |
| 1585 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt); |
| 1586 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff); |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1587 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1588 | |
| 1589 | static struct attribute *vmcmd_attrs[] = { |
| 1590 | &sys_vmcmd_on_reboot_attr.attr, |
| 1591 | &sys_vmcmd_on_panic_attr.attr, |
| 1592 | &sys_vmcmd_on_halt_attr.attr, |
| 1593 | &sys_vmcmd_on_poff_attr.attr, |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1594 | &sys_vmcmd_on_restart_attr.attr, |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1595 | NULL, |
| 1596 | }; |
| 1597 | |
| 1598 | static struct attribute_group vmcmd_attr_group = { |
| 1599 | .attrs = vmcmd_attrs, |
| 1600 | }; |
| 1601 | |
| 1602 | static struct kset *vmcmd_kset; |
| 1603 | |
| 1604 | static void vmcmd_run(struct shutdown_trigger *trigger) |
| 1605 | { |
Michael Holzheu | 8143ada | 2012-07-24 18:43:02 +0200 | [diff] [blame] | 1606 | char *cmd; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1607 | |
| 1608 | if (strcmp(trigger->name, ON_REIPL_STR) == 0) |
| 1609 | cmd = vmcmd_on_reboot; |
| 1610 | else if (strcmp(trigger->name, ON_PANIC_STR) == 0) |
| 1611 | cmd = vmcmd_on_panic; |
| 1612 | else if (strcmp(trigger->name, ON_HALT_STR) == 0) |
| 1613 | cmd = vmcmd_on_halt; |
| 1614 | else if (strcmp(trigger->name, ON_POFF_STR) == 0) |
| 1615 | cmd = vmcmd_on_poff; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1616 | else if (strcmp(trigger->name, ON_RESTART_STR) == 0) |
| 1617 | cmd = vmcmd_on_restart; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1618 | else |
| 1619 | return; |
| 1620 | |
| 1621 | if (strlen(cmd) == 0) |
| 1622 | return; |
Michael Holzheu | 8143ada | 2012-07-24 18:43:02 +0200 | [diff] [blame] | 1623 | __cpcmd(cmd, NULL, 0, NULL); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | static int vmcmd_init(void) |
| 1627 | { |
| 1628 | if (!MACHINE_IS_VM) |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 1629 | return -EOPNOTSUPP; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1630 | vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj); |
| 1631 | if (!vmcmd_kset) |
| 1632 | return -ENOMEM; |
| 1633 | return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group); |
| 1634 | } |
| 1635 | |
| 1636 | static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR, |
| 1637 | vmcmd_run, vmcmd_init}; |
| 1638 | |
| 1639 | /* |
| 1640 | * stop shutdown action: Stop Linux on shutdown. |
| 1641 | */ |
| 1642 | |
| 1643 | static void stop_run(struct shutdown_trigger *trigger) |
| 1644 | { |
Michael Holzheu | e1202ed | 2011-08-24 17:15:12 +0200 | [diff] [blame] | 1645 | if (strcmp(trigger->name, ON_PANIC_STR) == 0 || |
| 1646 | strcmp(trigger->name, ON_RESTART_STR) == 0) |
Michael Holzheu | c654749 | 2008-01-26 14:11:12 +0100 | [diff] [blame] | 1647 | disabled_wait((unsigned long) __builtin_return_address(0)); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1648 | smp_stop_cpu(); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR, |
| 1652 | stop_run, NULL}; |
| 1653 | |
| 1654 | /* action list */ |
| 1655 | |
| 1656 | static struct shutdown_action *shutdown_actions_list[] = { |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1657 | &ipl_action, &reipl_action, &dump_reipl_action, &dump_action, |
| 1658 | &vmcmd_action, &stop_action}; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1659 | #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *)) |
| 1660 | |
| 1661 | /* |
| 1662 | * Trigger section |
| 1663 | */ |
| 1664 | |
| 1665 | static struct kset *shutdown_actions_kset; |
| 1666 | |
| 1667 | static int set_trigger(const char *buf, struct shutdown_trigger *trigger, |
| 1668 | size_t len) |
| 1669 | { |
| 1670 | int i; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1671 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1672 | for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1673 | if (sysfs_streq(buf, shutdown_actions_list[i]->name)) { |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 1674 | if (shutdown_actions_list[i]->init_rc) { |
| 1675 | return shutdown_actions_list[i]->init_rc; |
| 1676 | } else { |
| 1677 | trigger->action = shutdown_actions_list[i]; |
| 1678 | return len; |
| 1679 | } |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | return -EINVAL; |
| 1683 | } |
| 1684 | |
| 1685 | /* on reipl */ |
| 1686 | |
| 1687 | static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR, |
| 1688 | &reipl_action}; |
| 1689 | |
| 1690 | static ssize_t on_reboot_show(struct kobject *kobj, |
| 1691 | struct kobj_attribute *attr, char *page) |
| 1692 | { |
| 1693 | return sprintf(page, "%s\n", on_reboot_trigger.action->name); |
| 1694 | } |
| 1695 | |
| 1696 | static ssize_t on_reboot_store(struct kobject *kobj, |
| 1697 | struct kobj_attribute *attr, |
| 1698 | const char *buf, size_t len) |
| 1699 | { |
| 1700 | return set_trigger(buf, &on_reboot_trigger, len); |
| 1701 | } |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1702 | static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1703 | |
| 1704 | static void do_machine_restart(char *__unused) |
| 1705 | { |
| 1706 | smp_send_stop(); |
| 1707 | on_reboot_trigger.action->fn(&on_reboot_trigger); |
| 1708 | reipl_run(NULL); |
| 1709 | } |
| 1710 | void (*_machine_restart)(char *command) = do_machine_restart; |
| 1711 | |
| 1712 | /* on panic */ |
| 1713 | |
| 1714 | static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action}; |
| 1715 | |
| 1716 | static ssize_t on_panic_show(struct kobject *kobj, |
| 1717 | struct kobj_attribute *attr, char *page) |
| 1718 | { |
| 1719 | return sprintf(page, "%s\n", on_panic_trigger.action->name); |
| 1720 | } |
| 1721 | |
| 1722 | static ssize_t on_panic_store(struct kobject *kobj, |
| 1723 | struct kobj_attribute *attr, |
| 1724 | const char *buf, size_t len) |
| 1725 | { |
| 1726 | return set_trigger(buf, &on_panic_trigger, len); |
| 1727 | } |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1728 | static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1729 | |
| 1730 | static void do_panic(void) |
| 1731 | { |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 1732 | lgr_info_log(); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1733 | on_panic_trigger.action->fn(&on_panic_trigger); |
| 1734 | stop_run(&on_panic_trigger); |
| 1735 | } |
| 1736 | |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1737 | /* on restart */ |
| 1738 | |
| 1739 | static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR, |
Michael Holzheu | e1202ed | 2011-08-24 17:15:12 +0200 | [diff] [blame] | 1740 | &stop_action}; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1741 | |
| 1742 | static ssize_t on_restart_show(struct kobject *kobj, |
| 1743 | struct kobj_attribute *attr, char *page) |
| 1744 | { |
| 1745 | return sprintf(page, "%s\n", on_restart_trigger.action->name); |
| 1746 | } |
| 1747 | |
| 1748 | static ssize_t on_restart_store(struct kobject *kobj, |
| 1749 | struct kobj_attribute *attr, |
| 1750 | const char *buf, size_t len) |
| 1751 | { |
| 1752 | return set_trigger(buf, &on_restart_trigger, len); |
| 1753 | } |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1754 | static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart); |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1755 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1756 | static void __do_restart(void *ignore) |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1757 | { |
Michael Holzheu | fa7c004 | 2012-05-21 11:30:30 +0200 | [diff] [blame] | 1758 | __arch_local_irq_stosm(0x04); /* enable DAT */ |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1759 | smp_send_stop(); |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 1760 | #ifdef CONFIG_CRASH_DUMP |
| 1761 | crash_kexec(NULL); |
| 1762 | #endif |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1763 | on_restart_trigger.action->fn(&on_restart_trigger); |
| 1764 | stop_run(&on_restart_trigger); |
| 1765 | } |
| 1766 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1767 | void do_restart(void) |
| 1768 | { |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 1769 | tracing_off(); |
| 1770 | debug_locks_off(); |
| 1771 | lgr_info_log(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1772 | smp_call_online_cpu(__do_restart, NULL); |
| 1773 | } |
| 1774 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1775 | /* on halt */ |
| 1776 | |
| 1777 | static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action}; |
| 1778 | |
| 1779 | static ssize_t on_halt_show(struct kobject *kobj, |
| 1780 | struct kobj_attribute *attr, char *page) |
| 1781 | { |
| 1782 | return sprintf(page, "%s\n", on_halt_trigger.action->name); |
| 1783 | } |
| 1784 | |
| 1785 | static ssize_t on_halt_store(struct kobject *kobj, |
| 1786 | struct kobj_attribute *attr, |
| 1787 | const char *buf, size_t len) |
| 1788 | { |
| 1789 | return set_trigger(buf, &on_halt_trigger, len); |
| 1790 | } |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1791 | static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1792 | |
| 1793 | static void do_machine_halt(void) |
| 1794 | { |
| 1795 | smp_send_stop(); |
| 1796 | on_halt_trigger.action->fn(&on_halt_trigger); |
| 1797 | stop_run(&on_halt_trigger); |
| 1798 | } |
| 1799 | void (*_machine_halt)(void) = do_machine_halt; |
| 1800 | |
| 1801 | /* on power off */ |
| 1802 | |
| 1803 | static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action}; |
| 1804 | |
| 1805 | static ssize_t on_poff_show(struct kobject *kobj, |
| 1806 | struct kobj_attribute *attr, char *page) |
| 1807 | { |
| 1808 | return sprintf(page, "%s\n", on_poff_trigger.action->name); |
| 1809 | } |
| 1810 | |
| 1811 | static ssize_t on_poff_store(struct kobject *kobj, |
| 1812 | struct kobj_attribute *attr, |
| 1813 | const char *buf, size_t len) |
| 1814 | { |
| 1815 | return set_trigger(buf, &on_poff_trigger, len); |
| 1816 | } |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1817 | static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1818 | |
| 1819 | static void do_machine_power_off(void) |
| 1820 | { |
| 1821 | smp_send_stop(); |
| 1822 | on_poff_trigger.action->fn(&on_poff_trigger); |
| 1823 | stop_run(&on_poff_trigger); |
| 1824 | } |
| 1825 | void (*_machine_power_off)(void) = do_machine_power_off; |
| 1826 | |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1827 | static struct attribute *shutdown_action_attrs[] = { |
| 1828 | &on_restart_attr.attr, |
| 1829 | &on_reboot_attr.attr, |
| 1830 | &on_panic_attr.attr, |
| 1831 | &on_halt_attr.attr, |
| 1832 | &on_poff_attr.attr, |
| 1833 | NULL, |
| 1834 | }; |
| 1835 | |
| 1836 | static struct attribute_group shutdown_action_attr_group = { |
| 1837 | .attrs = shutdown_action_attrs, |
| 1838 | }; |
| 1839 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1840 | static void __init shutdown_triggers_init(void) |
| 1841 | { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1842 | shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL, |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1843 | firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1844 | if (!shutdown_actions_kset) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1845 | goto fail; |
Sebastian Ott | 0f02437 | 2015-03-17 10:28:46 +0100 | [diff] [blame] | 1846 | if (sysfs_create_group(&shutdown_actions_kset->kobj, |
| 1847 | &shutdown_action_attr_group)) |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1848 | goto fail; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1849 | return; |
| 1850 | fail: |
| 1851 | panic("shutdown_triggers_init failed\n"); |
| 1852 | } |
| 1853 | |
| 1854 | static void __init shutdown_actions_init(void) |
| 1855 | { |
| 1856 | int i; |
| 1857 | |
| 1858 | for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { |
| 1859 | if (!shutdown_actions_list[i]->init) |
| 1860 | continue; |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 1861 | shutdown_actions_list[i]->init_rc = |
| 1862 | shutdown_actions_list[i]->init(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1863 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | static int __init s390_ipl_init(void) |
| 1867 | { |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1868 | char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; |
| 1869 | |
Heiko Carstens | d5ab7a3 | 2017-01-24 15:58:52 +0100 | [diff] [blame] | 1870 | sclp_early_get_ipl_info(&sclp_ipl_info); |
Michael Holzheu | 6992860 | 2014-08-26 17:51:08 +0200 | [diff] [blame] | 1871 | /* |
| 1872 | * Fix loadparm: There are systems where the (SCSI) LOADPARM |
| 1873 | * returned by read SCP info is invalid (contains EBCDIC blanks) |
| 1874 | * when the system has been booted via diag308. In that case we use |
| 1875 | * the value from diag308, if available. |
| 1876 | * |
| 1877 | * There are also systems where diag308 store does not work in |
| 1878 | * case the system is booted from HMC. Fortunately in this case |
| 1879 | * READ SCP info provides the correct value. |
| 1880 | */ |
| 1881 | if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && |
| 1882 | diag308_set_works) |
| 1883 | memcpy(sclp_ipl_info.loadparm, ipl_block.hdr.loadparm, |
| 1884 | LOADPARM_LEN); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1885 | shutdown_actions_init(); |
| 1886 | shutdown_triggers_init(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1887 | return 0; |
| 1888 | } |
| 1889 | |
| 1890 | __initcall(s390_ipl_init); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1891 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1892 | static void __init strncpy_skip_quote(char *dst, char *src, int n) |
| 1893 | { |
| 1894 | int sx, dx; |
| 1895 | |
| 1896 | dx = 0; |
| 1897 | for (sx = 0; src[sx] != 0; sx++) { |
| 1898 | if (src[sx] == '"') |
| 1899 | continue; |
| 1900 | dst[dx++] = src[sx]; |
| 1901 | if (dx >= n) |
| 1902 | break; |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | static int __init vmcmd_on_reboot_setup(char *str) |
| 1907 | { |
| 1908 | if (!MACHINE_IS_VM) |
| 1909 | return 1; |
| 1910 | strncpy_skip_quote(vmcmd_on_reboot, str, 127); |
| 1911 | vmcmd_on_reboot[127] = 0; |
| 1912 | on_reboot_trigger.action = &vmcmd_action; |
| 1913 | return 1; |
| 1914 | } |
| 1915 | __setup("vmreboot=", vmcmd_on_reboot_setup); |
| 1916 | |
| 1917 | static int __init vmcmd_on_panic_setup(char *str) |
| 1918 | { |
| 1919 | if (!MACHINE_IS_VM) |
| 1920 | return 1; |
| 1921 | strncpy_skip_quote(vmcmd_on_panic, str, 127); |
| 1922 | vmcmd_on_panic[127] = 0; |
| 1923 | on_panic_trigger.action = &vmcmd_action; |
| 1924 | return 1; |
| 1925 | } |
| 1926 | __setup("vmpanic=", vmcmd_on_panic_setup); |
| 1927 | |
| 1928 | static int __init vmcmd_on_halt_setup(char *str) |
| 1929 | { |
| 1930 | if (!MACHINE_IS_VM) |
| 1931 | return 1; |
| 1932 | strncpy_skip_quote(vmcmd_on_halt, str, 127); |
| 1933 | vmcmd_on_halt[127] = 0; |
| 1934 | on_halt_trigger.action = &vmcmd_action; |
| 1935 | return 1; |
| 1936 | } |
| 1937 | __setup("vmhalt=", vmcmd_on_halt_setup); |
| 1938 | |
| 1939 | static int __init vmcmd_on_poff_setup(char *str) |
| 1940 | { |
| 1941 | if (!MACHINE_IS_VM) |
| 1942 | return 1; |
| 1943 | strncpy_skip_quote(vmcmd_on_poff, str, 127); |
| 1944 | vmcmd_on_poff[127] = 0; |
| 1945 | on_poff_trigger.action = &vmcmd_action; |
| 1946 | return 1; |
| 1947 | } |
| 1948 | __setup("vmpoff=", vmcmd_on_poff_setup); |
| 1949 | |
| 1950 | static int on_panic_notify(struct notifier_block *self, |
| 1951 | unsigned long event, void *data) |
| 1952 | { |
| 1953 | do_panic(); |
| 1954 | return NOTIFY_OK; |
| 1955 | } |
| 1956 | |
| 1957 | static struct notifier_block on_panic_nb = { |
| 1958 | .notifier_call = on_panic_notify, |
Michael Holzheu | 7e9b580 | 2009-03-26 15:24:55 +0100 | [diff] [blame] | 1959 | .priority = INT_MIN, |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1960 | }; |
| 1961 | |
| 1962 | void __init setup_ipl(void) |
| 1963 | { |
| 1964 | ipl_info.type = get_ipl_type(); |
| 1965 | switch (ipl_info.type) { |
| 1966 | case IPL_TYPE_CCW: |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1967 | ipl_info.data.ccw.dev_id.ssid = ipl_ssid; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1968 | ipl_info.data.ccw.dev_id.devno = ipl_devno; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1969 | break; |
| 1970 | case IPL_TYPE_FCP: |
| 1971 | case IPL_TYPE_FCP_DUMP: |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 1972 | ipl_info.data.fcp.dev_id.ssid = 0; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1973 | ipl_info.data.fcp.dev_id.devno = |
| 1974 | IPL_PARMBLOCK_START->ipl_info.fcp.devno; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1975 | ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn; |
| 1976 | ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun; |
| 1977 | break; |
| 1978 | case IPL_TYPE_NSS: |
| 1979 | strncpy(ipl_info.data.nss.name, kernel_nss_name, |
| 1980 | sizeof(ipl_info.data.nss.name)); |
| 1981 | break; |
| 1982 | case IPL_TYPE_UNKNOWN: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1983 | /* We have no info to copy */ |
| 1984 | break; |
| 1985 | } |
| 1986 | atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb); |
| 1987 | } |
| 1988 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1989 | void __init ipl_update_parameters(void) |
| 1990 | { |
Michael Holzheu | 3a95e8e | 2008-08-01 16:39:10 +0200 | [diff] [blame] | 1991 | int rc; |
| 1992 | |
| 1993 | rc = diag308(DIAG308_STORE, &ipl_block); |
| 1994 | if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG)) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1995 | diag308_set_works = 1; |
| 1996 | } |
| 1997 | |
Heiko Carstens | d543a10 | 2016-12-06 15:52:10 +0100 | [diff] [blame] | 1998 | void __init ipl_verify_parameters(void) |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1999 | { |
| 2000 | struct cio_iplinfo iplinfo; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 2001 | |
| 2002 | if (cio_get_iplinfo(&iplinfo)) |
| 2003 | return; |
| 2004 | |
Sebastian Ott | 18e22a1 | 2015-06-29 18:39:54 +0200 | [diff] [blame] | 2005 | ipl_ssid = iplinfo.ssid; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 2006 | ipl_devno = iplinfo.devno; |
| 2007 | ipl_flags |= IPL_DEVNO_VALID; |
| 2008 | if (!iplinfo.is_qdio) |
| 2009 | return; |
| 2010 | ipl_flags |= IPL_PARMBLOCK_VALID; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 2011 | } |
| 2012 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2013 | static LIST_HEAD(rcall); |
| 2014 | static DEFINE_MUTEX(rcall_mutex); |
| 2015 | |
| 2016 | void register_reset_call(struct reset_call *reset) |
| 2017 | { |
| 2018 | mutex_lock(&rcall_mutex); |
| 2019 | list_add(&reset->list, &rcall); |
| 2020 | mutex_unlock(&rcall_mutex); |
| 2021 | } |
| 2022 | EXPORT_SYMBOL_GPL(register_reset_call); |
| 2023 | |
| 2024 | void unregister_reset_call(struct reset_call *reset) |
| 2025 | { |
| 2026 | mutex_lock(&rcall_mutex); |
| 2027 | list_del(&reset->list); |
| 2028 | mutex_unlock(&rcall_mutex); |
| 2029 | } |
| 2030 | EXPORT_SYMBOL_GPL(unregister_reset_call); |
| 2031 | |
| 2032 | static void do_reset_calls(void) |
| 2033 | { |
| 2034 | struct reset_call *reset; |
| 2035 | |
Michael Holzheu | 9dc7356 | 2011-08-03 16:44:22 +0200 | [diff] [blame] | 2036 | if (diag308_set_works) { |
| 2037 | diag308_reset(); |
| 2038 | return; |
| 2039 | } |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2040 | list_for_each_entry(reset, &rcall, list) |
| 2041 | reset->fn(); |
| 2042 | } |
| 2043 | |
Martin Schwidefsky | 1a36a39 | 2015-10-29 10:28:26 +0100 | [diff] [blame] | 2044 | void s390_reset_system(void) |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2045 | { |
Heiko Carstens | c667aea | 2015-12-31 10:29:00 +0100 | [diff] [blame] | 2046 | struct lowcore *lc; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2047 | |
Heiko Carstens | c667aea | 2015-12-31 10:29:00 +0100 | [diff] [blame] | 2048 | lc = (struct lowcore *)(unsigned long) store_prefix(); |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2049 | |
| 2050 | /* Stack for interrupt/machine check handler */ |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2051 | lc->panic_stack = S390_lowcore.panic_stack; |
| 2052 | |
| 2053 | /* Disable prefixing */ |
| 2054 | set_prefix(0); |
| 2055 | |
| 2056 | /* Disable lowcore protection */ |
| 2057 | __ctl_clear_bit(0,28); |
| 2058 | |
| 2059 | /* Set new machine check handler */ |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 2060 | S390_lowcore.mcck_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2061 | S390_lowcore.mcck_new_psw.addr = |
Heiko Carstens | fecc868a | 2016-01-18 12:49:44 +0100 | [diff] [blame] | 2062 | (unsigned long) s390_base_mcck_handler; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2063 | |
| 2064 | /* Set new program check handler */ |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 2065 | S390_lowcore.program_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2066 | S390_lowcore.program_new_psw.addr = |
Heiko Carstens | fecc868a | 2016-01-18 12:49:44 +0100 | [diff] [blame] | 2067 | (unsigned long) s390_base_pgm_handler; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2068 | |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 2069 | do_reset_calls(); |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 2070 | } |