2 * $Id: iucv.c,v 1.28 2004/04/15 06:34:58 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.28 $
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>
56 #include <asm/ccwdev.h> //for root device stuff
59 * All flags are defined in the field IPFLAGS1 of each function
60 * and can be found in CP Programming Services.
61 * IPSRCCLS - Indicates you have specified a source class
62 * IPFGMCL - Indicates you have specified a target class
63 * IPFGPID - Indicates you have specified a pathid
64 * IPFGMID - Indicates you have specified a message ID
65 * IPANSLST - Indicates that you are using an address list for
67 * IPBUFLST - Indicates that you are using an address list for
79 iucv_bus_match (struct device *dev, struct device_driver *drv)
84 struct bus_type iucv_bus = {
86 .match = iucv_bus_match,
89 struct device *iucv_root;
91 /* General IUCV interrupt structure */
99 } iucv_GeneralInterrupt;
101 static iucv_GeneralInterrupt *iucv_external_int_buffer;
103 /* Spin Lock declaration */
105 static spinlock_t iucv_lock = SPIN_LOCK_UNLOCKED;
107 static int messagesDisabled = 0;
109 /***************INTERRUPT HANDLING ***************/
112 struct list_head queue;
113 iucv_GeneralInterrupt data;
116 static struct list_head iucv_irq_queue;
117 static spinlock_t iucv_irq_queue_lock = SPIN_LOCK_UNLOCKED;
120 *Internal function prototypes
122 static void iucv_tasklet_handler(unsigned long);
123 static void iucv_irq_handler(struct pt_regs *, __u16);
125 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
127 /************ FUNCTION ID'S ****************************/
131 #define DECLARE_BUFFER 12
139 #define RETRIEVE_BUFFER 2
146 * members: list - list management.
148 * userid - 8 char array of machine identification
149 * user_data - 16 char array for user identification
150 * mask - 24 char array used to compare the 2 previous
151 * interrupt_table - vector of interrupt functions.
152 * pgm_data - ulong, application data that is passed
153 * to the interrupt handlers
155 typedef struct handler_t {
156 struct list_head list;
162 iucv_interrupt_ops_t *interrupt_table;
167 * iucv_handler_table: List of registered handlers.
169 static struct list_head iucv_handler_table;
172 * iucv_pathid_table: an array of *handler pointing into
173 * iucv_handler_table for fast indexing by pathid;
175 static handler **iucv_pathid_table;
177 static unsigned long max_connections;
180 * declare_flag: is 0 when iucv_declare_buffer has not been called
182 static int declare_flag;
184 * register_flag: is 0 when external interrupt has not been registered
186 static int register_flag;
188 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
189 /* Data struct 1: iparml_control
190 * Used for iucv_accept
195 * iucv_retrieve_buffer
196 * Data struct 2: iparml_dpl (data in parameter list)
197 * Used for iucv_send_prmmsg
198 * iucv_send2way_prmmsg
199 * iucv_send2way_prmmsg_array
201 * Data struct 3: iparml_db (data in a buffer)
202 * Used for iucv_receive
210 * iucv_send2way_array
211 * iucv_declare_buffer
212 * Data struct 4: iparml_purge
213 * Used for iucv_purge
215 * Data struct 5: iparml_set_mask
216 * Used for iucv_set_mask
281 iparml_control p_ctrl;
284 iparml_purge p_purge;
285 iparml_set_mask p_set_mask;
288 } __attribute__ ((aligned(8))) iucv_param;
289 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
291 static iucv_param * iucv_param_pool;
293 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
294 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
295 MODULE_LICENSE("GPL");
299 *******************************************************************************/
303 static int debuglevel = 0;
305 module_param(debuglevel, int, 0);
306 MODULE_PARM_DESC(debuglevel,
307 "Specifies the debug level (0=off ... 3=all)");
310 iucv_dumpit(char *title, void *buf, int len)
313 __u8 *p = (__u8 *)buf;
318 printk(KERN_DEBUG "%s\n", title);
320 for (i = 0; i < len; i++) {
321 if (!(i % 16) && i != 0)
323 else if (!(i % 4) && i != 0)
325 printk("%02X", *p++);
331 #define iucv_debug(lvl, fmt, args...) \
333 if (debuglevel >= lvl) \
334 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
339 #define iucv_debug(lvl, fmt, args...)
340 #define iucv_dumpit(title, buf, len)
346 *******************************************************************************/
354 char vbuf[] = "$Revision: 1.28 $";
355 char *version = vbuf;
357 if ((version = strchr(version, ':'))) {
358 char *p = strchr(version + 1, '$');
364 "IUCV lowlevel driver Version%s initialized\n", version);
368 * iucv_init - Initialization
370 * Allocates and initializes various data structures.
377 if (iucv_external_int_buffer)
380 if (!MACHINE_IS_VM) {
381 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
382 return -EPROTONOSUPPORT;
385 ret = bus_register(&iucv_bus);
387 printk(KERN_ERR "IUCV: failed to register bus.\n");
391 iucv_root = s390_root_dev_register("iucv");
392 if (IS_ERR(iucv_root)) {
393 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
394 bus_unregister(&iucv_bus);
395 return PTR_ERR(iucv_root);
398 /* Note: GFP_DMA used used to get memory below 2G */
399 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt),
401 if (!iucv_external_int_buffer) {
403 "%s: Could not allocate external interrupt buffer\n",
405 s390_root_dev_unregister(iucv_root);
408 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
410 /* Initialize parameter pool */
411 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
413 if (!iucv_param_pool) {
414 printk(KERN_WARNING "%s: Could not allocate param pool\n",
416 kfree(iucv_external_int_buffer);
417 iucv_external_int_buffer = NULL;
418 s390_root_dev_unregister(iucv_root);
421 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
423 /* Initialize irq queue */
424 INIT_LIST_HEAD(&iucv_irq_queue);
426 /* Initialize handler table */
427 INIT_LIST_HEAD(&iucv_handler_table);
434 * iucv_exit - De-Initialization
436 * Frees everything allocated from iucv_init.
438 static int iucv_retrieve_buffer (void);
443 iucv_retrieve_buffer();
444 if (iucv_external_int_buffer)
445 kfree(iucv_external_int_buffer);
447 kfree(iucv_param_pool);
448 s390_root_dev_unregister(iucv_root);
449 bus_unregister(&iucv_bus);
450 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
454 * grab_param: - Get a parameter buffer from the pre-allocated pool.
456 * This function searches for an unused element in the pre-allocated pool
457 * of parameter buffers. If one is found, it marks it "in use" and returns
458 * a pointer to it. The calling function is responsible for releasing it
459 * when it has finished its usage.
461 * Returns: A pointer to iucv_param.
463 static __inline__ iucv_param *
469 while (atomic_compare_and_swap(0, 1, &iucv_param_pool[i].in_use)) {
471 if (i >= PARAM_POOL_SIZE)
474 ret = &iucv_param_pool[i];
475 memset(&ret->param, 0, sizeof(ret->param));
480 * release_param - Release a parameter buffer.
481 * @p: A pointer to a struct iucv_param, previously obtained by calling
484 * This function marks the specified parameter buffer "unused".
486 static __inline__ void
487 release_param(void *p)
489 atomic_set(&((iucv_param *)p)->in_use, 0);
493 * iucv_add_handler: - Add a new handler
494 * @new_handler: handle that is being entered into chain.
496 * Places new handle on iucv_handler_table, if identical handler is not
499 * Returns: 0 on success, !0 on failure (handler already in chain).
502 iucv_add_handler (handler *new)
506 iucv_debug(1, "entering");
507 iucv_dumpit("handler:", new, sizeof(handler));
509 spin_lock_irqsave (&iucv_lock, flags);
510 if (!list_empty(&iucv_handler_table)) {
511 struct list_head *lh;
514 * Search list for handler with identical id. If one
515 * is found, the new handler is _not_ added.
517 list_for_each(lh, &iucv_handler_table) {
518 handler *h = list_entry(lh, handler, list);
519 if (memcmp(&new->id, &h->id, sizeof(h->id)) == 0) {
520 iucv_debug(1, "ret 1");
521 spin_unlock_irqrestore (&iucv_lock, flags);
527 * If we get here, no handler was found.
529 INIT_LIST_HEAD(&new->list);
530 list_add(&new->list, &iucv_handler_table);
531 spin_unlock_irqrestore (&iucv_lock, flags);
533 iucv_debug(1, "exiting");
539 * @code: identifier of IUCV call to CP.
540 * @parm: pointer to 40 byte iparml area passed to CP
542 * Calls CP to execute IUCV commands.
544 * Returns: return code from CP's IUCV call
546 static __inline__ ulong
547 b2f0(__u32 code, void *parm)
549 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
556 : "d" (code), "a" (parm)
560 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
562 return (unsigned long)*((__u8 *)(parm + 3));
566 * Name: iucv_add_pathid
567 * Purpose: Adds a path id to the system.
568 * Input: pathid - pathid that is going to be entered into system
569 * handle - address of handler that the pathid will be associated
571 * pgm_data - token passed in by application.
572 * Output: 0: successful addition of pathid
573 * - EINVAL - pathid entry is being used by another application
574 * - ENOMEM - storage allocation for a new pathid table failed
577 __iucv_add_pathid(__u16 pathid, handler *handler)
580 iucv_debug(1, "entering");
582 iucv_debug(1, "handler is pointing to %p", handler);
584 if (pathid > (max_connections - 1))
587 if (iucv_pathid_table[pathid]) {
588 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
590 "%s: Pathid being used, error.\n", __FUNCTION__);
593 iucv_pathid_table[pathid] = handler;
595 iucv_debug(1, "exiting");
597 } /* end of add_pathid function */
600 iucv_add_pathid(__u16 pathid, handler *handler)
605 spin_lock_irqsave (&iucv_lock, flags);
606 rc = __iucv_add_pathid(pathid, handler);
607 spin_unlock_irqrestore (&iucv_lock, flags);
612 iucv_remove_pathid(__u16 pathid)
616 if (pathid > (max_connections - 1))
619 spin_lock_irqsave (&iucv_lock, flags);
620 iucv_pathid_table[pathid] = NULL;
621 spin_unlock_irqrestore (&iucv_lock, flags);
625 * iucv_declare_buffer_cpu0
626 * Register at VM for subsequent IUCV operations. This is always
627 * executed on CPU 0. Called from iucv_declare_buffer().
630 iucv_declare_buffer_cpu0 (void *result)
634 if (!(result && (smp_processor_id() == 0)))
636 parm = (iparml_db *)grab_param();
637 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
638 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
639 *((ulong *)result) = parm->iprcode;
644 * iucv_retrieve_buffer_cpu0:
645 * Unregister IUCV usage at VM. This is always executed on CPU 0.
646 * Called from iucv_retrieve_buffer().
649 iucv_retrieve_buffer_cpu0 (void *result)
651 iparml_control *parm;
653 if (smp_processor_id() != 0)
655 parm = (iparml_control *)grab_param();
656 b2f0(RETRIEVE_BUFFER, parm);
661 * Name: iucv_declare_buffer
662 * Purpose: Specifies the guests real address of an external
665 * Output: iprcode - return code from b2f0 call
668 iucv_declare_buffer (void)
670 ulong b2f0_result = 0x0deadbeef;
672 iucv_debug(1, "entering");
674 if (smp_processor_id() == 0)
675 iucv_declare_buffer_cpu0(&b2f0_result);
677 smp_call_function(iucv_declare_buffer_cpu0, &b2f0_result, 0, 1);
679 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
680 if (b2f0_result == 0x0deadbeef)
682 iucv_debug(1, "exiting");
687 * iucv_retrieve_buffer:
689 * Terminates all use of IUCV.
690 * Returns: return code from CP
693 iucv_retrieve_buffer (void)
695 iucv_debug(1, "entering");
698 if (smp_processor_id() == 0)
699 iucv_retrieve_buffer_cpu0(0);
701 smp_call_function(iucv_retrieve_buffer_cpu0, 0, 0, 1);
705 iucv_debug(1, "exiting");
710 * iucv_remove_handler:
711 * @users_handler: handler to be removed
713 * Remove handler when application unregisters.
716 iucv_remove_handler(handler *handler)
720 if ((!iucv_pathid_table) || (!handler))
723 iucv_debug(1, "entering");
725 spin_lock_irqsave (&iucv_lock, flags);
726 list_del(&handler->list);
727 if (list_empty(&iucv_handler_table)) {
729 unregister_external_interrupt(0x4000, iucv_irq_handler);
733 spin_unlock_irqrestore (&iucv_lock, flags);
735 iucv_debug(1, "exiting");
740 * iucv_register_program:
741 * @pgmname: user identification
742 * @userid: machine identification
743 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
744 * used to determine who is given control.
745 * @ops: Address of interrupt handler table.
746 * @pgm_data: Application data to be passed to interrupt handlers.
748 * Registers an application with IUCV.
750 * The address of handler, or NULL on failure.
752 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
754 * If pgmmask is NULL, the internal mask is set to all 0xff's
755 * When userid is NULL, the first 8 bytes of the internal mask are forced
757 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
758 * are forced to 0x00 and the last 16 bytes to 0xff.
762 iucv_register_program (__u8 pgmname[16],
765 iucv_interrupt_ops_t * ops, void *pgm_data)
767 ulong rc = 0; /* return code from function calls */
768 handler *new_handler;
770 iucv_debug(1, "entering");
773 /* interrupt table is not defined */
774 printk(KERN_WARNING "%s: Interrupt table is not defined, "
775 "exiting\n", __FUNCTION__);
779 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
783 /* Allocate handler entry */
784 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
785 if (new_handler == NULL) {
786 printk(KERN_WARNING "%s: storage allocation for new handler "
787 "failed.\n", __FUNCTION__);
791 if (!iucv_pathid_table) {
797 max_connections = iucv_query_maxconn();
798 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
800 if (iucv_pathid_table == NULL) {
801 printk(KERN_WARNING "%s: iucv_pathid_table storage "
802 "allocation failed\n", __FUNCTION__);
806 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
808 memset(new_handler, 0, sizeof (handler));
809 memcpy(new_handler->id.user_data, pgmname,
810 sizeof (new_handler->id.user_data));
812 memcpy (new_handler->id.userid, userid,
813 sizeof (new_handler->id.userid));
814 ASCEBC (new_handler->id.userid,
815 sizeof (new_handler->id.userid));
816 EBC_TOUPPER (new_handler->id.userid,
817 sizeof (new_handler->id.userid));
820 memcpy (new_handler->id.mask, pgmmask,
821 sizeof (new_handler->id.mask));
823 memset (new_handler->id.mask, 0xFF,
824 sizeof (new_handler->id.mask));
828 memcpy (new_handler->id.mask, pgmmask,
829 sizeof (new_handler->id.mask));
831 memset (new_handler->id.mask, 0xFF,
832 sizeof (new_handler->id.mask));
834 memset (new_handler->id.userid, 0x00,
835 sizeof (new_handler->id.userid));
837 /* fill in the rest of handler */
838 new_handler->pgm_data = pgm_data;
839 new_handler->interrupt_table = ops;
842 * Check if someone else is registered with same pgmname, userid
843 * and mask. If someone is already registered with same pgmname,
844 * userid and mask, registration will fail and NULL will be returned
845 * to the application.
846 * If identical handler not found, then handler is added to list.
848 rc = iucv_add_handler(new_handler);
850 printk(KERN_WARNING "%s: Someone already registered with same "
851 "pgmname, userid, pgmmask\n", __FUNCTION__);
856 if (declare_flag == 0) {
857 rc = iucv_declare_buffer();
859 char *err = "Unknown";
860 iucv_remove_handler(new_handler);
864 err = "Directory error";
867 err = "Invalid length";
870 err = "Buffer already exists";
873 err = "Buffer overlap";
876 err = "Paging or storage error";
879 err = "Function not called";
882 printk(KERN_WARNING "%s: iucv_declare_buffer "
883 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc,
889 if (register_flag == 0) {
890 /* request the 0x4000 external interrupt */
891 rc = register_external_interrupt (0x4000, iucv_irq_handler);
893 iucv_remove_handler(new_handler);
895 printk(KERN_WARNING "%s: "
896 "register_external_interrupt returned %ld\n",
903 iucv_debug(1, "exiting");
905 } /* end of register function */
908 * iucv_unregister_program:
909 * @handle: address of handler
911 * Unregister application with IUCV.
913 * 0 on success, -EINVAL, if specified handle is invalid.
917 iucv_unregister_program (iucv_handle_t handle)
920 struct list_head *lh;
924 iucv_debug(1, "entering");
925 iucv_debug(1, "address of handler is %p", h);
927 /* Checking if handle is valid */
928 spin_lock_irqsave (&iucv_lock, flags);
929 list_for_each(lh, &iucv_handler_table) {
930 if ((handler *)handle == list_entry(lh, handler, list)) {
931 h = (handler *)handle;
936 spin_unlock_irqrestore (&iucv_lock, flags);
939 "%s: Handler not found in iucv_handler_table.\n",
943 "%s: NULL handle passed by application.\n",
949 * First, walk thru iucv_pathid_table and sever any pathid which is
950 * still pointing to the handler to be removed.
952 for (i = 0; i < max_connections; i++)
953 if (iucv_pathid_table[i] == h) {
954 spin_unlock_irqrestore (&iucv_lock, flags);
955 iucv_sever(i, h->id.user_data);
956 spin_lock_irqsave(&iucv_lock, flags);
958 spin_unlock_irqrestore (&iucv_lock, flags);
960 iucv_remove_handler(h);
963 iucv_debug(1, "exiting");
969 * @pathid: Path identification number
970 * @msglim_reqstd: The number of outstanding messages requested.
971 * @user_data: Data specified by the iucv_connect function.
972 * @flags1: Contains options for this path.
973 * - IPPRTY (0x20) Specifies if you want to send priority message.
974 * - IPRMDATA (0x80) Specifies whether your program can handle a message
975 * in the parameter list.
976 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
978 * @handle: Address of handler.
979 * @pgm_data: Application data passed to interrupt handlers.
980 * @flags1_out: Pointer to an int. If not NULL, on return the options for
981 * the path are stored at the given location:
982 * - IPPRTY (0x20) Indicates you may send a priority message.
983 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
984 * number of outstanding messages is stored at the given
987 * This function is issued after the user receives a Connection Pending external
988 * interrupt and now wishes to complete the IUCV communication path.
990 * return code from CP
993 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
994 __u8 user_data[16], int flags1,
995 iucv_handle_t handle, void *pgm_data,
996 int *flags1_out, __u16 * msglim)
998 ulong b2f0_result = 0;
1000 struct list_head *lh;
1002 iparml_control *parm;
1004 iucv_debug(1, "entering");
1005 iucv_debug(1, "pathid = %d", pathid);
1007 /* Checking if handle is valid */
1008 spin_lock_irqsave (&iucv_lock, flags);
1009 list_for_each(lh, &iucv_handler_table) {
1010 if ((handler *)handle == list_entry(lh, handler, list)) {
1011 h = (handler *)handle;
1015 spin_unlock_irqrestore (&iucv_lock, flags);
1020 "%s: Handler not found in iucv_handler_table.\n",
1024 "%s: NULL handle passed by application.\n",
1029 parm = (iparml_control *)grab_param();
1031 parm->ippathid = pathid;
1032 parm->ipmsglim = msglim_reqstd;
1034 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1036 parm->ipflags1 = (__u8)flags1;
1037 b2f0_result = b2f0(ACCEPT, parm);
1039 if (b2f0_result == 0) {
1041 *msglim = parm->ipmsglim;
1043 h->pgm_data = pgm_data;
1045 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1047 release_param(parm);
1049 iucv_debug(1, "exiting");
1055 * @pathid: Path identification number
1056 * @msglim_reqstd: Number of outstanding messages requested
1057 * @user_data: 16-byte user data
1058 * @userid: 8-byte of user identification
1059 * @system_name: 8-byte identifying the system name
1060 * @flags1: Specifies options for this path:
1061 * - IPPRTY (0x20) Specifies if you want to send priority message.
1062 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1063 * in the parameter list.
1064 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1066 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1067 * local system. If local is specified then target class
1068 * cannot be specified.
1069 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1070 * the path are stored at the given location:
1071 * - IPPRTY (0x20) Indicates you may send a priority message.
1072 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1073 * number of outstanding messages is stored at the given
1075 * @handle: Address of handler.
1076 * @pgm_data: Application data to be passed to interrupt handlers.
1078 * This function establishes an IUCV path. Although the connect may complete
1079 * successfully, you are not able to use the path until you receive an IUCV
1080 * Connection Complete external interrupt.
1081 * Returns: return code from CP, or one of the following
1083 * - return code from iucv_declare_buffer
1084 * - EINVAL - invalid handle passed by application
1085 * - EINVAL - pathid address is NULL
1086 * - ENOMEM - pathid table storage allocation failed
1087 * - return code from internal function add_pathid
1090 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1091 __u8 user_data[16], __u8 userid[8],
1092 __u8 system_name[8], int flags1,
1093 int *flags1_out, __u16 * msglim,
1094 iucv_handle_t handle, void *pgm_data)
1096 iparml_control *parm;
1097 iparml_control local_parm;
1098 struct list_head *lh;
1099 ulong b2f0_result = 0;
1101 int add_pathid_result = 0;
1103 __u8 no_memory[16] = "NO MEMORY";
1105 iucv_debug(1, "entering");
1107 /* Checking if handle is valid */
1108 spin_lock_irqsave (&iucv_lock, flags);
1109 list_for_each(lh, &iucv_handler_table) {
1110 if ((handler *)handle == list_entry(lh, handler, list)) {
1111 h = (handler *)handle;
1115 spin_unlock_irqrestore (&iucv_lock, flags);
1120 "%s: Handler not found in iucv_handler_table.\n",
1124 "%s: NULL handle passed by application.\n",
1129 if (pathid == NULL) {
1130 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1135 parm = (iparml_control *)grab_param();
1137 parm->ipmsglim = msglim_reqstd;
1140 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1143 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1144 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1145 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1149 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1150 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1151 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1154 /* In order to establish an IUCV connection, the procedure is:
1157 * take the ippathid from the b2f0 call
1158 * register the handler to the ippathid
1160 * Unfortunately, the ConnectionEstablished message gets sent after the
1161 * b2f0(CONNECT) call but before the register is handled.
1163 * In order for this race condition to be eliminated, the IUCV Control
1164 * Interrupts must be disabled for the above procedure.
1166 * David Kennedy <dkennedy@linuxcare.com>
1169 /* Enable everything but IUCV Control messages */
1170 iucv_setmask(~(AllInterrupts));
1171 messagesDisabled = 1;
1173 spin_lock_irqsave (&iucv_lock, flags);
1174 parm->ipflags1 = (__u8)flags1;
1175 b2f0_result = b2f0(CONNECT, parm);
1176 memcpy(&local_parm, parm, sizeof(local_parm));
1177 release_param(parm);
1179 if (b2f0_result == 0)
1180 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1181 spin_unlock_irqrestore (&iucv_lock, flags);
1185 messagesDisabled = 0;
1189 *pathid = parm->ippathid;
1191 /* Enable everything again */
1192 iucv_setmask(IUCVControlInterruptsFlag);
1195 *msglim = parm->ipmsglim;
1197 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1199 if (add_pathid_result) {
1200 iucv_sever(*pathid, no_memory);
1201 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1202 " %d\n", __FUNCTION__, add_pathid_result);
1203 return(add_pathid_result);
1206 iucv_debug(1, "exiting");
1212 * @pathid: Path identification number
1213 * @msgid: Message ID of message to purge.
1214 * @srccls: Message class of the message to purge.
1215 * @audit: Pointer to an __u32. If not NULL, on return, information about
1216 * asynchronous errors that may have affected the normal completion
1217 * of this message ist stored at the given location.
1219 * Cancels a message you have sent.
1220 * Returns: return code from CP
1223 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1226 ulong b2f0_result = 0;
1228 iucv_debug(1, "entering");
1229 iucv_debug(1, "pathid = %d", pathid);
1231 parm = (iparml_purge *)grab_param();
1233 parm->ipmsgid = msgid;
1234 parm->ippathid = pathid;
1235 parm->ipsrccls = srccls;
1236 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1237 b2f0_result = b2f0(PURGE, parm);
1239 if ((b2f0_result == 0) && audit) {
1240 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1241 /* parm->ipaudit has only 3 bytes */
1245 release_param(parm);
1247 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1248 iucv_debug(1, "exiting");
1253 * iucv_query_generic:
1254 * @want_maxconn: Flag, describing which value is to be returned.
1256 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1258 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1259 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1262 iucv_query_generic(int want_maxconn)
1264 iparml_purge *parm = (iparml_purge *)grab_param();
1265 int bufsize, maxconn;
1269 * Call b2f0 and store R0 (max buffer size),
1270 * R1 (max connections) and CC.
1275 ".long 0xb2f01000\n\t"
1280 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1281 : "d" (QUERY), "a" (parm)
1284 release_param(parm);
1294 * iucv_query_maxconn:
1296 * Determines the maximum number of connections thay may be established.
1298 * Returns: Maximum number of connections that can be.
1301 iucv_query_maxconn(void)
1303 return iucv_query_generic(1);
1307 * iucv_query_bufsize:
1309 * Determines the size of the external interrupt buffer.
1311 * Returns: Size of external interrupt buffer.
1314 iucv_query_bufsize (void)
1316 return iucv_query_generic(0);
1321 * @pathid: Path identification number
1322 * @user_data: 16-byte user data
1324 * Temporarily suspends incoming messages on an IUCV path.
1325 * You can later reactivate the path by invoking the iucv_resume function.
1326 * Returns: return code from CP
1329 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1331 iparml_control *parm;
1332 ulong b2f0_result = 0;
1334 iucv_debug(1, "entering");
1335 iucv_debug(1, "pathid = %d", pathid);
1337 parm = (iparml_control *)grab_param();
1339 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1340 parm->ippathid = pathid;
1342 b2f0_result = b2f0(QUIESCE, parm);
1343 release_param(parm);
1345 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1346 iucv_debug(1, "exiting");
1353 * @pathid: Path identification number.
1354 * @buffer: Address of buffer to receive. Must be below 2G.
1355 * @buflen: Length of buffer to receive.
1356 * @msgid: Specifies the message ID.
1357 * @trgcls: Specifies target class.
1358 * @flags1_out: Receives options for path on return.
1359 * - IPNORPY (0x10) Specifies whether a reply is required
1360 * - IPPRTY (0x20) Specifies if you want to send priority message
1361 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1362 * @residual_buffer: Receives the address of buffer updated by the number
1363 * of bytes you have received on return.
1364 * @residual_length: On return, receives one of the following values:
1365 * - 0 If the receive buffer is the same length as
1367 * - Remaining bytes in buffer If the receive buffer is longer than the
1369 * - Remaining bytes in message If the receive buffer is shorter than the
1372 * This function receives messages that are being sent to you over established
1374 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1375 * than the message, always 5
1376 * -EINVAL - buffer address is pointing to NULL
1379 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1380 void *buffer, ulong buflen,
1381 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1385 int moved = 0; /* number of bytes moved from parmlist to buffer */
1387 iucv_debug(2, "entering");
1392 parm = (iparml_db *)grab_param();
1394 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1395 parm->ipbfln1f = (__u32) ((ulong) buflen);
1396 parm->ipmsgid = msgid;
1397 parm->ippathid = pathid;
1398 parm->iptrgcls = trgcls;
1399 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1401 b2f0_result = b2f0(RECEIVE, parm);
1403 if (b2f0_result == 0 || b2f0_result == 5) {
1405 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1406 *flags1_out = (parm->ipflags1 & (~0x07));
1407 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1410 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1411 if (residual_length)
1412 *residual_length = parm->ipbfln1f;
1414 if (residual_buffer)
1415 *residual_buffer = parm->ipbfadr1;
1417 moved = min_t (unsigned long, buflen, 8);
1419 memcpy ((char *) buffer,
1420 (char *) &parm->ipbfadr1, moved);
1425 if (residual_length)
1426 *residual_length = abs (buflen - 8);
1428 if (residual_buffer)
1429 *residual_buffer = (ulong) (buffer + moved);
1432 release_param(parm);
1434 iucv_debug(2, "exiting");
1439 * Name: iucv_receive_array
1440 * Purpose: This function receives messages that are being sent to you
1441 * over established paths.
1442 * Input: pathid - path identification number
1443 * buffer - address of array of buffers
1444 * buflen - total length of buffers
1445 * msgid - specifies the message ID.
1446 * trgcls - specifies target class
1448 * flags1_out: Options for path.
1449 * IPNORPY - 0x10 specifies whether a reply is required
1450 * IPPRTY - 0x20 specifies if you want to send priority message
1451 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1452 * residual_buffer - address points to the current list entry IUCV
1455 * Contains one of the following values, if the receive buffer is:
1456 * The same length as the message, this field is zero.
1457 * Longer than the message, this field contains the number of
1458 * bytes remaining in the buffer.
1459 * Shorter than the message, this field contains the residual
1460 * count (that is, the number of bytes remaining in the
1461 * message that does not fit into the buffer. In this case
1463 * Return: b2f0_result - return code from CP
1464 * (-EINVAL) - buffer address is NULL
1467 iucv_receive_array (__u16 pathid,
1468 __u32 msgid, __u32 trgcls,
1469 iucv_array_t * buffer, ulong buflen,
1471 ulong * residual_buffer, ulong * residual_length)
1475 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1477 iucv_debug(2, "entering");
1482 parm = (iparml_db *)grab_param();
1484 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1485 parm->ipbfln1f = (__u32) buflen;
1486 parm->ipmsgid = msgid;
1487 parm->ippathid = pathid;
1488 parm->iptrgcls = trgcls;
1489 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1491 b2f0_result = b2f0(RECEIVE, parm);
1493 if (b2f0_result == 0 || b2f0_result == 5) {
1496 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1497 *flags1_out = (parm->ipflags1 & (~0x07));
1498 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1501 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1503 if (residual_length)
1504 *residual_length = parm->ipbfln1f;
1506 if (residual_buffer)
1507 *residual_buffer = parm->ipbfadr1;
1510 /* copy msg from parmlist to users array. */
1512 while ((moved < 8) && (moved < buflen)) {
1514 min_t (unsigned int,
1515 (buffer + i)->length, need_to_move);
1517 memcpy ((char *)((ulong)((buffer + i)->address)),
1518 ((char *) &parm->ipbfadr1) + moved,
1522 need_to_move -= dyn_len;
1524 (buffer + i)->address =
1526 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1529 (buffer + i)->length -= dyn_len;
1533 if (need_to_move) /* buflen < 8 bytes */
1536 if (residual_length)
1537 *residual_length = abs (buflen - 8);
1539 if (residual_buffer) {
1541 *residual_buffer = (ulong) buffer;
1544 (ulong) (buffer + (i - 1));
1549 release_param(parm);
1551 iucv_debug(2, "exiting");
1557 * @pathid: Path identification number.
1558 * @msgid: Message ID of the message to reject.
1559 * @trgcls: Target class of the message to reject.
1560 * Returns: return code from CP
1562 * Refuses a specified message. Between the time you are notified of a
1563 * message and the time that you complete the message, the message may
1567 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1570 ulong b2f0_result = 0;
1572 iucv_debug(1, "entering");
1573 iucv_debug(1, "pathid = %d", pathid);
1575 parm = (iparml_db *)grab_param();
1577 parm->ippathid = pathid;
1578 parm->ipmsgid = msgid;
1579 parm->iptrgcls = trgcls;
1580 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1582 b2f0_result = b2f0(REJECT, parm);
1583 release_param(parm);
1585 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1586 iucv_debug(1, "exiting");
1593 * Purpose: This function responds to the two-way messages that you
1594 * receive. You must identify completely the message to
1595 * which you wish to reply. ie, pathid, msgid, and trgcls.
1596 * Input: pathid - path identification number
1597 * msgid - specifies the message ID.
1598 * trgcls - specifies target class
1599 * flags1 - option for path
1600 * IPPRTY- 0x20 - specifies if you want to send priority message
1601 * buffer - address of reply buffer
1602 * buflen - length of reply buffer
1603 * Output: ipbfadr2 - Address of buffer updated by the number
1604 * of bytes you have moved.
1605 * ipbfln2f - Contains one of the following values:
1606 * If the answer buffer is the same length as the reply, this field
1608 * If the answer buffer is longer than the reply, this field contains
1609 * the number of bytes remaining in the buffer.
1610 * If the answer buffer is shorter than the reply, this field contains
1611 * a residual count (that is, the number of bytes remianing in the
1612 * reply that does not fit into the buffer. In this
1613 * case b2f0_result = 5.
1614 * Return: b2f0_result - return code from CP
1615 * (-EINVAL) - buffer address is NULL
1618 iucv_reply (__u16 pathid,
1619 __u32 msgid, __u32 trgcls,
1621 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1626 iucv_debug(2, "entering");
1631 parm = (iparml_db *)grab_param();
1633 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1634 parm->ipbfln2f = (__u32) buflen; /* length of message */
1635 parm->ippathid = pathid;
1636 parm->ipmsgid = msgid;
1637 parm->iptrgcls = trgcls;
1638 parm->ipflags1 = (__u8) flags1; /* priority message */
1640 b2f0_result = b2f0(REPLY, parm);
1642 if ((b2f0_result == 0) || (b2f0_result == 5)) {
1644 *ipbfadr2 = parm->ipbfadr2;
1646 *ipbfln2f = parm->ipbfln2f;
1648 release_param(parm);
1650 iucv_debug(2, "exiting");
1656 * Name: iucv_reply_array
1657 * Purpose: This function responds to the two-way messages that you
1658 * receive. You must identify completely the message to
1659 * which you wish to reply. ie, pathid, msgid, and trgcls.
1660 * The array identifies a list of addresses and lengths of
1661 * discontiguous buffers that contains the reply data.
1662 * Input: pathid - path identification number
1663 * msgid - specifies the message ID.
1664 * trgcls - specifies target class
1665 * flags1 - option for path
1666 * IPPRTY- specifies if you want to send priority message
1667 * buffer - address of array of reply buffers
1668 * buflen - total length of reply buffers
1669 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1670 * ipbfln2f - Contains one of the following values:
1671 * If the answer buffer is the same length as the reply, this field
1673 * If the answer buffer is longer than the reply, this field contains
1674 * the number of bytes remaining in the buffer.
1675 * If the answer buffer is shorter than the reply, this field contains
1676 * a residual count (that is, the number of bytes remianing in the
1677 * reply that does not fit into the buffer. In this
1678 * case b2f0_result = 5.
1679 * Return: b2f0_result - return code from CP
1680 * (-EINVAL) - buffer address is NULL
1683 iucv_reply_array (__u16 pathid,
1684 __u32 msgid, __u32 trgcls,
1686 iucv_array_t * buffer,
1687 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1692 iucv_debug(2, "entering");
1697 parm = (iparml_db *)grab_param();
1699 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1700 parm->ipbfln2f = buflen; /* length of message */
1701 parm->ippathid = pathid;
1702 parm->ipmsgid = msgid;
1703 parm->iptrgcls = trgcls;
1704 parm->ipflags1 = (IPANSLST | flags1);
1706 b2f0_result = b2f0(REPLY, parm);
1708 if ((b2f0_result == 0) || (b2f0_result == 5)) {
1711 *ipbfadr2 = parm->ipbfadr2;
1713 *ipbfln2f = parm->ipbfln2f;
1715 release_param(parm);
1717 iucv_debug(2, "exiting");
1723 * Name: iucv_reply_prmmsg
1724 * Purpose: This function responds to the two-way messages that you
1725 * receive. You must identify completely the message to
1726 * which you wish to reply. ie, pathid, msgid, and trgcls.
1727 * Prmmsg signifies the data is moved into the
1729 * Input: pathid - path identification number
1730 * msgid - specifies the message ID.
1731 * trgcls - specifies target class
1732 * flags1 - option for path
1733 * IPPRTY- specifies if you want to send priority message
1734 * prmmsg - 8-bytes of data to be placed into the parameter
1737 * Return: b2f0_result - return code from CP
1740 iucv_reply_prmmsg (__u16 pathid,
1741 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1746 iucv_debug(2, "entering");
1748 parm = (iparml_dpl *)grab_param();
1750 parm->ippathid = pathid;
1751 parm->ipmsgid = msgid;
1752 parm->iptrgcls = trgcls;
1753 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1754 parm->ipflags1 = (IPRMDATA | flags1);
1756 b2f0_result = b2f0(REPLY, parm);
1757 release_param(parm);
1759 iucv_debug(2, "exiting");
1766 * @pathid: Path identification number
1767 * @user_data: 16-byte of user data
1769 * This function restores communication over a quiesced path.
1770 * Returns: return code from CP
1773 iucv_resume (__u16 pathid, __u8 user_data[16])
1775 iparml_control *parm;
1776 ulong b2f0_result = 0;
1778 iucv_debug(1, "entering");
1779 iucv_debug(1, "pathid = %d", pathid);
1781 parm = (iparml_control *)grab_param();
1783 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1784 parm->ippathid = pathid;
1786 b2f0_result = b2f0(RESUME, parm);
1787 release_param(parm);
1789 iucv_debug(1, "exiting");
1796 * Purpose: sends messages
1797 * Input: pathid - ushort, pathid
1798 * msgid - ulong *, id of message returned to caller
1799 * trgcls - ulong, target message class
1800 * srccls - ulong, source message class
1801 * msgtag - ulong, message tag
1802 * flags1 - Contains options for this path.
1803 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1804 * buffer - pointer to buffer
1805 * buflen - ulong, length of buffer
1806 * Output: b2f0_result - return code from b2f0 call
1807 * msgid - returns message id
1810 iucv_send (__u16 pathid, __u32 * msgid,
1811 __u32 trgcls, __u32 srccls,
1812 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1817 iucv_debug(2, "entering");
1822 parm = (iparml_db *)grab_param();
1824 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1825 parm->ippathid = pathid;
1826 parm->iptrgcls = trgcls;
1827 parm->ipbfln1f = (__u32) buflen; /* length of message */
1828 parm->ipsrccls = srccls;
1829 parm->ipmsgtag = msgtag;
1830 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1832 b2f0_result = b2f0(SEND, parm);
1834 if ((b2f0_result == 0) && (msgid))
1835 *msgid = parm->ipmsgid;
1836 release_param(parm);
1838 iucv_debug(2, "exiting");
1844 * Name: iucv_send_array
1845 * Purpose: This function transmits data to another application.
1846 * The contents of buffer is the address of the array of
1847 * addresses and lengths of discontiguous buffers that hold
1848 * the message text. This is a one-way message and the
1849 * receiver will not reply to the message.
1850 * Input: pathid - path identification number
1851 * trgcls - specifies target class
1852 * srccls - specifies the source message class
1853 * msgtag - specifies a tag to be associated witht the message
1854 * flags1 - option for path
1855 * IPPRTY- specifies if you want to send priority message
1856 * buffer - address of array of send buffers
1857 * buflen - total length of send buffers
1858 * Output: msgid - specifies the message ID.
1859 * Return: b2f0_result - return code from CP
1860 * (-EINVAL) - buffer address is NULL
1863 iucv_send_array (__u16 pathid,
1867 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1872 iucv_debug(2, "entering");
1877 parm = (iparml_db *)grab_param();
1879 parm->ippathid = pathid;
1880 parm->iptrgcls = trgcls;
1881 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1882 parm->ipbfln1f = (__u32) buflen; /* length of message */
1883 parm->ipsrccls = srccls;
1884 parm->ipmsgtag = msgtag;
1885 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1886 b2f0_result = b2f0(SEND, parm);
1888 if ((b2f0_result == 0) && (msgid))
1889 *msgid = parm->ipmsgid;
1890 release_param(parm);
1892 iucv_debug(2, "exiting");
1897 * Name: iucv_send_prmmsg
1898 * Purpose: This function transmits data to another application.
1899 * Prmmsg specifies that the 8-bytes of data are to be moved
1900 * into the parameter list. This is a one-way message and the
1901 * receiver will not reply to the message.
1902 * Input: pathid - path identification number
1903 * trgcls - specifies target class
1904 * srccls - specifies the source message class
1905 * msgtag - specifies a tag to be associated with the message
1906 * flags1 - option for path
1907 * IPPRTY- specifies if you want to send priority message
1908 * prmmsg - 8-bytes of data to be placed into parameter list
1909 * Output: msgid - specifies the message ID.
1910 * Return: b2f0_result - return code from CP
1913 iucv_send_prmmsg (__u16 pathid,
1916 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1921 iucv_debug(2, "entering");
1923 parm = (iparml_dpl *)grab_param();
1925 parm->ippathid = pathid;
1926 parm->iptrgcls = trgcls;
1927 parm->ipsrccls = srccls;
1928 parm->ipmsgtag = msgtag;
1929 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1930 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1932 b2f0_result = b2f0(SEND, parm);
1934 if ((b2f0_result == 0) && (msgid))
1935 *msgid = parm->ipmsgid;
1936 release_param(parm);
1938 iucv_debug(2, "exiting");
1944 * Name: iucv_send2way
1945 * Purpose: This function transmits data to another application.
1946 * Data to be transmitted is in a buffer. The receiver
1947 * of the send is expected to reply to the message and
1948 * a buffer is provided into which IUCV moves the reply
1950 * Input: pathid - path identification number
1951 * trgcls - specifies target class
1952 * srccls - specifies the source message class
1953 * msgtag - specifies a tag associated with the message
1954 * flags1 - option for path
1955 * IPPRTY- specifies if you want to send priority message
1956 * buffer - address of send buffer
1957 * buflen - length of send buffer
1958 * ansbuf - address of buffer to reply with
1959 * anslen - length of buffer to reply with
1960 * Output: msgid - specifies the message ID.
1961 * Return: b2f0_result - return code from CP
1962 * (-EINVAL) - buffer or ansbuf address is NULL
1965 iucv_send2way (__u16 pathid,
1971 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1976 iucv_debug(2, "entering");
1978 if (!buffer || !ansbuf)
1981 parm = (iparml_db *)grab_param();
1983 parm->ippathid = pathid;
1984 parm->iptrgcls = trgcls;
1985 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1986 parm->ipbfln1f = (__u32) buflen; /* length of message */
1987 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1988 parm->ipbfln2f = (__u32) anslen;
1989 parm->ipsrccls = srccls;
1990 parm->ipmsgtag = msgtag;
1991 parm->ipflags1 = flags1; /* priority message */
1993 b2f0_result = b2f0(SEND, parm);
1995 if ((b2f0_result == 0) && (msgid))
1996 *msgid = parm->ipmsgid;
1997 release_param(parm);
1999 iucv_debug(2, "exiting");
2005 * Name: iucv_send2way_array
2006 * Purpose: This function transmits data to another application.
2007 * The contents of buffer is the address of the array of
2008 * addresses and lengths of discontiguous buffers that hold
2009 * the message text. The receiver of the send is expected to
2010 * reply to the message and a buffer is provided into which
2011 * IUCV moves the reply to this message.
2012 * Input: pathid - path identification number
2013 * trgcls - specifies target class
2014 * srccls - specifies the source message class
2015 * msgtag - spcifies a tag to be associated with the message
2016 * flags1 - option for path
2017 * IPPRTY- specifies if you want to send priority message
2018 * buffer - address of array of send buffers
2019 * buflen - total length of send buffers
2020 * ansbuf - address of buffer to reply with
2021 * anslen - length of buffer to reply with
2022 * Output: msgid - specifies the message ID.
2023 * Return: b2f0_result - return code from CP
2024 * (-EINVAL) - buffer address is NULL
2027 iucv_send2way_array (__u16 pathid,
2033 iucv_array_t * buffer,
2034 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2039 iucv_debug(2, "entering");
2041 if (!buffer || !ansbuf)
2044 parm = (iparml_db *)grab_param();
2046 parm->ippathid = pathid;
2047 parm->iptrgcls = trgcls;
2048 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2049 parm->ipbfln1f = (__u32) buflen; /* length of message */
2050 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2051 parm->ipbfln2f = (__u32) anslen;
2052 parm->ipsrccls = srccls;
2053 parm->ipmsgtag = msgtag;
2054 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2055 b2f0_result = b2f0(SEND, parm);
2056 if ((b2f0_result == 0) && (msgid))
2057 *msgid = parm->ipmsgid;
2058 release_param(parm);
2060 iucv_debug(2, "exiting");
2065 * Name: iucv_send2way_prmmsg
2066 * Purpose: This function transmits data to another application.
2067 * Prmmsg specifies that the 8-bytes of data are to be moved
2068 * into the parameter list. This is a two-way message and the
2069 * receiver of the message is expected to reply. A buffer
2070 * is provided into which IUCV moves the reply to this
2072 * Input: pathid - path identification number
2073 * trgcls - specifies target class
2074 * srccls - specifies the source message class
2075 * msgtag - specifies a tag to be associated with the message
2076 * flags1 - option for path
2077 * IPPRTY- specifies if you want to send priority message
2078 * prmmsg - 8-bytes of data to be placed in parameter list
2079 * ansbuf - address of buffer to reply with
2080 * anslen - length of buffer to reply with
2081 * Output: msgid - specifies the message ID.
2082 * Return: b2f0_result - return code from CP
2083 * (-EINVAL) - buffer address is NULL
2086 iucv_send2way_prmmsg (__u16 pathid,
2091 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2096 iucv_debug(2, "entering");
2101 parm = (iparml_dpl *)grab_param();
2103 parm->ippathid = pathid;
2104 parm->iptrgcls = trgcls;
2105 parm->ipsrccls = srccls;
2106 parm->ipmsgtag = msgtag;
2107 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2108 parm->ipbfln2f = (__u32) anslen;
2109 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2110 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2112 b2f0_result = b2f0(SEND, parm);
2114 if ((b2f0_result == 0) && (msgid))
2115 *msgid = parm->ipmsgid;
2116 release_param(parm);
2118 iucv_debug(2, "exiting");
2124 * Name: iucv_send2way_prmmsg_array
2125 * Purpose: This function transmits data to another application.
2126 * Prmmsg specifies that the 8-bytes of data are to be moved
2127 * into the parameter list. This is a two-way message and the
2128 * receiver of the message is expected to reply. A buffer
2129 * is provided into which IUCV moves the reply to this
2130 * message. The contents of ansbuf is the address of the
2131 * array of addresses and lengths of discontiguous buffers
2132 * that contain the reply.
2133 * Input: pathid - path identification number
2134 * trgcls - specifies target class
2135 * srccls - specifies the source message class
2136 * msgtag - specifies a tag to be associated with the message
2137 * flags1 - option for path
2138 * IPPRTY- specifies if you want to send priority message
2139 * prmmsg - 8-bytes of data to be placed into the parameter list
2140 * ansbuf - address of buffer to reply with
2141 * anslen - length of buffer to reply with
2142 * Output: msgid - specifies the message ID.
2143 * Return: b2f0_result - return code from CP
2144 * (-EINVAL) - ansbuf address is NULL
2147 iucv_send2way_prmmsg_array (__u16 pathid,
2154 iucv_array_t * ansbuf, ulong anslen)
2159 iucv_debug(2, "entering");
2164 parm = (iparml_dpl *)grab_param();
2166 parm->ippathid = pathid;
2167 parm->iptrgcls = trgcls;
2168 parm->ipsrccls = srccls;
2169 parm->ipmsgtag = msgtag;
2170 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2171 parm->ipbfln2f = (__u32) anslen;
2172 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2173 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2174 b2f0_result = b2f0(SEND, parm);
2175 if ((b2f0_result == 0) && (msgid))
2176 *msgid = parm->ipmsgid;
2177 release_param(parm);
2179 iucv_debug(2, "exiting");
2184 iucv_setmask_cpu0 (void *result)
2186 iparml_set_mask *parm;
2188 if (smp_processor_id() != 0)
2191 iucv_debug(1, "entering");
2192 parm = (iparml_set_mask *)grab_param();
2193 parm->ipmask = *((__u8*)result);
2194 *((ulong *)result) = b2f0(SETMASK, parm);
2195 release_param(parm);
2197 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2198 iucv_debug(1, "exiting");
2202 * Name: iucv_setmask
2203 * Purpose: This function enables or disables the following IUCV
2204 * external interruptions: Nonpriority and priority message
2205 * interrupts, nonpriority and priority reply interrupts.
2206 * Input: SetMaskFlag - options for interrupts
2207 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2208 * 0x40 - Priority_MessagePendingInterruptsFlag
2209 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2210 * 0x10 - Priority_MessageCompletionInterruptsFlag
2211 * 0x08 - IUCVControlInterruptsFlag
2213 * Return: b2f0_result - return code from CP
2216 iucv_setmask (int SetMaskFlag)
2223 u.param = SetMaskFlag;
2225 if (smp_processor_id() == 0)
2226 iucv_setmask_cpu0(&u);
2228 smp_call_function(iucv_setmask_cpu0, &u, 0, 1);
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__);
2288 memcpy(&irqdata->data, iucv_external_int_buffer,
2289 sizeof(iucv_GeneralInterrupt));
2291 spin_lock(&iucv_irq_queue_lock);
2292 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2293 spin_unlock(&iucv_irq_queue_lock);
2295 tasklet_schedule(&iucv_tasklet);
2300 * @int_buf: Pointer to copy of external interrupt buffer
2302 * The workhorse for handling interrupts queued by iucv_irq_handler().
2303 * This function is called from the bottom half iucv_tasklet_handler().
2306 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2309 struct list_head *lh;
2311 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2312 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2314 __u8 no_listener[16] = "NO LISTENER";
2316 iucv_debug(2, "entering, pathid %d, type %02X",
2317 int_buf->ippathid, int_buf->iptype);
2318 iucv_dumpit("External Interrupt Buffer:",
2319 int_buf, sizeof(iucv_GeneralInterrupt));
2321 ASCEBC (no_listener, 16);
2323 if (int_buf->iptype != 01) {
2324 if ((int_buf->ippathid) > (max_connections - 1)) {
2325 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2326 " > max_connections (%ld)\n", __FUNCTION__,
2327 int_buf->ippathid, max_connections - 1);
2329 h = iucv_pathid_table[int_buf->ippathid];
2330 interrupt = h->interrupt_table;
2331 iucv_dumpit("Handler:", h, sizeof(handler));
2335 /* end of if statement */
2336 switch (int_buf->iptype) {
2337 case 0x01: /* connection pending */
2338 if (messagesDisabled) {
2340 messagesDisabled = 0;
2342 spin_lock_irqsave(&iucv_lock, flags);
2343 list_for_each(lh, &iucv_handler_table) {
2344 h = list_entry(lh, handler, list);
2345 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2346 memcpy(temp_buff2, &(h->id.userid), 24);
2347 for (j = 0; j < 24; j++) {
2348 temp_buff1[j] &= (h->id.mask)[j];
2349 temp_buff2[j] &= (h->id.mask)[j];
2352 iucv_dumpit("temp_buff1:",
2353 temp_buff1, sizeof(temp_buff1));
2354 iucv_dumpit("temp_buff2",
2355 temp_buff2, sizeof(temp_buff2));
2357 if (memcmp (temp_buff1, temp_buff2, 24) == 0) {
2360 "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 module_init(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_reply_prmmsg);
2549 EXPORT_SYMBOL (iucv_resume);
2551 EXPORT_SYMBOL (iucv_send);
2553 EXPORT_SYMBOL (iucv_send2way);
2554 EXPORT_SYMBOL (iucv_send2way_array);
2555 EXPORT_SYMBOL (iucv_send_array);
2556 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2557 EXPORT_SYMBOL (iucv_send2way_prmmsg_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);