sclp_cmd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*
  2. * Copyright IBM Corp. 2007, 2009
  3. *
  4. * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
  5. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  6. */
  7. #define KMSG_COMPONENT "sclp_cmd"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/completion.h>
  10. #include <linux/init.h>
  11. #include <linux/errno.h>
  12. #include <linux/err.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <linux/mm.h>
  16. #include <linux/mmzone.h>
  17. #include <linux/memory.h>
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include <asm/chpid.h>
  21. #include <asm/sclp.h>
  22. #include <asm/setup.h>
  23. #include <asm/ctl_reg.h>
  24. #include "sclp.h"
  25. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  26. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  27. struct read_info_sccb {
  28. struct sccb_header header; /* 0-7 */
  29. u16 rnmax; /* 8-9 */
  30. u8 rnsize; /* 10 */
  31. u8 _reserved0[24 - 11]; /* 11-15 */
  32. u8 loadparm[8]; /* 24-31 */
  33. u8 _reserved1[48 - 32]; /* 32-47 */
  34. u64 facilities; /* 48-55 */
  35. u8 _reserved2[84 - 56]; /* 56-83 */
  36. u8 fac84; /* 84 */
  37. u8 fac85; /* 85 */
  38. u8 _reserved3[91 - 86]; /* 86-90 */
  39. u8 flags; /* 91 */
  40. u8 _reserved4[100 - 92]; /* 92-99 */
  41. u32 rnsize2; /* 100-103 */
  42. u64 rnmax2; /* 104-111 */
  43. u8 _reserved5[4096 - 112]; /* 112-4095 */
  44. } __attribute__((packed, aligned(PAGE_SIZE)));
  45. static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE);
  46. static struct read_info_sccb __initdata early_read_info_sccb;
  47. static int __initdata early_read_info_sccb_valid;
  48. u64 sclp_facilities;
  49. static u8 sclp_fac84;
  50. static u8 sclp_fac85;
  51. static unsigned long long rzm;
  52. static unsigned long long rnmax;
  53. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  54. {
  55. int rc;
  56. __ctl_set_bit(0, 9);
  57. rc = sclp_service_call(cmd, sccb);
  58. if (rc)
  59. goto out;
  60. __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
  61. PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
  62. local_irq_disable();
  63. out:
  64. /* Contents of the sccb might have changed. */
  65. barrier();
  66. __ctl_clear_bit(0, 9);
  67. return rc;
  68. }
  69. static void __init sclp_read_info_early(void)
  70. {
  71. int rc;
  72. int i;
  73. struct read_info_sccb *sccb;
  74. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  75. SCLP_CMDW_READ_SCP_INFO};
  76. sccb = &early_read_info_sccb;
  77. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  78. do {
  79. memset(sccb, 0, sizeof(*sccb));
  80. sccb->header.length = sizeof(*sccb);
  81. sccb->header.function_code = 0x80;
  82. sccb->header.control_mask[2] = 0x80;
  83. rc = sclp_cmd_sync_early(commands[i], sccb);
  84. } while (rc == -EBUSY);
  85. if (rc)
  86. break;
  87. if (sccb->header.response_code == 0x10) {
  88. early_read_info_sccb_valid = 1;
  89. break;
  90. }
  91. if (sccb->header.response_code != 0x1f0)
  92. break;
  93. }
  94. }
  95. static void __init sclp_event_mask_early(void)
  96. {
  97. struct init_sccb *sccb = &early_event_mask_sccb;
  98. int rc;
  99. do {
  100. memset(sccb, 0, sizeof(*sccb));
  101. sccb->header.length = sizeof(*sccb);
  102. sccb->mask_length = sizeof(sccb_mask_t);
  103. rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
  104. } while (rc == -EBUSY);
  105. }
  106. void __init sclp_facilities_detect(void)
  107. {
  108. struct read_info_sccb *sccb;
  109. sclp_read_info_early();
  110. if (!early_read_info_sccb_valid)
  111. return;
  112. sccb = &early_read_info_sccb;
  113. sclp_facilities = sccb->facilities;
  114. sclp_fac84 = sccb->fac84;
  115. sclp_fac85 = sccb->fac85;
  116. rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  117. rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  118. rzm <<= 20;
  119. sclp_event_mask_early();
  120. }
  121. bool __init sclp_has_linemode(void)
  122. {
  123. struct init_sccb *sccb = &early_event_mask_sccb;
  124. if (sccb->header.response_code != 0x20)
  125. return 0;
  126. if (sccb->sclp_send_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK))
  127. return 1;
  128. return 0;
  129. }
  130. bool __init sclp_has_vt220(void)
  131. {
  132. struct init_sccb *sccb = &early_event_mask_sccb;
  133. if (sccb->header.response_code != 0x20)
  134. return 0;
  135. if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
  136. return 1;
  137. return 0;
  138. }
  139. unsigned long long sclp_get_rnmax(void)
  140. {
  141. return rnmax;
  142. }
  143. unsigned long long sclp_get_rzm(void)
  144. {
  145. return rzm;
  146. }
  147. u8 sclp_get_fac85(void)
  148. {
  149. return sclp_fac85;
  150. }
  151. EXPORT_SYMBOL_GPL(sclp_get_fac85);
  152. /*
  153. * This function will be called after sclp_facilities_detect(), which gets
  154. * called from early.c code. Therefore the sccb should have valid contents.
  155. */
  156. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  157. {
  158. struct read_info_sccb *sccb;
  159. if (!early_read_info_sccb_valid)
  160. return;
  161. sccb = &early_read_info_sccb;
  162. info->is_valid = 1;
  163. if (sccb->flags & 0x2)
  164. info->has_dump = 1;
  165. memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
  166. }
  167. static void sclp_sync_callback(struct sclp_req *req, void *data)
  168. {
  169. struct completion *completion = data;
  170. complete(completion);
  171. }
  172. static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
  173. {
  174. struct completion completion;
  175. struct sclp_req *request;
  176. int rc;
  177. request = kzalloc(sizeof(*request), GFP_KERNEL);
  178. if (!request)
  179. return -ENOMEM;
  180. request->command = cmd;
  181. request->sccb = sccb;
  182. request->status = SCLP_REQ_FILLED;
  183. request->callback = sclp_sync_callback;
  184. request->callback_data = &completion;
  185. init_completion(&completion);
  186. /* Perform sclp request. */
  187. rc = sclp_add_request(request);
  188. if (rc)
  189. goto out;
  190. wait_for_completion(&completion);
  191. /* Check response. */
  192. if (request->status != SCLP_REQ_DONE) {
  193. pr_warning("sync request failed (cmd=0x%08x, "
  194. "status=0x%02x)\n", cmd, request->status);
  195. rc = -EIO;
  196. }
  197. out:
  198. kfree(request);
  199. return rc;
  200. }
  201. /*
  202. * CPU configuration related functions.
  203. */
  204. #define SCLP_CMDW_READ_CPU_INFO 0x00010001
  205. #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
  206. #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
  207. struct read_cpu_info_sccb {
  208. struct sccb_header header;
  209. u16 nr_configured;
  210. u16 offset_configured;
  211. u16 nr_standby;
  212. u16 offset_standby;
  213. u8 reserved[4096 - 16];
  214. } __attribute__((packed, aligned(PAGE_SIZE)));
  215. static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
  216. struct read_cpu_info_sccb *sccb)
  217. {
  218. char *page = (char *) sccb;
  219. memset(info, 0, sizeof(*info));
  220. info->configured = sccb->nr_configured;
  221. info->standby = sccb->nr_standby;
  222. info->combined = sccb->nr_configured + sccb->nr_standby;
  223. info->has_cpu_type = sclp_fac84 & 0x1;
  224. memcpy(&info->cpu, page + sccb->offset_configured,
  225. info->combined * sizeof(struct sclp_cpu_entry));
  226. }
  227. int sclp_get_cpu_info(struct sclp_cpu_info *info)
  228. {
  229. int rc;
  230. struct read_cpu_info_sccb *sccb;
  231. if (!SCLP_HAS_CPU_INFO)
  232. return -EOPNOTSUPP;
  233. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  234. if (!sccb)
  235. return -ENOMEM;
  236. sccb->header.length = sizeof(*sccb);
  237. rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
  238. if (rc)
  239. goto out;
  240. if (sccb->header.response_code != 0x0010) {
  241. pr_warning("readcpuinfo failed (response=0x%04x)\n",
  242. sccb->header.response_code);
  243. rc = -EIO;
  244. goto out;
  245. }
  246. sclp_fill_cpu_info(info, sccb);
  247. out:
  248. free_page((unsigned long) sccb);
  249. return rc;
  250. }
  251. struct cpu_configure_sccb {
  252. struct sccb_header header;
  253. } __attribute__((packed, aligned(8)));
  254. static int do_cpu_configure(sclp_cmdw_t cmd)
  255. {
  256. struct cpu_configure_sccb *sccb;
  257. int rc;
  258. if (!SCLP_HAS_CPU_RECONFIG)
  259. return -EOPNOTSUPP;
  260. /*
  261. * This is not going to cross a page boundary since we force
  262. * kmalloc to have a minimum alignment of 8 bytes on s390.
  263. */
  264. sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
  265. if (!sccb)
  266. return -ENOMEM;
  267. sccb->header.length = sizeof(*sccb);
  268. rc = do_sync_request(cmd, sccb);
  269. if (rc)
  270. goto out;
  271. switch (sccb->header.response_code) {
  272. case 0x0020:
  273. case 0x0120:
  274. break;
  275. default:
  276. pr_warning("configure cpu failed (cmd=0x%08x, "
  277. "response=0x%04x)\n", cmd,
  278. sccb->header.response_code);
  279. rc = -EIO;
  280. break;
  281. }
  282. out:
  283. kfree(sccb);
  284. return rc;
  285. }
  286. int sclp_cpu_configure(u8 cpu)
  287. {
  288. return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
  289. }
  290. int sclp_cpu_deconfigure(u8 cpu)
  291. {
  292. return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
  293. }
  294. #ifdef CONFIG_MEMORY_HOTPLUG
  295. static DEFINE_MUTEX(sclp_mem_mutex);
  296. static LIST_HEAD(sclp_mem_list);
  297. static u8 sclp_max_storage_id;
  298. static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
  299. static int sclp_mem_state_changed;
  300. struct memory_increment {
  301. struct list_head list;
  302. u16 rn;
  303. int standby;
  304. int usecount;
  305. };
  306. struct assign_storage_sccb {
  307. struct sccb_header header;
  308. u16 rn;
  309. } __packed;
  310. int arch_get_memory_phys_device(unsigned long start_pfn)
  311. {
  312. if (!rzm)
  313. return 0;
  314. return PFN_PHYS(start_pfn) >> ilog2(rzm);
  315. }
  316. static unsigned long long rn2addr(u16 rn)
  317. {
  318. return (unsigned long long) (rn - 1) * rzm;
  319. }
  320. static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
  321. {
  322. struct assign_storage_sccb *sccb;
  323. int rc;
  324. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  325. if (!sccb)
  326. return -ENOMEM;
  327. sccb->header.length = PAGE_SIZE;
  328. sccb->rn = rn;
  329. rc = do_sync_request(cmd, sccb);
  330. if (rc)
  331. goto out;
  332. switch (sccb->header.response_code) {
  333. case 0x0020:
  334. case 0x0120:
  335. break;
  336. default:
  337. pr_warning("assign storage failed (cmd=0x%08x, "
  338. "response=0x%04x, rn=0x%04x)\n", cmd,
  339. sccb->header.response_code, rn);
  340. rc = -EIO;
  341. break;
  342. }
  343. out:
  344. free_page((unsigned long) sccb);
  345. return rc;
  346. }
  347. static int sclp_assign_storage(u16 rn)
  348. {
  349. unsigned long long start, address;
  350. int rc;
  351. rc = do_assign_storage(0x000d0001, rn);
  352. if (rc)
  353. goto out;
  354. start = address = rn2addr(rn);
  355. for (; address < start + rzm; address += PAGE_SIZE)
  356. page_set_storage_key(address, PAGE_DEFAULT_KEY, 0);
  357. out:
  358. return rc;
  359. }
  360. static int sclp_unassign_storage(u16 rn)
  361. {
  362. return do_assign_storage(0x000c0001, rn);
  363. }
  364. struct attach_storage_sccb {
  365. struct sccb_header header;
  366. u16 :16;
  367. u16 assigned;
  368. u32 :32;
  369. u32 entries[0];
  370. } __packed;
  371. static int sclp_attach_storage(u8 id)
  372. {
  373. struct attach_storage_sccb *sccb;
  374. int rc;
  375. int i;
  376. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  377. if (!sccb)
  378. return -ENOMEM;
  379. sccb->header.length = PAGE_SIZE;
  380. rc = do_sync_request(0x00080001 | id << 8, sccb);
  381. if (rc)
  382. goto out;
  383. switch (sccb->header.response_code) {
  384. case 0x0020:
  385. set_bit(id, sclp_storage_ids);
  386. for (i = 0; i < sccb->assigned; i++) {
  387. if (sccb->entries[i])
  388. sclp_unassign_storage(sccb->entries[i] >> 16);
  389. }
  390. break;
  391. default:
  392. rc = -EIO;
  393. break;
  394. }
  395. out:
  396. free_page((unsigned long) sccb);
  397. return rc;
  398. }
  399. static int sclp_mem_change_state(unsigned long start, unsigned long size,
  400. int online)
  401. {
  402. struct memory_increment *incr;
  403. unsigned long long istart;
  404. int rc = 0;
  405. list_for_each_entry(incr, &sclp_mem_list, list) {
  406. istart = rn2addr(incr->rn);
  407. if (start + size - 1 < istart)
  408. break;
  409. if (start > istart + rzm - 1)
  410. continue;
  411. if (online) {
  412. if (incr->usecount++)
  413. continue;
  414. /*
  415. * Don't break the loop if one assign fails. Loop may
  416. * be walked again on CANCEL and we can't save
  417. * information if state changed before or not.
  418. * So continue and increase usecount for all increments.
  419. */
  420. rc |= sclp_assign_storage(incr->rn);
  421. } else {
  422. if (--incr->usecount)
  423. continue;
  424. sclp_unassign_storage(incr->rn);
  425. }
  426. }
  427. return rc ? -EIO : 0;
  428. }
  429. static int sclp_mem_notifier(struct notifier_block *nb,
  430. unsigned long action, void *data)
  431. {
  432. unsigned long start, size;
  433. struct memory_notify *arg;
  434. unsigned char id;
  435. int rc = 0;
  436. arg = data;
  437. start = arg->start_pfn << PAGE_SHIFT;
  438. size = arg->nr_pages << PAGE_SHIFT;
  439. mutex_lock(&sclp_mem_mutex);
  440. for_each_clear_bit(id, sclp_storage_ids, sclp_max_storage_id + 1)
  441. sclp_attach_storage(id);
  442. switch (action) {
  443. case MEM_ONLINE:
  444. case MEM_GOING_OFFLINE:
  445. case MEM_CANCEL_OFFLINE:
  446. break;
  447. case MEM_GOING_ONLINE:
  448. rc = sclp_mem_change_state(start, size, 1);
  449. break;
  450. case MEM_CANCEL_ONLINE:
  451. sclp_mem_change_state(start, size, 0);
  452. break;
  453. case MEM_OFFLINE:
  454. sclp_mem_change_state(start, size, 0);
  455. break;
  456. default:
  457. rc = -EINVAL;
  458. break;
  459. }
  460. if (!rc)
  461. sclp_mem_state_changed = 1;
  462. mutex_unlock(&sclp_mem_mutex);
  463. return rc ? NOTIFY_BAD : NOTIFY_OK;
  464. }
  465. static struct notifier_block sclp_mem_nb = {
  466. .notifier_call = sclp_mem_notifier,
  467. };
  468. static void __init add_memory_merged(u16 rn)
  469. {
  470. static u16 first_rn, num;
  471. unsigned long long start, size;
  472. if (rn && first_rn && (first_rn + num == rn)) {
  473. num++;
  474. return;
  475. }
  476. if (!first_rn)
  477. goto skip_add;
  478. start = rn2addr(first_rn);
  479. size = (unsigned long long ) num * rzm;
  480. if (start >= VMEM_MAX_PHYS)
  481. goto skip_add;
  482. if (start + size > VMEM_MAX_PHYS)
  483. size = VMEM_MAX_PHYS - start;
  484. if (memory_end_set && (start >= memory_end))
  485. goto skip_add;
  486. if (memory_end_set && (start + size > memory_end))
  487. size = memory_end - start;
  488. add_memory(0, start, size);
  489. skip_add:
  490. first_rn = rn;
  491. num = 1;
  492. }
  493. static void __init sclp_add_standby_memory(void)
  494. {
  495. struct memory_increment *incr;
  496. list_for_each_entry(incr, &sclp_mem_list, list)
  497. if (incr->standby)
  498. add_memory_merged(incr->rn);
  499. add_memory_merged(0);
  500. }
  501. static void __init insert_increment(u16 rn, int standby, int assigned)
  502. {
  503. struct memory_increment *incr, *new_incr;
  504. struct list_head *prev;
  505. u16 last_rn;
  506. new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
  507. if (!new_incr)
  508. return;
  509. new_incr->rn = rn;
  510. new_incr->standby = standby;
  511. if (!standby)
  512. new_incr->usecount = 1;
  513. last_rn = 0;
  514. prev = &sclp_mem_list;
  515. list_for_each_entry(incr, &sclp_mem_list, list) {
  516. if (assigned && incr->rn > rn)
  517. break;
  518. if (!assigned && incr->rn - last_rn > 1)
  519. break;
  520. last_rn = incr->rn;
  521. prev = &incr->list;
  522. }
  523. if (!assigned)
  524. new_incr->rn = last_rn + 1;
  525. if (new_incr->rn > rnmax) {
  526. kfree(new_incr);
  527. return;
  528. }
  529. list_add(&new_incr->list, prev);
  530. }
  531. static int sclp_mem_freeze(struct device *dev)
  532. {
  533. if (!sclp_mem_state_changed)
  534. return 0;
  535. pr_err("Memory hotplug state changed, suspend refused.\n");
  536. return -EPERM;
  537. }
  538. struct read_storage_sccb {
  539. struct sccb_header header;
  540. u16 max_id;
  541. u16 assigned;
  542. u16 standby;
  543. u16 :16;
  544. u32 entries[0];
  545. } __packed;
  546. static const struct dev_pm_ops sclp_mem_pm_ops = {
  547. .freeze = sclp_mem_freeze,
  548. };
  549. static struct platform_driver sclp_mem_pdrv = {
  550. .driver = {
  551. .name = "sclp_mem",
  552. .pm = &sclp_mem_pm_ops,
  553. },
  554. };
  555. static int __init sclp_detect_standby_memory(void)
  556. {
  557. struct platform_device *sclp_pdev;
  558. struct read_storage_sccb *sccb;
  559. int i, id, assigned, rc;
  560. if (!early_read_info_sccb_valid)
  561. return 0;
  562. if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
  563. return 0;
  564. rc = -ENOMEM;
  565. sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
  566. if (!sccb)
  567. goto out;
  568. assigned = 0;
  569. for (id = 0; id <= sclp_max_storage_id; id++) {
  570. memset(sccb, 0, PAGE_SIZE);
  571. sccb->header.length = PAGE_SIZE;
  572. rc = do_sync_request(0x00040001 | id << 8, sccb);
  573. if (rc)
  574. goto out;
  575. switch (sccb->header.response_code) {
  576. case 0x0010:
  577. set_bit(id, sclp_storage_ids);
  578. for (i = 0; i < sccb->assigned; i++) {
  579. if (!sccb->entries[i])
  580. continue;
  581. assigned++;
  582. insert_increment(sccb->entries[i] >> 16, 0, 1);
  583. }
  584. break;
  585. case 0x0310:
  586. break;
  587. case 0x0410:
  588. for (i = 0; i < sccb->assigned; i++) {
  589. if (!sccb->entries[i])
  590. continue;
  591. assigned++;
  592. insert_increment(sccb->entries[i] >> 16, 1, 1);
  593. }
  594. break;
  595. default:
  596. rc = -EIO;
  597. break;
  598. }
  599. if (!rc)
  600. sclp_max_storage_id = sccb->max_id;
  601. }
  602. if (rc || list_empty(&sclp_mem_list))
  603. goto out;
  604. for (i = 1; i <= rnmax - assigned; i++)
  605. insert_increment(0, 1, 0);
  606. rc = register_memory_notifier(&sclp_mem_nb);
  607. if (rc)
  608. goto out;
  609. rc = platform_driver_register(&sclp_mem_pdrv);
  610. if (rc)
  611. goto out;
  612. sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0);
  613. rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0;
  614. if (rc)
  615. goto out_driver;
  616. sclp_add_standby_memory();
  617. goto out;
  618. out_driver:
  619. platform_driver_unregister(&sclp_mem_pdrv);
  620. out:
  621. free_page((unsigned long) sccb);
  622. return rc;
  623. }
  624. __initcall(sclp_detect_standby_memory);
  625. #endif /* CONFIG_MEMORY_HOTPLUG */
  626. /*
  627. * Channel path configuration related functions.
  628. */
  629. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  630. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  631. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  632. struct chp_cfg_sccb {
  633. struct sccb_header header;
  634. u8 ccm;
  635. u8 reserved[6];
  636. u8 cssid;
  637. } __attribute__((packed));
  638. static int do_chp_configure(sclp_cmdw_t cmd)
  639. {
  640. struct chp_cfg_sccb *sccb;
  641. int rc;
  642. if (!SCLP_HAS_CHP_RECONFIG)
  643. return -EOPNOTSUPP;
  644. /* Prepare sccb. */
  645. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  646. if (!sccb)
  647. return -ENOMEM;
  648. sccb->header.length = sizeof(*sccb);
  649. rc = do_sync_request(cmd, sccb);
  650. if (rc)
  651. goto out;
  652. switch (sccb->header.response_code) {
  653. case 0x0020:
  654. case 0x0120:
  655. case 0x0440:
  656. case 0x0450:
  657. break;
  658. default:
  659. pr_warning("configure channel-path failed "
  660. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  661. sccb->header.response_code);
  662. rc = -EIO;
  663. break;
  664. }
  665. out:
  666. free_page((unsigned long) sccb);
  667. return rc;
  668. }
  669. /**
  670. * sclp_chp_configure - perform configure channel-path sclp command
  671. * @chpid: channel-path ID
  672. *
  673. * Perform configure channel-path command sclp command for specified chpid.
  674. * Return 0 after command successfully finished, non-zero otherwise.
  675. */
  676. int sclp_chp_configure(struct chp_id chpid)
  677. {
  678. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  679. }
  680. /**
  681. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  682. * @chpid: channel-path ID
  683. *
  684. * Perform deconfigure channel-path command sclp command for specified chpid
  685. * and wait for completion. On success return 0. Return non-zero otherwise.
  686. */
  687. int sclp_chp_deconfigure(struct chp_id chpid)
  688. {
  689. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  690. }
  691. struct chp_info_sccb {
  692. struct sccb_header header;
  693. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  694. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  695. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  696. u8 ccm;
  697. u8 reserved[6];
  698. u8 cssid;
  699. } __attribute__((packed));
  700. /**
  701. * sclp_chp_read_info - perform read channel-path information sclp command
  702. * @info: resulting channel-path information data
  703. *
  704. * Perform read channel-path information sclp command and wait for completion.
  705. * On success, store channel-path information in @info and return 0. Return
  706. * non-zero otherwise.
  707. */
  708. int sclp_chp_read_info(struct sclp_chp_info *info)
  709. {
  710. struct chp_info_sccb *sccb;
  711. int rc;
  712. if (!SCLP_HAS_CHP_INFO)
  713. return -EOPNOTSUPP;
  714. /* Prepare sccb. */
  715. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  716. if (!sccb)
  717. return -ENOMEM;
  718. sccb->header.length = sizeof(*sccb);
  719. rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  720. if (rc)
  721. goto out;
  722. if (sccb->header.response_code != 0x0010) {
  723. pr_warning("read channel-path info failed "
  724. "(response=0x%04x)\n", sccb->header.response_code);
  725. rc = -EIO;
  726. goto out;
  727. }
  728. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  729. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  730. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  731. out:
  732. free_page((unsigned long) sccb);
  733. return rc;
  734. }