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 *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
;
61 len
= eib
->ln1msg2
.ipbfln1f
;
62 msg
= kmalloc(len
+ 1, GFP_ATOMIC
|GFP_DMA
);
64 iucv_reject(eib
->ippathid
, eib
->ipmsgid
, eib
->iptrgcls
);
67 rc
= iucv_receive(eib
->ippathid
, eib
->ipmsgid
, eib
->iptrgcls
,
72 spin_lock(&smsg_list_lock
);
73 list_for_each_entry(cb
, &smsg_list
, list
)
74 if (strncmp(msg
+ 8, cb
->prefix
, cb
->len
) == 0) {
75 cb
->callback(msg
+ 8);
78 spin_unlock(&smsg_list_lock
);
83 static iucv_interrupt_ops_t smsg_ops
= {
84 .ConnectionComplete
= smsg_connection_complete
,
85 .MessagePending
= smsg_message_pending
,
88 static struct device_driver smsg_driver
= {
94 smsg_register_callback(char *prefix
, void (*callback
)(char *str
))
96 struct smsg_callback
*cb
;
98 cb
= kmalloc(sizeof(struct smsg_callback
), GFP_KERNEL
);
102 cb
->len
= strlen(prefix
);
103 cb
->callback
= callback
;
104 spin_lock(&smsg_list_lock
);
105 list_add_tail(&cb
->list
, &smsg_list
);
106 spin_unlock(&smsg_list_lock
);
111 smsg_unregister_callback(char *prefix
, void (*callback
)(char *str
))
113 struct smsg_callback
*cb
, *tmp
;
115 spin_lock(&smsg_list_lock
);
117 list_for_each_entry(tmp
, &smsg_list
, list
)
118 if (tmp
->callback
== callback
&&
119 strcmp(tmp
->prefix
, prefix
) == 0) {
124 spin_unlock(&smsg_list_lock
);
131 if (smsg_handle
> 0) {
132 cpcmd("SET SMSG OFF", 0, 0);
133 iucv_sever(smsg_pathid
, 0);
134 iucv_unregister_program(smsg_handle
);
135 driver_unregister(&smsg_driver
);
143 static unsigned char pgmmask
[24] = {
144 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
145 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
146 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
150 rc
= driver_register(&smsg_driver
);
152 printk(KERN_ERR
"SMSGIUCV: failed to register driver.\n");
155 smsg_handle
= iucv_register_program("SMSGIUCV ", "*MSG ",
156 pgmmask
, &smsg_ops
, 0);
158 printk(KERN_ERR
"SMSGIUCV: failed to register to iucv");
159 driver_unregister(&smsg_driver
);
160 return -EIO
; /* better errno ? */
162 rc
= iucv_connect (&smsg_pathid
, 1, 0, "*MSG ", 0, 0, 0, 0,
165 printk(KERN_ERR
"SMSGIUCV: failed to connect to *MSG");
166 iucv_unregister_program(smsg_handle
);
167 driver_unregister(&smsg_driver
);
171 cpcmd("SET SMSG IUCV", 0, 0);
175 module_init(smsg_init
);
176 module_exit(smsg_exit
);
177 MODULE_LICENSE("GPL");
179 EXPORT_SYMBOL(smsg_register_callback
);
180 EXPORT_SYMBOL(smsg_unregister_callback
);