blob: 50be9d063d686d81579228e954bed09ddc22d786 [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 *
5 * Copyright (C) IBM Corp. 2005,2006
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
9 */
10
11#include <linux/types.h>
12#include <linux/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>
Michael Holzheu46b05d22007-02-21 10:55:21 +010017#include <asm/ipl.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020018#include <asm/smp.h>
19#include <asm/setup.h>
20#include <asm/cpcmd.h>
21#include <asm/cio.h>
Michael Holzheu03a4d202006-12-04 15:39:58 +010022#include <asm/ebcdic.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010023#include <asm/reset.h>
Heiko Carstensab14de62007-02-05 21:18:37 +010024#include <asm/sclp.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020025
26#define IPL_PARM_BLOCK_VERSION 0
Michael Holzheu03a4d202006-12-04 15:39:58 +010027
Michael Holzheu411ed322007-04-27 16:01:49 +020028#define IPL_UNKNOWN_STR "unknown"
29#define IPL_CCW_STR "ccw"
30#define IPL_FCP_STR "fcp"
31#define IPL_FCP_DUMP_STR "fcp_dump"
32#define IPL_NSS_STR "nss"
Heiko Carstens615b04b2007-02-21 10:55:37 +010033
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020034static char *ipl_type_str(enum ipl_type type)
35{
36 switch (type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020037 case IPL_TYPE_CCW:
38 return IPL_CCW_STR;
39 case IPL_TYPE_FCP:
40 return IPL_FCP_STR;
Michael Holzheu411ed322007-04-27 16:01:49 +020041 case IPL_TYPE_FCP_DUMP:
42 return IPL_FCP_DUMP_STR;
Hongjie Yangfe355b72007-02-05 21:18:24 +010043 case IPL_TYPE_NSS:
44 return IPL_NSS_STR;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020045 case IPL_TYPE_UNKNOWN:
46 default:
47 return IPL_UNKNOWN_STR;
48 }
49}
50
Michael Holzheu411ed322007-04-27 16:01:49 +020051enum dump_type {
52 DUMP_TYPE_NONE = 1,
53 DUMP_TYPE_CCW = 2,
54 DUMP_TYPE_FCP = 4,
55};
56
57#define DUMP_NONE_STR "none"
58#define DUMP_CCW_STR "ccw"
59#define DUMP_FCP_STR "fcp"
60
61static char *dump_type_str(enum dump_type type)
62{
63 switch (type) {
64 case DUMP_TYPE_NONE:
65 return DUMP_NONE_STR;
66 case DUMP_TYPE_CCW:
67 return DUMP_CCW_STR;
68 case DUMP_TYPE_FCP:
69 return DUMP_FCP_STR;
70 default:
71 return NULL;
72 }
73}
74
75/*
76 * Must be in data section since the bss section
77 * is not cleared when these are accessed.
78 */
79static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
80u32 ipl_flags __attribute__((__section__(".data"))) = 0;
81
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020082enum ipl_method {
Michael Holzheu411ed322007-04-27 16:01:49 +020083 REIPL_METHOD_CCW_CIO,
84 REIPL_METHOD_CCW_DIAG,
85 REIPL_METHOD_CCW_VM,
86 REIPL_METHOD_FCP_RO_DIAG,
87 REIPL_METHOD_FCP_RW_DIAG,
88 REIPL_METHOD_FCP_RO_VM,
89 REIPL_METHOD_FCP_DUMP,
90 REIPL_METHOD_NSS,
91 REIPL_METHOD_DEFAULT,
92};
93
94enum dump_method {
95 DUMP_METHOD_NONE,
96 DUMP_METHOD_CCW_CIO,
97 DUMP_METHOD_CCW_DIAG,
98 DUMP_METHOD_CCW_VM,
99 DUMP_METHOD_FCP_DIAG,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200100};
101
102enum shutdown_action {
103 SHUTDOWN_REIPL,
104 SHUTDOWN_DUMP,
105 SHUTDOWN_STOP,
106};
107
108#define SHUTDOWN_REIPL_STR "reipl"
109#define SHUTDOWN_DUMP_STR "dump"
110#define SHUTDOWN_STOP_STR "stop"
111
112static char *shutdown_action_str(enum shutdown_action action)
113{
114 switch (action) {
115 case SHUTDOWN_REIPL:
116 return SHUTDOWN_REIPL_STR;
117 case SHUTDOWN_DUMP:
118 return SHUTDOWN_DUMP_STR;
119 case SHUTDOWN_STOP:
120 return SHUTDOWN_STOP_STR;
121 default:
Michael Holzheu2b932932007-02-21 10:55:24 +0100122 return NULL;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200123 }
124}
125
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200126static int diag308_set_works = 0;
127
128static int reipl_capabilities = IPL_TYPE_UNKNOWN;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100129
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200130static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200131static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200132static struct ipl_parameter_block *reipl_block_fcp;
133static struct ipl_parameter_block *reipl_block_ccw;
134
Hongjie Yangfe355b72007-02-05 21:18:24 +0100135static char reipl_nss_name[NSS_NAME_SIZE + 1];
136
Michael Holzheu411ed322007-04-27 16:01:49 +0200137static int dump_capabilities = DUMP_TYPE_NONE;
138static enum dump_type dump_type = DUMP_TYPE_NONE;
139static enum dump_method dump_method = DUMP_METHOD_NONE;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200140static struct ipl_parameter_block *dump_block_fcp;
141static struct ipl_parameter_block *dump_block_ccw;
142
143static enum shutdown_action on_panic_action = SHUTDOWN_STOP;
144
Heiko Carstens05dd2532007-07-10 11:24:09 +0200145static struct sclp_ipl_info sclp_ipl_info;
146
Michael Holzheu46b05d22007-02-21 10:55:21 +0100147int diag308(unsigned long subcode, void *addr)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200148{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200149 register unsigned long _addr asm("0") = (unsigned long) addr;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200150 register unsigned long _rc asm("1") = 0;
151
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200152 asm volatile(
153 " diag %0,%2,0x308\n"
154 "0:\n"
155 EX_TABLE(0b,0b)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200156 : "+d" (_addr), "+d" (_rc)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200157 : "d" (subcode) : "cc", "memory");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200158 return _rc;
159}
Michael Holzheu411ed322007-04-27 16:01:49 +0200160EXPORT_SYMBOL_GPL(diag308);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200161
162/* SYSFS */
163
164#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400165static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
166 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200167 char *page) \
168{ \
169 return sprintf(page, _format, _value); \
170} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400171static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200172 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
173
174#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400175static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
176 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200177 char *page) \
178{ \
179 return sprintf(page, _fmt_out, \
180 (unsigned long long) _value); \
181} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400182static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200184 const char *buf, size_t len) \
185{ \
186 unsigned long long value; \
187 if (sscanf(buf, _fmt_in, &value) != 1) \
188 return -EINVAL; \
189 _value = value; \
190 return len; \
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 | S_IWUSR), \
194 sys_##_prefix##_##_name##_show, \
195 sys_##_prefix##_##_name##_store);
196
Hongjie Yangfe355b72007-02-05 21:18:24 +0100197#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400198static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
199 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100200 char *page) \
201{ \
202 return sprintf(page, _fmt_out, _value); \
203} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400204static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
205 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100206 const char *buf, size_t len) \
207{ \
208 if (sscanf(buf, _fmt_in, _value) != 1) \
209 return -EINVAL; \
210 return len; \
211} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400212static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100213 __ATTR(_name,(S_IRUGO | S_IWUSR), \
214 sys_##_prefix##_##_name##_show, \
215 sys_##_prefix##_##_name##_store);
216
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200217static void make_attrs_ro(struct attribute **attrs)
218{
219 while (*attrs) {
220 (*attrs)->mode = S_IRUGO;
221 attrs++;
222 }
223}
224
225/*
226 * ipl section
227 */
228
Michael Holzheu411ed322007-04-27 16:01:49 +0200229static __init enum ipl_type get_ipl_type(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200230{
231 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
232
Hongjie Yangfe355b72007-02-05 21:18:24 +0100233 if (ipl_flags & IPL_NSS_VALID)
234 return IPL_TYPE_NSS;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200235 if (!(ipl_flags & IPL_DEVNO_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200236 return IPL_TYPE_UNKNOWN;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200237 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200238 return IPL_TYPE_CCW;
239 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
240 return IPL_TYPE_UNKNOWN;
241 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
242 return IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200243 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
244 return IPL_TYPE_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200245 return IPL_TYPE_FCP;
246}
247
Michael Holzheu411ed322007-04-27 16:01:49 +0200248void __init setup_ipl_info(void)
249{
250 ipl_info.type = get_ipl_type();
251 switch (ipl_info.type) {
252 case IPL_TYPE_CCW:
253 ipl_info.data.ccw.dev_id.devno = ipl_devno;
254 ipl_info.data.ccw.dev_id.ssid = 0;
255 break;
256 case IPL_TYPE_FCP:
257 case IPL_TYPE_FCP_DUMP:
258 ipl_info.data.fcp.dev_id.devno =
259 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
260 ipl_info.data.fcp.dev_id.ssid = 0;
261 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
262 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
263 break;
264 case IPL_TYPE_NSS:
265 strncpy(ipl_info.data.nss.name, kernel_nss_name,
266 sizeof(ipl_info.data.nss.name));
267 break;
268 case IPL_TYPE_UNKNOWN:
269 default:
270 /* We have no info to copy */
271 break;
272 }
273}
274
275struct ipl_info ipl_info;
276EXPORT_SYMBOL_GPL(ipl_info);
277
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400278static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
279 char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200280{
Michael Holzheu411ed322007-04-27 16:01:49 +0200281 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200282}
283
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400284static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200285
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400286static ssize_t sys_ipl_device_show(struct kobject *kobj,
287 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200288{
289 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
290
Michael Holzheu411ed322007-04-27 16:01:49 +0200291 switch (ipl_info.type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200292 case IPL_TYPE_CCW:
293 return sprintf(page, "0.0.%04x\n", ipl_devno);
294 case IPL_TYPE_FCP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200295 case IPL_TYPE_FCP_DUMP:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200296 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
297 default:
298 return 0;
299 }
300}
301
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400302static struct kobj_attribute sys_ipl_device_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200303 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
304
Al Viro05bd7112007-07-15 21:01:22 +0100305static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
306 char *buf, loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200307{
308 unsigned int size = IPL_PARMBLOCK_SIZE;
309
310 if (off > size)
311 return 0;
312 if (off + count > size)
313 count = size - off;
314 memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
315 return count;
316}
317
318static struct bin_attribute ipl_parameter_attr = {
319 .attr = {
320 .name = "binary_parameter",
321 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200322 },
323 .size = PAGE_SIZE,
324 .read = &ipl_parameter_read,
325};
326
Al Viro05bd7112007-07-15 21:01:22 +0100327static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
328 char *buf, loff_t off, size_t count)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200329{
330 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
331 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
332
333 if (off > size)
334 return 0;
335 if (off + count > size)
336 count = size - off;
337 memcpy(buf, scp_data + off, count);
338 return count;
339}
340
341static struct bin_attribute ipl_scp_data_attr = {
342 .attr = {
343 .name = "scp_data",
344 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200345 },
346 .size = PAGE_SIZE,
Al Viro05bd7112007-07-15 21:01:22 +0100347 .read = ipl_scp_data_read,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200348};
349
350/* FCP ipl device attributes */
351
352DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
353 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
354DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
355 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
356DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
357 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
358DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
359 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
360
361static struct attribute *ipl_fcp_attrs[] = {
362 &sys_ipl_type_attr.attr,
363 &sys_ipl_device_attr.attr,
364 &sys_ipl_fcp_wwpn_attr.attr,
365 &sys_ipl_fcp_lun_attr.attr,
366 &sys_ipl_fcp_bootprog_attr.attr,
367 &sys_ipl_fcp_br_lba_attr.attr,
368 NULL,
369};
370
371static struct attribute_group ipl_fcp_attr_group = {
372 .attrs = ipl_fcp_attrs,
373};
374
375/* CCW ipl device attributes */
376
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400377static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
378 struct kobj_attribute *attr, char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100379{
380 char loadparm[LOADPARM_LEN + 1] = {};
381
Heiko Carstens05dd2532007-07-10 11:24:09 +0200382 if (!sclp_ipl_info.is_valid)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100383 return sprintf(page, "#unknown#\n");
Heiko Carstens05dd2532007-07-10 11:24:09 +0200384 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100385 EBCASC(loadparm, LOADPARM_LEN);
386 strstrip(loadparm);
387 return sprintf(page, "%s\n", loadparm);
388}
389
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400390static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
Michael Holzheu03a4d202006-12-04 15:39:58 +0100391 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
392
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200393static struct attribute *ipl_ccw_attrs[] = {
394 &sys_ipl_type_attr.attr,
395 &sys_ipl_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100396 &sys_ipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200397 NULL,
398};
399
400static struct attribute_group ipl_ccw_attr_group = {
401 .attrs = ipl_ccw_attrs,
402};
403
Hongjie Yangfe355b72007-02-05 21:18:24 +0100404/* NSS ipl device attributes */
405
406DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
407
408static struct attribute *ipl_nss_attrs[] = {
409 &sys_ipl_type_attr.attr,
410 &sys_ipl_nss_name_attr.attr,
411 NULL,
412};
413
414static struct attribute_group ipl_nss_attr_group = {
415 .attrs = ipl_nss_attrs,
416};
417
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200418/* UNKNOWN ipl device attributes */
419
420static struct attribute *ipl_unknown_attrs[] = {
421 &sys_ipl_type_attr.attr,
422 NULL,
423};
424
425static struct attribute_group ipl_unknown_attr_group = {
426 .attrs = ipl_unknown_attrs,
427};
428
Greg Kroah-Hartman3514fac2007-10-16 10:11:44 -0600429static decl_subsys(ipl, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200430
431/*
432 * reipl section
433 */
434
435/* FCP reipl device attributes */
436
437DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
438 reipl_block_fcp->ipl_info.fcp.wwpn);
439DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
440 reipl_block_fcp->ipl_info.fcp.lun);
441DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
442 reipl_block_fcp->ipl_info.fcp.bootprog);
443DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
444 reipl_block_fcp->ipl_info.fcp.br_lba);
445DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
446 reipl_block_fcp->ipl_info.fcp.devno);
447
448static struct attribute *reipl_fcp_attrs[] = {
449 &sys_reipl_fcp_device_attr.attr,
450 &sys_reipl_fcp_wwpn_attr.attr,
451 &sys_reipl_fcp_lun_attr.attr,
452 &sys_reipl_fcp_bootprog_attr.attr,
453 &sys_reipl_fcp_br_lba_attr.attr,
454 NULL,
455};
456
457static struct attribute_group reipl_fcp_attr_group = {
458 .name = IPL_FCP_STR,
459 .attrs = reipl_fcp_attrs,
460};
461
462/* CCW reipl device attributes */
463
464DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
465 reipl_block_ccw->ipl_info.ccw.devno);
466
Michael Holzheu03a4d202006-12-04 15:39:58 +0100467static void reipl_get_ascii_loadparm(char *loadparm)
468{
469 memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
470 LOADPARM_LEN);
471 EBCASC(loadparm, LOADPARM_LEN);
472 loadparm[LOADPARM_LEN] = 0;
473 strstrip(loadparm);
474}
475
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400476static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
477 struct kobj_attribute *attr, char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100478{
479 char buf[LOADPARM_LEN + 1];
480
481 reipl_get_ascii_loadparm(buf);
482 return sprintf(page, "%s\n", buf);
483}
484
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400485static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
486 struct kobj_attribute *attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100487 const char *buf, size_t len)
488{
489 int i, lp_len;
490
491 /* ignore trailing newline */
492 lp_len = len;
493 if ((len > 0) && (buf[len - 1] == '\n'))
494 lp_len--;
495 /* loadparm can have max 8 characters and must not start with a blank */
496 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
497 return -EINVAL;
498 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
499 for (i = 0; i < lp_len; i++) {
500 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
501 (buf[i] == '.'))
502 continue;
503 return -EINVAL;
504 }
505 /* initialize loadparm with blanks */
506 memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
507 /* copy and convert to ebcdic */
508 memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
509 ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
510 return len;
511}
512
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400513static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
Michael Holzheu03a4d202006-12-04 15:39:58 +0100514 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
515 reipl_ccw_loadparm_store);
516
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200517static struct attribute *reipl_ccw_attrs[] = {
518 &sys_reipl_ccw_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100519 &sys_reipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200520 NULL,
521};
522
523static struct attribute_group reipl_ccw_attr_group = {
524 .name = IPL_CCW_STR,
525 .attrs = reipl_ccw_attrs,
526};
527
Hongjie Yangfe355b72007-02-05 21:18:24 +0100528
529/* NSS reipl device attributes */
530
531DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
532
533static struct attribute *reipl_nss_attrs[] = {
534 &sys_reipl_nss_name_attr.attr,
535 NULL,
536};
537
538static struct attribute_group reipl_nss_attr_group = {
539 .name = IPL_NSS_STR,
540 .attrs = reipl_nss_attrs,
541};
542
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200543/* reipl type */
544
545static int reipl_set_type(enum ipl_type type)
546{
547 if (!(reipl_capabilities & type))
548 return -EINVAL;
549
550 switch(type) {
551 case IPL_TYPE_CCW:
552 if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200553 reipl_method = REIPL_METHOD_CCW_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200554 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200555 reipl_method = REIPL_METHOD_CCW_CIO;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200556 break;
557 case IPL_TYPE_FCP:
558 if (diag308_set_works)
Michael Holzheu411ed322007-04-27 16:01:49 +0200559 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200560 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200561 reipl_method = REIPL_METHOD_FCP_RO_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200562 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200563 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
564 break;
565 case IPL_TYPE_FCP_DUMP:
566 reipl_method = REIPL_METHOD_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200567 break;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100568 case IPL_TYPE_NSS:
Michael Holzheu411ed322007-04-27 16:01:49 +0200569 reipl_method = REIPL_METHOD_NSS;
570 break;
571 case IPL_TYPE_UNKNOWN:
572 reipl_method = REIPL_METHOD_DEFAULT;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100573 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200574 default:
Michael Holzheu411ed322007-04-27 16:01:49 +0200575 BUG();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200576 }
577 reipl_type = type;
578 return 0;
579}
580
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400581static ssize_t reipl_type_show(struct kobject *kobj,
582 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200583{
584 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
585}
586
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400587static ssize_t reipl_type_store(struct kobject *kobj,
588 struct kobj_attribute *attr,
589 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200590{
591 int rc = -EINVAL;
592
593 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
594 rc = reipl_set_type(IPL_TYPE_CCW);
595 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
596 rc = reipl_set_type(IPL_TYPE_FCP);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100597 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
598 rc = reipl_set_type(IPL_TYPE_NSS);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200599 return (rc != 0) ? rc : len;
600}
601
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400602static struct kobj_attribute reipl_type_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200603 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
604
Greg Kroah-Hartman3514fac2007-10-16 10:11:44 -0600605static decl_subsys(reipl, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200606
607/*
608 * dump section
609 */
610
611/* FCP dump device attributes */
612
613DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
614 dump_block_fcp->ipl_info.fcp.wwpn);
615DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
616 dump_block_fcp->ipl_info.fcp.lun);
617DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
618 dump_block_fcp->ipl_info.fcp.bootprog);
619DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
620 dump_block_fcp->ipl_info.fcp.br_lba);
621DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
622 dump_block_fcp->ipl_info.fcp.devno);
623
624static struct attribute *dump_fcp_attrs[] = {
625 &sys_dump_fcp_device_attr.attr,
626 &sys_dump_fcp_wwpn_attr.attr,
627 &sys_dump_fcp_lun_attr.attr,
628 &sys_dump_fcp_bootprog_attr.attr,
629 &sys_dump_fcp_br_lba_attr.attr,
630 NULL,
631};
632
633static struct attribute_group dump_fcp_attr_group = {
634 .name = IPL_FCP_STR,
635 .attrs = dump_fcp_attrs,
636};
637
638/* CCW dump device attributes */
639
640DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
641 dump_block_ccw->ipl_info.ccw.devno);
642
643static struct attribute *dump_ccw_attrs[] = {
644 &sys_dump_ccw_device_attr.attr,
645 NULL,
646};
647
648static struct attribute_group dump_ccw_attr_group = {
649 .name = IPL_CCW_STR,
650 .attrs = dump_ccw_attrs,
651};
652
653/* dump type */
654
Michael Holzheu411ed322007-04-27 16:01:49 +0200655static int dump_set_type(enum dump_type type)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200656{
657 if (!(dump_capabilities & type))
658 return -EINVAL;
659 switch(type) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200660 case DUMP_TYPE_CCW:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200661 if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200662 dump_method = DUMP_METHOD_CCW_VM;
Michael Holzheue3d36832007-10-22 12:52:43 +0200663 else if (diag308_set_works)
664 dump_method = DUMP_METHOD_CCW_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200665 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200666 dump_method = DUMP_METHOD_CCW_CIO;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200667 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200668 case DUMP_TYPE_FCP:
669 dump_method = DUMP_METHOD_FCP_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200670 break;
671 default:
Michael Holzheu411ed322007-04-27 16:01:49 +0200672 dump_method = DUMP_METHOD_NONE;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200673 }
674 dump_type = type;
675 return 0;
676}
677
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400678static ssize_t dump_type_show(struct kobject *kobj,
679 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200680{
Michael Holzheu411ed322007-04-27 16:01:49 +0200681 return sprintf(page, "%s\n", dump_type_str(dump_type));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200682}
683
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400684static ssize_t dump_type_store(struct kobject *kobj,
685 struct kobj_attribute *attr,
686 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200687{
688 int rc = -EINVAL;
689
Michael Holzheu411ed322007-04-27 16:01:49 +0200690 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
691 rc = dump_set_type(DUMP_TYPE_NONE);
692 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
693 rc = dump_set_type(DUMP_TYPE_CCW);
694 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
695 rc = dump_set_type(DUMP_TYPE_FCP);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200696 return (rc != 0) ? rc : len;
697}
698
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400699static struct kobj_attribute dump_type_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200700 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
701
Greg Kroah-Hartman3514fac2007-10-16 10:11:44 -0600702static decl_subsys(dump, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200703
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200704/*
705 * Shutdown actions section
706 */
707
Greg Kroah-Hartman3514fac2007-10-16 10:11:44 -0600708static decl_subsys(shutdown_actions, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200709
710/* on panic */
711
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400712static ssize_t on_panic_show(struct kobject *kobj,
713 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200714{
715 return sprintf(page, "%s\n", shutdown_action_str(on_panic_action));
716}
717
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400718static ssize_t on_panic_store(struct kobject *kobj,
719 struct kobj_attribute *attr,
720 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200721{
722 if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0)
723 on_panic_action = SHUTDOWN_REIPL;
724 else if (strncmp(buf, SHUTDOWN_DUMP_STR,
725 strlen(SHUTDOWN_DUMP_STR)) == 0)
726 on_panic_action = SHUTDOWN_DUMP;
727 else if (strncmp(buf, SHUTDOWN_STOP_STR,
728 strlen(SHUTDOWN_STOP_STR)) == 0)
729 on_panic_action = SHUTDOWN_STOP;
730 else
731 return -EINVAL;
732
733 return len;
734}
735
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400736static struct kobj_attribute on_panic_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200737 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
738
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200739void do_reipl(void)
740{
741 struct ccw_dev_id devid;
742 static char buf[100];
Michael Holzheu03a4d202006-12-04 15:39:58 +0100743 char loadparm[LOADPARM_LEN + 1];
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200744
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200745 switch (reipl_method) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200746 case REIPL_METHOD_CCW_CIO:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200747 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
Michael Holzheu411ed322007-04-27 16:01:49 +0200748 if (ipl_info.type == IPL_TYPE_CCW && devid.devno == ipl_devno)
Michael Holzheu5986b0e2006-12-04 15:40:13 +0100749 diag308(DIAG308_IPL, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200750 devid.ssid = 0;
751 reipl_ccw_dev(&devid);
752 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200753 case REIPL_METHOD_CCW_VM:
Michael Holzheu58be9442006-12-15 17:18:25 +0100754 reipl_get_ascii_loadparm(loadparm);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100755 if (strlen(loadparm) == 0)
Michael Holzheu65171562007-10-12 16:11:42 +0200756 sprintf(buf, "IPL %X CLEAR",
Michael Holzheu03a4d202006-12-04 15:39:58 +0100757 reipl_block_ccw->ipl_info.ccw.devno);
758 else
Michael Holzheu65171562007-10-12 16:11:42 +0200759 sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
Michael Holzheu03a4d202006-12-04 15:39:58 +0100760 reipl_block_ccw->ipl_info.ccw.devno, loadparm);
Heiko Carstens740b5702006-12-04 15:40:30 +0100761 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200762 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200763 case REIPL_METHOD_CCW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200764 diag308(DIAG308_SET, reipl_block_ccw);
765 diag308(DIAG308_IPL, NULL);
766 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200767 case REIPL_METHOD_FCP_RW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200768 diag308(DIAG308_SET, reipl_block_fcp);
769 diag308(DIAG308_IPL, NULL);
770 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200771 case REIPL_METHOD_FCP_RO_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200772 diag308(DIAG308_IPL, NULL);
773 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200774 case REIPL_METHOD_FCP_RO_VM:
Heiko Carstens740b5702006-12-04 15:40:30 +0100775 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200776 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200777 case REIPL_METHOD_NSS:
Hongjie Yangfe355b72007-02-05 21:18:24 +0100778 sprintf(buf, "IPL %s", reipl_nss_name);
779 __cpcmd(buf, NULL, 0, NULL);
780 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200781 case REIPL_METHOD_DEFAULT:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200782 if (MACHINE_IS_VM)
Heiko Carstens740b5702006-12-04 15:40:30 +0100783 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200784 diag308(DIAG308_IPL, NULL);
785 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200786 case REIPL_METHOD_FCP_DUMP:
787 default:
788 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200789 }
Michael Holzheu3902e472006-12-04 15:40:05 +0100790 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200791}
792
793static void do_dump(void)
794{
795 struct ccw_dev_id devid;
796 static char buf[100];
797
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200798 switch (dump_method) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200799 case DUMP_METHOD_CCW_CIO:
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100800 smp_send_stop();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200801 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
802 devid.ssid = 0;
803 reipl_ccw_dev(&devid);
804 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200805 case DUMP_METHOD_CCW_VM:
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100806 smp_send_stop();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200807 sprintf(buf, "STORE STATUS");
Heiko Carstens740b5702006-12-04 15:40:30 +0100808 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200809 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
Heiko Carstens740b5702006-12-04 15:40:30 +0100810 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200811 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200812 case DUMP_METHOD_CCW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200813 diag308(DIAG308_SET, dump_block_ccw);
814 diag308(DIAG308_DUMP, NULL);
815 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200816 case DUMP_METHOD_FCP_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200817 diag308(DIAG308_SET, dump_block_fcp);
818 diag308(DIAG308_DUMP, NULL);
819 break;
Michael Holzheu411ed322007-04-27 16:01:49 +0200820 case DUMP_METHOD_NONE:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200821 default:
822 return;
823 }
824 printk(KERN_EMERG "Dump failed!\n");
825}
826
827/* init functions */
828
829static int __init ipl_register_fcp_files(void)
830{
831 int rc;
832
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200833 rc = sysfs_create_group(&ipl_subsys.kobj,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200834 &ipl_fcp_attr_group);
835 if (rc)
836 goto out;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200837 rc = sysfs_create_bin_file(&ipl_subsys.kobj,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200838 &ipl_parameter_attr);
839 if (rc)
840 goto out_ipl_parm;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200841 rc = sysfs_create_bin_file(&ipl_subsys.kobj,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200842 &ipl_scp_data_attr);
843 if (!rc)
844 goto out;
845
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200846 sysfs_remove_bin_file(&ipl_subsys.kobj, &ipl_parameter_attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200847
848out_ipl_parm:
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200849 sysfs_remove_group(&ipl_subsys.kobj, &ipl_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200850out:
851 return rc;
852}
853
854static int __init ipl_init(void)
855{
856 int rc;
857
858 rc = firmware_register(&ipl_subsys);
859 if (rc)
860 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +0200861 switch (ipl_info.type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200862 case IPL_TYPE_CCW:
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200863 rc = sysfs_create_group(&ipl_subsys.kobj,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200864 &ipl_ccw_attr_group);
865 break;
866 case IPL_TYPE_FCP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200867 case IPL_TYPE_FCP_DUMP:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200868 rc = ipl_register_fcp_files();
869 break;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100870 case IPL_TYPE_NSS:
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200871 rc = sysfs_create_group(&ipl_subsys.kobj,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100872 &ipl_nss_attr_group);
873 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200874 default:
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200875 rc = sysfs_create_group(&ipl_subsys.kobj,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200876 &ipl_unknown_attr_group);
877 break;
878 }
879 if (rc)
880 firmware_unregister(&ipl_subsys);
881 return rc;
882}
883
884static void __init reipl_probe(void)
885{
886 void *buffer;
887
888 buffer = (void *) get_zeroed_page(GFP_KERNEL);
889 if (!buffer)
890 return;
891 if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
892 diag308_set_works = 1;
893 free_page((unsigned long)buffer);
894}
895
Hongjie Yangfe355b72007-02-05 21:18:24 +0100896static int __init reipl_nss_init(void)
897{
898 int rc;
899
900 if (!MACHINE_IS_VM)
901 return 0;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200902 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_nss_attr_group);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100903 if (rc)
904 return rc;
905 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
906 reipl_capabilities |= IPL_TYPE_NSS;
907 return 0;
908}
909
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200910static int __init reipl_ccw_init(void)
911{
912 int rc;
913
914 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
915 if (!reipl_block_ccw)
916 return -ENOMEM;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200917 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_ccw_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200918 if (rc) {
919 free_page((unsigned long)reipl_block_ccw);
920 return rc;
921 }
922 reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
923 reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +0100924 reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200925 reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
Michael Holzheu03a4d202006-12-04 15:39:58 +0100926 /* check if read scp info worked and set loadparm */
Heiko Carstens05dd2532007-07-10 11:24:09 +0200927 if (sclp_ipl_info.is_valid)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100928 memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
Heiko Carstens05dd2532007-07-10 11:24:09 +0200929 &sclp_ipl_info.loadparm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100930 else
931 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
932 memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
933 LOADPARM_LEN);
934 /* FIXME: check for diag308_set_works when enabling diag ccw reipl */
935 if (!MACHINE_IS_VM)
936 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
Michael Holzheu411ed322007-04-27 16:01:49 +0200937 if (ipl_info.type == IPL_TYPE_CCW)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200938 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
939 reipl_capabilities |= IPL_TYPE_CCW;
940 return 0;
941}
942
943static int __init reipl_fcp_init(void)
944{
945 int rc;
946
Michael Holzheu411ed322007-04-27 16:01:49 +0200947 if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200948 return 0;
Michael Holzheu411ed322007-04-27 16:01:49 +0200949 if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200950 make_attrs_ro(reipl_fcp_attrs);
951
952 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
953 if (!reipl_block_fcp)
954 return -ENOMEM;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +0200955 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200956 if (rc) {
957 free_page((unsigned long)reipl_block_fcp);
958 return rc;
959 }
Michael Holzheu411ed322007-04-27 16:01:49 +0200960 if (ipl_info.type == IPL_TYPE_FCP) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200961 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
962 } else {
963 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
964 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +0100965 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200966 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
967 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
968 }
969 reipl_capabilities |= IPL_TYPE_FCP;
970 return 0;
971}
972
973static int __init reipl_init(void)
974{
975 int rc;
976
977 rc = firmware_register(&reipl_subsys);
978 if (rc)
979 return rc;
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400980 rc = sysfs_create_file(&reipl_subsys.kobj, &reipl_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200981 if (rc) {
982 firmware_unregister(&reipl_subsys);
983 return rc;
984 }
985 rc = reipl_ccw_init();
986 if (rc)
987 return rc;
988 rc = reipl_fcp_init();
989 if (rc)
990 return rc;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100991 rc = reipl_nss_init();
992 if (rc)
993 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +0200994 rc = reipl_set_type(ipl_info.type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200995 if (rc)
996 return rc;
997 return 0;
998}
999
1000static int __init dump_ccw_init(void)
1001{
1002 int rc;
1003
1004 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1005 if (!dump_block_ccw)
1006 return -ENOMEM;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +02001007 rc = sysfs_create_group(&dump_subsys.kobj, &dump_ccw_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001008 if (rc) {
1009 free_page((unsigned long)dump_block_ccw);
1010 return rc;
1011 }
1012 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1013 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001014 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001015 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
Michael Holzheu411ed322007-04-27 16:01:49 +02001016 dump_capabilities |= DUMP_TYPE_CCW;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001017 return 0;
1018}
1019
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001020static int __init dump_fcp_init(void)
1021{
1022 int rc;
1023
Heiko Carstens05dd2532007-07-10 11:24:09 +02001024 if (!sclp_ipl_info.has_dump)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001025 return 0; /* LDIPL DUMP is not installed */
1026 if (!diag308_set_works)
1027 return 0;
1028 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1029 if (!dump_block_fcp)
1030 return -ENOMEM;
Cornelia Huck0b0bb3c2007-05-10 15:45:41 +02001031 rc = sysfs_create_group(&dump_subsys.kobj, &dump_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001032 if (rc) {
1033 free_page((unsigned long)dump_block_fcp);
1034 return rc;
1035 }
1036 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1037 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001038 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001039 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1040 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
Michael Holzheu411ed322007-04-27 16:01:49 +02001041 dump_capabilities |= DUMP_TYPE_FCP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001042 return 0;
1043}
1044
1045#define SHUTDOWN_ON_PANIC_PRIO 0
1046
1047static int shutdown_on_panic_notify(struct notifier_block *self,
1048 unsigned long event, void *data)
1049{
1050 if (on_panic_action == SHUTDOWN_DUMP)
1051 do_dump();
1052 else if (on_panic_action == SHUTDOWN_REIPL)
1053 do_reipl();
1054 return NOTIFY_OK;
1055}
1056
1057static struct notifier_block shutdown_on_panic_nb = {
1058 .notifier_call = shutdown_on_panic_notify,
1059 .priority = SHUTDOWN_ON_PANIC_PRIO
1060};
1061
1062static int __init dump_init(void)
1063{
1064 int rc;
1065
1066 rc = firmware_register(&dump_subsys);
1067 if (rc)
1068 return rc;
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001069 rc = sysfs_create_file(&dump_subsys.kobj, &dump_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001070 if (rc) {
1071 firmware_unregister(&dump_subsys);
1072 return rc;
1073 }
1074 rc = dump_ccw_init();
1075 if (rc)
1076 return rc;
1077 rc = dump_fcp_init();
1078 if (rc)
1079 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001080 dump_set_type(DUMP_TYPE_NONE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001081 return 0;
1082}
1083
1084static int __init shutdown_actions_init(void)
1085{
1086 int rc;
1087
1088 rc = firmware_register(&shutdown_actions_subsys);
1089 if (rc)
1090 return rc;
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001091 rc = sysfs_create_file(&shutdown_actions_subsys.kobj, &on_panic_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001092 if (rc) {
1093 firmware_unregister(&shutdown_actions_subsys);
1094 return rc;
1095 }
1096 atomic_notifier_chain_register(&panic_notifier_list,
1097 &shutdown_on_panic_nb);
1098 return 0;
1099}
1100
1101static int __init s390_ipl_init(void)
1102{
1103 int rc;
1104
Heiko Carstens05dd2532007-07-10 11:24:09 +02001105 sclp_get_ipl_info(&sclp_ipl_info);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001106 reipl_probe();
1107 rc = ipl_init();
1108 if (rc)
1109 return rc;
1110 rc = reipl_init();
1111 if (rc)
1112 return rc;
1113 rc = dump_init();
1114 if (rc)
1115 return rc;
1116 rc = shutdown_actions_init();
1117 if (rc)
1118 return rc;
1119 return 0;
1120}
1121
1122__initcall(s390_ipl_init);
Heiko Carstens15e9b582006-12-04 15:40:26 +01001123
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001124void __init ipl_save_parameters(void)
1125{
1126 struct cio_iplinfo iplinfo;
1127 unsigned int *ipl_ptr;
1128 void *src, *dst;
1129
1130 if (cio_get_iplinfo(&iplinfo))
1131 return;
1132
1133 ipl_devno = iplinfo.devno;
1134 ipl_flags |= IPL_DEVNO_VALID;
1135 if (!iplinfo.is_qdio)
1136 return;
1137 ipl_flags |= IPL_PARMBLOCK_VALID;
1138 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1139 src = (void *)(unsigned long)*ipl_ptr;
1140 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1141 memmove(dst, src, PAGE_SIZE);
1142 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1143}
1144
Heiko Carstens15e9b582006-12-04 15:40:26 +01001145static LIST_HEAD(rcall);
1146static DEFINE_MUTEX(rcall_mutex);
1147
1148void register_reset_call(struct reset_call *reset)
1149{
1150 mutex_lock(&rcall_mutex);
1151 list_add(&reset->list, &rcall);
1152 mutex_unlock(&rcall_mutex);
1153}
1154EXPORT_SYMBOL_GPL(register_reset_call);
1155
1156void unregister_reset_call(struct reset_call *reset)
1157{
1158 mutex_lock(&rcall_mutex);
1159 list_del(&reset->list);
1160 mutex_unlock(&rcall_mutex);
1161}
1162EXPORT_SYMBOL_GPL(unregister_reset_call);
1163
1164static void do_reset_calls(void)
1165{
1166 struct reset_call *reset;
1167
1168 list_for_each_entry(reset, &rcall, list)
1169 reset->fn();
1170}
1171
Heiko Carstensc5dd8582007-03-05 23:35:43 +01001172u32 dump_prefix_page;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001173
1174void s390_reset_system(void)
1175{
1176 struct _lowcore *lc;
1177
Heiko Carstens15e9b582006-12-04 15:40:26 +01001178 lc = (struct _lowcore *)(unsigned long) store_prefix();
Michael Holzheua45e1412006-12-15 17:18:22 +01001179
1180 /* Stack for interrupt/machine check handler */
Heiko Carstens15e9b582006-12-04 15:40:26 +01001181 lc->panic_stack = S390_lowcore.panic_stack;
1182
Michael Holzheuda1cf232006-12-15 17:18:27 +01001183 /* Save prefix page address for dump case */
Heiko Carstensc5dd8582007-03-05 23:35:43 +01001184 dump_prefix_page = (u32)(unsigned long) lc;
Michael Holzheuda1cf232006-12-15 17:18:27 +01001185
Heiko Carstens15e9b582006-12-04 15:40:26 +01001186 /* Disable prefixing */
1187 set_prefix(0);
1188
1189 /* Disable lowcore protection */
1190 __ctl_clear_bit(0,28);
1191
1192 /* Set new machine check handler */
Gerald Schaeferc1821c22007-02-05 21:18:17 +01001193 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001194 S390_lowcore.mcck_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01001195 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01001196
1197 /* Set new program check handler */
Gerald Schaeferc1821c22007-02-05 21:18:17 +01001198 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
Michael Holzheua45e1412006-12-15 17:18:22 +01001199 S390_lowcore.program_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01001200 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01001201
Heiko Carstens15e9b582006-12-04 15:40:26 +01001202 do_reset_calls();
1203}