blob: 0e9f212dd92869304bac018f7647189a4d947bff [file] [log] [blame]
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001/*
2 * IUCV base infrastructure.
3 *
Ursula Braun6c005962009-06-16 10:30:41 +02004 * Copyright IBM Corp. 2001, 2009
5 *
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08006 * Author(s):
7 * Original source:
8 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
9 * Xenia Tkatschow (xenia@us.ibm.com)
10 * 2Gb awareness and general cleanup:
11 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
12 * Rewritten for af_iucv:
13 * Martin Schwidefsky <schwidefsky@de.ibm.com>
14 *
15 * Documentation used:
16 * The original source
17 * CP Programming Service, IBM document # SC24-5760
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
22 * any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
Ursula Braun8f7c5022008-12-25 13:39:47 +010034#define KMSG_COMPONENT "iucv"
35#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
36
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080037#include <linux/module.h>
38#include <linux/moduleparam.h>
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080039#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/slab.h>
42#include <linux/init.h>
43#include <linux/interrupt.h>
44#include <linux/list.h>
45#include <linux/errno.h>
46#include <linux/err.h>
47#include <linux/device.h>
48#include <linux/cpu.h>
Ursula Braun6c005962009-06-16 10:30:41 +020049#include <linux/reboot.h>
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080050#include <net/iucv/iucv.h>
51#include <asm/atomic.h>
52#include <asm/ebcdic.h>
53#include <asm/io.h>
54#include <asm/s390_ext.h>
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080055#include <asm/smp.h>
56
57/*
58 * FLAGS:
59 * All flags are defined in the field IPFLAGS1 of each function
60 * and can be found in CP Programming Services.
61 * IPSRCCLS - Indicates you have specified a source class.
62 * IPTRGCLS - Indicates you have specified a target class.
63 * IPFGPID - Indicates you have specified a pathid.
64 * IPFGMID - Indicates you have specified a message ID.
65 * IPNORPY - Indicates a one-way message. No reply expected.
66 * IPALL - Indicates that all paths are affected.
67 */
68#define IUCV_IPSRCCLS 0x01
69#define IUCV_IPTRGCLS 0x01
70#define IUCV_IPFGPID 0x02
71#define IUCV_IPFGMID 0x04
72#define IUCV_IPNORPY 0x10
73#define IUCV_IPALL 0x80
74
Heiko Carstensda99f052007-05-04 12:23:27 -070075static int iucv_bus_match(struct device *dev, struct device_driver *drv)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080076{
77 return 0;
78}
79
80struct bus_type iucv_bus = {
81 .name = "iucv",
82 .match = iucv_bus_match,
83};
Heiko Carstensda99f052007-05-04 12:23:27 -070084EXPORT_SYMBOL(iucv_bus);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080085
86struct device *iucv_root;
Heiko Carstensda99f052007-05-04 12:23:27 -070087EXPORT_SYMBOL(iucv_root);
88
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -080089static int iucv_available;
90
91/* General IUCV interrupt structure */
92struct iucv_irq_data {
93 u16 ippathid;
94 u8 ipflags1;
95 u8 iptype;
96 u32 res2[8];
97};
98
Martin Schwidefsky04b090d2007-04-28 23:03:59 -070099struct iucv_irq_list {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800100 struct list_head list;
101 struct iucv_irq_data data;
102};
103
Christoph Lameter70cf50352007-11-20 11:13:38 +0100104static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800105static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
106static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
107
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700108/*
109 * Queue of interrupt buffers lock for delivery via the tasklet
110 * (fast but can't call smp_call_function).
111 */
112static LIST_HEAD(iucv_task_queue);
113
114/*
115 * The tasklet for fast delivery of iucv interrupts.
116 */
117static void iucv_tasklet_fn(unsigned long);
118static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
119
120/*
121 * Queue of interrupt buffers for delivery via a work queue
122 * (slower but can call smp_call_function).
123 */
124static LIST_HEAD(iucv_work_queue);
125
126/*
127 * The work element to deliver path pending interrupts.
128 */
129static void iucv_work_fn(struct work_struct *work);
130static DECLARE_WORK(iucv_work, iucv_work_fn);
131
132/*
133 * Spinlock protecting task and work queue.
134 */
135static DEFINE_SPINLOCK(iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800136
137enum iucv_command_codes {
138 IUCV_QUERY = 0,
139 IUCV_RETRIEVE_BUFFER = 2,
140 IUCV_SEND = 4,
141 IUCV_RECEIVE = 5,
142 IUCV_REPLY = 6,
143 IUCV_REJECT = 8,
144 IUCV_PURGE = 9,
145 IUCV_ACCEPT = 10,
146 IUCV_CONNECT = 11,
147 IUCV_DECLARE_BUFFER = 12,
148 IUCV_QUIESCE = 13,
149 IUCV_RESUME = 14,
150 IUCV_SEVER = 15,
151 IUCV_SETMASK = 16,
152};
153
154/*
155 * Error messages that are used with the iucv_sever function. They get
156 * converted to EBCDIC.
157 */
158static char iucv_error_no_listener[16] = "NO LISTENER";
159static char iucv_error_no_memory[16] = "NO MEMORY";
160static char iucv_error_pathid[16] = "INVALID PATHID";
161
162/*
163 * iucv_handler_list: List of registered handlers.
164 */
165static LIST_HEAD(iucv_handler_list);
166
167/*
168 * iucv_path_table: an array of iucv_path structures.
169 */
170static struct iucv_path **iucv_path_table;
171static unsigned long iucv_max_pathid;
172
173/*
174 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
175 */
176static DEFINE_SPINLOCK(iucv_table_lock);
177
178/*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700179 * iucv_active_cpu: contains the number of the cpu executing the tasklet
180 * or the work handler. Needed for iucv_path_sever called from tasklet.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800181 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700182static int iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800183
184/*
185 * Mutex and wait queue for iucv_register/iucv_unregister.
186 */
187static DEFINE_MUTEX(iucv_register_mutex);
188
189/*
190 * Counter for number of non-smp capable handlers.
191 */
192static int iucv_nonsmp_handler;
193
194/*
195 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
196 * iucv_path_quiesce and iucv_path_sever.
197 */
198struct iucv_cmd_control {
199 u16 ippathid;
200 u8 ipflags1;
201 u8 iprcode;
202 u16 ipmsglim;
203 u16 res1;
204 u8 ipvmid[8];
205 u8 ipuser[16];
206 u8 iptarget[8];
207} __attribute__ ((packed,aligned(8)));
208
209/*
210 * Data in parameter list iucv structure. Used by iucv_message_send,
211 * iucv_message_send2way and iucv_message_reply.
212 */
213struct iucv_cmd_dpl {
214 u16 ippathid;
215 u8 ipflags1;
216 u8 iprcode;
217 u32 ipmsgid;
218 u32 iptrgcls;
219 u8 iprmmsg[8];
220 u32 ipsrccls;
221 u32 ipmsgtag;
222 u32 ipbfadr2;
223 u32 ipbfln2f;
224 u32 res;
225} __attribute__ ((packed,aligned(8)));
226
227/*
228 * Data in buffer iucv structure. Used by iucv_message_receive,
229 * iucv_message_reject, iucv_message_send, iucv_message_send2way
230 * and iucv_declare_cpu.
231 */
232struct iucv_cmd_db {
233 u16 ippathid;
234 u8 ipflags1;
235 u8 iprcode;
236 u32 ipmsgid;
237 u32 iptrgcls;
238 u32 ipbfadr1;
239 u32 ipbfln1f;
240 u32 ipsrccls;
241 u32 ipmsgtag;
242 u32 ipbfadr2;
243 u32 ipbfln2f;
244 u32 res;
245} __attribute__ ((packed,aligned(8)));
246
247/*
248 * Purge message iucv structure. Used by iucv_message_purge.
249 */
250struct iucv_cmd_purge {
251 u16 ippathid;
252 u8 ipflags1;
253 u8 iprcode;
254 u32 ipmsgid;
255 u8 ipaudit[3];
256 u8 res1[5];
257 u32 res2;
258 u32 ipsrccls;
259 u32 ipmsgtag;
260 u32 res3[3];
261} __attribute__ ((packed,aligned(8)));
262
263/*
264 * Set mask iucv structure. Used by iucv_enable_cpu.
265 */
266struct iucv_cmd_set_mask {
267 u8 ipmask;
268 u8 res1[2];
269 u8 iprcode;
270 u32 res2[9];
271} __attribute__ ((packed,aligned(8)));
272
273union iucv_param {
274 struct iucv_cmd_control ctrl;
275 struct iucv_cmd_dpl dpl;
276 struct iucv_cmd_db db;
277 struct iucv_cmd_purge purge;
278 struct iucv_cmd_set_mask set_mask;
279};
280
281/*
282 * Anchor for per-cpu IUCV command parameter block.
283 */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100284static union iucv_param *iucv_param[NR_CPUS];
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000285static union iucv_param *iucv_param_irq[NR_CPUS];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800286
287/**
288 * iucv_call_b2f0
289 * @code: identifier of IUCV call to CP.
290 * @parm: pointer to a struct iucv_parm block
291 *
292 * Calls CP to execute IUCV commands.
293 *
294 * Returns the result of the CP IUCV call.
295 */
296static inline int iucv_call_b2f0(int command, union iucv_param *parm)
297{
298 register unsigned long reg0 asm ("0");
299 register unsigned long reg1 asm ("1");
300 int ccode;
301
302 reg0 = command;
303 reg1 = virt_to_phys(parm);
304 asm volatile(
305 " .long 0xb2f01000\n"
306 " ipm %0\n"
307 " srl %0,28\n"
308 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
309 : "m" (*parm) : "cc");
310 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
311}
312
313/**
314 * iucv_query_maxconn
315 *
316 * Determines the maximum number of connections that may be established.
317 *
318 * Returns the maximum number of connections or -EPERM is IUCV is not
319 * available.
320 */
321static int iucv_query_maxconn(void)
322{
323 register unsigned long reg0 asm ("0");
324 register unsigned long reg1 asm ("1");
325 void *param;
326 int ccode;
327
328 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
329 if (!param)
330 return -ENOMEM;
331 reg0 = IUCV_QUERY;
332 reg1 = (unsigned long) param;
333 asm volatile (
334 " .long 0xb2f01000\n"
335 " ipm %0\n"
336 " srl %0,28\n"
337 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
338 if (ccode == 0)
339 iucv_max_pathid = reg0;
340 kfree(param);
341 return ccode ? -EPERM : 0;
342}
343
344/**
345 * iucv_allow_cpu
346 * @data: unused
347 *
348 * Allow iucv interrupts on this cpu.
349 */
350static void iucv_allow_cpu(void *data)
351{
352 int cpu = smp_processor_id();
353 union iucv_param *parm;
354
355 /*
356 * Enable all iucv interrupts.
357 * ipmask contains bits for the different interrupts
358 * 0x80 - Flag to allow nonpriority message pending interrupts
359 * 0x40 - Flag to allow priority message pending interrupts
360 * 0x20 - Flag to allow nonpriority message completion interrupts
361 * 0x10 - Flag to allow priority message completion interrupts
362 * 0x08 - Flag to allow IUCV control interrupts
363 */
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000364 parm = iucv_param_irq[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800365 memset(parm, 0, sizeof(union iucv_param));
366 parm->set_mask.ipmask = 0xf8;
367 iucv_call_b2f0(IUCV_SETMASK, parm);
368
369 /* Set indication that iucv interrupts are allowed for this cpu. */
370 cpu_set(cpu, iucv_irq_cpumask);
371}
372
373/**
374 * iucv_block_cpu
375 * @data: unused
376 *
377 * Block iucv interrupts on this cpu.
378 */
379static void iucv_block_cpu(void *data)
380{
381 int cpu = smp_processor_id();
382 union iucv_param *parm;
383
384 /* Disable all iucv interrupts. */
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000385 parm = iucv_param_irq[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800386 memset(parm, 0, sizeof(union iucv_param));
387 iucv_call_b2f0(IUCV_SETMASK, parm);
388
389 /* Clear indication that iucv interrupts are allowed for this cpu. */
390 cpu_clear(cpu, iucv_irq_cpumask);
391}
392
393/**
394 * iucv_declare_cpu
395 * @data: unused
396 *
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200397 * Declare a interrupt buffer on this cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800398 */
399static void iucv_declare_cpu(void *data)
400{
401 int cpu = smp_processor_id();
402 union iucv_param *parm;
403 int rc;
404
405 if (cpu_isset(cpu, iucv_buffer_cpumask))
406 return;
407
408 /* Declare interrupt buffer. */
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000409 parm = iucv_param_irq[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800410 memset(parm, 0, sizeof(union iucv_param));
Christoph Lameter70cf50352007-11-20 11:13:38 +0100411 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800412 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
413 if (rc) {
414 char *err = "Unknown";
Heiko Carstensda99f052007-05-04 12:23:27 -0700415 switch (rc) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800416 case 0x03:
417 err = "Directory error";
418 break;
419 case 0x0a:
420 err = "Invalid length";
421 break;
422 case 0x13:
423 err = "Buffer already exists";
424 break;
425 case 0x3e:
426 err = "Buffer overlap";
427 break;
428 case 0x5c:
429 err = "Paging or storage error";
430 break;
431 }
Ursula Braun8f7c5022008-12-25 13:39:47 +0100432 pr_warning("Defining an interrupt buffer on CPU %i"
433 " failed with 0x%02x (%s)\n", cpu, rc, err);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800434 return;
435 }
436
437 /* Set indication that an iucv buffer exists for this cpu. */
438 cpu_set(cpu, iucv_buffer_cpumask);
439
440 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
441 /* Enable iucv interrupts on this cpu. */
442 iucv_allow_cpu(NULL);
443 else
444 /* Disable iucv interrupts on this cpu. */
445 iucv_block_cpu(NULL);
446}
447
448/**
449 * iucv_retrieve_cpu
450 * @data: unused
451 *
452 * Retrieve interrupt buffer on this cpu.
453 */
454static void iucv_retrieve_cpu(void *data)
455{
456 int cpu = smp_processor_id();
457 union iucv_param *parm;
458
459 if (!cpu_isset(cpu, iucv_buffer_cpumask))
460 return;
461
462 /* Block iucv interrupts. */
463 iucv_block_cpu(NULL);
464
465 /* Retrieve interrupt buffer. */
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000466 parm = iucv_param_irq[cpu];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800467 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
468
469 /* Clear indication that an iucv buffer exists for this cpu. */
470 cpu_clear(cpu, iucv_buffer_cpumask);
471}
472
473/**
474 * iucv_setmask_smp
475 *
476 * Allow iucv interrupts on all cpus.
477 */
478static void iucv_setmask_mp(void)
479{
480 int cpu;
481
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700482 get_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800483 for_each_online_cpu(cpu)
484 /* Enable all cpus with a declared buffer. */
485 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
486 !cpu_isset(cpu, iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200487 smp_call_function_single(cpu, iucv_allow_cpu,
Jens Axboe8691e5a2008-06-06 11:18:06 +0200488 NULL, 1);
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700489 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800490}
491
492/**
493 * iucv_setmask_up
494 *
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700495 * Allow iucv interrupts on a single cpu.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800496 */
497static void iucv_setmask_up(void)
498{
499 cpumask_t cpumask;
500 int cpu;
501
502 /* Disable all cpu but the first in cpu_irq_cpumask. */
503 cpumask = iucv_irq_cpumask;
504 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
Mike Travis0e12f842008-05-12 21:21:13 +0200505 for_each_cpu_mask_nr(cpu, cpumask)
Jens Axboe8691e5a2008-06-06 11:18:06 +0200506 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800507}
508
509/**
510 * iucv_enable
511 *
512 * This function makes iucv ready for use. It allocates the pathid
513 * table, declares an iucv interrupt buffer and enables the iucv
514 * interrupts. Called when the first user has registered an iucv
515 * handler.
516 */
517static int iucv_enable(void)
518{
519 size_t alloc_size;
520 int cpu, rc;
521
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800522 get_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800523 rc = -ENOMEM;
524 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
525 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
526 if (!iucv_path_table)
527 goto out;
528 /* Declare per cpu buffers. */
529 rc = -EIO;
530 for_each_online_cpu(cpu)
Jens Axboe8691e5a2008-06-06 11:18:06 +0200531 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800532 if (cpus_empty(iucv_buffer_cpumask))
533 /* No cpu could declare an iucv buffer. */
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800534 goto out;
Heiko Carstens7b9d1b22008-06-09 15:50:30 -0700535 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800536 return 0;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800537out:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800538 kfree(iucv_path_table);
539 iucv_path_table = NULL;
540 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800541 return rc;
542}
543
544/**
545 * iucv_disable
546 *
547 * This function shuts down iucv. It disables iucv interrupts, retrieves
548 * the iucv interrupt buffer and frees the pathid table. Called after the
549 * last user unregister its iucv handler.
550 */
551static void iucv_disable(void)
552{
Heiko Carstens8b122ef2008-09-30 03:03:35 -0700553 get_online_cpus();
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200554 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800555 kfree(iucv_path_table);
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800556 iucv_path_table = NULL;
557 put_online_cpus();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800558}
559
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800560static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
561 unsigned long action, void *hcpu)
562{
563 cpumask_t cpumask;
564 long cpu = (long) hcpu;
565
566 switch (action) {
567 case CPU_UP_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700568 case CPU_UP_PREPARE_FROZEN:
Christoph Lameter70cf50352007-11-20 11:13:38 +0100569 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
570 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
571 if (!iucv_irq_data[cpu])
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800572 return NOTIFY_BAD;
Christoph Lameter70cf50352007-11-20 11:13:38 +0100573 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
574 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
Akinobu Mitad0236f82008-07-15 02:09:53 -0700575 if (!iucv_param[cpu]) {
576 kfree(iucv_irq_data[cpu]);
577 iucv_irq_data[cpu] = NULL;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800578 return NOTIFY_BAD;
Akinobu Mitad0236f82008-07-15 02:09:53 -0700579 }
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000580 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
581 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
582 if (!iucv_param_irq[cpu]) {
583 kfree(iucv_param[cpu]);
584 iucv_param[cpu] = NULL;
585 kfree(iucv_irq_data[cpu]);
586 iucv_irq_data[cpu] = NULL;
587 return NOTIFY_BAD;
588 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800589 break;
590 case CPU_UP_CANCELED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700591 case CPU_UP_CANCELED_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800592 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700593 case CPU_DEAD_FROZEN:
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000594 kfree(iucv_param_irq[cpu]);
595 iucv_param_irq[cpu] = NULL;
Christoph Lameter70cf50352007-11-20 11:13:38 +0100596 kfree(iucv_param[cpu]);
597 iucv_param[cpu] = NULL;
598 kfree(iucv_irq_data[cpu]);
599 iucv_irq_data[cpu] = NULL;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800600 break;
601 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700602 case CPU_ONLINE_FROZEN:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800603 case CPU_DOWN_FAILED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700604 case CPU_DOWN_FAILED_FROZEN:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800605 if (!iucv_path_table)
606 break;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200607 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800608 break;
609 case CPU_DOWN_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700610 case CPU_DOWN_PREPARE_FROZEN:
Heiko Carstensf1d3e4d2009-01-05 18:09:02 -0800611 if (!iucv_path_table)
612 break;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800613 cpumask = iucv_buffer_cpumask;
614 cpu_clear(cpu, cpumask);
615 if (cpus_empty(cpumask))
616 /* Can't offline last IUCV enabled cpu. */
617 return NOTIFY_BAD;
Jens Axboe8691e5a2008-06-06 11:18:06 +0200618 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800619 if (cpus_empty(iucv_irq_cpumask))
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200620 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
Jens Axboe8691e5a2008-06-06 11:18:06 +0200621 iucv_allow_cpu, NULL, 1);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800622 break;
623 }
624 return NOTIFY_OK;
625}
626
Heiko Carstensf1494ed2008-06-09 15:49:57 -0700627static struct notifier_block __refdata iucv_cpu_notifier = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800628 .notifier_call = iucv_cpu_notify,
629};
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800630
631/**
632 * iucv_sever_pathid
633 * @pathid: path identification number.
634 * @userdata: 16-bytes of user data.
635 *
636 * Sever an iucv path to free up the pathid. Used internally.
637 */
638static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
639{
640 union iucv_param *parm;
641
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000642 parm = iucv_param_irq[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800643 memset(parm, 0, sizeof(union iucv_param));
644 if (userdata)
645 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
646 parm->ctrl.ippathid = pathid;
647 return iucv_call_b2f0(IUCV_SEVER, parm);
648}
649
650/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700651 * __iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800652 * @dummy: unused dummy argument
653 *
654 * Nop function called via smp_call_function to force work items from
655 * pending external iucv interrupts to the work queue.
656 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700657static void __iucv_cleanup_queue(void *dummy)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800658{
659}
660
661/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700662 * iucv_cleanup_queue
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800663 *
664 * Function called after a path has been severed to find all remaining
665 * work items for the now stale pathid. The caller needs to hold the
666 * iucv_table_lock.
667 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700668static void iucv_cleanup_queue(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800669{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700670 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800671
672 /*
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700673 * When a path is severed, the pathid can be reused immediatly
674 * on a iucv connect or a connection pending interrupt. Remove
675 * all entries from the task queue that refer to a stale pathid
676 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
677 * or deliver the connection pending interrupt. To get all the
678 * pending interrupts force them to the work queue by calling
679 * an empty function on all cpus.
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800680 */
Jens Axboe8691e5a2008-06-06 11:18:06 +0200681 smp_call_function(__iucv_cleanup_queue, NULL, 1);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700682 spin_lock_irq(&iucv_queue_lock);
683 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
684 /* Remove stale work items from the task queue. */
685 if (iucv_path_table[p->data.ippathid] == NULL) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800686 list_del(&p->list);
687 kfree(p);
688 }
689 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700690 spin_unlock_irq(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800691}
692
693/**
694 * iucv_register:
695 * @handler: address of iucv handler structure
696 * @smp: != 0 indicates that the handler can deal with out of order messages
697 *
698 * Registers a driver with IUCV.
699 *
700 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
701 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
702 */
703int iucv_register(struct iucv_handler *handler, int smp)
704{
705 int rc;
706
707 if (!iucv_available)
708 return -ENOSYS;
709 mutex_lock(&iucv_register_mutex);
710 if (!smp)
711 iucv_nonsmp_handler++;
712 if (list_empty(&iucv_handler_list)) {
713 rc = iucv_enable();
714 if (rc)
715 goto out_mutex;
716 } else if (!smp && iucv_nonsmp_handler == 1)
717 iucv_setmask_up();
718 INIT_LIST_HEAD(&handler->paths);
719
Ursula Braun435bc9d2008-02-07 18:06:52 -0800720 spin_lock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800721 list_add_tail(&handler->list, &iucv_handler_list);
Ursula Braun435bc9d2008-02-07 18:06:52 -0800722 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800723 rc = 0;
724out_mutex:
725 mutex_unlock(&iucv_register_mutex);
726 return rc;
727}
Heiko Carstensda99f052007-05-04 12:23:27 -0700728EXPORT_SYMBOL(iucv_register);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800729
730/**
731 * iucv_unregister
732 * @handler: address of iucv handler structure
733 * @smp: != 0 indicates that the handler can deal with out of order messages
734 *
735 * Unregister driver from IUCV.
736 */
737void iucv_unregister(struct iucv_handler *handler, int smp)
738{
739 struct iucv_path *p, *n;
740
741 mutex_lock(&iucv_register_mutex);
742 spin_lock_bh(&iucv_table_lock);
743 /* Remove handler from the iucv_handler_list. */
744 list_del_init(&handler->list);
745 /* Sever all pathids still refering to the handler. */
746 list_for_each_entry_safe(p, n, &handler->paths, list) {
747 iucv_sever_pathid(p->pathid, NULL);
748 iucv_path_table[p->pathid] = NULL;
749 list_del(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800750 iucv_path_free(p);
751 }
752 spin_unlock_bh(&iucv_table_lock);
753 if (!smp)
754 iucv_nonsmp_handler--;
755 if (list_empty(&iucv_handler_list))
756 iucv_disable();
757 else if (!smp && iucv_nonsmp_handler == 0)
758 iucv_setmask_mp();
759 mutex_unlock(&iucv_register_mutex);
760}
Heiko Carstensda99f052007-05-04 12:23:27 -0700761EXPORT_SYMBOL(iucv_unregister);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800762
Ursula Braun6c005962009-06-16 10:30:41 +0200763static int iucv_reboot_event(struct notifier_block *this,
764 unsigned long event, void *ptr)
765{
766 int i, rc;
767
768 get_online_cpus();
769 on_each_cpu(iucv_block_cpu, NULL, 1);
770 preempt_disable();
771 for (i = 0; i < iucv_max_pathid; i++) {
772 if (iucv_path_table[i])
773 rc = iucv_sever_pathid(i, NULL);
774 }
775 preempt_enable();
776 put_online_cpus();
777 iucv_disable();
778 return NOTIFY_DONE;
779}
780
781static struct notifier_block iucv_reboot_notifier = {
782 .notifier_call = iucv_reboot_event,
783};
784
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800785/**
786 * iucv_path_accept
787 * @path: address of iucv path structure
788 * @handler: address of iucv handler structure
789 * @userdata: 16 bytes of data reflected to the communication partner
790 * @private: private data passed to interrupt handlers for this path
791 *
792 * This function is issued after the user received a connection pending
793 * external interrupt and now wishes to complete the IUCV communication path.
794 *
795 * Returns the result of the CP IUCV call.
796 */
797int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
798 u8 userdata[16], void *private)
799{
800 union iucv_param *parm;
801 int rc;
802
803 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +0200804 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
805 rc = -EIO;
806 goto out;
807 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800808 /* Prepare parameter block. */
Christoph Lameter70cf50352007-11-20 11:13:38 +0100809 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800810 memset(parm, 0, sizeof(union iucv_param));
811 parm->ctrl.ippathid = path->pathid;
812 parm->ctrl.ipmsglim = path->msglim;
813 if (userdata)
814 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
815 parm->ctrl.ipflags1 = path->flags;
816
817 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
818 if (!rc) {
819 path->private = private;
820 path->msglim = parm->ctrl.ipmsglim;
821 path->flags = parm->ctrl.ipflags1;
822 }
Ursula Braun6c005962009-06-16 10:30:41 +0200823out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800824 local_bh_enable();
825 return rc;
826}
Heiko Carstensda99f052007-05-04 12:23:27 -0700827EXPORT_SYMBOL(iucv_path_accept);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800828
829/**
830 * iucv_path_connect
831 * @path: address of iucv path structure
832 * @handler: address of iucv handler structure
833 * @userid: 8-byte user identification
834 * @system: 8-byte target system identification
835 * @userdata: 16 bytes of data reflected to the communication partner
836 * @private: private data passed to interrupt handlers for this path
837 *
838 * This function establishes an IUCV path. Although the connect may complete
839 * successfully, you are not able to use the path until you receive an IUCV
840 * Connection Complete external interrupt.
841 *
842 * Returns the result of the CP IUCV call.
843 */
844int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
845 u8 userid[8], u8 system[8], u8 userdata[16],
846 void *private)
847{
848 union iucv_param *parm;
849 int rc;
850
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700851 spin_lock_bh(&iucv_table_lock);
852 iucv_cleanup_queue();
Ursula Braun6c005962009-06-16 10:30:41 +0200853 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
854 rc = -EIO;
855 goto out;
856 }
Christoph Lameter70cf50352007-11-20 11:13:38 +0100857 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800858 memset(parm, 0, sizeof(union iucv_param));
859 parm->ctrl.ipmsglim = path->msglim;
860 parm->ctrl.ipflags1 = path->flags;
861 if (userid) {
862 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
863 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
864 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
865 }
866 if (system) {
867 memcpy(parm->ctrl.iptarget, system,
868 sizeof(parm->ctrl.iptarget));
869 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
870 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
871 }
872 if (userdata)
873 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
874
875 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
876 if (!rc) {
877 if (parm->ctrl.ippathid < iucv_max_pathid) {
878 path->pathid = parm->ctrl.ippathid;
879 path->msglim = parm->ctrl.ipmsglim;
880 path->flags = parm->ctrl.ipflags1;
881 path->handler = handler;
882 path->private = private;
883 list_add_tail(&path->list, &handler->paths);
884 iucv_path_table[path->pathid] = path;
885 } else {
886 iucv_sever_pathid(parm->ctrl.ippathid,
887 iucv_error_pathid);
888 rc = -EIO;
889 }
890 }
Ursula Braun6c005962009-06-16 10:30:41 +0200891out:
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700892 spin_unlock_bh(&iucv_table_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800893 return rc;
894}
Heiko Carstensda99f052007-05-04 12:23:27 -0700895EXPORT_SYMBOL(iucv_path_connect);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800896
897/**
898 * iucv_path_quiesce:
899 * @path: address of iucv path structure
900 * @userdata: 16 bytes of data reflected to the communication partner
901 *
902 * This function temporarily suspends incoming messages on an IUCV path.
903 * You can later reactivate the path by invoking the iucv_resume function.
904 *
905 * Returns the result from the CP IUCV call.
906 */
907int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
908{
909 union iucv_param *parm;
910 int rc;
911
912 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +0200913 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
914 rc = -EIO;
915 goto out;
916 }
Christoph Lameter70cf50352007-11-20 11:13:38 +0100917 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800918 memset(parm, 0, sizeof(union iucv_param));
919 if (userdata)
920 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
921 parm->ctrl.ippathid = path->pathid;
922 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
Ursula Braun6c005962009-06-16 10:30:41 +0200923out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800924 local_bh_enable();
925 return rc;
926}
Heiko Carstensda99f052007-05-04 12:23:27 -0700927EXPORT_SYMBOL(iucv_path_quiesce);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800928
929/**
930 * iucv_path_resume:
931 * @path: address of iucv path structure
932 * @userdata: 16 bytes of data reflected to the communication partner
933 *
934 * This function resumes incoming messages on an IUCV path that has
935 * been stopped with iucv_path_quiesce.
936 *
937 * Returns the result from the CP IUCV call.
938 */
939int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
940{
941 union iucv_param *parm;
942 int rc;
943
944 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +0200945 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
946 rc = -EIO;
947 goto out;
948 }
Christoph Lameter70cf50352007-11-20 11:13:38 +0100949 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800950 memset(parm, 0, sizeof(union iucv_param));
951 if (userdata)
952 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
953 parm->ctrl.ippathid = path->pathid;
954 rc = iucv_call_b2f0(IUCV_RESUME, parm);
Ursula Braun6c005962009-06-16 10:30:41 +0200955out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800956 local_bh_enable();
957 return rc;
958}
959
960/**
961 * iucv_path_sever
962 * @path: address of iucv path structure
963 * @userdata: 16 bytes of data reflected to the communication partner
964 *
965 * This function terminates an IUCV path.
966 *
967 * Returns the result from the CP IUCV call.
968 */
969int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
970{
971 int rc;
972
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800973 preempt_disable();
Ursula Braun6c005962009-06-16 10:30:41 +0200974 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
975 rc = -EIO;
976 goto out;
977 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700978 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800979 spin_lock_bh(&iucv_table_lock);
980 rc = iucv_sever_pathid(path->pathid, userdata);
Ursula Braun42e1b4c2009-04-21 23:26:20 +0000981 iucv_path_table[path->pathid] = NULL;
982 list_del_init(&path->list);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -0700983 if (iucv_active_cpu != smp_processor_id())
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800984 spin_unlock_bh(&iucv_table_lock);
Ursula Braun6c005962009-06-16 10:30:41 +0200985out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800986 preempt_enable();
987 return rc;
988}
Heiko Carstensda99f052007-05-04 12:23:27 -0700989EXPORT_SYMBOL(iucv_path_sever);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -0800990
991/**
992 * iucv_message_purge
993 * @path: address of iucv path structure
994 * @msg: address of iucv msg structure
995 * @srccls: source class of message
996 *
997 * Cancels a message you have sent.
998 *
999 * Returns the result from the CP IUCV call.
1000 */
1001int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
1002 u32 srccls)
1003{
1004 union iucv_param *parm;
1005 int rc;
1006
1007 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +02001008 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1009 rc = -EIO;
1010 goto out;
1011 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001012 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001013 memset(parm, 0, sizeof(union iucv_param));
1014 parm->purge.ippathid = path->pathid;
1015 parm->purge.ipmsgid = msg->id;
1016 parm->purge.ipsrccls = srccls;
1017 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
1018 rc = iucv_call_b2f0(IUCV_PURGE, parm);
1019 if (!rc) {
1020 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
1021 msg->tag = parm->purge.ipmsgtag;
1022 }
Ursula Braun6c005962009-06-16 10:30:41 +02001023out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001024 local_bh_enable();
1025 return rc;
1026}
Heiko Carstensda99f052007-05-04 12:23:27 -07001027EXPORT_SYMBOL(iucv_message_purge);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001028
1029/**
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001030 * iucv_message_receive_iprmdata
1031 * @path: address of iucv path structure
1032 * @msg: address of iucv msg structure
1033 * @flags: how the message is received (IUCV_IPBUFLST)
1034 * @buffer: address of data buffer or address of struct iucv_array
1035 * @size: length of data buffer
1036 * @residual:
1037 *
1038 * Internal function used by iucv_message_receive and __iucv_message_receive
1039 * to receive RMDATA data stored in struct iucv_message.
1040 */
1041static int iucv_message_receive_iprmdata(struct iucv_path *path,
1042 struct iucv_message *msg,
1043 u8 flags, void *buffer,
1044 size_t size, size_t *residual)
1045{
1046 struct iucv_array *array;
1047 u8 *rmmsg;
1048 size_t copy;
1049
1050 /*
1051 * Message is 8 bytes long and has been stored to the
1052 * message descriptor itself.
1053 */
1054 if (residual)
1055 *residual = abs(size - 8);
1056 rmmsg = msg->rmmsg;
1057 if (flags & IUCV_IPBUFLST) {
1058 /* Copy to struct iucv_array. */
1059 size = (size < 8) ? size : 8;
1060 for (array = buffer; size > 0; array++) {
1061 copy = min_t(size_t, size, array->length);
1062 memcpy((u8 *)(addr_t) array->address,
1063 rmmsg, copy);
1064 rmmsg += copy;
1065 size -= copy;
1066 }
1067 } else {
1068 /* Copy to direct buffer. */
1069 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1070 }
1071 return 0;
1072}
1073
1074/**
1075 * __iucv_message_receive
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001076 * @path: address of iucv path structure
1077 * @msg: address of iucv msg structure
1078 * @flags: how the message is received (IUCV_IPBUFLST)
1079 * @buffer: address of data buffer or address of struct iucv_array
1080 * @size: length of data buffer
1081 * @residual:
1082 *
1083 * This function receives messages that are being sent to you over
1084 * established paths. This function will deal with RMDATA messages
1085 * embedded in struct iucv_message as well.
1086 *
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001087 * Locking: no locking
1088 *
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001089 * Returns the result from the CP IUCV call.
1090 */
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001091int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1092 u8 flags, void *buffer, size_t size, size_t *residual)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001093{
1094 union iucv_param *parm;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001095 int rc;
1096
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001097 if (msg->flags & IUCV_IPRMDATA)
1098 return iucv_message_receive_iprmdata(path, msg, flags,
1099 buffer, size, residual);
Ursula Braun6c005962009-06-16 10:30:41 +02001100 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1101 rc = -EIO;
1102 goto out;
1103 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001104 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001105 memset(parm, 0, sizeof(union iucv_param));
1106 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1107 parm->db.ipbfln1f = (u32) size;
1108 parm->db.ipmsgid = msg->id;
1109 parm->db.ippathid = path->pathid;
1110 parm->db.iptrgcls = msg->class;
1111 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1112 IUCV_IPFGMID | IUCV_IPTRGCLS);
1113 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1114 if (!rc || rc == 5) {
1115 msg->flags = parm->db.ipflags1;
1116 if (residual)
1117 *residual = parm->db.ipbfln1f;
1118 }
Ursula Braun6c005962009-06-16 10:30:41 +02001119out:
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001120 return rc;
1121}
1122EXPORT_SYMBOL(__iucv_message_receive);
1123
1124/**
1125 * iucv_message_receive
1126 * @path: address of iucv path structure
1127 * @msg: address of iucv msg structure
1128 * @flags: how the message is received (IUCV_IPBUFLST)
1129 * @buffer: address of data buffer or address of struct iucv_array
1130 * @size: length of data buffer
1131 * @residual:
1132 *
1133 * This function receives messages that are being sent to you over
1134 * established paths. This function will deal with RMDATA messages
1135 * embedded in struct iucv_message as well.
1136 *
1137 * Locking: local_bh_enable/local_bh_disable
1138 *
1139 * Returns the result from the CP IUCV call.
1140 */
1141int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1142 u8 flags, void *buffer, size_t size, size_t *residual)
1143{
1144 int rc;
1145
1146 if (msg->flags & IUCV_IPRMDATA)
1147 return iucv_message_receive_iprmdata(path, msg, flags,
1148 buffer, size, residual);
1149 local_bh_disable();
1150 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001151 local_bh_enable();
1152 return rc;
1153}
Heiko Carstensda99f052007-05-04 12:23:27 -07001154EXPORT_SYMBOL(iucv_message_receive);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001155
1156/**
1157 * iucv_message_reject
1158 * @path: address of iucv path structure
1159 * @msg: address of iucv msg structure
1160 *
1161 * The reject function refuses a specified message. Between the time you
1162 * are notified of a message and the time that you complete the message,
1163 * the message may be rejected.
1164 *
1165 * Returns the result from the CP IUCV call.
1166 */
1167int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1168{
1169 union iucv_param *parm;
1170 int rc;
1171
1172 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +02001173 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1174 rc = -EIO;
1175 goto out;
1176 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001177 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001178 memset(parm, 0, sizeof(union iucv_param));
1179 parm->db.ippathid = path->pathid;
1180 parm->db.ipmsgid = msg->id;
1181 parm->db.iptrgcls = msg->class;
1182 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1183 rc = iucv_call_b2f0(IUCV_REJECT, parm);
Ursula Braun6c005962009-06-16 10:30:41 +02001184out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001185 local_bh_enable();
1186 return rc;
1187}
Heiko Carstensda99f052007-05-04 12:23:27 -07001188EXPORT_SYMBOL(iucv_message_reject);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001189
1190/**
1191 * iucv_message_reply
1192 * @path: address of iucv path structure
1193 * @msg: address of iucv msg structure
1194 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1195 * @reply: address of reply data buffer or address of struct iucv_array
1196 * @size: length of reply data buffer
1197 *
1198 * This function responds to the two-way messages that you receive. You
1199 * must identify completely the message to which you wish to reply. ie,
1200 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1201 * the parameter list.
1202 *
1203 * Returns the result from the CP IUCV call.
1204 */
1205int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1206 u8 flags, void *reply, size_t size)
1207{
1208 union iucv_param *parm;
1209 int rc;
1210
1211 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +02001212 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1213 rc = -EIO;
1214 goto out;
1215 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001216 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001217 memset(parm, 0, sizeof(union iucv_param));
1218 if (flags & IUCV_IPRMDATA) {
1219 parm->dpl.ippathid = path->pathid;
1220 parm->dpl.ipflags1 = flags;
1221 parm->dpl.ipmsgid = msg->id;
1222 parm->dpl.iptrgcls = msg->class;
1223 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1224 } else {
1225 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1226 parm->db.ipbfln1f = (u32) size;
1227 parm->db.ippathid = path->pathid;
1228 parm->db.ipflags1 = flags;
1229 parm->db.ipmsgid = msg->id;
1230 parm->db.iptrgcls = msg->class;
1231 }
1232 rc = iucv_call_b2f0(IUCV_REPLY, parm);
Ursula Braun6c005962009-06-16 10:30:41 +02001233out:
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_reply);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001238
1239/**
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001240 * __iucv_message_send
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001241 * @path: address of iucv path structure
1242 * @msg: address of iucv msg structure
1243 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1244 * @srccls: source class of message
1245 * @buffer: address of send buffer or address of struct iucv_array
1246 * @size: length of send buffer
1247 *
1248 * This function transmits data to another application. Data to be
1249 * transmitted is in a buffer and this is a one-way message and the
1250 * receiver will not reply to the message.
1251 *
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001252 * Locking: no locking
1253 *
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001254 * Returns the result from the CP IUCV call.
1255 */
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001256int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001257 u8 flags, u32 srccls, void *buffer, size_t size)
1258{
1259 union iucv_param *parm;
1260 int rc;
1261
Ursula Braun6c005962009-06-16 10:30:41 +02001262 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1263 rc = -EIO;
1264 goto out;
1265 }
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 /* Message of 8 bytes can be placed into the parameter list. */
1270 parm->dpl.ippathid = path->pathid;
1271 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1272 parm->dpl.iptrgcls = msg->class;
1273 parm->dpl.ipsrccls = srccls;
1274 parm->dpl.ipmsgtag = msg->tag;
1275 memcpy(parm->dpl.iprmmsg, buffer, 8);
1276 } else {
1277 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1278 parm->db.ipbfln1f = (u32) size;
1279 parm->db.ippathid = path->pathid;
1280 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1281 parm->db.iptrgcls = msg->class;
1282 parm->db.ipsrccls = srccls;
1283 parm->db.ipmsgtag = msg->tag;
1284 }
1285 rc = iucv_call_b2f0(IUCV_SEND, parm);
1286 if (!rc)
1287 msg->id = parm->db.ipmsgid;
Ursula Braun6c005962009-06-16 10:30:41 +02001288out:
Hendrik Brueckner91d5d45e2008-12-25 13:38:58 +01001289 return rc;
1290}
1291EXPORT_SYMBOL(__iucv_message_send);
1292
1293/**
1294 * iucv_message_send
1295 * @path: address of iucv path structure
1296 * @msg: address of iucv msg structure
1297 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1298 * @srccls: source class of message
1299 * @buffer: address of send buffer or address of struct iucv_array
1300 * @size: length of send buffer
1301 *
1302 * This function transmits data to another application. Data to be
1303 * transmitted is in a buffer and this is a one-way message and the
1304 * receiver will not reply to the message.
1305 *
1306 * Locking: local_bh_enable/local_bh_disable
1307 *
1308 * Returns the result from the CP IUCV call.
1309 */
1310int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1311 u8 flags, u32 srccls, void *buffer, size_t size)
1312{
1313 int rc;
1314
1315 local_bh_disable();
1316 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001317 local_bh_enable();
1318 return rc;
1319}
Heiko Carstensda99f052007-05-04 12:23:27 -07001320EXPORT_SYMBOL(iucv_message_send);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001321
1322/**
1323 * iucv_message_send2way
1324 * @path: address of iucv path structure
1325 * @msg: address of iucv msg structure
1326 * @flags: how the message is sent and the reply is received
1327 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1328 * @srccls: source class of message
1329 * @buffer: address of send buffer or address of struct iucv_array
1330 * @size: length of send buffer
1331 * @ansbuf: address of answer buffer or address of struct iucv_array
1332 * @asize: size of reply buffer
1333 *
1334 * This function transmits data to another application. Data to be
1335 * transmitted is in a buffer. The receiver of the send is expected to
1336 * reply to the message and a buffer is provided into which IUCV moves
1337 * the reply to this message.
1338 *
1339 * Returns the result from the CP IUCV call.
1340 */
1341int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1342 u8 flags, u32 srccls, void *buffer, size_t size,
1343 void *answer, size_t asize, size_t *residual)
1344{
1345 union iucv_param *parm;
1346 int rc;
1347
1348 local_bh_disable();
Ursula Braun6c005962009-06-16 10:30:41 +02001349 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1350 rc = -EIO;
1351 goto out;
1352 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001353 parm = iucv_param[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001354 memset(parm, 0, sizeof(union iucv_param));
1355 if (flags & IUCV_IPRMDATA) {
1356 parm->dpl.ippathid = path->pathid;
1357 parm->dpl.ipflags1 = path->flags; /* priority message */
1358 parm->dpl.iptrgcls = msg->class;
1359 parm->dpl.ipsrccls = srccls;
1360 parm->dpl.ipmsgtag = msg->tag;
1361 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1362 parm->dpl.ipbfln2f = (u32) asize;
1363 memcpy(parm->dpl.iprmmsg, buffer, 8);
1364 } else {
1365 parm->db.ippathid = path->pathid;
1366 parm->db.ipflags1 = path->flags; /* priority message */
1367 parm->db.iptrgcls = msg->class;
1368 parm->db.ipsrccls = srccls;
1369 parm->db.ipmsgtag = msg->tag;
1370 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1371 parm->db.ipbfln1f = (u32) size;
1372 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1373 parm->db.ipbfln2f = (u32) asize;
1374 }
1375 rc = iucv_call_b2f0(IUCV_SEND, parm);
1376 if (!rc)
1377 msg->id = parm->db.ipmsgid;
Ursula Braun6c005962009-06-16 10:30:41 +02001378out:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001379 local_bh_enable();
1380 return rc;
1381}
Heiko Carstensda99f052007-05-04 12:23:27 -07001382EXPORT_SYMBOL(iucv_message_send2way);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001383
1384/**
1385 * iucv_path_pending
1386 * @data: Pointer to external interrupt buffer
1387 *
1388 * Process connection pending work item. Called from tasklet while holding
1389 * iucv_table_lock.
1390 */
1391struct iucv_path_pending {
1392 u16 ippathid;
1393 u8 ipflags1;
1394 u8 iptype;
1395 u16 ipmsglim;
1396 u16 res1;
1397 u8 ipvmid[8];
1398 u8 ipuser[16];
1399 u32 res3;
1400 u8 ippollfg;
1401 u8 res4[3];
1402} __attribute__ ((packed));
1403
1404static void iucv_path_pending(struct iucv_irq_data *data)
1405{
1406 struct iucv_path_pending *ipp = (void *) data;
1407 struct iucv_handler *handler;
1408 struct iucv_path *path;
1409 char *error;
1410
1411 BUG_ON(iucv_path_table[ipp->ippathid]);
1412 /* New pathid, handler found. Create a new path struct. */
1413 error = iucv_error_no_memory;
1414 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1415 if (!path)
1416 goto out_sever;
1417 path->pathid = ipp->ippathid;
1418 iucv_path_table[path->pathid] = path;
1419 EBCASC(ipp->ipvmid, 8);
1420
1421 /* Call registered handler until one is found that wants the path. */
1422 list_for_each_entry(handler, &iucv_handler_list, list) {
1423 if (!handler->path_pending)
1424 continue;
1425 /*
1426 * Add path to handler to allow a call to iucv_path_sever
1427 * inside the path_pending function. If the handler returns
1428 * an error remove the path from the handler again.
1429 */
1430 list_add(&path->list, &handler->paths);
1431 path->handler = handler;
1432 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1433 return;
1434 list_del(&path->list);
1435 path->handler = NULL;
1436 }
1437 /* No handler wanted the path. */
1438 iucv_path_table[path->pathid] = NULL;
1439 iucv_path_free(path);
1440 error = iucv_error_no_listener;
1441out_sever:
1442 iucv_sever_pathid(ipp->ippathid, error);
1443}
1444
1445/**
1446 * iucv_path_complete
1447 * @data: Pointer to external interrupt buffer
1448 *
1449 * Process connection complete work item. Called from tasklet while holding
1450 * iucv_table_lock.
1451 */
1452struct iucv_path_complete {
1453 u16 ippathid;
1454 u8 ipflags1;
1455 u8 iptype;
1456 u16 ipmsglim;
1457 u16 res1;
1458 u8 res2[8];
1459 u8 ipuser[16];
1460 u32 res3;
1461 u8 ippollfg;
1462 u8 res4[3];
1463} __attribute__ ((packed));
1464
1465static void iucv_path_complete(struct iucv_irq_data *data)
1466{
1467 struct iucv_path_complete *ipc = (void *) data;
1468 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1469
Hendrik Bruecknerb8942e32009-04-21 23:26:23 +00001470 if (path)
1471 path->flags = ipc->ipflags1;
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001472 if (path && path->handler && path->handler->path_complete)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001473 path->handler->path_complete(path, ipc->ipuser);
1474}
1475
1476/**
1477 * iucv_path_severed
1478 * @data: Pointer to external interrupt buffer
1479 *
1480 * Process connection severed work item. Called from tasklet while holding
1481 * iucv_table_lock.
1482 */
1483struct iucv_path_severed {
1484 u16 ippathid;
1485 u8 res1;
1486 u8 iptype;
1487 u32 res2;
1488 u8 res3[8];
1489 u8 ipuser[16];
1490 u32 res4;
1491 u8 ippollfg;
1492 u8 res5[3];
1493} __attribute__ ((packed));
1494
1495static void iucv_path_severed(struct iucv_irq_data *data)
1496{
1497 struct iucv_path_severed *ips = (void *) data;
1498 struct iucv_path *path = iucv_path_table[ips->ippathid];
1499
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001500 if (!path || !path->handler) /* Already severed */
1501 return;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001502 if (path->handler->path_severed)
1503 path->handler->path_severed(path, ips->ipuser);
1504 else {
1505 iucv_sever_pathid(path->pathid, NULL);
1506 iucv_path_table[path->pathid] = NULL;
Ursula Braun42e1b4c2009-04-21 23:26:20 +00001507 list_del(&path->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001508 iucv_path_free(path);
1509 }
1510}
1511
1512/**
1513 * iucv_path_quiesced
1514 * @data: Pointer to external interrupt buffer
1515 *
1516 * Process connection quiesced work item. Called from tasklet while holding
1517 * iucv_table_lock.
1518 */
1519struct iucv_path_quiesced {
1520 u16 ippathid;
1521 u8 res1;
1522 u8 iptype;
1523 u32 res2;
1524 u8 res3[8];
1525 u8 ipuser[16];
1526 u32 res4;
1527 u8 ippollfg;
1528 u8 res5[3];
1529} __attribute__ ((packed));
1530
1531static void iucv_path_quiesced(struct iucv_irq_data *data)
1532{
1533 struct iucv_path_quiesced *ipq = (void *) data;
1534 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1535
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001536 if (path && path->handler && path->handler->path_quiesced)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001537 path->handler->path_quiesced(path, ipq->ipuser);
1538}
1539
1540/**
1541 * iucv_path_resumed
1542 * @data: Pointer to external interrupt buffer
1543 *
1544 * Process connection resumed work item. Called from tasklet while holding
1545 * iucv_table_lock.
1546 */
1547struct iucv_path_resumed {
1548 u16 ippathid;
1549 u8 res1;
1550 u8 iptype;
1551 u32 res2;
1552 u8 res3[8];
1553 u8 ipuser[16];
1554 u32 res4;
1555 u8 ippollfg;
1556 u8 res5[3];
1557} __attribute__ ((packed));
1558
1559static void iucv_path_resumed(struct iucv_irq_data *data)
1560{
1561 struct iucv_path_resumed *ipr = (void *) data;
1562 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1563
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001564 if (path && path->handler && path->handler->path_resumed)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001565 path->handler->path_resumed(path, ipr->ipuser);
1566}
1567
1568/**
1569 * iucv_message_complete
1570 * @data: Pointer to external interrupt buffer
1571 *
1572 * Process message complete work item. Called from tasklet while holding
1573 * iucv_table_lock.
1574 */
1575struct iucv_message_complete {
1576 u16 ippathid;
1577 u8 ipflags1;
1578 u8 iptype;
1579 u32 ipmsgid;
1580 u32 ipaudit;
1581 u8 iprmmsg[8];
1582 u32 ipsrccls;
1583 u32 ipmsgtag;
1584 u32 res;
1585 u32 ipbfln2f;
1586 u8 ippollfg;
1587 u8 res2[3];
1588} __attribute__ ((packed));
1589
1590static void iucv_message_complete(struct iucv_irq_data *data)
1591{
1592 struct iucv_message_complete *imc = (void *) data;
1593 struct iucv_path *path = iucv_path_table[imc->ippathid];
1594 struct iucv_message msg;
1595
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001596 if (path && path->handler && path->handler->message_complete) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001597 msg.flags = imc->ipflags1;
1598 msg.id = imc->ipmsgid;
1599 msg.audit = imc->ipaudit;
1600 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1601 msg.class = imc->ipsrccls;
1602 msg.tag = imc->ipmsgtag;
1603 msg.length = imc->ipbfln2f;
1604 path->handler->message_complete(path, &msg);
1605 }
1606}
1607
1608/**
1609 * iucv_message_pending
1610 * @data: Pointer to external interrupt buffer
1611 *
1612 * Process message pending work item. Called from tasklet while holding
1613 * iucv_table_lock.
1614 */
1615struct iucv_message_pending {
1616 u16 ippathid;
1617 u8 ipflags1;
1618 u8 iptype;
1619 u32 ipmsgid;
1620 u32 iptrgcls;
1621 union {
1622 u32 iprmmsg1_u32;
1623 u8 iprmmsg1[4];
1624 } ln1msg1;
1625 union {
1626 u32 ipbfln1f;
1627 u8 iprmmsg2[4];
1628 } ln1msg2;
1629 u32 res1[3];
1630 u32 ipbfln2f;
1631 u8 ippollfg;
1632 u8 res2[3];
1633} __attribute__ ((packed));
1634
1635static void iucv_message_pending(struct iucv_irq_data *data)
1636{
1637 struct iucv_message_pending *imp = (void *) data;
1638 struct iucv_path *path = iucv_path_table[imp->ippathid];
1639 struct iucv_message msg;
1640
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001641 if (path && path->handler && path->handler->message_pending) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001642 msg.flags = imp->ipflags1;
1643 msg.id = imp->ipmsgid;
1644 msg.class = imp->iptrgcls;
1645 if (imp->ipflags1 & IUCV_IPRMDATA) {
1646 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1647 msg.length = 8;
1648 } else
1649 msg.length = imp->ln1msg2.ipbfln1f;
1650 msg.reply_size = imp->ipbfln2f;
1651 path->handler->message_pending(path, &msg);
1652 }
1653}
1654
1655/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001656 * iucv_tasklet_fn:
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001657 *
1658 * This tasklet loops over the queue of irq buffers created by
1659 * iucv_external_interrupt, calls the appropriate action handler
1660 * and then frees the buffer.
1661 */
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001662static void iucv_tasklet_fn(unsigned long ignored)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001663{
1664 typedef void iucv_irq_fn(struct iucv_irq_data *);
1665 static iucv_irq_fn *irq_fn[] = {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001666 [0x02] = iucv_path_complete,
1667 [0x03] = iucv_path_severed,
1668 [0x04] = iucv_path_quiesced,
1669 [0x05] = iucv_path_resumed,
1670 [0x06] = iucv_message_complete,
1671 [0x07] = iucv_message_complete,
1672 [0x08] = iucv_message_pending,
1673 [0x09] = iucv_message_pending,
1674 };
Denis Chengb5e78332007-12-07 00:51:45 -08001675 LIST_HEAD(task_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001676 struct iucv_irq_list *p, *n;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001677
1678 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
Ursula Braun13fdc9a2007-07-14 19:03:41 -07001679 if (!spin_trylock(&iucv_table_lock)) {
1680 tasklet_schedule(&iucv_tasklet);
1681 return;
1682 }
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001683 iucv_active_cpu = smp_processor_id();
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001684
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001685 spin_lock_irq(&iucv_queue_lock);
1686 list_splice_init(&iucv_task_queue, &task_queue);
1687 spin_unlock_irq(&iucv_queue_lock);
1688
1689 list_for_each_entry_safe(p, n, &task_queue, list) {
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001690 list_del_init(&p->list);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001691 irq_fn[p->data.iptype](&p->data);
1692 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001693 }
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001694
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001695 iucv_active_cpu = -1;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001696 spin_unlock(&iucv_table_lock);
1697}
1698
1699/**
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001700 * iucv_work_fn:
1701 *
1702 * This work function loops over the queue of path pending irq blocks
1703 * created by iucv_external_interrupt, calls the appropriate action
1704 * handler and then frees the buffer.
1705 */
1706static void iucv_work_fn(struct work_struct *work)
1707{
1708 typedef void iucv_irq_fn(struct iucv_irq_data *);
Denis Chengb5e78332007-12-07 00:51:45 -08001709 LIST_HEAD(work_queue);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001710 struct iucv_irq_list *p, *n;
1711
1712 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1713 spin_lock_bh(&iucv_table_lock);
1714 iucv_active_cpu = smp_processor_id();
1715
1716 spin_lock_irq(&iucv_queue_lock);
1717 list_splice_init(&iucv_work_queue, &work_queue);
1718 spin_unlock_irq(&iucv_queue_lock);
1719
1720 iucv_cleanup_queue();
1721 list_for_each_entry_safe(p, n, &work_queue, list) {
1722 list_del_init(&p->list);
1723 iucv_path_pending(&p->data);
1724 kfree(p);
1725 }
1726
1727 iucv_active_cpu = -1;
1728 spin_unlock_bh(&iucv_table_lock);
1729}
1730
1731/**
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001732 * iucv_external_interrupt
1733 * @code: irq code
1734 *
1735 * Handles external interrupts coming in from CP.
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001736 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001737 */
1738static void iucv_external_interrupt(u16 code)
1739{
1740 struct iucv_irq_data *p;
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001741 struct iucv_irq_list *work;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001742
Christoph Lameter70cf50352007-11-20 11:13:38 +01001743 p = iucv_irq_data[smp_processor_id()];
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001744 if (p->ippathid >= iucv_max_pathid) {
Ursula Braunc2b4afd2008-07-14 09:59:29 +02001745 WARN_ON(p->ippathid >= iucv_max_pathid);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001746 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1747 return;
1748 }
Ursula Braunc2b4afd2008-07-14 09:59:29 +02001749 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001750 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001751 if (!work) {
Ursula Braun8f7c5022008-12-25 13:39:47 +01001752 pr_warning("iucv_external_interrupt: out of memory\n");
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001753 return;
1754 }
1755 memcpy(&work->data, p, sizeof(work->data));
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001756 spin_lock(&iucv_queue_lock);
1757 if (p->iptype == 0x01) {
1758 /* Path pending interrupt. */
1759 list_add_tail(&work->list, &iucv_work_queue);
1760 schedule_work(&iucv_work);
1761 } else {
1762 /* The other interrupts. */
1763 list_add_tail(&work->list, &iucv_task_queue);
1764 tasklet_schedule(&iucv_tasklet);
1765 }
1766 spin_unlock(&iucv_queue_lock);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001767}
1768
1769/**
1770 * iucv_init
1771 *
1772 * Allocates and initializes various data structures.
1773 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001774static int __init iucv_init(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001775{
1776 int rc;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001777 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001778
1779 if (!MACHINE_IS_VM) {
1780 rc = -EPROTONOSUPPORT;
1781 goto out;
1782 }
1783 rc = iucv_query_maxconn();
1784 if (rc)
1785 goto out;
Heiko Carstensda99f052007-05-04 12:23:27 -07001786 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001787 if (rc)
1788 goto out;
Mark McLoughlin035da162008-12-15 12:58:29 +00001789 iucv_root = root_device_register("iucv");
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001790 if (IS_ERR(iucv_root)) {
1791 rc = PTR_ERR(iucv_root);
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001792 goto out_int;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001793 }
Christoph Lameter70cf50352007-11-20 11:13:38 +01001794
1795 for_each_online_cpu(cpu) {
1796 /* Note: GFP_DMA used to get memory below 2G */
1797 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1798 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1799 if (!iucv_irq_data[cpu]) {
1800 rc = -ENOMEM;
1801 goto out_free;
1802 }
1803
1804 /* Allocate parameter blocks. */
1805 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1806 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1807 if (!iucv_param[cpu]) {
1808 rc = -ENOMEM;
1809 goto out_free;
1810 }
Ursula Braun42e1b4c2009-04-21 23:26:20 +00001811 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
1812 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1813 if (!iucv_param_irq[cpu]) {
1814 rc = -ENOMEM;
1815 goto out_free;
1816 }
1817
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001818 }
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001819 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1820 if (rc)
1821 goto out_free;
Ursula Braun6c005962009-06-16 10:30:41 +02001822 rc = register_reboot_notifier(&iucv_reboot_notifier);
1823 if (rc)
1824 goto out_cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001825 ASCEBC(iucv_error_no_listener, 16);
1826 ASCEBC(iucv_error_no_memory, 16);
1827 ASCEBC(iucv_error_pathid, 16);
1828 iucv_available = 1;
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001829 rc = bus_register(&iucv_bus);
1830 if (rc)
Ursula Braun6c005962009-06-16 10:30:41 +02001831 goto out_reboot;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001832 return 0;
1833
Ursula Braun6c005962009-06-16 10:30:41 +02001834out_reboot:
1835 unregister_reboot_notifier(&iucv_reboot_notifier);
Cornelia Huck2d7bf362008-04-10 02:12:45 -07001836out_cpu:
1837 unregister_hotcpu_notifier(&iucv_cpu_notifier);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001838out_free:
1839 for_each_possible_cpu(cpu) {
Ursula Braun42e1b4c2009-04-21 23:26:20 +00001840 kfree(iucv_param_irq[cpu]);
1841 iucv_param_irq[cpu] = NULL;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001842 kfree(iucv_param[cpu]);
1843 iucv_param[cpu] = NULL;
1844 kfree(iucv_irq_data[cpu]);
1845 iucv_irq_data[cpu] = NULL;
1846 }
Mark McLoughlin035da162008-12-15 12:58:29 +00001847 root_device_unregister(iucv_root);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001848out_int:
1849 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1850out:
1851 return rc;
1852}
1853
1854/**
1855 * iucv_exit
1856 *
1857 * Frees everything allocated from iucv_init.
1858 */
Heiko Carstensda99f052007-05-04 12:23:27 -07001859static void __exit iucv_exit(void)
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001860{
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001861 struct iucv_irq_list *p, *n;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001862 int cpu;
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001863
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001864 spin_lock_irq(&iucv_queue_lock);
1865 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1866 kfree(p);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001867 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1868 kfree(p);
Martin Schwidefsky04b090d2007-04-28 23:03:59 -07001869 spin_unlock_irq(&iucv_queue_lock);
Ursula Braun6c005962009-06-16 10:30:41 +02001870 unregister_reboot_notifier(&iucv_reboot_notifier);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001871 unregister_hotcpu_notifier(&iucv_cpu_notifier);
Christoph Lameter70cf50352007-11-20 11:13:38 +01001872 for_each_possible_cpu(cpu) {
Ursula Braun42e1b4c2009-04-21 23:26:20 +00001873 kfree(iucv_param_irq[cpu]);
1874 iucv_param_irq[cpu] = NULL;
Christoph Lameter70cf50352007-11-20 11:13:38 +01001875 kfree(iucv_param[cpu]);
1876 iucv_param[cpu] = NULL;
1877 kfree(iucv_irq_data[cpu]);
1878 iucv_irq_data[cpu] = NULL;
1879 }
Mark McLoughlin035da162008-12-15 12:58:29 +00001880 root_device_unregister(iucv_root);
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001881 bus_unregister(&iucv_bus);
1882 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1883}
1884
1885subsys_initcall(iucv_init);
1886module_exit(iucv_exit);
1887
Martin Schwidefsky2356f4c2007-02-08 13:37:42 -08001888MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1889MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1890MODULE_LICENSE("GPL");