zcore.c 18 KB

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