sclp_cpi.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Author: Martin Peschke <mpeschke@de.ibm.com>
  3. * Copyright (C) 2001 IBM Entwicklung GmbH, IBM Corporation
  4. *
  5. * SCLP Control-Program Identification.
  6. */
  7. #include <linux/config.h>
  8. #include <linux/version.h>
  9. #include <linux/kmod.h>
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/init.h>
  13. #include <linux/timer.h>
  14. #include <linux/string.h>
  15. #include <linux/err.h>
  16. #include <linux/slab.h>
  17. #include <asm/ebcdic.h>
  18. #include <asm/semaphore.h>
  19. #include "sclp.h"
  20. #include "sclp_rw.h"
  21. #define CPI_LENGTH_SYSTEM_TYPE 8
  22. #define CPI_LENGTH_SYSTEM_NAME 8
  23. #define CPI_LENGTH_SYSPLEX_NAME 8
  24. struct cpi_evbuf {
  25. struct evbuf_header header;
  26. u8 id_format;
  27. u8 reserved0;
  28. u8 system_type[CPI_LENGTH_SYSTEM_TYPE];
  29. u64 reserved1;
  30. u8 system_name[CPI_LENGTH_SYSTEM_NAME];
  31. u64 reserved2;
  32. u64 system_level;
  33. u64 reserved3;
  34. u8 sysplex_name[CPI_LENGTH_SYSPLEX_NAME];
  35. u8 reserved4[16];
  36. } __attribute__((packed));
  37. struct cpi_sccb {
  38. struct sccb_header header;
  39. struct cpi_evbuf cpi_evbuf;
  40. } __attribute__((packed));
  41. /* Event type structure for write message and write priority message */
  42. static struct sclp_register sclp_cpi_event =
  43. {
  44. .send_mask = EvTyp_CtlProgIdent_Mask
  45. };
  46. MODULE_AUTHOR(
  47. "Martin Peschke, IBM Deutschland Entwicklung GmbH "
  48. "<mpeschke@de.ibm.com>");
  49. MODULE_DESCRIPTION(
  50. "identify this operating system instance to the S/390 "
  51. "or zSeries hardware");
  52. static char *system_name = NULL;
  53. module_param(system_name, charp, 0);
  54. MODULE_PARM_DESC(system_name, "e.g. hostname - max. 8 characters");
  55. static char *sysplex_name = NULL;
  56. #ifdef ALLOW_SYSPLEX_NAME
  57. module_param(sysplex_name, charp, 0);
  58. MODULE_PARM_DESC(sysplex_name, "if applicable - max. 8 characters");
  59. #endif
  60. /* use default value for this field (as well as for system level) */
  61. static char *system_type = "LINUX";
  62. static int
  63. cpi_check_parms(void)
  64. {
  65. /* reject if no system type specified */
  66. if (!system_type) {
  67. printk("cpi: bug: no system type specified\n");
  68. return -EINVAL;
  69. }
  70. /* reject if system type larger than 8 characters */
  71. if (strlen(system_type) > CPI_LENGTH_SYSTEM_NAME) {
  72. printk("cpi: bug: system type has length of %li characters - "
  73. "only %i characters supported\n",
  74. strlen(system_type), CPI_LENGTH_SYSTEM_TYPE);
  75. return -EINVAL;
  76. }
  77. /* reject if no system name specified */
  78. if (!system_name) {
  79. printk("cpi: no system name specified\n");
  80. return -EINVAL;
  81. }
  82. /* reject if system name larger than 8 characters */
  83. if (strlen(system_name) > CPI_LENGTH_SYSTEM_NAME) {
  84. printk("cpi: system name has length of %li characters - "
  85. "only %i characters supported\n",
  86. strlen(system_name), CPI_LENGTH_SYSTEM_NAME);
  87. return -EINVAL;
  88. }
  89. /* reject if specified sysplex name larger than 8 characters */
  90. if (sysplex_name && strlen(sysplex_name) > CPI_LENGTH_SYSPLEX_NAME) {
  91. printk("cpi: sysplex name has length of %li characters"
  92. " - only %i characters supported\n",
  93. strlen(sysplex_name), CPI_LENGTH_SYSPLEX_NAME);
  94. return -EINVAL;
  95. }
  96. return 0;
  97. }
  98. static void
  99. cpi_callback(struct sclp_req *req, void *data)
  100. {
  101. struct semaphore *sem;
  102. sem = (struct semaphore *) data;
  103. up(sem);
  104. }
  105. static struct sclp_req *
  106. cpi_prepare_req(void)
  107. {
  108. struct sclp_req *req;
  109. struct cpi_sccb *sccb;
  110. struct cpi_evbuf *evb;
  111. req = (struct sclp_req *) kmalloc(sizeof(struct sclp_req), GFP_KERNEL);
  112. if (req == NULL)
  113. return ERR_PTR(-ENOMEM);
  114. sccb = (struct cpi_sccb *) __get_free_page(GFP_KERNEL | GFP_DMA);
  115. if (sccb == NULL) {
  116. kfree(req);
  117. return ERR_PTR(-ENOMEM);
  118. }
  119. memset(sccb, 0, sizeof(struct cpi_sccb));
  120. /* setup SCCB for Control-Program Identification */
  121. sccb->header.length = sizeof(struct cpi_sccb);
  122. sccb->cpi_evbuf.header.length = sizeof(struct cpi_evbuf);
  123. sccb->cpi_evbuf.header.type = 0x0B;
  124. evb = &sccb->cpi_evbuf;
  125. /* set system type */
  126. memset(evb->system_type, ' ', CPI_LENGTH_SYSTEM_TYPE);
  127. memcpy(evb->system_type, system_type, strlen(system_type));
  128. sclp_ascebc_str(evb->system_type, CPI_LENGTH_SYSTEM_TYPE);
  129. EBC_TOUPPER(evb->system_type, CPI_LENGTH_SYSTEM_TYPE);
  130. /* set system name */
  131. memset(evb->system_name, ' ', CPI_LENGTH_SYSTEM_NAME);
  132. memcpy(evb->system_name, system_name, strlen(system_name));
  133. sclp_ascebc_str(evb->system_name, CPI_LENGTH_SYSTEM_NAME);
  134. EBC_TOUPPER(evb->system_name, CPI_LENGTH_SYSTEM_NAME);
  135. /* set sytem level */
  136. evb->system_level = LINUX_VERSION_CODE;
  137. /* set sysplex name */
  138. if (sysplex_name) {
  139. memset(evb->sysplex_name, ' ', CPI_LENGTH_SYSPLEX_NAME);
  140. memcpy(evb->sysplex_name, sysplex_name, strlen(sysplex_name));
  141. sclp_ascebc_str(evb->sysplex_name, CPI_LENGTH_SYSPLEX_NAME);
  142. EBC_TOUPPER(evb->sysplex_name, CPI_LENGTH_SYSPLEX_NAME);
  143. }
  144. /* prepare request data structure presented to SCLP driver */
  145. req->command = SCLP_CMDW_WRITEDATA;
  146. req->sccb = sccb;
  147. req->status = SCLP_REQ_FILLED;
  148. req->callback = cpi_callback;
  149. return req;
  150. }
  151. static void
  152. cpi_free_req(struct sclp_req *req)
  153. {
  154. free_page((unsigned long) req->sccb);
  155. kfree(req);
  156. }
  157. static int __init
  158. cpi_module_init(void)
  159. {
  160. struct semaphore sem;
  161. struct sclp_req *req;
  162. int rc;
  163. rc = cpi_check_parms();
  164. if (rc)
  165. return rc;
  166. rc = sclp_register(&sclp_cpi_event);
  167. if (rc) {
  168. /* could not register sclp event. Die. */
  169. printk(KERN_WARNING "cpi: could not register to hardware "
  170. "console.\n");
  171. return -EINVAL;
  172. }
  173. if (!(sclp_cpi_event.sclp_send_mask & EvTyp_CtlProgIdent_Mask)) {
  174. printk(KERN_WARNING "cpi: no control program identification "
  175. "support\n");
  176. sclp_unregister(&sclp_cpi_event);
  177. return -ENOTSUPP;
  178. }
  179. req = cpi_prepare_req();
  180. if (IS_ERR(req)) {
  181. printk(KERN_WARNING "cpi: couldn't allocate request\n");
  182. sclp_unregister(&sclp_cpi_event);
  183. return PTR_ERR(req);
  184. }
  185. /* Prepare semaphore */
  186. sema_init(&sem, 0);
  187. req->callback_data = &sem;
  188. /* Add request to sclp queue */
  189. rc = sclp_add_request(req);
  190. if (rc) {
  191. printk(KERN_WARNING "cpi: could not start request\n");
  192. cpi_free_req(req);
  193. sclp_unregister(&sclp_cpi_event);
  194. return rc;
  195. }
  196. /* make "insmod" sleep until callback arrives */
  197. down(&sem);
  198. rc = ((struct cpi_sccb *) req->sccb)->header.response_code;
  199. if (rc != 0x0020) {
  200. printk(KERN_WARNING "cpi: failed with response code 0x%x\n",
  201. rc);
  202. rc = -ECOMM;
  203. } else
  204. rc = 0;
  205. cpi_free_req(req);
  206. sclp_unregister(&sclp_cpi_event);
  207. return rc;
  208. }
  209. static void __exit cpi_module_exit(void)
  210. {
  211. }
  212. /* declare driver module init/cleanup functions */
  213. module_init(cpi_module_init);
  214. module_exit(cpi_module_exit);