sclp_cmd.c 17 KB

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