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>
15 * Ursula Braun (ursula.braun@de.ibm.com)
19 * CP Programming Service, IBM document # SC24-5760
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2, or (at your option)
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #define KMSG_COMPONENT "iucv"
37 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
41 #include <linux/spinlock.h>
42 #include <linux/kernel.h>
43 #include <linux/slab.h>
44 #include <linux/init.h>
45 #include <linux/interrupt.h>
46 #include <linux/list.h>
47 #include <linux/errno.h>
48 #include <linux/err.h>
49 #include <linux/device.h>
50 #include <linux/cpu.h>
51 #include <linux/reboot.h>
52 #include <net/iucv/iucv.h>
53 #include <asm/atomic.h>
54 #include <asm/ebcdic.h>
56 #include <asm/s390_ext.h>
61 * All flags are defined in the field IPFLAGS1 of each function
62 * and can be found in CP Programming Services.
63 * IPSRCCLS - Indicates you have specified a source class.
64 * IPTRGCLS - Indicates you have specified a target class.
65 * IPFGPID - Indicates you have specified a pathid.
66 * IPFGMID - Indicates you have specified a message ID.
67 * IPNORPY - Indicates a one-way message. No reply expected.
68 * IPALL - Indicates that all paths are affected.
70 #define IUCV_IPSRCCLS 0x01
71 #define IUCV_IPTRGCLS 0x01
72 #define IUCV_IPFGPID 0x02
73 #define IUCV_IPFGMID 0x04
74 #define IUCV_IPNORPY 0x10
75 #define IUCV_IPALL 0x80
77 static int iucv_bus_match(struct device *dev, struct device_driver *drv)
82 static int iucv_pm_prepare(struct device *);
83 static void iucv_pm_complete(struct device *);
84 static int iucv_pm_freeze(struct device *);
85 static int iucv_pm_thaw(struct device *);
86 static int iucv_pm_restore(struct device *);
88 static struct dev_pm_ops iucv_pm_ops = {
89 .prepare = iucv_pm_prepare,
90 .complete = iucv_pm_complete,
91 .freeze = iucv_pm_freeze,
93 .restore = iucv_pm_restore,
96 struct bus_type iucv_bus = {
98 .match = iucv_bus_match,
101 EXPORT_SYMBOL(iucv_bus);
103 struct device *iucv_root;
104 EXPORT_SYMBOL(iucv_root);
106 static int iucv_available;
108 /* General IUCV interrupt structure */
109 struct iucv_irq_data {
116 struct iucv_irq_list {
117 struct list_head list;
118 struct iucv_irq_data data;
121 static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
122 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
123 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
126 * Queue of interrupt buffers lock for delivery via the tasklet
127 * (fast but can't call smp_call_function).
129 static LIST_HEAD(iucv_task_queue);
132 * The tasklet for fast delivery of iucv interrupts.
134 static void iucv_tasklet_fn(unsigned long);
135 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
138 * Queue of interrupt buffers for delivery via a work queue
139 * (slower but can call smp_call_function).
141 static LIST_HEAD(iucv_work_queue);
144 * The work element to deliver path pending interrupts.
146 static void iucv_work_fn(struct work_struct *work);
147 static DECLARE_WORK(iucv_work, iucv_work_fn);
150 * Spinlock protecting task and work queue.
152 static DEFINE_SPINLOCK(iucv_queue_lock);
154 enum iucv_command_codes {
156 IUCV_RETRIEVE_BUFFER = 2,
164 IUCV_DECLARE_BUFFER = 12,
169 IUCV_SETCONTROLMASK = 17,
173 * Error messages that are used with the iucv_sever function. They get
174 * converted to EBCDIC.
176 static char iucv_error_no_listener[16] = "NO LISTENER";
177 static char iucv_error_no_memory[16] = "NO MEMORY";
178 static char iucv_error_pathid[16] = "INVALID PATHID";
181 * iucv_handler_list: List of registered handlers.
183 static LIST_HEAD(iucv_handler_list);
186 * iucv_path_table: an array of iucv_path structures.
188 static struct iucv_path **iucv_path_table;
189 static unsigned long iucv_max_pathid;
192 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
194 static DEFINE_SPINLOCK(iucv_table_lock);
197 * iucv_active_cpu: contains the number of the cpu executing the tasklet
198 * or the work handler. Needed for iucv_path_sever called from tasklet.
200 static int iucv_active_cpu = -1;
203 * Mutex and wait queue for iucv_register/iucv_unregister.
205 static DEFINE_MUTEX(iucv_register_mutex);
208 * Counter for number of non-smp capable handlers.
210 static int iucv_nonsmp_handler;
213 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
214 * iucv_path_quiesce and iucv_path_sever.
216 struct iucv_cmd_control {
225 } __attribute__ ((packed,aligned(8)));
228 * Data in parameter list iucv structure. Used by iucv_message_send,
229 * iucv_message_send2way and iucv_message_reply.
231 struct iucv_cmd_dpl {
243 } __attribute__ ((packed,aligned(8)));
246 * Data in buffer iucv structure. Used by iucv_message_receive,
247 * iucv_message_reject, iucv_message_send, iucv_message_send2way
248 * and iucv_declare_cpu.
263 } __attribute__ ((packed,aligned(8)));
266 * Purge message iucv structure. Used by iucv_message_purge.
268 struct iucv_cmd_purge {
279 } __attribute__ ((packed,aligned(8)));
282 * Set mask iucv structure. Used by iucv_enable_cpu.
284 struct iucv_cmd_set_mask {
289 } __attribute__ ((packed,aligned(8)));
292 struct iucv_cmd_control ctrl;
293 struct iucv_cmd_dpl dpl;
294 struct iucv_cmd_db db;
295 struct iucv_cmd_purge purge;
296 struct iucv_cmd_set_mask set_mask;
300 * Anchor for per-cpu IUCV command parameter block.
302 static union iucv_param *iucv_param[NR_CPUS];
303 static union iucv_param *iucv_param_irq[NR_CPUS];
307 * @code: identifier of IUCV call to CP.
308 * @parm: pointer to a struct iucv_parm block
310 * Calls CP to execute IUCV commands.
312 * Returns the result of the CP IUCV call.
314 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
316 register unsigned long reg0 asm ("0");
317 register unsigned long reg1 asm ("1");
321 reg1 = virt_to_phys(parm);
323 " .long 0xb2f01000\n"
326 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
327 : "m" (*parm) : "cc");
328 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
334 * Determines the maximum number of connections that may be established.
336 * Returns the maximum number of connections or -EPERM is IUCV is not
339 static int iucv_query_maxconn(void)
341 register unsigned long reg0 asm ("0");
342 register unsigned long reg1 asm ("1");
346 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
350 reg1 = (unsigned long) param;
352 " .long 0xb2f01000\n"
355 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
357 iucv_max_pathid = reg0;
359 return ccode ? -EPERM : 0;
366 * Allow iucv interrupts on this cpu.
368 static void iucv_allow_cpu(void *data)
370 int cpu = smp_processor_id();
371 union iucv_param *parm;
374 * Enable all iucv interrupts.
375 * ipmask contains bits for the different interrupts
376 * 0x80 - Flag to allow nonpriority message pending interrupts
377 * 0x40 - Flag to allow priority message pending interrupts
378 * 0x20 - Flag to allow nonpriority message completion interrupts
379 * 0x10 - Flag to allow priority message completion interrupts
380 * 0x08 - Flag to allow IUCV control interrupts
382 parm = iucv_param_irq[cpu];
383 memset(parm, 0, sizeof(union iucv_param));
384 parm->set_mask.ipmask = 0xf8;
385 iucv_call_b2f0(IUCV_SETMASK, parm);
388 * Enable all iucv control interrupts.
389 * ipmask contains bits for the different interrupts
390 * 0x80 - Flag to allow pending connections interrupts
391 * 0x40 - Flag to allow connection complete interrupts
392 * 0x20 - Flag to allow connection severed interrupts
393 * 0x10 - Flag to allow connection quiesced interrupts
394 * 0x08 - Flag to allow connection resumed interrupts
396 memset(parm, 0, sizeof(union iucv_param));
397 parm->set_mask.ipmask = 0xf8;
398 iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
399 /* Set indication that iucv interrupts are allowed for this cpu. */
400 cpu_set(cpu, iucv_irq_cpumask);
407 * Block iucv interrupts on this cpu.
409 static void iucv_block_cpu(void *data)
411 int cpu = smp_processor_id();
412 union iucv_param *parm;
414 /* Disable all iucv interrupts. */
415 parm = iucv_param_irq[cpu];
416 memset(parm, 0, sizeof(union iucv_param));
417 iucv_call_b2f0(IUCV_SETMASK, parm);
419 /* Clear indication that iucv interrupts are allowed for this cpu. */
420 cpu_clear(cpu, iucv_irq_cpumask);
424 * iucv_block_cpu_almost
427 * Allow connection-severed interrupts only on this cpu.
429 static void iucv_block_cpu_almost(void *data)
431 int cpu = smp_processor_id();
432 union iucv_param *parm;
434 /* Allow iucv control interrupts only */
435 parm = iucv_param_irq[cpu];
436 memset(parm, 0, sizeof(union iucv_param));
437 parm->set_mask.ipmask = 0x08;
438 iucv_call_b2f0(IUCV_SETMASK, parm);
439 /* Allow iucv-severed interrupt only */
440 memset(parm, 0, sizeof(union iucv_param));
441 parm->set_mask.ipmask = 0x20;
442 iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
444 /* Clear indication that iucv interrupts are allowed for this cpu. */
445 cpu_clear(cpu, iucv_irq_cpumask);
452 * Declare a interrupt buffer on this cpu.
454 static void iucv_declare_cpu(void *data)
456 int cpu = smp_processor_id();
457 union iucv_param *parm;
460 if (cpu_isset(cpu, iucv_buffer_cpumask))
463 /* Declare interrupt buffer. */
464 parm = iucv_param_irq[cpu];
465 memset(parm, 0, sizeof(union iucv_param));
466 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
467 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
469 char *err = "Unknown";
472 err = "Directory error";
475 err = "Invalid length";
478 err = "Buffer already exists";
481 err = "Buffer overlap";
484 err = "Paging or storage error";
487 pr_warning("Defining an interrupt buffer on CPU %i"
488 " failed with 0x%02x (%s)\n", cpu, rc, err);
492 /* Set indication that an iucv buffer exists for this cpu. */
493 cpu_set(cpu, iucv_buffer_cpumask);
495 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
496 /* Enable iucv interrupts on this cpu. */
497 iucv_allow_cpu(NULL);
499 /* Disable iucv interrupts on this cpu. */
500 iucv_block_cpu(NULL);
507 * Retrieve interrupt buffer on this cpu.
509 static void iucv_retrieve_cpu(void *data)
511 int cpu = smp_processor_id();
512 union iucv_param *parm;
514 if (!cpu_isset(cpu, iucv_buffer_cpumask))
517 /* Block iucv interrupts. */
518 iucv_block_cpu(NULL);
520 /* Retrieve interrupt buffer. */
521 parm = iucv_param_irq[cpu];
522 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
524 /* Clear indication that an iucv buffer exists for this cpu. */
525 cpu_clear(cpu, iucv_buffer_cpumask);
531 * Allow iucv interrupts on all cpus.
533 static void iucv_setmask_mp(void)
538 for_each_online_cpu(cpu)
539 /* Enable all cpus with a declared buffer. */
540 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
541 !cpu_isset(cpu, iucv_irq_cpumask))
542 smp_call_function_single(cpu, iucv_allow_cpu,
550 * Allow iucv interrupts on a single cpu.
552 static void iucv_setmask_up(void)
557 /* Disable all cpu but the first in cpu_irq_cpumask. */
558 cpumask = iucv_irq_cpumask;
559 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
560 for_each_cpu_mask_nr(cpu, cpumask)
561 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
567 * This function makes iucv ready for use. It allocates the pathid
568 * table, declares an iucv interrupt buffer and enables the iucv
569 * interrupts. Called when the first user has registered an iucv
572 static int iucv_enable(void)
579 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
580 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
581 if (!iucv_path_table)
583 /* Declare per cpu buffers. */
585 for_each_online_cpu(cpu)
586 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
587 if (cpus_empty(iucv_buffer_cpumask))
588 /* No cpu could declare an iucv buffer. */
593 kfree(iucv_path_table);
594 iucv_path_table = NULL;
602 * This function shuts down iucv. It disables iucv interrupts, retrieves
603 * the iucv interrupt buffer and frees the pathid table. Called after the
604 * last user unregister its iucv handler.
606 static void iucv_disable(void)
609 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
610 kfree(iucv_path_table);
611 iucv_path_table = NULL;
615 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
616 unsigned long action, void *hcpu)
619 long cpu = (long) hcpu;
623 case CPU_UP_PREPARE_FROZEN:
624 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
625 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
626 if (!iucv_irq_data[cpu])
628 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
629 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
630 if (!iucv_param[cpu]) {
631 kfree(iucv_irq_data[cpu]);
632 iucv_irq_data[cpu] = NULL;
635 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
636 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
637 if (!iucv_param_irq[cpu]) {
638 kfree(iucv_param[cpu]);
639 iucv_param[cpu] = NULL;
640 kfree(iucv_irq_data[cpu]);
641 iucv_irq_data[cpu] = NULL;
645 case CPU_UP_CANCELED:
646 case CPU_UP_CANCELED_FROZEN:
648 case CPU_DEAD_FROZEN:
649 kfree(iucv_param_irq[cpu]);
650 iucv_param_irq[cpu] = NULL;
651 kfree(iucv_param[cpu]);
652 iucv_param[cpu] = NULL;
653 kfree(iucv_irq_data[cpu]);
654 iucv_irq_data[cpu] = NULL;
657 case CPU_ONLINE_FROZEN:
658 case CPU_DOWN_FAILED:
659 case CPU_DOWN_FAILED_FROZEN:
660 if (!iucv_path_table)
662 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
664 case CPU_DOWN_PREPARE:
665 case CPU_DOWN_PREPARE_FROZEN:
666 if (!iucv_path_table)
668 cpumask = iucv_buffer_cpumask;
669 cpu_clear(cpu, cpumask);
670 if (cpus_empty(cpumask))
671 /* Can't offline last IUCV enabled cpu. */
673 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
674 if (cpus_empty(iucv_irq_cpumask))
675 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
676 iucv_allow_cpu, NULL, 1);
682 static struct notifier_block __refdata iucv_cpu_notifier = {
683 .notifier_call = iucv_cpu_notify,
688 * @pathid: path identification number.
689 * @userdata: 16-bytes of user data.
691 * Sever an iucv path to free up the pathid. Used internally.
693 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
695 union iucv_param *parm;
697 parm = iucv_param_irq[smp_processor_id()];
698 memset(parm, 0, sizeof(union iucv_param));
700 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
701 parm->ctrl.ippathid = pathid;
702 return iucv_call_b2f0(IUCV_SEVER, parm);
706 * __iucv_cleanup_queue
707 * @dummy: unused dummy argument
709 * Nop function called via smp_call_function to force work items from
710 * pending external iucv interrupts to the work queue.
712 static void __iucv_cleanup_queue(void *dummy)
719 * Function called after a path has been severed to find all remaining
720 * work items for the now stale pathid. The caller needs to hold the
723 static void iucv_cleanup_queue(void)
725 struct iucv_irq_list *p, *n;
728 * When a path is severed, the pathid can be reused immediatly
729 * on a iucv connect or a connection pending interrupt. Remove
730 * all entries from the task queue that refer to a stale pathid
731 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
732 * or deliver the connection pending interrupt. To get all the
733 * pending interrupts force them to the work queue by calling
734 * an empty function on all cpus.
736 smp_call_function(__iucv_cleanup_queue, NULL, 1);
737 spin_lock_irq(&iucv_queue_lock);
738 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
739 /* Remove stale work items from the task queue. */
740 if (iucv_path_table[p->data.ippathid] == NULL) {
745 spin_unlock_irq(&iucv_queue_lock);
750 * @handler: address of iucv handler structure
751 * @smp: != 0 indicates that the handler can deal with out of order messages
753 * Registers a driver with IUCV.
755 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
756 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
758 int iucv_register(struct iucv_handler *handler, int smp)
764 mutex_lock(&iucv_register_mutex);
766 iucv_nonsmp_handler++;
767 if (list_empty(&iucv_handler_list)) {
771 } else if (!smp && iucv_nonsmp_handler == 1)
773 INIT_LIST_HEAD(&handler->paths);
775 spin_lock_bh(&iucv_table_lock);
776 list_add_tail(&handler->list, &iucv_handler_list);
777 spin_unlock_bh(&iucv_table_lock);
780 mutex_unlock(&iucv_register_mutex);
783 EXPORT_SYMBOL(iucv_register);
787 * @handler: address of iucv handler structure
788 * @smp: != 0 indicates that the handler can deal with out of order messages
790 * Unregister driver from IUCV.
792 void iucv_unregister(struct iucv_handler *handler, int smp)
794 struct iucv_path *p, *n;
796 mutex_lock(&iucv_register_mutex);
797 spin_lock_bh(&iucv_table_lock);
798 /* Remove handler from the iucv_handler_list. */
799 list_del_init(&handler->list);
800 /* Sever all pathids still refering to the handler. */
801 list_for_each_entry_safe(p, n, &handler->paths, list) {
802 iucv_sever_pathid(p->pathid, NULL);
803 iucv_path_table[p->pathid] = NULL;
807 spin_unlock_bh(&iucv_table_lock);
809 iucv_nonsmp_handler--;
810 if (list_empty(&iucv_handler_list))
812 else if (!smp && iucv_nonsmp_handler == 0)
814 mutex_unlock(&iucv_register_mutex);
816 EXPORT_SYMBOL(iucv_unregister);
818 static int iucv_reboot_event(struct notifier_block *this,
819 unsigned long event, void *ptr)
824 on_each_cpu(iucv_block_cpu, NULL, 1);
826 for (i = 0; i < iucv_max_pathid; i++) {
827 if (iucv_path_table[i])
828 rc = iucv_sever_pathid(i, NULL);
836 static struct notifier_block iucv_reboot_notifier = {
837 .notifier_call = iucv_reboot_event,
842 * @path: address of iucv path structure
843 * @handler: address of iucv handler structure
844 * @userdata: 16 bytes of data reflected to the communication partner
845 * @private: private data passed to interrupt handlers for this path
847 * This function is issued after the user received a connection pending
848 * external interrupt and now wishes to complete the IUCV communication path.
850 * Returns the result of the CP IUCV call.
852 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
853 u8 userdata[16], void *private)
855 union iucv_param *parm;
859 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
863 /* Prepare parameter block. */
864 parm = iucv_param[smp_processor_id()];
865 memset(parm, 0, sizeof(union iucv_param));
866 parm->ctrl.ippathid = path->pathid;
867 parm->ctrl.ipmsglim = path->msglim;
869 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
870 parm->ctrl.ipflags1 = path->flags;
872 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
874 path->private = private;
875 path->msglim = parm->ctrl.ipmsglim;
876 path->flags = parm->ctrl.ipflags1;
882 EXPORT_SYMBOL(iucv_path_accept);
886 * @path: address of iucv path structure
887 * @handler: address of iucv handler structure
888 * @userid: 8-byte user identification
889 * @system: 8-byte target system identification
890 * @userdata: 16 bytes of data reflected to the communication partner
891 * @private: private data passed to interrupt handlers for this path
893 * This function establishes an IUCV path. Although the connect may complete
894 * successfully, you are not able to use the path until you receive an IUCV
895 * Connection Complete external interrupt.
897 * Returns the result of the CP IUCV call.
899 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
900 u8 userid[8], u8 system[8], u8 userdata[16],
903 union iucv_param *parm;
906 spin_lock_bh(&iucv_table_lock);
907 iucv_cleanup_queue();
908 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
912 parm = iucv_param[smp_processor_id()];
913 memset(parm, 0, sizeof(union iucv_param));
914 parm->ctrl.ipmsglim = path->msglim;
915 parm->ctrl.ipflags1 = path->flags;
917 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
918 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
919 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
922 memcpy(parm->ctrl.iptarget, system,
923 sizeof(parm->ctrl.iptarget));
924 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
925 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
928 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
930 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
932 if (parm->ctrl.ippathid < iucv_max_pathid) {
933 path->pathid = parm->ctrl.ippathid;
934 path->msglim = parm->ctrl.ipmsglim;
935 path->flags = parm->ctrl.ipflags1;
936 path->handler = handler;
937 path->private = private;
938 list_add_tail(&path->list, &handler->paths);
939 iucv_path_table[path->pathid] = path;
941 iucv_sever_pathid(parm->ctrl.ippathid,
947 spin_unlock_bh(&iucv_table_lock);
950 EXPORT_SYMBOL(iucv_path_connect);
954 * @path: address of iucv path structure
955 * @userdata: 16 bytes of data reflected to the communication partner
957 * This function temporarily suspends incoming messages on an IUCV path.
958 * You can later reactivate the path by invoking the iucv_resume function.
960 * Returns the result from the CP IUCV call.
962 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
964 union iucv_param *parm;
968 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
972 parm = iucv_param[smp_processor_id()];
973 memset(parm, 0, sizeof(union iucv_param));
975 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
976 parm->ctrl.ippathid = path->pathid;
977 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
982 EXPORT_SYMBOL(iucv_path_quiesce);
986 * @path: address of iucv path structure
987 * @userdata: 16 bytes of data reflected to the communication partner
989 * This function resumes incoming messages on an IUCV path that has
990 * been stopped with iucv_path_quiesce.
992 * Returns the result from the CP IUCV call.
994 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
996 union iucv_param *parm;
1000 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1004 parm = iucv_param[smp_processor_id()];
1005 memset(parm, 0, sizeof(union iucv_param));
1007 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
1008 parm->ctrl.ippathid = path->pathid;
1009 rc = iucv_call_b2f0(IUCV_RESUME, parm);
1017 * @path: address of iucv path structure
1018 * @userdata: 16 bytes of data reflected to the communication partner
1020 * This function terminates an IUCV path.
1022 * Returns the result from the CP IUCV call.
1024 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
1029 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1033 if (iucv_active_cpu != smp_processor_id())
1034 spin_lock_bh(&iucv_table_lock);
1035 rc = iucv_sever_pathid(path->pathid, userdata);
1036 iucv_path_table[path->pathid] = NULL;
1037 list_del_init(&path->list);
1038 if (iucv_active_cpu != smp_processor_id())
1039 spin_unlock_bh(&iucv_table_lock);
1044 EXPORT_SYMBOL(iucv_path_sever);
1047 * iucv_message_purge
1048 * @path: address of iucv path structure
1049 * @msg: address of iucv msg structure
1050 * @srccls: source class of message
1052 * Cancels a message you have sent.
1054 * Returns the result from the CP IUCV call.
1056 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
1059 union iucv_param *parm;
1063 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1067 parm = iucv_param[smp_processor_id()];
1068 memset(parm, 0, sizeof(union iucv_param));
1069 parm->purge.ippathid = path->pathid;
1070 parm->purge.ipmsgid = msg->id;
1071 parm->purge.ipsrccls = srccls;
1072 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
1073 rc = iucv_call_b2f0(IUCV_PURGE, parm);
1075 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
1076 msg->tag = parm->purge.ipmsgtag;
1082 EXPORT_SYMBOL(iucv_message_purge);
1085 * iucv_message_receive_iprmdata
1086 * @path: address of iucv path structure
1087 * @msg: address of iucv msg structure
1088 * @flags: how the message is received (IUCV_IPBUFLST)
1089 * @buffer: address of data buffer or address of struct iucv_array
1090 * @size: length of data buffer
1093 * Internal function used by iucv_message_receive and __iucv_message_receive
1094 * to receive RMDATA data stored in struct iucv_message.
1096 static int iucv_message_receive_iprmdata(struct iucv_path *path,
1097 struct iucv_message *msg,
1098 u8 flags, void *buffer,
1099 size_t size, size_t *residual)
1101 struct iucv_array *array;
1106 * Message is 8 bytes long and has been stored to the
1107 * message descriptor itself.
1110 *residual = abs(size - 8);
1112 if (flags & IUCV_IPBUFLST) {
1113 /* Copy to struct iucv_array. */
1114 size = (size < 8) ? size : 8;
1115 for (array = buffer; size > 0; array++) {
1116 copy = min_t(size_t, size, array->length);
1117 memcpy((u8 *)(addr_t) array->address,
1123 /* Copy to direct buffer. */
1124 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1130 * __iucv_message_receive
1131 * @path: address of iucv path structure
1132 * @msg: address of iucv msg structure
1133 * @flags: how the message is received (IUCV_IPBUFLST)
1134 * @buffer: address of data buffer or address of struct iucv_array
1135 * @size: length of data buffer
1138 * This function receives messages that are being sent to you over
1139 * established paths. This function will deal with RMDATA messages
1140 * embedded in struct iucv_message as well.
1142 * Locking: no locking
1144 * Returns the result from the CP IUCV call.
1146 int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1147 u8 flags, void *buffer, size_t size, size_t *residual)
1149 union iucv_param *parm;
1152 if (msg->flags & IUCV_IPRMDATA)
1153 return iucv_message_receive_iprmdata(path, msg, flags,
1154 buffer, size, residual);
1155 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1159 parm = iucv_param[smp_processor_id()];
1160 memset(parm, 0, sizeof(union iucv_param));
1161 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1162 parm->db.ipbfln1f = (u32) size;
1163 parm->db.ipmsgid = msg->id;
1164 parm->db.ippathid = path->pathid;
1165 parm->db.iptrgcls = msg->class;
1166 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1167 IUCV_IPFGMID | IUCV_IPTRGCLS);
1168 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1169 if (!rc || rc == 5) {
1170 msg->flags = parm->db.ipflags1;
1172 *residual = parm->db.ipbfln1f;
1177 EXPORT_SYMBOL(__iucv_message_receive);
1180 * iucv_message_receive
1181 * @path: address of iucv path structure
1182 * @msg: address of iucv msg structure
1183 * @flags: how the message is received (IUCV_IPBUFLST)
1184 * @buffer: address of data buffer or address of struct iucv_array
1185 * @size: length of data buffer
1188 * This function receives messages that are being sent to you over
1189 * established paths. This function will deal with RMDATA messages
1190 * embedded in struct iucv_message as well.
1192 * Locking: local_bh_enable/local_bh_disable
1194 * Returns the result from the CP IUCV call.
1196 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1197 u8 flags, void *buffer, size_t size, size_t *residual)
1201 if (msg->flags & IUCV_IPRMDATA)
1202 return iucv_message_receive_iprmdata(path, msg, flags,
1203 buffer, size, residual);
1205 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
1209 EXPORT_SYMBOL(iucv_message_receive);
1212 * iucv_message_reject
1213 * @path: address of iucv path structure
1214 * @msg: address of iucv msg structure
1216 * The reject function refuses a specified message. Between the time you
1217 * are notified of a message and the time that you complete the message,
1218 * the message may be rejected.
1220 * Returns the result from the CP IUCV call.
1222 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1224 union iucv_param *parm;
1228 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1232 parm = iucv_param[smp_processor_id()];
1233 memset(parm, 0, sizeof(union iucv_param));
1234 parm->db.ippathid = path->pathid;
1235 parm->db.ipmsgid = msg->id;
1236 parm->db.iptrgcls = msg->class;
1237 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1238 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1243 EXPORT_SYMBOL(iucv_message_reject);
1246 * iucv_message_reply
1247 * @path: address of iucv path structure
1248 * @msg: address of iucv msg structure
1249 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1250 * @reply: address of reply data buffer or address of struct iucv_array
1251 * @size: length of reply data buffer
1253 * This function responds to the two-way messages that you receive. You
1254 * must identify completely the message to which you wish to reply. ie,
1255 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1256 * the parameter list.
1258 * Returns the result from the CP IUCV call.
1260 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1261 u8 flags, void *reply, size_t size)
1263 union iucv_param *parm;
1267 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1271 parm = iucv_param[smp_processor_id()];
1272 memset(parm, 0, sizeof(union iucv_param));
1273 if (flags & IUCV_IPRMDATA) {
1274 parm->dpl.ippathid = path->pathid;
1275 parm->dpl.ipflags1 = flags;
1276 parm->dpl.ipmsgid = msg->id;
1277 parm->dpl.iptrgcls = msg->class;
1278 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1280 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1281 parm->db.ipbfln1f = (u32) size;
1282 parm->db.ippathid = path->pathid;
1283 parm->db.ipflags1 = flags;
1284 parm->db.ipmsgid = msg->id;
1285 parm->db.iptrgcls = msg->class;
1287 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1292 EXPORT_SYMBOL(iucv_message_reply);
1295 * __iucv_message_send
1296 * @path: address of iucv path structure
1297 * @msg: address of iucv msg structure
1298 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1299 * @srccls: source class of message
1300 * @buffer: address of send buffer or address of struct iucv_array
1301 * @size: length of send buffer
1303 * This function transmits data to another application. Data to be
1304 * transmitted is in a buffer and this is a one-way message and the
1305 * receiver will not reply to the message.
1307 * Locking: no locking
1309 * Returns the result from the CP IUCV call.
1311 int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1312 u8 flags, u32 srccls, void *buffer, size_t size)
1314 union iucv_param *parm;
1317 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1321 parm = iucv_param[smp_processor_id()];
1322 memset(parm, 0, sizeof(union iucv_param));
1323 if (flags & IUCV_IPRMDATA) {
1324 /* Message of 8 bytes can be placed into the parameter list. */
1325 parm->dpl.ippathid = path->pathid;
1326 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1327 parm->dpl.iptrgcls = msg->class;
1328 parm->dpl.ipsrccls = srccls;
1329 parm->dpl.ipmsgtag = msg->tag;
1330 memcpy(parm->dpl.iprmmsg, buffer, 8);
1332 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1333 parm->db.ipbfln1f = (u32) size;
1334 parm->db.ippathid = path->pathid;
1335 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1336 parm->db.iptrgcls = msg->class;
1337 parm->db.ipsrccls = srccls;
1338 parm->db.ipmsgtag = msg->tag;
1340 rc = iucv_call_b2f0(IUCV_SEND, parm);
1342 msg->id = parm->db.ipmsgid;
1346 EXPORT_SYMBOL(__iucv_message_send);
1350 * @path: address of iucv path structure
1351 * @msg: address of iucv msg structure
1352 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1353 * @srccls: source class of message
1354 * @buffer: address of send buffer or address of struct iucv_array
1355 * @size: length of send buffer
1357 * This function transmits data to another application. Data to be
1358 * transmitted is in a buffer and this is a one-way message and the
1359 * receiver will not reply to the message.
1361 * Locking: local_bh_enable/local_bh_disable
1363 * Returns the result from the CP IUCV call.
1365 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1366 u8 flags, u32 srccls, void *buffer, size_t size)
1371 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
1375 EXPORT_SYMBOL(iucv_message_send);
1378 * iucv_message_send2way
1379 * @path: address of iucv path structure
1380 * @msg: address of iucv msg structure
1381 * @flags: how the message is sent and the reply is received
1382 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1383 * @srccls: source class of message
1384 * @buffer: address of send buffer or address of struct iucv_array
1385 * @size: length of send buffer
1386 * @ansbuf: address of answer buffer or address of struct iucv_array
1387 * @asize: size of reply buffer
1389 * This function transmits data to another application. Data to be
1390 * transmitted is in a buffer. The receiver of the send is expected to
1391 * reply to the message and a buffer is provided into which IUCV moves
1392 * the reply to this message.
1394 * Returns the result from the CP IUCV call.
1396 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1397 u8 flags, u32 srccls, void *buffer, size_t size,
1398 void *answer, size_t asize, size_t *residual)
1400 union iucv_param *parm;
1404 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
1408 parm = iucv_param[smp_processor_id()];
1409 memset(parm, 0, sizeof(union iucv_param));
1410 if (flags & IUCV_IPRMDATA) {
1411 parm->dpl.ippathid = path->pathid;
1412 parm->dpl.ipflags1 = path->flags; /* priority message */
1413 parm->dpl.iptrgcls = msg->class;
1414 parm->dpl.ipsrccls = srccls;
1415 parm->dpl.ipmsgtag = msg->tag;
1416 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1417 parm->dpl.ipbfln2f = (u32) asize;
1418 memcpy(parm->dpl.iprmmsg, buffer, 8);
1420 parm->db.ippathid = path->pathid;
1421 parm->db.ipflags1 = path->flags; /* priority message */
1422 parm->db.iptrgcls = msg->class;
1423 parm->db.ipsrccls = srccls;
1424 parm->db.ipmsgtag = msg->tag;
1425 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1426 parm->db.ipbfln1f = (u32) size;
1427 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1428 parm->db.ipbfln2f = (u32) asize;
1430 rc = iucv_call_b2f0(IUCV_SEND, parm);
1432 msg->id = parm->db.ipmsgid;
1437 EXPORT_SYMBOL(iucv_message_send2way);
1441 * @data: Pointer to external interrupt buffer
1443 * Process connection pending work item. Called from tasklet while holding
1446 struct iucv_path_pending {
1457 } __attribute__ ((packed));
1459 static void iucv_path_pending(struct iucv_irq_data *data)
1461 struct iucv_path_pending *ipp = (void *) data;
1462 struct iucv_handler *handler;
1463 struct iucv_path *path;
1466 BUG_ON(iucv_path_table[ipp->ippathid]);
1467 /* New pathid, handler found. Create a new path struct. */
1468 error = iucv_error_no_memory;
1469 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1472 path->pathid = ipp->ippathid;
1473 iucv_path_table[path->pathid] = path;
1474 EBCASC(ipp->ipvmid, 8);
1476 /* Call registered handler until one is found that wants the path. */
1477 list_for_each_entry(handler, &iucv_handler_list, list) {
1478 if (!handler->path_pending)
1481 * Add path to handler to allow a call to iucv_path_sever
1482 * inside the path_pending function. If the handler returns
1483 * an error remove the path from the handler again.
1485 list_add(&path->list, &handler->paths);
1486 path->handler = handler;
1487 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1489 list_del(&path->list);
1490 path->handler = NULL;
1492 /* No handler wanted the path. */
1493 iucv_path_table[path->pathid] = NULL;
1494 iucv_path_free(path);
1495 error = iucv_error_no_listener;
1497 iucv_sever_pathid(ipp->ippathid, error);
1501 * iucv_path_complete
1502 * @data: Pointer to external interrupt buffer
1504 * Process connection complete work item. Called from tasklet while holding
1507 struct iucv_path_complete {
1518 } __attribute__ ((packed));
1520 static void iucv_path_complete(struct iucv_irq_data *data)
1522 struct iucv_path_complete *ipc = (void *) data;
1523 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1526 path->flags = ipc->ipflags1;
1527 if (path && path->handler && path->handler->path_complete)
1528 path->handler->path_complete(path, ipc->ipuser);
1533 * @data: Pointer to external interrupt buffer
1535 * Process connection severed work item. Called from tasklet while holding
1538 struct iucv_path_severed {
1548 } __attribute__ ((packed));
1550 static void iucv_path_severed(struct iucv_irq_data *data)
1552 struct iucv_path_severed *ips = (void *) data;
1553 struct iucv_path *path = iucv_path_table[ips->ippathid];
1555 if (!path || !path->handler) /* Already severed */
1557 if (path->handler->path_severed)
1558 path->handler->path_severed(path, ips->ipuser);
1560 iucv_sever_pathid(path->pathid, NULL);
1561 iucv_path_table[path->pathid] = NULL;
1562 list_del(&path->list);
1563 iucv_path_free(path);
1568 * iucv_path_quiesced
1569 * @data: Pointer to external interrupt buffer
1571 * Process connection quiesced work item. Called from tasklet while holding
1574 struct iucv_path_quiesced {
1584 } __attribute__ ((packed));
1586 static void iucv_path_quiesced(struct iucv_irq_data *data)
1588 struct iucv_path_quiesced *ipq = (void *) data;
1589 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1591 if (path && path->handler && path->handler->path_quiesced)
1592 path->handler->path_quiesced(path, ipq->ipuser);
1597 * @data: Pointer to external interrupt buffer
1599 * Process connection resumed work item. Called from tasklet while holding
1602 struct iucv_path_resumed {
1612 } __attribute__ ((packed));
1614 static void iucv_path_resumed(struct iucv_irq_data *data)
1616 struct iucv_path_resumed *ipr = (void *) data;
1617 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1619 if (path && path->handler && path->handler->path_resumed)
1620 path->handler->path_resumed(path, ipr->ipuser);
1624 * iucv_message_complete
1625 * @data: Pointer to external interrupt buffer
1627 * Process message complete work item. Called from tasklet while holding
1630 struct iucv_message_complete {
1643 } __attribute__ ((packed));
1645 static void iucv_message_complete(struct iucv_irq_data *data)
1647 struct iucv_message_complete *imc = (void *) data;
1648 struct iucv_path *path = iucv_path_table[imc->ippathid];
1649 struct iucv_message msg;
1651 if (path && path->handler && path->handler->message_complete) {
1652 msg.flags = imc->ipflags1;
1653 msg.id = imc->ipmsgid;
1654 msg.audit = imc->ipaudit;
1655 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1656 msg.class = imc->ipsrccls;
1657 msg.tag = imc->ipmsgtag;
1658 msg.length = imc->ipbfln2f;
1659 path->handler->message_complete(path, &msg);
1664 * iucv_message_pending
1665 * @data: Pointer to external interrupt buffer
1667 * Process message pending work item. Called from tasklet while holding
1670 struct iucv_message_pending {
1688 } __attribute__ ((packed));
1690 static void iucv_message_pending(struct iucv_irq_data *data)
1692 struct iucv_message_pending *imp = (void *) data;
1693 struct iucv_path *path = iucv_path_table[imp->ippathid];
1694 struct iucv_message msg;
1696 if (path && path->handler && path->handler->message_pending) {
1697 msg.flags = imp->ipflags1;
1698 msg.id = imp->ipmsgid;
1699 msg.class = imp->iptrgcls;
1700 if (imp->ipflags1 & IUCV_IPRMDATA) {
1701 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1704 msg.length = imp->ln1msg2.ipbfln1f;
1705 msg.reply_size = imp->ipbfln2f;
1706 path->handler->message_pending(path, &msg);
1713 * This tasklet loops over the queue of irq buffers created by
1714 * iucv_external_interrupt, calls the appropriate action handler
1715 * and then frees the buffer.
1717 static void iucv_tasklet_fn(unsigned long ignored)
1719 typedef void iucv_irq_fn(struct iucv_irq_data *);
1720 static iucv_irq_fn *irq_fn[] = {
1721 [0x02] = iucv_path_complete,
1722 [0x03] = iucv_path_severed,
1723 [0x04] = iucv_path_quiesced,
1724 [0x05] = iucv_path_resumed,
1725 [0x06] = iucv_message_complete,
1726 [0x07] = iucv_message_complete,
1727 [0x08] = iucv_message_pending,
1728 [0x09] = iucv_message_pending,
1730 LIST_HEAD(task_queue);
1731 struct iucv_irq_list *p, *n;
1733 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1734 if (!spin_trylock(&iucv_table_lock)) {
1735 tasklet_schedule(&iucv_tasklet);
1738 iucv_active_cpu = smp_processor_id();
1740 spin_lock_irq(&iucv_queue_lock);
1741 list_splice_init(&iucv_task_queue, &task_queue);
1742 spin_unlock_irq(&iucv_queue_lock);
1744 list_for_each_entry_safe(p, n, &task_queue, list) {
1745 list_del_init(&p->list);
1746 irq_fn[p->data.iptype](&p->data);
1750 iucv_active_cpu = -1;
1751 spin_unlock(&iucv_table_lock);
1757 * This work function loops over the queue of path pending irq blocks
1758 * created by iucv_external_interrupt, calls the appropriate action
1759 * handler and then frees the buffer.
1761 static void iucv_work_fn(struct work_struct *work)
1763 typedef void iucv_irq_fn(struct iucv_irq_data *);
1764 LIST_HEAD(work_queue);
1765 struct iucv_irq_list *p, *n;
1767 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1768 spin_lock_bh(&iucv_table_lock);
1769 iucv_active_cpu = smp_processor_id();
1771 spin_lock_irq(&iucv_queue_lock);
1772 list_splice_init(&iucv_work_queue, &work_queue);
1773 spin_unlock_irq(&iucv_queue_lock);
1775 iucv_cleanup_queue();
1776 list_for_each_entry_safe(p, n, &work_queue, list) {
1777 list_del_init(&p->list);
1778 iucv_path_pending(&p->data);
1782 iucv_active_cpu = -1;
1783 spin_unlock_bh(&iucv_table_lock);
1787 * iucv_external_interrupt
1790 * Handles external interrupts coming in from CP.
1791 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1793 static void iucv_external_interrupt(u16 code)
1795 struct iucv_irq_data *p;
1796 struct iucv_irq_list *work;
1798 p = iucv_irq_data[smp_processor_id()];
1799 if (p->ippathid >= iucv_max_pathid) {
1800 WARN_ON(p->ippathid >= iucv_max_pathid);
1801 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1804 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1805 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1807 pr_warning("iucv_external_interrupt: out of memory\n");
1810 memcpy(&work->data, p, sizeof(work->data));
1811 spin_lock(&iucv_queue_lock);
1812 if (p->iptype == 0x01) {
1813 /* Path pending interrupt. */
1814 list_add_tail(&work->list, &iucv_work_queue);
1815 schedule_work(&iucv_work);
1817 /* The other interrupts. */
1818 list_add_tail(&work->list, &iucv_task_queue);
1819 tasklet_schedule(&iucv_tasklet);
1821 spin_unlock(&iucv_queue_lock);
1824 static int iucv_pm_prepare(struct device *dev)
1828 #ifdef CONFIG_PM_DEBUG
1829 printk(KERN_INFO "iucv_pm_prepare\n");
1831 if (dev->driver && dev->driver->pm && dev->driver->pm->prepare)
1832 rc = dev->driver->pm->prepare(dev);
1836 static void iucv_pm_complete(struct device *dev)
1838 #ifdef CONFIG_PM_DEBUG
1839 printk(KERN_INFO "iucv_pm_complete\n");
1841 if (dev->driver && dev->driver->pm && dev->driver->pm->complete)
1842 dev->driver->pm->complete(dev);
1846 * iucv_path_table_empty() - determine if iucv path table is empty
1848 * Returns 0 if there are still iucv pathes defined
1849 * 1 if there are no iucv pathes defined
1851 int iucv_path_table_empty(void)
1855 for (i = 0; i < iucv_max_pathid; i++) {
1856 if (iucv_path_table[i])
1863 * iucv_pm_freeze() - Freeze PM callback
1864 * @dev: iucv-based device
1866 * disable iucv interrupts
1867 * invoke callback function of the iucv-based driver
1868 * shut down iucv, if no iucv-pathes are established anymore
1870 static int iucv_pm_freeze(struct device *dev)
1875 #ifdef CONFIG_PM_DEBUG
1876 printk(KERN_WARNING "iucv_pm_freeze\n");
1878 for_each_cpu_mask_nr(cpu, iucv_irq_cpumask)
1879 smp_call_function_single(cpu, iucv_block_cpu_almost, NULL, 1);
1880 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
1881 rc = dev->driver->pm->freeze(dev);
1882 if (iucv_path_table_empty())
1888 * iucv_pm_thaw() - Thaw PM callback
1889 * @dev: iucv-based device
1891 * make iucv ready for use again: allocate path table, declare interrupt buffers
1892 * and enable iucv interrupts
1893 * invoke callback function of the iucv-based driver
1895 static int iucv_pm_thaw(struct device *dev)
1899 #ifdef CONFIG_PM_DEBUG
1900 printk(KERN_WARNING "iucv_pm_thaw\n");
1902 if (!iucv_path_table) {
1907 if (cpus_empty(iucv_irq_cpumask)) {
1908 if (iucv_nonsmp_handler)
1909 /* enable interrupts on one cpu */
1910 iucv_allow_cpu(NULL);
1912 /* enable interrupts on all cpus */
1915 if (dev->driver && dev->driver->pm && dev->driver->pm->thaw)
1916 rc = dev->driver->pm->thaw(dev);
1922 * iucv_pm_restore() - Restore PM callback
1923 * @dev: iucv-based device
1925 * make iucv ready for use again: allocate path table, declare interrupt buffers
1926 * and enable iucv interrupts
1927 * invoke callback function of the iucv-based driver
1929 static int iucv_pm_restore(struct device *dev)
1933 #ifdef CONFIG_PM_DEBUG
1934 printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
1936 if (cpus_empty(iucv_irq_cpumask)) {
1937 rc = iucv_query_maxconn();
1942 if (dev->driver && dev->driver->pm && dev->driver->pm->restore)
1943 rc = dev->driver->pm->restore(dev);
1951 * Allocates and initializes various data structures.
1953 static int __init iucv_init(void)
1958 if (!MACHINE_IS_VM) {
1959 rc = -EPROTONOSUPPORT;
1962 rc = iucv_query_maxconn();
1965 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1968 iucv_root = root_device_register("iucv");
1969 if (IS_ERR(iucv_root)) {
1970 rc = PTR_ERR(iucv_root);
1974 for_each_online_cpu(cpu) {
1975 /* Note: GFP_DMA used to get memory below 2G */
1976 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1977 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1978 if (!iucv_irq_data[cpu]) {
1983 /* Allocate parameter blocks. */
1984 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1985 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1986 if (!iucv_param[cpu]) {
1990 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
1991 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1992 if (!iucv_param_irq[cpu]) {
1998 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
2001 rc = register_reboot_notifier(&iucv_reboot_notifier);
2004 ASCEBC(iucv_error_no_listener, 16);
2005 ASCEBC(iucv_error_no_memory, 16);
2006 ASCEBC(iucv_error_pathid, 16);
2008 rc = bus_register(&iucv_bus);
2014 unregister_reboot_notifier(&iucv_reboot_notifier);
2016 unregister_hotcpu_notifier(&iucv_cpu_notifier);
2018 for_each_possible_cpu(cpu) {
2019 kfree(iucv_param_irq[cpu]);
2020 iucv_param_irq[cpu] = NULL;
2021 kfree(iucv_param[cpu]);
2022 iucv_param[cpu] = NULL;
2023 kfree(iucv_irq_data[cpu]);
2024 iucv_irq_data[cpu] = NULL;
2026 root_device_unregister(iucv_root);
2028 unregister_external_interrupt(0x4000, iucv_external_interrupt);
2036 * Frees everything allocated from iucv_init.
2038 static void __exit iucv_exit(void)
2040 struct iucv_irq_list *p, *n;
2043 spin_lock_irq(&iucv_queue_lock);
2044 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
2046 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
2048 spin_unlock_irq(&iucv_queue_lock);
2049 unregister_reboot_notifier(&iucv_reboot_notifier);
2050 unregister_hotcpu_notifier(&iucv_cpu_notifier);
2051 for_each_possible_cpu(cpu) {
2052 kfree(iucv_param_irq[cpu]);
2053 iucv_param_irq[cpu] = NULL;
2054 kfree(iucv_param[cpu]);
2055 iucv_param[cpu] = NULL;
2056 kfree(iucv_irq_data[cpu]);
2057 iucv_irq_data[cpu] = NULL;
2059 root_device_unregister(iucv_root);
2060 bus_unregister(&iucv_bus);
2061 unregister_external_interrupt(0x4000, iucv_external_interrupt);
2064 subsys_initcall(iucv_init);
2065 module_exit(iucv_exit);
2067 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
2068 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
2069 MODULE_LICENSE("GPL");