2 * IUCV base infrastructure.
4 * Copyright IBM Corp. 2001, 2009
8 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
9 * Xenia Tkatschow (xenia@us.ibm.com)
10 * 2Gb awareness and general cleanup:
11 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
12 * Rewritten for af_iucv:
13 * Martin Schwidefsky <schwidefsky@de.ibm.com>
17 * CP Programming Service, IBM document # SC24-5760
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #define KMSG_COMPONENT "iucv"
35 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
37 #include <linux/module.h>
38 #include <linux/moduleparam.h>
39 #include <linux/spinlock.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/init.h>
43 #include <linux/interrupt.h>
44 #include <linux/list.h>
45 #include <linux/errno.h>
46 #include <linux/err.h>
47 #include <linux/device.h>
48 #include <linux/cpu.h>
49 #include <linux/reboot.h>
50 #include <net/iucv/iucv.h>
51 #include <asm/atomic.h>
52 #include <asm/ebcdic.h>
54 #include <asm/s390_ext.h>
59 * All flags are defined in the field IPFLAGS1 of each function
60 * and can be found in CP Programming Services.
61 * IPSRCCLS - Indicates you have specified a source class.
62 * IPTRGCLS - Indicates you have specified a target class.
63 * IPFGPID - Indicates you have specified a pathid.
64 * IPFGMID - Indicates you have specified a message ID.
65 * IPNORPY - Indicates a one-way message. No reply expected.
66 * IPALL - Indicates that all paths are affected.
68 #define IUCV_IPSRCCLS 0x01
69 #define IUCV_IPTRGCLS 0x01
70 #define IUCV_IPFGPID 0x02
71 #define IUCV_IPFGMID 0x04
72 #define IUCV_IPNORPY 0x10
73 #define IUCV_IPALL 0x80
75 static int iucv_bus_match(struct device *dev, struct device_driver *drv)
80 struct bus_type iucv_bus = {
82 .match = iucv_bus_match,
84 EXPORT_SYMBOL(iucv_bus);
86 struct device *iucv_root;
87 EXPORT_SYMBOL(iucv_root);
89 static int iucv_available;
91 /* General IUCV interrupt structure */
92 struct iucv_irq_data {
99 struct iucv_irq_list {
100 struct list_head list;
101 struct iucv_irq_data data;
104 static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
105 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
106 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
109 * Queue of interrupt buffers lock for delivery via the tasklet
110 * (fast but can't call smp_call_function).
112 static LIST_HEAD(iucv_task_queue);
115 * The tasklet for fast delivery of iucv interrupts.
117 static void iucv_tasklet_fn(unsigned long);
118 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
121 * Queue of interrupt buffers for delivery via a work queue
122 * (slower but can call smp_call_function).
124 static LIST_HEAD(iucv_work_queue);
127 * The work element to deliver path pending interrupts.
129 static void iucv_work_fn(struct work_struct *work);
130 static DECLARE_WORK(iucv_work, iucv_work_fn);
133 * Spinlock protecting task and work queue.
135 static DEFINE_SPINLOCK(iucv_queue_lock);
137 enum iucv_command_codes {
139 IUCV_RETRIEVE_BUFFER = 2,
147 IUCV_DECLARE_BUFFER = 12,
155 * Error messages that are used with the iucv_sever function. They get
156 * converted to EBCDIC.
158 static char iucv_error_no_listener[16] = "NO LISTENER";
159 static char iucv_error_no_memory[16] = "NO MEMORY";
160 static char iucv_error_pathid[16] = "INVALID PATHID";
163 * iucv_handler_list: List of registered handlers.
165 static LIST_HEAD(iucv_handler_list);
168 * iucv_path_table: an array of iucv_path structures.
170 static struct iucv_path **iucv_path_table;
171 static unsigned long iucv_max_pathid;
174 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
176 static DEFINE_SPINLOCK(iucv_table_lock);
179 * iucv_active_cpu: contains the number of the cpu executing the tasklet
180 * or the work handler. Needed for iucv_path_sever called from tasklet.
182 static int iucv_active_cpu = -1;
185 * Mutex and wait queue for iucv_register/iucv_unregister.
187 static DEFINE_MUTEX(iucv_register_mutex);
190 * Counter for number of non-smp capable handlers.
192 static int iucv_nonsmp_handler;
195 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
196 * iucv_path_quiesce and iucv_path_sever.
198 struct iucv_cmd_control {
207 } __attribute__ ((packed,aligned(8)));
210 * Data in parameter list iucv structure. Used by iucv_message_send,
211 * iucv_message_send2way and iucv_message_reply.
213 struct iucv_cmd_dpl {
225 } __attribute__ ((packed,aligned(8)));
228 * Data in buffer iucv structure. Used by iucv_message_receive,
229 * iucv_message_reject, iucv_message_send, iucv_message_send2way
230 * and iucv_declare_cpu.
245 } __attribute__ ((packed,aligned(8)));
248 * Purge message iucv structure. Used by iucv_message_purge.
250 struct iucv_cmd_purge {
261 } __attribute__ ((packed,aligned(8)));
264 * Set mask iucv structure. Used by iucv_enable_cpu.
266 struct iucv_cmd_set_mask {
271 } __attribute__ ((packed,aligned(8)));
274 struct iucv_cmd_control ctrl;
275 struct iucv_cmd_dpl dpl;
276 struct iucv_cmd_db db;
277 struct iucv_cmd_purge purge;
278 struct iucv_cmd_set_mask set_mask;
282 * Anchor for per-cpu IUCV command parameter block.
284 static union iucv_param *iucv_param[NR_CPUS];
285 static union iucv_param *iucv_param_irq[NR_CPUS];
289 * @code: identifier of IUCV call to CP.
290 * @parm: pointer to a struct iucv_parm block
292 * Calls CP to execute IUCV commands.
294 * Returns the result of the CP IUCV call.
296 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
298 register unsigned long reg0 asm ("0");
299 register unsigned long reg1 asm ("1");
303 reg1 = virt_to_phys(parm);
305 " .long 0xb2f01000\n"
308 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
309 : "m" (*parm) : "cc");
310 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
316 * Determines the maximum number of connections that may be established.
318 * Returns the maximum number of connections or -EPERM is IUCV is not
321 static int iucv_query_maxconn(void)
323 register unsigned long reg0 asm ("0");
324 register unsigned long reg1 asm ("1");
328 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
332 reg1 = (unsigned long) param;
334 " .long 0xb2f01000\n"
337 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
339 iucv_max_pathid = reg0;
341 return ccode ? -EPERM : 0;
348 * Allow iucv interrupts on this cpu.
350 static void iucv_allow_cpu(void *data)
352 int cpu = smp_processor_id();
353 union iucv_param *parm;
356 * Enable all iucv interrupts.
357 * ipmask contains bits for the different interrupts
358 * 0x80 - Flag to allow nonpriority message pending interrupts
359 * 0x40 - Flag to allow priority message pending interrupts
360 * 0x20 - Flag to allow nonpriority message completion interrupts
361 * 0x10 - Flag to allow priority message completion interrupts
362 * 0x08 - Flag to allow IUCV control interrupts
364 parm = iucv_param_irq[cpu];
365 memset(parm, 0, sizeof(union iucv_param));
366 parm->set_mask.ipmask = 0xf8;
367 iucv_call_b2f0(IUCV_SETMASK, parm);
369 /* Set indication that iucv interrupts are allowed for this cpu. */
370 cpu_set(cpu, iucv_irq_cpumask);
377 * Block iucv interrupts on this cpu.
379 static void iucv_block_cpu(void *data)
381 int cpu = smp_processor_id();
382 union iucv_param *parm;
384 /* Disable all iucv interrupts. */
385 parm = iucv_param_irq[cpu];
386 memset(parm, 0, sizeof(union iucv_param));
387 iucv_call_b2f0(IUCV_SETMASK, parm);
389 /* Clear indication that iucv interrupts are allowed for this cpu. */
390 cpu_clear(cpu, iucv_irq_cpumask);
397 * Declare a interrupt buffer on this cpu.
399 static void iucv_declare_cpu(void *data)
401 int cpu = smp_processor_id();
402 union iucv_param *parm;
405 if (cpu_isset(cpu, iucv_buffer_cpumask))
408 /* Declare interrupt buffer. */
409 parm = iucv_param_irq[cpu];
410 memset(parm, 0, sizeof(union iucv_param));
411 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
412 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
414 char *err = "Unknown";
417 err = "Directory error";
420 err = "Invalid length";
423 err = "Buffer already exists";
426 err = "Buffer overlap";
429 err = "Paging or storage error";
432 pr_warning("Defining an interrupt buffer on CPU %i"
433 " failed with 0x%02x (%s)\n", cpu, rc, err);
437 /* Set indication that an iucv buffer exists for this cpu. */
438 cpu_set(cpu, iucv_buffer_cpumask);
440 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
441 /* Enable iucv interrupts on this cpu. */
442 iucv_allow_cpu(NULL);
444 /* Disable iucv interrupts on this cpu. */
445 iucv_block_cpu(NULL);
452 * Retrieve interrupt buffer on this cpu.
454 static void iucv_retrieve_cpu(void *data)
456 int cpu = smp_processor_id();
457 union iucv_param *parm;
459 if (!cpu_isset(cpu, iucv_buffer_cpumask))
462 /* Block iucv interrupts. */
463 iucv_block_cpu(NULL);
465 /* Retrieve interrupt buffer. */
466 parm = iucv_param_irq[cpu];
467 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
469 /* Clear indication that an iucv buffer exists for this cpu. */
470 cpu_clear(cpu, iucv_buffer_cpumask);
476 * Allow iucv interrupts on all cpus.
478 static void iucv_setmask_mp(void)
483 for_each_online_cpu(cpu)
484 /* Enable all cpus with a declared buffer. */
485 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
486 !cpu_isset(cpu, iucv_irq_cpumask))
487 smp_call_function_single(cpu, iucv_allow_cpu,
495 * Allow iucv interrupts on a single cpu.
497 static void iucv_setmask_up(void)
502 /* Disable all cpu but the first in cpu_irq_cpumask. */
503 cpumask = iucv_irq_cpumask;
504 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
505 for_each_cpu_mask_nr(cpu, cpumask)
506 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
512 * This function makes iucv ready for use. It allocates the pathid
513 * table, declares an iucv interrupt buffer and enables the iucv
514 * interrupts. Called when the first user has registered an iucv
517 static int iucv_enable(void)
524 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
525 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
526 if (!iucv_path_table)
528 /* Declare per cpu buffers. */
530 for_each_online_cpu(cpu)
531 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
532 if (cpus_empty(iucv_buffer_cpumask))
533 /* No cpu could declare an iucv buffer. */
538 kfree(iucv_path_table);
539 iucv_path_table = NULL;
547 * This function shuts down iucv. It disables iucv interrupts, retrieves
548 * the iucv interrupt buffer and frees the pathid table. Called after the
549 * last user unregister its iucv handler.
551 static void iucv_disable(void)
554 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
555 kfree(iucv_path_table);
556 iucv_path_table = NULL;
560 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
561 unsigned long action, void *hcpu)
564 long cpu = (long) hcpu;
568 case CPU_UP_PREPARE_FROZEN:
569 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
570 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
571 if (!iucv_irq_data[cpu])
573 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
574 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
575 if (!iucv_param[cpu]) {
576 kfree(iucv_irq_data[cpu]);
577 iucv_irq_data[cpu] = NULL;
580 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
581 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
582 if (!iucv_param_irq[cpu]) {
583 kfree(iucv_param[cpu]);
584 iucv_param[cpu] = NULL;
585 kfree(iucv_irq_data[cpu]);
586 iucv_irq_data[cpu] = NULL;
590 case CPU_UP_CANCELED:
591 case CPU_UP_CANCELED_FROZEN:
593 case CPU_DEAD_FROZEN:
594 kfree(iucv_param_irq[cpu]);
595 iucv_param_irq[cpu] = NULL;
596 kfree(iucv_param[cpu]);
597 iucv_param[cpu] = NULL;
598 kfree(iucv_irq_data[cpu]);
599 iucv_irq_data[cpu] = NULL;
602 case CPU_ONLINE_FROZEN:
603 case CPU_DOWN_FAILED:
604 case CPU_DOWN_FAILED_FROZEN:
605 if (!iucv_path_table)
607 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
609 case CPU_DOWN_PREPARE:
610 case CPU_DOWN_PREPARE_FROZEN:
611 if (!iucv_path_table)
613 cpumask = iucv_buffer_cpumask;
614 cpu_clear(cpu, cpumask);
615 if (cpus_empty(cpumask))
616 /* Can't offline last IUCV enabled cpu. */
618 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
619 if (cpus_empty(iucv_irq_cpumask))
620 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
621 iucv_allow_cpu, NULL, 1);
627 static struct notifier_block __refdata iucv_cpu_notifier = {
628 .notifier_call = iucv_cpu_notify,
633 * @pathid: path identification number.
634 * @userdata: 16-bytes of user data.
636 * Sever an iucv path to free up the pathid. Used internally.
638 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
640 union iucv_param *parm;
642 parm = iucv_param_irq[smp_processor_id()];
643 memset(parm, 0, sizeof(union iucv_param));
645 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
646 parm->ctrl.ippathid = pathid;
647 return iucv_call_b2f0(IUCV_SEVER, parm);
651 * __iucv_cleanup_queue
652 * @dummy: unused dummy argument
654 * Nop function called via smp_call_function to force work items from
655 * pending external iucv interrupts to the work queue.
657 static void __iucv_cleanup_queue(void *dummy)
664 * Function called after a path has been severed to find all remaining
665 * work items for the now stale pathid. The caller needs to hold the
668 static void iucv_cleanup_queue(void)
670 struct iucv_irq_list *p, *n;
673 * When a path is severed, the pathid can be reused immediatly
674 * on a iucv connect or a connection pending interrupt. Remove
675 * all entries from the task queue that refer to a stale pathid
676 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
677 * or deliver the connection pending interrupt. To get all the
678 * pending interrupts force them to the work queue by calling
679 * an empty function on all cpus.
681 smp_call_function(__iucv_cleanup_queue, NULL, 1);
682 spin_lock_irq(&iucv_queue_lock);
683 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
684 /* Remove stale work items from the task queue. */
685 if (iucv_path_table[p->data.ippathid] == NULL) {
690 spin_unlock_irq(&iucv_queue_lock);
695 * @handler: address of iucv handler structure
696 * @smp: != 0 indicates that the handler can deal with out of order messages
698 * Registers a driver with IUCV.
700 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
701 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
703 int iucv_register(struct iucv_handler *handler, int smp)
709 mutex_lock(&iucv_register_mutex);
711 iucv_nonsmp_handler++;
712 if (list_empty(&iucv_handler_list)) {
716 } else if (!smp && iucv_nonsmp_handler == 1)
718 INIT_LIST_HEAD(&handler->paths);
720 spin_lock_bh(&iucv_table_lock);
721 list_add_tail(&handler->list, &iucv_handler_list);
722 spin_unlock_bh(&iucv_table_lock);
725 mutex_unlock(&iucv_register_mutex);
728 EXPORT_SYMBOL(iucv_register);
732 * @handler: address of iucv handler structure
733 * @smp: != 0 indicates that the handler can deal with out of order messages
735 * Unregister driver from IUCV.
737 void iucv_unregister(struct iucv_handler *handler, int smp)
739 struct iucv_path *p, *n;
741 mutex_lock(&iucv_register_mutex);
742 spin_lock_bh(&iucv_table_lock);
743 /* Remove handler from the iucv_handler_list. */
744 list_del_init(&handler->list);
745 /* Sever all pathids still refering to the handler. */
746 list_for_each_entry_safe(p, n, &handler->paths, list) {
747 iucv_sever_pathid(p->pathid, NULL);
748 iucv_path_table[p->pathid] = NULL;
752 spin_unlock_bh(&iucv_table_lock);
754 iucv_nonsmp_handler--;
755 if (list_empty(&iucv_handler_list))
757 else if (!smp && iucv_nonsmp_handler == 0)
759 mutex_unlock(&iucv_register_mutex);
761 EXPORT_SYMBOL(iucv_unregister);
763 static int iucv_reboot_event(struct notifier_block *this,
764 unsigned long event, void *ptr)
769 on_each_cpu(iucv_block_cpu, NULL, 1);
771 for (i = 0; i < iucv_max_pathid; i++) {
772 if (iucv_path_table[i])
773 rc = iucv_sever_pathid(i, NULL);
781 static struct notifier_block iucv_reboot_notifier = {
782 .notifier_call = iucv_reboot_event,
787 * @path: address of iucv path structure
788 * @handler: address of iucv handler structure
789 * @userdata: 16 bytes of data reflected to the communication partner
790 * @private: private data passed to interrupt handlers for this path
792 * This function is issued after the user received a connection pending
793 * external interrupt and now wishes to complete the IUCV communication path.
795 * Returns the result of the CP IUCV call.
797 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
798 u8 userdata[16], void *private)
800 union iucv_param *parm;
804 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
808 /* Prepare parameter block. */
809 parm = iucv_param[smp_processor_id()];
810 memset(parm, 0, sizeof(union iucv_param));
811 parm->ctrl.ippathid = path->pathid;
812 parm->ctrl.ipmsglim = path->msglim;
814 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
815 parm->ctrl.ipflags1 = path->flags;
817 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
819 path->private = private;
820 path->msglim = parm->ctrl.ipmsglim;
821 path->flags = parm->ctrl.ipflags1;
827 EXPORT_SYMBOL(iucv_path_accept);
831 * @path: address of iucv path structure
832 * @handler: address of iucv handler structure
833 * @userid: 8-byte user identification
834 * @system: 8-byte target system identification
835 * @userdata: 16 bytes of data reflected to the communication partner
836 * @private: private data passed to interrupt handlers for this path
838 * This function establishes an IUCV path. Although the connect may complete
839 * successfully, you are not able to use the path until you receive an IUCV
840 * Connection Complete external interrupt.
842 * Returns the result of the CP IUCV call.
844 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
845 u8 userid[8], u8 system[8], u8 userdata[16],
848 union iucv_param *parm;
851 spin_lock_bh(&iucv_table_lock);
852 iucv_cleanup_queue();
853 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
857 parm = iucv_param[smp_processor_id()];
858 memset(parm, 0, sizeof(union iucv_param));
859 parm->ctrl.ipmsglim = path->msglim;
860 parm->ctrl.ipflags1 = path->flags;
862 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
863 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
864 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
867 memcpy(parm->ctrl.iptarget, system,
868 sizeof(parm->ctrl.iptarget));
869 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
870 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
873 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
875 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
877 if (parm->ctrl.ippathid < iucv_max_pathid) {
878 path->pathid = parm->ctrl.ippathid;
879 path->msglim = parm->ctrl.ipmsglim;
880 path->flags = parm->ctrl.ipflags1;
881 path->handler = handler;
882 path->private = private;
883 list_add_tail(&path->list, &handler->paths);
884 iucv_path_table[path->pathid] = path;
886 iucv_sever_pathid(parm->ctrl.ippathid,
892 spin_unlock_bh(&iucv_table_lock);
895 EXPORT_SYMBOL(iucv_path_connect);
899 * @path: address of iucv path structure
900 * @userdata: 16 bytes of data reflected to the communication partner
902 * This function temporarily suspends incoming messages on an IUCV path.
903 * You can later reactivate the path by invoking the iucv_resume function.
905 * Returns the result from the CP IUCV call.
907 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
909 union iucv_param *parm;
913 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
917 parm = iucv_param[smp_processor_id()];
918 memset(parm, 0, sizeof(union iucv_param));
920 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
921 parm->ctrl.ippathid = path->pathid;
922 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
927 EXPORT_SYMBOL(iucv_path_quiesce);
931 * @path: address of iucv path structure
932 * @userdata: 16 bytes of data reflected to the communication partner
934 * This function resumes incoming messages on an IUCV path that has
935 * been stopped with iucv_path_quiesce.
937 * Returns the result from the CP IUCV call.
939 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
941 union iucv_param *parm;
945 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
949 parm = iucv_param[smp_processor_id()];
950 memset(parm, 0, sizeof(union iucv_param));
952 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
953 parm->ctrl.ippathid = path->pathid;
954 rc = iucv_call_b2f0(IUCV_RESUME, parm);
962 * @path: address of iucv path structure
963 * @userdata: 16 bytes of data reflected to the communication partner
965 * This function terminates an IUCV path.
967 * Returns the result from the CP IUCV call.
969 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
974 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
978 if (iucv_active_cpu != smp_processor_id())
979 spin_lock_bh(&iucv_table_lock);
980 rc = iucv_sever_pathid(path->pathid, userdata);
981 iucv_path_table[path->pathid] = NULL;
982 list_del_init(&path->list);
983 if (iucv_active_cpu != smp_processor_id())
984 spin_unlock_bh(&iucv_table_lock);
989 EXPORT_SYMBOL(iucv_path_sever);
993 * @path: address of iucv path structure
994 * @msg: address of iucv msg structure
995 * @srccls: source class of message
997 * Cancels a message you have sent.
999 * Returns the result from the CP IUCV call.
1001 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
1004 union iucv_param *parm;
1008 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1012 parm = iucv_param[smp_processor_id()];
1013 memset(parm, 0, sizeof(union iucv_param));
1014 parm->purge.ippathid = path->pathid;
1015 parm->purge.ipmsgid = msg->id;
1016 parm->purge.ipsrccls = srccls;
1017 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
1018 rc = iucv_call_b2f0(IUCV_PURGE, parm);
1020 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
1021 msg->tag = parm->purge.ipmsgtag;
1027 EXPORT_SYMBOL(iucv_message_purge);
1030 * iucv_message_receive_iprmdata
1031 * @path: address of iucv path structure
1032 * @msg: address of iucv msg structure
1033 * @flags: how the message is received (IUCV_IPBUFLST)
1034 * @buffer: address of data buffer or address of struct iucv_array
1035 * @size: length of data buffer
1038 * Internal function used by iucv_message_receive and __iucv_message_receive
1039 * to receive RMDATA data stored in struct iucv_message.
1041 static int iucv_message_receive_iprmdata(struct iucv_path *path,
1042 struct iucv_message *msg,
1043 u8 flags, void *buffer,
1044 size_t size, size_t *residual)
1046 struct iucv_array *array;
1051 * Message is 8 bytes long and has been stored to the
1052 * message descriptor itself.
1055 *residual = abs(size - 8);
1057 if (flags & IUCV_IPBUFLST) {
1058 /* Copy to struct iucv_array. */
1059 size = (size < 8) ? size : 8;
1060 for (array = buffer; size > 0; array++) {
1061 copy = min_t(size_t, size, array->length);
1062 memcpy((u8 *)(addr_t) array->address,
1068 /* Copy to direct buffer. */
1069 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1075 * __iucv_message_receive
1076 * @path: address of iucv path structure
1077 * @msg: address of iucv msg structure
1078 * @flags: how the message is received (IUCV_IPBUFLST)
1079 * @buffer: address of data buffer or address of struct iucv_array
1080 * @size: length of data buffer
1083 * This function receives messages that are being sent to you over
1084 * established paths. This function will deal with RMDATA messages
1085 * embedded in struct iucv_message as well.
1087 * Locking: no locking
1089 * Returns the result from the CP IUCV call.
1091 int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1092 u8 flags, void *buffer, size_t size, size_t *residual)
1094 union iucv_param *parm;
1097 if (msg->flags & IUCV_IPRMDATA)
1098 return iucv_message_receive_iprmdata(path, msg, flags,
1099 buffer, size, residual);
1100 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1104 parm = iucv_param[smp_processor_id()];
1105 memset(parm, 0, sizeof(union iucv_param));
1106 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1107 parm->db.ipbfln1f = (u32) size;
1108 parm->db.ipmsgid = msg->id;
1109 parm->db.ippathid = path->pathid;
1110 parm->db.iptrgcls = msg->class;
1111 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1112 IUCV_IPFGMID | IUCV_IPTRGCLS);
1113 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1114 if (!rc || rc == 5) {
1115 msg->flags = parm->db.ipflags1;
1117 *residual = parm->db.ipbfln1f;
1122 EXPORT_SYMBOL(__iucv_message_receive);
1125 * iucv_message_receive
1126 * @path: address of iucv path structure
1127 * @msg: address of iucv msg structure
1128 * @flags: how the message is received (IUCV_IPBUFLST)
1129 * @buffer: address of data buffer or address of struct iucv_array
1130 * @size: length of data buffer
1133 * This function receives messages that are being sent to you over
1134 * established paths. This function will deal with RMDATA messages
1135 * embedded in struct iucv_message as well.
1137 * Locking: local_bh_enable/local_bh_disable
1139 * Returns the result from the CP IUCV call.
1141 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1142 u8 flags, void *buffer, size_t size, size_t *residual)
1146 if (msg->flags & IUCV_IPRMDATA)
1147 return iucv_message_receive_iprmdata(path, msg, flags,
1148 buffer, size, residual);
1150 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
1154 EXPORT_SYMBOL(iucv_message_receive);
1157 * iucv_message_reject
1158 * @path: address of iucv path structure
1159 * @msg: address of iucv msg structure
1161 * The reject function refuses a specified message. Between the time you
1162 * are notified of a message and the time that you complete the message,
1163 * the message may be rejected.
1165 * Returns the result from the CP IUCV call.
1167 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1169 union iucv_param *parm;
1173 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1177 parm = iucv_param[smp_processor_id()];
1178 memset(parm, 0, sizeof(union iucv_param));
1179 parm->db.ippathid = path->pathid;
1180 parm->db.ipmsgid = msg->id;
1181 parm->db.iptrgcls = msg->class;
1182 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1183 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1188 EXPORT_SYMBOL(iucv_message_reject);
1191 * iucv_message_reply
1192 * @path: address of iucv path structure
1193 * @msg: address of iucv msg structure
1194 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1195 * @reply: address of reply data buffer or address of struct iucv_array
1196 * @size: length of reply data buffer
1198 * This function responds to the two-way messages that you receive. You
1199 * must identify completely the message to which you wish to reply. ie,
1200 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1201 * the parameter list.
1203 * Returns the result from the CP IUCV call.
1205 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1206 u8 flags, void *reply, size_t size)
1208 union iucv_param *parm;
1212 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1216 parm = iucv_param[smp_processor_id()];
1217 memset(parm, 0, sizeof(union iucv_param));
1218 if (flags & IUCV_IPRMDATA) {
1219 parm->dpl.ippathid = path->pathid;
1220 parm->dpl.ipflags1 = flags;
1221 parm->dpl.ipmsgid = msg->id;
1222 parm->dpl.iptrgcls = msg->class;
1223 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1225 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1226 parm->db.ipbfln1f = (u32) size;
1227 parm->db.ippathid = path->pathid;
1228 parm->db.ipflags1 = flags;
1229 parm->db.ipmsgid = msg->id;
1230 parm->db.iptrgcls = msg->class;
1232 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1237 EXPORT_SYMBOL(iucv_message_reply);
1240 * __iucv_message_send
1241 * @path: address of iucv path structure
1242 * @msg: address of iucv msg structure
1243 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1244 * @srccls: source class of message
1245 * @buffer: address of send buffer or address of struct iucv_array
1246 * @size: length of send buffer
1248 * This function transmits data to another application. Data to be
1249 * transmitted is in a buffer and this is a one-way message and the
1250 * receiver will not reply to the message.
1252 * Locking: no locking
1254 * Returns the result from the CP IUCV call.
1256 int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1257 u8 flags, u32 srccls, void *buffer, size_t size)
1259 union iucv_param *parm;
1262 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1266 parm = iucv_param[smp_processor_id()];
1267 memset(parm, 0, sizeof(union iucv_param));
1268 if (flags & IUCV_IPRMDATA) {
1269 /* Message of 8 bytes can be placed into the parameter list. */
1270 parm->dpl.ippathid = path->pathid;
1271 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1272 parm->dpl.iptrgcls = msg->class;
1273 parm->dpl.ipsrccls = srccls;
1274 parm->dpl.ipmsgtag = msg->tag;
1275 memcpy(parm->dpl.iprmmsg, buffer, 8);
1277 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1278 parm->db.ipbfln1f = (u32) size;
1279 parm->db.ippathid = path->pathid;
1280 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1281 parm->db.iptrgcls = msg->class;
1282 parm->db.ipsrccls = srccls;
1283 parm->db.ipmsgtag = msg->tag;
1285 rc = iucv_call_b2f0(IUCV_SEND, parm);
1287 msg->id = parm->db.ipmsgid;
1291 EXPORT_SYMBOL(__iucv_message_send);
1295 * @path: address of iucv path structure
1296 * @msg: address of iucv msg structure
1297 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1298 * @srccls: source class of message
1299 * @buffer: address of send buffer or address of struct iucv_array
1300 * @size: length of send buffer
1302 * This function transmits data to another application. Data to be
1303 * transmitted is in a buffer and this is a one-way message and the
1304 * receiver will not reply to the message.
1306 * Locking: local_bh_enable/local_bh_disable
1308 * Returns the result from the CP IUCV call.
1310 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1311 u8 flags, u32 srccls, void *buffer, size_t size)
1316 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
1320 EXPORT_SYMBOL(iucv_message_send);
1323 * iucv_message_send2way
1324 * @path: address of iucv path structure
1325 * @msg: address of iucv msg structure
1326 * @flags: how the message is sent and the reply is received
1327 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1328 * @srccls: source class of message
1329 * @buffer: address of send buffer or address of struct iucv_array
1330 * @size: length of send buffer
1331 * @ansbuf: address of answer buffer or address of struct iucv_array
1332 * @asize: size of reply buffer
1334 * This function transmits data to another application. Data to be
1335 * transmitted is in a buffer. The receiver of the send is expected to
1336 * reply to the message and a buffer is provided into which IUCV moves
1337 * the reply to this message.
1339 * Returns the result from the CP IUCV call.
1341 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1342 u8 flags, u32 srccls, void *buffer, size_t size,
1343 void *answer, size_t asize, size_t *residual)
1345 union iucv_param *parm;
1349 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1353 parm = iucv_param[smp_processor_id()];
1354 memset(parm, 0, sizeof(union iucv_param));
1355 if (flags & IUCV_IPRMDATA) {
1356 parm->dpl.ippathid = path->pathid;
1357 parm->dpl.ipflags1 = path->flags; /* priority message */
1358 parm->dpl.iptrgcls = msg->class;
1359 parm->dpl.ipsrccls = srccls;
1360 parm->dpl.ipmsgtag = msg->tag;
1361 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1362 parm->dpl.ipbfln2f = (u32) asize;
1363 memcpy(parm->dpl.iprmmsg, buffer, 8);
1365 parm->db.ippathid = path->pathid;
1366 parm->db.ipflags1 = path->flags; /* priority message */
1367 parm->db.iptrgcls = msg->class;
1368 parm->db.ipsrccls = srccls;
1369 parm->db.ipmsgtag = msg->tag;
1370 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1371 parm->db.ipbfln1f = (u32) size;
1372 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1373 parm->db.ipbfln2f = (u32) asize;
1375 rc = iucv_call_b2f0(IUCV_SEND, parm);
1377 msg->id = parm->db.ipmsgid;
1382 EXPORT_SYMBOL(iucv_message_send2way);
1386 * @data: Pointer to external interrupt buffer
1388 * Process connection pending work item. Called from tasklet while holding
1391 struct iucv_path_pending {
1402 } __attribute__ ((packed));
1404 static void iucv_path_pending(struct iucv_irq_data *data)
1406 struct iucv_path_pending *ipp = (void *) data;
1407 struct iucv_handler *handler;
1408 struct iucv_path *path;
1411 BUG_ON(iucv_path_table[ipp->ippathid]);
1412 /* New pathid, handler found. Create a new path struct. */
1413 error = iucv_error_no_memory;
1414 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1417 path->pathid = ipp->ippathid;
1418 iucv_path_table[path->pathid] = path;
1419 EBCASC(ipp->ipvmid, 8);
1421 /* Call registered handler until one is found that wants the path. */
1422 list_for_each_entry(handler, &iucv_handler_list, list) {
1423 if (!handler->path_pending)
1426 * Add path to handler to allow a call to iucv_path_sever
1427 * inside the path_pending function. If the handler returns
1428 * an error remove the path from the handler again.
1430 list_add(&path->list, &handler->paths);
1431 path->handler = handler;
1432 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1434 list_del(&path->list);
1435 path->handler = NULL;
1437 /* No handler wanted the path. */
1438 iucv_path_table[path->pathid] = NULL;
1439 iucv_path_free(path);
1440 error = iucv_error_no_listener;
1442 iucv_sever_pathid(ipp->ippathid, error);
1446 * iucv_path_complete
1447 * @data: Pointer to external interrupt buffer
1449 * Process connection complete work item. Called from tasklet while holding
1452 struct iucv_path_complete {
1463 } __attribute__ ((packed));
1465 static void iucv_path_complete(struct iucv_irq_data *data)
1467 struct iucv_path_complete *ipc = (void *) data;
1468 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1471 path->flags = ipc->ipflags1;
1472 if (path && path->handler && path->handler->path_complete)
1473 path->handler->path_complete(path, ipc->ipuser);
1478 * @data: Pointer to external interrupt buffer
1480 * Process connection severed work item. Called from tasklet while holding
1483 struct iucv_path_severed {
1493 } __attribute__ ((packed));
1495 static void iucv_path_severed(struct iucv_irq_data *data)
1497 struct iucv_path_severed *ips = (void *) data;
1498 struct iucv_path *path = iucv_path_table[ips->ippathid];
1500 if (!path || !path->handler) /* Already severed */
1502 if (path->handler->path_severed)
1503 path->handler->path_severed(path, ips->ipuser);
1505 iucv_sever_pathid(path->pathid, NULL);
1506 iucv_path_table[path->pathid] = NULL;
1507 list_del(&path->list);
1508 iucv_path_free(path);
1513 * iucv_path_quiesced
1514 * @data: Pointer to external interrupt buffer
1516 * Process connection quiesced work item. Called from tasklet while holding
1519 struct iucv_path_quiesced {
1529 } __attribute__ ((packed));
1531 static void iucv_path_quiesced(struct iucv_irq_data *data)
1533 struct iucv_path_quiesced *ipq = (void *) data;
1534 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1536 if (path && path->handler && path->handler->path_quiesced)
1537 path->handler->path_quiesced(path, ipq->ipuser);
1542 * @data: Pointer to external interrupt buffer
1544 * Process connection resumed work item. Called from tasklet while holding
1547 struct iucv_path_resumed {
1557 } __attribute__ ((packed));
1559 static void iucv_path_resumed(struct iucv_irq_data *data)
1561 struct iucv_path_resumed *ipr = (void *) data;
1562 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1564 if (path && path->handler && path->handler->path_resumed)
1565 path->handler->path_resumed(path, ipr->ipuser);
1569 * iucv_message_complete
1570 * @data: Pointer to external interrupt buffer
1572 * Process message complete work item. Called from tasklet while holding
1575 struct iucv_message_complete {
1588 } __attribute__ ((packed));
1590 static void iucv_message_complete(struct iucv_irq_data *data)
1592 struct iucv_message_complete *imc = (void *) data;
1593 struct iucv_path *path = iucv_path_table[imc->ippathid];
1594 struct iucv_message msg;
1596 if (path && path->handler && path->handler->message_complete) {
1597 msg.flags = imc->ipflags1;
1598 msg.id = imc->ipmsgid;
1599 msg.audit = imc->ipaudit;
1600 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1601 msg.class = imc->ipsrccls;
1602 msg.tag = imc->ipmsgtag;
1603 msg.length = imc->ipbfln2f;
1604 path->handler->message_complete(path, &msg);
1609 * iucv_message_pending
1610 * @data: Pointer to external interrupt buffer
1612 * Process message pending work item. Called from tasklet while holding
1615 struct iucv_message_pending {
1633 } __attribute__ ((packed));
1635 static void iucv_message_pending(struct iucv_irq_data *data)
1637 struct iucv_message_pending *imp = (void *) data;
1638 struct iucv_path *path = iucv_path_table[imp->ippathid];
1639 struct iucv_message msg;
1641 if (path && path->handler && path->handler->message_pending) {
1642 msg.flags = imp->ipflags1;
1643 msg.id = imp->ipmsgid;
1644 msg.class = imp->iptrgcls;
1645 if (imp->ipflags1 & IUCV_IPRMDATA) {
1646 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1649 msg.length = imp->ln1msg2.ipbfln1f;
1650 msg.reply_size = imp->ipbfln2f;
1651 path->handler->message_pending(path, &msg);
1658 * This tasklet loops over the queue of irq buffers created by
1659 * iucv_external_interrupt, calls the appropriate action handler
1660 * and then frees the buffer.
1662 static void iucv_tasklet_fn(unsigned long ignored)
1664 typedef void iucv_irq_fn(struct iucv_irq_data *);
1665 static iucv_irq_fn *irq_fn[] = {
1666 [0x02] = iucv_path_complete,
1667 [0x03] = iucv_path_severed,
1668 [0x04] = iucv_path_quiesced,
1669 [0x05] = iucv_path_resumed,
1670 [0x06] = iucv_message_complete,
1671 [0x07] = iucv_message_complete,
1672 [0x08] = iucv_message_pending,
1673 [0x09] = iucv_message_pending,
1675 LIST_HEAD(task_queue);
1676 struct iucv_irq_list *p, *n;
1678 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1679 if (!spin_trylock(&iucv_table_lock)) {
1680 tasklet_schedule(&iucv_tasklet);
1683 iucv_active_cpu = smp_processor_id();
1685 spin_lock_irq(&iucv_queue_lock);
1686 list_splice_init(&iucv_task_queue, &task_queue);
1687 spin_unlock_irq(&iucv_queue_lock);
1689 list_for_each_entry_safe(p, n, &task_queue, list) {
1690 list_del_init(&p->list);
1691 irq_fn[p->data.iptype](&p->data);
1695 iucv_active_cpu = -1;
1696 spin_unlock(&iucv_table_lock);
1702 * This work function loops over the queue of path pending irq blocks
1703 * created by iucv_external_interrupt, calls the appropriate action
1704 * handler and then frees the buffer.
1706 static void iucv_work_fn(struct work_struct *work)
1708 typedef void iucv_irq_fn(struct iucv_irq_data *);
1709 LIST_HEAD(work_queue);
1710 struct iucv_irq_list *p, *n;
1712 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1713 spin_lock_bh(&iucv_table_lock);
1714 iucv_active_cpu = smp_processor_id();
1716 spin_lock_irq(&iucv_queue_lock);
1717 list_splice_init(&iucv_work_queue, &work_queue);
1718 spin_unlock_irq(&iucv_queue_lock);
1720 iucv_cleanup_queue();
1721 list_for_each_entry_safe(p, n, &work_queue, list) {
1722 list_del_init(&p->list);
1723 iucv_path_pending(&p->data);
1727 iucv_active_cpu = -1;
1728 spin_unlock_bh(&iucv_table_lock);
1732 * iucv_external_interrupt
1735 * Handles external interrupts coming in from CP.
1736 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1738 static void iucv_external_interrupt(u16 code)
1740 struct iucv_irq_data *p;
1741 struct iucv_irq_list *work;
1743 p = iucv_irq_data[smp_processor_id()];
1744 if (p->ippathid >= iucv_max_pathid) {
1745 WARN_ON(p->ippathid >= iucv_max_pathid);
1746 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1749 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1750 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1752 pr_warning("iucv_external_interrupt: out of memory\n");
1755 memcpy(&work->data, p, sizeof(work->data));
1756 spin_lock(&iucv_queue_lock);
1757 if (p->iptype == 0x01) {
1758 /* Path pending interrupt. */
1759 list_add_tail(&work->list, &iucv_work_queue);
1760 schedule_work(&iucv_work);
1762 /* The other interrupts. */
1763 list_add_tail(&work->list, &iucv_task_queue);
1764 tasklet_schedule(&iucv_tasklet);
1766 spin_unlock(&iucv_queue_lock);
1772 * Allocates and initializes various data structures.
1774 static int __init iucv_init(void)
1779 if (!MACHINE_IS_VM) {
1780 rc = -EPROTONOSUPPORT;
1783 rc = iucv_query_maxconn();
1786 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1789 iucv_root = root_device_register("iucv");
1790 if (IS_ERR(iucv_root)) {
1791 rc = PTR_ERR(iucv_root);
1795 for_each_online_cpu(cpu) {
1796 /* Note: GFP_DMA used to get memory below 2G */
1797 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1798 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1799 if (!iucv_irq_data[cpu]) {
1804 /* Allocate parameter blocks. */
1805 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1806 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1807 if (!iucv_param[cpu]) {
1811 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
1812 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1813 if (!iucv_param_irq[cpu]) {
1819 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1822 rc = register_reboot_notifier(&iucv_reboot_notifier);
1825 ASCEBC(iucv_error_no_listener, 16);
1826 ASCEBC(iucv_error_no_memory, 16);
1827 ASCEBC(iucv_error_pathid, 16);
1829 rc = bus_register(&iucv_bus);
1835 unregister_reboot_notifier(&iucv_reboot_notifier);
1837 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1839 for_each_possible_cpu(cpu) {
1840 kfree(iucv_param_irq[cpu]);
1841 iucv_param_irq[cpu] = NULL;
1842 kfree(iucv_param[cpu]);
1843 iucv_param[cpu] = NULL;
1844 kfree(iucv_irq_data[cpu]);
1845 iucv_irq_data[cpu] = NULL;
1847 root_device_unregister(iucv_root);
1849 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1857 * Frees everything allocated from iucv_init.
1859 static void __exit iucv_exit(void)
1861 struct iucv_irq_list *p, *n;
1864 spin_lock_irq(&iucv_queue_lock);
1865 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1867 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1869 spin_unlock_irq(&iucv_queue_lock);
1870 unregister_reboot_notifier(&iucv_reboot_notifier);
1871 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1872 for_each_possible_cpu(cpu) {
1873 kfree(iucv_param_irq[cpu]);
1874 iucv_param_irq[cpu] = NULL;
1875 kfree(iucv_param[cpu]);
1876 iucv_param[cpu] = NULL;
1877 kfree(iucv_irq_data[cpu]);
1878 iucv_irq_data[cpu] = NULL;
1880 root_device_unregister(iucv_root);
1881 bus_unregister(&iucv_bus);
1882 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1885 subsys_initcall(iucv_init);
1886 module_exit(iucv_exit);
1888 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1889 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1890 MODULE_LICENSE("GPL");