blob: 371a2d88f4ac7b6e170134b96b4924c69f8a8b99 [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 *
Michael Holzheu99ca4e52008-01-26 14:11:11 +01005 * Copyright IBM Corp. 2005,2007
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>
Michael Holzheu46b05d22007-02-21 10:55:21 +010018#include <asm/ipl.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020019#include <asm/smp.h>
20#include <asm/setup.h>
21#include <asm/cpcmd.h>
22#include <asm/cio.h>
Michael Holzheu03a4d202006-12-04 15:39:58 +010023#include <asm/ebcdic.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010024#include <asm/reset.h>
Heiko Carstensab14de62007-02-05 21:18:37 +010025#include <asm/sclp.h>
Heiko Carstens3bd5f3e2009-04-23 13:58:06 +020026#include <asm/sigp.h>
Frank Munzert159d1ff2009-03-26 15:24:45 +010027#include <asm/checksum.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020028
29#define IPL_PARM_BLOCK_VERSION 0
Michael Holzheu03a4d202006-12-04 15:39:58 +010030
Michael Holzheu411ed322007-04-27 16:01:49 +020031#define IPL_UNKNOWN_STR "unknown"
32#define IPL_CCW_STR "ccw"
33#define IPL_FCP_STR "fcp"
34#define IPL_FCP_DUMP_STR "fcp_dump"
35#define IPL_NSS_STR "nss"
Heiko Carstens615b04b2007-02-21 10:55:37 +010036
Michael Holzheu99ca4e52008-01-26 14:11:11 +010037#define DUMP_CCW_STR "ccw"
38#define DUMP_FCP_STR "fcp"
39#define DUMP_NONE_STR "none"
40
41/*
42 * Four shutdown trigger types are supported:
43 * - panic
44 * - halt
45 * - power off
46 * - reipl
47 */
48#define ON_PANIC_STR "on_panic"
49#define ON_HALT_STR "on_halt"
50#define ON_POFF_STR "on_poff"
51#define ON_REIPL_STR "on_reboot"
52
53struct shutdown_action;
54struct shutdown_trigger {
55 char *name;
56 struct shutdown_action *action;
57};
58
59/*
Frank Munzert099b7652009-03-26 15:23:43 +010060 * The following shutdown action types are supported:
Michael Holzheu99ca4e52008-01-26 14:11:11 +010061 */
62#define SHUTDOWN_ACTION_IPL_STR "ipl"
63#define SHUTDOWN_ACTION_REIPL_STR "reipl"
64#define SHUTDOWN_ACTION_DUMP_STR "dump"
65#define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
66#define SHUTDOWN_ACTION_STOP_STR "stop"
Frank Munzert099b7652009-03-26 15:23:43 +010067#define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
Michael Holzheu99ca4e52008-01-26 14:11:11 +010068
69struct shutdown_action {
70 char *name;
71 void (*fn) (struct shutdown_trigger *trigger);
72 int (*init) (void);
Frank Munzert81088812009-07-07 16:37:07 +020073 int init_rc;
Michael Holzheu99ca4e52008-01-26 14:11:11 +010074};
75
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020076static char *ipl_type_str(enum ipl_type type)
77{
78 switch (type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020079 case IPL_TYPE_CCW:
80 return IPL_CCW_STR;
81 case IPL_TYPE_FCP:
82 return IPL_FCP_STR;
Michael Holzheu411ed322007-04-27 16:01:49 +020083 case IPL_TYPE_FCP_DUMP:
84 return IPL_FCP_DUMP_STR;
Hongjie Yangfe355b72007-02-05 21:18:24 +010085 case IPL_TYPE_NSS:
86 return IPL_NSS_STR;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020087 case IPL_TYPE_UNKNOWN:
88 default:
89 return IPL_UNKNOWN_STR;
90 }
91}
92
Michael Holzheu411ed322007-04-27 16:01:49 +020093enum dump_type {
94 DUMP_TYPE_NONE = 1,
95 DUMP_TYPE_CCW = 2,
96 DUMP_TYPE_FCP = 4,
97};
98
Michael Holzheu411ed322007-04-27 16:01:49 +020099static char *dump_type_str(enum dump_type type)
100{
101 switch (type) {
102 case DUMP_TYPE_NONE:
103 return DUMP_NONE_STR;
104 case DUMP_TYPE_CCW:
105 return DUMP_CCW_STR;
106 case DUMP_TYPE_FCP:
107 return DUMP_FCP_STR;
108 default:
109 return NULL;
110 }
111}
112
113/*
114 * Must be in data section since the bss section
115 * is not cleared when these are accessed.
116 */
117static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
118u32 ipl_flags __attribute__((__section__(".data"))) = 0;
119
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200120enum ipl_method {
Michael Holzheu411ed322007-04-27 16:01:49 +0200121 REIPL_METHOD_CCW_CIO,
122 REIPL_METHOD_CCW_DIAG,
123 REIPL_METHOD_CCW_VM,
124 REIPL_METHOD_FCP_RO_DIAG,
125 REIPL_METHOD_FCP_RW_DIAG,
126 REIPL_METHOD_FCP_RO_VM,
127 REIPL_METHOD_FCP_DUMP,
128 REIPL_METHOD_NSS,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200129 REIPL_METHOD_NSS_DIAG,
Michael Holzheu411ed322007-04-27 16:01:49 +0200130 REIPL_METHOD_DEFAULT,
131};
132
133enum dump_method {
134 DUMP_METHOD_NONE,
135 DUMP_METHOD_CCW_CIO,
136 DUMP_METHOD_CCW_DIAG,
137 DUMP_METHOD_CCW_VM,
138 DUMP_METHOD_FCP_DIAG,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200139};
140
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200141static int diag308_set_works = 0;
142
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200143static struct ipl_parameter_block ipl_block;
144
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200145static int reipl_capabilities = IPL_TYPE_UNKNOWN;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100146
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200147static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200148static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200149static struct ipl_parameter_block *reipl_block_fcp;
150static struct ipl_parameter_block *reipl_block_ccw;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200151static struct ipl_parameter_block *reipl_block_nss;
Frank Munzert099b7652009-03-26 15:23:43 +0100152static struct ipl_parameter_block *reipl_block_actual;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100153
Michael Holzheu411ed322007-04-27 16:01:49 +0200154static int dump_capabilities = DUMP_TYPE_NONE;
155static enum dump_type dump_type = DUMP_TYPE_NONE;
156static enum dump_method dump_method = DUMP_METHOD_NONE;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200157static struct ipl_parameter_block *dump_block_fcp;
158static struct ipl_parameter_block *dump_block_ccw;
159
Heiko Carstens05dd2532007-07-10 11:24:09 +0200160static struct sclp_ipl_info sclp_ipl_info;
161
Michael Holzheu46b05d22007-02-21 10:55:21 +0100162int diag308(unsigned long subcode, void *addr)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200163{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200164 register unsigned long _addr asm("0") = (unsigned long) addr;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200165 register unsigned long _rc asm("1") = 0;
166
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200167 asm volatile(
168 " diag %0,%2,0x308\n"
169 "0:\n"
170 EX_TABLE(0b,0b)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200171 : "+d" (_addr), "+d" (_rc)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200172 : "d" (subcode) : "cc", "memory");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200173 return _rc;
174}
Michael Holzheu411ed322007-04-27 16:01:49 +0200175EXPORT_SYMBOL_GPL(diag308);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200176
177/* SYSFS */
178
179#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400180static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
181 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200182 char *page) \
183{ \
184 return sprintf(page, _format, _value); \
185} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400186static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200187 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
188
189#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400190static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
191 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200192 char *page) \
193{ \
194 return sprintf(page, _fmt_out, \
195 (unsigned long long) _value); \
196} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400197static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
198 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200199 const char *buf, size_t len) \
200{ \
201 unsigned long long value; \
202 if (sscanf(buf, _fmt_in, &value) != 1) \
203 return -EINVAL; \
204 _value = value; \
205 return len; \
206} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400207static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200208 __ATTR(_name,(S_IRUGO | S_IWUSR), \
209 sys_##_prefix##_##_name##_show, \
210 sys_##_prefix##_##_name##_store);
211
Hongjie Yangfe355b72007-02-05 21:18:24 +0100212#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400213static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
214 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100215 char *page) \
216{ \
217 return sprintf(page, _fmt_out, _value); \
218} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400219static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100221 const char *buf, size_t len) \
222{ \
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100223 strncpy(_value, buf, sizeof(_value) - 1); \
224 strstrip(_value); \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100225 return len; \
226} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400227static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100228 __ATTR(_name,(S_IRUGO | S_IWUSR), \
229 sys_##_prefix##_##_name##_show, \
230 sys_##_prefix##_##_name##_store);
231
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200232static void make_attrs_ro(struct attribute **attrs)
233{
234 while (*attrs) {
235 (*attrs)->mode = S_IRUGO;
236 attrs++;
237 }
238}
239
240/*
241 * ipl section
242 */
243
Michael Holzheu411ed322007-04-27 16:01:49 +0200244static __init enum ipl_type get_ipl_type(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200245{
246 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
247
Hongjie Yangfe355b72007-02-05 21:18:24 +0100248 if (ipl_flags & IPL_NSS_VALID)
249 return IPL_TYPE_NSS;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200250 if (!(ipl_flags & IPL_DEVNO_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200251 return IPL_TYPE_UNKNOWN;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200252 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200253 return IPL_TYPE_CCW;
254 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
255 return IPL_TYPE_UNKNOWN;
256 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
257 return IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200258 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
259 return IPL_TYPE_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200260 return IPL_TYPE_FCP;
261}
262
Michael Holzheu411ed322007-04-27 16:01:49 +0200263struct ipl_info ipl_info;
264EXPORT_SYMBOL_GPL(ipl_info);
265
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400266static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
267 char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200268{
Michael Holzheu411ed322007-04-27 16:01:49 +0200269 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200270}
271
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400272static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200273
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200274/* VM IPL PARM routines */
275static void reipl_get_ascii_vmparm(char *dest,
276 const struct ipl_parameter_block *ipb)
277{
278 int i;
279 int len = 0;
280 char has_lowercase = 0;
281
282 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
283 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
284
285 len = ipb->ipl_info.ccw.vm_parm_len;
286 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
287 /* If at least one character is lowercase, we assume mixed
288 * case; otherwise we convert everything to lowercase.
289 */
290 for (i = 0; i < len; i++)
291 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
292 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
293 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
294 has_lowercase = 1;
295 break;
296 }
297 if (!has_lowercase)
298 EBC_TOLOWER(dest, len);
299 EBCASC(dest, len);
300 }
301 dest[len] = 0;
302}
303
304void get_ipl_vmparm(char *dest)
305{
306 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
307 reipl_get_ascii_vmparm(dest, &ipl_block);
308 else
309 dest[0] = 0;
310}
311
312static ssize_t ipl_vm_parm_show(struct kobject *kobj,
313 struct kobj_attribute *attr, char *page)
314{
315 char parm[DIAG308_VMPARM_SIZE + 1] = {};
316
317 get_ipl_vmparm(parm);
318 return sprintf(page, "%s\n", parm);
319}
320
321static struct kobj_attribute sys_ipl_vm_parm_attr =
322 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
323
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400324static ssize_t sys_ipl_device_show(struct kobject *kobj,
325 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200326{
327 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
328
Michael Holzheu411ed322007-04-27 16:01:49 +0200329 switch (ipl_info.type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200330 case IPL_TYPE_CCW:
331 return sprintf(page, "0.0.%04x\n", ipl_devno);
332 case IPL_TYPE_FCP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200333 case IPL_TYPE_FCP_DUMP:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200334 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
335 default:
336 return 0;
337 }
338}
339
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400340static struct kobj_attribute sys_ipl_device_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200341 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
342
Al Viro05bd7112007-07-15 21:01:22 +0100343static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
344 char *buf, loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200345{
Akinobu Mita0788fea2008-07-14 09:59:17 +0200346 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
347 IPL_PARMBLOCK_SIZE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200348}
349
350static struct bin_attribute ipl_parameter_attr = {
351 .attr = {
352 .name = "binary_parameter",
353 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200354 },
355 .size = PAGE_SIZE,
356 .read = &ipl_parameter_read,
357};
358
Al Viro05bd7112007-07-15 21:01:22 +0100359static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
360 char *buf, loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200361{
362 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
363 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
364
Akinobu Mita0788fea2008-07-14 09:59:17 +0200365 return memory_read_from_buffer(buf, count, &off, scp_data, size);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200366}
367
368static struct bin_attribute ipl_scp_data_attr = {
369 .attr = {
370 .name = "scp_data",
371 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200372 },
373 .size = PAGE_SIZE,
Al Viro05bd7112007-07-15 21:01:22 +0100374 .read = ipl_scp_data_read,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200375};
376
377/* FCP ipl device attributes */
378
379DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
380 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
381DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
382 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
383DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
384 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
385DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
386 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
387
388static struct attribute *ipl_fcp_attrs[] = {
389 &sys_ipl_type_attr.attr,
390 &sys_ipl_device_attr.attr,
391 &sys_ipl_fcp_wwpn_attr.attr,
392 &sys_ipl_fcp_lun_attr.attr,
393 &sys_ipl_fcp_bootprog_attr.attr,
394 &sys_ipl_fcp_br_lba_attr.attr,
395 NULL,
396};
397
398static struct attribute_group ipl_fcp_attr_group = {
399 .attrs = ipl_fcp_attrs,
400};
401
402/* CCW ipl device attributes */
403
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400404static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
405 struct kobj_attribute *attr, char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100406{
407 char loadparm[LOADPARM_LEN + 1] = {};
408
Heiko Carstens05dd2532007-07-10 11:24:09 +0200409 if (!sclp_ipl_info.is_valid)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100410 return sprintf(page, "#unknown#\n");
Heiko Carstens05dd2532007-07-10 11:24:09 +0200411 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100412 EBCASC(loadparm, LOADPARM_LEN);
413 strstrip(loadparm);
414 return sprintf(page, "%s\n", loadparm);
415}
416
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400417static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
Michael Holzheu03a4d202006-12-04 15:39:58 +0100418 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
419
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200420static struct attribute *ipl_ccw_attrs_vm[] = {
421 &sys_ipl_type_attr.attr,
422 &sys_ipl_device_attr.attr,
423 &sys_ipl_ccw_loadparm_attr.attr,
424 &sys_ipl_vm_parm_attr.attr,
425 NULL,
426};
427
428static struct attribute *ipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200429 &sys_ipl_type_attr.attr,
430 &sys_ipl_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100431 &sys_ipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200432 NULL,
433};
434
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200435static struct attribute_group ipl_ccw_attr_group_vm = {
436 .attrs = ipl_ccw_attrs_vm,
437};
438
439static struct attribute_group ipl_ccw_attr_group_lpar = {
440 .attrs = ipl_ccw_attrs_lpar
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200441};
442
Hongjie Yangfe355b72007-02-05 21:18:24 +0100443/* NSS ipl device attributes */
444
445DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
446
447static struct attribute *ipl_nss_attrs[] = {
448 &sys_ipl_type_attr.attr,
449 &sys_ipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200450 &sys_ipl_ccw_loadparm_attr.attr,
451 &sys_ipl_vm_parm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100452 NULL,
453};
454
455static struct attribute_group ipl_nss_attr_group = {
456 .attrs = ipl_nss_attrs,
457};
458
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200459/* UNKNOWN ipl device attributes */
460
461static struct attribute *ipl_unknown_attrs[] = {
462 &sys_ipl_type_attr.attr,
463 NULL,
464};
465
466static struct attribute_group ipl_unknown_attr_group = {
467 .attrs = ipl_unknown_attrs,
468};
469
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -0400470static struct kset *ipl_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200471
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100472static int __init ipl_register_fcp_files(void)
473{
474 int rc;
475
476 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
477 if (rc)
478 goto out;
479 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
480 if (rc)
481 goto out_ipl_parm;
482 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
483 if (!rc)
484 goto out;
485
486 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
487
488out_ipl_parm:
489 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
490out:
491 return rc;
492}
493
494static void ipl_run(struct shutdown_trigger *trigger)
495{
496 diag308(DIAG308_IPL, NULL);
497 if (MACHINE_IS_VM)
498 __cpcmd("IPL", NULL, 0, NULL);
499 else if (ipl_info.type == IPL_TYPE_CCW)
500 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
501}
502
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100503static int __init ipl_init(void)
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100504{
505 int rc;
506
507 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
508 if (!ipl_kset) {
509 rc = -ENOMEM;
510 goto out;
511 }
512 switch (ipl_info.type) {
513 case IPL_TYPE_CCW:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200514 if (MACHINE_IS_VM)
515 rc = sysfs_create_group(&ipl_kset->kobj,
516 &ipl_ccw_attr_group_vm);
517 else
518 rc = sysfs_create_group(&ipl_kset->kobj,
519 &ipl_ccw_attr_group_lpar);
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100520 break;
521 case IPL_TYPE_FCP:
522 case IPL_TYPE_FCP_DUMP:
523 rc = ipl_register_fcp_files();
524 break;
525 case IPL_TYPE_NSS:
526 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
527 break;
528 default:
529 rc = sysfs_create_group(&ipl_kset->kobj,
530 &ipl_unknown_attr_group);
531 break;
532 }
533out:
534 if (rc)
535 panic("ipl_init failed: rc = %i\n", rc);
536
537 return 0;
538}
539
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100540static struct shutdown_action __refdata ipl_action = {
541 .name = SHUTDOWN_ACTION_IPL_STR,
542 .fn = ipl_run,
543 .init = ipl_init,
544};
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100545
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200546/*
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100547 * reipl shutdown action: Reboot Linux on shutdown.
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200548 */
549
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200550/* VM IPL PARM attributes */
551static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
552 char *page)
553{
554 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
555
556 reipl_get_ascii_vmparm(vmparm, ipb);
557 return sprintf(page, "%s\n", vmparm);
558}
559
560static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
561 size_t vmparm_max,
562 const char *buf, size_t len)
563{
564 int i, ip_len;
565
566 /* ignore trailing newline */
567 ip_len = len;
568 if ((len > 0) && (buf[len - 1] == '\n'))
569 ip_len--;
570
571 if (ip_len > vmparm_max)
572 return -EINVAL;
573
574 /* parm is used to store kernel options, check for common chars */
575 for (i = 0; i < ip_len; i++)
576 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
577 return -EINVAL;
578
579 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
580 ipb->ipl_info.ccw.vm_parm_len = ip_len;
581 if (ip_len > 0) {
582 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
583 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
584 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
585 } else {
586 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
587 }
588
589 return len;
590}
591
592/* NSS wrapper */
593static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
594 struct kobj_attribute *attr, char *page)
595{
596 return reipl_generic_vmparm_show(reipl_block_nss, page);
597}
598
599static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
600 struct kobj_attribute *attr,
601 const char *buf, size_t len)
602{
603 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
604}
605
606/* CCW wrapper */
607static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
608 struct kobj_attribute *attr, char *page)
609{
610 return reipl_generic_vmparm_show(reipl_block_ccw, page);
611}
612
613static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
614 struct kobj_attribute *attr,
615 const char *buf, size_t len)
616{
617 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
618}
619
620static struct kobj_attribute sys_reipl_nss_vmparm_attr =
621 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
622 reipl_nss_vmparm_store);
623static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
624 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
625 reipl_ccw_vmparm_store);
626
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200627/* FCP reipl device attributes */
628
629DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
630 reipl_block_fcp->ipl_info.fcp.wwpn);
631DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
632 reipl_block_fcp->ipl_info.fcp.lun);
633DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
634 reipl_block_fcp->ipl_info.fcp.bootprog);
635DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
636 reipl_block_fcp->ipl_info.fcp.br_lba);
637DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
638 reipl_block_fcp->ipl_info.fcp.devno);
639
640static struct attribute *reipl_fcp_attrs[] = {
641 &sys_reipl_fcp_device_attr.attr,
642 &sys_reipl_fcp_wwpn_attr.attr,
643 &sys_reipl_fcp_lun_attr.attr,
644 &sys_reipl_fcp_bootprog_attr.attr,
645 &sys_reipl_fcp_br_lba_attr.attr,
646 NULL,
647};
648
649static struct attribute_group reipl_fcp_attr_group = {
650 .name = IPL_FCP_STR,
651 .attrs = reipl_fcp_attrs,
652};
653
654/* CCW reipl device attributes */
655
656DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
657 reipl_block_ccw->ipl_info.ccw.devno);
658
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200659static void reipl_get_ascii_loadparm(char *loadparm,
660 struct ipl_parameter_block *ibp)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100661{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200662 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100663 EBCASC(loadparm, LOADPARM_LEN);
664 loadparm[LOADPARM_LEN] = 0;
665 strstrip(loadparm);
666}
667
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200668static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
669 char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100670{
671 char buf[LOADPARM_LEN + 1];
672
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200673 reipl_get_ascii_loadparm(buf, ipb);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100674 return sprintf(page, "%s\n", buf);
675}
676
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200677static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
678 const char *buf, size_t len)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100679{
680 int i, lp_len;
681
682 /* ignore trailing newline */
683 lp_len = len;
684 if ((len > 0) && (buf[len - 1] == '\n'))
685 lp_len--;
686 /* loadparm can have max 8 characters and must not start with a blank */
687 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
688 return -EINVAL;
689 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
690 for (i = 0; i < lp_len; i++) {
691 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
692 (buf[i] == '.'))
693 continue;
694 return -EINVAL;
695 }
696 /* initialize loadparm with blanks */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200697 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100698 /* copy and convert to ebcdic */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200699 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
700 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100701 return len;
702}
703
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200704/* NSS wrapper */
705static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
706 struct kobj_attribute *attr, char *page)
707{
708 return reipl_generic_loadparm_show(reipl_block_nss, page);
709}
Michael Holzheu03a4d202006-12-04 15:39:58 +0100710
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200711static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
712 struct kobj_attribute *attr,
713 const char *buf, size_t len)
714{
715 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
716}
717
718/* CCW wrapper */
719static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
720 struct kobj_attribute *attr, char *page)
721{
722 return reipl_generic_loadparm_show(reipl_block_ccw, page);
723}
724
725static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
726 struct kobj_attribute *attr,
727 const char *buf, size_t len)
728{
729 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
730}
731
732static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
733 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
734 reipl_ccw_loadparm_store);
735
736static struct attribute *reipl_ccw_attrs_vm[] = {
737 &sys_reipl_ccw_device_attr.attr,
738 &sys_reipl_ccw_loadparm_attr.attr,
739 &sys_reipl_ccw_vmparm_attr.attr,
740 NULL,
741};
742
743static struct attribute *reipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200744 &sys_reipl_ccw_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100745 &sys_reipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200746 NULL,
747};
748
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200749static struct attribute_group reipl_ccw_attr_group_vm = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200750 .name = IPL_CCW_STR,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200751 .attrs = reipl_ccw_attrs_vm,
752};
753
754static struct attribute_group reipl_ccw_attr_group_lpar = {
755 .name = IPL_CCW_STR,
756 .attrs = reipl_ccw_attrs_lpar,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200757};
758
Hongjie Yangfe355b72007-02-05 21:18:24 +0100759
760/* NSS reipl device attributes */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200761static void reipl_get_ascii_nss_name(char *dst,
762 struct ipl_parameter_block *ipb)
763{
764 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
765 EBCASC(dst, NSS_NAME_SIZE);
766 dst[NSS_NAME_SIZE] = 0;
767}
Hongjie Yangfe355b72007-02-05 21:18:24 +0100768
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200769static ssize_t reipl_nss_name_show(struct kobject *kobj,
770 struct kobj_attribute *attr, char *page)
771{
772 char nss_name[NSS_NAME_SIZE + 1] = {};
773
774 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
775 return sprintf(page, "%s\n", nss_name);
776}
777
778static ssize_t reipl_nss_name_store(struct kobject *kobj,
779 struct kobj_attribute *attr,
780 const char *buf, size_t len)
781{
782 int nss_len;
783
784 /* ignore trailing newline */
785 nss_len = len;
786 if ((len > 0) && (buf[len - 1] == '\n'))
787 nss_len--;
788
789 if (nss_len > NSS_NAME_SIZE)
790 return -EINVAL;
791
792 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
793 if (nss_len > 0) {
794 reipl_block_nss->ipl_info.ccw.vm_flags |=
795 DIAG308_VM_FLAGS_NSS_VALID;
796 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
797 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
798 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
799 } else {
800 reipl_block_nss->ipl_info.ccw.vm_flags &=
801 ~DIAG308_VM_FLAGS_NSS_VALID;
802 }
803
804 return len;
805}
806
807static struct kobj_attribute sys_reipl_nss_name_attr =
808 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
809 reipl_nss_name_store);
810
811static struct kobj_attribute sys_reipl_nss_loadparm_attr =
812 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
813 reipl_nss_loadparm_store);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100814
815static struct attribute *reipl_nss_attrs[] = {
816 &sys_reipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200817 &sys_reipl_nss_loadparm_attr.attr,
818 &sys_reipl_nss_vmparm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100819 NULL,
820};
821
822static struct attribute_group reipl_nss_attr_group = {
823 .name = IPL_NSS_STR,
824 .attrs = reipl_nss_attrs,
825};
826
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200827/* reipl type */
828
829static int reipl_set_type(enum ipl_type type)
830{
831 if (!(reipl_capabilities & type))
832 return -EINVAL;
833
834 switch(type) {
835 case IPL_TYPE_CCW:
Michael Holzheu48657d22008-01-26 14:11:17 +0100836 if (diag308_set_works)
837 reipl_method = REIPL_METHOD_CCW_DIAG;
838 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200839 reipl_method = REIPL_METHOD_CCW_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200840 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200841 reipl_method = REIPL_METHOD_CCW_CIO;
Frank Munzert099b7652009-03-26 15:23:43 +0100842 reipl_block_actual = reipl_block_ccw;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200843 break;
844 case IPL_TYPE_FCP:
845 if (diag308_set_works)
Michael Holzheu411ed322007-04-27 16:01:49 +0200846 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200847 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200848 reipl_method = REIPL_METHOD_FCP_RO_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200849 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200850 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
Frank Munzert099b7652009-03-26 15:23:43 +0100851 reipl_block_actual = reipl_block_fcp;
Michael Holzheu411ed322007-04-27 16:01:49 +0200852 break;
853 case IPL_TYPE_FCP_DUMP:
854 reipl_method = REIPL_METHOD_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200855 break;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100856 case IPL_TYPE_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200857 if (diag308_set_works)
858 reipl_method = REIPL_METHOD_NSS_DIAG;
859 else
860 reipl_method = REIPL_METHOD_NSS;
Frank Munzert099b7652009-03-26 15:23:43 +0100861 reipl_block_actual = reipl_block_nss;
Michael Holzheu411ed322007-04-27 16:01:49 +0200862 break;
863 case IPL_TYPE_UNKNOWN:
864 reipl_method = REIPL_METHOD_DEFAULT;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100865 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200866 default:
Michael Holzheu411ed322007-04-27 16:01:49 +0200867 BUG();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200868 }
869 reipl_type = type;
870 return 0;
871}
872
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400873static ssize_t reipl_type_show(struct kobject *kobj,
874 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200875{
876 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
877}
878
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400879static ssize_t reipl_type_store(struct kobject *kobj,
880 struct kobj_attribute *attr,
881 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200882{
883 int rc = -EINVAL;
884
885 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
886 rc = reipl_set_type(IPL_TYPE_CCW);
887 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
888 rc = reipl_set_type(IPL_TYPE_FCP);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100889 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
890 rc = reipl_set_type(IPL_TYPE_NSS);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200891 return (rc != 0) ? rc : len;
892}
893
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400894static struct kobj_attribute reipl_type_attr =
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100895 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200896
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -0400897static struct kset *reipl_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200898
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200899static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
900 const enum ipl_method m)
901{
902 char loadparm[LOADPARM_LEN + 1] = {};
903 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
904 char nss_name[NSS_NAME_SIZE + 1] = {};
905 size_t pos = 0;
906
907 reipl_get_ascii_loadparm(loadparm, ipb);
908 reipl_get_ascii_nss_name(nss_name, ipb);
909 reipl_get_ascii_vmparm(vmparm, ipb);
910
911 switch (m) {
912 case REIPL_METHOD_CCW_VM:
913 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
914 break;
915 case REIPL_METHOD_NSS:
916 pos = sprintf(dst, "IPL %s", nss_name);
917 break;
918 default:
919 break;
920 }
921 if (strlen(loadparm) > 0)
922 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
923 if (strlen(vmparm) > 0)
924 sprintf(dst + pos, " PARM %s", vmparm);
925}
926
Heiko Carstensa8061702008-04-17 07:46:26 +0200927static void reipl_run(struct shutdown_trigger *trigger)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200928{
929 struct ccw_dev_id devid;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200930 static char buf[128];
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200931
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200932 switch (reipl_method) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200933 case REIPL_METHOD_CCW_CIO:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200934 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
935 devid.ssid = 0;
936 reipl_ccw_dev(&devid);
937 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200938 case REIPL_METHOD_CCW_VM:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200939 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
Heiko Carstens740b5702006-12-04 15:40:30 +0100940 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200941 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200942 case REIPL_METHOD_CCW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200943 diag308(DIAG308_SET, reipl_block_ccw);
944 diag308(DIAG308_IPL, NULL);
945 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200946 case REIPL_METHOD_FCP_RW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200947 diag308(DIAG308_SET, reipl_block_fcp);
948 diag308(DIAG308_IPL, NULL);
949 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200950 case REIPL_METHOD_FCP_RO_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200951 diag308(DIAG308_IPL, NULL);
952 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200953 case REIPL_METHOD_FCP_RO_VM:
Heiko Carstens740b5702006-12-04 15:40:30 +0100954 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200955 break;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200956 case REIPL_METHOD_NSS_DIAG:
957 diag308(DIAG308_SET, reipl_block_nss);
958 diag308(DIAG308_IPL, NULL);
959 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200960 case REIPL_METHOD_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200961 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100962 __cpcmd(buf, NULL, 0, NULL);
963 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200964 case REIPL_METHOD_DEFAULT:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200965 if (MACHINE_IS_VM)
Heiko Carstens740b5702006-12-04 15:40:30 +0100966 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200967 diag308(DIAG308_IPL, NULL);
968 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200969 case REIPL_METHOD_FCP_DUMP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200970 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200971 }
Michael Holzheu208e5592008-03-05 12:37:15 +0100972 disabled_wait((unsigned long) __builtin_return_address(0));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200973}
974
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200975static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200976{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200977 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
978 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
979 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
980 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
981}
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200982
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200983static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
984{
985 /* LOADPARM */
986 /* check if read scp info worked and set loadparm */
987 if (sclp_ipl_info.is_valid)
988 memcpy(ipb->ipl_info.ccw.load_parm,
989 &sclp_ipl_info.loadparm, LOADPARM_LEN);
990 else
991 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
992 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
993 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
994
995 /* VM PARM */
996 if (MACHINE_IS_VM && diag308_set_works &&
997 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
998
999 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1000 ipb->ipl_info.ccw.vm_parm_len =
1001 ipl_block.ipl_info.ccw.vm_parm_len;
1002 memcpy(ipb->ipl_info.ccw.vm_parm,
1003 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1004 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001005}
1006
Hongjie Yangfe355b72007-02-05 21:18:24 +01001007static int __init reipl_nss_init(void)
1008{
1009 int rc;
1010
1011 if (!MACHINE_IS_VM)
1012 return 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001013
1014 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1015 if (!reipl_block_nss)
1016 return -ENOMEM;
1017
1018 if (!diag308_set_works)
1019 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1020
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001021 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001022 if (rc)
1023 return rc;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001024
1025 reipl_block_ccw_init(reipl_block_nss);
1026 if (ipl_info.type == IPL_TYPE_NSS) {
1027 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1028 ' ', NSS_NAME_SIZE);
1029 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1030 kernel_nss_name, strlen(kernel_nss_name));
1031 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1032 reipl_block_nss->ipl_info.ccw.vm_flags |=
1033 DIAG308_VM_FLAGS_NSS_VALID;
1034
1035 reipl_block_ccw_fill_parms(reipl_block_nss);
1036 }
1037
Hongjie Yangfe355b72007-02-05 21:18:24 +01001038 reipl_capabilities |= IPL_TYPE_NSS;
1039 return 0;
1040}
1041
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001042static int __init reipl_ccw_init(void)
1043{
1044 int rc;
1045
1046 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1047 if (!reipl_block_ccw)
1048 return -ENOMEM;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001049
1050 if (MACHINE_IS_VM) {
1051 if (!diag308_set_works)
1052 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1053 rc = sysfs_create_group(&reipl_kset->kobj,
1054 &reipl_ccw_attr_group_vm);
1055 } else {
1056 if(!diag308_set_works)
1057 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1058 rc = sysfs_create_group(&reipl_kset->kobj,
1059 &reipl_ccw_attr_group_lpar);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001060 }
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001061 if (rc)
1062 return rc;
1063
1064 reipl_block_ccw_init(reipl_block_ccw);
1065 if (ipl_info.type == IPL_TYPE_CCW) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001066 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001067 reipl_block_ccw_fill_parms(reipl_block_ccw);
1068 }
1069
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001070 reipl_capabilities |= IPL_TYPE_CCW;
1071 return 0;
1072}
1073
1074static int __init reipl_fcp_init(void)
1075{
1076 int rc;
1077
Michael Holzheu008d2d12009-03-26 15:24:51 +01001078 if (!diag308_set_works) {
1079 if (ipl_info.type == IPL_TYPE_FCP)
1080 make_attrs_ro(reipl_fcp_attrs);
1081 else
1082 return 0;
1083 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001084
1085 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1086 if (!reipl_block_fcp)
1087 return -ENOMEM;
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001088 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001089 if (rc) {
1090 free_page((unsigned long)reipl_block_fcp);
1091 return rc;
1092 }
Michael Holzheu411ed322007-04-27 16:01:49 +02001093 if (ipl_info.type == IPL_TYPE_FCP) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001094 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1095 } else {
1096 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1097 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001098 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001099 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1100 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1101 }
1102 reipl_capabilities |= IPL_TYPE_FCP;
1103 return 0;
1104}
1105
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001106static int __init reipl_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001107{
1108 int rc;
1109
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001110 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001111 if (!reipl_kset)
1112 return -ENOMEM;
1113 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001114 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001115 kset_unregister(reipl_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001116 return rc;
1117 }
1118 rc = reipl_ccw_init();
1119 if (rc)
1120 return rc;
1121 rc = reipl_fcp_init();
1122 if (rc)
1123 return rc;
Hongjie Yangfe355b72007-02-05 21:18:24 +01001124 rc = reipl_nss_init();
1125 if (rc)
1126 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001127 rc = reipl_set_type(ipl_info.type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001128 if (rc)
1129 return rc;
1130 return 0;
1131}
1132
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001133static struct shutdown_action __refdata reipl_action = {
1134 .name = SHUTDOWN_ACTION_REIPL_STR,
1135 .fn = reipl_run,
1136 .init = reipl_init,
1137};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001138
1139/*
1140 * dump shutdown action: Dump Linux on shutdown.
1141 */
1142
1143/* FCP dump device attributes */
1144
1145DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1146 dump_block_fcp->ipl_info.fcp.wwpn);
1147DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1148 dump_block_fcp->ipl_info.fcp.lun);
1149DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1150 dump_block_fcp->ipl_info.fcp.bootprog);
1151DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1152 dump_block_fcp->ipl_info.fcp.br_lba);
1153DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1154 dump_block_fcp->ipl_info.fcp.devno);
1155
1156static struct attribute *dump_fcp_attrs[] = {
1157 &sys_dump_fcp_device_attr.attr,
1158 &sys_dump_fcp_wwpn_attr.attr,
1159 &sys_dump_fcp_lun_attr.attr,
1160 &sys_dump_fcp_bootprog_attr.attr,
1161 &sys_dump_fcp_br_lba_attr.attr,
1162 NULL,
1163};
1164
1165static struct attribute_group dump_fcp_attr_group = {
1166 .name = IPL_FCP_STR,
1167 .attrs = dump_fcp_attrs,
1168};
1169
1170/* CCW dump device attributes */
1171
1172DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1173 dump_block_ccw->ipl_info.ccw.devno);
1174
1175static struct attribute *dump_ccw_attrs[] = {
1176 &sys_dump_ccw_device_attr.attr,
1177 NULL,
1178};
1179
1180static struct attribute_group dump_ccw_attr_group = {
1181 .name = IPL_CCW_STR,
1182 .attrs = dump_ccw_attrs,
1183};
1184
1185/* dump type */
1186
1187static int dump_set_type(enum dump_type type)
1188{
1189 if (!(dump_capabilities & type))
1190 return -EINVAL;
1191 switch (type) {
1192 case DUMP_TYPE_CCW:
Michael Holzheu48657d22008-01-26 14:11:17 +01001193 if (diag308_set_works)
1194 dump_method = DUMP_METHOD_CCW_DIAG;
1195 else if (MACHINE_IS_VM)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001196 dump_method = DUMP_METHOD_CCW_VM;
1197 else
1198 dump_method = DUMP_METHOD_CCW_CIO;
1199 break;
1200 case DUMP_TYPE_FCP:
1201 dump_method = DUMP_METHOD_FCP_DIAG;
1202 break;
1203 default:
1204 dump_method = DUMP_METHOD_NONE;
1205 }
1206 dump_type = type;
1207 return 0;
1208}
1209
1210static ssize_t dump_type_show(struct kobject *kobj,
1211 struct kobj_attribute *attr, char *page)
1212{
1213 return sprintf(page, "%s\n", dump_type_str(dump_type));
1214}
1215
1216static ssize_t dump_type_store(struct kobject *kobj,
1217 struct kobj_attribute *attr,
1218 const char *buf, size_t len)
1219{
1220 int rc = -EINVAL;
1221
1222 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1223 rc = dump_set_type(DUMP_TYPE_NONE);
1224 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1225 rc = dump_set_type(DUMP_TYPE_CCW);
1226 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1227 rc = dump_set_type(DUMP_TYPE_FCP);
1228 return (rc != 0) ? rc : len;
1229}
1230
1231static struct kobj_attribute dump_type_attr =
1232 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1233
1234static struct kset *dump_kset;
1235
1236static void dump_run(struct shutdown_trigger *trigger)
1237{
1238 struct ccw_dev_id devid;
1239 static char buf[100];
1240
1241 switch (dump_method) {
1242 case DUMP_METHOD_CCW_CIO:
1243 smp_send_stop();
1244 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1245 devid.ssid = 0;
1246 reipl_ccw_dev(&devid);
1247 break;
1248 case DUMP_METHOD_CCW_VM:
1249 smp_send_stop();
1250 sprintf(buf, "STORE STATUS");
1251 __cpcmd(buf, NULL, 0, NULL);
1252 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1253 __cpcmd(buf, NULL, 0, NULL);
1254 break;
1255 case DUMP_METHOD_CCW_DIAG:
1256 diag308(DIAG308_SET, dump_block_ccw);
1257 diag308(DIAG308_DUMP, NULL);
1258 break;
1259 case DUMP_METHOD_FCP_DIAG:
1260 diag308(DIAG308_SET, dump_block_fcp);
1261 diag308(DIAG308_DUMP, NULL);
1262 break;
1263 case DUMP_METHOD_NONE:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001264 return;
1265 }
1266 printk(KERN_EMERG "Dump failed!\n");
1267}
1268
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001269static int __init dump_ccw_init(void)
1270{
1271 int rc;
1272
1273 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1274 if (!dump_block_ccw)
1275 return -ENOMEM;
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001276 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001277 if (rc) {
1278 free_page((unsigned long)dump_block_ccw);
1279 return rc;
1280 }
1281 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1282 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001283 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001284 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
Michael Holzheu411ed322007-04-27 16:01:49 +02001285 dump_capabilities |= DUMP_TYPE_CCW;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001286 return 0;
1287}
1288
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001289static int __init dump_fcp_init(void)
1290{
1291 int rc;
1292
Heiko Carstens05dd2532007-07-10 11:24:09 +02001293 if (!sclp_ipl_info.has_dump)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001294 return 0; /* LDIPL DUMP is not installed */
1295 if (!diag308_set_works)
1296 return 0;
1297 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1298 if (!dump_block_fcp)
1299 return -ENOMEM;
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001300 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001301 if (rc) {
1302 free_page((unsigned long)dump_block_fcp);
1303 return rc;
1304 }
1305 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1306 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001307 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001308 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1309 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
Michael Holzheu411ed322007-04-27 16:01:49 +02001310 dump_capabilities |= DUMP_TYPE_FCP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001311 return 0;
1312}
1313
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001314static int __init dump_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001315{
1316 int rc;
1317
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001318 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001319 if (!dump_kset)
1320 return -ENOMEM;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001321 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001322 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001323 kset_unregister(dump_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001324 return rc;
1325 }
1326 rc = dump_ccw_init();
1327 if (rc)
1328 return rc;
1329 rc = dump_fcp_init();
1330 if (rc)
1331 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001332 dump_set_type(DUMP_TYPE_NONE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001333 return 0;
1334}
1335
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001336static struct shutdown_action __refdata dump_action = {
1337 .name = SHUTDOWN_ACTION_DUMP_STR,
1338 .fn = dump_run,
1339 .init = dump_init,
1340};
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001341
Frank Munzert099b7652009-03-26 15:23:43 +01001342static void dump_reipl_run(struct shutdown_trigger *trigger)
1343{
1344 preempt_disable();
1345 /*
1346 * Bypass dynamic address translation (DAT) when storing IPL parameter
1347 * information block address and checksum into the prefix area
1348 * (corresponding to absolute addresses 0-8191).
1349 * When enhanced DAT applies and the STE format control in one,
1350 * the absolute address is formed without prefixing. In this case a
1351 * normal store (stg/st) into the prefix area would no more match to
1352 * absolute addresses 0-8191.
1353 */
1354#ifdef CONFIG_64BIT
1355 asm volatile("sturg %0,%1"
1356 :: "a" ((unsigned long) reipl_block_actual),
1357 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1358#else
1359 asm volatile("stura %0,%1"
1360 :: "a" ((unsigned long) reipl_block_actual),
1361 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1362#endif
1363 asm volatile("stura %0,%1"
Frank Munzert159d1ff2009-03-26 15:24:45 +01001364 :: "a" (csum_partial(reipl_block_actual,
1365 reipl_block_actual->hdr.len, 0)),
Frank Munzert099b7652009-03-26 15:23:43 +01001366 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1367 preempt_enable();
1368 dump_run(trigger);
1369}
1370
1371static int __init dump_reipl_init(void)
1372{
1373 if (!diag308_set_works)
1374 return -EOPNOTSUPP;
1375 else
1376 return 0;
1377}
1378
1379static struct shutdown_action __refdata dump_reipl_action = {
1380 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1381 .fn = dump_reipl_run,
1382 .init = dump_reipl_init,
1383};
1384
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001385/*
1386 * vmcmd shutdown action: Trigger vm command on shutdown.
1387 */
1388
1389static char vmcmd_on_reboot[128];
1390static char vmcmd_on_panic[128];
1391static char vmcmd_on_halt[128];
1392static char vmcmd_on_poff[128];
1393
1394DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1395DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1396DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1397DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1398
1399static struct attribute *vmcmd_attrs[] = {
1400 &sys_vmcmd_on_reboot_attr.attr,
1401 &sys_vmcmd_on_panic_attr.attr,
1402 &sys_vmcmd_on_halt_attr.attr,
1403 &sys_vmcmd_on_poff_attr.attr,
1404 NULL,
1405};
1406
1407static struct attribute_group vmcmd_attr_group = {
1408 .attrs = vmcmd_attrs,
1409};
1410
1411static struct kset *vmcmd_kset;
1412
1413static void vmcmd_run(struct shutdown_trigger *trigger)
1414{
1415 char *cmd, *next_cmd;
1416
1417 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1418 cmd = vmcmd_on_reboot;
1419 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1420 cmd = vmcmd_on_panic;
1421 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1422 cmd = vmcmd_on_halt;
1423 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1424 cmd = vmcmd_on_poff;
1425 else
1426 return;
1427
1428 if (strlen(cmd) == 0)
1429 return;
1430 do {
1431 next_cmd = strchr(cmd, '\n');
1432 if (next_cmd) {
1433 next_cmd[0] = 0;
1434 next_cmd += 1;
1435 }
1436 __cpcmd(cmd, NULL, 0, NULL);
1437 cmd = next_cmd;
1438 } while (cmd != NULL);
1439}
1440
1441static int vmcmd_init(void)
1442{
1443 if (!MACHINE_IS_VM)
1444 return -ENOTSUPP;
1445 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1446 if (!vmcmd_kset)
1447 return -ENOMEM;
1448 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1449}
1450
1451static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1452 vmcmd_run, vmcmd_init};
1453
1454/*
1455 * stop shutdown action: Stop Linux on shutdown.
1456 */
1457
1458static void stop_run(struct shutdown_trigger *trigger)
1459{
Michael Holzheuc6547492008-01-26 14:11:12 +01001460 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1461 disabled_wait((unsigned long) __builtin_return_address(0));
1462 else {
1463 signal_processor(smp_processor_id(), sigp_stop);
1464 for (;;);
1465 }
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001466}
1467
1468static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1469 stop_run, NULL};
1470
1471/* action list */
1472
1473static struct shutdown_action *shutdown_actions_list[] = {
Frank Munzert099b7652009-03-26 15:23:43 +01001474 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1475 &vmcmd_action, &stop_action};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001476#define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1477
1478/*
1479 * Trigger section
1480 */
1481
1482static struct kset *shutdown_actions_kset;
1483
1484static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1485 size_t len)
1486{
1487 int i;
Frank Munzert099b7652009-03-26 15:23:43 +01001488
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001489 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
Frank Munzert099b7652009-03-26 15:23:43 +01001490 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
Frank Munzert81088812009-07-07 16:37:07 +02001491 if (shutdown_actions_list[i]->init_rc) {
1492 return shutdown_actions_list[i]->init_rc;
1493 } else {
1494 trigger->action = shutdown_actions_list[i];
1495 return len;
1496 }
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001497 }
1498 }
1499 return -EINVAL;
1500}
1501
1502/* on reipl */
1503
1504static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1505 &reipl_action};
1506
1507static ssize_t on_reboot_show(struct kobject *kobj,
1508 struct kobj_attribute *attr, char *page)
1509{
1510 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1511}
1512
1513static ssize_t on_reboot_store(struct kobject *kobj,
1514 struct kobj_attribute *attr,
1515 const char *buf, size_t len)
1516{
1517 return set_trigger(buf, &on_reboot_trigger, len);
1518}
1519
1520static struct kobj_attribute on_reboot_attr =
1521 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1522
1523static void do_machine_restart(char *__unused)
1524{
1525 smp_send_stop();
1526 on_reboot_trigger.action->fn(&on_reboot_trigger);
1527 reipl_run(NULL);
1528}
1529void (*_machine_restart)(char *command) = do_machine_restart;
1530
1531/* on panic */
1532
1533static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1534
1535static ssize_t on_panic_show(struct kobject *kobj,
1536 struct kobj_attribute *attr, char *page)
1537{
1538 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1539}
1540
1541static ssize_t on_panic_store(struct kobject *kobj,
1542 struct kobj_attribute *attr,
1543 const char *buf, size_t len)
1544{
1545 return set_trigger(buf, &on_panic_trigger, len);
1546}
1547
1548static struct kobj_attribute on_panic_attr =
1549 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1550
1551static void do_panic(void)
1552{
1553 on_panic_trigger.action->fn(&on_panic_trigger);
1554 stop_run(&on_panic_trigger);
1555}
1556
1557/* on halt */
1558
1559static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1560
1561static ssize_t on_halt_show(struct kobject *kobj,
1562 struct kobj_attribute *attr, char *page)
1563{
1564 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1565}
1566
1567static ssize_t on_halt_store(struct kobject *kobj,
1568 struct kobj_attribute *attr,
1569 const char *buf, size_t len)
1570{
1571 return set_trigger(buf, &on_halt_trigger, len);
1572}
1573
1574static struct kobj_attribute on_halt_attr =
1575 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1576
1577
1578static void do_machine_halt(void)
1579{
1580 smp_send_stop();
1581 on_halt_trigger.action->fn(&on_halt_trigger);
1582 stop_run(&on_halt_trigger);
1583}
1584void (*_machine_halt)(void) = do_machine_halt;
1585
1586/* on power off */
1587
1588static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1589
1590static ssize_t on_poff_show(struct kobject *kobj,
1591 struct kobj_attribute *attr, char *page)
1592{
1593 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1594}
1595
1596static ssize_t on_poff_store(struct kobject *kobj,
1597 struct kobj_attribute *attr,
1598 const char *buf, size_t len)
1599{
1600 return set_trigger(buf, &on_poff_trigger, len);
1601}
1602
1603static struct kobj_attribute on_poff_attr =
1604 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1605
1606
1607static void do_machine_power_off(void)
1608{
1609 smp_send_stop();
1610 on_poff_trigger.action->fn(&on_poff_trigger);
1611 stop_run(&on_poff_trigger);
1612}
1613void (*_machine_power_off)(void) = do_machine_power_off;
1614
1615static void __init shutdown_triggers_init(void)
1616{
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001617 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001618 firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001619 if (!shutdown_actions_kset)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001620 goto fail;
1621 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1622 &on_reboot_attr.attr))
1623 goto fail;
1624 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1625 &on_panic_attr.attr))
1626 goto fail;
1627 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1628 &on_halt_attr.attr))
1629 goto fail;
1630 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1631 &on_poff_attr.attr))
1632 goto fail;
1633
1634 return;
1635fail:
1636 panic("shutdown_triggers_init failed\n");
1637}
1638
1639static void __init shutdown_actions_init(void)
1640{
1641 int i;
1642
1643 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1644 if (!shutdown_actions_list[i]->init)
1645 continue;
Frank Munzert81088812009-07-07 16:37:07 +02001646 shutdown_actions_list[i]->init_rc =
1647 shutdown_actions_list[i]->init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001648 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001649}
1650
1651static int __init s390_ipl_init(void)
1652{
Michael Holzheud09293a2008-01-26 14:11:15 +01001653 sclp_get_ipl_info(&sclp_ipl_info);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001654 shutdown_actions_init();
1655 shutdown_triggers_init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001656 return 0;
1657}
1658
1659__initcall(s390_ipl_init);
Heiko Carstens15e9b582006-12-04 15:40:26 +01001660
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001661static void __init strncpy_skip_quote(char *dst, char *src, int n)
1662{
1663 int sx, dx;
1664
1665 dx = 0;
1666 for (sx = 0; src[sx] != 0; sx++) {
1667 if (src[sx] == '"')
1668 continue;
1669 dst[dx++] = src[sx];
1670 if (dx >= n)
1671 break;
1672 }
1673}
1674
1675static int __init vmcmd_on_reboot_setup(char *str)
1676{
1677 if (!MACHINE_IS_VM)
1678 return 1;
1679 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1680 vmcmd_on_reboot[127] = 0;
1681 on_reboot_trigger.action = &vmcmd_action;
1682 return 1;
1683}
1684__setup("vmreboot=", vmcmd_on_reboot_setup);
1685
1686static int __init vmcmd_on_panic_setup(char *str)
1687{
1688 if (!MACHINE_IS_VM)
1689 return 1;
1690 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1691 vmcmd_on_panic[127] = 0;
1692 on_panic_trigger.action = &vmcmd_action;
1693 return 1;
1694}
1695__setup("vmpanic=", vmcmd_on_panic_setup);
1696
1697static int __init vmcmd_on_halt_setup(char *str)
1698{
1699 if (!MACHINE_IS_VM)
1700 return 1;
1701 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1702 vmcmd_on_halt[127] = 0;
1703 on_halt_trigger.action = &vmcmd_action;
1704 return 1;
1705}
1706__setup("vmhalt=", vmcmd_on_halt_setup);
1707
1708static int __init vmcmd_on_poff_setup(char *str)
1709{
1710 if (!MACHINE_IS_VM)
1711 return 1;
1712 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1713 vmcmd_on_poff[127] = 0;
1714 on_poff_trigger.action = &vmcmd_action;
1715 return 1;
1716}
1717__setup("vmpoff=", vmcmd_on_poff_setup);
1718
1719static int on_panic_notify(struct notifier_block *self,
1720 unsigned long event, void *data)
1721{
1722 do_panic();
1723 return NOTIFY_OK;
1724}
1725
1726static struct notifier_block on_panic_nb = {
1727 .notifier_call = on_panic_notify,
Michael Holzheu7e9b5802009-03-26 15:24:55 +01001728 .priority = INT_MIN,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001729};
1730
1731void __init setup_ipl(void)
1732{
1733 ipl_info.type = get_ipl_type();
1734 switch (ipl_info.type) {
1735 case IPL_TYPE_CCW:
1736 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1737 ipl_info.data.ccw.dev_id.ssid = 0;
1738 break;
1739 case IPL_TYPE_FCP:
1740 case IPL_TYPE_FCP_DUMP:
1741 ipl_info.data.fcp.dev_id.devno =
1742 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1743 ipl_info.data.fcp.dev_id.ssid = 0;
1744 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1745 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1746 break;
1747 case IPL_TYPE_NSS:
1748 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1749 sizeof(ipl_info.data.nss.name));
1750 break;
1751 case IPL_TYPE_UNKNOWN:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001752 /* We have no info to copy */
1753 break;
1754 }
1755 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1756}
1757
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001758void __init ipl_update_parameters(void)
1759{
Michael Holzheu3a95e8e2008-08-01 16:39:10 +02001760 int rc;
1761
1762 rc = diag308(DIAG308_STORE, &ipl_block);
1763 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001764 diag308_set_works = 1;
1765}
1766
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001767void __init ipl_save_parameters(void)
1768{
1769 struct cio_iplinfo iplinfo;
1770 unsigned int *ipl_ptr;
1771 void *src, *dst;
1772
1773 if (cio_get_iplinfo(&iplinfo))
1774 return;
1775
1776 ipl_devno = iplinfo.devno;
1777 ipl_flags |= IPL_DEVNO_VALID;
1778 if (!iplinfo.is_qdio)
1779 return;
1780 ipl_flags |= IPL_PARMBLOCK_VALID;
1781 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1782 src = (void *)(unsigned long)*ipl_ptr;
1783 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1784 memmove(dst, src, PAGE_SIZE);
1785 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1786}
1787
Heiko Carstens15e9b582006-12-04 15:40:26 +01001788static LIST_HEAD(rcall);
1789static DEFINE_MUTEX(rcall_mutex);
1790
1791void register_reset_call(struct reset_call *reset)
1792{
1793 mutex_lock(&rcall_mutex);
1794 list_add(&reset->list, &rcall);
1795 mutex_unlock(&rcall_mutex);
1796}
1797EXPORT_SYMBOL_GPL(register_reset_call);
1798
1799void unregister_reset_call(struct reset_call *reset)
1800{
1801 mutex_lock(&rcall_mutex);
1802 list_del(&reset->list);
1803 mutex_unlock(&rcall_mutex);
1804}
1805EXPORT_SYMBOL_GPL(unregister_reset_call);
1806
1807static void do_reset_calls(void)
1808{
1809 struct reset_call *reset;
1810
1811 list_for_each_entry(reset, &rcall, list)
1812 reset->fn();
1813}
1814
Heiko Carstensc5dd8582007-03-05 23:35:43 +01001815u32 dump_prefix_page;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001816
1817void s390_reset_system(void)
1818{
1819 struct _lowcore *lc;
1820
Heiko Carstens15e9b582006-12-04 15:40:26 +01001821 lc = (struct _lowcore *)(unsigned long) store_prefix();
Michael Holzheua45e1412006-12-15 17:18:22 +01001822
1823 /* Stack for interrupt/machine check handler */
Heiko Carstens15e9b582006-12-04 15:40:26 +01001824 lc->panic_stack = S390_lowcore.panic_stack;
1825
Michael Holzheuda1cf232006-12-15 17:18:27 +01001826 /* Save prefix page address for dump case */
Heiko Carstensc5dd8582007-03-05 23:35:43 +01001827 dump_prefix_page = (u32)(unsigned long) lc;
Michael Holzheuda1cf232006-12-15 17:18:27 +01001828
Heiko Carstens15e9b582006-12-04 15:40:26 +01001829 /* Disable prefixing */
1830 set_prefix(0);
1831
1832 /* Disable lowcore protection */
1833 __ctl_clear_bit(0,28);
1834
1835 /* Set new machine check handler */
Gerald Schaeferc1821c22007-02-05 21:18:17 +01001836 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001837 S390_lowcore.mcck_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01001838 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01001839
1840 /* Set new program check handler */
Gerald Schaeferc1821c22007-02-05 21:18:17 +01001841 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
Michael Holzheua45e1412006-12-15 17:18:22 +01001842 S390_lowcore.program_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01001843 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01001844
Heiko Carstens15e9b582006-12-04 15:40:26 +01001845 do_reset_calls();
1846}
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001847