sclp_cpi.c 6.3 KB

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