sclp_cmd.c 20 KB

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