sclp_cmd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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. static void sclp_sync_callback(struct sclp_req *req, void *data)
  28. {
  29. struct completion *completion = data;
  30. complete(completion);
  31. }
  32. int sclp_sync_request(sclp_cmdw_t cmd, void *sccb)
  33. {
  34. return sclp_sync_request_timeout(cmd, sccb, 0);
  35. }
  36. int sclp_sync_request_timeout(sclp_cmdw_t cmd, void *sccb, int timeout)
  37. {
  38. struct completion completion;
  39. struct sclp_req *request;
  40. int rc;
  41. request = kzalloc(sizeof(*request), GFP_KERNEL);
  42. if (!request)
  43. return -ENOMEM;
  44. if (timeout)
  45. request->queue_timeout = timeout;
  46. request->command = cmd;
  47. request->sccb = sccb;
  48. request->status = SCLP_REQ_FILLED;
  49. request->callback = sclp_sync_callback;
  50. request->callback_data = &completion;
  51. init_completion(&completion);
  52. /* Perform sclp request. */
  53. rc = sclp_add_request(request);
  54. if (rc)
  55. goto out;
  56. wait_for_completion(&completion);
  57. /* Check response. */
  58. if (request->status != SCLP_REQ_DONE) {
  59. pr_warning("sync request failed (cmd=0x%08x, "
  60. "status=0x%02x)\n", cmd, request->status);
  61. rc = -EIO;
  62. }
  63. out:
  64. kfree(request);
  65. return rc;
  66. }
  67. /*
  68. * CPU configuration related functions.
  69. */
  70. #define SCLP_CMDW_READ_CPU_INFO 0x00010001
  71. #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
  72. #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
  73. struct read_cpu_info_sccb {
  74. struct sccb_header header;
  75. u16 nr_configured;
  76. u16 offset_configured;
  77. u16 nr_standby;
  78. u16 offset_standby;
  79. u8 reserved[4096 - 16];
  80. } __attribute__((packed, aligned(PAGE_SIZE)));
  81. static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
  82. struct read_cpu_info_sccb *sccb)
  83. {
  84. char *page = (char *) sccb;
  85. memset(info, 0, sizeof(*info));
  86. info->configured = sccb->nr_configured;
  87. info->standby = sccb->nr_standby;
  88. info->combined = sccb->nr_configured + sccb->nr_standby;
  89. info->has_cpu_type = sclp_fac84 & 0x1;
  90. memcpy(&info->cpu, page + sccb->offset_configured,
  91. info->combined * sizeof(struct sclp_cpu_entry));
  92. }
  93. int sclp_get_cpu_info(struct sclp_cpu_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_cpu_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_cpu_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_cpu_configure(u8 cpu)
  154. {
  155. return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
  156. }
  157. int sclp_cpu_deconfigure(u8 cpu)
  158. {
  159. return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 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 unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
  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. {
  350. unsigned long long start_align, size_align, alignment;
  351. alignment = memory_block_size_bytes();
  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. static u16 first_rn, num;
  362. unsigned long long start, size;
  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. align_to_block_size(&start, &size);
  380. if (size)
  381. add_memory(0, start, size);
  382. skip_add:
  383. first_rn = rn;
  384. num = 1;
  385. }
  386. static void __init sclp_add_standby_memory(void)
  387. {
  388. struct memory_increment *incr;
  389. list_for_each_entry(incr, &sclp_mem_list, list)
  390. if (incr->standby)
  391. add_memory_merged(incr->rn);
  392. add_memory_merged(0);
  393. }
  394. static void __init insert_increment(u16 rn, int standby, int assigned)
  395. {
  396. struct memory_increment *incr, *new_incr;
  397. struct list_head *prev;
  398. u16 last_rn;
  399. new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
  400. if (!new_incr)
  401. return;
  402. new_incr->rn = rn;
  403. new_incr->standby = standby;
  404. last_rn = 0;
  405. prev = &sclp_mem_list;
  406. list_for_each_entry(incr, &sclp_mem_list, list) {
  407. if (assigned && incr->rn > rn)
  408. break;
  409. if (!assigned && incr->rn - last_rn > 1)
  410. break;
  411. last_rn = incr->rn;
  412. prev = &incr->list;
  413. }
  414. if (!assigned)
  415. new_incr->rn = last_rn + 1;
  416. if (new_incr->rn > sclp_rnmax) {
  417. kfree(new_incr);
  418. return;
  419. }
  420. list_add(&new_incr->list, prev);
  421. }
  422. static int sclp_mem_freeze(struct device *dev)
  423. {
  424. if (!sclp_mem_state_changed)
  425. return 0;
  426. pr_err("Memory hotplug state changed, suspend refused.\n");
  427. return -EPERM;
  428. }
  429. struct read_storage_sccb {
  430. struct sccb_header header;
  431. u16 max_id;
  432. u16 assigned;
  433. u16 standby;
  434. u16 :16;
  435. u32 entries[0];
  436. } __packed;
  437. static const struct dev_pm_ops sclp_mem_pm_ops = {
  438. .freeze = sclp_mem_freeze,
  439. };
  440. static struct platform_driver sclp_mem_pdrv = {
  441. .driver = {
  442. .name = "sclp_mem",
  443. .pm = &sclp_mem_pm_ops,
  444. },
  445. };
  446. static int __init sclp_detect_standby_memory(void)
  447. {
  448. struct platform_device *sclp_pdev;
  449. struct read_storage_sccb *sccb;
  450. int i, id, assigned, rc;
  451. if (OLDMEM_BASE) /* No standby memory in kdump mode */
  452. return 0;
  453. if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
  454. return 0;
  455. rc = -ENOMEM;
  456. sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
  457. if (!sccb)
  458. goto out;
  459. assigned = 0;
  460. for (id = 0; id <= sclp_max_storage_id; id++) {
  461. memset(sccb, 0, PAGE_SIZE);
  462. sccb->header.length = PAGE_SIZE;
  463. rc = sclp_sync_request(0x00040001 | id << 8, sccb);
  464. if (rc)
  465. goto out;
  466. switch (sccb->header.response_code) {
  467. case 0x0010:
  468. set_bit(id, sclp_storage_ids);
  469. for (i = 0; i < sccb->assigned; i++) {
  470. if (!sccb->entries[i])
  471. continue;
  472. assigned++;
  473. insert_increment(sccb->entries[i] >> 16, 0, 1);
  474. }
  475. break;
  476. case 0x0310:
  477. break;
  478. case 0x0410:
  479. for (i = 0; i < sccb->assigned; i++) {
  480. if (!sccb->entries[i])
  481. continue;
  482. assigned++;
  483. insert_increment(sccb->entries[i] >> 16, 1, 1);
  484. }
  485. break;
  486. default:
  487. rc = -EIO;
  488. break;
  489. }
  490. if (!rc)
  491. sclp_max_storage_id = sccb->max_id;
  492. }
  493. if (rc || list_empty(&sclp_mem_list))
  494. goto out;
  495. for (i = 1; i <= sclp_rnmax - assigned; i++)
  496. insert_increment(0, 1, 0);
  497. rc = register_memory_notifier(&sclp_mem_nb);
  498. if (rc)
  499. goto out;
  500. rc = platform_driver_register(&sclp_mem_pdrv);
  501. if (rc)
  502. goto out;
  503. sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0);
  504. rc = PTR_ERR_OR_ZERO(sclp_pdev);
  505. if (rc)
  506. goto out_driver;
  507. sclp_add_standby_memory();
  508. goto out;
  509. out_driver:
  510. platform_driver_unregister(&sclp_mem_pdrv);
  511. out:
  512. free_page((unsigned long) sccb);
  513. return rc;
  514. }
  515. __initcall(sclp_detect_standby_memory);
  516. #endif /* CONFIG_MEMORY_HOTPLUG */
  517. /*
  518. * PCI I/O adapter configuration related functions.
  519. */
  520. #define SCLP_CMDW_CONFIGURE_PCI 0x001a0001
  521. #define SCLP_CMDW_DECONFIGURE_PCI 0x001b0001
  522. #define SCLP_RECONFIG_PCI_ATPYE 2
  523. struct pci_cfg_sccb {
  524. struct sccb_header header;
  525. u8 atype; /* adapter type */
  526. u8 reserved1;
  527. u16 reserved2;
  528. u32 aid; /* adapter identifier */
  529. } __packed;
  530. static int do_pci_configure(sclp_cmdw_t cmd, u32 fid)
  531. {
  532. struct pci_cfg_sccb *sccb;
  533. int rc;
  534. if (!SCLP_HAS_PCI_RECONFIG)
  535. return -EOPNOTSUPP;
  536. sccb = (struct pci_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  537. if (!sccb)
  538. return -ENOMEM;
  539. sccb->header.length = PAGE_SIZE;
  540. sccb->atype = SCLP_RECONFIG_PCI_ATPYE;
  541. sccb->aid = fid;
  542. rc = sclp_sync_request(cmd, sccb);
  543. if (rc)
  544. goto out;
  545. switch (sccb->header.response_code) {
  546. case 0x0020:
  547. case 0x0120:
  548. break;
  549. default:
  550. pr_warn("configure PCI I/O adapter failed: cmd=0x%08x response=0x%04x\n",
  551. cmd, sccb->header.response_code);
  552. rc = -EIO;
  553. break;
  554. }
  555. out:
  556. free_page((unsigned long) sccb);
  557. return rc;
  558. }
  559. int sclp_pci_configure(u32 fid)
  560. {
  561. return do_pci_configure(SCLP_CMDW_CONFIGURE_PCI, fid);
  562. }
  563. EXPORT_SYMBOL(sclp_pci_configure);
  564. int sclp_pci_deconfigure(u32 fid)
  565. {
  566. return do_pci_configure(SCLP_CMDW_DECONFIGURE_PCI, fid);
  567. }
  568. EXPORT_SYMBOL(sclp_pci_deconfigure);
  569. /*
  570. * Channel path configuration related functions.
  571. */
  572. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  573. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  574. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  575. struct chp_cfg_sccb {
  576. struct sccb_header header;
  577. u8 ccm;
  578. u8 reserved[6];
  579. u8 cssid;
  580. } __attribute__((packed));
  581. static int do_chp_configure(sclp_cmdw_t cmd)
  582. {
  583. struct chp_cfg_sccb *sccb;
  584. int rc;
  585. if (!SCLP_HAS_CHP_RECONFIG)
  586. return -EOPNOTSUPP;
  587. /* Prepare sccb. */
  588. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  589. if (!sccb)
  590. return -ENOMEM;
  591. sccb->header.length = sizeof(*sccb);
  592. rc = sclp_sync_request(cmd, sccb);
  593. if (rc)
  594. goto out;
  595. switch (sccb->header.response_code) {
  596. case 0x0020:
  597. case 0x0120:
  598. case 0x0440:
  599. case 0x0450:
  600. break;
  601. default:
  602. pr_warning("configure channel-path failed "
  603. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  604. sccb->header.response_code);
  605. rc = -EIO;
  606. break;
  607. }
  608. out:
  609. free_page((unsigned long) sccb);
  610. return rc;
  611. }
  612. /**
  613. * sclp_chp_configure - perform configure channel-path sclp command
  614. * @chpid: channel-path ID
  615. *
  616. * Perform configure channel-path command sclp command for specified chpid.
  617. * Return 0 after command successfully finished, non-zero otherwise.
  618. */
  619. int sclp_chp_configure(struct chp_id chpid)
  620. {
  621. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  622. }
  623. /**
  624. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  625. * @chpid: channel-path ID
  626. *
  627. * Perform deconfigure channel-path command sclp command for specified chpid
  628. * and wait for completion. On success return 0. Return non-zero otherwise.
  629. */
  630. int sclp_chp_deconfigure(struct chp_id chpid)
  631. {
  632. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  633. }
  634. struct chp_info_sccb {
  635. struct sccb_header header;
  636. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  637. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  638. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  639. u8 ccm;
  640. u8 reserved[6];
  641. u8 cssid;
  642. } __attribute__((packed));
  643. /**
  644. * sclp_chp_read_info - perform read channel-path information sclp command
  645. * @info: resulting channel-path information data
  646. *
  647. * Perform read channel-path information sclp command and wait for completion.
  648. * On success, store channel-path information in @info and return 0. Return
  649. * non-zero otherwise.
  650. */
  651. int sclp_chp_read_info(struct sclp_chp_info *info)
  652. {
  653. struct chp_info_sccb *sccb;
  654. int rc;
  655. if (!SCLP_HAS_CHP_INFO)
  656. return -EOPNOTSUPP;
  657. /* Prepare sccb. */
  658. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  659. if (!sccb)
  660. return -ENOMEM;
  661. sccb->header.length = sizeof(*sccb);
  662. rc = sclp_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  663. if (rc)
  664. goto out;
  665. if (sccb->header.response_code != 0x0010) {
  666. pr_warning("read channel-path info failed "
  667. "(response=0x%04x)\n", sccb->header.response_code);
  668. rc = -EIO;
  669. goto out;
  670. }
  671. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  672. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  673. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  674. out:
  675. free_page((unsigned long) sccb);
  676. return rc;
  677. }
  678. bool sclp_has_sprp(void)
  679. {
  680. return !!(sclp_fac84 & 0x2);
  681. }