zcore.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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 0x5
  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. u8 mvdump;
  205. u16 cpu_cnt;
  206. u16 real_cpu_cnt;
  207. u8 end_pad1[0x200-0x061];
  208. u64 mvdump_sign;
  209. u64 mvdump_zipl_time;
  210. u8 end_pad2[0x800-0x210];
  211. u32 lc_vec[512];
  212. } __attribute__((packed,__aligned__(16)));
  213. static struct zcore_header zcore_header = {
  214. .magic = DUMP_MAGIC,
  215. .version = DUMP_VERSION,
  216. .header_size = 4096,
  217. .dump_level = 0,
  218. .page_size = PAGE_SIZE,
  219. .mem_start = 0,
  220. #ifdef CONFIG_64BIT
  221. .build_arch = DUMP_ARCH_S390X,
  222. #else
  223. .build_arch = DUMP_ARCH_S390,
  224. #endif
  225. };
  226. /*
  227. * Copy lowcore info to buffer. Use map in order to copy only register parts.
  228. *
  229. * @buf: User buffer
  230. * @sa: Pointer to save area
  231. * @sa_off: Offset in save area to copy
  232. * @len: Number of bytes to copy
  233. */
  234. static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
  235. {
  236. int i;
  237. char *lc_mask = (char*)&sys_info.lc_mask;
  238. for (i = 0; i < len; i++) {
  239. if (!lc_mask[i + sa_off])
  240. continue;
  241. if (copy_to_user(buf + i, sa + sa_off + i, 1))
  242. return -EFAULT;
  243. }
  244. return 0;
  245. }
  246. /*
  247. * Copy lowcores info to memory, if necessary
  248. *
  249. * @buf: User buffer
  250. * @addr: Start address of buffer in dump memory
  251. * @count: Size of buffer
  252. */
  253. static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
  254. {
  255. unsigned long end;
  256. int i = 0;
  257. if (count == 0)
  258. return 0;
  259. end = start + count;
  260. while (zfcpdump_save_areas[i]) {
  261. unsigned long cp_start, cp_end; /* copy range */
  262. unsigned long sa_start, sa_end; /* save area range */
  263. unsigned long prefix;
  264. unsigned long sa_off, len, buf_off;
  265. prefix = zfcpdump_save_areas[i]->pref_reg;
  266. sa_start = prefix + sys_info.sa_base;
  267. sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
  268. if ((end < sa_start) || (start > sa_end))
  269. goto next;
  270. cp_start = max(start, sa_start);
  271. cp_end = min(end, sa_end);
  272. buf_off = cp_start - start;
  273. sa_off = cp_start - sa_start;
  274. len = cp_end - cp_start;
  275. TRACE("copy_lc for: %lx\n", start);
  276. if (copy_lc(buf + buf_off, zfcpdump_save_areas[i], sa_off, len))
  277. return -EFAULT;
  278. next:
  279. i++;
  280. }
  281. return 0;
  282. }
  283. /*
  284. * Read routine for zcore character device
  285. * First 4K are dump header
  286. * Next 32MB are HSA Memory
  287. * Rest is read from absolute Memory
  288. */
  289. static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
  290. loff_t *ppos)
  291. {
  292. unsigned long mem_start; /* Start address in memory */
  293. size_t mem_offs; /* Offset in dump memory */
  294. size_t hdr_count; /* Size of header part of output buffer */
  295. size_t size;
  296. int rc;
  297. mutex_lock(&zcore_mutex);
  298. if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
  299. rc = -EINVAL;
  300. goto fail;
  301. }
  302. count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
  303. /* Copy dump header */
  304. if (*ppos < HEADER_SIZE) {
  305. size = min(count, (size_t) (HEADER_SIZE - *ppos));
  306. if (copy_to_user(buf, &zcore_header + *ppos, size)) {
  307. rc = -EFAULT;
  308. goto fail;
  309. }
  310. hdr_count = size;
  311. mem_start = 0;
  312. } else {
  313. hdr_count = 0;
  314. mem_start = *ppos - HEADER_SIZE;
  315. }
  316. mem_offs = 0;
  317. /* Copy from HSA data */
  318. if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
  319. size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
  320. - mem_start));
  321. rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
  322. if (rc)
  323. goto fail;
  324. mem_offs += size;
  325. }
  326. /* Copy from real mem */
  327. size = count - mem_offs - hdr_count;
  328. rc = memcpy_real_user(buf + hdr_count + mem_offs, mem_start + mem_offs,
  329. size);
  330. if (rc)
  331. goto fail;
  332. /*
  333. * Since s390 dump analysis tools like lcrash or crash
  334. * expect register sets in the prefix pages of the cpus,
  335. * we copy them into the read buffer, if necessary.
  336. * buf + hdr_count: Start of memory part of output buffer
  337. * mem_start: Start memory address to copy from
  338. * count - hdr_count: Size of memory area to copy
  339. */
  340. if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
  341. rc = -EFAULT;
  342. goto fail;
  343. }
  344. *ppos += count;
  345. fail:
  346. mutex_unlock(&zcore_mutex);
  347. return (rc < 0) ? rc : count;
  348. }
  349. static int zcore_open(struct inode *inode, struct file *filp)
  350. {
  351. if (!hsa_available)
  352. return -ENODATA;
  353. else
  354. return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
  355. }
  356. static int zcore_release(struct inode *inode, struct file *filep)
  357. {
  358. diag308(DIAG308_REL_HSA, NULL);
  359. hsa_available = 0;
  360. return 0;
  361. }
  362. static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
  363. {
  364. loff_t rc;
  365. mutex_lock(&zcore_mutex);
  366. switch (orig) {
  367. case 0:
  368. file->f_pos = offset;
  369. rc = file->f_pos;
  370. break;
  371. case 1:
  372. file->f_pos += offset;
  373. rc = file->f_pos;
  374. break;
  375. default:
  376. rc = -EINVAL;
  377. }
  378. mutex_unlock(&zcore_mutex);
  379. return rc;
  380. }
  381. static const struct file_operations zcore_fops = {
  382. .owner = THIS_MODULE,
  383. .llseek = zcore_lseek,
  384. .read = zcore_read,
  385. .open = zcore_open,
  386. .release = zcore_release,
  387. };
  388. static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
  389. size_t count, loff_t *ppos)
  390. {
  391. return simple_read_from_buffer(buf, count, ppos, filp->private_data,
  392. MEMORY_CHUNKS * CHUNK_INFO_SIZE);
  393. }
  394. static int zcore_memmap_open(struct inode *inode, struct file *filp)
  395. {
  396. int i;
  397. char *buf;
  398. struct mem_chunk *chunk_array;
  399. chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
  400. GFP_KERNEL);
  401. if (!chunk_array)
  402. return -ENOMEM;
  403. detect_memory_layout(chunk_array);
  404. buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL);
  405. if (!buf) {
  406. kfree(chunk_array);
  407. return -ENOMEM;
  408. }
  409. for (i = 0; i < MEMORY_CHUNKS; i++) {
  410. sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ",
  411. (unsigned long long) chunk_array[i].addr,
  412. (unsigned long long) chunk_array[i].size);
  413. if (chunk_array[i].size == 0)
  414. break;
  415. }
  416. kfree(chunk_array);
  417. filp->private_data = buf;
  418. return 0;
  419. }
  420. static int zcore_memmap_release(struct inode *inode, struct file *filp)
  421. {
  422. kfree(filp->private_data);
  423. return 0;
  424. }
  425. static const struct file_operations zcore_memmap_fops = {
  426. .owner = THIS_MODULE,
  427. .read = zcore_memmap_read,
  428. .open = zcore_memmap_open,
  429. .release = zcore_memmap_release,
  430. };
  431. static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
  432. size_t count, loff_t *ppos)
  433. {
  434. if (ipl_block) {
  435. diag308(DIAG308_SET, ipl_block);
  436. diag308(DIAG308_IPL, NULL);
  437. }
  438. return count;
  439. }
  440. static int zcore_reipl_open(struct inode *inode, struct file *filp)
  441. {
  442. return 0;
  443. }
  444. static int zcore_reipl_release(struct inode *inode, struct file *filp)
  445. {
  446. return 0;
  447. }
  448. static const struct file_operations zcore_reipl_fops = {
  449. .owner = THIS_MODULE,
  450. .write = zcore_reipl_write,
  451. .open = zcore_reipl_open,
  452. .release = zcore_reipl_release,
  453. };
  454. #ifdef CONFIG_32BIT
  455. static void __init set_lc_mask(struct save_area *map)
  456. {
  457. memset(&map->ext_save, 0xff, sizeof(map->ext_save));
  458. memset(&map->timer, 0xff, sizeof(map->timer));
  459. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  460. memset(&map->psw, 0xff, sizeof(map->psw));
  461. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  462. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  463. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  464. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  465. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  466. }
  467. #else /* CONFIG_32BIT */
  468. static void __init set_lc_mask(struct save_area *map)
  469. {
  470. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  471. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  472. memset(&map->psw, 0xff, sizeof(map->psw));
  473. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  474. memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
  475. memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
  476. memset(&map->timer, 0xff, sizeof(map->timer));
  477. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  478. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  479. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  480. }
  481. #endif /* CONFIG_32BIT */
  482. /*
  483. * Initialize dump globals for a given architecture
  484. */
  485. static int __init sys_info_init(enum arch_id arch)
  486. {
  487. int rc;
  488. switch (arch) {
  489. case ARCH_S390X:
  490. pr_alert("DETECTED 'S390X (64 bit) OS'\n");
  491. break;
  492. case ARCH_S390:
  493. pr_alert("DETECTED 'S390 (32 bit) OS'\n");
  494. break;
  495. default:
  496. pr_alert("0x%x is an unknown architecture.\n",arch);
  497. return -EINVAL;
  498. }
  499. sys_info.sa_base = SAVE_AREA_BASE;
  500. sys_info.sa_size = sizeof(struct save_area);
  501. sys_info.arch = arch;
  502. set_lc_mask(&sys_info.lc_mask);
  503. rc = init_cpu_info(arch);
  504. if (rc)
  505. return rc;
  506. sys_info.mem_size = real_memory_size;
  507. return 0;
  508. }
  509. static int __init check_sdias(void)
  510. {
  511. int rc, act_hsa_size;
  512. rc = sclp_sdias_blk_count();
  513. if (rc < 0) {
  514. TRACE("Could not determine HSA size\n");
  515. return rc;
  516. }
  517. act_hsa_size = (rc - 1) * PAGE_SIZE;
  518. if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
  519. TRACE("HSA size too small: %i\n", act_hsa_size);
  520. return -EINVAL;
  521. }
  522. return 0;
  523. }
  524. static int __init get_mem_size(unsigned long *mem)
  525. {
  526. int i;
  527. struct mem_chunk *chunk_array;
  528. chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
  529. GFP_KERNEL);
  530. if (!chunk_array)
  531. return -ENOMEM;
  532. detect_memory_layout(chunk_array);
  533. for (i = 0; i < MEMORY_CHUNKS; i++) {
  534. if (chunk_array[i].size == 0)
  535. break;
  536. *mem += chunk_array[i].size;
  537. }
  538. kfree(chunk_array);
  539. return 0;
  540. }
  541. static int __init zcore_header_init(int arch, struct zcore_header *hdr)
  542. {
  543. int rc, i;
  544. unsigned long memory = 0;
  545. u32 prefix;
  546. if (arch == ARCH_S390X)
  547. hdr->arch_id = DUMP_ARCH_S390X;
  548. else
  549. hdr->arch_id = DUMP_ARCH_S390;
  550. rc = get_mem_size(&memory);
  551. if (rc)
  552. return rc;
  553. hdr->mem_size = memory;
  554. hdr->rmem_size = memory;
  555. hdr->mem_end = sys_info.mem_size;
  556. hdr->num_pages = memory / PAGE_SIZE;
  557. hdr->tod = get_clock();
  558. get_cpu_id(&hdr->cpu_id);
  559. for (i = 0; zfcpdump_save_areas[i]; i++) {
  560. prefix = zfcpdump_save_areas[i]->pref_reg;
  561. hdr->real_cpu_cnt++;
  562. if (!prefix)
  563. continue;
  564. hdr->lc_vec[hdr->cpu_cnt] = prefix;
  565. hdr->cpu_cnt++;
  566. }
  567. return 0;
  568. }
  569. /*
  570. * Provide IPL parameter information block from either HSA or memory
  571. * for future reipl
  572. */
  573. static int __init zcore_reipl_init(void)
  574. {
  575. struct ipib_info ipib_info;
  576. int rc;
  577. rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
  578. if (rc)
  579. return rc;
  580. if (ipib_info.ipib == 0)
  581. return 0;
  582. ipl_block = (void *) __get_free_page(GFP_KERNEL);
  583. if (!ipl_block)
  584. return -ENOMEM;
  585. if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
  586. rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
  587. else
  588. rc = memcpy_real(ipl_block, ipib_info.ipib, PAGE_SIZE);
  589. if (rc) {
  590. free_page((unsigned long) ipl_block);
  591. return rc;
  592. }
  593. if (csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
  594. ipib_info.checksum) {
  595. TRACE("Checksum does not match\n");
  596. free_page((unsigned long) ipl_block);
  597. ipl_block = NULL;
  598. }
  599. return 0;
  600. }
  601. static int __init zcore_init(void)
  602. {
  603. unsigned char arch;
  604. int rc;
  605. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  606. return -ENODATA;
  607. zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
  608. debug_register_view(zcore_dbf, &debug_sprintf_view);
  609. debug_set_level(zcore_dbf, 6);
  610. TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
  611. TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
  612. TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
  613. rc = sclp_sdias_init();
  614. if (rc)
  615. goto fail;
  616. rc = check_sdias();
  617. if (rc)
  618. goto fail;
  619. rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
  620. if (rc)
  621. goto fail;
  622. #ifdef CONFIG_64BIT
  623. if (arch == ARCH_S390) {
  624. pr_alert("The 64-bit dump tool cannot be used for a "
  625. "32-bit system\n");
  626. rc = -EINVAL;
  627. goto fail;
  628. }
  629. #else /* CONFIG_64BIT */
  630. if (arch == ARCH_S390X) {
  631. pr_alert("The 32-bit dump tool cannot be used for a "
  632. "64-bit system\n");
  633. rc = -EINVAL;
  634. goto fail;
  635. }
  636. #endif /* CONFIG_64BIT */
  637. rc = sys_info_init(arch);
  638. if (rc)
  639. goto fail;
  640. rc = zcore_header_init(arch, &zcore_header);
  641. if (rc)
  642. goto fail;
  643. rc = zcore_reipl_init();
  644. if (rc)
  645. goto fail;
  646. zcore_dir = debugfs_create_dir("zcore" , NULL);
  647. if (!zcore_dir) {
  648. rc = -ENOMEM;
  649. goto fail;
  650. }
  651. zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
  652. &zcore_fops);
  653. if (!zcore_file) {
  654. rc = -ENOMEM;
  655. goto fail_dir;
  656. }
  657. zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
  658. NULL, &zcore_memmap_fops);
  659. if (!zcore_memmap_file) {
  660. rc = -ENOMEM;
  661. goto fail_file;
  662. }
  663. zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
  664. NULL, &zcore_reipl_fops);
  665. if (!zcore_reipl_file) {
  666. rc = -ENOMEM;
  667. goto fail_memmap_file;
  668. }
  669. hsa_available = 1;
  670. return 0;
  671. fail_memmap_file:
  672. debugfs_remove(zcore_memmap_file);
  673. fail_file:
  674. debugfs_remove(zcore_file);
  675. fail_dir:
  676. debugfs_remove(zcore_dir);
  677. fail:
  678. diag308(DIAG308_REL_HSA, NULL);
  679. return rc;
  680. }
  681. static void __exit zcore_exit(void)
  682. {
  683. debug_unregister(zcore_dbf);
  684. sclp_sdias_exit();
  685. free_page((unsigned long) ipl_block);
  686. debugfs_remove(zcore_reipl_file);
  687. debugfs_remove(zcore_memmap_file);
  688. debugfs_remove(zcore_file);
  689. debugfs_remove(zcore_dir);
  690. diag308(DIAG308_REL_HSA, NULL);
  691. }
  692. MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
  693. MODULE_DESCRIPTION("zcore module for zfcpdump support");
  694. MODULE_LICENSE("GPL");
  695. subsys_initcall(zcore_init);
  696. module_exit(zcore_exit);