Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/ipl.c |
| 3 | * ipl/reipl/dump support for Linux on s390. |
| 4 | * |
| 5 | * Copyright (C) IBM Corp. 2005,2006 |
| 6 | * Author(s): Michael Holzheu <holzheu@de.ibm.com> |
| 7 | * Heiko Carstens <heiko.carstens@de.ibm.com> |
| 8 | * Volker Sameske <sameske@de.ibm.com> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/reboot.h> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 16 | #include <linux/ctype.h> |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 17 | #include <asm/smp.h> |
| 18 | #include <asm/setup.h> |
| 19 | #include <asm/cpcmd.h> |
| 20 | #include <asm/cio.h> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 21 | #include <asm/ebcdic.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 22 | #include <asm/reset.h> |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 23 | |
| 24 | #define IPL_PARM_BLOCK_VERSION 0 |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 25 | #define LOADPARM_LEN 8 |
| 26 | |
| 27 | extern char s390_readinfo_sccb[]; |
| 28 | #define SCCB_VALID (*((__u16*)&s390_readinfo_sccb[6]) == 0x0010) |
| 29 | #define SCCB_LOADPARM (&s390_readinfo_sccb[24]) |
| 30 | #define SCCB_FLAG (s390_readinfo_sccb[91]) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 31 | |
| 32 | enum ipl_type { |
| 33 | IPL_TYPE_NONE = 1, |
| 34 | IPL_TYPE_UNKNOWN = 2, |
| 35 | IPL_TYPE_CCW = 4, |
| 36 | IPL_TYPE_FCP = 8, |
| 37 | }; |
| 38 | |
| 39 | #define IPL_NONE_STR "none" |
| 40 | #define IPL_UNKNOWN_STR "unknown" |
| 41 | #define IPL_CCW_STR "ccw" |
| 42 | #define IPL_FCP_STR "fcp" |
| 43 | |
| 44 | static char *ipl_type_str(enum ipl_type type) |
| 45 | { |
| 46 | switch (type) { |
| 47 | case IPL_TYPE_NONE: |
| 48 | return IPL_NONE_STR; |
| 49 | case IPL_TYPE_CCW: |
| 50 | return IPL_CCW_STR; |
| 51 | case IPL_TYPE_FCP: |
| 52 | return IPL_FCP_STR; |
| 53 | case IPL_TYPE_UNKNOWN: |
| 54 | default: |
| 55 | return IPL_UNKNOWN_STR; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | enum ipl_method { |
| 60 | IPL_METHOD_NONE, |
| 61 | IPL_METHOD_CCW_CIO, |
| 62 | IPL_METHOD_CCW_DIAG, |
| 63 | IPL_METHOD_CCW_VM, |
| 64 | IPL_METHOD_FCP_RO_DIAG, |
| 65 | IPL_METHOD_FCP_RW_DIAG, |
| 66 | IPL_METHOD_FCP_RO_VM, |
| 67 | }; |
| 68 | |
| 69 | enum shutdown_action { |
| 70 | SHUTDOWN_REIPL, |
| 71 | SHUTDOWN_DUMP, |
| 72 | SHUTDOWN_STOP, |
| 73 | }; |
| 74 | |
| 75 | #define SHUTDOWN_REIPL_STR "reipl" |
| 76 | #define SHUTDOWN_DUMP_STR "dump" |
| 77 | #define SHUTDOWN_STOP_STR "stop" |
| 78 | |
| 79 | static char *shutdown_action_str(enum shutdown_action action) |
| 80 | { |
| 81 | switch (action) { |
| 82 | case SHUTDOWN_REIPL: |
| 83 | return SHUTDOWN_REIPL_STR; |
| 84 | case SHUTDOWN_DUMP: |
| 85 | return SHUTDOWN_DUMP_STR; |
| 86 | case SHUTDOWN_STOP: |
| 87 | return SHUTDOWN_STOP_STR; |
| 88 | default: |
| 89 | BUG(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | enum diag308_subcode { |
| 94 | DIAG308_IPL = 3, |
| 95 | DIAG308_DUMP = 4, |
| 96 | DIAG308_SET = 5, |
| 97 | DIAG308_STORE = 6, |
| 98 | }; |
| 99 | |
| 100 | enum diag308_ipl_type { |
| 101 | DIAG308_IPL_TYPE_FCP = 0, |
| 102 | DIAG308_IPL_TYPE_CCW = 2, |
| 103 | }; |
| 104 | |
| 105 | enum diag308_opt { |
| 106 | DIAG308_IPL_OPT_IPL = 0x10, |
| 107 | DIAG308_IPL_OPT_DUMP = 0x20, |
| 108 | }; |
| 109 | |
| 110 | enum diag308_rc { |
| 111 | DIAG308_RC_OK = 1, |
| 112 | }; |
| 113 | |
| 114 | static int diag308_set_works = 0; |
| 115 | |
| 116 | static int reipl_capabilities = IPL_TYPE_UNKNOWN; |
| 117 | static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN; |
| 118 | static enum ipl_method reipl_method = IPL_METHOD_NONE; |
| 119 | static struct ipl_parameter_block *reipl_block_fcp; |
| 120 | static struct ipl_parameter_block *reipl_block_ccw; |
| 121 | |
| 122 | static int dump_capabilities = IPL_TYPE_NONE; |
| 123 | static enum ipl_type dump_type = IPL_TYPE_NONE; |
| 124 | static enum ipl_method dump_method = IPL_METHOD_NONE; |
| 125 | static struct ipl_parameter_block *dump_block_fcp; |
| 126 | static struct ipl_parameter_block *dump_block_ccw; |
| 127 | |
| 128 | static enum shutdown_action on_panic_action = SHUTDOWN_STOP; |
| 129 | |
| 130 | static int diag308(unsigned long subcode, void *addr) |
| 131 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 132 | register unsigned long _addr asm("0") = (unsigned long) addr; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 133 | register unsigned long _rc asm("1") = 0; |
| 134 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 135 | asm volatile( |
| 136 | " diag %0,%2,0x308\n" |
| 137 | "0:\n" |
| 138 | EX_TABLE(0b,0b) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 139 | : "+d" (_addr), "+d" (_rc) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 140 | : "d" (subcode) : "cc", "memory"); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 141 | return _rc; |
| 142 | } |
| 143 | |
| 144 | /* SYSFS */ |
| 145 | |
| 146 | #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ |
| 147 | static ssize_t sys_##_prefix##_##_name##_show(struct subsystem *subsys, \ |
| 148 | char *page) \ |
| 149 | { \ |
| 150 | return sprintf(page, _format, _value); \ |
| 151 | } \ |
| 152 | static struct subsys_attribute sys_##_prefix##_##_name##_attr = \ |
| 153 | __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL); |
| 154 | |
| 155 | #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ |
| 156 | static ssize_t sys_##_prefix##_##_name##_show(struct subsystem *subsys, \ |
| 157 | char *page) \ |
| 158 | { \ |
| 159 | return sprintf(page, _fmt_out, \ |
| 160 | (unsigned long long) _value); \ |
| 161 | } \ |
| 162 | static ssize_t sys_##_prefix##_##_name##_store(struct subsystem *subsys,\ |
| 163 | const char *buf, size_t len) \ |
| 164 | { \ |
| 165 | unsigned long long value; \ |
| 166 | if (sscanf(buf, _fmt_in, &value) != 1) \ |
| 167 | return -EINVAL; \ |
| 168 | _value = value; \ |
| 169 | return len; \ |
| 170 | } \ |
| 171 | static struct subsys_attribute sys_##_prefix##_##_name##_attr = \ |
| 172 | __ATTR(_name,(S_IRUGO | S_IWUSR), \ |
| 173 | sys_##_prefix##_##_name##_show, \ |
| 174 | sys_##_prefix##_##_name##_store); |
| 175 | |
| 176 | static void make_attrs_ro(struct attribute **attrs) |
| 177 | { |
| 178 | while (*attrs) { |
| 179 | (*attrs)->mode = S_IRUGO; |
| 180 | attrs++; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * ipl section |
| 186 | */ |
| 187 | |
| 188 | static enum ipl_type ipl_get_type(void) |
| 189 | { |
| 190 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 191 | |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 192 | if (!(ipl_flags & IPL_DEVNO_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 193 | return IPL_TYPE_UNKNOWN; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 194 | if (!(ipl_flags & IPL_PARMBLOCK_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 195 | return IPL_TYPE_CCW; |
| 196 | if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION) |
| 197 | return IPL_TYPE_UNKNOWN; |
| 198 | if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP) |
| 199 | return IPL_TYPE_UNKNOWN; |
| 200 | return IPL_TYPE_FCP; |
| 201 | } |
| 202 | |
| 203 | static ssize_t ipl_type_show(struct subsystem *subsys, char *page) |
| 204 | { |
| 205 | return sprintf(page, "%s\n", ipl_type_str(ipl_get_type())); |
| 206 | } |
| 207 | |
| 208 | static struct subsys_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); |
| 209 | |
| 210 | static ssize_t sys_ipl_device_show(struct subsystem *subsys, char *page) |
| 211 | { |
| 212 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 213 | |
| 214 | switch (ipl_get_type()) { |
| 215 | case IPL_TYPE_CCW: |
| 216 | return sprintf(page, "0.0.%04x\n", ipl_devno); |
| 217 | case IPL_TYPE_FCP: |
| 218 | return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno); |
| 219 | default: |
| 220 | return 0; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | static struct subsys_attribute sys_ipl_device_attr = |
| 225 | __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); |
| 226 | |
| 227 | static ssize_t ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, |
| 228 | size_t count) |
| 229 | { |
| 230 | unsigned int size = IPL_PARMBLOCK_SIZE; |
| 231 | |
| 232 | if (off > size) |
| 233 | return 0; |
| 234 | if (off + count > size) |
| 235 | count = size - off; |
| 236 | memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count); |
| 237 | return count; |
| 238 | } |
| 239 | |
| 240 | static struct bin_attribute ipl_parameter_attr = { |
| 241 | .attr = { |
| 242 | .name = "binary_parameter", |
| 243 | .mode = S_IRUGO, |
| 244 | .owner = THIS_MODULE, |
| 245 | }, |
| 246 | .size = PAGE_SIZE, |
| 247 | .read = &ipl_parameter_read, |
| 248 | }; |
| 249 | |
| 250 | static ssize_t ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, |
| 251 | size_t count) |
| 252 | { |
| 253 | unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len; |
| 254 | void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data; |
| 255 | |
| 256 | if (off > size) |
| 257 | return 0; |
| 258 | if (off + count > size) |
| 259 | count = size - off; |
| 260 | memcpy(buf, scp_data + off, count); |
| 261 | return count; |
| 262 | } |
| 263 | |
| 264 | static struct bin_attribute ipl_scp_data_attr = { |
| 265 | .attr = { |
| 266 | .name = "scp_data", |
| 267 | .mode = S_IRUGO, |
| 268 | .owner = THIS_MODULE, |
| 269 | }, |
| 270 | .size = PAGE_SIZE, |
| 271 | .read = &ipl_scp_data_read, |
| 272 | }; |
| 273 | |
| 274 | /* FCP ipl device attributes */ |
| 275 | |
| 276 | DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long) |
| 277 | IPL_PARMBLOCK_START->ipl_info.fcp.wwpn); |
| 278 | DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long) |
| 279 | IPL_PARMBLOCK_START->ipl_info.fcp.lun); |
| 280 | DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long) |
| 281 | IPL_PARMBLOCK_START->ipl_info.fcp.bootprog); |
| 282 | DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long) |
| 283 | IPL_PARMBLOCK_START->ipl_info.fcp.br_lba); |
| 284 | |
| 285 | static struct attribute *ipl_fcp_attrs[] = { |
| 286 | &sys_ipl_type_attr.attr, |
| 287 | &sys_ipl_device_attr.attr, |
| 288 | &sys_ipl_fcp_wwpn_attr.attr, |
| 289 | &sys_ipl_fcp_lun_attr.attr, |
| 290 | &sys_ipl_fcp_bootprog_attr.attr, |
| 291 | &sys_ipl_fcp_br_lba_attr.attr, |
| 292 | NULL, |
| 293 | }; |
| 294 | |
| 295 | static struct attribute_group ipl_fcp_attr_group = { |
| 296 | .attrs = ipl_fcp_attrs, |
| 297 | }; |
| 298 | |
| 299 | /* CCW ipl device attributes */ |
| 300 | |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 301 | static ssize_t ipl_ccw_loadparm_show(struct subsystem *subsys, char *page) |
| 302 | { |
| 303 | char loadparm[LOADPARM_LEN + 1] = {}; |
| 304 | |
| 305 | if (!SCCB_VALID) |
| 306 | return sprintf(page, "#unknown#\n"); |
| 307 | memcpy(loadparm, SCCB_LOADPARM, LOADPARM_LEN); |
| 308 | EBCASC(loadparm, LOADPARM_LEN); |
| 309 | strstrip(loadparm); |
| 310 | return sprintf(page, "%s\n", loadparm); |
| 311 | } |
| 312 | |
| 313 | static struct subsys_attribute sys_ipl_ccw_loadparm_attr = |
| 314 | __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); |
| 315 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 316 | static struct attribute *ipl_ccw_attrs[] = { |
| 317 | &sys_ipl_type_attr.attr, |
| 318 | &sys_ipl_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 319 | &sys_ipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 320 | NULL, |
| 321 | }; |
| 322 | |
| 323 | static struct attribute_group ipl_ccw_attr_group = { |
| 324 | .attrs = ipl_ccw_attrs, |
| 325 | }; |
| 326 | |
| 327 | /* UNKNOWN ipl device attributes */ |
| 328 | |
| 329 | static struct attribute *ipl_unknown_attrs[] = { |
| 330 | &sys_ipl_type_attr.attr, |
| 331 | NULL, |
| 332 | }; |
| 333 | |
| 334 | static struct attribute_group ipl_unknown_attr_group = { |
| 335 | .attrs = ipl_unknown_attrs, |
| 336 | }; |
| 337 | |
| 338 | static decl_subsys(ipl, NULL, NULL); |
| 339 | |
| 340 | /* |
| 341 | * reipl section |
| 342 | */ |
| 343 | |
| 344 | /* FCP reipl device attributes */ |
| 345 | |
| 346 | DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n", |
| 347 | reipl_block_fcp->ipl_info.fcp.wwpn); |
| 348 | DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n", |
| 349 | reipl_block_fcp->ipl_info.fcp.lun); |
| 350 | DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n", |
| 351 | reipl_block_fcp->ipl_info.fcp.bootprog); |
| 352 | DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n", |
| 353 | reipl_block_fcp->ipl_info.fcp.br_lba); |
| 354 | DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 355 | reipl_block_fcp->ipl_info.fcp.devno); |
| 356 | |
| 357 | static struct attribute *reipl_fcp_attrs[] = { |
| 358 | &sys_reipl_fcp_device_attr.attr, |
| 359 | &sys_reipl_fcp_wwpn_attr.attr, |
| 360 | &sys_reipl_fcp_lun_attr.attr, |
| 361 | &sys_reipl_fcp_bootprog_attr.attr, |
| 362 | &sys_reipl_fcp_br_lba_attr.attr, |
| 363 | NULL, |
| 364 | }; |
| 365 | |
| 366 | static struct attribute_group reipl_fcp_attr_group = { |
| 367 | .name = IPL_FCP_STR, |
| 368 | .attrs = reipl_fcp_attrs, |
| 369 | }; |
| 370 | |
| 371 | /* CCW reipl device attributes */ |
| 372 | |
| 373 | DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 374 | reipl_block_ccw->ipl_info.ccw.devno); |
| 375 | |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 376 | static void reipl_get_ascii_loadparm(char *loadparm) |
| 377 | { |
| 378 | memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param, |
| 379 | LOADPARM_LEN); |
| 380 | EBCASC(loadparm, LOADPARM_LEN); |
| 381 | loadparm[LOADPARM_LEN] = 0; |
| 382 | strstrip(loadparm); |
| 383 | } |
| 384 | |
| 385 | static ssize_t reipl_ccw_loadparm_show(struct subsystem *subsys, char *page) |
| 386 | { |
| 387 | char buf[LOADPARM_LEN + 1]; |
| 388 | |
| 389 | reipl_get_ascii_loadparm(buf); |
| 390 | return sprintf(page, "%s\n", buf); |
| 391 | } |
| 392 | |
| 393 | static ssize_t reipl_ccw_loadparm_store(struct subsystem *subsys, |
| 394 | const char *buf, size_t len) |
| 395 | { |
| 396 | int i, lp_len; |
| 397 | |
| 398 | /* ignore trailing newline */ |
| 399 | lp_len = len; |
| 400 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 401 | lp_len--; |
| 402 | /* loadparm can have max 8 characters and must not start with a blank */ |
| 403 | if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' '))) |
| 404 | return -EINVAL; |
| 405 | /* loadparm can only contain "a-z,A-Z,0-9,SP,." */ |
| 406 | for (i = 0; i < lp_len; i++) { |
| 407 | if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') || |
| 408 | (buf[i] == '.')) |
| 409 | continue; |
| 410 | return -EINVAL; |
| 411 | } |
| 412 | /* initialize loadparm with blanks */ |
| 413 | memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN); |
| 414 | /* copy and convert to ebcdic */ |
| 415 | memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len); |
| 416 | ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN); |
| 417 | return len; |
| 418 | } |
| 419 | |
| 420 | static struct subsys_attribute sys_reipl_ccw_loadparm_attr = |
| 421 | __ATTR(loadparm, 0644, reipl_ccw_loadparm_show, |
| 422 | reipl_ccw_loadparm_store); |
| 423 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 424 | static struct attribute *reipl_ccw_attrs[] = { |
| 425 | &sys_reipl_ccw_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 426 | &sys_reipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 427 | NULL, |
| 428 | }; |
| 429 | |
| 430 | static struct attribute_group reipl_ccw_attr_group = { |
| 431 | .name = IPL_CCW_STR, |
| 432 | .attrs = reipl_ccw_attrs, |
| 433 | }; |
| 434 | |
| 435 | /* reipl type */ |
| 436 | |
| 437 | static int reipl_set_type(enum ipl_type type) |
| 438 | { |
| 439 | if (!(reipl_capabilities & type)) |
| 440 | return -EINVAL; |
| 441 | |
| 442 | switch(type) { |
| 443 | case IPL_TYPE_CCW: |
| 444 | if (MACHINE_IS_VM) |
| 445 | reipl_method = IPL_METHOD_CCW_VM; |
| 446 | else |
| 447 | reipl_method = IPL_METHOD_CCW_CIO; |
| 448 | break; |
| 449 | case IPL_TYPE_FCP: |
| 450 | if (diag308_set_works) |
| 451 | reipl_method = IPL_METHOD_FCP_RW_DIAG; |
| 452 | else if (MACHINE_IS_VM) |
| 453 | reipl_method = IPL_METHOD_FCP_RO_VM; |
| 454 | else |
| 455 | reipl_method = IPL_METHOD_FCP_RO_DIAG; |
| 456 | break; |
| 457 | default: |
| 458 | reipl_method = IPL_METHOD_NONE; |
| 459 | } |
| 460 | reipl_type = type; |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static ssize_t reipl_type_show(struct subsystem *subsys, char *page) |
| 465 | { |
| 466 | return sprintf(page, "%s\n", ipl_type_str(reipl_type)); |
| 467 | } |
| 468 | |
| 469 | static ssize_t reipl_type_store(struct subsystem *subsys, const char *buf, |
| 470 | size_t len) |
| 471 | { |
| 472 | int rc = -EINVAL; |
| 473 | |
| 474 | if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0) |
| 475 | rc = reipl_set_type(IPL_TYPE_CCW); |
| 476 | else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0) |
| 477 | rc = reipl_set_type(IPL_TYPE_FCP); |
| 478 | return (rc != 0) ? rc : len; |
| 479 | } |
| 480 | |
| 481 | static struct subsys_attribute reipl_type_attr = |
| 482 | __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); |
| 483 | |
| 484 | static decl_subsys(reipl, NULL, NULL); |
| 485 | |
| 486 | /* |
| 487 | * dump section |
| 488 | */ |
| 489 | |
| 490 | /* FCP dump device attributes */ |
| 491 | |
| 492 | DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n", |
| 493 | dump_block_fcp->ipl_info.fcp.wwpn); |
| 494 | DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n", |
| 495 | dump_block_fcp->ipl_info.fcp.lun); |
| 496 | DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n", |
| 497 | dump_block_fcp->ipl_info.fcp.bootprog); |
| 498 | DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n", |
| 499 | dump_block_fcp->ipl_info.fcp.br_lba); |
| 500 | DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 501 | dump_block_fcp->ipl_info.fcp.devno); |
| 502 | |
| 503 | static struct attribute *dump_fcp_attrs[] = { |
| 504 | &sys_dump_fcp_device_attr.attr, |
| 505 | &sys_dump_fcp_wwpn_attr.attr, |
| 506 | &sys_dump_fcp_lun_attr.attr, |
| 507 | &sys_dump_fcp_bootprog_attr.attr, |
| 508 | &sys_dump_fcp_br_lba_attr.attr, |
| 509 | NULL, |
| 510 | }; |
| 511 | |
| 512 | static struct attribute_group dump_fcp_attr_group = { |
| 513 | .name = IPL_FCP_STR, |
| 514 | .attrs = dump_fcp_attrs, |
| 515 | }; |
| 516 | |
| 517 | /* CCW dump device attributes */ |
| 518 | |
| 519 | DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 520 | dump_block_ccw->ipl_info.ccw.devno); |
| 521 | |
| 522 | static struct attribute *dump_ccw_attrs[] = { |
| 523 | &sys_dump_ccw_device_attr.attr, |
| 524 | NULL, |
| 525 | }; |
| 526 | |
| 527 | static struct attribute_group dump_ccw_attr_group = { |
| 528 | .name = IPL_CCW_STR, |
| 529 | .attrs = dump_ccw_attrs, |
| 530 | }; |
| 531 | |
| 532 | /* dump type */ |
| 533 | |
| 534 | static int dump_set_type(enum ipl_type type) |
| 535 | { |
| 536 | if (!(dump_capabilities & type)) |
| 537 | return -EINVAL; |
| 538 | switch(type) { |
| 539 | case IPL_TYPE_CCW: |
| 540 | if (MACHINE_IS_VM) |
| 541 | dump_method = IPL_METHOD_CCW_VM; |
| 542 | else |
| 543 | dump_method = IPL_METHOD_CCW_CIO; |
| 544 | break; |
| 545 | case IPL_TYPE_FCP: |
| 546 | dump_method = IPL_METHOD_FCP_RW_DIAG; |
| 547 | break; |
| 548 | default: |
| 549 | dump_method = IPL_METHOD_NONE; |
| 550 | } |
| 551 | dump_type = type; |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | static ssize_t dump_type_show(struct subsystem *subsys, char *page) |
| 556 | { |
| 557 | return sprintf(page, "%s\n", ipl_type_str(dump_type)); |
| 558 | } |
| 559 | |
| 560 | static ssize_t dump_type_store(struct subsystem *subsys, const char *buf, |
| 561 | size_t len) |
| 562 | { |
| 563 | int rc = -EINVAL; |
| 564 | |
| 565 | if (strncmp(buf, IPL_NONE_STR, strlen(IPL_NONE_STR)) == 0) |
| 566 | rc = dump_set_type(IPL_TYPE_NONE); |
| 567 | else if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0) |
| 568 | rc = dump_set_type(IPL_TYPE_CCW); |
| 569 | else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0) |
| 570 | rc = dump_set_type(IPL_TYPE_FCP); |
| 571 | return (rc != 0) ? rc : len; |
| 572 | } |
| 573 | |
| 574 | static struct subsys_attribute dump_type_attr = |
| 575 | __ATTR(dump_type, 0644, dump_type_show, dump_type_store); |
| 576 | |
| 577 | static decl_subsys(dump, NULL, NULL); |
| 578 | |
| 579 | #ifdef CONFIG_SMP |
| 580 | static void dump_smp_stop_all(void) |
| 581 | { |
| 582 | int cpu; |
| 583 | preempt_disable(); |
| 584 | for_each_online_cpu(cpu) { |
| 585 | if (cpu == smp_processor_id()) |
| 586 | continue; |
| 587 | while (signal_processor(cpu, sigp_stop) == sigp_busy) |
| 588 | udelay(10); |
| 589 | } |
| 590 | preempt_enable(); |
| 591 | } |
| 592 | #else |
| 593 | #define dump_smp_stop_all() do { } while (0) |
| 594 | #endif |
| 595 | |
| 596 | /* |
| 597 | * Shutdown actions section |
| 598 | */ |
| 599 | |
| 600 | static decl_subsys(shutdown_actions, NULL, NULL); |
| 601 | |
| 602 | /* on panic */ |
| 603 | |
| 604 | static ssize_t on_panic_show(struct subsystem *subsys, char *page) |
| 605 | { |
| 606 | return sprintf(page, "%s\n", shutdown_action_str(on_panic_action)); |
| 607 | } |
| 608 | |
| 609 | static ssize_t on_panic_store(struct subsystem *subsys, const char *buf, |
| 610 | size_t len) |
| 611 | { |
| 612 | if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0) |
| 613 | on_panic_action = SHUTDOWN_REIPL; |
| 614 | else if (strncmp(buf, SHUTDOWN_DUMP_STR, |
| 615 | strlen(SHUTDOWN_DUMP_STR)) == 0) |
| 616 | on_panic_action = SHUTDOWN_DUMP; |
| 617 | else if (strncmp(buf, SHUTDOWN_STOP_STR, |
| 618 | strlen(SHUTDOWN_STOP_STR)) == 0) |
| 619 | on_panic_action = SHUTDOWN_STOP; |
| 620 | else |
| 621 | return -EINVAL; |
| 622 | |
| 623 | return len; |
| 624 | } |
| 625 | |
| 626 | static struct subsys_attribute on_panic_attr = |
| 627 | __ATTR(on_panic, 0644, on_panic_show, on_panic_store); |
| 628 | |
| 629 | static void print_fcp_block(struct ipl_parameter_block *fcp_block) |
| 630 | { |
| 631 | printk(KERN_EMERG "wwpn: %016llx\n", |
| 632 | (unsigned long long)fcp_block->ipl_info.fcp.wwpn); |
| 633 | printk(KERN_EMERG "lun: %016llx\n", |
| 634 | (unsigned long long)fcp_block->ipl_info.fcp.lun); |
| 635 | printk(KERN_EMERG "bootprog: %lld\n", |
| 636 | (unsigned long long)fcp_block->ipl_info.fcp.bootprog); |
| 637 | printk(KERN_EMERG "br_lba: %lld\n", |
| 638 | (unsigned long long)fcp_block->ipl_info.fcp.br_lba); |
| 639 | printk(KERN_EMERG "device: %llx\n", |
| 640 | (unsigned long long)fcp_block->ipl_info.fcp.devno); |
| 641 | printk(KERN_EMERG "opt: %x\n", fcp_block->ipl_info.fcp.opt); |
| 642 | } |
| 643 | |
| 644 | void do_reipl(void) |
| 645 | { |
| 646 | struct ccw_dev_id devid; |
| 647 | static char buf[100]; |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 648 | char loadparm[LOADPARM_LEN + 1]; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 649 | |
| 650 | switch (reipl_type) { |
| 651 | case IPL_TYPE_CCW: |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 652 | reipl_get_ascii_loadparm(loadparm); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 653 | printk(KERN_EMERG "reboot on ccw device: 0.0.%04x\n", |
| 654 | reipl_block_ccw->ipl_info.ccw.devno); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 655 | printk(KERN_EMERG "loadparm = '%s'\n", loadparm); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 656 | break; |
| 657 | case IPL_TYPE_FCP: |
| 658 | printk(KERN_EMERG "reboot on fcp device:\n"); |
| 659 | print_fcp_block(reipl_block_fcp); |
| 660 | break; |
| 661 | default: |
| 662 | break; |
| 663 | } |
| 664 | |
| 665 | switch (reipl_method) { |
| 666 | case IPL_METHOD_CCW_CIO: |
| 667 | devid.devno = reipl_block_ccw->ipl_info.ccw.devno; |
Michael Holzheu | 5986b0e | 2006-12-04 15:40:13 +0100 | [diff] [blame] | 668 | if (ipl_get_type() == IPL_TYPE_CCW && devid.devno == ipl_devno) |
| 669 | diag308(DIAG308_IPL, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 670 | devid.ssid = 0; |
| 671 | reipl_ccw_dev(&devid); |
| 672 | break; |
| 673 | case IPL_METHOD_CCW_VM: |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 674 | if (strlen(loadparm) == 0) |
| 675 | sprintf(buf, "IPL %X", |
| 676 | reipl_block_ccw->ipl_info.ccw.devno); |
| 677 | else |
| 678 | sprintf(buf, "IPL %X LOADPARM '%s'", |
| 679 | reipl_block_ccw->ipl_info.ccw.devno, loadparm); |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame^] | 680 | __cpcmd(buf, NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 681 | break; |
| 682 | case IPL_METHOD_CCW_DIAG: |
| 683 | diag308(DIAG308_SET, reipl_block_ccw); |
| 684 | diag308(DIAG308_IPL, NULL); |
| 685 | break; |
| 686 | case IPL_METHOD_FCP_RW_DIAG: |
| 687 | diag308(DIAG308_SET, reipl_block_fcp); |
| 688 | diag308(DIAG308_IPL, NULL); |
| 689 | break; |
| 690 | case IPL_METHOD_FCP_RO_DIAG: |
| 691 | diag308(DIAG308_IPL, NULL); |
| 692 | break; |
| 693 | case IPL_METHOD_FCP_RO_VM: |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame^] | 694 | __cpcmd("IPL", NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 695 | break; |
| 696 | case IPL_METHOD_NONE: |
| 697 | default: |
| 698 | if (MACHINE_IS_VM) |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame^] | 699 | __cpcmd("IPL", NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 700 | diag308(DIAG308_IPL, NULL); |
| 701 | break; |
| 702 | } |
Michael Holzheu | 3902e47 | 2006-12-04 15:40:05 +0100 | [diff] [blame] | 703 | printk(KERN_EMERG "reboot failed!\n"); |
| 704 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static void do_dump(void) |
| 708 | { |
| 709 | struct ccw_dev_id devid; |
| 710 | static char buf[100]; |
| 711 | |
| 712 | switch (dump_type) { |
| 713 | case IPL_TYPE_CCW: |
| 714 | printk(KERN_EMERG "Automatic dump on ccw device: 0.0.%04x\n", |
| 715 | dump_block_ccw->ipl_info.ccw.devno); |
| 716 | break; |
| 717 | case IPL_TYPE_FCP: |
| 718 | printk(KERN_EMERG "Automatic dump on fcp device:\n"); |
| 719 | print_fcp_block(dump_block_fcp); |
| 720 | break; |
| 721 | default: |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | switch (dump_method) { |
| 726 | case IPL_METHOD_CCW_CIO: |
| 727 | dump_smp_stop_all(); |
| 728 | devid.devno = dump_block_ccw->ipl_info.ccw.devno; |
| 729 | devid.ssid = 0; |
| 730 | reipl_ccw_dev(&devid); |
| 731 | break; |
| 732 | case IPL_METHOD_CCW_VM: |
| 733 | dump_smp_stop_all(); |
| 734 | sprintf(buf, "STORE STATUS"); |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame^] | 735 | __cpcmd(buf, NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 736 | sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno); |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame^] | 737 | __cpcmd(buf, NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 738 | break; |
| 739 | case IPL_METHOD_CCW_DIAG: |
| 740 | diag308(DIAG308_SET, dump_block_ccw); |
| 741 | diag308(DIAG308_DUMP, NULL); |
| 742 | break; |
| 743 | case IPL_METHOD_FCP_RW_DIAG: |
| 744 | diag308(DIAG308_SET, dump_block_fcp); |
| 745 | diag308(DIAG308_DUMP, NULL); |
| 746 | break; |
| 747 | case IPL_METHOD_NONE: |
| 748 | default: |
| 749 | return; |
| 750 | } |
| 751 | printk(KERN_EMERG "Dump failed!\n"); |
| 752 | } |
| 753 | |
| 754 | /* init functions */ |
| 755 | |
| 756 | static int __init ipl_register_fcp_files(void) |
| 757 | { |
| 758 | int rc; |
| 759 | |
| 760 | rc = sysfs_create_group(&ipl_subsys.kset.kobj, |
| 761 | &ipl_fcp_attr_group); |
| 762 | if (rc) |
| 763 | goto out; |
| 764 | rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj, |
| 765 | &ipl_parameter_attr); |
| 766 | if (rc) |
| 767 | goto out_ipl_parm; |
| 768 | rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj, |
| 769 | &ipl_scp_data_attr); |
| 770 | if (!rc) |
| 771 | goto out; |
| 772 | |
| 773 | sysfs_remove_bin_file(&ipl_subsys.kset.kobj, &ipl_parameter_attr); |
| 774 | |
| 775 | out_ipl_parm: |
| 776 | sysfs_remove_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group); |
| 777 | out: |
| 778 | return rc; |
| 779 | } |
| 780 | |
| 781 | static int __init ipl_init(void) |
| 782 | { |
| 783 | int rc; |
| 784 | |
| 785 | rc = firmware_register(&ipl_subsys); |
| 786 | if (rc) |
| 787 | return rc; |
| 788 | switch (ipl_get_type()) { |
| 789 | case IPL_TYPE_CCW: |
| 790 | rc = sysfs_create_group(&ipl_subsys.kset.kobj, |
| 791 | &ipl_ccw_attr_group); |
| 792 | break; |
| 793 | case IPL_TYPE_FCP: |
| 794 | rc = ipl_register_fcp_files(); |
| 795 | break; |
| 796 | default: |
| 797 | rc = sysfs_create_group(&ipl_subsys.kset.kobj, |
| 798 | &ipl_unknown_attr_group); |
| 799 | break; |
| 800 | } |
| 801 | if (rc) |
| 802 | firmware_unregister(&ipl_subsys); |
| 803 | return rc; |
| 804 | } |
| 805 | |
| 806 | static void __init reipl_probe(void) |
| 807 | { |
| 808 | void *buffer; |
| 809 | |
| 810 | buffer = (void *) get_zeroed_page(GFP_KERNEL); |
| 811 | if (!buffer) |
| 812 | return; |
| 813 | if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK) |
| 814 | diag308_set_works = 1; |
| 815 | free_page((unsigned long)buffer); |
| 816 | } |
| 817 | |
| 818 | static int __init reipl_ccw_init(void) |
| 819 | { |
| 820 | int rc; |
| 821 | |
| 822 | reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 823 | if (!reipl_block_ccw) |
| 824 | return -ENOMEM; |
| 825 | rc = sysfs_create_group(&reipl_subsys.kset.kobj, &reipl_ccw_attr_group); |
| 826 | if (rc) { |
| 827 | free_page((unsigned long)reipl_block_ccw); |
| 828 | return rc; |
| 829 | } |
| 830 | reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 831 | reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 832 | reipl_block_ccw->hdr.blk0_len = sizeof(reipl_block_ccw->ipl_info.ccw); |
| 833 | reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 834 | /* check if read scp info worked and set loadparm */ |
| 835 | if (SCCB_VALID) |
| 836 | memcpy(reipl_block_ccw->ipl_info.ccw.load_param, |
| 837 | SCCB_LOADPARM, LOADPARM_LEN); |
| 838 | else |
| 839 | /* read scp info failed: set empty loadparm (EBCDIC blanks) */ |
| 840 | memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40, |
| 841 | LOADPARM_LEN); |
| 842 | /* FIXME: check for diag308_set_works when enabling diag ccw reipl */ |
| 843 | if (!MACHINE_IS_VM) |
| 844 | sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 845 | if (ipl_get_type() == IPL_TYPE_CCW) |
| 846 | reipl_block_ccw->ipl_info.ccw.devno = ipl_devno; |
| 847 | reipl_capabilities |= IPL_TYPE_CCW; |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static int __init reipl_fcp_init(void) |
| 852 | { |
| 853 | int rc; |
| 854 | |
| 855 | if ((!diag308_set_works) && (ipl_get_type() != IPL_TYPE_FCP)) |
| 856 | return 0; |
| 857 | if ((!diag308_set_works) && (ipl_get_type() == IPL_TYPE_FCP)) |
| 858 | make_attrs_ro(reipl_fcp_attrs); |
| 859 | |
| 860 | reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 861 | if (!reipl_block_fcp) |
| 862 | return -ENOMEM; |
| 863 | rc = sysfs_create_group(&reipl_subsys.kset.kobj, &reipl_fcp_attr_group); |
| 864 | if (rc) { |
| 865 | free_page((unsigned long)reipl_block_fcp); |
| 866 | return rc; |
| 867 | } |
| 868 | if (ipl_get_type() == IPL_TYPE_FCP) { |
| 869 | memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE); |
| 870 | } else { |
| 871 | reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 872 | reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 873 | reipl_block_fcp->hdr.blk0_len = |
| 874 | sizeof(reipl_block_fcp->ipl_info.fcp); |
| 875 | reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 876 | reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL; |
| 877 | } |
| 878 | reipl_capabilities |= IPL_TYPE_FCP; |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | static int __init reipl_init(void) |
| 883 | { |
| 884 | int rc; |
| 885 | |
| 886 | rc = firmware_register(&reipl_subsys); |
| 887 | if (rc) |
| 888 | return rc; |
| 889 | rc = subsys_create_file(&reipl_subsys, &reipl_type_attr); |
| 890 | if (rc) { |
| 891 | firmware_unregister(&reipl_subsys); |
| 892 | return rc; |
| 893 | } |
| 894 | rc = reipl_ccw_init(); |
| 895 | if (rc) |
| 896 | return rc; |
| 897 | rc = reipl_fcp_init(); |
| 898 | if (rc) |
| 899 | return rc; |
| 900 | rc = reipl_set_type(ipl_get_type()); |
| 901 | if (rc) |
| 902 | return rc; |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | static int __init dump_ccw_init(void) |
| 907 | { |
| 908 | int rc; |
| 909 | |
| 910 | dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 911 | if (!dump_block_ccw) |
| 912 | return -ENOMEM; |
| 913 | rc = sysfs_create_group(&dump_subsys.kset.kobj, &dump_ccw_attr_group); |
| 914 | if (rc) { |
| 915 | free_page((unsigned long)dump_block_ccw); |
| 916 | return rc; |
| 917 | } |
| 918 | dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 919 | dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 920 | dump_block_ccw->hdr.blk0_len = sizeof(reipl_block_ccw->ipl_info.ccw); |
| 921 | dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
| 922 | dump_capabilities |= IPL_TYPE_CCW; |
| 923 | return 0; |
| 924 | } |
| 925 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 926 | static int __init dump_fcp_init(void) |
| 927 | { |
| 928 | int rc; |
| 929 | |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 930 | if(!(SCCB_FLAG & 0x2) || !SCCB_VALID) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 931 | return 0; /* LDIPL DUMP is not installed */ |
| 932 | if (!diag308_set_works) |
| 933 | return 0; |
| 934 | dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 935 | if (!dump_block_fcp) |
| 936 | return -ENOMEM; |
| 937 | rc = sysfs_create_group(&dump_subsys.kset.kobj, &dump_fcp_attr_group); |
| 938 | if (rc) { |
| 939 | free_page((unsigned long)dump_block_fcp); |
| 940 | return rc; |
| 941 | } |
| 942 | dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 943 | dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 944 | dump_block_fcp->hdr.blk0_len = sizeof(dump_block_fcp->ipl_info.fcp); |
| 945 | dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 946 | dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP; |
| 947 | dump_capabilities |= IPL_TYPE_FCP; |
| 948 | return 0; |
| 949 | } |
| 950 | |
| 951 | #define SHUTDOWN_ON_PANIC_PRIO 0 |
| 952 | |
| 953 | static int shutdown_on_panic_notify(struct notifier_block *self, |
| 954 | unsigned long event, void *data) |
| 955 | { |
| 956 | if (on_panic_action == SHUTDOWN_DUMP) |
| 957 | do_dump(); |
| 958 | else if (on_panic_action == SHUTDOWN_REIPL) |
| 959 | do_reipl(); |
| 960 | return NOTIFY_OK; |
| 961 | } |
| 962 | |
| 963 | static struct notifier_block shutdown_on_panic_nb = { |
| 964 | .notifier_call = shutdown_on_panic_notify, |
| 965 | .priority = SHUTDOWN_ON_PANIC_PRIO |
| 966 | }; |
| 967 | |
| 968 | static int __init dump_init(void) |
| 969 | { |
| 970 | int rc; |
| 971 | |
| 972 | rc = firmware_register(&dump_subsys); |
| 973 | if (rc) |
| 974 | return rc; |
| 975 | rc = subsys_create_file(&dump_subsys, &dump_type_attr); |
| 976 | if (rc) { |
| 977 | firmware_unregister(&dump_subsys); |
| 978 | return rc; |
| 979 | } |
| 980 | rc = dump_ccw_init(); |
| 981 | if (rc) |
| 982 | return rc; |
| 983 | rc = dump_fcp_init(); |
| 984 | if (rc) |
| 985 | return rc; |
| 986 | dump_set_type(IPL_TYPE_NONE); |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | static int __init shutdown_actions_init(void) |
| 991 | { |
| 992 | int rc; |
| 993 | |
| 994 | rc = firmware_register(&shutdown_actions_subsys); |
| 995 | if (rc) |
| 996 | return rc; |
| 997 | rc = subsys_create_file(&shutdown_actions_subsys, &on_panic_attr); |
| 998 | if (rc) { |
| 999 | firmware_unregister(&shutdown_actions_subsys); |
| 1000 | return rc; |
| 1001 | } |
| 1002 | atomic_notifier_chain_register(&panic_notifier_list, |
| 1003 | &shutdown_on_panic_nb); |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | static int __init s390_ipl_init(void) |
| 1008 | { |
| 1009 | int rc; |
| 1010 | |
| 1011 | reipl_probe(); |
| 1012 | rc = ipl_init(); |
| 1013 | if (rc) |
| 1014 | return rc; |
| 1015 | rc = reipl_init(); |
| 1016 | if (rc) |
| 1017 | return rc; |
| 1018 | rc = dump_init(); |
| 1019 | if (rc) |
| 1020 | return rc; |
| 1021 | rc = shutdown_actions_init(); |
| 1022 | if (rc) |
| 1023 | return rc; |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | __initcall(s390_ipl_init); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1028 | |
| 1029 | static LIST_HEAD(rcall); |
| 1030 | static DEFINE_MUTEX(rcall_mutex); |
| 1031 | |
| 1032 | void register_reset_call(struct reset_call *reset) |
| 1033 | { |
| 1034 | mutex_lock(&rcall_mutex); |
| 1035 | list_add(&reset->list, &rcall); |
| 1036 | mutex_unlock(&rcall_mutex); |
| 1037 | } |
| 1038 | EXPORT_SYMBOL_GPL(register_reset_call); |
| 1039 | |
| 1040 | void unregister_reset_call(struct reset_call *reset) |
| 1041 | { |
| 1042 | mutex_lock(&rcall_mutex); |
| 1043 | list_del(&reset->list); |
| 1044 | mutex_unlock(&rcall_mutex); |
| 1045 | } |
| 1046 | EXPORT_SYMBOL_GPL(unregister_reset_call); |
| 1047 | |
| 1048 | static void do_reset_calls(void) |
| 1049 | { |
| 1050 | struct reset_call *reset; |
| 1051 | |
| 1052 | list_for_each_entry(reset, &rcall, list) |
| 1053 | reset->fn(); |
| 1054 | } |
| 1055 | |
| 1056 | extern void reset_mcck_handler(void); |
| 1057 | |
| 1058 | void s390_reset_system(void) |
| 1059 | { |
| 1060 | struct _lowcore *lc; |
| 1061 | |
| 1062 | /* Disable all interrupts/machine checks */ |
| 1063 | __load_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK); |
| 1064 | |
| 1065 | /* Stack for interrupt/machine check handler */ |
| 1066 | lc = (struct _lowcore *)(unsigned long) store_prefix(); |
| 1067 | lc->panic_stack = S390_lowcore.panic_stack; |
| 1068 | |
| 1069 | /* Disable prefixing */ |
| 1070 | set_prefix(0); |
| 1071 | |
| 1072 | /* Disable lowcore protection */ |
| 1073 | __ctl_clear_bit(0,28); |
| 1074 | |
| 1075 | /* Set new machine check handler */ |
| 1076 | S390_lowcore.mcck_new_psw.mask = PSW_KERNEL_BITS & ~PSW_MASK_MCHECK; |
| 1077 | S390_lowcore.mcck_new_psw.addr = |
| 1078 | PSW_ADDR_AMODE | (unsigned long) &reset_mcck_handler; |
| 1079 | do_reset_calls(); |
| 1080 | } |