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