sclp_cmd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. unsigned long long start, address;
  310. int rc;
  311. rc = do_assign_storage(0x000d0001, rn);
  312. if (rc)
  313. goto out;
  314. start = address = rn2addr(rn);
  315. for (; address < start + rzm; address += PAGE_SIZE)
  316. page_set_storage_key(address, PAGE_DEFAULT_KEY, 0);
  317. out:
  318. return rc;
  319. }
  320. static int sclp_unassign_storage(u16 rn)
  321. {
  322. return do_assign_storage(0x000c0001, rn);
  323. }
  324. struct attach_storage_sccb {
  325. struct sccb_header header;
  326. u16 :16;
  327. u16 assigned;
  328. u32 :32;
  329. u32 entries[0];
  330. } __packed;
  331. static int sclp_attach_storage(u8 id)
  332. {
  333. struct attach_storage_sccb *sccb;
  334. int rc;
  335. int i;
  336. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  337. if (!sccb)
  338. return -ENOMEM;
  339. sccb->header.length = PAGE_SIZE;
  340. rc = do_sync_request(0x00080001 | id << 8, sccb);
  341. if (rc)
  342. goto out;
  343. switch (sccb->header.response_code) {
  344. case 0x0020:
  345. set_bit(id, sclp_storage_ids);
  346. for (i = 0; i < sccb->assigned; i++) {
  347. if (sccb->entries[i])
  348. sclp_unassign_storage(sccb->entries[i] >> 16);
  349. }
  350. break;
  351. default:
  352. rc = -EIO;
  353. break;
  354. }
  355. out:
  356. free_page((unsigned long) sccb);
  357. return rc;
  358. }
  359. static int sclp_mem_change_state(unsigned long start, unsigned long size,
  360. int online)
  361. {
  362. struct memory_increment *incr;
  363. unsigned long long istart;
  364. int rc = 0;
  365. list_for_each_entry(incr, &sclp_mem_list, list) {
  366. istart = rn2addr(incr->rn);
  367. if (start + size - 1 < istart)
  368. break;
  369. if (start > istart + rzm - 1)
  370. continue;
  371. if (online) {
  372. if (incr->usecount++)
  373. continue;
  374. /*
  375. * Don't break the loop if one assign fails. Loop may
  376. * be walked again on CANCEL and we can't save
  377. * information if state changed before or not.
  378. * So continue and increase usecount for all increments.
  379. */
  380. rc |= sclp_assign_storage(incr->rn);
  381. } else {
  382. if (--incr->usecount)
  383. continue;
  384. sclp_unassign_storage(incr->rn);
  385. }
  386. }
  387. return rc ? -EIO : 0;
  388. }
  389. static int sclp_mem_notifier(struct notifier_block *nb,
  390. unsigned long action, void *data)
  391. {
  392. unsigned long start, size;
  393. struct memory_notify *arg;
  394. unsigned char id;
  395. int rc = 0;
  396. arg = data;
  397. start = arg->start_pfn << PAGE_SHIFT;
  398. size = arg->nr_pages << PAGE_SHIFT;
  399. mutex_lock(&sclp_mem_mutex);
  400. for_each_clear_bit(id, sclp_storage_ids, sclp_max_storage_id + 1)
  401. sclp_attach_storage(id);
  402. switch (action) {
  403. case MEM_ONLINE:
  404. case MEM_GOING_OFFLINE:
  405. case MEM_CANCEL_OFFLINE:
  406. break;
  407. case MEM_GOING_ONLINE:
  408. rc = sclp_mem_change_state(start, size, 1);
  409. break;
  410. case MEM_CANCEL_ONLINE:
  411. sclp_mem_change_state(start, size, 0);
  412. break;
  413. case MEM_OFFLINE:
  414. sclp_mem_change_state(start, size, 0);
  415. break;
  416. default:
  417. rc = -EINVAL;
  418. break;
  419. }
  420. if (!rc)
  421. sclp_mem_state_changed = 1;
  422. mutex_unlock(&sclp_mem_mutex);
  423. return rc ? NOTIFY_BAD : NOTIFY_OK;
  424. }
  425. static struct notifier_block sclp_mem_nb = {
  426. .notifier_call = sclp_mem_notifier,
  427. };
  428. static void __init add_memory_merged(u16 rn)
  429. {
  430. static u16 first_rn, num;
  431. unsigned long long start, size;
  432. if (rn && first_rn && (first_rn + num == rn)) {
  433. num++;
  434. return;
  435. }
  436. if (!first_rn)
  437. goto skip_add;
  438. start = rn2addr(first_rn);
  439. size = (unsigned long long ) num * rzm;
  440. if (start >= VMEM_MAX_PHYS)
  441. goto skip_add;
  442. if (start + size > VMEM_MAX_PHYS)
  443. size = VMEM_MAX_PHYS - start;
  444. if (memory_end_set && (start >= memory_end))
  445. goto skip_add;
  446. if (memory_end_set && (start + size > memory_end))
  447. size = memory_end - start;
  448. add_memory(0, start, size);
  449. skip_add:
  450. first_rn = rn;
  451. num = 1;
  452. }
  453. static void __init sclp_add_standby_memory(void)
  454. {
  455. struct memory_increment *incr;
  456. list_for_each_entry(incr, &sclp_mem_list, list)
  457. if (incr->standby)
  458. add_memory_merged(incr->rn);
  459. add_memory_merged(0);
  460. }
  461. static void __init insert_increment(u16 rn, int standby, int assigned)
  462. {
  463. struct memory_increment *incr, *new_incr;
  464. struct list_head *prev;
  465. u16 last_rn;
  466. new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
  467. if (!new_incr)
  468. return;
  469. new_incr->rn = rn;
  470. new_incr->standby = standby;
  471. if (!standby)
  472. new_incr->usecount = 1;
  473. last_rn = 0;
  474. prev = &sclp_mem_list;
  475. list_for_each_entry(incr, &sclp_mem_list, list) {
  476. if (assigned && incr->rn > rn)
  477. break;
  478. if (!assigned && incr->rn - last_rn > 1)
  479. break;
  480. last_rn = incr->rn;
  481. prev = &incr->list;
  482. }
  483. if (!assigned)
  484. new_incr->rn = last_rn + 1;
  485. if (new_incr->rn > rnmax) {
  486. kfree(new_incr);
  487. return;
  488. }
  489. list_add(&new_incr->list, prev);
  490. }
  491. static int sclp_mem_freeze(struct device *dev)
  492. {
  493. if (!sclp_mem_state_changed)
  494. return 0;
  495. pr_err("Memory hotplug state changed, suspend refused.\n");
  496. return -EPERM;
  497. }
  498. struct read_storage_sccb {
  499. struct sccb_header header;
  500. u16 max_id;
  501. u16 assigned;
  502. u16 standby;
  503. u16 :16;
  504. u32 entries[0];
  505. } __packed;
  506. static const struct dev_pm_ops sclp_mem_pm_ops = {
  507. .freeze = sclp_mem_freeze,
  508. };
  509. static struct platform_driver sclp_mem_pdrv = {
  510. .driver = {
  511. .name = "sclp_mem",
  512. .pm = &sclp_mem_pm_ops,
  513. },
  514. };
  515. static int __init sclp_detect_standby_memory(void)
  516. {
  517. struct platform_device *sclp_pdev;
  518. struct read_storage_sccb *sccb;
  519. int i, id, assigned, rc;
  520. if (!early_read_info_sccb_valid)
  521. return 0;
  522. if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
  523. return 0;
  524. rc = -ENOMEM;
  525. sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
  526. if (!sccb)
  527. goto out;
  528. assigned = 0;
  529. for (id = 0; id <= sclp_max_storage_id; id++) {
  530. memset(sccb, 0, PAGE_SIZE);
  531. sccb->header.length = PAGE_SIZE;
  532. rc = do_sync_request(0x00040001 | id << 8, sccb);
  533. if (rc)
  534. goto out;
  535. switch (sccb->header.response_code) {
  536. case 0x0010:
  537. set_bit(id, sclp_storage_ids);
  538. for (i = 0; i < sccb->assigned; i++) {
  539. if (!sccb->entries[i])
  540. continue;
  541. assigned++;
  542. insert_increment(sccb->entries[i] >> 16, 0, 1);
  543. }
  544. break;
  545. case 0x0310:
  546. break;
  547. case 0x0410:
  548. for (i = 0; i < sccb->assigned; i++) {
  549. if (!sccb->entries[i])
  550. continue;
  551. assigned++;
  552. insert_increment(sccb->entries[i] >> 16, 1, 1);
  553. }
  554. break;
  555. default:
  556. rc = -EIO;
  557. break;
  558. }
  559. if (!rc)
  560. sclp_max_storage_id = sccb->max_id;
  561. }
  562. if (rc || list_empty(&sclp_mem_list))
  563. goto out;
  564. for (i = 1; i <= rnmax - assigned; i++)
  565. insert_increment(0, 1, 0);
  566. rc = register_memory_notifier(&sclp_mem_nb);
  567. if (rc)
  568. goto out;
  569. rc = platform_driver_register(&sclp_mem_pdrv);
  570. if (rc)
  571. goto out;
  572. sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0);
  573. rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0;
  574. if (rc)
  575. goto out_driver;
  576. sclp_add_standby_memory();
  577. goto out;
  578. out_driver:
  579. platform_driver_unregister(&sclp_mem_pdrv);
  580. out:
  581. free_page((unsigned long) sccb);
  582. return rc;
  583. }
  584. __initcall(sclp_detect_standby_memory);
  585. #endif /* CONFIG_MEMORY_HOTPLUG */
  586. /*
  587. * Channel path configuration related functions.
  588. */
  589. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  590. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  591. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  592. struct chp_cfg_sccb {
  593. struct sccb_header header;
  594. u8 ccm;
  595. u8 reserved[6];
  596. u8 cssid;
  597. } __attribute__((packed));
  598. static int do_chp_configure(sclp_cmdw_t cmd)
  599. {
  600. struct chp_cfg_sccb *sccb;
  601. int rc;
  602. if (!SCLP_HAS_CHP_RECONFIG)
  603. return -EOPNOTSUPP;
  604. /* Prepare sccb. */
  605. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  606. if (!sccb)
  607. return -ENOMEM;
  608. sccb->header.length = sizeof(*sccb);
  609. rc = do_sync_request(cmd, sccb);
  610. if (rc)
  611. goto out;
  612. switch (sccb->header.response_code) {
  613. case 0x0020:
  614. case 0x0120:
  615. case 0x0440:
  616. case 0x0450:
  617. break;
  618. default:
  619. pr_warning("configure channel-path failed "
  620. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  621. sccb->header.response_code);
  622. rc = -EIO;
  623. break;
  624. }
  625. out:
  626. free_page((unsigned long) sccb);
  627. return rc;
  628. }
  629. /**
  630. * sclp_chp_configure - perform configure channel-path sclp command
  631. * @chpid: channel-path ID
  632. *
  633. * Perform configure channel-path command sclp command for specified chpid.
  634. * Return 0 after command successfully finished, non-zero otherwise.
  635. */
  636. int sclp_chp_configure(struct chp_id chpid)
  637. {
  638. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  639. }
  640. /**
  641. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  642. * @chpid: channel-path ID
  643. *
  644. * Perform deconfigure channel-path command sclp command for specified chpid
  645. * and wait for completion. On success return 0. Return non-zero otherwise.
  646. */
  647. int sclp_chp_deconfigure(struct chp_id chpid)
  648. {
  649. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  650. }
  651. struct chp_info_sccb {
  652. struct sccb_header header;
  653. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  654. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  655. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  656. u8 ccm;
  657. u8 reserved[6];
  658. u8 cssid;
  659. } __attribute__((packed));
  660. /**
  661. * sclp_chp_read_info - perform read channel-path information sclp command
  662. * @info: resulting channel-path information data
  663. *
  664. * Perform read channel-path information sclp command and wait for completion.
  665. * On success, store channel-path information in @info and return 0. Return
  666. * non-zero otherwise.
  667. */
  668. int sclp_chp_read_info(struct sclp_chp_info *info)
  669. {
  670. struct chp_info_sccb *sccb;
  671. int rc;
  672. if (!SCLP_HAS_CHP_INFO)
  673. return -EOPNOTSUPP;
  674. /* Prepare sccb. */
  675. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  676. if (!sccb)
  677. return -ENOMEM;
  678. sccb->header.length = sizeof(*sccb);
  679. rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  680. if (rc)
  681. goto out;
  682. if (sccb->header.response_code != 0x0010) {
  683. pr_warning("read channel-path info failed "
  684. "(response=0x%04x)\n", sccb->header.response_code);
  685. rc = -EIO;
  686. goto out;
  687. }
  688. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  689. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  690. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  691. out:
  692. free_page((unsigned long) sccb);
  693. return rc;
  694. }