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