sclp_cmd.c 17 KB

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