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