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
, const struct device_driver
*drv
)
70 const struct bus_type iucv_bus
= {
72 .match
= iucv_bus_match
,
74 EXPORT_SYMBOL(iucv_bus
);
76 static struct device
*iucv_root
;
78 static void iucv_release_device(struct device
*device
)
83 struct device
*iucv_alloc_device(const struct attribute_group
**attrs
,
84 struct device_driver
*driver
,
85 void *priv
, const char *fmt
, ...)
92 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
96 vsnprintf(buf
, sizeof(buf
), fmt
, vargs
);
97 rc
= dev_set_name(dev
, "%s", buf
);
101 dev
->bus
= &iucv_bus
;
102 dev
->parent
= iucv_root
;
103 dev
->driver
= driver
;
105 dev
->release
= iucv_release_device
;
106 dev_set_drvdata(dev
, priv
);
113 EXPORT_SYMBOL(iucv_alloc_device
);
115 static int iucv_available
;
117 /* General IUCV interrupt structure */
118 struct iucv_irq_data
{
125 struct iucv_irq_list
{
126 struct list_head list
;
127 struct iucv_irq_data data
;
130 static struct iucv_irq_data
*iucv_irq_data
[NR_CPUS
];
131 static cpumask_t iucv_buffer_cpumask
= { CPU_BITS_NONE
};
132 static cpumask_t iucv_irq_cpumask
= { CPU_BITS_NONE
};
135 * Queue of interrupt buffers lock for delivery via the tasklet
136 * (fast but can't call smp_call_function).
138 static LIST_HEAD(iucv_task_queue
);
141 * The tasklet for fast delivery of iucv interrupts.
143 static void iucv_tasklet_fn(unsigned long);
144 static DECLARE_TASKLET_OLD(iucv_tasklet
, iucv_tasklet_fn
);
147 * Queue of interrupt buffers for delivery via a work queue
148 * (slower but can call smp_call_function).
150 static LIST_HEAD(iucv_work_queue
);
153 * The work element to deliver path pending interrupts.
155 static void iucv_work_fn(struct work_struct
*work
);
156 static DECLARE_WORK(iucv_work
, iucv_work_fn
);
159 * Spinlock protecting task and work queue.
161 static DEFINE_SPINLOCK(iucv_queue_lock
);
163 enum iucv_command_codes
{
165 IUCV_RETRIEVE_BUFFER
= 2,
173 IUCV_DECLARE_BUFFER
= 12,
178 IUCV_SETCONTROLMASK
= 17,
182 * Error messages that are used with the iucv_sever function. They get
183 * converted to EBCDIC.
185 static char iucv_error_no_listener
[16] = "NO LISTENER";
186 static char iucv_error_no_memory
[16] = "NO MEMORY";
187 static char iucv_error_pathid
[16] = "INVALID PATHID";
190 * iucv_handler_list: List of registered handlers.
192 static LIST_HEAD(iucv_handler_list
);
195 * iucv_path_table: array of pointers to iucv_path structures.
197 static struct iucv_path
**iucv_path_table
;
198 static unsigned long iucv_max_pathid
;
201 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
203 static DEFINE_SPINLOCK(iucv_table_lock
);
206 * iucv_active_cpu: contains the number of the cpu executing the tasklet
207 * or the work handler. Needed for iucv_path_sever called from tasklet.
209 static int iucv_active_cpu
= -1;
212 * Mutex and wait queue for iucv_register/iucv_unregister.
214 static DEFINE_MUTEX(iucv_register_mutex
);
217 * Counter for number of non-smp capable handlers.
219 static int iucv_nonsmp_handler
;
222 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
223 * iucv_path_quiesce and iucv_path_sever.
225 struct iucv_cmd_control
{
234 } __attribute__ ((packed
,aligned(8)));
237 * Data in parameter list iucv structure. Used by iucv_message_send,
238 * iucv_message_send2way and iucv_message_reply.
240 struct iucv_cmd_dpl
{
252 } __attribute__ ((packed
,aligned(8)));
255 * Data in buffer iucv structure. Used by iucv_message_receive,
256 * iucv_message_reject, iucv_message_send, iucv_message_send2way
257 * and iucv_declare_cpu.
272 } __attribute__ ((packed
,aligned(8)));
275 * Purge message iucv structure. Used by iucv_message_purge.
277 struct iucv_cmd_purge
{
288 } __attribute__ ((packed
,aligned(8)));
291 * Set mask iucv structure. Used by iucv_enable_cpu.
293 struct iucv_cmd_set_mask
{
298 } __attribute__ ((packed
,aligned(8)));
301 struct iucv_cmd_control ctrl
;
302 struct iucv_cmd_dpl dpl
;
303 struct iucv_cmd_db db
;
304 struct iucv_cmd_purge purge
;
305 struct iucv_cmd_set_mask set_mask
;
309 * Anchor for per-cpu IUCV command parameter block.
311 static union iucv_param
*iucv_param
[NR_CPUS
];
312 static union iucv_param
*iucv_param_irq
[NR_CPUS
];
316 * @command: identifier of IUCV call to CP.
317 * @parm: pointer to a struct iucv_parm block
319 * Calls CP to execute IUCV commands.
321 * Returns the result of the CP IUCV call.
323 static inline int __iucv_call_b2f0(int command
, union iucv_param
*parm
)
325 unsigned long reg1
= virt_to_phys(parm
);
331 " .long 0xb2f01000\n"
334 : [cc
] "=&d" (cc
), "+m" (*parm
)
335 : [reg0
] "d" ((unsigned long)command
),
341 static inline int iucv_call_b2f0(int command
, union iucv_param
*parm
)
345 ccode
= __iucv_call_b2f0(command
, parm
);
346 return ccode
== 1 ? parm
->ctrl
.iprcode
: ccode
;
352 * Determines the maximum number of connections that may be established.
354 * Returns the maximum number of connections or -EPERM is IUCV is not
357 static int __iucv_query_maxconn(void *param
, unsigned long *max_pathid
)
359 unsigned long reg1
= virt_to_phys(param
);
365 " .long 0xb2f01000\n"
369 : [cc
] "=&d" (cc
), [reg1
] "+&d" (reg1
)
370 : [cmd
] "K" (IUCV_QUERY
)
376 static int iucv_query_maxconn(void)
378 unsigned long max_pathid
;
382 param
= kzalloc(sizeof(union iucv_param
), GFP_KERNEL
| GFP_DMA
);
385 ccode
= __iucv_query_maxconn(param
, &max_pathid
);
387 iucv_max_pathid
= max_pathid
;
389 return ccode
? -EPERM
: 0;
396 * Allow iucv interrupts on this cpu.
398 static void iucv_allow_cpu(void *data
)
400 int cpu
= smp_processor_id();
401 union iucv_param
*parm
;
404 * Enable all iucv interrupts.
405 * ipmask contains bits for the different interrupts
406 * 0x80 - Flag to allow nonpriority message pending interrupts
407 * 0x40 - Flag to allow priority message pending interrupts
408 * 0x20 - Flag to allow nonpriority message completion interrupts
409 * 0x10 - Flag to allow priority message completion interrupts
410 * 0x08 - Flag to allow IUCV control interrupts
412 parm
= iucv_param_irq
[cpu
];
413 memset(parm
, 0, sizeof(union iucv_param
));
414 parm
->set_mask
.ipmask
= 0xf8;
415 iucv_call_b2f0(IUCV_SETMASK
, parm
);
418 * Enable all iucv control interrupts.
419 * ipmask contains bits for the different interrupts
420 * 0x80 - Flag to allow pending connections interrupts
421 * 0x40 - Flag to allow connection complete interrupts
422 * 0x20 - Flag to allow connection severed interrupts
423 * 0x10 - Flag to allow connection quiesced interrupts
424 * 0x08 - Flag to allow connection resumed interrupts
426 memset(parm
, 0, sizeof(union iucv_param
));
427 parm
->set_mask
.ipmask
= 0xf8;
428 iucv_call_b2f0(IUCV_SETCONTROLMASK
, parm
);
429 /* Set indication that iucv interrupts are allowed for this cpu. */
430 cpumask_set_cpu(cpu
, &iucv_irq_cpumask
);
437 * Block iucv interrupts on this cpu.
439 static void iucv_block_cpu(void *data
)
441 int cpu
= smp_processor_id();
442 union iucv_param
*parm
;
444 /* Disable all iucv interrupts. */
445 parm
= iucv_param_irq
[cpu
];
446 memset(parm
, 0, sizeof(union iucv_param
));
447 iucv_call_b2f0(IUCV_SETMASK
, parm
);
449 /* Clear indication that iucv interrupts are allowed for this cpu. */
450 cpumask_clear_cpu(cpu
, &iucv_irq_cpumask
);
457 * Declare a interrupt buffer on this cpu.
459 static void iucv_declare_cpu(void *data
)
461 int cpu
= smp_processor_id();
462 union iucv_param
*parm
;
465 if (cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
))
468 /* Declare interrupt buffer. */
469 parm
= iucv_param_irq
[cpu
];
470 memset(parm
, 0, sizeof(union iucv_param
));
471 parm
->db
.ipbfadr1
= virt_to_dma32(iucv_irq_data
[cpu
]);
472 rc
= iucv_call_b2f0(IUCV_DECLARE_BUFFER
, parm
);
474 char *err
= "Unknown";
477 err
= "Directory error";
480 err
= "Invalid length";
483 err
= "Buffer already exists";
486 err
= "Buffer overlap";
489 err
= "Paging or storage error";
492 pr_warn("Defining an interrupt buffer on CPU %i failed with 0x%02x (%s)\n",
497 /* Set indication that an iucv buffer exists for this cpu. */
498 cpumask_set_cpu(cpu
, &iucv_buffer_cpumask
);
500 if (iucv_nonsmp_handler
== 0 || cpumask_empty(&iucv_irq_cpumask
))
501 /* Enable iucv interrupts on this cpu. */
502 iucv_allow_cpu(NULL
);
504 /* Disable iucv interrupts on this cpu. */
505 iucv_block_cpu(NULL
);
512 * Retrieve interrupt buffer on this cpu.
514 static void iucv_retrieve_cpu(void *data
)
516 int cpu
= smp_processor_id();
517 union iucv_param
*parm
;
519 if (!cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
))
522 /* Block iucv interrupts. */
523 iucv_block_cpu(NULL
);
525 /* Retrieve interrupt buffer. */
526 parm
= iucv_param_irq
[cpu
];
527 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER
, parm
);
529 /* Clear indication that an iucv buffer exists for this cpu. */
530 cpumask_clear_cpu(cpu
, &iucv_buffer_cpumask
);
536 * Allow iucv interrupts on all cpus.
538 static void iucv_setmask_mp(void)
543 for_each_online_cpu(cpu
)
544 /* Enable all cpus with a declared buffer. */
545 if (cpumask_test_cpu(cpu
, &iucv_buffer_cpumask
) &&
546 !cpumask_test_cpu(cpu
, &iucv_irq_cpumask
))
547 smp_call_function_single(cpu
, iucv_allow_cpu
,
555 * Allow iucv interrupts on a single cpu.
557 static void iucv_setmask_up(void)
559 static cpumask_t cpumask
;
562 /* Disable all cpu but the first in cpu_irq_cpumask. */
563 cpumask_copy(&cpumask
, &iucv_irq_cpumask
);
564 cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask
), &cpumask
);
565 for_each_cpu(cpu
, &cpumask
)
566 smp_call_function_single(cpu
, iucv_block_cpu
, NULL
, 1);
572 * This function makes iucv ready for use. It allocates the pathid
573 * table, declares an iucv interrupt buffer and enables the iucv
574 * interrupts. Called when the first user has registered an iucv
577 static int iucv_enable(void)
584 alloc_size
= iucv_max_pathid
* sizeof(*iucv_path_table
);
585 iucv_path_table
= kzalloc(alloc_size
, GFP_KERNEL
);
586 if (!iucv_path_table
)
588 /* Declare per cpu buffers. */
590 for_each_online_cpu(cpu
)
591 smp_call_function_single(cpu
, iucv_declare_cpu
, NULL
, 1);
592 if (cpumask_empty(&iucv_buffer_cpumask
))
593 /* No cpu could declare an iucv buffer. */
598 kfree(iucv_path_table
);
599 iucv_path_table
= NULL
;
607 * This function shuts down iucv. It disables iucv interrupts, retrieves
608 * the iucv interrupt buffer and frees the pathid table. Called after the
609 * last user unregister its iucv handler.
611 static void iucv_disable(void)
614 on_each_cpu(iucv_retrieve_cpu
, NULL
, 1);
615 kfree(iucv_path_table
);
616 iucv_path_table
= NULL
;
620 static int iucv_cpu_dead(unsigned int cpu
)
622 kfree(iucv_param_irq
[cpu
]);
623 iucv_param_irq
[cpu
] = NULL
;
624 kfree(iucv_param
[cpu
]);
625 iucv_param
[cpu
] = NULL
;
626 kfree(iucv_irq_data
[cpu
]);
627 iucv_irq_data
[cpu
] = NULL
;
631 static int iucv_cpu_prepare(unsigned int cpu
)
633 /* Note: GFP_DMA used to get memory below 2G */
634 iucv_irq_data
[cpu
] = kmalloc_node(sizeof(struct iucv_irq_data
),
635 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
636 if (!iucv_irq_data
[cpu
])
639 /* Allocate parameter blocks. */
640 iucv_param
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
641 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
642 if (!iucv_param
[cpu
])
645 iucv_param_irq
[cpu
] = kmalloc_node(sizeof(union iucv_param
),
646 GFP_KERNEL
|GFP_DMA
, cpu_to_node(cpu
));
647 if (!iucv_param_irq
[cpu
])
657 static int iucv_cpu_online(unsigned int cpu
)
659 if (!iucv_path_table
)
661 iucv_declare_cpu(NULL
);
665 static int iucv_cpu_down_prep(unsigned int cpu
)
667 cpumask_var_t cpumask
;
670 if (!iucv_path_table
)
673 if (!alloc_cpumask_var(&cpumask
, GFP_KERNEL
))
676 cpumask_copy(cpumask
, &iucv_buffer_cpumask
);
677 cpumask_clear_cpu(cpu
, cpumask
);
678 if (cpumask_empty(cpumask
)) {
679 /* Can't offline last IUCV enabled cpu. */
684 iucv_retrieve_cpu(NULL
);
685 if (!cpumask_empty(&iucv_irq_cpumask
))
688 smp_call_function_single(cpumask_first(&iucv_buffer_cpumask
),
689 iucv_allow_cpu
, NULL
, 1);
692 free_cpumask_var(cpumask
);
698 * @pathid: path identification number.
699 * @userdata: 16-bytes of user data.
701 * Sever an iucv path to free up the pathid. Used internally.
703 static int iucv_sever_pathid(u16 pathid
, u8
*userdata
)
705 union iucv_param
*parm
;
707 parm
= iucv_param_irq
[smp_processor_id()];
708 memset(parm
, 0, sizeof(union iucv_param
));
710 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
711 parm
->ctrl
.ippathid
= pathid
;
712 return iucv_call_b2f0(IUCV_SEVER
, parm
);
716 * __iucv_cleanup_queue
717 * @dummy: unused dummy argument
719 * Nop function called via smp_call_function to force work items from
720 * pending external iucv interrupts to the work queue.
722 static void __iucv_cleanup_queue(void *dummy
)
729 * Function called after a path has been severed to find all remaining
730 * work items for the now stale pathid. The caller needs to hold the
733 static void iucv_cleanup_queue(void)
735 struct iucv_irq_list
*p
, *n
;
738 * When a path is severed, the pathid can be reused immediately
739 * on a iucv connect or a connection pending interrupt. Remove
740 * all entries from the task queue that refer to a stale pathid
741 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
742 * or deliver the connection pending interrupt. To get all the
743 * pending interrupts force them to the work queue by calling
744 * an empty function on all cpus.
746 smp_call_function(__iucv_cleanup_queue
, NULL
, 1);
747 spin_lock_irq(&iucv_queue_lock
);
748 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
) {
749 /* Remove stale work items from the task queue. */
750 if (iucv_path_table
[p
->data
.ippathid
] == NULL
) {
755 spin_unlock_irq(&iucv_queue_lock
);
760 * @handler: address of iucv handler structure
761 * @smp: != 0 indicates that the handler can deal with out of order messages
763 * Registers a driver with IUCV.
765 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
766 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
768 int iucv_register(struct iucv_handler
*handler
, int smp
)
774 mutex_lock(&iucv_register_mutex
);
776 iucv_nonsmp_handler
++;
777 if (list_empty(&iucv_handler_list
)) {
781 } else if (!smp
&& iucv_nonsmp_handler
== 1)
783 INIT_LIST_HEAD(&handler
->paths
);
785 spin_lock_bh(&iucv_table_lock
);
786 list_add_tail(&handler
->list
, &iucv_handler_list
);
787 spin_unlock_bh(&iucv_table_lock
);
790 mutex_unlock(&iucv_register_mutex
);
793 EXPORT_SYMBOL(iucv_register
);
797 * @handler: address of iucv handler structure
798 * @smp: != 0 indicates that the handler can deal with out of order messages
800 * Unregister driver from IUCV.
802 void iucv_unregister(struct iucv_handler
*handler
, int smp
)
804 struct iucv_path
*p
, *n
;
806 mutex_lock(&iucv_register_mutex
);
807 spin_lock_bh(&iucv_table_lock
);
808 /* Remove handler from the iucv_handler_list. */
809 list_del_init(&handler
->list
);
810 /* Sever all pathids still referring to the handler. */
811 list_for_each_entry_safe(p
, n
, &handler
->paths
, list
) {
812 iucv_sever_pathid(p
->pathid
, NULL
);
813 iucv_path_table
[p
->pathid
] = NULL
;
817 spin_unlock_bh(&iucv_table_lock
);
819 iucv_nonsmp_handler
--;
820 if (list_empty(&iucv_handler_list
))
822 else if (!smp
&& iucv_nonsmp_handler
== 0)
824 mutex_unlock(&iucv_register_mutex
);
826 EXPORT_SYMBOL(iucv_unregister
);
828 static int iucv_reboot_event(struct notifier_block
*this,
829 unsigned long event
, void *ptr
)
833 if (cpumask_empty(&iucv_irq_cpumask
))
837 on_each_cpu_mask(&iucv_irq_cpumask
, iucv_block_cpu
, NULL
, 1);
839 for (i
= 0; i
< iucv_max_pathid
; i
++) {
840 if (iucv_path_table
[i
])
841 iucv_sever_pathid(i
, NULL
);
849 static struct notifier_block iucv_reboot_notifier
= {
850 .notifier_call
= iucv_reboot_event
,
855 * @path: address of iucv path structure
856 * @handler: address of iucv handler structure
857 * @userdata: 16 bytes of data reflected to the communication partner
858 * @private: private data passed to interrupt handlers for this path
860 * This function is issued after the user received a connection pending
861 * external interrupt and now wishes to complete the IUCV communication path.
863 * Returns the result of the CP IUCV call.
865 int iucv_path_accept(struct iucv_path
*path
, struct iucv_handler
*handler
,
866 u8
*userdata
, void *private)
868 union iucv_param
*parm
;
872 if (cpumask_empty(&iucv_buffer_cpumask
)) {
876 /* Prepare parameter block. */
877 parm
= iucv_param
[smp_processor_id()];
878 memset(parm
, 0, sizeof(union iucv_param
));
879 parm
->ctrl
.ippathid
= path
->pathid
;
880 parm
->ctrl
.ipmsglim
= path
->msglim
;
882 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
883 parm
->ctrl
.ipflags1
= path
->flags
;
885 rc
= iucv_call_b2f0(IUCV_ACCEPT
, parm
);
887 path
->private = private;
888 path
->msglim
= parm
->ctrl
.ipmsglim
;
889 path
->flags
= parm
->ctrl
.ipflags1
;
895 EXPORT_SYMBOL(iucv_path_accept
);
899 * @path: address of iucv path structure
900 * @handler: address of iucv handler structure
901 * @userid: 8-byte user identification
902 * @system: 8-byte target system identification
903 * @userdata: 16 bytes of data reflected to the communication partner
904 * @private: private data passed to interrupt handlers for this path
906 * This function establishes an IUCV path. Although the connect may complete
907 * successfully, you are not able to use the path until you receive an IUCV
908 * Connection Complete external interrupt.
910 * Returns the result of the CP IUCV call.
912 int iucv_path_connect(struct iucv_path
*path
, struct iucv_handler
*handler
,
913 u8
*userid
, u8
*system
, u8
*userdata
,
916 union iucv_param
*parm
;
919 spin_lock_bh(&iucv_table_lock
);
920 iucv_cleanup_queue();
921 if (cpumask_empty(&iucv_buffer_cpumask
)) {
925 parm
= iucv_param
[smp_processor_id()];
926 memset(parm
, 0, sizeof(union iucv_param
));
927 parm
->ctrl
.ipmsglim
= path
->msglim
;
928 parm
->ctrl
.ipflags1
= path
->flags
;
930 memcpy(parm
->ctrl
.ipvmid
, userid
, sizeof(parm
->ctrl
.ipvmid
));
931 ASCEBC(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
932 EBC_TOUPPER(parm
->ctrl
.ipvmid
, sizeof(parm
->ctrl
.ipvmid
));
935 memcpy(parm
->ctrl
.iptarget
, system
,
936 sizeof(parm
->ctrl
.iptarget
));
937 ASCEBC(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
938 EBC_TOUPPER(parm
->ctrl
.iptarget
, sizeof(parm
->ctrl
.iptarget
));
941 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
943 rc
= iucv_call_b2f0(IUCV_CONNECT
, parm
);
945 if (parm
->ctrl
.ippathid
< iucv_max_pathid
) {
946 path
->pathid
= parm
->ctrl
.ippathid
;
947 path
->msglim
= parm
->ctrl
.ipmsglim
;
948 path
->flags
= parm
->ctrl
.ipflags1
;
949 path
->handler
= handler
;
950 path
->private = private;
951 list_add_tail(&path
->list
, &handler
->paths
);
952 iucv_path_table
[path
->pathid
] = path
;
954 iucv_sever_pathid(parm
->ctrl
.ippathid
,
960 spin_unlock_bh(&iucv_table_lock
);
963 EXPORT_SYMBOL(iucv_path_connect
);
967 * @path: address of iucv path structure
968 * @userdata: 16 bytes of data reflected to the communication partner
970 * This function temporarily suspends incoming messages on an IUCV path.
971 * You can later reactivate the path by invoking the iucv_resume function.
973 * Returns the result from the CP IUCV call.
975 int iucv_path_quiesce(struct iucv_path
*path
, u8
*userdata
)
977 union iucv_param
*parm
;
981 if (cpumask_empty(&iucv_buffer_cpumask
)) {
985 parm
= iucv_param
[smp_processor_id()];
986 memset(parm
, 0, sizeof(union iucv_param
));
988 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
989 parm
->ctrl
.ippathid
= path
->pathid
;
990 rc
= iucv_call_b2f0(IUCV_QUIESCE
, parm
);
995 EXPORT_SYMBOL(iucv_path_quiesce
);
999 * @path: address of iucv path structure
1000 * @userdata: 16 bytes of data reflected to the communication partner
1002 * This function resumes incoming messages on an IUCV path that has
1003 * been stopped with iucv_path_quiesce.
1005 * Returns the result from the CP IUCV call.
1007 int iucv_path_resume(struct iucv_path
*path
, u8
*userdata
)
1009 union iucv_param
*parm
;
1013 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1017 parm
= iucv_param
[smp_processor_id()];
1018 memset(parm
, 0, sizeof(union iucv_param
));
1020 memcpy(parm
->ctrl
.ipuser
, userdata
, sizeof(parm
->ctrl
.ipuser
));
1021 parm
->ctrl
.ippathid
= path
->pathid
;
1022 rc
= iucv_call_b2f0(IUCV_RESUME
, parm
);
1030 * @path: address of iucv path structure
1031 * @userdata: 16 bytes of data reflected to the communication partner
1033 * This function terminates an IUCV path.
1035 * Returns the result from the CP IUCV call.
1037 int iucv_path_sever(struct iucv_path
*path
, u8
*userdata
)
1042 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1046 if (iucv_active_cpu
!= smp_processor_id())
1047 spin_lock_bh(&iucv_table_lock
);
1048 rc
= iucv_sever_pathid(path
->pathid
, userdata
);
1049 iucv_path_table
[path
->pathid
] = NULL
;
1050 list_del_init(&path
->list
);
1051 if (iucv_active_cpu
!= smp_processor_id())
1052 spin_unlock_bh(&iucv_table_lock
);
1057 EXPORT_SYMBOL(iucv_path_sever
);
1060 * iucv_message_purge
1061 * @path: address of iucv path structure
1062 * @msg: address of iucv msg structure
1063 * @srccls: source class of message
1065 * Cancels a message you have sent.
1067 * Returns the result from the CP IUCV call.
1069 int iucv_message_purge(struct iucv_path
*path
, struct iucv_message
*msg
,
1072 union iucv_param
*parm
;
1076 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1080 parm
= iucv_param
[smp_processor_id()];
1081 memset(parm
, 0, sizeof(union iucv_param
));
1082 parm
->purge
.ippathid
= path
->pathid
;
1083 parm
->purge
.ipmsgid
= msg
->id
;
1084 parm
->purge
.ipsrccls
= srccls
;
1085 parm
->purge
.ipflags1
= IUCV_IPSRCCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
;
1086 rc
= iucv_call_b2f0(IUCV_PURGE
, parm
);
1088 msg
->audit
= (*(u32
*) &parm
->purge
.ipaudit
) >> 8;
1089 msg
->tag
= parm
->purge
.ipmsgtag
;
1095 EXPORT_SYMBOL(iucv_message_purge
);
1098 * iucv_message_receive_iprmdata
1099 * @path: address of iucv path structure
1100 * @msg: address of iucv msg structure
1101 * @flags: how the message is received (IUCV_IPBUFLST)
1102 * @buffer: address of data buffer or address of struct iucv_array
1103 * @size: length of data buffer
1106 * Internal function used by iucv_message_receive and __iucv_message_receive
1107 * to receive RMDATA data stored in struct iucv_message.
1109 static int iucv_message_receive_iprmdata(struct iucv_path
*path
,
1110 struct iucv_message
*msg
,
1111 u8 flags
, void *buffer
,
1112 size_t size
, size_t *residual
)
1114 struct iucv_array
*array
;
1119 * Message is 8 bytes long and has been stored to the
1120 * message descriptor itself.
1123 *residual
= abs(size
- 8);
1125 if (flags
& IUCV_IPBUFLST
) {
1126 /* Copy to struct iucv_array. */
1127 size
= (size
< 8) ? size
: 8;
1128 for (array
= buffer
; size
> 0; array
++) {
1129 copy
= min_t(size_t, size
, array
->length
);
1130 memcpy(dma32_to_virt(array
->address
), rmmsg
, copy
);
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
))
1170 parm
= iucv_param
[smp_processor_id()];
1171 memset(parm
, 0, sizeof(union iucv_param
));
1172 parm
->db
.ipbfadr1
= virt_to_dma32(buffer
);
1173 parm
->db
.ipbfln1f
= (u32
) size
;
1174 parm
->db
.ipmsgid
= msg
->id
;
1175 parm
->db
.ippathid
= path
->pathid
;
1176 parm
->db
.iptrgcls
= msg
->class;
1177 parm
->db
.ipflags1
= (flags
| IUCV_IPFGPID
|
1178 IUCV_IPFGMID
| IUCV_IPTRGCLS
);
1179 rc
= iucv_call_b2f0(IUCV_RECEIVE
, parm
);
1180 if (!rc
|| rc
== 5) {
1181 msg
->flags
= parm
->db
.ipflags1
;
1183 *residual
= parm
->db
.ipbfln1f
;
1187 EXPORT_SYMBOL(__iucv_message_receive
);
1190 * iucv_message_receive
1191 * @path: address of iucv path structure
1192 * @msg: address of iucv msg structure
1193 * @flags: how the message is received (IUCV_IPBUFLST)
1194 * @buffer: address of data buffer or address of struct iucv_array
1195 * @size: length of data buffer
1198 * This function receives messages that are being sent to you over
1199 * established paths. This function will deal with RMDATA messages
1200 * embedded in struct iucv_message as well.
1202 * Locking: local_bh_enable/local_bh_disable
1204 * Returns the result from the CP IUCV call.
1206 int iucv_message_receive(struct iucv_path
*path
, struct iucv_message
*msg
,
1207 u8 flags
, void *buffer
, size_t size
, size_t *residual
)
1211 if (msg
->flags
& IUCV_IPRMDATA
)
1212 return iucv_message_receive_iprmdata(path
, msg
, flags
,
1213 buffer
, size
, residual
);
1215 rc
= __iucv_message_receive(path
, msg
, flags
, buffer
, size
, residual
);
1219 EXPORT_SYMBOL(iucv_message_receive
);
1222 * iucv_message_reject
1223 * @path: address of iucv path structure
1224 * @msg: address of iucv msg structure
1226 * The reject function refuses a specified message. Between the time you
1227 * are notified of a message and the time that you complete the message,
1228 * the message may be rejected.
1230 * Returns the result from the CP IUCV call.
1232 int iucv_message_reject(struct iucv_path
*path
, struct iucv_message
*msg
)
1234 union iucv_param
*parm
;
1238 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1242 parm
= iucv_param
[smp_processor_id()];
1243 memset(parm
, 0, sizeof(union iucv_param
));
1244 parm
->db
.ippathid
= path
->pathid
;
1245 parm
->db
.ipmsgid
= msg
->id
;
1246 parm
->db
.iptrgcls
= msg
->class;
1247 parm
->db
.ipflags1
= (IUCV_IPTRGCLS
| IUCV_IPFGMID
| IUCV_IPFGPID
);
1248 rc
= iucv_call_b2f0(IUCV_REJECT
, parm
);
1253 EXPORT_SYMBOL(iucv_message_reject
);
1256 * iucv_message_reply
1257 * @path: address of iucv path structure
1258 * @msg: address of iucv msg structure
1259 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1260 * @reply: address of reply data buffer or address of struct iucv_array
1261 * @size: length of reply data buffer
1263 * This function responds to the two-way messages that you receive. You
1264 * must identify completely the message to which you wish to reply. ie,
1265 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1266 * the parameter list.
1268 * Returns the result from the CP IUCV call.
1270 int iucv_message_reply(struct iucv_path
*path
, struct iucv_message
*msg
,
1271 u8 flags
, void *reply
, size_t size
)
1273 union iucv_param
*parm
;
1277 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1281 parm
= iucv_param
[smp_processor_id()];
1282 memset(parm
, 0, sizeof(union iucv_param
));
1283 if (flags
& IUCV_IPRMDATA
) {
1284 parm
->dpl
.ippathid
= path
->pathid
;
1285 parm
->dpl
.ipflags1
= flags
;
1286 parm
->dpl
.ipmsgid
= msg
->id
;
1287 parm
->dpl
.iptrgcls
= msg
->class;
1288 memcpy(parm
->dpl
.iprmmsg
, reply
, min_t(size_t, size
, 8));
1290 parm
->db
.ipbfadr1
= virt_to_dma32(reply
);
1291 parm
->db
.ipbfln1f
= (u32
) size
;
1292 parm
->db
.ippathid
= path
->pathid
;
1293 parm
->db
.ipflags1
= flags
;
1294 parm
->db
.ipmsgid
= msg
->id
;
1295 parm
->db
.iptrgcls
= msg
->class;
1297 rc
= iucv_call_b2f0(IUCV_REPLY
, parm
);
1302 EXPORT_SYMBOL(iucv_message_reply
);
1305 * __iucv_message_send
1306 * @path: address of iucv path structure
1307 * @msg: address of iucv msg structure
1308 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1309 * @srccls: source class of message
1310 * @buffer: address of send buffer or address of struct iucv_array
1311 * @size: length of send buffer
1313 * This function transmits data to another application. Data to be
1314 * transmitted is in a buffer and this is a one-way message and the
1315 * receiver will not reply to the message.
1317 * Locking: no locking
1319 * Returns the result from the CP IUCV call.
1321 int __iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1322 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1324 union iucv_param
*parm
;
1327 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1331 parm
= iucv_param
[smp_processor_id()];
1332 memset(parm
, 0, sizeof(union iucv_param
));
1333 if (flags
& IUCV_IPRMDATA
) {
1334 /* Message of 8 bytes can be placed into the parameter list. */
1335 parm
->dpl
.ippathid
= path
->pathid
;
1336 parm
->dpl
.ipflags1
= flags
| IUCV_IPNORPY
;
1337 parm
->dpl
.iptrgcls
= msg
->class;
1338 parm
->dpl
.ipsrccls
= srccls
;
1339 parm
->dpl
.ipmsgtag
= msg
->tag
;
1340 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1342 parm
->db
.ipbfadr1
= virt_to_dma32(buffer
);
1343 parm
->db
.ipbfln1f
= (u32
) size
;
1344 parm
->db
.ippathid
= path
->pathid
;
1345 parm
->db
.ipflags1
= flags
| IUCV_IPNORPY
;
1346 parm
->db
.iptrgcls
= msg
->class;
1347 parm
->db
.ipsrccls
= srccls
;
1348 parm
->db
.ipmsgtag
= msg
->tag
;
1350 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1352 msg
->id
= parm
->db
.ipmsgid
;
1356 EXPORT_SYMBOL(__iucv_message_send
);
1360 * @path: address of iucv path structure
1361 * @msg: address of iucv msg structure
1362 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1363 * @srccls: source class of message
1364 * @buffer: address of send buffer or address of struct iucv_array
1365 * @size: length of send buffer
1367 * This function transmits data to another application. Data to be
1368 * transmitted is in a buffer and this is a one-way message and the
1369 * receiver will not reply to the message.
1371 * Locking: local_bh_enable/local_bh_disable
1373 * Returns the result from the CP IUCV call.
1375 int iucv_message_send(struct iucv_path
*path
, struct iucv_message
*msg
,
1376 u8 flags
, u32 srccls
, void *buffer
, size_t size
)
1381 rc
= __iucv_message_send(path
, msg
, flags
, srccls
, buffer
, size
);
1385 EXPORT_SYMBOL(iucv_message_send
);
1388 * iucv_message_send2way
1389 * @path: address of iucv path structure
1390 * @msg: address of iucv msg structure
1391 * @flags: how the message is sent and the reply is received
1392 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1393 * @srccls: source class of message
1394 * @buffer: address of send buffer or address of struct iucv_array
1395 * @size: length of send buffer
1396 * @answer: address of answer buffer or address of struct iucv_array
1397 * @asize: size of reply buffer
1398 * @residual: ignored
1400 * This function transmits data to another application. Data to be
1401 * transmitted is in a buffer. The receiver of the send is expected to
1402 * reply to the message and a buffer is provided into which IUCV moves
1403 * the reply to this message.
1405 * Returns the result from the CP IUCV call.
1407 int iucv_message_send2way(struct iucv_path
*path
, struct iucv_message
*msg
,
1408 u8 flags
, u32 srccls
, void *buffer
, size_t size
,
1409 void *answer
, size_t asize
, size_t *residual
)
1411 union iucv_param
*parm
;
1415 if (cpumask_empty(&iucv_buffer_cpumask
)) {
1419 parm
= iucv_param
[smp_processor_id()];
1420 memset(parm
, 0, sizeof(union iucv_param
));
1421 if (flags
& IUCV_IPRMDATA
) {
1422 parm
->dpl
.ippathid
= path
->pathid
;
1423 parm
->dpl
.ipflags1
= path
->flags
; /* priority message */
1424 parm
->dpl
.iptrgcls
= msg
->class;
1425 parm
->dpl
.ipsrccls
= srccls
;
1426 parm
->dpl
.ipmsgtag
= msg
->tag
;
1427 parm
->dpl
.ipbfadr2
= virt_to_dma32(answer
);
1428 parm
->dpl
.ipbfln2f
= (u32
) asize
;
1429 memcpy(parm
->dpl
.iprmmsg
, buffer
, 8);
1431 parm
->db
.ippathid
= path
->pathid
;
1432 parm
->db
.ipflags1
= path
->flags
; /* priority message */
1433 parm
->db
.iptrgcls
= msg
->class;
1434 parm
->db
.ipsrccls
= srccls
;
1435 parm
->db
.ipmsgtag
= msg
->tag
;
1436 parm
->db
.ipbfadr1
= virt_to_dma32(buffer
);
1437 parm
->db
.ipbfln1f
= (u32
) size
;
1438 parm
->db
.ipbfadr2
= virt_to_dma32(answer
);
1439 parm
->db
.ipbfln2f
= (u32
) asize
;
1441 rc
= iucv_call_b2f0(IUCV_SEND
, parm
);
1443 msg
->id
= parm
->db
.ipmsgid
;
1448 EXPORT_SYMBOL(iucv_message_send2way
);
1450 struct iucv_path_pending
{
1465 * @data: Pointer to external interrupt buffer
1467 * Process connection pending work item. Called from tasklet while holding
1470 static void iucv_path_pending(struct iucv_irq_data
*data
)
1472 struct iucv_path_pending
*ipp
= (void *) data
;
1473 struct iucv_handler
*handler
;
1474 struct iucv_path
*path
;
1477 BUG_ON(iucv_path_table
[ipp
->ippathid
]);
1478 /* New pathid, handler found. Create a new path struct. */
1479 error
= iucv_error_no_memory
;
1480 path
= iucv_path_alloc(ipp
->ipmsglim
, ipp
->ipflags1
, GFP_ATOMIC
);
1483 path
->pathid
= ipp
->ippathid
;
1484 iucv_path_table
[path
->pathid
] = path
;
1485 EBCASC(ipp
->ipvmid
, 8);
1487 /* Call registered handler until one is found that wants the path. */
1488 list_for_each_entry(handler
, &iucv_handler_list
, list
) {
1489 if (!handler
->path_pending
)
1492 * Add path to handler to allow a call to iucv_path_sever
1493 * inside the path_pending function. If the handler returns
1494 * an error remove the path from the handler again.
1496 list_add(&path
->list
, &handler
->paths
);
1497 path
->handler
= handler
;
1498 if (!handler
->path_pending(path
, ipp
->ipvmid
, ipp
->ipuser
))
1500 list_del(&path
->list
);
1501 path
->handler
= NULL
;
1503 /* No handler wanted the path. */
1504 iucv_path_table
[path
->pathid
] = NULL
;
1505 iucv_path_free(path
);
1506 error
= iucv_error_no_listener
;
1508 iucv_sever_pathid(ipp
->ippathid
, error
);
1511 struct iucv_path_complete
{
1525 * iucv_path_complete
1526 * @data: Pointer to external interrupt buffer
1528 * Process connection complete work item. Called from tasklet while holding
1531 static void iucv_path_complete(struct iucv_irq_data
*data
)
1533 struct iucv_path_complete
*ipc
= (void *) data
;
1534 struct iucv_path
*path
= iucv_path_table
[ipc
->ippathid
];
1537 path
->flags
= ipc
->ipflags1
;
1538 if (path
&& path
->handler
&& path
->handler
->path_complete
)
1539 path
->handler
->path_complete(path
, ipc
->ipuser
);
1542 struct iucv_path_severed
{
1556 * @data: Pointer to external interrupt buffer
1558 * Process connection severed work item. Called from tasklet while holding
1561 static void iucv_path_severed(struct iucv_irq_data
*data
)
1563 struct iucv_path_severed
*ips
= (void *) data
;
1564 struct iucv_path
*path
= iucv_path_table
[ips
->ippathid
];
1566 if (!path
|| !path
->handler
) /* Already severed */
1568 if (path
->handler
->path_severed
)
1569 path
->handler
->path_severed(path
, ips
->ipuser
);
1571 iucv_sever_pathid(path
->pathid
, NULL
);
1572 iucv_path_table
[path
->pathid
] = NULL
;
1573 list_del(&path
->list
);
1574 iucv_path_free(path
);
1578 struct iucv_path_quiesced
{
1591 * iucv_path_quiesced
1592 * @data: Pointer to external interrupt buffer
1594 * Process connection quiesced work item. Called from tasklet while holding
1597 static void iucv_path_quiesced(struct iucv_irq_data
*data
)
1599 struct iucv_path_quiesced
*ipq
= (void *) data
;
1600 struct iucv_path
*path
= iucv_path_table
[ipq
->ippathid
];
1602 if (path
&& path
->handler
&& path
->handler
->path_quiesced
)
1603 path
->handler
->path_quiesced(path
, ipq
->ipuser
);
1606 struct iucv_path_resumed
{
1620 * @data: Pointer to external interrupt buffer
1622 * Process connection resumed work item. Called from tasklet while holding
1625 static void iucv_path_resumed(struct iucv_irq_data
*data
)
1627 struct iucv_path_resumed
*ipr
= (void *) data
;
1628 struct iucv_path
*path
= iucv_path_table
[ipr
->ippathid
];
1630 if (path
&& path
->handler
&& path
->handler
->path_resumed
)
1631 path
->handler
->path_resumed(path
, ipr
->ipuser
);
1634 struct iucv_message_complete
{
1650 * iucv_message_complete
1651 * @data: Pointer to external interrupt buffer
1653 * Process message complete work item. Called from tasklet while holding
1656 static void iucv_message_complete(struct iucv_irq_data
*data
)
1658 struct iucv_message_complete
*imc
= (void *) data
;
1659 struct iucv_path
*path
= iucv_path_table
[imc
->ippathid
];
1660 struct iucv_message msg
;
1662 if (path
&& path
->handler
&& path
->handler
->message_complete
) {
1663 msg
.flags
= imc
->ipflags1
;
1664 msg
.id
= imc
->ipmsgid
;
1665 msg
.audit
= imc
->ipaudit
;
1666 memcpy(msg
.rmmsg
, imc
->iprmmsg
, 8);
1667 msg
.class = imc
->ipsrccls
;
1668 msg
.tag
= imc
->ipmsgtag
;
1669 msg
.length
= imc
->ipbfln2f
;
1670 path
->handler
->message_complete(path
, &msg
);
1674 struct iucv_message_pending
{
1697 * iucv_message_pending
1698 * @data: Pointer to external interrupt buffer
1700 * Process message pending work item. Called from tasklet while holding
1703 static void iucv_message_pending(struct iucv_irq_data
*data
)
1705 struct iucv_message_pending
*imp
= (void *) data
;
1706 struct iucv_path
*path
= iucv_path_table
[imp
->ippathid
];
1707 struct iucv_message msg
;
1709 if (path
&& path
->handler
&& path
->handler
->message_pending
) {
1710 msg
.flags
= imp
->ipflags1
;
1711 msg
.id
= imp
->ipmsgid
;
1712 msg
.class = imp
->iptrgcls
;
1713 if (imp
->ipflags1
& IUCV_IPRMDATA
) {
1714 memcpy(msg
.rmmsg
, &imp
->rmmsg
, 8);
1717 msg
.length
= imp
->rmmsg
.ln1msg2
.ipbfln1f
;
1718 msg
.reply_size
= imp
->ipbfln2f
;
1719 path
->handler
->message_pending(path
, &msg
);
1726 * This tasklet loops over the queue of irq buffers created by
1727 * iucv_external_interrupt, calls the appropriate action handler
1728 * and then frees the buffer.
1730 static void iucv_tasklet_fn(unsigned long ignored
)
1732 typedef void iucv_irq_fn(struct iucv_irq_data
*);
1733 static iucv_irq_fn
*irq_fn
[] = {
1734 [0x02] = iucv_path_complete
,
1735 [0x03] = iucv_path_severed
,
1736 [0x04] = iucv_path_quiesced
,
1737 [0x05] = iucv_path_resumed
,
1738 [0x06] = iucv_message_complete
,
1739 [0x07] = iucv_message_complete
,
1740 [0x08] = iucv_message_pending
,
1741 [0x09] = iucv_message_pending
,
1743 LIST_HEAD(task_queue
);
1744 struct iucv_irq_list
*p
, *n
;
1746 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1747 if (!spin_trylock(&iucv_table_lock
)) {
1748 tasklet_schedule(&iucv_tasklet
);
1751 iucv_active_cpu
= smp_processor_id();
1753 spin_lock_irq(&iucv_queue_lock
);
1754 list_splice_init(&iucv_task_queue
, &task_queue
);
1755 spin_unlock_irq(&iucv_queue_lock
);
1757 list_for_each_entry_safe(p
, n
, &task_queue
, list
) {
1758 list_del_init(&p
->list
);
1759 irq_fn
[p
->data
.iptype
](&p
->data
);
1763 iucv_active_cpu
= -1;
1764 spin_unlock(&iucv_table_lock
);
1770 * This work function loops over the queue of path pending irq blocks
1771 * created by iucv_external_interrupt, calls the appropriate action
1772 * handler and then frees the buffer.
1774 static void iucv_work_fn(struct work_struct
*work
)
1776 LIST_HEAD(work_queue
);
1777 struct iucv_irq_list
*p
, *n
;
1779 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1780 spin_lock_bh(&iucv_table_lock
);
1781 iucv_active_cpu
= smp_processor_id();
1783 spin_lock_irq(&iucv_queue_lock
);
1784 list_splice_init(&iucv_work_queue
, &work_queue
);
1785 spin_unlock_irq(&iucv_queue_lock
);
1787 iucv_cleanup_queue();
1788 list_for_each_entry_safe(p
, n
, &work_queue
, list
) {
1789 list_del_init(&p
->list
);
1790 iucv_path_pending(&p
->data
);
1794 iucv_active_cpu
= -1;
1795 spin_unlock_bh(&iucv_table_lock
);
1799 * 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 struct iucv_interface iucv_if
= {
1838 .message_receive
= iucv_message_receive
,
1839 .__message_receive
= __iucv_message_receive
,
1840 .message_reply
= iucv_message_reply
,
1841 .message_reject
= iucv_message_reject
,
1842 .message_send
= iucv_message_send
,
1843 .__message_send
= __iucv_message_send
,
1844 .message_send2way
= iucv_message_send2way
,
1845 .message_purge
= iucv_message_purge
,
1846 .path_accept
= iucv_path_accept
,
1847 .path_connect
= iucv_path_connect
,
1848 .path_quiesce
= iucv_path_quiesce
,
1849 .path_resume
= iucv_path_resume
,
1850 .path_sever
= iucv_path_sever
,
1851 .iucv_register
= iucv_register
,
1852 .iucv_unregister
= iucv_unregister
,
1856 EXPORT_SYMBOL(iucv_if
);
1858 static enum cpuhp_state iucv_online
;
1862 * Allocates and initializes various data structures.
1864 static int __init
iucv_init(void)
1868 if (!MACHINE_IS_VM
) {
1869 rc
= -EPROTONOSUPPORT
;
1872 system_ctl_set_bit(0, CR0_IUCV_BIT
);
1873 rc
= iucv_query_maxconn();
1876 rc
= register_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
1879 iucv_root
= root_device_register("iucv");
1880 if (IS_ERR(iucv_root
)) {
1881 rc
= PTR_ERR(iucv_root
);
1885 rc
= cpuhp_setup_state(CPUHP_NET_IUCV_PREPARE
, "net/iucv:prepare",
1886 iucv_cpu_prepare
, iucv_cpu_dead
);
1889 rc
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "net/iucv:online",
1890 iucv_cpu_online
, iucv_cpu_down_prep
);
1895 rc
= register_reboot_notifier(&iucv_reboot_notifier
);
1898 ASCEBC(iucv_error_no_listener
, 16);
1899 ASCEBC(iucv_error_no_memory
, 16);
1900 ASCEBC(iucv_error_pathid
, 16);
1902 rc
= bus_register(&iucv_bus
);
1905 iucv_if
.root
= iucv_root
;
1906 iucv_if
.bus
= &iucv_bus
;
1910 unregister_reboot_notifier(&iucv_reboot_notifier
);
1912 cpuhp_remove_state(iucv_online
);
1914 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE
);
1916 root_device_unregister(iucv_root
);
1918 unregister_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
1920 system_ctl_clear_bit(0, 1);
1928 * Frees everything allocated from iucv_init.
1930 static void __exit
iucv_exit(void)
1932 struct iucv_irq_list
*p
, *n
;
1934 spin_lock_irq(&iucv_queue_lock
);
1935 list_for_each_entry_safe(p
, n
, &iucv_task_queue
, list
)
1937 list_for_each_entry_safe(p
, n
, &iucv_work_queue
, list
)
1939 spin_unlock_irq(&iucv_queue_lock
);
1940 unregister_reboot_notifier(&iucv_reboot_notifier
);
1942 cpuhp_remove_state_nocalls(iucv_online
);
1943 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE
);
1944 root_device_unregister(iucv_root
);
1945 bus_unregister(&iucv_bus
);
1946 unregister_external_irq(EXT_IRQ_IUCV
, iucv_external_interrupt
);
1949 subsys_initcall(iucv_init
);
1950 module_exit(iucv_exit
);
1952 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert <felfert@millenux.com>");
1953 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1954 MODULE_LICENSE("GPL");