sclp_cmd.c 17 KB

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