sclp_cmd.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*
  2. * Copyright IBM Corp. 2007,2012
  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/export.h>
  14. #include <linux/slab.h>
  15. #include <linux/string.h>
  16. #include <linux/mm.h>
  17. #include <linux/mmzone.h>
  18. #include <linux/memory.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <asm/ctl_reg.h>
  22. #include <asm/chpid.h>
  23. #include <asm/setup.h>
  24. #include <asm/page.h>
  25. #include <asm/sclp.h>
  26. #include "sclp.h"
  27. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  28. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  29. struct read_info_sccb {
  30. struct sccb_header header; /* 0-7 */
  31. u16 rnmax; /* 8-9 */
  32. u8 rnsize; /* 10 */
  33. u8 _reserved0[24 - 11]; /* 11-15 */
  34. u8 loadparm[8]; /* 24-31 */
  35. u8 _reserved1[48 - 32]; /* 32-47 */
  36. u64 facilities; /* 48-55 */
  37. u8 _reserved2[84 - 56]; /* 56-83 */
  38. u8 fac84; /* 84 */
  39. u8 fac85; /* 85 */
  40. u8 _reserved3[91 - 86]; /* 86-90 */
  41. u8 flags; /* 91 */
  42. u8 _reserved4[100 - 92]; /* 92-99 */
  43. u32 rnsize2; /* 100-103 */
  44. u64 rnmax2; /* 104-111 */
  45. u8 _reserved5[4096 - 112]; /* 112-4095 */
  46. } __attribute__((packed, aligned(PAGE_SIZE)));
  47. static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE);
  48. static struct read_info_sccb __initdata early_read_info_sccb;
  49. static int __initdata early_read_info_sccb_valid;
  50. u64 sclp_facilities;
  51. static u8 sclp_fac84;
  52. static u8 sclp_fac85;
  53. static unsigned long long rzm;
  54. static unsigned long long rnmax;
  55. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  56. {
  57. int rc;
  58. __ctl_set_bit(0, 9);
  59. rc = sclp_service_call(cmd, sccb);
  60. if (rc)
  61. goto out;
  62. __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
  63. PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
  64. local_irq_disable();
  65. out:
  66. /* Contents of the sccb might have changed. */
  67. barrier();
  68. __ctl_clear_bit(0, 9);
  69. return rc;
  70. }
  71. static void __init sclp_read_info_early(void)
  72. {
  73. int rc;
  74. int i;
  75. struct read_info_sccb *sccb;
  76. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  77. SCLP_CMDW_READ_SCP_INFO};
  78. sccb = &early_read_info_sccb;
  79. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  80. do {
  81. memset(sccb, 0, sizeof(*sccb));
  82. sccb->header.length = sizeof(*sccb);
  83. sccb->header.function_code = 0x80;
  84. sccb->header.control_mask[2] = 0x80;
  85. rc = sclp_cmd_sync_early(commands[i], sccb);
  86. } while (rc == -EBUSY);
  87. if (rc)
  88. break;
  89. if (sccb->header.response_code == 0x10) {
  90. early_read_info_sccb_valid = 1;
  91. break;
  92. }
  93. if (sccb->header.response_code != 0x1f0)
  94. break;
  95. }
  96. }
  97. static void __init sclp_event_mask_early(void)
  98. {
  99. struct init_sccb *sccb = &early_event_mask_sccb;
  100. int rc;
  101. do {
  102. memset(sccb, 0, sizeof(*sccb));
  103. sccb->header.length = sizeof(*sccb);
  104. sccb->mask_length = sizeof(sccb_mask_t);
  105. rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
  106. } while (rc == -EBUSY);
  107. }
  108. void __init sclp_facilities_detect(void)
  109. {
  110. struct read_info_sccb *sccb;
  111. sclp_read_info_early();
  112. if (!early_read_info_sccb_valid)
  113. return;
  114. sccb = &early_read_info_sccb;
  115. sclp_facilities = sccb->facilities;
  116. sclp_fac84 = sccb->fac84;
  117. sclp_fac85 = sccb->fac85;
  118. rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  119. rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  120. rzm <<= 20;
  121. sclp_event_mask_early();
  122. }
  123. bool __init sclp_has_linemode(void)
  124. {
  125. struct init_sccb *sccb = &early_event_mask_sccb;
  126. if (sccb->header.response_code != 0x20)
  127. return 0;
  128. if (sccb->sclp_send_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK))
  129. return 1;
  130. return 0;
  131. }
  132. bool __init sclp_has_vt220(void)
  133. {
  134. struct init_sccb *sccb = &early_event_mask_sccb;
  135. if (sccb->header.response_code != 0x20)
  136. return 0;
  137. if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
  138. return 1;
  139. return 0;
  140. }
  141. unsigned long long sclp_get_rnmax(void)
  142. {
  143. return rnmax;
  144. }
  145. unsigned long long sclp_get_rzm(void)
  146. {
  147. return rzm;
  148. }
  149. u8 sclp_get_fac85(void)
  150. {
  151. return sclp_fac85;
  152. }
  153. EXPORT_SYMBOL_GPL(sclp_get_fac85);
  154. /*
  155. * This function will be called after sclp_facilities_detect(), which gets
  156. * called from early.c code. Therefore the sccb should have valid contents.
  157. */
  158. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  159. {
  160. struct read_info_sccb *sccb;
  161. if (!early_read_info_sccb_valid)
  162. return;
  163. sccb = &early_read_info_sccb;
  164. info->is_valid = 1;
  165. if (sccb->flags & 0x2)
  166. info->has_dump = 1;
  167. memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
  168. }
  169. static void sclp_sync_callback(struct sclp_req *req, void *data)
  170. {
  171. struct completion *completion = data;
  172. complete(completion);
  173. }
  174. static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
  175. {
  176. struct completion completion;
  177. struct sclp_req *request;
  178. int rc;
  179. request = kzalloc(sizeof(*request), GFP_KERNEL);
  180. if (!request)
  181. return -ENOMEM;
  182. request->command = cmd;
  183. request->sccb = sccb;
  184. request->status = SCLP_REQ_FILLED;
  185. request->callback = sclp_sync_callback;
  186. request->callback_data = &completion;
  187. init_completion(&completion);
  188. /* Perform sclp request. */
  189. rc = sclp_add_request(request);
  190. if (rc)
  191. goto out;
  192. wait_for_completion(&completion);
  193. /* Check response. */
  194. if (request->status != SCLP_REQ_DONE) {
  195. pr_warning("sync request failed (cmd=0x%08x, "
  196. "status=0x%02x)\n", cmd, request->status);
  197. rc = -EIO;
  198. }
  199. out:
  200. kfree(request);
  201. return rc;
  202. }
  203. /*
  204. * CPU configuration related functions.
  205. */
  206. #define SCLP_CMDW_READ_CPU_INFO 0x00010001
  207. #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
  208. #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
  209. struct read_cpu_info_sccb {
  210. struct sccb_header header;
  211. u16 nr_configured;
  212. u16 offset_configured;
  213. u16 nr_standby;
  214. u16 offset_standby;
  215. u8 reserved[4096 - 16];
  216. } __attribute__((packed, aligned(PAGE_SIZE)));
  217. static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
  218. struct read_cpu_info_sccb *sccb)
  219. {
  220. char *page = (char *) sccb;
  221. memset(info, 0, sizeof(*info));
  222. info->configured = sccb->nr_configured;
  223. info->standby = sccb->nr_standby;
  224. info->combined = sccb->nr_configured + sccb->nr_standby;
  225. info->has_cpu_type = sclp_fac84 & 0x1;
  226. memcpy(&info->cpu, page + sccb->offset_configured,
  227. info->combined * sizeof(struct sclp_cpu_entry));
  228. }
  229. int sclp_get_cpu_info(struct sclp_cpu_info *info)
  230. {
  231. int rc;
  232. struct read_cpu_info_sccb *sccb;
  233. if (!SCLP_HAS_CPU_INFO)
  234. return -EOPNOTSUPP;
  235. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  236. if (!sccb)
  237. return -ENOMEM;
  238. sccb->header.length = sizeof(*sccb);
  239. rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
  240. if (rc)
  241. goto out;
  242. if (sccb->header.response_code != 0x0010) {
  243. pr_warning("readcpuinfo failed (response=0x%04x)\n",
  244. sccb->header.response_code);
  245. rc = -EIO;
  246. goto out;
  247. }
  248. sclp_fill_cpu_info(info, sccb);
  249. out:
  250. free_page((unsigned long) sccb);
  251. return rc;
  252. }
  253. struct cpu_configure_sccb {
  254. struct sccb_header header;
  255. } __attribute__((packed, aligned(8)));
  256. static int do_cpu_configure(sclp_cmdw_t cmd)
  257. {
  258. struct cpu_configure_sccb *sccb;
  259. int rc;
  260. if (!SCLP_HAS_CPU_RECONFIG)
  261. return -EOPNOTSUPP;
  262. /*
  263. * This is not going to cross a page boundary since we force
  264. * kmalloc to have a minimum alignment of 8 bytes on s390.
  265. */
  266. sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
  267. if (!sccb)
  268. return -ENOMEM;
  269. sccb->header.length = sizeof(*sccb);
  270. rc = do_sync_request(cmd, sccb);
  271. if (rc)
  272. goto out;
  273. switch (sccb->header.response_code) {
  274. case 0x0020:
  275. case 0x0120:
  276. break;
  277. default:
  278. pr_warning("configure cpu failed (cmd=0x%08x, "
  279. "response=0x%04x)\n", cmd,
  280. sccb->header.response_code);
  281. rc = -EIO;
  282. break;
  283. }
  284. out:
  285. kfree(sccb);
  286. return rc;
  287. }
  288. int sclp_cpu_configure(u8 cpu)
  289. {
  290. return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
  291. }
  292. int sclp_cpu_deconfigure(u8 cpu)
  293. {
  294. return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
  295. }
  296. #ifdef CONFIG_MEMORY_HOTPLUG
  297. static DEFINE_MUTEX(sclp_mem_mutex);
  298. static LIST_HEAD(sclp_mem_list);
  299. static u8 sclp_max_storage_id;
  300. static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
  301. static int sclp_mem_state_changed;
  302. struct memory_increment {
  303. struct list_head list;
  304. u16 rn;
  305. int standby;
  306. int usecount;
  307. };
  308. struct assign_storage_sccb {
  309. struct sccb_header header;
  310. u16 rn;
  311. } __packed;
  312. int arch_get_memory_phys_device(unsigned long start_pfn)
  313. {
  314. if (!rzm)
  315. return 0;
  316. return PFN_PHYS(start_pfn) >> ilog2(rzm);
  317. }
  318. static unsigned long long rn2addr(u16 rn)
  319. {
  320. return (unsigned long long) (rn - 1) * rzm;
  321. }
  322. static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
  323. {
  324. struct assign_storage_sccb *sccb;
  325. int rc;
  326. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  327. if (!sccb)
  328. return -ENOMEM;
  329. sccb->header.length = PAGE_SIZE;
  330. sccb->rn = rn;
  331. rc = do_sync_request(cmd, sccb);
  332. if (rc)
  333. goto out;
  334. switch (sccb->header.response_code) {
  335. case 0x0020:
  336. case 0x0120:
  337. break;
  338. default:
  339. pr_warning("assign storage failed (cmd=0x%08x, "
  340. "response=0x%04x, rn=0x%04x)\n", cmd,
  341. sccb->header.response_code, rn);
  342. rc = -EIO;
  343. break;
  344. }
  345. out:
  346. free_page((unsigned long) sccb);
  347. return rc;
  348. }
  349. static int sclp_assign_storage(u16 rn)
  350. {
  351. unsigned long long start;
  352. int rc;
  353. rc = do_assign_storage(0x000d0001, rn);
  354. if (rc)
  355. return rc;
  356. start = rn2addr(rn);
  357. storage_key_init_range(start, start + rzm);
  358. return 0;
  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. * PCI I/O adapter configuration related functions.
  628. */
  629. #define SCLP_CMDW_CONFIGURE_PCI 0x001a0001
  630. #define SCLP_CMDW_DECONFIGURE_PCI 0x001b0001
  631. #define SCLP_RECONFIG_PCI_ATPYE 2
  632. struct pci_cfg_sccb {
  633. struct sccb_header header;
  634. u8 atype; /* adapter type */
  635. u8 reserved1;
  636. u16 reserved2;
  637. u32 aid; /* adapter identifier */
  638. } __packed;
  639. static int do_pci_configure(sclp_cmdw_t cmd, u32 fid)
  640. {
  641. struct pci_cfg_sccb *sccb;
  642. int rc;
  643. if (!SCLP_HAS_PCI_RECONFIG)
  644. return -EOPNOTSUPP;
  645. sccb = (struct pci_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  646. if (!sccb)
  647. return -ENOMEM;
  648. sccb->header.length = PAGE_SIZE;
  649. sccb->atype = SCLP_RECONFIG_PCI_ATPYE;
  650. sccb->aid = fid;
  651. rc = do_sync_request(cmd, sccb);
  652. if (rc)
  653. goto out;
  654. switch (sccb->header.response_code) {
  655. case 0x0020:
  656. case 0x0120:
  657. break;
  658. default:
  659. pr_warn("configure PCI I/O adapter failed: cmd=0x%08x response=0x%04x\n",
  660. cmd, sccb->header.response_code);
  661. rc = -EIO;
  662. break;
  663. }
  664. out:
  665. free_page((unsigned long) sccb);
  666. return rc;
  667. }
  668. int sclp_pci_configure(u32 fid)
  669. {
  670. return do_pci_configure(SCLP_CMDW_CONFIGURE_PCI, fid);
  671. }
  672. EXPORT_SYMBOL(sclp_pci_configure);
  673. int sclp_pci_deconfigure(u32 fid)
  674. {
  675. return do_pci_configure(SCLP_CMDW_DECONFIGURE_PCI, fid);
  676. }
  677. EXPORT_SYMBOL(sclp_pci_deconfigure);
  678. /*
  679. * Channel path configuration related functions.
  680. */
  681. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  682. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  683. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  684. struct chp_cfg_sccb {
  685. struct sccb_header header;
  686. u8 ccm;
  687. u8 reserved[6];
  688. u8 cssid;
  689. } __attribute__((packed));
  690. static int do_chp_configure(sclp_cmdw_t cmd)
  691. {
  692. struct chp_cfg_sccb *sccb;
  693. int rc;
  694. if (!SCLP_HAS_CHP_RECONFIG)
  695. return -EOPNOTSUPP;
  696. /* Prepare sccb. */
  697. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  698. if (!sccb)
  699. return -ENOMEM;
  700. sccb->header.length = sizeof(*sccb);
  701. rc = do_sync_request(cmd, sccb);
  702. if (rc)
  703. goto out;
  704. switch (sccb->header.response_code) {
  705. case 0x0020:
  706. case 0x0120:
  707. case 0x0440:
  708. case 0x0450:
  709. break;
  710. default:
  711. pr_warning("configure channel-path failed "
  712. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  713. sccb->header.response_code);
  714. rc = -EIO;
  715. break;
  716. }
  717. out:
  718. free_page((unsigned long) sccb);
  719. return rc;
  720. }
  721. /**
  722. * sclp_chp_configure - perform configure channel-path sclp command
  723. * @chpid: channel-path ID
  724. *
  725. * Perform configure channel-path command sclp command for specified chpid.
  726. * Return 0 after command successfully finished, non-zero otherwise.
  727. */
  728. int sclp_chp_configure(struct chp_id chpid)
  729. {
  730. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  731. }
  732. /**
  733. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  734. * @chpid: channel-path ID
  735. *
  736. * Perform deconfigure channel-path command sclp command for specified chpid
  737. * and wait for completion. On success return 0. Return non-zero otherwise.
  738. */
  739. int sclp_chp_deconfigure(struct chp_id chpid)
  740. {
  741. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  742. }
  743. struct chp_info_sccb {
  744. struct sccb_header header;
  745. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  746. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  747. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  748. u8 ccm;
  749. u8 reserved[6];
  750. u8 cssid;
  751. } __attribute__((packed));
  752. /**
  753. * sclp_chp_read_info - perform read channel-path information sclp command
  754. * @info: resulting channel-path information data
  755. *
  756. * Perform read channel-path information sclp command and wait for completion.
  757. * On success, store channel-path information in @info and return 0. Return
  758. * non-zero otherwise.
  759. */
  760. int sclp_chp_read_info(struct sclp_chp_info *info)
  761. {
  762. struct chp_info_sccb *sccb;
  763. int rc;
  764. if (!SCLP_HAS_CHP_INFO)
  765. return -EOPNOTSUPP;
  766. /* Prepare sccb. */
  767. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  768. if (!sccb)
  769. return -ENOMEM;
  770. sccb->header.length = sizeof(*sccb);
  771. rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  772. if (rc)
  773. goto out;
  774. if (sccb->header.response_code != 0x0010) {
  775. pr_warning("read channel-path info failed "
  776. "(response=0x%04x)\n", sccb->header.response_code);
  777. rc = -EIO;
  778. goto out;
  779. }
  780. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  781. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  782. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  783. out:
  784. free_page((unsigned long) sccb);
  785. return rc;
  786. }