2 * $Id: iucv.c,v 1.45 2005/04/26 22:59:06 braunu Exp $
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
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)
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)
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.45 $
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>
54 #include <asm/s390_ext.h>
55 #include <asm/ebcdic.h>
57 #include <asm/ccwdev.h> //for root device stuff
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
68 * IPBUFLST - Indicates that you are using an address list for
80 iucv_bus_match (struct device
*dev
, struct device_driver
*drv
)
85 struct bus_type iucv_bus
= {
87 .match
= iucv_bus_match
,
90 struct device
*iucv_root
;
92 /* General IUCV interrupt structure */
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 ***************/
113 struct list_head queue
;
114 iucv_GeneralInterrupt data
;
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 ****************************/
132 #define DECLARE_BUFFER 12
140 #define RETRIEVE_BUFFER 2
147 * members: list - list management.
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
;
163 iucv_interrupt_ops_t
*interrupt_table
;
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
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
204 * Data struct 3: iparml_db (data in a buffer)
205 * Used for iucv_receive
213 * iucv_send2way_array
214 * iucv_declare_buffer
215 * Data struct 4: iparml_purge
216 * Used for iucv_purge
218 * Data struct 5: iparml_set_mask
219 * Used for iucv_set_mask
284 iparml_control p_ctrl
;
287 iparml_purge p_purge
;
288 iparml_set_mask p_set_mask
;
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");
303 *******************************************************************************/
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)");
314 iucv_dumpit(char *title
, void *buf
, int len
)
317 __u8
*p
= (__u8
*)buf
;
322 printk(KERN_DEBUG
"%s\n", title
);
324 for (i
= 0; i
< len
; i
++) {
325 if (!(i
% 16) && i
!= 0)
327 else if (!(i
% 4) && i
!= 0)
329 printk("%02X", *p
++);
335 #define iucv_debug(lvl, fmt, args...) \
337 if (debuglevel >= lvl) \
338 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
343 #define iucv_debug(lvl, fmt, args...)
344 #define iucv_dumpit(title, buf, len)
350 *******************************************************************************/
358 char vbuf
[] = "$Revision: 1.45 $";
359 char *version
= vbuf
;
361 if ((version
= strchr(version
, ':'))) {
362 char *p
= strchr(version
+ 1, '$');
368 "IUCV lowlevel driver Version%s initialized\n", version
);
372 * iucv_init - Initialization
374 * Allocates and initializes various data structures.
381 if (iucv_external_int_buffer
)
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
);
391 printk(KERN_ERR
"IUCV: failed to register bus.\n");
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
),
405 if (!iucv_external_int_buffer
) {
407 "%s: Could not allocate external interrupt buffer\n",
409 s390_root_dev_unregister(iucv_root
);
410 bus_unregister(&iucv_bus
);
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
,
418 if (!iucv_param_pool
) {
419 printk(KERN_WARNING
"%s: Could not allocate param pool\n",
421 kfree(iucv_external_int_buffer
);
422 iucv_external_int_buffer
= NULL
;
423 s390_root_dev_unregister(iucv_root
);
424 bus_unregister(&iucv_bus
);
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
);
440 * iucv_exit - De-Initialization
442 * Frees everything allocated from iucv_init.
444 static int iucv_retrieve_buffer (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
*
479 ptr
= iucv_param_pool
+ hint
;
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
));
492 * release_param - Release a parameter buffer.
493 * @p: A pointer to a struct iucv_param, previously obtained by calling
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
511 * Returns: 0 on success, !0 on failure (handler already in chain).
514 iucv_add_handler (handler
*new)
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
);
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");
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
));
568 : "d" (code
), "a" (parm
)
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
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
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))
599 if (iucv_pathid_table
[pathid
]) {
600 iucv_debug(1, "pathid entry is %p", iucv_pathid_table
[pathid
]);
602 "%s: Pathid being used, error.\n", __FUNCTION__
);
605 iucv_pathid_table
[pathid
] = handler
;
607 iucv_debug(1, "exiting");
609 } /* end of add_pathid function */
612 iucv_add_pathid(__u16 pathid
, handler
*handler
)
617 spin_lock_irqsave (&iucv_lock
, flags
);
618 rc
= __iucv_add_pathid(pathid
, handler
);
619 spin_unlock_irqrestore (&iucv_lock
, flags
);
624 iucv_remove_pathid(__u16 pathid
)
628 if (pathid
> (max_connections
- 1))
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().
642 iucv_declare_buffer_cpuid (void *result
)
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
;
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().
660 iucv_retrieve_buffer_cpuid (void *cpu
)
662 iparml_control
*parm
;
664 parm
= (iparml_control
*)grab_param();
665 b2f0(RETRIEVE_BUFFER
, parm
);
670 * Name: iucv_declare_buffer
671 * Purpose: Specifies the guests real address of an external
674 * Output: iprcode - return code from b2f0 call
677 iucv_declare_buffer (void)
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
);
692 smp_put_cpu(iucv_cpuid
);
695 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer
);
697 spin_unlock_irqrestore (&iucv_lock
, flags
);
700 iucv_debug(1, "exiting");
705 * iucv_retrieve_buffer:
707 * Terminates all use of IUCV.
708 * Returns: return code from CP
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
);
721 iucv_debug(1, "exiting");
726 * iucv_remove_handler:
727 * @users_handler: handler to be removed
729 * Remove handler when application unregisters.
732 iucv_remove_handler(handler
*handler
)
736 if ((!iucv_pathid_table
) || (!handler
))
739 iucv_debug(1, "entering");
741 spin_lock_irqsave (&iucv_lock
, flags
);
742 list_del(&handler
->list
);
743 if (list_empty(&iucv_handler_table
)) {
745 unregister_external_interrupt(0x4000, iucv_irq_handler
);
749 spin_unlock_irqrestore (&iucv_lock
, flags
);
751 iucv_debug(1, "exiting");
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.
766 * The address of handler, or NULL on failure.
768 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
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
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.
778 iucv_register_program (__u8 pgmname
[16],
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");
789 /* interrupt table is not defined */
790 printk(KERN_WARNING
"%s: Interrupt table is not defined, "
791 "exiting\n", __FUNCTION__
);
795 printk(KERN_WARNING
"%s: pgmname not provided\n", __FUNCTION__
);
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__
);
807 if (!iucv_pathid_table
) {
813 max_connections
= iucv_query_maxconn();
814 iucv_pathid_table
= kmalloc(max_connections
* sizeof(handler
*),
816 if (iucv_pathid_table
== NULL
) {
817 printk(KERN_WARNING
"%s: iucv_pathid_table storage "
818 "allocation failed\n", __FUNCTION__
);
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
));
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
));
836 memcpy (new_handler
->id
.mask
, pgmmask
,
837 sizeof (new_handler
->id
.mask
));
839 memset (new_handler
->id
.mask
, 0xFF,
840 sizeof (new_handler
->id
.mask
));
844 memcpy (new_handler
->id
.mask
, pgmmask
,
845 sizeof (new_handler
->id
.mask
));
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
);
866 printk(KERN_WARNING
"%s: Someone already registered with same "
867 "pgmname, userid, pgmmask\n", __FUNCTION__
);
872 rc
= iucv_declare_buffer();
874 char *err
= "Unknown";
875 iucv_remove_handler(new_handler
);
879 err
= "Directory error";
882 err
= "Invalid length";
885 err
= "Buffer already exists";
888 err
= "Buffer overlap";
891 err
= "Paging or storage error";
894 printk(KERN_WARNING
"%s: iucv_declare_buffer "
895 "returned error 0x%02lx (%s)\n", __FUNCTION__
, rc
, err
);
898 if (!register_flag
) {
899 /* request the 0x4000 external interrupt */
900 rc
= register_external_interrupt (0x4000, iucv_irq_handler
);
902 iucv_remove_handler(new_handler
);
904 printk(KERN_WARNING
"%s: "
905 "register_external_interrupt returned %ld\n",
912 iucv_debug(1, "exiting");
914 } /* end of register function */
917 * iucv_unregister_program:
918 * @handle: address of handler
920 * Unregister application with IUCV.
922 * 0 on success, -EINVAL, if specified handle is invalid.
926 iucv_unregister_program (iucv_handle_t handle
)
929 struct list_head
*lh
;
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
;
945 spin_unlock_irqrestore (&iucv_lock
, flags
);
948 "%s: Handler not found in iucv_handler_table.\n",
952 "%s: NULL handle passed by application.\n",
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
);
972 iucv_debug(1, "exiting");
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
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
996 * This function is issued after the user receives a Connection Pending external
997 * interrupt and now wishes to complete the IUCV communication path.
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;
1009 struct list_head
*lh
;
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
;
1024 spin_unlock_irqrestore (&iucv_lock
, flags
);
1029 "%s: Handler not found in iucv_handler_table.\n",
1033 "%s: NULL handle passed by application.\n",
1038 parm
= (iparml_control
*)grab_param();
1040 parm
->ippathid
= pathid
;
1041 parm
->ipmsglim
= msglim_reqstd
;
1043 memcpy(parm
->ipuser
, user_data
, sizeof(parm
->ipuser
));
1045 parm
->ipflags1
= (__u8
)flags1
;
1046 b2f0_result
= b2f0(ACCEPT
, parm
);
1050 *msglim
= parm
->ipmsglim
;
1052 h
->pgm_data
= pgm_data
;
1054 *flags1_out
= (parm
->ipflags1
& IPPRTY
) ? IPPRTY
: 0;
1056 release_param(parm
);
1058 iucv_debug(1, "exiting");
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
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
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
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;
1110 int add_pathid_result
= 0;
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
;
1124 spin_unlock_irqrestore (&iucv_lock
, flags
);
1129 "%s: Handler not found in iucv_handler_table.\n",
1133 "%s: NULL handle passed by application.\n",
1138 if (pathid
== NULL
) {
1139 printk(KERN_WARNING
"%s: NULL pathid pointer\n",
1144 parm
= (iparml_control
*)grab_param();
1146 parm
->ipmsglim
= msglim_reqstd
;
1149 memcpy(parm
->ipuser
, user_data
, sizeof(parm
->ipuser
));
1152 memcpy(parm
->ipvmid
, userid
, sizeof(parm
->ipvmid
));
1153 ASCEBC(parm
->ipvmid
, sizeof(parm
->ipvmid
));
1154 EBC_TOUPPER(parm
->ipvmid
, sizeof(parm
->ipvmid
));
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:
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
);
1189 add_pathid_result
= __iucv_add_pathid(parm
->ippathid
, h
);
1190 spin_unlock_irqrestore (&iucv_lock
, flags
);
1194 messagesDisabled
= 0;
1198 *pathid
= parm
->ippathid
;
1200 /* Enable everything again */
1201 iucv_setmask(IUCVControlInterruptsFlag
);
1204 *msglim
= parm
->ipmsglim
;
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");
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
)
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 */
1254 release_param(parm
);
1256 iucv_debug(1, "b2f0_result = %ld", b2f0_result
);
1257 iucv_debug(1, "exiting");
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.
1271 iucv_query_generic(int want_maxconn
)
1273 iparml_purge
*parm
= (iparml_purge
*)grab_param();
1274 int bufsize
, maxconn
;
1278 * Call b2f0 and store R0 (max buffer size),
1279 * R1 (max connections) and CC.
1284 ".long 0xb2f01000\n\t"
1289 : "=d" (ccode
), "=m" (bufsize
), "=m" (maxconn
)
1290 : "d" (QUERY
), "a" (parm
)
1293 release_param(parm
);
1303 * iucv_query_maxconn:
1305 * Determines the maximum number of connections thay may be established.
1307 * Returns: Maximum number of connections that can be.
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.
1323 iucv_query_bufsize (void)
1325 return iucv_query_generic(0);
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");
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
1376 * - Remaining bytes in buffer If the receive buffer is longer than the
1378 * - Remaining bytes in message If the receive buffer is shorter than the
1381 * This function receives messages that are being sent to you over established
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
)
1394 int moved
= 0; /* number of bytes moved from parmlist to buffer */
1396 iucv_debug(2, "entering");
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) {
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
;
1426 moved
= min_t (unsigned long, buflen
, 8);
1428 memcpy ((char *) buffer
,
1429 (char *) &parm
->ipbfadr1
, moved
);
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");
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
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
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
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
,
1480 ulong
* residual_buffer
, ulong
* residual_length
)
1484 int i
= 0, moved
= 0, need_to_move
= 8, dyn_len
;
1486 iucv_debug(2, "entering");
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) {
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
;
1519 /* copy msg from parmlist to users array. */
1521 while ((moved
< 8) && (moved
< buflen
)) {
1523 min_t (unsigned int,
1524 (buffer
+ i
)->length
, need_to_move
);
1526 memcpy ((char *)((ulong
)((buffer
+ i
)->address
)),
1527 ((char *) &parm
->ipbfadr1
) + moved
,
1531 need_to_move
-= dyn_len
;
1533 (buffer
+ i
)->address
=
1535 ((ulong
)(__u8
*) ((ulong
)(buffer
+ i
)->address
)
1538 (buffer
+ i
)->length
-= dyn_len
;
1542 if (need_to_move
) /* buflen < 8 bytes */
1545 if (residual_length
)
1546 *residual_length
= abs (buflen
- 8);
1548 if (residual_buffer
) {
1550 *residual_buffer
= (ulong
) buffer
;
1553 (ulong
) (buffer
+ (i
- 1));
1558 release_param(parm
);
1560 iucv_debug(2, "exiting");
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
1576 iucv_reject (__u16 pathid
, __u32 msgid
, __u32 trgcls
)
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");
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
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
,
1630 void *buffer
, ulong buflen
, ulong
* ipbfadr2
, ulong
* ipbfln2f
)
1635 iucv_debug(2, "entering");
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)) {
1653 *ipbfadr2
= parm
->ipbfadr2
;
1655 *ipbfln2f
= parm
->ipbfln2f
;
1657 release_param(parm
);
1659 iucv_debug(2, "exiting");
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
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
,
1695 iucv_array_t
* buffer
,
1696 ulong buflen
, ulong
* ipbfadr2
, ulong
* ipbfln2f
)
1701 iucv_debug(2, "entering");
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)) {
1720 *ipbfadr2
= parm
->ipbfadr2
;
1722 *ipbfln2f
= parm
->ipbfln2f
;
1724 release_param(parm
);
1726 iucv_debug(2, "exiting");
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
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
1746 * Return: b2f0_result - return code from CP
1749 iucv_reply_prmmsg (__u16 pathid
,
1750 __u32 msgid
, __u32 trgcls
, int flags1
, __u8 prmmsg
[8])
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");
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");
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
)
1826 iucv_debug(2, "entering");
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");
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
,
1876 __u32 msgtag
, int flags1
, iucv_array_t
* buffer
, ulong buflen
)
1881 iucv_debug(2, "entering");
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");
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
,
1925 __u32 srccls
, __u32 msgtag
, int flags1
, __u8 prmmsg
[8])
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");
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
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
,
1980 void *buffer
, ulong buflen
, void *ansbuf
, ulong anslen
)
1985 iucv_debug(2, "entering");
1987 if (!buffer
|| !ansbuf
)
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");
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
,
2042 iucv_array_t
* buffer
,
2043 ulong buflen
, iucv_array_t
* ansbuf
, ulong anslen
)
2048 iucv_debug(2, "entering");
2050 if (!buffer
|| !ansbuf
)
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");
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
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
,
2100 ulong flags1
, __u8 prmmsg
[8], void *ansbuf
, ulong anslen
)
2105 iucv_debug(2, "entering");
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");
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
,
2163 iucv_array_t
* ansbuf
, ulong anslen
)
2168 iucv_debug(2, "entering");
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");
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
2219 * Return: b2f0_result - return code from CP
2222 iucv_setmask (int SetMaskFlag
)
2230 u
.param
= SetMaskFlag
;
2232 smp_call_function_on(iucv_setmask_cpuid
, &u
, 0, 1, iucv_cpuid
);
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
);
2261 iucv_remove_pathid(pathid
);
2262 release_param(parm
);
2264 iucv_debug(1, "exiting");
2269 * Interrupt Handlers
2270 *******************************************************************************/
2274 * @regs: Current registers
2277 * Handles external interrupts coming in from CP.
2278 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2281 iucv_irq_handler(struct pt_regs
*regs
, __u16 code
)
2283 iucv_irqdata
*irqdata
;
2285 irqdata
= kmalloc(sizeof(iucv_irqdata
), GFP_ATOMIC
);
2287 printk(KERN_WARNING
"%s: out of memory\n", __FUNCTION__
);
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
);
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().
2309 iucv_do_int(iucv_GeneralInterrupt
* int_buf
)
2312 struct list_head
*lh
;
2314 iucv_interrupt_ops_t
*interrupt
= NULL
; /* interrupt addresses */
2315 __u8 temp_buff1
[24], temp_buff2
[24]; /* masked handler id. */
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);
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
) {
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)) {
2363 "found a matching handler");
2368 spin_unlock_irqrestore (&iucv_lock
, flags
);
2370 /* ADD PATH TO PATHID TABLE */
2371 rc
= iucv_add_pathid(int_buf
->ippathid
, h
);
2373 iucv_sever (int_buf
->ippathid
,
2376 "add_pathid failed, rc = %d",
2379 interrupt
= h
->interrupt_table
;
2380 if (interrupt
->ConnectionPending
) {
2381 EBCASC (int_buf
->ipvmid
, 8);
2382 interrupt
->ConnectionPending(
2383 (iucv_ConnectionPending
*)int_buf
,
2386 iucv_sever(int_buf
->ippathid
,
2390 iucv_sever(int_buf
->ippathid
, no_listener
);
2393 case 0x02: /*connection complete */
2394 if (messagesDisabled
) {
2396 messagesDisabled
= 0;
2399 if (interrupt
->ConnectionComplete
)
2401 interrupt
->ConnectionComplete(
2402 (iucv_ConnectionComplete
*)int_buf
,
2407 "ConnectionComplete not called");
2409 iucv_sever(int_buf
->ippathid
, no_listener
);
2412 case 0x03: /* connection severed */
2413 if (messagesDisabled
) {
2415 messagesDisabled
= 0;
2418 if (interrupt
->ConnectionSevered
)
2419 interrupt
->ConnectionSevered(
2420 (iucv_ConnectionSevered
*)int_buf
,
2424 iucv_sever (int_buf
->ippathid
, no_listener
);
2426 iucv_sever(int_buf
->ippathid
, no_listener
);
2429 case 0x04: /* connection quiesced */
2430 if (messagesDisabled
) {
2432 messagesDisabled
= 0;
2435 if (interrupt
->ConnectionQuiesced
)
2436 interrupt
->ConnectionQuiesced(
2437 (iucv_ConnectionQuiesced
*)int_buf
,
2441 "ConnectionQuiesced not called");
2445 case 0x05: /* connection resumed */
2446 if (messagesDisabled
) {
2448 messagesDisabled
= 0;
2451 if (interrupt
->ConnectionResumed
)
2452 interrupt
->ConnectionResumed(
2453 (iucv_ConnectionResumed
*)int_buf
,
2457 "ConnectionResumed not called");
2461 case 0x06: /* priority message complete */
2462 case 0x07: /* nonpriority message complete */
2464 if (interrupt
->MessageComplete
)
2465 interrupt
->MessageComplete(
2466 (iucv_MessageComplete
*)int_buf
,
2470 "MessageComplete not called");
2474 case 0x08: /* priority message pending */
2475 case 0x09: /* nonpriority message pending */
2477 if (interrupt
->MessagePending
)
2478 interrupt
->MessagePending(
2479 (iucv_MessagePending
*) int_buf
,
2483 "MessagePending not called");
2486 default: /* unknown iucv type */
2487 printk(KERN_WARNING
"%s: unknown iucv interrupt\n",
2492 iucv_debug(2, "exiting pathid %d, type %02X",
2493 int_buf
->ippathid
, int_buf
->iptype
);
2499 * iucv_tasklet_handler:
2501 * This function loops over the queue of irq buffers and runs iucv_do_int()
2502 * on every queue element.
2505 iucv_tasklet_handler(unsigned long ignored
)
2507 struct list_head head
;
2508 struct list_head
*next
;
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
);
2517 while (next
!= &head
) {
2518 iucv_irqdata
*p
= list_entry(next
, iucv_irqdata
, queue
);
2521 iucv_do_int(&p
->data
);
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
);
2539 EXPORT_SYMBOL (iucv_purge
);
2540 EXPORT_SYMBOL (iucv_query_maxconn
);
2541 EXPORT_SYMBOL (iucv_query_bufsize
);
2542 EXPORT_SYMBOL (iucv_quiesce
);
2544 EXPORT_SYMBOL (iucv_receive
);
2546 EXPORT_SYMBOL (iucv_receive_array
);
2548 EXPORT_SYMBOL (iucv_reject
);
2550 EXPORT_SYMBOL (iucv_reply
);
2551 EXPORT_SYMBOL (iucv_reply_array
);
2552 EXPORT_SYMBOL (iucv_resume
);
2554 EXPORT_SYMBOL (iucv_reply_prmmsg
);
2555 EXPORT_SYMBOL (iucv_send
);
2556 EXPORT_SYMBOL (iucv_send2way
);
2557 EXPORT_SYMBOL (iucv_send2way_array
);
2558 EXPORT_SYMBOL (iucv_send2way_prmmsg
);
2559 EXPORT_SYMBOL (iucv_send2way_prmmsg_array
);
2561 EXPORT_SYMBOL (iucv_send_array
);
2562 EXPORT_SYMBOL (iucv_send_prmmsg
);
2563 EXPORT_SYMBOL (iucv_setmask
);
2565 EXPORT_SYMBOL (iucv_sever
);
2566 EXPORT_SYMBOL (iucv_register_program
);
2567 EXPORT_SYMBOL (iucv_unregister_program
);