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 kfree(iucv_external_int_buffer);
451 iucv_external_int_buffer = NULL;
452 kfree(iucv_param_pool);
453 iucv_param_pool = NULL;
454 s390_root_dev_unregister(iucv_root);
455 bus_unregister(&iucv_bus);
456 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
460 * grab_param: - Get a parameter buffer from the pre-allocated pool.
462 * This function searches for an unused element in the pre-allocated pool
463 * of parameter buffers. If one is found, it marks it "in use" and returns
464 * a pointer to it. The calling function is responsible for releasing it
465 * when it has finished its usage.
467 * Returns: A pointer to iucv_param.
469 static __inline__ iucv_param *
475 ptr = iucv_param_pool + hint;
478 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
479 ptr = iucv_param_pool;
480 } while (atomic_compare_and_swap(0, 1, &ptr->in_use));
481 hint = ptr - iucv_param_pool;
483 memset(&ptr->param, 0, sizeof(ptr->param));
488 * release_param - Release a parameter buffer.
489 * @p: A pointer to a struct iucv_param, previously obtained by calling
492 * This function marks the specified parameter buffer "unused".
494 static __inline__ void
495 release_param(void *p)
497 atomic_set(&((iucv_param *)p)->in_use, 0);
501 * iucv_add_handler: - Add a new handler
502 * @new_handler: handle that is being entered into chain.
504 * Places new handle on iucv_handler_table, if identical handler is not
507 * Returns: 0 on success, !0 on failure (handler already in chain).
510 iucv_add_handler (handler *new)
514 iucv_debug(1, "entering");
515 iucv_dumpit("handler:", new, sizeof(handler));
517 spin_lock_irqsave (&iucv_lock, flags);
518 if (!list_empty(&iucv_handler_table)) {
519 struct list_head *lh;
522 * Search list for handler with identical id. If one
523 * is found, the new handler is _not_ added.
525 list_for_each(lh, &iucv_handler_table) {
526 handler *h = list_entry(lh, handler, list);
527 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
528 iucv_debug(1, "ret 1");
529 spin_unlock_irqrestore (&iucv_lock, flags);
535 * If we get here, no handler was found.
537 INIT_LIST_HEAD(&new->list);
538 list_add(&new->list, &iucv_handler_table);
539 spin_unlock_irqrestore (&iucv_lock, flags);
541 iucv_debug(1, "exiting");
547 * @code: identifier of IUCV call to CP.
548 * @parm: pointer to 40 byte iparml area passed to CP
550 * Calls CP to execute IUCV commands.
552 * Returns: return code from CP's IUCV call
554 static __inline__ ulong
555 b2f0(__u32 code, void *parm)
557 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
564 : "d" (code), "a" (parm)
568 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
570 return (unsigned long)*((__u8 *)(parm + 3));
574 * Name: iucv_add_pathid
575 * Purpose: Adds a path id to the system.
576 * Input: pathid - pathid that is going to be entered into system
577 * handle - address of handler that the pathid will be associated
579 * pgm_data - token passed in by application.
580 * Output: 0: successful addition of pathid
581 * - EINVAL - pathid entry is being used by another application
582 * - ENOMEM - storage allocation for a new pathid table failed
585 __iucv_add_pathid(__u16 pathid, handler *handler)
588 iucv_debug(1, "entering");
590 iucv_debug(1, "handler is pointing to %p", handler);
592 if (pathid > (max_connections - 1))
595 if (iucv_pathid_table[pathid]) {
596 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
598 "%s: Pathid being used, error.\n", __FUNCTION__);
601 iucv_pathid_table[pathid] = handler;
603 iucv_debug(1, "exiting");
605 } /* end of add_pathid function */
608 iucv_add_pathid(__u16 pathid, handler *handler)
613 spin_lock_irqsave (&iucv_lock, flags);
614 rc = __iucv_add_pathid(pathid, handler);
615 spin_unlock_irqrestore (&iucv_lock, flags);
620 iucv_remove_pathid(__u16 pathid)
624 if (pathid > (max_connections - 1))
627 spin_lock_irqsave (&iucv_lock, flags);
628 iucv_pathid_table[pathid] = NULL;
629 spin_unlock_irqrestore (&iucv_lock, flags);
633 * iucv_declare_buffer_cpuid
634 * Register at VM for subsequent IUCV operations. This is executed
635 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
638 iucv_declare_buffer_cpuid (void *result)
642 parm = (iparml_db *)grab_param();
643 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
644 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
645 *((ulong *)result) = parm->iprcode;
650 * iucv_retrieve_buffer_cpuid:
651 * Unregister IUCV usage at VM. This is always executed on the same
652 * cpu that registered the buffer to VM.
653 * Called from iucv_retrieve_buffer().
656 iucv_retrieve_buffer_cpuid (void *cpu)
658 iparml_control *parm;
660 parm = (iparml_control *)grab_param();
661 b2f0(RETRIEVE_BUFFER, parm);
666 * Name: iucv_declare_buffer
667 * Purpose: Specifies the guests real address of an external
670 * Output: iprcode - return code from b2f0 call
673 iucv_declare_buffer (void)
678 iucv_debug(1, "entering");
679 b2f0_result = -ENODEV;
680 spin_lock_irqsave (&iucv_lock, flags);
681 if (iucv_cpuid == -1) {
682 /* Reserve any cpu for use by iucv. */
683 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
684 spin_unlock_irqrestore (&iucv_lock, flags);
685 smp_call_function_on(iucv_declare_buffer_cpuid,
686 &b2f0_result, 0, 1, iucv_cpuid);
688 smp_put_cpu(iucv_cpuid);
691 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
693 spin_unlock_irqrestore (&iucv_lock, flags);
696 iucv_debug(1, "exiting");
701 * iucv_retrieve_buffer:
703 * Terminates all use of IUCV.
704 * Returns: return code from CP
707 iucv_retrieve_buffer (void)
709 iucv_debug(1, "entering");
710 if (iucv_cpuid != -1) {
711 smp_call_function_on(iucv_retrieve_buffer_cpuid,
712 0, 0, 1, iucv_cpuid);
713 /* Release the cpu reserved by iucv_declare_buffer. */
714 smp_put_cpu(iucv_cpuid);
717 iucv_debug(1, "exiting");
722 * iucv_remove_handler:
723 * @users_handler: handler to be removed
725 * Remove handler when application unregisters.
728 iucv_remove_handler(handler *handler)
732 if ((!iucv_pathid_table) || (!handler))
735 iucv_debug(1, "entering");
737 spin_lock_irqsave (&iucv_lock, flags);
738 list_del(&handler->list);
739 if (list_empty(&iucv_handler_table)) {
741 unregister_external_interrupt(0x4000, iucv_irq_handler);
745 spin_unlock_irqrestore (&iucv_lock, flags);
747 iucv_debug(1, "exiting");
752 * iucv_register_program:
753 * @pgmname: user identification
754 * @userid: machine identification
755 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
756 * used to determine who is given control.
757 * @ops: Address of interrupt handler table.
758 * @pgm_data: Application data to be passed to interrupt handlers.
760 * Registers an application with IUCV.
762 * The address of handler, or NULL on failure.
764 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
766 * If pgmmask is NULL, the internal mask is set to all 0xff's
767 * When userid is NULL, the first 8 bytes of the internal mask are forced
769 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
770 * are forced to 0x00 and the last 16 bytes to 0xff.
774 iucv_register_program (__u8 pgmname[16],
777 iucv_interrupt_ops_t * ops, void *pgm_data)
779 ulong rc = 0; /* return code from function calls */
780 handler *new_handler;
782 iucv_debug(1, "entering");
785 /* interrupt table is not defined */
786 printk(KERN_WARNING "%s: Interrupt table is not defined, "
787 "exiting\n", __FUNCTION__);
791 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
795 /* Allocate handler entry */
796 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
797 if (new_handler == NULL) {
798 printk(KERN_WARNING "%s: storage allocation for new handler "
799 "failed.\n", __FUNCTION__);
803 if (!iucv_pathid_table) {
809 max_connections = iucv_query_maxconn();
810 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
812 if (iucv_pathid_table == NULL) {
813 printk(KERN_WARNING "%s: iucv_pathid_table storage "
814 "allocation failed\n", __FUNCTION__);
818 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
820 memset(new_handler, 0, sizeof (handler));
821 memcpy(new_handler->id.user_data, pgmname,
822 sizeof (new_handler->id.user_data));
824 memcpy (new_handler->id.userid, userid,
825 sizeof (new_handler->id.userid));
826 ASCEBC (new_handler->id.userid,
827 sizeof (new_handler->id.userid));
828 EBC_TOUPPER (new_handler->id.userid,
829 sizeof (new_handler->id.userid));
832 memcpy (new_handler->id.mask, pgmmask,
833 sizeof (new_handler->id.mask));
835 memset (new_handler->id.mask, 0xFF,
836 sizeof (new_handler->id.mask));
840 memcpy (new_handler->id.mask, pgmmask,
841 sizeof (new_handler->id.mask));
843 memset (new_handler->id.mask, 0xFF,
844 sizeof (new_handler->id.mask));
846 memset (new_handler->id.userid, 0x00,
847 sizeof (new_handler->id.userid));
849 /* fill in the rest of handler */
850 new_handler->pgm_data = pgm_data;
851 new_handler->interrupt_table = ops;
854 * Check if someone else is registered with same pgmname, userid
855 * and mask. If someone is already registered with same pgmname,
856 * userid and mask, registration will fail and NULL will be returned
857 * to the application.
858 * If identical handler not found, then handler is added to list.
860 rc = iucv_add_handler(new_handler);
862 printk(KERN_WARNING "%s: Someone already registered with same "
863 "pgmname, userid, pgmmask\n", __FUNCTION__);
868 rc = iucv_declare_buffer();
870 char *err = "Unknown";
871 iucv_remove_handler(new_handler);
875 err = "Directory error";
878 err = "Invalid length";
881 err = "Buffer already exists";
884 err = "Buffer overlap";
887 err = "Paging or storage error";
890 printk(KERN_WARNING "%s: iucv_declare_buffer "
891 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
894 if (!register_flag) {
895 /* request the 0x4000 external interrupt */
896 rc = register_external_interrupt (0x4000, iucv_irq_handler);
898 iucv_remove_handler(new_handler);
900 printk(KERN_WARNING "%s: "
901 "register_external_interrupt returned %ld\n",
908 iucv_debug(1, "exiting");
910 } /* end of register function */
913 * iucv_unregister_program:
914 * @handle: address of handler
916 * Unregister application with IUCV.
918 * 0 on success, -EINVAL, if specified handle is invalid.
922 iucv_unregister_program (iucv_handle_t handle)
925 struct list_head *lh;
929 iucv_debug(1, "entering");
930 iucv_debug(1, "address of handler is %p", h);
932 /* Checking if handle is valid */
933 spin_lock_irqsave (&iucv_lock, flags);
934 list_for_each(lh, &iucv_handler_table) {
935 if ((handler *)handle == list_entry(lh, handler, list)) {
936 h = (handler *)handle;
941 spin_unlock_irqrestore (&iucv_lock, flags);
944 "%s: Handler not found in iucv_handler_table.\n",
948 "%s: NULL handle passed by application.\n",
954 * First, walk thru iucv_pathid_table and sever any pathid which is
955 * still pointing to the handler to be removed.
957 for (i = 0; i < max_connections; i++)
958 if (iucv_pathid_table[i] == h) {
959 spin_unlock_irqrestore (&iucv_lock, flags);
960 iucv_sever(i, h->id.user_data);
961 spin_lock_irqsave(&iucv_lock, flags);
963 spin_unlock_irqrestore (&iucv_lock, flags);
965 iucv_remove_handler(h);
968 iucv_debug(1, "exiting");
974 * @pathid: Path identification number
975 * @msglim_reqstd: The number of outstanding messages requested.
976 * @user_data: Data specified by the iucv_connect function.
977 * @flags1: Contains options for this path.
978 * - IPPRTY (0x20) Specifies if you want to send priority message.
979 * - IPRMDATA (0x80) Specifies whether your program can handle a message
980 * in the parameter list.
981 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
983 * @handle: Address of handler.
984 * @pgm_data: Application data passed to interrupt handlers.
985 * @flags1_out: Pointer to an int. If not NULL, on return the options for
986 * the path are stored at the given location:
987 * - IPPRTY (0x20) Indicates you may send a priority message.
988 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
989 * number of outstanding messages is stored at the given
992 * This function is issued after the user receives a Connection Pending external
993 * interrupt and now wishes to complete the IUCV communication path.
995 * return code from CP
998 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
999 __u8 user_data[16], int flags1,
1000 iucv_handle_t handle, void *pgm_data,
1001 int *flags1_out, __u16 * msglim)
1003 ulong b2f0_result = 0;
1005 struct list_head *lh;
1007 iparml_control *parm;
1009 iucv_debug(1, "entering");
1010 iucv_debug(1, "pathid = %d", pathid);
1012 /* Checking if handle is valid */
1013 spin_lock_irqsave (&iucv_lock, flags);
1014 list_for_each(lh, &iucv_handler_table) {
1015 if ((handler *)handle == list_entry(lh, handler, list)) {
1016 h = (handler *)handle;
1020 spin_unlock_irqrestore (&iucv_lock, flags);
1025 "%s: Handler not found in iucv_handler_table.\n",
1029 "%s: NULL handle passed by application.\n",
1034 parm = (iparml_control *)grab_param();
1036 parm->ippathid = pathid;
1037 parm->ipmsglim = msglim_reqstd;
1039 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1041 parm->ipflags1 = (__u8)flags1;
1042 b2f0_result = b2f0(ACCEPT, parm);
1046 *msglim = parm->ipmsglim;
1048 h->pgm_data = pgm_data;
1050 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1052 release_param(parm);
1054 iucv_debug(1, "exiting");
1060 * @pathid: Path identification number
1061 * @msglim_reqstd: Number of outstanding messages requested
1062 * @user_data: 16-byte user data
1063 * @userid: 8-byte of user identification
1064 * @system_name: 8-byte identifying the system name
1065 * @flags1: Specifies options for this path:
1066 * - IPPRTY (0x20) Specifies if you want to send priority message.
1067 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1068 * in the parameter list.
1069 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1071 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1072 * local system. If local is specified then target class
1073 * cannot be specified.
1074 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1075 * the path are stored at the given location:
1076 * - IPPRTY (0x20) Indicates you may send a priority message.
1077 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1078 * number of outstanding messages is stored at the given
1080 * @handle: Address of handler.
1081 * @pgm_data: Application data to be passed to interrupt handlers.
1083 * This function establishes an IUCV path. Although the connect may complete
1084 * successfully, you are not able to use the path until you receive an IUCV
1085 * Connection Complete external interrupt.
1086 * Returns: return code from CP, or one of the following
1088 * - return code from iucv_declare_buffer
1089 * - EINVAL - invalid handle passed by application
1090 * - EINVAL - pathid address is NULL
1091 * - ENOMEM - pathid table storage allocation failed
1092 * - return code from internal function add_pathid
1095 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1096 __u8 user_data[16], __u8 userid[8],
1097 __u8 system_name[8], int flags1,
1098 int *flags1_out, __u16 * msglim,
1099 iucv_handle_t handle, void *pgm_data)
1101 iparml_control *parm;
1102 iparml_control local_parm;
1103 struct list_head *lh;
1104 ulong b2f0_result = 0;
1106 int add_pathid_result = 0;
1108 __u8 no_memory[16] = "NO MEMORY";
1110 iucv_debug(1, "entering");
1112 /* Checking if handle is valid */
1113 spin_lock_irqsave (&iucv_lock, flags);
1114 list_for_each(lh, &iucv_handler_table) {
1115 if ((handler *)handle == list_entry(lh, handler, list)) {
1116 h = (handler *)handle;
1120 spin_unlock_irqrestore (&iucv_lock, flags);
1125 "%s: Handler not found in iucv_handler_table.\n",
1129 "%s: NULL handle passed by application.\n",
1134 if (pathid == NULL) {
1135 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1140 parm = (iparml_control *)grab_param();
1142 parm->ipmsglim = msglim_reqstd;
1145 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1148 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1149 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1150 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1154 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1155 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1156 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1159 /* In order to establish an IUCV connection, the procedure is:
1162 * take the ippathid from the b2f0 call
1163 * register the handler to the ippathid
1165 * Unfortunately, the ConnectionEstablished message gets sent after the
1166 * b2f0(CONNECT) call but before the register is handled.
1168 * In order for this race condition to be eliminated, the IUCV Control
1169 * Interrupts must be disabled for the above procedure.
1171 * David Kennedy <dkennedy@linuxcare.com>
1174 /* Enable everything but IUCV Control messages */
1175 iucv_setmask(~(AllInterrupts));
1176 messagesDisabled = 1;
1178 spin_lock_irqsave (&iucv_lock, flags);
1179 parm->ipflags1 = (__u8)flags1;
1180 b2f0_result = b2f0(CONNECT, parm);
1181 memcpy(&local_parm, parm, sizeof(local_parm));
1182 release_param(parm);
1185 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1186 spin_unlock_irqrestore (&iucv_lock, flags);
1190 messagesDisabled = 0;
1194 *pathid = parm->ippathid;
1196 /* Enable everything again */
1197 iucv_setmask(IUCVControlInterruptsFlag);
1200 *msglim = parm->ipmsglim;
1202 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1204 if (add_pathid_result) {
1205 iucv_sever(*pathid, no_memory);
1206 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1207 " %d\n", __FUNCTION__, add_pathid_result);
1208 return(add_pathid_result);
1211 iucv_debug(1, "exiting");
1217 * @pathid: Path identification number
1218 * @msgid: Message ID of message to purge.
1219 * @srccls: Message class of the message to purge.
1220 * @audit: Pointer to an __u32. If not NULL, on return, information about
1221 * asynchronous errors that may have affected the normal completion
1222 * of this message ist stored at the given location.
1224 * Cancels a message you have sent.
1225 * Returns: return code from CP
1228 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1231 ulong b2f0_result = 0;
1233 iucv_debug(1, "entering");
1234 iucv_debug(1, "pathid = %d", pathid);
1236 parm = (iparml_purge *)grab_param();
1238 parm->ipmsgid = msgid;
1239 parm->ippathid = pathid;
1240 parm->ipsrccls = srccls;
1241 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1242 b2f0_result = b2f0(PURGE, parm);
1244 if (!b2f0_result && audit) {
1245 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1246 /* parm->ipaudit has only 3 bytes */
1250 release_param(parm);
1252 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1253 iucv_debug(1, "exiting");
1258 * iucv_query_generic:
1259 * @want_maxconn: Flag, describing which value is to be returned.
1261 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1263 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1264 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1267 iucv_query_generic(int want_maxconn)
1269 iparml_purge *parm = (iparml_purge *)grab_param();
1270 int bufsize, maxconn;
1274 * Call b2f0 and store R0 (max buffer size),
1275 * R1 (max connections) and CC.
1280 ".long 0xb2f01000\n\t"
1285 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1286 : "d" (QUERY), "a" (parm)
1289 release_param(parm);
1299 * iucv_query_maxconn:
1301 * Determines the maximum number of connections thay may be established.
1303 * Returns: Maximum number of connections that can be.
1306 iucv_query_maxconn(void)
1308 return iucv_query_generic(1);
1312 * iucv_query_bufsize:
1314 * Determines the size of the external interrupt buffer.
1316 * Returns: Size of external interrupt buffer.
1319 iucv_query_bufsize (void)
1321 return iucv_query_generic(0);
1326 * @pathid: Path identification number
1327 * @user_data: 16-byte user data
1329 * Temporarily suspends incoming messages on an IUCV path.
1330 * You can later reactivate the path by invoking the iucv_resume function.
1331 * Returns: return code from CP
1334 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1336 iparml_control *parm;
1337 ulong b2f0_result = 0;
1339 iucv_debug(1, "entering");
1340 iucv_debug(1, "pathid = %d", pathid);
1342 parm = (iparml_control *)grab_param();
1344 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1345 parm->ippathid = pathid;
1347 b2f0_result = b2f0(QUIESCE, parm);
1348 release_param(parm);
1350 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1351 iucv_debug(1, "exiting");
1358 * @pathid: Path identification number.
1359 * @buffer: Address of buffer to receive. Must be below 2G.
1360 * @buflen: Length of buffer to receive.
1361 * @msgid: Specifies the message ID.
1362 * @trgcls: Specifies target class.
1363 * @flags1_out: Receives options for path on return.
1364 * - IPNORPY (0x10) Specifies whether a reply is required
1365 * - IPPRTY (0x20) Specifies if you want to send priority message
1366 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1367 * @residual_buffer: Receives the address of buffer updated by the number
1368 * of bytes you have received on return.
1369 * @residual_length: On return, receives one of the following values:
1370 * - 0 If the receive buffer is the same length as
1372 * - Remaining bytes in buffer If the receive buffer is longer than the
1374 * - Remaining bytes in message If the receive buffer is shorter than the
1377 * This function receives messages that are being sent to you over established
1379 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1380 * than the message, always 5
1381 * -EINVAL - buffer address is pointing to NULL
1384 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1385 void *buffer, ulong buflen,
1386 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1390 int moved = 0; /* number of bytes moved from parmlist to buffer */
1392 iucv_debug(2, "entering");
1397 parm = (iparml_db *)grab_param();
1399 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1400 parm->ipbfln1f = (__u32) ((ulong) buflen);
1401 parm->ipmsgid = msgid;
1402 parm->ippathid = pathid;
1403 parm->iptrgcls = trgcls;
1404 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1406 b2f0_result = b2f0(RECEIVE, parm);
1408 if (!b2f0_result || b2f0_result == 5) {
1410 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1411 *flags1_out = (parm->ipflags1 & (~0x07));
1412 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1415 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1416 if (residual_length)
1417 *residual_length = parm->ipbfln1f;
1419 if (residual_buffer)
1420 *residual_buffer = parm->ipbfadr1;
1422 moved = min_t (unsigned long, buflen, 8);
1424 memcpy ((char *) buffer,
1425 (char *) &parm->ipbfadr1, moved);
1430 if (residual_length)
1431 *residual_length = abs (buflen - 8);
1433 if (residual_buffer)
1434 *residual_buffer = (ulong) (buffer + moved);
1437 release_param(parm);
1439 iucv_debug(2, "exiting");
1444 * Name: iucv_receive_array
1445 * Purpose: This function receives messages that are being sent to you
1446 * over established paths.
1447 * Input: pathid - path identification number
1448 * buffer - address of array of buffers
1449 * buflen - total length of buffers
1450 * msgid - specifies the message ID.
1451 * trgcls - specifies target class
1453 * flags1_out: Options for path.
1454 * IPNORPY - 0x10 specifies whether a reply is required
1455 * IPPRTY - 0x20 specifies if you want to send priority message
1456 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1457 * residual_buffer - address points to the current list entry IUCV
1460 * Contains one of the following values, if the receive buffer is:
1461 * The same length as the message, this field is zero.
1462 * Longer than the message, this field contains the number of
1463 * bytes remaining in the buffer.
1464 * Shorter than the message, this field contains the residual
1465 * count (that is, the number of bytes remaining in the
1466 * message that does not fit into the buffer. In this case
1468 * Return: b2f0_result - return code from CP
1469 * (-EINVAL) - buffer address is NULL
1472 iucv_receive_array (__u16 pathid,
1473 __u32 msgid, __u32 trgcls,
1474 iucv_array_t * buffer, ulong buflen,
1476 ulong * residual_buffer, ulong * residual_length)
1480 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1482 iucv_debug(2, "entering");
1487 parm = (iparml_db *)grab_param();
1489 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1490 parm->ipbfln1f = (__u32) buflen;
1491 parm->ipmsgid = msgid;
1492 parm->ippathid = pathid;
1493 parm->iptrgcls = trgcls;
1494 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1496 b2f0_result = b2f0(RECEIVE, parm);
1498 if (!b2f0_result || b2f0_result == 5) {
1501 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1502 *flags1_out = (parm->ipflags1 & (~0x07));
1503 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1506 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1508 if (residual_length)
1509 *residual_length = parm->ipbfln1f;
1511 if (residual_buffer)
1512 *residual_buffer = parm->ipbfadr1;
1515 /* copy msg from parmlist to users array. */
1517 while ((moved < 8) && (moved < buflen)) {
1519 min_t (unsigned int,
1520 (buffer + i)->length, need_to_move);
1522 memcpy ((char *)((ulong)((buffer + i)->address)),
1523 ((char *) &parm->ipbfadr1) + moved,
1527 need_to_move -= dyn_len;
1529 (buffer + i)->address =
1531 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1534 (buffer + i)->length -= dyn_len;
1538 if (need_to_move) /* buflen < 8 bytes */
1541 if (residual_length)
1542 *residual_length = abs (buflen - 8);
1544 if (residual_buffer) {
1546 *residual_buffer = (ulong) buffer;
1549 (ulong) (buffer + (i - 1));
1554 release_param(parm);
1556 iucv_debug(2, "exiting");
1562 * @pathid: Path identification number.
1563 * @msgid: Message ID of the message to reject.
1564 * @trgcls: Target class of the message to reject.
1565 * Returns: return code from CP
1567 * Refuses a specified message. Between the time you are notified of a
1568 * message and the time that you complete the message, the message may
1572 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1575 ulong b2f0_result = 0;
1577 iucv_debug(1, "entering");
1578 iucv_debug(1, "pathid = %d", pathid);
1580 parm = (iparml_db *)grab_param();
1582 parm->ippathid = pathid;
1583 parm->ipmsgid = msgid;
1584 parm->iptrgcls = trgcls;
1585 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1587 b2f0_result = b2f0(REJECT, parm);
1588 release_param(parm);
1590 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1591 iucv_debug(1, "exiting");
1598 * Purpose: This function responds to the two-way messages that you
1599 * receive. You must identify completely the message to
1600 * which you wish to reply. ie, pathid, msgid, and trgcls.
1601 * Input: pathid - path identification number
1602 * msgid - specifies the message ID.
1603 * trgcls - specifies target class
1604 * flags1 - option for path
1605 * IPPRTY- 0x20 - specifies if you want to send priority message
1606 * buffer - address of reply buffer
1607 * buflen - length of reply buffer
1608 * Output: ipbfadr2 - Address of buffer updated by the number
1609 * of bytes you have moved.
1610 * ipbfln2f - Contains one of the following values:
1611 * If the answer buffer is the same length as the reply, this field
1613 * If the answer buffer is longer than the reply, this field contains
1614 * the number of bytes remaining in the buffer.
1615 * If the answer buffer is shorter than the reply, this field contains
1616 * a residual count (that is, the number of bytes remianing in the
1617 * reply that does not fit into the buffer. In this
1618 * case b2f0_result = 5.
1619 * Return: b2f0_result - return code from CP
1620 * (-EINVAL) - buffer address is NULL
1623 iucv_reply (__u16 pathid,
1624 __u32 msgid, __u32 trgcls,
1626 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1631 iucv_debug(2, "entering");
1636 parm = (iparml_db *)grab_param();
1638 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1639 parm->ipbfln2f = (__u32) buflen; /* length of message */
1640 parm->ippathid = pathid;
1641 parm->ipmsgid = msgid;
1642 parm->iptrgcls = trgcls;
1643 parm->ipflags1 = (__u8) flags1; /* priority message */
1645 b2f0_result = b2f0(REPLY, parm);
1647 if ((!b2f0_result) || (b2f0_result == 5)) {
1649 *ipbfadr2 = parm->ipbfadr2;
1651 *ipbfln2f = parm->ipbfln2f;
1653 release_param(parm);
1655 iucv_debug(2, "exiting");
1661 * Name: iucv_reply_array
1662 * Purpose: This function responds to the two-way messages that you
1663 * receive. You must identify completely the message to
1664 * which you wish to reply. ie, pathid, msgid, and trgcls.
1665 * The array identifies a list of addresses and lengths of
1666 * discontiguous buffers that contains the reply data.
1667 * Input: pathid - path identification number
1668 * msgid - specifies the message ID.
1669 * trgcls - specifies target class
1670 * flags1 - option for path
1671 * IPPRTY- specifies if you want to send priority message
1672 * buffer - address of array of reply buffers
1673 * buflen - total length of reply buffers
1674 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1675 * ipbfln2f - Contains one of the following values:
1676 * If the answer buffer is the same length as the reply, this field
1678 * If the answer buffer is longer than the reply, this field contains
1679 * the number of bytes remaining in the buffer.
1680 * If the answer buffer is shorter than the reply, this field contains
1681 * a residual count (that is, the number of bytes remianing in the
1682 * reply that does not fit into the buffer. In this
1683 * case b2f0_result = 5.
1684 * Return: b2f0_result - return code from CP
1685 * (-EINVAL) - buffer address is NULL
1688 iucv_reply_array (__u16 pathid,
1689 __u32 msgid, __u32 trgcls,
1691 iucv_array_t * buffer,
1692 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1697 iucv_debug(2, "entering");
1702 parm = (iparml_db *)grab_param();
1704 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1705 parm->ipbfln2f = buflen; /* length of message */
1706 parm->ippathid = pathid;
1707 parm->ipmsgid = msgid;
1708 parm->iptrgcls = trgcls;
1709 parm->ipflags1 = (IPANSLST | flags1);
1711 b2f0_result = b2f0(REPLY, parm);
1713 if ((!b2f0_result) || (b2f0_result == 5)) {
1716 *ipbfadr2 = parm->ipbfadr2;
1718 *ipbfln2f = parm->ipbfln2f;
1720 release_param(parm);
1722 iucv_debug(2, "exiting");
1728 * Name: iucv_reply_prmmsg
1729 * Purpose: This function responds to the two-way messages that you
1730 * receive. You must identify completely the message to
1731 * which you wish to reply. ie, pathid, msgid, and trgcls.
1732 * Prmmsg signifies the data is moved into the
1734 * Input: pathid - path identification number
1735 * msgid - specifies the message ID.
1736 * trgcls - specifies target class
1737 * flags1 - option for path
1738 * IPPRTY- specifies if you want to send priority message
1739 * prmmsg - 8-bytes of data to be placed into the parameter
1742 * Return: b2f0_result - return code from CP
1745 iucv_reply_prmmsg (__u16 pathid,
1746 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1751 iucv_debug(2, "entering");
1753 parm = (iparml_dpl *)grab_param();
1755 parm->ippathid = pathid;
1756 parm->ipmsgid = msgid;
1757 parm->iptrgcls = trgcls;
1758 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1759 parm->ipflags1 = (IPRMDATA | flags1);
1761 b2f0_result = b2f0(REPLY, parm);
1762 release_param(parm);
1764 iucv_debug(2, "exiting");
1771 * @pathid: Path identification number
1772 * @user_data: 16-byte of user data
1774 * This function restores communication over a quiesced path.
1775 * Returns: return code from CP
1778 iucv_resume (__u16 pathid, __u8 user_data[16])
1780 iparml_control *parm;
1781 ulong b2f0_result = 0;
1783 iucv_debug(1, "entering");
1784 iucv_debug(1, "pathid = %d", pathid);
1786 parm = (iparml_control *)grab_param();
1788 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1789 parm->ippathid = pathid;
1791 b2f0_result = b2f0(RESUME, parm);
1792 release_param(parm);
1794 iucv_debug(1, "exiting");
1801 * Purpose: sends messages
1802 * Input: pathid - ushort, pathid
1803 * msgid - ulong *, id of message returned to caller
1804 * trgcls - ulong, target message class
1805 * srccls - ulong, source message class
1806 * msgtag - ulong, message tag
1807 * flags1 - Contains options for this path.
1808 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1809 * buffer - pointer to buffer
1810 * buflen - ulong, length of buffer
1811 * Output: b2f0_result - return code from b2f0 call
1812 * msgid - returns message id
1815 iucv_send (__u16 pathid, __u32 * msgid,
1816 __u32 trgcls, __u32 srccls,
1817 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1822 iucv_debug(2, "entering");
1827 parm = (iparml_db *)grab_param();
1829 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1830 parm->ippathid = pathid;
1831 parm->iptrgcls = trgcls;
1832 parm->ipbfln1f = (__u32) buflen; /* length of message */
1833 parm->ipsrccls = srccls;
1834 parm->ipmsgtag = msgtag;
1835 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1837 b2f0_result = b2f0(SEND, parm);
1839 if ((!b2f0_result) && (msgid))
1840 *msgid = parm->ipmsgid;
1841 release_param(parm);
1843 iucv_debug(2, "exiting");
1849 * Name: iucv_send_array
1850 * Purpose: This function transmits data to another application.
1851 * The contents of buffer is the address of the array of
1852 * addresses and lengths of discontiguous buffers that hold
1853 * the message text. This is a one-way message and the
1854 * receiver will not reply to the message.
1855 * Input: pathid - path identification number
1856 * trgcls - specifies target class
1857 * srccls - specifies the source message class
1858 * msgtag - specifies a tag to be associated witht the message
1859 * flags1 - option for path
1860 * IPPRTY- specifies if you want to send priority message
1861 * buffer - address of array of send buffers
1862 * buflen - total length of send buffers
1863 * Output: msgid - specifies the message ID.
1864 * Return: b2f0_result - return code from CP
1865 * (-EINVAL) - buffer address is NULL
1868 iucv_send_array (__u16 pathid,
1872 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1877 iucv_debug(2, "entering");
1882 parm = (iparml_db *)grab_param();
1884 parm->ippathid = pathid;
1885 parm->iptrgcls = trgcls;
1886 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1887 parm->ipbfln1f = (__u32) buflen; /* length of message */
1888 parm->ipsrccls = srccls;
1889 parm->ipmsgtag = msgtag;
1890 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1891 b2f0_result = b2f0(SEND, parm);
1893 if ((!b2f0_result) && (msgid))
1894 *msgid = parm->ipmsgid;
1895 release_param(parm);
1897 iucv_debug(2, "exiting");
1902 * Name: iucv_send_prmmsg
1903 * Purpose: This function transmits data to another application.
1904 * Prmmsg specifies that the 8-bytes of data are to be moved
1905 * into the parameter list. This is a one-way message and the
1906 * receiver will not reply to the message.
1907 * Input: pathid - path identification number
1908 * trgcls - specifies target class
1909 * srccls - specifies the source message class
1910 * msgtag - specifies a tag to be associated with the message
1911 * flags1 - option for path
1912 * IPPRTY- specifies if you want to send priority message
1913 * prmmsg - 8-bytes of data to be placed into parameter list
1914 * Output: msgid - specifies the message ID.
1915 * Return: b2f0_result - return code from CP
1918 iucv_send_prmmsg (__u16 pathid,
1921 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1926 iucv_debug(2, "entering");
1928 parm = (iparml_dpl *)grab_param();
1930 parm->ippathid = pathid;
1931 parm->iptrgcls = trgcls;
1932 parm->ipsrccls = srccls;
1933 parm->ipmsgtag = msgtag;
1934 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1935 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1937 b2f0_result = b2f0(SEND, parm);
1939 if ((!b2f0_result) && (msgid))
1940 *msgid = parm->ipmsgid;
1941 release_param(parm);
1943 iucv_debug(2, "exiting");
1949 * Name: iucv_send2way
1950 * Purpose: This function transmits data to another application.
1951 * Data to be transmitted is in a buffer. The receiver
1952 * of the send is expected to reply to the message and
1953 * a buffer is provided into which IUCV moves the reply
1955 * Input: pathid - path identification number
1956 * trgcls - specifies target class
1957 * srccls - specifies the source message class
1958 * msgtag - specifies a tag associated with the message
1959 * flags1 - option for path
1960 * IPPRTY- specifies if you want to send priority message
1961 * buffer - address of send buffer
1962 * buflen - length of send buffer
1963 * ansbuf - address of buffer to reply with
1964 * anslen - length of buffer to reply with
1965 * Output: msgid - specifies the message ID.
1966 * Return: b2f0_result - return code from CP
1967 * (-EINVAL) - buffer or ansbuf address is NULL
1970 iucv_send2way (__u16 pathid,
1976 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1981 iucv_debug(2, "entering");
1983 if (!buffer || !ansbuf)
1986 parm = (iparml_db *)grab_param();
1988 parm->ippathid = pathid;
1989 parm->iptrgcls = trgcls;
1990 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1991 parm->ipbfln1f = (__u32) buflen; /* length of message */
1992 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1993 parm->ipbfln2f = (__u32) anslen;
1994 parm->ipsrccls = srccls;
1995 parm->ipmsgtag = msgtag;
1996 parm->ipflags1 = flags1; /* priority message */
1998 b2f0_result = b2f0(SEND, parm);
2000 if ((!b2f0_result) && (msgid))
2001 *msgid = parm->ipmsgid;
2002 release_param(parm);
2004 iucv_debug(2, "exiting");
2010 * Name: iucv_send2way_array
2011 * Purpose: This function transmits data to another application.
2012 * The contents of buffer is the address of the array of
2013 * addresses and lengths of discontiguous buffers that hold
2014 * the message text. The receiver of the send is expected to
2015 * reply to the message and a buffer is provided into which
2016 * IUCV moves the reply to this message.
2017 * Input: pathid - path identification number
2018 * trgcls - specifies target class
2019 * srccls - specifies the source message class
2020 * msgtag - spcifies a tag to be associated with the message
2021 * flags1 - option for path
2022 * IPPRTY- specifies if you want to send priority message
2023 * buffer - address of array of send buffers
2024 * buflen - total length of send buffers
2025 * ansbuf - address of buffer to reply with
2026 * anslen - length of buffer to reply with
2027 * Output: msgid - specifies the message ID.
2028 * Return: b2f0_result - return code from CP
2029 * (-EINVAL) - buffer address is NULL
2032 iucv_send2way_array (__u16 pathid,
2038 iucv_array_t * buffer,
2039 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2044 iucv_debug(2, "entering");
2046 if (!buffer || !ansbuf)
2049 parm = (iparml_db *)grab_param();
2051 parm->ippathid = pathid;
2052 parm->iptrgcls = trgcls;
2053 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2054 parm->ipbfln1f = (__u32) buflen; /* length of message */
2055 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2056 parm->ipbfln2f = (__u32) anslen;
2057 parm->ipsrccls = srccls;
2058 parm->ipmsgtag = msgtag;
2059 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2060 b2f0_result = b2f0(SEND, parm);
2061 if ((!b2f0_result) && (msgid))
2062 *msgid = parm->ipmsgid;
2063 release_param(parm);
2065 iucv_debug(2, "exiting");
2070 * Name: iucv_send2way_prmmsg
2071 * Purpose: This function transmits data to another application.
2072 * Prmmsg specifies that the 8-bytes of data are to be moved
2073 * into the parameter list. This is a two-way message and the
2074 * receiver of the message is expected to reply. A buffer
2075 * is provided into which IUCV moves the reply to this
2077 * Input: pathid - path identification number
2078 * trgcls - specifies target class
2079 * srccls - specifies the source message class
2080 * msgtag - specifies a tag to be associated with the message
2081 * flags1 - option for path
2082 * IPPRTY- specifies if you want to send priority message
2083 * prmmsg - 8-bytes of data to be placed in parameter list
2084 * ansbuf - address of buffer to reply with
2085 * anslen - length of buffer to reply with
2086 * Output: msgid - specifies the message ID.
2087 * Return: b2f0_result - return code from CP
2088 * (-EINVAL) - buffer address is NULL
2091 iucv_send2way_prmmsg (__u16 pathid,
2096 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2101 iucv_debug(2, "entering");
2106 parm = (iparml_dpl *)grab_param();
2108 parm->ippathid = pathid;
2109 parm->iptrgcls = trgcls;
2110 parm->ipsrccls = srccls;
2111 parm->ipmsgtag = msgtag;
2112 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2113 parm->ipbfln2f = (__u32) anslen;
2114 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2115 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2117 b2f0_result = b2f0(SEND, parm);
2119 if ((!b2f0_result) && (msgid))
2120 *msgid = parm->ipmsgid;
2121 release_param(parm);
2123 iucv_debug(2, "exiting");
2129 * Name: iucv_send2way_prmmsg_array
2130 * Purpose: This function transmits data to another application.
2131 * Prmmsg specifies that the 8-bytes of data are to be moved
2132 * into the parameter list. This is a two-way message and the
2133 * receiver of the message is expected to reply. A buffer
2134 * is provided into which IUCV moves the reply to this
2135 * message. The contents of ansbuf is the address of the
2136 * array of addresses and lengths of discontiguous buffers
2137 * that contain the reply.
2138 * Input: pathid - path identification number
2139 * trgcls - specifies target class
2140 * srccls - specifies the source message class
2141 * msgtag - specifies a tag to be associated with the message
2142 * flags1 - option for path
2143 * IPPRTY- specifies if you want to send priority message
2144 * prmmsg - 8-bytes of data to be placed into the parameter list
2145 * ansbuf - address of buffer to reply with
2146 * anslen - length of buffer to reply with
2147 * Output: msgid - specifies the message ID.
2148 * Return: b2f0_result - return code from CP
2149 * (-EINVAL) - ansbuf address is NULL
2152 iucv_send2way_prmmsg_array (__u16 pathid,
2159 iucv_array_t * ansbuf, ulong anslen)
2164 iucv_debug(2, "entering");
2169 parm = (iparml_dpl *)grab_param();
2171 parm->ippathid = pathid;
2172 parm->iptrgcls = trgcls;
2173 parm->ipsrccls = srccls;
2174 parm->ipmsgtag = msgtag;
2175 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2176 parm->ipbfln2f = (__u32) anslen;
2177 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2178 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2179 b2f0_result = b2f0(SEND, parm);
2180 if ((!b2f0_result) && (msgid))
2181 *msgid = parm->ipmsgid;
2182 release_param(parm);
2184 iucv_debug(2, "exiting");
2189 iucv_setmask_cpuid (void *result)
2191 iparml_set_mask *parm;
2193 iucv_debug(1, "entering");
2194 parm = (iparml_set_mask *)grab_param();
2195 parm->ipmask = *((__u8*)result);
2196 *((ulong *)result) = b2f0(SETMASK, parm);
2197 release_param(parm);
2199 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2200 iucv_debug(1, "exiting");
2204 * Name: iucv_setmask
2205 * Purpose: This function enables or disables the following IUCV
2206 * external interruptions: Nonpriority and priority message
2207 * interrupts, nonpriority and priority reply interrupts.
2208 * Input: SetMaskFlag - options for interrupts
2209 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2210 * 0x40 - Priority_MessagePendingInterruptsFlag
2211 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2212 * 0x10 - Priority_MessageCompletionInterruptsFlag
2213 * 0x08 - IUCVControlInterruptsFlag
2215 * Return: b2f0_result - return code from CP
2218 iucv_setmask (int SetMaskFlag)
2226 u.param = SetMaskFlag;
2228 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2236 * @pathid: Path identification number
2237 * @user_data: 16-byte of user data
2239 * This function terminates an iucv path.
2240 * Returns: return code from CP
2243 iucv_sever(__u16 pathid, __u8 user_data[16])
2245 iparml_control *parm;
2246 ulong b2f0_result = 0;
2248 iucv_debug(1, "entering");
2249 parm = (iparml_control *)grab_param();
2251 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2252 parm->ippathid = pathid;
2254 b2f0_result = b2f0(SEVER, parm);
2257 iucv_remove_pathid(pathid);
2258 release_param(parm);
2260 iucv_debug(1, "exiting");
2265 * Interrupt Handlers
2266 *******************************************************************************/
2270 * @regs: Current registers
2273 * Handles external interrupts coming in from CP.
2274 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2277 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2279 iucv_irqdata *irqdata;
2281 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2283 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2287 memcpy(&irqdata->data, iucv_external_int_buffer,
2288 sizeof(iucv_GeneralInterrupt));
2290 spin_lock(&iucv_irq_queue_lock);
2291 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2292 spin_unlock(&iucv_irq_queue_lock);
2294 tasklet_schedule(&iucv_tasklet);
2299 * @int_buf: Pointer to copy of external interrupt buffer
2301 * The workhorse for handling interrupts queued by iucv_irq_handler().
2302 * This function is called from the bottom half iucv_tasklet_handler().
2305 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2308 struct list_head *lh;
2310 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2311 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2313 __u8 no_listener[16] = "NO LISTENER";
2315 iucv_debug(2, "entering, pathid %d, type %02X",
2316 int_buf->ippathid, int_buf->iptype);
2317 iucv_dumpit("External Interrupt Buffer:",
2318 int_buf, sizeof(iucv_GeneralInterrupt));
2320 ASCEBC (no_listener, 16);
2322 if (int_buf->iptype != 01) {
2323 if ((int_buf->ippathid) > (max_connections - 1)) {
2324 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2325 " > max_connections (%ld)\n", __FUNCTION__,
2326 int_buf->ippathid, max_connections - 1);
2328 h = iucv_pathid_table[int_buf->ippathid];
2329 interrupt = h->interrupt_table;
2330 iucv_dumpit("Handler:", h, sizeof(handler));
2334 /* end of if statement */
2335 switch (int_buf->iptype) {
2336 case 0x01: /* connection pending */
2337 if (messagesDisabled) {
2339 messagesDisabled = 0;
2341 spin_lock_irqsave(&iucv_lock, flags);
2342 list_for_each(lh, &iucv_handler_table) {
2343 h = list_entry(lh, handler, list);
2344 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2345 memcpy(temp_buff2, &(h->id.userid), 24);
2346 for (j = 0; j < 24; j++) {
2347 temp_buff1[j] &= (h->id.mask)[j];
2348 temp_buff2[j] &= (h->id.mask)[j];
2351 iucv_dumpit("temp_buff1:",
2352 temp_buff1, sizeof(temp_buff1));
2353 iucv_dumpit("temp_buff2",
2354 temp_buff2, sizeof(temp_buff2));
2356 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2359 "found a matching handler");
2364 spin_unlock_irqrestore (&iucv_lock, flags);
2366 /* ADD PATH TO PATHID TABLE */
2367 rc = iucv_add_pathid(int_buf->ippathid, h);
2369 iucv_sever (int_buf->ippathid,
2372 "add_pathid failed, rc = %d",
2375 interrupt = h->interrupt_table;
2376 if (interrupt->ConnectionPending) {
2377 EBCASC (int_buf->ipvmid, 8);
2378 interrupt->ConnectionPending(
2379 (iucv_ConnectionPending *)int_buf,
2382 iucv_sever(int_buf->ippathid,
2386 iucv_sever(int_buf->ippathid, no_listener);
2389 case 0x02: /*connection complete */
2390 if (messagesDisabled) {
2392 messagesDisabled = 0;
2395 if (interrupt->ConnectionComplete)
2397 interrupt->ConnectionComplete(
2398 (iucv_ConnectionComplete *)int_buf,
2403 "ConnectionComplete not called");
2405 iucv_sever(int_buf->ippathid, no_listener);
2408 case 0x03: /* connection severed */
2409 if (messagesDisabled) {
2411 messagesDisabled = 0;
2414 if (interrupt->ConnectionSevered)
2415 interrupt->ConnectionSevered(
2416 (iucv_ConnectionSevered *)int_buf,
2420 iucv_sever (int_buf->ippathid, no_listener);
2422 iucv_sever(int_buf->ippathid, no_listener);
2425 case 0x04: /* connection quiesced */
2426 if (messagesDisabled) {
2428 messagesDisabled = 0;
2431 if (interrupt->ConnectionQuiesced)
2432 interrupt->ConnectionQuiesced(
2433 (iucv_ConnectionQuiesced *)int_buf,
2437 "ConnectionQuiesced not called");
2441 case 0x05: /* connection resumed */
2442 if (messagesDisabled) {
2444 messagesDisabled = 0;
2447 if (interrupt->ConnectionResumed)
2448 interrupt->ConnectionResumed(
2449 (iucv_ConnectionResumed *)int_buf,
2453 "ConnectionResumed not called");
2457 case 0x06: /* priority message complete */
2458 case 0x07: /* nonpriority message complete */
2460 if (interrupt->MessageComplete)
2461 interrupt->MessageComplete(
2462 (iucv_MessageComplete *)int_buf,
2466 "MessageComplete not called");
2470 case 0x08: /* priority message pending */
2471 case 0x09: /* nonpriority message pending */
2473 if (interrupt->MessagePending)
2474 interrupt->MessagePending(
2475 (iucv_MessagePending *) int_buf,
2479 "MessagePending not called");
2482 default: /* unknown iucv type */
2483 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2488 iucv_debug(2, "exiting pathid %d, type %02X",
2489 int_buf->ippathid, int_buf->iptype);
2495 * iucv_tasklet_handler:
2497 * This function loops over the queue of irq buffers and runs iucv_do_int()
2498 * on every queue element.
2501 iucv_tasklet_handler(unsigned long ignored)
2503 struct list_head head;
2504 struct list_head *next;
2507 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2508 list_add(&head, &iucv_irq_queue);
2509 list_del_init(&iucv_irq_queue);
2510 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2513 while (next != &head) {
2514 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2517 iucv_do_int(&p->data);
2524 subsys_initcall(iucv_init);
2525 module_exit(iucv_exit);
2528 * Export all public stuff
2530 EXPORT_SYMBOL (iucv_bus);
2531 EXPORT_SYMBOL (iucv_root);
2532 EXPORT_SYMBOL (iucv_accept);
2533 EXPORT_SYMBOL (iucv_connect);
2535 EXPORT_SYMBOL (iucv_purge);
2536 EXPORT_SYMBOL (iucv_query_maxconn);
2537 EXPORT_SYMBOL (iucv_query_bufsize);
2538 EXPORT_SYMBOL (iucv_quiesce);
2540 EXPORT_SYMBOL (iucv_receive);
2542 EXPORT_SYMBOL (iucv_receive_array);
2544 EXPORT_SYMBOL (iucv_reject);
2546 EXPORT_SYMBOL (iucv_reply);
2547 EXPORT_SYMBOL (iucv_reply_array);
2548 EXPORT_SYMBOL (iucv_resume);
2550 EXPORT_SYMBOL (iucv_reply_prmmsg);
2551 EXPORT_SYMBOL (iucv_send);
2552 EXPORT_SYMBOL (iucv_send2way);
2553 EXPORT_SYMBOL (iucv_send2way_array);
2554 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2555 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2557 EXPORT_SYMBOL (iucv_send_array);
2558 EXPORT_SYMBOL (iucv_send_prmmsg);
2559 EXPORT_SYMBOL (iucv_setmask);
2561 EXPORT_SYMBOL (iucv_sever);
2562 EXPORT_SYMBOL (iucv_register_program);
2563 EXPORT_SYMBOL (iucv_unregister_program);