blob: 153e21ce2336ede8c468a792d204c8c4e3aa5f77 [file] [log] [blame]
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001/*
2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
4 *
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04005 * Copyright IBM Corp. 2005,2012
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02006 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
9 */
10
11#include <linux/types.h>
12#include <linux/module.h>
13#include <linux/device.h>
14#include <linux/delay.h>
15#include <linux/reboot.h>
Michael Holzheu03a4d202006-12-04 15:39:58 +010016#include <linux/ctype.h>
Akinobu Mita0788fea2008-07-14 09:59:17 +020017#include <linux/fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/gfp.h>
Michael Holzheu60a0c682011-10-30 15:16:40 +010019#include <linux/crash_dump.h>
Michael Holzheu3ab121a2012-03-11 11:59:32 -040020#include <linux/debug_locks.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010021#include <asm/ipl.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020022#include <asm/smp.h>
23#include <asm/setup.h>
24#include <asm/cpcmd.h>
25#include <asm/cio.h>
Michael Holzheu03a4d202006-12-04 15:39:58 +010026#include <asm/ebcdic.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010027#include <asm/reset.h>
Heiko Carstensab14de62007-02-05 21:18:37 +010028#include <asm/sclp.h>
Frank Munzert159d1ff2009-03-26 15:24:45 +010029#include <asm/checksum.h>
Michael Holzheu3ab121a2012-03-11 11:59:32 -040030#include <asm/debug.h>
Martin Schwidefsky638ad342011-10-30 15:17:13 +010031#include "entry.h"
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020032
33#define IPL_PARM_BLOCK_VERSION 0
Michael Holzheu03a4d202006-12-04 15:39:58 +010034
Michael Holzheu411ed322007-04-27 16:01:49 +020035#define IPL_UNKNOWN_STR "unknown"
36#define IPL_CCW_STR "ccw"
37#define IPL_FCP_STR "fcp"
38#define IPL_FCP_DUMP_STR "fcp_dump"
39#define IPL_NSS_STR "nss"
Heiko Carstens615b04b2007-02-21 10:55:37 +010040
Michael Holzheu99ca4e52008-01-26 14:11:11 +010041#define DUMP_CCW_STR "ccw"
42#define DUMP_FCP_STR "fcp"
43#define DUMP_NONE_STR "none"
44
45/*
46 * Four shutdown trigger types are supported:
47 * - panic
48 * - halt
49 * - power off
50 * - reipl
Michael Holzheu7dd6b332011-08-03 16:44:19 +020051 * - restart
Michael Holzheu99ca4e52008-01-26 14:11:11 +010052 */
53#define ON_PANIC_STR "on_panic"
54#define ON_HALT_STR "on_halt"
55#define ON_POFF_STR "on_poff"
56#define ON_REIPL_STR "on_reboot"
Michael Holzheu7dd6b332011-08-03 16:44:19 +020057#define ON_RESTART_STR "on_restart"
Michael Holzheu99ca4e52008-01-26 14:11:11 +010058
59struct shutdown_action;
60struct shutdown_trigger {
61 char *name;
62 struct shutdown_action *action;
63};
64
65/*
Frank Munzert099b7652009-03-26 15:23:43 +010066 * The following shutdown action types are supported:
Michael Holzheu99ca4e52008-01-26 14:11:11 +010067 */
68#define SHUTDOWN_ACTION_IPL_STR "ipl"
69#define SHUTDOWN_ACTION_REIPL_STR "reipl"
70#define SHUTDOWN_ACTION_DUMP_STR "dump"
71#define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72#define SHUTDOWN_ACTION_STOP_STR "stop"
Frank Munzert099b7652009-03-26 15:23:43 +010073#define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
Michael Holzheu99ca4e52008-01-26 14:11:11 +010074
75struct shutdown_action {
76 char *name;
77 void (*fn) (struct shutdown_trigger *trigger);
78 int (*init) (void);
Frank Munzert81088812009-07-07 16:37:07 +020079 int init_rc;
Michael Holzheu99ca4e52008-01-26 14:11:11 +010080};
81
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020082static char *ipl_type_str(enum ipl_type type)
83{
84 switch (type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020085 case IPL_TYPE_CCW:
86 return IPL_CCW_STR;
87 case IPL_TYPE_FCP:
88 return IPL_FCP_STR;
Michael Holzheu411ed322007-04-27 16:01:49 +020089 case IPL_TYPE_FCP_DUMP:
90 return IPL_FCP_DUMP_STR;
Hongjie Yangfe355b72007-02-05 21:18:24 +010091 case IPL_TYPE_NSS:
92 return IPL_NSS_STR;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020093 case IPL_TYPE_UNKNOWN:
94 default:
95 return IPL_UNKNOWN_STR;
96 }
97}
98
Michael Holzheu411ed322007-04-27 16:01:49 +020099enum dump_type {
100 DUMP_TYPE_NONE = 1,
101 DUMP_TYPE_CCW = 2,
102 DUMP_TYPE_FCP = 4,
103};
104
Michael Holzheu411ed322007-04-27 16:01:49 +0200105static char *dump_type_str(enum dump_type type)
106{
107 switch (type) {
108 case DUMP_TYPE_NONE:
109 return DUMP_NONE_STR;
110 case DUMP_TYPE_CCW:
111 return DUMP_CCW_STR;
112 case DUMP_TYPE_FCP:
113 return DUMP_FCP_STR;
114 default:
115 return NULL;
116 }
117}
118
119/*
120 * Must be in data section since the bss section
121 * is not cleared when these are accessed.
122 */
123static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
124u32 ipl_flags __attribute__((__section__(".data"))) = 0;
125
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200126enum ipl_method {
Michael Holzheu411ed322007-04-27 16:01:49 +0200127 REIPL_METHOD_CCW_CIO,
128 REIPL_METHOD_CCW_DIAG,
129 REIPL_METHOD_CCW_VM,
130 REIPL_METHOD_FCP_RO_DIAG,
131 REIPL_METHOD_FCP_RW_DIAG,
132 REIPL_METHOD_FCP_RO_VM,
133 REIPL_METHOD_FCP_DUMP,
134 REIPL_METHOD_NSS,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200135 REIPL_METHOD_NSS_DIAG,
Michael Holzheu411ed322007-04-27 16:01:49 +0200136 REIPL_METHOD_DEFAULT,
137};
138
139enum dump_method {
140 DUMP_METHOD_NONE,
141 DUMP_METHOD_CCW_CIO,
142 DUMP_METHOD_CCW_DIAG,
143 DUMP_METHOD_CCW_VM,
144 DUMP_METHOD_FCP_DIAG,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200145};
146
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200147static int diag308_set_works = 0;
148
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200149static struct ipl_parameter_block ipl_block;
150
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200151static int reipl_capabilities = IPL_TYPE_UNKNOWN;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100152
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200153static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200154static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200155static struct ipl_parameter_block *reipl_block_fcp;
156static struct ipl_parameter_block *reipl_block_ccw;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200157static struct ipl_parameter_block *reipl_block_nss;
Frank Munzert099b7652009-03-26 15:23:43 +0100158static struct ipl_parameter_block *reipl_block_actual;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100159
Michael Holzheu411ed322007-04-27 16:01:49 +0200160static int dump_capabilities = DUMP_TYPE_NONE;
161static enum dump_type dump_type = DUMP_TYPE_NONE;
162static enum dump_method dump_method = DUMP_METHOD_NONE;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200163static struct ipl_parameter_block *dump_block_fcp;
164static struct ipl_parameter_block *dump_block_ccw;
165
Heiko Carstens05dd2532007-07-10 11:24:09 +0200166static struct sclp_ipl_info sclp_ipl_info;
167
Michael Holzheu46b05d22007-02-21 10:55:21 +0100168int diag308(unsigned long subcode, void *addr)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200169{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200170 register unsigned long _addr asm("0") = (unsigned long) addr;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200171 register unsigned long _rc asm("1") = 0;
172
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200173 asm volatile(
174 " diag %0,%2,0x308\n"
175 "0:\n"
176 EX_TABLE(0b,0b)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200177 : "+d" (_addr), "+d" (_rc)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200178 : "d" (subcode) : "cc", "memory");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200179 return _rc;
180}
Michael Holzheu411ed322007-04-27 16:01:49 +0200181EXPORT_SYMBOL_GPL(diag308);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200182
183/* SYSFS */
184
185#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400186static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200188 char *page) \
189{ \
190 return sprintf(page, _format, _value); \
191} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400192static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200193 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
194
195#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400196static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200198 char *page) \
199{ \
200 return sprintf(page, _fmt_out, \
201 (unsigned long long) _value); \
202} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400203static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
204 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200205 const char *buf, size_t len) \
206{ \
207 unsigned long long value; \
208 if (sscanf(buf, _fmt_in, &value) != 1) \
209 return -EINVAL; \
210 _value = value; \
211 return len; \
212} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400213static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200214 __ATTR(_name,(S_IRUGO | S_IWUSR), \
215 sys_##_prefix##_##_name##_show, \
216 sys_##_prefix##_##_name##_store);
217
Hongjie Yangfe355b72007-02-05 21:18:24 +0100218#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400219static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100221 char *page) \
222{ \
223 return sprintf(page, _fmt_out, _value); \
224} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400225static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
226 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100227 const char *buf, size_t len) \
228{ \
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100229 strncpy(_value, buf, sizeof(_value) - 1); \
Heiko Carstens1d802e22009-12-18 17:43:27 +0100230 strim(_value); \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100231 return len; \
232} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400233static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100234 __ATTR(_name,(S_IRUGO | S_IWUSR), \
235 sys_##_prefix##_##_name##_show, \
236 sys_##_prefix##_##_name##_store);
237
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200238static void make_attrs_ro(struct attribute **attrs)
239{
240 while (*attrs) {
241 (*attrs)->mode = S_IRUGO;
242 attrs++;
243 }
244}
245
246/*
247 * ipl section
248 */
249
Michael Holzheu411ed322007-04-27 16:01:49 +0200250static __init enum ipl_type get_ipl_type(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200251{
252 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
253
Hongjie Yangfe355b72007-02-05 21:18:24 +0100254 if (ipl_flags & IPL_NSS_VALID)
255 return IPL_TYPE_NSS;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200256 if (!(ipl_flags & IPL_DEVNO_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200257 return IPL_TYPE_UNKNOWN;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200258 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200259 return IPL_TYPE_CCW;
260 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
261 return IPL_TYPE_UNKNOWN;
262 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
263 return IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200264 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
265 return IPL_TYPE_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200266 return IPL_TYPE_FCP;
267}
268
Michael Holzheu411ed322007-04-27 16:01:49 +0200269struct ipl_info ipl_info;
270EXPORT_SYMBOL_GPL(ipl_info);
271
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400272static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
273 char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200274{
Michael Holzheu411ed322007-04-27 16:01:49 +0200275 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200276}
277
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400278static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200279
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200280/* VM IPL PARM routines */
Martin Schwidefskyc4736d92011-10-30 15:17:11 +0100281static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
282 const struct ipl_parameter_block *ipb)
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200283{
284 int i;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200285 size_t len;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200286 char has_lowercase = 0;
287
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200288 len = 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200289 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
290 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
291
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200292 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200293 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
294 /* If at least one character is lowercase, we assume mixed
295 * case; otherwise we convert everything to lowercase.
296 */
297 for (i = 0; i < len; i++)
298 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
299 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
300 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
301 has_lowercase = 1;
302 break;
303 }
304 if (!has_lowercase)
305 EBC_TOLOWER(dest, len);
306 EBCASC(dest, len);
307 }
308 dest[len] = 0;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200309
310 return len;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200311}
312
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200313size_t append_ipl_vmparm(char *dest, size_t size)
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200314{
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200315 size_t rc;
316
317 rc = 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200318 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200319 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200320 else
321 dest[0] = 0;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200322 return rc;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200323}
324
325static ssize_t ipl_vm_parm_show(struct kobject *kobj,
326 struct kobj_attribute *attr, char *page)
327{
328 char parm[DIAG308_VMPARM_SIZE + 1] = {};
329
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200330 append_ipl_vmparm(parm, sizeof(parm));
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200331 return sprintf(page, "%s\n", parm);
332}
333
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200334static size_t scpdata_length(const char* buf, size_t count)
335{
336 while (count) {
337 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
338 break;
339 count--;
340 }
341 return count;
342}
343
Martin Schwidefskyc4736d92011-10-30 15:17:11 +0100344static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
345 const struct ipl_parameter_block *ipb)
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200346{
347 size_t count;
348 size_t i;
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200349 int has_lowercase;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200350
351 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
352 ipb->ipl_info.fcp.scp_data_len));
353 if (!count)
354 goto out;
355
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200356 has_lowercase = 0;
357 for (i = 0; i < count; i++) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200358 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
359 count = 0;
360 goto out;
361 }
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200362 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
363 has_lowercase = 1;
364 }
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200365
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200366 if (has_lowercase)
367 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
368 else
369 for (i = 0; i < count; i++)
370 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200371out:
372 dest[count] = '\0';
373 return count;
374}
375
376size_t append_ipl_scpdata(char *dest, size_t len)
377{
378 size_t rc;
379
380 rc = 0;
381 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
382 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
383 else
384 dest[0] = 0;
385 return rc;
386}
387
388
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200389static struct kobj_attribute sys_ipl_vm_parm_attr =
390 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
391
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400392static ssize_t sys_ipl_device_show(struct kobject *kobj,
393 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200394{
395 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
396
Michael Holzheu411ed322007-04-27 16:01:49 +0200397 switch (ipl_info.type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200398 case IPL_TYPE_CCW:
399 return sprintf(page, "0.0.%04x\n", ipl_devno);
400 case IPL_TYPE_FCP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200401 case IPL_TYPE_FCP_DUMP:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200402 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
403 default:
404 return 0;
405 }
406}
407
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400408static struct kobj_attribute sys_ipl_device_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200409 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
410
Chris Wright2c3c8be2010-05-12 18:28:57 -0700411static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
412 struct bin_attribute *attr, char *buf,
413 loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200414{
Akinobu Mita0788fea2008-07-14 09:59:17 +0200415 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
416 IPL_PARMBLOCK_SIZE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200417}
418
419static struct bin_attribute ipl_parameter_attr = {
420 .attr = {
421 .name = "binary_parameter",
422 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200423 },
424 .size = PAGE_SIZE,
425 .read = &ipl_parameter_read,
426};
427
Chris Wright2c3c8be2010-05-12 18:28:57 -0700428static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
429 struct bin_attribute *attr, char *buf,
430 loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200431{
432 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
433 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
434
Akinobu Mita0788fea2008-07-14 09:59:17 +0200435 return memory_read_from_buffer(buf, count, &off, scp_data, size);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200436}
437
438static struct bin_attribute ipl_scp_data_attr = {
439 .attr = {
440 .name = "scp_data",
441 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200442 },
443 .size = PAGE_SIZE,
Al Viro05bd7112007-07-15 21:01:22 +0100444 .read = ipl_scp_data_read,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200445};
446
447/* FCP ipl device attributes */
448
449DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
451DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
452 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
453DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
455DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
456 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
457
458static struct attribute *ipl_fcp_attrs[] = {
459 &sys_ipl_type_attr.attr,
460 &sys_ipl_device_attr.attr,
461 &sys_ipl_fcp_wwpn_attr.attr,
462 &sys_ipl_fcp_lun_attr.attr,
463 &sys_ipl_fcp_bootprog_attr.attr,
464 &sys_ipl_fcp_br_lba_attr.attr,
465 NULL,
466};
467
468static struct attribute_group ipl_fcp_attr_group = {
469 .attrs = ipl_fcp_attrs,
470};
471
472/* CCW ipl device attributes */
473
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400474static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
475 struct kobj_attribute *attr, char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100476{
477 char loadparm[LOADPARM_LEN + 1] = {};
478
Heiko Carstens05dd2532007-07-10 11:24:09 +0200479 if (!sclp_ipl_info.is_valid)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100480 return sprintf(page, "#unknown#\n");
Heiko Carstens05dd2532007-07-10 11:24:09 +0200481 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100482 EBCASC(loadparm, LOADPARM_LEN);
Heiko Carstens1d802e22009-12-18 17:43:27 +0100483 strim(loadparm);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100484 return sprintf(page, "%s\n", loadparm);
485}
486
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400487static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
Michael Holzheu03a4d202006-12-04 15:39:58 +0100488 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
489
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200490static struct attribute *ipl_ccw_attrs_vm[] = {
491 &sys_ipl_type_attr.attr,
492 &sys_ipl_device_attr.attr,
493 &sys_ipl_ccw_loadparm_attr.attr,
494 &sys_ipl_vm_parm_attr.attr,
495 NULL,
496};
497
498static struct attribute *ipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200499 &sys_ipl_type_attr.attr,
500 &sys_ipl_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100501 &sys_ipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200502 NULL,
503};
504
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200505static struct attribute_group ipl_ccw_attr_group_vm = {
506 .attrs = ipl_ccw_attrs_vm,
507};
508
509static struct attribute_group ipl_ccw_attr_group_lpar = {
510 .attrs = ipl_ccw_attrs_lpar
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200511};
512
Hongjie Yangfe355b72007-02-05 21:18:24 +0100513/* NSS ipl device attributes */
514
515DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
516
517static struct attribute *ipl_nss_attrs[] = {
518 &sys_ipl_type_attr.attr,
519 &sys_ipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200520 &sys_ipl_ccw_loadparm_attr.attr,
521 &sys_ipl_vm_parm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100522 NULL,
523};
524
525static struct attribute_group ipl_nss_attr_group = {
526 .attrs = ipl_nss_attrs,
527};
528
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200529/* UNKNOWN ipl device attributes */
530
531static struct attribute *ipl_unknown_attrs[] = {
532 &sys_ipl_type_attr.attr,
533 NULL,
534};
535
536static struct attribute_group ipl_unknown_attr_group = {
537 .attrs = ipl_unknown_attrs,
538};
539
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -0400540static struct kset *ipl_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200541
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100542static int __init ipl_register_fcp_files(void)
543{
544 int rc;
545
546 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
547 if (rc)
548 goto out;
549 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
550 if (rc)
551 goto out_ipl_parm;
552 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
553 if (!rc)
554 goto out;
555
556 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
557
558out_ipl_parm:
559 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
560out:
561 return rc;
562}
563
Heiko Carstens2c2df112010-02-26 22:37:34 +0100564static void __ipl_run(void *unused)
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100565{
566 diag308(DIAG308_IPL, NULL);
567 if (MACHINE_IS_VM)
568 __cpcmd("IPL", NULL, 0, NULL);
569 else if (ipl_info.type == IPL_TYPE_CCW)
570 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
571}
572
Heiko Carstens2c2df112010-02-26 22:37:34 +0100573static void ipl_run(struct shutdown_trigger *trigger)
574{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400575 smp_call_ipl_cpu(__ipl_run, NULL);
Heiko Carstens2c2df112010-02-26 22:37:34 +0100576}
577
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100578static int __init ipl_init(void)
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100579{
580 int rc;
581
582 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
583 if (!ipl_kset) {
584 rc = -ENOMEM;
585 goto out;
586 }
587 switch (ipl_info.type) {
588 case IPL_TYPE_CCW:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200589 if (MACHINE_IS_VM)
590 rc = sysfs_create_group(&ipl_kset->kobj,
591 &ipl_ccw_attr_group_vm);
592 else
593 rc = sysfs_create_group(&ipl_kset->kobj,
594 &ipl_ccw_attr_group_lpar);
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100595 break;
596 case IPL_TYPE_FCP:
597 case IPL_TYPE_FCP_DUMP:
598 rc = ipl_register_fcp_files();
599 break;
600 case IPL_TYPE_NSS:
601 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
602 break;
603 default:
604 rc = sysfs_create_group(&ipl_kset->kobj,
605 &ipl_unknown_attr_group);
606 break;
607 }
608out:
609 if (rc)
610 panic("ipl_init failed: rc = %i\n", rc);
611
612 return 0;
613}
614
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100615static struct shutdown_action __refdata ipl_action = {
616 .name = SHUTDOWN_ACTION_IPL_STR,
617 .fn = ipl_run,
618 .init = ipl_init,
619};
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100620
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200621/*
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100622 * reipl shutdown action: Reboot Linux on shutdown.
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200623 */
624
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200625/* VM IPL PARM attributes */
626static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
627 char *page)
628{
629 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
630
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200631 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200632 return sprintf(page, "%s\n", vmparm);
633}
634
635static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
636 size_t vmparm_max,
637 const char *buf, size_t len)
638{
639 int i, ip_len;
640
641 /* ignore trailing newline */
642 ip_len = len;
643 if ((len > 0) && (buf[len - 1] == '\n'))
644 ip_len--;
645
646 if (ip_len > vmparm_max)
647 return -EINVAL;
648
649 /* parm is used to store kernel options, check for common chars */
650 for (i = 0; i < ip_len; i++)
651 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
652 return -EINVAL;
653
654 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
655 ipb->ipl_info.ccw.vm_parm_len = ip_len;
656 if (ip_len > 0) {
657 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
658 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
659 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
660 } else {
661 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
662 }
663
664 return len;
665}
666
667/* NSS wrapper */
668static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
669 struct kobj_attribute *attr, char *page)
670{
671 return reipl_generic_vmparm_show(reipl_block_nss, page);
672}
673
674static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
675 struct kobj_attribute *attr,
676 const char *buf, size_t len)
677{
678 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
679}
680
681/* CCW wrapper */
682static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
683 struct kobj_attribute *attr, char *page)
684{
685 return reipl_generic_vmparm_show(reipl_block_ccw, page);
686}
687
688static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
689 struct kobj_attribute *attr,
690 const char *buf, size_t len)
691{
692 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
693}
694
695static struct kobj_attribute sys_reipl_nss_vmparm_attr =
696 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
697 reipl_nss_vmparm_store);
698static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
699 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
700 reipl_ccw_vmparm_store);
701
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200702/* FCP reipl device attributes */
703
Chris Wright2c3c8be2010-05-12 18:28:57 -0700704static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200705 struct bin_attribute *attr,
706 char *buf, loff_t off, size_t count)
707{
708 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
709 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
710
711 return memory_read_from_buffer(buf, count, &off, scp_data, size);
712}
713
Chris Wright2c3c8be2010-05-12 18:28:57 -0700714static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200715 struct bin_attribute *attr,
716 char *buf, loff_t off, size_t count)
717{
718 size_t padding;
719 size_t scpdata_len;
720
721 if (off < 0)
722 return -EINVAL;
723
724 if (off >= DIAG308_SCPDATA_SIZE)
725 return -ENOSPC;
726
727 if (count > DIAG308_SCPDATA_SIZE - off)
728 count = DIAG308_SCPDATA_SIZE - off;
729
730 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
731 scpdata_len = off + count;
732
733 if (scpdata_len % 8) {
734 padding = 8 - (scpdata_len % 8);
735 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
736 0, padding);
737 scpdata_len += padding;
738 }
739
740 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
741 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
742 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
743
744 return count;
745}
746
747static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
748 .attr = {
749 .name = "scp_data",
750 .mode = S_IRUGO | S_IWUSR,
751 },
752 .size = PAGE_SIZE,
753 .read = reipl_fcp_scpdata_read,
754 .write = reipl_fcp_scpdata_write,
755};
756
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200757DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
758 reipl_block_fcp->ipl_info.fcp.wwpn);
759DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
760 reipl_block_fcp->ipl_info.fcp.lun);
761DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
762 reipl_block_fcp->ipl_info.fcp.bootprog);
763DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
764 reipl_block_fcp->ipl_info.fcp.br_lba);
765DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
766 reipl_block_fcp->ipl_info.fcp.devno);
767
768static struct attribute *reipl_fcp_attrs[] = {
769 &sys_reipl_fcp_device_attr.attr,
770 &sys_reipl_fcp_wwpn_attr.attr,
771 &sys_reipl_fcp_lun_attr.attr,
772 &sys_reipl_fcp_bootprog_attr.attr,
773 &sys_reipl_fcp_br_lba_attr.attr,
774 NULL,
775};
776
777static struct attribute_group reipl_fcp_attr_group = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200778 .attrs = reipl_fcp_attrs,
779};
780
781/* CCW reipl device attributes */
782
783DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
784 reipl_block_ccw->ipl_info.ccw.devno);
785
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200786static void reipl_get_ascii_loadparm(char *loadparm,
787 struct ipl_parameter_block *ibp)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100788{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200789 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100790 EBCASC(loadparm, LOADPARM_LEN);
791 loadparm[LOADPARM_LEN] = 0;
Heiko Carstens1d802e22009-12-18 17:43:27 +0100792 strim(loadparm);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100793}
794
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200795static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
796 char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100797{
798 char buf[LOADPARM_LEN + 1];
799
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200800 reipl_get_ascii_loadparm(buf, ipb);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100801 return sprintf(page, "%s\n", buf);
802}
803
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200804static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
805 const char *buf, size_t len)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100806{
807 int i, lp_len;
808
809 /* ignore trailing newline */
810 lp_len = len;
811 if ((len > 0) && (buf[len - 1] == '\n'))
812 lp_len--;
813 /* loadparm can have max 8 characters and must not start with a blank */
814 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
815 return -EINVAL;
816 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
817 for (i = 0; i < lp_len; i++) {
818 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
819 (buf[i] == '.'))
820 continue;
821 return -EINVAL;
822 }
823 /* initialize loadparm with blanks */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200824 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100825 /* copy and convert to ebcdic */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200826 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
827 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100828 return len;
829}
830
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200831/* NSS wrapper */
832static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
833 struct kobj_attribute *attr, char *page)
834{
835 return reipl_generic_loadparm_show(reipl_block_nss, page);
836}
Michael Holzheu03a4d202006-12-04 15:39:58 +0100837
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200838static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
839 struct kobj_attribute *attr,
840 const char *buf, size_t len)
841{
842 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
843}
844
845/* CCW wrapper */
846static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
847 struct kobj_attribute *attr, char *page)
848{
849 return reipl_generic_loadparm_show(reipl_block_ccw, page);
850}
851
852static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
853 struct kobj_attribute *attr,
854 const char *buf, size_t len)
855{
856 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
857}
858
859static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
860 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
861 reipl_ccw_loadparm_store);
862
863static struct attribute *reipl_ccw_attrs_vm[] = {
864 &sys_reipl_ccw_device_attr.attr,
865 &sys_reipl_ccw_loadparm_attr.attr,
866 &sys_reipl_ccw_vmparm_attr.attr,
867 NULL,
868};
869
870static struct attribute *reipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200871 &sys_reipl_ccw_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100872 &sys_reipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200873 NULL,
874};
875
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200876static struct attribute_group reipl_ccw_attr_group_vm = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200877 .name = IPL_CCW_STR,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200878 .attrs = reipl_ccw_attrs_vm,
879};
880
881static struct attribute_group reipl_ccw_attr_group_lpar = {
882 .name = IPL_CCW_STR,
883 .attrs = reipl_ccw_attrs_lpar,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200884};
885
Hongjie Yangfe355b72007-02-05 21:18:24 +0100886
887/* NSS reipl device attributes */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200888static void reipl_get_ascii_nss_name(char *dst,
889 struct ipl_parameter_block *ipb)
890{
891 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
892 EBCASC(dst, NSS_NAME_SIZE);
893 dst[NSS_NAME_SIZE] = 0;
894}
Hongjie Yangfe355b72007-02-05 21:18:24 +0100895
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200896static ssize_t reipl_nss_name_show(struct kobject *kobj,
897 struct kobj_attribute *attr, char *page)
898{
899 char nss_name[NSS_NAME_SIZE + 1] = {};
900
901 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
902 return sprintf(page, "%s\n", nss_name);
903}
904
905static ssize_t reipl_nss_name_store(struct kobject *kobj,
906 struct kobj_attribute *attr,
907 const char *buf, size_t len)
908{
909 int nss_len;
910
911 /* ignore trailing newline */
912 nss_len = len;
913 if ((len > 0) && (buf[len - 1] == '\n'))
914 nss_len--;
915
916 if (nss_len > NSS_NAME_SIZE)
917 return -EINVAL;
918
919 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
920 if (nss_len > 0) {
921 reipl_block_nss->ipl_info.ccw.vm_flags |=
922 DIAG308_VM_FLAGS_NSS_VALID;
923 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
924 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
925 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
926 } else {
927 reipl_block_nss->ipl_info.ccw.vm_flags &=
928 ~DIAG308_VM_FLAGS_NSS_VALID;
929 }
930
931 return len;
932}
933
934static struct kobj_attribute sys_reipl_nss_name_attr =
935 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
936 reipl_nss_name_store);
937
938static struct kobj_attribute sys_reipl_nss_loadparm_attr =
939 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
940 reipl_nss_loadparm_store);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100941
942static struct attribute *reipl_nss_attrs[] = {
943 &sys_reipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200944 &sys_reipl_nss_loadparm_attr.attr,
945 &sys_reipl_nss_vmparm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100946 NULL,
947};
948
949static struct attribute_group reipl_nss_attr_group = {
950 .name = IPL_NSS_STR,
951 .attrs = reipl_nss_attrs,
952};
953
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200954/* reipl type */
955
956static int reipl_set_type(enum ipl_type type)
957{
958 if (!(reipl_capabilities & type))
959 return -EINVAL;
960
961 switch(type) {
962 case IPL_TYPE_CCW:
Michael Holzheu48657d22008-01-26 14:11:17 +0100963 if (diag308_set_works)
964 reipl_method = REIPL_METHOD_CCW_DIAG;
965 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200966 reipl_method = REIPL_METHOD_CCW_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200967 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200968 reipl_method = REIPL_METHOD_CCW_CIO;
Frank Munzert099b7652009-03-26 15:23:43 +0100969 reipl_block_actual = reipl_block_ccw;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200970 break;
971 case IPL_TYPE_FCP:
972 if (diag308_set_works)
Michael Holzheu411ed322007-04-27 16:01:49 +0200973 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200974 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200975 reipl_method = REIPL_METHOD_FCP_RO_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200976 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200977 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
Frank Munzert099b7652009-03-26 15:23:43 +0100978 reipl_block_actual = reipl_block_fcp;
Michael Holzheu411ed322007-04-27 16:01:49 +0200979 break;
980 case IPL_TYPE_FCP_DUMP:
981 reipl_method = REIPL_METHOD_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200982 break;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100983 case IPL_TYPE_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200984 if (diag308_set_works)
985 reipl_method = REIPL_METHOD_NSS_DIAG;
986 else
987 reipl_method = REIPL_METHOD_NSS;
Frank Munzert099b7652009-03-26 15:23:43 +0100988 reipl_block_actual = reipl_block_nss;
Michael Holzheu411ed322007-04-27 16:01:49 +0200989 break;
990 case IPL_TYPE_UNKNOWN:
991 reipl_method = REIPL_METHOD_DEFAULT;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100992 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200993 default:
Michael Holzheu411ed322007-04-27 16:01:49 +0200994 BUG();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200995 }
996 reipl_type = type;
997 return 0;
998}
999
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001000static ssize_t reipl_type_show(struct kobject *kobj,
1001 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001002{
1003 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1004}
1005
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001006static ssize_t reipl_type_store(struct kobject *kobj,
1007 struct kobj_attribute *attr,
1008 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001009{
1010 int rc = -EINVAL;
1011
1012 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1013 rc = reipl_set_type(IPL_TYPE_CCW);
1014 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1015 rc = reipl_set_type(IPL_TYPE_FCP);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001016 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1017 rc = reipl_set_type(IPL_TYPE_NSS);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001018 return (rc != 0) ? rc : len;
1019}
1020
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001021static struct kobj_attribute reipl_type_attr =
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001022 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001023
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001024static struct kset *reipl_kset;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001025static struct kset *reipl_fcp_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001026
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001027static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1028 const enum ipl_method m)
1029{
1030 char loadparm[LOADPARM_LEN + 1] = {};
1031 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1032 char nss_name[NSS_NAME_SIZE + 1] = {};
1033 size_t pos = 0;
1034
1035 reipl_get_ascii_loadparm(loadparm, ipb);
1036 reipl_get_ascii_nss_name(nss_name, ipb);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001037 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001038
1039 switch (m) {
1040 case REIPL_METHOD_CCW_VM:
1041 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1042 break;
1043 case REIPL_METHOD_NSS:
1044 pos = sprintf(dst, "IPL %s", nss_name);
1045 break;
1046 default:
1047 break;
1048 }
1049 if (strlen(loadparm) > 0)
1050 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1051 if (strlen(vmparm) > 0)
1052 sprintf(dst + pos, " PARM %s", vmparm);
1053}
1054
Heiko Carstens2c2df112010-02-26 22:37:34 +01001055static void __reipl_run(void *unused)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001056{
1057 struct ccw_dev_id devid;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001058 static char buf[128];
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001059
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001060 switch (reipl_method) {
Michael Holzheu411ed322007-04-27 16:01:49 +02001061 case REIPL_METHOD_CCW_CIO:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001062 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1063 devid.ssid = 0;
1064 reipl_ccw_dev(&devid);
1065 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001066 case REIPL_METHOD_CCW_VM:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001067 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
Heiko Carstens740b5702006-12-04 15:40:30 +01001068 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001069 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001070 case REIPL_METHOD_CCW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001071 diag308(DIAG308_SET, reipl_block_ccw);
1072 diag308(DIAG308_IPL, NULL);
1073 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001074 case REIPL_METHOD_FCP_RW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001075 diag308(DIAG308_SET, reipl_block_fcp);
1076 diag308(DIAG308_IPL, NULL);
1077 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001078 case REIPL_METHOD_FCP_RO_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001079 diag308(DIAG308_IPL, NULL);
1080 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001081 case REIPL_METHOD_FCP_RO_VM:
Heiko Carstens740b5702006-12-04 15:40:30 +01001082 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001083 break;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001084 case REIPL_METHOD_NSS_DIAG:
1085 diag308(DIAG308_SET, reipl_block_nss);
1086 diag308(DIAG308_IPL, NULL);
1087 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001088 case REIPL_METHOD_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001089 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001090 __cpcmd(buf, NULL, 0, NULL);
1091 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001092 case REIPL_METHOD_DEFAULT:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001093 if (MACHINE_IS_VM)
Heiko Carstens740b5702006-12-04 15:40:30 +01001094 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001095 diag308(DIAG308_IPL, NULL);
1096 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001097 case REIPL_METHOD_FCP_DUMP:
Michael Holzheu411ed322007-04-27 16:01:49 +02001098 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001099 }
Michael Holzheu208e5592008-03-05 12:37:15 +01001100 disabled_wait((unsigned long) __builtin_return_address(0));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001101}
1102
Heiko Carstens2c2df112010-02-26 22:37:34 +01001103static void reipl_run(struct shutdown_trigger *trigger)
1104{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001105 smp_call_ipl_cpu(__reipl_run, NULL);
Heiko Carstens2c2df112010-02-26 22:37:34 +01001106}
1107
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001108static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001109{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001110 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1111 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1112 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1113 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1114}
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001115
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001116static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1117{
1118 /* LOADPARM */
1119 /* check if read scp info worked and set loadparm */
1120 if (sclp_ipl_info.is_valid)
1121 memcpy(ipb->ipl_info.ccw.load_parm,
1122 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1123 else
1124 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1125 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1126 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1127
1128 /* VM PARM */
1129 if (MACHINE_IS_VM && diag308_set_works &&
1130 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1131
1132 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1133 ipb->ipl_info.ccw.vm_parm_len =
1134 ipl_block.ipl_info.ccw.vm_parm_len;
1135 memcpy(ipb->ipl_info.ccw.vm_parm,
1136 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1137 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001138}
1139
Hongjie Yangfe355b72007-02-05 21:18:24 +01001140static int __init reipl_nss_init(void)
1141{
1142 int rc;
1143
1144 if (!MACHINE_IS_VM)
1145 return 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001146
1147 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1148 if (!reipl_block_nss)
1149 return -ENOMEM;
1150
1151 if (!diag308_set_works)
1152 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1153
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001154 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001155 if (rc)
1156 return rc;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001157
1158 reipl_block_ccw_init(reipl_block_nss);
1159 if (ipl_info.type == IPL_TYPE_NSS) {
1160 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1161 ' ', NSS_NAME_SIZE);
1162 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1163 kernel_nss_name, strlen(kernel_nss_name));
1164 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1165 reipl_block_nss->ipl_info.ccw.vm_flags |=
1166 DIAG308_VM_FLAGS_NSS_VALID;
1167
1168 reipl_block_ccw_fill_parms(reipl_block_nss);
1169 }
1170
Hongjie Yangfe355b72007-02-05 21:18:24 +01001171 reipl_capabilities |= IPL_TYPE_NSS;
1172 return 0;
1173}
1174
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001175static int __init reipl_ccw_init(void)
1176{
1177 int rc;
1178
1179 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1180 if (!reipl_block_ccw)
1181 return -ENOMEM;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001182
1183 if (MACHINE_IS_VM) {
1184 if (!diag308_set_works)
1185 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1186 rc = sysfs_create_group(&reipl_kset->kobj,
1187 &reipl_ccw_attr_group_vm);
1188 } else {
1189 if(!diag308_set_works)
1190 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1191 rc = sysfs_create_group(&reipl_kset->kobj,
1192 &reipl_ccw_attr_group_lpar);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001193 }
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001194 if (rc)
1195 return rc;
1196
1197 reipl_block_ccw_init(reipl_block_ccw);
1198 if (ipl_info.type == IPL_TYPE_CCW) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001199 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001200 reipl_block_ccw_fill_parms(reipl_block_ccw);
1201 }
1202
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001203 reipl_capabilities |= IPL_TYPE_CCW;
1204 return 0;
1205}
1206
1207static int __init reipl_fcp_init(void)
1208{
1209 int rc;
1210
Michael Holzheu008d2d12009-03-26 15:24:51 +01001211 if (!diag308_set_works) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001212 if (ipl_info.type == IPL_TYPE_FCP) {
Michael Holzheu008d2d12009-03-26 15:24:51 +01001213 make_attrs_ro(reipl_fcp_attrs);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001214 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1215 } else
Michael Holzheu008d2d12009-03-26 15:24:51 +01001216 return 0;
1217 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001218
1219 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1220 if (!reipl_block_fcp)
1221 return -ENOMEM;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001222
1223 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1224 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1225 &reipl_kset->kobj);
Julia Lawall798620f2011-08-24 17:15:11 +02001226 if (!reipl_fcp_kset) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001227 free_page((unsigned long) reipl_block_fcp);
1228 return -ENOMEM;
1229 }
1230
1231 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001232 if (rc) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001233 kset_unregister(reipl_fcp_kset);
1234 free_page((unsigned long) reipl_block_fcp);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001235 return rc;
1236 }
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001237
1238 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1239 &sys_reipl_fcp_scp_data_attr);
1240 if (rc) {
1241 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1242 kset_unregister(reipl_fcp_kset);
1243 free_page((unsigned long) reipl_block_fcp);
1244 return rc;
1245 }
1246
1247 if (ipl_info.type == IPL_TYPE_FCP)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001248 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001249 else {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001250 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1251 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001252 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001253 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1254 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1255 }
1256 reipl_capabilities |= IPL_TYPE_FCP;
1257 return 0;
1258}
1259
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001260static int __init reipl_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001261{
1262 int rc;
1263
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001264 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001265 if (!reipl_kset)
1266 return -ENOMEM;
1267 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001268 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001269 kset_unregister(reipl_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001270 return rc;
1271 }
1272 rc = reipl_ccw_init();
1273 if (rc)
1274 return rc;
1275 rc = reipl_fcp_init();
1276 if (rc)
1277 return rc;
Hongjie Yangfe355b72007-02-05 21:18:24 +01001278 rc = reipl_nss_init();
1279 if (rc)
1280 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001281 rc = reipl_set_type(ipl_info.type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001282 if (rc)
1283 return rc;
1284 return 0;
1285}
1286
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001287static struct shutdown_action __refdata reipl_action = {
1288 .name = SHUTDOWN_ACTION_REIPL_STR,
1289 .fn = reipl_run,
1290 .init = reipl_init,
1291};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001292
1293/*
1294 * dump shutdown action: Dump Linux on shutdown.
1295 */
1296
1297/* FCP dump device attributes */
1298
1299DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1300 dump_block_fcp->ipl_info.fcp.wwpn);
1301DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1302 dump_block_fcp->ipl_info.fcp.lun);
1303DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1304 dump_block_fcp->ipl_info.fcp.bootprog);
1305DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1306 dump_block_fcp->ipl_info.fcp.br_lba);
1307DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1308 dump_block_fcp->ipl_info.fcp.devno);
1309
1310static struct attribute *dump_fcp_attrs[] = {
1311 &sys_dump_fcp_device_attr.attr,
1312 &sys_dump_fcp_wwpn_attr.attr,
1313 &sys_dump_fcp_lun_attr.attr,
1314 &sys_dump_fcp_bootprog_attr.attr,
1315 &sys_dump_fcp_br_lba_attr.attr,
1316 NULL,
1317};
1318
1319static struct attribute_group dump_fcp_attr_group = {
1320 .name = IPL_FCP_STR,
1321 .attrs = dump_fcp_attrs,
1322};
1323
1324/* CCW dump device attributes */
1325
1326DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1327 dump_block_ccw->ipl_info.ccw.devno);
1328
1329static struct attribute *dump_ccw_attrs[] = {
1330 &sys_dump_ccw_device_attr.attr,
1331 NULL,
1332};
1333
1334static struct attribute_group dump_ccw_attr_group = {
1335 .name = IPL_CCW_STR,
1336 .attrs = dump_ccw_attrs,
1337};
1338
1339/* dump type */
1340
1341static 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:
Michael Holzheu48657d22008-01-26 14:11:17 +01001347 if (diag308_set_works)
1348 dump_method = DUMP_METHOD_CCW_DIAG;
1349 else if (MACHINE_IS_VM)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001350 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
1364static 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
1370static 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
1385static struct kobj_attribute dump_type_attr =
1386 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1387
1388static struct kset *dump_kset;
1389
Heiko Carstens2c2df112010-02-26 22:37:34 +01001390static void __dump_run(void *unused)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001391{
1392 struct ccw_dev_id devid;
1393 static char buf[100];
1394
1395 switch (dump_method) {
1396 case DUMP_METHOD_CCW_CIO:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001397 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1398 devid.ssid = 0;
1399 reipl_ccw_dev(&devid);
1400 break;
1401 case DUMP_METHOD_CCW_VM:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001402 sprintf(buf, "STORE STATUS");
1403 __cpcmd(buf, NULL, 0, NULL);
1404 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1405 __cpcmd(buf, NULL, 0, NULL);
1406 break;
1407 case DUMP_METHOD_CCW_DIAG:
1408 diag308(DIAG308_SET, dump_block_ccw);
1409 diag308(DIAG308_DUMP, NULL);
1410 break;
1411 case DUMP_METHOD_FCP_DIAG:
1412 diag308(DIAG308_SET, dump_block_fcp);
1413 diag308(DIAG308_DUMP, NULL);
1414 break;
Heiko Carstens2c2df112010-02-26 22:37:34 +01001415 default:
1416 break;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001417 }
Heiko Carstens2c2df112010-02-26 22:37:34 +01001418}
1419
1420static void dump_run(struct shutdown_trigger *trigger)
1421{
1422 if (dump_method == DUMP_METHOD_NONE)
1423 return;
1424 smp_send_stop();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001425 smp_call_ipl_cpu(__dump_run, NULL);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001426}
1427
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001428static int __init dump_ccw_init(void)
1429{
1430 int rc;
1431
1432 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1433 if (!dump_block_ccw)
1434 return -ENOMEM;
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001435 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001436 if (rc) {
1437 free_page((unsigned long)dump_block_ccw);
1438 return rc;
1439 }
1440 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1441 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001442 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001443 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
Michael Holzheu411ed322007-04-27 16:01:49 +02001444 dump_capabilities |= DUMP_TYPE_CCW;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001445 return 0;
1446}
1447
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001448static int __init dump_fcp_init(void)
1449{
1450 int rc;
1451
Heiko Carstens05dd2532007-07-10 11:24:09 +02001452 if (!sclp_ipl_info.has_dump)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001453 return 0; /* LDIPL DUMP is not installed */
1454 if (!diag308_set_works)
1455 return 0;
1456 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1457 if (!dump_block_fcp)
1458 return -ENOMEM;
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001459 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001460 if (rc) {
1461 free_page((unsigned long)dump_block_fcp);
1462 return rc;
1463 }
1464 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1465 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001466 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001467 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1468 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
Michael Holzheu411ed322007-04-27 16:01:49 +02001469 dump_capabilities |= DUMP_TYPE_FCP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001470 return 0;
1471}
1472
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001473static int __init dump_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001474{
1475 int rc;
1476
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001477 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001478 if (!dump_kset)
1479 return -ENOMEM;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001480 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001481 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001482 kset_unregister(dump_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001483 return rc;
1484 }
1485 rc = dump_ccw_init();
1486 if (rc)
1487 return rc;
1488 rc = dump_fcp_init();
1489 if (rc)
1490 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001491 dump_set_type(DUMP_TYPE_NONE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001492 return 0;
1493}
1494
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001495static struct shutdown_action __refdata dump_action = {
1496 .name = SHUTDOWN_ACTION_DUMP_STR,
1497 .fn = dump_run,
1498 .init = dump_init,
1499};
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001500
Frank Munzert099b7652009-03-26 15:23:43 +01001501static void dump_reipl_run(struct shutdown_trigger *trigger)
1502{
Michael Holzheub43445f2012-03-11 11:59:28 -04001503 u32 csum;
1504
1505 csum = csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1506 copy_to_absolute_zero(&S390_lowcore.ipib_checksum, &csum, sizeof(csum));
1507 copy_to_absolute_zero(&S390_lowcore.ipib, &reipl_block_actual,
1508 sizeof(reipl_block_actual));
Frank Munzert099b7652009-03-26 15:23:43 +01001509 dump_run(trigger);
1510}
1511
1512static int __init dump_reipl_init(void)
1513{
1514 if (!diag308_set_works)
1515 return -EOPNOTSUPP;
1516 else
1517 return 0;
1518}
1519
1520static struct shutdown_action __refdata dump_reipl_action = {
1521 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1522 .fn = dump_reipl_run,
1523 .init = dump_reipl_init,
1524};
1525
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001526/*
1527 * vmcmd shutdown action: Trigger vm command on shutdown.
1528 */
1529
1530static char vmcmd_on_reboot[128];
1531static char vmcmd_on_panic[128];
1532static char vmcmd_on_halt[128];
1533static char vmcmd_on_poff[128];
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001534static char vmcmd_on_restart[128];
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001535
1536DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1537DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1538DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1539DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001540DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001541
1542static struct attribute *vmcmd_attrs[] = {
1543 &sys_vmcmd_on_reboot_attr.attr,
1544 &sys_vmcmd_on_panic_attr.attr,
1545 &sys_vmcmd_on_halt_attr.attr,
1546 &sys_vmcmd_on_poff_attr.attr,
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001547 &sys_vmcmd_on_restart_attr.attr,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001548 NULL,
1549};
1550
1551static struct attribute_group vmcmd_attr_group = {
1552 .attrs = vmcmd_attrs,
1553};
1554
1555static struct kset *vmcmd_kset;
1556
1557static void vmcmd_run(struct shutdown_trigger *trigger)
1558{
1559 char *cmd, *next_cmd;
1560
1561 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1562 cmd = vmcmd_on_reboot;
1563 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1564 cmd = vmcmd_on_panic;
1565 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1566 cmd = vmcmd_on_halt;
1567 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1568 cmd = vmcmd_on_poff;
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001569 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1570 cmd = vmcmd_on_restart;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001571 else
1572 return;
1573
1574 if (strlen(cmd) == 0)
1575 return;
1576 do {
1577 next_cmd = strchr(cmd, '\n');
1578 if (next_cmd) {
1579 next_cmd[0] = 0;
1580 next_cmd += 1;
1581 }
1582 __cpcmd(cmd, NULL, 0, NULL);
1583 cmd = next_cmd;
1584 } while (cmd != NULL);
1585}
1586
1587static int vmcmd_init(void)
1588{
1589 if (!MACHINE_IS_VM)
Heiko Carstensb8e660b2010-02-26 22:37:41 +01001590 return -EOPNOTSUPP;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001591 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1592 if (!vmcmd_kset)
1593 return -ENOMEM;
1594 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1595}
1596
1597static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1598 vmcmd_run, vmcmd_init};
1599
1600/*
1601 * stop shutdown action: Stop Linux on shutdown.
1602 */
1603
1604static void stop_run(struct shutdown_trigger *trigger)
1605{
Michael Holzheue1202ed2011-08-24 17:15:12 +02001606 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1607 strcmp(trigger->name, ON_RESTART_STR) == 0)
Michael Holzheuc6547492008-01-26 14:11:12 +01001608 disabled_wait((unsigned long) __builtin_return_address(0));
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001609 smp_stop_cpu();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001610}
1611
1612static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1613 stop_run, NULL};
1614
1615/* action list */
1616
1617static struct shutdown_action *shutdown_actions_list[] = {
Frank Munzert099b7652009-03-26 15:23:43 +01001618 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1619 &vmcmd_action, &stop_action};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001620#define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1621
1622/*
1623 * Trigger section
1624 */
1625
1626static struct kset *shutdown_actions_kset;
1627
1628static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1629 size_t len)
1630{
1631 int i;
Frank Munzert099b7652009-03-26 15:23:43 +01001632
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001633 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
Frank Munzert099b7652009-03-26 15:23:43 +01001634 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
Frank Munzert81088812009-07-07 16:37:07 +02001635 if (shutdown_actions_list[i]->init_rc) {
1636 return shutdown_actions_list[i]->init_rc;
1637 } else {
1638 trigger->action = shutdown_actions_list[i];
1639 return len;
1640 }
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001641 }
1642 }
1643 return -EINVAL;
1644}
1645
1646/* on reipl */
1647
1648static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1649 &reipl_action};
1650
1651static ssize_t on_reboot_show(struct kobject *kobj,
1652 struct kobj_attribute *attr, char *page)
1653{
1654 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1655}
1656
1657static ssize_t on_reboot_store(struct kobject *kobj,
1658 struct kobj_attribute *attr,
1659 const char *buf, size_t len)
1660{
1661 return set_trigger(buf, &on_reboot_trigger, len);
1662}
1663
1664static struct kobj_attribute on_reboot_attr =
1665 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1666
1667static void do_machine_restart(char *__unused)
1668{
1669 smp_send_stop();
1670 on_reboot_trigger.action->fn(&on_reboot_trigger);
1671 reipl_run(NULL);
1672}
1673void (*_machine_restart)(char *command) = do_machine_restart;
1674
1675/* on panic */
1676
1677static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1678
1679static ssize_t on_panic_show(struct kobject *kobj,
1680 struct kobj_attribute *attr, char *page)
1681{
1682 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1683}
1684
1685static ssize_t on_panic_store(struct kobject *kobj,
1686 struct kobj_attribute *attr,
1687 const char *buf, size_t len)
1688{
1689 return set_trigger(buf, &on_panic_trigger, len);
1690}
1691
1692static struct kobj_attribute on_panic_attr =
1693 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1694
1695static void do_panic(void)
1696{
Michael Holzheu3ab121a2012-03-11 11:59:32 -04001697 lgr_info_log();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001698 on_panic_trigger.action->fn(&on_panic_trigger);
1699 stop_run(&on_panic_trigger);
1700}
1701
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001702/* on restart */
1703
1704static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
Michael Holzheue1202ed2011-08-24 17:15:12 +02001705 &stop_action};
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001706
1707static ssize_t on_restart_show(struct kobject *kobj,
1708 struct kobj_attribute *attr, char *page)
1709{
1710 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1711}
1712
1713static ssize_t on_restart_store(struct kobject *kobj,
1714 struct kobj_attribute *attr,
1715 const char *buf, size_t len)
1716{
1717 return set_trigger(buf, &on_restart_trigger, len);
1718}
1719
1720static struct kobj_attribute on_restart_attr =
1721 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1722
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001723static void __do_restart(void *ignore)
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001724{
1725 smp_send_stop();
Michael Holzheu60a0c682011-10-30 15:16:40 +01001726#ifdef CONFIG_CRASH_DUMP
1727 crash_kexec(NULL);
1728#endif
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001729 on_restart_trigger.action->fn(&on_restart_trigger);
1730 stop_run(&on_restart_trigger);
1731}
1732
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001733void do_restart(void)
1734{
Michael Holzheu3ab121a2012-03-11 11:59:32 -04001735 tracing_off();
1736 debug_locks_off();
1737 lgr_info_log();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001738 smp_call_online_cpu(__do_restart, NULL);
1739}
1740
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001741/* on halt */
1742
1743static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1744
1745static ssize_t on_halt_show(struct kobject *kobj,
1746 struct kobj_attribute *attr, char *page)
1747{
1748 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1749}
1750
1751static ssize_t on_halt_store(struct kobject *kobj,
1752 struct kobj_attribute *attr,
1753 const char *buf, size_t len)
1754{
1755 return set_trigger(buf, &on_halt_trigger, len);
1756}
1757
1758static struct kobj_attribute on_halt_attr =
1759 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1760
1761
1762static void do_machine_halt(void)
1763{
1764 smp_send_stop();
1765 on_halt_trigger.action->fn(&on_halt_trigger);
1766 stop_run(&on_halt_trigger);
1767}
1768void (*_machine_halt)(void) = do_machine_halt;
1769
1770/* on power off */
1771
1772static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1773
1774static ssize_t on_poff_show(struct kobject *kobj,
1775 struct kobj_attribute *attr, char *page)
1776{
1777 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1778}
1779
1780static ssize_t on_poff_store(struct kobject *kobj,
1781 struct kobj_attribute *attr,
1782 const char *buf, size_t len)
1783{
1784 return set_trigger(buf, &on_poff_trigger, len);
1785}
1786
1787static struct kobj_attribute on_poff_attr =
1788 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1789
1790
1791static void do_machine_power_off(void)
1792{
1793 smp_send_stop();
1794 on_poff_trigger.action->fn(&on_poff_trigger);
1795 stop_run(&on_poff_trigger);
1796}
1797void (*_machine_power_off)(void) = do_machine_power_off;
1798
1799static void __init shutdown_triggers_init(void)
1800{
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001801 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001802 firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001803 if (!shutdown_actions_kset)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001804 goto fail;
1805 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1806 &on_reboot_attr.attr))
1807 goto fail;
1808 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1809 &on_panic_attr.attr))
1810 goto fail;
1811 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1812 &on_halt_attr.attr))
1813 goto fail;
1814 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1815 &on_poff_attr.attr))
1816 goto fail;
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001817 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1818 &on_restart_attr.attr))
1819 goto fail;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001820 return;
1821fail:
1822 panic("shutdown_triggers_init failed\n");
1823}
1824
1825static void __init shutdown_actions_init(void)
1826{
1827 int i;
1828
1829 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1830 if (!shutdown_actions_list[i]->init)
1831 continue;
Frank Munzert81088812009-07-07 16:37:07 +02001832 shutdown_actions_list[i]->init_rc =
1833 shutdown_actions_list[i]->init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001834 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001835}
1836
1837static int __init s390_ipl_init(void)
1838{
Michael Holzheud09293a2008-01-26 14:11:15 +01001839 sclp_get_ipl_info(&sclp_ipl_info);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001840 shutdown_actions_init();
1841 shutdown_triggers_init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001842 return 0;
1843}
1844
1845__initcall(s390_ipl_init);
Heiko Carstens15e9b582006-12-04 15:40:26 +01001846
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001847static void __init strncpy_skip_quote(char *dst, char *src, int n)
1848{
1849 int sx, dx;
1850
1851 dx = 0;
1852 for (sx = 0; src[sx] != 0; sx++) {
1853 if (src[sx] == '"')
1854 continue;
1855 dst[dx++] = src[sx];
1856 if (dx >= n)
1857 break;
1858 }
1859}
1860
1861static int __init vmcmd_on_reboot_setup(char *str)
1862{
1863 if (!MACHINE_IS_VM)
1864 return 1;
1865 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1866 vmcmd_on_reboot[127] = 0;
1867 on_reboot_trigger.action = &vmcmd_action;
1868 return 1;
1869}
1870__setup("vmreboot=", vmcmd_on_reboot_setup);
1871
1872static int __init vmcmd_on_panic_setup(char *str)
1873{
1874 if (!MACHINE_IS_VM)
1875 return 1;
1876 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1877 vmcmd_on_panic[127] = 0;
1878 on_panic_trigger.action = &vmcmd_action;
1879 return 1;
1880}
1881__setup("vmpanic=", vmcmd_on_panic_setup);
1882
1883static int __init vmcmd_on_halt_setup(char *str)
1884{
1885 if (!MACHINE_IS_VM)
1886 return 1;
1887 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1888 vmcmd_on_halt[127] = 0;
1889 on_halt_trigger.action = &vmcmd_action;
1890 return 1;
1891}
1892__setup("vmhalt=", vmcmd_on_halt_setup);
1893
1894static int __init vmcmd_on_poff_setup(char *str)
1895{
1896 if (!MACHINE_IS_VM)
1897 return 1;
1898 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1899 vmcmd_on_poff[127] = 0;
1900 on_poff_trigger.action = &vmcmd_action;
1901 return 1;
1902}
1903__setup("vmpoff=", vmcmd_on_poff_setup);
1904
1905static int on_panic_notify(struct notifier_block *self,
1906 unsigned long event, void *data)
1907{
1908 do_panic();
1909 return NOTIFY_OK;
1910}
1911
1912static struct notifier_block on_panic_nb = {
1913 .notifier_call = on_panic_notify,
Michael Holzheu7e9b5802009-03-26 15:24:55 +01001914 .priority = INT_MIN,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001915};
1916
1917void __init setup_ipl(void)
1918{
1919 ipl_info.type = get_ipl_type();
1920 switch (ipl_info.type) {
1921 case IPL_TYPE_CCW:
1922 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1923 ipl_info.data.ccw.dev_id.ssid = 0;
1924 break;
1925 case IPL_TYPE_FCP:
1926 case IPL_TYPE_FCP_DUMP:
1927 ipl_info.data.fcp.dev_id.devno =
1928 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1929 ipl_info.data.fcp.dev_id.ssid = 0;
1930 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1931 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1932 break;
1933 case IPL_TYPE_NSS:
1934 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1935 sizeof(ipl_info.data.nss.name));
1936 break;
1937 case IPL_TYPE_UNKNOWN:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001938 /* We have no info to copy */
1939 break;
1940 }
1941 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1942}
1943
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001944void __init ipl_update_parameters(void)
1945{
Michael Holzheu3a95e8e2008-08-01 16:39:10 +02001946 int rc;
1947
1948 rc = diag308(DIAG308_STORE, &ipl_block);
1949 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001950 diag308_set_works = 1;
1951}
1952
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001953void __init ipl_save_parameters(void)
1954{
1955 struct cio_iplinfo iplinfo;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001956 void *src, *dst;
1957
1958 if (cio_get_iplinfo(&iplinfo))
1959 return;
1960
1961 ipl_devno = iplinfo.devno;
1962 ipl_flags |= IPL_DEVNO_VALID;
1963 if (!iplinfo.is_qdio)
1964 return;
1965 ipl_flags |= IPL_PARMBLOCK_VALID;
Heiko Carstenscbb870c2010-02-26 22:37:43 +01001966 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001967 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1968 memmove(dst, src, PAGE_SIZE);
Heiko Carstenscbb870c2010-02-26 22:37:43 +01001969 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001970}
1971
Heiko Carstens15e9b582006-12-04 15:40:26 +01001972static LIST_HEAD(rcall);
1973static DEFINE_MUTEX(rcall_mutex);
1974
1975void 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}
1981EXPORT_SYMBOL_GPL(register_reset_call);
1982
1983void unregister_reset_call(struct reset_call *reset)
1984{
1985 mutex_lock(&rcall_mutex);
1986 list_del(&reset->list);
1987 mutex_unlock(&rcall_mutex);
1988}
1989EXPORT_SYMBOL_GPL(unregister_reset_call);
1990
1991static void do_reset_calls(void)
1992{
1993 struct reset_call *reset;
1994
Michael Holzheu9dc73562011-08-03 16:44:22 +02001995#ifdef CONFIG_64BIT
1996 if (diag308_set_works) {
1997 diag308_reset();
1998 return;
1999 }
2000#endif
Heiko Carstens15e9b582006-12-04 15:40:26 +01002001 list_for_each_entry(reset, &rcall, list)
2002 reset->fn();
2003}
2004
Heiko Carstensc5dd8582007-03-05 23:35:43 +01002005u32 dump_prefix_page;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002006
Michael Holzheu60a0c682011-10-30 15:16:40 +01002007void s390_reset_system(void (*func)(void *), void *data)
Heiko Carstens15e9b582006-12-04 15:40:26 +01002008{
2009 struct _lowcore *lc;
2010
Heiko Carstens15e9b582006-12-04 15:40:26 +01002011 lc = (struct _lowcore *)(unsigned long) store_prefix();
Michael Holzheua45e1412006-12-15 17:18:22 +01002012
2013 /* Stack for interrupt/machine check handler */
Heiko Carstens15e9b582006-12-04 15:40:26 +01002014 lc->panic_stack = S390_lowcore.panic_stack;
2015
Michael Holzheuda1cf232006-12-15 17:18:27 +01002016 /* Save prefix page address for dump case */
Heiko Carstensc5dd8582007-03-05 23:35:43 +01002017 dump_prefix_page = (u32)(unsigned long) lc;
Michael Holzheuda1cf232006-12-15 17:18:27 +01002018
Heiko Carstens15e9b582006-12-04 15:40:26 +01002019 /* Disable prefixing */
2020 set_prefix(0);
2021
2022 /* Disable lowcore protection */
2023 __ctl_clear_bit(0,28);
2024
2025 /* Set new machine check handler */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +01002026 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002027 S390_lowcore.mcck_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002028 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002029
2030 /* Set new program check handler */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +01002031 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Michael Holzheua45e1412006-12-15 17:18:22 +01002032 S390_lowcore.program_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002033 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002034
Michael Holzheu60a0c682011-10-30 15:16:40 +01002035 /* Store status at absolute zero */
2036 store_status();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01002037
Michael Holzheu60a0c682011-10-30 15:16:40 +01002038 do_reset_calls();
2039 if (func)
2040 func(data);
2041}