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