Linux-2.6.12-rc2
[linux-2.6/kvm.git] / drivers / s390 / net / iucv.c
blob1ac6563ee3e0fd0574f8e79e275130606defed3d
1 /*
2 * $Id: iucv.c,v 1.43 2005/02/09 14:47:43 braunu Exp $
4 * IUCV network driver
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s):
8 * Original source:
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)
14 * Documentation used:
15 * The original source
16 * CP Programming Service, IBM document # SC24-5760
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * RELEASE-TAG: IUCV lowlevel driver $Revision: 1.43 $
36 /* #define DEBUG */
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/config.h>
42 #include <linux/spinlock.h>
43 #include <linux/kernel.h>
44 #include <linux/slab.h>
45 #include <linux/init.h>
46 #include <linux/interrupt.h>
47 #include <linux/list.h>
48 #include <linux/errno.h>
49 #include <linux/err.h>
50 #include <linux/device.h>
51 #include <asm/atomic.h>
52 #include "iucv.h"
53 #include <asm/io.h>
54 #include <asm/s390_ext.h>
55 #include <asm/ebcdic.h>
56 #include <asm/smp.h>
57 #include <asm/ccwdev.h> //for root device stuff
59 /* FLAGS:
60 * All flags are defined in the field IPFLAGS1 of each function
61 * and can be found in CP Programming Services.
62 * IPSRCCLS - Indicates you have specified a source class
63 * IPFGMCL - Indicates you have specified a target class
64 * IPFGPID - Indicates you have specified a pathid
65 * IPFGMID - Indicates you have specified a message ID
66 * IPANSLST - Indicates that you are using an address list for
67 * reply data
68 * IPBUFLST - Indicates that you are using an address list for
69 * message data
72 #define IPSRCCLS 0x01
73 #define IPFGMCL 0x01
74 #define IPFGPID 0x02
75 #define IPFGMID 0x04
76 #define IPANSLST 0x08
77 #define IPBUFLST 0x40
79 static int
80 iucv_bus_match (struct device *dev, struct device_driver *drv)
82 return 0;
85 struct bus_type iucv_bus = {
86 .name = "iucv",
87 .match = iucv_bus_match,
88 };
90 struct device *iucv_root;
92 /* General IUCV interrupt structure */
93 typedef struct {
94 __u16 ippathid;
95 __u8 res1;
96 __u8 iptype;
97 __u32 res2;
98 __u8 ipvmid[8];
99 __u8 res3[24];
100 } iucv_GeneralInterrupt;
102 static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
104 /* Spin Lock declaration */
106 static DEFINE_SPINLOCK(iucv_lock);
108 static int messagesDisabled = 0;
110 /***************INTERRUPT HANDLING ***************/
112 typedef struct {
113 struct list_head queue;
114 iucv_GeneralInterrupt data;
115 } iucv_irqdata;
117 static struct list_head iucv_irq_queue;
118 static DEFINE_SPINLOCK(iucv_irq_queue_lock);
121 *Internal function prototypes
123 static void iucv_tasklet_handler(unsigned long);
124 static void iucv_irq_handler(struct pt_regs *, __u16);
126 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
128 /************ FUNCTION ID'S ****************************/
130 #define ACCEPT 10
131 #define CONNECT 11
132 #define DECLARE_BUFFER 12
133 #define PURGE 9
134 #define QUERY 0
135 #define QUIESCE 13
136 #define RECEIVE 5
137 #define REJECT 8
138 #define REPLY 6
139 #define RESUME 14
140 #define RETRIEVE_BUFFER 2
141 #define SEND 4
142 #define SETMASK 16
143 #define SEVER 15
146 * Structure: handler
147 * members: list - list management.
148 * structure: id
149 * userid - 8 char array of machine identification
150 * user_data - 16 char array for user identification
151 * mask - 24 char array used to compare the 2 previous
152 * interrupt_table - vector of interrupt functions.
153 * pgm_data - ulong, application data that is passed
154 * to the interrupt handlers
156 typedef struct handler_t {
157 struct list_head list;
158 struct {
159 __u8 userid[8];
160 __u8 user_data[16];
161 __u8 mask[24];
162 } id;
163 iucv_interrupt_ops_t *interrupt_table;
164 void *pgm_data;
165 } handler;
168 * iucv_handler_table: List of registered handlers.
170 static struct list_head iucv_handler_table;
173 * iucv_pathid_table: an array of *handler pointing into
174 * iucv_handler_table for fast indexing by pathid;
176 static handler **iucv_pathid_table;
178 static unsigned long max_connections;
181 * iucv_cpuid: contains the logical cpu number of the cpu which
182 * has declared the iucv buffer by issuing DECLARE_BUFFER.
183 * If no cpu has done the initialization iucv_cpuid contains -1.
185 static int iucv_cpuid = -1;
187 * register_flag: is 0 when external interrupt has not been registered
189 static int register_flag;
191 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
192 /* Data struct 1: iparml_control
193 * Used for iucv_accept
194 * iucv_connect
195 * iucv_quiesce
196 * iucv_resume
197 * iucv_sever
198 * iucv_retrieve_buffer
199 * Data struct 2: iparml_dpl (data in parameter list)
200 * Used for iucv_send_prmmsg
201 * iucv_send2way_prmmsg
202 * iucv_send2way_prmmsg_array
203 * iucv_reply_prmmsg
204 * Data struct 3: iparml_db (data in a buffer)
205 * Used for iucv_receive
206 * iucv_receive_array
207 * iucv_reject
208 * iucv_reply
209 * iucv_reply_array
210 * iucv_send
211 * iucv_send_array
212 * iucv_send2way
213 * iucv_send2way_array
214 * iucv_declare_buffer
215 * Data struct 4: iparml_purge
216 * Used for iucv_purge
217 * iucv_query
218 * Data struct 5: iparml_set_mask
219 * Used for iucv_set_mask
222 typedef struct {
223 __u16 ippathid;
224 __u8 ipflags1;
225 __u8 iprcode;
226 __u16 ipmsglim;
227 __u16 res1;
228 __u8 ipvmid[8];
229 __u8 ipuser[16];
230 __u8 iptarget[8];
231 } iparml_control;
233 typedef struct {
234 __u16 ippathid;
235 __u8 ipflags1;
236 __u8 iprcode;
237 __u32 ipmsgid;
238 __u32 iptrgcls;
239 __u8 iprmmsg[8];
240 __u32 ipsrccls;
241 __u32 ipmsgtag;
242 __u32 ipbfadr2;
243 __u32 ipbfln2f;
244 __u32 res;
245 } iparml_dpl;
247 typedef struct {
248 __u16 ippathid;
249 __u8 ipflags1;
250 __u8 iprcode;
251 __u32 ipmsgid;
252 __u32 iptrgcls;
253 __u32 ipbfadr1;
254 __u32 ipbfln1f;
255 __u32 ipsrccls;
256 __u32 ipmsgtag;
257 __u32 ipbfadr2;
258 __u32 ipbfln2f;
259 __u32 res;
260 } iparml_db;
262 typedef struct {
263 __u16 ippathid;
264 __u8 ipflags1;
265 __u8 iprcode;
266 __u32 ipmsgid;
267 __u8 ipaudit[3];
268 __u8 res1[5];
269 __u32 res2;
270 __u32 ipsrccls;
271 __u32 ipmsgtag;
272 __u32 res3[3];
273 } iparml_purge;
275 typedef struct {
276 __u8 ipmask;
277 __u8 res1[2];
278 __u8 iprcode;
279 __u32 res2[9];
280 } iparml_set_mask;
282 typedef struct {
283 union {
284 iparml_control p_ctrl;
285 iparml_dpl p_dpl;
286 iparml_db p_db;
287 iparml_purge p_purge;
288 iparml_set_mask p_set_mask;
289 } param;
290 atomic_t in_use;
291 __u32 res;
292 } __attribute__ ((aligned(8))) iucv_param;
293 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
295 static iucv_param * iucv_param_pool;
297 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
298 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
299 MODULE_LICENSE("GPL");
302 * Debugging stuff
303 *******************************************************************************/
306 #ifdef DEBUG
307 static int debuglevel = 0;
309 module_param(debuglevel, int, 0);
310 MODULE_PARM_DESC(debuglevel,
311 "Specifies the debug level (0=off ... 3=all)");
313 static void
314 iucv_dumpit(char *title, void *buf, int len)
316 int i;
317 __u8 *p = (__u8 *)buf;
319 if (debuglevel < 3)
320 return;
322 printk(KERN_DEBUG "%s\n", title);
323 printk(" ");
324 for (i = 0; i < len; i++) {
325 if (!(i % 16) && i != 0)
326 printk ("\n ");
327 else if (!(i % 4) && i != 0)
328 printk(" ");
329 printk("%02X", *p++);
331 if (len % 16)
332 printk ("\n");
333 return;
335 #define iucv_debug(lvl, fmt, args...) \
336 do { \
337 if (debuglevel >= lvl) \
338 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
339 } while (0)
341 #else
343 #define iucv_debug(lvl, fmt, args...)
344 #define iucv_dumpit(title, buf, len)
346 #endif
349 * Internal functions
350 *******************************************************************************/
353 * print start banner
355 static void
356 iucv_banner(void)
358 char vbuf[] = "$Revision: 1.43 $";
359 char *version = vbuf;
361 if ((version = strchr(version, ':'))) {
362 char *p = strchr(version + 1, '$');
363 if (p)
364 *p = '\0';
365 } else
366 version = " ??? ";
367 printk(KERN_INFO
368 "IUCV lowlevel driver Version%s initialized\n", version);
372 * iucv_init - Initialization
374 * Allocates and initializes various data structures.
376 static int
377 iucv_init(void)
379 int ret;
381 if (iucv_external_int_buffer)
382 return 0;
384 if (!MACHINE_IS_VM) {
385 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
386 return -EPROTONOSUPPORT;
389 ret = bus_register(&iucv_bus);
390 if (ret) {
391 printk(KERN_ERR "IUCV: failed to register bus.\n");
392 return ret;
395 iucv_root = s390_root_dev_register("iucv");
396 if (IS_ERR(iucv_root)) {
397 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
398 bus_unregister(&iucv_bus);
399 return PTR_ERR(iucv_root);
402 /* Note: GFP_DMA used used to get memory below 2G */
403 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt),
404 GFP_KERNEL|GFP_DMA);
405 if (!iucv_external_int_buffer) {
406 printk(KERN_WARNING
407 "%s: Could not allocate external interrupt buffer\n",
408 __FUNCTION__);
409 s390_root_dev_unregister(iucv_root);
410 bus_unregister(&iucv_bus);
411 return -ENOMEM;
413 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
415 /* Initialize parameter pool */
416 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
417 GFP_KERNEL|GFP_DMA);
418 if (!iucv_param_pool) {
419 printk(KERN_WARNING "%s: Could not allocate param pool\n",
420 __FUNCTION__);
421 kfree(iucv_external_int_buffer);
422 iucv_external_int_buffer = NULL;
423 s390_root_dev_unregister(iucv_root);
424 bus_unregister(&iucv_bus);
425 return -ENOMEM;
427 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
429 /* Initialize irq queue */
430 INIT_LIST_HEAD(&iucv_irq_queue);
432 /* Initialize handler table */
433 INIT_LIST_HEAD(&iucv_handler_table);
435 iucv_banner();
436 return 0;
440 * iucv_exit - De-Initialization
442 * Frees everything allocated from iucv_init.
444 static int iucv_retrieve_buffer (void);
446 static void
447 iucv_exit(void)
449 iucv_retrieve_buffer();
450 if (iucv_external_int_buffer) {
451 kfree(iucv_external_int_buffer);
452 iucv_external_int_buffer = NULL;
454 if (iucv_param_pool) {
455 kfree(iucv_param_pool);
456 iucv_param_pool = NULL;
458 s390_root_dev_unregister(iucv_root);
459 bus_unregister(&iucv_bus);
460 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
464 * grab_param: - Get a parameter buffer from the pre-allocated pool.
466 * This function searches for an unused element in the pre-allocated pool
467 * of parameter buffers. If one is found, it marks it "in use" and returns
468 * a pointer to it. The calling function is responsible for releasing it
469 * when it has finished its usage.
471 * Returns: A pointer to iucv_param.
473 static __inline__ iucv_param *
474 grab_param(void)
476 iucv_param *ptr;
477 static int hint = 0;
479 ptr = iucv_param_pool + hint;
480 do {
481 ptr++;
482 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
483 ptr = iucv_param_pool;
484 } while (atomic_compare_and_swap(0, 1, &ptr->in_use));
485 hint = ptr - iucv_param_pool;
487 memset(&ptr->param, 0, sizeof(ptr->param));
488 return ptr;
492 * release_param - Release a parameter buffer.
493 * @p: A pointer to a struct iucv_param, previously obtained by calling
494 * grab_param().
496 * This function marks the specified parameter buffer "unused".
498 static __inline__ void
499 release_param(void *p)
501 atomic_set(&((iucv_param *)p)->in_use, 0);
505 * iucv_add_handler: - Add a new handler
506 * @new_handler: handle that is being entered into chain.
508 * Places new handle on iucv_handler_table, if identical handler is not
509 * found.
511 * Returns: 0 on success, !0 on failure (handler already in chain).
513 static int
514 iucv_add_handler (handler *new)
516 ulong flags;
518 iucv_debug(1, "entering");
519 iucv_dumpit("handler:", new, sizeof(handler));
521 spin_lock_irqsave (&iucv_lock, flags);
522 if (!list_empty(&iucv_handler_table)) {
523 struct list_head *lh;
526 * Search list for handler with identical id. If one
527 * is found, the new handler is _not_ added.
529 list_for_each(lh, &iucv_handler_table) {
530 handler *h = list_entry(lh, handler, list);
531 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
532 iucv_debug(1, "ret 1");
533 spin_unlock_irqrestore (&iucv_lock, flags);
534 return 1;
539 * If we get here, no handler was found.
541 INIT_LIST_HEAD(&new->list);
542 list_add(&new->list, &iucv_handler_table);
543 spin_unlock_irqrestore (&iucv_lock, flags);
545 iucv_debug(1, "exiting");
546 return 0;
550 * b2f0:
551 * @code: identifier of IUCV call to CP.
552 * @parm: pointer to 40 byte iparml area passed to CP
554 * Calls CP to execute IUCV commands.
556 * Returns: return code from CP's IUCV call
558 static __inline__ ulong
559 b2f0(__u32 code, void *parm)
561 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
563 asm volatile (
564 "LRA 1,0(%1)\n\t"
565 "LR 0,%0\n\t"
566 ".long 0xb2f01000"
568 : "d" (code), "a" (parm)
569 : "0", "1"
572 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
574 return (unsigned long)*((__u8 *)(parm + 3));
578 * Name: iucv_add_pathid
579 * Purpose: Adds a path id to the system.
580 * Input: pathid - pathid that is going to be entered into system
581 * handle - address of handler that the pathid will be associated
582 * with.
583 * pgm_data - token passed in by application.
584 * Output: 0: successful addition of pathid
585 * - EINVAL - pathid entry is being used by another application
586 * - ENOMEM - storage allocation for a new pathid table failed
588 static int
589 __iucv_add_pathid(__u16 pathid, handler *handler)
592 iucv_debug(1, "entering");
594 iucv_debug(1, "handler is pointing to %p", handler);
596 if (pathid > (max_connections - 1))
597 return -EINVAL;
599 if (iucv_pathid_table[pathid]) {
600 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
601 printk(KERN_WARNING
602 "%s: Pathid being used, error.\n", __FUNCTION__);
603 return -EINVAL;
605 iucv_pathid_table[pathid] = handler;
607 iucv_debug(1, "exiting");
608 return 0;
609 } /* end of add_pathid function */
611 static int
612 iucv_add_pathid(__u16 pathid, handler *handler)
614 ulong flags;
615 int rc;
617 spin_lock_irqsave (&iucv_lock, flags);
618 rc = __iucv_add_pathid(pathid, handler);
619 spin_unlock_irqrestore (&iucv_lock, flags);
620 return rc;
623 static void
624 iucv_remove_pathid(__u16 pathid)
626 ulong flags;
628 if (pathid > (max_connections - 1))
629 return;
631 spin_lock_irqsave (&iucv_lock, flags);
632 iucv_pathid_table[pathid] = NULL;
633 spin_unlock_irqrestore (&iucv_lock, flags);
637 * iucv_declare_buffer_cpuid
638 * Register at VM for subsequent IUCV operations. This is executed
639 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
641 static void
642 iucv_declare_buffer_cpuid (void *result)
644 iparml_db *parm;
646 parm = (iparml_db *)grab_param();
647 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
648 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
649 *((ulong *)result) = parm->iprcode;
650 release_param(parm);
654 * iucv_retrieve_buffer_cpuid:
655 * Unregister IUCV usage at VM. This is always executed on the same
656 * cpu that registered the buffer to VM.
657 * Called from iucv_retrieve_buffer().
659 static void
660 iucv_retrieve_buffer_cpuid (void *cpu)
662 iparml_control *parm;
664 parm = (iparml_control *)grab_param();
665 b2f0(RETRIEVE_BUFFER, parm);
666 release_param(parm);
670 * Name: iucv_declare_buffer
671 * Purpose: Specifies the guests real address of an external
672 * interrupt.
673 * Input: void
674 * Output: iprcode - return code from b2f0 call
676 static int
677 iucv_declare_buffer (void)
679 unsigned long flags;
680 ulong b2f0_result;
682 iucv_debug(1, "entering");
683 b2f0_result = -ENODEV;
684 spin_lock_irqsave (&iucv_lock, flags);
685 if (iucv_cpuid == -1) {
686 /* Reserve any cpu for use by iucv. */
687 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
688 spin_unlock_irqrestore (&iucv_lock, flags);
689 smp_call_function_on(iucv_declare_buffer_cpuid,
690 &b2f0_result, 0, 1, iucv_cpuid);
691 if (b2f0_result) {
692 smp_put_cpu(iucv_cpuid);
693 iucv_cpuid = -1;
695 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
696 } else {
697 spin_unlock_irqrestore (&iucv_lock, flags);
698 b2f0_result = 0;
700 iucv_debug(1, "exiting");
701 return b2f0_result;
705 * iucv_retrieve_buffer:
707 * Terminates all use of IUCV.
708 * Returns: return code from CP
710 static int
711 iucv_retrieve_buffer (void)
713 iucv_debug(1, "entering");
714 if (iucv_cpuid != -1) {
715 smp_call_function_on(iucv_retrieve_buffer_cpuid,
716 0, 0, 1, iucv_cpuid);
717 /* Release the cpu reserved by iucv_declare_buffer. */
718 smp_put_cpu(iucv_cpuid);
719 iucv_cpuid = -1;
721 iucv_debug(1, "exiting");
722 return 0;
726 * iucv_remove_handler:
727 * @users_handler: handler to be removed
729 * Remove handler when application unregisters.
731 static void
732 iucv_remove_handler(handler *handler)
734 unsigned long flags;
736 if ((!iucv_pathid_table) || (!handler))
737 return;
739 iucv_debug(1, "entering");
741 spin_lock_irqsave (&iucv_lock, flags);
742 list_del(&handler->list);
743 if (list_empty(&iucv_handler_table)) {
744 if (register_flag) {
745 unregister_external_interrupt(0x4000, iucv_irq_handler);
746 register_flag = 0;
749 spin_unlock_irqrestore (&iucv_lock, flags);
751 iucv_debug(1, "exiting");
752 return;
756 * iucv_register_program:
757 * @pgmname: user identification
758 * @userid: machine identification
759 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
760 * used to determine who is given control.
761 * @ops: Address of interrupt handler table.
762 * @pgm_data: Application data to be passed to interrupt handlers.
764 * Registers an application with IUCV.
765 * Returns:
766 * The address of handler, or NULL on failure.
767 * NOTE on pgmmask:
768 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
769 * handler as is.
770 * If pgmmask is NULL, the internal mask is set to all 0xff's
771 * When userid is NULL, the first 8 bytes of the internal mask are forced
772 * to 0x00.
773 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
774 * are forced to 0x00 and the last 16 bytes to 0xff.
777 iucv_handle_t
778 iucv_register_program (__u8 pgmname[16],
779 __u8 userid[8],
780 __u8 pgmmask[24],
781 iucv_interrupt_ops_t * ops, void *pgm_data)
783 ulong rc = 0; /* return code from function calls */
784 handler *new_handler;
786 iucv_debug(1, "entering");
788 if (ops == NULL) {
789 /* interrupt table is not defined */
790 printk(KERN_WARNING "%s: Interrupt table is not defined, "
791 "exiting\n", __FUNCTION__);
792 return NULL;
794 if (!pgmname) {
795 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
796 return NULL;
799 /* Allocate handler entry */
800 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
801 if (new_handler == NULL) {
802 printk(KERN_WARNING "%s: storage allocation for new handler "
803 "failed.\n", __FUNCTION__);
804 return NULL;
807 if (!iucv_pathid_table) {
808 if (iucv_init()) {
809 kfree(new_handler);
810 return NULL;
813 max_connections = iucv_query_maxconn();
814 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
815 GFP_ATOMIC);
816 if (iucv_pathid_table == NULL) {
817 printk(KERN_WARNING "%s: iucv_pathid_table storage "
818 "allocation failed\n", __FUNCTION__);
819 kfree(new_handler);
820 return NULL;
822 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
824 memset(new_handler, 0, sizeof (handler));
825 memcpy(new_handler->id.user_data, pgmname,
826 sizeof (new_handler->id.user_data));
827 if (userid) {
828 memcpy (new_handler->id.userid, userid,
829 sizeof (new_handler->id.userid));
830 ASCEBC (new_handler->id.userid,
831 sizeof (new_handler->id.userid));
832 EBC_TOUPPER (new_handler->id.userid,
833 sizeof (new_handler->id.userid));
835 if (pgmmask) {
836 memcpy (new_handler->id.mask, pgmmask,
837 sizeof (new_handler->id.mask));
838 } else {
839 memset (new_handler->id.mask, 0xFF,
840 sizeof (new_handler->id.mask));
842 } else {
843 if (pgmmask) {
844 memcpy (new_handler->id.mask, pgmmask,
845 sizeof (new_handler->id.mask));
846 } else {
847 memset (new_handler->id.mask, 0xFF,
848 sizeof (new_handler->id.mask));
850 memset (new_handler->id.userid, 0x00,
851 sizeof (new_handler->id.userid));
853 /* fill in the rest of handler */
854 new_handler->pgm_data = pgm_data;
855 new_handler->interrupt_table = ops;
858 * Check if someone else is registered with same pgmname, userid
859 * and mask. If someone is already registered with same pgmname,
860 * userid and mask, registration will fail and NULL will be returned
861 * to the application.
862 * If identical handler not found, then handler is added to list.
864 rc = iucv_add_handler(new_handler);
865 if (rc) {
866 printk(KERN_WARNING "%s: Someone already registered with same "
867 "pgmname, userid, pgmmask\n", __FUNCTION__);
868 kfree (new_handler);
869 return NULL;
872 rc = iucv_declare_buffer();
873 if (rc) {
874 char *err = "Unknown";
875 iucv_remove_handler(new_handler);
876 kfree(new_handler);
877 switch(rc) {
878 case 0x03:
879 err = "Directory error";
880 break;
881 case 0x0a:
882 err = "Invalid length";
883 break;
884 case 0x13:
885 err = "Buffer already exists";
886 break;
887 case 0x3e:
888 err = "Buffer overlap";
889 break;
890 case 0x5c:
891 err = "Paging or storage error";
892 break;
894 printk(KERN_WARNING "%s: iucv_declare_buffer "
895 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
896 return NULL;
898 if (!register_flag) {
899 /* request the 0x4000 external interrupt */
900 rc = register_external_interrupt (0x4000, iucv_irq_handler);
901 if (rc) {
902 iucv_remove_handler(new_handler);
903 kfree (new_handler);
904 printk(KERN_WARNING "%s: "
905 "register_external_interrupt returned %ld\n",
906 __FUNCTION__, rc);
907 return NULL;
910 register_flag = 1;
912 iucv_debug(1, "exiting");
913 return new_handler;
914 } /* end of register function */
917 * iucv_unregister_program:
918 * @handle: address of handler
920 * Unregister application with IUCV.
921 * Returns:
922 * 0 on success, -EINVAL, if specified handle is invalid.
926 iucv_unregister_program (iucv_handle_t handle)
928 handler *h = NULL;
929 struct list_head *lh;
930 int i;
931 ulong flags;
933 iucv_debug(1, "entering");
934 iucv_debug(1, "address of handler is %p", h);
936 /* Checking if handle is valid */
937 spin_lock_irqsave (&iucv_lock, flags);
938 list_for_each(lh, &iucv_handler_table) {
939 if ((handler *)handle == list_entry(lh, handler, list)) {
940 h = (handler *)handle;
941 break;
944 if (!h) {
945 spin_unlock_irqrestore (&iucv_lock, flags);
946 if (handle)
947 printk(KERN_WARNING
948 "%s: Handler not found in iucv_handler_table.\n",
949 __FUNCTION__);
950 else
951 printk(KERN_WARNING
952 "%s: NULL handle passed by application.\n",
953 __FUNCTION__);
954 return -EINVAL;
958 * First, walk thru iucv_pathid_table and sever any pathid which is
959 * still pointing to the handler to be removed.
961 for (i = 0; i < max_connections; i++)
962 if (iucv_pathid_table[i] == h) {
963 spin_unlock_irqrestore (&iucv_lock, flags);
964 iucv_sever(i, h->id.user_data);
965 spin_lock_irqsave(&iucv_lock, flags);
967 spin_unlock_irqrestore (&iucv_lock, flags);
969 iucv_remove_handler(h);
970 kfree(h);
972 iucv_debug(1, "exiting");
973 return 0;
977 * iucv_accept:
978 * @pathid: Path identification number
979 * @msglim_reqstd: The number of outstanding messages requested.
980 * @user_data: Data specified by the iucv_connect function.
981 * @flags1: Contains options for this path.
982 * - IPPRTY (0x20) Specifies if you want to send priority message.
983 * - IPRMDATA (0x80) Specifies whether your program can handle a message
984 * in the parameter list.
985 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
986 * established.
987 * @handle: Address of handler.
988 * @pgm_data: Application data passed to interrupt handlers.
989 * @flags1_out: Pointer to an int. If not NULL, on return the options for
990 * the path are stored at the given location:
991 * - IPPRTY (0x20) Indicates you may send a priority message.
992 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
993 * number of outstanding messages is stored at the given
994 * location.
996 * This function is issued after the user receives a Connection Pending external
997 * interrupt and now wishes to complete the IUCV communication path.
998 * Returns:
999 * return code from CP
1002 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
1003 __u8 user_data[16], int flags1,
1004 iucv_handle_t handle, void *pgm_data,
1005 int *flags1_out, __u16 * msglim)
1007 ulong b2f0_result = 0;
1008 ulong flags;
1009 struct list_head *lh;
1010 handler *h = NULL;
1011 iparml_control *parm;
1013 iucv_debug(1, "entering");
1014 iucv_debug(1, "pathid = %d", pathid);
1016 /* Checking if handle is valid */
1017 spin_lock_irqsave (&iucv_lock, flags);
1018 list_for_each(lh, &iucv_handler_table) {
1019 if ((handler *)handle == list_entry(lh, handler, list)) {
1020 h = (handler *)handle;
1021 break;
1024 spin_unlock_irqrestore (&iucv_lock, flags);
1026 if (!h) {
1027 if (handle)
1028 printk(KERN_WARNING
1029 "%s: Handler not found in iucv_handler_table.\n",
1030 __FUNCTION__);
1031 else
1032 printk(KERN_WARNING
1033 "%s: NULL handle passed by application.\n",
1034 __FUNCTION__);
1035 return -EINVAL;
1038 parm = (iparml_control *)grab_param();
1040 parm->ippathid = pathid;
1041 parm->ipmsglim = msglim_reqstd;
1042 if (user_data)
1043 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1045 parm->ipflags1 = (__u8)flags1;
1046 b2f0_result = b2f0(ACCEPT, parm);
1048 if (!b2f0_result) {
1049 if (msglim)
1050 *msglim = parm->ipmsglim;
1051 if (pgm_data)
1052 h->pgm_data = pgm_data;
1053 if (flags1_out)
1054 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1056 release_param(parm);
1058 iucv_debug(1, "exiting");
1059 return b2f0_result;
1063 * iucv_connect:
1064 * @pathid: Path identification number
1065 * @msglim_reqstd: Number of outstanding messages requested
1066 * @user_data: 16-byte user data
1067 * @userid: 8-byte of user identification
1068 * @system_name: 8-byte identifying the system name
1069 * @flags1: Specifies options for this path:
1070 * - IPPRTY (0x20) Specifies if you want to send priority message.
1071 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1072 * in the parameter list.
1073 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1074 * established.
1075 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1076 * local system. If local is specified then target class
1077 * cannot be specified.
1078 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1079 * the path are stored at the given location:
1080 * - IPPRTY (0x20) Indicates you may send a priority message.
1081 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1082 * number of outstanding messages is stored at the given
1083 * location.
1084 * @handle: Address of handler.
1085 * @pgm_data: Application data to be passed to interrupt handlers.
1087 * This function establishes an IUCV path. Although the connect may complete
1088 * successfully, you are not able to use the path until you receive an IUCV
1089 * Connection Complete external interrupt.
1090 * Returns: return code from CP, or one of the following
1091 * - ENOMEM
1092 * - return code from iucv_declare_buffer
1093 * - EINVAL - invalid handle passed by application
1094 * - EINVAL - pathid address is NULL
1095 * - ENOMEM - pathid table storage allocation failed
1096 * - return code from internal function add_pathid
1099 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1100 __u8 user_data[16], __u8 userid[8],
1101 __u8 system_name[8], int flags1,
1102 int *flags1_out, __u16 * msglim,
1103 iucv_handle_t handle, void *pgm_data)
1105 iparml_control *parm;
1106 iparml_control local_parm;
1107 struct list_head *lh;
1108 ulong b2f0_result = 0;
1109 ulong flags;
1110 int add_pathid_result = 0;
1111 handler *h = NULL;
1112 __u8 no_memory[16] = "NO MEMORY";
1114 iucv_debug(1, "entering");
1116 /* Checking if handle is valid */
1117 spin_lock_irqsave (&iucv_lock, flags);
1118 list_for_each(lh, &iucv_handler_table) {
1119 if ((handler *)handle == list_entry(lh, handler, list)) {
1120 h = (handler *)handle;
1121 break;
1124 spin_unlock_irqrestore (&iucv_lock, flags);
1126 if (!h) {
1127 if (handle)
1128 printk(KERN_WARNING
1129 "%s: Handler not found in iucv_handler_table.\n",
1130 __FUNCTION__);
1131 else
1132 printk(KERN_WARNING
1133 "%s: NULL handle passed by application.\n",
1134 __FUNCTION__);
1135 return -EINVAL;
1138 if (pathid == NULL) {
1139 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1140 __FUNCTION__);
1141 return -EINVAL;
1144 parm = (iparml_control *)grab_param();
1146 parm->ipmsglim = msglim_reqstd;
1148 if (user_data)
1149 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1151 if (userid) {
1152 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1153 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1154 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1157 if (system_name) {
1158 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1159 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1160 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1163 /* In order to establish an IUCV connection, the procedure is:
1165 * b2f0(CONNECT)
1166 * take the ippathid from the b2f0 call
1167 * register the handler to the ippathid
1169 * Unfortunately, the ConnectionEstablished message gets sent after the
1170 * b2f0(CONNECT) call but before the register is handled.
1172 * In order for this race condition to be eliminated, the IUCV Control
1173 * Interrupts must be disabled for the above procedure.
1175 * David Kennedy <dkennedy@linuxcare.com>
1178 /* Enable everything but IUCV Control messages */
1179 iucv_setmask(~(AllInterrupts));
1180 messagesDisabled = 1;
1182 spin_lock_irqsave (&iucv_lock, flags);
1183 parm->ipflags1 = (__u8)flags1;
1184 b2f0_result = b2f0(CONNECT, parm);
1185 memcpy(&local_parm, parm, sizeof(local_parm));
1186 release_param(parm);
1187 parm = &local_parm;
1188 if (!b2f0_result)
1189 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1190 spin_unlock_irqrestore (&iucv_lock, flags);
1192 if (b2f0_result) {
1193 iucv_setmask(~0);
1194 messagesDisabled = 0;
1195 return b2f0_result;
1198 *pathid = parm->ippathid;
1200 /* Enable everything again */
1201 iucv_setmask(IUCVControlInterruptsFlag);
1203 if (msglim)
1204 *msglim = parm->ipmsglim;
1205 if (flags1_out)
1206 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1208 if (add_pathid_result) {
1209 iucv_sever(*pathid, no_memory);
1210 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1211 " %d\n", __FUNCTION__, add_pathid_result);
1212 return(add_pathid_result);
1215 iucv_debug(1, "exiting");
1216 return b2f0_result;
1220 * iucv_purge:
1221 * @pathid: Path identification number
1222 * @msgid: Message ID of message to purge.
1223 * @srccls: Message class of the message to purge.
1224 * @audit: Pointer to an __u32. If not NULL, on return, information about
1225 * asynchronous errors that may have affected the normal completion
1226 * of this message ist stored at the given location.
1228 * Cancels a message you have sent.
1229 * Returns: return code from CP
1232 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1234 iparml_purge *parm;
1235 ulong b2f0_result = 0;
1237 iucv_debug(1, "entering");
1238 iucv_debug(1, "pathid = %d", pathid);
1240 parm = (iparml_purge *)grab_param();
1242 parm->ipmsgid = msgid;
1243 parm->ippathid = pathid;
1244 parm->ipsrccls = srccls;
1245 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1246 b2f0_result = b2f0(PURGE, parm);
1248 if (!b2f0_result && audit) {
1249 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1250 /* parm->ipaudit has only 3 bytes */
1251 *audit >>= 8;
1254 release_param(parm);
1256 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1257 iucv_debug(1, "exiting");
1258 return b2f0_result;
1262 * iucv_query_generic:
1263 * @want_maxconn: Flag, describing which value is to be returned.
1265 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1267 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1268 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1270 static int
1271 iucv_query_generic(int want_maxconn)
1273 iparml_purge *parm = (iparml_purge *)grab_param();
1274 int bufsize, maxconn;
1275 int ccode;
1278 * Call b2f0 and store R0 (max buffer size),
1279 * R1 (max connections) and CC.
1281 asm volatile (
1282 "LRA 1,0(%4)\n\t"
1283 "LR 0,%3\n\t"
1284 ".long 0xb2f01000\n\t"
1285 "IPM %0\n\t"
1286 "SRL %0,28\n\t"
1287 "ST 0,%1\n\t"
1288 "ST 1,%2\n\t"
1289 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1290 : "d" (QUERY), "a" (parm)
1291 : "0", "1", "cc"
1293 release_param(parm);
1295 if (ccode)
1296 return -EPERM;
1297 if (want_maxconn)
1298 return maxconn;
1299 return bufsize;
1303 * iucv_query_maxconn:
1305 * Determines the maximum number of connections thay may be established.
1307 * Returns: Maximum number of connections that can be.
1309 ulong
1310 iucv_query_maxconn(void)
1312 return iucv_query_generic(1);
1316 * iucv_query_bufsize:
1318 * Determines the size of the external interrupt buffer.
1320 * Returns: Size of external interrupt buffer.
1322 ulong
1323 iucv_query_bufsize (void)
1325 return iucv_query_generic(0);
1329 * iucv_quiesce:
1330 * @pathid: Path identification number
1331 * @user_data: 16-byte user data
1333 * Temporarily suspends incoming messages on an IUCV path.
1334 * You can later reactivate the path by invoking the iucv_resume function.
1335 * Returns: return code from CP
1338 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1340 iparml_control *parm;
1341 ulong b2f0_result = 0;
1343 iucv_debug(1, "entering");
1344 iucv_debug(1, "pathid = %d", pathid);
1346 parm = (iparml_control *)grab_param();
1348 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1349 parm->ippathid = pathid;
1351 b2f0_result = b2f0(QUIESCE, parm);
1352 release_param(parm);
1354 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1355 iucv_debug(1, "exiting");
1357 return b2f0_result;
1361 * iucv_receive:
1362 * @pathid: Path identification number.
1363 * @buffer: Address of buffer to receive. Must be below 2G.
1364 * @buflen: Length of buffer to receive.
1365 * @msgid: Specifies the message ID.
1366 * @trgcls: Specifies target class.
1367 * @flags1_out: Receives options for path on return.
1368 * - IPNORPY (0x10) Specifies whether a reply is required
1369 * - IPPRTY (0x20) Specifies if you want to send priority message
1370 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1371 * @residual_buffer: Receives the address of buffer updated by the number
1372 * of bytes you have received on return.
1373 * @residual_length: On return, receives one of the following values:
1374 * - 0 If the receive buffer is the same length as
1375 * the message.
1376 * - Remaining bytes in buffer If the receive buffer is longer than the
1377 * message.
1378 * - Remaining bytes in message If the receive buffer is shorter than the
1379 * message.
1381 * This function receives messages that are being sent to you over established
1382 * paths.
1383 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1384 * than the message, always 5
1385 * -EINVAL - buffer address is pointing to NULL
1388 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1389 void *buffer, ulong buflen,
1390 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1392 iparml_db *parm;
1393 ulong b2f0_result;
1394 int moved = 0; /* number of bytes moved from parmlist to buffer */
1396 iucv_debug(2, "entering");
1398 if (!buffer)
1399 return -EINVAL;
1401 parm = (iparml_db *)grab_param();
1403 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1404 parm->ipbfln1f = (__u32) ((ulong) buflen);
1405 parm->ipmsgid = msgid;
1406 parm->ippathid = pathid;
1407 parm->iptrgcls = trgcls;
1408 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1410 b2f0_result = b2f0(RECEIVE, parm);
1412 if (!b2f0_result || b2f0_result == 5) {
1413 if (flags1_out) {
1414 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1415 *flags1_out = (parm->ipflags1 & (~0x07));
1416 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1419 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1420 if (residual_length)
1421 *residual_length = parm->ipbfln1f;
1423 if (residual_buffer)
1424 *residual_buffer = parm->ipbfadr1;
1425 } else {
1426 moved = min_t (unsigned long, buflen, 8);
1428 memcpy ((char *) buffer,
1429 (char *) &parm->ipbfadr1, moved);
1431 if (buflen < 8)
1432 b2f0_result = 5;
1434 if (residual_length)
1435 *residual_length = abs (buflen - 8);
1437 if (residual_buffer)
1438 *residual_buffer = (ulong) (buffer + moved);
1441 release_param(parm);
1443 iucv_debug(2, "exiting");
1444 return b2f0_result;
1448 * Name: iucv_receive_array
1449 * Purpose: This function receives messages that are being sent to you
1450 * over established paths.
1451 * Input: pathid - path identification number
1452 * buffer - address of array of buffers
1453 * buflen - total length of buffers
1454 * msgid - specifies the message ID.
1455 * trgcls - specifies target class
1456 * Output:
1457 * flags1_out: Options for path.
1458 * IPNORPY - 0x10 specifies whether a reply is required
1459 * IPPRTY - 0x20 specifies if you want to send priority message
1460 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1461 * residual_buffer - address points to the current list entry IUCV
1462 * is working on.
1463 * residual_length -
1464 * Contains one of the following values, if the receive buffer is:
1465 * The same length as the message, this field is zero.
1466 * Longer than the message, this field contains the number of
1467 * bytes remaining in the buffer.
1468 * Shorter than the message, this field contains the residual
1469 * count (that is, the number of bytes remaining in the
1470 * message that does not fit into the buffer. In this case
1471 * b2f0_result = 5.
1472 * Return: b2f0_result - return code from CP
1473 * (-EINVAL) - buffer address is NULL
1476 iucv_receive_array (__u16 pathid,
1477 __u32 msgid, __u32 trgcls,
1478 iucv_array_t * buffer, ulong buflen,
1479 int *flags1_out,
1480 ulong * residual_buffer, ulong * residual_length)
1482 iparml_db *parm;
1483 ulong b2f0_result;
1484 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1486 iucv_debug(2, "entering");
1488 if (!buffer)
1489 return -EINVAL;
1491 parm = (iparml_db *)grab_param();
1493 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1494 parm->ipbfln1f = (__u32) buflen;
1495 parm->ipmsgid = msgid;
1496 parm->ippathid = pathid;
1497 parm->iptrgcls = trgcls;
1498 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1500 b2f0_result = b2f0(RECEIVE, parm);
1502 if (!b2f0_result || b2f0_result == 5) {
1504 if (flags1_out) {
1505 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1506 *flags1_out = (parm->ipflags1 & (~0x07));
1507 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1510 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1512 if (residual_length)
1513 *residual_length = parm->ipbfln1f;
1515 if (residual_buffer)
1516 *residual_buffer = parm->ipbfadr1;
1518 } else {
1519 /* copy msg from parmlist to users array. */
1521 while ((moved < 8) && (moved < buflen)) {
1522 dyn_len =
1523 min_t (unsigned int,
1524 (buffer + i)->length, need_to_move);
1526 memcpy ((char *)((ulong)((buffer + i)->address)),
1527 ((char *) &parm->ipbfadr1) + moved,
1528 dyn_len);
1530 moved += dyn_len;
1531 need_to_move -= dyn_len;
1533 (buffer + i)->address =
1534 (__u32)
1535 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1536 + dyn_len);
1538 (buffer + i)->length -= dyn_len;
1539 i++;
1542 if (need_to_move) /* buflen < 8 bytes */
1543 b2f0_result = 5;
1545 if (residual_length)
1546 *residual_length = abs (buflen - 8);
1548 if (residual_buffer) {
1549 if (!moved)
1550 *residual_buffer = (ulong) buffer;
1551 else
1552 *residual_buffer =
1553 (ulong) (buffer + (i - 1));
1558 release_param(parm);
1560 iucv_debug(2, "exiting");
1561 return b2f0_result;
1565 * iucv_reject:
1566 * @pathid: Path identification number.
1567 * @msgid: Message ID of the message to reject.
1568 * @trgcls: Target class of the message to reject.
1569 * Returns: return code from CP
1571 * Refuses a specified message. Between the time you are notified of a
1572 * message and the time that you complete the message, the message may
1573 * be rejected.
1576 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1578 iparml_db *parm;
1579 ulong b2f0_result = 0;
1581 iucv_debug(1, "entering");
1582 iucv_debug(1, "pathid = %d", pathid);
1584 parm = (iparml_db *)grab_param();
1586 parm->ippathid = pathid;
1587 parm->ipmsgid = msgid;
1588 parm->iptrgcls = trgcls;
1589 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1591 b2f0_result = b2f0(REJECT, parm);
1592 release_param(parm);
1594 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1595 iucv_debug(1, "exiting");
1597 return b2f0_result;
1601 * Name: iucv_reply
1602 * Purpose: This function responds to the two-way messages that you
1603 * receive. You must identify completely the message to
1604 * which you wish to reply. ie, pathid, msgid, and trgcls.
1605 * Input: pathid - path identification number
1606 * msgid - specifies the message ID.
1607 * trgcls - specifies target class
1608 * flags1 - option for path
1609 * IPPRTY- 0x20 - specifies if you want to send priority message
1610 * buffer - address of reply buffer
1611 * buflen - length of reply buffer
1612 * Output: ipbfadr2 - Address of buffer updated by the number
1613 * of bytes you have moved.
1614 * ipbfln2f - Contains one of the following values:
1615 * If the answer buffer is the same length as the reply, this field
1616 * contains zero.
1617 * If the answer buffer is longer than the reply, this field contains
1618 * the number of bytes remaining in the buffer.
1619 * If the answer buffer is shorter than the reply, this field contains
1620 * a residual count (that is, the number of bytes remianing in the
1621 * reply that does not fit into the buffer. In this
1622 * case b2f0_result = 5.
1623 * Return: b2f0_result - return code from CP
1624 * (-EINVAL) - buffer address is NULL
1627 iucv_reply (__u16 pathid,
1628 __u32 msgid, __u32 trgcls,
1629 int flags1,
1630 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1632 iparml_db *parm;
1633 ulong b2f0_result;
1635 iucv_debug(2, "entering");
1637 if (!buffer)
1638 return -EINVAL;
1640 parm = (iparml_db *)grab_param();
1642 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1643 parm->ipbfln2f = (__u32) buflen; /* length of message */
1644 parm->ippathid = pathid;
1645 parm->ipmsgid = msgid;
1646 parm->iptrgcls = trgcls;
1647 parm->ipflags1 = (__u8) flags1; /* priority message */
1649 b2f0_result = b2f0(REPLY, parm);
1651 if ((!b2f0_result) || (b2f0_result == 5)) {
1652 if (ipbfadr2)
1653 *ipbfadr2 = parm->ipbfadr2;
1654 if (ipbfln2f)
1655 *ipbfln2f = parm->ipbfln2f;
1657 release_param(parm);
1659 iucv_debug(2, "exiting");
1661 return b2f0_result;
1665 * Name: iucv_reply_array
1666 * Purpose: This function responds to the two-way messages that you
1667 * receive. You must identify completely the message to
1668 * which you wish to reply. ie, pathid, msgid, and trgcls.
1669 * The array identifies a list of addresses and lengths of
1670 * discontiguous buffers that contains the reply data.
1671 * Input: pathid - path identification number
1672 * msgid - specifies the message ID.
1673 * trgcls - specifies target class
1674 * flags1 - option for path
1675 * IPPRTY- specifies if you want to send priority message
1676 * buffer - address of array of reply buffers
1677 * buflen - total length of reply buffers
1678 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1679 * ipbfln2f - Contains one of the following values:
1680 * If the answer buffer is the same length as the reply, this field
1681 * contains zero.
1682 * If the answer buffer is longer than the reply, this field contains
1683 * the number of bytes remaining in the buffer.
1684 * If the answer buffer is shorter than the reply, this field contains
1685 * a residual count (that is, the number of bytes remianing in the
1686 * reply that does not fit into the buffer. In this
1687 * case b2f0_result = 5.
1688 * Return: b2f0_result - return code from CP
1689 * (-EINVAL) - buffer address is NULL
1692 iucv_reply_array (__u16 pathid,
1693 __u32 msgid, __u32 trgcls,
1694 int flags1,
1695 iucv_array_t * buffer,
1696 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1698 iparml_db *parm;
1699 ulong b2f0_result;
1701 iucv_debug(2, "entering");
1703 if (!buffer)
1704 return -EINVAL;
1706 parm = (iparml_db *)grab_param();
1708 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1709 parm->ipbfln2f = buflen; /* length of message */
1710 parm->ippathid = pathid;
1711 parm->ipmsgid = msgid;
1712 parm->iptrgcls = trgcls;
1713 parm->ipflags1 = (IPANSLST | flags1);
1715 b2f0_result = b2f0(REPLY, parm);
1717 if ((!b2f0_result) || (b2f0_result == 5)) {
1719 if (ipbfadr2)
1720 *ipbfadr2 = parm->ipbfadr2;
1721 if (ipbfln2f)
1722 *ipbfln2f = parm->ipbfln2f;
1724 release_param(parm);
1726 iucv_debug(2, "exiting");
1728 return b2f0_result;
1732 * Name: iucv_reply_prmmsg
1733 * Purpose: This function responds to the two-way messages that you
1734 * receive. You must identify completely the message to
1735 * which you wish to reply. ie, pathid, msgid, and trgcls.
1736 * Prmmsg signifies the data is moved into the
1737 * parameter list.
1738 * Input: pathid - path identification number
1739 * msgid - specifies the message ID.
1740 * trgcls - specifies target class
1741 * flags1 - option for path
1742 * IPPRTY- specifies if you want to send priority message
1743 * prmmsg - 8-bytes of data to be placed into the parameter
1744 * list.
1745 * Output: NA
1746 * Return: b2f0_result - return code from CP
1749 iucv_reply_prmmsg (__u16 pathid,
1750 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1752 iparml_dpl *parm;
1753 ulong b2f0_result;
1755 iucv_debug(2, "entering");
1757 parm = (iparml_dpl *)grab_param();
1759 parm->ippathid = pathid;
1760 parm->ipmsgid = msgid;
1761 parm->iptrgcls = trgcls;
1762 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1763 parm->ipflags1 = (IPRMDATA | flags1);
1765 b2f0_result = b2f0(REPLY, parm);
1766 release_param(parm);
1768 iucv_debug(2, "exiting");
1770 return b2f0_result;
1774 * iucv_resume:
1775 * @pathid: Path identification number
1776 * @user_data: 16-byte of user data
1778 * This function restores communication over a quiesced path.
1779 * Returns: return code from CP
1782 iucv_resume (__u16 pathid, __u8 user_data[16])
1784 iparml_control *parm;
1785 ulong b2f0_result = 0;
1787 iucv_debug(1, "entering");
1788 iucv_debug(1, "pathid = %d", pathid);
1790 parm = (iparml_control *)grab_param();
1792 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1793 parm->ippathid = pathid;
1795 b2f0_result = b2f0(RESUME, parm);
1796 release_param(parm);
1798 iucv_debug(1, "exiting");
1800 return b2f0_result;
1804 * Name: iucv_send
1805 * Purpose: sends messages
1806 * Input: pathid - ushort, pathid
1807 * msgid - ulong *, id of message returned to caller
1808 * trgcls - ulong, target message class
1809 * srccls - ulong, source message class
1810 * msgtag - ulong, message tag
1811 * flags1 - Contains options for this path.
1812 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1813 * buffer - pointer to buffer
1814 * buflen - ulong, length of buffer
1815 * Output: b2f0_result - return code from b2f0 call
1816 * msgid - returns message id
1819 iucv_send (__u16 pathid, __u32 * msgid,
1820 __u32 trgcls, __u32 srccls,
1821 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1823 iparml_db *parm;
1824 ulong b2f0_result;
1826 iucv_debug(2, "entering");
1828 if (!buffer)
1829 return -EINVAL;
1831 parm = (iparml_db *)grab_param();
1833 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1834 parm->ippathid = pathid;
1835 parm->iptrgcls = trgcls;
1836 parm->ipbfln1f = (__u32) buflen; /* length of message */
1837 parm->ipsrccls = srccls;
1838 parm->ipmsgtag = msgtag;
1839 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1841 b2f0_result = b2f0(SEND, parm);
1843 if ((!b2f0_result) && (msgid))
1844 *msgid = parm->ipmsgid;
1845 release_param(parm);
1847 iucv_debug(2, "exiting");
1849 return b2f0_result;
1853 * Name: iucv_send_array
1854 * Purpose: This function transmits data to another application.
1855 * The contents of buffer is the address of the array of
1856 * addresses and lengths of discontiguous buffers that hold
1857 * the message text. This is a one-way message and the
1858 * receiver will not reply to the message.
1859 * Input: pathid - path identification number
1860 * trgcls - specifies target class
1861 * srccls - specifies the source message class
1862 * msgtag - specifies a tag to be associated witht the message
1863 * flags1 - option for path
1864 * IPPRTY- specifies if you want to send priority message
1865 * buffer - address of array of send buffers
1866 * buflen - total length of send buffers
1867 * Output: msgid - specifies the message ID.
1868 * Return: b2f0_result - return code from CP
1869 * (-EINVAL) - buffer address is NULL
1872 iucv_send_array (__u16 pathid,
1873 __u32 * msgid,
1874 __u32 trgcls,
1875 __u32 srccls,
1876 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1878 iparml_db *parm;
1879 ulong b2f0_result;
1881 iucv_debug(2, "entering");
1883 if (!buffer)
1884 return -EINVAL;
1886 parm = (iparml_db *)grab_param();
1888 parm->ippathid = pathid;
1889 parm->iptrgcls = trgcls;
1890 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1891 parm->ipbfln1f = (__u32) buflen; /* length of message */
1892 parm->ipsrccls = srccls;
1893 parm->ipmsgtag = msgtag;
1894 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1895 b2f0_result = b2f0(SEND, parm);
1897 if ((!b2f0_result) && (msgid))
1898 *msgid = parm->ipmsgid;
1899 release_param(parm);
1901 iucv_debug(2, "exiting");
1902 return b2f0_result;
1906 * Name: iucv_send_prmmsg
1907 * Purpose: This function transmits data to another application.
1908 * Prmmsg specifies that the 8-bytes of data are to be moved
1909 * into the parameter list. This is a one-way message and the
1910 * receiver will not reply to the message.
1911 * Input: pathid - path identification number
1912 * trgcls - specifies target class
1913 * srccls - specifies the source message class
1914 * msgtag - specifies a tag to be associated with the message
1915 * flags1 - option for path
1916 * IPPRTY- specifies if you want to send priority message
1917 * prmmsg - 8-bytes of data to be placed into parameter list
1918 * Output: msgid - specifies the message ID.
1919 * Return: b2f0_result - return code from CP
1922 iucv_send_prmmsg (__u16 pathid,
1923 __u32 * msgid,
1924 __u32 trgcls,
1925 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1927 iparml_dpl *parm;
1928 ulong b2f0_result;
1930 iucv_debug(2, "entering");
1932 parm = (iparml_dpl *)grab_param();
1934 parm->ippathid = pathid;
1935 parm->iptrgcls = trgcls;
1936 parm->ipsrccls = srccls;
1937 parm->ipmsgtag = msgtag;
1938 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1939 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1941 b2f0_result = b2f0(SEND, parm);
1943 if ((!b2f0_result) && (msgid))
1944 *msgid = parm->ipmsgid;
1945 release_param(parm);
1947 iucv_debug(2, "exiting");
1949 return b2f0_result;
1953 * Name: iucv_send2way
1954 * Purpose: This function transmits data to another application.
1955 * Data to be transmitted is in a buffer. The receiver
1956 * of the send is expected to reply to the message and
1957 * a buffer is provided into which IUCV moves the reply
1958 * to this message.
1959 * Input: pathid - path identification number
1960 * trgcls - specifies target class
1961 * srccls - specifies the source message class
1962 * msgtag - specifies a tag associated with the message
1963 * flags1 - option for path
1964 * IPPRTY- specifies if you want to send priority message
1965 * buffer - address of send buffer
1966 * buflen - length of send buffer
1967 * ansbuf - address of buffer to reply with
1968 * anslen - length of buffer to reply with
1969 * Output: msgid - specifies the message ID.
1970 * Return: b2f0_result - return code from CP
1971 * (-EINVAL) - buffer or ansbuf address is NULL
1974 iucv_send2way (__u16 pathid,
1975 __u32 * msgid,
1976 __u32 trgcls,
1977 __u32 srccls,
1978 __u32 msgtag,
1979 int flags1,
1980 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1982 iparml_db *parm;
1983 ulong b2f0_result;
1985 iucv_debug(2, "entering");
1987 if (!buffer || !ansbuf)
1988 return -EINVAL;
1990 parm = (iparml_db *)grab_param();
1992 parm->ippathid = pathid;
1993 parm->iptrgcls = trgcls;
1994 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1995 parm->ipbfln1f = (__u32) buflen; /* length of message */
1996 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1997 parm->ipbfln2f = (__u32) anslen;
1998 parm->ipsrccls = srccls;
1999 parm->ipmsgtag = msgtag;
2000 parm->ipflags1 = flags1; /* priority message */
2002 b2f0_result = b2f0(SEND, parm);
2004 if ((!b2f0_result) && (msgid))
2005 *msgid = parm->ipmsgid;
2006 release_param(parm);
2008 iucv_debug(2, "exiting");
2010 return b2f0_result;
2014 * Name: iucv_send2way_array
2015 * Purpose: This function transmits data to another application.
2016 * The contents of buffer is the address of the array of
2017 * addresses and lengths of discontiguous buffers that hold
2018 * the message text. The receiver of the send is expected to
2019 * reply to the message and a buffer is provided into which
2020 * IUCV moves the reply to this message.
2021 * Input: pathid - path identification number
2022 * trgcls - specifies target class
2023 * srccls - specifies the source message class
2024 * msgtag - spcifies a tag to be associated with the message
2025 * flags1 - option for path
2026 * IPPRTY- specifies if you want to send priority message
2027 * buffer - address of array of send buffers
2028 * buflen - total length of send buffers
2029 * ansbuf - address of buffer to reply with
2030 * anslen - length of buffer to reply with
2031 * Output: msgid - specifies the message ID.
2032 * Return: b2f0_result - return code from CP
2033 * (-EINVAL) - buffer address is NULL
2036 iucv_send2way_array (__u16 pathid,
2037 __u32 * msgid,
2038 __u32 trgcls,
2039 __u32 srccls,
2040 __u32 msgtag,
2041 int flags1,
2042 iucv_array_t * buffer,
2043 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2045 iparml_db *parm;
2046 ulong b2f0_result;
2048 iucv_debug(2, "entering");
2050 if (!buffer || !ansbuf)
2051 return -EINVAL;
2053 parm = (iparml_db *)grab_param();
2055 parm->ippathid = pathid;
2056 parm->iptrgcls = trgcls;
2057 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2058 parm->ipbfln1f = (__u32) buflen; /* length of message */
2059 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2060 parm->ipbfln2f = (__u32) anslen;
2061 parm->ipsrccls = srccls;
2062 parm->ipmsgtag = msgtag;
2063 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2064 b2f0_result = b2f0(SEND, parm);
2065 if ((!b2f0_result) && (msgid))
2066 *msgid = parm->ipmsgid;
2067 release_param(parm);
2069 iucv_debug(2, "exiting");
2070 return b2f0_result;
2074 * Name: iucv_send2way_prmmsg
2075 * Purpose: This function transmits data to another application.
2076 * Prmmsg specifies that the 8-bytes of data are to be moved
2077 * into the parameter list. This is a two-way message and the
2078 * receiver of the message is expected to reply. A buffer
2079 * is provided into which IUCV moves the reply to this
2080 * message.
2081 * Input: pathid - path identification number
2082 * trgcls - specifies target class
2083 * srccls - specifies the source message class
2084 * msgtag - specifies a tag to be associated with the message
2085 * flags1 - option for path
2086 * IPPRTY- specifies if you want to send priority message
2087 * prmmsg - 8-bytes of data to be placed in parameter list
2088 * ansbuf - address of buffer to reply with
2089 * anslen - length of buffer to reply with
2090 * Output: msgid - specifies the message ID.
2091 * Return: b2f0_result - return code from CP
2092 * (-EINVAL) - buffer address is NULL
2095 iucv_send2way_prmmsg (__u16 pathid,
2096 __u32 * msgid,
2097 __u32 trgcls,
2098 __u32 srccls,
2099 __u32 msgtag,
2100 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2102 iparml_dpl *parm;
2103 ulong b2f0_result;
2105 iucv_debug(2, "entering");
2107 if (!ansbuf)
2108 return -EINVAL;
2110 parm = (iparml_dpl *)grab_param();
2112 parm->ippathid = pathid;
2113 parm->iptrgcls = trgcls;
2114 parm->ipsrccls = srccls;
2115 parm->ipmsgtag = msgtag;
2116 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2117 parm->ipbfln2f = (__u32) anslen;
2118 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2119 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2121 b2f0_result = b2f0(SEND, parm);
2123 if ((!b2f0_result) && (msgid))
2124 *msgid = parm->ipmsgid;
2125 release_param(parm);
2127 iucv_debug(2, "exiting");
2129 return b2f0_result;
2133 * Name: iucv_send2way_prmmsg_array
2134 * Purpose: This function transmits data to another application.
2135 * Prmmsg specifies that the 8-bytes of data are to be moved
2136 * into the parameter list. This is a two-way message and the
2137 * receiver of the message is expected to reply. A buffer
2138 * is provided into which IUCV moves the reply to this
2139 * message. The contents of ansbuf is the address of the
2140 * array of addresses and lengths of discontiguous buffers
2141 * that contain the reply.
2142 * Input: pathid - path identification number
2143 * trgcls - specifies target class
2144 * srccls - specifies the source message class
2145 * msgtag - specifies a tag to be associated with the message
2146 * flags1 - option for path
2147 * IPPRTY- specifies if you want to send priority message
2148 * prmmsg - 8-bytes of data to be placed into the parameter list
2149 * ansbuf - address of buffer to reply with
2150 * anslen - length of buffer to reply with
2151 * Output: msgid - specifies the message ID.
2152 * Return: b2f0_result - return code from CP
2153 * (-EINVAL) - ansbuf address is NULL
2156 iucv_send2way_prmmsg_array (__u16 pathid,
2157 __u32 * msgid,
2158 __u32 trgcls,
2159 __u32 srccls,
2160 __u32 msgtag,
2161 int flags1,
2162 __u8 prmmsg[8],
2163 iucv_array_t * ansbuf, ulong anslen)
2165 iparml_dpl *parm;
2166 ulong b2f0_result;
2168 iucv_debug(2, "entering");
2170 if (!ansbuf)
2171 return -EINVAL;
2173 parm = (iparml_dpl *)grab_param();
2175 parm->ippathid = pathid;
2176 parm->iptrgcls = trgcls;
2177 parm->ipsrccls = srccls;
2178 parm->ipmsgtag = msgtag;
2179 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2180 parm->ipbfln2f = (__u32) anslen;
2181 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2182 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2183 b2f0_result = b2f0(SEND, parm);
2184 if ((!b2f0_result) && (msgid))
2185 *msgid = parm->ipmsgid;
2186 release_param(parm);
2188 iucv_debug(2, "exiting");
2189 return b2f0_result;
2192 void
2193 iucv_setmask_cpuid (void *result)
2195 iparml_set_mask *parm;
2197 iucv_debug(1, "entering");
2198 parm = (iparml_set_mask *)grab_param();
2199 parm->ipmask = *((__u8*)result);
2200 *((ulong *)result) = b2f0(SETMASK, parm);
2201 release_param(parm);
2203 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2204 iucv_debug(1, "exiting");
2208 * Name: iucv_setmask
2209 * Purpose: This function enables or disables the following IUCV
2210 * external interruptions: Nonpriority and priority message
2211 * interrupts, nonpriority and priority reply interrupts.
2212 * Input: SetMaskFlag - options for interrupts
2213 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2214 * 0x40 - Priority_MessagePendingInterruptsFlag
2215 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2216 * 0x10 - Priority_MessageCompletionInterruptsFlag
2217 * 0x08 - IUCVControlInterruptsFlag
2218 * Output: NA
2219 * Return: b2f0_result - return code from CP
2222 iucv_setmask (int SetMaskFlag)
2224 union {
2225 ulong result;
2226 __u8 param;
2227 } u;
2228 int cpu;
2230 u.param = SetMaskFlag;
2231 cpu = get_cpu();
2232 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2233 put_cpu();
2235 return u.result;
2239 * iucv_sever:
2240 * @pathid: Path identification number
2241 * @user_data: 16-byte of user data
2243 * This function terminates an iucv path.
2244 * Returns: return code from CP
2247 iucv_sever(__u16 pathid, __u8 user_data[16])
2249 iparml_control *parm;
2250 ulong b2f0_result = 0;
2252 iucv_debug(1, "entering");
2253 parm = (iparml_control *)grab_param();
2255 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2256 parm->ippathid = pathid;
2258 b2f0_result = b2f0(SEVER, parm);
2260 if (!b2f0_result)
2261 iucv_remove_pathid(pathid);
2262 release_param(parm);
2264 iucv_debug(1, "exiting");
2265 return b2f0_result;
2269 * Interrupt Handlers
2270 *******************************************************************************/
2273 * iucv_irq_handler:
2274 * @regs: Current registers
2275 * @code: irq code
2277 * Handles external interrupts coming in from CP.
2278 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2280 static void
2281 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2283 iucv_irqdata *irqdata;
2285 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2286 if (!irqdata) {
2287 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2288 return;
2291 memcpy(&irqdata->data, iucv_external_int_buffer,
2292 sizeof(iucv_GeneralInterrupt));
2294 spin_lock(&iucv_irq_queue_lock);
2295 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2296 spin_unlock(&iucv_irq_queue_lock);
2298 tasklet_schedule(&iucv_tasklet);
2302 * iucv_do_int:
2303 * @int_buf: Pointer to copy of external interrupt buffer
2305 * The workhorse for handling interrupts queued by iucv_irq_handler().
2306 * This function is called from the bottom half iucv_tasklet_handler().
2308 static void
2309 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2311 handler *h = NULL;
2312 struct list_head *lh;
2313 ulong flags;
2314 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2315 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2316 int rc = 0, j = 0;
2317 __u8 no_listener[16] = "NO LISTENER";
2319 iucv_debug(2, "entering, pathid %d, type %02X",
2320 int_buf->ippathid, int_buf->iptype);
2321 iucv_dumpit("External Interrupt Buffer:",
2322 int_buf, sizeof(iucv_GeneralInterrupt));
2324 ASCEBC (no_listener, 16);
2326 if (int_buf->iptype != 01) {
2327 if ((int_buf->ippathid) > (max_connections - 1)) {
2328 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2329 " > max_connections (%ld)\n", __FUNCTION__,
2330 int_buf->ippathid, max_connections - 1);
2331 } else {
2332 h = iucv_pathid_table[int_buf->ippathid];
2333 interrupt = h->interrupt_table;
2334 iucv_dumpit("Handler:", h, sizeof(handler));
2338 /* end of if statement */
2339 switch (int_buf->iptype) {
2340 case 0x01: /* connection pending */
2341 if (messagesDisabled) {
2342 iucv_setmask(~0);
2343 messagesDisabled = 0;
2345 spin_lock_irqsave(&iucv_lock, flags);
2346 list_for_each(lh, &iucv_handler_table) {
2347 h = list_entry(lh, handler, list);
2348 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2349 memcpy(temp_buff2, &(h->id.userid), 24);
2350 for (j = 0; j < 24; j++) {
2351 temp_buff1[j] &= (h->id.mask)[j];
2352 temp_buff2[j] &= (h->id.mask)[j];
2355 iucv_dumpit("temp_buff1:",
2356 temp_buff1, sizeof(temp_buff1));
2357 iucv_dumpit("temp_buff2",
2358 temp_buff2, sizeof(temp_buff2));
2360 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2362 iucv_debug(2,
2363 "found a matching handler");
2364 break;
2365 } else
2366 h = NULL;
2368 spin_unlock_irqrestore (&iucv_lock, flags);
2369 if (h) {
2370 /* ADD PATH TO PATHID TABLE */
2371 rc = iucv_add_pathid(int_buf->ippathid, h);
2372 if (rc) {
2373 iucv_sever (int_buf->ippathid,
2374 no_listener);
2375 iucv_debug(1,
2376 "add_pathid failed, rc = %d",
2377 rc);
2378 } else {
2379 interrupt = h->interrupt_table;
2380 if (interrupt->ConnectionPending) {
2381 EBCASC (int_buf->ipvmid, 8);
2382 interrupt->ConnectionPending(
2383 (iucv_ConnectionPending *)int_buf,
2384 h->pgm_data);
2385 } else
2386 iucv_sever(int_buf->ippathid,
2387 no_listener);
2389 } else
2390 iucv_sever(int_buf->ippathid, no_listener);
2391 break;
2393 case 0x02: /*connection complete */
2394 if (messagesDisabled) {
2395 iucv_setmask(~0);
2396 messagesDisabled = 0;
2398 if (h) {
2399 if (interrupt->ConnectionComplete)
2401 interrupt->ConnectionComplete(
2402 (iucv_ConnectionComplete *)int_buf,
2403 h->pgm_data);
2405 else
2406 iucv_debug(1,
2407 "ConnectionComplete not called");
2408 } else
2409 iucv_sever(int_buf->ippathid, no_listener);
2410 break;
2412 case 0x03: /* connection severed */
2413 if (messagesDisabled) {
2414 iucv_setmask(~0);
2415 messagesDisabled = 0;
2417 if (h) {
2418 if (interrupt->ConnectionSevered)
2419 interrupt->ConnectionSevered(
2420 (iucv_ConnectionSevered *)int_buf,
2421 h->pgm_data);
2423 else
2424 iucv_sever (int_buf->ippathid, no_listener);
2425 } else
2426 iucv_sever(int_buf->ippathid, no_listener);
2427 break;
2429 case 0x04: /* connection quiesced */
2430 if (messagesDisabled) {
2431 iucv_setmask(~0);
2432 messagesDisabled = 0;
2434 if (h) {
2435 if (interrupt->ConnectionQuiesced)
2436 interrupt->ConnectionQuiesced(
2437 (iucv_ConnectionQuiesced *)int_buf,
2438 h->pgm_data);
2439 else
2440 iucv_debug(1,
2441 "ConnectionQuiesced not called");
2443 break;
2445 case 0x05: /* connection resumed */
2446 if (messagesDisabled) {
2447 iucv_setmask(~0);
2448 messagesDisabled = 0;
2450 if (h) {
2451 if (interrupt->ConnectionResumed)
2452 interrupt->ConnectionResumed(
2453 (iucv_ConnectionResumed *)int_buf,
2454 h->pgm_data);
2455 else
2456 iucv_debug(1,
2457 "ConnectionResumed not called");
2459 break;
2461 case 0x06: /* priority message complete */
2462 case 0x07: /* nonpriority message complete */
2463 if (h) {
2464 if (interrupt->MessageComplete)
2465 interrupt->MessageComplete(
2466 (iucv_MessageComplete *)int_buf,
2467 h->pgm_data);
2468 else
2469 iucv_debug(2,
2470 "MessageComplete not called");
2472 break;
2474 case 0x08: /* priority message pending */
2475 case 0x09: /* nonpriority message pending */
2476 if (h) {
2477 if (interrupt->MessagePending)
2478 interrupt->MessagePending(
2479 (iucv_MessagePending *) int_buf,
2480 h->pgm_data);
2481 else
2482 iucv_debug(2,
2483 "MessagePending not called");
2485 break;
2486 default: /* unknown iucv type */
2487 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2488 __FUNCTION__);
2489 break;
2490 } /* end switch */
2492 iucv_debug(2, "exiting pathid %d, type %02X",
2493 int_buf->ippathid, int_buf->iptype);
2495 return;
2499 * iucv_tasklet_handler:
2501 * This function loops over the queue of irq buffers and runs iucv_do_int()
2502 * on every queue element.
2504 static void
2505 iucv_tasklet_handler(unsigned long ignored)
2507 struct list_head head;
2508 struct list_head *next;
2509 ulong flags;
2511 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2512 list_add(&head, &iucv_irq_queue);
2513 list_del_init(&iucv_irq_queue);
2514 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2516 next = head.next;
2517 while (next != &head) {
2518 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2520 next = next->next;
2521 iucv_do_int(&p->data);
2522 kfree(p);
2525 return;
2528 subsys_initcall(iucv_init);
2529 module_exit(iucv_exit);
2532 * Export all public stuff
2534 EXPORT_SYMBOL (iucv_bus);
2535 EXPORT_SYMBOL (iucv_root);
2536 EXPORT_SYMBOL (iucv_accept);
2537 EXPORT_SYMBOL (iucv_connect);
2538 #if 0
2539 EXPORT_SYMBOL (iucv_purge);
2540 EXPORT_SYMBOL (iucv_query_maxconn);
2541 EXPORT_SYMBOL (iucv_query_bufsize);
2542 EXPORT_SYMBOL (iucv_quiesce);
2543 #endif
2544 EXPORT_SYMBOL (iucv_receive);
2545 #if 0
2546 EXPORT_SYMBOL (iucv_receive_array);
2547 #endif
2548 EXPORT_SYMBOL (iucv_reject);
2549 #if 0
2550 EXPORT_SYMBOL (iucv_reply);
2551 EXPORT_SYMBOL (iucv_reply_array);
2552 EXPORT_SYMBOL (iucv_resume);
2553 #endif
2554 EXPORT_SYMBOL (iucv_reply_prmmsg);
2555 EXPORT_SYMBOL (iucv_send);
2556 #if 0
2557 EXPORT_SYMBOL (iucv_send2way);
2558 EXPORT_SYMBOL (iucv_send2way_array);
2559 EXPORT_SYMBOL (iucv_send_array);
2560 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2561 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2562 EXPORT_SYMBOL (iucv_send_prmmsg);
2563 EXPORT_SYMBOL (iucv_setmask);
2564 #endif
2565 EXPORT_SYMBOL (iucv_sever);
2566 EXPORT_SYMBOL (iucv_register_program);
2567 EXPORT_SYMBOL (iucv_unregister_program);