ipl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /*
  2. * arch/s390/kernel/ipl.c
  3. * ipl/reipl/dump support for Linux on s390.
  4. *
  5. * Copyright (C) IBM Corp. 2005,2006
  6. * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  7. * Heiko Carstens <heiko.carstens@de.ibm.com>
  8. * Volker Sameske <sameske@de.ibm.com>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/module.h>
  12. #include <linux/device.h>
  13. #include <linux/delay.h>
  14. #include <linux/reboot.h>
  15. #include <asm/smp.h>
  16. #include <asm/setup.h>
  17. #include <asm/cpcmd.h>
  18. #include <asm/cio.h>
  19. #define IPL_PARM_BLOCK_VERSION 0
  20. enum ipl_type {
  21. IPL_TYPE_NONE = 1,
  22. IPL_TYPE_UNKNOWN = 2,
  23. IPL_TYPE_CCW = 4,
  24. IPL_TYPE_FCP = 8,
  25. };
  26. #define IPL_NONE_STR "none"
  27. #define IPL_UNKNOWN_STR "unknown"
  28. #define IPL_CCW_STR "ccw"
  29. #define IPL_FCP_STR "fcp"
  30. static char *ipl_type_str(enum ipl_type type)
  31. {
  32. switch (type) {
  33. case IPL_TYPE_NONE:
  34. return IPL_NONE_STR;
  35. case IPL_TYPE_CCW:
  36. return IPL_CCW_STR;
  37. case IPL_TYPE_FCP:
  38. return IPL_FCP_STR;
  39. case IPL_TYPE_UNKNOWN:
  40. default:
  41. return IPL_UNKNOWN_STR;
  42. }
  43. }
  44. enum ipl_method {
  45. IPL_METHOD_NONE,
  46. IPL_METHOD_CCW_CIO,
  47. IPL_METHOD_CCW_DIAG,
  48. IPL_METHOD_CCW_VM,
  49. IPL_METHOD_FCP_RO_DIAG,
  50. IPL_METHOD_FCP_RW_DIAG,
  51. IPL_METHOD_FCP_RO_VM,
  52. };
  53. enum shutdown_action {
  54. SHUTDOWN_REIPL,
  55. SHUTDOWN_DUMP,
  56. SHUTDOWN_STOP,
  57. };
  58. #define SHUTDOWN_REIPL_STR "reipl"
  59. #define SHUTDOWN_DUMP_STR "dump"
  60. #define SHUTDOWN_STOP_STR "stop"
  61. static char *shutdown_action_str(enum shutdown_action action)
  62. {
  63. switch (action) {
  64. case SHUTDOWN_REIPL:
  65. return SHUTDOWN_REIPL_STR;
  66. case SHUTDOWN_DUMP:
  67. return SHUTDOWN_DUMP_STR;
  68. case SHUTDOWN_STOP:
  69. return SHUTDOWN_STOP_STR;
  70. default:
  71. BUG();
  72. }
  73. }
  74. enum diag308_subcode {
  75. DIAG308_IPL = 3,
  76. DIAG308_DUMP = 4,
  77. DIAG308_SET = 5,
  78. DIAG308_STORE = 6,
  79. };
  80. enum diag308_ipl_type {
  81. DIAG308_IPL_TYPE_FCP = 0,
  82. DIAG308_IPL_TYPE_CCW = 2,
  83. };
  84. enum diag308_opt {
  85. DIAG308_IPL_OPT_IPL = 0x10,
  86. DIAG308_IPL_OPT_DUMP = 0x20,
  87. };
  88. enum diag308_rc {
  89. DIAG308_RC_OK = 1,
  90. };
  91. static int diag308_set_works = 0;
  92. static int reipl_capabilities = IPL_TYPE_UNKNOWN;
  93. static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
  94. static enum ipl_method reipl_method = IPL_METHOD_NONE;
  95. static struct ipl_parameter_block *reipl_block_fcp;
  96. static struct ipl_parameter_block *reipl_block_ccw;
  97. static int dump_capabilities = IPL_TYPE_NONE;
  98. static enum ipl_type dump_type = IPL_TYPE_NONE;
  99. static enum ipl_method dump_method = IPL_METHOD_NONE;
  100. static struct ipl_parameter_block *dump_block_fcp;
  101. static struct ipl_parameter_block *dump_block_ccw;
  102. static enum shutdown_action on_panic_action = SHUTDOWN_STOP;
  103. static int diag308(unsigned long subcode, void *addr)
  104. {
  105. register unsigned long _addr asm("0") = (unsigned long) addr;
  106. register unsigned long _rc asm("1") = 0;
  107. asm volatile(
  108. " diag %0,%2,0x308\n"
  109. "0:\n"
  110. EX_TABLE(0b,0b)
  111. : "+d" (_addr), "+d" (_rc)
  112. : "d" (subcode) : "cc", "memory");
  113. return _rc;
  114. }
  115. /* SYSFS */
  116. #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
  117. static ssize_t sys_##_prefix##_##_name##_show(struct subsystem *subsys, \
  118. char *page) \
  119. { \
  120. return sprintf(page, _format, _value); \
  121. } \
  122. static struct subsys_attribute sys_##_prefix##_##_name##_attr = \
  123. __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
  124. #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
  125. static ssize_t sys_##_prefix##_##_name##_show(struct subsystem *subsys, \
  126. char *page) \
  127. { \
  128. return sprintf(page, _fmt_out, \
  129. (unsigned long long) _value); \
  130. } \
  131. static ssize_t sys_##_prefix##_##_name##_store(struct subsystem *subsys,\
  132. const char *buf, size_t len) \
  133. { \
  134. unsigned long long value; \
  135. if (sscanf(buf, _fmt_in, &value) != 1) \
  136. return -EINVAL; \
  137. _value = value; \
  138. return len; \
  139. } \
  140. static struct subsys_attribute sys_##_prefix##_##_name##_attr = \
  141. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  142. sys_##_prefix##_##_name##_show, \
  143. sys_##_prefix##_##_name##_store);
  144. static void make_attrs_ro(struct attribute **attrs)
  145. {
  146. while (*attrs) {
  147. (*attrs)->mode = S_IRUGO;
  148. attrs++;
  149. }
  150. }
  151. /*
  152. * ipl section
  153. */
  154. static enum ipl_type ipl_get_type(void)
  155. {
  156. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  157. if (!(ipl_flags & IPL_DEVNO_VALID))
  158. return IPL_TYPE_UNKNOWN;
  159. if (!(ipl_flags & IPL_PARMBLOCK_VALID))
  160. return IPL_TYPE_CCW;
  161. if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
  162. return IPL_TYPE_UNKNOWN;
  163. if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
  164. return IPL_TYPE_UNKNOWN;
  165. return IPL_TYPE_FCP;
  166. }
  167. static ssize_t ipl_type_show(struct subsystem *subsys, char *page)
  168. {
  169. return sprintf(page, "%s\n", ipl_type_str(ipl_get_type()));
  170. }
  171. static struct subsys_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
  172. static ssize_t sys_ipl_device_show(struct subsystem *subsys, char *page)
  173. {
  174. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  175. switch (ipl_get_type()) {
  176. case IPL_TYPE_CCW:
  177. return sprintf(page, "0.0.%04x\n", ipl_devno);
  178. case IPL_TYPE_FCP:
  179. return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
  180. default:
  181. return 0;
  182. }
  183. }
  184. static struct subsys_attribute sys_ipl_device_attr =
  185. __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
  186. static ssize_t ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off,
  187. size_t count)
  188. {
  189. unsigned int size = IPL_PARMBLOCK_SIZE;
  190. if (off > size)
  191. return 0;
  192. if (off + count > size)
  193. count = size - off;
  194. memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
  195. return count;
  196. }
  197. static struct bin_attribute ipl_parameter_attr = {
  198. .attr = {
  199. .name = "binary_parameter",
  200. .mode = S_IRUGO,
  201. .owner = THIS_MODULE,
  202. },
  203. .size = PAGE_SIZE,
  204. .read = &ipl_parameter_read,
  205. };
  206. static ssize_t ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off,
  207. size_t count)
  208. {
  209. unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
  210. void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
  211. if (off > size)
  212. return 0;
  213. if (off + count > size)
  214. count = size - off;
  215. memcpy(buf, scp_data + off, count);
  216. return count;
  217. }
  218. static struct bin_attribute ipl_scp_data_attr = {
  219. .attr = {
  220. .name = "scp_data",
  221. .mode = S_IRUGO,
  222. .owner = THIS_MODULE,
  223. },
  224. .size = PAGE_SIZE,
  225. .read = &ipl_scp_data_read,
  226. };
  227. /* FCP ipl device attributes */
  228. DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
  229. IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
  230. DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
  231. IPL_PARMBLOCK_START->ipl_info.fcp.lun);
  232. DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
  233. IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
  234. DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
  235. IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
  236. static struct attribute *ipl_fcp_attrs[] = {
  237. &sys_ipl_type_attr.attr,
  238. &sys_ipl_device_attr.attr,
  239. &sys_ipl_fcp_wwpn_attr.attr,
  240. &sys_ipl_fcp_lun_attr.attr,
  241. &sys_ipl_fcp_bootprog_attr.attr,
  242. &sys_ipl_fcp_br_lba_attr.attr,
  243. NULL,
  244. };
  245. static struct attribute_group ipl_fcp_attr_group = {
  246. .attrs = ipl_fcp_attrs,
  247. };
  248. /* CCW ipl device attributes */
  249. static struct attribute *ipl_ccw_attrs[] = {
  250. &sys_ipl_type_attr.attr,
  251. &sys_ipl_device_attr.attr,
  252. NULL,
  253. };
  254. static struct attribute_group ipl_ccw_attr_group = {
  255. .attrs = ipl_ccw_attrs,
  256. };
  257. /* UNKNOWN ipl device attributes */
  258. static struct attribute *ipl_unknown_attrs[] = {
  259. &sys_ipl_type_attr.attr,
  260. NULL,
  261. };
  262. static struct attribute_group ipl_unknown_attr_group = {
  263. .attrs = ipl_unknown_attrs,
  264. };
  265. static decl_subsys(ipl, NULL, NULL);
  266. /*
  267. * reipl section
  268. */
  269. /* FCP reipl device attributes */
  270. DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  271. reipl_block_fcp->ipl_info.fcp.wwpn);
  272. DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
  273. reipl_block_fcp->ipl_info.fcp.lun);
  274. DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
  275. reipl_block_fcp->ipl_info.fcp.bootprog);
  276. DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
  277. reipl_block_fcp->ipl_info.fcp.br_lba);
  278. DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  279. reipl_block_fcp->ipl_info.fcp.devno);
  280. static struct attribute *reipl_fcp_attrs[] = {
  281. &sys_reipl_fcp_device_attr.attr,
  282. &sys_reipl_fcp_wwpn_attr.attr,
  283. &sys_reipl_fcp_lun_attr.attr,
  284. &sys_reipl_fcp_bootprog_attr.attr,
  285. &sys_reipl_fcp_br_lba_attr.attr,
  286. NULL,
  287. };
  288. static struct attribute_group reipl_fcp_attr_group = {
  289. .name = IPL_FCP_STR,
  290. .attrs = reipl_fcp_attrs,
  291. };
  292. /* CCW reipl device attributes */
  293. DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  294. reipl_block_ccw->ipl_info.ccw.devno);
  295. static struct attribute *reipl_ccw_attrs[] = {
  296. &sys_reipl_ccw_device_attr.attr,
  297. NULL,
  298. };
  299. static struct attribute_group reipl_ccw_attr_group = {
  300. .name = IPL_CCW_STR,
  301. .attrs = reipl_ccw_attrs,
  302. };
  303. /* reipl type */
  304. static int reipl_set_type(enum ipl_type type)
  305. {
  306. if (!(reipl_capabilities & type))
  307. return -EINVAL;
  308. switch(type) {
  309. case IPL_TYPE_CCW:
  310. if (MACHINE_IS_VM)
  311. reipl_method = IPL_METHOD_CCW_VM;
  312. else
  313. reipl_method = IPL_METHOD_CCW_CIO;
  314. break;
  315. case IPL_TYPE_FCP:
  316. if (diag308_set_works)
  317. reipl_method = IPL_METHOD_FCP_RW_DIAG;
  318. else if (MACHINE_IS_VM)
  319. reipl_method = IPL_METHOD_FCP_RO_VM;
  320. else
  321. reipl_method = IPL_METHOD_FCP_RO_DIAG;
  322. break;
  323. default:
  324. reipl_method = IPL_METHOD_NONE;
  325. }
  326. reipl_type = type;
  327. return 0;
  328. }
  329. static ssize_t reipl_type_show(struct subsystem *subsys, char *page)
  330. {
  331. return sprintf(page, "%s\n", ipl_type_str(reipl_type));
  332. }
  333. static ssize_t reipl_type_store(struct subsystem *subsys, const char *buf,
  334. size_t len)
  335. {
  336. int rc = -EINVAL;
  337. if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  338. rc = reipl_set_type(IPL_TYPE_CCW);
  339. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  340. rc = reipl_set_type(IPL_TYPE_FCP);
  341. return (rc != 0) ? rc : len;
  342. }
  343. static struct subsys_attribute reipl_type_attr =
  344. __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
  345. static decl_subsys(reipl, NULL, NULL);
  346. /*
  347. * dump section
  348. */
  349. /* FCP dump device attributes */
  350. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  351. dump_block_fcp->ipl_info.fcp.wwpn);
  352. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
  353. dump_block_fcp->ipl_info.fcp.lun);
  354. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  355. dump_block_fcp->ipl_info.fcp.bootprog);
  356. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  357. dump_block_fcp->ipl_info.fcp.br_lba);
  358. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  359. dump_block_fcp->ipl_info.fcp.devno);
  360. static struct attribute *dump_fcp_attrs[] = {
  361. &sys_dump_fcp_device_attr.attr,
  362. &sys_dump_fcp_wwpn_attr.attr,
  363. &sys_dump_fcp_lun_attr.attr,
  364. &sys_dump_fcp_bootprog_attr.attr,
  365. &sys_dump_fcp_br_lba_attr.attr,
  366. NULL,
  367. };
  368. static struct attribute_group dump_fcp_attr_group = {
  369. .name = IPL_FCP_STR,
  370. .attrs = dump_fcp_attrs,
  371. };
  372. /* CCW dump device attributes */
  373. DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  374. dump_block_ccw->ipl_info.ccw.devno);
  375. static struct attribute *dump_ccw_attrs[] = {
  376. &sys_dump_ccw_device_attr.attr,
  377. NULL,
  378. };
  379. static struct attribute_group dump_ccw_attr_group = {
  380. .name = IPL_CCW_STR,
  381. .attrs = dump_ccw_attrs,
  382. };
  383. /* dump type */
  384. static int dump_set_type(enum ipl_type type)
  385. {
  386. if (!(dump_capabilities & type))
  387. return -EINVAL;
  388. switch(type) {
  389. case IPL_TYPE_CCW:
  390. if (MACHINE_IS_VM)
  391. dump_method = IPL_METHOD_CCW_VM;
  392. else
  393. dump_method = IPL_METHOD_CCW_CIO;
  394. break;
  395. case IPL_TYPE_FCP:
  396. dump_method = IPL_METHOD_FCP_RW_DIAG;
  397. break;
  398. default:
  399. dump_method = IPL_METHOD_NONE;
  400. }
  401. dump_type = type;
  402. return 0;
  403. }
  404. static ssize_t dump_type_show(struct subsystem *subsys, char *page)
  405. {
  406. return sprintf(page, "%s\n", ipl_type_str(dump_type));
  407. }
  408. static ssize_t dump_type_store(struct subsystem *subsys, const char *buf,
  409. size_t len)
  410. {
  411. int rc = -EINVAL;
  412. if (strncmp(buf, IPL_NONE_STR, strlen(IPL_NONE_STR)) == 0)
  413. rc = dump_set_type(IPL_TYPE_NONE);
  414. else if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  415. rc = dump_set_type(IPL_TYPE_CCW);
  416. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  417. rc = dump_set_type(IPL_TYPE_FCP);
  418. return (rc != 0) ? rc : len;
  419. }
  420. static struct subsys_attribute dump_type_attr =
  421. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  422. static decl_subsys(dump, NULL, NULL);
  423. #ifdef CONFIG_SMP
  424. static void dump_smp_stop_all(void)
  425. {
  426. int cpu;
  427. preempt_disable();
  428. for_each_online_cpu(cpu) {
  429. if (cpu == smp_processor_id())
  430. continue;
  431. while (signal_processor(cpu, sigp_stop) == sigp_busy)
  432. udelay(10);
  433. }
  434. preempt_enable();
  435. }
  436. #else
  437. #define dump_smp_stop_all() do { } while (0)
  438. #endif
  439. /*
  440. * Shutdown actions section
  441. */
  442. static decl_subsys(shutdown_actions, NULL, NULL);
  443. /* on panic */
  444. static ssize_t on_panic_show(struct subsystem *subsys, char *page)
  445. {
  446. return sprintf(page, "%s\n", shutdown_action_str(on_panic_action));
  447. }
  448. static ssize_t on_panic_store(struct subsystem *subsys, const char *buf,
  449. size_t len)
  450. {
  451. if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0)
  452. on_panic_action = SHUTDOWN_REIPL;
  453. else if (strncmp(buf, SHUTDOWN_DUMP_STR,
  454. strlen(SHUTDOWN_DUMP_STR)) == 0)
  455. on_panic_action = SHUTDOWN_DUMP;
  456. else if (strncmp(buf, SHUTDOWN_STOP_STR,
  457. strlen(SHUTDOWN_STOP_STR)) == 0)
  458. on_panic_action = SHUTDOWN_STOP;
  459. else
  460. return -EINVAL;
  461. return len;
  462. }
  463. static struct subsys_attribute on_panic_attr =
  464. __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
  465. static void print_fcp_block(struct ipl_parameter_block *fcp_block)
  466. {
  467. printk(KERN_EMERG "wwpn: %016llx\n",
  468. (unsigned long long)fcp_block->ipl_info.fcp.wwpn);
  469. printk(KERN_EMERG "lun: %016llx\n",
  470. (unsigned long long)fcp_block->ipl_info.fcp.lun);
  471. printk(KERN_EMERG "bootprog: %lld\n",
  472. (unsigned long long)fcp_block->ipl_info.fcp.bootprog);
  473. printk(KERN_EMERG "br_lba: %lld\n",
  474. (unsigned long long)fcp_block->ipl_info.fcp.br_lba);
  475. printk(KERN_EMERG "device: %llx\n",
  476. (unsigned long long)fcp_block->ipl_info.fcp.devno);
  477. printk(KERN_EMERG "opt: %x\n", fcp_block->ipl_info.fcp.opt);
  478. }
  479. void do_reipl(void)
  480. {
  481. struct ccw_dev_id devid;
  482. static char buf[100];
  483. switch (reipl_type) {
  484. case IPL_TYPE_CCW:
  485. printk(KERN_EMERG "reboot on ccw device: 0.0.%04x\n",
  486. reipl_block_ccw->ipl_info.ccw.devno);
  487. break;
  488. case IPL_TYPE_FCP:
  489. printk(KERN_EMERG "reboot on fcp device:\n");
  490. print_fcp_block(reipl_block_fcp);
  491. break;
  492. default:
  493. break;
  494. }
  495. switch (reipl_method) {
  496. case IPL_METHOD_CCW_CIO:
  497. devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
  498. devid.ssid = 0;
  499. reipl_ccw_dev(&devid);
  500. break;
  501. case IPL_METHOD_CCW_VM:
  502. sprintf(buf, "IPL %X", reipl_block_ccw->ipl_info.ccw.devno);
  503. cpcmd(buf, NULL, 0, NULL);
  504. break;
  505. case IPL_METHOD_CCW_DIAG:
  506. diag308(DIAG308_SET, reipl_block_ccw);
  507. diag308(DIAG308_IPL, NULL);
  508. break;
  509. case IPL_METHOD_FCP_RW_DIAG:
  510. diag308(DIAG308_SET, reipl_block_fcp);
  511. diag308(DIAG308_IPL, NULL);
  512. break;
  513. case IPL_METHOD_FCP_RO_DIAG:
  514. diag308(DIAG308_IPL, NULL);
  515. break;
  516. case IPL_METHOD_FCP_RO_VM:
  517. cpcmd("IPL", NULL, 0, NULL);
  518. break;
  519. case IPL_METHOD_NONE:
  520. default:
  521. if (MACHINE_IS_VM)
  522. cpcmd("IPL", NULL, 0, NULL);
  523. diag308(DIAG308_IPL, NULL);
  524. break;
  525. }
  526. panic("reipl failed!\n");
  527. }
  528. static void do_dump(void)
  529. {
  530. struct ccw_dev_id devid;
  531. static char buf[100];
  532. switch (dump_type) {
  533. case IPL_TYPE_CCW:
  534. printk(KERN_EMERG "Automatic dump on ccw device: 0.0.%04x\n",
  535. dump_block_ccw->ipl_info.ccw.devno);
  536. break;
  537. case IPL_TYPE_FCP:
  538. printk(KERN_EMERG "Automatic dump on fcp device:\n");
  539. print_fcp_block(dump_block_fcp);
  540. break;
  541. default:
  542. return;
  543. }
  544. switch (dump_method) {
  545. case IPL_METHOD_CCW_CIO:
  546. dump_smp_stop_all();
  547. devid.devno = dump_block_ccw->ipl_info.ccw.devno;
  548. devid.ssid = 0;
  549. reipl_ccw_dev(&devid);
  550. break;
  551. case IPL_METHOD_CCW_VM:
  552. dump_smp_stop_all();
  553. sprintf(buf, "STORE STATUS");
  554. cpcmd(buf, NULL, 0, NULL);
  555. sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
  556. cpcmd(buf, NULL, 0, NULL);
  557. break;
  558. case IPL_METHOD_CCW_DIAG:
  559. diag308(DIAG308_SET, dump_block_ccw);
  560. diag308(DIAG308_DUMP, NULL);
  561. break;
  562. case IPL_METHOD_FCP_RW_DIAG:
  563. diag308(DIAG308_SET, dump_block_fcp);
  564. diag308(DIAG308_DUMP, NULL);
  565. break;
  566. case IPL_METHOD_NONE:
  567. default:
  568. return;
  569. }
  570. printk(KERN_EMERG "Dump failed!\n");
  571. }
  572. /* init functions */
  573. static int __init ipl_register_fcp_files(void)
  574. {
  575. int rc;
  576. rc = sysfs_create_group(&ipl_subsys.kset.kobj,
  577. &ipl_fcp_attr_group);
  578. if (rc)
  579. goto out;
  580. rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj,
  581. &ipl_parameter_attr);
  582. if (rc)
  583. goto out_ipl_parm;
  584. rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj,
  585. &ipl_scp_data_attr);
  586. if (!rc)
  587. goto out;
  588. sysfs_remove_bin_file(&ipl_subsys.kset.kobj, &ipl_parameter_attr);
  589. out_ipl_parm:
  590. sysfs_remove_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
  591. out:
  592. return rc;
  593. }
  594. static int __init ipl_init(void)
  595. {
  596. int rc;
  597. rc = firmware_register(&ipl_subsys);
  598. if (rc)
  599. return rc;
  600. switch (ipl_get_type()) {
  601. case IPL_TYPE_CCW:
  602. rc = sysfs_create_group(&ipl_subsys.kset.kobj,
  603. &ipl_ccw_attr_group);
  604. break;
  605. case IPL_TYPE_FCP:
  606. rc = ipl_register_fcp_files();
  607. break;
  608. default:
  609. rc = sysfs_create_group(&ipl_subsys.kset.kobj,
  610. &ipl_unknown_attr_group);
  611. break;
  612. }
  613. if (rc)
  614. firmware_unregister(&ipl_subsys);
  615. return rc;
  616. }
  617. static void __init reipl_probe(void)
  618. {
  619. void *buffer;
  620. buffer = (void *) get_zeroed_page(GFP_KERNEL);
  621. if (!buffer)
  622. return;
  623. if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
  624. diag308_set_works = 1;
  625. free_page((unsigned long)buffer);
  626. }
  627. static int __init reipl_ccw_init(void)
  628. {
  629. int rc;
  630. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  631. if (!reipl_block_ccw)
  632. return -ENOMEM;
  633. rc = sysfs_create_group(&reipl_subsys.kset.kobj, &reipl_ccw_attr_group);
  634. if (rc) {
  635. free_page((unsigned long)reipl_block_ccw);
  636. return rc;
  637. }
  638. reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  639. reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  640. reipl_block_ccw->hdr.blk0_len = sizeof(reipl_block_ccw->ipl_info.ccw);
  641. reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  642. if (ipl_get_type() == IPL_TYPE_CCW)
  643. reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
  644. reipl_capabilities |= IPL_TYPE_CCW;
  645. return 0;
  646. }
  647. static int __init reipl_fcp_init(void)
  648. {
  649. int rc;
  650. if ((!diag308_set_works) && (ipl_get_type() != IPL_TYPE_FCP))
  651. return 0;
  652. if ((!diag308_set_works) && (ipl_get_type() == IPL_TYPE_FCP))
  653. make_attrs_ro(reipl_fcp_attrs);
  654. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  655. if (!reipl_block_fcp)
  656. return -ENOMEM;
  657. rc = sysfs_create_group(&reipl_subsys.kset.kobj, &reipl_fcp_attr_group);
  658. if (rc) {
  659. free_page((unsigned long)reipl_block_fcp);
  660. return rc;
  661. }
  662. if (ipl_get_type() == IPL_TYPE_FCP) {
  663. memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
  664. } else {
  665. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  666. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  667. reipl_block_fcp->hdr.blk0_len =
  668. sizeof(reipl_block_fcp->ipl_info.fcp);
  669. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  670. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  671. }
  672. reipl_capabilities |= IPL_TYPE_FCP;
  673. return 0;
  674. }
  675. static int __init reipl_init(void)
  676. {
  677. int rc;
  678. rc = firmware_register(&reipl_subsys);
  679. if (rc)
  680. return rc;
  681. rc = subsys_create_file(&reipl_subsys, &reipl_type_attr);
  682. if (rc) {
  683. firmware_unregister(&reipl_subsys);
  684. return rc;
  685. }
  686. rc = reipl_ccw_init();
  687. if (rc)
  688. return rc;
  689. rc = reipl_fcp_init();
  690. if (rc)
  691. return rc;
  692. rc = reipl_set_type(ipl_get_type());
  693. if (rc)
  694. return rc;
  695. return 0;
  696. }
  697. static int __init dump_ccw_init(void)
  698. {
  699. int rc;
  700. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  701. if (!dump_block_ccw)
  702. return -ENOMEM;
  703. rc = sysfs_create_group(&dump_subsys.kset.kobj, &dump_ccw_attr_group);
  704. if (rc) {
  705. free_page((unsigned long)dump_block_ccw);
  706. return rc;
  707. }
  708. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  709. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  710. dump_block_ccw->hdr.blk0_len = sizeof(reipl_block_ccw->ipl_info.ccw);
  711. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  712. dump_capabilities |= IPL_TYPE_CCW;
  713. return 0;
  714. }
  715. extern char s390_readinfo_sccb[];
  716. static int __init dump_fcp_init(void)
  717. {
  718. int rc;
  719. if(!(s390_readinfo_sccb[91] & 0x2))
  720. return 0; /* LDIPL DUMP is not installed */
  721. if (!diag308_set_works)
  722. return 0;
  723. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  724. if (!dump_block_fcp)
  725. return -ENOMEM;
  726. rc = sysfs_create_group(&dump_subsys.kset.kobj, &dump_fcp_attr_group);
  727. if (rc) {
  728. free_page((unsigned long)dump_block_fcp);
  729. return rc;
  730. }
  731. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  732. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  733. dump_block_fcp->hdr.blk0_len = sizeof(dump_block_fcp->ipl_info.fcp);
  734. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  735. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  736. dump_capabilities |= IPL_TYPE_FCP;
  737. return 0;
  738. }
  739. #define SHUTDOWN_ON_PANIC_PRIO 0
  740. static int shutdown_on_panic_notify(struct notifier_block *self,
  741. unsigned long event, void *data)
  742. {
  743. if (on_panic_action == SHUTDOWN_DUMP)
  744. do_dump();
  745. else if (on_panic_action == SHUTDOWN_REIPL)
  746. do_reipl();
  747. return NOTIFY_OK;
  748. }
  749. static struct notifier_block shutdown_on_panic_nb = {
  750. .notifier_call = shutdown_on_panic_notify,
  751. .priority = SHUTDOWN_ON_PANIC_PRIO
  752. };
  753. static int __init dump_init(void)
  754. {
  755. int rc;
  756. rc = firmware_register(&dump_subsys);
  757. if (rc)
  758. return rc;
  759. rc = subsys_create_file(&dump_subsys, &dump_type_attr);
  760. if (rc) {
  761. firmware_unregister(&dump_subsys);
  762. return rc;
  763. }
  764. rc = dump_ccw_init();
  765. if (rc)
  766. return rc;
  767. rc = dump_fcp_init();
  768. if (rc)
  769. return rc;
  770. dump_set_type(IPL_TYPE_NONE);
  771. return 0;
  772. }
  773. static int __init shutdown_actions_init(void)
  774. {
  775. int rc;
  776. rc = firmware_register(&shutdown_actions_subsys);
  777. if (rc)
  778. return rc;
  779. rc = subsys_create_file(&shutdown_actions_subsys, &on_panic_attr);
  780. if (rc) {
  781. firmware_unregister(&shutdown_actions_subsys);
  782. return rc;
  783. }
  784. atomic_notifier_chain_register(&panic_notifier_list,
  785. &shutdown_on_panic_nb);
  786. return 0;
  787. }
  788. static int __init s390_ipl_init(void)
  789. {
  790. int rc;
  791. reipl_probe();
  792. rc = ipl_init();
  793. if (rc)
  794. return rc;
  795. rc = reipl_init();
  796. if (rc)
  797. return rc;
  798. rc = dump_init();
  799. if (rc)
  800. return rc;
  801. rc = shutdown_actions_init();
  802. if (rc)
  803. return rc;
  804. return 0;
  805. }
  806. __initcall(s390_ipl_init);