sclp_cmd.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * drivers/s390/char/sclp_cmd.c
  3. *
  4. * Copyright IBM Corp. 2007
  5. * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
  6. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  7. */
  8. #include <linux/completion.h>
  9. #include <linux/init.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/string.h>
  13. #include <asm/chpid.h>
  14. #include <asm/sclp.h>
  15. #include "sclp.h"
  16. #define TAG "sclp_cmd: "
  17. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  18. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  19. struct read_info_sccb {
  20. struct sccb_header header; /* 0-7 */
  21. u16 rnmax; /* 8-9 */
  22. u8 rnsize; /* 10 */
  23. u8 _reserved0[24 - 11]; /* 11-15 */
  24. u8 loadparm[8]; /* 24-31 */
  25. u8 _reserved1[48 - 32]; /* 32-47 */
  26. u64 facilities; /* 48-55 */
  27. u8 _reserved2[84 - 56]; /* 56-83 */
  28. u8 fac84; /* 84 */
  29. u8 _reserved3[91 - 85]; /* 85-90 */
  30. u8 flags; /* 91 */
  31. u8 _reserved4[100 - 92]; /* 92-99 */
  32. u32 rnsize2; /* 100-103 */
  33. u64 rnmax2; /* 104-111 */
  34. u8 _reserved5[4096 - 112]; /* 112-4095 */
  35. } __attribute__((packed, aligned(PAGE_SIZE)));
  36. static struct read_info_sccb __initdata early_read_info_sccb;
  37. static int __initdata early_read_info_sccb_valid;
  38. u64 sclp_facilities;
  39. static u8 sclp_fac84;
  40. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  41. {
  42. int rc;
  43. __ctl_set_bit(0, 9);
  44. rc = sclp_service_call(cmd, sccb);
  45. if (rc)
  46. goto out;
  47. __load_psw_mask(PSW_BASE_BITS | PSW_MASK_EXT |
  48. PSW_MASK_WAIT | PSW_DEFAULT_KEY);
  49. local_irq_disable();
  50. out:
  51. /* Contents of the sccb might have changed. */
  52. barrier();
  53. __ctl_clear_bit(0, 9);
  54. return rc;
  55. }
  56. void __init sclp_read_info_early(void)
  57. {
  58. int rc;
  59. int i;
  60. struct read_info_sccb *sccb;
  61. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  62. SCLP_CMDW_READ_SCP_INFO};
  63. sccb = &early_read_info_sccb;
  64. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  65. do {
  66. memset(sccb, 0, sizeof(*sccb));
  67. sccb->header.length = sizeof(*sccb);
  68. sccb->header.control_mask[2] = 0x80;
  69. rc = sclp_cmd_sync_early(commands[i], sccb);
  70. } while (rc == -EBUSY);
  71. if (rc)
  72. break;
  73. if (sccb->header.response_code == 0x10) {
  74. early_read_info_sccb_valid = 1;
  75. break;
  76. }
  77. if (sccb->header.response_code != 0x1f0)
  78. break;
  79. }
  80. }
  81. void __init sclp_facilities_detect(void)
  82. {
  83. if (!early_read_info_sccb_valid)
  84. return;
  85. sclp_facilities = early_read_info_sccb.facilities;
  86. sclp_fac84 = early_read_info_sccb.fac84;
  87. }
  88. unsigned long long __init sclp_memory_detect(void)
  89. {
  90. unsigned long long memsize;
  91. struct read_info_sccb *sccb;
  92. if (!early_read_info_sccb_valid)
  93. return 0;
  94. sccb = &early_read_info_sccb;
  95. if (sccb->rnsize)
  96. memsize = sccb->rnsize << 20;
  97. else
  98. memsize = sccb->rnsize2 << 20;
  99. if (sccb->rnmax)
  100. memsize *= sccb->rnmax;
  101. else
  102. memsize *= sccb->rnmax2;
  103. return memsize;
  104. }
  105. /*
  106. * This function will be called after sclp_memory_detect(), which gets called
  107. * early from early.c code. Therefore the sccb should have valid contents.
  108. */
  109. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  110. {
  111. struct read_info_sccb *sccb;
  112. if (!early_read_info_sccb_valid)
  113. return;
  114. sccb = &early_read_info_sccb;
  115. info->is_valid = 1;
  116. if (sccb->flags & 0x2)
  117. info->has_dump = 1;
  118. memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
  119. }
  120. static void sclp_sync_callback(struct sclp_req *req, void *data)
  121. {
  122. struct completion *completion = data;
  123. complete(completion);
  124. }
  125. static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
  126. {
  127. struct completion completion;
  128. struct sclp_req *request;
  129. int rc;
  130. request = kzalloc(sizeof(*request), GFP_KERNEL);
  131. if (!request)
  132. return -ENOMEM;
  133. request->command = cmd;
  134. request->sccb = sccb;
  135. request->status = SCLP_REQ_FILLED;
  136. request->callback = sclp_sync_callback;
  137. request->callback_data = &completion;
  138. init_completion(&completion);
  139. /* Perform sclp request. */
  140. rc = sclp_add_request(request);
  141. if (rc)
  142. goto out;
  143. wait_for_completion(&completion);
  144. /* Check response. */
  145. if (request->status != SCLP_REQ_DONE) {
  146. printk(KERN_WARNING TAG "sync request failed "
  147. "(cmd=0x%08x, status=0x%02x)\n", cmd, request->status);
  148. rc = -EIO;
  149. }
  150. out:
  151. kfree(request);
  152. return rc;
  153. }
  154. /*
  155. * CPU configuration related functions.
  156. */
  157. #define SCLP_CMDW_READ_CPU_INFO 0x00010001
  158. #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
  159. #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
  160. struct read_cpu_info_sccb {
  161. struct sccb_header header;
  162. u16 nr_configured;
  163. u16 offset_configured;
  164. u16 nr_standby;
  165. u16 offset_standby;
  166. u8 reserved[4096 - 16];
  167. } __attribute__((packed, aligned(PAGE_SIZE)));
  168. static struct read_cpu_info_sccb __initdata early_read_cpu_info_sccb;
  169. static struct sclp_cpu_info __initdata sclp_cpu_info;
  170. static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
  171. struct read_cpu_info_sccb *sccb)
  172. {
  173. char *page = (char *) sccb;
  174. memset(info, 0, sizeof(*info));
  175. info->configured = sccb->nr_configured;
  176. info->standby = sccb->nr_standby;
  177. info->combined = sccb->nr_configured + sccb->nr_standby;
  178. info->has_cpu_type = sclp_fac84 & 0x1;
  179. memcpy(&info->cpu, page + sccb->offset_configured,
  180. info->combined * sizeof(struct sclp_cpu_entry));
  181. }
  182. void __init sclp_read_cpu_info_early(void)
  183. {
  184. int rc;
  185. struct read_cpu_info_sccb *sccb;
  186. if (!SCLP_HAS_CPU_INFO)
  187. return;
  188. sccb = &early_read_cpu_info_sccb;
  189. do {
  190. memset(sccb, 0, sizeof(*sccb));
  191. sccb->header.length = sizeof(*sccb);
  192. rc = sclp_cmd_sync_early(SCLP_CMDW_READ_CPU_INFO, sccb);
  193. } while (rc == -EBUSY);
  194. if (rc)
  195. return;
  196. if (sccb->header.response_code != 0x10)
  197. return;
  198. sclp_fill_cpu_info(&sclp_cpu_info, sccb);
  199. }
  200. static int __init sclp_get_cpu_info_early(struct sclp_cpu_info *info)
  201. {
  202. if (!SCLP_HAS_CPU_INFO)
  203. return -EOPNOTSUPP;
  204. *info = sclp_cpu_info;
  205. return 0;
  206. }
  207. static int sclp_get_cpu_info_late(struct sclp_cpu_info *info)
  208. {
  209. int rc;
  210. struct read_cpu_info_sccb *sccb;
  211. if (!SCLP_HAS_CPU_INFO)
  212. return -EOPNOTSUPP;
  213. sccb = (struct read_cpu_info_sccb *) __get_free_page(GFP_KERNEL
  214. | GFP_DMA);
  215. if (!sccb)
  216. return -ENOMEM;
  217. memset(sccb, 0, sizeof(*sccb));
  218. sccb->header.length = sizeof(*sccb);
  219. rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
  220. if (rc)
  221. goto out;
  222. if (sccb->header.response_code != 0x0010) {
  223. printk(KERN_WARNING TAG "readcpuinfo failed "
  224. "(response=0x%04x)\n", sccb->header.response_code);
  225. rc = -EIO;
  226. goto out;
  227. }
  228. sclp_fill_cpu_info(info, sccb);
  229. out:
  230. free_page((unsigned long) sccb);
  231. return rc;
  232. }
  233. int __init_refok sclp_get_cpu_info(struct sclp_cpu_info *info)
  234. {
  235. if (slab_is_available())
  236. return sclp_get_cpu_info_late(info);
  237. return sclp_get_cpu_info_early(info);
  238. }
  239. struct cpu_configure_sccb {
  240. struct sccb_header header;
  241. } __attribute__((packed, aligned(8)));
  242. static int do_cpu_configure(sclp_cmdw_t cmd)
  243. {
  244. struct cpu_configure_sccb *sccb;
  245. int rc;
  246. if (!SCLP_HAS_CPU_RECONFIG)
  247. return -EOPNOTSUPP;
  248. /*
  249. * This is not going to cross a page boundary since we force
  250. * kmalloc to have a minimum alignment of 8 bytes on s390.
  251. */
  252. sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
  253. if (!sccb)
  254. return -ENOMEM;
  255. sccb->header.length = sizeof(*sccb);
  256. rc = do_sync_request(cmd, sccb);
  257. if (rc)
  258. goto out;
  259. switch (sccb->header.response_code) {
  260. case 0x0020:
  261. case 0x0120:
  262. break;
  263. default:
  264. printk(KERN_WARNING TAG "configure cpu failed (cmd=0x%08x, "
  265. "response=0x%04x)\n", cmd, sccb->header.response_code);
  266. rc = -EIO;
  267. break;
  268. }
  269. out:
  270. kfree(sccb);
  271. return rc;
  272. }
  273. int sclp_cpu_configure(u8 cpu)
  274. {
  275. return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
  276. }
  277. int sclp_cpu_deconfigure(u8 cpu)
  278. {
  279. return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
  280. }
  281. /*
  282. * Channel path configuration related functions.
  283. */
  284. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  285. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  286. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  287. struct chp_cfg_sccb {
  288. struct sccb_header header;
  289. u8 ccm;
  290. u8 reserved[6];
  291. u8 cssid;
  292. } __attribute__((packed));
  293. static int do_chp_configure(sclp_cmdw_t cmd)
  294. {
  295. struct chp_cfg_sccb *sccb;
  296. int rc;
  297. if (!SCLP_HAS_CHP_RECONFIG)
  298. return -EOPNOTSUPP;
  299. /* Prepare sccb. */
  300. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  301. if (!sccb)
  302. return -ENOMEM;
  303. sccb->header.length = sizeof(*sccb);
  304. rc = do_sync_request(cmd, sccb);
  305. if (rc)
  306. goto out;
  307. switch (sccb->header.response_code) {
  308. case 0x0020:
  309. case 0x0120:
  310. case 0x0440:
  311. case 0x0450:
  312. break;
  313. default:
  314. printk(KERN_WARNING TAG "configure channel-path failed "
  315. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  316. sccb->header.response_code);
  317. rc = -EIO;
  318. break;
  319. }
  320. out:
  321. free_page((unsigned long) sccb);
  322. return rc;
  323. }
  324. /**
  325. * sclp_chp_configure - perform configure channel-path sclp command
  326. * @chpid: channel-path ID
  327. *
  328. * Perform configure channel-path command sclp command for specified chpid.
  329. * Return 0 after command successfully finished, non-zero otherwise.
  330. */
  331. int sclp_chp_configure(struct chp_id chpid)
  332. {
  333. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  334. }
  335. /**
  336. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  337. * @chpid: channel-path ID
  338. *
  339. * Perform deconfigure channel-path command sclp command for specified chpid
  340. * and wait for completion. On success return 0. Return non-zero otherwise.
  341. */
  342. int sclp_chp_deconfigure(struct chp_id chpid)
  343. {
  344. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  345. }
  346. struct chp_info_sccb {
  347. struct sccb_header header;
  348. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  349. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  350. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  351. u8 ccm;
  352. u8 reserved[6];
  353. u8 cssid;
  354. } __attribute__((packed));
  355. /**
  356. * sclp_chp_read_info - perform read channel-path information sclp command
  357. * @info: resulting channel-path information data
  358. *
  359. * Perform read channel-path information sclp command and wait for completion.
  360. * On success, store channel-path information in @info and return 0. Return
  361. * non-zero otherwise.
  362. */
  363. int sclp_chp_read_info(struct sclp_chp_info *info)
  364. {
  365. struct chp_info_sccb *sccb;
  366. int rc;
  367. if (!SCLP_HAS_CHP_INFO)
  368. return -EOPNOTSUPP;
  369. /* Prepare sccb. */
  370. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  371. if (!sccb)
  372. return -ENOMEM;
  373. sccb->header.length = sizeof(*sccb);
  374. rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  375. if (rc)
  376. goto out;
  377. if (sccb->header.response_code != 0x0010) {
  378. printk(KERN_WARNING TAG "read channel-path info failed "
  379. "(response=0x%04x)\n", sccb->header.response_code);
  380. rc = -EIO;
  381. goto out;
  382. }
  383. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  384. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  385. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  386. out:
  387. free_page((unsigned long) sccb);
  388. return rc;
  389. }