blob: 032f61e985951bc85e1825a1e42529e660406713 [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
Ursula Braun8f7c5022008-12-25 13:39:47 +010033#define KMSG_COMPONENT "iucv"
34#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
35
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080036#include <linux/module.h>
37#include <linux/moduleparam.h>
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080038#include <linux/spinlock.h>
39#include <linux/kernel.h>
40#include <linux/slab.h>
41#include <linux/init.h>
42#include <linux/interrupt.h>
43#include <linux/list.h>
44#include <linux/errno.h>
45#include <linux/err.h>
46#include <linux/device.h>
47#include <linux/cpu.h>
48#include <net/iucv/iucv.h>
49#include <asm/atomic.h>
50#include <asm/ebcdic.h>
51#include <asm/io.h>
52#include <asm/s390_ext.h>
53#include <asm/s390_rdev.h>
54#include <asm/smp.h>
55
56/*
57 * FLAGS:
58 * All flags are defined in the field IPFLAGS1 of each function
59 * and can be found in CP Programming Services.
60 * IPSRCCLS - Indicates you have specified a source class.
61 * IPTRGCLS - Indicates you have specified a target class.
62 * IPFGPID - Indicates you have specified a pathid.
63 * IPFGMID - Indicates you have specified a message ID.
64 * IPNORPY - Indicates a one-way message. No reply expected.
65 * IPALL - Indicates that all paths are affected.
66 */
67#define IUCV_IPSRCCLS 0x01
68#define IUCV_IPTRGCLS 0x01
69#define IUCV_IPFGPID 0x02
70#define IUCV_IPFGMID 0x04
71#define IUCV_IPNORPY 0x10
72#define IUCV_IPALL 0x80
73
Heiko Carstensda99f052007-05-04 12:23:27 -070074static int iucv_bus_match(struct device *dev, struct device_driver *drv)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080075{
76 return 0;
77}
78
79struct bus_type iucv_bus = {
80 .name = "iucv",
81 .match = iucv_bus_match,
82};
Heiko Carstensda99f052007-05-04 12:23:27 -070083EXPORT_SYMBOL(iucv_bus);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080084
85struct device *iucv_root;
Heiko Carstensda99f052007-05-04 12:23:27 -070086EXPORT_SYMBOL(iucv_root);
87
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080088static int iucv_available;
89
90/* General IUCV interrupt structure */
91struct iucv_irq_data {
92 u16 ippathid;
93 u8 ipflags1;
94 u8 iptype;
95 u32 res2[8];
96};
97
Martin Schwidefsky04b090d2007-04-28 23:03:59 -070098struct iucv_irq_list {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080099 struct list_head list;
100 struct iucv_irq_data data;
101};
102
Christoph Lameter70cf50352007-11-20 11:13:38 +0100103static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800104static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
105static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
106
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700107/*
108 * Queue of interrupt buffers lock for delivery via the tasklet
109 * (fast but can't call smp_call_function).
110 */
111static LIST_HEAD(iucv_task_queue);
112
113/*
114 * The tasklet for fast delivery of iucv interrupts.
115 */
116static void iucv_tasklet_fn(unsigned long);
117static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
118
119/*
120 * Queue of interrupt buffers for delivery via a work queue
121 * (slower but can call smp_call_function).
122 */
123static LIST_HEAD(iucv_work_queue);
124
125/*
126 * The work element to deliver path pending interrupts.
127 */
128static void iucv_work_fn(struct work_struct *work);
129static DECLARE_WORK(iucv_work, iucv_work_fn);
130
131/*
132 * Spinlock protecting task and work queue.
133 */
134static DEFINE_SPINLOCK(iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800135
136enum iucv_command_codes {
137 IUCV_QUERY = 0,
138 IUCV_RETRIEVE_BUFFER = 2,
139 IUCV_SEND = 4,
140 IUCV_RECEIVE = 5,
141 IUCV_REPLY = 6,
142 IUCV_REJECT = 8,
143 IUCV_PURGE = 9,
144 IUCV_ACCEPT = 10,
145 IUCV_CONNECT = 11,
146 IUCV_DECLARE_BUFFER = 12,
147 IUCV_QUIESCE = 13,
148 IUCV_RESUME = 14,
149 IUCV_SEVER = 15,
150 IUCV_SETMASK = 16,
151};
152
153/*
154 * Error messages that are used with the iucv_sever function. They get
155 * converted to EBCDIC.
156 */
157static char iucv_error_no_listener[16] = "NO LISTENER";
158static char iucv_error_no_memory[16] = "NO MEMORY";
159static char iucv_error_pathid[16] = "INVALID PATHID";
160
161/*
162 * iucv_handler_list: List of registered handlers.
163 */
164static LIST_HEAD(iucv_handler_list);
165
166/*
167 * iucv_path_table: an array of iucv_path structures.
168 */
169static struct iucv_path **iucv_path_table;
170static unsigned long iucv_max_pathid;
171
172/*
173 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
174 */
175static DEFINE_SPINLOCK(iucv_table_lock);
176
177/*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700178 * iucv_active_cpu: contains the number of the cpu executing the tasklet
179 * or the work handler. Needed for iucv_path_sever called from tasklet.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800180 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700181static int iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800182
183/*
184 * Mutex and wait queue for iucv_register/iucv_unregister.
185 */
186static DEFINE_MUTEX(iucv_register_mutex);
187
188/*
189 * Counter for number of non-smp capable handlers.
190 */
191static int iucv_nonsmp_handler;
192
193/*
194 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
195 * iucv_path_quiesce and iucv_path_sever.
196 */
197struct iucv_cmd_control {
198 u16 ippathid;
199 u8 ipflags1;
200 u8 iprcode;
201 u16 ipmsglim;
202 u16 res1;
203 u8 ipvmid[8];
204 u8 ipuser[16];
205 u8 iptarget[8];
206} __attribute__ ((packed,aligned(8)));
207
208/*
209 * Data in parameter list iucv structure. Used by iucv_message_send,
210 * iucv_message_send2way and iucv_message_reply.
211 */
212struct iucv_cmd_dpl {
213 u16 ippathid;
214 u8 ipflags1;
215 u8 iprcode;
216 u32 ipmsgid;
217 u32 iptrgcls;
218 u8 iprmmsg[8];
219 u32 ipsrccls;
220 u32 ipmsgtag;
221 u32 ipbfadr2;
222 u32 ipbfln2f;
223 u32 res;
224} __attribute__ ((packed,aligned(8)));
225
226/*
227 * Data in buffer iucv structure. Used by iucv_message_receive,
228 * iucv_message_reject, iucv_message_send, iucv_message_send2way
229 * and iucv_declare_cpu.
230 */
231struct iucv_cmd_db {
232 u16 ippathid;
233 u8 ipflags1;
234 u8 iprcode;
235 u32 ipmsgid;
236 u32 iptrgcls;
237 u32 ipbfadr1;
238 u32 ipbfln1f;
239 u32 ipsrccls;
240 u32 ipmsgtag;
241 u32 ipbfadr2;
242 u32 ipbfln2f;
243 u32 res;
244} __attribute__ ((packed,aligned(8)));
245
246/*
247 * Purge message iucv structure. Used by iucv_message_purge.
248 */
249struct iucv_cmd_purge {
250 u16 ippathid;
251 u8 ipflags1;
252 u8 iprcode;
253 u32 ipmsgid;
254 u8 ipaudit[3];
255 u8 res1[5];
256 u32 res2;
257 u32 ipsrccls;
258 u32 ipmsgtag;
259 u32 res3[3];
260} __attribute__ ((packed,aligned(8)));
261
262/*
263 * Set mask iucv structure. Used by iucv_enable_cpu.
264 */
265struct iucv_cmd_set_mask {
266 u8 ipmask;
267 u8 res1[2];
268 u8 iprcode;
269 u32 res2[9];
270} __attribute__ ((packed,aligned(8)));
271
272union iucv_param {
273 struct iucv_cmd_control ctrl;
274 struct iucv_cmd_dpl dpl;
275 struct iucv_cmd_db db;
276 struct iucv_cmd_purge purge;
277 struct iucv_cmd_set_mask set_mask;
278};
279
280/*
281 * Anchor for per-cpu IUCV command parameter block.
282 */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100283static union iucv_param *iucv_param[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800284
285/**
286 * iucv_call_b2f0
287 * @code: identifier of IUCV call to CP.
288 * @parm: pointer to a struct iucv_parm block
289 *
290 * Calls CP to execute IUCV commands.
291 *
292 * Returns the result of the CP IUCV call.
293 */
294static inline int iucv_call_b2f0(int command, union iucv_param *parm)
295{
296 register unsigned long reg0 asm ("0");
297 register unsigned long reg1 asm ("1");
298 int ccode;
299
300 reg0 = command;
301 reg1 = virt_to_phys(parm);
302 asm volatile(
303 " .long 0xb2f01000\n"
304 " ipm %0\n"
305 " srl %0,28\n"
306 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
307 : "m" (*parm) : "cc");
308 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
309}
310
311/**
312 * iucv_query_maxconn
313 *
314 * Determines the maximum number of connections that may be established.
315 *
316 * Returns the maximum number of connections or -EPERM is IUCV is not
317 * available.
318 */
319static int iucv_query_maxconn(void)
320{
321 register unsigned long reg0 asm ("0");
322 register unsigned long reg1 asm ("1");
323 void *param;
324 int ccode;
325
326 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
327 if (!param)
328 return -ENOMEM;
329 reg0 = IUCV_QUERY;
330 reg1 = (unsigned long) param;
331 asm volatile (
332 " .long 0xb2f01000\n"
333 " ipm %0\n"
334 " srl %0,28\n"
335 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
336 if (ccode == 0)
337 iucv_max_pathid = reg0;
338 kfree(param);
339 return ccode ? -EPERM : 0;
340}
341
342/**
343 * iucv_allow_cpu
344 * @data: unused
345 *
346 * Allow iucv interrupts on this cpu.
347 */
348static void iucv_allow_cpu(void *data)
349{
350 int cpu = smp_processor_id();
351 union iucv_param *parm;
352
353 /*
354 * Enable all iucv interrupts.
355 * ipmask contains bits for the different interrupts
356 * 0x80 - Flag to allow nonpriority message pending interrupts
357 * 0x40 - Flag to allow priority message pending interrupts
358 * 0x20 - Flag to allow nonpriority message completion interrupts
359 * 0x10 - Flag to allow priority message completion interrupts
360 * 0x08 - Flag to allow IUCV control interrupts
361 */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100362 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800363 memset(parm, 0, sizeof(union iucv_param));
364 parm->set_mask.ipmask = 0xf8;
365 iucv_call_b2f0(IUCV_SETMASK, parm);
366
367 /* Set indication that iucv interrupts are allowed for this cpu. */
368 cpu_set(cpu, iucv_irq_cpumask);
369}
370
371/**
372 * iucv_block_cpu
373 * @data: unused
374 *
375 * Block iucv interrupts on this cpu.
376 */
377static void iucv_block_cpu(void *data)
378{
379 int cpu = smp_processor_id();
380 union iucv_param *parm;
381
382 /* Disable all iucv interrupts. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100383 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800384 memset(parm, 0, sizeof(union iucv_param));
385 iucv_call_b2f0(IUCV_SETMASK, parm);
386
387 /* Clear indication that iucv interrupts are allowed for this cpu. */
388 cpu_clear(cpu, iucv_irq_cpumask);
389}
390
391/**
392 * iucv_declare_cpu
393 * @data: unused
394 *
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200395 * Declare a interrupt buffer on this cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800396 */
397static void iucv_declare_cpu(void *data)
398{
399 int cpu = smp_processor_id();
400 union iucv_param *parm;
401 int rc;
402
403 if (cpu_isset(cpu, iucv_buffer_cpumask))
404 return;
405
406 /* Declare interrupt buffer. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100407 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800408 memset(parm, 0, sizeof(union iucv_param));
Christoph Lameter70cf50352007-11-20 11:13:38 +0100409 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800410 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
411 if (rc) {
412 char *err = "Unknown";
Heiko Carstensda99f052007-05-04 12:23:27 -0700413 switch (rc) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800414 case 0x03:
415 err = "Directory error";
416 break;
417 case 0x0a:
418 err = "Invalid length";
419 break;
420 case 0x13:
421 err = "Buffer already exists";
422 break;
423 case 0x3e:
424 err = "Buffer overlap";
425 break;
426 case 0x5c:
427 err = "Paging or storage error";
428 break;
429 }
Ursula Braun8f7c5022008-12-25 13:39:47 +0100430 pr_warning("Defining an interrupt buffer on CPU %i"
431 " failed with 0x%02x (%s)\n", cpu, rc, err);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800432 return;
433 }
434
435 /* Set indication that an iucv buffer exists for this cpu. */
436 cpu_set(cpu, iucv_buffer_cpumask);
437
438 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
439 /* Enable iucv interrupts on this cpu. */
440 iucv_allow_cpu(NULL);
441 else
442 /* Disable iucv interrupts on this cpu. */
443 iucv_block_cpu(NULL);
444}
445
446/**
447 * iucv_retrieve_cpu
448 * @data: unused
449 *
450 * Retrieve interrupt buffer on this cpu.
451 */
452static void iucv_retrieve_cpu(void *data)
453{
454 int cpu = smp_processor_id();
455 union iucv_param *parm;
456
457 if (!cpu_isset(cpu, iucv_buffer_cpumask))
458 return;
459
460 /* Block iucv interrupts. */
461 iucv_block_cpu(NULL);
462
463 /* Retrieve interrupt buffer. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100464 parm = iucv_param[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800465 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
466
467 /* Clear indication that an iucv buffer exists for this cpu. */
468 cpu_clear(cpu, iucv_buffer_cpumask);
469}
470
471/**
472 * iucv_setmask_smp
473 *
474 * Allow iucv interrupts on all cpus.
475 */
476static void iucv_setmask_mp(void)
477{
478 int cpu;
479
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700480 get_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800481 for_each_online_cpu(cpu)
482 /* Enable all cpus with a declared buffer. */
483 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
484 !cpu_isset(cpu, iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200485 smp_call_function_single(cpu, iucv_allow_cpu,
Jens Axboe8691e5a2008-06-06 11:18:06 +0200486 NULL, 1);
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700487 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800488}
489
490/**
491 * iucv_setmask_up
492 *
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700493 * Allow iucv interrupts on a single cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800494 */
495static void iucv_setmask_up(void)
496{
497 cpumask_t cpumask;
498 int cpu;
499
500 /* Disable all cpu but the first in cpu_irq_cpumask. */
501 cpumask = iucv_irq_cpumask;
502 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
Mike Travis0e12f842008-05-12 21:21:13 +0200503 for_each_cpu_mask_nr(cpu, cpumask)
Jens Axboe8691e5a2008-06-06 11:18:06 +0200504 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800505}
506
507/**
508 * iucv_enable
509 *
510 * This function makes iucv ready for use. It allocates the pathid
511 * table, declares an iucv interrupt buffer and enables the iucv
512 * interrupts. Called when the first user has registered an iucv
513 * handler.
514 */
515static int iucv_enable(void)
516{
517 size_t alloc_size;
518 int cpu, rc;
519
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800520 get_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800521 rc = -ENOMEM;
522 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
523 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
524 if (!iucv_path_table)
525 goto out;
526 /* Declare per cpu buffers. */
527 rc = -EIO;
528 for_each_online_cpu(cpu)
Jens Axboe8691e5a2008-06-06 11:18:06 +0200529 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800530 if (cpus_empty(iucv_buffer_cpumask))
531 /* No cpu could declare an iucv buffer. */
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800532 goto out;
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700533 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800534 return 0;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800535out:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800536 kfree(iucv_path_table);
537 iucv_path_table = NULL;
538 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800539 return rc;
540}
541
542/**
543 * iucv_disable
544 *
545 * This function shuts down iucv. It disables iucv interrupts, retrieves
546 * the iucv interrupt buffer and frees the pathid table. Called after the
547 * last user unregister its iucv handler.
548 */
549static void iucv_disable(void)
550{
Heiko Carstens8b122ef2008-09-30 03:03:35 -0700551 get_online_cpus();
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200552 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800553 kfree(iucv_path_table);
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800554 iucv_path_table = NULL;
555 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800556}
557
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800558static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
559 unsigned long action, void *hcpu)
560{
561 cpumask_t cpumask;
562 long cpu = (long) hcpu;
563
564 switch (action) {
565 case CPU_UP_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700566 case CPU_UP_PREPARE_FROZEN:
Christoph Lameter70cf50352007-11-20 11:13:38 +0100567 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
568 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
569 if (!iucv_irq_data[cpu])
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800570 return NOTIFY_BAD;
Christoph Lameter70cf50352007-11-20 11:13:38 +0100571 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
572 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
Akinobu Mitad0236f82008-07-15 02:09:53 -0700573 if (!iucv_param[cpu]) {
574 kfree(iucv_irq_data[cpu]);
575 iucv_irq_data[cpu] = NULL;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800576 return NOTIFY_BAD;
Akinobu Mitad0236f82008-07-15 02:09:53 -0700577 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800578 break;
579 case CPU_UP_CANCELED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700580 case CPU_UP_CANCELED_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800581 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700582 case CPU_DEAD_FROZEN:
Christoph Lameter70cf50352007-11-20 11:13:38 +0100583 kfree(iucv_param[cpu]);
584 iucv_param[cpu] = NULL;
585 kfree(iucv_irq_data[cpu]);
586 iucv_irq_data[cpu] = NULL;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800587 break;
588 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700589 case CPU_ONLINE_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800590 case CPU_DOWN_FAILED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700591 case CPU_DOWN_FAILED_FROZEN:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800592 if (!iucv_path_table)
593 break;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200594 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800595 break;
596 case CPU_DOWN_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700597 case CPU_DOWN_PREPARE_FROZEN:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800598 if (!iucv_path_table)
599 break;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800600 cpumask = iucv_buffer_cpumask;
601 cpu_clear(cpu, cpumask);
602 if (cpus_empty(cpumask))
603 /* Can't offline last IUCV enabled cpu. */
604 return NOTIFY_BAD;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200605 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800606 if (cpus_empty(iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200607 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
Jens Axboe8691e5a2008-06-06 11:18:06 +0200608 iucv_allow_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800609 break;
610 }
611 return NOTIFY_OK;
612}
613
Heiko Carstensf1494ed2008-06-09 15:49:57 -0700614static struct notifier_block __refdata iucv_cpu_notifier = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800615 .notifier_call = iucv_cpu_notify,
616};
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800617
618/**
619 * iucv_sever_pathid
620 * @pathid: path identification number.
621 * @userdata: 16-bytes of user data.
622 *
623 * Sever an iucv path to free up the pathid. Used internally.
624 */
625static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
626{
627 union iucv_param *parm;
628
Christoph Lameter70cf50352007-11-20 11:13:38 +0100629 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800630 memset(parm, 0, sizeof(union iucv_param));
631 if (userdata)
632 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
633 parm->ctrl.ippathid = pathid;
634 return iucv_call_b2f0(IUCV_SEVER, parm);
635}
636
637/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700638 * __iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800639 * @dummy: unused dummy argument
640 *
641 * Nop function called via smp_call_function to force work items from
642 * pending external iucv interrupts to the work queue.
643 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700644static void __iucv_cleanup_queue(void *dummy)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800645{
646}
647
648/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700649 * iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800650 *
651 * Function called after a path has been severed to find all remaining
652 * work items for the now stale pathid. The caller needs to hold the
653 * iucv_table_lock.
654 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700655static void iucv_cleanup_queue(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800656{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700657 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800658
659 /*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700660 * When a path is severed, the pathid can be reused immediatly
661 * on a iucv connect or a connection pending interrupt. Remove
662 * all entries from the task queue that refer to a stale pathid
663 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
664 * or deliver the connection pending interrupt. To get all the
665 * pending interrupts force them to the work queue by calling
666 * an empty function on all cpus.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800667 */
Jens Axboe8691e5a2008-06-06 11:18:06 +0200668 smp_call_function(__iucv_cleanup_queue, NULL, 1);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700669 spin_lock_irq(&iucv_queue_lock);
670 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
671 /* Remove stale work items from the task queue. */
672 if (iucv_path_table[p->data.ippathid] == NULL) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800673 list_del(&p->list);
674 kfree(p);
675 }
676 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700677 spin_unlock_irq(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800678}
679
680/**
681 * iucv_register:
682 * @handler: address of iucv handler structure
683 * @smp: != 0 indicates that the handler can deal with out of order messages
684 *
685 * Registers a driver with IUCV.
686 *
687 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
688 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
689 */
690int iucv_register(struct iucv_handler *handler, int smp)
691{
692 int rc;
693
694 if (!iucv_available)
695 return -ENOSYS;
696 mutex_lock(&iucv_register_mutex);
697 if (!smp)
698 iucv_nonsmp_handler++;
699 if (list_empty(&iucv_handler_list)) {
700 rc = iucv_enable();
701 if (rc)
702 goto out_mutex;
703 } else if (!smp && iucv_nonsmp_handler == 1)
704 iucv_setmask_up();
705 INIT_LIST_HEAD(&handler->paths);
706
Ursula Braun435bc9d2008-02-07 18:06:52 -0800707 spin_lock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800708 list_add_tail(&handler->list, &iucv_handler_list);
Ursula Braun435bc9d2008-02-07 18:06:52 -0800709 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800710 rc = 0;
711out_mutex:
712 mutex_unlock(&iucv_register_mutex);
713 return rc;
714}
Heiko Carstensda99f052007-05-04 12:23:27 -0700715EXPORT_SYMBOL(iucv_register);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800716
717/**
718 * iucv_unregister
719 * @handler: address of iucv handler structure
720 * @smp: != 0 indicates that the handler can deal with out of order messages
721 *
722 * Unregister driver from IUCV.
723 */
724void iucv_unregister(struct iucv_handler *handler, int smp)
725{
726 struct iucv_path *p, *n;
727
728 mutex_lock(&iucv_register_mutex);
729 spin_lock_bh(&iucv_table_lock);
730 /* Remove handler from the iucv_handler_list. */
731 list_del_init(&handler->list);
732 /* Sever all pathids still refering to the handler. */
733 list_for_each_entry_safe(p, n, &handler->paths, list) {
734 iucv_sever_pathid(p->pathid, NULL);
735 iucv_path_table[p->pathid] = NULL;
736 list_del(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800737 iucv_path_free(p);
738 }
739 spin_unlock_bh(&iucv_table_lock);
740 if (!smp)
741 iucv_nonsmp_handler--;
742 if (list_empty(&iucv_handler_list))
743 iucv_disable();
744 else if (!smp && iucv_nonsmp_handler == 0)
745 iucv_setmask_mp();
746 mutex_unlock(&iucv_register_mutex);
747}
Heiko Carstensda99f052007-05-04 12:23:27 -0700748EXPORT_SYMBOL(iucv_unregister);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800749
750/**
751 * iucv_path_accept
752 * @path: address of iucv path structure
753 * @handler: address of iucv handler structure
754 * @userdata: 16 bytes of data reflected to the communication partner
755 * @private: private data passed to interrupt handlers for this path
756 *
757 * This function is issued after the user received a connection pending
758 * external interrupt and now wishes to complete the IUCV communication path.
759 *
760 * Returns the result of the CP IUCV call.
761 */
762int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
763 u8 userdata[16], void *private)
764{
765 union iucv_param *parm;
766 int rc;
767
768 local_bh_disable();
769 /* Prepare parameter block. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100770 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800771 memset(parm, 0, sizeof(union iucv_param));
772 parm->ctrl.ippathid = path->pathid;
773 parm->ctrl.ipmsglim = path->msglim;
774 if (userdata)
775 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
776 parm->ctrl.ipflags1 = path->flags;
777
778 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
779 if (!rc) {
780 path->private = private;
781 path->msglim = parm->ctrl.ipmsglim;
782 path->flags = parm->ctrl.ipflags1;
783 }
784 local_bh_enable();
785 return rc;
786}
Heiko Carstensda99f052007-05-04 12:23:27 -0700787EXPORT_SYMBOL(iucv_path_accept);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800788
789/**
790 * iucv_path_connect
791 * @path: address of iucv path structure
792 * @handler: address of iucv handler structure
793 * @userid: 8-byte user identification
794 * @system: 8-byte target system identification
795 * @userdata: 16 bytes of data reflected to the communication partner
796 * @private: private data passed to interrupt handlers for this path
797 *
798 * This function establishes an IUCV path. Although the connect may complete
799 * successfully, you are not able to use the path until you receive an IUCV
800 * Connection Complete external interrupt.
801 *
802 * Returns the result of the CP IUCV call.
803 */
804int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
805 u8 userid[8], u8 system[8], u8 userdata[16],
806 void *private)
807{
808 union iucv_param *parm;
809 int rc;
810
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700811 spin_lock_bh(&iucv_table_lock);
812 iucv_cleanup_queue();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100813 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800814 memset(parm, 0, sizeof(union iucv_param));
815 parm->ctrl.ipmsglim = path->msglim;
816 parm->ctrl.ipflags1 = path->flags;
817 if (userid) {
818 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
819 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
820 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
821 }
822 if (system) {
823 memcpy(parm->ctrl.iptarget, system,
824 sizeof(parm->ctrl.iptarget));
825 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
826 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
827 }
828 if (userdata)
829 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
830
831 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
832 if (!rc) {
833 if (parm->ctrl.ippathid < iucv_max_pathid) {
834 path->pathid = parm->ctrl.ippathid;
835 path->msglim = parm->ctrl.ipmsglim;
836 path->flags = parm->ctrl.ipflags1;
837 path->handler = handler;
838 path->private = private;
839 list_add_tail(&path->list, &handler->paths);
840 iucv_path_table[path->pathid] = path;
841 } else {
842 iucv_sever_pathid(parm->ctrl.ippathid,
843 iucv_error_pathid);
844 rc = -EIO;
845 }
846 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700847 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800848 return rc;
849}
Heiko Carstensda99f052007-05-04 12:23:27 -0700850EXPORT_SYMBOL(iucv_path_connect);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800851
852/**
853 * iucv_path_quiesce:
854 * @path: address of iucv path structure
855 * @userdata: 16 bytes of data reflected to the communication partner
856 *
857 * This function temporarily suspends incoming messages on an IUCV path.
858 * You can later reactivate the path by invoking the iucv_resume function.
859 *
860 * Returns the result from the CP IUCV call.
861 */
862int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
863{
864 union iucv_param *parm;
865 int rc;
866
867 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100868 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800869 memset(parm, 0, sizeof(union iucv_param));
870 if (userdata)
871 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
872 parm->ctrl.ippathid = path->pathid;
873 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
874 local_bh_enable();
875 return rc;
876}
Heiko Carstensda99f052007-05-04 12:23:27 -0700877EXPORT_SYMBOL(iucv_path_quiesce);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800878
879/**
880 * iucv_path_resume:
881 * @path: address of iucv path structure
882 * @userdata: 16 bytes of data reflected to the communication partner
883 *
884 * This function resumes incoming messages on an IUCV path that has
885 * been stopped with iucv_path_quiesce.
886 *
887 * Returns the result from the CP IUCV call.
888 */
889int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
890{
891 union iucv_param *parm;
892 int rc;
893
894 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100895 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800896 memset(parm, 0, sizeof(union iucv_param));
897 if (userdata)
898 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
899 parm->ctrl.ippathid = path->pathid;
900 rc = iucv_call_b2f0(IUCV_RESUME, parm);
901 local_bh_enable();
902 return rc;
903}
904
905/**
906 * iucv_path_sever
907 * @path: address of iucv path structure
908 * @userdata: 16 bytes of data reflected to the communication partner
909 *
910 * This function terminates an IUCV path.
911 *
912 * Returns the result from the CP IUCV call.
913 */
914int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
915{
916 int rc;
917
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800918 preempt_disable();
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700919 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800920 spin_lock_bh(&iucv_table_lock);
921 rc = iucv_sever_pathid(path->pathid, userdata);
922 if (!rc) {
923 iucv_path_table[path->pathid] = NULL;
924 list_del_init(&path->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800925 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700926 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800927 spin_unlock_bh(&iucv_table_lock);
928 preempt_enable();
929 return rc;
930}
Heiko Carstensda99f052007-05-04 12:23:27 -0700931EXPORT_SYMBOL(iucv_path_sever);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800932
933/**
934 * iucv_message_purge
935 * @path: address of iucv path structure
936 * @msg: address of iucv msg structure
937 * @srccls: source class of message
938 *
939 * Cancels a message you have sent.
940 *
941 * Returns the result from the CP IUCV call.
942 */
943int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
944 u32 srccls)
945{
946 union iucv_param *parm;
947 int rc;
948
949 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +0100950 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800951 memset(parm, 0, sizeof(union iucv_param));
952 parm->purge.ippathid = path->pathid;
953 parm->purge.ipmsgid = msg->id;
954 parm->purge.ipsrccls = srccls;
955 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
956 rc = iucv_call_b2f0(IUCV_PURGE, parm);
957 if (!rc) {
958 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
959 msg->tag = parm->purge.ipmsgtag;
960 }
961 local_bh_enable();
962 return rc;
963}
Heiko Carstensda99f052007-05-04 12:23:27 -0700964EXPORT_SYMBOL(iucv_message_purge);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800965
966/**
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +0100967 * iucv_message_receive_iprmdata
968 * @path: address of iucv path structure
969 * @msg: address of iucv msg structure
970 * @flags: how the message is received (IUCV_IPBUFLST)
971 * @buffer: address of data buffer or address of struct iucv_array
972 * @size: length of data buffer
973 * @residual:
974 *
975 * Internal function used by iucv_message_receive and __iucv_message_receive
976 * to receive RMDATA data stored in struct iucv_message.
977 */
978static int iucv_message_receive_iprmdata(struct iucv_path *path,
979 struct iucv_message *msg,
980 u8 flags, void *buffer,
981 size_t size, size_t *residual)
982{
983 struct iucv_array *array;
984 u8 *rmmsg;
985 size_t copy;
986
987 /*
988 * Message is 8 bytes long and has been stored to the
989 * message descriptor itself.
990 */
991 if (residual)
992 *residual = abs(size - 8);
993 rmmsg = msg->rmmsg;
994 if (flags & IUCV_IPBUFLST) {
995 /* Copy to struct iucv_array. */
996 size = (size < 8) ? size : 8;
997 for (array = buffer; size > 0; array++) {
998 copy = min_t(size_t, size, array->length);
999 memcpy((u8 *)(addr_t) array->address,
1000 rmmsg, copy);
1001 rmmsg += copy;
1002 size -= copy;
1003 }
1004 } else {
1005 /* Copy to direct buffer. */
1006 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1007 }
1008 return 0;
1009}
1010
1011/**
1012 * __iucv_message_receive
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001013 * @path: address of iucv path structure
1014 * @msg: address of iucv msg structure
1015 * @flags: how the message is received (IUCV_IPBUFLST)
1016 * @buffer: address of data buffer or address of struct iucv_array
1017 * @size: length of data buffer
1018 * @residual:
1019 *
1020 * This function receives messages that are being sent to you over
1021 * established paths. This function will deal with RMDATA messages
1022 * embedded in struct iucv_message as well.
1023 *
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001024 * Locking: no locking
1025 *
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001026 * Returns the result from the CP IUCV call.
1027 */
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001028int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1029 u8 flags, void *buffer, size_t size, size_t *residual)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001030{
1031 union iucv_param *parm;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001032 int rc;
1033
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001034 if (msg->flags & IUCV_IPRMDATA)
1035 return iucv_message_receive_iprmdata(path, msg, flags,
1036 buffer, size, residual);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001037 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001038 memset(parm, 0, sizeof(union iucv_param));
1039 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1040 parm->db.ipbfln1f = (u32) size;
1041 parm->db.ipmsgid = msg->id;
1042 parm->db.ippathid = path->pathid;
1043 parm->db.iptrgcls = msg->class;
1044 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1045 IUCV_IPFGMID | IUCV_IPTRGCLS);
1046 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1047 if (!rc || rc == 5) {
1048 msg->flags = parm->db.ipflags1;
1049 if (residual)
1050 *residual = parm->db.ipbfln1f;
1051 }
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001052 return rc;
1053}
1054EXPORT_SYMBOL(__iucv_message_receive);
1055
1056/**
1057 * iucv_message_receive
1058 * @path: address of iucv path structure
1059 * @msg: address of iucv msg structure
1060 * @flags: how the message is received (IUCV_IPBUFLST)
1061 * @buffer: address of data buffer or address of struct iucv_array
1062 * @size: length of data buffer
1063 * @residual:
1064 *
1065 * This function receives messages that are being sent to you over
1066 * established paths. This function will deal with RMDATA messages
1067 * embedded in struct iucv_message as well.
1068 *
1069 * Locking: local_bh_enable/local_bh_disable
1070 *
1071 * Returns the result from the CP IUCV call.
1072 */
1073int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1074 u8 flags, void *buffer, size_t size, size_t *residual)
1075{
1076 int rc;
1077
1078 if (msg->flags & IUCV_IPRMDATA)
1079 return iucv_message_receive_iprmdata(path, msg, flags,
1080 buffer, size, residual);
1081 local_bh_disable();
1082 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001083 local_bh_enable();
1084 return rc;
1085}
Heiko Carstensda99f052007-05-04 12:23:27 -07001086EXPORT_SYMBOL(iucv_message_receive);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001087
1088/**
1089 * iucv_message_reject
1090 * @path: address of iucv path structure
1091 * @msg: address of iucv msg structure
1092 *
1093 * The reject function refuses a specified message. Between the time you
1094 * are notified of a message and the time that you complete the message,
1095 * the message may be rejected.
1096 *
1097 * Returns the result from the CP IUCV call.
1098 */
1099int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1100{
1101 union iucv_param *parm;
1102 int rc;
1103
1104 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001105 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001106 memset(parm, 0, sizeof(union iucv_param));
1107 parm->db.ippathid = path->pathid;
1108 parm->db.ipmsgid = msg->id;
1109 parm->db.iptrgcls = msg->class;
1110 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1111 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1112 local_bh_enable();
1113 return rc;
1114}
Heiko Carstensda99f052007-05-04 12:23:27 -07001115EXPORT_SYMBOL(iucv_message_reject);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001116
1117/**
1118 * iucv_message_reply
1119 * @path: address of iucv path structure
1120 * @msg: address of iucv msg structure
1121 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1122 * @reply: address of reply data buffer or address of struct iucv_array
1123 * @size: length of reply data buffer
1124 *
1125 * This function responds to the two-way messages that you receive. You
1126 * must identify completely the message to which you wish to reply. ie,
1127 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1128 * the parameter list.
1129 *
1130 * Returns the result from the CP IUCV call.
1131 */
1132int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1133 u8 flags, void *reply, size_t size)
1134{
1135 union iucv_param *parm;
1136 int rc;
1137
1138 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001139 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001140 memset(parm, 0, sizeof(union iucv_param));
1141 if (flags & IUCV_IPRMDATA) {
1142 parm->dpl.ippathid = path->pathid;
1143 parm->dpl.ipflags1 = flags;
1144 parm->dpl.ipmsgid = msg->id;
1145 parm->dpl.iptrgcls = msg->class;
1146 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1147 } else {
1148 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1149 parm->db.ipbfln1f = (u32) size;
1150 parm->db.ippathid = path->pathid;
1151 parm->db.ipflags1 = flags;
1152 parm->db.ipmsgid = msg->id;
1153 parm->db.iptrgcls = msg->class;
1154 }
1155 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1156 local_bh_enable();
1157 return rc;
1158}
Heiko Carstensda99f052007-05-04 12:23:27 -07001159EXPORT_SYMBOL(iucv_message_reply);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001160
1161/**
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001162 * __iucv_message_send
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001163 * @path: address of iucv path structure
1164 * @msg: address of iucv msg structure
1165 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1166 * @srccls: source class of message
1167 * @buffer: address of send buffer or address of struct iucv_array
1168 * @size: length of send buffer
1169 *
1170 * This function transmits data to another application. Data to be
1171 * transmitted is in a buffer and this is a one-way message and the
1172 * receiver will not reply to the message.
1173 *
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001174 * Locking: no locking
1175 *
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001176 * Returns the result from the CP IUCV call.
1177 */
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001178int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001179 u8 flags, u32 srccls, void *buffer, size_t size)
1180{
1181 union iucv_param *parm;
1182 int rc;
1183
Christoph Lameter70cf50352007-11-20 11:13:38 +01001184 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001185 memset(parm, 0, sizeof(union iucv_param));
1186 if (flags & IUCV_IPRMDATA) {
1187 /* Message of 8 bytes can be placed into the parameter list. */
1188 parm->dpl.ippathid = path->pathid;
1189 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1190 parm->dpl.iptrgcls = msg->class;
1191 parm->dpl.ipsrccls = srccls;
1192 parm->dpl.ipmsgtag = msg->tag;
1193 memcpy(parm->dpl.iprmmsg, buffer, 8);
1194 } else {
1195 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1196 parm->db.ipbfln1f = (u32) size;
1197 parm->db.ippathid = path->pathid;
1198 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1199 parm->db.iptrgcls = msg->class;
1200 parm->db.ipsrccls = srccls;
1201 parm->db.ipmsgtag = msg->tag;
1202 }
1203 rc = iucv_call_b2f0(IUCV_SEND, parm);
1204 if (!rc)
1205 msg->id = parm->db.ipmsgid;
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001206 return rc;
1207}
1208EXPORT_SYMBOL(__iucv_message_send);
1209
1210/**
1211 * iucv_message_send
1212 * @path: address of iucv path structure
1213 * @msg: address of iucv msg structure
1214 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1215 * @srccls: source class of message
1216 * @buffer: address of send buffer or address of struct iucv_array
1217 * @size: length of send buffer
1218 *
1219 * This function transmits data to another application. Data to be
1220 * transmitted is in a buffer and this is a one-way message and the
1221 * receiver will not reply to the message.
1222 *
1223 * Locking: local_bh_enable/local_bh_disable
1224 *
1225 * Returns the result from the CP IUCV call.
1226 */
1227int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1228 u8 flags, u32 srccls, void *buffer, size_t size)
1229{
1230 int rc;
1231
1232 local_bh_disable();
1233 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001234 local_bh_enable();
1235 return rc;
1236}
Heiko Carstensda99f052007-05-04 12:23:27 -07001237EXPORT_SYMBOL(iucv_message_send);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001238
1239/**
1240 * iucv_message_send2way
1241 * @path: address of iucv path structure
1242 * @msg: address of iucv msg structure
1243 * @flags: how the message is sent and the reply is received
1244 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1245 * @srccls: source class of message
1246 * @buffer: address of send buffer or address of struct iucv_array
1247 * @size: length of send buffer
1248 * @ansbuf: address of answer buffer or address of struct iucv_array
1249 * @asize: size of reply buffer
1250 *
1251 * This function transmits data to another application. Data to be
1252 * transmitted is in a buffer. The receiver of the send is expected to
1253 * reply to the message and a buffer is provided into which IUCV moves
1254 * the reply to this message.
1255 *
1256 * Returns the result from the CP IUCV call.
1257 */
1258int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1259 u8 flags, u32 srccls, void *buffer, size_t size,
1260 void *answer, size_t asize, size_t *residual)
1261{
1262 union iucv_param *parm;
1263 int rc;
1264
1265 local_bh_disable();
Christoph Lameter70cf50352007-11-20 11:13:38 +01001266 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001267 memset(parm, 0, sizeof(union iucv_param));
1268 if (flags & IUCV_IPRMDATA) {
1269 parm->dpl.ippathid = path->pathid;
1270 parm->dpl.ipflags1 = path->flags; /* priority message */
1271 parm->dpl.iptrgcls = msg->class;
1272 parm->dpl.ipsrccls = srccls;
1273 parm->dpl.ipmsgtag = msg->tag;
1274 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1275 parm->dpl.ipbfln2f = (u32) asize;
1276 memcpy(parm->dpl.iprmmsg, buffer, 8);
1277 } else {
1278 parm->db.ippathid = path->pathid;
1279 parm->db.ipflags1 = path->flags; /* priority message */
1280 parm->db.iptrgcls = msg->class;
1281 parm->db.ipsrccls = srccls;
1282 parm->db.ipmsgtag = msg->tag;
1283 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1284 parm->db.ipbfln1f = (u32) size;
1285 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1286 parm->db.ipbfln2f = (u32) asize;
1287 }
1288 rc = iucv_call_b2f0(IUCV_SEND, parm);
1289 if (!rc)
1290 msg->id = parm->db.ipmsgid;
1291 local_bh_enable();
1292 return rc;
1293}
Heiko Carstensda99f052007-05-04 12:23:27 -07001294EXPORT_SYMBOL(iucv_message_send2way);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001295
1296/**
1297 * iucv_path_pending
1298 * @data: Pointer to external interrupt buffer
1299 *
1300 * Process connection pending work item. Called from tasklet while holding
1301 * iucv_table_lock.
1302 */
1303struct iucv_path_pending {
1304 u16 ippathid;
1305 u8 ipflags1;
1306 u8 iptype;
1307 u16 ipmsglim;
1308 u16 res1;
1309 u8 ipvmid[8];
1310 u8 ipuser[16];
1311 u32 res3;
1312 u8 ippollfg;
1313 u8 res4[3];
1314} __attribute__ ((packed));
1315
1316static void iucv_path_pending(struct iucv_irq_data *data)
1317{
1318 struct iucv_path_pending *ipp = (void *) data;
1319 struct iucv_handler *handler;
1320 struct iucv_path *path;
1321 char *error;
1322
1323 BUG_ON(iucv_path_table[ipp->ippathid]);
1324 /* New pathid, handler found. Create a new path struct. */
1325 error = iucv_error_no_memory;
1326 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1327 if (!path)
1328 goto out_sever;
1329 path->pathid = ipp->ippathid;
1330 iucv_path_table[path->pathid] = path;
1331 EBCASC(ipp->ipvmid, 8);
1332
1333 /* Call registered handler until one is found that wants the path. */
1334 list_for_each_entry(handler, &iucv_handler_list, list) {
1335 if (!handler->path_pending)
1336 continue;
1337 /*
1338 * Add path to handler to allow a call to iucv_path_sever
1339 * inside the path_pending function. If the handler returns
1340 * an error remove the path from the handler again.
1341 */
1342 list_add(&path->list, &handler->paths);
1343 path->handler = handler;
1344 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1345 return;
1346 list_del(&path->list);
1347 path->handler = NULL;
1348 }
1349 /* No handler wanted the path. */
1350 iucv_path_table[path->pathid] = NULL;
1351 iucv_path_free(path);
1352 error = iucv_error_no_listener;
1353out_sever:
1354 iucv_sever_pathid(ipp->ippathid, error);
1355}
1356
1357/**
1358 * iucv_path_complete
1359 * @data: Pointer to external interrupt buffer
1360 *
1361 * Process connection complete work item. Called from tasklet while holding
1362 * iucv_table_lock.
1363 */
1364struct iucv_path_complete {
1365 u16 ippathid;
1366 u8 ipflags1;
1367 u8 iptype;
1368 u16 ipmsglim;
1369 u16 res1;
1370 u8 res2[8];
1371 u8 ipuser[16];
1372 u32 res3;
1373 u8 ippollfg;
1374 u8 res4[3];
1375} __attribute__ ((packed));
1376
1377static void iucv_path_complete(struct iucv_irq_data *data)
1378{
1379 struct iucv_path_complete *ipc = (void *) data;
1380 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1381
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001382 if (path && path->handler && path->handler->path_complete)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001383 path->handler->path_complete(path, ipc->ipuser);
1384}
1385
1386/**
1387 * iucv_path_severed
1388 * @data: Pointer to external interrupt buffer
1389 *
1390 * Process connection severed work item. Called from tasklet while holding
1391 * iucv_table_lock.
1392 */
1393struct iucv_path_severed {
1394 u16 ippathid;
1395 u8 res1;
1396 u8 iptype;
1397 u32 res2;
1398 u8 res3[8];
1399 u8 ipuser[16];
1400 u32 res4;
1401 u8 ippollfg;
1402 u8 res5[3];
1403} __attribute__ ((packed));
1404
1405static void iucv_path_severed(struct iucv_irq_data *data)
1406{
1407 struct iucv_path_severed *ips = (void *) data;
1408 struct iucv_path *path = iucv_path_table[ips->ippathid];
1409
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001410 if (!path || !path->handler) /* Already severed */
1411 return;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001412 if (path->handler->path_severed)
1413 path->handler->path_severed(path, ips->ipuser);
1414 else {
1415 iucv_sever_pathid(path->pathid, NULL);
1416 iucv_path_table[path->pathid] = NULL;
1417 list_del_init(&path->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001418 iucv_path_free(path);
1419 }
1420}
1421
1422/**
1423 * iucv_path_quiesced
1424 * @data: Pointer to external interrupt buffer
1425 *
1426 * Process connection quiesced work item. Called from tasklet while holding
1427 * iucv_table_lock.
1428 */
1429struct iucv_path_quiesced {
1430 u16 ippathid;
1431 u8 res1;
1432 u8 iptype;
1433 u32 res2;
1434 u8 res3[8];
1435 u8 ipuser[16];
1436 u32 res4;
1437 u8 ippollfg;
1438 u8 res5[3];
1439} __attribute__ ((packed));
1440
1441static void iucv_path_quiesced(struct iucv_irq_data *data)
1442{
1443 struct iucv_path_quiesced *ipq = (void *) data;
1444 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1445
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001446 if (path && path->handler && path->handler->path_quiesced)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001447 path->handler->path_quiesced(path, ipq->ipuser);
1448}
1449
1450/**
1451 * iucv_path_resumed
1452 * @data: Pointer to external interrupt buffer
1453 *
1454 * Process connection resumed work item. Called from tasklet while holding
1455 * iucv_table_lock.
1456 */
1457struct iucv_path_resumed {
1458 u16 ippathid;
1459 u8 res1;
1460 u8 iptype;
1461 u32 res2;
1462 u8 res3[8];
1463 u8 ipuser[16];
1464 u32 res4;
1465 u8 ippollfg;
1466 u8 res5[3];
1467} __attribute__ ((packed));
1468
1469static void iucv_path_resumed(struct iucv_irq_data *data)
1470{
1471 struct iucv_path_resumed *ipr = (void *) data;
1472 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1473
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001474 if (path && path->handler && path->handler->path_resumed)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001475 path->handler->path_resumed(path, ipr->ipuser);
1476}
1477
1478/**
1479 * iucv_message_complete
1480 * @data: Pointer to external interrupt buffer
1481 *
1482 * Process message complete work item. Called from tasklet while holding
1483 * iucv_table_lock.
1484 */
1485struct iucv_message_complete {
1486 u16 ippathid;
1487 u8 ipflags1;
1488 u8 iptype;
1489 u32 ipmsgid;
1490 u32 ipaudit;
1491 u8 iprmmsg[8];
1492 u32 ipsrccls;
1493 u32 ipmsgtag;
1494 u32 res;
1495 u32 ipbfln2f;
1496 u8 ippollfg;
1497 u8 res2[3];
1498} __attribute__ ((packed));
1499
1500static void iucv_message_complete(struct iucv_irq_data *data)
1501{
1502 struct iucv_message_complete *imc = (void *) data;
1503 struct iucv_path *path = iucv_path_table[imc->ippathid];
1504 struct iucv_message msg;
1505
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001506 if (path && path->handler && path->handler->message_complete) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001507 msg.flags = imc->ipflags1;
1508 msg.id = imc->ipmsgid;
1509 msg.audit = imc->ipaudit;
1510 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1511 msg.class = imc->ipsrccls;
1512 msg.tag = imc->ipmsgtag;
1513 msg.length = imc->ipbfln2f;
1514 path->handler->message_complete(path, &msg);
1515 }
1516}
1517
1518/**
1519 * iucv_message_pending
1520 * @data: Pointer to external interrupt buffer
1521 *
1522 * Process message pending work item. Called from tasklet while holding
1523 * iucv_table_lock.
1524 */
1525struct iucv_message_pending {
1526 u16 ippathid;
1527 u8 ipflags1;
1528 u8 iptype;
1529 u32 ipmsgid;
1530 u32 iptrgcls;
1531 union {
1532 u32 iprmmsg1_u32;
1533 u8 iprmmsg1[4];
1534 } ln1msg1;
1535 union {
1536 u32 ipbfln1f;
1537 u8 iprmmsg2[4];
1538 } ln1msg2;
1539 u32 res1[3];
1540 u32 ipbfln2f;
1541 u8 ippollfg;
1542 u8 res2[3];
1543} __attribute__ ((packed));
1544
1545static void iucv_message_pending(struct iucv_irq_data *data)
1546{
1547 struct iucv_message_pending *imp = (void *) data;
1548 struct iucv_path *path = iucv_path_table[imp->ippathid];
1549 struct iucv_message msg;
1550
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001551 if (path && path->handler && path->handler->message_pending) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001552 msg.flags = imp->ipflags1;
1553 msg.id = imp->ipmsgid;
1554 msg.class = imp->iptrgcls;
1555 if (imp->ipflags1 & IUCV_IPRMDATA) {
1556 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1557 msg.length = 8;
1558 } else
1559 msg.length = imp->ln1msg2.ipbfln1f;
1560 msg.reply_size = imp->ipbfln2f;
1561 path->handler->message_pending(path, &msg);
1562 }
1563}
1564
1565/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001566 * iucv_tasklet_fn:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001567 *
1568 * This tasklet loops over the queue of irq buffers created by
1569 * iucv_external_interrupt, calls the appropriate action handler
1570 * and then frees the buffer.
1571 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001572static void iucv_tasklet_fn(unsigned long ignored)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001573{
1574 typedef void iucv_irq_fn(struct iucv_irq_data *);
1575 static iucv_irq_fn *irq_fn[] = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001576 [0x02] = iucv_path_complete,
1577 [0x03] = iucv_path_severed,
1578 [0x04] = iucv_path_quiesced,
1579 [0x05] = iucv_path_resumed,
1580 [0x06] = iucv_message_complete,
1581 [0x07] = iucv_message_complete,
1582 [0x08] = iucv_message_pending,
1583 [0x09] = iucv_message_pending,
1584 };
Denis Chengb5e78332007-12-07 00:51:45 -08001585 LIST_HEAD(task_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001586 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001587
1588 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
Ursula Braun13fdc9a2007-07-14 19:03:41 -07001589 if (!spin_trylock(&iucv_table_lock)) {
1590 tasklet_schedule(&iucv_tasklet);
1591 return;
1592 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001593 iucv_active_cpu = smp_processor_id();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001594
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001595 spin_lock_irq(&iucv_queue_lock);
1596 list_splice_init(&iucv_task_queue, &task_queue);
1597 spin_unlock_irq(&iucv_queue_lock);
1598
1599 list_for_each_entry_safe(p, n, &task_queue, list) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001600 list_del_init(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001601 irq_fn[p->data.iptype](&p->data);
1602 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001603 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001604
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001605 iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001606 spin_unlock(&iucv_table_lock);
1607}
1608
1609/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001610 * iucv_work_fn:
1611 *
1612 * This work function loops over the queue of path pending irq blocks
1613 * created by iucv_external_interrupt, calls the appropriate action
1614 * handler and then frees the buffer.
1615 */
1616static void iucv_work_fn(struct work_struct *work)
1617{
1618 typedef void iucv_irq_fn(struct iucv_irq_data *);
Denis Chengb5e78332007-12-07 00:51:45 -08001619 LIST_HEAD(work_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001620 struct iucv_irq_list *p, *n;
1621
1622 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1623 spin_lock_bh(&iucv_table_lock);
1624 iucv_active_cpu = smp_processor_id();
1625
1626 spin_lock_irq(&iucv_queue_lock);
1627 list_splice_init(&iucv_work_queue, &work_queue);
1628 spin_unlock_irq(&iucv_queue_lock);
1629
1630 iucv_cleanup_queue();
1631 list_for_each_entry_safe(p, n, &work_queue, list) {
1632 list_del_init(&p->list);
1633 iucv_path_pending(&p->data);
1634 kfree(p);
1635 }
1636
1637 iucv_active_cpu = -1;
1638 spin_unlock_bh(&iucv_table_lock);
1639}
1640
1641/**
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001642 * iucv_external_interrupt
1643 * @code: irq code
1644 *
1645 * Handles external interrupts coming in from CP.
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001646 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001647 */
1648static void iucv_external_interrupt(u16 code)
1649{
1650 struct iucv_irq_data *p;
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001651 struct iucv_irq_list *work;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001652
Christoph Lameter70cf50352007-11-20 11:13:38 +01001653 p = iucv_irq_data[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001654 if (p->ippathid >= iucv_max_pathid) {
Ursula Braunc2b4afd2008-07-14 09:59:29 +02001655 WARN_ON(p->ippathid >= iucv_max_pathid);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001656 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1657 return;
1658 }
Ursula Braunc2b4afd2008-07-14 09:59:29 +02001659 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001660 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001661 if (!work) {
Ursula Braun8f7c5022008-12-25 13:39:47 +01001662 pr_warning("iucv_external_interrupt: out of memory\n");
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001663 return;
1664 }
1665 memcpy(&work->data, p, sizeof(work->data));
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001666 spin_lock(&iucv_queue_lock);
1667 if (p->iptype == 0x01) {
1668 /* Path pending interrupt. */
1669 list_add_tail(&work->list, &iucv_work_queue);
1670 schedule_work(&iucv_work);
1671 } else {
1672 /* The other interrupts. */
1673 list_add_tail(&work->list, &iucv_task_queue);
1674 tasklet_schedule(&iucv_tasklet);
1675 }
1676 spin_unlock(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001677}
1678
1679/**
1680 * iucv_init
1681 *
1682 * Allocates and initializes various data structures.
1683 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001684static int __init iucv_init(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001685{
1686 int rc;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001687 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001688
1689 if (!MACHINE_IS_VM) {
1690 rc = -EPROTONOSUPPORT;
1691 goto out;
1692 }
1693 rc = iucv_query_maxconn();
1694 if (rc)
1695 goto out;
Heiko Carstensda99f052007-05-04 12:23:27 -07001696 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001697 if (rc)
1698 goto out;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001699 iucv_root = s390_root_dev_register("iucv");
1700 if (IS_ERR(iucv_root)) {
1701 rc = PTR_ERR(iucv_root);
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001702 goto out_int;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001703 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001704
1705 for_each_online_cpu(cpu) {
1706 /* Note: GFP_DMA used to get memory below 2G */
1707 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1708 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1709 if (!iucv_irq_data[cpu]) {
1710 rc = -ENOMEM;
1711 goto out_free;
1712 }
1713
1714 /* Allocate parameter blocks. */
1715 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1716 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1717 if (!iucv_param[cpu]) {
1718 rc = -ENOMEM;
1719 goto out_free;
1720 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001721 }
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001722 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1723 if (rc)
1724 goto out_free;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001725 ASCEBC(iucv_error_no_listener, 16);
1726 ASCEBC(iucv_error_no_memory, 16);
1727 ASCEBC(iucv_error_pathid, 16);
1728 iucv_available = 1;
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001729 rc = bus_register(&iucv_bus);
1730 if (rc)
1731 goto out_cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001732 return 0;
1733
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001734out_cpu:
1735 unregister_hotcpu_notifier(&iucv_cpu_notifier);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001736out_free:
1737 for_each_possible_cpu(cpu) {
1738 kfree(iucv_param[cpu]);
1739 iucv_param[cpu] = NULL;
1740 kfree(iucv_irq_data[cpu]);
1741 iucv_irq_data[cpu] = NULL;
1742 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001743 s390_root_dev_unregister(iucv_root);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001744out_int:
1745 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1746out:
1747 return rc;
1748}
1749
1750/**
1751 * iucv_exit
1752 *
1753 * Frees everything allocated from iucv_init.
1754 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001755static void __exit iucv_exit(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001756{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001757 struct iucv_irq_list *p, *n;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001758 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001759
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001760 spin_lock_irq(&iucv_queue_lock);
1761 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1762 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001763 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1764 kfree(p);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001765 spin_unlock_irq(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001766 unregister_hotcpu_notifier(&iucv_cpu_notifier);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001767 for_each_possible_cpu(cpu) {
1768 kfree(iucv_param[cpu]);
1769 iucv_param[cpu] = NULL;
1770 kfree(iucv_irq_data[cpu]);
1771 iucv_irq_data[cpu] = NULL;
1772 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001773 s390_root_dev_unregister(iucv_root);
1774 bus_unregister(&iucv_bus);
1775 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1776}
1777
1778subsys_initcall(iucv_init);
1779module_exit(iucv_exit);
1780
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001781MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1782MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1783MODULE_LICENSE("GPL");