Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / net / iucv / iucv.c
blob70df1399f8e9a8c5a49a5059e397459e5a693109
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 preempt_disable();
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, 0, 1);
484 preempt_enable();
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, 0, 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 preempt_disable();
525 for_each_online_cpu(cpu)
526 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
527 preempt_enable();
528 if (cpus_empty(iucv_buffer_cpumask))
529 /* No cpu could declare an iucv buffer. */
530 goto out_path;
531 return 0;
533 out_path:
534 kfree(iucv_path_table);
535 out:
536 return rc;
540 * iucv_disable
542 * This function shuts down iucv. It disables iucv interrupts, retrieves
543 * the iucv interrupt buffer and frees the pathid table. Called after the
544 * last user unregister its iucv handler.
546 static void iucv_disable(void)
548 on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
549 kfree(iucv_path_table);
552 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
553 unsigned long action, void *hcpu)
555 cpumask_t cpumask;
556 long cpu = (long) hcpu;
558 switch (action) {
559 case CPU_UP_PREPARE:
560 case CPU_UP_PREPARE_FROZEN:
561 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
562 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
563 if (!iucv_irq_data[cpu])
564 return NOTIFY_BAD;
565 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
566 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
567 if (!iucv_param[cpu])
568 return NOTIFY_BAD;
569 break;
570 case CPU_UP_CANCELED:
571 case CPU_UP_CANCELED_FROZEN:
572 case CPU_DEAD:
573 case CPU_DEAD_FROZEN:
574 kfree(iucv_param[cpu]);
575 iucv_param[cpu] = NULL;
576 kfree(iucv_irq_data[cpu]);
577 iucv_irq_data[cpu] = NULL;
578 break;
579 case CPU_ONLINE:
580 case CPU_ONLINE_FROZEN:
581 case CPU_DOWN_FAILED:
582 case CPU_DOWN_FAILED_FROZEN:
583 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
584 break;
585 case CPU_DOWN_PREPARE:
586 case CPU_DOWN_PREPARE_FROZEN:
587 cpumask = iucv_buffer_cpumask;
588 cpu_clear(cpu, cpumask);
589 if (cpus_empty(cpumask))
590 /* Can't offline last IUCV enabled cpu. */
591 return NOTIFY_BAD;
592 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 0, 1);
593 if (cpus_empty(iucv_irq_cpumask))
594 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
595 iucv_allow_cpu, NULL, 0, 1);
596 break;
598 return NOTIFY_OK;
601 static struct notifier_block __cpuinitdata iucv_cpu_notifier = {
602 .notifier_call = iucv_cpu_notify,
606 * iucv_sever_pathid
607 * @pathid: path identification number.
608 * @userdata: 16-bytes of user data.
610 * Sever an iucv path to free up the pathid. Used internally.
612 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
614 union iucv_param *parm;
616 parm = iucv_param[smp_processor_id()];
617 memset(parm, 0, sizeof(union iucv_param));
618 if (userdata)
619 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
620 parm->ctrl.ippathid = pathid;
621 return iucv_call_b2f0(IUCV_SEVER, parm);
624 <<<<<<< HEAD:net/iucv/iucv.c
625 #ifdef CONFIG_SMP
626 =======
627 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:net/iucv/iucv.c
629 * __iucv_cleanup_queue
630 * @dummy: unused dummy argument
632 * Nop function called via smp_call_function to force work items from
633 * pending external iucv interrupts to the work queue.
635 static void __iucv_cleanup_queue(void *dummy)
638 <<<<<<< HEAD:net/iucv/iucv.c
639 #endif
640 =======
641 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:net/iucv/iucv.c
644 * iucv_cleanup_queue
646 * Function called after a path has been severed to find all remaining
647 * work items for the now stale pathid. The caller needs to hold the
648 * iucv_table_lock.
650 static void iucv_cleanup_queue(void)
652 struct iucv_irq_list *p, *n;
655 * When a path is severed, the pathid can be reused immediatly
656 * on a iucv connect or a connection pending interrupt. Remove
657 * all entries from the task queue that refer to a stale pathid
658 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
659 * or deliver the connection pending interrupt. To get all the
660 * pending interrupts force them to the work queue by calling
661 * an empty function on all cpus.
663 smp_call_function(__iucv_cleanup_queue, NULL, 0, 1);
664 spin_lock_irq(&iucv_queue_lock);
665 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
666 /* Remove stale work items from the task queue. */
667 if (iucv_path_table[p->data.ippathid] == NULL) {
668 list_del(&p->list);
669 kfree(p);
672 spin_unlock_irq(&iucv_queue_lock);
676 * iucv_register:
677 * @handler: address of iucv handler structure
678 * @smp: != 0 indicates that the handler can deal with out of order messages
680 * Registers a driver with IUCV.
682 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
683 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
685 int iucv_register(struct iucv_handler *handler, int smp)
687 int rc;
689 if (!iucv_available)
690 return -ENOSYS;
691 mutex_lock(&iucv_register_mutex);
692 if (!smp)
693 iucv_nonsmp_handler++;
694 if (list_empty(&iucv_handler_list)) {
695 rc = iucv_enable();
696 if (rc)
697 goto out_mutex;
698 } else if (!smp && iucv_nonsmp_handler == 1)
699 iucv_setmask_up();
700 INIT_LIST_HEAD(&handler->paths);
702 spin_lock_bh(&iucv_table_lock);
703 list_add_tail(&handler->list, &iucv_handler_list);
704 spin_unlock_bh(&iucv_table_lock);
705 rc = 0;
706 out_mutex:
707 mutex_unlock(&iucv_register_mutex);
708 return rc;
710 EXPORT_SYMBOL(iucv_register);
713 * iucv_unregister
714 * @handler: address of iucv handler structure
715 * @smp: != 0 indicates that the handler can deal with out of order messages
717 * Unregister driver from IUCV.
719 void iucv_unregister(struct iucv_handler *handler, int smp)
721 struct iucv_path *p, *n;
723 mutex_lock(&iucv_register_mutex);
724 spin_lock_bh(&iucv_table_lock);
725 /* Remove handler from the iucv_handler_list. */
726 list_del_init(&handler->list);
727 /* Sever all pathids still refering to the handler. */
728 list_for_each_entry_safe(p, n, &handler->paths, list) {
729 iucv_sever_pathid(p->pathid, NULL);
730 iucv_path_table[p->pathid] = NULL;
731 list_del(&p->list);
732 iucv_path_free(p);
734 spin_unlock_bh(&iucv_table_lock);
735 if (!smp)
736 iucv_nonsmp_handler--;
737 if (list_empty(&iucv_handler_list))
738 iucv_disable();
739 else if (!smp && iucv_nonsmp_handler == 0)
740 iucv_setmask_mp();
741 mutex_unlock(&iucv_register_mutex);
743 EXPORT_SYMBOL(iucv_unregister);
746 * iucv_path_accept
747 * @path: address of iucv path structure
748 * @handler: address of iucv handler structure
749 * @userdata: 16 bytes of data reflected to the communication partner
750 * @private: private data passed to interrupt handlers for this path
752 * This function is issued after the user received a connection pending
753 * external interrupt and now wishes to complete the IUCV communication path.
755 * Returns the result of the CP IUCV call.
757 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
758 u8 userdata[16], void *private)
760 union iucv_param *parm;
761 int rc;
763 local_bh_disable();
764 /* Prepare parameter block. */
765 parm = iucv_param[smp_processor_id()];
766 memset(parm, 0, sizeof(union iucv_param));
767 parm->ctrl.ippathid = path->pathid;
768 parm->ctrl.ipmsglim = path->msglim;
769 if (userdata)
770 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
771 parm->ctrl.ipflags1 = path->flags;
773 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
774 if (!rc) {
775 path->private = private;
776 path->msglim = parm->ctrl.ipmsglim;
777 path->flags = parm->ctrl.ipflags1;
779 local_bh_enable();
780 return rc;
782 EXPORT_SYMBOL(iucv_path_accept);
785 * iucv_path_connect
786 * @path: address of iucv path structure
787 * @handler: address of iucv handler structure
788 * @userid: 8-byte user identification
789 * @system: 8-byte target system identification
790 * @userdata: 16 bytes of data reflected to the communication partner
791 * @private: private data passed to interrupt handlers for this path
793 * This function establishes an IUCV path. Although the connect may complete
794 * successfully, you are not able to use the path until you receive an IUCV
795 * Connection Complete external interrupt.
797 * Returns the result of the CP IUCV call.
799 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
800 u8 userid[8], u8 system[8], u8 userdata[16],
801 void *private)
803 union iucv_param *parm;
804 int rc;
806 BUG_ON(in_atomic());
807 spin_lock_bh(&iucv_table_lock);
808 iucv_cleanup_queue();
809 parm = iucv_param[smp_processor_id()];
810 memset(parm, 0, sizeof(union iucv_param));
811 parm->ctrl.ipmsglim = path->msglim;
812 parm->ctrl.ipflags1 = path->flags;
813 if (userid) {
814 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
815 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
816 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
818 if (system) {
819 memcpy(parm->ctrl.iptarget, system,
820 sizeof(parm->ctrl.iptarget));
821 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
822 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
824 if (userdata)
825 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
827 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
828 if (!rc) {
829 if (parm->ctrl.ippathid < iucv_max_pathid) {
830 path->pathid = parm->ctrl.ippathid;
831 path->msglim = parm->ctrl.ipmsglim;
832 path->flags = parm->ctrl.ipflags1;
833 path->handler = handler;
834 path->private = private;
835 list_add_tail(&path->list, &handler->paths);
836 iucv_path_table[path->pathid] = path;
837 } else {
838 iucv_sever_pathid(parm->ctrl.ippathid,
839 iucv_error_pathid);
840 rc = -EIO;
843 spin_unlock_bh(&iucv_table_lock);
844 return rc;
846 EXPORT_SYMBOL(iucv_path_connect);
849 * iucv_path_quiesce:
850 * @path: address of iucv path structure
851 * @userdata: 16 bytes of data reflected to the communication partner
853 * This function temporarily suspends incoming messages on an IUCV path.
854 * You can later reactivate the path by invoking the iucv_resume function.
856 * Returns the result from the CP IUCV call.
858 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
860 union iucv_param *parm;
861 int rc;
863 local_bh_disable();
864 parm = iucv_param[smp_processor_id()];
865 memset(parm, 0, sizeof(union iucv_param));
866 if (userdata)
867 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
868 parm->ctrl.ippathid = path->pathid;
869 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
870 local_bh_enable();
871 return rc;
873 EXPORT_SYMBOL(iucv_path_quiesce);
876 * iucv_path_resume:
877 * @path: address of iucv path structure
878 * @userdata: 16 bytes of data reflected to the communication partner
880 * This function resumes incoming messages on an IUCV path that has
881 * been stopped with iucv_path_quiesce.
883 * Returns the result from the CP IUCV call.
885 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
887 union iucv_param *parm;
888 int rc;
890 local_bh_disable();
891 parm = iucv_param[smp_processor_id()];
892 memset(parm, 0, sizeof(union iucv_param));
893 if (userdata)
894 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
895 parm->ctrl.ippathid = path->pathid;
896 rc = iucv_call_b2f0(IUCV_RESUME, parm);
897 local_bh_enable();
898 return rc;
902 * iucv_path_sever
903 * @path: address of iucv path structure
904 * @userdata: 16 bytes of data reflected to the communication partner
906 * This function terminates an IUCV path.
908 * Returns the result from the CP IUCV call.
910 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
912 int rc;
914 preempt_disable();
915 if (iucv_active_cpu != smp_processor_id())
916 spin_lock_bh(&iucv_table_lock);
917 rc = iucv_sever_pathid(path->pathid, userdata);
918 if (!rc) {
919 iucv_path_table[path->pathid] = NULL;
920 list_del_init(&path->list);
922 if (iucv_active_cpu != smp_processor_id())
923 spin_unlock_bh(&iucv_table_lock);
924 preempt_enable();
925 return rc;
927 EXPORT_SYMBOL(iucv_path_sever);
930 * iucv_message_purge
931 * @path: address of iucv path structure
932 * @msg: address of iucv msg structure
933 * @srccls: source class of message
935 * Cancels a message you have sent.
937 * Returns the result from the CP IUCV call.
939 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
940 u32 srccls)
942 union iucv_param *parm;
943 int rc;
945 local_bh_disable();
946 parm = iucv_param[smp_processor_id()];
947 memset(parm, 0, sizeof(union iucv_param));
948 parm->purge.ippathid = path->pathid;
949 parm->purge.ipmsgid = msg->id;
950 parm->purge.ipsrccls = srccls;
951 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
952 rc = iucv_call_b2f0(IUCV_PURGE, parm);
953 if (!rc) {
954 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
955 msg->tag = parm->purge.ipmsgtag;
957 local_bh_enable();
958 return rc;
960 EXPORT_SYMBOL(iucv_message_purge);
963 * iucv_message_receive
964 * @path: address of iucv path structure
965 * @msg: address of iucv msg structure
966 * @flags: how the message is received (IUCV_IPBUFLST)
967 * @buffer: address of data buffer or address of struct iucv_array
968 * @size: length of data buffer
969 * @residual:
971 * This function receives messages that are being sent to you over
972 * established paths. This function will deal with RMDATA messages
973 * embedded in struct iucv_message as well.
975 * Returns the result from the CP IUCV call.
977 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
978 u8 flags, void *buffer, size_t size, size_t *residual)
980 union iucv_param *parm;
981 struct iucv_array *array;
982 u8 *rmmsg;
983 size_t copy;
984 int rc;
986 if (msg->flags & IUCV_IPRMDATA) {
988 * Message is 8 bytes long and has been stored to the
989 * message descriptor itself.
991 rc = (size < 8) ? 5 : 0;
992 if (residual)
993 *residual = abs(size - 8);
994 rmmsg = msg->rmmsg;
995 if (flags & IUCV_IPBUFLST) {
996 /* Copy to struct iucv_array. */
997 size = (size < 8) ? size : 8;
998 for (array = buffer; size > 0; array++) {
999 copy = min_t(size_t, size, array->length);
1000 memcpy((u8 *)(addr_t) array->address,
1001 rmmsg, copy);
1002 rmmsg += copy;
1003 size -= copy;
1005 } else {
1006 /* Copy to direct buffer. */
1007 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1009 return 0;
1012 local_bh_disable();
1013 parm = iucv_param[smp_processor_id()];
1014 memset(parm, 0, sizeof(union iucv_param));
1015 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1016 parm->db.ipbfln1f = (u32) size;
1017 parm->db.ipmsgid = msg->id;
1018 parm->db.ippathid = path->pathid;
1019 parm->db.iptrgcls = msg->class;
1020 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1021 IUCV_IPFGMID | IUCV_IPTRGCLS);
1022 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1023 if (!rc || rc == 5) {
1024 msg->flags = parm->db.ipflags1;
1025 if (residual)
1026 *residual = parm->db.ipbfln1f;
1028 local_bh_enable();
1029 return rc;
1031 EXPORT_SYMBOL(iucv_message_receive);
1034 * iucv_message_reject
1035 * @path: address of iucv path structure
1036 * @msg: address of iucv msg structure
1038 * The reject function refuses a specified message. Between the time you
1039 * are notified of a message and the time that you complete the message,
1040 * the message may be rejected.
1042 * Returns the result from the CP IUCV call.
1044 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1046 union iucv_param *parm;
1047 int rc;
1049 local_bh_disable();
1050 parm = iucv_param[smp_processor_id()];
1051 memset(parm, 0, sizeof(union iucv_param));
1052 parm->db.ippathid = path->pathid;
1053 parm->db.ipmsgid = msg->id;
1054 parm->db.iptrgcls = msg->class;
1055 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1056 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1057 local_bh_enable();
1058 return rc;
1060 EXPORT_SYMBOL(iucv_message_reject);
1063 * iucv_message_reply
1064 * @path: address of iucv path structure
1065 * @msg: address of iucv msg structure
1066 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1067 * @reply: address of reply data buffer or address of struct iucv_array
1068 * @size: length of reply data buffer
1070 * This function responds to the two-way messages that you receive. You
1071 * must identify completely the message to which you wish to reply. ie,
1072 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1073 * the parameter list.
1075 * Returns the result from the CP IUCV call.
1077 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1078 u8 flags, void *reply, size_t size)
1080 union iucv_param *parm;
1081 int rc;
1083 local_bh_disable();
1084 parm = iucv_param[smp_processor_id()];
1085 memset(parm, 0, sizeof(union iucv_param));
1086 if (flags & IUCV_IPRMDATA) {
1087 parm->dpl.ippathid = path->pathid;
1088 parm->dpl.ipflags1 = flags;
1089 parm->dpl.ipmsgid = msg->id;
1090 parm->dpl.iptrgcls = msg->class;
1091 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1092 } else {
1093 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1094 parm->db.ipbfln1f = (u32) size;
1095 parm->db.ippathid = path->pathid;
1096 parm->db.ipflags1 = flags;
1097 parm->db.ipmsgid = msg->id;
1098 parm->db.iptrgcls = msg->class;
1100 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1101 local_bh_enable();
1102 return rc;
1104 EXPORT_SYMBOL(iucv_message_reply);
1107 * iucv_message_send
1108 * @path: address of iucv path structure
1109 * @msg: address of iucv msg structure
1110 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1111 * @srccls: source class of message
1112 * @buffer: address of send buffer or address of struct iucv_array
1113 * @size: length of send buffer
1115 * This function transmits data to another application. Data to be
1116 * transmitted is in a buffer and this is a one-way message and the
1117 * receiver will not reply to the message.
1119 * Returns the result from the CP IUCV call.
1121 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1122 u8 flags, u32 srccls, void *buffer, size_t size)
1124 union iucv_param *parm;
1125 int rc;
1127 local_bh_disable();
1128 parm = iucv_param[smp_processor_id()];
1129 memset(parm, 0, sizeof(union iucv_param));
1130 if (flags & IUCV_IPRMDATA) {
1131 /* Message of 8 bytes can be placed into the parameter list. */
1132 parm->dpl.ippathid = path->pathid;
1133 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1134 parm->dpl.iptrgcls = msg->class;
1135 parm->dpl.ipsrccls = srccls;
1136 parm->dpl.ipmsgtag = msg->tag;
1137 memcpy(parm->dpl.iprmmsg, buffer, 8);
1138 } else {
1139 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1140 parm->db.ipbfln1f = (u32) size;
1141 parm->db.ippathid = path->pathid;
1142 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1143 parm->db.iptrgcls = msg->class;
1144 parm->db.ipsrccls = srccls;
1145 parm->db.ipmsgtag = msg->tag;
1147 rc = iucv_call_b2f0(IUCV_SEND, parm);
1148 if (!rc)
1149 msg->id = parm->db.ipmsgid;
1150 local_bh_enable();
1151 return rc;
1153 EXPORT_SYMBOL(iucv_message_send);
1156 * iucv_message_send2way
1157 * @path: address of iucv path structure
1158 * @msg: address of iucv msg structure
1159 * @flags: how the message is sent and the reply is received
1160 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1161 * @srccls: source class of message
1162 * @buffer: address of send buffer or address of struct iucv_array
1163 * @size: length of send buffer
1164 * @ansbuf: address of answer buffer or address of struct iucv_array
1165 * @asize: size of reply buffer
1167 * This function transmits data to another application. Data to be
1168 * transmitted is in a buffer. The receiver of the send is expected to
1169 * reply to the message and a buffer is provided into which IUCV moves
1170 * the reply to this message.
1172 * Returns the result from the CP IUCV call.
1174 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1175 u8 flags, u32 srccls, void *buffer, size_t size,
1176 void *answer, size_t asize, size_t *residual)
1178 union iucv_param *parm;
1179 int rc;
1181 local_bh_disable();
1182 parm = iucv_param[smp_processor_id()];
1183 memset(parm, 0, sizeof(union iucv_param));
1184 if (flags & IUCV_IPRMDATA) {
1185 parm->dpl.ippathid = path->pathid;
1186 parm->dpl.ipflags1 = path->flags; /* priority message */
1187 parm->dpl.iptrgcls = msg->class;
1188 parm->dpl.ipsrccls = srccls;
1189 parm->dpl.ipmsgtag = msg->tag;
1190 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1191 parm->dpl.ipbfln2f = (u32) asize;
1192 memcpy(parm->dpl.iprmmsg, buffer, 8);
1193 } else {
1194 parm->db.ippathid = path->pathid;
1195 parm->db.ipflags1 = path->flags; /* priority message */
1196 parm->db.iptrgcls = msg->class;
1197 parm->db.ipsrccls = srccls;
1198 parm->db.ipmsgtag = msg->tag;
1199 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1200 parm->db.ipbfln1f = (u32) size;
1201 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1202 parm->db.ipbfln2f = (u32) asize;
1204 rc = iucv_call_b2f0(IUCV_SEND, parm);
1205 if (!rc)
1206 msg->id = parm->db.ipmsgid;
1207 local_bh_enable();
1208 return rc;
1210 EXPORT_SYMBOL(iucv_message_send2way);
1213 * iucv_path_pending
1214 * @data: Pointer to external interrupt buffer
1216 * Process connection pending work item. Called from tasklet while holding
1217 * iucv_table_lock.
1219 struct iucv_path_pending {
1220 u16 ippathid;
1221 u8 ipflags1;
1222 u8 iptype;
1223 u16 ipmsglim;
1224 u16 res1;
1225 u8 ipvmid[8];
1226 u8 ipuser[16];
1227 u32 res3;
1228 u8 ippollfg;
1229 u8 res4[3];
1230 } __attribute__ ((packed));
1232 static void iucv_path_pending(struct iucv_irq_data *data)
1234 struct iucv_path_pending *ipp = (void *) data;
1235 struct iucv_handler *handler;
1236 struct iucv_path *path;
1237 char *error;
1239 BUG_ON(iucv_path_table[ipp->ippathid]);
1240 /* New pathid, handler found. Create a new path struct. */
1241 error = iucv_error_no_memory;
1242 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1243 if (!path)
1244 goto out_sever;
1245 path->pathid = ipp->ippathid;
1246 iucv_path_table[path->pathid] = path;
1247 EBCASC(ipp->ipvmid, 8);
1249 /* Call registered handler until one is found that wants the path. */
1250 list_for_each_entry(handler, &iucv_handler_list, list) {
1251 if (!handler->path_pending)
1252 continue;
1254 * Add path to handler to allow a call to iucv_path_sever
1255 * inside the path_pending function. If the handler returns
1256 * an error remove the path from the handler again.
1258 list_add(&path->list, &handler->paths);
1259 path->handler = handler;
1260 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1261 return;
1262 list_del(&path->list);
1263 path->handler = NULL;
1265 /* No handler wanted the path. */
1266 iucv_path_table[path->pathid] = NULL;
1267 iucv_path_free(path);
1268 error = iucv_error_no_listener;
1269 out_sever:
1270 iucv_sever_pathid(ipp->ippathid, error);
1274 * iucv_path_complete
1275 * @data: Pointer to external interrupt buffer
1277 * Process connection complete work item. Called from tasklet while holding
1278 * iucv_table_lock.
1280 struct iucv_path_complete {
1281 u16 ippathid;
1282 u8 ipflags1;
1283 u8 iptype;
1284 u16 ipmsglim;
1285 u16 res1;
1286 u8 res2[8];
1287 u8 ipuser[16];
1288 u32 res3;
1289 u8 ippollfg;
1290 u8 res4[3];
1291 } __attribute__ ((packed));
1293 static void iucv_path_complete(struct iucv_irq_data *data)
1295 struct iucv_path_complete *ipc = (void *) data;
1296 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1298 if (path && path->handler && path->handler->path_complete)
1299 path->handler->path_complete(path, ipc->ipuser);
1303 * iucv_path_severed
1304 * @data: Pointer to external interrupt buffer
1306 * Process connection severed work item. Called from tasklet while holding
1307 * iucv_table_lock.
1309 struct iucv_path_severed {
1310 u16 ippathid;
1311 u8 res1;
1312 u8 iptype;
1313 u32 res2;
1314 u8 res3[8];
1315 u8 ipuser[16];
1316 u32 res4;
1317 u8 ippollfg;
1318 u8 res5[3];
1319 } __attribute__ ((packed));
1321 static void iucv_path_severed(struct iucv_irq_data *data)
1323 struct iucv_path_severed *ips = (void *) data;
1324 struct iucv_path *path = iucv_path_table[ips->ippathid];
1326 if (!path || !path->handler) /* Already severed */
1327 return;
1328 if (path->handler->path_severed)
1329 path->handler->path_severed(path, ips->ipuser);
1330 else {
1331 iucv_sever_pathid(path->pathid, NULL);
1332 iucv_path_table[path->pathid] = NULL;
1333 list_del_init(&path->list);
1334 iucv_path_free(path);
1339 * iucv_path_quiesced
1340 * @data: Pointer to external interrupt buffer
1342 * Process connection quiesced work item. Called from tasklet while holding
1343 * iucv_table_lock.
1345 struct iucv_path_quiesced {
1346 u16 ippathid;
1347 u8 res1;
1348 u8 iptype;
1349 u32 res2;
1350 u8 res3[8];
1351 u8 ipuser[16];
1352 u32 res4;
1353 u8 ippollfg;
1354 u8 res5[3];
1355 } __attribute__ ((packed));
1357 static void iucv_path_quiesced(struct iucv_irq_data *data)
1359 struct iucv_path_quiesced *ipq = (void *) data;
1360 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1362 if (path && path->handler && path->handler->path_quiesced)
1363 path->handler->path_quiesced(path, ipq->ipuser);
1367 * iucv_path_resumed
1368 * @data: Pointer to external interrupt buffer
1370 * Process connection resumed work item. Called from tasklet while holding
1371 * iucv_table_lock.
1373 struct iucv_path_resumed {
1374 u16 ippathid;
1375 u8 res1;
1376 u8 iptype;
1377 u32 res2;
1378 u8 res3[8];
1379 u8 ipuser[16];
1380 u32 res4;
1381 u8 ippollfg;
1382 u8 res5[3];
1383 } __attribute__ ((packed));
1385 static void iucv_path_resumed(struct iucv_irq_data *data)
1387 struct iucv_path_resumed *ipr = (void *) data;
1388 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1390 if (path && path->handler && path->handler->path_resumed)
1391 path->handler->path_resumed(path, ipr->ipuser);
1395 * iucv_message_complete
1396 * @data: Pointer to external interrupt buffer
1398 * Process message complete work item. Called from tasklet while holding
1399 * iucv_table_lock.
1401 struct iucv_message_complete {
1402 u16 ippathid;
1403 u8 ipflags1;
1404 u8 iptype;
1405 u32 ipmsgid;
1406 u32 ipaudit;
1407 u8 iprmmsg[8];
1408 u32 ipsrccls;
1409 u32 ipmsgtag;
1410 u32 res;
1411 u32 ipbfln2f;
1412 u8 ippollfg;
1413 u8 res2[3];
1414 } __attribute__ ((packed));
1416 static void iucv_message_complete(struct iucv_irq_data *data)
1418 struct iucv_message_complete *imc = (void *) data;
1419 struct iucv_path *path = iucv_path_table[imc->ippathid];
1420 struct iucv_message msg;
1422 if (path && path->handler && path->handler->message_complete) {
1423 msg.flags = imc->ipflags1;
1424 msg.id = imc->ipmsgid;
1425 msg.audit = imc->ipaudit;
1426 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1427 msg.class = imc->ipsrccls;
1428 msg.tag = imc->ipmsgtag;
1429 msg.length = imc->ipbfln2f;
1430 path->handler->message_complete(path, &msg);
1435 * iucv_message_pending
1436 * @data: Pointer to external interrupt buffer
1438 * Process message pending work item. Called from tasklet while holding
1439 * iucv_table_lock.
1441 struct iucv_message_pending {
1442 u16 ippathid;
1443 u8 ipflags1;
1444 u8 iptype;
1445 u32 ipmsgid;
1446 u32 iptrgcls;
1447 union {
1448 u32 iprmmsg1_u32;
1449 u8 iprmmsg1[4];
1450 } ln1msg1;
1451 union {
1452 u32 ipbfln1f;
1453 u8 iprmmsg2[4];
1454 } ln1msg2;
1455 u32 res1[3];
1456 u32 ipbfln2f;
1457 u8 ippollfg;
1458 u8 res2[3];
1459 } __attribute__ ((packed));
1461 static void iucv_message_pending(struct iucv_irq_data *data)
1463 struct iucv_message_pending *imp = (void *) data;
1464 struct iucv_path *path = iucv_path_table[imp->ippathid];
1465 struct iucv_message msg;
1467 if (path && path->handler && path->handler->message_pending) {
1468 msg.flags = imp->ipflags1;
1469 msg.id = imp->ipmsgid;
1470 msg.class = imp->iptrgcls;
1471 if (imp->ipflags1 & IUCV_IPRMDATA) {
1472 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1473 msg.length = 8;
1474 } else
1475 msg.length = imp->ln1msg2.ipbfln1f;
1476 msg.reply_size = imp->ipbfln2f;
1477 path->handler->message_pending(path, &msg);
1482 * iucv_tasklet_fn:
1484 * This tasklet loops over the queue of irq buffers created by
1485 * iucv_external_interrupt, calls the appropriate action handler
1486 * and then frees the buffer.
1488 static void iucv_tasklet_fn(unsigned long ignored)
1490 typedef void iucv_irq_fn(struct iucv_irq_data *);
1491 static iucv_irq_fn *irq_fn[] = {
1492 [0x02] = iucv_path_complete,
1493 [0x03] = iucv_path_severed,
1494 [0x04] = iucv_path_quiesced,
1495 [0x05] = iucv_path_resumed,
1496 [0x06] = iucv_message_complete,
1497 [0x07] = iucv_message_complete,
1498 [0x08] = iucv_message_pending,
1499 [0x09] = iucv_message_pending,
1501 LIST_HEAD(task_queue);
1502 struct iucv_irq_list *p, *n;
1504 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1505 if (!spin_trylock(&iucv_table_lock)) {
1506 tasklet_schedule(&iucv_tasklet);
1507 return;
1509 iucv_active_cpu = smp_processor_id();
1511 spin_lock_irq(&iucv_queue_lock);
1512 list_splice_init(&iucv_task_queue, &task_queue);
1513 spin_unlock_irq(&iucv_queue_lock);
1515 list_for_each_entry_safe(p, n, &task_queue, list) {
1516 list_del_init(&p->list);
1517 irq_fn[p->data.iptype](&p->data);
1518 kfree(p);
1521 iucv_active_cpu = -1;
1522 spin_unlock(&iucv_table_lock);
1526 * iucv_work_fn:
1528 * This work function loops over the queue of path pending irq blocks
1529 * created by iucv_external_interrupt, calls the appropriate action
1530 * handler and then frees the buffer.
1532 static void iucv_work_fn(struct work_struct *work)
1534 typedef void iucv_irq_fn(struct iucv_irq_data *);
1535 LIST_HEAD(work_queue);
1536 struct iucv_irq_list *p, *n;
1538 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1539 spin_lock_bh(&iucv_table_lock);
1540 iucv_active_cpu = smp_processor_id();
1542 spin_lock_irq(&iucv_queue_lock);
1543 list_splice_init(&iucv_work_queue, &work_queue);
1544 spin_unlock_irq(&iucv_queue_lock);
1546 iucv_cleanup_queue();
1547 list_for_each_entry_safe(p, n, &work_queue, list) {
1548 list_del_init(&p->list);
1549 iucv_path_pending(&p->data);
1550 kfree(p);
1553 iucv_active_cpu = -1;
1554 spin_unlock_bh(&iucv_table_lock);
1558 * iucv_external_interrupt
1559 * @code: irq code
1561 * Handles external interrupts coming in from CP.
1562 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1564 static void iucv_external_interrupt(u16 code)
1566 struct iucv_irq_data *p;
1567 struct iucv_irq_list *work;
1569 p = iucv_irq_data[smp_processor_id()];
1570 if (p->ippathid >= iucv_max_pathid) {
1571 printk(KERN_WARNING "iucv_do_int: Got interrupt with "
1572 "pathid %d > max_connections (%ld)\n",
1573 p->ippathid, iucv_max_pathid - 1);
1574 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1575 return;
1577 if (p->iptype < 0x01 || p->iptype > 0x09) {
1578 printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
1579 return;
1581 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1582 if (!work) {
1583 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1584 return;
1586 memcpy(&work->data, p, sizeof(work->data));
1587 spin_lock(&iucv_queue_lock);
1588 if (p->iptype == 0x01) {
1589 /* Path pending interrupt. */
1590 list_add_tail(&work->list, &iucv_work_queue);
1591 schedule_work(&iucv_work);
1592 } else {
1593 /* The other interrupts. */
1594 list_add_tail(&work->list, &iucv_task_queue);
1595 tasklet_schedule(&iucv_tasklet);
1597 spin_unlock(&iucv_queue_lock);
1601 * iucv_init
1603 * Allocates and initializes various data structures.
1605 static int __init iucv_init(void)
1607 int rc;
1608 int cpu;
1610 if (!MACHINE_IS_VM) {
1611 rc = -EPROTONOSUPPORT;
1612 goto out;
1614 rc = iucv_query_maxconn();
1615 if (rc)
1616 goto out;
1617 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1618 if (rc)
1619 goto out;
1620 rc = bus_register(&iucv_bus);
1621 if (rc)
1622 goto out_int;
1623 iucv_root = s390_root_dev_register("iucv");
1624 if (IS_ERR(iucv_root)) {
1625 rc = PTR_ERR(iucv_root);
1626 goto out_bus;
1629 for_each_online_cpu(cpu) {
1630 /* Note: GFP_DMA used to get memory below 2G */
1631 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1632 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1633 if (!iucv_irq_data[cpu]) {
1634 rc = -ENOMEM;
1635 goto out_free;
1638 /* Allocate parameter blocks. */
1639 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1640 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1641 if (!iucv_param[cpu]) {
1642 rc = -ENOMEM;
1643 goto out_free;
1646 register_hotcpu_notifier(&iucv_cpu_notifier);
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 return 0;
1653 out_free:
1654 for_each_possible_cpu(cpu) {
1655 kfree(iucv_param[cpu]);
1656 iucv_param[cpu] = NULL;
1657 kfree(iucv_irq_data[cpu]);
1658 iucv_irq_data[cpu] = NULL;
1660 s390_root_dev_unregister(iucv_root);
1661 out_bus:
1662 bus_unregister(&iucv_bus);
1663 out_int:
1664 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1665 out:
1666 return rc;
1670 * iucv_exit
1672 * Frees everything allocated from iucv_init.
1674 static void __exit iucv_exit(void)
1676 struct iucv_irq_list *p, *n;
1677 int cpu;
1679 spin_lock_irq(&iucv_queue_lock);
1680 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1681 kfree(p);
1682 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1683 kfree(p);
1684 spin_unlock_irq(&iucv_queue_lock);
1685 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1686 for_each_possible_cpu(cpu) {
1687 kfree(iucv_param[cpu]);
1688 iucv_param[cpu] = NULL;
1689 kfree(iucv_irq_data[cpu]);
1690 iucv_irq_data[cpu] = NULL;
1692 s390_root_dev_unregister(iucv_root);
1693 bus_unregister(&iucv_bus);
1694 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1697 subsys_initcall(iucv_init);
1698 module_exit(iucv_exit);
1700 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1701 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1702 MODULE_LICENSE("GPL");