4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
8 * Xenia Tkatschow (xenia@us.ibm.com)
9 * 2Gb awareness and general cleanup:
10 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
14 * CP Programming Service, IBM document # SC24-5760
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
37 #include <linux/spinlock.h>
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
42 #include <linux/list.h>
43 #include <linux/errno.h>
44 #include <linux/err.h>
45 #include <linux/device.h>
46 #include <asm/atomic.h>
49 #include <asm/s390_ext.h>
50 #include <asm/ebcdic.h>
52 #include <asm/s390_rdev.h>
55 * All flags are defined in the field IPFLAGS1 of each function
56 * and can be found in CP Programming Services.
57 * IPSRCCLS - Indicates you have specified a source class
58 * IPFGMCL - Indicates you have specified a target class
59 * IPFGPID - Indicates you have specified a pathid
60 * IPFGMID - Indicates you have specified a message ID
61 * IPANSLST - Indicates that you are using an address list for
63 * IPBUFLST - Indicates that you are using an address list for
75 iucv_bus_match (struct device *dev, struct device_driver *drv)
80 struct bus_type iucv_bus = {
82 .match = iucv_bus_match,
85 struct device *iucv_root;
87 /* General IUCV interrupt structure */
95 } iucv_GeneralInterrupt;
97 static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
99 /* Spin Lock declaration */
101 static DEFINE_SPINLOCK(iucv_lock);
103 static int messagesDisabled = 0;
105 /***************INTERRUPT HANDLING ***************/
108 struct list_head queue;
109 iucv_GeneralInterrupt data;
112 static struct list_head iucv_irq_queue;
113 static DEFINE_SPINLOCK(iucv_irq_queue_lock);
116 *Internal function prototypes
118 static void iucv_tasklet_handler(unsigned long);
119 static void iucv_irq_handler(struct pt_regs *, __u16);
121 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
123 /************ FUNCTION ID'S ****************************/
127 #define DECLARE_BUFFER 12
135 #define RETRIEVE_BUFFER 2
142 * members: list - list management.
144 * userid - 8 char array of machine identification
145 * user_data - 16 char array for user identification
146 * mask - 24 char array used to compare the 2 previous
147 * interrupt_table - vector of interrupt functions.
148 * pgm_data - ulong, application data that is passed
149 * to the interrupt handlers
151 typedef struct handler_t {
152 struct list_head list;
158 iucv_interrupt_ops_t *interrupt_table;
163 * iucv_handler_table: List of registered handlers.
165 static struct list_head iucv_handler_table;
168 * iucv_pathid_table: an array of *handler pointing into
169 * iucv_handler_table for fast indexing by pathid;
171 static handler **iucv_pathid_table;
173 static unsigned long max_connections;
176 * iucv_cpuid: contains the logical cpu number of the cpu which
177 * has declared the iucv buffer by issuing DECLARE_BUFFER.
178 * If no cpu has done the initialization iucv_cpuid contains -1.
180 static int iucv_cpuid = -1;
182 * register_flag: is 0 when external interrupt has not been registered
184 static int register_flag;
186 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
187 /* Data struct 1: iparml_control
188 * Used for iucv_accept
193 * iucv_retrieve_buffer
194 * Data struct 2: iparml_dpl (data in parameter list)
195 * Used for iucv_send_prmmsg
196 * iucv_send2way_prmmsg
197 * iucv_send2way_prmmsg_array
199 * Data struct 3: iparml_db (data in a buffer)
200 * Used for iucv_receive
208 * iucv_send2way_array
209 * iucv_declare_buffer
210 * Data struct 4: iparml_purge
211 * Used for iucv_purge
213 * Data struct 5: iparml_set_mask
214 * Used for iucv_set_mask
279 iparml_control p_ctrl;
282 iparml_purge p_purge;
283 iparml_set_mask p_set_mask;
287 } __attribute__ ((aligned(8))) iucv_param;
288 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
290 static iucv_param * iucv_param_pool;
292 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
293 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
294 MODULE_LICENSE("GPL");
298 *******************************************************************************/
302 static int debuglevel = 0;
304 module_param(debuglevel, int, 0);
305 MODULE_PARM_DESC(debuglevel,
306 "Specifies the debug level (0=off ... 3=all)");
309 iucv_dumpit(char *title, void *buf, int len)
312 __u8 *p = (__u8 *)buf;
317 printk(KERN_DEBUG "%s\n", title);
319 for (i = 0; i < len; i++) {
320 if (!(i % 16) && i != 0)
322 else if (!(i % 4) && i != 0)
324 printk("%02X", *p++);
330 #define iucv_debug(lvl, fmt, args...) \
332 if (debuglevel >= lvl) \
333 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
338 #define iucv_debug(lvl, fmt, args...) do { } while (0)
339 #define iucv_dumpit(title, buf, len) do { } while (0)
345 *******************************************************************************/
353 printk(KERN_INFO "IUCV lowlevel driver initialized\n");
357 * iucv_init - Initialization
359 * Allocates and initializes various data structures.
366 if (iucv_external_int_buffer)
369 if (!MACHINE_IS_VM) {
370 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
371 return -EPROTONOSUPPORT;
374 ret = bus_register(&iucv_bus);
376 printk(KERN_ERR "IUCV: failed to register bus.\n");
380 iucv_root = s390_root_dev_register("iucv");
381 if (IS_ERR(iucv_root)) {
382 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
383 bus_unregister(&iucv_bus);
384 return PTR_ERR(iucv_root);
387 /* Note: GFP_DMA used used to get memory below 2G */
388 iucv_external_int_buffer = kzalloc(sizeof(iucv_GeneralInterrupt),
390 if (!iucv_external_int_buffer) {
392 "%s: Could not allocate external interrupt buffer\n",
394 s390_root_dev_unregister(iucv_root);
395 bus_unregister(&iucv_bus);
399 /* Initialize parameter pool */
400 iucv_param_pool = kzalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
402 if (!iucv_param_pool) {
403 printk(KERN_WARNING "%s: Could not allocate param pool\n",
405 kfree(iucv_external_int_buffer);
406 iucv_external_int_buffer = NULL;
407 s390_root_dev_unregister(iucv_root);
408 bus_unregister(&iucv_bus);
412 /* Initialize irq queue */
413 INIT_LIST_HEAD(&iucv_irq_queue);
415 /* Initialize handler table */
416 INIT_LIST_HEAD(&iucv_handler_table);
423 * iucv_exit - De-Initialization
425 * Frees everything allocated from iucv_init.
427 static int iucv_retrieve_buffer (void);
432 iucv_retrieve_buffer();
433 kfree(iucv_external_int_buffer);
434 iucv_external_int_buffer = NULL;
435 kfree(iucv_param_pool);
436 iucv_param_pool = NULL;
437 s390_root_dev_unregister(iucv_root);
438 bus_unregister(&iucv_bus);
439 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
443 * grab_param: - Get a parameter buffer from the pre-allocated pool.
445 * This function searches for an unused element in the pre-allocated pool
446 * of parameter buffers. If one is found, it marks it "in use" and returns
447 * a pointer to it. The calling function is responsible for releasing it
448 * when it has finished its usage.
450 * Returns: A pointer to iucv_param.
452 static __inline__ iucv_param *
458 ptr = iucv_param_pool + hint;
461 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
462 ptr = iucv_param_pool;
463 } while (atomic_cmpxchg(&ptr->in_use, 0, 1) != 0);
464 hint = ptr - iucv_param_pool;
466 memset(&ptr->param, 0, sizeof(ptr->param));
471 * release_param - Release a parameter buffer.
472 * @p: A pointer to a struct iucv_param, previously obtained by calling
475 * This function marks the specified parameter buffer "unused".
477 static __inline__ void
478 release_param(void *p)
480 atomic_set(&((iucv_param *)p)->in_use, 0);
484 * iucv_add_handler: - Add a new handler
485 * @new_handler: handle that is being entered into chain.
487 * Places new handle on iucv_handler_table, if identical handler is not
490 * Returns: 0 on success, !0 on failure (handler already in chain).
493 iucv_add_handler (handler *new)
497 iucv_debug(1, "entering");
498 iucv_dumpit("handler:", new, sizeof(handler));
500 spin_lock_irqsave (&iucv_lock, flags);
501 if (!list_empty(&iucv_handler_table)) {
502 struct list_head *lh;
505 * Search list for handler with identical id. If one
506 * is found, the new handler is _not_ added.
508 list_for_each(lh, &iucv_handler_table) {
509 handler *h = list_entry(lh, handler, list);
510 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
511 iucv_debug(1, "ret 1");
512 spin_unlock_irqrestore (&iucv_lock, flags);
518 * If we get here, no handler was found.
520 INIT_LIST_HEAD(&new->list);
521 list_add(&new->list, &iucv_handler_table);
522 spin_unlock_irqrestore (&iucv_lock, flags);
524 iucv_debug(1, "exiting");
530 * @code: identifier of IUCV call to CP.
531 * @parm: pointer to 40 byte iparml area passed to CP
533 * Calls CP to execute IUCV commands.
535 * Returns: return code from CP's IUCV call
537 static __inline__ ulong
538 b2f0(__u32 code, void *parm)
540 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
547 : "d" (code), "a" (parm)
551 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
553 return (unsigned long)*((__u8 *)(parm + 3));
557 * Name: iucv_add_pathid
558 * Purpose: Adds a path id to the system.
559 * Input: pathid - pathid that is going to be entered into system
560 * handle - address of handler that the pathid will be associated
562 * pgm_data - token passed in by application.
563 * Output: 0: successful addition of pathid
564 * - EINVAL - pathid entry is being used by another application
565 * - ENOMEM - storage allocation for a new pathid table failed
568 __iucv_add_pathid(__u16 pathid, handler *handler)
571 iucv_debug(1, "entering");
573 iucv_debug(1, "handler is pointing to %p", handler);
575 if (pathid > (max_connections - 1))
578 if (iucv_pathid_table[pathid]) {
579 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
581 "%s: Pathid being used, error.\n", __FUNCTION__);
584 iucv_pathid_table[pathid] = handler;
586 iucv_debug(1, "exiting");
588 } /* end of add_pathid function */
591 iucv_add_pathid(__u16 pathid, handler *handler)
596 spin_lock_irqsave (&iucv_lock, flags);
597 rc = __iucv_add_pathid(pathid, handler);
598 spin_unlock_irqrestore (&iucv_lock, flags);
603 iucv_remove_pathid(__u16 pathid)
607 if (pathid > (max_connections - 1))
610 spin_lock_irqsave (&iucv_lock, flags);
611 iucv_pathid_table[pathid] = NULL;
612 spin_unlock_irqrestore (&iucv_lock, flags);
616 * iucv_declare_buffer_cpuid
617 * Register at VM for subsequent IUCV operations. This is executed
618 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
621 iucv_declare_buffer_cpuid (void *result)
625 parm = (iparml_db *)grab_param();
626 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
627 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
628 *((ulong *)result) = parm->iprcode;
633 * iucv_retrieve_buffer_cpuid:
634 * Unregister IUCV usage at VM. This is always executed on the same
635 * cpu that registered the buffer to VM.
636 * Called from iucv_retrieve_buffer().
639 iucv_retrieve_buffer_cpuid (void *cpu)
641 iparml_control *parm;
643 parm = (iparml_control *)grab_param();
644 b2f0(RETRIEVE_BUFFER, parm);
649 * Name: iucv_declare_buffer
650 * Purpose: Specifies the guests real address of an external
653 * Output: iprcode - return code from b2f0 call
656 iucv_declare_buffer (void)
661 iucv_debug(1, "entering");
662 b2f0_result = -ENODEV;
663 spin_lock_irqsave (&iucv_lock, flags);
664 if (iucv_cpuid == -1) {
665 /* Reserve any cpu for use by iucv. */
666 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
667 spin_unlock_irqrestore (&iucv_lock, flags);
668 smp_call_function_on(iucv_declare_buffer_cpuid,
669 &b2f0_result, 0, 1, iucv_cpuid);
671 smp_put_cpu(iucv_cpuid);
674 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
676 spin_unlock_irqrestore (&iucv_lock, flags);
679 iucv_debug(1, "exiting");
684 * iucv_retrieve_buffer:
686 * Terminates all use of IUCV.
687 * Returns: return code from CP
690 iucv_retrieve_buffer (void)
692 iucv_debug(1, "entering");
693 if (iucv_cpuid != -1) {
694 smp_call_function_on(iucv_retrieve_buffer_cpuid,
695 NULL, 0, 1, iucv_cpuid);
696 /* Release the cpu reserved by iucv_declare_buffer. */
697 smp_put_cpu(iucv_cpuid);
700 iucv_debug(1, "exiting");
705 * iucv_remove_handler:
706 * @users_handler: handler to be removed
708 * Remove handler when application unregisters.
711 iucv_remove_handler(handler *handler)
715 if ((!iucv_pathid_table) || (!handler))
718 iucv_debug(1, "entering");
720 spin_lock_irqsave (&iucv_lock, flags);
721 list_del(&handler->list);
722 if (list_empty(&iucv_handler_table)) {
724 unregister_external_interrupt(0x4000, iucv_irq_handler);
728 spin_unlock_irqrestore (&iucv_lock, flags);
730 iucv_debug(1, "exiting");
735 * iucv_register_program:
736 * @pgmname: user identification
737 * @userid: machine identification
738 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
739 * used to determine who is given control.
740 * @ops: Address of interrupt handler table.
741 * @pgm_data: Application data to be passed to interrupt handlers.
743 * Registers an application with IUCV.
745 * The address of handler, or NULL on failure.
747 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
749 * If pgmmask is NULL, the internal mask is set to all 0xff's
750 * When userid is NULL, the first 8 bytes of the internal mask are forced
752 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
753 * are forced to 0x00 and the last 16 bytes to 0xff.
757 iucv_register_program (__u8 pgmname[16],
760 iucv_interrupt_ops_t * ops, void *pgm_data)
762 ulong rc = 0; /* return code from function calls */
763 handler *new_handler;
765 iucv_debug(1, "entering");
768 /* interrupt table is not defined */
769 printk(KERN_WARNING "%s: Interrupt table is not defined, "
770 "exiting\n", __FUNCTION__);
774 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
778 /* Allocate handler entry */
779 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
780 if (new_handler == NULL) {
781 printk(KERN_WARNING "%s: storage allocation for new handler "
782 "failed.\n", __FUNCTION__);
786 if (!iucv_pathid_table) {
792 max_connections = iucv_query_maxconn();
793 iucv_pathid_table = kcalloc(max_connections, sizeof(handler *),
795 if (iucv_pathid_table == NULL) {
796 printk(KERN_WARNING "%s: iucv_pathid_table storage "
797 "allocation failed\n", __FUNCTION__);
802 memset(new_handler, 0, sizeof (handler));
803 memcpy(new_handler->id.user_data, pgmname,
804 sizeof (new_handler->id.user_data));
806 memcpy (new_handler->id.userid, userid,
807 sizeof (new_handler->id.userid));
808 ASCEBC (new_handler->id.userid,
809 sizeof (new_handler->id.userid));
810 EBC_TOUPPER (new_handler->id.userid,
811 sizeof (new_handler->id.userid));
814 memcpy (new_handler->id.mask, pgmmask,
815 sizeof (new_handler->id.mask));
817 memset (new_handler->id.mask, 0xFF,
818 sizeof (new_handler->id.mask));
822 memcpy (new_handler->id.mask, pgmmask,
823 sizeof (new_handler->id.mask));
825 memset (new_handler->id.mask, 0xFF,
826 sizeof (new_handler->id.mask));
828 memset (new_handler->id.userid, 0x00,
829 sizeof (new_handler->id.userid));
831 /* fill in the rest of handler */
832 new_handler->pgm_data = pgm_data;
833 new_handler->interrupt_table = ops;
836 * Check if someone else is registered with same pgmname, userid
837 * and mask. If someone is already registered with same pgmname,
838 * userid and mask, registration will fail and NULL will be returned
839 * to the application.
840 * If identical handler not found, then handler is added to list.
842 rc = iucv_add_handler(new_handler);
844 printk(KERN_WARNING "%s: Someone already registered with same "
845 "pgmname, userid, pgmmask\n", __FUNCTION__);
850 rc = iucv_declare_buffer();
852 char *err = "Unknown";
853 iucv_remove_handler(new_handler);
857 err = "Directory error";
860 err = "Invalid length";
863 err = "Buffer already exists";
866 err = "Buffer overlap";
869 err = "Paging or storage error";
872 printk(KERN_WARNING "%s: iucv_declare_buffer "
873 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
876 if (!register_flag) {
877 /* request the 0x4000 external interrupt */
878 rc = register_external_interrupt (0x4000, iucv_irq_handler);
880 iucv_remove_handler(new_handler);
882 printk(KERN_WARNING "%s: "
883 "register_external_interrupt returned %ld\n",
890 iucv_debug(1, "exiting");
892 } /* end of register function */
895 * iucv_unregister_program:
896 * @handle: address of handler
898 * Unregister application with IUCV.
900 * 0 on success, -EINVAL, if specified handle is invalid.
904 iucv_unregister_program (iucv_handle_t handle)
907 struct list_head *lh;
911 iucv_debug(1, "entering");
912 iucv_debug(1, "address of handler is %p", h);
914 /* Checking if handle is valid */
915 spin_lock_irqsave (&iucv_lock, flags);
916 list_for_each(lh, &iucv_handler_table) {
917 if ((handler *)handle == list_entry(lh, handler, list)) {
918 h = (handler *)handle;
923 spin_unlock_irqrestore (&iucv_lock, flags);
926 "%s: Handler not found in iucv_handler_table.\n",
930 "%s: NULL handle passed by application.\n",
936 * First, walk thru iucv_pathid_table and sever any pathid which is
937 * still pointing to the handler to be removed.
939 for (i = 0; i < max_connections; i++)
940 if (iucv_pathid_table[i] == h) {
941 spin_unlock_irqrestore (&iucv_lock, flags);
942 iucv_sever(i, h->id.user_data);
943 spin_lock_irqsave(&iucv_lock, flags);
945 spin_unlock_irqrestore (&iucv_lock, flags);
947 iucv_remove_handler(h);
950 iucv_debug(1, "exiting");
956 * @pathid: Path identification number
957 * @msglim_reqstd: The number of outstanding messages requested.
958 * @user_data: Data specified by the iucv_connect function.
959 * @flags1: Contains options for this path.
960 * - IPPRTY (0x20) Specifies if you want to send priority message.
961 * - IPRMDATA (0x80) Specifies whether your program can handle a message
962 * in the parameter list.
963 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
965 * @handle: Address of handler.
966 * @pgm_data: Application data passed to interrupt handlers.
967 * @flags1_out: Pointer to an int. If not NULL, on return the options for
968 * the path are stored at the given location:
969 * - IPPRTY (0x20) Indicates you may send a priority message.
970 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
971 * number of outstanding messages is stored at the given
974 * This function is issued after the user receives a Connection Pending external
975 * interrupt and now wishes to complete the IUCV communication path.
977 * return code from CP
980 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
981 __u8 user_data[16], int flags1,
982 iucv_handle_t handle, void *pgm_data,
983 int *flags1_out, __u16 * msglim)
985 ulong b2f0_result = 0;
987 struct list_head *lh;
989 iparml_control *parm;
991 iucv_debug(1, "entering");
992 iucv_debug(1, "pathid = %d", pathid);
994 /* Checking if handle is valid */
995 spin_lock_irqsave (&iucv_lock, flags);
996 list_for_each(lh, &iucv_handler_table) {
997 if ((handler *)handle == list_entry(lh, handler, list)) {
998 h = (handler *)handle;
1002 spin_unlock_irqrestore (&iucv_lock, flags);
1007 "%s: Handler not found in iucv_handler_table.\n",
1011 "%s: NULL handle passed by application.\n",
1016 parm = (iparml_control *)grab_param();
1018 parm->ippathid = pathid;
1019 parm->ipmsglim = msglim_reqstd;
1021 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1023 parm->ipflags1 = (__u8)flags1;
1024 b2f0_result = b2f0(ACCEPT, parm);
1028 *msglim = parm->ipmsglim;
1030 h->pgm_data = pgm_data;
1032 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1034 release_param(parm);
1036 iucv_debug(1, "exiting");
1042 * @pathid: Path identification number
1043 * @msglim_reqstd: Number of outstanding messages requested
1044 * @user_data: 16-byte user data
1045 * @userid: 8-byte of user identification
1046 * @system_name: 8-byte identifying the system name
1047 * @flags1: Specifies options for this path:
1048 * - IPPRTY (0x20) Specifies if you want to send priority message.
1049 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1050 * in the parameter list.
1051 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1053 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1054 * local system. If local is specified then target class
1055 * cannot be specified.
1056 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1057 * the path are stored at the given location:
1058 * - IPPRTY (0x20) Indicates you may send a priority message.
1059 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1060 * number of outstanding messages is stored at the given
1062 * @handle: Address of handler.
1063 * @pgm_data: Application data to be passed to interrupt handlers.
1065 * This function establishes an IUCV path. Although the connect may complete
1066 * successfully, you are not able to use the path until you receive an IUCV
1067 * Connection Complete external interrupt.
1068 * Returns: return code from CP, or one of the following
1070 * - return code from iucv_declare_buffer
1071 * - EINVAL - invalid handle passed by application
1072 * - EINVAL - pathid address is NULL
1073 * - ENOMEM - pathid table storage allocation failed
1074 * - return code from internal function add_pathid
1077 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1078 __u8 user_data[16], __u8 userid[8],
1079 __u8 system_name[8], int flags1,
1080 int *flags1_out, __u16 * msglim,
1081 iucv_handle_t handle, void *pgm_data)
1083 iparml_control *parm;
1084 iparml_control local_parm;
1085 struct list_head *lh;
1086 ulong b2f0_result = 0;
1088 int add_pathid_result = 0;
1090 __u8 no_memory[16] = "NO MEMORY";
1092 iucv_debug(1, "entering");
1094 /* Checking if handle is valid */
1095 spin_lock_irqsave (&iucv_lock, flags);
1096 list_for_each(lh, &iucv_handler_table) {
1097 if ((handler *)handle == list_entry(lh, handler, list)) {
1098 h = (handler *)handle;
1102 spin_unlock_irqrestore (&iucv_lock, flags);
1107 "%s: Handler not found in iucv_handler_table.\n",
1111 "%s: NULL handle passed by application.\n",
1116 if (pathid == NULL) {
1117 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1122 parm = (iparml_control *)grab_param();
1124 parm->ipmsglim = msglim_reqstd;
1127 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1130 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1131 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1132 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1136 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1137 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1138 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1141 /* In order to establish an IUCV connection, the procedure is:
1144 * take the ippathid from the b2f0 call
1145 * register the handler to the ippathid
1147 * Unfortunately, the ConnectionEstablished message gets sent after the
1148 * b2f0(CONNECT) call but before the register is handled.
1150 * In order for this race condition to be eliminated, the IUCV Control
1151 * Interrupts must be disabled for the above procedure.
1153 * David Kennedy <dkennedy@linuxcare.com>
1156 /* Enable everything but IUCV Control messages */
1157 iucv_setmask(~(AllInterrupts));
1158 messagesDisabled = 1;
1160 spin_lock_irqsave (&iucv_lock, flags);
1161 parm->ipflags1 = (__u8)flags1;
1162 b2f0_result = b2f0(CONNECT, parm);
1163 memcpy(&local_parm, parm, sizeof(local_parm));
1164 release_param(parm);
1167 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1168 spin_unlock_irqrestore (&iucv_lock, flags);
1172 messagesDisabled = 0;
1176 *pathid = parm->ippathid;
1178 /* Enable everything again */
1179 iucv_setmask(IUCVControlInterruptsFlag);
1182 *msglim = parm->ipmsglim;
1184 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1186 if (add_pathid_result) {
1187 iucv_sever(*pathid, no_memory);
1188 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1189 " %d\n", __FUNCTION__, add_pathid_result);
1190 return(add_pathid_result);
1193 iucv_debug(1, "exiting");
1199 * @pathid: Path identification number
1200 * @msgid: Message ID of message to purge.
1201 * @srccls: Message class of the message to purge.
1202 * @audit: Pointer to an __u32. If not NULL, on return, information about
1203 * asynchronous errors that may have affected the normal completion
1204 * of this message ist stored at the given location.
1206 * Cancels a message you have sent.
1207 * Returns: return code from CP
1210 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1213 ulong b2f0_result = 0;
1215 iucv_debug(1, "entering");
1216 iucv_debug(1, "pathid = %d", pathid);
1218 parm = (iparml_purge *)grab_param();
1220 parm->ipmsgid = msgid;
1221 parm->ippathid = pathid;
1222 parm->ipsrccls = srccls;
1223 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1224 b2f0_result = b2f0(PURGE, parm);
1226 if (!b2f0_result && audit) {
1227 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1228 /* parm->ipaudit has only 3 bytes */
1232 release_param(parm);
1234 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1235 iucv_debug(1, "exiting");
1240 * iucv_query_generic:
1241 * @want_maxconn: Flag, describing which value is to be returned.
1243 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1245 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1246 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1249 iucv_query_generic(int want_maxconn)
1251 iparml_purge *parm = (iparml_purge *)grab_param();
1252 int bufsize, maxconn;
1256 * Call b2f0 and store R0 (max buffer size),
1257 * R1 (max connections) and CC.
1262 ".long 0xb2f01000\n\t"
1267 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1268 : "d" (QUERY), "a" (parm)
1271 release_param(parm);
1281 * iucv_query_maxconn:
1283 * Determines the maximum number of connections thay may be established.
1285 * Returns: Maximum number of connections that can be.
1288 iucv_query_maxconn(void)
1290 return iucv_query_generic(1);
1294 * iucv_query_bufsize:
1296 * Determines the size of the external interrupt buffer.
1298 * Returns: Size of external interrupt buffer.
1301 iucv_query_bufsize (void)
1303 return iucv_query_generic(0);
1308 * @pathid: Path identification number
1309 * @user_data: 16-byte user data
1311 * Temporarily suspends incoming messages on an IUCV path.
1312 * You can later reactivate the path by invoking the iucv_resume function.
1313 * Returns: return code from CP
1316 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1318 iparml_control *parm;
1319 ulong b2f0_result = 0;
1321 iucv_debug(1, "entering");
1322 iucv_debug(1, "pathid = %d", pathid);
1324 parm = (iparml_control *)grab_param();
1326 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1327 parm->ippathid = pathid;
1329 b2f0_result = b2f0(QUIESCE, parm);
1330 release_param(parm);
1332 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1333 iucv_debug(1, "exiting");
1340 * @pathid: Path identification number.
1341 * @buffer: Address of buffer to receive. Must be below 2G.
1342 * @buflen: Length of buffer to receive.
1343 * @msgid: Specifies the message ID.
1344 * @trgcls: Specifies target class.
1345 * @flags1_out: Receives options for path on return.
1346 * - IPNORPY (0x10) Specifies whether a reply is required
1347 * - IPPRTY (0x20) Specifies if you want to send priority message
1348 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1349 * @residual_buffer: Receives the address of buffer updated by the number
1350 * of bytes you have received on return.
1351 * @residual_length: On return, receives one of the following values:
1352 * - 0 If the receive buffer is the same length as
1354 * - Remaining bytes in buffer If the receive buffer is longer than the
1356 * - Remaining bytes in message If the receive buffer is shorter than the
1359 * This function receives messages that are being sent to you over established
1361 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1362 * than the message, always 5
1363 * -EINVAL - buffer address is pointing to NULL
1366 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1367 void *buffer, ulong buflen,
1368 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1372 int moved = 0; /* number of bytes moved from parmlist to buffer */
1374 iucv_debug(2, "entering");
1379 parm = (iparml_db *)grab_param();
1381 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1382 parm->ipbfln1f = (__u32) ((ulong) buflen);
1383 parm->ipmsgid = msgid;
1384 parm->ippathid = pathid;
1385 parm->iptrgcls = trgcls;
1386 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1388 b2f0_result = b2f0(RECEIVE, parm);
1390 if (!b2f0_result || b2f0_result == 5) {
1392 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1393 *flags1_out = (parm->ipflags1 & (~0x07));
1394 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1397 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1398 if (residual_length)
1399 *residual_length = parm->ipbfln1f;
1401 if (residual_buffer)
1402 *residual_buffer = parm->ipbfadr1;
1404 moved = min_t (unsigned long, buflen, 8);
1406 memcpy ((char *) buffer,
1407 (char *) &parm->ipbfadr1, moved);
1412 if (residual_length)
1413 *residual_length = abs (buflen - 8);
1415 if (residual_buffer)
1416 *residual_buffer = (ulong) (buffer + moved);
1419 release_param(parm);
1421 iucv_debug(2, "exiting");
1426 * Name: iucv_receive_array
1427 * Purpose: This function receives messages that are being sent to you
1428 * over established paths.
1429 * Input: pathid - path identification number
1430 * buffer - address of array of buffers
1431 * buflen - total length of buffers
1432 * msgid - specifies the message ID.
1433 * trgcls - specifies target class
1435 * flags1_out: Options for path.
1436 * IPNORPY - 0x10 specifies whether a reply is required
1437 * IPPRTY - 0x20 specifies if you want to send priority message
1438 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1439 * residual_buffer - address points to the current list entry IUCV
1442 * Contains one of the following values, if the receive buffer is:
1443 * The same length as the message, this field is zero.
1444 * Longer than the message, this field contains the number of
1445 * bytes remaining in the buffer.
1446 * Shorter than the message, this field contains the residual
1447 * count (that is, the number of bytes remaining in the
1448 * message that does not fit into the buffer. In this case
1450 * Return: b2f0_result - return code from CP
1451 * (-EINVAL) - buffer address is NULL
1454 iucv_receive_array (__u16 pathid,
1455 __u32 msgid, __u32 trgcls,
1456 iucv_array_t * buffer, ulong buflen,
1458 ulong * residual_buffer, ulong * residual_length)
1462 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1464 iucv_debug(2, "entering");
1469 parm = (iparml_db *)grab_param();
1471 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1472 parm->ipbfln1f = (__u32) buflen;
1473 parm->ipmsgid = msgid;
1474 parm->ippathid = pathid;
1475 parm->iptrgcls = trgcls;
1476 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1478 b2f0_result = b2f0(RECEIVE, parm);
1480 if (!b2f0_result || b2f0_result == 5) {
1483 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1484 *flags1_out = (parm->ipflags1 & (~0x07));
1485 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1488 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1490 if (residual_length)
1491 *residual_length = parm->ipbfln1f;
1493 if (residual_buffer)
1494 *residual_buffer = parm->ipbfadr1;
1497 /* copy msg from parmlist to users array. */
1499 while ((moved < 8) && (moved < buflen)) {
1501 min_t (unsigned int,
1502 (buffer + i)->length, need_to_move);
1504 memcpy ((char *)((ulong)((buffer + i)->address)),
1505 ((char *) &parm->ipbfadr1) + moved,
1509 need_to_move -= dyn_len;
1511 (buffer + i)->address =
1513 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1516 (buffer + i)->length -= dyn_len;
1520 if (need_to_move) /* buflen < 8 bytes */
1523 if (residual_length)
1524 *residual_length = abs (buflen - 8);
1526 if (residual_buffer) {
1528 *residual_buffer = (ulong) buffer;
1531 (ulong) (buffer + (i - 1));
1536 release_param(parm);
1538 iucv_debug(2, "exiting");
1544 * @pathid: Path identification number.
1545 * @msgid: Message ID of the message to reject.
1546 * @trgcls: Target class of the message to reject.
1547 * Returns: return code from CP
1549 * Refuses a specified message. Between the time you are notified of a
1550 * message and the time that you complete the message, the message may
1554 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1557 ulong b2f0_result = 0;
1559 iucv_debug(1, "entering");
1560 iucv_debug(1, "pathid = %d", pathid);
1562 parm = (iparml_db *)grab_param();
1564 parm->ippathid = pathid;
1565 parm->ipmsgid = msgid;
1566 parm->iptrgcls = trgcls;
1567 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1569 b2f0_result = b2f0(REJECT, parm);
1570 release_param(parm);
1572 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1573 iucv_debug(1, "exiting");
1580 * Purpose: This function responds to the two-way messages that you
1581 * receive. You must identify completely the message to
1582 * which you wish to reply. ie, pathid, msgid, and trgcls.
1583 * Input: pathid - path identification number
1584 * msgid - specifies the message ID.
1585 * trgcls - specifies target class
1586 * flags1 - option for path
1587 * IPPRTY- 0x20 - specifies if you want to send priority message
1588 * buffer - address of reply buffer
1589 * buflen - length of reply buffer
1590 * Output: ipbfadr2 - Address of buffer updated by the number
1591 * of bytes you have moved.
1592 * ipbfln2f - Contains one of the following values:
1593 * If the answer buffer is the same length as the reply, this field
1595 * If the answer buffer is longer than the reply, this field contains
1596 * the number of bytes remaining in the buffer.
1597 * If the answer buffer is shorter than the reply, this field contains
1598 * a residual count (that is, the number of bytes remianing in the
1599 * reply that does not fit into the buffer. In this
1600 * case b2f0_result = 5.
1601 * Return: b2f0_result - return code from CP
1602 * (-EINVAL) - buffer address is NULL
1605 iucv_reply (__u16 pathid,
1606 __u32 msgid, __u32 trgcls,
1608 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1613 iucv_debug(2, "entering");
1618 parm = (iparml_db *)grab_param();
1620 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1621 parm->ipbfln2f = (__u32) buflen; /* length of message */
1622 parm->ippathid = pathid;
1623 parm->ipmsgid = msgid;
1624 parm->iptrgcls = trgcls;
1625 parm->ipflags1 = (__u8) flags1; /* priority message */
1627 b2f0_result = b2f0(REPLY, parm);
1629 if ((!b2f0_result) || (b2f0_result == 5)) {
1631 *ipbfadr2 = parm->ipbfadr2;
1633 *ipbfln2f = parm->ipbfln2f;
1635 release_param(parm);
1637 iucv_debug(2, "exiting");
1643 * Name: iucv_reply_array
1644 * Purpose: This function responds to the two-way messages that you
1645 * receive. You must identify completely the message to
1646 * which you wish to reply. ie, pathid, msgid, and trgcls.
1647 * The array identifies a list of addresses and lengths of
1648 * discontiguous buffers that contains the reply data.
1649 * Input: pathid - path identification number
1650 * msgid - specifies the message ID.
1651 * trgcls - specifies target class
1652 * flags1 - option for path
1653 * IPPRTY- specifies if you want to send priority message
1654 * buffer - address of array of reply buffers
1655 * buflen - total length of reply buffers
1656 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1657 * ipbfln2f - Contains one of the following values:
1658 * If the answer buffer is the same length as the reply, this field
1660 * If the answer buffer is longer than the reply, this field contains
1661 * the number of bytes remaining in the buffer.
1662 * If the answer buffer is shorter than the reply, this field contains
1663 * a residual count (that is, the number of bytes remianing in the
1664 * reply that does not fit into the buffer. In this
1665 * case b2f0_result = 5.
1666 * Return: b2f0_result - return code from CP
1667 * (-EINVAL) - buffer address is NULL
1670 iucv_reply_array (__u16 pathid,
1671 __u32 msgid, __u32 trgcls,
1673 iucv_array_t * buffer,
1674 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1679 iucv_debug(2, "entering");
1684 parm = (iparml_db *)grab_param();
1686 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1687 parm->ipbfln2f = buflen; /* length of message */
1688 parm->ippathid = pathid;
1689 parm->ipmsgid = msgid;
1690 parm->iptrgcls = trgcls;
1691 parm->ipflags1 = (IPANSLST | flags1);
1693 b2f0_result = b2f0(REPLY, parm);
1695 if ((!b2f0_result) || (b2f0_result == 5)) {
1698 *ipbfadr2 = parm->ipbfadr2;
1700 *ipbfln2f = parm->ipbfln2f;
1702 release_param(parm);
1704 iucv_debug(2, "exiting");
1710 * Name: iucv_reply_prmmsg
1711 * Purpose: This function responds to the two-way messages that you
1712 * receive. You must identify completely the message to
1713 * which you wish to reply. ie, pathid, msgid, and trgcls.
1714 * Prmmsg signifies the data is moved into the
1716 * Input: pathid - path identification number
1717 * msgid - specifies the message ID.
1718 * trgcls - specifies target class
1719 * flags1 - option for path
1720 * IPPRTY- specifies if you want to send priority message
1721 * prmmsg - 8-bytes of data to be placed into the parameter
1724 * Return: b2f0_result - return code from CP
1727 iucv_reply_prmmsg (__u16 pathid,
1728 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1733 iucv_debug(2, "entering");
1735 parm = (iparml_dpl *)grab_param();
1737 parm->ippathid = pathid;
1738 parm->ipmsgid = msgid;
1739 parm->iptrgcls = trgcls;
1740 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1741 parm->ipflags1 = (IPRMDATA | flags1);
1743 b2f0_result = b2f0(REPLY, parm);
1744 release_param(parm);
1746 iucv_debug(2, "exiting");
1753 * @pathid: Path identification number
1754 * @user_data: 16-byte of user data
1756 * This function restores communication over a quiesced path.
1757 * Returns: return code from CP
1760 iucv_resume (__u16 pathid, __u8 user_data[16])
1762 iparml_control *parm;
1763 ulong b2f0_result = 0;
1765 iucv_debug(1, "entering");
1766 iucv_debug(1, "pathid = %d", pathid);
1768 parm = (iparml_control *)grab_param();
1770 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1771 parm->ippathid = pathid;
1773 b2f0_result = b2f0(RESUME, parm);
1774 release_param(parm);
1776 iucv_debug(1, "exiting");
1783 * Purpose: sends messages
1784 * Input: pathid - ushort, pathid
1785 * msgid - ulong *, id of message returned to caller
1786 * trgcls - ulong, target message class
1787 * srccls - ulong, source message class
1788 * msgtag - ulong, message tag
1789 * flags1 - Contains options for this path.
1790 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1791 * buffer - pointer to buffer
1792 * buflen - ulong, length of buffer
1793 * Output: b2f0_result - return code from b2f0 call
1794 * msgid - returns message id
1797 iucv_send (__u16 pathid, __u32 * msgid,
1798 __u32 trgcls, __u32 srccls,
1799 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1804 iucv_debug(2, "entering");
1809 parm = (iparml_db *)grab_param();
1811 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1812 parm->ippathid = pathid;
1813 parm->iptrgcls = trgcls;
1814 parm->ipbfln1f = (__u32) buflen; /* length of message */
1815 parm->ipsrccls = srccls;
1816 parm->ipmsgtag = msgtag;
1817 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1819 b2f0_result = b2f0(SEND, parm);
1821 if ((!b2f0_result) && (msgid))
1822 *msgid = parm->ipmsgid;
1823 release_param(parm);
1825 iucv_debug(2, "exiting");
1831 * Name: iucv_send_array
1832 * Purpose: This function transmits data to another application.
1833 * The contents of buffer is the address of the array of
1834 * addresses and lengths of discontiguous buffers that hold
1835 * the message text. This is a one-way message and the
1836 * receiver will not reply to the message.
1837 * Input: pathid - path identification number
1838 * trgcls - specifies target class
1839 * srccls - specifies the source message class
1840 * msgtag - specifies a tag to be associated witht the message
1841 * flags1 - option for path
1842 * IPPRTY- specifies if you want to send priority message
1843 * buffer - address of array of send buffers
1844 * buflen - total length of send buffers
1845 * Output: msgid - specifies the message ID.
1846 * Return: b2f0_result - return code from CP
1847 * (-EINVAL) - buffer address is NULL
1850 iucv_send_array (__u16 pathid,
1854 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1859 iucv_debug(2, "entering");
1864 parm = (iparml_db *)grab_param();
1866 parm->ippathid = pathid;
1867 parm->iptrgcls = trgcls;
1868 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1869 parm->ipbfln1f = (__u32) buflen; /* length of message */
1870 parm->ipsrccls = srccls;
1871 parm->ipmsgtag = msgtag;
1872 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1873 b2f0_result = b2f0(SEND, parm);
1875 if ((!b2f0_result) && (msgid))
1876 *msgid = parm->ipmsgid;
1877 release_param(parm);
1879 iucv_debug(2, "exiting");
1884 * Name: iucv_send_prmmsg
1885 * Purpose: This function transmits data to another application.
1886 * Prmmsg specifies that the 8-bytes of data are to be moved
1887 * into the parameter list. This is a one-way message and the
1888 * receiver will not reply to the message.
1889 * Input: pathid - path identification number
1890 * trgcls - specifies target class
1891 * srccls - specifies the source message class
1892 * msgtag - specifies a tag to be associated with the message
1893 * flags1 - option for path
1894 * IPPRTY- specifies if you want to send priority message
1895 * prmmsg - 8-bytes of data to be placed into parameter list
1896 * Output: msgid - specifies the message ID.
1897 * Return: b2f0_result - return code from CP
1900 iucv_send_prmmsg (__u16 pathid,
1903 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1908 iucv_debug(2, "entering");
1910 parm = (iparml_dpl *)grab_param();
1912 parm->ippathid = pathid;
1913 parm->iptrgcls = trgcls;
1914 parm->ipsrccls = srccls;
1915 parm->ipmsgtag = msgtag;
1916 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1917 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1919 b2f0_result = b2f0(SEND, parm);
1921 if ((!b2f0_result) && (msgid))
1922 *msgid = parm->ipmsgid;
1923 release_param(parm);
1925 iucv_debug(2, "exiting");
1931 * Name: iucv_send2way
1932 * Purpose: This function transmits data to another application.
1933 * Data to be transmitted is in a buffer. The receiver
1934 * of the send is expected to reply to the message and
1935 * a buffer is provided into which IUCV moves the reply
1937 * Input: pathid - path identification number
1938 * trgcls - specifies target class
1939 * srccls - specifies the source message class
1940 * msgtag - specifies a tag associated with the message
1941 * flags1 - option for path
1942 * IPPRTY- specifies if you want to send priority message
1943 * buffer - address of send buffer
1944 * buflen - length of send buffer
1945 * ansbuf - address of buffer to reply with
1946 * anslen - length of buffer to reply with
1947 * Output: msgid - specifies the message ID.
1948 * Return: b2f0_result - return code from CP
1949 * (-EINVAL) - buffer or ansbuf address is NULL
1952 iucv_send2way (__u16 pathid,
1958 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1963 iucv_debug(2, "entering");
1965 if (!buffer || !ansbuf)
1968 parm = (iparml_db *)grab_param();
1970 parm->ippathid = pathid;
1971 parm->iptrgcls = trgcls;
1972 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1973 parm->ipbfln1f = (__u32) buflen; /* length of message */
1974 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1975 parm->ipbfln2f = (__u32) anslen;
1976 parm->ipsrccls = srccls;
1977 parm->ipmsgtag = msgtag;
1978 parm->ipflags1 = flags1; /* priority message */
1980 b2f0_result = b2f0(SEND, parm);
1982 if ((!b2f0_result) && (msgid))
1983 *msgid = parm->ipmsgid;
1984 release_param(parm);
1986 iucv_debug(2, "exiting");
1992 * Name: iucv_send2way_array
1993 * Purpose: This function transmits data to another application.
1994 * The contents of buffer is the address of the array of
1995 * addresses and lengths of discontiguous buffers that hold
1996 * the message text. The receiver of the send is expected to
1997 * reply to the message and a buffer is provided into which
1998 * IUCV moves the reply to this message.
1999 * Input: pathid - path identification number
2000 * trgcls - specifies target class
2001 * srccls - specifies the source message class
2002 * msgtag - spcifies a tag to be associated with the message
2003 * flags1 - option for path
2004 * IPPRTY- specifies if you want to send priority message
2005 * buffer - address of array of send buffers
2006 * buflen - total length of send buffers
2007 * ansbuf - address of buffer to reply with
2008 * anslen - length of buffer to reply with
2009 * Output: msgid - specifies the message ID.
2010 * Return: b2f0_result - return code from CP
2011 * (-EINVAL) - buffer address is NULL
2014 iucv_send2way_array (__u16 pathid,
2020 iucv_array_t * buffer,
2021 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2026 iucv_debug(2, "entering");
2028 if (!buffer || !ansbuf)
2031 parm = (iparml_db *)grab_param();
2033 parm->ippathid = pathid;
2034 parm->iptrgcls = trgcls;
2035 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2036 parm->ipbfln1f = (__u32) buflen; /* length of message */
2037 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2038 parm->ipbfln2f = (__u32) anslen;
2039 parm->ipsrccls = srccls;
2040 parm->ipmsgtag = msgtag;
2041 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2042 b2f0_result = b2f0(SEND, parm);
2043 if ((!b2f0_result) && (msgid))
2044 *msgid = parm->ipmsgid;
2045 release_param(parm);
2047 iucv_debug(2, "exiting");
2052 * Name: iucv_send2way_prmmsg
2053 * Purpose: This function transmits data to another application.
2054 * Prmmsg specifies that the 8-bytes of data are to be moved
2055 * into the parameter list. This is a two-way message and the
2056 * receiver of the message is expected to reply. A buffer
2057 * is provided into which IUCV moves the reply to this
2059 * Input: pathid - path identification number
2060 * trgcls - specifies target class
2061 * srccls - specifies the source message class
2062 * msgtag - specifies a tag to be associated with the message
2063 * flags1 - option for path
2064 * IPPRTY- specifies if you want to send priority message
2065 * prmmsg - 8-bytes of data to be placed in parameter list
2066 * ansbuf - address of buffer to reply with
2067 * anslen - length of buffer to reply with
2068 * Output: msgid - specifies the message ID.
2069 * Return: b2f0_result - return code from CP
2070 * (-EINVAL) - buffer address is NULL
2073 iucv_send2way_prmmsg (__u16 pathid,
2078 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2083 iucv_debug(2, "entering");
2088 parm = (iparml_dpl *)grab_param();
2090 parm->ippathid = pathid;
2091 parm->iptrgcls = trgcls;
2092 parm->ipsrccls = srccls;
2093 parm->ipmsgtag = msgtag;
2094 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2095 parm->ipbfln2f = (__u32) anslen;
2096 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2097 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2099 b2f0_result = b2f0(SEND, parm);
2101 if ((!b2f0_result) && (msgid))
2102 *msgid = parm->ipmsgid;
2103 release_param(parm);
2105 iucv_debug(2, "exiting");
2111 * Name: iucv_send2way_prmmsg_array
2112 * Purpose: This function transmits data to another application.
2113 * Prmmsg specifies that the 8-bytes of data are to be moved
2114 * into the parameter list. This is a two-way message and the
2115 * receiver of the message is expected to reply. A buffer
2116 * is provided into which IUCV moves the reply to this
2117 * message. The contents of ansbuf is the address of the
2118 * array of addresses and lengths of discontiguous buffers
2119 * that contain the reply.
2120 * Input: pathid - path identification number
2121 * trgcls - specifies target class
2122 * srccls - specifies the source message class
2123 * msgtag - specifies a tag to be associated with the message
2124 * flags1 - option for path
2125 * IPPRTY- specifies if you want to send priority message
2126 * prmmsg - 8-bytes of data to be placed into the parameter list
2127 * ansbuf - address of buffer to reply with
2128 * anslen - length of buffer to reply with
2129 * Output: msgid - specifies the message ID.
2130 * Return: b2f0_result - return code from CP
2131 * (-EINVAL) - ansbuf address is NULL
2134 iucv_send2way_prmmsg_array (__u16 pathid,
2141 iucv_array_t * ansbuf, ulong anslen)
2146 iucv_debug(2, "entering");
2151 parm = (iparml_dpl *)grab_param();
2153 parm->ippathid = pathid;
2154 parm->iptrgcls = trgcls;
2155 parm->ipsrccls = srccls;
2156 parm->ipmsgtag = msgtag;
2157 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2158 parm->ipbfln2f = (__u32) anslen;
2159 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2160 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2161 b2f0_result = b2f0(SEND, parm);
2162 if ((!b2f0_result) && (msgid))
2163 *msgid = parm->ipmsgid;
2164 release_param(parm);
2166 iucv_debug(2, "exiting");
2171 iucv_setmask_cpuid (void *result)
2173 iparml_set_mask *parm;
2175 iucv_debug(1, "entering");
2176 parm = (iparml_set_mask *)grab_param();
2177 parm->ipmask = *((__u8*)result);
2178 *((ulong *)result) = b2f0(SETMASK, parm);
2179 release_param(parm);
2181 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2182 iucv_debug(1, "exiting");
2186 * Name: iucv_setmask
2187 * Purpose: This function enables or disables the following IUCV
2188 * external interruptions: Nonpriority and priority message
2189 * interrupts, nonpriority and priority reply interrupts.
2190 * Input: SetMaskFlag - options for interrupts
2191 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2192 * 0x40 - Priority_MessagePendingInterruptsFlag
2193 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2194 * 0x10 - Priority_MessageCompletionInterruptsFlag
2195 * 0x08 - IUCVControlInterruptsFlag
2197 * Return: b2f0_result - return code from CP
2200 iucv_setmask (int SetMaskFlag)
2208 u.param = SetMaskFlag;
2210 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2218 * @pathid: Path identification number
2219 * @user_data: 16-byte of user data
2221 * This function terminates an iucv path.
2222 * Returns: return code from CP
2225 iucv_sever(__u16 pathid, __u8 user_data[16])
2227 iparml_control *parm;
2228 ulong b2f0_result = 0;
2230 iucv_debug(1, "entering");
2231 parm = (iparml_control *)grab_param();
2233 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2234 parm->ippathid = pathid;
2236 b2f0_result = b2f0(SEVER, parm);
2239 iucv_remove_pathid(pathid);
2240 release_param(parm);
2242 iucv_debug(1, "exiting");
2247 * Interrupt Handlers
2248 *******************************************************************************/
2252 * @regs: Current registers
2255 * Handles external interrupts coming in from CP.
2256 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2259 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2261 iucv_irqdata *irqdata;
2263 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2265 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2269 memcpy(&irqdata->data, iucv_external_int_buffer,
2270 sizeof(iucv_GeneralInterrupt));
2272 spin_lock(&iucv_irq_queue_lock);
2273 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2274 spin_unlock(&iucv_irq_queue_lock);
2276 tasklet_schedule(&iucv_tasklet);
2281 * @int_buf: Pointer to copy of external interrupt buffer
2283 * The workhorse for handling interrupts queued by iucv_irq_handler().
2284 * This function is called from the bottom half iucv_tasklet_handler().
2287 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2290 struct list_head *lh;
2292 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2293 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2295 __u8 no_listener[16] = "NO LISTENER";
2297 iucv_debug(2, "entering, pathid %d, type %02X",
2298 int_buf->ippathid, int_buf->iptype);
2299 iucv_dumpit("External Interrupt Buffer:",
2300 int_buf, sizeof(iucv_GeneralInterrupt));
2302 ASCEBC (no_listener, 16);
2304 if (int_buf->iptype != 01) {
2305 if ((int_buf->ippathid) > (max_connections - 1)) {
2306 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2307 " > max_connections (%ld)\n", __FUNCTION__,
2308 int_buf->ippathid, max_connections - 1);
2310 h = iucv_pathid_table[int_buf->ippathid];
2311 interrupt = h->interrupt_table;
2312 iucv_dumpit("Handler:", h, sizeof(handler));
2316 /* end of if statement */
2317 switch (int_buf->iptype) {
2318 case 0x01: /* connection pending */
2319 if (messagesDisabled) {
2321 messagesDisabled = 0;
2323 spin_lock_irqsave(&iucv_lock, flags);
2324 list_for_each(lh, &iucv_handler_table) {
2325 h = list_entry(lh, handler, list);
2326 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2327 memcpy(temp_buff2, &(h->id.userid), 24);
2328 for (j = 0; j < 24; j++) {
2329 temp_buff1[j] &= (h->id.mask)[j];
2330 temp_buff2[j] &= (h->id.mask)[j];
2333 iucv_dumpit("temp_buff1:",
2334 temp_buff1, sizeof(temp_buff1));
2335 iucv_dumpit("temp_buff2",
2336 temp_buff2, sizeof(temp_buff2));
2338 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2341 "found a matching handler");
2346 spin_unlock_irqrestore (&iucv_lock, flags);
2348 /* ADD PATH TO PATHID TABLE */
2349 rc = iucv_add_pathid(int_buf->ippathid, h);
2351 iucv_sever (int_buf->ippathid,
2354 "add_pathid failed, rc = %d",
2357 interrupt = h->interrupt_table;
2358 if (interrupt->ConnectionPending) {
2359 EBCASC (int_buf->ipvmid, 8);
2360 interrupt->ConnectionPending(
2361 (iucv_ConnectionPending *)int_buf,
2364 iucv_sever(int_buf->ippathid,
2368 iucv_sever(int_buf->ippathid, no_listener);
2371 case 0x02: /*connection complete */
2372 if (messagesDisabled) {
2374 messagesDisabled = 0;
2377 if (interrupt->ConnectionComplete)
2379 interrupt->ConnectionComplete(
2380 (iucv_ConnectionComplete *)int_buf,
2385 "ConnectionComplete not called");
2387 iucv_sever(int_buf->ippathid, no_listener);
2390 case 0x03: /* connection severed */
2391 if (messagesDisabled) {
2393 messagesDisabled = 0;
2396 if (interrupt->ConnectionSevered)
2397 interrupt->ConnectionSevered(
2398 (iucv_ConnectionSevered *)int_buf,
2402 iucv_sever (int_buf->ippathid, no_listener);
2404 iucv_sever(int_buf->ippathid, no_listener);
2407 case 0x04: /* connection quiesced */
2408 if (messagesDisabled) {
2410 messagesDisabled = 0;
2413 if (interrupt->ConnectionQuiesced)
2414 interrupt->ConnectionQuiesced(
2415 (iucv_ConnectionQuiesced *)int_buf,
2419 "ConnectionQuiesced not called");
2423 case 0x05: /* connection resumed */
2424 if (messagesDisabled) {
2426 messagesDisabled = 0;
2429 if (interrupt->ConnectionResumed)
2430 interrupt->ConnectionResumed(
2431 (iucv_ConnectionResumed *)int_buf,
2435 "ConnectionResumed not called");
2439 case 0x06: /* priority message complete */
2440 case 0x07: /* nonpriority message complete */
2442 if (interrupt->MessageComplete)
2443 interrupt->MessageComplete(
2444 (iucv_MessageComplete *)int_buf,
2448 "MessageComplete not called");
2452 case 0x08: /* priority message pending */
2453 case 0x09: /* nonpriority message pending */
2455 if (interrupt->MessagePending)
2456 interrupt->MessagePending(
2457 (iucv_MessagePending *) int_buf,
2461 "MessagePending not called");
2464 default: /* unknown iucv type */
2465 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2470 iucv_debug(2, "exiting pathid %d, type %02X",
2471 int_buf->ippathid, int_buf->iptype);
2477 * iucv_tasklet_handler:
2479 * This function loops over the queue of irq buffers and runs iucv_do_int()
2480 * on every queue element.
2483 iucv_tasklet_handler(unsigned long ignored)
2485 struct list_head head;
2486 struct list_head *next;
2489 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2490 list_add(&head, &iucv_irq_queue);
2491 list_del_init(&iucv_irq_queue);
2492 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2495 while (next != &head) {
2496 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2499 iucv_do_int(&p->data);
2506 subsys_initcall(iucv_init);
2507 module_exit(iucv_exit);
2510 * Export all public stuff
2512 EXPORT_SYMBOL (iucv_bus);
2513 EXPORT_SYMBOL (iucv_root);
2514 EXPORT_SYMBOL (iucv_accept);
2515 EXPORT_SYMBOL (iucv_connect);
2517 EXPORT_SYMBOL (iucv_purge);
2518 EXPORT_SYMBOL (iucv_query_maxconn);
2519 EXPORT_SYMBOL (iucv_query_bufsize);
2520 EXPORT_SYMBOL (iucv_quiesce);
2522 EXPORT_SYMBOL (iucv_receive);
2524 EXPORT_SYMBOL (iucv_receive_array);
2526 EXPORT_SYMBOL (iucv_reject);
2528 EXPORT_SYMBOL (iucv_reply);
2529 EXPORT_SYMBOL (iucv_reply_array);
2530 EXPORT_SYMBOL (iucv_resume);
2532 EXPORT_SYMBOL (iucv_reply_prmmsg);
2533 EXPORT_SYMBOL (iucv_send);
2534 EXPORT_SYMBOL (iucv_send2way);
2535 EXPORT_SYMBOL (iucv_send2way_array);
2536 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2537 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2539 EXPORT_SYMBOL (iucv_send_array);
2540 EXPORT_SYMBOL (iucv_send_prmmsg);
2541 EXPORT_SYMBOL (iucv_setmask);
2543 EXPORT_SYMBOL (iucv_sever);
2544 EXPORT_SYMBOL (iucv_register_program);
2545 EXPORT_SYMBOL (iucv_unregister_program);