1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IUCV base infrastructure.
5 * Copyright IBM Corp. 2001, 2009
9 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
10 * Xenia Tkatschow (xenia@us.ibm.com)
11 * 2Gb awareness and general cleanup:
12 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
13 * Rewritten for af_iucv:
14 * Martin Schwidefsky <schwidefsky@de.ibm.com>
16 * Ursula Braun (ursula.braun@de.ibm.com)
20 * CP Programming Service, IBM document # SC24-5760
23 #define KMSG_COMPONENT "iucv"
24 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
26 #include <linux/kernel_stat.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/spinlock.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/init.h>
33 #include <linux/interrupt.h>
34 #include <linux/list.h>
35 #include <linux/errno.h>
36 #include <linux/err.h>
37 #include <linux/device.h>
38 #include <linux/cpu.h>
39 #include <linux/reboot.h>
40 #include <net/iucv/iucv.h>
41 #include <linux/atomic.h>
42 #include <asm/ebcdic.h>
49 * All flags are defined in the field IPFLAGS1 of each function
50 * and can be found in CP Programming Services.
51 * IPSRCCLS - Indicates you have specified a source class.
52 * IPTRGCLS - Indicates you have specified a target class.
53 * IPFGPID - Indicates you have specified a pathid.
54 * IPFGMID - Indicates you have specified a message ID.
55 * IPNORPY - Indicates a one-way message. No reply expected.
56 * IPALL - Indicates that all paths are affected.
58 #define IUCV_IPSRCCLS 0x01
59 #define IUCV_IPTRGCLS 0x01
60 #define IUCV_IPFGPID 0x02
61 #define IUCV_IPFGMID 0x04
62 #define IUCV_IPNORPY 0x10
63 #define IUCV_IPALL 0x80
65 static int iucv_bus_match(struct device
*dev
, struct device_driver
*drv
)
74 IUCV_PM_RESTORING
= 3,
76 static enum iucv_pm_states iucv_pm_state
;
78 static int iucv_pm_prepare(struct device
*);
79 static void iucv_pm_complete(struct device
*);
80 static int iucv_pm_freeze(struct device
*);
81 static int iucv_pm_thaw(struct device
*);
82 static int iucv_pm_restore(struct device
*);
84 static const struct dev_pm_ops iucv_pm_ops
= {
85 .prepare
= iucv_pm_prepare
,
86 .complete
= iucv_pm_complete
,
87 .freeze
= iucv_pm_freeze
,
89 .restore
= iucv_pm_restore
,
92 struct bus_type iucv_bus
= {
94 .match
= iucv_bus_match
,
97 EXPORT_SYMBOL(iucv_bus
);
99 struct device
*iucv_root
;
100 EXPORT_SYMBOL(iucv_root
);
102 static int iucv_available
;
104 /* General IUCV interrupt structure */
105 struct iucv_irq_data
{
112 struct iucv_irq_list
{
113 struct list_head list
;
114 struct iucv_irq_data data
;
117 static struct iucv_irq_data
*iucv_irq_data
[NR_CPUS
];
118 static cpumask_t iucv_buffer_cpumask
= { CPU_BITS_NONE
};
119 static cpumask_t iucv_irq_cpumask
= { CPU_BITS_NONE
};
122 * Queue of interrupt buffers lock for delivery via the tasklet
123 * (fast but can't call smp_call_function).
125 static LIST_HEAD(iucv_task_queue
);
128 * The tasklet for fast delivery of iucv interrupts.
130 static void iucv_tasklet_fn(unsigned long);
131 static DECLARE_TASKLET(iucv_tasklet
, iucv_tasklet_fn
,0);
134 * Queue of interrupt buffers for delivery via a work queue
135 * (slower but can call smp_call_function).
137 static LIST_HEAD(iucv_work_queue
);
140 * The work element to deliver path pending interrupts.
142 static void iucv_work_fn(struct work_struct
*work
);
143 static DECLARE_WORK(iucv_work
, iucv_work_fn
);
146 * Spinlock protecting task and work queue.
148 static DEFINE_SPINLOCK(iucv_queue_lock
);
150 enum iucv_command_codes
{
152 IUCV_RETRIEVE_BUFFER
= 2,
160 IUCV_DECLARE_BUFFER
= 12,
165 IUCV_SETCONTROLMASK
= 17,
169 * Error messages that are used with the iucv_sever function. They get
170 * converted to EBCDIC.
172 static char iucv_error_no_listener
[16] = "NO LISTENER";
173 static char iucv_error_no_memory
[16] = "NO MEMORY";
174 static char iucv_error_pathid
[16] = "INVALID PATHID";
177 * iucv_handler_list: List of registered handlers.
179 static LIST_HEAD(iucv_handler_list
);
182 * iucv_path_table: an array of iucv_path structures.
184 static struct iucv_path
**iucv_path_table
;
185 static unsigned long iucv_max_pathid
;
188 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
190 static DEFINE_SPINLOCK(iucv_table_lock
);
193 * iucv_active_cpu: contains the number of the cpu executing the tasklet
194 * or the work handler. Needed for iucv_path_sever called from tasklet.
196 static int iucv_active_cpu
= -1;
199 * Mutex and wait queue for iucv_register/iucv_unregister.
201 static DEFINE_MUTEX(iucv_register_mutex
);
204 * Counter for number of non-smp capable handlers.
206 static int iucv_nonsmp_handler
;
209 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
210 * iucv_path_quiesce and iucv_path_sever.
212 struct iucv_cmd_control
{
221 } __attribute__ ((packed
,aligned(8)));
224 * Data in parameter list iucv structure. Used by iucv_message_send,
225 * iucv_message_send2way and iucv_message_reply.
227 struct iucv_cmd_dpl
{
239 } __attribute__ ((packed
,aligned(8)));
242 * Data in buffer iucv structure. Used by iucv_message_receive,
243 * iucv_message_reject, iucv_message_send, iucv_message_send2way
244 * and iucv_declare_cpu.
259 } __attribute__ ((packed
,aligned(8)));
262 * Purge message iucv structure. Used by iucv_message_purge.
264 struct iucv_cmd_purge
{
275 } __attribute__ ((packed
,aligned(8)));
278 * Set mask iucv structure. Used by iucv_enable_cpu.
280 struct iucv_cmd_set_mask
{
285 } __attribute__ ((packed
,aligned(8)));
288 struct iucv_cmd_control ctrl
;
289 struct iucv_cmd_dpl dpl
;
290 struct iucv_cmd_db db
;
291 struct iucv_cmd_purge purge
;
292 struct iucv_cmd_set_mask set_mask
;
296 * Anchor for per-cpu IUCV command parameter block.
298 static union iucv_param
*iucv_param
[NR_CPUS
];
299 static union iucv_param
*iucv_param_irq
[NR_CPUS
];
303 * @code: identifier of IUCV call to CP.
304 * @parm: pointer to a struct iucv_parm block
306 * Calls CP to execute IUCV commands.
308 * Returns the result of the CP IUCV call.
310 static inline int __iucv_call_b2f0(int command
, union iucv_param
*parm
)
312 register unsigned long reg0
asm ("0");
313 register unsigned long reg1
asm ("1");
317 reg1
= (unsigned long)parm
;
319 " .long 0xb2f01000\n"
322 : "=d" (ccode
), "=m" (*parm
), "+d" (reg0
), "+a" (reg1
)
323 : "m" (*parm
) : "cc");
327 static inline int iucv_call_b2f0(int command
, union iucv_param
*parm
)
331 ccode
= __iucv_call_b2f0(command
, parm
);
332 return ccode
== 1 ? parm
->ctrl
.iprcode
: ccode
;
338 * Determines the maximum number of connections that may be established.
340 * Returns the maximum number of connections or -EPERM is IUCV is not
343 static int __iucv_query_maxconn(void *param
, unsigned long *max_pathid
)
345 register unsigned long reg0
asm ("0");
346 register unsigned long reg1
asm ("1");
350 reg1
= (unsigned long) param
;
352 " .long 0xb2f01000\n"
355 : "=d" (ccode
), "+d" (reg0
), "+d" (reg1
) : : "cc");
360 static int iucv_query_maxconn(void)
362 unsigned long max_pathid
;
366 param
= kzalloc(sizeof(union iucv_param
), GFP_KERNEL
| GFP_DMA
);
369 ccode
= __iucv_query_maxconn(param
, &max_pathid
);
371 iucv_max_pathid
= max_pathid
;
373 return ccode
? -EPERM
: 0;
380 * Allow iucv interrupts on this cpu.
382 static void iucv_allow_cpu(void *data
)
384 int cpu
= smp_processor_id();
385 union iucv_param
*parm
;
388 * Enable all iucv interrupts.
389 * ipmask contains bits for the different interrupts
390 * 0x80 - Flag to allow nonpriority message pending interrupts
391 * 0x40 - Flag to allow priority message pending interrupts
392 * 0x20 - Flag to allow nonpriority message completion interrupts
393 * 0x10 - Flag to allow priority message completion interrupts
394 * 0x08 - Flag to allow IUCV control interrupts
396 parm
= iucv_param_irq
[cpu
];
397 memset(parm
, 0, sizeof(union iucv_param
));
398 parm
->set_mask
.ipmask
= 0xf8;
399 iucv_call_b2f0(IUCV_SETMASK
, parm
);
402 * Enable all iucv control interrupts.
403 * ipmask contains bits for the different interrupts
404 * 0x80 - Flag to allow pending connections interrupts
405 * 0x40 - Flag to allow connection complete interrupts
406 * 0x20 - Flag to allow connection severed interrupts
407 * 0x10 - Flag to allow connection quiesced interrupts
408 * 0x08 - Flag to allow connection resumed interrupts
410 memset(parm
, 0, sizeof(union iucv_param
));
411 parm
->set_mask
.ipmask
= 0xf8;
412 iucv_call_b2f0(IUCV_SETCONTROLMASK
, parm
);
413 /* Set indication that iucv interrupts are allowed for this cpu. */
414 cpumask_set_cpu(cpu
, &iucv_irq_cpumask
);
421 * Block iucv interrupts on this cpu.
423 static void iucv_block_cpu(void *data
)
425 int cpu
= smp_processor_id();
426 union iucv_param
*parm
;
428 /* Disable all iucv interrupts. */
429 parm
= iucv_param_irq
[cpu
];
430 memset(parm
, 0, sizeof(union iucv_param
));
431 iucv_call_b2f0(IUCV_SETMASK
, parm
);
433 /* Clear indication that iucv interrupts are allowed for this cpu. */
434 cpumask_clear_cpu(cpu
, &iucv_irq_cpumask
);
438 * iucv_block_cpu_almost
441 * Allow connection-severed interrupts only on this cpu.
443 static void iucv_block_cpu_almost(void *data
)
445 int cpu
= smp_processor_id();
446 union iucv_param
*parm
;
448 /* Allow iucv control interrupts only */
449 parm
= iucv_param_irq
[cpu
];
450 memset(parm
, 0, sizeof(union iucv_param
));
451 parm
->set_mask
.ipmask
= 0x08;
452 iucv_call_b2f0(IUCV_SETMASK
, parm
);
453 /* Allow iucv-severed interrupt only */
454 memset(parm
, 0, sizeof(union iucv_param
));
455 parm
->set_mask
.ipmask
= 0x20;
456 iucv_call_b2f0(IUCV_SETCONTROLMASK
, parm
);
458 /* Clear indication that iucv interrupts are allowed for this cpu. */
459 cpumask_clear_cpu(cpu
, &iucv_irq_cpumask
);
466 * Declare a interrupt buffer on this cpu.
468 static void iucv_declare_cpu(void *data
)
470 int cpu
= smp_processor_id();
471 union iucv_param
*parm
;
474 if (cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
))
477 /* Declare interrupt buffer. */
478 parm
= iucv_param_irq
[cpu
];
479 memset(parm
, 0, sizeof(union iucv_param
));
480 parm
->db
.ipbfadr1
= virt_to_phys(iucv_irq_data
[cpu
]);
481 rc
= iucv_call_b2f0(IUCV_DECLARE_BUFFER
, parm
);
483 char *err
= "Unknown";
486 err
= "Directory error";
489 err
= "Invalid length";
492 err
= "Buffer already exists";
495 err
= "Buffer overlap";
498 err
= "Paging or storage error";
501 pr_warn("Defining an interrupt buffer on CPU %i failed with 0x%02x (%s)\n",
506 /* Set indication that an iucv buffer exists for this cpu. */
507 cpumask_set_cpu(cpu
, &iucv_buffer_cpumask
);
509 if (iucv_nonsmp_handler
== 0 || cpumask_empty(&iucv_irq_cpumask
))
510 /* Enable iucv interrupts on this cpu. */
511 iucv_allow_cpu(NULL
);
513 /* Disable iucv interrupts on this cpu. */
514 iucv_block_cpu(NULL
);
521 * Retrieve interrupt buffer on this cpu.
523 static void iucv_retrieve_cpu(void *data
)
525 int cpu
= smp_processor_id();
526 union iucv_param
*parm
;
528 if (!cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
))
531 /* Block iucv interrupts. */
532 iucv_block_cpu(NULL
);
534 /* Retrieve interrupt buffer. */
535 parm
= iucv_param_irq
[cpu
];
536 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER
, parm
);
538 /* Clear indication that an iucv buffer exists for this cpu. */
539 cpumask_clear_cpu(cpu
, &iucv_buffer_cpumask
);
545 * Allow iucv interrupts on all cpus.
547 static void iucv_setmask_mp(void)
552 for_each_online_cpu(cpu
)
553 /* Enable all cpus with a declared buffer. */
554 if (cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
) &&
555 !cpumask_test_cpu(cpu
, &iucv_irq_cpumask
))
556 smp_call_function_single(cpu
, iucv_allow_cpu
,
564 * Allow iucv interrupts on a single cpu.
566 static void iucv_setmask_up(void)
571 /* Disable all cpu but the first in cpu_irq_cpumask. */
572 cpumask_copy(&cpumask
, &iucv_irq_cpumask
);
573 cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask
), &cpumask
);
574 for_each_cpu(cpu
, &cpumask
)
575 smp_call_function_single(cpu
, iucv_block_cpu
, NULL
, 1);
581 * This function makes iucv ready for use. It allocates the pathid
582 * table, declares an iucv interrupt buffer and enables the iucv
583 * interrupts. Called when the first user has registered an iucv
586 static int iucv_enable(void)
593 alloc_size
= iucv_max_pathid
* sizeof(struct iucv_path
);
594 iucv_path_table
= kzalloc(alloc_size
, GFP_KERNEL
);
595 if (!iucv_path_table
)
597 /* Declare per cpu buffers. */
599 for_each_online_cpu(cpu
)
600 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
601 if (cpumask_empty(&iucv_buffer_cpumask
))
602 /* No cpu could declare an iucv buffer. */
607 kfree(iucv_path_table
);
608 iucv_path_table
= NULL
;
616 * This function shuts down iucv. It disables iucv interrupts, retrieves
617 * the iucv interrupt buffer and frees the pathid table. Called after the
618 * last user unregister its iucv handler.
620 static void iucv_disable(void)
623 on_each_cpu(iucv_retrieve_cpu
, NULL
, 1);
624 kfree(iucv_path_table
);
625 iucv_path_table
= NULL
;
629 static int iucv_cpu_dead(unsigned int cpu
)
631 kfree(iucv_param_irq
[cpu
]);
632 iucv_param_irq
[cpu
] = NULL
;
633 kfree(iucv_param
[cpu
]);
634 iucv_param
[cpu
] = NULL
;
635 kfree(iucv_irq_data
[cpu
]);
636 iucv_irq_data
[cpu
] = NULL
;
640 static int iucv_cpu_prepare(unsigned int cpu
)
642 /* Note: GFP_DMA used to get memory below 2G */
643 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
644 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
645 if (!iucv_irq_data
[cpu
])
648 /* Allocate parameter blocks. */
649 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
650 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
651 if (!iucv_param
[cpu
])
654 iucv_param_irq
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
655 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
656 if (!iucv_param_irq
[cpu
])
666 static int iucv_cpu_online(unsigned int cpu
)
668 if (!iucv_path_table
)
670 iucv_declare_cpu(NULL
);
674 static int iucv_cpu_down_prep(unsigned int cpu
)
678 if (!iucv_path_table
)
681 cpumask_copy(&cpumask
, &iucv_buffer_cpumask
);
682 cpumask_clear_cpu(cpu
, &cpumask
);
683 if (cpumask_empty(&cpumask
))
684 /* Can't offline last IUCV enabled cpu. */
687 iucv_retrieve_cpu(NULL
);
688 if (!cpumask_empty(&iucv_irq_cpumask
))
690 smp_call_function_single(cpumask_first(&iucv_buffer_cpumask
),
691 iucv_allow_cpu
, NULL
, 1);
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
)
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 immediately
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 referring 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
)
832 if (cpumask_empty(&iucv_irq_cpumask
))
836 on_each_cpu_mask(&iucv_irq_cpumask
, iucv_block_cpu
, NULL
, 1);
838 for (i
= 0; i
< iucv_max_pathid
; i
++) {
839 if (iucv_path_table
[i
])
840 iucv_sever_pathid(i
, NULL
);
848 static struct notifier_block iucv_reboot_notifier
= {
849 .notifier_call
= iucv_reboot_event
,
854 * @path: address of iucv path structure
855 * @handler: address of iucv handler structure
856 * @userdata: 16 bytes of data reflected to the communication partner
857 * @private: private data passed to interrupt handlers for this path
859 * This function is issued after the user received a connection pending
860 * external interrupt and now wishes to complete the IUCV communication path.
862 * Returns the result of the CP IUCV call.
864 int iucv_path_accept(struct iucv_path
*path
, struct iucv_handler
*handler
,
865 u8
*userdata
, void *private)
867 union iucv_param
*parm
;
871 if (cpumask_empty(&iucv_buffer_cpumask
)) {
875 /* Prepare parameter block. */
876 parm
= iucv_param
[smp_processor_id()];
877 memset(parm
, 0, sizeof(union iucv_param
));
878 parm
->ctrl
.ippathid
= path
->pathid
;
879 parm
->ctrl
.ipmsglim
= path
->msglim
;
881 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
882 parm
->ctrl
.ipflags1
= path
->flags
;
884 rc
= iucv_call_b2f0(IUCV_ACCEPT
, parm
);
886 path
->private = private;
887 path
->msglim
= parm
->ctrl
.ipmsglim
;
888 path
->flags
= parm
->ctrl
.ipflags1
;
894 EXPORT_SYMBOL(iucv_path_accept
);
898 * @path: address of iucv path structure
899 * @handler: address of iucv handler structure
900 * @userid: 8-byte user identification
901 * @system: 8-byte target system identification
902 * @userdata: 16 bytes of data reflected to the communication partner
903 * @private: private data passed to interrupt handlers for this path
905 * This function establishes an IUCV path. Although the connect may complete
906 * successfully, you are not able to use the path until you receive an IUCV
907 * Connection Complete external interrupt.
909 * Returns the result of the CP IUCV call.
911 int iucv_path_connect(struct iucv_path
*path
, struct iucv_handler
*handler
,
912 u8
*userid
, u8
*system
, u8
*userdata
,
915 union iucv_param
*parm
;
918 spin_lock_bh(&iucv_table_lock
);
919 iucv_cleanup_queue();
920 if (cpumask_empty(&iucv_buffer_cpumask
)) {
924 parm
= iucv_param
[smp_processor_id()];
925 memset(parm
, 0, sizeof(union iucv_param
));
926 parm
->ctrl
.ipmsglim
= path
->msglim
;
927 parm
->ctrl
.ipflags1
= path
->flags
;
929 memcpy(parm
->ctrl
.ipvmid
, userid
, sizeof(parm
->ctrl
.ipvmid
));
930 ASCEBC(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
931 EBC_TOUPPER(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
934 memcpy(parm
->ctrl
.iptarget
, system
,
935 sizeof(parm
->ctrl
.iptarget
));
936 ASCEBC(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
937 EBC_TOUPPER(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
940 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
942 rc
= iucv_call_b2f0(IUCV_CONNECT
, parm
);
944 if (parm
->ctrl
.ippathid
< iucv_max_pathid
) {
945 path
->pathid
= parm
->ctrl
.ippathid
;
946 path
->msglim
= parm
->ctrl
.ipmsglim
;
947 path
->flags
= parm
->ctrl
.ipflags1
;
948 path
->handler
= handler
;
949 path
->private = private;
950 list_add_tail(&path
->list
, &handler
->paths
);
951 iucv_path_table
[path
->pathid
] = path
;
953 iucv_sever_pathid(parm
->ctrl
.ippathid
,
959 spin_unlock_bh(&iucv_table_lock
);
962 EXPORT_SYMBOL(iucv_path_connect
);
966 * @path: address of iucv path structure
967 * @userdata: 16 bytes of data reflected to the communication partner
969 * This function temporarily suspends incoming messages on an IUCV path.
970 * You can later reactivate the path by invoking the iucv_resume function.
972 * Returns the result from the CP IUCV call.
974 int iucv_path_quiesce(struct iucv_path
*path
, u8
*userdata
)
976 union iucv_param
*parm
;
980 if (cpumask_empty(&iucv_buffer_cpumask
)) {
984 parm
= iucv_param
[smp_processor_id()];
985 memset(parm
, 0, sizeof(union iucv_param
));
987 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
988 parm
->ctrl
.ippathid
= path
->pathid
;
989 rc
= iucv_call_b2f0(IUCV_QUIESCE
, parm
);
994 EXPORT_SYMBOL(iucv_path_quiesce
);
998 * @path: address of iucv path structure
999 * @userdata: 16 bytes of data reflected to the communication partner
1001 * This function resumes incoming messages on an IUCV path that has
1002 * been stopped with iucv_path_quiesce.
1004 * Returns the result from the CP IUCV call.
1006 int iucv_path_resume(struct iucv_path
*path
, u8
*userdata
)
1008 union iucv_param
*parm
;
1012 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1016 parm
= iucv_param
[smp_processor_id()];
1017 memset(parm
, 0, sizeof(union iucv_param
));
1019 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
1020 parm
->ctrl
.ippathid
= path
->pathid
;
1021 rc
= iucv_call_b2f0(IUCV_RESUME
, parm
);
1029 * @path: address of iucv path structure
1030 * @userdata: 16 bytes of data reflected to the communication partner
1032 * This function terminates an IUCV path.
1034 * Returns the result from the CP IUCV call.
1036 int iucv_path_sever(struct iucv_path
*path
, u8
*userdata
)
1041 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1045 if (iucv_active_cpu
!= smp_processor_id())
1046 spin_lock_bh(&iucv_table_lock
);
1047 rc
= iucv_sever_pathid(path
->pathid
, userdata
);
1048 iucv_path_table
[path
->pathid
] = NULL
;
1049 list_del_init(&path
->list
);
1050 if (iucv_active_cpu
!= smp_processor_id())
1051 spin_unlock_bh(&iucv_table_lock
);
1056 EXPORT_SYMBOL(iucv_path_sever
);
1059 * iucv_message_purge
1060 * @path: address of iucv path structure
1061 * @msg: address of iucv msg structure
1062 * @srccls: source class of message
1064 * Cancels a message you have sent.
1066 * Returns the result from the CP IUCV call.
1068 int iucv_message_purge(struct iucv_path
*path
, struct iucv_message
*msg
,
1071 union iucv_param
*parm
;
1075 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1079 parm
= iucv_param
[smp_processor_id()];
1080 memset(parm
, 0, sizeof(union iucv_param
));
1081 parm
->purge
.ippathid
= path
->pathid
;
1082 parm
->purge
.ipmsgid
= msg
->id
;
1083 parm
->purge
.ipsrccls
= srccls
;
1084 parm
->purge
.ipflags1
= IUCV_IPSRCCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
;
1085 rc
= iucv_call_b2f0(IUCV_PURGE
, parm
);
1087 msg
->audit
= (*(u32
*) &parm
->purge
.ipaudit
) >> 8;
1088 msg
->tag
= parm
->purge
.ipmsgtag
;
1094 EXPORT_SYMBOL(iucv_message_purge
);
1097 * iucv_message_receive_iprmdata
1098 * @path: address of iucv path structure
1099 * @msg: address of iucv msg structure
1100 * @flags: how the message is received (IUCV_IPBUFLST)
1101 * @buffer: address of data buffer or address of struct iucv_array
1102 * @size: length of data buffer
1105 * Internal function used by iucv_message_receive and __iucv_message_receive
1106 * to receive RMDATA data stored in struct iucv_message.
1108 static int iucv_message_receive_iprmdata(struct iucv_path
*path
,
1109 struct iucv_message
*msg
,
1110 u8 flags
, void *buffer
,
1111 size_t size
, size_t *residual
)
1113 struct iucv_array
*array
;
1118 * Message is 8 bytes long and has been stored to the
1119 * message descriptor itself.
1122 *residual
= abs(size
- 8);
1124 if (flags
& IUCV_IPBUFLST
) {
1125 /* Copy to struct iucv_array. */
1126 size
= (size
< 8) ? size
: 8;
1127 for (array
= buffer
; size
> 0; array
++) {
1128 copy
= min_t(size_t, size
, array
->length
);
1129 memcpy((u8
*)(addr_t
) array
->address
,
1135 /* Copy to direct buffer. */
1136 memcpy(buffer
, rmmsg
, min_t(size_t, size
, 8));
1142 * __iucv_message_receive
1143 * @path: address of iucv path structure
1144 * @msg: address of iucv msg structure
1145 * @flags: how the message is received (IUCV_IPBUFLST)
1146 * @buffer: address of data buffer or address of struct iucv_array
1147 * @size: length of data buffer
1150 * This function receives messages that are being sent to you over
1151 * established paths. This function will deal with RMDATA messages
1152 * embedded in struct iucv_message as well.
1154 * Locking: no locking
1156 * Returns the result from the CP IUCV call.
1158 int __iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1159 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1161 union iucv_param
*parm
;
1164 if (msg
->flags
& IUCV_IPRMDATA
)
1165 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1166 buffer
, size
, residual
);
1167 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1171 parm
= iucv_param
[smp_processor_id()];
1172 memset(parm
, 0, sizeof(union iucv_param
));
1173 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1174 parm
->db
.ipbfln1f
= (u32
) size
;
1175 parm
->db
.ipmsgid
= msg
->id
;
1176 parm
->db
.ippathid
= path
->pathid
;
1177 parm
->db
.iptrgcls
= msg
->class;
1178 parm
->db
.ipflags1
= (flags
| IUCV_IPFGPID
|
1179 IUCV_IPFGMID
| IUCV_IPTRGCLS
);
1180 rc
= iucv_call_b2f0(IUCV_RECEIVE
, parm
);
1181 if (!rc
|| rc
== 5) {
1182 msg
->flags
= parm
->db
.ipflags1
;
1184 *residual
= parm
->db
.ipbfln1f
;
1189 EXPORT_SYMBOL(__iucv_message_receive
);
1192 * iucv_message_receive
1193 * @path: address of iucv path structure
1194 * @msg: address of iucv msg structure
1195 * @flags: how the message is received (IUCV_IPBUFLST)
1196 * @buffer: address of data buffer or address of struct iucv_array
1197 * @size: length of data buffer
1200 * This function receives messages that are being sent to you over
1201 * established paths. This function will deal with RMDATA messages
1202 * embedded in struct iucv_message as well.
1204 * Locking: local_bh_enable/local_bh_disable
1206 * Returns the result from the CP IUCV call.
1208 int iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1209 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1213 if (msg
->flags
& IUCV_IPRMDATA
)
1214 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1215 buffer
, size
, residual
);
1217 rc
= __iucv_message_receive(path
, msg
, flags
, buffer
, size
, residual
);
1221 EXPORT_SYMBOL(iucv_message_receive
);
1224 * iucv_message_reject
1225 * @path: address of iucv path structure
1226 * @msg: address of iucv msg structure
1228 * The reject function refuses a specified message. Between the time you
1229 * are notified of a message and the time that you complete the message,
1230 * the message may be rejected.
1232 * Returns the result from the CP IUCV call.
1234 int iucv_message_reject(struct iucv_path
*path
, struct iucv_message
*msg
)
1236 union iucv_param
*parm
;
1240 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1244 parm
= iucv_param
[smp_processor_id()];
1245 memset(parm
, 0, sizeof(union iucv_param
));
1246 parm
->db
.ippathid
= path
->pathid
;
1247 parm
->db
.ipmsgid
= msg
->id
;
1248 parm
->db
.iptrgcls
= msg
->class;
1249 parm
->db
.ipflags1
= (IUCV_IPTRGCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
);
1250 rc
= iucv_call_b2f0(IUCV_REJECT
, parm
);
1255 EXPORT_SYMBOL(iucv_message_reject
);
1258 * iucv_message_reply
1259 * @path: address of iucv path structure
1260 * @msg: address of iucv msg structure
1261 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1262 * @reply: address of reply data buffer or address of struct iucv_array
1263 * @size: length of reply data buffer
1265 * This function responds to the two-way messages that you receive. You
1266 * must identify completely the message to which you wish to reply. ie,
1267 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1268 * the parameter list.
1270 * Returns the result from the CP IUCV call.
1272 int iucv_message_reply(struct iucv_path
*path
, struct iucv_message
*msg
,
1273 u8 flags
, void *reply
, size_t size
)
1275 union iucv_param
*parm
;
1279 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1283 parm
= iucv_param
[smp_processor_id()];
1284 memset(parm
, 0, sizeof(union iucv_param
));
1285 if (flags
& IUCV_IPRMDATA
) {
1286 parm
->dpl
.ippathid
= path
->pathid
;
1287 parm
->dpl
.ipflags1
= flags
;
1288 parm
->dpl
.ipmsgid
= msg
->id
;
1289 parm
->dpl
.iptrgcls
= msg
->class;
1290 memcpy(parm
->dpl
.iprmmsg
, reply
, min_t(size_t, size
, 8));
1292 parm
->db
.ipbfadr1
= (u32
)(addr_t
) reply
;
1293 parm
->db
.ipbfln1f
= (u32
) size
;
1294 parm
->db
.ippathid
= path
->pathid
;
1295 parm
->db
.ipflags1
= flags
;
1296 parm
->db
.ipmsgid
= msg
->id
;
1297 parm
->db
.iptrgcls
= msg
->class;
1299 rc
= iucv_call_b2f0(IUCV_REPLY
, parm
);
1304 EXPORT_SYMBOL(iucv_message_reply
);
1307 * __iucv_message_send
1308 * @path: address of iucv path structure
1309 * @msg: address of iucv msg structure
1310 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1311 * @srccls: source class of message
1312 * @buffer: address of send buffer or address of struct iucv_array
1313 * @size: length of send buffer
1315 * This function transmits data to another application. Data to be
1316 * transmitted is in a buffer and this is a one-way message and the
1317 * receiver will not reply to the message.
1319 * Locking: no locking
1321 * Returns the result from the CP IUCV call.
1323 int __iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1324 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1326 union iucv_param
*parm
;
1329 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1333 parm
= iucv_param
[smp_processor_id()];
1334 memset(parm
, 0, sizeof(union iucv_param
));
1335 if (flags
& IUCV_IPRMDATA
) {
1336 /* Message of 8 bytes can be placed into the parameter list. */
1337 parm
->dpl
.ippathid
= path
->pathid
;
1338 parm
->dpl
.ipflags1
= flags
| IUCV_IPNORPY
;
1339 parm
->dpl
.iptrgcls
= msg
->class;
1340 parm
->dpl
.ipsrccls
= srccls
;
1341 parm
->dpl
.ipmsgtag
= msg
->tag
;
1342 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1344 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1345 parm
->db
.ipbfln1f
= (u32
) size
;
1346 parm
->db
.ippathid
= path
->pathid
;
1347 parm
->db
.ipflags1
= flags
| IUCV_IPNORPY
;
1348 parm
->db
.iptrgcls
= msg
->class;
1349 parm
->db
.ipsrccls
= srccls
;
1350 parm
->db
.ipmsgtag
= msg
->tag
;
1352 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1354 msg
->id
= parm
->db
.ipmsgid
;
1358 EXPORT_SYMBOL(__iucv_message_send
);
1362 * @path: address of iucv path structure
1363 * @msg: address of iucv msg structure
1364 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1365 * @srccls: source class of message
1366 * @buffer: address of send buffer or address of struct iucv_array
1367 * @size: length of send buffer
1369 * This function transmits data to another application. Data to be
1370 * transmitted is in a buffer and this is a one-way message and the
1371 * receiver will not reply to the message.
1373 * Locking: local_bh_enable/local_bh_disable
1375 * Returns the result from the CP IUCV call.
1377 int iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1378 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1383 rc
= __iucv_message_send(path
, msg
, flags
, srccls
, buffer
, size
);
1387 EXPORT_SYMBOL(iucv_message_send
);
1390 * iucv_message_send2way
1391 * @path: address of iucv path structure
1392 * @msg: address of iucv msg structure
1393 * @flags: how the message is sent and the reply is received
1394 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1395 * @srccls: source class of message
1396 * @buffer: address of send buffer or address of struct iucv_array
1397 * @size: length of send buffer
1398 * @ansbuf: address of answer buffer or address of struct iucv_array
1399 * @asize: size of reply buffer
1401 * This function transmits data to another application. Data to be
1402 * transmitted is in a buffer. The receiver of the send is expected to
1403 * reply to the message and a buffer is provided into which IUCV moves
1404 * the reply to this message.
1406 * Returns the result from the CP IUCV call.
1408 int iucv_message_send2way(struct iucv_path
*path
, struct iucv_message
*msg
,
1409 u8 flags
, u32 srccls
, void *buffer
, size_t size
,
1410 void *answer
, size_t asize
, size_t *residual
)
1412 union iucv_param
*parm
;
1416 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1420 parm
= iucv_param
[smp_processor_id()];
1421 memset(parm
, 0, sizeof(union iucv_param
));
1422 if (flags
& IUCV_IPRMDATA
) {
1423 parm
->dpl
.ippathid
= path
->pathid
;
1424 parm
->dpl
.ipflags1
= path
->flags
; /* priority message */
1425 parm
->dpl
.iptrgcls
= msg
->class;
1426 parm
->dpl
.ipsrccls
= srccls
;
1427 parm
->dpl
.ipmsgtag
= msg
->tag
;
1428 parm
->dpl
.ipbfadr2
= (u32
)(addr_t
) answer
;
1429 parm
->dpl
.ipbfln2f
= (u32
) asize
;
1430 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1432 parm
->db
.ippathid
= path
->pathid
;
1433 parm
->db
.ipflags1
= path
->flags
; /* priority message */
1434 parm
->db
.iptrgcls
= msg
->class;
1435 parm
->db
.ipsrccls
= srccls
;
1436 parm
->db
.ipmsgtag
= msg
->tag
;
1437 parm
->db
.ipbfadr1
= (u32
)(addr_t
) buffer
;
1438 parm
->db
.ipbfln1f
= (u32
) size
;
1439 parm
->db
.ipbfadr2
= (u32
)(addr_t
) answer
;
1440 parm
->db
.ipbfln2f
= (u32
) asize
;
1442 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1444 msg
->id
= parm
->db
.ipmsgid
;
1449 EXPORT_SYMBOL(iucv_message_send2way
);
1453 * @data: Pointer to external interrupt buffer
1455 * Process connection pending work item. Called from tasklet while holding
1458 struct iucv_path_pending
{
1471 static void iucv_path_pending(struct iucv_irq_data
*data
)
1473 struct iucv_path_pending
*ipp
= (void *) data
;
1474 struct iucv_handler
*handler
;
1475 struct iucv_path
*path
;
1478 BUG_ON(iucv_path_table
[ipp
->ippathid
]);
1479 /* New pathid, handler found. Create a new path struct. */
1480 error
= iucv_error_no_memory
;
1481 path
= iucv_path_alloc(ipp
->ipmsglim
, ipp
->ipflags1
, GFP_ATOMIC
);
1484 path
->pathid
= ipp
->ippathid
;
1485 iucv_path_table
[path
->pathid
] = path
;
1486 EBCASC(ipp
->ipvmid
, 8);
1488 /* Call registered handler until one is found that wants the path. */
1489 list_for_each_entry(handler
, &iucv_handler_list
, list
) {
1490 if (!handler
->path_pending
)
1493 * Add path to handler to allow a call to iucv_path_sever
1494 * inside the path_pending function. If the handler returns
1495 * an error remove the path from the handler again.
1497 list_add(&path
->list
, &handler
->paths
);
1498 path
->handler
= handler
;
1499 if (!handler
->path_pending(path
, ipp
->ipvmid
, ipp
->ipuser
))
1501 list_del(&path
->list
);
1502 path
->handler
= NULL
;
1504 /* No handler wanted the path. */
1505 iucv_path_table
[path
->pathid
] = NULL
;
1506 iucv_path_free(path
);
1507 error
= iucv_error_no_listener
;
1509 iucv_sever_pathid(ipp
->ippathid
, error
);
1513 * iucv_path_complete
1514 * @data: Pointer to external interrupt buffer
1516 * Process connection complete work item. Called from tasklet while holding
1519 struct iucv_path_complete
{
1532 static void iucv_path_complete(struct iucv_irq_data
*data
)
1534 struct iucv_path_complete
*ipc
= (void *) data
;
1535 struct iucv_path
*path
= iucv_path_table
[ipc
->ippathid
];
1538 path
->flags
= ipc
->ipflags1
;
1539 if (path
&& path
->handler
&& path
->handler
->path_complete
)
1540 path
->handler
->path_complete(path
, ipc
->ipuser
);
1545 * @data: Pointer to external interrupt buffer
1547 * Process connection severed work item. Called from tasklet while holding
1550 struct iucv_path_severed
{
1562 static void iucv_path_severed(struct iucv_irq_data
*data
)
1564 struct iucv_path_severed
*ips
= (void *) data
;
1565 struct iucv_path
*path
= iucv_path_table
[ips
->ippathid
];
1567 if (!path
|| !path
->handler
) /* Already severed */
1569 if (path
->handler
->path_severed
)
1570 path
->handler
->path_severed(path
, ips
->ipuser
);
1572 iucv_sever_pathid(path
->pathid
, NULL
);
1573 iucv_path_table
[path
->pathid
] = NULL
;
1574 list_del(&path
->list
);
1575 iucv_path_free(path
);
1580 * iucv_path_quiesced
1581 * @data: Pointer to external interrupt buffer
1583 * Process connection quiesced work item. Called from tasklet while holding
1586 struct iucv_path_quiesced
{
1598 static void iucv_path_quiesced(struct iucv_irq_data
*data
)
1600 struct iucv_path_quiesced
*ipq
= (void *) data
;
1601 struct iucv_path
*path
= iucv_path_table
[ipq
->ippathid
];
1603 if (path
&& path
->handler
&& path
->handler
->path_quiesced
)
1604 path
->handler
->path_quiesced(path
, ipq
->ipuser
);
1609 * @data: Pointer to external interrupt buffer
1611 * Process connection resumed work item. Called from tasklet while holding
1614 struct iucv_path_resumed
{
1626 static void iucv_path_resumed(struct iucv_irq_data
*data
)
1628 struct iucv_path_resumed
*ipr
= (void *) data
;
1629 struct iucv_path
*path
= iucv_path_table
[ipr
->ippathid
];
1631 if (path
&& path
->handler
&& path
->handler
->path_resumed
)
1632 path
->handler
->path_resumed(path
, ipr
->ipuser
);
1636 * iucv_message_complete
1637 * @data: Pointer to external interrupt buffer
1639 * Process message complete work item. Called from tasklet while holding
1642 struct iucv_message_complete
{
1657 static void iucv_message_complete(struct iucv_irq_data
*data
)
1659 struct iucv_message_complete
*imc
= (void *) data
;
1660 struct iucv_path
*path
= iucv_path_table
[imc
->ippathid
];
1661 struct iucv_message msg
;
1663 if (path
&& path
->handler
&& path
->handler
->message_complete
) {
1664 msg
.flags
= imc
->ipflags1
;
1665 msg
.id
= imc
->ipmsgid
;
1666 msg
.audit
= imc
->ipaudit
;
1667 memcpy(msg
.rmmsg
, imc
->iprmmsg
, 8);
1668 msg
.class = imc
->ipsrccls
;
1669 msg
.tag
= imc
->ipmsgtag
;
1670 msg
.length
= imc
->ipbfln2f
;
1671 path
->handler
->message_complete(path
, &msg
);
1676 * iucv_message_pending
1677 * @data: Pointer to external interrupt buffer
1679 * Process message pending work item. Called from tasklet while holding
1682 struct iucv_message_pending
{
1702 static void iucv_message_pending(struct iucv_irq_data
*data
)
1704 struct iucv_message_pending
*imp
= (void *) data
;
1705 struct iucv_path
*path
= iucv_path_table
[imp
->ippathid
];
1706 struct iucv_message msg
;
1708 if (path
&& path
->handler
&& path
->handler
->message_pending
) {
1709 msg
.flags
= imp
->ipflags1
;
1710 msg
.id
= imp
->ipmsgid
;
1711 msg
.class = imp
->iptrgcls
;
1712 if (imp
->ipflags1
& IUCV_IPRMDATA
) {
1713 memcpy(msg
.rmmsg
, imp
->ln1msg1
.iprmmsg1
, 8);
1716 msg
.length
= imp
->ln1msg2
.ipbfln1f
;
1717 msg
.reply_size
= imp
->ipbfln2f
;
1718 path
->handler
->message_pending(path
, &msg
);
1725 * This tasklet loops over the queue of irq buffers created by
1726 * iucv_external_interrupt, calls the appropriate action handler
1727 * and then frees the buffer.
1729 static void iucv_tasklet_fn(unsigned long ignored
)
1731 typedef void iucv_irq_fn(struct iucv_irq_data
*);
1732 static iucv_irq_fn
*irq_fn
[] = {
1733 [0x02] = iucv_path_complete
,
1734 [0x03] = iucv_path_severed
,
1735 [0x04] = iucv_path_quiesced
,
1736 [0x05] = iucv_path_resumed
,
1737 [0x06] = iucv_message_complete
,
1738 [0x07] = iucv_message_complete
,
1739 [0x08] = iucv_message_pending
,
1740 [0x09] = iucv_message_pending
,
1742 LIST_HEAD(task_queue
);
1743 struct iucv_irq_list
*p
, *n
;
1745 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1746 if (!spin_trylock(&iucv_table_lock
)) {
1747 tasklet_schedule(&iucv_tasklet
);
1750 iucv_active_cpu
= smp_processor_id();
1752 spin_lock_irq(&iucv_queue_lock
);
1753 list_splice_init(&iucv_task_queue
, &task_queue
);
1754 spin_unlock_irq(&iucv_queue_lock
);
1756 list_for_each_entry_safe(p
, n
, &task_queue
, list
) {
1757 list_del_init(&p
->list
);
1758 irq_fn
[p
->data
.iptype
](&p
->data
);
1762 iucv_active_cpu
= -1;
1763 spin_unlock(&iucv_table_lock
);
1769 * This work function loops over the queue of path pending irq blocks
1770 * created by iucv_external_interrupt, calls the appropriate action
1771 * handler and then frees the buffer.
1773 static void iucv_work_fn(struct work_struct
*work
)
1775 LIST_HEAD(work_queue
);
1776 struct iucv_irq_list
*p
, *n
;
1778 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1779 spin_lock_bh(&iucv_table_lock
);
1780 iucv_active_cpu
= smp_processor_id();
1782 spin_lock_irq(&iucv_queue_lock
);
1783 list_splice_init(&iucv_work_queue
, &work_queue
);
1784 spin_unlock_irq(&iucv_queue_lock
);
1786 iucv_cleanup_queue();
1787 list_for_each_entry_safe(p
, n
, &work_queue
, list
) {
1788 list_del_init(&p
->list
);
1789 iucv_path_pending(&p
->data
);
1793 iucv_active_cpu
= -1;
1794 spin_unlock_bh(&iucv_table_lock
);
1798 * iucv_external_interrupt
1801 * Handles external interrupts coming in from CP.
1802 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1804 static void iucv_external_interrupt(struct ext_code ext_code
,
1805 unsigned int param32
, unsigned long param64
)
1807 struct iucv_irq_data
*p
;
1808 struct iucv_irq_list
*work
;
1810 inc_irq_stat(IRQEXT_IUC
);
1811 p
= iucv_irq_data
[smp_processor_id()];
1812 if (p
->ippathid
>= iucv_max_pathid
) {
1813 WARN_ON(p
->ippathid
>= iucv_max_pathid
);
1814 iucv_sever_pathid(p
->ippathid
, iucv_error_no_listener
);
1817 BUG_ON(p
->iptype
< 0x01 || p
->iptype
> 0x09);
1818 work
= kmalloc(sizeof(struct iucv_irq_list
), GFP_ATOMIC
);
1820 pr_warn("iucv_external_interrupt: out of memory\n");
1823 memcpy(&work
->data
, p
, sizeof(work
->data
));
1824 spin_lock(&iucv_queue_lock
);
1825 if (p
->iptype
== 0x01) {
1826 /* Path pending interrupt. */
1827 list_add_tail(&work
->list
, &iucv_work_queue
);
1828 schedule_work(&iucv_work
);
1830 /* The other interrupts. */
1831 list_add_tail(&work
->list
, &iucv_task_queue
);
1832 tasklet_schedule(&iucv_tasklet
);
1834 spin_unlock(&iucv_queue_lock
);
1837 static int iucv_pm_prepare(struct device
*dev
)
1841 #ifdef CONFIG_PM_DEBUG
1842 printk(KERN_INFO
"iucv_pm_prepare\n");
1844 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->prepare
)
1845 rc
= dev
->driver
->pm
->prepare(dev
);
1849 static void iucv_pm_complete(struct device
*dev
)
1851 #ifdef CONFIG_PM_DEBUG
1852 printk(KERN_INFO
"iucv_pm_complete\n");
1854 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->complete
)
1855 dev
->driver
->pm
->complete(dev
);
1859 * iucv_path_table_empty() - determine if iucv path table is empty
1861 * Returns 0 if there are still iucv pathes defined
1862 * 1 if there are no iucv pathes defined
1864 static int iucv_path_table_empty(void)
1868 for (i
= 0; i
< iucv_max_pathid
; i
++) {
1869 if (iucv_path_table
[i
])
1876 * iucv_pm_freeze() - Freeze PM callback
1877 * @dev: iucv-based device
1879 * disable iucv interrupts
1880 * invoke callback function of the iucv-based driver
1881 * shut down iucv, if no iucv-pathes are established anymore
1883 static int iucv_pm_freeze(struct device
*dev
)
1886 struct iucv_irq_list
*p
, *n
;
1889 #ifdef CONFIG_PM_DEBUG
1890 printk(KERN_WARNING
"iucv_pm_freeze\n");
1892 if (iucv_pm_state
!= IUCV_PM_FREEZING
) {
1893 for_each_cpu(cpu
, &iucv_irq_cpumask
)
1894 smp_call_function_single(cpu
, iucv_block_cpu_almost
,
1896 cancel_work_sync(&iucv_work
);
1897 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
) {
1898 list_del_init(&p
->list
);
1899 iucv_sever_pathid(p
->data
.ippathid
,
1900 iucv_error_no_listener
);
1904 iucv_pm_state
= IUCV_PM_FREEZING
;
1905 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->freeze
)
1906 rc
= dev
->driver
->pm
->freeze(dev
);
1907 if (iucv_path_table_empty())
1913 * iucv_pm_thaw() - Thaw PM callback
1914 * @dev: iucv-based device
1916 * make iucv ready for use again: allocate path table, declare interrupt buffers
1917 * and enable iucv interrupts
1918 * invoke callback function of the iucv-based driver
1920 static int iucv_pm_thaw(struct device
*dev
)
1924 #ifdef CONFIG_PM_DEBUG
1925 printk(KERN_WARNING
"iucv_pm_thaw\n");
1927 iucv_pm_state
= IUCV_PM_THAWING
;
1928 if (!iucv_path_table
) {
1933 if (cpumask_empty(&iucv_irq_cpumask
)) {
1934 if (iucv_nonsmp_handler
)
1935 /* enable interrupts on one cpu */
1936 iucv_allow_cpu(NULL
);
1938 /* enable interrupts on all cpus */
1941 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->thaw
)
1942 rc
= dev
->driver
->pm
->thaw(dev
);
1948 * iucv_pm_restore() - Restore PM callback
1949 * @dev: iucv-based device
1951 * make iucv ready for use again: allocate path table, declare interrupt buffers
1952 * and enable iucv interrupts
1953 * invoke callback function of the iucv-based driver
1955 static int iucv_pm_restore(struct device
*dev
)
1959 #ifdef CONFIG_PM_DEBUG
1960 printk(KERN_WARNING
"iucv_pm_restore %p\n", iucv_path_table
);
1962 if ((iucv_pm_state
!= IUCV_PM_RESTORING
) && iucv_path_table
)
1963 pr_warn("Suspending Linux did not completely close all IUCV connections\n");
1964 iucv_pm_state
= IUCV_PM_RESTORING
;
1965 if (cpumask_empty(&iucv_irq_cpumask
)) {
1966 rc
= iucv_query_maxconn();
1971 if (dev
->driver
&& dev
->driver
->pm
&& dev
->driver
->pm
->restore
)
1972 rc
= dev
->driver
->pm
->restore(dev
);
1977 struct iucv_interface iucv_if
= {
1978 .message_receive
= iucv_message_receive
,
1979 .__message_receive
= __iucv_message_receive
,
1980 .message_reply
= iucv_message_reply
,
1981 .message_reject
= iucv_message_reject
,
1982 .message_send
= iucv_message_send
,
1983 .__message_send
= __iucv_message_send
,
1984 .message_send2way
= iucv_message_send2way
,
1985 .message_purge
= iucv_message_purge
,
1986 .path_accept
= iucv_path_accept
,
1987 .path_connect
= iucv_path_connect
,
1988 .path_quiesce
= iucv_path_quiesce
,
1989 .path_resume
= iucv_path_resume
,
1990 .path_sever
= iucv_path_sever
,
1991 .iucv_register
= iucv_register
,
1992 .iucv_unregister
= iucv_unregister
,
1996 EXPORT_SYMBOL(iucv_if
);
1998 static enum cpuhp_state iucv_online
;
2002 * Allocates and initializes various data structures.
2004 static int __init
iucv_init(void)
2008 if (!MACHINE_IS_VM
) {
2009 rc
= -EPROTONOSUPPORT
;
2013 rc
= iucv_query_maxconn();
2016 rc
= register_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
2019 iucv_root
= root_device_register("iucv");
2020 if (IS_ERR(iucv_root
)) {
2021 rc
= PTR_ERR(iucv_root
);
2025 rc
= cpuhp_setup_state(CPUHP_NET_IUCV_PREPARE
, "net/iucv:prepare",
2026 iucv_cpu_prepare
, iucv_cpu_dead
);
2029 rc
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "net/iucv:online",
2030 iucv_cpu_online
, iucv_cpu_down_prep
);
2035 rc
= register_reboot_notifier(&iucv_reboot_notifier
);
2038 ASCEBC(iucv_error_no_listener
, 16);
2039 ASCEBC(iucv_error_no_memory
, 16);
2040 ASCEBC(iucv_error_pathid
, 16);
2042 rc
= bus_register(&iucv_bus
);
2045 iucv_if
.root
= iucv_root
;
2046 iucv_if
.bus
= &iucv_bus
;
2050 unregister_reboot_notifier(&iucv_reboot_notifier
);
2052 cpuhp_remove_state(iucv_online
);
2054 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE
);
2056 root_device_unregister(iucv_root
);
2058 unregister_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
2060 ctl_clear_bit(0, 1);
2068 * Frees everything allocated from iucv_init.
2070 static void __exit
iucv_exit(void)
2072 struct iucv_irq_list
*p
, *n
;
2074 spin_lock_irq(&iucv_queue_lock
);
2075 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
)
2077 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
)
2079 spin_unlock_irq(&iucv_queue_lock
);
2080 unregister_reboot_notifier(&iucv_reboot_notifier
);
2082 cpuhp_remove_state_nocalls(iucv_online
);
2083 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE
);
2084 root_device_unregister(iucv_root
);
2085 bus_unregister(&iucv_bus
);
2086 unregister_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
2089 subsys_initcall(iucv_init
);
2090 module_exit(iucv_exit
);
2092 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
2093 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
2094 MODULE_LICENSE("GPL");