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