zcore.c 18 KB

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