2 * IUCV base infrastructure.
4 * Copyright 2001, 2006 IBM Deutschland Entwicklung GmbH, IBM Corporation
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>
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)
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 #define KMSG_COMPONENT "iucv"
34 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
36 #include <linux/module.h>
37 #include <linux/moduleparam.h>
38 #include <linux/spinlock.h>
39 #include <linux/kernel.h>
40 #include <linux/slab.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/list.h>
44 #include <linux/errno.h>
45 #include <linux/err.h>
46 #include <linux/device.h>
47 #include <linux/cpu.h>
48 #include <net/iucv/iucv.h>
49 #include <asm/atomic.h>
50 #include <asm/ebcdic.h>
52 #include <asm/s390_ext.h>
53 #include <asm/s390_rdev.h>
58 * All flags are defined in the field IPFLAGS1 of each function
59 * and can be found in CP Programming Services.
60 * IPSRCCLS - Indicates you have specified a source class.
61 * IPTRGCLS - Indicates you have specified a target class.
62 * IPFGPID - Indicates you have specified a pathid.
63 * IPFGMID - Indicates you have specified a message ID.
64 * IPNORPY - Indicates a one-way message. No reply expected.
65 * IPALL - Indicates that all paths are affected.
67 #define IUCV_IPSRCCLS 0x01
68 #define IUCV_IPTRGCLS 0x01
69 #define IUCV_IPFGPID 0x02
70 #define IUCV_IPFGMID 0x04
71 #define IUCV_IPNORPY 0x10
72 #define IUCV_IPALL 0x80
74 static int iucv_bus_match(struct device
*dev
, struct device_driver
*drv
)
79 struct bus_type iucv_bus
= {
81 .match
= iucv_bus_match
,
83 EXPORT_SYMBOL(iucv_bus
);
85 struct device
*iucv_root
;
86 EXPORT_SYMBOL(iucv_root
);
88 static int iucv_available
;
90 /* General IUCV interrupt structure */
91 struct iucv_irq_data
{
98 struct iucv_irq_list
{
99 struct list_head list
;
100 struct iucv_irq_data data
;
103 static struct iucv_irq_data
*iucv_irq_data
[NR_CPUS
];
104 static cpumask_t iucv_buffer_cpumask
= CPU_MASK_NONE
;
105 static cpumask_t iucv_irq_cpumask
= CPU_MASK_NONE
;
108 * Queue of interrupt buffers lock for delivery via the tasklet
109 * (fast but can't call smp_call_function).
111 static LIST_HEAD(iucv_task_queue
);
114 * The tasklet for fast delivery of iucv interrupts.
116 static void iucv_tasklet_fn(unsigned long);
117 static DECLARE_TASKLET(iucv_tasklet
, iucv_tasklet_fn
,0);
120 * Queue of interrupt buffers for delivery via a work queue
121 * (slower but can call smp_call_function).
123 static LIST_HEAD(iucv_work_queue
);
126 * The work element to deliver path pending interrupts.
128 static void iucv_work_fn(struct work_struct
*work
);
129 static DECLARE_WORK(iucv_work
, iucv_work_fn
);
132 * Spinlock protecting task and work queue.
134 static DEFINE_SPINLOCK(iucv_queue_lock
);
136 enum iucv_command_codes
{
138 IUCV_RETRIEVE_BUFFER
= 2,
146 IUCV_DECLARE_BUFFER
= 12,
154 * Error messages that are used with the iucv_sever function. They get
155 * converted to EBCDIC.
157 static char iucv_error_no_listener
[16] = "NO LISTENER";
158 static char iucv_error_no_memory
[16] = "NO MEMORY";
159 static char iucv_error_pathid
[16] = "INVALID PATHID";
162 * iucv_handler_list: List of registered handlers.
164 static LIST_HEAD(iucv_handler_list
);
167 * iucv_path_table: an array of iucv_path structures.
169 static struct iucv_path
**iucv_path_table
;
170 static unsigned long iucv_max_pathid
;
173 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
175 static DEFINE_SPINLOCK(iucv_table_lock
);
178 * iucv_active_cpu: contains the number of the cpu executing the tasklet
179 * or the work handler. Needed for iucv_path_sever called from tasklet.
181 static int iucv_active_cpu
= -1;
184 * Mutex and wait queue for iucv_register/iucv_unregister.
186 static DEFINE_MUTEX(iucv_register_mutex
);
189 * Counter for number of non-smp capable handlers.
191 static int iucv_nonsmp_handler
;
194 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
195 * iucv_path_quiesce and iucv_path_sever.
197 struct iucv_cmd_control
{
206 } __attribute__ ((packed
,aligned(8)));
209 * Data in parameter list iucv structure. Used by iucv_message_send,
210 * iucv_message_send2way and iucv_message_reply.
212 struct iucv_cmd_dpl
{
224 } __attribute__ ((packed
,aligned(8)));
227 * Data in buffer iucv structure. Used by iucv_message_receive,
228 * iucv_message_reject, iucv_message_send, iucv_message_send2way
229 * and iucv_declare_cpu.
244 } __attribute__ ((packed
,aligned(8)));
247 * Purge message iucv structure. Used by iucv_message_purge.
249 struct iucv_cmd_purge
{
260 } __attribute__ ((packed
,aligned(8)));
263 * Set mask iucv structure. Used by iucv_enable_cpu.
265 struct iucv_cmd_set_mask
{
270 } __attribute__ ((packed
,aligned(8)));
273 struct iucv_cmd_control ctrl
;
274 struct iucv_cmd_dpl dpl
;
275 struct iucv_cmd_db db
;
276 struct iucv_cmd_purge purge
;
277 struct iucv_cmd_set_mask set_mask
;
281 * Anchor for per-cpu IUCV command parameter block.
283 static union iucv_param
*iucv_param
[NR_CPUS
];
287 * @code: identifier of IUCV call to CP.
288 * @parm: pointer to a struct iucv_parm block
290 * Calls CP to execute IUCV commands.
292 * Returns the result of the CP IUCV call.
294 static inline int iucv_call_b2f0(int command
, union iucv_param
*parm
)
296 register unsigned long reg0
asm ("0");
297 register unsigned long reg1
asm ("1");
301 reg1
= virt_to_phys(parm
);
303 " .long 0xb2f01000\n"
306 : "=d" (ccode
), "=m" (*parm
), "+d" (reg0
), "+a" (reg1
)
307 : "m" (*parm
) : "cc");
308 return (ccode
== 1) ? parm
->ctrl
.iprcode
: ccode
;
314 * Determines the maximum number of connections that may be established.
316 * Returns the maximum number of connections or -EPERM is IUCV is not
319 static int iucv_query_maxconn(void)
321 register unsigned long reg0
asm ("0");
322 register unsigned long reg1
asm ("1");
326 param
= kzalloc(sizeof(union iucv_param
), GFP_KERNEL
|GFP_DMA
);
330 reg1
= (unsigned long) param
;
332 " .long 0xb2f01000\n"
335 : "=d" (ccode
), "+d" (reg0
), "+d" (reg1
) : : "cc");
337 iucv_max_pathid
= reg0
;
339 return ccode
? -EPERM
: 0;
346 * Allow iucv interrupts on this cpu.
348 static void iucv_allow_cpu(void *data
)
350 int cpu
= smp_processor_id();
351 union iucv_param
*parm
;
354 * Enable all iucv interrupts.
355 * ipmask contains bits for the different interrupts
356 * 0x80 - Flag to allow nonpriority message pending interrupts
357 * 0x40 - Flag to allow priority message pending interrupts
358 * 0x20 - Flag to allow nonpriority message completion interrupts
359 * 0x10 - Flag to allow priority message completion interrupts
360 * 0x08 - Flag to allow IUCV control interrupts
362 parm
= iucv_param
[cpu
];
363 memset(parm
, 0, sizeof(union iucv_param
));
364 parm
->set_mask
.ipmask
= 0xf8;
365 iucv_call_b2f0(IUCV_SETMASK
, parm
);
367 /* Set indication that iucv interrupts are allowed for this cpu. */
368 cpu_set(cpu
, iucv_irq_cpumask
);
375 * Block iucv interrupts on this cpu.
377 static void iucv_block_cpu(void *data
)
379 int cpu
= smp_processor_id();
380 union iucv_param
*parm
;
382 /* Disable all iucv interrupts. */
383 parm
= iucv_param
[cpu
];
384 memset(parm
, 0, sizeof(union iucv_param
));
385 iucv_call_b2f0(IUCV_SETMASK
, parm
);
387 /* Clear indication that iucv interrupts are allowed for this cpu. */
388 cpu_clear(cpu
, iucv_irq_cpumask
);
395 * Declare a interrupt buffer on this cpu.
397 static void iucv_declare_cpu(void *data
)
399 int cpu
= smp_processor_id();
400 union iucv_param
*parm
;
403 if (cpu_isset(cpu
, iucv_buffer_cpumask
))
406 /* Declare interrupt buffer. */
407 parm
= iucv_param
[cpu
];
408 memset(parm
, 0, sizeof(union iucv_param
));
409 parm
->db
.ipbfadr1
= virt_to_phys(iucv_irq_data
[cpu
]);
410 rc
= iucv_call_b2f0(IUCV_DECLARE_BUFFER
, parm
);
412 char *err
= "Unknown";
415 err
= "Directory error";
418 err
= "Invalid length";
421 err
= "Buffer already exists";
424 err
= "Buffer overlap";
427 err
= "Paging or storage error";
430 pr_warning("Defining an interrupt buffer on CPU %i"
431 " failed with 0x%02x (%s)\n", cpu
, rc
, err
);
435 /* Set indication that an iucv buffer exists for this cpu. */
436 cpu_set(cpu
, iucv_buffer_cpumask
);
438 if (iucv_nonsmp_handler
== 0 || cpus_empty(iucv_irq_cpumask
))
439 /* Enable iucv interrupts on this cpu. */
440 iucv_allow_cpu(NULL
);
442 /* Disable iucv interrupts on this cpu. */
443 iucv_block_cpu(NULL
);
450 * Retrieve interrupt buffer on this cpu.
452 static void iucv_retrieve_cpu(void *data
)
454 int cpu
= smp_processor_id();
455 union iucv_param
*parm
;
457 if (!cpu_isset(cpu
, iucv_buffer_cpumask
))
460 /* Block iucv interrupts. */
461 iucv_block_cpu(NULL
);
463 /* Retrieve interrupt buffer. */
464 parm
= iucv_param
[cpu
];
465 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER
, parm
);
467 /* Clear indication that an iucv buffer exists for this cpu. */
468 cpu_clear(cpu
, iucv_buffer_cpumask
);
474 * Allow iucv interrupts on all cpus.
476 static void iucv_setmask_mp(void)
481 for_each_online_cpu(cpu
)
482 /* Enable all cpus with a declared buffer. */
483 if (cpu_isset(cpu
, iucv_buffer_cpumask
) &&
484 !cpu_isset(cpu
, iucv_irq_cpumask
))
485 smp_call_function_single(cpu
, iucv_allow_cpu
,
493 * Allow iucv interrupts on a single cpu.
495 static void iucv_setmask_up(void)
500 /* Disable all cpu but the first in cpu_irq_cpumask. */
501 cpumask
= iucv_irq_cpumask
;
502 cpu_clear(first_cpu(iucv_irq_cpumask
), cpumask
);
503 for_each_cpu_mask_nr(cpu
, cpumask
)
504 smp_call_function_single(cpu
, iucv_block_cpu
, NULL
, 1);
510 * This function makes iucv ready for use. It allocates the pathid
511 * table, declares an iucv interrupt buffer and enables the iucv
512 * interrupts. Called when the first user has registered an iucv
515 static int iucv_enable(void)
522 alloc_size
= iucv_max_pathid
* sizeof(struct iucv_path
);
523 iucv_path_table
= kzalloc(alloc_size
, GFP_KERNEL
);
524 if (!iucv_path_table
)
526 /* Declare per cpu buffers. */
528 for_each_online_cpu(cpu
)
529 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
530 if (cpus_empty(iucv_buffer_cpumask
))
531 /* No cpu could declare an iucv buffer. */
536 kfree(iucv_path_table
);
537 iucv_path_table
= NULL
;
545 * This function shuts down iucv. It disables iucv interrupts, retrieves
546 * the iucv interrupt buffer and frees the pathid table. Called after the
547 * last user unregister its iucv handler.
549 static void iucv_disable(void)
552 on_each_cpu(iucv_retrieve_cpu
, NULL
, 1);
553 kfree(iucv_path_table
);
554 iucv_path_table
= NULL
;
558 static int __cpuinit
iucv_cpu_notify(struct notifier_block
*self
,
559 unsigned long action
, void *hcpu
)
562 long cpu
= (long) hcpu
;
566 case CPU_UP_PREPARE_FROZEN
:
567 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
568 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
569 if (!iucv_irq_data
[cpu
])
571 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
572 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
573 if (!iucv_param
[cpu
]) {
574 kfree(iucv_irq_data
[cpu
]);
575 iucv_irq_data
[cpu
] = NULL
;
579 case CPU_UP_CANCELED
:
580 case CPU_UP_CANCELED_FROZEN
:
582 case CPU_DEAD_FROZEN
:
583 kfree(iucv_param
[cpu
]);
584 iucv_param
[cpu
] = NULL
;
585 kfree(iucv_irq_data
[cpu
]);
586 iucv_irq_data
[cpu
] = NULL
;
589 case CPU_ONLINE_FROZEN
:
590 case CPU_DOWN_FAILED
:
591 case CPU_DOWN_FAILED_FROZEN
:
592 if (!iucv_path_table
)
594 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
596 case CPU_DOWN_PREPARE
:
597 case CPU_DOWN_PREPARE_FROZEN
:
598 if (!iucv_path_table
)
600 cpumask
= iucv_buffer_cpumask
;
601 cpu_clear(cpu
, cpumask
);
602 if (cpus_empty(cpumask
))
603 /* Can't offline last IUCV enabled cpu. */
605 smp_call_function_single(cpu
, iucv_retrieve_cpu
, NULL
, 1);
606 if (cpus_empty(iucv_irq_cpumask
))
607 smp_call_function_single(first_cpu(iucv_buffer_cpumask
),
608 iucv_allow_cpu
, NULL
, 1);
614 static struct notifier_block __refdata iucv_cpu_notifier
= {
615 .notifier_call
= iucv_cpu_notify
,
620 * @pathid: path identification number.
621 * @userdata: 16-bytes of user data.
623 * Sever an iucv path to free up the pathid. Used internally.
625 static int iucv_sever_pathid(u16 pathid
, u8 userdata
[16])
627 union iucv_param
*parm
;
629 parm
= iucv_param
[smp_processor_id()];
630 memset(parm
, 0, sizeof(union iucv_param
));
632 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
633 parm
->ctrl
.ippathid
= pathid
;
634 return iucv_call_b2f0(IUCV_SEVER
, parm
);
638 * __iucv_cleanup_queue
639 * @dummy: unused dummy argument
641 * Nop function called via smp_call_function to force work items from
642 * pending external iucv interrupts to the work queue.
644 static void __iucv_cleanup_queue(void *dummy
)
651 * Function called after a path has been severed to find all remaining
652 * work items for the now stale pathid. The caller needs to hold the
655 static void iucv_cleanup_queue(void)
657 struct iucv_irq_list
*p
, *n
;
660 * When a path is severed, the pathid can be reused immediatly
661 * on a iucv connect or a connection pending interrupt. Remove
662 * all entries from the task queue that refer to a stale pathid
663 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
664 * or deliver the connection pending interrupt. To get all the
665 * pending interrupts force them to the work queue by calling
666 * an empty function on all cpus.
668 smp_call_function(__iucv_cleanup_queue
, NULL
, 1);
669 spin_lock_irq(&iucv_queue_lock
);
670 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
) {
671 /* Remove stale work items from the task queue. */
672 if (iucv_path_table
[p
->data
.ippathid
] == NULL
) {
677 spin_unlock_irq(&iucv_queue_lock
);
682 * @handler: address of iucv handler structure
683 * @smp: != 0 indicates that the handler can deal with out of order messages
685 * Registers a driver with IUCV.
687 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
688 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
690 int iucv_register(struct iucv_handler
*handler
, int smp
)
696 mutex_lock(&iucv_register_mutex
);
698 iucv_nonsmp_handler
++;
699 if (list_empty(&iucv_handler_list
)) {
703 } else if (!smp
&& iucv_nonsmp_handler
== 1)
705 INIT_LIST_HEAD(&handler
->paths
);
707 spin_lock_bh(&iucv_table_lock
);
708 list_add_tail(&handler
->list
, &iucv_handler_list
);
709 spin_unlock_bh(&iucv_table_lock
);
712 mutex_unlock(&iucv_register_mutex
);
715 EXPORT_SYMBOL(iucv_register
);
719 * @handler: address of iucv handler structure
720 * @smp: != 0 indicates that the handler can deal with out of order messages
722 * Unregister driver from IUCV.
724 void iucv_unregister(struct iucv_handler
*handler
, int smp
)
726 struct iucv_path
*p
, *n
;
728 mutex_lock(&iucv_register_mutex
);
729 spin_lock_bh(&iucv_table_lock
);
730 /* Remove handler from the iucv_handler_list. */
731 list_del_init(&handler
->list
);
732 /* Sever all pathids still refering to the handler. */
733 list_for_each_entry_safe(p
, n
, &handler
->paths
, list
) {
734 iucv_sever_pathid(p
->pathid
, NULL
);
735 iucv_path_table
[p
->pathid
] = NULL
;
739 spin_unlock_bh(&iucv_table_lock
);
741 iucv_nonsmp_handler
--;
742 if (list_empty(&iucv_handler_list
))
744 else if (!smp
&& iucv_nonsmp_handler
== 0)
746 mutex_unlock(&iucv_register_mutex
);
748 EXPORT_SYMBOL(iucv_unregister
);
752 * @path: address of iucv path structure
753 * @handler: address of iucv handler structure
754 * @userdata: 16 bytes of data reflected to the communication partner
755 * @private: private data passed to interrupt handlers for this path
757 * This function is issued after the user received a connection pending
758 * external interrupt and now wishes to complete the IUCV communication path.
760 * Returns the result of the CP IUCV call.
762 int iucv_path_accept(struct iucv_path
*path
, struct iucv_handler
*handler
,
763 u8 userdata
[16], void *private)
765 union iucv_param
*parm
;
769 /* Prepare parameter block. */
770 parm
= iucv_param
[smp_processor_id()];
771 memset(parm
, 0, sizeof(union iucv_param
));
772 parm
->ctrl
.ippathid
= path
->pathid
;
773 parm
->ctrl
.ipmsglim
= path
->msglim
;
775 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
776 parm
->ctrl
.ipflags1
= path
->flags
;
778 rc
= iucv_call_b2f0(IUCV_ACCEPT
, parm
);
780 path
->private = private;
781 path
->msglim
= parm
->ctrl
.ipmsglim
;
782 path
->flags
= parm
->ctrl
.ipflags1
;
787 EXPORT_SYMBOL(iucv_path_accept
);
791 * @path: address of iucv path structure
792 * @handler: address of iucv handler structure
793 * @userid: 8-byte user identification
794 * @system: 8-byte target system identification
795 * @userdata: 16 bytes of data reflected to the communication partner
796 * @private: private data passed to interrupt handlers for this path
798 * This function establishes an IUCV path. Although the connect may complete
799 * successfully, you are not able to use the path until you receive an IUCV
800 * Connection Complete external interrupt.
802 * Returns the result of the CP IUCV call.
804 int iucv_path_connect(struct iucv_path
*path
, struct iucv_handler
*handler
,
805 u8 userid
[8], u8 system
[8], u8 userdata
[16],
808 union iucv_param
*parm
;
811 spin_lock_bh(&iucv_table_lock
);
812 iucv_cleanup_queue();
813 parm
= iucv_param
[smp_processor_id()];
814 memset(parm
, 0, sizeof(union iucv_param
));
815 parm
->ctrl
.ipmsglim
= path
->msglim
;
816 parm
->ctrl
.ipflags1
= path
->flags
;
818 memcpy(parm
->ctrl
.ipvmid
, userid
, sizeof(parm
->ctrl
.ipvmid
));
819 ASCEBC(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
820 EBC_TOUPPER(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
823 memcpy(parm
->ctrl
.iptarget
, system
,
824 sizeof(parm
->ctrl
.iptarget
));
825 ASCEBC(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
826 EBC_TOUPPER(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
829 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
831 rc
= iucv_call_b2f0(IUCV_CONNECT
, parm
);
833 if (parm
->ctrl
.ippathid
< iucv_max_pathid
) {
834 path
->pathid
= parm
->ctrl
.ippathid
;
835 path
->msglim
= parm
->ctrl
.ipmsglim
;
836 path
->flags
= parm
->ctrl
.ipflags1
;
837 path
->handler
= handler
;
838 path
->private = private;
839 list_add_tail(&path
->list
, &handler
->paths
);
840 iucv_path_table
[path
->pathid
] = path
;
842 iucv_sever_pathid(parm
->ctrl
.ippathid
,
847 spin_unlock_bh(&iucv_table_lock
);
850 EXPORT_SYMBOL(iucv_path_connect
);
854 * @path: address of iucv path structure
855 * @userdata: 16 bytes of data reflected to the communication partner
857 * This function temporarily suspends incoming messages on an IUCV path.
858 * You can later reactivate the path by invoking the iucv_resume function.
860 * Returns the result from the CP IUCV call.
862 int iucv_path_quiesce(struct iucv_path
*path
, u8 userdata
[16])
864 union iucv_param
*parm
;
868 parm
= iucv_param
[smp_processor_id()];
869 memset(parm
, 0, sizeof(union iucv_param
));
871 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
872 parm
->ctrl
.ippathid
= path
->pathid
;
873 rc
= iucv_call_b2f0(IUCV_QUIESCE
, parm
);
877 EXPORT_SYMBOL(iucv_path_quiesce
);
881 * @path: address of iucv path structure
882 * @userdata: 16 bytes of data reflected to the communication partner
884 * This function resumes incoming messages on an IUCV path that has
885 * been stopped with iucv_path_quiesce.
887 * Returns the result from the CP IUCV call.
889 int iucv_path_resume(struct iucv_path
*path
, u8 userdata
[16])
891 union iucv_param
*parm
;
895 parm
= iucv_param
[smp_processor_id()];
896 memset(parm
, 0, sizeof(union iucv_param
));
898 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
899 parm
->ctrl
.ippathid
= path
->pathid
;
900 rc
= iucv_call_b2f0(IUCV_RESUME
, parm
);
907 * @path: address of iucv path structure
908 * @userdata: 16 bytes of data reflected to the communication partner
910 * This function terminates an IUCV path.
912 * Returns the result from the CP IUCV call.
914 int iucv_path_sever(struct iucv_path
*path
, u8 userdata
[16])
919 if (iucv_active_cpu
!= smp_processor_id())
920 spin_lock_bh(&iucv_table_lock
);
921 rc
= iucv_sever_pathid(path
->pathid
, userdata
);
923 iucv_path_table
[path
->pathid
] = NULL
;
924 list_del_init(&path
->list
);
926 if (iucv_active_cpu
!= smp_processor_id())
927 spin_unlock_bh(&iucv_table_lock
);
931 EXPORT_SYMBOL(iucv_path_sever
);
935 * @path: address of iucv path structure
936 * @msg: address of iucv msg structure
937 * @srccls: source class of message
939 * Cancels a message you have sent.
941 * Returns the result from the CP IUCV call.
943 int iucv_message_purge(struct iucv_path
*path
, struct iucv_message
*msg
,
946 union iucv_param
*parm
;
950 parm
= iucv_param
[smp_processor_id()];
951 memset(parm
, 0, sizeof(union iucv_param
));
952 parm
->purge
.ippathid
= path
->pathid
;
953 parm
->purge
.ipmsgid
= msg
->id
;
954 parm
->purge
.ipsrccls
= srccls
;
955 parm
->purge
.ipflags1
= IUCV_IPSRCCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
;
956 rc
= iucv_call_b2f0(IUCV_PURGE
, parm
);
958 msg
->audit
= (*(u32
*) &parm
->purge
.ipaudit
) >> 8;
959 msg
->tag
= parm
->purge
.ipmsgtag
;
964 EXPORT_SYMBOL(iucv_message_purge
);
967 * iucv_message_receive_iprmdata
968 * @path: address of iucv path structure
969 * @msg: address of iucv msg structure
970 * @flags: how the message is received (IUCV_IPBUFLST)
971 * @buffer: address of data buffer or address of struct iucv_array
972 * @size: length of data buffer
975 * Internal function used by iucv_message_receive and __iucv_message_receive
976 * to receive RMDATA data stored in struct iucv_message.
978 static int iucv_message_receive_iprmdata(struct iucv_path
*path
,
979 struct iucv_message
*msg
,
980 u8 flags
, void *buffer
,
981 size_t size
, size_t *residual
)
983 struct iucv_array
*array
;
988 * Message is 8 bytes long and has been stored to the
989 * message descriptor itself.
992 *residual
= abs(size
- 8);
994 if (flags
& IUCV_IPBUFLST
) {
995 /* Copy to struct iucv_array. */
996 size
= (size
< 8) ? size
: 8;
997 for (array
= buffer
; size
> 0; array
++) {
998 copy
= min_t(size_t, size
, array
->length
);
999 memcpy((u8
*)(addr_t
) array
->address
,
1005 /* Copy to direct buffer. */
1006 memcpy(buffer
, rmmsg
, min_t(size_t, size
, 8));
1012 * __iucv_message_receive
1013 * @path: address of iucv path structure
1014 * @msg: address of iucv msg structure
1015 * @flags: how the message is received (IUCV_IPBUFLST)
1016 * @buffer: address of data buffer or address of struct iucv_array
1017 * @size: length of data buffer
1020 * This function receives messages that are being sent to you over
1021 * established paths. This function will deal with RMDATA messages
1022 * embedded in struct iucv_message as well.
1024 * Locking: no locking
1026 * Returns the result from the CP IUCV call.
1028 int __iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1029 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1031 union iucv_param
*parm
;
1034 if (msg
->flags
& IUCV_IPRMDATA
)
1035 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1036 buffer
, size
, residual
);
1037 parm
= iucv_param
[smp_processor_id()];
1038 memset(parm
, 0, sizeof(union iucv_param
));
1039 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1040 parm
->db
.ipbfln1f
= (u32
) size
;
1041 parm
->db
.ipmsgid
= msg
->id
;
1042 parm
->db
.ippathid
= path
->pathid
;
1043 parm
->db
.iptrgcls
= msg
->class;
1044 parm
->db
.ipflags1
= (flags
| IUCV_IPFGPID
|
1045 IUCV_IPFGMID
| IUCV_IPTRGCLS
);
1046 rc
= iucv_call_b2f0(IUCV_RECEIVE
, parm
);
1047 if (!rc
|| rc
== 5) {
1048 msg
->flags
= parm
->db
.ipflags1
;
1050 *residual
= parm
->db
.ipbfln1f
;
1054 EXPORT_SYMBOL(__iucv_message_receive
);
1057 * iucv_message_receive
1058 * @path: address of iucv path structure
1059 * @msg: address of iucv msg structure
1060 * @flags: how the message is received (IUCV_IPBUFLST)
1061 * @buffer: address of data buffer or address of struct iucv_array
1062 * @size: length of data buffer
1065 * This function receives messages that are being sent to you over
1066 * established paths. This function will deal with RMDATA messages
1067 * embedded in struct iucv_message as well.
1069 * Locking: local_bh_enable/local_bh_disable
1071 * Returns the result from the CP IUCV call.
1073 int iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1074 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1078 if (msg
->flags
& IUCV_IPRMDATA
)
1079 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1080 buffer
, size
, residual
);
1082 rc
= __iucv_message_receive(path
, msg
, flags
, buffer
, size
, residual
);
1086 EXPORT_SYMBOL(iucv_message_receive
);
1089 * iucv_message_reject
1090 * @path: address of iucv path structure
1091 * @msg: address of iucv msg structure
1093 * The reject function refuses a specified message. Between the time you
1094 * are notified of a message and the time that you complete the message,
1095 * the message may be rejected.
1097 * Returns the result from the CP IUCV call.
1099 int iucv_message_reject(struct iucv_path
*path
, struct iucv_message
*msg
)
1101 union iucv_param
*parm
;
1105 parm
= iucv_param
[smp_processor_id()];
1106 memset(parm
, 0, sizeof(union iucv_param
));
1107 parm
->db
.ippathid
= path
->pathid
;
1108 parm
->db
.ipmsgid
= msg
->id
;
1109 parm
->db
.iptrgcls
= msg
->class;
1110 parm
->db
.ipflags1
= (IUCV_IPTRGCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
);
1111 rc
= iucv_call_b2f0(IUCV_REJECT
, parm
);
1115 EXPORT_SYMBOL(iucv_message_reject
);
1118 * iucv_message_reply
1119 * @path: address of iucv path structure
1120 * @msg: address of iucv msg structure
1121 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1122 * @reply: address of reply data buffer or address of struct iucv_array
1123 * @size: length of reply data buffer
1125 * This function responds to the two-way messages that you receive. You
1126 * must identify completely the message to which you wish to reply. ie,
1127 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1128 * the parameter list.
1130 * Returns the result from the CP IUCV call.
1132 int iucv_message_reply(struct iucv_path
*path
, struct iucv_message
*msg
,
1133 u8 flags
, void *reply
, size_t size
)
1135 union iucv_param
*parm
;
1139 parm
= iucv_param
[smp_processor_id()];
1140 memset(parm
, 0, sizeof(union iucv_param
));
1141 if (flags
& IUCV_IPRMDATA
) {
1142 parm
->dpl
.ippathid
= path
->pathid
;
1143 parm
->dpl
.ipflags1
= flags
;
1144 parm
->dpl
.ipmsgid
= msg
->id
;
1145 parm
->dpl
.iptrgcls
= msg
->class;
1146 memcpy(parm
->dpl
.iprmmsg
, reply
, min_t(size_t, size
, 8));
1148 parm
->db
.ipbfadr1
= (u32
)(addr_t
) reply
;
1149 parm
->db
.ipbfln1f
= (u32
) size
;
1150 parm
->db
.ippathid
= path
->pathid
;
1151 parm
->db
.ipflags1
= flags
;
1152 parm
->db
.ipmsgid
= msg
->id
;
1153 parm
->db
.iptrgcls
= msg
->class;
1155 rc
= iucv_call_b2f0(IUCV_REPLY
, parm
);
1159 EXPORT_SYMBOL(iucv_message_reply
);
1162 * __iucv_message_send
1163 * @path: address of iucv path structure
1164 * @msg: address of iucv msg structure
1165 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1166 * @srccls: source class of message
1167 * @buffer: address of send buffer or address of struct iucv_array
1168 * @size: length of send buffer
1170 * This function transmits data to another application. Data to be
1171 * transmitted is in a buffer and this is a one-way message and the
1172 * receiver will not reply to the message.
1174 * Locking: no locking
1176 * Returns the result from the CP IUCV call.
1178 int __iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1179 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1181 union iucv_param
*parm
;
1184 parm
= iucv_param
[smp_processor_id()];
1185 memset(parm
, 0, sizeof(union iucv_param
));
1186 if (flags
& IUCV_IPRMDATA
) {
1187 /* Message of 8 bytes can be placed into the parameter list. */
1188 parm
->dpl
.ippathid
= path
->pathid
;
1189 parm
->dpl
.ipflags1
= flags
| IUCV_IPNORPY
;
1190 parm
->dpl
.iptrgcls
= msg
->class;
1191 parm
->dpl
.ipsrccls
= srccls
;
1192 parm
->dpl
.ipmsgtag
= msg
->tag
;
1193 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1195 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1196 parm
->db
.ipbfln1f
= (u32
) size
;
1197 parm
->db
.ippathid
= path
->pathid
;
1198 parm
->db
.ipflags1
= flags
| IUCV_IPNORPY
;
1199 parm
->db
.iptrgcls
= msg
->class;
1200 parm
->db
.ipsrccls
= srccls
;
1201 parm
->db
.ipmsgtag
= msg
->tag
;
1203 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1205 msg
->id
= parm
->db
.ipmsgid
;
1208 EXPORT_SYMBOL(__iucv_message_send
);
1212 * @path: address of iucv path structure
1213 * @msg: address of iucv msg structure
1214 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1215 * @srccls: source class of message
1216 * @buffer: address of send buffer or address of struct iucv_array
1217 * @size: length of send buffer
1219 * This function transmits data to another application. Data to be
1220 * transmitted is in a buffer and this is a one-way message and the
1221 * receiver will not reply to the message.
1223 * Locking: local_bh_enable/local_bh_disable
1225 * Returns the result from the CP IUCV call.
1227 int iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1228 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1233 rc
= __iucv_message_send(path
, msg
, flags
, srccls
, buffer
, size
);
1237 EXPORT_SYMBOL(iucv_message_send
);
1240 * iucv_message_send2way
1241 * @path: address of iucv path structure
1242 * @msg: address of iucv msg structure
1243 * @flags: how the message is sent and the reply is received
1244 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1245 * @srccls: source class of message
1246 * @buffer: address of send buffer or address of struct iucv_array
1247 * @size: length of send buffer
1248 * @ansbuf: address of answer buffer or address of struct iucv_array
1249 * @asize: size of reply buffer
1251 * This function transmits data to another application. Data to be
1252 * transmitted is in a buffer. The receiver of the send is expected to
1253 * reply to the message and a buffer is provided into which IUCV moves
1254 * the reply to this message.
1256 * Returns the result from the CP IUCV call.
1258 int iucv_message_send2way(struct iucv_path
*path
, struct iucv_message
*msg
,
1259 u8 flags
, u32 srccls
, void *buffer
, size_t size
,
1260 void *answer
, size_t asize
, size_t *residual
)
1262 union iucv_param
*parm
;
1266 parm
= iucv_param
[smp_processor_id()];
1267 memset(parm
, 0, sizeof(union iucv_param
));
1268 if (flags
& IUCV_IPRMDATA
) {
1269 parm
->dpl
.ippathid
= path
->pathid
;
1270 parm
->dpl
.ipflags1
= path
->flags
; /* priority message */
1271 parm
->dpl
.iptrgcls
= msg
->class;
1272 parm
->dpl
.ipsrccls
= srccls
;
1273 parm
->dpl
.ipmsgtag
= msg
->tag
;
1274 parm
->dpl
.ipbfadr2
= (u32
)(addr_t
) answer
;
1275 parm
->dpl
.ipbfln2f
= (u32
) asize
;
1276 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1278 parm
->db
.ippathid
= path
->pathid
;
1279 parm
->db
.ipflags1
= path
->flags
; /* priority message */
1280 parm
->db
.iptrgcls
= msg
->class;
1281 parm
->db
.ipsrccls
= srccls
;
1282 parm
->db
.ipmsgtag
= msg
->tag
;
1283 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1284 parm
->db
.ipbfln1f
= (u32
) size
;
1285 parm
->db
.ipbfadr2
= (u32
)(addr_t
) answer
;
1286 parm
->db
.ipbfln2f
= (u32
) asize
;
1288 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1290 msg
->id
= parm
->db
.ipmsgid
;
1294 EXPORT_SYMBOL(iucv_message_send2way
);
1298 * @data: Pointer to external interrupt buffer
1300 * Process connection pending work item. Called from tasklet while holding
1303 struct iucv_path_pending
{
1314 } __attribute__ ((packed
));
1316 static void iucv_path_pending(struct iucv_irq_data
*data
)
1318 struct iucv_path_pending
*ipp
= (void *) data
;
1319 struct iucv_handler
*handler
;
1320 struct iucv_path
*path
;
1323 BUG_ON(iucv_path_table
[ipp
->ippathid
]);
1324 /* New pathid, handler found. Create a new path struct. */
1325 error
= iucv_error_no_memory
;
1326 path
= iucv_path_alloc(ipp
->ipmsglim
, ipp
->ipflags1
, GFP_ATOMIC
);
1329 path
->pathid
= ipp
->ippathid
;
1330 iucv_path_table
[path
->pathid
] = path
;
1331 EBCASC(ipp
->ipvmid
, 8);
1333 /* Call registered handler until one is found that wants the path. */
1334 list_for_each_entry(handler
, &iucv_handler_list
, list
) {
1335 if (!handler
->path_pending
)
1338 * Add path to handler to allow a call to iucv_path_sever
1339 * inside the path_pending function. If the handler returns
1340 * an error remove the path from the handler again.
1342 list_add(&path
->list
, &handler
->paths
);
1343 path
->handler
= handler
;
1344 if (!handler
->path_pending(path
, ipp
->ipvmid
, ipp
->ipuser
))
1346 list_del(&path
->list
);
1347 path
->handler
= NULL
;
1349 /* No handler wanted the path. */
1350 iucv_path_table
[path
->pathid
] = NULL
;
1351 iucv_path_free(path
);
1352 error
= iucv_error_no_listener
;
1354 iucv_sever_pathid(ipp
->ippathid
, error
);
1358 * iucv_path_complete
1359 * @data: Pointer to external interrupt buffer
1361 * Process connection complete work item. Called from tasklet while holding
1364 struct iucv_path_complete
{
1375 } __attribute__ ((packed
));
1377 static void iucv_path_complete(struct iucv_irq_data
*data
)
1379 struct iucv_path_complete
*ipc
= (void *) data
;
1380 struct iucv_path
*path
= iucv_path_table
[ipc
->ippathid
];
1382 if (path
&& path
->handler
&& path
->handler
->path_complete
)
1383 path
->handler
->path_complete(path
, ipc
->ipuser
);
1388 * @data: Pointer to external interrupt buffer
1390 * Process connection severed work item. Called from tasklet while holding
1393 struct iucv_path_severed
{
1403 } __attribute__ ((packed
));
1405 static void iucv_path_severed(struct iucv_irq_data
*data
)
1407 struct iucv_path_severed
*ips
= (void *) data
;
1408 struct iucv_path
*path
= iucv_path_table
[ips
->ippathid
];
1410 if (!path
|| !path
->handler
) /* Already severed */
1412 if (path
->handler
->path_severed
)
1413 path
->handler
->path_severed(path
, ips
->ipuser
);
1415 iucv_sever_pathid(path
->pathid
, NULL
);
1416 iucv_path_table
[path
->pathid
] = NULL
;
1417 list_del_init(&path
->list
);
1418 iucv_path_free(path
);
1423 * iucv_path_quiesced
1424 * @data: Pointer to external interrupt buffer
1426 * Process connection quiesced work item. Called from tasklet while holding
1429 struct iucv_path_quiesced
{
1439 } __attribute__ ((packed
));
1441 static void iucv_path_quiesced(struct iucv_irq_data
*data
)
1443 struct iucv_path_quiesced
*ipq
= (void *) data
;
1444 struct iucv_path
*path
= iucv_path_table
[ipq
->ippathid
];
1446 if (path
&& path
->handler
&& path
->handler
->path_quiesced
)
1447 path
->handler
->path_quiesced(path
, ipq
->ipuser
);
1452 * @data: Pointer to external interrupt buffer
1454 * Process connection resumed work item. Called from tasklet while holding
1457 struct iucv_path_resumed
{
1467 } __attribute__ ((packed
));
1469 static void iucv_path_resumed(struct iucv_irq_data
*data
)
1471 struct iucv_path_resumed
*ipr
= (void *) data
;
1472 struct iucv_path
*path
= iucv_path_table
[ipr
->ippathid
];
1474 if (path
&& path
->handler
&& path
->handler
->path_resumed
)
1475 path
->handler
->path_resumed(path
, ipr
->ipuser
);
1479 * iucv_message_complete
1480 * @data: Pointer to external interrupt buffer
1482 * Process message complete work item. Called from tasklet while holding
1485 struct iucv_message_complete
{
1498 } __attribute__ ((packed
));
1500 static void iucv_message_complete(struct iucv_irq_data
*data
)
1502 struct iucv_message_complete
*imc
= (void *) data
;
1503 struct iucv_path
*path
= iucv_path_table
[imc
->ippathid
];
1504 struct iucv_message msg
;
1506 if (path
&& path
->handler
&& path
->handler
->message_complete
) {
1507 msg
.flags
= imc
->ipflags1
;
1508 msg
.id
= imc
->ipmsgid
;
1509 msg
.audit
= imc
->ipaudit
;
1510 memcpy(msg
.rmmsg
, imc
->iprmmsg
, 8);
1511 msg
.class = imc
->ipsrccls
;
1512 msg
.tag
= imc
->ipmsgtag
;
1513 msg
.length
= imc
->ipbfln2f
;
1514 path
->handler
->message_complete(path
, &msg
);
1519 * iucv_message_pending
1520 * @data: Pointer to external interrupt buffer
1522 * Process message pending work item. Called from tasklet while holding
1525 struct iucv_message_pending
{
1543 } __attribute__ ((packed
));
1545 static void iucv_message_pending(struct iucv_irq_data
*data
)
1547 struct iucv_message_pending
*imp
= (void *) data
;
1548 struct iucv_path
*path
= iucv_path_table
[imp
->ippathid
];
1549 struct iucv_message msg
;
1551 if (path
&& path
->handler
&& path
->handler
->message_pending
) {
1552 msg
.flags
= imp
->ipflags1
;
1553 msg
.id
= imp
->ipmsgid
;
1554 msg
.class = imp
->iptrgcls
;
1555 if (imp
->ipflags1
& IUCV_IPRMDATA
) {
1556 memcpy(msg
.rmmsg
, imp
->ln1msg1
.iprmmsg1
, 8);
1559 msg
.length
= imp
->ln1msg2
.ipbfln1f
;
1560 msg
.reply_size
= imp
->ipbfln2f
;
1561 path
->handler
->message_pending(path
, &msg
);
1568 * This tasklet loops over the queue of irq buffers created by
1569 * iucv_external_interrupt, calls the appropriate action handler
1570 * and then frees the buffer.
1572 static void iucv_tasklet_fn(unsigned long ignored
)
1574 typedef void iucv_irq_fn(struct iucv_irq_data
*);
1575 static iucv_irq_fn
*irq_fn
[] = {
1576 [0x02] = iucv_path_complete
,
1577 [0x03] = iucv_path_severed
,
1578 [0x04] = iucv_path_quiesced
,
1579 [0x05] = iucv_path_resumed
,
1580 [0x06] = iucv_message_complete
,
1581 [0x07] = iucv_message_complete
,
1582 [0x08] = iucv_message_pending
,
1583 [0x09] = iucv_message_pending
,
1585 LIST_HEAD(task_queue
);
1586 struct iucv_irq_list
*p
, *n
;
1588 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1589 if (!spin_trylock(&iucv_table_lock
)) {
1590 tasklet_schedule(&iucv_tasklet
);
1593 iucv_active_cpu
= smp_processor_id();
1595 spin_lock_irq(&iucv_queue_lock
);
1596 list_splice_init(&iucv_task_queue
, &task_queue
);
1597 spin_unlock_irq(&iucv_queue_lock
);
1599 list_for_each_entry_safe(p
, n
, &task_queue
, list
) {
1600 list_del_init(&p
->list
);
1601 irq_fn
[p
->data
.iptype
](&p
->data
);
1605 iucv_active_cpu
= -1;
1606 spin_unlock(&iucv_table_lock
);
1612 * This work function loops over the queue of path pending irq blocks
1613 * created by iucv_external_interrupt, calls the appropriate action
1614 * handler and then frees the buffer.
1616 static void iucv_work_fn(struct work_struct
*work
)
1618 typedef void iucv_irq_fn(struct iucv_irq_data
*);
1619 LIST_HEAD(work_queue
);
1620 struct iucv_irq_list
*p
, *n
;
1622 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1623 spin_lock_bh(&iucv_table_lock
);
1624 iucv_active_cpu
= smp_processor_id();
1626 spin_lock_irq(&iucv_queue_lock
);
1627 list_splice_init(&iucv_work_queue
, &work_queue
);
1628 spin_unlock_irq(&iucv_queue_lock
);
1630 iucv_cleanup_queue();
1631 list_for_each_entry_safe(p
, n
, &work_queue
, list
) {
1632 list_del_init(&p
->list
);
1633 iucv_path_pending(&p
->data
);
1637 iucv_active_cpu
= -1;
1638 spin_unlock_bh(&iucv_table_lock
);
1642 * iucv_external_interrupt
1645 * Handles external interrupts coming in from CP.
1646 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1648 static void iucv_external_interrupt(u16 code
)
1650 struct iucv_irq_data
*p
;
1651 struct iucv_irq_list
*work
;
1653 p
= iucv_irq_data
[smp_processor_id()];
1654 if (p
->ippathid
>= iucv_max_pathid
) {
1655 WARN_ON(p
->ippathid
>= iucv_max_pathid
);
1656 iucv_sever_pathid(p
->ippathid
, iucv_error_no_listener
);
1659 BUG_ON(p
->iptype
< 0x01 || p
->iptype
> 0x09);
1660 work
= kmalloc(sizeof(struct iucv_irq_list
), GFP_ATOMIC
);
1662 pr_warning("iucv_external_interrupt: out of memory\n");
1665 memcpy(&work
->data
, p
, sizeof(work
->data
));
1666 spin_lock(&iucv_queue_lock
);
1667 if (p
->iptype
== 0x01) {
1668 /* Path pending interrupt. */
1669 list_add_tail(&work
->list
, &iucv_work_queue
);
1670 schedule_work(&iucv_work
);
1672 /* The other interrupts. */
1673 list_add_tail(&work
->list
, &iucv_task_queue
);
1674 tasklet_schedule(&iucv_tasklet
);
1676 spin_unlock(&iucv_queue_lock
);
1682 * Allocates and initializes various data structures.
1684 static int __init
iucv_init(void)
1689 if (!MACHINE_IS_VM
) {
1690 rc
= -EPROTONOSUPPORT
;
1693 rc
= iucv_query_maxconn();
1696 rc
= register_external_interrupt(0x4000, iucv_external_interrupt
);
1699 iucv_root
= s390_root_dev_register("iucv");
1700 if (IS_ERR(iucv_root
)) {
1701 rc
= PTR_ERR(iucv_root
);
1705 for_each_online_cpu(cpu
) {
1706 /* Note: GFP_DMA used to get memory below 2G */
1707 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
1708 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
1709 if (!iucv_irq_data
[cpu
]) {
1714 /* Allocate parameter blocks. */
1715 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
1716 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
1717 if (!iucv_param
[cpu
]) {
1722 rc
= register_hotcpu_notifier(&iucv_cpu_notifier
);
1725 ASCEBC(iucv_error_no_listener
, 16);
1726 ASCEBC(iucv_error_no_memory
, 16);
1727 ASCEBC(iucv_error_pathid
, 16);
1729 rc
= bus_register(&iucv_bus
);
1735 unregister_hotcpu_notifier(&iucv_cpu_notifier
);
1737 for_each_possible_cpu(cpu
) {
1738 kfree(iucv_param
[cpu
]);
1739 iucv_param
[cpu
] = NULL
;
1740 kfree(iucv_irq_data
[cpu
]);
1741 iucv_irq_data
[cpu
] = NULL
;
1743 s390_root_dev_unregister(iucv_root
);
1745 unregister_external_interrupt(0x4000, iucv_external_interrupt
);
1753 * Frees everything allocated from iucv_init.
1755 static void __exit
iucv_exit(void)
1757 struct iucv_irq_list
*p
, *n
;
1760 spin_lock_irq(&iucv_queue_lock
);
1761 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
)
1763 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
)
1765 spin_unlock_irq(&iucv_queue_lock
);
1766 unregister_hotcpu_notifier(&iucv_cpu_notifier
);
1767 for_each_possible_cpu(cpu
) {
1768 kfree(iucv_param
[cpu
]);
1769 iucv_param
[cpu
] = NULL
;
1770 kfree(iucv_irq_data
[cpu
]);
1771 iucv_irq_data
[cpu
] = NULL
;
1773 s390_root_dev_unregister(iucv_root
);
1774 bus_unregister(&iucv_bus
);
1775 unregister_external_interrupt(0x4000, iucv_external_interrupt
);
1778 subsys_initcall(iucv_init
);
1779 module_exit(iucv_exit
);
1781 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1782 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1783 MODULE_LICENSE("GPL");