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