zcore.c 18 KB

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