2 * IUCV special message driver
4 * Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/errno.h>
25 #include <linux/device.h>
26 #include <asm/cpcmd.h>
27 #include <asm/ebcdic.h>
31 struct smsg_callback
{
32 struct list_head list
;
35 void (*callback
)(char *from
, char *str
);
39 ("(C) 2003 IBM Corporation by Martin Schwidefsky (schwidefsky@de.ibm.com)");
40 MODULE_DESCRIPTION ("Linux for S/390 IUCV special message driver");
42 static iucv_handle_t smsg_handle
;
43 static unsigned short smsg_pathid
;
44 static DEFINE_SPINLOCK(smsg_list_lock
);
45 static struct list_head smsg_list
= LIST_HEAD_INIT(smsg_list
);
48 smsg_connection_complete(iucv_ConnectionComplete
*eib
, void *pgm_data
)
54 smsg_message_pending(iucv_MessagePending
*eib
, void *pgm_data
)
56 struct smsg_callback
*cb
;
58 unsigned char sender
[9];
62 len
= eib
->ln1msg2
.ipbfln1f
;
63 msg
= kmalloc(len
+ 1, GFP_ATOMIC
|GFP_DMA
);
65 iucv_reject(eib
->ippathid
, eib
->ipmsgid
, eib
->iptrgcls
);
68 rc
= iucv_receive(eib
->ippathid
, eib
->ipmsgid
, eib
->iptrgcls
,
73 memcpy(sender
, msg
, 8);
75 /* Remove trailing whitespace from the sender name. */
76 for (i
= 7; i
>= 0; i
--) {
77 if (sender
[i
] != ' ' && sender
[i
] != '\t')
81 spin_lock(&smsg_list_lock
);
82 list_for_each_entry(cb
, &smsg_list
, list
)
83 if (strncmp(msg
+ 8, cb
->prefix
, cb
->len
) == 0) {
84 cb
->callback(sender
, msg
+ 8);
87 spin_unlock(&smsg_list_lock
);
92 static iucv_interrupt_ops_t smsg_ops
= {
93 .ConnectionComplete
= smsg_connection_complete
,
94 .MessagePending
= smsg_message_pending
,
97 static struct device_driver smsg_driver
= {
103 smsg_register_callback(char *prefix
, void (*callback
)(char *from
, char *str
))
105 struct smsg_callback
*cb
;
107 cb
= kmalloc(sizeof(struct smsg_callback
), GFP_KERNEL
);
111 cb
->len
= strlen(prefix
);
112 cb
->callback
= callback
;
113 spin_lock(&smsg_list_lock
);
114 list_add_tail(&cb
->list
, &smsg_list
);
115 spin_unlock(&smsg_list_lock
);
120 smsg_unregister_callback(char *prefix
, void (*callback
)(char *from
, char *str
))
122 struct smsg_callback
*cb
, *tmp
;
124 spin_lock(&smsg_list_lock
);
126 list_for_each_entry(tmp
, &smsg_list
, list
)
127 if (tmp
->callback
== callback
&&
128 strcmp(tmp
->prefix
, prefix
) == 0) {
133 spin_unlock(&smsg_list_lock
);
140 if (smsg_handle
> 0) {
141 cpcmd("SET SMSG OFF", NULL
, 0, NULL
);
142 iucv_sever(smsg_pathid
, 0);
143 iucv_unregister_program(smsg_handle
);
144 driver_unregister(&smsg_driver
);
152 static unsigned char pgmmask
[24] = {
153 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
154 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
155 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
159 rc
= driver_register(&smsg_driver
);
161 printk(KERN_ERR
"SMSGIUCV: failed to register driver.\n");
164 smsg_handle
= iucv_register_program("SMSGIUCV ", "*MSG ",
165 pgmmask
, &smsg_ops
, 0);
167 printk(KERN_ERR
"SMSGIUCV: failed to register to iucv");
168 driver_unregister(&smsg_driver
);
169 return -EIO
; /* better errno ? */
171 rc
= iucv_connect (&smsg_pathid
, 255, 0, "*MSG ", 0, 0, 0, 0,
174 printk(KERN_ERR
"SMSGIUCV: failed to connect to *MSG");
175 iucv_unregister_program(smsg_handle
);
176 driver_unregister(&smsg_driver
);
180 cpcmd("SET SMSG IUCV", NULL
, 0, NULL
);
184 module_init(smsg_init
);
185 module_exit(smsg_exit
);
186 MODULE_LICENSE("GPL");
188 EXPORT_SYMBOL(smsg_register_callback
);
189 EXPORT_SYMBOL(smsg_unregister_callback
);