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
)
86 IUCV_PM_RESTORING
= 3,
88 static enum iucv_pm_states iucv_pm_state
;
90 static int iucv_pm_prepare(struct device
*);
91 static void iucv_pm_complete(struct device
*);
92 static int iucv_pm_freeze(struct device
*);
93 static int iucv_pm_thaw(struct device
*);
94 static int iucv_pm_restore(struct device
*);
96 static const struct dev_pm_ops iucv_pm_ops
= {
97 .prepare
= iucv_pm_prepare
,
98 .complete
= iucv_pm_complete
,
99 .freeze
= iucv_pm_freeze
,
100 .thaw
= iucv_pm_thaw
,
101 .restore
= iucv_pm_restore
,
104 struct bus_type iucv_bus
= {
106 .match
= iucv_bus_match
,
109 EXPORT_SYMBOL(iucv_bus
);
111 struct device
*iucv_root
;
112 EXPORT_SYMBOL(iucv_root
);
114 static int iucv_available
;
116 /* General IUCV interrupt structure */
117 struct iucv_irq_data
{
124 struct iucv_irq_list
{
125 struct list_head list
;
126 struct iucv_irq_data data
;
129 static struct iucv_irq_data
*iucv_irq_data
[NR_CPUS
];
130 static cpumask_t iucv_buffer_cpumask
= CPU_MASK_NONE
;
131 static cpumask_t iucv_irq_cpumask
= CPU_MASK_NONE
;
134 * Queue of interrupt buffers lock for delivery via the tasklet
135 * (fast but can't call smp_call_function).
137 static LIST_HEAD(iucv_task_queue
);
140 * The tasklet for fast delivery of iucv interrupts.
142 static void iucv_tasklet_fn(unsigned long);
143 static DECLARE_TASKLET(iucv_tasklet
, iucv_tasklet_fn
,0);
146 * Queue of interrupt buffers for delivery via a work queue
147 * (slower but can call smp_call_function).
149 static LIST_HEAD(iucv_work_queue
);
152 * The work element to deliver path pending interrupts.
154 static void iucv_work_fn(struct work_struct
*work
);
155 static DECLARE_WORK(iucv_work
, iucv_work_fn
);
158 * Spinlock protecting task and work queue.
160 static DEFINE_SPINLOCK(iucv_queue_lock
);
162 enum iucv_command_codes
{
164 IUCV_RETRIEVE_BUFFER
= 2,
172 IUCV_DECLARE_BUFFER
= 12,
177 IUCV_SETCONTROLMASK
= 17,
181 * Error messages that are used with the iucv_sever function. They get
182 * converted to EBCDIC.
184 static char iucv_error_no_listener
[16] = "NO LISTENER";
185 static char iucv_error_no_memory
[16] = "NO MEMORY";
186 static char iucv_error_pathid
[16] = "INVALID PATHID";
189 * iucv_handler_list: List of registered handlers.
191 static LIST_HEAD(iucv_handler_list
);
194 * iucv_path_table: an array of iucv_path structures.
196 static struct iucv_path
**iucv_path_table
;
197 static unsigned long iucv_max_pathid
;
200 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
202 static DEFINE_SPINLOCK(iucv_table_lock
);
205 * iucv_active_cpu: contains the number of the cpu executing the tasklet
206 * or the work handler. Needed for iucv_path_sever called from tasklet.
208 static int iucv_active_cpu
= -1;
211 * Mutex and wait queue for iucv_register/iucv_unregister.
213 static DEFINE_MUTEX(iucv_register_mutex
);
216 * Counter for number of non-smp capable handlers.
218 static int iucv_nonsmp_handler
;
221 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
222 * iucv_path_quiesce and iucv_path_sever.
224 struct iucv_cmd_control
{
233 } __attribute__ ((packed
,aligned(8)));
236 * Data in parameter list iucv structure. Used by iucv_message_send,
237 * iucv_message_send2way and iucv_message_reply.
239 struct iucv_cmd_dpl
{
251 } __attribute__ ((packed
,aligned(8)));
254 * Data in buffer iucv structure. Used by iucv_message_receive,
255 * iucv_message_reject, iucv_message_send, iucv_message_send2way
256 * and iucv_declare_cpu.
271 } __attribute__ ((packed
,aligned(8)));
274 * Purge message iucv structure. Used by iucv_message_purge.
276 struct iucv_cmd_purge
{
287 } __attribute__ ((packed
,aligned(8)));
290 * Set mask iucv structure. Used by iucv_enable_cpu.
292 struct iucv_cmd_set_mask
{
297 } __attribute__ ((packed
,aligned(8)));
300 struct iucv_cmd_control ctrl
;
301 struct iucv_cmd_dpl dpl
;
302 struct iucv_cmd_db db
;
303 struct iucv_cmd_purge purge
;
304 struct iucv_cmd_set_mask set_mask
;
308 * Anchor for per-cpu IUCV command parameter block.
310 static union iucv_param
*iucv_param
[NR_CPUS
];
311 static union iucv_param
*iucv_param_irq
[NR_CPUS
];
315 * @code: identifier of IUCV call to CP.
316 * @parm: pointer to a struct iucv_parm block
318 * Calls CP to execute IUCV commands.
320 * Returns the result of the CP IUCV call.
322 static inline int iucv_call_b2f0(int command
, union iucv_param
*parm
)
324 register unsigned long reg0
asm ("0");
325 register unsigned long reg1
asm ("1");
329 reg1
= virt_to_phys(parm
);
331 " .long 0xb2f01000\n"
334 : "=d" (ccode
), "=m" (*parm
), "+d" (reg0
), "+a" (reg1
)
335 : "m" (*parm
) : "cc");
336 return (ccode
== 1) ? parm
->ctrl
.iprcode
: ccode
;
342 * Determines the maximum number of connections that may be established.
344 * Returns the maximum number of connections or -EPERM is IUCV is not
347 static int iucv_query_maxconn(void)
349 register unsigned long reg0
asm ("0");
350 register unsigned long reg1
asm ("1");
354 param
= kzalloc(sizeof(union iucv_param
), GFP_KERNEL
|GFP_DMA
);
358 reg1
= (unsigned long) param
;
360 " .long 0xb2f01000\n"
363 : "=d" (ccode
), "+d" (reg0
), "+d" (reg1
) : : "cc");
365 iucv_max_pathid
= reg1
;
367 return ccode
? -EPERM
: 0;
374 * Allow iucv interrupts on this cpu.
376 static void iucv_allow_cpu(void *data
)
378 int cpu
= smp_processor_id();
379 union iucv_param
*parm
;
382 * Enable all iucv interrupts.
383 * ipmask contains bits for the different interrupts
384 * 0x80 - Flag to allow nonpriority message pending interrupts
385 * 0x40 - Flag to allow priority message pending interrupts
386 * 0x20 - Flag to allow nonpriority message completion interrupts
387 * 0x10 - Flag to allow priority message completion interrupts
388 * 0x08 - Flag to allow IUCV control interrupts
390 parm
= iucv_param_irq
[cpu
];
391 memset(parm
, 0, sizeof(union iucv_param
));
392 parm
->set_mask
.ipmask
= 0xf8;
393 iucv_call_b2f0(IUCV_SETMASK
, parm
);
396 * Enable all iucv control interrupts.
397 * ipmask contains bits for the different interrupts
398 * 0x80 - Flag to allow pending connections interrupts
399 * 0x40 - Flag to allow connection complete interrupts
400 * 0x20 - Flag to allow connection severed interrupts
401 * 0x10 - Flag to allow connection quiesced interrupts
402 * 0x08 - Flag to allow connection resumed interrupts
404 memset(parm
, 0, sizeof(union iucv_param
));
405 parm
->set_mask
.ipmask
= 0xf8;
406 iucv_call_b2f0(IUCV_SETCONTROLMASK
, parm
);
407 /* Set indication that iucv interrupts are allowed for this cpu. */
408 cpu_set(cpu
, iucv_irq_cpumask
);
415 * Block iucv interrupts on this cpu.
417 static void iucv_block_cpu(void *data
)
419 int cpu
= smp_processor_id();
420 union iucv_param
*parm
;
422 /* Disable all iucv interrupts. */
423 parm
= iucv_param_irq
[cpu
];
424 memset(parm
, 0, sizeof(union iucv_param
));
425 iucv_call_b2f0(IUCV_SETMASK
, parm
);
427 /* Clear indication that iucv interrupts are allowed for this cpu. */
428 cpu_clear(cpu
, iucv_irq_cpumask
);
432 * iucv_block_cpu_almost
435 * Allow connection-severed interrupts only on this cpu.
437 static void iucv_block_cpu_almost(void *data
)
439 int cpu
= smp_processor_id();
440 union iucv_param
*parm
;
442 /* Allow iucv control interrupts only */
443 parm
= iucv_param_irq
[cpu
];
444 memset(parm
, 0, sizeof(union iucv_param
));
445 parm
->set_mask
.ipmask
= 0x08;
446 iucv_call_b2f0(IUCV_SETMASK
, parm
);
447 /* Allow iucv-severed interrupt only */
448 memset(parm
, 0, sizeof(union iucv_param
));
449 parm
->set_mask
.ipmask
= 0x20;
450 iucv_call_b2f0(IUCV_SETCONTROLMASK
, parm
);
452 /* Clear indication that iucv interrupts are allowed for this cpu. */
453 cpu_clear(cpu
, iucv_irq_cpumask
);
460 * Declare a interrupt buffer on this cpu.
462 static void iucv_declare_cpu(void *data
)
464 int cpu
= smp_processor_id();
465 union iucv_param
*parm
;
468 if (cpu_isset(cpu
, iucv_buffer_cpumask
))
471 /* Declare interrupt buffer. */
472 parm
= iucv_param_irq
[cpu
];
473 memset(parm
, 0, sizeof(union iucv_param
));
474 parm
->db
.ipbfadr1
= virt_to_phys(iucv_irq_data
[cpu
]);
475 rc
= iucv_call_b2f0(IUCV_DECLARE_BUFFER
, parm
);
477 char *err
= "Unknown";
480 err
= "Directory error";
483 err
= "Invalid length";
486 err
= "Buffer already exists";
489 err
= "Buffer overlap";
492 err
= "Paging or storage error";
495 pr_warning("Defining an interrupt buffer on CPU %i"
496 " failed with 0x%02x (%s)\n", cpu
, rc
, err
);
500 /* Set indication that an iucv buffer exists for this cpu. */
501 cpu_set(cpu
, iucv_buffer_cpumask
);
503 if (iucv_nonsmp_handler
== 0 || cpus_empty(iucv_irq_cpumask
))
504 /* Enable iucv interrupts on this cpu. */
505 iucv_allow_cpu(NULL
);
507 /* Disable iucv interrupts on this cpu. */
508 iucv_block_cpu(NULL
);
515 * Retrieve interrupt buffer on this cpu.
517 static void iucv_retrieve_cpu(void *data
)
519 int cpu
= smp_processor_id();
520 union iucv_param
*parm
;
522 if (!cpu_isset(cpu
, iucv_buffer_cpumask
))
525 /* Block iucv interrupts. */
526 iucv_block_cpu(NULL
);
528 /* Retrieve interrupt buffer. */
529 parm
= iucv_param_irq
[cpu
];
530 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER
, parm
);
532 /* Clear indication that an iucv buffer exists for this cpu. */
533 cpu_clear(cpu
, iucv_buffer_cpumask
);
539 * Allow iucv interrupts on all cpus.
541 static void iucv_setmask_mp(void)
546 for_each_online_cpu(cpu
)
547 /* Enable all cpus with a declared buffer. */
548 if (cpu_isset(cpu
, iucv_buffer_cpumask
) &&
549 !cpu_isset(cpu
, iucv_irq_cpumask
))
550 smp_call_function_single(cpu
, iucv_allow_cpu
,
558 * Allow iucv interrupts on a single cpu.
560 static void iucv_setmask_up(void)
565 /* Disable all cpu but the first in cpu_irq_cpumask. */
566 cpumask
= iucv_irq_cpumask
;
567 cpu_clear(first_cpu(iucv_irq_cpumask
), cpumask
);
568 for_each_cpu_mask_nr(cpu
, cpumask
)
569 smp_call_function_single(cpu
, iucv_block_cpu
, NULL
, 1);
575 * This function makes iucv ready for use. It allocates the pathid
576 * table, declares an iucv interrupt buffer and enables the iucv
577 * interrupts. Called when the first user has registered an iucv
580 static int iucv_enable(void)
587 alloc_size
= iucv_max_pathid
* sizeof(struct iucv_path
);
588 iucv_path_table
= kzalloc(alloc_size
, GFP_KERNEL
);
589 if (!iucv_path_table
)
591 /* Declare per cpu buffers. */
593 for_each_online_cpu(cpu
)
594 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
595 if (cpus_empty(iucv_buffer_cpumask
))
596 /* No cpu could declare an iucv buffer. */
601 kfree(iucv_path_table
);
602 iucv_path_table
= NULL
;
610 * This function shuts down iucv. It disables iucv interrupts, retrieves
611 * the iucv interrupt buffer and frees the pathid table. Called after the
612 * last user unregister its iucv handler.
614 static void iucv_disable(void)
617 on_each_cpu(iucv_retrieve_cpu
, NULL
, 1);
618 kfree(iucv_path_table
);
619 iucv_path_table
= NULL
;
623 static int __cpuinit
iucv_cpu_notify(struct notifier_block
*self
,
624 unsigned long action
, void *hcpu
)
627 long cpu
= (long) hcpu
;
631 case CPU_UP_PREPARE_FROZEN
:
632 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
633 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
634 if (!iucv_irq_data
[cpu
])
635 return notifier_from_errno(-ENOMEM
);
637 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
638 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
639 if (!iucv_param
[cpu
]) {
640 kfree(iucv_irq_data
[cpu
]);
641 iucv_irq_data
[cpu
] = NULL
;
642 return notifier_from_errno(-ENOMEM
);
644 iucv_param_irq
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
645 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
646 if (!iucv_param_irq
[cpu
]) {
647 kfree(iucv_param
[cpu
]);
648 iucv_param
[cpu
] = NULL
;
649 kfree(iucv_irq_data
[cpu
]);
650 iucv_irq_data
[cpu
] = NULL
;
651 return notifier_from_errno(-ENOMEM
);
654 case CPU_UP_CANCELED
:
655 case CPU_UP_CANCELED_FROZEN
:
657 case CPU_DEAD_FROZEN
:
658 kfree(iucv_param_irq
[cpu
]);
659 iucv_param_irq
[cpu
] = NULL
;
660 kfree(iucv_param
[cpu
]);
661 iucv_param
[cpu
] = NULL
;
662 kfree(iucv_irq_data
[cpu
]);
663 iucv_irq_data
[cpu
] = NULL
;
666 case CPU_ONLINE_FROZEN
:
667 case CPU_DOWN_FAILED
:
668 case CPU_DOWN_FAILED_FROZEN
:
669 if (!iucv_path_table
)
671 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
673 case CPU_DOWN_PREPARE
:
674 case CPU_DOWN_PREPARE_FROZEN
:
675 if (!iucv_path_table
)
677 cpumask
= iucv_buffer_cpumask
;
678 cpu_clear(cpu
, cpumask
);
679 if (cpus_empty(cpumask
))
680 /* Can't offline last IUCV enabled cpu. */
681 return notifier_from_errno(-EINVAL
);
682 smp_call_function_single(cpu
, iucv_retrieve_cpu
, NULL
, 1);
683 if (cpus_empty(iucv_irq_cpumask
))
684 smp_call_function_single(first_cpu(iucv_buffer_cpumask
),
685 iucv_allow_cpu
, NULL
, 1);
691 static struct notifier_block __refdata iucv_cpu_notifier
= {
692 .notifier_call
= iucv_cpu_notify
,
697 * @pathid: path identification number.
698 * @userdata: 16-bytes of user data.
700 * Sever an iucv path to free up the pathid. Used internally.
702 static int iucv_sever_pathid(u16 pathid
, u8 userdata
[16])
704 union iucv_param
*parm
;
706 parm
= iucv_param_irq
[smp_processor_id()];
707 memset(parm
, 0, sizeof(union iucv_param
));
709 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
710 parm
->ctrl
.ippathid
= pathid
;
711 return iucv_call_b2f0(IUCV_SEVER
, parm
);
715 * __iucv_cleanup_queue
716 * @dummy: unused dummy argument
718 * Nop function called via smp_call_function to force work items from
719 * pending external iucv interrupts to the work queue.
721 static void __iucv_cleanup_queue(void *dummy
)
728 * Function called after a path has been severed to find all remaining
729 * work items for the now stale pathid. The caller needs to hold the
732 static void iucv_cleanup_queue(void)
734 struct iucv_irq_list
*p
, *n
;
737 * When a path is severed, the pathid can be reused immediatly
738 * on a iucv connect or a connection pending interrupt. Remove
739 * all entries from the task queue that refer to a stale pathid
740 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
741 * or deliver the connection pending interrupt. To get all the
742 * pending interrupts force them to the work queue by calling
743 * an empty function on all cpus.
745 smp_call_function(__iucv_cleanup_queue
, NULL
, 1);
746 spin_lock_irq(&iucv_queue_lock
);
747 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
) {
748 /* Remove stale work items from the task queue. */
749 if (iucv_path_table
[p
->data
.ippathid
] == NULL
) {
754 spin_unlock_irq(&iucv_queue_lock
);
759 * @handler: address of iucv handler structure
760 * @smp: != 0 indicates that the handler can deal with out of order messages
762 * Registers a driver with IUCV.
764 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
765 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
767 int iucv_register(struct iucv_handler
*handler
, int smp
)
773 mutex_lock(&iucv_register_mutex
);
775 iucv_nonsmp_handler
++;
776 if (list_empty(&iucv_handler_list
)) {
780 } else if (!smp
&& iucv_nonsmp_handler
== 1)
782 INIT_LIST_HEAD(&handler
->paths
);
784 spin_lock_bh(&iucv_table_lock
);
785 list_add_tail(&handler
->list
, &iucv_handler_list
);
786 spin_unlock_bh(&iucv_table_lock
);
789 mutex_unlock(&iucv_register_mutex
);
792 EXPORT_SYMBOL(iucv_register
);
796 * @handler: address of iucv handler structure
797 * @smp: != 0 indicates that the handler can deal with out of order messages
799 * Unregister driver from IUCV.
801 void iucv_unregister(struct iucv_handler
*handler
, int smp
)
803 struct iucv_path
*p
, *n
;
805 mutex_lock(&iucv_register_mutex
);
806 spin_lock_bh(&iucv_table_lock
);
807 /* Remove handler from the iucv_handler_list. */
808 list_del_init(&handler
->list
);
809 /* Sever all pathids still refering to the handler. */
810 list_for_each_entry_safe(p
, n
, &handler
->paths
, list
) {
811 iucv_sever_pathid(p
->pathid
, NULL
);
812 iucv_path_table
[p
->pathid
] = NULL
;
816 spin_unlock_bh(&iucv_table_lock
);
818 iucv_nonsmp_handler
--;
819 if (list_empty(&iucv_handler_list
))
821 else if (!smp
&& iucv_nonsmp_handler
== 0)
823 mutex_unlock(&iucv_register_mutex
);
825 EXPORT_SYMBOL(iucv_unregister
);
827 static int iucv_reboot_event(struct notifier_block
*this,
828 unsigned long event
, void *ptr
)
833 on_each_cpu(iucv_block_cpu
, NULL
, 1);
835 for (i
= 0; i
< iucv_max_pathid
; i
++) {
836 if (iucv_path_table
[i
])
837 rc
= iucv_sever_pathid(i
, NULL
);
845 static struct notifier_block iucv_reboot_notifier
= {
846 .notifier_call
= iucv_reboot_event
,
851 * @path: address of iucv path structure
852 * @handler: address of iucv handler structure
853 * @userdata: 16 bytes of data reflected to the communication partner
854 * @private: private data passed to interrupt handlers for this path
856 * This function is issued after the user received a connection pending
857 * external interrupt and now wishes to complete the IUCV communication path.
859 * Returns the result of the CP IUCV call.
861 int iucv_path_accept(struct iucv_path
*path
, struct iucv_handler
*handler
,
862 u8 userdata
[16], void *private)
864 union iucv_param
*parm
;
868 if (cpus_empty(iucv_buffer_cpumask
)) {
872 /* Prepare parameter block. */
873 parm
= iucv_param
[smp_processor_id()];
874 memset(parm
, 0, sizeof(union iucv_param
));
875 parm
->ctrl
.ippathid
= path
->pathid
;
876 parm
->ctrl
.ipmsglim
= path
->msglim
;
878 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
879 parm
->ctrl
.ipflags1
= path
->flags
;
881 rc
= iucv_call_b2f0(IUCV_ACCEPT
, parm
);
883 path
->private = private;
884 path
->msglim
= parm
->ctrl
.ipmsglim
;
885 path
->flags
= parm
->ctrl
.ipflags1
;
891 EXPORT_SYMBOL(iucv_path_accept
);
895 * @path: address of iucv path structure
896 * @handler: address of iucv handler structure
897 * @userid: 8-byte user identification
898 * @system: 8-byte target system identification
899 * @userdata: 16 bytes of data reflected to the communication partner
900 * @private: private data passed to interrupt handlers for this path
902 * This function establishes an IUCV path. Although the connect may complete
903 * successfully, you are not able to use the path until you receive an IUCV
904 * Connection Complete external interrupt.
906 * Returns the result of the CP IUCV call.
908 int iucv_path_connect(struct iucv_path
*path
, struct iucv_handler
*handler
,
909 u8 userid
[8], u8 system
[8], u8 userdata
[16],
912 union iucv_param
*parm
;
915 spin_lock_bh(&iucv_table_lock
);
916 iucv_cleanup_queue();
917 if (cpus_empty(iucv_buffer_cpumask
)) {
921 parm
= iucv_param
[smp_processor_id()];
922 memset(parm
, 0, sizeof(union iucv_param
));
923 parm
->ctrl
.ipmsglim
= path
->msglim
;
924 parm
->ctrl
.ipflags1
= path
->flags
;
926 memcpy(parm
->ctrl
.ipvmid
, userid
, sizeof(parm
->ctrl
.ipvmid
));
927 ASCEBC(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
928 EBC_TOUPPER(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
931 memcpy(parm
->ctrl
.iptarget
, system
,
932 sizeof(parm
->ctrl
.iptarget
));
933 ASCEBC(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
934 EBC_TOUPPER(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
937 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
939 rc
= iucv_call_b2f0(IUCV_CONNECT
, parm
);
941 if (parm
->ctrl
.ippathid
< iucv_max_pathid
) {
942 path
->pathid
= parm
->ctrl
.ippathid
;
943 path
->msglim
= parm
->ctrl
.ipmsglim
;
944 path
->flags
= parm
->ctrl
.ipflags1
;
945 path
->handler
= handler
;
946 path
->private = private;
947 list_add_tail(&path
->list
, &handler
->paths
);
948 iucv_path_table
[path
->pathid
] = path
;
950 iucv_sever_pathid(parm
->ctrl
.ippathid
,
956 spin_unlock_bh(&iucv_table_lock
);
959 EXPORT_SYMBOL(iucv_path_connect
);
963 * @path: address of iucv path structure
964 * @userdata: 16 bytes of data reflected to the communication partner
966 * This function temporarily suspends incoming messages on an IUCV path.
967 * You can later reactivate the path by invoking the iucv_resume function.
969 * Returns the result from the CP IUCV call.
971 int iucv_path_quiesce(struct iucv_path
*path
, u8 userdata
[16])
973 union iucv_param
*parm
;
977 if (cpus_empty(iucv_buffer_cpumask
)) {
981 parm
= iucv_param
[smp_processor_id()];
982 memset(parm
, 0, sizeof(union iucv_param
));
984 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
985 parm
->ctrl
.ippathid
= path
->pathid
;
986 rc
= iucv_call_b2f0(IUCV_QUIESCE
, parm
);
991 EXPORT_SYMBOL(iucv_path_quiesce
);
995 * @path: address of iucv path structure
996 * @userdata: 16 bytes of data reflected to the communication partner
998 * This function resumes incoming messages on an IUCV path that has
999 * been stopped with iucv_path_quiesce.
1001 * Returns the result from the CP IUCV call.
1003 int iucv_path_resume(struct iucv_path
*path
, u8 userdata
[16])
1005 union iucv_param
*parm
;
1009 if (cpus_empty(iucv_buffer_cpumask
)) {
1013 parm
= iucv_param
[smp_processor_id()];
1014 memset(parm
, 0, sizeof(union iucv_param
));
1016 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
1017 parm
->ctrl
.ippathid
= path
->pathid
;
1018 rc
= iucv_call_b2f0(IUCV_RESUME
, parm
);
1026 * @path: address of iucv path structure
1027 * @userdata: 16 bytes of data reflected to the communication partner
1029 * This function terminates an IUCV path.
1031 * Returns the result from the CP IUCV call.
1033 int iucv_path_sever(struct iucv_path
*path
, u8 userdata
[16])
1038 if (cpus_empty(iucv_buffer_cpumask
)) {
1042 if (iucv_active_cpu
!= smp_processor_id())
1043 spin_lock_bh(&iucv_table_lock
);
1044 rc
= iucv_sever_pathid(path
->pathid
, userdata
);
1045 iucv_path_table
[path
->pathid
] = NULL
;
1046 list_del_init(&path
->list
);
1047 if (iucv_active_cpu
!= smp_processor_id())
1048 spin_unlock_bh(&iucv_table_lock
);
1053 EXPORT_SYMBOL(iucv_path_sever
);
1056 * iucv_message_purge
1057 * @path: address of iucv path structure
1058 * @msg: address of iucv msg structure
1059 * @srccls: source class of message
1061 * Cancels a message you have sent.
1063 * Returns the result from the CP IUCV call.
1065 int iucv_message_purge(struct iucv_path
*path
, struct iucv_message
*msg
,
1068 union iucv_param
*parm
;
1072 if (cpus_empty(iucv_buffer_cpumask
)) {
1076 parm
= iucv_param
[smp_processor_id()];
1077 memset(parm
, 0, sizeof(union iucv_param
));
1078 parm
->purge
.ippathid
= path
->pathid
;
1079 parm
->purge
.ipmsgid
= msg
->id
;
1080 parm
->purge
.ipsrccls
= srccls
;
1081 parm
->purge
.ipflags1
= IUCV_IPSRCCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
;
1082 rc
= iucv_call_b2f0(IUCV_PURGE
, parm
);
1084 msg
->audit
= (*(u32
*) &parm
->purge
.ipaudit
) >> 8;
1085 msg
->tag
= parm
->purge
.ipmsgtag
;
1091 EXPORT_SYMBOL(iucv_message_purge
);
1094 * iucv_message_receive_iprmdata
1095 * @path: address of iucv path structure
1096 * @msg: address of iucv msg structure
1097 * @flags: how the message is received (IUCV_IPBUFLST)
1098 * @buffer: address of data buffer or address of struct iucv_array
1099 * @size: length of data buffer
1102 * Internal function used by iucv_message_receive and __iucv_message_receive
1103 * to receive RMDATA data stored in struct iucv_message.
1105 static int iucv_message_receive_iprmdata(struct iucv_path
*path
,
1106 struct iucv_message
*msg
,
1107 u8 flags
, void *buffer
,
1108 size_t size
, size_t *residual
)
1110 struct iucv_array
*array
;
1115 * Message is 8 bytes long and has been stored to the
1116 * message descriptor itself.
1119 *residual
= abs(size
- 8);
1121 if (flags
& IUCV_IPBUFLST
) {
1122 /* Copy to struct iucv_array. */
1123 size
= (size
< 8) ? size
: 8;
1124 for (array
= buffer
; size
> 0; array
++) {
1125 copy
= min_t(size_t, size
, array
->length
);
1126 memcpy((u8
*)(addr_t
) array
->address
,
1132 /* Copy to direct buffer. */
1133 memcpy(buffer
, rmmsg
, min_t(size_t, size
, 8));
1139 * __iucv_message_receive
1140 * @path: address of iucv path structure
1141 * @msg: address of iucv msg structure
1142 * @flags: how the message is received (IUCV_IPBUFLST)
1143 * @buffer: address of data buffer or address of struct iucv_array
1144 * @size: length of data buffer
1147 * This function receives messages that are being sent to you over
1148 * established paths. This function will deal with RMDATA messages
1149 * embedded in struct iucv_message as well.
1151 * Locking: no locking
1153 * Returns the result from the CP IUCV call.
1155 int __iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1156 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1158 union iucv_param
*parm
;
1161 if (msg
->flags
& IUCV_IPRMDATA
)
1162 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1163 buffer
, size
, residual
);
1164 if (cpus_empty(iucv_buffer_cpumask
)) {
1168 parm
= iucv_param
[smp_processor_id()];
1169 memset(parm
, 0, sizeof(union iucv_param
));
1170 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1171 parm
->db
.ipbfln1f
= (u32
) size
;
1172 parm
->db
.ipmsgid
= msg
->id
;
1173 parm
->db
.ippathid
= path
->pathid
;
1174 parm
->db
.iptrgcls
= msg
->class;
1175 parm
->db
.ipflags1
= (flags
| IUCV_IPFGPID
|
1176 IUCV_IPFGMID
| IUCV_IPTRGCLS
);
1177 rc
= iucv_call_b2f0(IUCV_RECEIVE
, parm
);
1178 if (!rc
|| rc
== 5) {
1179 msg
->flags
= parm
->db
.ipflags1
;
1181 *residual
= parm
->db
.ipbfln1f
;
1186 EXPORT_SYMBOL(__iucv_message_receive
);
1189 * iucv_message_receive
1190 * @path: address of iucv path structure
1191 * @msg: address of iucv msg structure
1192 * @flags: how the message is received (IUCV_IPBUFLST)
1193 * @buffer: address of data buffer or address of struct iucv_array
1194 * @size: length of data buffer
1197 * This function receives messages that are being sent to you over
1198 * established paths. This function will deal with RMDATA messages
1199 * embedded in struct iucv_message as well.
1201 * Locking: local_bh_enable/local_bh_disable
1203 * Returns the result from the CP IUCV call.
1205 int iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1206 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1210 if (msg
->flags
& IUCV_IPRMDATA
)
1211 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1212 buffer
, size
, residual
);
1214 rc
= __iucv_message_receive(path
, msg
, flags
, buffer
, size
, residual
);
1218 EXPORT_SYMBOL(iucv_message_receive
);
1221 * iucv_message_reject
1222 * @path: address of iucv path structure
1223 * @msg: address of iucv msg structure
1225 * The reject function refuses a specified message. Between the time you
1226 * are notified of a message and the time that you complete the message,
1227 * the message may be rejected.
1229 * Returns the result from the CP IUCV call.
1231 int iucv_message_reject(struct iucv_path
*path
, struct iucv_message
*msg
)
1233 union iucv_param
*parm
;
1237 if (cpus_empty(iucv_buffer_cpumask
)) {
1241 parm
= iucv_param
[smp_processor_id()];
1242 memset(parm
, 0, sizeof(union iucv_param
));
1243 parm
->db
.ippathid
= path
->pathid
;
1244 parm
->db
.ipmsgid
= msg
->id
;
1245 parm
->db
.iptrgcls
= msg
->class;
1246 parm
->db
.ipflags1
= (IUCV_IPTRGCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
);
1247 rc
= iucv_call_b2f0(IUCV_REJECT
, parm
);
1252 EXPORT_SYMBOL(iucv_message_reject
);
1255 * iucv_message_reply
1256 * @path: address of iucv path structure
1257 * @msg: address of iucv msg structure
1258 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1259 * @reply: address of reply data buffer or address of struct iucv_array
1260 * @size: length of reply data buffer
1262 * This function responds to the two-way messages that you receive. You
1263 * must identify completely the message to which you wish to reply. ie,
1264 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1265 * the parameter list.
1267 * Returns the result from the CP IUCV call.
1269 int iucv_message_reply(struct iucv_path
*path
, struct iucv_message
*msg
,
1270 u8 flags
, void *reply
, size_t size
)
1272 union iucv_param
*parm
;
1276 if (cpus_empty(iucv_buffer_cpumask
)) {
1280 parm
= iucv_param
[smp_processor_id()];
1281 memset(parm
, 0, sizeof(union iucv_param
));
1282 if (flags
& IUCV_IPRMDATA
) {
1283 parm
->dpl
.ippathid
= path
->pathid
;
1284 parm
->dpl
.ipflags1
= flags
;
1285 parm
->dpl
.ipmsgid
= msg
->id
;
1286 parm
->dpl
.iptrgcls
= msg
->class;
1287 memcpy(parm
->dpl
.iprmmsg
, reply
, min_t(size_t, size
, 8));
1289 parm
->db
.ipbfadr1
= (u32
)(addr_t
) reply
;
1290 parm
->db
.ipbfln1f
= (u32
) size
;
1291 parm
->db
.ippathid
= path
->pathid
;
1292 parm
->db
.ipflags1
= flags
;
1293 parm
->db
.ipmsgid
= msg
->id
;
1294 parm
->db
.iptrgcls
= msg
->class;
1296 rc
= iucv_call_b2f0(IUCV_REPLY
, parm
);
1301 EXPORT_SYMBOL(iucv_message_reply
);
1304 * __iucv_message_send
1305 * @path: address of iucv path structure
1306 * @msg: address of iucv msg structure
1307 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1308 * @srccls: source class of message
1309 * @buffer: address of send buffer or address of struct iucv_array
1310 * @size: length of send buffer
1312 * This function transmits data to another application. Data to be
1313 * transmitted is in a buffer and this is a one-way message and the
1314 * receiver will not reply to the message.
1316 * Locking: no locking
1318 * Returns the result from the CP IUCV call.
1320 int __iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1321 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1323 union iucv_param
*parm
;
1326 if (cpus_empty(iucv_buffer_cpumask
)) {
1330 parm
= iucv_param
[smp_processor_id()];
1331 memset(parm
, 0, sizeof(union iucv_param
));
1332 if (flags
& IUCV_IPRMDATA
) {
1333 /* Message of 8 bytes can be placed into the parameter list. */
1334 parm
->dpl
.ippathid
= path
->pathid
;
1335 parm
->dpl
.ipflags1
= flags
| IUCV_IPNORPY
;
1336 parm
->dpl
.iptrgcls
= msg
->class;
1337 parm
->dpl
.ipsrccls
= srccls
;
1338 parm
->dpl
.ipmsgtag
= msg
->tag
;
1339 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1341 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1342 parm
->db
.ipbfln1f
= (u32
) size
;
1343 parm
->db
.ippathid
= path
->pathid
;
1344 parm
->db
.ipflags1
= flags
| IUCV_IPNORPY
;
1345 parm
->db
.iptrgcls
= msg
->class;
1346 parm
->db
.ipsrccls
= srccls
;
1347 parm
->db
.ipmsgtag
= msg
->tag
;
1349 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1351 msg
->id
= parm
->db
.ipmsgid
;
1355 EXPORT_SYMBOL(__iucv_message_send
);
1359 * @path: address of iucv path structure
1360 * @msg: address of iucv msg structure
1361 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1362 * @srccls: source class of message
1363 * @buffer: address of send buffer or address of struct iucv_array
1364 * @size: length of send buffer
1366 * This function transmits data to another application. Data to be
1367 * transmitted is in a buffer and this is a one-way message and the
1368 * receiver will not reply to the message.
1370 * Locking: local_bh_enable/local_bh_disable
1372 * Returns the result from the CP IUCV call.
1374 int iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1375 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1380 rc
= __iucv_message_send(path
, msg
, flags
, srccls
, buffer
, size
);
1384 EXPORT_SYMBOL(iucv_message_send
);
1387 * iucv_message_send2way
1388 * @path: address of iucv path structure
1389 * @msg: address of iucv msg structure
1390 * @flags: how the message is sent and the reply is received
1391 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1392 * @srccls: source class of message
1393 * @buffer: address of send buffer or address of struct iucv_array
1394 * @size: length of send buffer
1395 * @ansbuf: address of answer buffer or address of struct iucv_array
1396 * @asize: size of reply buffer
1398 * This function transmits data to another application. Data to be
1399 * transmitted is in a buffer. The receiver of the send is expected to
1400 * reply to the message and a buffer is provided into which IUCV moves
1401 * the reply to this message.
1403 * Returns the result from the CP IUCV call.
1405 int iucv_message_send2way(struct iucv_path
*path
, struct iucv_message
*msg
,
1406 u8 flags
, u32 srccls
, void *buffer
, size_t size
,
1407 void *answer
, size_t asize
, size_t *residual
)
1409 union iucv_param
*parm
;
1413 if (cpus_empty(iucv_buffer_cpumask
)) {
1417 parm
= iucv_param
[smp_processor_id()];
1418 memset(parm
, 0, sizeof(union iucv_param
));
1419 if (flags
& IUCV_IPRMDATA
) {
1420 parm
->dpl
.ippathid
= path
->pathid
;
1421 parm
->dpl
.ipflags1
= path
->flags
; /* priority message */
1422 parm
->dpl
.iptrgcls
= msg
->class;
1423 parm
->dpl
.ipsrccls
= srccls
;
1424 parm
->dpl
.ipmsgtag
= msg
->tag
;
1425 parm
->dpl
.ipbfadr2
= (u32
)(addr_t
) answer
;
1426 parm
->dpl
.ipbfln2f
= (u32
) asize
;
1427 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1429 parm
->db
.ippathid
= path
->pathid
;
1430 parm
->db
.ipflags1
= path
->flags
; /* priority message */
1431 parm
->db
.iptrgcls
= msg
->class;
1432 parm
->db
.ipsrccls
= srccls
;
1433 parm
->db
.ipmsgtag
= msg
->tag
;
1434 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1435 parm
->db
.ipbfln1f
= (u32
) size
;
1436 parm
->db
.ipbfadr2
= (u32
)(addr_t
) answer
;
1437 parm
->db
.ipbfln2f
= (u32
) asize
;
1439 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1441 msg
->id
= parm
->db
.ipmsgid
;
1446 EXPORT_SYMBOL(iucv_message_send2way
);
1450 * @data: Pointer to external interrupt buffer
1452 * Process connection pending work item. Called from tasklet while holding
1455 struct iucv_path_pending
{
1468 static void iucv_path_pending(struct iucv_irq_data
*data
)
1470 struct iucv_path_pending
*ipp
= (void *) data
;
1471 struct iucv_handler
*handler
;
1472 struct iucv_path
*path
;
1475 BUG_ON(iucv_path_table
[ipp
->ippathid
]);
1476 /* New pathid, handler found. Create a new path struct. */
1477 error
= iucv_error_no_memory
;
1478 path
= iucv_path_alloc(ipp
->ipmsglim
, ipp
->ipflags1
, GFP_ATOMIC
);
1481 path
->pathid
= ipp
->ippathid
;
1482 iucv_path_table
[path
->pathid
] = path
;
1483 EBCASC(ipp
->ipvmid
, 8);
1485 /* Call registered handler until one is found that wants the path. */
1486 list_for_each_entry(handler
, &iucv_handler_list
, list
) {
1487 if (!handler
->path_pending
)
1490 * Add path to handler to allow a call to iucv_path_sever
1491 * inside the path_pending function. If the handler returns
1492 * an error remove the path from the handler again.
1494 list_add(&path
->list
, &handler
->paths
);
1495 path
->handler
= handler
;
1496 if (!handler
->path_pending(path
, ipp
->ipvmid
, ipp
->ipuser
))
1498 list_del(&path
->list
);
1499 path
->handler
= NULL
;
1501 /* No handler wanted the path. */
1502 iucv_path_table
[path
->pathid
] = NULL
;
1503 iucv_path_free(path
);
1504 error
= iucv_error_no_listener
;
1506 iucv_sever_pathid(ipp
->ippathid
, error
);
1510 * iucv_path_complete
1511 * @data: Pointer to external interrupt buffer
1513 * Process connection complete work item. Called from tasklet while holding
1516 struct iucv_path_complete
{
1529 static void iucv_path_complete(struct iucv_irq_data
*data
)
1531 struct iucv_path_complete
*ipc
= (void *) data
;
1532 struct iucv_path
*path
= iucv_path_table
[ipc
->ippathid
];
1535 path
->flags
= ipc
->ipflags1
;
1536 if (path
&& path
->handler
&& path
->handler
->path_complete
)
1537 path
->handler
->path_complete(path
, ipc
->ipuser
);
1542 * @data: Pointer to external interrupt buffer
1544 * Process connection severed work item. Called from tasklet while holding
1547 struct iucv_path_severed
{
1559 static void iucv_path_severed(struct iucv_irq_data
*data
)
1561 struct iucv_path_severed
*ips
= (void *) data
;
1562 struct iucv_path
*path
= iucv_path_table
[ips
->ippathid
];
1564 if (!path
|| !path
->handler
) /* Already severed */
1566 if (path
->handler
->path_severed
)
1567 path
->handler
->path_severed(path
, ips
->ipuser
);
1569 iucv_sever_pathid(path
->pathid
, NULL
);
1570 iucv_path_table
[path
->pathid
] = NULL
;
1571 list_del(&path
->list
);
1572 iucv_path_free(path
);
1577 * iucv_path_quiesced
1578 * @data: Pointer to external interrupt buffer
1580 * Process connection quiesced work item. Called from tasklet while holding
1583 struct iucv_path_quiesced
{
1595 static void iucv_path_quiesced(struct iucv_irq_data
*data
)
1597 struct iucv_path_quiesced
*ipq
= (void *) data
;
1598 struct iucv_path
*path
= iucv_path_table
[ipq
->ippathid
];
1600 if (path
&& path
->handler
&& path
->handler
->path_quiesced
)
1601 path
->handler
->path_quiesced(path
, ipq
->ipuser
);
1606 * @data: Pointer to external interrupt buffer
1608 * Process connection resumed work item. Called from tasklet while holding
1611 struct iucv_path_resumed
{
1623 static void iucv_path_resumed(struct iucv_irq_data
*data
)
1625 struct iucv_path_resumed
*ipr
= (void *) data
;
1626 struct iucv_path
*path
= iucv_path_table
[ipr
->ippathid
];
1628 if (path
&& path
->handler
&& path
->handler
->path_resumed
)
1629 path
->handler
->path_resumed(path
, ipr
->ipuser
);
1633 * iucv_message_complete
1634 * @data: Pointer to external interrupt buffer
1636 * Process message complete work item. Called from tasklet while holding
1639 struct iucv_message_complete
{
1654 static void iucv_message_complete(struct iucv_irq_data
*data
)
1656 struct iucv_message_complete
*imc
= (void *) data
;
1657 struct iucv_path
*path
= iucv_path_table
[imc
->ippathid
];
1658 struct iucv_message msg
;
1660 if (path
&& path
->handler
&& path
->handler
->message_complete
) {
1661 msg
.flags
= imc
->ipflags1
;
1662 msg
.id
= imc
->ipmsgid
;
1663 msg
.audit
= imc
->ipaudit
;
1664 memcpy(msg
.rmmsg
, imc
->iprmmsg
, 8);
1665 msg
.class = imc
->ipsrccls
;
1666 msg
.tag
= imc
->ipmsgtag
;
1667 msg
.length
= imc
->ipbfln2f
;
1668 path
->handler
->message_complete(path
, &msg
);
1673 * iucv_message_pending
1674 * @data: Pointer to external interrupt buffer
1676 * Process message pending work item. Called from tasklet while holding
1679 struct iucv_message_pending
{
1699 static void iucv_message_pending(struct iucv_irq_data
*data
)
1701 struct iucv_message_pending
*imp
= (void *) data
;
1702 struct iucv_path
*path
= iucv_path_table
[imp
->ippathid
];
1703 struct iucv_message msg
;
1705 if (path
&& path
->handler
&& path
->handler
->message_pending
) {
1706 msg
.flags
= imp
->ipflags1
;
1707 msg
.id
= imp
->ipmsgid
;
1708 msg
.class = imp
->iptrgcls
;
1709 if (imp
->ipflags1
& IUCV_IPRMDATA
) {
1710 memcpy(msg
.rmmsg
, imp
->ln1msg1
.iprmmsg1
, 8);
1713 msg
.length
= imp
->ln1msg2
.ipbfln1f
;
1714 msg
.reply_size
= imp
->ipbfln2f
;
1715 path
->handler
->message_pending(path
, &msg
);
1722 * This tasklet loops over the queue of irq buffers created by
1723 * iucv_external_interrupt, calls the appropriate action handler
1724 * and then frees the buffer.
1726 static void iucv_tasklet_fn(unsigned long ignored
)
1728 typedef void iucv_irq_fn(struct iucv_irq_data
*);
1729 static iucv_irq_fn
*irq_fn
[] = {
1730 [0x02] = iucv_path_complete
,
1731 [0x03] = iucv_path_severed
,
1732 [0x04] = iucv_path_quiesced
,
1733 [0x05] = iucv_path_resumed
,
1734 [0x06] = iucv_message_complete
,
1735 [0x07] = iucv_message_complete
,
1736 [0x08] = iucv_message_pending
,
1737 [0x09] = iucv_message_pending
,
1739 LIST_HEAD(task_queue
);
1740 struct iucv_irq_list
*p
, *n
;
1742 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1743 if (!spin_trylock(&iucv_table_lock
)) {
1744 tasklet_schedule(&iucv_tasklet
);
1747 iucv_active_cpu
= smp_processor_id();
1749 spin_lock_irq(&iucv_queue_lock
);
1750 list_splice_init(&iucv_task_queue
, &task_queue
);
1751 spin_unlock_irq(&iucv_queue_lock
);
1753 list_for_each_entry_safe(p
, n
, &task_queue
, list
) {
1754 list_del_init(&p
->list
);
1755 irq_fn
[p
->data
.iptype
](&p
->data
);
1759 iucv_active_cpu
= -1;
1760 spin_unlock(&iucv_table_lock
);
1766 * This work function loops over the queue of path pending irq blocks
1767 * created by iucv_external_interrupt, calls the appropriate action
1768 * handler and then frees the buffer.
1770 static void iucv_work_fn(struct work_struct
*work
)
1772 LIST_HEAD(work_queue
);
1773 struct iucv_irq_list
*p
, *n
;
1775 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1776 spin_lock_bh(&iucv_table_lock
);
1777 iucv_active_cpu
= smp_processor_id();
1779 spin_lock_irq(&iucv_queue_lock
);
1780 list_splice_init(&iucv_work_queue
, &work_queue
);
1781 spin_unlock_irq(&iucv_queue_lock
);
1783 iucv_cleanup_queue();
1784 list_for_each_entry_safe(p
, n
, &work_queue
, list
) {
1785 list_del_init(&p
->list
);
1786 iucv_path_pending(&p
->data
);
1790 iucv_active_cpu
= -1;
1791 spin_unlock_bh(&iucv_table_lock
);
1795 * iucv_external_interrupt
1798 * Handles external interrupts coming in from CP.
1799 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1801 static void iucv_external_interrupt(unsigned int ext_int_code
,
1802 unsigned int param32
, unsigned long param64
)
1804 struct iucv_irq_data
*p
;
1805 struct iucv_irq_list
*work
;
1807 p
= iucv_irq_data
[smp_processor_id()];
1808 if (p
->ippathid
>= iucv_max_pathid
) {
1809 WARN_ON(p
->ippathid
>= iucv_max_pathid
);
1810 iucv_sever_pathid(p
->ippathid
, iucv_error_no_listener
);
1813 BUG_ON(p
->iptype
< 0x01 || p
->iptype
> 0x09);
1814 work
= kmalloc(sizeof(struct iucv_irq_list
), GFP_ATOMIC
);
1816 pr_warning("iucv_external_interrupt: out of memory\n");
1819 memcpy(&work
->data
, p
, sizeof(work
->data
));
1820 spin_lock(&iucv_queue_lock
);
1821 if (p
->iptype
== 0x01) {
1822 /* Path pending interrupt. */
1823 list_add_tail(&work
->list
, &iucv_work_queue
);
1824 schedule_work(&iucv_work
);
1826 /* The other interrupts. */
1827 list_add_tail(&work
->list
, &iucv_task_queue
);
1828 tasklet_schedule(&iucv_tasklet
);
1830 spin_unlock(&iucv_queue_lock
);
1833 static int iucv_pm_prepare(struct device
*dev
)
1837 #ifdef CONFIG_PM_DEBUG
1838 printk(KERN_INFO
"iucv_pm_prepare\n");
1840 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->prepare
)
1841 rc
= dev
->driver
->pm
->prepare(dev
);
1845 static void iucv_pm_complete(struct device
*dev
)
1847 #ifdef CONFIG_PM_DEBUG
1848 printk(KERN_INFO
"iucv_pm_complete\n");
1850 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->complete
)
1851 dev
->driver
->pm
->complete(dev
);
1855 * iucv_path_table_empty() - determine if iucv path table is empty
1857 * Returns 0 if there are still iucv pathes defined
1858 * 1 if there are no iucv pathes defined
1860 int iucv_path_table_empty(void)
1864 for (i
= 0; i
< iucv_max_pathid
; i
++) {
1865 if (iucv_path_table
[i
])
1872 * iucv_pm_freeze() - Freeze PM callback
1873 * @dev: iucv-based device
1875 * disable iucv interrupts
1876 * invoke callback function of the iucv-based driver
1877 * shut down iucv, if no iucv-pathes are established anymore
1879 static int iucv_pm_freeze(struct device
*dev
)
1882 struct iucv_irq_list
*p
, *n
;
1885 #ifdef CONFIG_PM_DEBUG
1886 printk(KERN_WARNING
"iucv_pm_freeze\n");
1888 if (iucv_pm_state
!= IUCV_PM_FREEZING
) {
1889 for_each_cpu_mask_nr(cpu
, iucv_irq_cpumask
)
1890 smp_call_function_single(cpu
, iucv_block_cpu_almost
,
1892 cancel_work_sync(&iucv_work
);
1893 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
) {
1894 list_del_init(&p
->list
);
1895 iucv_sever_pathid(p
->data
.ippathid
,
1896 iucv_error_no_listener
);
1900 iucv_pm_state
= IUCV_PM_FREEZING
;
1901 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->freeze
)
1902 rc
= dev
->driver
->pm
->freeze(dev
);
1903 if (iucv_path_table_empty())
1909 * iucv_pm_thaw() - Thaw PM callback
1910 * @dev: iucv-based device
1912 * make iucv ready for use again: allocate path table, declare interrupt buffers
1913 * and enable iucv interrupts
1914 * invoke callback function of the iucv-based driver
1916 static int iucv_pm_thaw(struct device
*dev
)
1920 #ifdef CONFIG_PM_DEBUG
1921 printk(KERN_WARNING
"iucv_pm_thaw\n");
1923 iucv_pm_state
= IUCV_PM_THAWING
;
1924 if (!iucv_path_table
) {
1929 if (cpus_empty(iucv_irq_cpumask
)) {
1930 if (iucv_nonsmp_handler
)
1931 /* enable interrupts on one cpu */
1932 iucv_allow_cpu(NULL
);
1934 /* enable interrupts on all cpus */
1937 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->thaw
)
1938 rc
= dev
->driver
->pm
->thaw(dev
);
1944 * iucv_pm_restore() - Restore PM callback
1945 * @dev: iucv-based device
1947 * make iucv ready for use again: allocate path table, declare interrupt buffers
1948 * and enable iucv interrupts
1949 * invoke callback function of the iucv-based driver
1951 static int iucv_pm_restore(struct device
*dev
)
1955 #ifdef CONFIG_PM_DEBUG
1956 printk(KERN_WARNING
"iucv_pm_restore %p\n", iucv_path_table
);
1958 if ((iucv_pm_state
!= IUCV_PM_RESTORING
) && iucv_path_table
)
1959 pr_warning("Suspending Linux did not completely close all IUCV "
1961 iucv_pm_state
= IUCV_PM_RESTORING
;
1962 if (cpus_empty(iucv_irq_cpumask
)) {
1963 rc
= iucv_query_maxconn();
1968 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->restore
)
1969 rc
= dev
->driver
->pm
->restore(dev
);
1977 * Allocates and initializes various data structures.
1979 static int __init
iucv_init(void)
1984 if (!MACHINE_IS_VM
) {
1985 rc
= -EPROTONOSUPPORT
;
1988 rc
= iucv_query_maxconn();
1991 rc
= register_external_interrupt(0x4000, iucv_external_interrupt
);
1994 iucv_root
= root_device_register("iucv");
1995 if (IS_ERR(iucv_root
)) {
1996 rc
= PTR_ERR(iucv_root
);
2000 for_each_online_cpu(cpu
) {
2001 /* Note: GFP_DMA used to get memory below 2G */
2002 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
2003 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
2004 if (!iucv_irq_data
[cpu
]) {
2009 /* Allocate parameter blocks. */
2010 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
2011 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
2012 if (!iucv_param
[cpu
]) {
2016 iucv_param_irq
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
2017 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
2018 if (!iucv_param_irq
[cpu
]) {
2024 rc
= register_hotcpu_notifier(&iucv_cpu_notifier
);
2027 rc
= register_reboot_notifier(&iucv_reboot_notifier
);
2030 ASCEBC(iucv_error_no_listener
, 16);
2031 ASCEBC(iucv_error_no_memory
, 16);
2032 ASCEBC(iucv_error_pathid
, 16);
2034 rc
= bus_register(&iucv_bus
);
2040 unregister_reboot_notifier(&iucv_reboot_notifier
);
2042 unregister_hotcpu_notifier(&iucv_cpu_notifier
);
2044 for_each_possible_cpu(cpu
) {
2045 kfree(iucv_param_irq
[cpu
]);
2046 iucv_param_irq
[cpu
] = NULL
;
2047 kfree(iucv_param
[cpu
]);
2048 iucv_param
[cpu
] = NULL
;
2049 kfree(iucv_irq_data
[cpu
]);
2050 iucv_irq_data
[cpu
] = NULL
;
2052 root_device_unregister(iucv_root
);
2054 unregister_external_interrupt(0x4000, iucv_external_interrupt
);
2062 * Frees everything allocated from iucv_init.
2064 static void __exit
iucv_exit(void)
2066 struct iucv_irq_list
*p
, *n
;
2069 spin_lock_irq(&iucv_queue_lock
);
2070 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
)
2072 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
)
2074 spin_unlock_irq(&iucv_queue_lock
);
2075 unregister_reboot_notifier(&iucv_reboot_notifier
);
2076 unregister_hotcpu_notifier(&iucv_cpu_notifier
);
2077 for_each_possible_cpu(cpu
) {
2078 kfree(iucv_param_irq
[cpu
]);
2079 iucv_param_irq
[cpu
] = NULL
;
2080 kfree(iucv_param
[cpu
]);
2081 iucv_param
[cpu
] = NULL
;
2082 kfree(iucv_irq_data
[cpu
]);
2083 iucv_irq_data
[cpu
] = NULL
;
2085 root_device_unregister(iucv_root
);
2086 bus_unregister(&iucv_bus
);
2087 unregister_external_interrupt(0x4000, iucv_external_interrupt
);
2090 subsys_initcall(iucv_init
);
2091 module_exit(iucv_exit
);
2093 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
2094 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
2095 MODULE_LICENSE("GPL");