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