sclp_cmd.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 void sclp_fill_cpu_info(struct sclp_cpu_info *info,
  169. struct read_cpu_info_sccb *sccb)
  170. {
  171. char *page = (char *) sccb;
  172. memset(info, 0, sizeof(*info));
  173. info->configured = sccb->nr_configured;
  174. info->standby = sccb->nr_standby;
  175. info->combined = sccb->nr_configured + sccb->nr_standby;
  176. info->has_cpu_type = sclp_fac84 & 0x1;
  177. memcpy(&info->cpu, page + sccb->offset_configured,
  178. info->combined * sizeof(struct sclp_cpu_entry));
  179. }
  180. int sclp_get_cpu_info(struct sclp_cpu_info *info)
  181. {
  182. int rc;
  183. struct read_cpu_info_sccb *sccb;
  184. if (!SCLP_HAS_CPU_INFO)
  185. return -EOPNOTSUPP;
  186. sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  187. if (!sccb)
  188. return -ENOMEM;
  189. sccb->header.length = sizeof(*sccb);
  190. rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
  191. if (rc)
  192. goto out;
  193. if (sccb->header.response_code != 0x0010) {
  194. printk(KERN_WARNING TAG "readcpuinfo failed "
  195. "(response=0x%04x)\n", sccb->header.response_code);
  196. rc = -EIO;
  197. goto out;
  198. }
  199. sclp_fill_cpu_info(info, sccb);
  200. out:
  201. free_page((unsigned long) sccb);
  202. return rc;
  203. }
  204. struct cpu_configure_sccb {
  205. struct sccb_header header;
  206. } __attribute__((packed, aligned(8)));
  207. static int do_cpu_configure(sclp_cmdw_t cmd)
  208. {
  209. struct cpu_configure_sccb *sccb;
  210. int rc;
  211. if (!SCLP_HAS_CPU_RECONFIG)
  212. return -EOPNOTSUPP;
  213. /*
  214. * This is not going to cross a page boundary since we force
  215. * kmalloc to have a minimum alignment of 8 bytes on s390.
  216. */
  217. sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
  218. if (!sccb)
  219. return -ENOMEM;
  220. sccb->header.length = sizeof(*sccb);
  221. rc = do_sync_request(cmd, sccb);
  222. if (rc)
  223. goto out;
  224. switch (sccb->header.response_code) {
  225. case 0x0020:
  226. case 0x0120:
  227. break;
  228. default:
  229. printk(KERN_WARNING TAG "configure cpu failed (cmd=0x%08x, "
  230. "response=0x%04x)\n", cmd, sccb->header.response_code);
  231. rc = -EIO;
  232. break;
  233. }
  234. out:
  235. kfree(sccb);
  236. return rc;
  237. }
  238. int sclp_cpu_configure(u8 cpu)
  239. {
  240. return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
  241. }
  242. int sclp_cpu_deconfigure(u8 cpu)
  243. {
  244. return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
  245. }
  246. /*
  247. * Channel path configuration related functions.
  248. */
  249. #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
  250. #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
  251. #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
  252. struct chp_cfg_sccb {
  253. struct sccb_header header;
  254. u8 ccm;
  255. u8 reserved[6];
  256. u8 cssid;
  257. } __attribute__((packed));
  258. static int do_chp_configure(sclp_cmdw_t cmd)
  259. {
  260. struct chp_cfg_sccb *sccb;
  261. int rc;
  262. if (!SCLP_HAS_CHP_RECONFIG)
  263. return -EOPNOTSUPP;
  264. /* Prepare sccb. */
  265. sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  266. if (!sccb)
  267. return -ENOMEM;
  268. sccb->header.length = sizeof(*sccb);
  269. rc = do_sync_request(cmd, sccb);
  270. if (rc)
  271. goto out;
  272. switch (sccb->header.response_code) {
  273. case 0x0020:
  274. case 0x0120:
  275. case 0x0440:
  276. case 0x0450:
  277. break;
  278. default:
  279. printk(KERN_WARNING TAG "configure channel-path failed "
  280. "(cmd=0x%08x, response=0x%04x)\n", cmd,
  281. sccb->header.response_code);
  282. rc = -EIO;
  283. break;
  284. }
  285. out:
  286. free_page((unsigned long) sccb);
  287. return rc;
  288. }
  289. /**
  290. * sclp_chp_configure - perform configure channel-path sclp command
  291. * @chpid: channel-path ID
  292. *
  293. * Perform configure channel-path command sclp command for specified chpid.
  294. * Return 0 after command successfully finished, non-zero otherwise.
  295. */
  296. int sclp_chp_configure(struct chp_id chpid)
  297. {
  298. return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
  299. }
  300. /**
  301. * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
  302. * @chpid: channel-path ID
  303. *
  304. * Perform deconfigure channel-path command sclp command for specified chpid
  305. * and wait for completion. On success return 0. Return non-zero otherwise.
  306. */
  307. int sclp_chp_deconfigure(struct chp_id chpid)
  308. {
  309. return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
  310. }
  311. struct chp_info_sccb {
  312. struct sccb_header header;
  313. u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
  314. u8 standby[SCLP_CHP_INFO_MASK_SIZE];
  315. u8 configured[SCLP_CHP_INFO_MASK_SIZE];
  316. u8 ccm;
  317. u8 reserved[6];
  318. u8 cssid;
  319. } __attribute__((packed));
  320. /**
  321. * sclp_chp_read_info - perform read channel-path information sclp command
  322. * @info: resulting channel-path information data
  323. *
  324. * Perform read channel-path information sclp command and wait for completion.
  325. * On success, store channel-path information in @info and return 0. Return
  326. * non-zero otherwise.
  327. */
  328. int sclp_chp_read_info(struct sclp_chp_info *info)
  329. {
  330. struct chp_info_sccb *sccb;
  331. int rc;
  332. if (!SCLP_HAS_CHP_INFO)
  333. return -EOPNOTSUPP;
  334. /* Prepare sccb. */
  335. sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  336. if (!sccb)
  337. return -ENOMEM;
  338. sccb->header.length = sizeof(*sccb);
  339. rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
  340. if (rc)
  341. goto out;
  342. if (sccb->header.response_code != 0x0010) {
  343. printk(KERN_WARNING TAG "read channel-path info failed "
  344. "(response=0x%04x)\n", sccb->header.response_code);
  345. rc = -EIO;
  346. goto out;
  347. }
  348. memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
  349. memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
  350. memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
  351. out:
  352. free_page((unsigned long) sccb);
  353. return rc;
  354. }