sclp_cmd.c 17 KB

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