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