sclp_cmd.c 17 KB

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