2 * Author: Martin Peschke <mpeschke@de.ibm.com>
3 * Copyright (C) 2001 IBM Entwicklung GmbH, IBM Corporation
5 * SCLP Control-Program Identification.
8 #include <linux/config.h>
9 #include <linux/version.h>
10 #include <linux/kmod.h>
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/init.h>
14 #include <linux/timer.h>
15 #include <linux/string.h>
16 #include <linux/err.h>
17 #include <linux/slab.h>
18 #include <asm/ebcdic.h>
19 #include <asm/semaphore.h>
24 #define CPI_LENGTH_SYSTEM_TYPE 8
25 #define CPI_LENGTH_SYSTEM_NAME 8
26 #define CPI_LENGTH_SYSPLEX_NAME 8
29 struct evbuf_header header;
32 u8 system_type[CPI_LENGTH_SYSTEM_TYPE];
34 u8 system_name[CPI_LENGTH_SYSTEM_NAME];
38 u8 sysplex_name[CPI_LENGTH_SYSPLEX_NAME];
40 } __attribute__((packed));
43 struct sccb_header header;
44 struct cpi_evbuf cpi_evbuf;
45 } __attribute__((packed));
47 /* Event type structure for write message and write priority message */
48 static struct sclp_register sclp_cpi_event =
50 .send_mask = EvTyp_CtlProgIdent_Mask
54 "Martin Peschke, IBM Deutschland Entwicklung GmbH "
55 "<mpeschke@de.ibm.com>");
58 "identify this operating system instance to the S/390 "
59 "or zSeries hardware");
61 static char *system_name = NULL;
62 module_param(system_name, charp, 0);
63 MODULE_PARM_DESC(system_name, "e.g. hostname - max. 8 characters");
65 static char *sysplex_name = NULL;
66 #ifdef ALLOW_SYSPLEX_NAME
67 module_param(sysplex_name, charp, 0);
68 MODULE_PARM_DESC(sysplex_name, "if applicable - max. 8 characters");
71 /* use default value for this field (as well as for system level) */
72 static char *system_type = "LINUX";
77 /* reject if no system type specified */
79 printk("cpi: bug: no system type specified\n");
83 /* reject if system type larger than 8 characters */
84 if (strlen(system_type) > CPI_LENGTH_SYSTEM_NAME) {
85 printk("cpi: bug: system type has length of %li characters - "
86 "only %i characters supported\n",
87 strlen(system_type), CPI_LENGTH_SYSTEM_TYPE);
91 /* reject if no system name specified */
93 printk("cpi: no system name specified\n");
97 /* reject if system name larger than 8 characters */
98 if (strlen(system_name) > CPI_LENGTH_SYSTEM_NAME) {
99 printk("cpi: system name has length of %li characters - "
100 "only %i characters supported\n",
101 strlen(system_name), CPI_LENGTH_SYSTEM_NAME);
105 /* reject if specified sysplex name larger than 8 characters */
106 if (sysplex_name && strlen(sysplex_name) > CPI_LENGTH_SYSPLEX_NAME) {
107 printk("cpi: sysplex name has length of %li characters"
108 " - only %i characters supported\n",
109 strlen(sysplex_name), CPI_LENGTH_SYSPLEX_NAME);
116 cpi_callback(struct sclp_req *req, void *data)
118 struct semaphore *sem;
120 sem = (struct semaphore *) data;
124 static struct sclp_req *
125 cpi_prepare_req(void)
127 struct sclp_req *req;
128 struct cpi_sccb *sccb;
129 struct cpi_evbuf *evb;
131 req = (struct sclp_req *) kmalloc(sizeof(struct sclp_req), GFP_KERNEL);
133 return ERR_PTR(-ENOMEM);
134 sccb = (struct cpi_sccb *) __get_free_page(GFP_KERNEL | GFP_DMA);
137 return ERR_PTR(-ENOMEM);
139 memset(sccb, 0, sizeof(struct cpi_sccb));
141 /* setup SCCB for Control-Program Identification */
142 sccb->header.length = sizeof(struct cpi_sccb);
143 sccb->cpi_evbuf.header.length = sizeof(struct cpi_evbuf);
144 sccb->cpi_evbuf.header.type = 0x0B;
145 evb = &sccb->cpi_evbuf;
147 /* set system type */
148 memset(evb->system_type, ' ', CPI_LENGTH_SYSTEM_TYPE);
149 memcpy(evb->system_type, system_type, strlen(system_type));
150 sclp_ascebc_str(evb->system_type, CPI_LENGTH_SYSTEM_TYPE);
151 EBC_TOUPPER(evb->system_type, CPI_LENGTH_SYSTEM_TYPE);
153 /* set system name */
154 memset(evb->system_name, ' ', CPI_LENGTH_SYSTEM_NAME);
155 memcpy(evb->system_name, system_name, strlen(system_name));
156 sclp_ascebc_str(evb->system_name, CPI_LENGTH_SYSTEM_NAME);
157 EBC_TOUPPER(evb->system_name, CPI_LENGTH_SYSTEM_NAME);
159 /* set sytem level */
160 evb->system_level = LINUX_VERSION_CODE;
162 /* set sysplex name */
164 memset(evb->sysplex_name, ' ', CPI_LENGTH_SYSPLEX_NAME);
165 memcpy(evb->sysplex_name, sysplex_name, strlen(sysplex_name));
166 sclp_ascebc_str(evb->sysplex_name, CPI_LENGTH_SYSPLEX_NAME);
167 EBC_TOUPPER(evb->sysplex_name, CPI_LENGTH_SYSPLEX_NAME);
170 /* prepare request data structure presented to SCLP driver */
171 req->command = SCLP_CMDW_WRITEDATA;
173 req->status = SCLP_REQ_FILLED;
174 req->callback = cpi_callback;
179 cpi_free_req(struct sclp_req *req)
181 free_page((unsigned long) req->sccb);
186 cpi_module_init(void)
188 struct semaphore sem;
189 struct sclp_req *req;
192 rc = cpi_check_parms();
196 rc = sclp_register(&sclp_cpi_event);
198 /* could not register sclp event. Die. */
199 printk(KERN_WARNING "cpi: could not register to hardware "
203 if (!(sclp_cpi_event.sclp_send_mask & EvTyp_CtlProgIdent_Mask)) {
204 printk(KERN_WARNING "cpi: no control program identification "
206 sclp_unregister(&sclp_cpi_event);
210 req = cpi_prepare_req();
212 printk(KERN_WARNING "cpi: couldn't allocate request\n");
213 sclp_unregister(&sclp_cpi_event);
217 /* Prepare semaphore */
219 req->callback_data = &sem;
220 /* Add request to sclp queue */
221 rc = sclp_add_request(req);
223 printk(KERN_WARNING "cpi: could not start request\n");
225 sclp_unregister(&sclp_cpi_event);
228 /* make "insmod" sleep until callback arrives */
231 rc = ((struct cpi_sccb *) req->sccb)->header.response_code;
233 printk(KERN_WARNING "cpi: failed with response code 0x%x\n",
240 sclp_unregister(&sclp_cpi_event);
246 static void __exit cpi_module_exit(void)
251 /* declare driver module init/cleanup functions */
252 module_init(cpi_module_init);
253 module_exit(cpi_module_exit);