ipl.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  1. /*
  2. * ipl/reipl/dump support for Linux on s390.
  3. *
  4. * Copyright IBM Corp. 2005, 2012
  5. * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  6. * Heiko Carstens <heiko.carstens@de.ibm.com>
  7. * Volker Sameske <sameske@de.ibm.com>
  8. */
  9. #include <linux/types.h>
  10. #include <linux/module.h>
  11. #include <linux/device.h>
  12. #include <linux/delay.h>
  13. #include <linux/reboot.h>
  14. #include <linux/ctype.h>
  15. #include <linux/fs.h>
  16. #include <linux/gfp.h>
  17. #include <linux/crash_dump.h>
  18. #include <linux/debug_locks.h>
  19. #include <asm/diag.h>
  20. #include <asm/ipl.h>
  21. #include <asm/smp.h>
  22. #include <asm/setup.h>
  23. #include <asm/cpcmd.h>
  24. #include <asm/cio.h>
  25. #include <asm/ebcdic.h>
  26. #include <asm/reset.h>
  27. #include <asm/sclp.h>
  28. #include <asm/checksum.h>
  29. #include <asm/debug.h>
  30. #include <asm/os_info.h>
  31. #include "entry.h"
  32. #define IPL_PARM_BLOCK_VERSION 0
  33. #define IPL_UNKNOWN_STR "unknown"
  34. #define IPL_CCW_STR "ccw"
  35. #define IPL_FCP_STR "fcp"
  36. #define IPL_FCP_DUMP_STR "fcp_dump"
  37. #define IPL_NSS_STR "nss"
  38. #define DUMP_CCW_STR "ccw"
  39. #define DUMP_FCP_STR "fcp"
  40. #define DUMP_NONE_STR "none"
  41. /*
  42. * Four shutdown trigger types are supported:
  43. * - panic
  44. * - halt
  45. * - power off
  46. * - reipl
  47. * - restart
  48. */
  49. #define ON_PANIC_STR "on_panic"
  50. #define ON_HALT_STR "on_halt"
  51. #define ON_POFF_STR "on_poff"
  52. #define ON_REIPL_STR "on_reboot"
  53. #define ON_RESTART_STR "on_restart"
  54. struct shutdown_action;
  55. struct shutdown_trigger {
  56. char *name;
  57. struct shutdown_action *action;
  58. };
  59. /*
  60. * The following shutdown action types are supported:
  61. */
  62. #define SHUTDOWN_ACTION_IPL_STR "ipl"
  63. #define SHUTDOWN_ACTION_REIPL_STR "reipl"
  64. #define SHUTDOWN_ACTION_DUMP_STR "dump"
  65. #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
  66. #define SHUTDOWN_ACTION_STOP_STR "stop"
  67. #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
  68. struct shutdown_action {
  69. char *name;
  70. void (*fn) (struct shutdown_trigger *trigger);
  71. int (*init) (void);
  72. int init_rc;
  73. };
  74. static char *ipl_type_str(enum ipl_type type)
  75. {
  76. switch (type) {
  77. case IPL_TYPE_CCW:
  78. return IPL_CCW_STR;
  79. case IPL_TYPE_FCP:
  80. return IPL_FCP_STR;
  81. case IPL_TYPE_FCP_DUMP:
  82. return IPL_FCP_DUMP_STR;
  83. case IPL_TYPE_NSS:
  84. return IPL_NSS_STR;
  85. case IPL_TYPE_UNKNOWN:
  86. default:
  87. return IPL_UNKNOWN_STR;
  88. }
  89. }
  90. enum dump_type {
  91. DUMP_TYPE_NONE = 1,
  92. DUMP_TYPE_CCW = 2,
  93. DUMP_TYPE_FCP = 4,
  94. };
  95. static char *dump_type_str(enum dump_type type)
  96. {
  97. switch (type) {
  98. case DUMP_TYPE_NONE:
  99. return DUMP_NONE_STR;
  100. case DUMP_TYPE_CCW:
  101. return DUMP_CCW_STR;
  102. case DUMP_TYPE_FCP:
  103. return DUMP_FCP_STR;
  104. default:
  105. return NULL;
  106. }
  107. }
  108. /*
  109. * Must be in data section since the bss section
  110. * is not cleared when these are accessed.
  111. */
  112. static u8 ipl_ssid __section(.data) = 0;
  113. static u16 ipl_devno __section(.data) = 0;
  114. u32 ipl_flags __section(.data) = 0;
  115. enum ipl_method {
  116. REIPL_METHOD_CCW_CIO,
  117. REIPL_METHOD_CCW_DIAG,
  118. REIPL_METHOD_CCW_VM,
  119. REIPL_METHOD_FCP_RO_DIAG,
  120. REIPL_METHOD_FCP_RW_DIAG,
  121. REIPL_METHOD_FCP_RO_VM,
  122. REIPL_METHOD_FCP_DUMP,
  123. REIPL_METHOD_NSS,
  124. REIPL_METHOD_NSS_DIAG,
  125. REIPL_METHOD_DEFAULT,
  126. };
  127. enum dump_method {
  128. DUMP_METHOD_NONE,
  129. DUMP_METHOD_CCW_CIO,
  130. DUMP_METHOD_CCW_DIAG,
  131. DUMP_METHOD_CCW_VM,
  132. DUMP_METHOD_FCP_DIAG,
  133. };
  134. static int diag308_set_works = 0;
  135. static struct ipl_parameter_block ipl_block;
  136. static int reipl_capabilities = IPL_TYPE_UNKNOWN;
  137. static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
  138. static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
  139. static struct ipl_parameter_block *reipl_block_fcp;
  140. static struct ipl_parameter_block *reipl_block_ccw;
  141. static struct ipl_parameter_block *reipl_block_nss;
  142. static struct ipl_parameter_block *reipl_block_actual;
  143. static int dump_capabilities = DUMP_TYPE_NONE;
  144. static enum dump_type dump_type = DUMP_TYPE_NONE;
  145. static enum dump_method dump_method = DUMP_METHOD_NONE;
  146. static struct ipl_parameter_block *dump_block_fcp;
  147. static struct ipl_parameter_block *dump_block_ccw;
  148. static struct sclp_ipl_info sclp_ipl_info;
  149. static inline int __diag308(unsigned long subcode, void *addr)
  150. {
  151. register unsigned long _addr asm("0") = (unsigned long) addr;
  152. register unsigned long _rc asm("1") = 0;
  153. asm volatile(
  154. " diag %0,%2,0x308\n"
  155. "0: nopr %%r7\n"
  156. EX_TABLE(0b,0b)
  157. : "+d" (_addr), "+d" (_rc)
  158. : "d" (subcode) : "cc", "memory");
  159. return _rc;
  160. }
  161. int diag308(unsigned long subcode, void *addr)
  162. {
  163. diag_stat_inc(DIAG_STAT_X308);
  164. return __diag308(subcode, addr);
  165. }
  166. EXPORT_SYMBOL_GPL(diag308);
  167. /* SYSFS */
  168. #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
  169. static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
  170. struct kobj_attribute *attr, \
  171. char *page) \
  172. { \
  173. return snprintf(page, PAGE_SIZE, _format, ##args); \
  174. }
  175. #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
  176. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  177. struct kobj_attribute *attr, \
  178. const char *buf, size_t len) \
  179. { \
  180. unsigned long long ssid, devno; \
  181. \
  182. if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
  183. return -EINVAL; \
  184. \
  185. if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
  186. return -EINVAL; \
  187. \
  188. _ipl_blk.ssid = ssid; \
  189. _ipl_blk.devno = devno; \
  190. return len; \
  191. }
  192. #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
  193. IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
  194. _ipl_blk.ssid, _ipl_blk.devno); \
  195. IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
  196. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  197. __ATTR(_name, (S_IRUGO | S_IWUSR), \
  198. sys_##_prefix##_##_name##_show, \
  199. sys_##_prefix##_##_name##_store) \
  200. #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
  201. IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
  202. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  203. __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
  204. #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
  205. IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
  206. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  207. struct kobj_attribute *attr, \
  208. const char *buf, size_t len) \
  209. { \
  210. unsigned long long value; \
  211. if (sscanf(buf, _fmt_in, &value) != 1) \
  212. return -EINVAL; \
  213. _value = value; \
  214. return len; \
  215. } \
  216. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  217. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  218. sys_##_prefix##_##_name##_show, \
  219. sys_##_prefix##_##_name##_store)
  220. #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
  221. IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
  222. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  223. struct kobj_attribute *attr, \
  224. const char *buf, size_t len) \
  225. { \
  226. strncpy(_value, buf, sizeof(_value) - 1); \
  227. strim(_value); \
  228. return len; \
  229. } \
  230. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  231. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  232. sys_##_prefix##_##_name##_show, \
  233. sys_##_prefix##_##_name##_store)
  234. static void make_attrs_ro(struct attribute **attrs)
  235. {
  236. while (*attrs) {
  237. (*attrs)->mode = S_IRUGO;
  238. attrs++;
  239. }
  240. }
  241. /*
  242. * ipl section
  243. */
  244. static __init enum ipl_type get_ipl_type(void)
  245. {
  246. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  247. if (ipl_flags & IPL_NSS_VALID)
  248. return IPL_TYPE_NSS;
  249. if (!(ipl_flags & IPL_DEVNO_VALID))
  250. return IPL_TYPE_UNKNOWN;
  251. if (!(ipl_flags & IPL_PARMBLOCK_VALID))
  252. return IPL_TYPE_CCW;
  253. if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
  254. return IPL_TYPE_UNKNOWN;
  255. if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
  256. return IPL_TYPE_UNKNOWN;
  257. if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
  258. return IPL_TYPE_FCP_DUMP;
  259. return IPL_TYPE_FCP;
  260. }
  261. struct ipl_info ipl_info;
  262. EXPORT_SYMBOL_GPL(ipl_info);
  263. static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
  264. char *page)
  265. {
  266. return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
  267. }
  268. static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
  269. /* VM IPL PARM routines */
  270. static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
  271. const struct ipl_parameter_block *ipb)
  272. {
  273. int i;
  274. size_t len;
  275. char has_lowercase = 0;
  276. len = 0;
  277. if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
  278. (ipb->ipl_info.ccw.vm_parm_len > 0)) {
  279. len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
  280. memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
  281. /* If at least one character is lowercase, we assume mixed
  282. * case; otherwise we convert everything to lowercase.
  283. */
  284. for (i = 0; i < len; i++)
  285. if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
  286. (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
  287. (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
  288. has_lowercase = 1;
  289. break;
  290. }
  291. if (!has_lowercase)
  292. EBC_TOLOWER(dest, len);
  293. EBCASC(dest, len);
  294. }
  295. dest[len] = 0;
  296. return len;
  297. }
  298. size_t append_ipl_vmparm(char *dest, size_t size)
  299. {
  300. size_t rc;
  301. rc = 0;
  302. if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
  303. rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
  304. else
  305. dest[0] = 0;
  306. return rc;
  307. }
  308. static ssize_t ipl_vm_parm_show(struct kobject *kobj,
  309. struct kobj_attribute *attr, char *page)
  310. {
  311. char parm[DIAG308_VMPARM_SIZE + 1] = {};
  312. append_ipl_vmparm(parm, sizeof(parm));
  313. return sprintf(page, "%s\n", parm);
  314. }
  315. static size_t scpdata_length(const char* buf, size_t count)
  316. {
  317. while (count) {
  318. if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
  319. break;
  320. count--;
  321. }
  322. return count;
  323. }
  324. static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
  325. const struct ipl_parameter_block *ipb)
  326. {
  327. size_t count;
  328. size_t i;
  329. int has_lowercase;
  330. count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
  331. ipb->ipl_info.fcp.scp_data_len));
  332. if (!count)
  333. goto out;
  334. has_lowercase = 0;
  335. for (i = 0; i < count; i++) {
  336. if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
  337. count = 0;
  338. goto out;
  339. }
  340. if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
  341. has_lowercase = 1;
  342. }
  343. if (has_lowercase)
  344. memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
  345. else
  346. for (i = 0; i < count; i++)
  347. dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
  348. out:
  349. dest[count] = '\0';
  350. return count;
  351. }
  352. size_t append_ipl_scpdata(char *dest, size_t len)
  353. {
  354. size_t rc;
  355. rc = 0;
  356. if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
  357. rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
  358. else
  359. dest[0] = 0;
  360. return rc;
  361. }
  362. static struct kobj_attribute sys_ipl_vm_parm_attr =
  363. __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
  364. static ssize_t sys_ipl_device_show(struct kobject *kobj,
  365. struct kobj_attribute *attr, char *page)
  366. {
  367. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  368. switch (ipl_info.type) {
  369. case IPL_TYPE_CCW:
  370. return sprintf(page, "0.%x.%04x\n", ipl_ssid, ipl_devno);
  371. case IPL_TYPE_FCP:
  372. case IPL_TYPE_FCP_DUMP:
  373. return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
  374. default:
  375. return 0;
  376. }
  377. }
  378. static struct kobj_attribute sys_ipl_device_attr =
  379. __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
  380. static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
  381. struct bin_attribute *attr, char *buf,
  382. loff_t off, size_t count)
  383. {
  384. return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
  385. IPL_PARMBLOCK_SIZE);
  386. }
  387. static struct bin_attribute ipl_parameter_attr =
  388. __BIN_ATTR(binary_parameter, S_IRUGO, ipl_parameter_read, NULL,
  389. PAGE_SIZE);
  390. static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
  391. struct bin_attribute *attr, char *buf,
  392. loff_t off, size_t count)
  393. {
  394. unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
  395. void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
  396. return memory_read_from_buffer(buf, count, &off, scp_data, size);
  397. }
  398. static struct bin_attribute ipl_scp_data_attr =
  399. __BIN_ATTR(scp_data, S_IRUGO, ipl_scp_data_read, NULL, PAGE_SIZE);
  400. static struct bin_attribute *ipl_fcp_bin_attrs[] = {
  401. &ipl_parameter_attr,
  402. &ipl_scp_data_attr,
  403. NULL,
  404. };
  405. /* FCP ipl device attributes */
  406. DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
  407. IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
  408. DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
  409. IPL_PARMBLOCK_START->ipl_info.fcp.lun);
  410. DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
  411. IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
  412. DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
  413. IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
  414. static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
  415. struct kobj_attribute *attr, char *page)
  416. {
  417. char loadparm[LOADPARM_LEN + 1] = {};
  418. if (!sclp_ipl_info.is_valid)
  419. return sprintf(page, "#unknown#\n");
  420. memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
  421. EBCASC(loadparm, LOADPARM_LEN);
  422. strim(loadparm);
  423. return sprintf(page, "%s\n", loadparm);
  424. }
  425. static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
  426. __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
  427. static struct attribute *ipl_fcp_attrs[] = {
  428. &sys_ipl_type_attr.attr,
  429. &sys_ipl_device_attr.attr,
  430. &sys_ipl_fcp_wwpn_attr.attr,
  431. &sys_ipl_fcp_lun_attr.attr,
  432. &sys_ipl_fcp_bootprog_attr.attr,
  433. &sys_ipl_fcp_br_lba_attr.attr,
  434. &sys_ipl_ccw_loadparm_attr.attr,
  435. NULL,
  436. };
  437. static struct attribute_group ipl_fcp_attr_group = {
  438. .attrs = ipl_fcp_attrs,
  439. .bin_attrs = ipl_fcp_bin_attrs,
  440. };
  441. /* CCW ipl device attributes */
  442. static struct attribute *ipl_ccw_attrs_vm[] = {
  443. &sys_ipl_type_attr.attr,
  444. &sys_ipl_device_attr.attr,
  445. &sys_ipl_ccw_loadparm_attr.attr,
  446. &sys_ipl_vm_parm_attr.attr,
  447. NULL,
  448. };
  449. static struct attribute *ipl_ccw_attrs_lpar[] = {
  450. &sys_ipl_type_attr.attr,
  451. &sys_ipl_device_attr.attr,
  452. &sys_ipl_ccw_loadparm_attr.attr,
  453. NULL,
  454. };
  455. static struct attribute_group ipl_ccw_attr_group_vm = {
  456. .attrs = ipl_ccw_attrs_vm,
  457. };
  458. static struct attribute_group ipl_ccw_attr_group_lpar = {
  459. .attrs = ipl_ccw_attrs_lpar
  460. };
  461. /* NSS ipl device attributes */
  462. DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
  463. static struct attribute *ipl_nss_attrs[] = {
  464. &sys_ipl_type_attr.attr,
  465. &sys_ipl_nss_name_attr.attr,
  466. &sys_ipl_ccw_loadparm_attr.attr,
  467. &sys_ipl_vm_parm_attr.attr,
  468. NULL,
  469. };
  470. static struct attribute_group ipl_nss_attr_group = {
  471. .attrs = ipl_nss_attrs,
  472. };
  473. /* UNKNOWN ipl device attributes */
  474. static struct attribute *ipl_unknown_attrs[] = {
  475. &sys_ipl_type_attr.attr,
  476. NULL,
  477. };
  478. static struct attribute_group ipl_unknown_attr_group = {
  479. .attrs = ipl_unknown_attrs,
  480. };
  481. static struct kset *ipl_kset;
  482. static void __ipl_run(void *unused)
  483. {
  484. __bpon();
  485. diag308(DIAG308_LOAD_CLEAR, NULL);
  486. if (MACHINE_IS_VM)
  487. __cpcmd("IPL", NULL, 0, NULL);
  488. else if (ipl_info.type == IPL_TYPE_CCW)
  489. reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
  490. }
  491. static void ipl_run(struct shutdown_trigger *trigger)
  492. {
  493. smp_call_ipl_cpu(__ipl_run, NULL);
  494. }
  495. static int __init ipl_init(void)
  496. {
  497. int rc;
  498. ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
  499. if (!ipl_kset) {
  500. rc = -ENOMEM;
  501. goto out;
  502. }
  503. switch (ipl_info.type) {
  504. case IPL_TYPE_CCW:
  505. if (MACHINE_IS_VM)
  506. rc = sysfs_create_group(&ipl_kset->kobj,
  507. &ipl_ccw_attr_group_vm);
  508. else
  509. rc = sysfs_create_group(&ipl_kset->kobj,
  510. &ipl_ccw_attr_group_lpar);
  511. break;
  512. case IPL_TYPE_FCP:
  513. case IPL_TYPE_FCP_DUMP:
  514. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
  515. break;
  516. case IPL_TYPE_NSS:
  517. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
  518. break;
  519. default:
  520. rc = sysfs_create_group(&ipl_kset->kobj,
  521. &ipl_unknown_attr_group);
  522. break;
  523. }
  524. out:
  525. if (rc)
  526. panic("ipl_init failed: rc = %i\n", rc);
  527. return 0;
  528. }
  529. static struct shutdown_action __refdata ipl_action = {
  530. .name = SHUTDOWN_ACTION_IPL_STR,
  531. .fn = ipl_run,
  532. .init = ipl_init,
  533. };
  534. /*
  535. * reipl shutdown action: Reboot Linux on shutdown.
  536. */
  537. /* VM IPL PARM attributes */
  538. static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
  539. char *page)
  540. {
  541. char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
  542. reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
  543. return sprintf(page, "%s\n", vmparm);
  544. }
  545. static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
  546. size_t vmparm_max,
  547. const char *buf, size_t len)
  548. {
  549. int i, ip_len;
  550. /* ignore trailing newline */
  551. ip_len = len;
  552. if ((len > 0) && (buf[len - 1] == '\n'))
  553. ip_len--;
  554. if (ip_len > vmparm_max)
  555. return -EINVAL;
  556. /* parm is used to store kernel options, check for common chars */
  557. for (i = 0; i < ip_len; i++)
  558. if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
  559. return -EINVAL;
  560. memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
  561. ipb->ipl_info.ccw.vm_parm_len = ip_len;
  562. if (ip_len > 0) {
  563. ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
  564. memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
  565. ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
  566. } else {
  567. ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
  568. }
  569. return len;
  570. }
  571. /* NSS wrapper */
  572. static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
  573. struct kobj_attribute *attr, char *page)
  574. {
  575. return reipl_generic_vmparm_show(reipl_block_nss, page);
  576. }
  577. static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
  578. struct kobj_attribute *attr,
  579. const char *buf, size_t len)
  580. {
  581. return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
  582. }
  583. /* CCW wrapper */
  584. static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
  585. struct kobj_attribute *attr, char *page)
  586. {
  587. return reipl_generic_vmparm_show(reipl_block_ccw, page);
  588. }
  589. static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
  590. struct kobj_attribute *attr,
  591. const char *buf, size_t len)
  592. {
  593. return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
  594. }
  595. static struct kobj_attribute sys_reipl_nss_vmparm_attr =
  596. __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
  597. reipl_nss_vmparm_store);
  598. static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
  599. __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
  600. reipl_ccw_vmparm_store);
  601. /* FCP reipl device attributes */
  602. static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
  603. struct bin_attribute *attr,
  604. char *buf, loff_t off, size_t count)
  605. {
  606. size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
  607. void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
  608. return memory_read_from_buffer(buf, count, &off, scp_data, size);
  609. }
  610. static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
  611. struct bin_attribute *attr,
  612. char *buf, loff_t off, size_t count)
  613. {
  614. size_t scpdata_len = count;
  615. size_t padding;
  616. if (off)
  617. return -EINVAL;
  618. memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf, count);
  619. if (scpdata_len % 8) {
  620. padding = 8 - (scpdata_len % 8);
  621. memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
  622. 0, padding);
  623. scpdata_len += padding;
  624. }
  625. reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
  626. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
  627. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
  628. return count;
  629. }
  630. static struct bin_attribute sys_reipl_fcp_scp_data_attr =
  631. __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_fcp_scpdata_read,
  632. reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
  633. static struct bin_attribute *reipl_fcp_bin_attrs[] = {
  634. &sys_reipl_fcp_scp_data_attr,
  635. NULL,
  636. };
  637. DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
  638. reipl_block_fcp->ipl_info.fcp.wwpn);
  639. DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
  640. reipl_block_fcp->ipl_info.fcp.lun);
  641. DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
  642. reipl_block_fcp->ipl_info.fcp.bootprog);
  643. DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
  644. reipl_block_fcp->ipl_info.fcp.br_lba);
  645. DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  646. reipl_block_fcp->ipl_info.fcp.devno);
  647. static void reipl_get_ascii_loadparm(char *loadparm,
  648. struct ipl_parameter_block *ibp)
  649. {
  650. memcpy(loadparm, ibp->hdr.loadparm, LOADPARM_LEN);
  651. EBCASC(loadparm, LOADPARM_LEN);
  652. loadparm[LOADPARM_LEN] = 0;
  653. strim(loadparm);
  654. }
  655. static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
  656. char *page)
  657. {
  658. char buf[LOADPARM_LEN + 1];
  659. reipl_get_ascii_loadparm(buf, ipb);
  660. return sprintf(page, "%s\n", buf);
  661. }
  662. static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
  663. const char *buf, size_t len)
  664. {
  665. int i, lp_len;
  666. /* ignore trailing newline */
  667. lp_len = len;
  668. if ((len > 0) && (buf[len - 1] == '\n'))
  669. lp_len--;
  670. /* loadparm can have max 8 characters and must not start with a blank */
  671. if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
  672. return -EINVAL;
  673. /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
  674. for (i = 0; i < lp_len; i++) {
  675. if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
  676. (buf[i] == '.'))
  677. continue;
  678. return -EINVAL;
  679. }
  680. /* initialize loadparm with blanks */
  681. memset(ipb->hdr.loadparm, ' ', LOADPARM_LEN);
  682. /* copy and convert to ebcdic */
  683. memcpy(ipb->hdr.loadparm, buf, lp_len);
  684. ASCEBC(ipb->hdr.loadparm, LOADPARM_LEN);
  685. ipb->hdr.flags |= DIAG308_FLAGS_LP_VALID;
  686. return len;
  687. }
  688. /* FCP wrapper */
  689. static ssize_t reipl_fcp_loadparm_show(struct kobject *kobj,
  690. struct kobj_attribute *attr, char *page)
  691. {
  692. return reipl_generic_loadparm_show(reipl_block_fcp, page);
  693. }
  694. static ssize_t reipl_fcp_loadparm_store(struct kobject *kobj,
  695. struct kobj_attribute *attr,
  696. const char *buf, size_t len)
  697. {
  698. return reipl_generic_loadparm_store(reipl_block_fcp, buf, len);
  699. }
  700. static struct kobj_attribute sys_reipl_fcp_loadparm_attr =
  701. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_fcp_loadparm_show,
  702. reipl_fcp_loadparm_store);
  703. static struct attribute *reipl_fcp_attrs[] = {
  704. &sys_reipl_fcp_device_attr.attr,
  705. &sys_reipl_fcp_wwpn_attr.attr,
  706. &sys_reipl_fcp_lun_attr.attr,
  707. &sys_reipl_fcp_bootprog_attr.attr,
  708. &sys_reipl_fcp_br_lba_attr.attr,
  709. &sys_reipl_fcp_loadparm_attr.attr,
  710. NULL,
  711. };
  712. static struct attribute_group reipl_fcp_attr_group = {
  713. .attrs = reipl_fcp_attrs,
  714. .bin_attrs = reipl_fcp_bin_attrs,
  715. };
  716. /* CCW reipl device attributes */
  717. DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ipl_info.ccw);
  718. /* NSS wrapper */
  719. static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
  720. struct kobj_attribute *attr, char *page)
  721. {
  722. return reipl_generic_loadparm_show(reipl_block_nss, page);
  723. }
  724. static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
  725. struct kobj_attribute *attr,
  726. const char *buf, size_t len)
  727. {
  728. return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
  729. }
  730. /* CCW wrapper */
  731. static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
  732. struct kobj_attribute *attr, char *page)
  733. {
  734. return reipl_generic_loadparm_show(reipl_block_ccw, page);
  735. }
  736. static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
  737. struct kobj_attribute *attr,
  738. const char *buf, size_t len)
  739. {
  740. return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
  741. }
  742. static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
  743. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
  744. reipl_ccw_loadparm_store);
  745. static struct attribute *reipl_ccw_attrs_vm[] = {
  746. &sys_reipl_ccw_device_attr.attr,
  747. &sys_reipl_ccw_loadparm_attr.attr,
  748. &sys_reipl_ccw_vmparm_attr.attr,
  749. NULL,
  750. };
  751. static struct attribute *reipl_ccw_attrs_lpar[] = {
  752. &sys_reipl_ccw_device_attr.attr,
  753. &sys_reipl_ccw_loadparm_attr.attr,
  754. NULL,
  755. };
  756. static struct attribute_group reipl_ccw_attr_group_vm = {
  757. .name = IPL_CCW_STR,
  758. .attrs = reipl_ccw_attrs_vm,
  759. };
  760. static struct attribute_group reipl_ccw_attr_group_lpar = {
  761. .name = IPL_CCW_STR,
  762. .attrs = reipl_ccw_attrs_lpar,
  763. };
  764. /* NSS reipl device attributes */
  765. static void reipl_get_ascii_nss_name(char *dst,
  766. struct ipl_parameter_block *ipb)
  767. {
  768. memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
  769. EBCASC(dst, NSS_NAME_SIZE);
  770. dst[NSS_NAME_SIZE] = 0;
  771. }
  772. static ssize_t reipl_nss_name_show(struct kobject *kobj,
  773. struct kobj_attribute *attr, char *page)
  774. {
  775. char nss_name[NSS_NAME_SIZE + 1] = {};
  776. reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
  777. return sprintf(page, "%s\n", nss_name);
  778. }
  779. static ssize_t reipl_nss_name_store(struct kobject *kobj,
  780. struct kobj_attribute *attr,
  781. const char *buf, size_t len)
  782. {
  783. int nss_len;
  784. /* ignore trailing newline */
  785. nss_len = len;
  786. if ((len > 0) && (buf[len - 1] == '\n'))
  787. nss_len--;
  788. if (nss_len > NSS_NAME_SIZE)
  789. return -EINVAL;
  790. memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
  791. if (nss_len > 0) {
  792. reipl_block_nss->ipl_info.ccw.vm_flags |=
  793. DIAG308_VM_FLAGS_NSS_VALID;
  794. memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
  795. ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
  796. EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
  797. } else {
  798. reipl_block_nss->ipl_info.ccw.vm_flags &=
  799. ~DIAG308_VM_FLAGS_NSS_VALID;
  800. }
  801. return len;
  802. }
  803. static struct kobj_attribute sys_reipl_nss_name_attr =
  804. __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
  805. reipl_nss_name_store);
  806. static struct kobj_attribute sys_reipl_nss_loadparm_attr =
  807. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
  808. reipl_nss_loadparm_store);
  809. static struct attribute *reipl_nss_attrs[] = {
  810. &sys_reipl_nss_name_attr.attr,
  811. &sys_reipl_nss_loadparm_attr.attr,
  812. &sys_reipl_nss_vmparm_attr.attr,
  813. NULL,
  814. };
  815. static struct attribute_group reipl_nss_attr_group = {
  816. .name = IPL_NSS_STR,
  817. .attrs = reipl_nss_attrs,
  818. };
  819. static void set_reipl_block_actual(struct ipl_parameter_block *reipl_block)
  820. {
  821. reipl_block_actual = reipl_block;
  822. os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
  823. reipl_block->hdr.len);
  824. }
  825. /* reipl type */
  826. static int reipl_set_type(enum ipl_type type)
  827. {
  828. if (!(reipl_capabilities & type))
  829. return -EINVAL;
  830. switch(type) {
  831. case IPL_TYPE_CCW:
  832. if (diag308_set_works)
  833. reipl_method = REIPL_METHOD_CCW_DIAG;
  834. else if (MACHINE_IS_VM)
  835. reipl_method = REIPL_METHOD_CCW_VM;
  836. else
  837. reipl_method = REIPL_METHOD_CCW_CIO;
  838. set_reipl_block_actual(reipl_block_ccw);
  839. break;
  840. case IPL_TYPE_FCP:
  841. if (diag308_set_works)
  842. reipl_method = REIPL_METHOD_FCP_RW_DIAG;
  843. else if (MACHINE_IS_VM)
  844. reipl_method = REIPL_METHOD_FCP_RO_VM;
  845. else
  846. reipl_method = REIPL_METHOD_FCP_RO_DIAG;
  847. set_reipl_block_actual(reipl_block_fcp);
  848. break;
  849. case IPL_TYPE_FCP_DUMP:
  850. reipl_method = REIPL_METHOD_FCP_DUMP;
  851. break;
  852. case IPL_TYPE_NSS:
  853. if (diag308_set_works)
  854. reipl_method = REIPL_METHOD_NSS_DIAG;
  855. else
  856. reipl_method = REIPL_METHOD_NSS;
  857. set_reipl_block_actual(reipl_block_nss);
  858. break;
  859. case IPL_TYPE_UNKNOWN:
  860. reipl_method = REIPL_METHOD_DEFAULT;
  861. break;
  862. default:
  863. BUG();
  864. }
  865. reipl_type = type;
  866. return 0;
  867. }
  868. static ssize_t reipl_type_show(struct kobject *kobj,
  869. struct kobj_attribute *attr, char *page)
  870. {
  871. return sprintf(page, "%s\n", ipl_type_str(reipl_type));
  872. }
  873. static ssize_t reipl_type_store(struct kobject *kobj,
  874. struct kobj_attribute *attr,
  875. const char *buf, size_t len)
  876. {
  877. int rc = -EINVAL;
  878. if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  879. rc = reipl_set_type(IPL_TYPE_CCW);
  880. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  881. rc = reipl_set_type(IPL_TYPE_FCP);
  882. else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
  883. rc = reipl_set_type(IPL_TYPE_NSS);
  884. return (rc != 0) ? rc : len;
  885. }
  886. static struct kobj_attribute reipl_type_attr =
  887. __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
  888. static struct kset *reipl_kset;
  889. static struct kset *reipl_fcp_kset;
  890. static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
  891. const enum ipl_method m)
  892. {
  893. char loadparm[LOADPARM_LEN + 1] = {};
  894. char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
  895. char nss_name[NSS_NAME_SIZE + 1] = {};
  896. size_t pos = 0;
  897. reipl_get_ascii_loadparm(loadparm, ipb);
  898. reipl_get_ascii_nss_name(nss_name, ipb);
  899. reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
  900. switch (m) {
  901. case REIPL_METHOD_CCW_VM:
  902. pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
  903. break;
  904. case REIPL_METHOD_NSS:
  905. pos = sprintf(dst, "IPL %s", nss_name);
  906. break;
  907. default:
  908. break;
  909. }
  910. if (strlen(loadparm) > 0)
  911. pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
  912. if (strlen(vmparm) > 0)
  913. sprintf(dst + pos, " PARM %s", vmparm);
  914. }
  915. static void __reipl_run(void *unused)
  916. {
  917. struct ccw_dev_id devid;
  918. static char buf[128];
  919. switch (reipl_method) {
  920. case REIPL_METHOD_CCW_CIO:
  921. devid.ssid = reipl_block_ccw->ipl_info.ccw.ssid;
  922. devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
  923. reipl_ccw_dev(&devid);
  924. break;
  925. case REIPL_METHOD_CCW_VM:
  926. get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
  927. __cpcmd(buf, NULL, 0, NULL);
  928. break;
  929. case REIPL_METHOD_CCW_DIAG:
  930. diag308(DIAG308_SET, reipl_block_ccw);
  931. if (MACHINE_IS_LPAR)
  932. diag308(DIAG308_LOAD_NORMAL_DUMP, NULL);
  933. else
  934. diag308(DIAG308_LOAD_CLEAR, NULL);
  935. break;
  936. case REIPL_METHOD_FCP_RW_DIAG:
  937. diag308(DIAG308_SET, reipl_block_fcp);
  938. diag308(DIAG308_LOAD_CLEAR, NULL);
  939. break;
  940. case REIPL_METHOD_FCP_RO_DIAG:
  941. diag308(DIAG308_LOAD_CLEAR, NULL);
  942. break;
  943. case REIPL_METHOD_FCP_RO_VM:
  944. __cpcmd("IPL", NULL, 0, NULL);
  945. break;
  946. case REIPL_METHOD_NSS_DIAG:
  947. diag308(DIAG308_SET, reipl_block_nss);
  948. diag308(DIAG308_LOAD_CLEAR, NULL);
  949. break;
  950. case REIPL_METHOD_NSS:
  951. get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
  952. __cpcmd(buf, NULL, 0, NULL);
  953. break;
  954. case REIPL_METHOD_DEFAULT:
  955. if (MACHINE_IS_VM)
  956. __cpcmd("IPL", NULL, 0, NULL);
  957. diag308(DIAG308_LOAD_CLEAR, NULL);
  958. break;
  959. case REIPL_METHOD_FCP_DUMP:
  960. break;
  961. }
  962. disabled_wait((unsigned long) __builtin_return_address(0));
  963. }
  964. static void reipl_run(struct shutdown_trigger *trigger)
  965. {
  966. smp_call_ipl_cpu(__reipl_run, NULL);
  967. }
  968. static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
  969. {
  970. ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
  971. ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
  972. ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  973. ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  974. }
  975. static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
  976. {
  977. /* LOADPARM */
  978. /* check if read scp info worked and set loadparm */
  979. if (sclp_ipl_info.is_valid)
  980. memcpy(ipb->hdr.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
  981. else
  982. /* read scp info failed: set empty loadparm (EBCDIC blanks) */
  983. memset(ipb->hdr.loadparm, 0x40, LOADPARM_LEN);
  984. ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
  985. /* VM PARM */
  986. if (MACHINE_IS_VM && diag308_set_works &&
  987. (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
  988. ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
  989. ipb->ipl_info.ccw.vm_parm_len =
  990. ipl_block.ipl_info.ccw.vm_parm_len;
  991. memcpy(ipb->ipl_info.ccw.vm_parm,
  992. ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
  993. }
  994. }
  995. static int __init reipl_nss_init(void)
  996. {
  997. int rc;
  998. if (!MACHINE_IS_VM)
  999. return 0;
  1000. reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
  1001. if (!reipl_block_nss)
  1002. return -ENOMEM;
  1003. if (!diag308_set_works)
  1004. sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
  1005. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
  1006. if (rc)
  1007. return rc;
  1008. reipl_block_ccw_init(reipl_block_nss);
  1009. if (ipl_info.type == IPL_TYPE_NSS) {
  1010. memset(reipl_block_nss->ipl_info.ccw.nss_name,
  1011. ' ', NSS_NAME_SIZE);
  1012. memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
  1013. kernel_nss_name, strlen(kernel_nss_name));
  1014. ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
  1015. reipl_block_nss->ipl_info.ccw.vm_flags |=
  1016. DIAG308_VM_FLAGS_NSS_VALID;
  1017. reipl_block_ccw_fill_parms(reipl_block_nss);
  1018. }
  1019. reipl_capabilities |= IPL_TYPE_NSS;
  1020. return 0;
  1021. }
  1022. static int __init reipl_ccw_init(void)
  1023. {
  1024. int rc;
  1025. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  1026. if (!reipl_block_ccw)
  1027. return -ENOMEM;
  1028. if (MACHINE_IS_VM) {
  1029. if (!diag308_set_works)
  1030. sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
  1031. rc = sysfs_create_group(&reipl_kset->kobj,
  1032. &reipl_ccw_attr_group_vm);
  1033. } else {
  1034. if(!diag308_set_works)
  1035. sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
  1036. rc = sysfs_create_group(&reipl_kset->kobj,
  1037. &reipl_ccw_attr_group_lpar);
  1038. }
  1039. if (rc)
  1040. return rc;
  1041. reipl_block_ccw_init(reipl_block_ccw);
  1042. if (ipl_info.type == IPL_TYPE_CCW) {
  1043. reipl_block_ccw->ipl_info.ccw.ssid = ipl_ssid;
  1044. reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
  1045. reipl_block_ccw_fill_parms(reipl_block_ccw);
  1046. }
  1047. reipl_capabilities |= IPL_TYPE_CCW;
  1048. return 0;
  1049. }
  1050. static int __init reipl_fcp_init(void)
  1051. {
  1052. int rc;
  1053. if (!diag308_set_works) {
  1054. if (ipl_info.type == IPL_TYPE_FCP) {
  1055. make_attrs_ro(reipl_fcp_attrs);
  1056. sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
  1057. } else
  1058. return 0;
  1059. }
  1060. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  1061. if (!reipl_block_fcp)
  1062. return -ENOMEM;
  1063. /* sysfs: create fcp kset for mixing attr group and bin attrs */
  1064. reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
  1065. &reipl_kset->kobj);
  1066. if (!reipl_fcp_kset) {
  1067. free_page((unsigned long) reipl_block_fcp);
  1068. return -ENOMEM;
  1069. }
  1070. rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
  1071. if (rc) {
  1072. kset_unregister(reipl_fcp_kset);
  1073. free_page((unsigned long) reipl_block_fcp);
  1074. return rc;
  1075. }
  1076. if (ipl_info.type == IPL_TYPE_FCP) {
  1077. memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
  1078. /*
  1079. * Fix loadparm: There are systems where the (SCSI) LOADPARM
  1080. * is invalid in the SCSI IPL parameter block, so take it
  1081. * always from sclp_ipl_info.
  1082. */
  1083. memcpy(reipl_block_fcp->hdr.loadparm, sclp_ipl_info.loadparm,
  1084. LOADPARM_LEN);
  1085. } else {
  1086. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  1087. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  1088. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  1089. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  1090. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  1091. }
  1092. reipl_capabilities |= IPL_TYPE_FCP;
  1093. return 0;
  1094. }
  1095. static int __init reipl_type_init(void)
  1096. {
  1097. enum ipl_type reipl_type = ipl_info.type;
  1098. struct ipl_parameter_block *reipl_block;
  1099. unsigned long size;
  1100. reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
  1101. if (!reipl_block)
  1102. goto out;
  1103. /*
  1104. * If we have an OS info reipl block, this will be used
  1105. */
  1106. if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) {
  1107. memcpy(reipl_block_fcp, reipl_block, size);
  1108. reipl_type = IPL_TYPE_FCP;
  1109. } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) {
  1110. memcpy(reipl_block_ccw, reipl_block, size);
  1111. reipl_type = IPL_TYPE_CCW;
  1112. }
  1113. out:
  1114. return reipl_set_type(reipl_type);
  1115. }
  1116. static int __init reipl_init(void)
  1117. {
  1118. int rc;
  1119. reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
  1120. if (!reipl_kset)
  1121. return -ENOMEM;
  1122. rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
  1123. if (rc) {
  1124. kset_unregister(reipl_kset);
  1125. return rc;
  1126. }
  1127. rc = reipl_ccw_init();
  1128. if (rc)
  1129. return rc;
  1130. rc = reipl_fcp_init();
  1131. if (rc)
  1132. return rc;
  1133. rc = reipl_nss_init();
  1134. if (rc)
  1135. return rc;
  1136. return reipl_type_init();
  1137. }
  1138. static struct shutdown_action __refdata reipl_action = {
  1139. .name = SHUTDOWN_ACTION_REIPL_STR,
  1140. .fn = reipl_run,
  1141. .init = reipl_init,
  1142. };
  1143. /*
  1144. * dump shutdown action: Dump Linux on shutdown.
  1145. */
  1146. /* FCP dump device attributes */
  1147. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
  1148. dump_block_fcp->ipl_info.fcp.wwpn);
  1149. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
  1150. dump_block_fcp->ipl_info.fcp.lun);
  1151. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  1152. dump_block_fcp->ipl_info.fcp.bootprog);
  1153. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  1154. dump_block_fcp->ipl_info.fcp.br_lba);
  1155. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  1156. dump_block_fcp->ipl_info.fcp.devno);
  1157. static struct attribute *dump_fcp_attrs[] = {
  1158. &sys_dump_fcp_device_attr.attr,
  1159. &sys_dump_fcp_wwpn_attr.attr,
  1160. &sys_dump_fcp_lun_attr.attr,
  1161. &sys_dump_fcp_bootprog_attr.attr,
  1162. &sys_dump_fcp_br_lba_attr.attr,
  1163. NULL,
  1164. };
  1165. static struct attribute_group dump_fcp_attr_group = {
  1166. .name = IPL_FCP_STR,
  1167. .attrs = dump_fcp_attrs,
  1168. };
  1169. /* CCW dump device attributes */
  1170. DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ipl_info.ccw);
  1171. static struct attribute *dump_ccw_attrs[] = {
  1172. &sys_dump_ccw_device_attr.attr,
  1173. NULL,
  1174. };
  1175. static struct attribute_group dump_ccw_attr_group = {
  1176. .name = IPL_CCW_STR,
  1177. .attrs = dump_ccw_attrs,
  1178. };
  1179. /* dump type */
  1180. static int dump_set_type(enum dump_type type)
  1181. {
  1182. if (!(dump_capabilities & type))
  1183. return -EINVAL;
  1184. switch (type) {
  1185. case DUMP_TYPE_CCW:
  1186. if (diag308_set_works)
  1187. dump_method = DUMP_METHOD_CCW_DIAG;
  1188. else if (MACHINE_IS_VM)
  1189. dump_method = DUMP_METHOD_CCW_VM;
  1190. else
  1191. dump_method = DUMP_METHOD_CCW_CIO;
  1192. break;
  1193. case DUMP_TYPE_FCP:
  1194. dump_method = DUMP_METHOD_FCP_DIAG;
  1195. break;
  1196. default:
  1197. dump_method = DUMP_METHOD_NONE;
  1198. }
  1199. dump_type = type;
  1200. return 0;
  1201. }
  1202. static ssize_t dump_type_show(struct kobject *kobj,
  1203. struct kobj_attribute *attr, char *page)
  1204. {
  1205. return sprintf(page, "%s\n", dump_type_str(dump_type));
  1206. }
  1207. static ssize_t dump_type_store(struct kobject *kobj,
  1208. struct kobj_attribute *attr,
  1209. const char *buf, size_t len)
  1210. {
  1211. int rc = -EINVAL;
  1212. if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
  1213. rc = dump_set_type(DUMP_TYPE_NONE);
  1214. else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
  1215. rc = dump_set_type(DUMP_TYPE_CCW);
  1216. else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
  1217. rc = dump_set_type(DUMP_TYPE_FCP);
  1218. return (rc != 0) ? rc : len;
  1219. }
  1220. static struct kobj_attribute dump_type_attr =
  1221. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  1222. static struct kset *dump_kset;
  1223. static void diag308_dump(void *dump_block)
  1224. {
  1225. diag308(DIAG308_SET, dump_block);
  1226. while (1) {
  1227. if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
  1228. break;
  1229. udelay_simple(USEC_PER_SEC);
  1230. }
  1231. }
  1232. static void __dump_run(void *unused)
  1233. {
  1234. struct ccw_dev_id devid;
  1235. static char buf[100];
  1236. switch (dump_method) {
  1237. case DUMP_METHOD_CCW_CIO:
  1238. devid.ssid = dump_block_ccw->ipl_info.ccw.ssid;
  1239. devid.devno = dump_block_ccw->ipl_info.ccw.devno;
  1240. reipl_ccw_dev(&devid);
  1241. break;
  1242. case DUMP_METHOD_CCW_VM:
  1243. sprintf(buf, "STORE STATUS");
  1244. __cpcmd(buf, NULL, 0, NULL);
  1245. sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
  1246. __cpcmd(buf, NULL, 0, NULL);
  1247. break;
  1248. case DUMP_METHOD_CCW_DIAG:
  1249. diag308_dump(dump_block_ccw);
  1250. break;
  1251. case DUMP_METHOD_FCP_DIAG:
  1252. diag308_dump(dump_block_fcp);
  1253. break;
  1254. default:
  1255. break;
  1256. }
  1257. }
  1258. static void dump_run(struct shutdown_trigger *trigger)
  1259. {
  1260. if (dump_method == DUMP_METHOD_NONE)
  1261. return;
  1262. smp_send_stop();
  1263. smp_call_ipl_cpu(__dump_run, NULL);
  1264. }
  1265. static int __init dump_ccw_init(void)
  1266. {
  1267. int rc;
  1268. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  1269. if (!dump_block_ccw)
  1270. return -ENOMEM;
  1271. rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
  1272. if (rc) {
  1273. free_page((unsigned long)dump_block_ccw);
  1274. return rc;
  1275. }
  1276. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  1277. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  1278. dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  1279. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  1280. dump_capabilities |= DUMP_TYPE_CCW;
  1281. return 0;
  1282. }
  1283. static int __init dump_fcp_init(void)
  1284. {
  1285. int rc;
  1286. if (!sclp_ipl_info.has_dump)
  1287. return 0; /* LDIPL DUMP is not installed */
  1288. if (!diag308_set_works)
  1289. return 0;
  1290. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  1291. if (!dump_block_fcp)
  1292. return -ENOMEM;
  1293. rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
  1294. if (rc) {
  1295. free_page((unsigned long)dump_block_fcp);
  1296. return rc;
  1297. }
  1298. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  1299. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  1300. dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  1301. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  1302. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  1303. dump_capabilities |= DUMP_TYPE_FCP;
  1304. return 0;
  1305. }
  1306. static int __init dump_init(void)
  1307. {
  1308. int rc;
  1309. dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
  1310. if (!dump_kset)
  1311. return -ENOMEM;
  1312. rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
  1313. if (rc) {
  1314. kset_unregister(dump_kset);
  1315. return rc;
  1316. }
  1317. rc = dump_ccw_init();
  1318. if (rc)
  1319. return rc;
  1320. rc = dump_fcp_init();
  1321. if (rc)
  1322. return rc;
  1323. dump_set_type(DUMP_TYPE_NONE);
  1324. return 0;
  1325. }
  1326. static struct shutdown_action __refdata dump_action = {
  1327. .name = SHUTDOWN_ACTION_DUMP_STR,
  1328. .fn = dump_run,
  1329. .init = dump_init,
  1330. };
  1331. static void dump_reipl_run(struct shutdown_trigger *trigger)
  1332. {
  1333. unsigned long ipib = (unsigned long) reipl_block_actual;
  1334. unsigned int csum;
  1335. csum = csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
  1336. mem_assign_absolute(S390_lowcore.ipib, ipib);
  1337. mem_assign_absolute(S390_lowcore.ipib_checksum, csum);
  1338. dump_run(trigger);
  1339. }
  1340. static int __init dump_reipl_init(void)
  1341. {
  1342. if (!diag308_set_works)
  1343. return -EOPNOTSUPP;
  1344. else
  1345. return 0;
  1346. }
  1347. static struct shutdown_action __refdata dump_reipl_action = {
  1348. .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
  1349. .fn = dump_reipl_run,
  1350. .init = dump_reipl_init,
  1351. };
  1352. /*
  1353. * vmcmd shutdown action: Trigger vm command on shutdown.
  1354. */
  1355. static char vmcmd_on_reboot[128];
  1356. static char vmcmd_on_panic[128];
  1357. static char vmcmd_on_halt[128];
  1358. static char vmcmd_on_poff[128];
  1359. static char vmcmd_on_restart[128];
  1360. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
  1361. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
  1362. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
  1363. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
  1364. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
  1365. static struct attribute *vmcmd_attrs[] = {
  1366. &sys_vmcmd_on_reboot_attr.attr,
  1367. &sys_vmcmd_on_panic_attr.attr,
  1368. &sys_vmcmd_on_halt_attr.attr,
  1369. &sys_vmcmd_on_poff_attr.attr,
  1370. &sys_vmcmd_on_restart_attr.attr,
  1371. NULL,
  1372. };
  1373. static struct attribute_group vmcmd_attr_group = {
  1374. .attrs = vmcmd_attrs,
  1375. };
  1376. static struct kset *vmcmd_kset;
  1377. static void vmcmd_run(struct shutdown_trigger *trigger)
  1378. {
  1379. char *cmd;
  1380. if (strcmp(trigger->name, ON_REIPL_STR) == 0)
  1381. cmd = vmcmd_on_reboot;
  1382. else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  1383. cmd = vmcmd_on_panic;
  1384. else if (strcmp(trigger->name, ON_HALT_STR) == 0)
  1385. cmd = vmcmd_on_halt;
  1386. else if (strcmp(trigger->name, ON_POFF_STR) == 0)
  1387. cmd = vmcmd_on_poff;
  1388. else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
  1389. cmd = vmcmd_on_restart;
  1390. else
  1391. return;
  1392. if (strlen(cmd) == 0)
  1393. return;
  1394. __cpcmd(cmd, NULL, 0, NULL);
  1395. }
  1396. static int vmcmd_init(void)
  1397. {
  1398. if (!MACHINE_IS_VM)
  1399. return -EOPNOTSUPP;
  1400. vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
  1401. if (!vmcmd_kset)
  1402. return -ENOMEM;
  1403. return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
  1404. }
  1405. static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
  1406. vmcmd_run, vmcmd_init};
  1407. /*
  1408. * stop shutdown action: Stop Linux on shutdown.
  1409. */
  1410. static void stop_run(struct shutdown_trigger *trigger)
  1411. {
  1412. if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
  1413. strcmp(trigger->name, ON_RESTART_STR) == 0)
  1414. disabled_wait((unsigned long) __builtin_return_address(0));
  1415. smp_stop_cpu();
  1416. }
  1417. static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
  1418. stop_run, NULL};
  1419. /* action list */
  1420. static struct shutdown_action *shutdown_actions_list[] = {
  1421. &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
  1422. &vmcmd_action, &stop_action};
  1423. #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
  1424. /*
  1425. * Trigger section
  1426. */
  1427. static struct kset *shutdown_actions_kset;
  1428. static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
  1429. size_t len)
  1430. {
  1431. int i;
  1432. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1433. if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
  1434. if (shutdown_actions_list[i]->init_rc) {
  1435. return shutdown_actions_list[i]->init_rc;
  1436. } else {
  1437. trigger->action = shutdown_actions_list[i];
  1438. return len;
  1439. }
  1440. }
  1441. }
  1442. return -EINVAL;
  1443. }
  1444. /* on reipl */
  1445. static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
  1446. &reipl_action};
  1447. static ssize_t on_reboot_show(struct kobject *kobj,
  1448. struct kobj_attribute *attr, char *page)
  1449. {
  1450. return sprintf(page, "%s\n", on_reboot_trigger.action->name);
  1451. }
  1452. static ssize_t on_reboot_store(struct kobject *kobj,
  1453. struct kobj_attribute *attr,
  1454. const char *buf, size_t len)
  1455. {
  1456. return set_trigger(buf, &on_reboot_trigger, len);
  1457. }
  1458. static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
  1459. static void do_machine_restart(char *__unused)
  1460. {
  1461. smp_send_stop();
  1462. on_reboot_trigger.action->fn(&on_reboot_trigger);
  1463. reipl_run(NULL);
  1464. }
  1465. void (*_machine_restart)(char *command) = do_machine_restart;
  1466. /* on panic */
  1467. static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
  1468. static ssize_t on_panic_show(struct kobject *kobj,
  1469. struct kobj_attribute *attr, char *page)
  1470. {
  1471. return sprintf(page, "%s\n", on_panic_trigger.action->name);
  1472. }
  1473. static ssize_t on_panic_store(struct kobject *kobj,
  1474. struct kobj_attribute *attr,
  1475. const char *buf, size_t len)
  1476. {
  1477. return set_trigger(buf, &on_panic_trigger, len);
  1478. }
  1479. static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
  1480. static void do_panic(void)
  1481. {
  1482. lgr_info_log();
  1483. on_panic_trigger.action->fn(&on_panic_trigger);
  1484. stop_run(&on_panic_trigger);
  1485. }
  1486. /* on restart */
  1487. static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
  1488. &stop_action};
  1489. static ssize_t on_restart_show(struct kobject *kobj,
  1490. struct kobj_attribute *attr, char *page)
  1491. {
  1492. return sprintf(page, "%s\n", on_restart_trigger.action->name);
  1493. }
  1494. static ssize_t on_restart_store(struct kobject *kobj,
  1495. struct kobj_attribute *attr,
  1496. const char *buf, size_t len)
  1497. {
  1498. return set_trigger(buf, &on_restart_trigger, len);
  1499. }
  1500. static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
  1501. static void __do_restart(void *ignore)
  1502. {
  1503. __arch_local_irq_stosm(0x04); /* enable DAT */
  1504. smp_send_stop();
  1505. #ifdef CONFIG_CRASH_DUMP
  1506. crash_kexec(NULL);
  1507. #endif
  1508. on_restart_trigger.action->fn(&on_restart_trigger);
  1509. stop_run(&on_restart_trigger);
  1510. }
  1511. void do_restart(void)
  1512. {
  1513. tracing_off();
  1514. debug_locks_off();
  1515. lgr_info_log();
  1516. smp_call_online_cpu(__do_restart, NULL);
  1517. }
  1518. /* on halt */
  1519. static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
  1520. static ssize_t on_halt_show(struct kobject *kobj,
  1521. struct kobj_attribute *attr, char *page)
  1522. {
  1523. return sprintf(page, "%s\n", on_halt_trigger.action->name);
  1524. }
  1525. static ssize_t on_halt_store(struct kobject *kobj,
  1526. struct kobj_attribute *attr,
  1527. const char *buf, size_t len)
  1528. {
  1529. return set_trigger(buf, &on_halt_trigger, len);
  1530. }
  1531. static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
  1532. static void do_machine_halt(void)
  1533. {
  1534. smp_send_stop();
  1535. on_halt_trigger.action->fn(&on_halt_trigger);
  1536. stop_run(&on_halt_trigger);
  1537. }
  1538. void (*_machine_halt)(void) = do_machine_halt;
  1539. /* on power off */
  1540. static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
  1541. static ssize_t on_poff_show(struct kobject *kobj,
  1542. struct kobj_attribute *attr, char *page)
  1543. {
  1544. return sprintf(page, "%s\n", on_poff_trigger.action->name);
  1545. }
  1546. static ssize_t on_poff_store(struct kobject *kobj,
  1547. struct kobj_attribute *attr,
  1548. const char *buf, size_t len)
  1549. {
  1550. return set_trigger(buf, &on_poff_trigger, len);
  1551. }
  1552. static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
  1553. static void do_machine_power_off(void)
  1554. {
  1555. smp_send_stop();
  1556. on_poff_trigger.action->fn(&on_poff_trigger);
  1557. stop_run(&on_poff_trigger);
  1558. }
  1559. void (*_machine_power_off)(void) = do_machine_power_off;
  1560. static struct attribute *shutdown_action_attrs[] = {
  1561. &on_restart_attr.attr,
  1562. &on_reboot_attr.attr,
  1563. &on_panic_attr.attr,
  1564. &on_halt_attr.attr,
  1565. &on_poff_attr.attr,
  1566. NULL,
  1567. };
  1568. static struct attribute_group shutdown_action_attr_group = {
  1569. .attrs = shutdown_action_attrs,
  1570. };
  1571. static void __init shutdown_triggers_init(void)
  1572. {
  1573. shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
  1574. firmware_kobj);
  1575. if (!shutdown_actions_kset)
  1576. goto fail;
  1577. if (sysfs_create_group(&shutdown_actions_kset->kobj,
  1578. &shutdown_action_attr_group))
  1579. goto fail;
  1580. return;
  1581. fail:
  1582. panic("shutdown_triggers_init failed\n");
  1583. }
  1584. static void __init shutdown_actions_init(void)
  1585. {
  1586. int i;
  1587. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1588. if (!shutdown_actions_list[i]->init)
  1589. continue;
  1590. shutdown_actions_list[i]->init_rc =
  1591. shutdown_actions_list[i]->init();
  1592. }
  1593. }
  1594. static int __init s390_ipl_init(void)
  1595. {
  1596. char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
  1597. sclp_get_ipl_info(&sclp_ipl_info);
  1598. /*
  1599. * Fix loadparm: There are systems where the (SCSI) LOADPARM
  1600. * returned by read SCP info is invalid (contains EBCDIC blanks)
  1601. * when the system has been booted via diag308. In that case we use
  1602. * the value from diag308, if available.
  1603. *
  1604. * There are also systems where diag308 store does not work in
  1605. * case the system is booted from HMC. Fortunately in this case
  1606. * READ SCP info provides the correct value.
  1607. */
  1608. if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 &&
  1609. diag308_set_works)
  1610. memcpy(sclp_ipl_info.loadparm, ipl_block.hdr.loadparm,
  1611. LOADPARM_LEN);
  1612. shutdown_actions_init();
  1613. shutdown_triggers_init();
  1614. return 0;
  1615. }
  1616. __initcall(s390_ipl_init);
  1617. static void __init strncpy_skip_quote(char *dst, char *src, int n)
  1618. {
  1619. int sx, dx;
  1620. dx = 0;
  1621. for (sx = 0; src[sx] != 0; sx++) {
  1622. if (src[sx] == '"')
  1623. continue;
  1624. dst[dx++] = src[sx];
  1625. if (dx >= n)
  1626. break;
  1627. }
  1628. }
  1629. static int __init vmcmd_on_reboot_setup(char *str)
  1630. {
  1631. if (!MACHINE_IS_VM)
  1632. return 1;
  1633. strncpy_skip_quote(vmcmd_on_reboot, str, 127);
  1634. vmcmd_on_reboot[127] = 0;
  1635. on_reboot_trigger.action = &vmcmd_action;
  1636. return 1;
  1637. }
  1638. __setup("vmreboot=", vmcmd_on_reboot_setup);
  1639. static int __init vmcmd_on_panic_setup(char *str)
  1640. {
  1641. if (!MACHINE_IS_VM)
  1642. return 1;
  1643. strncpy_skip_quote(vmcmd_on_panic, str, 127);
  1644. vmcmd_on_panic[127] = 0;
  1645. on_panic_trigger.action = &vmcmd_action;
  1646. return 1;
  1647. }
  1648. __setup("vmpanic=", vmcmd_on_panic_setup);
  1649. static int __init vmcmd_on_halt_setup(char *str)
  1650. {
  1651. if (!MACHINE_IS_VM)
  1652. return 1;
  1653. strncpy_skip_quote(vmcmd_on_halt, str, 127);
  1654. vmcmd_on_halt[127] = 0;
  1655. on_halt_trigger.action = &vmcmd_action;
  1656. return 1;
  1657. }
  1658. __setup("vmhalt=", vmcmd_on_halt_setup);
  1659. static int __init vmcmd_on_poff_setup(char *str)
  1660. {
  1661. if (!MACHINE_IS_VM)
  1662. return 1;
  1663. strncpy_skip_quote(vmcmd_on_poff, str, 127);
  1664. vmcmd_on_poff[127] = 0;
  1665. on_poff_trigger.action = &vmcmd_action;
  1666. return 1;
  1667. }
  1668. __setup("vmpoff=", vmcmd_on_poff_setup);
  1669. static int on_panic_notify(struct notifier_block *self,
  1670. unsigned long event, void *data)
  1671. {
  1672. do_panic();
  1673. return NOTIFY_OK;
  1674. }
  1675. static struct notifier_block on_panic_nb = {
  1676. .notifier_call = on_panic_notify,
  1677. .priority = INT_MIN,
  1678. };
  1679. void __init setup_ipl(void)
  1680. {
  1681. ipl_info.type = get_ipl_type();
  1682. switch (ipl_info.type) {
  1683. case IPL_TYPE_CCW:
  1684. ipl_info.data.ccw.dev_id.ssid = ipl_ssid;
  1685. ipl_info.data.ccw.dev_id.devno = ipl_devno;
  1686. break;
  1687. case IPL_TYPE_FCP:
  1688. case IPL_TYPE_FCP_DUMP:
  1689. ipl_info.data.fcp.dev_id.ssid = 0;
  1690. ipl_info.data.fcp.dev_id.devno =
  1691. IPL_PARMBLOCK_START->ipl_info.fcp.devno;
  1692. ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
  1693. ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
  1694. break;
  1695. case IPL_TYPE_NSS:
  1696. strncpy(ipl_info.data.nss.name, kernel_nss_name,
  1697. sizeof(ipl_info.data.nss.name));
  1698. break;
  1699. case IPL_TYPE_UNKNOWN:
  1700. /* We have no info to copy */
  1701. break;
  1702. }
  1703. atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
  1704. }
  1705. void __init ipl_update_parameters(void)
  1706. {
  1707. int rc;
  1708. rc = diag308(DIAG308_STORE, &ipl_block);
  1709. if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
  1710. diag308_set_works = 1;
  1711. }
  1712. void __init ipl_save_parameters(void)
  1713. {
  1714. struct cio_iplinfo iplinfo;
  1715. void *src, *dst;
  1716. if (cio_get_iplinfo(&iplinfo))
  1717. return;
  1718. ipl_ssid = iplinfo.ssid;
  1719. ipl_devno = iplinfo.devno;
  1720. ipl_flags |= IPL_DEVNO_VALID;
  1721. if (!iplinfo.is_qdio)
  1722. return;
  1723. ipl_flags |= IPL_PARMBLOCK_VALID;
  1724. src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
  1725. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  1726. memmove(dst, src, PAGE_SIZE);
  1727. S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
  1728. }
  1729. static LIST_HEAD(rcall);
  1730. static DEFINE_MUTEX(rcall_mutex);
  1731. void register_reset_call(struct reset_call *reset)
  1732. {
  1733. mutex_lock(&rcall_mutex);
  1734. list_add(&reset->list, &rcall);
  1735. mutex_unlock(&rcall_mutex);
  1736. }
  1737. EXPORT_SYMBOL_GPL(register_reset_call);
  1738. void unregister_reset_call(struct reset_call *reset)
  1739. {
  1740. mutex_lock(&rcall_mutex);
  1741. list_del(&reset->list);
  1742. mutex_unlock(&rcall_mutex);
  1743. }
  1744. EXPORT_SYMBOL_GPL(unregister_reset_call);
  1745. static void do_reset_calls(void)
  1746. {
  1747. struct reset_call *reset;
  1748. if (diag308_set_works) {
  1749. diag308_reset();
  1750. return;
  1751. }
  1752. list_for_each_entry(reset, &rcall, list)
  1753. reset->fn();
  1754. }
  1755. void s390_reset_system(void)
  1756. {
  1757. struct lowcore *lc;
  1758. lc = (struct lowcore *)(unsigned long) store_prefix();
  1759. /* Stack for interrupt/machine check handler */
  1760. lc->panic_stack = S390_lowcore.panic_stack;
  1761. /* Disable prefixing */
  1762. set_prefix(0);
  1763. /* Disable lowcore protection */
  1764. __ctl_clear_bit(0,28);
  1765. /* Set new machine check handler */
  1766. S390_lowcore.mcck_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT;
  1767. S390_lowcore.mcck_new_psw.addr =
  1768. (unsigned long) s390_base_mcck_handler;
  1769. /* Set new program check handler */
  1770. S390_lowcore.program_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT;
  1771. S390_lowcore.program_new_psw.addr =
  1772. (unsigned long) s390_base_pgm_handler;
  1773. do_reset_calls();
  1774. }