zcore.c 18 KB

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