aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2007-02-08 16:51:11 -0500
committerDavid S. Miller <davem@davemloft.net>2007-02-08 16:51:11 -0500
commit5da5e658debb7deddbfe5c133c76db3be0a3e12c (patch)
tree79d50ebde60058d4a92705f2b16f299306e5ec42
parenteebce38567373e3abbb640ab145d154831cc55df (diff)
[S390]: Adapt special message interface to new IUCV API
Adapt special message interface to new IUCV API Signed-off-by: Frank Pavlic <fpavlic@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/s390/net/smsgiucv.c147
1 files changed, 74 insertions, 73 deletions
diff --git a/drivers/s390/net/smsgiucv.c b/drivers/s390/net/smsgiucv.c
index b8179c27ceb6..3ccca5871fdf 100644
--- a/drivers/s390/net/smsgiucv.c
+++ b/drivers/s390/net/smsgiucv.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * IUCV special message driver 2 * IUCV special message driver
3 * 3 *
4 * Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation 4 * Copyright 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -23,10 +23,10 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/device.h> 25#include <linux/device.h>
26#include <net/iucv/iucv.h>
26#include <asm/cpcmd.h> 27#include <asm/cpcmd.h>
27#include <asm/ebcdic.h> 28#include <asm/ebcdic.h>
28 29#include "smsgiucv.h"
29#include "iucv.h"
30 30
31struct smsg_callback { 31struct smsg_callback {
32 struct list_head list; 32 struct list_head list;
@@ -39,38 +39,46 @@ MODULE_AUTHOR
39 ("(C) 2003 IBM Corporation by Martin Schwidefsky (schwidefsky@de.ibm.com)"); 39 ("(C) 2003 IBM Corporation by Martin Schwidefsky (schwidefsky@de.ibm.com)");
40MODULE_DESCRIPTION ("Linux for S/390 IUCV special message driver"); 40MODULE_DESCRIPTION ("Linux for S/390 IUCV special message driver");
41 41
42static iucv_handle_t smsg_handle; 42static struct iucv_path *smsg_path;
43static unsigned short smsg_pathid; 43
44static DEFINE_SPINLOCK(smsg_list_lock); 44static DEFINE_SPINLOCK(smsg_list_lock);
45static struct list_head smsg_list = LIST_HEAD_INIT(smsg_list); 45static struct list_head smsg_list = LIST_HEAD_INIT(smsg_list);
46 46
47static void 47static int smsg_path_pending(struct iucv_path *, u8 ipvmid[8], u8 ipuser[16]);
48smsg_connection_complete(iucv_ConnectionComplete *eib, void *pgm_data) 48static void smsg_message_pending(struct iucv_path *, struct iucv_message *);
49
50static struct iucv_handler smsg_handler = {
51 .path_pending = smsg_path_pending,
52 .message_pending = smsg_message_pending,
53};
54
55static int smsg_path_pending(struct iucv_path *path, u8 ipvmid[8],
56 u8 ipuser[16])
49{ 57{
58 if (strncmp(ipvmid, "*MSG ", sizeof(ipvmid)) != 0)
59 return -EINVAL;
60 /* Path pending from *MSG. */
61 return iucv_path_accept(path, &smsg_handler, "SMSGIUCV ", NULL);
50} 62}
51 63
52 64static void smsg_message_pending(struct iucv_path *path,
53static void 65 struct iucv_message *msg)
54smsg_message_pending(iucv_MessagePending *eib, void *pgm_data)
55{ 66{
56 struct smsg_callback *cb; 67 struct smsg_callback *cb;
57 unsigned char *msg; 68 unsigned char *buffer;
58 unsigned char sender[9]; 69 unsigned char sender[9];
59 unsigned short len;
60 int rc, i; 70 int rc, i;
61 71
62 len = eib->ln1msg2.ipbfln1f; 72 buffer = kmalloc(msg->length + 1, GFP_ATOMIC | GFP_DMA);
63 msg = kmalloc(len + 1, GFP_ATOMIC|GFP_DMA); 73 if (!buffer) {
64 if (!msg) { 74 iucv_message_reject(path, msg);
65 iucv_reject(eib->ippathid, eib->ipmsgid, eib->iptrgcls);
66 return; 75 return;
67 } 76 }
68 rc = iucv_receive(eib->ippathid, eib->ipmsgid, eib->iptrgcls, 77 rc = iucv_message_receive(path, msg, 0, buffer, msg->length, NULL);
69 msg, len, NULL, NULL, NULL);
70 if (rc == 0) { 78 if (rc == 0) {
71 msg[len] = 0; 79 buffer[msg->length] = 0;
72 EBCASC(msg, len); 80 EBCASC(buffer, msg->length);
73 memcpy(sender, msg, 8); 81 memcpy(sender, buffer, 8);
74 sender[8] = 0; 82 sender[8] = 0;
75 /* Remove trailing whitespace from the sender name. */ 83 /* Remove trailing whitespace from the sender name. */
76 for (i = 7; i >= 0; i--) { 84 for (i = 7; i >= 0; i--) {
@@ -80,27 +88,17 @@ smsg_message_pending(iucv_MessagePending *eib, void *pgm_data)
80 } 88 }
81 spin_lock(&smsg_list_lock); 89 spin_lock(&smsg_list_lock);
82 list_for_each_entry(cb, &smsg_list, list) 90 list_for_each_entry(cb, &smsg_list, list)
83 if (strncmp(msg + 8, cb->prefix, cb->len) == 0) { 91 if (strncmp(buffer + 8, cb->prefix, cb->len) == 0) {
84 cb->callback(sender, msg + 8); 92 cb->callback(sender, buffer + 8);
85 break; 93 break;
86 } 94 }
87 spin_unlock(&smsg_list_lock); 95 spin_unlock(&smsg_list_lock);
88 } 96 }
89 kfree(msg); 97 kfree(buffer);
90} 98}
91 99
92static iucv_interrupt_ops_t smsg_ops = { 100int smsg_register_callback(char *prefix,
93 .ConnectionComplete = smsg_connection_complete, 101 void (*callback)(char *from, char *str))
94 .MessagePending = smsg_message_pending,
95};
96
97static struct device_driver smsg_driver = {
98 .name = "SMSGIUCV",
99 .bus = &iucv_bus,
100};
101
102int
103smsg_register_callback(char *prefix, void (*callback)(char *from, char *str))
104{ 102{
105 struct smsg_callback *cb; 103 struct smsg_callback *cb;
106 104
@@ -110,18 +108,18 @@ smsg_register_callback(char *prefix, void (*callback)(char *from, char *str))
110 cb->prefix = prefix; 108 cb->prefix = prefix;
111 cb->len = strlen(prefix); 109 cb->len = strlen(prefix);
112 cb->callback = callback; 110 cb->callback = callback;
113 spin_lock(&smsg_list_lock); 111 spin_lock_bh(&smsg_list_lock);
114 list_add_tail(&cb->list, &smsg_list); 112 list_add_tail(&cb->list, &smsg_list);
115 spin_unlock(&smsg_list_lock); 113 spin_unlock_bh(&smsg_list_lock);
116 return 0; 114 return 0;
117} 115}
118 116
119void 117void smsg_unregister_callback(char *prefix,
120smsg_unregister_callback(char *prefix, void (*callback)(char *from, char *str)) 118 void (*callback)(char *from, char *str))
121{ 119{
122 struct smsg_callback *cb, *tmp; 120 struct smsg_callback *cb, *tmp;
123 121
124 spin_lock(&smsg_list_lock); 122 spin_lock_bh(&smsg_list_lock);
125 cb = NULL; 123 cb = NULL;
126 list_for_each_entry(tmp, &smsg_list, list) 124 list_for_each_entry(tmp, &smsg_list, list)
127 if (tmp->callback == callback && 125 if (tmp->callback == callback &&
@@ -130,55 +128,58 @@ smsg_unregister_callback(char *prefix, void (*callback)(char *from, char *str))
130 list_del(&cb->list); 128 list_del(&cb->list);
131 break; 129 break;
132 } 130 }
133 spin_unlock(&smsg_list_lock); 131 spin_unlock_bh(&smsg_list_lock);
134 kfree(cb); 132 kfree(cb);
135} 133}
136 134
137static void __exit 135static struct device_driver smsg_driver = {
138smsg_exit(void) 136 .name = "SMSGIUCV",
137 .bus = &iucv_bus,
138};
139
140static void __exit smsg_exit(void)
139{ 141{
140 if (smsg_handle > 0) { 142 cpcmd("SET SMSG IUCV", NULL, 0, NULL);
141 cpcmd("SET SMSG OFF", NULL, 0, NULL); 143 iucv_unregister(&smsg_handler, 1);
142 iucv_sever(smsg_pathid, NULL); 144 driver_unregister(&smsg_driver);
143 iucv_unregister_program(smsg_handle);
144 driver_unregister(&smsg_driver);
145 }
146 return;
147} 145}
148 146
149static int __init 147static int __init smsg_init(void)
150smsg_init(void)
151{ 148{
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
156 };
157 int rc; 149 int rc;
158 150
159 rc = driver_register(&smsg_driver); 151 rc = driver_register(&smsg_driver);
160 if (rc != 0) { 152 if (rc != 0)
161 printk(KERN_ERR "SMSGIUCV: failed to register driver.\n"); 153 goto out;
162 return rc; 154 rc = iucv_register(&smsg_handler, 1);
163 } 155 if (rc) {
164 smsg_handle = iucv_register_program("SMSGIUCV ", "*MSG ",
165 pgmmask, &smsg_ops, NULL);
166 if (!smsg_handle) {
167 printk(KERN_ERR "SMSGIUCV: failed to register to iucv"); 156 printk(KERN_ERR "SMSGIUCV: failed to register to iucv");
168 driver_unregister(&smsg_driver); 157 rc = -EIO; /* better errno ? */
169 return -EIO; /* better errno ? */ 158 goto out_driver;
159 }
160 smsg_path = iucv_path_alloc(255, 0, GFP_KERNEL);
161 if (!smsg_path) {
162 rc = -ENOMEM;
163 goto out_register;
170 } 164 }
171 rc = iucv_connect (&smsg_pathid, 255, NULL, "*MSG ", NULL, 0, 165 rc = iucv_path_connect(smsg_path, &smsg_handler, "*MSG ",
172 NULL, NULL, smsg_handle, NULL); 166 NULL, NULL, NULL);
173 if (rc) { 167 if (rc) {
174 printk(KERN_ERR "SMSGIUCV: failed to connect to *MSG"); 168 printk(KERN_ERR "SMSGIUCV: failed to connect to *MSG");
175 iucv_unregister_program(smsg_handle); 169 rc = -EIO; /* better errno ? */
176 driver_unregister(&smsg_driver); 170 goto out_free;
177 smsg_handle = NULL;
178 return -EIO;
179 } 171 }
180 cpcmd("SET SMSG IUCV", NULL, 0, NULL); 172 cpcmd("SET SMSG IUCV", NULL, 0, NULL);
181 return 0; 173 return 0;
174
175out_free:
176 iucv_path_free(smsg_path);
177out_register:
178 iucv_unregister(&smsg_handler, 1);
179out_driver:
180 driver_unregister(&smsg_driver);
181out:
182 return rc;
182} 183}
183 184
184module_init(smsg_init); 185module_init(smsg_init);