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