blob: d764f4c1b7e4eac68962e3bb95b37df2d57ece97 [file] [log] [blame]
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001/*
2 * IUCV base infrastructure.
3 *
4 * Copyright 2001, 2006 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s):
6 * Original source:
7 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
8 * Xenia Tkatschow (xenia@us.ibm.com)
9 * 2Gb awareness and general cleanup:
10 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
11 * Rewritten for af_iucv:
12 * Martin Schwidefsky <schwidefsky@de.ibm.com>
13 *
14 * Documentation used:
15 * The original source
16 * CP Programming Service, IBM document # SC24-5760
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/module.h>
34#include <linux/moduleparam.h>
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080035#include <linux/spinlock.h>
36#include <linux/kernel.h>
37#include <linux/slab.h>
38#include <linux/init.h>
39#include <linux/interrupt.h>
40#include <linux/list.h>
41#include <linux/errno.h>
42#include <linux/err.h>
43#include <linux/device.h>
44#include <linux/cpu.h>
45#include <net/iucv/iucv.h>
46#include <asm/atomic.h>
47#include <asm/ebcdic.h>
48#include <asm/io.h>
49#include <asm/s390_ext.h>
50#include <asm/s390_rdev.h>
51#include <asm/smp.h>
52
53/*
54 * FLAGS:
55 * All flags are defined in the field IPFLAGS1 of each function
56 * and can be found in CP Programming Services.
57 * IPSRCCLS - Indicates you have specified a source class.
58 * IPTRGCLS - Indicates you have specified a target class.
59 * IPFGPID - Indicates you have specified a pathid.
60 * IPFGMID - Indicates you have specified a message ID.
61 * IPNORPY - Indicates a one-way message. No reply expected.
62 * IPALL - Indicates that all paths are affected.
63 */
64#define IUCV_IPSRCCLS 0x01
65#define IUCV_IPTRGCLS 0x01
66#define IUCV_IPFGPID 0x02
67#define IUCV_IPFGMID 0x04
68#define IUCV_IPNORPY 0x10
69#define IUCV_IPALL 0x80
70
Heiko Carstensda99f052007-05-04 12:23:27 -070071static int iucv_bus_match(struct device *dev, struct device_driver *drv)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080072{
73 return 0;
74}
75
76struct bus_type iucv_bus = {
77 .name = "iucv",
78 .match = iucv_bus_match,
79};
Heiko Carstensda99f052007-05-04 12:23:27 -070080EXPORT_SYMBOL(iucv_bus);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080081
82struct device *iucv_root;
Heiko Carstensda99f052007-05-04 12:23:27 -070083EXPORT_SYMBOL(iucv_root);
84
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080085static int iucv_available;
86
87/* General IUCV interrupt structure */
88struct iucv_irq_data {
89 u16 ippathid;
90 u8 ipflags1;
91 u8 iptype;
92 u32 res2[8];
93};
94
Martin Schwidefsky04b090d2007-04-28 23:03:59 -070095struct iucv_irq_list {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080096 struct list_head list;
97 struct iucv_irq_data data;
98};
99
Christoph Lameter70cf50352007-11-20 11:13:38 +0100100static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800101static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
102static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
103
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700104/*
105 * Queue of interrupt buffers lock for delivery via the tasklet
106 * (fast but can't call smp_call_function).
107 */
108static LIST_HEAD(iucv_task_queue);
109
110/*
111 * The tasklet for fast delivery of iucv interrupts.
112 */
113static void iucv_tasklet_fn(unsigned long);
114static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
115
116/*
117 * Queue of interrupt buffers for delivery via a work queue
118 * (slower but can call smp_call_function).
119 */
120static LIST_HEAD(iucv_work_queue);
121
122/*
123 * The work element to deliver path pending interrupts.
124 */
125static void iucv_work_fn(struct work_struct *work);
126static DECLARE_WORK(iucv_work, iucv_work_fn);
127
128/*
129 * Spinlock protecting task and work queue.
130 */
131static DEFINE_SPINLOCK(iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800132
133enum iucv_command_codes {
134 IUCV_QUERY = 0,
135 IUCV_RETRIEVE_BUFFER = 2,
136 IUCV_SEND = 4,
137 IUCV_RECEIVE = 5,
138 IUCV_REPLY = 6,
139 IUCV_REJECT = 8,
140 IUCV_PURGE = 9,
141 IUCV_ACCEPT = 10,
142 IUCV_CONNECT = 11,
143 IUCV_DECLARE_BUFFER = 12,
144 IUCV_QUIESCE = 13,
145 IUCV_RESUME = 14,
146 IUCV_SEVER = 15,
147 IUCV_SETMASK = 16,
148};
149
150/*
151 * Error messages that are used with the iucv_sever function. They get
152 * converted to EBCDIC.
153 */
154static char iucv_error_no_listener[16] = "NO LISTENER";
155static char iucv_error_no_memory[16] = "NO MEMORY";
156static char iucv_error_pathid[16] = "INVALID PATHID";
157
158/*
159 * iucv_handler_list: List of registered handlers.
160 */
161static LIST_HEAD(iucv_handler_list);
162
163/*
164 * iucv_path_table: an array of iucv_path structures.
165 */
166static struct iucv_path **iucv_path_table;
167static unsigned long iucv_max_pathid;
168
169/*
170 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
171 */
172static DEFINE_SPINLOCK(iucv_table_lock);
173
174/*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700175 * iucv_active_cpu: contains the number of the cpu executing the tasklet
176 * or the work handler. Needed for iucv_path_sever called from tasklet.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800177 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700178static int iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800179
180/*
181 * Mutex and wait queue for iucv_register/iucv_unregister.
182 */
183static DEFINE_MUTEX(iucv_register_mutex);
184
185/*
186 * Counter for number of non-smp capable handlers.
187 */
188static int iucv_nonsmp_handler;
189
190/*
191 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
192 * iucv_path_quiesce and iucv_path_sever.
193 */
194struct iucv_cmd_control {
195 u16 ippathid;
196 u8 ipflags1;
197 u8 iprcode;
198 u16 ipmsglim;
199 u16 res1;
200 u8 ipvmid[8];
201 u8 ipuser[16];
202 u8 iptarget[8];
203} __attribute__ ((packed,aligned(8)));
204
205/*
206 * Data in parameter list iucv structure. Used by iucv_message_send,
207 * iucv_message_send2way and iucv_message_reply.
208 */
209struct iucv_cmd_dpl {
210 u16 ippathid;
211 u8 ipflags1;
212 u8 iprcode;
213 u32 ipmsgid;
214 u32 iptrgcls;
215 u8 iprmmsg[8];
216 u32 ipsrccls;
217 u32 ipmsgtag;
218 u32 ipbfadr2;
219 u32 ipbfln2f;
220 u32 res;
221} __attribute__ ((packed,aligned(8)));
222
223/*
224 * Data in buffer iucv structure. Used by iucv_message_receive,
225 * iucv_message_reject, iucv_message_send, iucv_message_send2way
226 * and iucv_declare_cpu.
227 */
228struct iucv_cmd_db {
229 u16 ippathid;
230 u8 ipflags1;
231 u8 iprcode;
232 u32 ipmsgid;
233 u32 iptrgcls;
234 u32 ipbfadr1;
235 u32 ipbfln1f;
236 u32 ipsrccls;
237 u32 ipmsgtag;
238 u32 ipbfadr2;
239 u32 ipbfln2f;
240 u32 res;
241} __attribute__ ((packed,aligned(8)));
242
243/*
244 * Purge message iucv structure. Used by iucv_message_purge.
245 */
246struct iucv_cmd_purge {
247 u16 ippathid;
248 u8 ipflags1;
249 u8 iprcode;
250 u32 ipmsgid;
251 u8 ipaudit[3];
252 u8 res1[5];
253 u32 res2;
254 u32 ipsrccls;
255 u32 ipmsgtag;
256 u32 res3[3];
257} __attribute__ ((packed,aligned(8)));
258
259/*
260 * Set mask iucv structure. Used by iucv_enable_cpu.
261 */
262struct iucv_cmd_set_mask {
263 u8 ipmask;
264 u8 res1[2];
265 u8 iprcode;
266 u32 res2[9];
267} __attribute__ ((packed,aligned(8)));
268
269union iucv_param {
270 struct iucv_cmd_control ctrl;
271 struct iucv_cmd_dpl dpl;
272 struct iucv_cmd_db db;
273 struct iucv_cmd_purge purge;
274 struct iucv_cmd_set_mask set_mask;
275};
276
277/*
278 * Anchor for per-cpu IUCV command parameter block.
279 */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100280static union iucv_param *iucv_param[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800281
282/**
283 * iucv_call_b2f0
284 * @code: identifier of IUCV call to CP.
285 * @parm: pointer to a struct iucv_parm block
286 *
287 * Calls CP to execute IUCV commands.
288 *
289 * Returns the result of the CP IUCV call.
290 */
291static inline int iucv_call_b2f0(int command, union iucv_param *parm)
292{
293 register unsigned long reg0 asm ("0");
294 register unsigned long reg1 asm ("1");
295 int ccode;
296
297 reg0 = command;
298 reg1 = virt_to_phys(parm);
299 asm volatile(
300 " .long 0xb2f01000\n"
301 " ipm %0\n"
302 " srl %0,28\n"
303 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
304 : "m" (*parm) : "cc");
305 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
306}
307
308/**
309 * iucv_query_maxconn
310 *
311 * Determines the maximum number of connections that may be established.
312 *
313 * Returns the maximum number of connections or -EPERM is IUCV is not
314 * available.
315 */
316static int iucv_query_maxconn(void)
317{
318 register unsigned long reg0 asm ("0");
319 register unsigned long reg1 asm ("1");
320 void *param;
321 int ccode;
322
323 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
324 if (!param)
325 return -ENOMEM;
326 reg0 = IUCV_QUERY;
327 reg1 = (unsigned long) param;
328 asm volatile (
329 " .long 0xb2f01000\n"
330 " ipm %0\n"
331 " srl %0,28\n"
332 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
333 if (ccode == 0)
334 iucv_max_pathid = reg0;
335 kfree(param);
336 return ccode ? -EPERM : 0;
337}
338
339/**
340 * iucv_allow_cpu
341 * @data: unused
342 *
343 * Allow iucv interrupts on this cpu.
344 */
345static void iucv_allow_cpu(void *data)
346{
347 int cpu = smp_processor_id();
348 union iucv_param *parm;
349
350 /*
351 * Enable all iucv interrupts.
352 * ipmask contains bits for the different interrupts
353 * 0x80 - Flag to allow nonpriority message pending interrupts
354 * 0x40 - Flag to allow priority message pending interrupts
355 * 0x20 - Flag to allow nonpriority message completion interrupts
356 * 0x10 - Flag to allow priority message completion interrupts
357 * 0x08 - Flag to allow IUCV control interrupts
358 */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100359 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800360 memset(parm, 0, sizeof(union iucv_param));
361 parm->set_mask.ipmask = 0xf8;
362 iucv_call_b2f0(IUCV_SETMASK, parm);
363
364 /* Set indication that iucv interrupts are allowed for this cpu. */
365 cpu_set(cpu, iucv_irq_cpumask);
366}
367
368/**
369 * iucv_block_cpu
370 * @data: unused
371 *
372 * Block iucv interrupts on this cpu.
373 */
374static void iucv_block_cpu(void *data)
375{
376 int cpu = smp_processor_id();
377 union iucv_param *parm;
378
379 /* Disable all iucv interrupts. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100380 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800381 memset(parm, 0, sizeof(union iucv_param));
382 iucv_call_b2f0(IUCV_SETMASK, parm);
383
384 /* Clear indication that iucv interrupts are allowed for this cpu. */
385 cpu_clear(cpu, iucv_irq_cpumask);
386}
387
388/**
389 * iucv_declare_cpu
390 * @data: unused
391 *
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200392 * Declare a interrupt buffer on this cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800393 */
394static void iucv_declare_cpu(void *data)
395{
396 int cpu = smp_processor_id();
397 union iucv_param *parm;
398 int rc;
399
400 if (cpu_isset(cpu, iucv_buffer_cpumask))
401 return;
402
403 /* Declare interrupt buffer. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100404 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800405 memset(parm, 0, sizeof(union iucv_param));
Christoph Lameter70cf50352007-11-20 11:13:38 +0100406 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800407 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
408 if (rc) {
409 char *err = "Unknown";
Heiko Carstensda99f052007-05-04 12:23:27 -0700410 switch (rc) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800411 case 0x03:
412 err = "Directory error";
413 break;
414 case 0x0a:
415 err = "Invalid length";
416 break;
417 case 0x13:
418 err = "Buffer already exists";
419 break;
420 case 0x3e:
421 err = "Buffer overlap";
422 break;
423 case 0x5c:
424 err = "Paging or storage error";
425 break;
426 }
427 printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
428 "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
429 return;
430 }
431
432 /* Set indication that an iucv buffer exists for this cpu. */
433 cpu_set(cpu, iucv_buffer_cpumask);
434
435 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
436 /* Enable iucv interrupts on this cpu. */
437 iucv_allow_cpu(NULL);
438 else
439 /* Disable iucv interrupts on this cpu. */
440 iucv_block_cpu(NULL);
441}
442
443/**
444 * iucv_retrieve_cpu
445 * @data: unused
446 *
447 * Retrieve interrupt buffer on this cpu.
448 */
449static void iucv_retrieve_cpu(void *data)
450{
451 int cpu = smp_processor_id();
452 union iucv_param *parm;
453
454 if (!cpu_isset(cpu, iucv_buffer_cpumask))
455 return;
456
457 /* Block iucv interrupts. */
458 iucv_block_cpu(NULL);
459
460 /* Retrieve interrupt buffer. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100461 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800462 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
463
464 /* Clear indication that an iucv buffer exists for this cpu. */
465 cpu_clear(cpu, iucv_buffer_cpumask);
466}
467
468/**
469 * iucv_setmask_smp
470 *
471 * Allow iucv interrupts on all cpus.
472 */
473static void iucv_setmask_mp(void)
474{
475 int cpu;
476
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700477 preempt_disable();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800478 for_each_online_cpu(cpu)
479 /* Enable all cpus with a declared buffer. */
480 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
481 !cpu_isset(cpu, iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200482 smp_call_function_single(cpu, iucv_allow_cpu,
483 NULL, 0, 1);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700484 preempt_enable();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800485}
486
487/**
488 * iucv_setmask_up
489 *
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700490 * Allow iucv interrupts on a single cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800491 */
492static void iucv_setmask_up(void)
493{
494 cpumask_t cpumask;
495 int cpu;
496
497 /* Disable all cpu but the first in cpu_irq_cpumask. */
498 cpumask = iucv_irq_cpumask;
499 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
500 for_each_cpu_mask(cpu, cpumask)
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200501 smp_call_function_single(cpu, iucv_block_cpu, NULL, 0, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800502}
503
504/**
505 * iucv_enable
506 *
507 * This function makes iucv ready for use. It allocates the pathid
508 * table, declares an iucv interrupt buffer and enables the iucv
509 * interrupts. Called when the first user has registered an iucv
510 * handler.
511 */
512static int iucv_enable(void)
513{
514 size_t alloc_size;
515 int cpu, rc;
516
517 rc = -ENOMEM;
518 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
519 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
520 if (!iucv_path_table)
521 goto out;
522 /* Declare per cpu buffers. */
523 rc = -EIO;
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700524 preempt_disable();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800525 for_each_online_cpu(cpu)
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200526 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700527 preempt_enable();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800528 if (cpus_empty(iucv_buffer_cpumask))
529 /* No cpu could declare an iucv buffer. */
530 goto out_path;
531 return 0;
532
533out_path:
534 kfree(iucv_path_table);
535out:
536 return rc;
537}
538
539/**
540 * iucv_disable
541 *
542 * This function shuts down iucv. It disables iucv interrupts, retrieves
543 * the iucv interrupt buffer and frees the pathid table. Called after the
544 * last user unregister its iucv handler.
545 */
546static void iucv_disable(void)
547{
548 on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
549 kfree(iucv_path_table);
550}
551
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800552static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
553 unsigned long action, void *hcpu)
554{
555 cpumask_t cpumask;
556 long cpu = (long) hcpu;
557
558 switch (action) {
559 case CPU_UP_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700560 case CPU_UP_PREPARE_FROZEN:
Christoph Lameter70cf50352007-11-20 11:13:38 +0100561 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
562 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
563 if (!iucv_irq_data[cpu])
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800564 return NOTIFY_BAD;
Christoph Lameter70cf50352007-11-20 11:13:38 +0100565 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
566 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
567 if (!iucv_param[cpu])
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800568 return NOTIFY_BAD;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800569 break;
570 case CPU_UP_CANCELED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700571 case CPU_UP_CANCELED_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800572 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700573 case CPU_DEAD_FROZEN:
Christoph Lameter70cf50352007-11-20 11:13:38 +0100574 kfree(iucv_param[cpu]);
575 iucv_param[cpu] = NULL;
576 kfree(iucv_irq_data[cpu]);
577 iucv_irq_data[cpu] = NULL;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800578 break;
579 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700580 case CPU_ONLINE_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800581 case CPU_DOWN_FAILED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700582 case CPU_DOWN_FAILED_FROZEN:
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200583 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800584 break;
585 case CPU_DOWN_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700586 case CPU_DOWN_PREPARE_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800587 cpumask = iucv_buffer_cpumask;
588 cpu_clear(cpu, cpumask);
589 if (cpus_empty(cpumask))
590 /* Can't offline last IUCV enabled cpu. */
591 return NOTIFY_BAD;
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200592 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 0, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800593 if (cpus_empty(iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200594 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
595 iucv_allow_cpu, NULL, 0, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800596 break;
597 }
598 return NOTIFY_OK;
599}
600
Heiko Carstensda99f052007-05-04 12:23:27 -0700601static struct notifier_block __cpuinitdata iucv_cpu_notifier = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800602 .notifier_call = iucv_cpu_notify,
603};
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800604
605/**
606 * iucv_sever_pathid
607 * @pathid: path identification number.
608 * @userdata: 16-bytes of user data.
609 *
610 * Sever an iucv path to free up the pathid. Used internally.
611 */
612static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
613{
614 union iucv_param *parm;
615
Christoph Lameter70cf50352007-11-20 11:13:38 +0100616 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800617 memset(parm, 0, sizeof(union iucv_param));
618 if (userdata)
619 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
620 parm->ctrl.ippathid = pathid;
621 return iucv_call_b2f0(IUCV_SEVER, parm);
622}
623
624/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700625 * __iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800626 * @dummy: unused dummy argument
627 *
628 * Nop function called via smp_call_function to force work items from
629 * pending external iucv interrupts to the work queue.
630 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700631static void __iucv_cleanup_queue(void *dummy)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800632{
633}
634
635/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700636 * iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800637 *
638 * Function called after a path has been severed to find all remaining
639 * work items for the now stale pathid. The caller needs to hold the
640 * iucv_table_lock.
641 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700642static void iucv_cleanup_queue(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800643{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700644 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800645
646 /*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700647 * When a path is severed, the pathid can be reused immediatly
648 * on a iucv connect or a connection pending interrupt. Remove
649 * all entries from the task queue that refer to a stale pathid
650 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
651 * or deliver the connection pending interrupt. To get all the
652 * pending interrupts force them to the work queue by calling
653 * an empty function on all cpus.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800654 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700655 smp_call_function(__iucv_cleanup_queue, NULL, 0, 1);
656 spin_lock_irq(&iucv_queue_lock);
657 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
658 /* Remove stale work items from the task queue. */
659 if (iucv_path_table[p->data.ippathid] == NULL) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800660 list_del(&p->list);
661 kfree(p);
662 }
663 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700664 spin_unlock_irq(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800665}
666
667/**
668 * iucv_register:
669 * @handler: address of iucv handler structure
670 * @smp: != 0 indicates that the handler can deal with out of order messages
671 *
672 * Registers a driver with IUCV.
673 *
674 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
675 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
676 */
677int iucv_register(struct iucv_handler *handler, int smp)
678{
679 int rc;
680
681 if (!iucv_available)
682 return -ENOSYS;
683 mutex_lock(&iucv_register_mutex);
684 if (!smp)
685 iucv_nonsmp_handler++;
686 if (list_empty(&iucv_handler_list)) {
687 rc = iucv_enable();
688 if (rc)
689 goto out_mutex;
690 } else if (!smp && iucv_nonsmp_handler == 1)
691 iucv_setmask_up();
692 INIT_LIST_HEAD(&handler->paths);
693
Ursula Braun435bc9d2008-02-07 18:06:52 -0800694 spin_lock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800695 list_add_tail(&handler->list, &iucv_handler_list);
Ursula Braun435bc9d2008-02-07 18:06:52 -0800696 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800697 rc = 0;
698out_mutex:
699 mutex_unlock(&iucv_register_mutex);
700 return rc;
701}
Heiko Carstensda99f052007-05-04 12:23:27 -0700702EXPORT_SYMBOL(iucv_register);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800703
704/**
705 * iucv_unregister
706 * @handler: address of iucv handler structure
707 * @smp: != 0 indicates that the handler can deal with out of order messages
708 *
709 * Unregister driver from IUCV.
710 */
711void iucv_unregister(struct iucv_handler *handler, int smp)
712{
713 struct iucv_path *p, *n;
714
715 mutex_lock(&iucv_register_mutex);
716 spin_lock_bh(&iucv_table_lock);
717 /* Remove handler from the iucv_handler_list. */
718 list_del_init(&handler->list);
719 /* Sever all pathids still refering to the handler. */
720 list_for_each_entry_safe(p, n, &handler->paths, list) {
721 iucv_sever_pathid(p->pathid, NULL);
722 iucv_path_table[p->pathid] = NULL;
723 list_del(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800724 iucv_path_free(p);
725 }
726 spin_unlock_bh(&iucv_table_lock);
727 if (!smp)
728 iucv_nonsmp_handler--;
729 if (list_empty(&iucv_handler_list))
730 iucv_disable();
731 else if (!smp && iucv_nonsmp_handler == 0)
732 iucv_setmask_mp();
733 mutex_unlock(&iucv_register_mutex);
734}
Heiko Carstensda99f052007-05-04 12:23:27 -0700735EXPORT_SYMBOL(iucv_unregister);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800736
737/**
738 * iucv_path_accept
739 * @path: address of iucv path structure
740 * @handler: address of iucv handler structure
741 * @userdata: 16 bytes of data reflected to the communication partner
742 * @private: private data passed to interrupt handlers for this path
743 *
744 * This function is issued after the user received a connection pending
745 * external interrupt and now wishes to complete the IUCV communication path.
746 *
747 * Returns the result of the CP IUCV call.
748 */
749int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
750 u8 userdata[16], void *private)
751{
752 union iucv_param *parm;
753 int rc;
754
755 local_bh_disable();
756 /* Prepare parameter block. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100757 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800758 memset(parm, 0, sizeof(union iucv_param));
759 parm->ctrl.ippathid = path->pathid;
760 parm->ctrl.ipmsglim = path->msglim;
761 if (userdata)
762 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
763 parm->ctrl.ipflags1 = path->flags;
764
765 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
766 if (!rc) {
767 path->private = private;
768 path->msglim = parm->ctrl.ipmsglim;
769 path->flags = parm->ctrl.ipflags1;
770 }
771 local_bh_enable();
772 return rc;
773}
Heiko Carstensda99f052007-05-04 12:23:27 -0700774EXPORT_SYMBOL(iucv_path_accept);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800775
776/**
777 * iucv_path_connect
778 * @path: address of iucv path structure
779 * @handler: address of iucv handler structure
780 * @userid: 8-byte user identification
781 * @system: 8-byte target system identification
782 * @userdata: 16 bytes of data reflected to the communication partner
783 * @private: private data passed to interrupt handlers for this path
784 *
785 * This function establishes an IUCV path. Although the connect may complete
786 * successfully, you are not able to use the path until you receive an IUCV
787 * Connection Complete external interrupt.
788 *
789 * Returns the result of the CP IUCV call.
790 */
791int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
792 u8 userid[8], u8 system[8], u8 userdata[16],
793 void *private)
794{
795 union iucv_param *parm;
796 int rc;
797
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700798 BUG_ON(in_atomic());
799 spin_lock_bh(&iucv_table_lock);
800 iucv_cleanup_queue();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100801 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800802 memset(parm, 0, sizeof(union iucv_param));
803 parm->ctrl.ipmsglim = path->msglim;
804 parm->ctrl.ipflags1 = path->flags;
805 if (userid) {
806 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
807 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
808 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
809 }
810 if (system) {
811 memcpy(parm->ctrl.iptarget, system,
812 sizeof(parm->ctrl.iptarget));
813 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
814 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
815 }
816 if (userdata)
817 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
818
819 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
820 if (!rc) {
821 if (parm->ctrl.ippathid < iucv_max_pathid) {
822 path->pathid = parm->ctrl.ippathid;
823 path->msglim = parm->ctrl.ipmsglim;
824 path->flags = parm->ctrl.ipflags1;
825 path->handler = handler;
826 path->private = private;
827 list_add_tail(&path->list, &handler->paths);
828 iucv_path_table[path->pathid] = path;
829 } else {
830 iucv_sever_pathid(parm->ctrl.ippathid,
831 iucv_error_pathid);
832 rc = -EIO;
833 }
834 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700835 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800836 return rc;
837}
Heiko Carstensda99f052007-05-04 12:23:27 -0700838EXPORT_SYMBOL(iucv_path_connect);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800839
840/**
841 * iucv_path_quiesce:
842 * @path: address of iucv path structure
843 * @userdata: 16 bytes of data reflected to the communication partner
844 *
845 * This function temporarily suspends incoming messages on an IUCV path.
846 * You can later reactivate the path by invoking the iucv_resume function.
847 *
848 * Returns the result from the CP IUCV call.
849 */
850int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
851{
852 union iucv_param *parm;
853 int rc;
854
855 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100856 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800857 memset(parm, 0, sizeof(union iucv_param));
858 if (userdata)
859 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
860 parm->ctrl.ippathid = path->pathid;
861 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
862 local_bh_enable();
863 return rc;
864}
Heiko Carstensda99f052007-05-04 12:23:27 -0700865EXPORT_SYMBOL(iucv_path_quiesce);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800866
867/**
868 * iucv_path_resume:
869 * @path: address of iucv path structure
870 * @userdata: 16 bytes of data reflected to the communication partner
871 *
872 * This function resumes incoming messages on an IUCV path that has
873 * been stopped with iucv_path_quiesce.
874 *
875 * Returns the result from the CP IUCV call.
876 */
877int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
878{
879 union iucv_param *parm;
880 int rc;
881
882 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100883 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800884 memset(parm, 0, sizeof(union iucv_param));
885 if (userdata)
886 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
887 parm->ctrl.ippathid = path->pathid;
888 rc = iucv_call_b2f0(IUCV_RESUME, parm);
889 local_bh_enable();
890 return rc;
891}
892
893/**
894 * iucv_path_sever
895 * @path: address of iucv path structure
896 * @userdata: 16 bytes of data reflected to the communication partner
897 *
898 * This function terminates an IUCV path.
899 *
900 * Returns the result from the CP IUCV call.
901 */
902int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
903{
904 int rc;
905
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800906 preempt_disable();
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700907 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800908 spin_lock_bh(&iucv_table_lock);
909 rc = iucv_sever_pathid(path->pathid, userdata);
910 if (!rc) {
911 iucv_path_table[path->pathid] = NULL;
912 list_del_init(&path->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800913 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700914 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800915 spin_unlock_bh(&iucv_table_lock);
916 preempt_enable();
917 return rc;
918}
Heiko Carstensda99f052007-05-04 12:23:27 -0700919EXPORT_SYMBOL(iucv_path_sever);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800920
921/**
922 * iucv_message_purge
923 * @path: address of iucv path structure
924 * @msg: address of iucv msg structure
925 * @srccls: source class of message
926 *
927 * Cancels a message you have sent.
928 *
929 * Returns the result from the CP IUCV call.
930 */
931int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
932 u32 srccls)
933{
934 union iucv_param *parm;
935 int rc;
936
937 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100938 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800939 memset(parm, 0, sizeof(union iucv_param));
940 parm->purge.ippathid = path->pathid;
941 parm->purge.ipmsgid = msg->id;
942 parm->purge.ipsrccls = srccls;
943 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
944 rc = iucv_call_b2f0(IUCV_PURGE, parm);
945 if (!rc) {
946 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
947 msg->tag = parm->purge.ipmsgtag;
948 }
949 local_bh_enable();
950 return rc;
951}
Heiko Carstensda99f052007-05-04 12:23:27 -0700952EXPORT_SYMBOL(iucv_message_purge);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800953
954/**
955 * iucv_message_receive
956 * @path: address of iucv path structure
957 * @msg: address of iucv msg structure
958 * @flags: how the message is received (IUCV_IPBUFLST)
959 * @buffer: address of data buffer or address of struct iucv_array
960 * @size: length of data buffer
961 * @residual:
962 *
963 * This function receives messages that are being sent to you over
964 * established paths. This function will deal with RMDATA messages
965 * embedded in struct iucv_message as well.
966 *
967 * Returns the result from the CP IUCV call.
968 */
969int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
970 u8 flags, void *buffer, size_t size, size_t *residual)
971{
972 union iucv_param *parm;
973 struct iucv_array *array;
974 u8 *rmmsg;
975 size_t copy;
976 int rc;
977
978 if (msg->flags & IUCV_IPRMDATA) {
979 /*
980 * Message is 8 bytes long and has been stored to the
981 * message descriptor itself.
982 */
983 rc = (size < 8) ? 5 : 0;
984 if (residual)
985 *residual = abs(size - 8);
986 rmmsg = msg->rmmsg;
987 if (flags & IUCV_IPBUFLST) {
988 /* Copy to struct iucv_array. */
989 size = (size < 8) ? size : 8;
990 for (array = buffer; size > 0; array++) {
991 copy = min_t(size_t, size, array->length);
992 memcpy((u8 *)(addr_t) array->address,
993 rmmsg, copy);
994 rmmsg += copy;
995 size -= copy;
996 }
997 } else {
998 /* Copy to direct buffer. */
999 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1000 }
1001 return 0;
1002 }
1003
1004 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001005 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001006 memset(parm, 0, sizeof(union iucv_param));
1007 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1008 parm->db.ipbfln1f = (u32) size;
1009 parm->db.ipmsgid = msg->id;
1010 parm->db.ippathid = path->pathid;
1011 parm->db.iptrgcls = msg->class;
1012 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1013 IUCV_IPFGMID | IUCV_IPTRGCLS);
1014 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1015 if (!rc || rc == 5) {
1016 msg->flags = parm->db.ipflags1;
1017 if (residual)
1018 *residual = parm->db.ipbfln1f;
1019 }
1020 local_bh_enable();
1021 return rc;
1022}
Heiko Carstensda99f052007-05-04 12:23:27 -07001023EXPORT_SYMBOL(iucv_message_receive);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001024
1025/**
1026 * iucv_message_reject
1027 * @path: address of iucv path structure
1028 * @msg: address of iucv msg structure
1029 *
1030 * The reject function refuses a specified message. Between the time you
1031 * are notified of a message and the time that you complete the message,
1032 * the message may be rejected.
1033 *
1034 * Returns the result from the CP IUCV call.
1035 */
1036int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1037{
1038 union iucv_param *parm;
1039 int rc;
1040
1041 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001042 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001043 memset(parm, 0, sizeof(union iucv_param));
1044 parm->db.ippathid = path->pathid;
1045 parm->db.ipmsgid = msg->id;
1046 parm->db.iptrgcls = msg->class;
1047 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1048 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1049 local_bh_enable();
1050 return rc;
1051}
Heiko Carstensda99f052007-05-04 12:23:27 -07001052EXPORT_SYMBOL(iucv_message_reject);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001053
1054/**
1055 * iucv_message_reply
1056 * @path: address of iucv path structure
1057 * @msg: address of iucv msg structure
1058 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1059 * @reply: address of reply data buffer or address of struct iucv_array
1060 * @size: length of reply data buffer
1061 *
1062 * This function responds to the two-way messages that you receive. You
1063 * must identify completely the message to which you wish to reply. ie,
1064 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1065 * the parameter list.
1066 *
1067 * Returns the result from the CP IUCV call.
1068 */
1069int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1070 u8 flags, void *reply, size_t size)
1071{
1072 union iucv_param *parm;
1073 int rc;
1074
1075 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001076 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001077 memset(parm, 0, sizeof(union iucv_param));
1078 if (flags & IUCV_IPRMDATA) {
1079 parm->dpl.ippathid = path->pathid;
1080 parm->dpl.ipflags1 = flags;
1081 parm->dpl.ipmsgid = msg->id;
1082 parm->dpl.iptrgcls = msg->class;
1083 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1084 } else {
1085 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1086 parm->db.ipbfln1f = (u32) size;
1087 parm->db.ippathid = path->pathid;
1088 parm->db.ipflags1 = flags;
1089 parm->db.ipmsgid = msg->id;
1090 parm->db.iptrgcls = msg->class;
1091 }
1092 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1093 local_bh_enable();
1094 return rc;
1095}
Heiko Carstensda99f052007-05-04 12:23:27 -07001096EXPORT_SYMBOL(iucv_message_reply);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001097
1098/**
1099 * iucv_message_send
1100 * @path: address of iucv path structure
1101 * @msg: address of iucv msg structure
1102 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1103 * @srccls: source class of message
1104 * @buffer: address of send buffer or address of struct iucv_array
1105 * @size: length of send buffer
1106 *
1107 * This function transmits data to another application. Data to be
1108 * transmitted is in a buffer and this is a one-way message and the
1109 * receiver will not reply to the message.
1110 *
1111 * Returns the result from the CP IUCV call.
1112 */
1113int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1114 u8 flags, u32 srccls, void *buffer, size_t size)
1115{
1116 union iucv_param *parm;
1117 int rc;
1118
1119 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001120 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001121 memset(parm, 0, sizeof(union iucv_param));
1122 if (flags & IUCV_IPRMDATA) {
1123 /* Message of 8 bytes can be placed into the parameter list. */
1124 parm->dpl.ippathid = path->pathid;
1125 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1126 parm->dpl.iptrgcls = msg->class;
1127 parm->dpl.ipsrccls = srccls;
1128 parm->dpl.ipmsgtag = msg->tag;
1129 memcpy(parm->dpl.iprmmsg, buffer, 8);
1130 } else {
1131 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1132 parm->db.ipbfln1f = (u32) size;
1133 parm->db.ippathid = path->pathid;
1134 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1135 parm->db.iptrgcls = msg->class;
1136 parm->db.ipsrccls = srccls;
1137 parm->db.ipmsgtag = msg->tag;
1138 }
1139 rc = iucv_call_b2f0(IUCV_SEND, parm);
1140 if (!rc)
1141 msg->id = parm->db.ipmsgid;
1142 local_bh_enable();
1143 return rc;
1144}
Heiko Carstensda99f052007-05-04 12:23:27 -07001145EXPORT_SYMBOL(iucv_message_send);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001146
1147/**
1148 * iucv_message_send2way
1149 * @path: address of iucv path structure
1150 * @msg: address of iucv msg structure
1151 * @flags: how the message is sent and the reply is received
1152 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1153 * @srccls: source class of message
1154 * @buffer: address of send buffer or address of struct iucv_array
1155 * @size: length of send buffer
1156 * @ansbuf: address of answer buffer or address of struct iucv_array
1157 * @asize: size of reply buffer
1158 *
1159 * This function transmits data to another application. Data to be
1160 * transmitted is in a buffer. The receiver of the send is expected to
1161 * reply to the message and a buffer is provided into which IUCV moves
1162 * the reply to this message.
1163 *
1164 * Returns the result from the CP IUCV call.
1165 */
1166int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1167 u8 flags, u32 srccls, void *buffer, size_t size,
1168 void *answer, size_t asize, size_t *residual)
1169{
1170 union iucv_param *parm;
1171 int rc;
1172
1173 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001174 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001175 memset(parm, 0, sizeof(union iucv_param));
1176 if (flags & IUCV_IPRMDATA) {
1177 parm->dpl.ippathid = path->pathid;
1178 parm->dpl.ipflags1 = path->flags; /* priority message */
1179 parm->dpl.iptrgcls = msg->class;
1180 parm->dpl.ipsrccls = srccls;
1181 parm->dpl.ipmsgtag = msg->tag;
1182 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1183 parm->dpl.ipbfln2f = (u32) asize;
1184 memcpy(parm->dpl.iprmmsg, buffer, 8);
1185 } else {
1186 parm->db.ippathid = path->pathid;
1187 parm->db.ipflags1 = path->flags; /* priority message */
1188 parm->db.iptrgcls = msg->class;
1189 parm->db.ipsrccls = srccls;
1190 parm->db.ipmsgtag = msg->tag;
1191 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1192 parm->db.ipbfln1f = (u32) size;
1193 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1194 parm->db.ipbfln2f = (u32) asize;
1195 }
1196 rc = iucv_call_b2f0(IUCV_SEND, parm);
1197 if (!rc)
1198 msg->id = parm->db.ipmsgid;
1199 local_bh_enable();
1200 return rc;
1201}
Heiko Carstensda99f052007-05-04 12:23:27 -07001202EXPORT_SYMBOL(iucv_message_send2way);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001203
1204/**
1205 * iucv_path_pending
1206 * @data: Pointer to external interrupt buffer
1207 *
1208 * Process connection pending work item. Called from tasklet while holding
1209 * iucv_table_lock.
1210 */
1211struct iucv_path_pending {
1212 u16 ippathid;
1213 u8 ipflags1;
1214 u8 iptype;
1215 u16 ipmsglim;
1216 u16 res1;
1217 u8 ipvmid[8];
1218 u8 ipuser[16];
1219 u32 res3;
1220 u8 ippollfg;
1221 u8 res4[3];
1222} __attribute__ ((packed));
1223
1224static void iucv_path_pending(struct iucv_irq_data *data)
1225{
1226 struct iucv_path_pending *ipp = (void *) data;
1227 struct iucv_handler *handler;
1228 struct iucv_path *path;
1229 char *error;
1230
1231 BUG_ON(iucv_path_table[ipp->ippathid]);
1232 /* New pathid, handler found. Create a new path struct. */
1233 error = iucv_error_no_memory;
1234 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1235 if (!path)
1236 goto out_sever;
1237 path->pathid = ipp->ippathid;
1238 iucv_path_table[path->pathid] = path;
1239 EBCASC(ipp->ipvmid, 8);
1240
1241 /* Call registered handler until one is found that wants the path. */
1242 list_for_each_entry(handler, &iucv_handler_list, list) {
1243 if (!handler->path_pending)
1244 continue;
1245 /*
1246 * Add path to handler to allow a call to iucv_path_sever
1247 * inside the path_pending function. If the handler returns
1248 * an error remove the path from the handler again.
1249 */
1250 list_add(&path->list, &handler->paths);
1251 path->handler = handler;
1252 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1253 return;
1254 list_del(&path->list);
1255 path->handler = NULL;
1256 }
1257 /* No handler wanted the path. */
1258 iucv_path_table[path->pathid] = NULL;
1259 iucv_path_free(path);
1260 error = iucv_error_no_listener;
1261out_sever:
1262 iucv_sever_pathid(ipp->ippathid, error);
1263}
1264
1265/**
1266 * iucv_path_complete
1267 * @data: Pointer to external interrupt buffer
1268 *
1269 * Process connection complete work item. Called from tasklet while holding
1270 * iucv_table_lock.
1271 */
1272struct iucv_path_complete {
1273 u16 ippathid;
1274 u8 ipflags1;
1275 u8 iptype;
1276 u16 ipmsglim;
1277 u16 res1;
1278 u8 res2[8];
1279 u8 ipuser[16];
1280 u32 res3;
1281 u8 ippollfg;
1282 u8 res4[3];
1283} __attribute__ ((packed));
1284
1285static void iucv_path_complete(struct iucv_irq_data *data)
1286{
1287 struct iucv_path_complete *ipc = (void *) data;
1288 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1289
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001290 if (path && path->handler && path->handler->path_complete)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001291 path->handler->path_complete(path, ipc->ipuser);
1292}
1293
1294/**
1295 * iucv_path_severed
1296 * @data: Pointer to external interrupt buffer
1297 *
1298 * Process connection severed work item. Called from tasklet while holding
1299 * iucv_table_lock.
1300 */
1301struct iucv_path_severed {
1302 u16 ippathid;
1303 u8 res1;
1304 u8 iptype;
1305 u32 res2;
1306 u8 res3[8];
1307 u8 ipuser[16];
1308 u32 res4;
1309 u8 ippollfg;
1310 u8 res5[3];
1311} __attribute__ ((packed));
1312
1313static void iucv_path_severed(struct iucv_irq_data *data)
1314{
1315 struct iucv_path_severed *ips = (void *) data;
1316 struct iucv_path *path = iucv_path_table[ips->ippathid];
1317
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001318 if (!path || !path->handler) /* Already severed */
1319 return;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001320 if (path->handler->path_severed)
1321 path->handler->path_severed(path, ips->ipuser);
1322 else {
1323 iucv_sever_pathid(path->pathid, NULL);
1324 iucv_path_table[path->pathid] = NULL;
1325 list_del_init(&path->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001326 iucv_path_free(path);
1327 }
1328}
1329
1330/**
1331 * iucv_path_quiesced
1332 * @data: Pointer to external interrupt buffer
1333 *
1334 * Process connection quiesced work item. Called from tasklet while holding
1335 * iucv_table_lock.
1336 */
1337struct iucv_path_quiesced {
1338 u16 ippathid;
1339 u8 res1;
1340 u8 iptype;
1341 u32 res2;
1342 u8 res3[8];
1343 u8 ipuser[16];
1344 u32 res4;
1345 u8 ippollfg;
1346 u8 res5[3];
1347} __attribute__ ((packed));
1348
1349static void iucv_path_quiesced(struct iucv_irq_data *data)
1350{
1351 struct iucv_path_quiesced *ipq = (void *) data;
1352 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1353
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001354 if (path && path->handler && path->handler->path_quiesced)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001355 path->handler->path_quiesced(path, ipq->ipuser);
1356}
1357
1358/**
1359 * iucv_path_resumed
1360 * @data: Pointer to external interrupt buffer
1361 *
1362 * Process connection resumed work item. Called from tasklet while holding
1363 * iucv_table_lock.
1364 */
1365struct iucv_path_resumed {
1366 u16 ippathid;
1367 u8 res1;
1368 u8 iptype;
1369 u32 res2;
1370 u8 res3[8];
1371 u8 ipuser[16];
1372 u32 res4;
1373 u8 ippollfg;
1374 u8 res5[3];
1375} __attribute__ ((packed));
1376
1377static void iucv_path_resumed(struct iucv_irq_data *data)
1378{
1379 struct iucv_path_resumed *ipr = (void *) data;
1380 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1381
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001382 if (path && path->handler && path->handler->path_resumed)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001383 path->handler->path_resumed(path, ipr->ipuser);
1384}
1385
1386/**
1387 * iucv_message_complete
1388 * @data: Pointer to external interrupt buffer
1389 *
1390 * Process message complete work item. Called from tasklet while holding
1391 * iucv_table_lock.
1392 */
1393struct iucv_message_complete {
1394 u16 ippathid;
1395 u8 ipflags1;
1396 u8 iptype;
1397 u32 ipmsgid;
1398 u32 ipaudit;
1399 u8 iprmmsg[8];
1400 u32 ipsrccls;
1401 u32 ipmsgtag;
1402 u32 res;
1403 u32 ipbfln2f;
1404 u8 ippollfg;
1405 u8 res2[3];
1406} __attribute__ ((packed));
1407
1408static void iucv_message_complete(struct iucv_irq_data *data)
1409{
1410 struct iucv_message_complete *imc = (void *) data;
1411 struct iucv_path *path = iucv_path_table[imc->ippathid];
1412 struct iucv_message msg;
1413
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001414 if (path && path->handler && path->handler->message_complete) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001415 msg.flags = imc->ipflags1;
1416 msg.id = imc->ipmsgid;
1417 msg.audit = imc->ipaudit;
1418 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1419 msg.class = imc->ipsrccls;
1420 msg.tag = imc->ipmsgtag;
1421 msg.length = imc->ipbfln2f;
1422 path->handler->message_complete(path, &msg);
1423 }
1424}
1425
1426/**
1427 * iucv_message_pending
1428 * @data: Pointer to external interrupt buffer
1429 *
1430 * Process message pending work item. Called from tasklet while holding
1431 * iucv_table_lock.
1432 */
1433struct iucv_message_pending {
1434 u16 ippathid;
1435 u8 ipflags1;
1436 u8 iptype;
1437 u32 ipmsgid;
1438 u32 iptrgcls;
1439 union {
1440 u32 iprmmsg1_u32;
1441 u8 iprmmsg1[4];
1442 } ln1msg1;
1443 union {
1444 u32 ipbfln1f;
1445 u8 iprmmsg2[4];
1446 } ln1msg2;
1447 u32 res1[3];
1448 u32 ipbfln2f;
1449 u8 ippollfg;
1450 u8 res2[3];
1451} __attribute__ ((packed));
1452
1453static void iucv_message_pending(struct iucv_irq_data *data)
1454{
1455 struct iucv_message_pending *imp = (void *) data;
1456 struct iucv_path *path = iucv_path_table[imp->ippathid];
1457 struct iucv_message msg;
1458
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001459 if (path && path->handler && path->handler->message_pending) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001460 msg.flags = imp->ipflags1;
1461 msg.id = imp->ipmsgid;
1462 msg.class = imp->iptrgcls;
1463 if (imp->ipflags1 & IUCV_IPRMDATA) {
1464 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1465 msg.length = 8;
1466 } else
1467 msg.length = imp->ln1msg2.ipbfln1f;
1468 msg.reply_size = imp->ipbfln2f;
1469 path->handler->message_pending(path, &msg);
1470 }
1471}
1472
1473/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001474 * iucv_tasklet_fn:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001475 *
1476 * This tasklet loops over the queue of irq buffers created by
1477 * iucv_external_interrupt, calls the appropriate action handler
1478 * and then frees the buffer.
1479 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001480static void iucv_tasklet_fn(unsigned long ignored)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001481{
1482 typedef void iucv_irq_fn(struct iucv_irq_data *);
1483 static iucv_irq_fn *irq_fn[] = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001484 [0x02] = iucv_path_complete,
1485 [0x03] = iucv_path_severed,
1486 [0x04] = iucv_path_quiesced,
1487 [0x05] = iucv_path_resumed,
1488 [0x06] = iucv_message_complete,
1489 [0x07] = iucv_message_complete,
1490 [0x08] = iucv_message_pending,
1491 [0x09] = iucv_message_pending,
1492 };
Denis Chengb5e78332007-12-07 00:51:45 -08001493 LIST_HEAD(task_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001494 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001495
1496 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
Ursula Braun13fdc9a2007-07-14 19:03:41 -07001497 if (!spin_trylock(&iucv_table_lock)) {
1498 tasklet_schedule(&iucv_tasklet);
1499 return;
1500 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001501 iucv_active_cpu = smp_processor_id();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001502
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001503 spin_lock_irq(&iucv_queue_lock);
1504 list_splice_init(&iucv_task_queue, &task_queue);
1505 spin_unlock_irq(&iucv_queue_lock);
1506
1507 list_for_each_entry_safe(p, n, &task_queue, list) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001508 list_del_init(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001509 irq_fn[p->data.iptype](&p->data);
1510 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001511 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001512
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001513 iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001514 spin_unlock(&iucv_table_lock);
1515}
1516
1517/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001518 * iucv_work_fn:
1519 *
1520 * This work function loops over the queue of path pending irq blocks
1521 * created by iucv_external_interrupt, calls the appropriate action
1522 * handler and then frees the buffer.
1523 */
1524static void iucv_work_fn(struct work_struct *work)
1525{
1526 typedef void iucv_irq_fn(struct iucv_irq_data *);
Denis Chengb5e78332007-12-07 00:51:45 -08001527 LIST_HEAD(work_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001528 struct iucv_irq_list *p, *n;
1529
1530 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1531 spin_lock_bh(&iucv_table_lock);
1532 iucv_active_cpu = smp_processor_id();
1533
1534 spin_lock_irq(&iucv_queue_lock);
1535 list_splice_init(&iucv_work_queue, &work_queue);
1536 spin_unlock_irq(&iucv_queue_lock);
1537
1538 iucv_cleanup_queue();
1539 list_for_each_entry_safe(p, n, &work_queue, list) {
1540 list_del_init(&p->list);
1541 iucv_path_pending(&p->data);
1542 kfree(p);
1543 }
1544
1545 iucv_active_cpu = -1;
1546 spin_unlock_bh(&iucv_table_lock);
1547}
1548
1549/**
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001550 * iucv_external_interrupt
1551 * @code: irq code
1552 *
1553 * Handles external interrupts coming in from CP.
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001554 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001555 */
1556static void iucv_external_interrupt(u16 code)
1557{
1558 struct iucv_irq_data *p;
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001559 struct iucv_irq_list *work;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001560
Christoph Lameter70cf50352007-11-20 11:13:38 +01001561 p = iucv_irq_data[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001562 if (p->ippathid >= iucv_max_pathid) {
1563 printk(KERN_WARNING "iucv_do_int: Got interrupt with "
1564 "pathid %d > max_connections (%ld)\n",
1565 p->ippathid, iucv_max_pathid - 1);
1566 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1567 return;
1568 }
1569 if (p->iptype < 0x01 || p->iptype > 0x09) {
1570 printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
1571 return;
1572 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001573 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001574 if (!work) {
1575 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1576 return;
1577 }
1578 memcpy(&work->data, p, sizeof(work->data));
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001579 spin_lock(&iucv_queue_lock);
1580 if (p->iptype == 0x01) {
1581 /* Path pending interrupt. */
1582 list_add_tail(&work->list, &iucv_work_queue);
1583 schedule_work(&iucv_work);
1584 } else {
1585 /* The other interrupts. */
1586 list_add_tail(&work->list, &iucv_task_queue);
1587 tasklet_schedule(&iucv_tasklet);
1588 }
1589 spin_unlock(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001590}
1591
1592/**
1593 * iucv_init
1594 *
1595 * Allocates and initializes various data structures.
1596 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001597static int __init iucv_init(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001598{
1599 int rc;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001600 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001601
1602 if (!MACHINE_IS_VM) {
1603 rc = -EPROTONOSUPPORT;
1604 goto out;
1605 }
1606 rc = iucv_query_maxconn();
1607 if (rc)
1608 goto out;
Heiko Carstensda99f052007-05-04 12:23:27 -07001609 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001610 if (rc)
1611 goto out;
1612 rc = bus_register(&iucv_bus);
1613 if (rc)
1614 goto out_int;
1615 iucv_root = s390_root_dev_register("iucv");
1616 if (IS_ERR(iucv_root)) {
1617 rc = PTR_ERR(iucv_root);
1618 goto out_bus;
1619 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001620
1621 for_each_online_cpu(cpu) {
1622 /* Note: GFP_DMA used to get memory below 2G */
1623 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1624 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1625 if (!iucv_irq_data[cpu]) {
1626 rc = -ENOMEM;
1627 goto out_free;
1628 }
1629
1630 /* Allocate parameter blocks. */
1631 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1632 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1633 if (!iucv_param[cpu]) {
1634 rc = -ENOMEM;
1635 goto out_free;
1636 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001637 }
1638 register_hotcpu_notifier(&iucv_cpu_notifier);
1639 ASCEBC(iucv_error_no_listener, 16);
1640 ASCEBC(iucv_error_no_memory, 16);
1641 ASCEBC(iucv_error_pathid, 16);
1642 iucv_available = 1;
1643 return 0;
1644
Christoph Lameter70cf50352007-11-20 11:13:38 +01001645out_free:
1646 for_each_possible_cpu(cpu) {
1647 kfree(iucv_param[cpu]);
1648 iucv_param[cpu] = NULL;
1649 kfree(iucv_irq_data[cpu]);
1650 iucv_irq_data[cpu] = NULL;
1651 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001652 s390_root_dev_unregister(iucv_root);
1653out_bus:
1654 bus_unregister(&iucv_bus);
1655out_int:
1656 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1657out:
1658 return rc;
1659}
1660
1661/**
1662 * iucv_exit
1663 *
1664 * Frees everything allocated from iucv_init.
1665 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001666static void __exit iucv_exit(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001667{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001668 struct iucv_irq_list *p, *n;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001669 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001670
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001671 spin_lock_irq(&iucv_queue_lock);
1672 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1673 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001674 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1675 kfree(p);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001676 spin_unlock_irq(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001677 unregister_hotcpu_notifier(&iucv_cpu_notifier);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001678 for_each_possible_cpu(cpu) {
1679 kfree(iucv_param[cpu]);
1680 iucv_param[cpu] = NULL;
1681 kfree(iucv_irq_data[cpu]);
1682 iucv_irq_data[cpu] = NULL;
1683 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001684 s390_root_dev_unregister(iucv_root);
1685 bus_unregister(&iucv_bus);
1686 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1687}
1688
1689subsys_initcall(iucv_init);
1690module_exit(iucv_exit);
1691
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001692MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1693MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1694MODULE_LICENSE("GPL");