2 * $Id: iucv.c,v 1.38 2004/07/09 15:59:53 mschwide 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.38 $
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 = NULL;
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 * iucv_cpuid: contains the logical cpu number of the cpu which
181 * has declared the iucv buffer by issuing DECLARE_BUFFER.
182 * If no cpu has done the initialization iucv_cpuid contains -1.
184 static int iucv_cpuid = -1;
186 * register_flag: is 0 when external interrupt has not been registered
188 static int register_flag;
190 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
191 /* Data struct 1: iparml_control
192 * Used for iucv_accept
197 * iucv_retrieve_buffer
198 * Data struct 2: iparml_dpl (data in parameter list)
199 * Used for iucv_send_prmmsg
200 * iucv_send2way_prmmsg
201 * iucv_send2way_prmmsg_array
203 * Data struct 3: iparml_db (data in a buffer)
204 * Used for iucv_receive
212 * iucv_send2way_array
213 * iucv_declare_buffer
214 * Data struct 4: iparml_purge
215 * Used for iucv_purge
217 * Data struct 5: iparml_set_mask
218 * Used for iucv_set_mask
283 iparml_control p_ctrl;
286 iparml_purge p_purge;
287 iparml_set_mask p_set_mask;
291 } __attribute__ ((aligned(8))) iucv_param;
292 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
294 static iucv_param * iucv_param_pool;
296 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
297 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
298 MODULE_LICENSE("GPL");
302 *******************************************************************************/
306 static int debuglevel = 0;
308 module_param(debuglevel, int, 0);
309 MODULE_PARM_DESC(debuglevel,
310 "Specifies the debug level (0=off ... 3=all)");
313 iucv_dumpit(char *title, void *buf, int len)
316 __u8 *p = (__u8 *)buf;
321 printk(KERN_DEBUG "%s\n", title);
323 for (i = 0; i < len; i++) {
324 if (!(i % 16) && i != 0)
326 else if (!(i % 4) && i != 0)
328 printk("%02X", *p++);
334 #define iucv_debug(lvl, fmt, args...) \
336 if (debuglevel >= lvl) \
337 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
342 #define iucv_debug(lvl, fmt, args...)
343 #define iucv_dumpit(title, buf, len)
349 *******************************************************************************/
357 char vbuf[] = "$Revision: 1.38 $";
358 char *version = vbuf;
360 if ((version = strchr(version, ':'))) {
361 char *p = strchr(version + 1, '$');
367 "IUCV lowlevel driver Version%s initialized\n", version);
371 * iucv_init - Initialization
373 * Allocates and initializes various data structures.
380 if (iucv_external_int_buffer)
383 if (!MACHINE_IS_VM) {
384 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
385 return -EPROTONOSUPPORT;
388 ret = bus_register(&iucv_bus);
390 printk(KERN_ERR "IUCV: failed to register bus.\n");
394 iucv_root = s390_root_dev_register("iucv");
395 if (IS_ERR(iucv_root)) {
396 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
397 bus_unregister(&iucv_bus);
398 return PTR_ERR(iucv_root);
401 /* Note: GFP_DMA used used to get memory below 2G */
402 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt),
404 if (!iucv_external_int_buffer) {
406 "%s: Could not allocate external interrupt buffer\n",
408 s390_root_dev_unregister(iucv_root);
409 bus_unregister(&iucv_bus);
412 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
414 /* Initialize parameter pool */
415 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
417 if (!iucv_param_pool) {
418 printk(KERN_WARNING "%s: Could not allocate param pool\n",
420 kfree(iucv_external_int_buffer);
421 iucv_external_int_buffer = NULL;
422 s390_root_dev_unregister(iucv_root);
423 bus_unregister(&iucv_bus);
426 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
428 /* Initialize irq queue */
429 INIT_LIST_HEAD(&iucv_irq_queue);
431 /* Initialize handler table */
432 INIT_LIST_HEAD(&iucv_handler_table);
439 * iucv_exit - De-Initialization
441 * Frees everything allocated from iucv_init.
443 static int iucv_retrieve_buffer (void);
448 iucv_retrieve_buffer();
449 if (iucv_external_int_buffer) {
450 kfree(iucv_external_int_buffer);
451 iucv_external_int_buffer = NULL;
453 if (iucv_param_pool) {
454 kfree(iucv_param_pool);
455 iucv_param_pool = NULL;
457 s390_root_dev_unregister(iucv_root);
458 bus_unregister(&iucv_bus);
459 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
463 * grab_param: - Get a parameter buffer from the pre-allocated pool.
465 * This function searches for an unused element in the pre-allocated pool
466 * of parameter buffers. If one is found, it marks it "in use" and returns
467 * a pointer to it. The calling function is responsible for releasing it
468 * when it has finished its usage.
470 * Returns: A pointer to iucv_param.
472 static __inline__ iucv_param *
478 ptr = iucv_param_pool + hint;
481 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
482 ptr = iucv_param_pool;
483 } while (atomic_compare_and_swap(0, 1, &ptr->in_use));
484 hint = ptr - iucv_param_pool;
486 memset(&ptr->param, 0, sizeof(ptr->param));
491 * release_param - Release a parameter buffer.
492 * @p: A pointer to a struct iucv_param, previously obtained by calling
495 * This function marks the specified parameter buffer "unused".
497 static __inline__ void
498 release_param(void *p)
500 atomic_set(&((iucv_param *)p)->in_use, 0);
504 * iucv_add_handler: - Add a new handler
505 * @new_handler: handle that is being entered into chain.
507 * Places new handle on iucv_handler_table, if identical handler is not
510 * Returns: 0 on success, !0 on failure (handler already in chain).
513 iucv_add_handler (handler *new)
517 iucv_debug(1, "entering");
518 iucv_dumpit("handler:", new, sizeof(handler));
520 spin_lock_irqsave (&iucv_lock, flags);
521 if (!list_empty(&iucv_handler_table)) {
522 struct list_head *lh;
525 * Search list for handler with identical id. If one
526 * is found, the new handler is _not_ added.
528 list_for_each(lh, &iucv_handler_table) {
529 handler *h = list_entry(lh, handler, list);
530 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
531 iucv_debug(1, "ret 1");
532 spin_unlock_irqrestore (&iucv_lock, flags);
538 * If we get here, no handler was found.
540 INIT_LIST_HEAD(&new->list);
541 list_add(&new->list, &iucv_handler_table);
542 spin_unlock_irqrestore (&iucv_lock, flags);
544 iucv_debug(1, "exiting");
550 * @code: identifier of IUCV call to CP.
551 * @parm: pointer to 40 byte iparml area passed to CP
553 * Calls CP to execute IUCV commands.
555 * Returns: return code from CP's IUCV call
557 static __inline__ ulong
558 b2f0(__u32 code, void *parm)
560 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
567 : "d" (code), "a" (parm)
571 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
573 return (unsigned long)*((__u8 *)(parm + 3));
577 * Name: iucv_add_pathid
578 * Purpose: Adds a path id to the system.
579 * Input: pathid - pathid that is going to be entered into system
580 * handle - address of handler that the pathid will be associated
582 * pgm_data - token passed in by application.
583 * Output: 0: successful addition of pathid
584 * - EINVAL - pathid entry is being used by another application
585 * - ENOMEM - storage allocation for a new pathid table failed
588 __iucv_add_pathid(__u16 pathid, handler *handler)
591 iucv_debug(1, "entering");
593 iucv_debug(1, "handler is pointing to %p", handler);
595 if (pathid > (max_connections - 1))
598 if (iucv_pathid_table[pathid]) {
599 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
601 "%s: Pathid being used, error.\n", __FUNCTION__);
604 iucv_pathid_table[pathid] = handler;
606 iucv_debug(1, "exiting");
608 } /* end of add_pathid function */
611 iucv_add_pathid(__u16 pathid, handler *handler)
616 spin_lock_irqsave (&iucv_lock, flags);
617 rc = __iucv_add_pathid(pathid, handler);
618 spin_unlock_irqrestore (&iucv_lock, flags);
623 iucv_remove_pathid(__u16 pathid)
627 if (pathid > (max_connections - 1))
630 spin_lock_irqsave (&iucv_lock, flags);
631 iucv_pathid_table[pathid] = NULL;
632 spin_unlock_irqrestore (&iucv_lock, flags);
636 * iucv_declare_buffer_cpuid
637 * Register at VM for subsequent IUCV operations. This is executed
638 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
641 iucv_declare_buffer_cpuid (void *result)
645 parm = (iparml_db *)grab_param();
646 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
647 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
648 *((ulong *)result) = parm->iprcode;
653 * iucv_retrieve_buffer_cpuid:
654 * Unregister IUCV usage at VM. This is always executed on the same
655 * cpu that registered the buffer to VM.
656 * Called from iucv_retrieve_buffer().
659 iucv_retrieve_buffer_cpuid (void *cpu)
661 iparml_control *parm;
663 parm = (iparml_control *)grab_param();
664 b2f0(RETRIEVE_BUFFER, parm);
669 * Name: iucv_declare_buffer
670 * Purpose: Specifies the guests real address of an external
673 * Output: iprcode - return code from b2f0 call
676 iucv_declare_buffer (void)
681 iucv_debug(1, "entering");
682 b2f0_result = -ENODEV;
683 spin_lock_irqsave (&iucv_lock, flags);
684 if (iucv_cpuid == -1) {
685 /* Reserve any cpu for use by iucv. */
686 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
687 spin_unlock_irqrestore (&iucv_lock, flags);
688 smp_call_function_on(iucv_declare_buffer_cpuid,
689 &b2f0_result, 0, 1, iucv_cpuid);
691 smp_put_cpu(iucv_cpuid);
694 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
696 spin_unlock_irqrestore (&iucv_lock, flags);
699 iucv_debug(1, "exiting");
704 * iucv_retrieve_buffer:
706 * Terminates all use of IUCV.
707 * Returns: return code from CP
710 iucv_retrieve_buffer (void)
712 iucv_debug(1, "entering");
713 if (iucv_cpuid != -1) {
714 smp_call_function_on(iucv_retrieve_buffer_cpuid,
715 0, 0, 1, iucv_cpuid);
716 /* Release the cpu reserved by iucv_declare_buffer. */
717 smp_put_cpu(iucv_cpuid);
720 iucv_debug(1, "exiting");
725 * iucv_remove_handler:
726 * @users_handler: handler to be removed
728 * Remove handler when application unregisters.
731 iucv_remove_handler(handler *handler)
735 if ((!iucv_pathid_table) || (!handler))
738 iucv_debug(1, "entering");
740 spin_lock_irqsave (&iucv_lock, flags);
741 list_del(&handler->list);
742 if (list_empty(&iucv_handler_table)) {
744 unregister_external_interrupt(0x4000, iucv_irq_handler);
748 spin_unlock_irqrestore (&iucv_lock, flags);
750 iucv_debug(1, "exiting");
755 * iucv_register_program:
756 * @pgmname: user identification
757 * @userid: machine identification
758 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
759 * used to determine who is given control.
760 * @ops: Address of interrupt handler table.
761 * @pgm_data: Application data to be passed to interrupt handlers.
763 * Registers an application with IUCV.
765 * The address of handler, or NULL on failure.
767 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
769 * If pgmmask is NULL, the internal mask is set to all 0xff's
770 * When userid is NULL, the first 8 bytes of the internal mask are forced
772 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
773 * are forced to 0x00 and the last 16 bytes to 0xff.
777 iucv_register_program (__u8 pgmname[16],
780 iucv_interrupt_ops_t * ops, void *pgm_data)
782 ulong rc = 0; /* return code from function calls */
783 handler *new_handler;
785 iucv_debug(1, "entering");
788 /* interrupt table is not defined */
789 printk(KERN_WARNING "%s: Interrupt table is not defined, "
790 "exiting\n", __FUNCTION__);
794 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
798 /* Allocate handler entry */
799 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
800 if (new_handler == NULL) {
801 printk(KERN_WARNING "%s: storage allocation for new handler "
802 "failed.\n", __FUNCTION__);
806 if (!iucv_pathid_table) {
812 max_connections = iucv_query_maxconn();
813 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
815 if (iucv_pathid_table == NULL) {
816 printk(KERN_WARNING "%s: iucv_pathid_table storage "
817 "allocation failed\n", __FUNCTION__);
821 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
823 memset(new_handler, 0, sizeof (handler));
824 memcpy(new_handler->id.user_data, pgmname,
825 sizeof (new_handler->id.user_data));
827 memcpy (new_handler->id.userid, userid,
828 sizeof (new_handler->id.userid));
829 ASCEBC (new_handler->id.userid,
830 sizeof (new_handler->id.userid));
831 EBC_TOUPPER (new_handler->id.userid,
832 sizeof (new_handler->id.userid));
835 memcpy (new_handler->id.mask, pgmmask,
836 sizeof (new_handler->id.mask));
838 memset (new_handler->id.mask, 0xFF,
839 sizeof (new_handler->id.mask));
843 memcpy (new_handler->id.mask, pgmmask,
844 sizeof (new_handler->id.mask));
846 memset (new_handler->id.mask, 0xFF,
847 sizeof (new_handler->id.mask));
849 memset (new_handler->id.userid, 0x00,
850 sizeof (new_handler->id.userid));
852 /* fill in the rest of handler */
853 new_handler->pgm_data = pgm_data;
854 new_handler->interrupt_table = ops;
857 * Check if someone else is registered with same pgmname, userid
858 * and mask. If someone is already registered with same pgmname,
859 * userid and mask, registration will fail and NULL will be returned
860 * to the application.
861 * If identical handler not found, then handler is added to list.
863 rc = iucv_add_handler(new_handler);
865 printk(KERN_WARNING "%s: Someone already registered with same "
866 "pgmname, userid, pgmmask\n", __FUNCTION__);
871 rc = iucv_declare_buffer();
873 char *err = "Unknown";
874 iucv_remove_handler(new_handler);
878 err = "No CPU can be reserved";
881 err = "Directory error";
884 err = "Invalid length";
887 err = "Buffer already exists";
890 err = "Buffer overlap";
893 err = "Paging or storage error";
896 printk(KERN_WARNING "%s: iucv_declare_buffer "
897 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
900 if (!register_flag) {
901 /* request the 0x4000 external interrupt */
902 rc = register_external_interrupt (0x4000, iucv_irq_handler);
904 iucv_remove_handler(new_handler);
906 printk(KERN_WARNING "%s: "
907 "register_external_interrupt returned %ld\n",
914 iucv_debug(1, "exiting");
916 } /* end of register function */
919 * iucv_unregister_program:
920 * @handle: address of handler
922 * Unregister application with IUCV.
924 * 0 on success, -EINVAL, if specified handle is invalid.
928 iucv_unregister_program (iucv_handle_t handle)
931 struct list_head *lh;
935 iucv_debug(1, "entering");
936 iucv_debug(1, "address of handler is %p", h);
938 /* Checking if handle is valid */
939 spin_lock_irqsave (&iucv_lock, flags);
940 list_for_each(lh, &iucv_handler_table) {
941 if ((handler *)handle == list_entry(lh, handler, list)) {
942 h = (handler *)handle;
947 spin_unlock_irqrestore (&iucv_lock, flags);
950 "%s: Handler not found in iucv_handler_table.\n",
954 "%s: NULL handle passed by application.\n",
960 * First, walk thru iucv_pathid_table and sever any pathid which is
961 * still pointing to the handler to be removed.
963 for (i = 0; i < max_connections; i++)
964 if (iucv_pathid_table[i] == h) {
965 spin_unlock_irqrestore (&iucv_lock, flags);
966 iucv_sever(i, h->id.user_data);
967 spin_lock_irqsave(&iucv_lock, flags);
969 spin_unlock_irqrestore (&iucv_lock, flags);
971 iucv_remove_handler(h);
974 iucv_debug(1, "exiting");
980 * @pathid: Path identification number
981 * @msglim_reqstd: The number of outstanding messages requested.
982 * @user_data: Data specified by the iucv_connect function.
983 * @flags1: Contains options for this path.
984 * - IPPRTY (0x20) Specifies if you want to send priority message.
985 * - IPRMDATA (0x80) Specifies whether your program can handle a message
986 * in the parameter list.
987 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
989 * @handle: Address of handler.
990 * @pgm_data: Application data passed to interrupt handlers.
991 * @flags1_out: Pointer to an int. If not NULL, on return the options for
992 * the path are stored at the given location:
993 * - IPPRTY (0x20) Indicates you may send a priority message.
994 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
995 * number of outstanding messages is stored at the given
998 * This function is issued after the user receives a Connection Pending external
999 * interrupt and now wishes to complete the IUCV communication path.
1001 * return code from CP
1004 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
1005 __u8 user_data[16], int flags1,
1006 iucv_handle_t handle, void *pgm_data,
1007 int *flags1_out, __u16 * msglim)
1009 ulong b2f0_result = 0;
1011 struct list_head *lh;
1013 iparml_control *parm;
1015 iucv_debug(1, "entering");
1016 iucv_debug(1, "pathid = %d", pathid);
1018 /* Checking if handle is valid */
1019 spin_lock_irqsave (&iucv_lock, flags);
1020 list_for_each(lh, &iucv_handler_table) {
1021 if ((handler *)handle == list_entry(lh, handler, list)) {
1022 h = (handler *)handle;
1026 spin_unlock_irqrestore (&iucv_lock, flags);
1031 "%s: Handler not found in iucv_handler_table.\n",
1035 "%s: NULL handle passed by application.\n",
1040 parm = (iparml_control *)grab_param();
1042 parm->ippathid = pathid;
1043 parm->ipmsglim = msglim_reqstd;
1045 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1047 parm->ipflags1 = (__u8)flags1;
1048 b2f0_result = b2f0(ACCEPT, parm);
1052 *msglim = parm->ipmsglim;
1054 h->pgm_data = pgm_data;
1056 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1058 release_param(parm);
1060 iucv_debug(1, "exiting");
1066 * @pathid: Path identification number
1067 * @msglim_reqstd: Number of outstanding messages requested
1068 * @user_data: 16-byte user data
1069 * @userid: 8-byte of user identification
1070 * @system_name: 8-byte identifying the system name
1071 * @flags1: Specifies options for this path:
1072 * - IPPRTY (0x20) Specifies if you want to send priority message.
1073 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1074 * in the parameter list.
1075 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1077 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1078 * local system. If local is specified then target class
1079 * cannot be specified.
1080 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1081 * the path are stored at the given location:
1082 * - IPPRTY (0x20) Indicates you may send a priority message.
1083 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1084 * number of outstanding messages is stored at the given
1086 * @handle: Address of handler.
1087 * @pgm_data: Application data to be passed to interrupt handlers.
1089 * This function establishes an IUCV path. Although the connect may complete
1090 * successfully, you are not able to use the path until you receive an IUCV
1091 * Connection Complete external interrupt.
1092 * Returns: return code from CP, or one of the following
1094 * - return code from iucv_declare_buffer
1095 * - EINVAL - invalid handle passed by application
1096 * - EINVAL - pathid address is NULL
1097 * - ENOMEM - pathid table storage allocation failed
1098 * - return code from internal function add_pathid
1101 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1102 __u8 user_data[16], __u8 userid[8],
1103 __u8 system_name[8], int flags1,
1104 int *flags1_out, __u16 * msglim,
1105 iucv_handle_t handle, void *pgm_data)
1107 iparml_control *parm;
1108 iparml_control local_parm;
1109 struct list_head *lh;
1110 ulong b2f0_result = 0;
1112 int add_pathid_result = 0;
1114 __u8 no_memory[16] = "NO MEMORY";
1116 iucv_debug(1, "entering");
1118 /* Checking if handle is valid */
1119 spin_lock_irqsave (&iucv_lock, flags);
1120 list_for_each(lh, &iucv_handler_table) {
1121 if ((handler *)handle == list_entry(lh, handler, list)) {
1122 h = (handler *)handle;
1126 spin_unlock_irqrestore (&iucv_lock, flags);
1131 "%s: Handler not found in iucv_handler_table.\n",
1135 "%s: NULL handle passed by application.\n",
1140 if (pathid == NULL) {
1141 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1146 parm = (iparml_control *)grab_param();
1148 parm->ipmsglim = msglim_reqstd;
1151 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1154 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1155 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1156 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1160 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1161 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1162 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1165 /* In order to establish an IUCV connection, the procedure is:
1168 * take the ippathid from the b2f0 call
1169 * register the handler to the ippathid
1171 * Unfortunately, the ConnectionEstablished message gets sent after the
1172 * b2f0(CONNECT) call but before the register is handled.
1174 * In order for this race condition to be eliminated, the IUCV Control
1175 * Interrupts must be disabled for the above procedure.
1177 * David Kennedy <dkennedy@linuxcare.com>
1180 /* Enable everything but IUCV Control messages */
1181 iucv_setmask(~(AllInterrupts));
1182 messagesDisabled = 1;
1184 spin_lock_irqsave (&iucv_lock, flags);
1185 parm->ipflags1 = (__u8)flags1;
1186 b2f0_result = b2f0(CONNECT, parm);
1187 memcpy(&local_parm, parm, sizeof(local_parm));
1188 release_param(parm);
1191 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1192 spin_unlock_irqrestore (&iucv_lock, flags);
1196 messagesDisabled = 0;
1200 *pathid = parm->ippathid;
1202 /* Enable everything again */
1203 iucv_setmask(IUCVControlInterruptsFlag);
1206 *msglim = parm->ipmsglim;
1208 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1210 if (add_pathid_result) {
1211 iucv_sever(*pathid, no_memory);
1212 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1213 " %d\n", __FUNCTION__, add_pathid_result);
1214 return(add_pathid_result);
1217 iucv_debug(1, "exiting");
1223 * @pathid: Path identification number
1224 * @msgid: Message ID of message to purge.
1225 * @srccls: Message class of the message to purge.
1226 * @audit: Pointer to an __u32. If not NULL, on return, information about
1227 * asynchronous errors that may have affected the normal completion
1228 * of this message ist stored at the given location.
1230 * Cancels a message you have sent.
1231 * Returns: return code from CP
1234 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1237 ulong b2f0_result = 0;
1239 iucv_debug(1, "entering");
1240 iucv_debug(1, "pathid = %d", pathid);
1242 parm = (iparml_purge *)grab_param();
1244 parm->ipmsgid = msgid;
1245 parm->ippathid = pathid;
1246 parm->ipsrccls = srccls;
1247 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1248 b2f0_result = b2f0(PURGE, parm);
1250 if (!b2f0_result && audit) {
1251 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1252 /* parm->ipaudit has only 3 bytes */
1256 release_param(parm);
1258 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1259 iucv_debug(1, "exiting");
1264 * iucv_query_generic:
1265 * @want_maxconn: Flag, describing which value is to be returned.
1267 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1269 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1270 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1273 iucv_query_generic(int want_maxconn)
1275 iparml_purge *parm = (iparml_purge *)grab_param();
1276 int bufsize, maxconn;
1280 * Call b2f0 and store R0 (max buffer size),
1281 * R1 (max connections) and CC.
1286 ".long 0xb2f01000\n\t"
1291 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1292 : "d" (QUERY), "a" (parm)
1295 release_param(parm);
1305 * iucv_query_maxconn:
1307 * Determines the maximum number of connections thay may be established.
1309 * Returns: Maximum number of connections that can be.
1312 iucv_query_maxconn(void)
1314 return iucv_query_generic(1);
1318 * iucv_query_bufsize:
1320 * Determines the size of the external interrupt buffer.
1322 * Returns: Size of external interrupt buffer.
1325 iucv_query_bufsize (void)
1327 return iucv_query_generic(0);
1332 * @pathid: Path identification number
1333 * @user_data: 16-byte user data
1335 * Temporarily suspends incoming messages on an IUCV path.
1336 * You can later reactivate the path by invoking the iucv_resume function.
1337 * Returns: return code from CP
1340 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1342 iparml_control *parm;
1343 ulong b2f0_result = 0;
1345 iucv_debug(1, "entering");
1346 iucv_debug(1, "pathid = %d", pathid);
1348 parm = (iparml_control *)grab_param();
1350 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1351 parm->ippathid = pathid;
1353 b2f0_result = b2f0(QUIESCE, parm);
1354 release_param(parm);
1356 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1357 iucv_debug(1, "exiting");
1364 * @pathid: Path identification number.
1365 * @buffer: Address of buffer to receive. Must be below 2G.
1366 * @buflen: Length of buffer to receive.
1367 * @msgid: Specifies the message ID.
1368 * @trgcls: Specifies target class.
1369 * @flags1_out: Receives options for path on return.
1370 * - IPNORPY (0x10) Specifies whether a reply is required
1371 * - IPPRTY (0x20) Specifies if you want to send priority message
1372 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1373 * @residual_buffer: Receives the address of buffer updated by the number
1374 * of bytes you have received on return.
1375 * @residual_length: On return, receives one of the following values:
1376 * - 0 If the receive buffer is the same length as
1378 * - Remaining bytes in buffer If the receive buffer is longer than the
1380 * - Remaining bytes in message If the receive buffer is shorter than the
1383 * This function receives messages that are being sent to you over established
1385 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1386 * than the message, always 5
1387 * -EINVAL - buffer address is pointing to NULL
1390 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1391 void *buffer, ulong buflen,
1392 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1396 int moved = 0; /* number of bytes moved from parmlist to buffer */
1398 iucv_debug(2, "entering");
1403 parm = (iparml_db *)grab_param();
1405 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1406 parm->ipbfln1f = (__u32) ((ulong) buflen);
1407 parm->ipmsgid = msgid;
1408 parm->ippathid = pathid;
1409 parm->iptrgcls = trgcls;
1410 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1412 b2f0_result = b2f0(RECEIVE, parm);
1414 if (!b2f0_result || b2f0_result == 5) {
1416 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1417 *flags1_out = (parm->ipflags1 & (~0x07));
1418 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1421 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1422 if (residual_length)
1423 *residual_length = parm->ipbfln1f;
1425 if (residual_buffer)
1426 *residual_buffer = parm->ipbfadr1;
1428 moved = min_t (unsigned long, buflen, 8);
1430 memcpy ((char *) buffer,
1431 (char *) &parm->ipbfadr1, moved);
1436 if (residual_length)
1437 *residual_length = abs (buflen - 8);
1439 if (residual_buffer)
1440 *residual_buffer = (ulong) (buffer + moved);
1443 release_param(parm);
1445 iucv_debug(2, "exiting");
1450 * Name: iucv_receive_array
1451 * Purpose: This function receives messages that are being sent to you
1452 * over established paths.
1453 * Input: pathid - path identification number
1454 * buffer - address of array of buffers
1455 * buflen - total length of buffers
1456 * msgid - specifies the message ID.
1457 * trgcls - specifies target class
1459 * flags1_out: Options for path.
1460 * IPNORPY - 0x10 specifies whether a reply is required
1461 * IPPRTY - 0x20 specifies if you want to send priority message
1462 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1463 * residual_buffer - address points to the current list entry IUCV
1466 * Contains one of the following values, if the receive buffer is:
1467 * The same length as the message, this field is zero.
1468 * Longer than the message, this field contains the number of
1469 * bytes remaining in the buffer.
1470 * Shorter than the message, this field contains the residual
1471 * count (that is, the number of bytes remaining in the
1472 * message that does not fit into the buffer. In this case
1474 * Return: b2f0_result - return code from CP
1475 * (-EINVAL) - buffer address is NULL
1478 iucv_receive_array (__u16 pathid,
1479 __u32 msgid, __u32 trgcls,
1480 iucv_array_t * buffer, ulong buflen,
1482 ulong * residual_buffer, ulong * residual_length)
1486 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1488 iucv_debug(2, "entering");
1493 parm = (iparml_db *)grab_param();
1495 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1496 parm->ipbfln1f = (__u32) buflen;
1497 parm->ipmsgid = msgid;
1498 parm->ippathid = pathid;
1499 parm->iptrgcls = trgcls;
1500 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1502 b2f0_result = b2f0(RECEIVE, parm);
1504 if (!b2f0_result || b2f0_result == 5) {
1507 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1508 *flags1_out = (parm->ipflags1 & (~0x07));
1509 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1512 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1514 if (residual_length)
1515 *residual_length = parm->ipbfln1f;
1517 if (residual_buffer)
1518 *residual_buffer = parm->ipbfadr1;
1521 /* copy msg from parmlist to users array. */
1523 while ((moved < 8) && (moved < buflen)) {
1525 min_t (unsigned int,
1526 (buffer + i)->length, need_to_move);
1528 memcpy ((char *)((ulong)((buffer + i)->address)),
1529 ((char *) &parm->ipbfadr1) + moved,
1533 need_to_move -= dyn_len;
1535 (buffer + i)->address =
1537 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1540 (buffer + i)->length -= dyn_len;
1544 if (need_to_move) /* buflen < 8 bytes */
1547 if (residual_length)
1548 *residual_length = abs (buflen - 8);
1550 if (residual_buffer) {
1552 *residual_buffer = (ulong) buffer;
1555 (ulong) (buffer + (i - 1));
1560 release_param(parm);
1562 iucv_debug(2, "exiting");
1568 * @pathid: Path identification number.
1569 * @msgid: Message ID of the message to reject.
1570 * @trgcls: Target class of the message to reject.
1571 * Returns: return code from CP
1573 * Refuses a specified message. Between the time you are notified of a
1574 * message and the time that you complete the message, the message may
1578 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1581 ulong b2f0_result = 0;
1583 iucv_debug(1, "entering");
1584 iucv_debug(1, "pathid = %d", pathid);
1586 parm = (iparml_db *)grab_param();
1588 parm->ippathid = pathid;
1589 parm->ipmsgid = msgid;
1590 parm->iptrgcls = trgcls;
1591 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1593 b2f0_result = b2f0(REJECT, parm);
1594 release_param(parm);
1596 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1597 iucv_debug(1, "exiting");
1604 * Purpose: This function responds to the two-way messages that you
1605 * receive. You must identify completely the message to
1606 * which you wish to reply. ie, pathid, msgid, and trgcls.
1607 * Input: pathid - path identification number
1608 * msgid - specifies the message ID.
1609 * trgcls - specifies target class
1610 * flags1 - option for path
1611 * IPPRTY- 0x20 - specifies if you want to send priority message
1612 * buffer - address of reply buffer
1613 * buflen - length of reply buffer
1614 * Output: ipbfadr2 - Address of buffer updated by the number
1615 * of bytes you have moved.
1616 * ipbfln2f - Contains one of the following values:
1617 * If the answer buffer is the same length as the reply, this field
1619 * If the answer buffer is longer than the reply, this field contains
1620 * the number of bytes remaining in the buffer.
1621 * If the answer buffer is shorter than the reply, this field contains
1622 * a residual count (that is, the number of bytes remianing in the
1623 * reply that does not fit into the buffer. In this
1624 * case b2f0_result = 5.
1625 * Return: b2f0_result - return code from CP
1626 * (-EINVAL) - buffer address is NULL
1629 iucv_reply (__u16 pathid,
1630 __u32 msgid, __u32 trgcls,
1632 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1637 iucv_debug(2, "entering");
1642 parm = (iparml_db *)grab_param();
1644 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1645 parm->ipbfln2f = (__u32) buflen; /* length of message */
1646 parm->ippathid = pathid;
1647 parm->ipmsgid = msgid;
1648 parm->iptrgcls = trgcls;
1649 parm->ipflags1 = (__u8) flags1; /* priority message */
1651 b2f0_result = b2f0(REPLY, parm);
1653 if ((!b2f0_result) || (b2f0_result == 5)) {
1655 *ipbfadr2 = parm->ipbfadr2;
1657 *ipbfln2f = parm->ipbfln2f;
1659 release_param(parm);
1661 iucv_debug(2, "exiting");
1667 * Name: iucv_reply_array
1668 * Purpose: This function responds to the two-way messages that you
1669 * receive. You must identify completely the message to
1670 * which you wish to reply. ie, pathid, msgid, and trgcls.
1671 * The array identifies a list of addresses and lengths of
1672 * discontiguous buffers that contains the reply data.
1673 * Input: pathid - path identification number
1674 * msgid - specifies the message ID.
1675 * trgcls - specifies target class
1676 * flags1 - option for path
1677 * IPPRTY- specifies if you want to send priority message
1678 * buffer - address of array of reply buffers
1679 * buflen - total length of reply buffers
1680 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1681 * ipbfln2f - Contains one of the following values:
1682 * If the answer buffer is the same length as the reply, this field
1684 * If the answer buffer is longer than the reply, this field contains
1685 * the number of bytes remaining in the buffer.
1686 * If the answer buffer is shorter than the reply, this field contains
1687 * a residual count (that is, the number of bytes remianing in the
1688 * reply that does not fit into the buffer. In this
1689 * case b2f0_result = 5.
1690 * Return: b2f0_result - return code from CP
1691 * (-EINVAL) - buffer address is NULL
1694 iucv_reply_array (__u16 pathid,
1695 __u32 msgid, __u32 trgcls,
1697 iucv_array_t * buffer,
1698 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1703 iucv_debug(2, "entering");
1708 parm = (iparml_db *)grab_param();
1710 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1711 parm->ipbfln2f = buflen; /* length of message */
1712 parm->ippathid = pathid;
1713 parm->ipmsgid = msgid;
1714 parm->iptrgcls = trgcls;
1715 parm->ipflags1 = (IPANSLST | flags1);
1717 b2f0_result = b2f0(REPLY, parm);
1719 if ((!b2f0_result) || (b2f0_result == 5)) {
1722 *ipbfadr2 = parm->ipbfadr2;
1724 *ipbfln2f = parm->ipbfln2f;
1726 release_param(parm);
1728 iucv_debug(2, "exiting");
1734 * Name: iucv_reply_prmmsg
1735 * Purpose: This function responds to the two-way messages that you
1736 * receive. You must identify completely the message to
1737 * which you wish to reply. ie, pathid, msgid, and trgcls.
1738 * Prmmsg signifies the data is moved into the
1740 * Input: pathid - path identification number
1741 * msgid - specifies the message ID.
1742 * trgcls - specifies target class
1743 * flags1 - option for path
1744 * IPPRTY- specifies if you want to send priority message
1745 * prmmsg - 8-bytes of data to be placed into the parameter
1748 * Return: b2f0_result - return code from CP
1751 iucv_reply_prmmsg (__u16 pathid,
1752 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1757 iucv_debug(2, "entering");
1759 parm = (iparml_dpl *)grab_param();
1761 parm->ippathid = pathid;
1762 parm->ipmsgid = msgid;
1763 parm->iptrgcls = trgcls;
1764 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1765 parm->ipflags1 = (IPRMDATA | flags1);
1767 b2f0_result = b2f0(REPLY, parm);
1768 release_param(parm);
1770 iucv_debug(2, "exiting");
1777 * @pathid: Path identification number
1778 * @user_data: 16-byte of user data
1780 * This function restores communication over a quiesced path.
1781 * Returns: return code from CP
1784 iucv_resume (__u16 pathid, __u8 user_data[16])
1786 iparml_control *parm;
1787 ulong b2f0_result = 0;
1789 iucv_debug(1, "entering");
1790 iucv_debug(1, "pathid = %d", pathid);
1792 parm = (iparml_control *)grab_param();
1794 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1795 parm->ippathid = pathid;
1797 b2f0_result = b2f0(RESUME, parm);
1798 release_param(parm);
1800 iucv_debug(1, "exiting");
1807 * Purpose: sends messages
1808 * Input: pathid - ushort, pathid
1809 * msgid - ulong *, id of message returned to caller
1810 * trgcls - ulong, target message class
1811 * srccls - ulong, source message class
1812 * msgtag - ulong, message tag
1813 * flags1 - Contains options for this path.
1814 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1815 * buffer - pointer to buffer
1816 * buflen - ulong, length of buffer
1817 * Output: b2f0_result - return code from b2f0 call
1818 * msgid - returns message id
1821 iucv_send (__u16 pathid, __u32 * msgid,
1822 __u32 trgcls, __u32 srccls,
1823 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1828 iucv_debug(2, "entering");
1833 parm = (iparml_db *)grab_param();
1835 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1836 parm->ippathid = pathid;
1837 parm->iptrgcls = trgcls;
1838 parm->ipbfln1f = (__u32) buflen; /* length of message */
1839 parm->ipsrccls = srccls;
1840 parm->ipmsgtag = msgtag;
1841 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1843 b2f0_result = b2f0(SEND, parm);
1845 if ((!b2f0_result) && (msgid))
1846 *msgid = parm->ipmsgid;
1847 release_param(parm);
1849 iucv_debug(2, "exiting");
1855 * Name: iucv_send_array
1856 * Purpose: This function transmits data to another application.
1857 * The contents of buffer is the address of the array of
1858 * addresses and lengths of discontiguous buffers that hold
1859 * the message text. This is a one-way message and the
1860 * receiver will not reply to the message.
1861 * Input: pathid - path identification number
1862 * trgcls - specifies target class
1863 * srccls - specifies the source message class
1864 * msgtag - specifies a tag to be associated witht the message
1865 * flags1 - option for path
1866 * IPPRTY- specifies if you want to send priority message
1867 * buffer - address of array of send buffers
1868 * buflen - total length of send buffers
1869 * Output: msgid - specifies the message ID.
1870 * Return: b2f0_result - return code from CP
1871 * (-EINVAL) - buffer address is NULL
1874 iucv_send_array (__u16 pathid,
1878 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1883 iucv_debug(2, "entering");
1888 parm = (iparml_db *)grab_param();
1890 parm->ippathid = pathid;
1891 parm->iptrgcls = trgcls;
1892 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1893 parm->ipbfln1f = (__u32) buflen; /* length of message */
1894 parm->ipsrccls = srccls;
1895 parm->ipmsgtag = msgtag;
1896 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1897 b2f0_result = b2f0(SEND, parm);
1899 if ((!b2f0_result) && (msgid))
1900 *msgid = parm->ipmsgid;
1901 release_param(parm);
1903 iucv_debug(2, "exiting");
1908 * Name: iucv_send_prmmsg
1909 * Purpose: This function transmits data to another application.
1910 * Prmmsg specifies that the 8-bytes of data are to be moved
1911 * into the parameter list. This is a one-way message and the
1912 * receiver will not reply to the message.
1913 * Input: pathid - path identification number
1914 * trgcls - specifies target class
1915 * srccls - specifies the source message class
1916 * msgtag - specifies a tag to be associated with the message
1917 * flags1 - option for path
1918 * IPPRTY- specifies if you want to send priority message
1919 * prmmsg - 8-bytes of data to be placed into parameter list
1920 * Output: msgid - specifies the message ID.
1921 * Return: b2f0_result - return code from CP
1924 iucv_send_prmmsg (__u16 pathid,
1927 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1932 iucv_debug(2, "entering");
1934 parm = (iparml_dpl *)grab_param();
1936 parm->ippathid = pathid;
1937 parm->iptrgcls = trgcls;
1938 parm->ipsrccls = srccls;
1939 parm->ipmsgtag = msgtag;
1940 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1941 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1943 b2f0_result = b2f0(SEND, parm);
1945 if ((!b2f0_result) && (msgid))
1946 *msgid = parm->ipmsgid;
1947 release_param(parm);
1949 iucv_debug(2, "exiting");
1955 * Name: iucv_send2way
1956 * Purpose: This function transmits data to another application.
1957 * Data to be transmitted is in a buffer. The receiver
1958 * of the send is expected to reply to the message and
1959 * a buffer is provided into which IUCV moves the reply
1961 * Input: pathid - path identification number
1962 * trgcls - specifies target class
1963 * srccls - specifies the source message class
1964 * msgtag - specifies a tag associated with the message
1965 * flags1 - option for path
1966 * IPPRTY- specifies if you want to send priority message
1967 * buffer - address of send buffer
1968 * buflen - length of send buffer
1969 * ansbuf - address of buffer to reply with
1970 * anslen - length of buffer to reply with
1971 * Output: msgid - specifies the message ID.
1972 * Return: b2f0_result - return code from CP
1973 * (-EINVAL) - buffer or ansbuf address is NULL
1976 iucv_send2way (__u16 pathid,
1982 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1987 iucv_debug(2, "entering");
1989 if (!buffer || !ansbuf)
1992 parm = (iparml_db *)grab_param();
1994 parm->ippathid = pathid;
1995 parm->iptrgcls = trgcls;
1996 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1997 parm->ipbfln1f = (__u32) buflen; /* length of message */
1998 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1999 parm->ipbfln2f = (__u32) anslen;
2000 parm->ipsrccls = srccls;
2001 parm->ipmsgtag = msgtag;
2002 parm->ipflags1 = flags1; /* priority message */
2004 b2f0_result = b2f0(SEND, parm);
2006 if ((!b2f0_result) && (msgid))
2007 *msgid = parm->ipmsgid;
2008 release_param(parm);
2010 iucv_debug(2, "exiting");
2016 * Name: iucv_send2way_array
2017 * Purpose: This function transmits data to another application.
2018 * The contents of buffer is the address of the array of
2019 * addresses and lengths of discontiguous buffers that hold
2020 * the message text. The receiver of the send is expected to
2021 * reply to the message and a buffer is provided into which
2022 * IUCV moves the reply to this message.
2023 * Input: pathid - path identification number
2024 * trgcls - specifies target class
2025 * srccls - specifies the source message class
2026 * msgtag - spcifies a tag to be associated with the message
2027 * flags1 - option for path
2028 * IPPRTY- specifies if you want to send priority message
2029 * buffer - address of array of send buffers
2030 * buflen - total length of send buffers
2031 * ansbuf - address of buffer to reply with
2032 * anslen - length of buffer to reply with
2033 * Output: msgid - specifies the message ID.
2034 * Return: b2f0_result - return code from CP
2035 * (-EINVAL) - buffer address is NULL
2038 iucv_send2way_array (__u16 pathid,
2044 iucv_array_t * buffer,
2045 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2050 iucv_debug(2, "entering");
2052 if (!buffer || !ansbuf)
2055 parm = (iparml_db *)grab_param();
2057 parm->ippathid = pathid;
2058 parm->iptrgcls = trgcls;
2059 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2060 parm->ipbfln1f = (__u32) buflen; /* length of message */
2061 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2062 parm->ipbfln2f = (__u32) anslen;
2063 parm->ipsrccls = srccls;
2064 parm->ipmsgtag = msgtag;
2065 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2066 b2f0_result = b2f0(SEND, parm);
2067 if ((!b2f0_result) && (msgid))
2068 *msgid = parm->ipmsgid;
2069 release_param(parm);
2071 iucv_debug(2, "exiting");
2076 * Name: iucv_send2way_prmmsg
2077 * Purpose: This function transmits data to another application.
2078 * Prmmsg specifies that the 8-bytes of data are to be moved
2079 * into the parameter list. This is a two-way message and the
2080 * receiver of the message is expected to reply. A buffer
2081 * is provided into which IUCV moves the reply to this
2083 * Input: pathid - path identification number
2084 * trgcls - specifies target class
2085 * srccls - specifies the source message class
2086 * msgtag - specifies a tag to be associated with the message
2087 * flags1 - option for path
2088 * IPPRTY- specifies if you want to send priority message
2089 * prmmsg - 8-bytes of data to be placed in parameter list
2090 * ansbuf - address of buffer to reply with
2091 * anslen - length of buffer to reply with
2092 * Output: msgid - specifies the message ID.
2093 * Return: b2f0_result - return code from CP
2094 * (-EINVAL) - buffer address is NULL
2097 iucv_send2way_prmmsg (__u16 pathid,
2102 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2107 iucv_debug(2, "entering");
2112 parm = (iparml_dpl *)grab_param();
2114 parm->ippathid = pathid;
2115 parm->iptrgcls = trgcls;
2116 parm->ipsrccls = srccls;
2117 parm->ipmsgtag = msgtag;
2118 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2119 parm->ipbfln2f = (__u32) anslen;
2120 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2121 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2123 b2f0_result = b2f0(SEND, parm);
2125 if ((!b2f0_result) && (msgid))
2126 *msgid = parm->ipmsgid;
2127 release_param(parm);
2129 iucv_debug(2, "exiting");
2135 * Name: iucv_send2way_prmmsg_array
2136 * Purpose: This function transmits data to another application.
2137 * Prmmsg specifies that the 8-bytes of data are to be moved
2138 * into the parameter list. This is a two-way message and the
2139 * receiver of the message is expected to reply. A buffer
2140 * is provided into which IUCV moves the reply to this
2141 * message. The contents of ansbuf is the address of the
2142 * array of addresses and lengths of discontiguous buffers
2143 * that contain the reply.
2144 * Input: pathid - path identification number
2145 * trgcls - specifies target class
2146 * srccls - specifies the source message class
2147 * msgtag - specifies a tag to be associated with the message
2148 * flags1 - option for path
2149 * IPPRTY- specifies if you want to send priority message
2150 * prmmsg - 8-bytes of data to be placed into the parameter list
2151 * ansbuf - address of buffer to reply with
2152 * anslen - length of buffer to reply with
2153 * Output: msgid - specifies the message ID.
2154 * Return: b2f0_result - return code from CP
2155 * (-EINVAL) - ansbuf address is NULL
2158 iucv_send2way_prmmsg_array (__u16 pathid,
2165 iucv_array_t * ansbuf, ulong anslen)
2170 iucv_debug(2, "entering");
2175 parm = (iparml_dpl *)grab_param();
2177 parm->ippathid = pathid;
2178 parm->iptrgcls = trgcls;
2179 parm->ipsrccls = srccls;
2180 parm->ipmsgtag = msgtag;
2181 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2182 parm->ipbfln2f = (__u32) anslen;
2183 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2184 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2185 b2f0_result = b2f0(SEND, parm);
2186 if ((!b2f0_result) && (msgid))
2187 *msgid = parm->ipmsgid;
2188 release_param(parm);
2190 iucv_debug(2, "exiting");
2195 iucv_setmask_cpuid (void *result)
2197 iparml_set_mask *parm;
2199 iucv_debug(1, "entering");
2200 parm = (iparml_set_mask *)grab_param();
2201 parm->ipmask = *((__u8*)result);
2202 *((ulong *)result) = b2f0(SETMASK, parm);
2203 release_param(parm);
2205 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2206 iucv_debug(1, "exiting");
2210 * Name: iucv_setmask
2211 * Purpose: This function enables or disables the following IUCV
2212 * external interruptions: Nonpriority and priority message
2213 * interrupts, nonpriority and priority reply interrupts.
2214 * Input: SetMaskFlag - options for interrupts
2215 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2216 * 0x40 - Priority_MessagePendingInterruptsFlag
2217 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2218 * 0x10 - Priority_MessageCompletionInterruptsFlag
2219 * 0x08 - IUCVControlInterruptsFlag
2221 * Return: b2f0_result - return code from CP
2224 iucv_setmask (int SetMaskFlag)
2232 u.param = SetMaskFlag;
2234 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2242 * @pathid: Path identification number
2243 * @user_data: 16-byte of user data
2245 * This function terminates an iucv path.
2246 * Returns: return code from CP
2249 iucv_sever(__u16 pathid, __u8 user_data[16])
2251 iparml_control *parm;
2252 ulong b2f0_result = 0;
2254 iucv_debug(1, "entering");
2255 parm = (iparml_control *)grab_param();
2257 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2258 parm->ippathid = pathid;
2260 b2f0_result = b2f0(SEVER, parm);
2263 iucv_remove_pathid(pathid);
2264 release_param(parm);
2266 iucv_debug(1, "exiting");
2271 * Interrupt Handlers
2272 *******************************************************************************/
2276 * @regs: Current registers
2279 * Handles external interrupts coming in from CP.
2280 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2283 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2285 iucv_irqdata *irqdata;
2287 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2289 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2294 memcpy(&irqdata->data, iucv_external_int_buffer,
2295 sizeof(iucv_GeneralInterrupt));
2297 spin_lock(&iucv_irq_queue_lock);
2298 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2299 spin_unlock(&iucv_irq_queue_lock);
2301 tasklet_schedule(&iucv_tasklet);
2306 * @int_buf: Pointer to copy of external interrupt buffer
2308 * The workhorse for handling interrupts queued by iucv_irq_handler().
2309 * This function is called from the bottom half iucv_tasklet_handler().
2312 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2315 struct list_head *lh;
2317 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2318 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2320 __u8 no_listener[16] = "NO LISTENER";
2322 iucv_debug(2, "entering, pathid %d, type %02X",
2323 int_buf->ippathid, int_buf->iptype);
2324 iucv_dumpit("External Interrupt Buffer:",
2325 int_buf, sizeof(iucv_GeneralInterrupt));
2327 ASCEBC (no_listener, 16);
2329 if (int_buf->iptype != 01) {
2330 if ((int_buf->ippathid) > (max_connections - 1)) {
2331 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2332 " > max_connections (%ld)\n", __FUNCTION__,
2333 int_buf->ippathid, max_connections - 1);
2335 h = iucv_pathid_table[int_buf->ippathid];
2336 interrupt = h->interrupt_table;
2337 iucv_dumpit("Handler:", h, sizeof(handler));
2341 /* end of if statement */
2342 switch (int_buf->iptype) {
2343 case 0x01: /* connection pending */
2344 if (messagesDisabled) {
2346 messagesDisabled = 0;
2348 spin_lock_irqsave(&iucv_lock, flags);
2349 list_for_each(lh, &iucv_handler_table) {
2350 h = list_entry(lh, handler, list);
2351 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2352 memcpy(temp_buff2, &(h->id.userid), 24);
2353 for (j = 0; j < 24; j++) {
2354 temp_buff1[j] &= (h->id.mask)[j];
2355 temp_buff2[j] &= (h->id.mask)[j];
2358 iucv_dumpit("temp_buff1:",
2359 temp_buff1, sizeof(temp_buff1));
2360 iucv_dumpit("temp_buff2",
2361 temp_buff2, sizeof(temp_buff2));
2363 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2366 "found a matching handler");
2371 spin_unlock_irqrestore (&iucv_lock, flags);
2373 /* ADD PATH TO PATHID TABLE */
2374 rc = iucv_add_pathid(int_buf->ippathid, h);
2376 iucv_sever (int_buf->ippathid,
2379 "add_pathid failed, rc = %d",
2382 interrupt = h->interrupt_table;
2383 if (interrupt->ConnectionPending) {
2384 EBCASC (int_buf->ipvmid, 8);
2385 interrupt->ConnectionPending(
2386 (iucv_ConnectionPending *)int_buf,
2389 iucv_sever(int_buf->ippathid,
2393 iucv_sever(int_buf->ippathid, no_listener);
2396 case 0x02: /*connection complete */
2397 if (messagesDisabled) {
2399 messagesDisabled = 0;
2402 if (interrupt->ConnectionComplete)
2404 interrupt->ConnectionComplete(
2405 (iucv_ConnectionComplete *)int_buf,
2410 "ConnectionComplete not called");
2412 iucv_sever(int_buf->ippathid, no_listener);
2415 case 0x03: /* connection severed */
2416 if (messagesDisabled) {
2418 messagesDisabled = 0;
2421 if (interrupt->ConnectionSevered)
2422 interrupt->ConnectionSevered(
2423 (iucv_ConnectionSevered *)int_buf,
2427 iucv_sever (int_buf->ippathid, no_listener);
2429 iucv_sever(int_buf->ippathid, no_listener);
2432 case 0x04: /* connection quiesced */
2433 if (messagesDisabled) {
2435 messagesDisabled = 0;
2438 if (interrupt->ConnectionQuiesced)
2439 interrupt->ConnectionQuiesced(
2440 (iucv_ConnectionQuiesced *)int_buf,
2444 "ConnectionQuiesced not called");
2448 case 0x05: /* connection resumed */
2449 if (messagesDisabled) {
2451 messagesDisabled = 0;
2454 if (interrupt->ConnectionResumed)
2455 interrupt->ConnectionResumed(
2456 (iucv_ConnectionResumed *)int_buf,
2460 "ConnectionResumed not called");
2464 case 0x06: /* priority message complete */
2465 case 0x07: /* nonpriority message complete */
2467 if (interrupt->MessageComplete)
2468 interrupt->MessageComplete(
2469 (iucv_MessageComplete *)int_buf,
2473 "MessageComplete not called");
2477 case 0x08: /* priority message pending */
2478 case 0x09: /* nonpriority message pending */
2480 if (interrupt->MessagePending)
2481 interrupt->MessagePending(
2482 (iucv_MessagePending *) int_buf,
2486 "MessagePending not called");
2489 default: /* unknown iucv type */
2490 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2495 iucv_debug(2, "exiting pathid %d, type %02X",
2496 int_buf->ippathid, int_buf->iptype);
2502 * iucv_tasklet_handler:
2504 * This function loops over the queue of irq buffers and runs iucv_do_int()
2505 * on every queue element.
2508 iucv_tasklet_handler(unsigned long ignored)
2510 struct list_head head;
2511 struct list_head *next;
2514 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2515 list_add(&head, &iucv_irq_queue);
2516 list_del_init(&iucv_irq_queue);
2517 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2520 while (next != &head) {
2521 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2524 iucv_do_int(&p->data);
2531 module_init(iucv_init);
2532 module_exit(iucv_exit);
2535 * Export all public stuff
2537 EXPORT_SYMBOL (iucv_bus);
2538 EXPORT_SYMBOL (iucv_root);
2539 EXPORT_SYMBOL (iucv_accept);
2540 EXPORT_SYMBOL (iucv_connect);
2542 EXPORT_SYMBOL (iucv_purge);
2543 EXPORT_SYMBOL (iucv_query_maxconn);
2544 EXPORT_SYMBOL (iucv_query_bufsize);
2545 EXPORT_SYMBOL (iucv_quiesce);
2547 EXPORT_SYMBOL (iucv_receive);
2549 EXPORT_SYMBOL (iucv_receive_array);
2551 EXPORT_SYMBOL (iucv_reject);
2553 EXPORT_SYMBOL (iucv_reply);
2554 EXPORT_SYMBOL (iucv_reply_array);
2555 EXPORT_SYMBOL (iucv_reply_prmmsg);
2556 EXPORT_SYMBOL (iucv_resume);
2558 EXPORT_SYMBOL (iucv_send);
2560 EXPORT_SYMBOL (iucv_send2way);
2561 EXPORT_SYMBOL (iucv_send2way_array);
2562 EXPORT_SYMBOL (iucv_send_array);
2563 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2564 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2565 EXPORT_SYMBOL (iucv_send_prmmsg);
2566 EXPORT_SYMBOL (iucv_setmask);
2568 EXPORT_SYMBOL (iucv_sever);
2569 EXPORT_SYMBOL (iucv_register_program);
2570 EXPORT_SYMBOL (iucv_unregister_program);