Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6/verdex.git] / net / iucv / iucv.c
bloba598c73848401a215216a6f76ee3d5f0836f520e
1 /*
2 * IUCV base infrastructure.
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>
14 * Documentation used:
15 * The original source
16 * CP Programming Service, IBM document # SC24-5760
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.
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.
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.
33 #include <linux/module.h>
34 #include <linux/moduleparam.h>
35 #include <linux/spinlock.h>
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/init.h>
39 #include <linux/interrupt.h>
40 #include <linux/list.h>
41 #include <linux/errno.h>
42 #include <linux/err.h>
43 #include <linux/device.h>
44 #include <linux/cpu.h>
45 #include <net/iucv/iucv.h>
46 #include <asm/atomic.h>
47 #include <asm/ebcdic.h>
48 #include <asm/io.h>
49 #include <asm/s390_ext.h>
50 #include <asm/s390_rdev.h>
51 #include <asm/smp.h>
54 * FLAGS:
55 * All flags are defined in the field IPFLAGS1 of each function
56 * and can be found in CP Programming Services.
57 * IPSRCCLS - Indicates you have specified a source class.
58 * IPTRGCLS - Indicates you have specified a target class.
59 * IPFGPID - Indicates you have specified a pathid.
60 * IPFGMID - Indicates you have specified a message ID.
61 * IPNORPY - Indicates a one-way message. No reply expected.
62 * IPALL - Indicates that all paths are affected.
64 #define IUCV_IPSRCCLS 0x01
65 #define IUCV_IPTRGCLS 0x01
66 #define IUCV_IPFGPID 0x02
67 #define IUCV_IPFGMID 0x04
68 #define IUCV_IPNORPY 0x10
69 #define IUCV_IPALL 0x80
71 static int iucv_bus_match(struct device *dev, struct device_driver *drv)
73 return 0;
76 struct bus_type iucv_bus = {
77 .name = "iucv",
78 .match = iucv_bus_match,
80 EXPORT_SYMBOL(iucv_bus);
82 struct device *iucv_root;
83 EXPORT_SYMBOL(iucv_root);
85 static int iucv_available;
87 /* General IUCV interrupt structure */
88 struct iucv_irq_data {
89 u16 ippathid;
90 u8 ipflags1;
91 u8 iptype;
92 u32 res2[8];
95 struct iucv_irq_list {
96 struct list_head list;
97 struct iucv_irq_data data;
100 static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
101 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
102 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
105 * Queue of interrupt buffers lock for delivery via the tasklet
106 * (fast but can't call smp_call_function).
108 static LIST_HEAD(iucv_task_queue);
111 * The tasklet for fast delivery of iucv interrupts.
113 static void iucv_tasklet_fn(unsigned long);
114 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
117 * Queue of interrupt buffers for delivery via a work queue
118 * (slower but can call smp_call_function).
120 static LIST_HEAD(iucv_work_queue);
123 * The work element to deliver path pending interrupts.
125 static void iucv_work_fn(struct work_struct *work);
126 static DECLARE_WORK(iucv_work, iucv_work_fn);
129 * Spinlock protecting task and work queue.
131 static DEFINE_SPINLOCK(iucv_queue_lock);
133 enum iucv_command_codes {
134 IUCV_QUERY = 0,
135 IUCV_RETRIEVE_BUFFER = 2,
136 IUCV_SEND = 4,
137 IUCV_RECEIVE = 5,
138 IUCV_REPLY = 6,
139 IUCV_REJECT = 8,
140 IUCV_PURGE = 9,
141 IUCV_ACCEPT = 10,
142 IUCV_CONNECT = 11,
143 IUCV_DECLARE_BUFFER = 12,
144 IUCV_QUIESCE = 13,
145 IUCV_RESUME = 14,
146 IUCV_SEVER = 15,
147 IUCV_SETMASK = 16,
151 * Error messages that are used with the iucv_sever function. They get
152 * converted to EBCDIC.
154 static char iucv_error_no_listener[16] = "NO LISTENER";
155 static char iucv_error_no_memory[16] = "NO MEMORY";
156 static char iucv_error_pathid[16] = "INVALID PATHID";
159 * iucv_handler_list: List of registered handlers.
161 static LIST_HEAD(iucv_handler_list);
164 * iucv_path_table: an array of iucv_path structures.
166 static struct iucv_path **iucv_path_table;
167 static unsigned long iucv_max_pathid;
170 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
172 static DEFINE_SPINLOCK(iucv_table_lock);
175 * iucv_active_cpu: contains the number of the cpu executing the tasklet
176 * or the work handler. Needed for iucv_path_sever called from tasklet.
178 static int iucv_active_cpu = -1;
181 * Mutex and wait queue for iucv_register/iucv_unregister.
183 static DEFINE_MUTEX(iucv_register_mutex);
186 * Counter for number of non-smp capable handlers.
188 static int iucv_nonsmp_handler;
191 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
192 * iucv_path_quiesce and iucv_path_sever.
194 struct iucv_cmd_control {
195 u16 ippathid;
196 u8 ipflags1;
197 u8 iprcode;
198 u16 ipmsglim;
199 u16 res1;
200 u8 ipvmid[8];
201 u8 ipuser[16];
202 u8 iptarget[8];
203 } __attribute__ ((packed,aligned(8)));
206 * Data in parameter list iucv structure. Used by iucv_message_send,
207 * iucv_message_send2way and iucv_message_reply.
209 struct iucv_cmd_dpl {
210 u16 ippathid;
211 u8 ipflags1;
212 u8 iprcode;
213 u32 ipmsgid;
214 u32 iptrgcls;
215 u8 iprmmsg[8];
216 u32 ipsrccls;
217 u32 ipmsgtag;
218 u32 ipbfadr2;
219 u32 ipbfln2f;
220 u32 res;
221 } __attribute__ ((packed,aligned(8)));
224 * Data in buffer iucv structure. Used by iucv_message_receive,
225 * iucv_message_reject, iucv_message_send, iucv_message_send2way
226 * and iucv_declare_cpu.
228 struct iucv_cmd_db {
229 u16 ippathid;
230 u8 ipflags1;
231 u8 iprcode;
232 u32 ipmsgid;
233 u32 iptrgcls;
234 u32 ipbfadr1;
235 u32 ipbfln1f;
236 u32 ipsrccls;
237 u32 ipmsgtag;
238 u32 ipbfadr2;
239 u32 ipbfln2f;
240 u32 res;
241 } __attribute__ ((packed,aligned(8)));
244 * Purge message iucv structure. Used by iucv_message_purge.
246 struct iucv_cmd_purge {
247 u16 ippathid;
248 u8 ipflags1;
249 u8 iprcode;
250 u32 ipmsgid;
251 u8 ipaudit[3];
252 u8 res1[5];
253 u32 res2;
254 u32 ipsrccls;
255 u32 ipmsgtag;
256 u32 res3[3];
257 } __attribute__ ((packed,aligned(8)));
260 * Set mask iucv structure. Used by iucv_enable_cpu.
262 struct iucv_cmd_set_mask {
263 u8 ipmask;
264 u8 res1[2];
265 u8 iprcode;
266 u32 res2[9];
267 } __attribute__ ((packed,aligned(8)));
269 union iucv_param {
270 struct iucv_cmd_control ctrl;
271 struct iucv_cmd_dpl dpl;
272 struct iucv_cmd_db db;
273 struct iucv_cmd_purge purge;
274 struct iucv_cmd_set_mask set_mask;
278 * Anchor for per-cpu IUCV command parameter block.
280 static union iucv_param *iucv_param[NR_CPUS];
283 * iucv_call_b2f0
284 * @code: identifier of IUCV call to CP.
285 * @parm: pointer to a struct iucv_parm block
287 * Calls CP to execute IUCV commands.
289 * Returns the result of the CP IUCV call.
291 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
293 register unsigned long reg0 asm ("0");
294 register unsigned long reg1 asm ("1");
295 int ccode;
297 reg0 = command;
298 reg1 = virt_to_phys(parm);
299 asm volatile(
300 " .long 0xb2f01000\n"
301 " ipm %0\n"
302 " srl %0,28\n"
303 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
304 : "m" (*parm) : "cc");
305 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
309 * iucv_query_maxconn
311 * Determines the maximum number of connections that may be established.
313 * Returns the maximum number of connections or -EPERM is IUCV is not
314 * available.
316 static int iucv_query_maxconn(void)
318 register unsigned long reg0 asm ("0");
319 register unsigned long reg1 asm ("1");
320 void *param;
321 int ccode;
323 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
324 if (!param)
325 return -ENOMEM;
326 reg0 = IUCV_QUERY;
327 reg1 = (unsigned long) param;
328 asm volatile (
329 " .long 0xb2f01000\n"
330 " ipm %0\n"
331 " srl %0,28\n"
332 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
333 if (ccode == 0)
334 iucv_max_pathid = reg0;
335 kfree(param);
336 return ccode ? -EPERM : 0;
340 * iucv_allow_cpu
341 * @data: unused
343 * Allow iucv interrupts on this cpu.
345 static void iucv_allow_cpu(void *data)
347 int cpu = smp_processor_id();
348 union iucv_param *parm;
351 * Enable all iucv interrupts.
352 * ipmask contains bits for the different interrupts
353 * 0x80 - Flag to allow nonpriority message pending interrupts
354 * 0x40 - Flag to allow priority message pending interrupts
355 * 0x20 - Flag to allow nonpriority message completion interrupts
356 * 0x10 - Flag to allow priority message completion interrupts
357 * 0x08 - Flag to allow IUCV control interrupts
359 parm = iucv_param[cpu];
360 memset(parm, 0, sizeof(union iucv_param));
361 parm->set_mask.ipmask = 0xf8;
362 iucv_call_b2f0(IUCV_SETMASK, parm);
364 /* Set indication that iucv interrupts are allowed for this cpu. */
365 cpu_set(cpu, iucv_irq_cpumask);
369 * iucv_block_cpu
370 * @data: unused
372 * Block iucv interrupts on this cpu.
374 static void iucv_block_cpu(void *data)
376 int cpu = smp_processor_id();
377 union iucv_param *parm;
379 /* Disable all iucv interrupts. */
380 parm = iucv_param[cpu];
381 memset(parm, 0, sizeof(union iucv_param));
382 iucv_call_b2f0(IUCV_SETMASK, parm);
384 /* Clear indication that iucv interrupts are allowed for this cpu. */
385 cpu_clear(cpu, iucv_irq_cpumask);
389 * iucv_declare_cpu
390 * @data: unused
392 * Declare a interrupt buffer on this cpu.
394 static void iucv_declare_cpu(void *data)
396 int cpu = smp_processor_id();
397 union iucv_param *parm;
398 int rc;
400 if (cpu_isset(cpu, iucv_buffer_cpumask))
401 return;
403 /* Declare interrupt buffer. */
404 parm = iucv_param[cpu];
405 memset(parm, 0, sizeof(union iucv_param));
406 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
407 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
408 if (rc) {
409 char *err = "Unknown";
410 switch (rc) {
411 case 0x03:
412 err = "Directory error";
413 break;
414 case 0x0a:
415 err = "Invalid length";
416 break;
417 case 0x13:
418 err = "Buffer already exists";
419 break;
420 case 0x3e:
421 err = "Buffer overlap";
422 break;
423 case 0x5c:
424 err = "Paging or storage error";
425 break;
427 printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
428 "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
429 return;
432 /* Set indication that an iucv buffer exists for this cpu. */
433 cpu_set(cpu, iucv_buffer_cpumask);
435 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
436 /* Enable iucv interrupts on this cpu. */
437 iucv_allow_cpu(NULL);
438 else
439 /* Disable iucv interrupts on this cpu. */
440 iucv_block_cpu(NULL);
444 * iucv_retrieve_cpu
445 * @data: unused
447 * Retrieve interrupt buffer on this cpu.
449 static void iucv_retrieve_cpu(void *data)
451 int cpu = smp_processor_id();
452 union iucv_param *parm;
454 if (!cpu_isset(cpu, iucv_buffer_cpumask))
455 return;
457 /* Block iucv interrupts. */
458 iucv_block_cpu(NULL);
460 /* Retrieve interrupt buffer. */
461 parm = iucv_param[cpu];
462 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
464 /* Clear indication that an iucv buffer exists for this cpu. */
465 cpu_clear(cpu, iucv_buffer_cpumask);
469 * iucv_setmask_smp
471 * Allow iucv interrupts on all cpus.
473 static void iucv_setmask_mp(void)
475 int cpu;
477 get_online_cpus();
478 for_each_online_cpu(cpu)
479 /* Enable all cpus with a declared buffer. */
480 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
481 !cpu_isset(cpu, iucv_irq_cpumask))
482 smp_call_function_single(cpu, iucv_allow_cpu,
483 NULL, 1);
484 put_online_cpus();
488 * iucv_setmask_up
490 * Allow iucv interrupts on a single cpu.
492 static void iucv_setmask_up(void)
494 cpumask_t cpumask;
495 int cpu;
497 /* Disable all cpu but the first in cpu_irq_cpumask. */
498 cpumask = iucv_irq_cpumask;
499 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
500 for_each_cpu_mask(cpu, cpumask)
501 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
505 * iucv_enable
507 * This function makes iucv ready for use. It allocates the pathid
508 * table, declares an iucv interrupt buffer and enables the iucv
509 * interrupts. Called when the first user has registered an iucv
510 * handler.
512 static int iucv_enable(void)
514 size_t alloc_size;
515 int cpu, rc;
517 rc = -ENOMEM;
518 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
519 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
520 if (!iucv_path_table)
521 goto out;
522 /* Declare per cpu buffers. */
523 rc = -EIO;
524 get_online_cpus();
525 for_each_online_cpu(cpu)
526 <<<<<<< HEAD:net/iucv/iucv.c
527 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
528 =======
529 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
530 preempt_enable();
531 >>>>>>> 5b664cb235e97afbf34db9c4d77f08ebd725335e:net/iucv/iucv.c
532 if (cpus_empty(iucv_buffer_cpumask))
533 /* No cpu could declare an iucv buffer. */
534 goto out_path;
535 put_online_cpus();
536 return 0;
538 out_path:
539 put_online_cpus();
540 kfree(iucv_path_table);
541 out:
542 return rc;
546 * iucv_disable
548 * This function shuts down iucv. It disables iucv interrupts, retrieves
549 * the iucv interrupt buffer and frees the pathid table. Called after the
550 * last user unregister its iucv handler.
552 static void iucv_disable(void)
554 <<<<<<< HEAD:net/iucv/iucv.c
555 get_online_cpus();
556 on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
557 put_online_cpus();
558 =======
559 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
560 >>>>>>> 5b664cb235e97afbf34db9c4d77f08ebd725335e:net/iucv/iucv.c
561 kfree(iucv_path_table);
564 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
565 unsigned long action, void *hcpu)
567 cpumask_t cpumask;
568 long cpu = (long) hcpu;
570 switch (action) {
571 case CPU_UP_PREPARE:
572 case CPU_UP_PREPARE_FROZEN:
573 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
574 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
575 if (!iucv_irq_data[cpu])
576 return NOTIFY_BAD;
577 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
578 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
579 if (!iucv_param[cpu]) {
580 kfree(iucv_irq_data[cpu]);
581 iucv_irq_data[cpu] = NULL;
582 return NOTIFY_BAD;
584 break;
585 case CPU_UP_CANCELED:
586 case CPU_UP_CANCELED_FROZEN:
587 case CPU_DEAD:
588 case CPU_DEAD_FROZEN:
589 kfree(iucv_param[cpu]);
590 iucv_param[cpu] = NULL;
591 kfree(iucv_irq_data[cpu]);
592 iucv_irq_data[cpu] = NULL;
593 break;
594 case CPU_ONLINE:
595 case CPU_ONLINE_FROZEN:
596 case CPU_DOWN_FAILED:
597 case CPU_DOWN_FAILED_FROZEN:
598 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
599 break;
600 case CPU_DOWN_PREPARE:
601 case CPU_DOWN_PREPARE_FROZEN:
602 cpumask = iucv_buffer_cpumask;
603 cpu_clear(cpu, cpumask);
604 if (cpus_empty(cpumask))
605 /* Can't offline last IUCV enabled cpu. */
606 return NOTIFY_BAD;
607 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
608 if (cpus_empty(iucv_irq_cpumask))
609 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
610 iucv_allow_cpu, NULL, 1);
611 break;
613 return NOTIFY_OK;
616 static struct notifier_block __refdata iucv_cpu_notifier = {
617 .notifier_call = iucv_cpu_notify,
621 * iucv_sever_pathid
622 * @pathid: path identification number.
623 * @userdata: 16-bytes of user data.
625 * Sever an iucv path to free up the pathid. Used internally.
627 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
629 union iucv_param *parm;
631 parm = iucv_param[smp_processor_id()];
632 memset(parm, 0, sizeof(union iucv_param));
633 if (userdata)
634 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
635 parm->ctrl.ippathid = pathid;
636 return iucv_call_b2f0(IUCV_SEVER, parm);
640 * __iucv_cleanup_queue
641 * @dummy: unused dummy argument
643 * Nop function called via smp_call_function to force work items from
644 * pending external iucv interrupts to the work queue.
646 static void __iucv_cleanup_queue(void *dummy)
651 * iucv_cleanup_queue
653 * Function called after a path has been severed to find all remaining
654 * work items for the now stale pathid. The caller needs to hold the
655 * iucv_table_lock.
657 static void iucv_cleanup_queue(void)
659 struct iucv_irq_list *p, *n;
662 * When a path is severed, the pathid can be reused immediatly
663 * on a iucv connect or a connection pending interrupt. Remove
664 * all entries from the task queue that refer to a stale pathid
665 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
666 * or deliver the connection pending interrupt. To get all the
667 * pending interrupts force them to the work queue by calling
668 * an empty function on all cpus.
670 smp_call_function(__iucv_cleanup_queue, NULL, 1);
671 spin_lock_irq(&iucv_queue_lock);
672 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
673 /* Remove stale work items from the task queue. */
674 if (iucv_path_table[p->data.ippathid] == NULL) {
675 list_del(&p->list);
676 kfree(p);
679 spin_unlock_irq(&iucv_queue_lock);
683 * iucv_register:
684 * @handler: address of iucv handler structure
685 * @smp: != 0 indicates that the handler can deal with out of order messages
687 * Registers a driver with IUCV.
689 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
690 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
692 int iucv_register(struct iucv_handler *handler, int smp)
694 int rc;
696 if (!iucv_available)
697 return -ENOSYS;
698 mutex_lock(&iucv_register_mutex);
699 if (!smp)
700 iucv_nonsmp_handler++;
701 if (list_empty(&iucv_handler_list)) {
702 rc = iucv_enable();
703 if (rc)
704 goto out_mutex;
705 } else if (!smp && iucv_nonsmp_handler == 1)
706 iucv_setmask_up();
707 INIT_LIST_HEAD(&handler->paths);
709 spin_lock_bh(&iucv_table_lock);
710 list_add_tail(&handler->list, &iucv_handler_list);
711 spin_unlock_bh(&iucv_table_lock);
712 rc = 0;
713 out_mutex:
714 mutex_unlock(&iucv_register_mutex);
715 return rc;
717 EXPORT_SYMBOL(iucv_register);
720 * iucv_unregister
721 * @handler: address of iucv handler structure
722 * @smp: != 0 indicates that the handler can deal with out of order messages
724 * Unregister driver from IUCV.
726 void iucv_unregister(struct iucv_handler *handler, int smp)
728 struct iucv_path *p, *n;
730 mutex_lock(&iucv_register_mutex);
731 spin_lock_bh(&iucv_table_lock);
732 /* Remove handler from the iucv_handler_list. */
733 list_del_init(&handler->list);
734 /* Sever all pathids still refering to the handler. */
735 list_for_each_entry_safe(p, n, &handler->paths, list) {
736 iucv_sever_pathid(p->pathid, NULL);
737 iucv_path_table[p->pathid] = NULL;
738 list_del(&p->list);
739 iucv_path_free(p);
741 spin_unlock_bh(&iucv_table_lock);
742 if (!smp)
743 iucv_nonsmp_handler--;
744 if (list_empty(&iucv_handler_list))
745 iucv_disable();
746 else if (!smp && iucv_nonsmp_handler == 0)
747 iucv_setmask_mp();
748 mutex_unlock(&iucv_register_mutex);
750 EXPORT_SYMBOL(iucv_unregister);
753 * iucv_path_accept
754 * @path: address of iucv path structure
755 * @handler: address of iucv handler structure
756 * @userdata: 16 bytes of data reflected to the communication partner
757 * @private: private data passed to interrupt handlers for this path
759 * This function is issued after the user received a connection pending
760 * external interrupt and now wishes to complete the IUCV communication path.
762 * Returns the result of the CP IUCV call.
764 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
765 u8 userdata[16], void *private)
767 union iucv_param *parm;
768 int rc;
770 local_bh_disable();
771 /* Prepare parameter block. */
772 parm = iucv_param[smp_processor_id()];
773 memset(parm, 0, sizeof(union iucv_param));
774 parm->ctrl.ippathid = path->pathid;
775 parm->ctrl.ipmsglim = path->msglim;
776 if (userdata)
777 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
778 parm->ctrl.ipflags1 = path->flags;
780 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
781 if (!rc) {
782 path->private = private;
783 path->msglim = parm->ctrl.ipmsglim;
784 path->flags = parm->ctrl.ipflags1;
786 local_bh_enable();
787 return rc;
789 EXPORT_SYMBOL(iucv_path_accept);
792 * iucv_path_connect
793 * @path: address of iucv path structure
794 * @handler: address of iucv handler structure
795 * @userid: 8-byte user identification
796 * @system: 8-byte target system identification
797 * @userdata: 16 bytes of data reflected to the communication partner
798 * @private: private data passed to interrupt handlers for this path
800 * This function establishes an IUCV path. Although the connect may complete
801 * successfully, you are not able to use the path until you receive an IUCV
802 * Connection Complete external interrupt.
804 * Returns the result of the CP IUCV call.
806 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
807 u8 userid[8], u8 system[8], u8 userdata[16],
808 void *private)
810 union iucv_param *parm;
811 int rc;
813 spin_lock_bh(&iucv_table_lock);
814 iucv_cleanup_queue();
815 parm = iucv_param[smp_processor_id()];
816 memset(parm, 0, sizeof(union iucv_param));
817 parm->ctrl.ipmsglim = path->msglim;
818 parm->ctrl.ipflags1 = path->flags;
819 if (userid) {
820 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
821 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
822 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
824 if (system) {
825 memcpy(parm->ctrl.iptarget, system,
826 sizeof(parm->ctrl.iptarget));
827 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
828 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
830 if (userdata)
831 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
833 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
834 if (!rc) {
835 if (parm->ctrl.ippathid < iucv_max_pathid) {
836 path->pathid = parm->ctrl.ippathid;
837 path->msglim = parm->ctrl.ipmsglim;
838 path->flags = parm->ctrl.ipflags1;
839 path->handler = handler;
840 path->private = private;
841 list_add_tail(&path->list, &handler->paths);
842 iucv_path_table[path->pathid] = path;
843 } else {
844 iucv_sever_pathid(parm->ctrl.ippathid,
845 iucv_error_pathid);
846 rc = -EIO;
849 spin_unlock_bh(&iucv_table_lock);
850 return rc;
852 EXPORT_SYMBOL(iucv_path_connect);
855 * iucv_path_quiesce:
856 * @path: address of iucv path structure
857 * @userdata: 16 bytes of data reflected to the communication partner
859 * This function temporarily suspends incoming messages on an IUCV path.
860 * You can later reactivate the path by invoking the iucv_resume function.
862 * Returns the result from the CP IUCV call.
864 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
866 union iucv_param *parm;
867 int rc;
869 local_bh_disable();
870 parm = iucv_param[smp_processor_id()];
871 memset(parm, 0, sizeof(union iucv_param));
872 if (userdata)
873 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
874 parm->ctrl.ippathid = path->pathid;
875 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
876 local_bh_enable();
877 return rc;
879 EXPORT_SYMBOL(iucv_path_quiesce);
882 * iucv_path_resume:
883 * @path: address of iucv path structure
884 * @userdata: 16 bytes of data reflected to the communication partner
886 * This function resumes incoming messages on an IUCV path that has
887 * been stopped with iucv_path_quiesce.
889 * Returns the result from the CP IUCV call.
891 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
893 union iucv_param *parm;
894 int rc;
896 local_bh_disable();
897 parm = iucv_param[smp_processor_id()];
898 memset(parm, 0, sizeof(union iucv_param));
899 if (userdata)
900 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
901 parm->ctrl.ippathid = path->pathid;
902 rc = iucv_call_b2f0(IUCV_RESUME, parm);
903 local_bh_enable();
904 return rc;
908 * iucv_path_sever
909 * @path: address of iucv path structure
910 * @userdata: 16 bytes of data reflected to the communication partner
912 * This function terminates an IUCV path.
914 * Returns the result from the CP IUCV call.
916 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
918 int rc;
920 preempt_disable();
921 if (iucv_active_cpu != smp_processor_id())
922 spin_lock_bh(&iucv_table_lock);
923 rc = iucv_sever_pathid(path->pathid, userdata);
924 if (!rc) {
925 iucv_path_table[path->pathid] = NULL;
926 list_del_init(&path->list);
928 if (iucv_active_cpu != smp_processor_id())
929 spin_unlock_bh(&iucv_table_lock);
930 preempt_enable();
931 return rc;
933 EXPORT_SYMBOL(iucv_path_sever);
936 * iucv_message_purge
937 * @path: address of iucv path structure
938 * @msg: address of iucv msg structure
939 * @srccls: source class of message
941 * Cancels a message you have sent.
943 * Returns the result from the CP IUCV call.
945 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
946 u32 srccls)
948 union iucv_param *parm;
949 int rc;
951 local_bh_disable();
952 parm = iucv_param[smp_processor_id()];
953 memset(parm, 0, sizeof(union iucv_param));
954 parm->purge.ippathid = path->pathid;
955 parm->purge.ipmsgid = msg->id;
956 parm->purge.ipsrccls = srccls;
957 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
958 rc = iucv_call_b2f0(IUCV_PURGE, parm);
959 if (!rc) {
960 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
961 msg->tag = parm->purge.ipmsgtag;
963 local_bh_enable();
964 return rc;
966 EXPORT_SYMBOL(iucv_message_purge);
969 * iucv_message_receive
970 * @path: address of iucv path structure
971 * @msg: address of iucv msg structure
972 * @flags: how the message is received (IUCV_IPBUFLST)
973 * @buffer: address of data buffer or address of struct iucv_array
974 * @size: length of data buffer
975 * @residual:
977 * This function receives messages that are being sent to you over
978 * established paths. This function will deal with RMDATA messages
979 * embedded in struct iucv_message as well.
981 * Returns the result from the CP IUCV call.
983 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
984 u8 flags, void *buffer, size_t size, size_t *residual)
986 union iucv_param *parm;
987 struct iucv_array *array;
988 u8 *rmmsg;
989 size_t copy;
990 int rc;
992 if (msg->flags & IUCV_IPRMDATA) {
994 * Message is 8 bytes long and has been stored to the
995 * message descriptor itself.
997 rc = (size < 8) ? 5 : 0;
998 if (residual)
999 *residual = abs(size - 8);
1000 rmmsg = msg->rmmsg;
1001 if (flags & IUCV_IPBUFLST) {
1002 /* Copy to struct iucv_array. */
1003 size = (size < 8) ? size : 8;
1004 for (array = buffer; size > 0; array++) {
1005 copy = min_t(size_t, size, array->length);
1006 memcpy((u8 *)(addr_t) array->address,
1007 rmmsg, copy);
1008 rmmsg += copy;
1009 size -= copy;
1011 } else {
1012 /* Copy to direct buffer. */
1013 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1015 return 0;
1018 local_bh_disable();
1019 parm = iucv_param[smp_processor_id()];
1020 memset(parm, 0, sizeof(union iucv_param));
1021 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1022 parm->db.ipbfln1f = (u32) size;
1023 parm->db.ipmsgid = msg->id;
1024 parm->db.ippathid = path->pathid;
1025 parm->db.iptrgcls = msg->class;
1026 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1027 IUCV_IPFGMID | IUCV_IPTRGCLS);
1028 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1029 if (!rc || rc == 5) {
1030 msg->flags = parm->db.ipflags1;
1031 if (residual)
1032 *residual = parm->db.ipbfln1f;
1034 local_bh_enable();
1035 return rc;
1037 EXPORT_SYMBOL(iucv_message_receive);
1040 * iucv_message_reject
1041 * @path: address of iucv path structure
1042 * @msg: address of iucv msg structure
1044 * The reject function refuses a specified message. Between the time you
1045 * are notified of a message and the time that you complete the message,
1046 * the message may be rejected.
1048 * Returns the result from the CP IUCV call.
1050 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1052 union iucv_param *parm;
1053 int rc;
1055 local_bh_disable();
1056 parm = iucv_param[smp_processor_id()];
1057 memset(parm, 0, sizeof(union iucv_param));
1058 parm->db.ippathid = path->pathid;
1059 parm->db.ipmsgid = msg->id;
1060 parm->db.iptrgcls = msg->class;
1061 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1062 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1063 local_bh_enable();
1064 return rc;
1066 EXPORT_SYMBOL(iucv_message_reject);
1069 * iucv_message_reply
1070 * @path: address of iucv path structure
1071 * @msg: address of iucv msg structure
1072 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1073 * @reply: address of reply data buffer or address of struct iucv_array
1074 * @size: length of reply data buffer
1076 * This function responds to the two-way messages that you receive. You
1077 * must identify completely the message to which you wish to reply. ie,
1078 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1079 * the parameter list.
1081 * Returns the result from the CP IUCV call.
1083 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1084 u8 flags, void *reply, size_t size)
1086 union iucv_param *parm;
1087 int rc;
1089 local_bh_disable();
1090 parm = iucv_param[smp_processor_id()];
1091 memset(parm, 0, sizeof(union iucv_param));
1092 if (flags & IUCV_IPRMDATA) {
1093 parm->dpl.ippathid = path->pathid;
1094 parm->dpl.ipflags1 = flags;
1095 parm->dpl.ipmsgid = msg->id;
1096 parm->dpl.iptrgcls = msg->class;
1097 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1098 } else {
1099 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1100 parm->db.ipbfln1f = (u32) size;
1101 parm->db.ippathid = path->pathid;
1102 parm->db.ipflags1 = flags;
1103 parm->db.ipmsgid = msg->id;
1104 parm->db.iptrgcls = msg->class;
1106 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1107 local_bh_enable();
1108 return rc;
1110 EXPORT_SYMBOL(iucv_message_reply);
1113 * iucv_message_send
1114 * @path: address of iucv path structure
1115 * @msg: address of iucv msg structure
1116 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1117 * @srccls: source class of message
1118 * @buffer: address of send buffer or address of struct iucv_array
1119 * @size: length of send buffer
1121 * This function transmits data to another application. Data to be
1122 * transmitted is in a buffer and this is a one-way message and the
1123 * receiver will not reply to the message.
1125 * Returns the result from the CP IUCV call.
1127 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1128 u8 flags, u32 srccls, void *buffer, size_t size)
1130 union iucv_param *parm;
1131 int rc;
1133 local_bh_disable();
1134 parm = iucv_param[smp_processor_id()];
1135 memset(parm, 0, sizeof(union iucv_param));
1136 if (flags & IUCV_IPRMDATA) {
1137 /* Message of 8 bytes can be placed into the parameter list. */
1138 parm->dpl.ippathid = path->pathid;
1139 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1140 parm->dpl.iptrgcls = msg->class;
1141 parm->dpl.ipsrccls = srccls;
1142 parm->dpl.ipmsgtag = msg->tag;
1143 memcpy(parm->dpl.iprmmsg, buffer, 8);
1144 } else {
1145 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1146 parm->db.ipbfln1f = (u32) size;
1147 parm->db.ippathid = path->pathid;
1148 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1149 parm->db.iptrgcls = msg->class;
1150 parm->db.ipsrccls = srccls;
1151 parm->db.ipmsgtag = msg->tag;
1153 rc = iucv_call_b2f0(IUCV_SEND, parm);
1154 if (!rc)
1155 msg->id = parm->db.ipmsgid;
1156 local_bh_enable();
1157 return rc;
1159 EXPORT_SYMBOL(iucv_message_send);
1162 * iucv_message_send2way
1163 * @path: address of iucv path structure
1164 * @msg: address of iucv msg structure
1165 * @flags: how the message is sent and the reply is received
1166 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1167 * @srccls: source class of message
1168 * @buffer: address of send buffer or address of struct iucv_array
1169 * @size: length of send buffer
1170 * @ansbuf: address of answer buffer or address of struct iucv_array
1171 * @asize: size of reply buffer
1173 * This function transmits data to another application. Data to be
1174 * transmitted is in a buffer. The receiver of the send is expected to
1175 * reply to the message and a buffer is provided into which IUCV moves
1176 * the reply to this message.
1178 * Returns the result from the CP IUCV call.
1180 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1181 u8 flags, u32 srccls, void *buffer, size_t size,
1182 void *answer, size_t asize, size_t *residual)
1184 union iucv_param *parm;
1185 int rc;
1187 local_bh_disable();
1188 parm = iucv_param[smp_processor_id()];
1189 memset(parm, 0, sizeof(union iucv_param));
1190 if (flags & IUCV_IPRMDATA) {
1191 parm->dpl.ippathid = path->pathid;
1192 parm->dpl.ipflags1 = path->flags; /* priority message */
1193 parm->dpl.iptrgcls = msg->class;
1194 parm->dpl.ipsrccls = srccls;
1195 parm->dpl.ipmsgtag = msg->tag;
1196 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1197 parm->dpl.ipbfln2f = (u32) asize;
1198 memcpy(parm->dpl.iprmmsg, buffer, 8);
1199 } else {
1200 parm->db.ippathid = path->pathid;
1201 parm->db.ipflags1 = path->flags; /* priority message */
1202 parm->db.iptrgcls = msg->class;
1203 parm->db.ipsrccls = srccls;
1204 parm->db.ipmsgtag = msg->tag;
1205 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1206 parm->db.ipbfln1f = (u32) size;
1207 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1208 parm->db.ipbfln2f = (u32) asize;
1210 rc = iucv_call_b2f0(IUCV_SEND, parm);
1211 if (!rc)
1212 msg->id = parm->db.ipmsgid;
1213 local_bh_enable();
1214 return rc;
1216 EXPORT_SYMBOL(iucv_message_send2way);
1219 * iucv_path_pending
1220 * @data: Pointer to external interrupt buffer
1222 * Process connection pending work item. Called from tasklet while holding
1223 * iucv_table_lock.
1225 struct iucv_path_pending {
1226 u16 ippathid;
1227 u8 ipflags1;
1228 u8 iptype;
1229 u16 ipmsglim;
1230 u16 res1;
1231 u8 ipvmid[8];
1232 u8 ipuser[16];
1233 u32 res3;
1234 u8 ippollfg;
1235 u8 res4[3];
1236 } __attribute__ ((packed));
1238 static void iucv_path_pending(struct iucv_irq_data *data)
1240 struct iucv_path_pending *ipp = (void *) data;
1241 struct iucv_handler *handler;
1242 struct iucv_path *path;
1243 char *error;
1245 BUG_ON(iucv_path_table[ipp->ippathid]);
1246 /* New pathid, handler found. Create a new path struct. */
1247 error = iucv_error_no_memory;
1248 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1249 if (!path)
1250 goto out_sever;
1251 path->pathid = ipp->ippathid;
1252 iucv_path_table[path->pathid] = path;
1253 EBCASC(ipp->ipvmid, 8);
1255 /* Call registered handler until one is found that wants the path. */
1256 list_for_each_entry(handler, &iucv_handler_list, list) {
1257 if (!handler->path_pending)
1258 continue;
1260 * Add path to handler to allow a call to iucv_path_sever
1261 * inside the path_pending function. If the handler returns
1262 * an error remove the path from the handler again.
1264 list_add(&path->list, &handler->paths);
1265 path->handler = handler;
1266 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1267 return;
1268 list_del(&path->list);
1269 path->handler = NULL;
1271 /* No handler wanted the path. */
1272 iucv_path_table[path->pathid] = NULL;
1273 iucv_path_free(path);
1274 error = iucv_error_no_listener;
1275 out_sever:
1276 iucv_sever_pathid(ipp->ippathid, error);
1280 * iucv_path_complete
1281 * @data: Pointer to external interrupt buffer
1283 * Process connection complete work item. Called from tasklet while holding
1284 * iucv_table_lock.
1286 struct iucv_path_complete {
1287 u16 ippathid;
1288 u8 ipflags1;
1289 u8 iptype;
1290 u16 ipmsglim;
1291 u16 res1;
1292 u8 res2[8];
1293 u8 ipuser[16];
1294 u32 res3;
1295 u8 ippollfg;
1296 u8 res4[3];
1297 } __attribute__ ((packed));
1299 static void iucv_path_complete(struct iucv_irq_data *data)
1301 struct iucv_path_complete *ipc = (void *) data;
1302 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1304 if (path && path->handler && path->handler->path_complete)
1305 path->handler->path_complete(path, ipc->ipuser);
1309 * iucv_path_severed
1310 * @data: Pointer to external interrupt buffer
1312 * Process connection severed work item. Called from tasklet while holding
1313 * iucv_table_lock.
1315 struct iucv_path_severed {
1316 u16 ippathid;
1317 u8 res1;
1318 u8 iptype;
1319 u32 res2;
1320 u8 res3[8];
1321 u8 ipuser[16];
1322 u32 res4;
1323 u8 ippollfg;
1324 u8 res5[3];
1325 } __attribute__ ((packed));
1327 static void iucv_path_severed(struct iucv_irq_data *data)
1329 struct iucv_path_severed *ips = (void *) data;
1330 struct iucv_path *path = iucv_path_table[ips->ippathid];
1332 if (!path || !path->handler) /* Already severed */
1333 return;
1334 if (path->handler->path_severed)
1335 path->handler->path_severed(path, ips->ipuser);
1336 else {
1337 iucv_sever_pathid(path->pathid, NULL);
1338 iucv_path_table[path->pathid] = NULL;
1339 list_del_init(&path->list);
1340 iucv_path_free(path);
1345 * iucv_path_quiesced
1346 * @data: Pointer to external interrupt buffer
1348 * Process connection quiesced work item. Called from tasklet while holding
1349 * iucv_table_lock.
1351 struct iucv_path_quiesced {
1352 u16 ippathid;
1353 u8 res1;
1354 u8 iptype;
1355 u32 res2;
1356 u8 res3[8];
1357 u8 ipuser[16];
1358 u32 res4;
1359 u8 ippollfg;
1360 u8 res5[3];
1361 } __attribute__ ((packed));
1363 static void iucv_path_quiesced(struct iucv_irq_data *data)
1365 struct iucv_path_quiesced *ipq = (void *) data;
1366 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1368 if (path && path->handler && path->handler->path_quiesced)
1369 path->handler->path_quiesced(path, ipq->ipuser);
1373 * iucv_path_resumed
1374 * @data: Pointer to external interrupt buffer
1376 * Process connection resumed work item. Called from tasklet while holding
1377 * iucv_table_lock.
1379 struct iucv_path_resumed {
1380 u16 ippathid;
1381 u8 res1;
1382 u8 iptype;
1383 u32 res2;
1384 u8 res3[8];
1385 u8 ipuser[16];
1386 u32 res4;
1387 u8 ippollfg;
1388 u8 res5[3];
1389 } __attribute__ ((packed));
1391 static void iucv_path_resumed(struct iucv_irq_data *data)
1393 struct iucv_path_resumed *ipr = (void *) data;
1394 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1396 if (path && path->handler && path->handler->path_resumed)
1397 path->handler->path_resumed(path, ipr->ipuser);
1401 * iucv_message_complete
1402 * @data: Pointer to external interrupt buffer
1404 * Process message complete work item. Called from tasklet while holding
1405 * iucv_table_lock.
1407 struct iucv_message_complete {
1408 u16 ippathid;
1409 u8 ipflags1;
1410 u8 iptype;
1411 u32 ipmsgid;
1412 u32 ipaudit;
1413 u8 iprmmsg[8];
1414 u32 ipsrccls;
1415 u32 ipmsgtag;
1416 u32 res;
1417 u32 ipbfln2f;
1418 u8 ippollfg;
1419 u8 res2[3];
1420 } __attribute__ ((packed));
1422 static void iucv_message_complete(struct iucv_irq_data *data)
1424 struct iucv_message_complete *imc = (void *) data;
1425 struct iucv_path *path = iucv_path_table[imc->ippathid];
1426 struct iucv_message msg;
1428 if (path && path->handler && path->handler->message_complete) {
1429 msg.flags = imc->ipflags1;
1430 msg.id = imc->ipmsgid;
1431 msg.audit = imc->ipaudit;
1432 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1433 msg.class = imc->ipsrccls;
1434 msg.tag = imc->ipmsgtag;
1435 msg.length = imc->ipbfln2f;
1436 path->handler->message_complete(path, &msg);
1441 * iucv_message_pending
1442 * @data: Pointer to external interrupt buffer
1444 * Process message pending work item. Called from tasklet while holding
1445 * iucv_table_lock.
1447 struct iucv_message_pending {
1448 u16 ippathid;
1449 u8 ipflags1;
1450 u8 iptype;
1451 u32 ipmsgid;
1452 u32 iptrgcls;
1453 union {
1454 u32 iprmmsg1_u32;
1455 u8 iprmmsg1[4];
1456 } ln1msg1;
1457 union {
1458 u32 ipbfln1f;
1459 u8 iprmmsg2[4];
1460 } ln1msg2;
1461 u32 res1[3];
1462 u32 ipbfln2f;
1463 u8 ippollfg;
1464 u8 res2[3];
1465 } __attribute__ ((packed));
1467 static void iucv_message_pending(struct iucv_irq_data *data)
1469 struct iucv_message_pending *imp = (void *) data;
1470 struct iucv_path *path = iucv_path_table[imp->ippathid];
1471 struct iucv_message msg;
1473 if (path && path->handler && path->handler->message_pending) {
1474 msg.flags = imp->ipflags1;
1475 msg.id = imp->ipmsgid;
1476 msg.class = imp->iptrgcls;
1477 if (imp->ipflags1 & IUCV_IPRMDATA) {
1478 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1479 msg.length = 8;
1480 } else
1481 msg.length = imp->ln1msg2.ipbfln1f;
1482 msg.reply_size = imp->ipbfln2f;
1483 path->handler->message_pending(path, &msg);
1488 * iucv_tasklet_fn:
1490 * This tasklet loops over the queue of irq buffers created by
1491 * iucv_external_interrupt, calls the appropriate action handler
1492 * and then frees the buffer.
1494 static void iucv_tasklet_fn(unsigned long ignored)
1496 typedef void iucv_irq_fn(struct iucv_irq_data *);
1497 static iucv_irq_fn *irq_fn[] = {
1498 [0x02] = iucv_path_complete,
1499 [0x03] = iucv_path_severed,
1500 [0x04] = iucv_path_quiesced,
1501 [0x05] = iucv_path_resumed,
1502 [0x06] = iucv_message_complete,
1503 [0x07] = iucv_message_complete,
1504 [0x08] = iucv_message_pending,
1505 [0x09] = iucv_message_pending,
1507 LIST_HEAD(task_queue);
1508 struct iucv_irq_list *p, *n;
1510 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1511 if (!spin_trylock(&iucv_table_lock)) {
1512 tasklet_schedule(&iucv_tasklet);
1513 return;
1515 iucv_active_cpu = smp_processor_id();
1517 spin_lock_irq(&iucv_queue_lock);
1518 list_splice_init(&iucv_task_queue, &task_queue);
1519 spin_unlock_irq(&iucv_queue_lock);
1521 list_for_each_entry_safe(p, n, &task_queue, list) {
1522 list_del_init(&p->list);
1523 irq_fn[p->data.iptype](&p->data);
1524 kfree(p);
1527 iucv_active_cpu = -1;
1528 spin_unlock(&iucv_table_lock);
1532 * iucv_work_fn:
1534 * This work function loops over the queue of path pending irq blocks
1535 * created by iucv_external_interrupt, calls the appropriate action
1536 * handler and then frees the buffer.
1538 static void iucv_work_fn(struct work_struct *work)
1540 typedef void iucv_irq_fn(struct iucv_irq_data *);
1541 LIST_HEAD(work_queue);
1542 struct iucv_irq_list *p, *n;
1544 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1545 spin_lock_bh(&iucv_table_lock);
1546 iucv_active_cpu = smp_processor_id();
1548 spin_lock_irq(&iucv_queue_lock);
1549 list_splice_init(&iucv_work_queue, &work_queue);
1550 spin_unlock_irq(&iucv_queue_lock);
1552 iucv_cleanup_queue();
1553 list_for_each_entry_safe(p, n, &work_queue, list) {
1554 list_del_init(&p->list);
1555 iucv_path_pending(&p->data);
1556 kfree(p);
1559 iucv_active_cpu = -1;
1560 spin_unlock_bh(&iucv_table_lock);
1564 * iucv_external_interrupt
1565 * @code: irq code
1567 * Handles external interrupts coming in from CP.
1568 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1570 static void iucv_external_interrupt(u16 code)
1572 struct iucv_irq_data *p;
1573 struct iucv_irq_list *work;
1575 p = iucv_irq_data[smp_processor_id()];
1576 if (p->ippathid >= iucv_max_pathid) {
1577 WARN_ON(p->ippathid >= iucv_max_pathid);
1578 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1579 return;
1581 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1582 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1583 if (!work) {
1584 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1585 return;
1587 memcpy(&work->data, p, sizeof(work->data));
1588 spin_lock(&iucv_queue_lock);
1589 if (p->iptype == 0x01) {
1590 /* Path pending interrupt. */
1591 list_add_tail(&work->list, &iucv_work_queue);
1592 schedule_work(&iucv_work);
1593 } else {
1594 /* The other interrupts. */
1595 list_add_tail(&work->list, &iucv_task_queue);
1596 tasklet_schedule(&iucv_tasklet);
1598 spin_unlock(&iucv_queue_lock);
1602 * iucv_init
1604 * Allocates and initializes various data structures.
1606 static int __init iucv_init(void)
1608 int rc;
1609 int cpu;
1611 if (!MACHINE_IS_VM) {
1612 rc = -EPROTONOSUPPORT;
1613 goto out;
1615 rc = iucv_query_maxconn();
1616 if (rc)
1617 goto out;
1618 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1619 if (rc)
1620 goto out;
1621 iucv_root = s390_root_dev_register("iucv");
1622 if (IS_ERR(iucv_root)) {
1623 rc = PTR_ERR(iucv_root);
1624 goto out_int;
1627 for_each_online_cpu(cpu) {
1628 /* Note: GFP_DMA used to get memory below 2G */
1629 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1630 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1631 if (!iucv_irq_data[cpu]) {
1632 rc = -ENOMEM;
1633 goto out_free;
1636 /* Allocate parameter blocks. */
1637 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1638 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1639 if (!iucv_param[cpu]) {
1640 rc = -ENOMEM;
1641 goto out_free;
1644 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1645 if (rc)
1646 goto out_free;
1647 ASCEBC(iucv_error_no_listener, 16);
1648 ASCEBC(iucv_error_no_memory, 16);
1649 ASCEBC(iucv_error_pathid, 16);
1650 iucv_available = 1;
1651 rc = bus_register(&iucv_bus);
1652 if (rc)
1653 goto out_cpu;
1654 return 0;
1656 out_cpu:
1657 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1658 out_free:
1659 for_each_possible_cpu(cpu) {
1660 kfree(iucv_param[cpu]);
1661 iucv_param[cpu] = NULL;
1662 kfree(iucv_irq_data[cpu]);
1663 iucv_irq_data[cpu] = NULL;
1665 s390_root_dev_unregister(iucv_root);
1666 out_int:
1667 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1668 out:
1669 return rc;
1673 * iucv_exit
1675 * Frees everything allocated from iucv_init.
1677 static void __exit iucv_exit(void)
1679 struct iucv_irq_list *p, *n;
1680 int cpu;
1682 spin_lock_irq(&iucv_queue_lock);
1683 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1684 kfree(p);
1685 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1686 kfree(p);
1687 spin_unlock_irq(&iucv_queue_lock);
1688 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1689 for_each_possible_cpu(cpu) {
1690 kfree(iucv_param[cpu]);
1691 iucv_param[cpu] = NULL;
1692 kfree(iucv_irq_data[cpu]);
1693 iucv_irq_data[cpu] = NULL;
1695 s390_root_dev_unregister(iucv_root);
1696 bus_unregister(&iucv_bus);
1697 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1700 subsys_initcall(iucv_init);
1701 module_exit(iucv_exit);
1703 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1704 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1705 MODULE_LICENSE("GPL");