9 #define KMSG_COMPONENT "monreader"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #include <linux/ctype.h>
22 #include <linux/poll.h>
23 #include <linux/device.h>
24 #include <linux/slab.h>
26 #include <asm/uaccess.h>
31 #define MON_COLLECT_SAMPLE 0x80
32 #define MON_COLLECT_EVENT 0x40
33 #define MON_SERVICE "*MONITOR"
34 #define MON_IN_USE 0x01
35 #define MON_MSGLIM 255
37 static char mon_dcss_name[9] =
"MONDCSS\0";
58 static unsigned long mon_in_use = 0;
60 static unsigned long mon_dcss_start;
61 static unsigned long mon_dcss_end;
66 static u8 user_data_connect[16] = {
72 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76 static u8 user_data_sever[16] = {
77 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
78 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
81 static struct device *monreader_device;
90 static void dcss_mkname(
char *ascii_name,
char *ebcdic_name)
94 for (i = 0; i < 8; i++) {
95 if (ascii_name[i] ==
'\0')
97 ebcdic_name[
i] =
toupper(ascii_name[i]);
100 ebcdic_name[i] =
' ';
104 static inline unsigned long mon_mca_start(
struct mon_msg *monmsg)
106 return *(
u32 *) &monmsg->
msg.rmmsg;
109 static inline unsigned long mon_mca_end(
struct mon_msg *monmsg)
111 return *(
u32 *) &monmsg->
msg.rmmsg[4];
119 static inline u32 mon_mca_size(
struct mon_msg *monmsg)
121 return mon_mca_end(monmsg) - mon_mca_start(monmsg) + 1;
124 static inline u32 mon_rec_start(
struct mon_msg *monmsg)
126 return *((
u32 *) (mon_mca_start(monmsg) + monmsg->
mca_offset + 4));
129 static inline u32 mon_rec_end(
struct mon_msg *monmsg)
131 return *((
u32 *) (mon_mca_start(monmsg) + monmsg->
mca_offset + 8));
134 static int mon_check_mca(
struct mon_msg *monmsg)
136 if ((mon_rec_end(monmsg) <= mon_rec_start(monmsg)) ||
137 (mon_rec_start(monmsg) < mon_dcss_start) ||
138 (mon_rec_end(monmsg) > mon_dcss_end) ||
139 (mon_mca_type(monmsg, 0) == 0) ||
140 (mon_mca_size(monmsg) % 12 != 0) ||
141 (mon_mca_end(monmsg) <= mon_mca_start(monmsg)) ||
142 (mon_mca_end(monmsg) > mon_dcss_end) ||
143 (mon_mca_start(monmsg) < mon_dcss_start) ||
144 ((mon_mca_type(monmsg, 1) == 0) && (mon_mca_type(monmsg, 2) == 0)))
149 static int mon_send_reply(
struct mon_msg *monmsg,
166 pr_err(
"Reading monitor data failed with rc=%i\n", rc);
172 static void mon_free_mem(
struct mon_private *monpriv)
194 mon_free_mem(monpriv);
201 static inline void mon_next_mca(
struct mon_msg *monmsg)
245 pr_err(
"z/VM *MONITOR system service disconnected with rc=%i\n",
261 pr_warning(
"The read queue for monitor data is full\n");
270 .path_complete = mon_iucv_path_complete,
271 .path_severed = mon_iucv_path_severed,
272 .message_pending = mon_iucv_message_pending,
291 monpriv = mon_alloc_mem();
301 rc = iucv_path_connect(monpriv->
path, &monreader_iucv_handler,
304 pr_err(
"Connecting to the z/VM *MONITOR system service "
305 "failed with rc=%i\n", rc);
326 iucv_path_free(monpriv->
path);
328 mon_free_mem(monpriv);
335 static int mon_close(
struct inode *inode,
struct file *filp)
346 pr_warning(
"Disconnecting the z/VM *MONITOR system "
347 "service failed with rc=%i\n", rc);
348 iucv_path_free(monpriv->
path);
367 size_t count, loff_t *ppos)
374 monmsg = mon_next_message(monpriv);
376 return PTR_ERR(monmsg);
393 if (mon_check_mca(monmsg))
397 mce_start = mon_mca_start(monmsg) + monmsg->
mca_offset;
398 if ((monmsg->
pos >= mce_start) && (monmsg->
pos < mce_start + 12)) {
399 count =
min(count, (
size_t) mce_start + 12 - monmsg->
pos);
405 if (monmsg->
pos == mce_start + 12)
406 monmsg->
pos = mon_rec_start(monmsg);
411 if (monmsg->
pos <= mon_rec_end(monmsg)) {
412 count =
min(count, (
size_t) mon_rec_end(monmsg) - monmsg->
pos
419 if (monmsg->
pos > mon_rec_end(monmsg))
420 mon_next_mca(monmsg);
424 ret = mon_send_reply(monmsg, monpriv);
436 poll_wait(filp, &mon_read_wait_queue, p);
447 .release = &mon_close,
463 static int monreader_freeze(
struct device *
dev)
473 pr_warning(
"Disconnecting the z/VM *MONITOR system "
474 "service failed with rc=%i\n", rc);
475 iucv_path_free(monpriv->
path);
487 static int monreader_thaw(
struct device *dev)
498 rc = iucv_path_connect(monpriv->
path, &monreader_iucv_handler,
501 pr_err(
"Connecting to the z/VM *MONITOR system service "
502 "failed with rc=%i\n", rc);
513 iucv_path_free(monpriv->
path);
520 static int monreader_restore(
struct device *dev)
526 &mon_dcss_start, &mon_dcss_end);
529 panic(
"fatal monreader resume error: no monitor dcss\n");
531 return monreader_thaw(dev);
534 static const struct dev_pm_ops monreader_pm_ops = {
535 .freeze = monreader_freeze,
536 .thaw = monreader_thaw,
537 .restore = monreader_restore,
543 .pm = &monreader_pm_ops,
550 static int __init mon_init(
void)
555 pr_err(
"The z/VM *MONITOR record device driver cannot be "
556 "loaded without z/VM\n");
565 pr_err(
"The z/VM *MONITOR record device driver failed to "
566 "register with IUCV\n");
574 if (!monreader_device) {
582 monreader_device->
driver = &monreader_driver;
596 pr_err(
"The specified *MONITOR DCSS %s does not have the "
597 "required type SC\n", mon_dcss_name);
603 &mon_dcss_start, &mon_dcss_end);
609 dcss_mkname(mon_dcss_name, &user_data_connect[8]);
631 static void __exit mon_exit(
void)
647 "service, max. 8 chars. Default is MONDCSS");
651 "monitor service records.");