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