Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / s390 / net / iucv.c
blobe0c7deb9883189f012d0b27d67c83db08317b01e
1 /*
2 * IUCV network driver
4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s):
6 * Original source:
7 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
8 * Xenia Tkatschow (xenia@us.ibm.com)
9 * 2Gb awareness and general cleanup:
10 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
12 * Documentation used:
13 * The original source
14 * CP Programming Service, IBM document # SC24-5760
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 /* #define DEBUG */
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/config.h>
38 #include <linux/spinlock.h>
39 #include <linux/kernel.h>
40 #include <linux/slab.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/list.h>
44 #include <linux/errno.h>
45 #include <linux/err.h>
46 #include <linux/device.h>
47 #include <asm/atomic.h>
48 #include "iucv.h"
49 #include <asm/io.h>
50 #include <asm/s390_ext.h>
51 #include <asm/ebcdic.h>
52 #include <asm/smp.h>
53 #include <asm/s390_rdev.h>
55 /* FLAGS:
56 * All flags are defined in the field IPFLAGS1 of each function
57 * and can be found in CP Programming Services.
58 * IPSRCCLS - Indicates you have specified a source class
59 * IPFGMCL - Indicates you have specified a target class
60 * IPFGPID - Indicates you have specified a pathid
61 * IPFGMID - Indicates you have specified a message ID
62 * IPANSLST - Indicates that you are using an address list for
63 * reply data
64 * IPBUFLST - Indicates that you are using an address list for
65 * message data
68 #define IPSRCCLS 0x01
69 #define IPFGMCL 0x01
70 #define IPFGPID 0x02
71 #define IPFGMID 0x04
72 #define IPANSLST 0x08
73 #define IPBUFLST 0x40
75 static int
76 iucv_bus_match (struct device *dev, struct device_driver *drv)
78 return 0;
81 struct bus_type iucv_bus = {
82 .name = "iucv",
83 .match = iucv_bus_match,
86 struct device *iucv_root;
88 /* General IUCV interrupt structure */
89 typedef struct {
90 __u16 ippathid;
91 __u8 res1;
92 __u8 iptype;
93 __u32 res2;
94 __u8 ipvmid[8];
95 __u8 res3[24];
96 } iucv_GeneralInterrupt;
98 static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
100 /* Spin Lock declaration */
102 static DEFINE_SPINLOCK(iucv_lock);
104 static int messagesDisabled = 0;
106 /***************INTERRUPT HANDLING ***************/
108 typedef struct {
109 struct list_head queue;
110 iucv_GeneralInterrupt data;
111 } iucv_irqdata;
113 static struct list_head iucv_irq_queue;
114 static DEFINE_SPINLOCK(iucv_irq_queue_lock);
117 *Internal function prototypes
119 static void iucv_tasklet_handler(unsigned long);
120 static void iucv_irq_handler(struct pt_regs *, __u16);
122 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
124 /************ FUNCTION ID'S ****************************/
126 #define ACCEPT 10
127 #define CONNECT 11
128 #define DECLARE_BUFFER 12
129 #define PURGE 9
130 #define QUERY 0
131 #define QUIESCE 13
132 #define RECEIVE 5
133 #define REJECT 8
134 #define REPLY 6
135 #define RESUME 14
136 #define RETRIEVE_BUFFER 2
137 #define SEND 4
138 #define SETMASK 16
139 #define SEVER 15
142 * Structure: handler
143 * members: list - list management.
144 * structure: id
145 * userid - 8 char array of machine identification
146 * user_data - 16 char array for user identification
147 * mask - 24 char array used to compare the 2 previous
148 * interrupt_table - vector of interrupt functions.
149 * pgm_data - ulong, application data that is passed
150 * to the interrupt handlers
152 typedef struct handler_t {
153 struct list_head list;
154 struct {
155 __u8 userid[8];
156 __u8 user_data[16];
157 __u8 mask[24];
158 } id;
159 iucv_interrupt_ops_t *interrupt_table;
160 void *pgm_data;
161 } handler;
164 * iucv_handler_table: List of registered handlers.
166 static struct list_head iucv_handler_table;
169 * iucv_pathid_table: an array of *handler pointing into
170 * iucv_handler_table for fast indexing by pathid;
172 static handler **iucv_pathid_table;
174 static unsigned long max_connections;
177 * iucv_cpuid: contains the logical cpu number of the cpu which
178 * has declared the iucv buffer by issuing DECLARE_BUFFER.
179 * If no cpu has done the initialization iucv_cpuid contains -1.
181 static int iucv_cpuid = -1;
183 * register_flag: is 0 when external interrupt has not been registered
185 static int register_flag;
187 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
188 /* Data struct 1: iparml_control
189 * Used for iucv_accept
190 * iucv_connect
191 * iucv_quiesce
192 * iucv_resume
193 * iucv_sever
194 * iucv_retrieve_buffer
195 * Data struct 2: iparml_dpl (data in parameter list)
196 * Used for iucv_send_prmmsg
197 * iucv_send2way_prmmsg
198 * iucv_send2way_prmmsg_array
199 * iucv_reply_prmmsg
200 * Data struct 3: iparml_db (data in a buffer)
201 * Used for iucv_receive
202 * iucv_receive_array
203 * iucv_reject
204 * iucv_reply
205 * iucv_reply_array
206 * iucv_send
207 * iucv_send_array
208 * iucv_send2way
209 * iucv_send2way_array
210 * iucv_declare_buffer
211 * Data struct 4: iparml_purge
212 * Used for iucv_purge
213 * iucv_query
214 * Data struct 5: iparml_set_mask
215 * Used for iucv_set_mask
218 typedef struct {
219 __u16 ippathid;
220 __u8 ipflags1;
221 __u8 iprcode;
222 __u16 ipmsglim;
223 __u16 res1;
224 __u8 ipvmid[8];
225 __u8 ipuser[16];
226 __u8 iptarget[8];
227 } iparml_control;
229 typedef struct {
230 __u16 ippathid;
231 __u8 ipflags1;
232 __u8 iprcode;
233 __u32 ipmsgid;
234 __u32 iptrgcls;
235 __u8 iprmmsg[8];
236 __u32 ipsrccls;
237 __u32 ipmsgtag;
238 __u32 ipbfadr2;
239 __u32 ipbfln2f;
240 __u32 res;
241 } iparml_dpl;
243 typedef struct {
244 __u16 ippathid;
245 __u8 ipflags1;
246 __u8 iprcode;
247 __u32 ipmsgid;
248 __u32 iptrgcls;
249 __u32 ipbfadr1;
250 __u32 ipbfln1f;
251 __u32 ipsrccls;
252 __u32 ipmsgtag;
253 __u32 ipbfadr2;
254 __u32 ipbfln2f;
255 __u32 res;
256 } iparml_db;
258 typedef struct {
259 __u16 ippathid;
260 __u8 ipflags1;
261 __u8 iprcode;
262 __u32 ipmsgid;
263 __u8 ipaudit[3];
264 __u8 res1[5];
265 __u32 res2;
266 __u32 ipsrccls;
267 __u32 ipmsgtag;
268 __u32 res3[3];
269 } iparml_purge;
271 typedef struct {
272 __u8 ipmask;
273 __u8 res1[2];
274 __u8 iprcode;
275 __u32 res2[9];
276 } iparml_set_mask;
278 typedef struct {
279 union {
280 iparml_control p_ctrl;
281 iparml_dpl p_dpl;
282 iparml_db p_db;
283 iparml_purge p_purge;
284 iparml_set_mask p_set_mask;
285 } param;
286 atomic_t in_use;
287 __u32 res;
288 } __attribute__ ((aligned(8))) iucv_param;
289 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
291 static iucv_param * iucv_param_pool;
293 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
294 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
295 MODULE_LICENSE("GPL");
298 * Debugging stuff
299 *******************************************************************************/
302 #ifdef DEBUG
303 static int debuglevel = 0;
305 module_param(debuglevel, int, 0);
306 MODULE_PARM_DESC(debuglevel,
307 "Specifies the debug level (0=off ... 3=all)");
309 static void
310 iucv_dumpit(char *title, void *buf, int len)
312 int i;
313 __u8 *p = (__u8 *)buf;
315 if (debuglevel < 3)
316 return;
318 printk(KERN_DEBUG "%s\n", title);
319 printk(" ");
320 for (i = 0; i < len; i++) {
321 if (!(i % 16) && i != 0)
322 printk ("\n ");
323 else if (!(i % 4) && i != 0)
324 printk(" ");
325 printk("%02X", *p++);
327 if (len % 16)
328 printk ("\n");
329 return;
331 #define iucv_debug(lvl, fmt, args...) \
332 do { \
333 if (debuglevel >= lvl) \
334 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
335 } while (0)
337 #else
339 #define iucv_debug(lvl, fmt, args...)
340 #define iucv_dumpit(title, buf, len)
342 #endif
345 * Internal functions
346 *******************************************************************************/
349 * print start banner
351 static void
352 iucv_banner(void)
354 printk(KERN_INFO "IUCV lowlevel driver initialized\n");
358 * iucv_init - Initialization
360 * Allocates and initializes various data structures.
362 static int
363 iucv_init(void)
365 int ret;
367 if (iucv_external_int_buffer)
368 return 0;
370 if (!MACHINE_IS_VM) {
371 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
372 return -EPROTONOSUPPORT;
375 ret = bus_register(&iucv_bus);
376 if (ret) {
377 printk(KERN_ERR "IUCV: failed to register bus.\n");
378 return ret;
381 iucv_root = s390_root_dev_register("iucv");
382 if (IS_ERR(iucv_root)) {
383 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
384 bus_unregister(&iucv_bus);
385 return PTR_ERR(iucv_root);
388 /* Note: GFP_DMA used used to get memory below 2G */
389 iucv_external_int_buffer = kzalloc(sizeof(iucv_GeneralInterrupt),
390 GFP_KERNEL|GFP_DMA);
391 if (!iucv_external_int_buffer) {
392 printk(KERN_WARNING
393 "%s: Could not allocate external interrupt buffer\n",
394 __FUNCTION__);
395 s390_root_dev_unregister(iucv_root);
396 bus_unregister(&iucv_bus);
397 return -ENOMEM;
400 /* Initialize parameter pool */
401 iucv_param_pool = kzalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
402 GFP_KERNEL|GFP_DMA);
403 if (!iucv_param_pool) {
404 printk(KERN_WARNING "%s: Could not allocate param pool\n",
405 __FUNCTION__);
406 kfree(iucv_external_int_buffer);
407 iucv_external_int_buffer = NULL;
408 s390_root_dev_unregister(iucv_root);
409 bus_unregister(&iucv_bus);
410 return -ENOMEM;
413 /* Initialize irq queue */
414 INIT_LIST_HEAD(&iucv_irq_queue);
416 /* Initialize handler table */
417 INIT_LIST_HEAD(&iucv_handler_table);
419 iucv_banner();
420 return 0;
424 * iucv_exit - De-Initialization
426 * Frees everything allocated from iucv_init.
428 static int iucv_retrieve_buffer (void);
430 static void
431 iucv_exit(void)
433 iucv_retrieve_buffer();
434 kfree(iucv_external_int_buffer);
435 iucv_external_int_buffer = NULL;
436 kfree(iucv_param_pool);
437 iucv_param_pool = NULL;
438 s390_root_dev_unregister(iucv_root);
439 bus_unregister(&iucv_bus);
440 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
444 * grab_param: - Get a parameter buffer from the pre-allocated pool.
446 * This function searches for an unused element in the pre-allocated pool
447 * of parameter buffers. If one is found, it marks it "in use" and returns
448 * a pointer to it. The calling function is responsible for releasing it
449 * when it has finished its usage.
451 * Returns: A pointer to iucv_param.
453 static __inline__ iucv_param *
454 grab_param(void)
456 iucv_param *ptr;
457 static int hint = 0;
459 ptr = iucv_param_pool + hint;
460 do {
461 ptr++;
462 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
463 ptr = iucv_param_pool;
464 } while (atomic_cmpxchg(&ptr->in_use, 0, 1) != 0);
465 hint = ptr - iucv_param_pool;
467 memset(&ptr->param, 0, sizeof(ptr->param));
468 return ptr;
472 * release_param - Release a parameter buffer.
473 * @p: A pointer to a struct iucv_param, previously obtained by calling
474 * grab_param().
476 * This function marks the specified parameter buffer "unused".
478 static __inline__ void
479 release_param(void *p)
481 atomic_set(&((iucv_param *)p)->in_use, 0);
485 * iucv_add_handler: - Add a new handler
486 * @new_handler: handle that is being entered into chain.
488 * Places new handle on iucv_handler_table, if identical handler is not
489 * found.
491 * Returns: 0 on success, !0 on failure (handler already in chain).
493 static int
494 iucv_add_handler (handler *new)
496 ulong flags;
498 iucv_debug(1, "entering");
499 iucv_dumpit("handler:", new, sizeof(handler));
501 spin_lock_irqsave (&iucv_lock, flags);
502 if (!list_empty(&iucv_handler_table)) {
503 struct list_head *lh;
506 * Search list for handler with identical id. If one
507 * is found, the new handler is _not_ added.
509 list_for_each(lh, &iucv_handler_table) {
510 handler *h = list_entry(lh, handler, list);
511 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
512 iucv_debug(1, "ret 1");
513 spin_unlock_irqrestore (&iucv_lock, flags);
514 return 1;
519 * If we get here, no handler was found.
521 INIT_LIST_HEAD(&new->list);
522 list_add(&new->list, &iucv_handler_table);
523 spin_unlock_irqrestore (&iucv_lock, flags);
525 iucv_debug(1, "exiting");
526 return 0;
530 * b2f0:
531 * @code: identifier of IUCV call to CP.
532 * @parm: pointer to 40 byte iparml area passed to CP
534 * Calls CP to execute IUCV commands.
536 * Returns: return code from CP's IUCV call
538 static __inline__ ulong
539 b2f0(__u32 code, void *parm)
541 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
543 asm volatile (
544 "LRA 1,0(%1)\n\t"
545 "LR 0,%0\n\t"
546 ".long 0xb2f01000"
548 : "d" (code), "a" (parm)
549 : "0", "1"
552 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
554 return (unsigned long)*((__u8 *)(parm + 3));
558 * Name: iucv_add_pathid
559 * Purpose: Adds a path id to the system.
560 * Input: pathid - pathid that is going to be entered into system
561 * handle - address of handler that the pathid will be associated
562 * with.
563 * pgm_data - token passed in by application.
564 * Output: 0: successful addition of pathid
565 * - EINVAL - pathid entry is being used by another application
566 * - ENOMEM - storage allocation for a new pathid table failed
568 static int
569 __iucv_add_pathid(__u16 pathid, handler *handler)
572 iucv_debug(1, "entering");
574 iucv_debug(1, "handler is pointing to %p", handler);
576 if (pathid > (max_connections - 1))
577 return -EINVAL;
579 if (iucv_pathid_table[pathid]) {
580 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
581 printk(KERN_WARNING
582 "%s: Pathid being used, error.\n", __FUNCTION__);
583 return -EINVAL;
585 iucv_pathid_table[pathid] = handler;
587 iucv_debug(1, "exiting");
588 return 0;
589 } /* end of add_pathid function */
591 static int
592 iucv_add_pathid(__u16 pathid, handler *handler)
594 ulong flags;
595 int rc;
597 spin_lock_irqsave (&iucv_lock, flags);
598 rc = __iucv_add_pathid(pathid, handler);
599 spin_unlock_irqrestore (&iucv_lock, flags);
600 return rc;
603 static void
604 iucv_remove_pathid(__u16 pathid)
606 ulong flags;
608 if (pathid > (max_connections - 1))
609 return;
611 spin_lock_irqsave (&iucv_lock, flags);
612 iucv_pathid_table[pathid] = NULL;
613 spin_unlock_irqrestore (&iucv_lock, flags);
617 * iucv_declare_buffer_cpuid
618 * Register at VM for subsequent IUCV operations. This is executed
619 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
621 static void
622 iucv_declare_buffer_cpuid (void *result)
624 iparml_db *parm;
626 parm = (iparml_db *)grab_param();
627 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
628 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
629 *((ulong *)result) = parm->iprcode;
630 release_param(parm);
634 * iucv_retrieve_buffer_cpuid:
635 * Unregister IUCV usage at VM. This is always executed on the same
636 * cpu that registered the buffer to VM.
637 * Called from iucv_retrieve_buffer().
639 static void
640 iucv_retrieve_buffer_cpuid (void *cpu)
642 iparml_control *parm;
644 parm = (iparml_control *)grab_param();
645 b2f0(RETRIEVE_BUFFER, parm);
646 release_param(parm);
650 * Name: iucv_declare_buffer
651 * Purpose: Specifies the guests real address of an external
652 * interrupt.
653 * Input: void
654 * Output: iprcode - return code from b2f0 call
656 static int
657 iucv_declare_buffer (void)
659 unsigned long flags;
660 ulong b2f0_result;
662 iucv_debug(1, "entering");
663 b2f0_result = -ENODEV;
664 spin_lock_irqsave (&iucv_lock, flags);
665 if (iucv_cpuid == -1) {
666 /* Reserve any cpu for use by iucv. */
667 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
668 spin_unlock_irqrestore (&iucv_lock, flags);
669 smp_call_function_on(iucv_declare_buffer_cpuid,
670 &b2f0_result, 0, 1, iucv_cpuid);
671 if (b2f0_result) {
672 smp_put_cpu(iucv_cpuid);
673 iucv_cpuid = -1;
675 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
676 } else {
677 spin_unlock_irqrestore (&iucv_lock, flags);
678 b2f0_result = 0;
680 iucv_debug(1, "exiting");
681 return b2f0_result;
685 * iucv_retrieve_buffer:
687 * Terminates all use of IUCV.
688 * Returns: return code from CP
690 static int
691 iucv_retrieve_buffer (void)
693 iucv_debug(1, "entering");
694 if (iucv_cpuid != -1) {
695 smp_call_function_on(iucv_retrieve_buffer_cpuid,
696 0, 0, 1, iucv_cpuid);
697 /* Release the cpu reserved by iucv_declare_buffer. */
698 smp_put_cpu(iucv_cpuid);
699 iucv_cpuid = -1;
701 iucv_debug(1, "exiting");
702 return 0;
706 * iucv_remove_handler:
707 * @users_handler: handler to be removed
709 * Remove handler when application unregisters.
711 static void
712 iucv_remove_handler(handler *handler)
714 unsigned long flags;
716 if ((!iucv_pathid_table) || (!handler))
717 return;
719 iucv_debug(1, "entering");
721 spin_lock_irqsave (&iucv_lock, flags);
722 list_del(&handler->list);
723 if (list_empty(&iucv_handler_table)) {
724 if (register_flag) {
725 unregister_external_interrupt(0x4000, iucv_irq_handler);
726 register_flag = 0;
729 spin_unlock_irqrestore (&iucv_lock, flags);
731 iucv_debug(1, "exiting");
732 return;
736 * iucv_register_program:
737 * @pgmname: user identification
738 * @userid: machine identification
739 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
740 * used to determine who is given control.
741 * @ops: Address of interrupt handler table.
742 * @pgm_data: Application data to be passed to interrupt handlers.
744 * Registers an application with IUCV.
745 * Returns:
746 * The address of handler, or NULL on failure.
747 * NOTE on pgmmask:
748 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
749 * handler as is.
750 * If pgmmask is NULL, the internal mask is set to all 0xff's
751 * When userid is NULL, the first 8 bytes of the internal mask are forced
752 * to 0x00.
753 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
754 * are forced to 0x00 and the last 16 bytes to 0xff.
757 iucv_handle_t
758 iucv_register_program (__u8 pgmname[16],
759 __u8 userid[8],
760 __u8 pgmmask[24],
761 iucv_interrupt_ops_t * ops, void *pgm_data)
763 ulong rc = 0; /* return code from function calls */
764 handler *new_handler;
766 iucv_debug(1, "entering");
768 if (ops == NULL) {
769 /* interrupt table is not defined */
770 printk(KERN_WARNING "%s: Interrupt table is not defined, "
771 "exiting\n", __FUNCTION__);
772 return NULL;
774 if (!pgmname) {
775 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
776 return NULL;
779 /* Allocate handler entry */
780 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
781 if (new_handler == NULL) {
782 printk(KERN_WARNING "%s: storage allocation for new handler "
783 "failed.\n", __FUNCTION__);
784 return NULL;
787 if (!iucv_pathid_table) {
788 if (iucv_init()) {
789 kfree(new_handler);
790 return NULL;
793 max_connections = iucv_query_maxconn();
794 iucv_pathid_table = kcalloc(max_connections, sizeof(handler *),
795 GFP_ATOMIC);
796 if (iucv_pathid_table == NULL) {
797 printk(KERN_WARNING "%s: iucv_pathid_table storage "
798 "allocation failed\n", __FUNCTION__);
799 kfree(new_handler);
800 return NULL;
803 memset(new_handler, 0, sizeof (handler));
804 memcpy(new_handler->id.user_data, pgmname,
805 sizeof (new_handler->id.user_data));
806 if (userid) {
807 memcpy (new_handler->id.userid, userid,
808 sizeof (new_handler->id.userid));
809 ASCEBC (new_handler->id.userid,
810 sizeof (new_handler->id.userid));
811 EBC_TOUPPER (new_handler->id.userid,
812 sizeof (new_handler->id.userid));
814 if (pgmmask) {
815 memcpy (new_handler->id.mask, pgmmask,
816 sizeof (new_handler->id.mask));
817 } else {
818 memset (new_handler->id.mask, 0xFF,
819 sizeof (new_handler->id.mask));
821 } else {
822 if (pgmmask) {
823 memcpy (new_handler->id.mask, pgmmask,
824 sizeof (new_handler->id.mask));
825 } else {
826 memset (new_handler->id.mask, 0xFF,
827 sizeof (new_handler->id.mask));
829 memset (new_handler->id.userid, 0x00,
830 sizeof (new_handler->id.userid));
832 /* fill in the rest of handler */
833 new_handler->pgm_data = pgm_data;
834 new_handler->interrupt_table = ops;
837 * Check if someone else is registered with same pgmname, userid
838 * and mask. If someone is already registered with same pgmname,
839 * userid and mask, registration will fail and NULL will be returned
840 * to the application.
841 * If identical handler not found, then handler is added to list.
843 rc = iucv_add_handler(new_handler);
844 if (rc) {
845 printk(KERN_WARNING "%s: Someone already registered with same "
846 "pgmname, userid, pgmmask\n", __FUNCTION__);
847 kfree (new_handler);
848 return NULL;
851 rc = iucv_declare_buffer();
852 if (rc) {
853 char *err = "Unknown";
854 iucv_remove_handler(new_handler);
855 kfree(new_handler);
856 switch(rc) {
857 case 0x03:
858 err = "Directory error";
859 break;
860 case 0x0a:
861 err = "Invalid length";
862 break;
863 case 0x13:
864 err = "Buffer already exists";
865 break;
866 case 0x3e:
867 err = "Buffer overlap";
868 break;
869 case 0x5c:
870 err = "Paging or storage error";
871 break;
873 printk(KERN_WARNING "%s: iucv_declare_buffer "
874 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
875 return NULL;
877 if (!register_flag) {
878 /* request the 0x4000 external interrupt */
879 rc = register_external_interrupt (0x4000, iucv_irq_handler);
880 if (rc) {
881 iucv_remove_handler(new_handler);
882 kfree (new_handler);
883 printk(KERN_WARNING "%s: "
884 "register_external_interrupt returned %ld\n",
885 __FUNCTION__, rc);
886 return NULL;
889 register_flag = 1;
891 iucv_debug(1, "exiting");
892 return new_handler;
893 } /* end of register function */
896 * iucv_unregister_program:
897 * @handle: address of handler
899 * Unregister application with IUCV.
900 * Returns:
901 * 0 on success, -EINVAL, if specified handle is invalid.
905 iucv_unregister_program (iucv_handle_t handle)
907 handler *h = NULL;
908 struct list_head *lh;
909 int i;
910 ulong flags;
912 iucv_debug(1, "entering");
913 iucv_debug(1, "address of handler is %p", h);
915 /* Checking if handle is valid */
916 spin_lock_irqsave (&iucv_lock, flags);
917 list_for_each(lh, &iucv_handler_table) {
918 if ((handler *)handle == list_entry(lh, handler, list)) {
919 h = (handler *)handle;
920 break;
923 if (!h) {
924 spin_unlock_irqrestore (&iucv_lock, flags);
925 if (handle)
926 printk(KERN_WARNING
927 "%s: Handler not found in iucv_handler_table.\n",
928 __FUNCTION__);
929 else
930 printk(KERN_WARNING
931 "%s: NULL handle passed by application.\n",
932 __FUNCTION__);
933 return -EINVAL;
937 * First, walk thru iucv_pathid_table and sever any pathid which is
938 * still pointing to the handler to be removed.
940 for (i = 0; i < max_connections; i++)
941 if (iucv_pathid_table[i] == h) {
942 spin_unlock_irqrestore (&iucv_lock, flags);
943 iucv_sever(i, h->id.user_data);
944 spin_lock_irqsave(&iucv_lock, flags);
946 spin_unlock_irqrestore (&iucv_lock, flags);
948 iucv_remove_handler(h);
949 kfree(h);
951 iucv_debug(1, "exiting");
952 return 0;
956 * iucv_accept:
957 * @pathid: Path identification number
958 * @msglim_reqstd: The number of outstanding messages requested.
959 * @user_data: Data specified by the iucv_connect function.
960 * @flags1: Contains options for this path.
961 * - IPPRTY (0x20) Specifies if you want to send priority message.
962 * - IPRMDATA (0x80) Specifies whether your program can handle a message
963 * in the parameter list.
964 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
965 * established.
966 * @handle: Address of handler.
967 * @pgm_data: Application data passed to interrupt handlers.
968 * @flags1_out: Pointer to an int. If not NULL, on return the options for
969 * the path are stored at the given location:
970 * - IPPRTY (0x20) Indicates you may send a priority message.
971 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
972 * number of outstanding messages is stored at the given
973 * location.
975 * This function is issued after the user receives a Connection Pending external
976 * interrupt and now wishes to complete the IUCV communication path.
977 * Returns:
978 * return code from CP
981 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
982 __u8 user_data[16], int flags1,
983 iucv_handle_t handle, void *pgm_data,
984 int *flags1_out, __u16 * msglim)
986 ulong b2f0_result = 0;
987 ulong flags;
988 struct list_head *lh;
989 handler *h = NULL;
990 iparml_control *parm;
992 iucv_debug(1, "entering");
993 iucv_debug(1, "pathid = %d", pathid);
995 /* Checking if handle is valid */
996 spin_lock_irqsave (&iucv_lock, flags);
997 list_for_each(lh, &iucv_handler_table) {
998 if ((handler *)handle == list_entry(lh, handler, list)) {
999 h = (handler *)handle;
1000 break;
1003 spin_unlock_irqrestore (&iucv_lock, flags);
1005 if (!h) {
1006 if (handle)
1007 printk(KERN_WARNING
1008 "%s: Handler not found in iucv_handler_table.\n",
1009 __FUNCTION__);
1010 else
1011 printk(KERN_WARNING
1012 "%s: NULL handle passed by application.\n",
1013 __FUNCTION__);
1014 return -EINVAL;
1017 parm = (iparml_control *)grab_param();
1019 parm->ippathid = pathid;
1020 parm->ipmsglim = msglim_reqstd;
1021 if (user_data)
1022 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1024 parm->ipflags1 = (__u8)flags1;
1025 b2f0_result = b2f0(ACCEPT, parm);
1027 if (!b2f0_result) {
1028 if (msglim)
1029 *msglim = parm->ipmsglim;
1030 if (pgm_data)
1031 h->pgm_data = pgm_data;
1032 if (flags1_out)
1033 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1035 release_param(parm);
1037 iucv_debug(1, "exiting");
1038 return b2f0_result;
1042 * iucv_connect:
1043 * @pathid: Path identification number
1044 * @msglim_reqstd: Number of outstanding messages requested
1045 * @user_data: 16-byte user data
1046 * @userid: 8-byte of user identification
1047 * @system_name: 8-byte identifying the system name
1048 * @flags1: Specifies options for this path:
1049 * - IPPRTY (0x20) Specifies if you want to send priority message.
1050 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1051 * in the parameter list.
1052 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1053 * established.
1054 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1055 * local system. If local is specified then target class
1056 * cannot be specified.
1057 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1058 * the path are stored at the given location:
1059 * - IPPRTY (0x20) Indicates you may send a priority message.
1060 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1061 * number of outstanding messages is stored at the given
1062 * location.
1063 * @handle: Address of handler.
1064 * @pgm_data: Application data to be passed to interrupt handlers.
1066 * This function establishes an IUCV path. Although the connect may complete
1067 * successfully, you are not able to use the path until you receive an IUCV
1068 * Connection Complete external interrupt.
1069 * Returns: return code from CP, or one of the following
1070 * - ENOMEM
1071 * - return code from iucv_declare_buffer
1072 * - EINVAL - invalid handle passed by application
1073 * - EINVAL - pathid address is NULL
1074 * - ENOMEM - pathid table storage allocation failed
1075 * - return code from internal function add_pathid
1078 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1079 __u8 user_data[16], __u8 userid[8],
1080 __u8 system_name[8], int flags1,
1081 int *flags1_out, __u16 * msglim,
1082 iucv_handle_t handle, void *pgm_data)
1084 iparml_control *parm;
1085 iparml_control local_parm;
1086 struct list_head *lh;
1087 ulong b2f0_result = 0;
1088 ulong flags;
1089 int add_pathid_result = 0;
1090 handler *h = NULL;
1091 __u8 no_memory[16] = "NO MEMORY";
1093 iucv_debug(1, "entering");
1095 /* Checking if handle is valid */
1096 spin_lock_irqsave (&iucv_lock, flags);
1097 list_for_each(lh, &iucv_handler_table) {
1098 if ((handler *)handle == list_entry(lh, handler, list)) {
1099 h = (handler *)handle;
1100 break;
1103 spin_unlock_irqrestore (&iucv_lock, flags);
1105 if (!h) {
1106 if (handle)
1107 printk(KERN_WARNING
1108 "%s: Handler not found in iucv_handler_table.\n",
1109 __FUNCTION__);
1110 else
1111 printk(KERN_WARNING
1112 "%s: NULL handle passed by application.\n",
1113 __FUNCTION__);
1114 return -EINVAL;
1117 if (pathid == NULL) {
1118 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1119 __FUNCTION__);
1120 return -EINVAL;
1123 parm = (iparml_control *)grab_param();
1125 parm->ipmsglim = msglim_reqstd;
1127 if (user_data)
1128 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1130 if (userid) {
1131 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1132 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1133 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1136 if (system_name) {
1137 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1138 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1139 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1142 /* In order to establish an IUCV connection, the procedure is:
1144 * b2f0(CONNECT)
1145 * take the ippathid from the b2f0 call
1146 * register the handler to the ippathid
1148 * Unfortunately, the ConnectionEstablished message gets sent after the
1149 * b2f0(CONNECT) call but before the register is handled.
1151 * In order for this race condition to be eliminated, the IUCV Control
1152 * Interrupts must be disabled for the above procedure.
1154 * David Kennedy <dkennedy@linuxcare.com>
1157 /* Enable everything but IUCV Control messages */
1158 iucv_setmask(~(AllInterrupts));
1159 messagesDisabled = 1;
1161 spin_lock_irqsave (&iucv_lock, flags);
1162 parm->ipflags1 = (__u8)flags1;
1163 b2f0_result = b2f0(CONNECT, parm);
1164 memcpy(&local_parm, parm, sizeof(local_parm));
1165 release_param(parm);
1166 parm = &local_parm;
1167 if (!b2f0_result)
1168 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1169 spin_unlock_irqrestore (&iucv_lock, flags);
1171 if (b2f0_result) {
1172 iucv_setmask(~0);
1173 messagesDisabled = 0;
1174 return b2f0_result;
1177 *pathid = parm->ippathid;
1179 /* Enable everything again */
1180 iucv_setmask(IUCVControlInterruptsFlag);
1182 if (msglim)
1183 *msglim = parm->ipmsglim;
1184 if (flags1_out)
1185 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1187 if (add_pathid_result) {
1188 iucv_sever(*pathid, no_memory);
1189 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1190 " %d\n", __FUNCTION__, add_pathid_result);
1191 return(add_pathid_result);
1194 iucv_debug(1, "exiting");
1195 return b2f0_result;
1199 * iucv_purge:
1200 * @pathid: Path identification number
1201 * @msgid: Message ID of message to purge.
1202 * @srccls: Message class of the message to purge.
1203 * @audit: Pointer to an __u32. If not NULL, on return, information about
1204 * asynchronous errors that may have affected the normal completion
1205 * of this message ist stored at the given location.
1207 * Cancels a message you have sent.
1208 * Returns: return code from CP
1211 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1213 iparml_purge *parm;
1214 ulong b2f0_result = 0;
1216 iucv_debug(1, "entering");
1217 iucv_debug(1, "pathid = %d", pathid);
1219 parm = (iparml_purge *)grab_param();
1221 parm->ipmsgid = msgid;
1222 parm->ippathid = pathid;
1223 parm->ipsrccls = srccls;
1224 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1225 b2f0_result = b2f0(PURGE, parm);
1227 if (!b2f0_result && audit) {
1228 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1229 /* parm->ipaudit has only 3 bytes */
1230 *audit >>= 8;
1233 release_param(parm);
1235 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1236 iucv_debug(1, "exiting");
1237 return b2f0_result;
1241 * iucv_query_generic:
1242 * @want_maxconn: Flag, describing which value is to be returned.
1244 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1246 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1247 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1249 static int
1250 iucv_query_generic(int want_maxconn)
1252 iparml_purge *parm = (iparml_purge *)grab_param();
1253 int bufsize, maxconn;
1254 int ccode;
1257 * Call b2f0 and store R0 (max buffer size),
1258 * R1 (max connections) and CC.
1260 asm volatile (
1261 "LRA 1,0(%4)\n\t"
1262 "LR 0,%3\n\t"
1263 ".long 0xb2f01000\n\t"
1264 "IPM %0\n\t"
1265 "SRL %0,28\n\t"
1266 "ST 0,%1\n\t"
1267 "ST 1,%2\n\t"
1268 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1269 : "d" (QUERY), "a" (parm)
1270 : "0", "1", "cc"
1272 release_param(parm);
1274 if (ccode)
1275 return -EPERM;
1276 if (want_maxconn)
1277 return maxconn;
1278 return bufsize;
1282 * iucv_query_maxconn:
1284 * Determines the maximum number of connections thay may be established.
1286 * Returns: Maximum number of connections that can be.
1288 ulong
1289 iucv_query_maxconn(void)
1291 return iucv_query_generic(1);
1295 * iucv_query_bufsize:
1297 * Determines the size of the external interrupt buffer.
1299 * Returns: Size of external interrupt buffer.
1301 ulong
1302 iucv_query_bufsize (void)
1304 return iucv_query_generic(0);
1308 * iucv_quiesce:
1309 * @pathid: Path identification number
1310 * @user_data: 16-byte user data
1312 * Temporarily suspends incoming messages on an IUCV path.
1313 * You can later reactivate the path by invoking the iucv_resume function.
1314 * Returns: return code from CP
1317 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1319 iparml_control *parm;
1320 ulong b2f0_result = 0;
1322 iucv_debug(1, "entering");
1323 iucv_debug(1, "pathid = %d", pathid);
1325 parm = (iparml_control *)grab_param();
1327 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1328 parm->ippathid = pathid;
1330 b2f0_result = b2f0(QUIESCE, parm);
1331 release_param(parm);
1333 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1334 iucv_debug(1, "exiting");
1336 return b2f0_result;
1340 * iucv_receive:
1341 * @pathid: Path identification number.
1342 * @buffer: Address of buffer to receive. Must be below 2G.
1343 * @buflen: Length of buffer to receive.
1344 * @msgid: Specifies the message ID.
1345 * @trgcls: Specifies target class.
1346 * @flags1_out: Receives options for path on return.
1347 * - IPNORPY (0x10) Specifies whether a reply is required
1348 * - IPPRTY (0x20) Specifies if you want to send priority message
1349 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1350 * @residual_buffer: Receives the address of buffer updated by the number
1351 * of bytes you have received on return.
1352 * @residual_length: On return, receives one of the following values:
1353 * - 0 If the receive buffer is the same length as
1354 * the message.
1355 * - Remaining bytes in buffer If the receive buffer is longer than the
1356 * message.
1357 * - Remaining bytes in message If the receive buffer is shorter than the
1358 * message.
1360 * This function receives messages that are being sent to you over established
1361 * paths.
1362 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1363 * than the message, always 5
1364 * -EINVAL - buffer address is pointing to NULL
1367 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1368 void *buffer, ulong buflen,
1369 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1371 iparml_db *parm;
1372 ulong b2f0_result;
1373 int moved = 0; /* number of bytes moved from parmlist to buffer */
1375 iucv_debug(2, "entering");
1377 if (!buffer)
1378 return -EINVAL;
1380 parm = (iparml_db *)grab_param();
1382 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1383 parm->ipbfln1f = (__u32) ((ulong) buflen);
1384 parm->ipmsgid = msgid;
1385 parm->ippathid = pathid;
1386 parm->iptrgcls = trgcls;
1387 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1389 b2f0_result = b2f0(RECEIVE, parm);
1391 if (!b2f0_result || b2f0_result == 5) {
1392 if (flags1_out) {
1393 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1394 *flags1_out = (parm->ipflags1 & (~0x07));
1395 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1398 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1399 if (residual_length)
1400 *residual_length = parm->ipbfln1f;
1402 if (residual_buffer)
1403 *residual_buffer = parm->ipbfadr1;
1404 } else {
1405 moved = min_t (unsigned long, buflen, 8);
1407 memcpy ((char *) buffer,
1408 (char *) &parm->ipbfadr1, moved);
1410 if (buflen < 8)
1411 b2f0_result = 5;
1413 if (residual_length)
1414 *residual_length = abs (buflen - 8);
1416 if (residual_buffer)
1417 *residual_buffer = (ulong) (buffer + moved);
1420 release_param(parm);
1422 iucv_debug(2, "exiting");
1423 return b2f0_result;
1427 * Name: iucv_receive_array
1428 * Purpose: This function receives messages that are being sent to you
1429 * over established paths.
1430 * Input: pathid - path identification number
1431 * buffer - address of array of buffers
1432 * buflen - total length of buffers
1433 * msgid - specifies the message ID.
1434 * trgcls - specifies target class
1435 * Output:
1436 * flags1_out: Options for path.
1437 * IPNORPY - 0x10 specifies whether a reply is required
1438 * IPPRTY - 0x20 specifies if you want to send priority message
1439 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1440 * residual_buffer - address points to the current list entry IUCV
1441 * is working on.
1442 * residual_length -
1443 * Contains one of the following values, if the receive buffer is:
1444 * The same length as the message, this field is zero.
1445 * Longer than the message, this field contains the number of
1446 * bytes remaining in the buffer.
1447 * Shorter than the message, this field contains the residual
1448 * count (that is, the number of bytes remaining in the
1449 * message that does not fit into the buffer. In this case
1450 * b2f0_result = 5.
1451 * Return: b2f0_result - return code from CP
1452 * (-EINVAL) - buffer address is NULL
1455 iucv_receive_array (__u16 pathid,
1456 __u32 msgid, __u32 trgcls,
1457 iucv_array_t * buffer, ulong buflen,
1458 int *flags1_out,
1459 ulong * residual_buffer, ulong * residual_length)
1461 iparml_db *parm;
1462 ulong b2f0_result;
1463 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1465 iucv_debug(2, "entering");
1467 if (!buffer)
1468 return -EINVAL;
1470 parm = (iparml_db *)grab_param();
1472 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1473 parm->ipbfln1f = (__u32) buflen;
1474 parm->ipmsgid = msgid;
1475 parm->ippathid = pathid;
1476 parm->iptrgcls = trgcls;
1477 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1479 b2f0_result = b2f0(RECEIVE, parm);
1481 if (!b2f0_result || b2f0_result == 5) {
1483 if (flags1_out) {
1484 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1485 *flags1_out = (parm->ipflags1 & (~0x07));
1486 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1489 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1491 if (residual_length)
1492 *residual_length = parm->ipbfln1f;
1494 if (residual_buffer)
1495 *residual_buffer = parm->ipbfadr1;
1497 } else {
1498 /* copy msg from parmlist to users array. */
1500 while ((moved < 8) && (moved < buflen)) {
1501 dyn_len =
1502 min_t (unsigned int,
1503 (buffer + i)->length, need_to_move);
1505 memcpy ((char *)((ulong)((buffer + i)->address)),
1506 ((char *) &parm->ipbfadr1) + moved,
1507 dyn_len);
1509 moved += dyn_len;
1510 need_to_move -= dyn_len;
1512 (buffer + i)->address =
1513 (__u32)
1514 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1515 + dyn_len);
1517 (buffer + i)->length -= dyn_len;
1518 i++;
1521 if (need_to_move) /* buflen < 8 bytes */
1522 b2f0_result = 5;
1524 if (residual_length)
1525 *residual_length = abs (buflen - 8);
1527 if (residual_buffer) {
1528 if (!moved)
1529 *residual_buffer = (ulong) buffer;
1530 else
1531 *residual_buffer =
1532 (ulong) (buffer + (i - 1));
1537 release_param(parm);
1539 iucv_debug(2, "exiting");
1540 return b2f0_result;
1544 * iucv_reject:
1545 * @pathid: Path identification number.
1546 * @msgid: Message ID of the message to reject.
1547 * @trgcls: Target class of the message to reject.
1548 * Returns: return code from CP
1550 * Refuses a specified message. Between the time you are notified of a
1551 * message and the time that you complete the message, the message may
1552 * be rejected.
1555 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1557 iparml_db *parm;
1558 ulong b2f0_result = 0;
1560 iucv_debug(1, "entering");
1561 iucv_debug(1, "pathid = %d", pathid);
1563 parm = (iparml_db *)grab_param();
1565 parm->ippathid = pathid;
1566 parm->ipmsgid = msgid;
1567 parm->iptrgcls = trgcls;
1568 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1570 b2f0_result = b2f0(REJECT, parm);
1571 release_param(parm);
1573 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1574 iucv_debug(1, "exiting");
1576 return b2f0_result;
1580 * Name: iucv_reply
1581 * Purpose: This function responds to the two-way messages that you
1582 * receive. You must identify completely the message to
1583 * which you wish to reply. ie, pathid, msgid, and trgcls.
1584 * Input: pathid - path identification number
1585 * msgid - specifies the message ID.
1586 * trgcls - specifies target class
1587 * flags1 - option for path
1588 * IPPRTY- 0x20 - specifies if you want to send priority message
1589 * buffer - address of reply buffer
1590 * buflen - length of reply buffer
1591 * Output: ipbfadr2 - Address of buffer updated by the number
1592 * of bytes you have moved.
1593 * ipbfln2f - Contains one of the following values:
1594 * If the answer buffer is the same length as the reply, this field
1595 * contains zero.
1596 * If the answer buffer is longer than the reply, this field contains
1597 * the number of bytes remaining in the buffer.
1598 * If the answer buffer is shorter than the reply, this field contains
1599 * a residual count (that is, the number of bytes remianing in the
1600 * reply that does not fit into the buffer. In this
1601 * case b2f0_result = 5.
1602 * Return: b2f0_result - return code from CP
1603 * (-EINVAL) - buffer address is NULL
1606 iucv_reply (__u16 pathid,
1607 __u32 msgid, __u32 trgcls,
1608 int flags1,
1609 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1611 iparml_db *parm;
1612 ulong b2f0_result;
1614 iucv_debug(2, "entering");
1616 if (!buffer)
1617 return -EINVAL;
1619 parm = (iparml_db *)grab_param();
1621 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1622 parm->ipbfln2f = (__u32) buflen; /* length of message */
1623 parm->ippathid = pathid;
1624 parm->ipmsgid = msgid;
1625 parm->iptrgcls = trgcls;
1626 parm->ipflags1 = (__u8) flags1; /* priority message */
1628 b2f0_result = b2f0(REPLY, parm);
1630 if ((!b2f0_result) || (b2f0_result == 5)) {
1631 if (ipbfadr2)
1632 *ipbfadr2 = parm->ipbfadr2;
1633 if (ipbfln2f)
1634 *ipbfln2f = parm->ipbfln2f;
1636 release_param(parm);
1638 iucv_debug(2, "exiting");
1640 return b2f0_result;
1644 * Name: iucv_reply_array
1645 * Purpose: This function responds to the two-way messages that you
1646 * receive. You must identify completely the message to
1647 * which you wish to reply. ie, pathid, msgid, and trgcls.
1648 * The array identifies a list of addresses and lengths of
1649 * discontiguous buffers that contains the reply data.
1650 * Input: pathid - path identification number
1651 * msgid - specifies the message ID.
1652 * trgcls - specifies target class
1653 * flags1 - option for path
1654 * IPPRTY- specifies if you want to send priority message
1655 * buffer - address of array of reply buffers
1656 * buflen - total length of reply buffers
1657 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1658 * ipbfln2f - Contains one of the following values:
1659 * If the answer buffer is the same length as the reply, this field
1660 * contains zero.
1661 * If the answer buffer is longer than the reply, this field contains
1662 * the number of bytes remaining in the buffer.
1663 * If the answer buffer is shorter than the reply, this field contains
1664 * a residual count (that is, the number of bytes remianing in the
1665 * reply that does not fit into the buffer. In this
1666 * case b2f0_result = 5.
1667 * Return: b2f0_result - return code from CP
1668 * (-EINVAL) - buffer address is NULL
1671 iucv_reply_array (__u16 pathid,
1672 __u32 msgid, __u32 trgcls,
1673 int flags1,
1674 iucv_array_t * buffer,
1675 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1677 iparml_db *parm;
1678 ulong b2f0_result;
1680 iucv_debug(2, "entering");
1682 if (!buffer)
1683 return -EINVAL;
1685 parm = (iparml_db *)grab_param();
1687 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1688 parm->ipbfln2f = buflen; /* length of message */
1689 parm->ippathid = pathid;
1690 parm->ipmsgid = msgid;
1691 parm->iptrgcls = trgcls;
1692 parm->ipflags1 = (IPANSLST | flags1);
1694 b2f0_result = b2f0(REPLY, parm);
1696 if ((!b2f0_result) || (b2f0_result == 5)) {
1698 if (ipbfadr2)
1699 *ipbfadr2 = parm->ipbfadr2;
1700 if (ipbfln2f)
1701 *ipbfln2f = parm->ipbfln2f;
1703 release_param(parm);
1705 iucv_debug(2, "exiting");
1707 return b2f0_result;
1711 * Name: iucv_reply_prmmsg
1712 * Purpose: This function responds to the two-way messages that you
1713 * receive. You must identify completely the message to
1714 * which you wish to reply. ie, pathid, msgid, and trgcls.
1715 * Prmmsg signifies the data is moved into the
1716 * parameter list.
1717 * Input: pathid - path identification number
1718 * msgid - specifies the message ID.
1719 * trgcls - specifies target class
1720 * flags1 - option for path
1721 * IPPRTY- specifies if you want to send priority message
1722 * prmmsg - 8-bytes of data to be placed into the parameter
1723 * list.
1724 * Output: NA
1725 * Return: b2f0_result - return code from CP
1728 iucv_reply_prmmsg (__u16 pathid,
1729 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1731 iparml_dpl *parm;
1732 ulong b2f0_result;
1734 iucv_debug(2, "entering");
1736 parm = (iparml_dpl *)grab_param();
1738 parm->ippathid = pathid;
1739 parm->ipmsgid = msgid;
1740 parm->iptrgcls = trgcls;
1741 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1742 parm->ipflags1 = (IPRMDATA | flags1);
1744 b2f0_result = b2f0(REPLY, parm);
1745 release_param(parm);
1747 iucv_debug(2, "exiting");
1749 return b2f0_result;
1753 * iucv_resume:
1754 * @pathid: Path identification number
1755 * @user_data: 16-byte of user data
1757 * This function restores communication over a quiesced path.
1758 * Returns: return code from CP
1761 iucv_resume (__u16 pathid, __u8 user_data[16])
1763 iparml_control *parm;
1764 ulong b2f0_result = 0;
1766 iucv_debug(1, "entering");
1767 iucv_debug(1, "pathid = %d", pathid);
1769 parm = (iparml_control *)grab_param();
1771 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1772 parm->ippathid = pathid;
1774 b2f0_result = b2f0(RESUME, parm);
1775 release_param(parm);
1777 iucv_debug(1, "exiting");
1779 return b2f0_result;
1783 * Name: iucv_send
1784 * Purpose: sends messages
1785 * Input: pathid - ushort, pathid
1786 * msgid - ulong *, id of message returned to caller
1787 * trgcls - ulong, target message class
1788 * srccls - ulong, source message class
1789 * msgtag - ulong, message tag
1790 * flags1 - Contains options for this path.
1791 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1792 * buffer - pointer to buffer
1793 * buflen - ulong, length of buffer
1794 * Output: b2f0_result - return code from b2f0 call
1795 * msgid - returns message id
1798 iucv_send (__u16 pathid, __u32 * msgid,
1799 __u32 trgcls, __u32 srccls,
1800 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1802 iparml_db *parm;
1803 ulong b2f0_result;
1805 iucv_debug(2, "entering");
1807 if (!buffer)
1808 return -EINVAL;
1810 parm = (iparml_db *)grab_param();
1812 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1813 parm->ippathid = pathid;
1814 parm->iptrgcls = trgcls;
1815 parm->ipbfln1f = (__u32) buflen; /* length of message */
1816 parm->ipsrccls = srccls;
1817 parm->ipmsgtag = msgtag;
1818 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1820 b2f0_result = b2f0(SEND, parm);
1822 if ((!b2f0_result) && (msgid))
1823 *msgid = parm->ipmsgid;
1824 release_param(parm);
1826 iucv_debug(2, "exiting");
1828 return b2f0_result;
1832 * Name: iucv_send_array
1833 * Purpose: This function transmits data to another application.
1834 * The contents of buffer is the address of the array of
1835 * addresses and lengths of discontiguous buffers that hold
1836 * the message text. This is a one-way message and the
1837 * receiver will not reply to the message.
1838 * Input: pathid - path identification number
1839 * trgcls - specifies target class
1840 * srccls - specifies the source message class
1841 * msgtag - specifies a tag to be associated witht the message
1842 * flags1 - option for path
1843 * IPPRTY- specifies if you want to send priority message
1844 * buffer - address of array of send buffers
1845 * buflen - total length of send buffers
1846 * Output: msgid - specifies the message ID.
1847 * Return: b2f0_result - return code from CP
1848 * (-EINVAL) - buffer address is NULL
1851 iucv_send_array (__u16 pathid,
1852 __u32 * msgid,
1853 __u32 trgcls,
1854 __u32 srccls,
1855 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1857 iparml_db *parm;
1858 ulong b2f0_result;
1860 iucv_debug(2, "entering");
1862 if (!buffer)
1863 return -EINVAL;
1865 parm = (iparml_db *)grab_param();
1867 parm->ippathid = pathid;
1868 parm->iptrgcls = trgcls;
1869 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1870 parm->ipbfln1f = (__u32) buflen; /* length of message */
1871 parm->ipsrccls = srccls;
1872 parm->ipmsgtag = msgtag;
1873 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1874 b2f0_result = b2f0(SEND, parm);
1876 if ((!b2f0_result) && (msgid))
1877 *msgid = parm->ipmsgid;
1878 release_param(parm);
1880 iucv_debug(2, "exiting");
1881 return b2f0_result;
1885 * Name: iucv_send_prmmsg
1886 * Purpose: This function transmits data to another application.
1887 * Prmmsg specifies that the 8-bytes of data are to be moved
1888 * into the parameter list. This is a one-way message and the
1889 * receiver will not reply to the message.
1890 * Input: pathid - path identification number
1891 * trgcls - specifies target class
1892 * srccls - specifies the source message class
1893 * msgtag - specifies a tag to be associated with the message
1894 * flags1 - option for path
1895 * IPPRTY- specifies if you want to send priority message
1896 * prmmsg - 8-bytes of data to be placed into parameter list
1897 * Output: msgid - specifies the message ID.
1898 * Return: b2f0_result - return code from CP
1901 iucv_send_prmmsg (__u16 pathid,
1902 __u32 * msgid,
1903 __u32 trgcls,
1904 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1906 iparml_dpl *parm;
1907 ulong b2f0_result;
1909 iucv_debug(2, "entering");
1911 parm = (iparml_dpl *)grab_param();
1913 parm->ippathid = pathid;
1914 parm->iptrgcls = trgcls;
1915 parm->ipsrccls = srccls;
1916 parm->ipmsgtag = msgtag;
1917 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1918 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1920 b2f0_result = b2f0(SEND, parm);
1922 if ((!b2f0_result) && (msgid))
1923 *msgid = parm->ipmsgid;
1924 release_param(parm);
1926 iucv_debug(2, "exiting");
1928 return b2f0_result;
1932 * Name: iucv_send2way
1933 * Purpose: This function transmits data to another application.
1934 * Data to be transmitted is in a buffer. The receiver
1935 * of the send is expected to reply to the message and
1936 * a buffer is provided into which IUCV moves the reply
1937 * to this message.
1938 * Input: pathid - path identification number
1939 * trgcls - specifies target class
1940 * srccls - specifies the source message class
1941 * msgtag - specifies a tag associated with the message
1942 * flags1 - option for path
1943 * IPPRTY- specifies if you want to send priority message
1944 * buffer - address of send buffer
1945 * buflen - length of send buffer
1946 * ansbuf - address of buffer to reply with
1947 * anslen - length of buffer to reply with
1948 * Output: msgid - specifies the message ID.
1949 * Return: b2f0_result - return code from CP
1950 * (-EINVAL) - buffer or ansbuf address is NULL
1953 iucv_send2way (__u16 pathid,
1954 __u32 * msgid,
1955 __u32 trgcls,
1956 __u32 srccls,
1957 __u32 msgtag,
1958 int flags1,
1959 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1961 iparml_db *parm;
1962 ulong b2f0_result;
1964 iucv_debug(2, "entering");
1966 if (!buffer || !ansbuf)
1967 return -EINVAL;
1969 parm = (iparml_db *)grab_param();
1971 parm->ippathid = pathid;
1972 parm->iptrgcls = trgcls;
1973 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1974 parm->ipbfln1f = (__u32) buflen; /* length of message */
1975 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1976 parm->ipbfln2f = (__u32) anslen;
1977 parm->ipsrccls = srccls;
1978 parm->ipmsgtag = msgtag;
1979 parm->ipflags1 = flags1; /* priority message */
1981 b2f0_result = b2f0(SEND, parm);
1983 if ((!b2f0_result) && (msgid))
1984 *msgid = parm->ipmsgid;
1985 release_param(parm);
1987 iucv_debug(2, "exiting");
1989 return b2f0_result;
1993 * Name: iucv_send2way_array
1994 * Purpose: This function transmits data to another application.
1995 * The contents of buffer is the address of the array of
1996 * addresses and lengths of discontiguous buffers that hold
1997 * the message text. The receiver of the send is expected to
1998 * reply to the message and a buffer is provided into which
1999 * IUCV moves the reply to this message.
2000 * Input: pathid - path identification number
2001 * trgcls - specifies target class
2002 * srccls - specifies the source message class
2003 * msgtag - spcifies a tag to be associated with the message
2004 * flags1 - option for path
2005 * IPPRTY- specifies if you want to send priority message
2006 * buffer - address of array of send buffers
2007 * buflen - total length of send buffers
2008 * ansbuf - address of buffer to reply with
2009 * anslen - length of buffer to reply with
2010 * Output: msgid - specifies the message ID.
2011 * Return: b2f0_result - return code from CP
2012 * (-EINVAL) - buffer address is NULL
2015 iucv_send2way_array (__u16 pathid,
2016 __u32 * msgid,
2017 __u32 trgcls,
2018 __u32 srccls,
2019 __u32 msgtag,
2020 int flags1,
2021 iucv_array_t * buffer,
2022 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2024 iparml_db *parm;
2025 ulong b2f0_result;
2027 iucv_debug(2, "entering");
2029 if (!buffer || !ansbuf)
2030 return -EINVAL;
2032 parm = (iparml_db *)grab_param();
2034 parm->ippathid = pathid;
2035 parm->iptrgcls = trgcls;
2036 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2037 parm->ipbfln1f = (__u32) buflen; /* length of message */
2038 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2039 parm->ipbfln2f = (__u32) anslen;
2040 parm->ipsrccls = srccls;
2041 parm->ipmsgtag = msgtag;
2042 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2043 b2f0_result = b2f0(SEND, parm);
2044 if ((!b2f0_result) && (msgid))
2045 *msgid = parm->ipmsgid;
2046 release_param(parm);
2048 iucv_debug(2, "exiting");
2049 return b2f0_result;
2053 * Name: iucv_send2way_prmmsg
2054 * Purpose: This function transmits data to another application.
2055 * Prmmsg specifies that the 8-bytes of data are to be moved
2056 * into the parameter list. This is a two-way message and the
2057 * receiver of the message is expected to reply. A buffer
2058 * is provided into which IUCV moves the reply to this
2059 * message.
2060 * Input: pathid - path identification number
2061 * trgcls - specifies target class
2062 * srccls - specifies the source message class
2063 * msgtag - specifies a tag to be associated with the message
2064 * flags1 - option for path
2065 * IPPRTY- specifies if you want to send priority message
2066 * prmmsg - 8-bytes of data to be placed in parameter list
2067 * ansbuf - address of buffer to reply with
2068 * anslen - length of buffer to reply with
2069 * Output: msgid - specifies the message ID.
2070 * Return: b2f0_result - return code from CP
2071 * (-EINVAL) - buffer address is NULL
2074 iucv_send2way_prmmsg (__u16 pathid,
2075 __u32 * msgid,
2076 __u32 trgcls,
2077 __u32 srccls,
2078 __u32 msgtag,
2079 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2081 iparml_dpl *parm;
2082 ulong b2f0_result;
2084 iucv_debug(2, "entering");
2086 if (!ansbuf)
2087 return -EINVAL;
2089 parm = (iparml_dpl *)grab_param();
2091 parm->ippathid = pathid;
2092 parm->iptrgcls = trgcls;
2093 parm->ipsrccls = srccls;
2094 parm->ipmsgtag = msgtag;
2095 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2096 parm->ipbfln2f = (__u32) anslen;
2097 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2098 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2100 b2f0_result = b2f0(SEND, parm);
2102 if ((!b2f0_result) && (msgid))
2103 *msgid = parm->ipmsgid;
2104 release_param(parm);
2106 iucv_debug(2, "exiting");
2108 return b2f0_result;
2112 * Name: iucv_send2way_prmmsg_array
2113 * Purpose: This function transmits data to another application.
2114 * Prmmsg specifies that the 8-bytes of data are to be moved
2115 * into the parameter list. This is a two-way message and the
2116 * receiver of the message is expected to reply. A buffer
2117 * is provided into which IUCV moves the reply to this
2118 * message. The contents of ansbuf is the address of the
2119 * array of addresses and lengths of discontiguous buffers
2120 * that contain the reply.
2121 * Input: pathid - path identification number
2122 * trgcls - specifies target class
2123 * srccls - specifies the source message class
2124 * msgtag - specifies a tag to be associated with the message
2125 * flags1 - option for path
2126 * IPPRTY- specifies if you want to send priority message
2127 * prmmsg - 8-bytes of data to be placed into the parameter list
2128 * ansbuf - address of buffer to reply with
2129 * anslen - length of buffer to reply with
2130 * Output: msgid - specifies the message ID.
2131 * Return: b2f0_result - return code from CP
2132 * (-EINVAL) - ansbuf address is NULL
2135 iucv_send2way_prmmsg_array (__u16 pathid,
2136 __u32 * msgid,
2137 __u32 trgcls,
2138 __u32 srccls,
2139 __u32 msgtag,
2140 int flags1,
2141 __u8 prmmsg[8],
2142 iucv_array_t * ansbuf, ulong anslen)
2144 iparml_dpl *parm;
2145 ulong b2f0_result;
2147 iucv_debug(2, "entering");
2149 if (!ansbuf)
2150 return -EINVAL;
2152 parm = (iparml_dpl *)grab_param();
2154 parm->ippathid = pathid;
2155 parm->iptrgcls = trgcls;
2156 parm->ipsrccls = srccls;
2157 parm->ipmsgtag = msgtag;
2158 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2159 parm->ipbfln2f = (__u32) anslen;
2160 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2161 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2162 b2f0_result = b2f0(SEND, parm);
2163 if ((!b2f0_result) && (msgid))
2164 *msgid = parm->ipmsgid;
2165 release_param(parm);
2167 iucv_debug(2, "exiting");
2168 return b2f0_result;
2171 void
2172 iucv_setmask_cpuid (void *result)
2174 iparml_set_mask *parm;
2176 iucv_debug(1, "entering");
2177 parm = (iparml_set_mask *)grab_param();
2178 parm->ipmask = *((__u8*)result);
2179 *((ulong *)result) = b2f0(SETMASK, parm);
2180 release_param(parm);
2182 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2183 iucv_debug(1, "exiting");
2187 * Name: iucv_setmask
2188 * Purpose: This function enables or disables the following IUCV
2189 * external interruptions: Nonpriority and priority message
2190 * interrupts, nonpriority and priority reply interrupts.
2191 * Input: SetMaskFlag - options for interrupts
2192 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2193 * 0x40 - Priority_MessagePendingInterruptsFlag
2194 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2195 * 0x10 - Priority_MessageCompletionInterruptsFlag
2196 * 0x08 - IUCVControlInterruptsFlag
2197 * Output: NA
2198 * Return: b2f0_result - return code from CP
2201 iucv_setmask (int SetMaskFlag)
2203 union {
2204 ulong result;
2205 __u8 param;
2206 } u;
2207 int cpu;
2209 u.param = SetMaskFlag;
2210 cpu = get_cpu();
2211 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2212 put_cpu();
2214 return u.result;
2218 * iucv_sever:
2219 * @pathid: Path identification number
2220 * @user_data: 16-byte of user data
2222 * This function terminates an iucv path.
2223 * Returns: return code from CP
2226 iucv_sever(__u16 pathid, __u8 user_data[16])
2228 iparml_control *parm;
2229 ulong b2f0_result = 0;
2231 iucv_debug(1, "entering");
2232 parm = (iparml_control *)grab_param();
2234 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2235 parm->ippathid = pathid;
2237 b2f0_result = b2f0(SEVER, parm);
2239 if (!b2f0_result)
2240 iucv_remove_pathid(pathid);
2241 release_param(parm);
2243 iucv_debug(1, "exiting");
2244 return b2f0_result;
2248 * Interrupt Handlers
2249 *******************************************************************************/
2252 * iucv_irq_handler:
2253 * @regs: Current registers
2254 * @code: irq code
2256 * Handles external interrupts coming in from CP.
2257 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2259 static void
2260 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2262 iucv_irqdata *irqdata;
2264 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2265 if (!irqdata) {
2266 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2267 return;
2270 memcpy(&irqdata->data, iucv_external_int_buffer,
2271 sizeof(iucv_GeneralInterrupt));
2273 spin_lock(&iucv_irq_queue_lock);
2274 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2275 spin_unlock(&iucv_irq_queue_lock);
2277 tasklet_schedule(&iucv_tasklet);
2281 * iucv_do_int:
2282 * @int_buf: Pointer to copy of external interrupt buffer
2284 * The workhorse for handling interrupts queued by iucv_irq_handler().
2285 * This function is called from the bottom half iucv_tasklet_handler().
2287 static void
2288 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2290 handler *h = NULL;
2291 struct list_head *lh;
2292 ulong flags;
2293 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2294 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2295 int rc = 0, j = 0;
2296 __u8 no_listener[16] = "NO LISTENER";
2298 iucv_debug(2, "entering, pathid %d, type %02X",
2299 int_buf->ippathid, int_buf->iptype);
2300 iucv_dumpit("External Interrupt Buffer:",
2301 int_buf, sizeof(iucv_GeneralInterrupt));
2303 ASCEBC (no_listener, 16);
2305 if (int_buf->iptype != 01) {
2306 if ((int_buf->ippathid) > (max_connections - 1)) {
2307 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2308 " > max_connections (%ld)\n", __FUNCTION__,
2309 int_buf->ippathid, max_connections - 1);
2310 } else {
2311 h = iucv_pathid_table[int_buf->ippathid];
2312 interrupt = h->interrupt_table;
2313 iucv_dumpit("Handler:", h, sizeof(handler));
2317 /* end of if statement */
2318 switch (int_buf->iptype) {
2319 case 0x01: /* connection pending */
2320 if (messagesDisabled) {
2321 iucv_setmask(~0);
2322 messagesDisabled = 0;
2324 spin_lock_irqsave(&iucv_lock, flags);
2325 list_for_each(lh, &iucv_handler_table) {
2326 h = list_entry(lh, handler, list);
2327 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2328 memcpy(temp_buff2, &(h->id.userid), 24);
2329 for (j = 0; j < 24; j++) {
2330 temp_buff1[j] &= (h->id.mask)[j];
2331 temp_buff2[j] &= (h->id.mask)[j];
2334 iucv_dumpit("temp_buff1:",
2335 temp_buff1, sizeof(temp_buff1));
2336 iucv_dumpit("temp_buff2",
2337 temp_buff2, sizeof(temp_buff2));
2339 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2341 iucv_debug(2,
2342 "found a matching handler");
2343 break;
2344 } else
2345 h = NULL;
2347 spin_unlock_irqrestore (&iucv_lock, flags);
2348 if (h) {
2349 /* ADD PATH TO PATHID TABLE */
2350 rc = iucv_add_pathid(int_buf->ippathid, h);
2351 if (rc) {
2352 iucv_sever (int_buf->ippathid,
2353 no_listener);
2354 iucv_debug(1,
2355 "add_pathid failed, rc = %d",
2356 rc);
2357 } else {
2358 interrupt = h->interrupt_table;
2359 if (interrupt->ConnectionPending) {
2360 EBCASC (int_buf->ipvmid, 8);
2361 interrupt->ConnectionPending(
2362 (iucv_ConnectionPending *)int_buf,
2363 h->pgm_data);
2364 } else
2365 iucv_sever(int_buf->ippathid,
2366 no_listener);
2368 } else
2369 iucv_sever(int_buf->ippathid, no_listener);
2370 break;
2372 case 0x02: /*connection complete */
2373 if (messagesDisabled) {
2374 iucv_setmask(~0);
2375 messagesDisabled = 0;
2377 if (h) {
2378 if (interrupt->ConnectionComplete)
2380 interrupt->ConnectionComplete(
2381 (iucv_ConnectionComplete *)int_buf,
2382 h->pgm_data);
2384 else
2385 iucv_debug(1,
2386 "ConnectionComplete not called");
2387 } else
2388 iucv_sever(int_buf->ippathid, no_listener);
2389 break;
2391 case 0x03: /* connection severed */
2392 if (messagesDisabled) {
2393 iucv_setmask(~0);
2394 messagesDisabled = 0;
2396 if (h) {
2397 if (interrupt->ConnectionSevered)
2398 interrupt->ConnectionSevered(
2399 (iucv_ConnectionSevered *)int_buf,
2400 h->pgm_data);
2402 else
2403 iucv_sever (int_buf->ippathid, no_listener);
2404 } else
2405 iucv_sever(int_buf->ippathid, no_listener);
2406 break;
2408 case 0x04: /* connection quiesced */
2409 if (messagesDisabled) {
2410 iucv_setmask(~0);
2411 messagesDisabled = 0;
2413 if (h) {
2414 if (interrupt->ConnectionQuiesced)
2415 interrupt->ConnectionQuiesced(
2416 (iucv_ConnectionQuiesced *)int_buf,
2417 h->pgm_data);
2418 else
2419 iucv_debug(1,
2420 "ConnectionQuiesced not called");
2422 break;
2424 case 0x05: /* connection resumed */
2425 if (messagesDisabled) {
2426 iucv_setmask(~0);
2427 messagesDisabled = 0;
2429 if (h) {
2430 if (interrupt->ConnectionResumed)
2431 interrupt->ConnectionResumed(
2432 (iucv_ConnectionResumed *)int_buf,
2433 h->pgm_data);
2434 else
2435 iucv_debug(1,
2436 "ConnectionResumed not called");
2438 break;
2440 case 0x06: /* priority message complete */
2441 case 0x07: /* nonpriority message complete */
2442 if (h) {
2443 if (interrupt->MessageComplete)
2444 interrupt->MessageComplete(
2445 (iucv_MessageComplete *)int_buf,
2446 h->pgm_data);
2447 else
2448 iucv_debug(2,
2449 "MessageComplete not called");
2451 break;
2453 case 0x08: /* priority message pending */
2454 case 0x09: /* nonpriority message pending */
2455 if (h) {
2456 if (interrupt->MessagePending)
2457 interrupt->MessagePending(
2458 (iucv_MessagePending *) int_buf,
2459 h->pgm_data);
2460 else
2461 iucv_debug(2,
2462 "MessagePending not called");
2464 break;
2465 default: /* unknown iucv type */
2466 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2467 __FUNCTION__);
2468 break;
2469 } /* end switch */
2471 iucv_debug(2, "exiting pathid %d, type %02X",
2472 int_buf->ippathid, int_buf->iptype);
2474 return;
2478 * iucv_tasklet_handler:
2480 * This function loops over the queue of irq buffers and runs iucv_do_int()
2481 * on every queue element.
2483 static void
2484 iucv_tasklet_handler(unsigned long ignored)
2486 struct list_head head;
2487 struct list_head *next;
2488 ulong flags;
2490 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2491 list_add(&head, &iucv_irq_queue);
2492 list_del_init(&iucv_irq_queue);
2493 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2495 next = head.next;
2496 while (next != &head) {
2497 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2499 next = next->next;
2500 iucv_do_int(&p->data);
2501 kfree(p);
2504 return;
2507 subsys_initcall(iucv_init);
2508 module_exit(iucv_exit);
2511 * Export all public stuff
2513 EXPORT_SYMBOL (iucv_bus);
2514 EXPORT_SYMBOL (iucv_root);
2515 EXPORT_SYMBOL (iucv_accept);
2516 EXPORT_SYMBOL (iucv_connect);
2517 #if 0
2518 EXPORT_SYMBOL (iucv_purge);
2519 EXPORT_SYMBOL (iucv_query_maxconn);
2520 EXPORT_SYMBOL (iucv_query_bufsize);
2521 EXPORT_SYMBOL (iucv_quiesce);
2522 #endif
2523 EXPORT_SYMBOL (iucv_receive);
2524 #if 0
2525 EXPORT_SYMBOL (iucv_receive_array);
2526 #endif
2527 EXPORT_SYMBOL (iucv_reject);
2528 #if 0
2529 EXPORT_SYMBOL (iucv_reply);
2530 EXPORT_SYMBOL (iucv_reply_array);
2531 EXPORT_SYMBOL (iucv_resume);
2532 #endif
2533 EXPORT_SYMBOL (iucv_reply_prmmsg);
2534 EXPORT_SYMBOL (iucv_send);
2535 EXPORT_SYMBOL (iucv_send2way);
2536 EXPORT_SYMBOL (iucv_send2way_array);
2537 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2538 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2539 #if 0
2540 EXPORT_SYMBOL (iucv_send_array);
2541 EXPORT_SYMBOL (iucv_send_prmmsg);
2542 EXPORT_SYMBOL (iucv_setmask);
2543 #endif
2544 EXPORT_SYMBOL (iucv_sever);
2545 EXPORT_SYMBOL (iucv_register_program);
2546 EXPORT_SYMBOL (iucv_unregister_program);