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