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