2 * Enable Asynchronous Notification via SCLP.
4 * Copyright IBM Corp. 2009
5 * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/stat.h>
13 #include <linux/string.h>
14 #include <linux/ctype.h>
15 #include <linux/kmod.h>
16 #include <linux/err.h>
17 #include <linux/errno.h>
18 #include <linux/proc_fs.h>
19 #include <linux/sysctl.h>
20 #include <linux/utsname.h>
23 static int callhome_enabled
;
24 static struct sclp_req
*request
;
25 static struct sclp_async_sccb
*sccb
;
26 static int sclp_async_send_wait(char *message
);
27 static struct ctl_table_header
*callhome_sysctl_header
;
28 static DEFINE_SPINLOCK(sclp_async_lock
);
29 static char nodename
[64];
30 #define SCLP_NORMAL_WRITE 0x00
33 struct evbuf_header header
;
40 char data
[3000]; /* there is still some space left */
41 } __attribute__((packed
));
43 struct sclp_async_sccb
{
44 struct sccb_header header
;
45 struct async_evbuf evbuf
;
46 } __attribute__((packed
));
48 static struct sclp_register sclp_async_register
= {
49 .send_mask
= EVTYP_ASYNC_MASK
,
52 static int call_home_on_panic(struct notifier_block
*self
,
53 unsigned long event
, void *data
)
55 strncat(data
, nodename
, strlen(nodename
));
56 sclp_async_send_wait(data
);
60 static struct notifier_block call_home_panic_nb
= {
61 .notifier_call
= call_home_on_panic
,
65 static int proc_handler_callhome(struct ctl_table
*ctl
, int write
,
66 void __user
*buffer
, size_t *count
,
73 if (!*count
| (*ppos
&& !write
)) {
78 len
= sprintf(buf
, "%d\n", callhome_enabled
);
80 rc
= copy_to_user(buffer
, buf
, sizeof(buf
));
85 rc
= copy_from_user(buf
, buffer
, sizeof(buf
));
88 if (strict_strtoul(buf
, 0, &val
) != 0)
90 if (val
!= 0 && val
!= 1)
92 callhome_enabled
= val
;
99 static struct ctl_table callhome_table
[] = {
101 .procname
= "callhome",
103 .proc_handler
= proc_handler_callhome
,
108 static struct ctl_table kern_dir_table
[] = {
110 .ctl_name
= CTL_KERN
,
111 .procname
= "kernel",
114 .child
= callhome_table
,
120 * Function used to transfer asynchronous notification
121 * records which waits for send completion
123 static int sclp_async_send_wait(char *message
)
125 struct async_evbuf
*evb
;
129 if (!callhome_enabled
)
131 sccb
->evbuf
.header
.type
= EVTYP_ASYNC
;
132 sccb
->evbuf
.rtype
= 0xA5;
133 sccb
->evbuf
.otype
= 0x00;
135 request
->command
= SCLP_CMDW_WRITE_EVENT_DATA
;
136 request
->sccb
= sccb
;
137 request
->status
= SCLP_REQ_FILLED
;
138 strncpy(sccb
->evbuf
.data
, message
, sizeof(sccb
->evbuf
.data
));
141 * e.g. 5639CC140 500 Red Hat RHEL5 Linux for zSeries (RHEL AS)
143 strncpy(sccb
->evbuf
.comp_id
, "000000000", sizeof(sccb
->evbuf
.comp_id
));
144 sccb
->evbuf
.header
.length
= sizeof(sccb
->evbuf
);
145 sccb
->header
.length
= sizeof(sccb
->evbuf
) + sizeof(sccb
->header
);
146 sccb
->header
.function_code
= SCLP_NORMAL_WRITE
;
147 rc
= sclp_add_request(request
);
150 spin_lock_irqsave(&sclp_async_lock
, flags
);
151 while (request
->status
!= SCLP_REQ_DONE
&&
152 request
->status
!= SCLP_REQ_FAILED
) {
155 spin_unlock_irqrestore(&sclp_async_lock
, flags
);
156 if (request
->status
!= SCLP_REQ_DONE
)
158 rc
= ((struct sclp_async_sccb
*)
159 request
->sccb
)->header
.response_code
;
162 if (evb
->header
.flags
!= 0x80)
167 static int __init
sclp_async_init(void)
171 rc
= sclp_register(&sclp_async_register
);
174 callhome_sysctl_header
= register_sysctl_table(kern_dir_table
);
175 if (!callhome_sysctl_header
) {
179 if (!(sclp_async_register
.sclp_receive_mask
& EVTYP_ASYNC_MASK
)) {
184 request
= kzalloc(sizeof(struct sclp_req
), GFP_KERNEL
);
187 sccb
= (struct sclp_async_sccb
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
190 rc
= atomic_notifier_chain_register(&panic_notifier_list
,
191 &call_home_panic_nb
);
195 strncpy(nodename
, init_utsname()->nodename
, 64);
200 free_page((unsigned long) sccb
);
202 unregister_sysctl_table(callhome_sysctl_header
);
204 sclp_unregister(&sclp_async_register
);
208 module_init(sclp_async_init
);
210 static void __exit
sclp_async_exit(void)
212 atomic_notifier_chain_unregister(&panic_notifier_list
,
213 &call_home_panic_nb
);
214 unregister_sysctl_table(callhome_sysctl_header
);
215 sclp_unregister(&sclp_async_register
);
216 free_page((unsigned long) sccb
);
219 module_exit(sclp_async_exit
);
221 MODULE_AUTHOR("Copyright IBM Corp. 2009");
222 MODULE_AUTHOR("Hans-Joachim Picht <hans@linux.vnet.ibm.com>");
223 MODULE_LICENSE("GPL");
224 MODULE_DESCRIPTION("SCLP Asynchronous Notification Records");