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