zcore.c 18.3 KB
Newer Older
M
Michael Holzheu 已提交
1 2 3 4 5 6 7
/*
 * zcore module to export memory content and register sets for creating system
 * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
 * dump format as s390 standalone dumps.
 *
 * For more information please refer to Documentation/s390/zfcpdump.txt
 *
8
 * Copyright IBM Corp. 2003, 2008
M
Michael Holzheu 已提交
9 10 11
 * Author(s): Michael Holzheu
 */

12 13 14
#define KMSG_COMPONENT "zdump"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt

M
Michael Holzheu 已提交
15
#include <linux/init.h>
16
#include <linux/slab.h>
M
Michael Holzheu 已提交
17 18
#include <linux/miscdevice.h>
#include <linux/debugfs.h>
19
#include <linux/module.h>
20
#include <asm/asm-offsets.h>
M
Michael Holzheu 已提交
21 22 23 24 25 26 27
#include <asm/ipl.h>
#include <asm/sclp.h>
#include <asm/setup.h>
#include <asm/uaccess.h>
#include <asm/debug.h>
#include <asm/processor.h>
#include <asm/irqflags.h>
28
#include <asm/checksum.h>
H
Heiko Carstens 已提交
29
#include "sclp.h"
M
Michael Holzheu 已提交
30 31 32 33 34

#define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)

#define TO_USER		0
#define TO_KERNEL	1
35
#define CHUNK_INFO_SIZE	34 /* 2 16-byte char, each followed by blank */
M
Michael Holzheu 已提交
36 37 38 39 40 41 42 43 44

enum arch_id {
	ARCH_S390	= 0,
	ARCH_S390X	= 1,
};

/* dump system info */

struct sys_info {
45 46 47 48 49 50
	enum arch_id	 arch;
	unsigned long	 sa_base;
	u32		 sa_size;
	int		 cpu_map[NR_CPUS];
	unsigned long	 mem_size;
	struct save_area lc_mask;
M
Michael Holzheu 已提交
51 52
};

F
Frank Munzert 已提交
53 54 55 56 57
struct ipib_info {
	unsigned long	ipib;
	u32		checksum;
}  __attribute__((packed));

M
Michael Holzheu 已提交
58 59 60 61 62
static struct sys_info sys_info;
static struct debug_info *zcore_dbf;
static int hsa_available;
static struct dentry *zcore_dir;
static struct dentry *zcore_file;
63
static struct dentry *zcore_memmap_file;
F
Frank Munzert 已提交
64
static struct dentry *zcore_reipl_file;
M
Michael Holzheu 已提交
65
static struct dentry *zcore_hsa_file;
F
Frank Munzert 已提交
66
static struct ipl_parameter_block *ipl_block;
M
Michael Holzheu 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80

/*
 * Copy memory from HSA to kernel or user memory (not reentrant):
 *
 * @dest:  Kernel or user buffer where memory should be copied to
 * @src:   Start address within HSA where data should be copied
 * @count: Size of buffer, which should be copied
 * @mode:  Either TO_KERNEL or TO_USER
 */
static int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
{
	int offs, blk_num;
	static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));

M
Michael Holzheu 已提交
81 82
	if (!hsa_available)
		return -ENODATA;
M
Michael Holzheu 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
	if (count == 0)
		return 0;

	/* copy first block */
	offs = 0;
	if ((src % PAGE_SIZE) != 0) {
		blk_num = src / PAGE_SIZE + 2;
		if (sclp_sdias_copy(buf, blk_num, 1)) {
			TRACE("sclp_sdias_copy() failed\n");
			return -EIO;
		}
		offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
		if (mode == TO_USER) {
			if (copy_to_user((__force __user void*) dest,
					 buf + (src % PAGE_SIZE), offs))
				return -EFAULT;
		} else
			memcpy(dest, buf + (src % PAGE_SIZE), offs);
	}
	if (offs == count)
		goto out;

	/* copy middle */
	for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
		blk_num = (src + offs) / PAGE_SIZE + 2;
		if (sclp_sdias_copy(buf, blk_num, 1)) {
			TRACE("sclp_sdias_copy() failed\n");
			return -EIO;
		}
		if (mode == TO_USER) {
			if (copy_to_user((__force __user void*) dest + offs,
					 buf, PAGE_SIZE))
				return -EFAULT;
		} else
			memcpy(dest + offs, buf, PAGE_SIZE);
	}
	if (offs == count)
		goto out;

	/* copy last block */
	blk_num = (src + offs) / PAGE_SIZE + 2;
	if (sclp_sdias_copy(buf, blk_num, 1)) {
		TRACE("sclp_sdias_copy() failed\n");
		return -EIO;
	}
	if (mode == TO_USER) {
		if (copy_to_user((__force __user void*) dest + offs, buf,
				 PAGE_SIZE))
			return -EFAULT;
	} else
		memcpy(dest + offs, buf, count - offs);
out:
	return 0;
}

static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
{
	return memcpy_hsa((void __force *) dest, src, count, TO_USER);
}

static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
{
	return memcpy_hsa(dest, src, count, TO_KERNEL);
}

static int __init init_cpu_info(enum arch_id arch)
{
150
	struct save_area *sa;
M
Michael Holzheu 已提交
151 152 153 154

	/* get info for boot cpu from lowcore, stored in the HSA */

	sa = kmalloc(sizeof(*sa), GFP_KERNEL);
155
	if (!sa)
M
Michael Holzheu 已提交
156 157
		return -ENOMEM;
	if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
158
		TRACE("could not copy from HSA\n");
M
Michael Holzheu 已提交
159 160 161 162 163 164 165 166 167
		kfree(sa);
		return -EIO;
	}
	zfcpdump_save_areas[0] = sa;
	return 0;
}

static DEFINE_MUTEX(zcore_mutex);

168
#define DUMP_VERSION	0x5
M
Michael Holzheu 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#define DUMP_MAGIC	0xa8190173618f23fdULL
#define DUMP_ARCH_S390X	2
#define DUMP_ARCH_S390	1
#define HEADER_SIZE	4096

/* dump header dumped according to s390 crash dump format */

struct zcore_header {
	u64 magic;
	u32 version;
	u32 header_size;
	u32 dump_level;
	u32 page_size;
	u64 mem_size;
	u64 mem_start;
	u64 mem_end;
	u32 num_pages;
	u32 pad1;
	u64 tod;
188
	struct cpuid cpu_id;
M
Michael Holzheu 已提交
189
	u32 arch_id;
M
Michael Holzheu 已提交
190
	u32 volnr;
M
Michael Holzheu 已提交
191
	u32 build_arch;
M
Michael Holzheu 已提交
192
	u64 rmem_size;
193 194 195 196 197 198 199 200
	u8 mvdump;
	u16 cpu_cnt;
	u16 real_cpu_cnt;
	u8 end_pad1[0x200-0x061];
	u64 mvdump_sign;
	u64 mvdump_zipl_time;
	u8 end_pad2[0x800-0x210];
	u32 lc_vec[512];
M
Michael Holzheu 已提交
201 202 203 204 205 206 207 208 209
} __attribute__((packed,__aligned__(16)));

static struct zcore_header zcore_header = {
	.magic		= DUMP_MAGIC,
	.version	= DUMP_VERSION,
	.header_size	= 4096,
	.dump_level	= 0,
	.page_size	= PAGE_SIZE,
	.mem_start	= 0,
210
#ifdef CONFIG_64BIT
M
Michael Holzheu 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
	.build_arch	= DUMP_ARCH_S390X,
#else
	.build_arch	= DUMP_ARCH_S390,
#endif
};

/*
 * Copy lowcore info to buffer. Use map in order to copy only register parts.
 *
 * @buf:    User buffer
 * @sa:     Pointer to save area
 * @sa_off: Offset in save area to copy
 * @len:    Number of bytes to copy
 */
static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
{
	int i;
	char *lc_mask = (char*)&sys_info.lc_mask;

	for (i = 0; i < len; i++) {
		if (!lc_mask[i + sa_off])
			continue;
		if (copy_to_user(buf + i, sa + sa_off + i, 1))
			return -EFAULT;
	}
	return 0;
}

/*
 * Copy lowcores info to memory, if necessary
 *
 * @buf:   User buffer
 * @addr:  Start address of buffer in dump memory
 * @count: Size of buffer
 */
static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
{
	unsigned long end;
	int i = 0;

	if (count == 0)
		return 0;

	end = start + count;
	while (zfcpdump_save_areas[i]) {
		unsigned long cp_start, cp_end; /* copy range */
		unsigned long sa_start, sa_end; /* save area range */
		unsigned long prefix;
		unsigned long sa_off, len, buf_off;

261
		prefix = zfcpdump_save_areas[i]->pref_reg;
M
Michael Holzheu 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
		sa_start = prefix + sys_info.sa_base;
		sa_end = prefix + sys_info.sa_base + sys_info.sa_size;

		if ((end < sa_start) || (start > sa_end))
			goto next;
		cp_start = max(start, sa_start);
		cp_end = min(end, sa_end);

		buf_off = cp_start - start;
		sa_off = cp_start - sa_start;
		len = cp_end - cp_start;

		TRACE("copy_lc for: %lx\n", start);
		if (copy_lc(buf + buf_off, zfcpdump_save_areas[i], sa_off, len))
			return -EFAULT;
next:
		i++;
	}
	return 0;
}

M
Michael Holzheu 已提交
283 284 285 286 287 288 289 290 291
/*
 * Release the HSA
 */
static void release_hsa(void)
{
	diag308(DIAG308_REL_HSA, NULL);
	hsa_available = 0;
}

M
Michael Holzheu 已提交
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
/*
 * Read routine for zcore character device
 * First 4K are dump header
 * Next 32MB are HSA Memory
 * Rest is read from absolute Memory
 */
static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
			  loff_t *ppos)
{
	unsigned long mem_start; /* Start address in memory */
	size_t mem_offs;	 /* Offset in dump memory */
	size_t hdr_count;	 /* Size of header part of output buffer */
	size_t size;
	int rc;

	mutex_lock(&zcore_mutex);

	if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
		rc = -EINVAL;
		goto fail;
	}

	count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));

	/* Copy dump header */
	if (*ppos < HEADER_SIZE) {
		size = min(count, (size_t) (HEADER_SIZE - *ppos));
		if (copy_to_user(buf, &zcore_header + *ppos, size)) {
			rc = -EFAULT;
			goto fail;
		}
		hdr_count = size;
		mem_start = 0;
	} else {
		hdr_count = 0;
		mem_start = *ppos - HEADER_SIZE;
	}

	mem_offs = 0;

	/* Copy from HSA data */
	if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
		size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
			   - mem_start));
		rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
		if (rc)
			goto fail;

		mem_offs += size;
	}

	/* Copy from real mem */
	size = count - mem_offs - hdr_count;
345 346
	rc = copy_to_user_real(buf + hdr_count + mem_offs,
			       (void *) mem_start + mem_offs, size);
M
Michael Holzheu 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
	if (rc)
		goto fail;

	/*
	 * Since s390 dump analysis tools like lcrash or crash
	 * expect register sets in the prefix pages of the cpus,
	 * we copy them into the read buffer, if necessary.
	 * buf + hdr_count: Start of memory part of output buffer
	 * mem_start: Start memory address to copy from
	 * count - hdr_count: Size of memory area to copy
	 */
	if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
		rc = -EFAULT;
		goto fail;
	}
	*ppos += count;
fail:
	mutex_unlock(&zcore_mutex);
	return (rc < 0) ? rc : count;
}

static int zcore_open(struct inode *inode, struct file *filp)
{
	if (!hsa_available)
		return -ENODATA;
	else
		return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
}

static int zcore_release(struct inode *inode, struct file *filep)
{
M
Michael Holzheu 已提交
378 379
	if (hsa_available)
		release_hsa();
M
Michael Holzheu 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
	return 0;
}

static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
{
	loff_t rc;

	mutex_lock(&zcore_mutex);
	switch (orig) {
	case 0:
		file->f_pos = offset;
		rc = file->f_pos;
		break;
	case 1:
		file->f_pos += offset;
		rc = file->f_pos;
		break;
	default:
		rc = -EINVAL;
	}
	mutex_unlock(&zcore_mutex);
	return rc;
}

404
static const struct file_operations zcore_fops = {
M
Michael Holzheu 已提交
405 406 407 408 409 410 411
	.owner		= THIS_MODULE,
	.llseek		= zcore_lseek,
	.read		= zcore_read,
	.open		= zcore_open,
	.release	= zcore_release,
};

412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
				 size_t count, loff_t *ppos)
{
	return simple_read_from_buffer(buf, count, ppos, filp->private_data,
				       MEMORY_CHUNKS * CHUNK_INFO_SIZE);
}

static int zcore_memmap_open(struct inode *inode, struct file *filp)
{
	int i;
	char *buf;
	struct mem_chunk *chunk_array;

	chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
			      GFP_KERNEL);
	if (!chunk_array)
		return -ENOMEM;
	detect_memory_layout(chunk_array);
	buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL);
	if (!buf) {
		kfree(chunk_array);
		return -ENOMEM;
	}
	for (i = 0; i < MEMORY_CHUNKS; i++) {
		sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ",
			(unsigned long long) chunk_array[i].addr,
			(unsigned long long) chunk_array[i].size);
		if (chunk_array[i].size == 0)
			break;
	}
	kfree(chunk_array);
	filp->private_data = buf;
444
	return nonseekable_open(inode, filp);
445 446 447 448 449 450 451 452 453 454 455 456 457
}

static int zcore_memmap_release(struct inode *inode, struct file *filp)
{
	kfree(filp->private_data);
	return 0;
}

static const struct file_operations zcore_memmap_fops = {
	.owner		= THIS_MODULE,
	.read		= zcore_memmap_read,
	.open		= zcore_memmap_open,
	.release	= zcore_memmap_release,
458
	.llseek		= no_llseek,
459 460
};

F
Frank Munzert 已提交
461 462 463 464 465 466 467 468 469 470 471 472
static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
				 size_t count, loff_t *ppos)
{
	if (ipl_block) {
		diag308(DIAG308_SET, ipl_block);
		diag308(DIAG308_IPL, NULL);
	}
	return count;
}

static int zcore_reipl_open(struct inode *inode, struct file *filp)
{
473
	return nonseekable_open(inode, filp);
F
Frank Munzert 已提交
474 475 476 477 478 479 480 481 482 483 484 485
}

static int zcore_reipl_release(struct inode *inode, struct file *filp)
{
	return 0;
}

static const struct file_operations zcore_reipl_fops = {
	.owner		= THIS_MODULE,
	.write		= zcore_reipl_write,
	.open		= zcore_reipl_open,
	.release	= zcore_reipl_release,
486
	.llseek		= no_llseek,
F
Frank Munzert 已提交
487 488
};

M
Michael Holzheu 已提交
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
			      size_t count, loff_t *ppos)
{
	static char str[18];

	if (hsa_available)
		snprintf(str, sizeof(str), "%lx\n", ZFCPDUMP_HSA_SIZE);
	else
		snprintf(str, sizeof(str), "0\n");
	return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
}

static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
			       size_t count, loff_t *ppos)
{
	char value;

	if (*ppos != 0)
		return -EPIPE;
	if (copy_from_user(&value, buf, 1))
		return -EFAULT;
	if (value != '0')
		return -EINVAL;
	release_hsa();
	return count;
}

static const struct file_operations zcore_hsa_fops = {
	.owner		= THIS_MODULE,
	.write		= zcore_hsa_write,
	.read		= zcore_hsa_read,
	.open		= nonseekable_open,
	.llseek		= no_llseek,
};

524
#ifdef CONFIG_32BIT
M
Michael Holzheu 已提交
525

526
static void __init set_lc_mask(struct save_area *map)
M
Michael Holzheu 已提交
527
{
528 529 530 531 532 533 534 535 536
	memset(&map->ext_save, 0xff, sizeof(map->ext_save));
	memset(&map->timer, 0xff, sizeof(map->timer));
	memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
	memset(&map->psw, 0xff, sizeof(map->psw));
	memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
	memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
	memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
	memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
	memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
M
Michael Holzheu 已提交
537 538
}

539 540 541
#else /* CONFIG_32BIT */

static void __init set_lc_mask(struct save_area *map)
M
Michael Holzheu 已提交
542
{
543 544 545 546 547 548 549 550 551 552
	memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
	memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
	memset(&map->psw, 0xff, sizeof(map->psw));
	memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
	memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
	memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
	memset(&map->timer, 0xff, sizeof(map->timer));
	memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
	memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
	memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
M
Michael Holzheu 已提交
553 554
}

555 556
#endif /* CONFIG_32BIT */

M
Michael Holzheu 已提交
557 558 559 560 561
/*
 * Initialize dump globals for a given architecture
 */
static int __init sys_info_init(enum arch_id arch)
{
562 563
	int rc;

M
Michael Holzheu 已提交
564 565
	switch (arch) {
	case ARCH_S390X:
566
		pr_alert("DETECTED 'S390X (64 bit) OS'\n");
M
Michael Holzheu 已提交
567 568
		break;
	case ARCH_S390:
569
		pr_alert("DETECTED 'S390 (32 bit) OS'\n");
M
Michael Holzheu 已提交
570 571
		break;
	default:
572
		pr_alert("0x%x is an unknown architecture.\n",arch);
M
Michael Holzheu 已提交
573 574
		return -EINVAL;
	}
575 576
	sys_info.sa_base = SAVE_AREA_BASE;
	sys_info.sa_size = sizeof(struct save_area);
M
Michael Holzheu 已提交
577
	sys_info.arch = arch;
578
	set_lc_mask(&sys_info.lc_mask);
579 580 581
	rc = init_cpu_info(arch);
	if (rc)
		return rc;
M
Michael Holzheu 已提交
582 583 584 585 586 587 588 589 590 591 592
	sys_info.mem_size = real_memory_size;

	return 0;
}

static int __init check_sdias(void)
{
	int rc, act_hsa_size;

	rc = sclp_sdias_blk_count();
	if (rc < 0) {
593
		TRACE("Could not determine HSA size\n");
M
Michael Holzheu 已提交
594 595 596 597
		return rc;
	}
	act_hsa_size = (rc - 1) * PAGE_SIZE;
	if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
598
		TRACE("HSA size too small: %i\n", act_hsa_size);
M
Michael Holzheu 已提交
599 600 601 602 603
		return -EINVAL;
	}
	return 0;
}

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
static int __init get_mem_size(unsigned long *mem)
{
	int i;
	struct mem_chunk *chunk_array;

	chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
			      GFP_KERNEL);
	if (!chunk_array)
		return -ENOMEM;
	detect_memory_layout(chunk_array);
	for (i = 0; i < MEMORY_CHUNKS; i++) {
		if (chunk_array[i].size == 0)
			break;
		*mem += chunk_array[i].size;
	}
	kfree(chunk_array);
	return 0;
}

static int __init zcore_header_init(int arch, struct zcore_header *hdr)
M
Michael Holzheu 已提交
624
{
625
	int rc, i;
626
	unsigned long memory = 0;
627
	u32 prefix;
628

M
Michael Holzheu 已提交
629 630 631 632
	if (arch == ARCH_S390X)
		hdr->arch_id = DUMP_ARCH_S390X;
	else
		hdr->arch_id = DUMP_ARCH_S390;
633 634 635 636 637
	rc = get_mem_size(&memory);
	if (rc)
		return rc;
	hdr->mem_size = memory;
	hdr->rmem_size = memory;
M
Michael Holzheu 已提交
638
	hdr->mem_end = sys_info.mem_size;
639
	hdr->num_pages = memory / PAGE_SIZE;
640
	hdr->tod = get_tod_clock();
M
Michael Holzheu 已提交
641
	get_cpu_id(&hdr->cpu_id);
642 643 644 645 646 647 648 649
	for (i = 0; zfcpdump_save_areas[i]; i++) {
		prefix = zfcpdump_save_areas[i]->pref_reg;
		hdr->real_cpu_cnt++;
		if (!prefix)
			continue;
		hdr->lc_vec[hdr->cpu_cnt] = prefix;
		hdr->cpu_cnt++;
	}
650
	return 0;
M
Michael Holzheu 已提交
651 652
}

F
Frank Munzert 已提交
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
/*
 * Provide IPL parameter information block from either HSA or memory
 * for future reipl
 */
static int __init zcore_reipl_init(void)
{
	struct ipib_info ipib_info;
	int rc;

	rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
	if (rc)
		return rc;
	if (ipib_info.ipib == 0)
		return 0;
	ipl_block = (void *) __get_free_page(GFP_KERNEL);
	if (!ipl_block)
		return -ENOMEM;
	if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
		rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
	else
673
		rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
674
	if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
675
	    ipib_info.checksum) {
F
Frank Munzert 已提交
676 677 678 679 680 681 682
		TRACE("Checksum does not match\n");
		free_page((unsigned long) ipl_block);
		ipl_block = NULL;
	}
	return 0;
}

M
Michael Holzheu 已提交
683 684 685 686 687 688 689
static int __init zcore_init(void)
{
	unsigned char arch;
	int rc;

	if (ipl_info.type != IPL_TYPE_FCP_DUMP)
		return -ENODATA;
690 691
	if (OLDMEM_BASE)
		return -ENODATA;
M
Michael Holzheu 已提交
692 693 694 695 696 697 698 699 700

	zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
	debug_register_view(zcore_dbf, &debug_sprintf_view);
	debug_set_level(zcore_dbf, 6);

	TRACE("devno:  %x\n", ipl_info.data.fcp.dev_id.devno);
	TRACE("wwpn:   %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
	TRACE("lun:    %llx\n", (unsigned long long) ipl_info.data.fcp.lun);

H
Heiko Carstens 已提交
701
	rc = sclp_sdias_init();
M
Michael Holzheu 已提交
702 703 704 705
	if (rc)
		goto fail;

	rc = check_sdias();
706
	if (rc)
M
Michael Holzheu 已提交
707
		goto fail;
M
Michael Holzheu 已提交
708
	hsa_available = 1;
M
Michael Holzheu 已提交
709 710

	rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
711
	if (rc)
M
Michael Holzheu 已提交
712 713
		goto fail;

714 715 716 717 718 719 720 721
#ifdef CONFIG_64BIT
	if (arch == ARCH_S390) {
		pr_alert("The 64-bit dump tool cannot be used for a "
			 "32-bit system\n");
		rc = -EINVAL;
		goto fail;
	}
#else /* CONFIG_64BIT */
M
Michael Holzheu 已提交
722
	if (arch == ARCH_S390X) {
723 724
		pr_alert("The 32-bit dump tool cannot be used for a "
			 "64-bit system\n");
M
Michael Holzheu 已提交
725 726 727
		rc = -EINVAL;
		goto fail;
	}
728
#endif /* CONFIG_64BIT */
M
Michael Holzheu 已提交
729 730

	rc = sys_info_init(arch);
731
	if (rc)
M
Michael Holzheu 已提交
732 733
		goto fail;

734 735 736
	rc = zcore_header_init(arch, &zcore_header);
	if (rc)
		goto fail;
M
Michael Holzheu 已提交
737

F
Frank Munzert 已提交
738 739 740 741
	rc = zcore_reipl_init();
	if (rc)
		goto fail;

M
Michael Holzheu 已提交
742 743 744 745 746 747 748 749 750
	zcore_dir = debugfs_create_dir("zcore" , NULL);
	if (!zcore_dir) {
		rc = -ENOMEM;
		goto fail;
	}
	zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
					 &zcore_fops);
	if (!zcore_file) {
		rc = -ENOMEM;
751 752 753 754 755 756 757
		goto fail_dir;
	}
	zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
						NULL, &zcore_memmap_fops);
	if (!zcore_memmap_file) {
		rc = -ENOMEM;
		goto fail_file;
M
Michael Holzheu 已提交
758
	}
F
Frank Munzert 已提交
759 760 761 762 763 764
	zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
						NULL, &zcore_reipl_fops);
	if (!zcore_reipl_file) {
		rc = -ENOMEM;
		goto fail_memmap_file;
	}
M
Michael Holzheu 已提交
765 766 767 768 769 770
	zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
					     NULL, &zcore_hsa_fops);
	if (!zcore_hsa_file) {
		rc = -ENOMEM;
		goto fail_reipl_file;
	}
M
Michael Holzheu 已提交
771 772
	return 0;

M
Michael Holzheu 已提交
773 774
fail_reipl_file:
	debugfs_remove(zcore_reipl_file);
F
Frank Munzert 已提交
775 776
fail_memmap_file:
	debugfs_remove(zcore_memmap_file);
777 778 779 780
fail_file:
	debugfs_remove(zcore_file);
fail_dir:
	debugfs_remove(zcore_dir);
M
Michael Holzheu 已提交
781 782 783 784 785 786 787 788
fail:
	diag308(DIAG308_REL_HSA, NULL);
	return rc;
}

static void __exit zcore_exit(void)
{
	debug_unregister(zcore_dbf);
H
Heiko Carstens 已提交
789
	sclp_sdias_exit();
F
Frank Munzert 已提交
790
	free_page((unsigned long) ipl_block);
M
Michael Holzheu 已提交
791
	debugfs_remove(zcore_hsa_file);
F
Frank Munzert 已提交
792 793 794 795
	debugfs_remove(zcore_reipl_file);
	debugfs_remove(zcore_memmap_file);
	debugfs_remove(zcore_file);
	debugfs_remove(zcore_dir);
M
Michael Holzheu 已提交
796 797 798
	diag308(DIAG308_REL_HSA, NULL);
}

F
Frank Munzert 已提交
799
MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
M
Michael Holzheu 已提交
800 801 802 803 804
MODULE_DESCRIPTION("zcore module for zfcpdump support");
MODULE_LICENSE("GPL");

subsys_initcall(zcore_init);
module_exit(zcore_exit);