]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/s390/char/zcore.c
Merge branch 'oprofile-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-beck.git] / drivers / s390 / char / zcore.c
1 /*
2  * zcore module to export memory content and register sets for creating system
3  * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
4  * dump format as s390 standalone dumps.
5  *
6  * For more information please refer to Documentation/s390/zfcpdump.txt
7  *
8  * Copyright IBM Corp. 2003,2008
9  * Author(s): Michael Holzheu
10  */
11
12 #define KMSG_COMPONENT "zdump"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14
15 #include <linux/init.h>
16 #include <linux/miscdevice.h>
17 #include <linux/debugfs.h>
18 #include <asm/asm-offsets.h>
19 #include <asm/ipl.h>
20 #include <asm/sclp.h>
21 #include <asm/setup.h>
22 #include <asm/sigp.h>
23 #include <asm/uaccess.h>
24 #include <asm/debug.h>
25 #include <asm/processor.h>
26 #include <asm/irqflags.h>
27 #include <asm/checksum.h>
28 #include "sclp.h"
29
30 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
31
32 #define TO_USER         0
33 #define TO_KERNEL       1
34 #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
35
36 enum arch_id {
37         ARCH_S390       = 0,
38         ARCH_S390X      = 1,
39 };
40
41 /* dump system info */
42
43 struct sys_info {
44         enum arch_id     arch;
45         unsigned long    sa_base;
46         u32              sa_size;
47         int              cpu_map[NR_CPUS];
48         unsigned long    mem_size;
49         struct save_area lc_mask;
50 };
51
52 struct ipib_info {
53         unsigned long   ipib;
54         u32             checksum;
55 }  __attribute__((packed));
56
57 static struct sys_info sys_info;
58 static struct debug_info *zcore_dbf;
59 static int hsa_available;
60 static struct dentry *zcore_dir;
61 static struct dentry *zcore_file;
62 static struct dentry *zcore_memmap_file;
63 static struct dentry *zcore_reipl_file;
64 static struct ipl_parameter_block *ipl_block;
65
66 /*
67  * Copy memory from HSA to kernel or user memory (not reentrant):
68  *
69  * @dest:  Kernel or user buffer where memory should be copied to
70  * @src:   Start address within HSA where data should be copied
71  * @count: Size of buffer, which should be copied
72  * @mode:  Either TO_KERNEL or TO_USER
73  */
74 static int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
75 {
76         int offs, blk_num;
77         static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
78
79         if (count == 0)
80                 return 0;
81
82         /* copy first block */
83         offs = 0;
84         if ((src % PAGE_SIZE) != 0) {
85                 blk_num = src / PAGE_SIZE + 2;
86                 if (sclp_sdias_copy(buf, blk_num, 1)) {
87                         TRACE("sclp_sdias_copy() failed\n");
88                         return -EIO;
89                 }
90                 offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
91                 if (mode == TO_USER) {
92                         if (copy_to_user((__force __user void*) dest,
93                                          buf + (src % PAGE_SIZE), offs))
94                                 return -EFAULT;
95                 } else
96                         memcpy(dest, buf + (src % PAGE_SIZE), offs);
97         }
98         if (offs == count)
99                 goto out;
100
101         /* copy middle */
102         for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
103                 blk_num = (src + offs) / PAGE_SIZE + 2;
104                 if (sclp_sdias_copy(buf, blk_num, 1)) {
105                         TRACE("sclp_sdias_copy() failed\n");
106                         return -EIO;
107                 }
108                 if (mode == TO_USER) {
109                         if (copy_to_user((__force __user void*) dest + offs,
110                                          buf, PAGE_SIZE))
111                                 return -EFAULT;
112                 } else
113                         memcpy(dest + offs, buf, PAGE_SIZE);
114         }
115         if (offs == count)
116                 goto out;
117
118         /* copy last block */
119         blk_num = (src + offs) / PAGE_SIZE + 2;
120         if (sclp_sdias_copy(buf, blk_num, 1)) {
121                 TRACE("sclp_sdias_copy() failed\n");
122                 return -EIO;
123         }
124         if (mode == TO_USER) {
125                 if (copy_to_user((__force __user void*) dest + offs, buf,
126                                  PAGE_SIZE))
127                         return -EFAULT;
128         } else
129                 memcpy(dest + offs, buf, count - offs);
130 out:
131         return 0;
132 }
133
134 static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
135 {
136         return memcpy_hsa((void __force *) dest, src, count, TO_USER);
137 }
138
139 static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
140 {
141         return memcpy_hsa(dest, src, count, TO_KERNEL);
142 }
143
144 static int memcpy_real(void *dest, unsigned long src, size_t count)
145 {
146         unsigned long flags;
147         int rc = -EFAULT;
148         register unsigned long _dest asm("2") = (unsigned long) dest;
149         register unsigned long _len1 asm("3") = (unsigned long) count;
150         register unsigned long _src  asm("4") = src;
151         register unsigned long _len2 asm("5") = (unsigned long) count;
152
153         if (count == 0)
154                 return 0;
155         flags = __raw_local_irq_stnsm(0xf8UL); /* switch to real mode */
156         asm volatile (
157                 "0:     mvcle   %1,%2,0x0\n"
158                 "1:     jo      0b\n"
159                 "       lhi     %0,0x0\n"
160                 "2:\n"
161                 EX_TABLE(1b,2b)
162                 : "+d" (rc), "+d" (_dest), "+d" (_src), "+d" (_len1),
163                   "+d" (_len2), "=m" (*((long*)dest))
164                 : "m" (*((long*)src))
165                 : "cc", "memory");
166         __raw_local_irq_ssm(flags);
167
168         return rc;
169 }
170
171 static int memcpy_real_user(void __user *dest, unsigned long src, size_t count)
172 {
173         static char buf[4096];
174         int offs = 0, size;
175
176         while (offs < count) {
177                 size = min(sizeof(buf), count - offs);
178                 if (memcpy_real(buf, src + offs, size))
179                         return -EFAULT;
180                 if (copy_to_user(dest + offs, buf, size))
181                         return -EFAULT;
182                 offs += size;
183         }
184         return 0;
185 }
186
187 static int __init init_cpu_info(enum arch_id arch)
188 {
189         struct save_area *sa;
190
191         /* get info for boot cpu from lowcore, stored in the HSA */
192
193         sa = kmalloc(sizeof(*sa), GFP_KERNEL);
194         if (!sa)
195                 return -ENOMEM;
196         if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
197                 TRACE("could not copy from HSA\n");
198                 kfree(sa);
199                 return -EIO;
200         }
201         zfcpdump_save_areas[0] = sa;
202         return 0;
203 }
204
205 static DEFINE_MUTEX(zcore_mutex);
206
207 #define DUMP_VERSION    0x5
208 #define DUMP_MAGIC      0xa8190173618f23fdULL
209 #define DUMP_ARCH_S390X 2
210 #define DUMP_ARCH_S390  1
211 #define HEADER_SIZE     4096
212
213 /* dump header dumped according to s390 crash dump format */
214
215 struct zcore_header {
216         u64 magic;
217         u32 version;
218         u32 header_size;
219         u32 dump_level;
220         u32 page_size;
221         u64 mem_size;
222         u64 mem_start;
223         u64 mem_end;
224         u32 num_pages;
225         u32 pad1;
226         u64 tod;
227         struct cpuid cpu_id;
228         u32 arch_id;
229         u32 volnr;
230         u32 build_arch;
231         u64 rmem_size;
232         u8 mvdump;
233         u16 cpu_cnt;
234         u16 real_cpu_cnt;
235         u8 end_pad1[0x200-0x061];
236         u64 mvdump_sign;
237         u64 mvdump_zipl_time;
238         u8 end_pad2[0x800-0x210];
239         u32 lc_vec[512];
240 } __attribute__((packed,__aligned__(16)));
241
242 static struct zcore_header zcore_header = {
243         .magic          = DUMP_MAGIC,
244         .version        = DUMP_VERSION,
245         .header_size    = 4096,
246         .dump_level     = 0,
247         .page_size      = PAGE_SIZE,
248         .mem_start      = 0,
249 #ifdef CONFIG_64BIT
250         .build_arch     = DUMP_ARCH_S390X,
251 #else
252         .build_arch     = DUMP_ARCH_S390,
253 #endif
254 };
255
256 /*
257  * Copy lowcore info to buffer. Use map in order to copy only register parts.
258  *
259  * @buf:    User buffer
260  * @sa:     Pointer to save area
261  * @sa_off: Offset in save area to copy
262  * @len:    Number of bytes to copy
263  */
264 static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
265 {
266         int i;
267         char *lc_mask = (char*)&sys_info.lc_mask;
268
269         for (i = 0; i < len; i++) {
270                 if (!lc_mask[i + sa_off])
271                         continue;
272                 if (copy_to_user(buf + i, sa + sa_off + i, 1))
273                         return -EFAULT;
274         }
275         return 0;
276 }
277
278 /*
279  * Copy lowcores info to memory, if necessary
280  *
281  * @buf:   User buffer
282  * @addr:  Start address of buffer in dump memory
283  * @count: Size of buffer
284  */
285 static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
286 {
287         unsigned long end;
288         int i = 0;
289
290         if (count == 0)
291                 return 0;
292
293         end = start + count;
294         while (zfcpdump_save_areas[i]) {
295                 unsigned long cp_start, cp_end; /* copy range */
296                 unsigned long sa_start, sa_end; /* save area range */
297                 unsigned long prefix;
298                 unsigned long sa_off, len, buf_off;
299
300                 prefix = zfcpdump_save_areas[i]->pref_reg;
301                 sa_start = prefix + sys_info.sa_base;
302                 sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
303
304                 if ((end < sa_start) || (start > sa_end))
305                         goto next;
306                 cp_start = max(start, sa_start);
307                 cp_end = min(end, sa_end);
308
309                 buf_off = cp_start - start;
310                 sa_off = cp_start - sa_start;
311                 len = cp_end - cp_start;
312
313                 TRACE("copy_lc for: %lx\n", start);
314                 if (copy_lc(buf + buf_off, zfcpdump_save_areas[i], sa_off, len))
315                         return -EFAULT;
316 next:
317                 i++;
318         }
319         return 0;
320 }
321
322 /*
323  * Read routine for zcore character device
324  * First 4K are dump header
325  * Next 32MB are HSA Memory
326  * Rest is read from absolute Memory
327  */
328 static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
329                           loff_t *ppos)
330 {
331         unsigned long mem_start; /* Start address in memory */
332         size_t mem_offs;         /* Offset in dump memory */
333         size_t hdr_count;        /* Size of header part of output buffer */
334         size_t size;
335         int rc;
336
337         mutex_lock(&zcore_mutex);
338
339         if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
340                 rc = -EINVAL;
341                 goto fail;
342         }
343
344         count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
345
346         /* Copy dump header */
347         if (*ppos < HEADER_SIZE) {
348                 size = min(count, (size_t) (HEADER_SIZE - *ppos));
349                 if (copy_to_user(buf, &zcore_header + *ppos, size)) {
350                         rc = -EFAULT;
351                         goto fail;
352                 }
353                 hdr_count = size;
354                 mem_start = 0;
355         } else {
356                 hdr_count = 0;
357                 mem_start = *ppos - HEADER_SIZE;
358         }
359
360         mem_offs = 0;
361
362         /* Copy from HSA data */
363         if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
364                 size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
365                            - mem_start));
366                 rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
367                 if (rc)
368                         goto fail;
369
370                 mem_offs += size;
371         }
372
373         /* Copy from real mem */
374         size = count - mem_offs - hdr_count;
375         rc = memcpy_real_user(buf + hdr_count + mem_offs, mem_start + mem_offs,
376                               size);
377         if (rc)
378                 goto fail;
379
380         /*
381          * Since s390 dump analysis tools like lcrash or crash
382          * expect register sets in the prefix pages of the cpus,
383          * we copy them into the read buffer, if necessary.
384          * buf + hdr_count: Start of memory part of output buffer
385          * mem_start: Start memory address to copy from
386          * count - hdr_count: Size of memory area to copy
387          */
388         if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
389                 rc = -EFAULT;
390                 goto fail;
391         }
392         *ppos += count;
393 fail:
394         mutex_unlock(&zcore_mutex);
395         return (rc < 0) ? rc : count;
396 }
397
398 static int zcore_open(struct inode *inode, struct file *filp)
399 {
400         if (!hsa_available)
401                 return -ENODATA;
402         else
403                 return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
404 }
405
406 static int zcore_release(struct inode *inode, struct file *filep)
407 {
408         diag308(DIAG308_REL_HSA, NULL);
409         hsa_available = 0;
410         return 0;
411 }
412
413 static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
414 {
415         loff_t rc;
416
417         mutex_lock(&zcore_mutex);
418         switch (orig) {
419         case 0:
420                 file->f_pos = offset;
421                 rc = file->f_pos;
422                 break;
423         case 1:
424                 file->f_pos += offset;
425                 rc = file->f_pos;
426                 break;
427         default:
428                 rc = -EINVAL;
429         }
430         mutex_unlock(&zcore_mutex);
431         return rc;
432 }
433
434 static const struct file_operations zcore_fops = {
435         .owner          = THIS_MODULE,
436         .llseek         = zcore_lseek,
437         .read           = zcore_read,
438         .open           = zcore_open,
439         .release        = zcore_release,
440 };
441
442 static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
443                                  size_t count, loff_t *ppos)
444 {
445         return simple_read_from_buffer(buf, count, ppos, filp->private_data,
446                                        MEMORY_CHUNKS * CHUNK_INFO_SIZE);
447 }
448
449 static int zcore_memmap_open(struct inode *inode, struct file *filp)
450 {
451         int i;
452         char *buf;
453         struct mem_chunk *chunk_array;
454
455         chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
456                               GFP_KERNEL);
457         if (!chunk_array)
458                 return -ENOMEM;
459         detect_memory_layout(chunk_array);
460         buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL);
461         if (!buf) {
462                 kfree(chunk_array);
463                 return -ENOMEM;
464         }
465         for (i = 0; i < MEMORY_CHUNKS; i++) {
466                 sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ",
467                         (unsigned long long) chunk_array[i].addr,
468                         (unsigned long long) chunk_array[i].size);
469                 if (chunk_array[i].size == 0)
470                         break;
471         }
472         kfree(chunk_array);
473         filp->private_data = buf;
474         return 0;
475 }
476
477 static int zcore_memmap_release(struct inode *inode, struct file *filp)
478 {
479         kfree(filp->private_data);
480         return 0;
481 }
482
483 static const struct file_operations zcore_memmap_fops = {
484         .owner          = THIS_MODULE,
485         .read           = zcore_memmap_read,
486         .open           = zcore_memmap_open,
487         .release        = zcore_memmap_release,
488 };
489
490 static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
491                                  size_t count, loff_t *ppos)
492 {
493         if (ipl_block) {
494                 diag308(DIAG308_SET, ipl_block);
495                 diag308(DIAG308_IPL, NULL);
496         }
497         return count;
498 }
499
500 static int zcore_reipl_open(struct inode *inode, struct file *filp)
501 {
502         return 0;
503 }
504
505 static int zcore_reipl_release(struct inode *inode, struct file *filp)
506 {
507         return 0;
508 }
509
510 static const struct file_operations zcore_reipl_fops = {
511         .owner          = THIS_MODULE,
512         .write          = zcore_reipl_write,
513         .open           = zcore_reipl_open,
514         .release        = zcore_reipl_release,
515 };
516
517 #ifdef CONFIG_32BIT
518
519 static void __init set_lc_mask(struct save_area *map)
520 {
521         memset(&map->ext_save, 0xff, sizeof(map->ext_save));
522         memset(&map->timer, 0xff, sizeof(map->timer));
523         memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
524         memset(&map->psw, 0xff, sizeof(map->psw));
525         memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
526         memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
527         memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
528         memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
529         memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
530 }
531
532 #else /* CONFIG_32BIT */
533
534 static void __init set_lc_mask(struct save_area *map)
535 {
536         memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
537         memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
538         memset(&map->psw, 0xff, sizeof(map->psw));
539         memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
540         memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
541         memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
542         memset(&map->timer, 0xff, sizeof(map->timer));
543         memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
544         memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
545         memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
546 }
547
548 #endif /* CONFIG_32BIT */
549
550 /*
551  * Initialize dump globals for a given architecture
552  */
553 static int __init sys_info_init(enum arch_id arch)
554 {
555         int rc;
556
557         switch (arch) {
558         case ARCH_S390X:
559                 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
560                 break;
561         case ARCH_S390:
562                 pr_alert("DETECTED 'S390 (32 bit) OS'\n");
563                 break;
564         default:
565                 pr_alert("0x%x is an unknown architecture.\n",arch);
566                 return -EINVAL;
567         }
568         sys_info.sa_base = SAVE_AREA_BASE;
569         sys_info.sa_size = sizeof(struct save_area);
570         sys_info.arch = arch;
571         set_lc_mask(&sys_info.lc_mask);
572         rc = init_cpu_info(arch);
573         if (rc)
574                 return rc;
575         sys_info.mem_size = real_memory_size;
576
577         return 0;
578 }
579
580 static int __init check_sdias(void)
581 {
582         int rc, act_hsa_size;
583
584         rc = sclp_sdias_blk_count();
585         if (rc < 0) {
586                 TRACE("Could not determine HSA size\n");
587                 return rc;
588         }
589         act_hsa_size = (rc - 1) * PAGE_SIZE;
590         if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
591                 TRACE("HSA size too small: %i\n", act_hsa_size);
592                 return -EINVAL;
593         }
594         return 0;
595 }
596
597 static int __init get_mem_size(unsigned long *mem)
598 {
599         int i;
600         struct mem_chunk *chunk_array;
601
602         chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
603                               GFP_KERNEL);
604         if (!chunk_array)
605                 return -ENOMEM;
606         detect_memory_layout(chunk_array);
607         for (i = 0; i < MEMORY_CHUNKS; i++) {
608                 if (chunk_array[i].size == 0)
609                         break;
610                 *mem += chunk_array[i].size;
611         }
612         kfree(chunk_array);
613         return 0;
614 }
615
616 static int __init zcore_header_init(int arch, struct zcore_header *hdr)
617 {
618         int rc, i;
619         unsigned long memory = 0;
620         u32 prefix;
621
622         if (arch == ARCH_S390X)
623                 hdr->arch_id = DUMP_ARCH_S390X;
624         else
625                 hdr->arch_id = DUMP_ARCH_S390;
626         rc = get_mem_size(&memory);
627         if (rc)
628                 return rc;
629         hdr->mem_size = memory;
630         hdr->rmem_size = memory;
631         hdr->mem_end = sys_info.mem_size;
632         hdr->num_pages = memory / PAGE_SIZE;
633         hdr->tod = get_clock();
634         get_cpu_id(&hdr->cpu_id);
635         for (i = 0; zfcpdump_save_areas[i]; i++) {
636                 prefix = zfcpdump_save_areas[i]->pref_reg;
637                 hdr->real_cpu_cnt++;
638                 if (!prefix)
639                         continue;
640                 hdr->lc_vec[hdr->cpu_cnt] = prefix;
641                 hdr->cpu_cnt++;
642         }
643         return 0;
644 }
645
646 /*
647  * Provide IPL parameter information block from either HSA or memory
648  * for future reipl
649  */
650 static int __init zcore_reipl_init(void)
651 {
652         struct ipib_info ipib_info;
653         int rc;
654
655         rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
656         if (rc)
657                 return rc;
658         if (ipib_info.ipib == 0)
659                 return 0;
660         ipl_block = (void *) __get_free_page(GFP_KERNEL);
661         if (!ipl_block)
662                 return -ENOMEM;
663         if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
664                 rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
665         else
666                 rc = memcpy_real(ipl_block, ipib_info.ipib, PAGE_SIZE);
667         if (rc) {
668                 free_page((unsigned long) ipl_block);
669                 return rc;
670         }
671         if (csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
672             ipib_info.checksum) {
673                 TRACE("Checksum does not match\n");
674                 free_page((unsigned long) ipl_block);
675                 ipl_block = NULL;
676         }
677         return 0;
678 }
679
680 static int __init zcore_init(void)
681 {
682         unsigned char arch;
683         int rc;
684
685         if (ipl_info.type != IPL_TYPE_FCP_DUMP)
686                 return -ENODATA;
687
688         zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
689         debug_register_view(zcore_dbf, &debug_sprintf_view);
690         debug_set_level(zcore_dbf, 6);
691
692         TRACE("devno:  %x\n", ipl_info.data.fcp.dev_id.devno);
693         TRACE("wwpn:   %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
694         TRACE("lun:    %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
695
696         rc = sclp_sdias_init();
697         if (rc)
698                 goto fail;
699
700         rc = check_sdias();
701         if (rc)
702                 goto fail;
703
704         rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
705         if (rc)
706                 goto fail;
707
708 #ifdef CONFIG_64BIT
709         if (arch == ARCH_S390) {
710                 pr_alert("The 64-bit dump tool cannot be used for a "
711                          "32-bit system\n");
712                 rc = -EINVAL;
713                 goto fail;
714         }
715 #else /* CONFIG_64BIT */
716         if (arch == ARCH_S390X) {
717                 pr_alert("The 32-bit dump tool cannot be used for a "
718                          "64-bit system\n");
719                 rc = -EINVAL;
720                 goto fail;
721         }
722 #endif /* CONFIG_64BIT */
723
724         rc = sys_info_init(arch);
725         if (rc)
726                 goto fail;
727
728         rc = zcore_header_init(arch, &zcore_header);
729         if (rc)
730                 goto fail;
731
732         rc = zcore_reipl_init();
733         if (rc)
734                 goto fail;
735
736         zcore_dir = debugfs_create_dir("zcore" , NULL);
737         if (!zcore_dir) {
738                 rc = -ENOMEM;
739                 goto fail;
740         }
741         zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
742                                          &zcore_fops);
743         if (!zcore_file) {
744                 rc = -ENOMEM;
745                 goto fail_dir;
746         }
747         zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
748                                                 NULL, &zcore_memmap_fops);
749         if (!zcore_memmap_file) {
750                 rc = -ENOMEM;
751                 goto fail_file;
752         }
753         zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
754                                                 NULL, &zcore_reipl_fops);
755         if (!zcore_reipl_file) {
756                 rc = -ENOMEM;
757                 goto fail_memmap_file;
758         }
759         hsa_available = 1;
760         return 0;
761
762 fail_memmap_file:
763         debugfs_remove(zcore_memmap_file);
764 fail_file:
765         debugfs_remove(zcore_file);
766 fail_dir:
767         debugfs_remove(zcore_dir);
768 fail:
769         diag308(DIAG308_REL_HSA, NULL);
770         return rc;
771 }
772
773 static void __exit zcore_exit(void)
774 {
775         debug_unregister(zcore_dbf);
776         sclp_sdias_exit();
777         free_page((unsigned long) ipl_block);
778         debugfs_remove(zcore_reipl_file);
779         debugfs_remove(zcore_memmap_file);
780         debugfs_remove(zcore_file);
781         debugfs_remove(zcore_dir);
782         diag308(DIAG308_REL_HSA, NULL);
783 }
784
785 MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
786 MODULE_DESCRIPTION("zcore module for zfcpdump support");
787 MODULE_LICENSE("GPL");
788
789 subsys_initcall(zcore_init);
790 module_exit(zcore_exit);