zcore.c 18 KB

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