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>
36 #include <linux/config.h>
38 #include <linux/spinlock.h>
39 #include <linux/kernel.h>
40 #include <linux/slab.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/list.h>
44 #include <linux/errno.h>
45 #include <linux/err.h>
46 #include <linux/device.h>
47 #include <asm/atomic.h>
50 #include <asm/s390_ext.h>
51 #include <asm/ebcdic.h>
53 #include <asm/s390_rdev.h>
56 * All flags are defined in the field IPFLAGS1 of each function
57 * and can be found in CP Programming Services.
58 * IPSRCCLS - Indicates you have specified a source class
59 * IPFGMCL - Indicates you have specified a target class
60 * IPFGPID - Indicates you have specified a pathid
61 * IPFGMID - Indicates you have specified a message ID
62 * IPANSLST - Indicates that you are using an address list for
64 * IPBUFLST - Indicates that you are using an address list for
76 iucv_bus_match (struct device *dev, struct device_driver *drv)
81 struct bus_type iucv_bus = {
83 .match = iucv_bus_match,
86 struct device *iucv_root;
88 /* General IUCV interrupt structure */
96 } iucv_GeneralInterrupt;
98 static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
100 /* Spin Lock declaration */
102 static DEFINE_SPINLOCK(iucv_lock);
104 static int messagesDisabled = 0;
106 /***************INTERRUPT HANDLING ***************/
109 struct list_head queue;
110 iucv_GeneralInterrupt data;
113 static struct list_head iucv_irq_queue;
114 static DEFINE_SPINLOCK(iucv_irq_queue_lock);
117 *Internal function prototypes
119 static void iucv_tasklet_handler(unsigned long);
120 static void iucv_irq_handler(struct pt_regs *, __u16);
122 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
124 /************ FUNCTION ID'S ****************************/
128 #define DECLARE_BUFFER 12
136 #define RETRIEVE_BUFFER 2
143 * members: list - list management.
145 * userid - 8 char array of machine identification
146 * user_data - 16 char array for user identification
147 * mask - 24 char array used to compare the 2 previous
148 * interrupt_table - vector of interrupt functions.
149 * pgm_data - ulong, application data that is passed
150 * to the interrupt handlers
152 typedef struct handler_t {
153 struct list_head list;
159 iucv_interrupt_ops_t *interrupt_table;
164 * iucv_handler_table: List of registered handlers.
166 static struct list_head iucv_handler_table;
169 * iucv_pathid_table: an array of *handler pointing into
170 * iucv_handler_table for fast indexing by pathid;
172 static handler **iucv_pathid_table;
174 static unsigned long max_connections;
177 * iucv_cpuid: contains the logical cpu number of the cpu which
178 * has declared the iucv buffer by issuing DECLARE_BUFFER.
179 * If no cpu has done the initialization iucv_cpuid contains -1.
181 static int iucv_cpuid = -1;
183 * register_flag: is 0 when external interrupt has not been registered
185 static int register_flag;
187 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
188 /* Data struct 1: iparml_control
189 * Used for iucv_accept
194 * iucv_retrieve_buffer
195 * Data struct 2: iparml_dpl (data in parameter list)
196 * Used for iucv_send_prmmsg
197 * iucv_send2way_prmmsg
198 * iucv_send2way_prmmsg_array
200 * Data struct 3: iparml_db (data in a buffer)
201 * Used for iucv_receive
209 * iucv_send2way_array
210 * iucv_declare_buffer
211 * Data struct 4: iparml_purge
212 * Used for iucv_purge
214 * Data struct 5: iparml_set_mask
215 * Used for iucv_set_mask
280 iparml_control p_ctrl;
283 iparml_purge p_purge;
284 iparml_set_mask p_set_mask;
288 } __attribute__ ((aligned(8))) iucv_param;
289 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
291 static iucv_param * iucv_param_pool;
293 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
294 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
295 MODULE_LICENSE("GPL");
299 *******************************************************************************/
303 static int debuglevel = 0;
305 module_param(debuglevel, int, 0);
306 MODULE_PARM_DESC(debuglevel,
307 "Specifies the debug level (0=off ... 3=all)");
310 iucv_dumpit(char *title, void *buf, int len)
313 __u8 *p = (__u8 *)buf;
318 printk(KERN_DEBUG "%s\n", title);
320 for (i = 0; i < len; i++) {
321 if (!(i % 16) && i != 0)
323 else if (!(i % 4) && i != 0)
325 printk("%02X", *p++);
331 #define iucv_debug(lvl, fmt, args...) \
333 if (debuglevel >= lvl) \
334 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
339 #define iucv_debug(lvl, fmt, args...)
340 #define iucv_dumpit(title, buf, len)
346 *******************************************************************************/
354 printk(KERN_INFO "IUCV lowlevel driver initialized\n");
358 * iucv_init - Initialization
360 * Allocates and initializes various data structures.
367 if (iucv_external_int_buffer)
370 if (!MACHINE_IS_VM) {
371 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
372 return -EPROTONOSUPPORT;
375 ret = bus_register(&iucv_bus);
377 printk(KERN_ERR "IUCV: failed to register bus.\n");
381 iucv_root = s390_root_dev_register("iucv");
382 if (IS_ERR(iucv_root)) {
383 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
384 bus_unregister(&iucv_bus);
385 return PTR_ERR(iucv_root);
388 /* Note: GFP_DMA used used to get memory below 2G */
389 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt),
391 if (!iucv_external_int_buffer) {
393 "%s: Could not allocate external interrupt buffer\n",
395 s390_root_dev_unregister(iucv_root);
396 bus_unregister(&iucv_bus);
399 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
401 /* Initialize parameter pool */
402 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
404 if (!iucv_param_pool) {
405 printk(KERN_WARNING "%s: Could not allocate param pool\n",
407 kfree(iucv_external_int_buffer);
408 iucv_external_int_buffer = NULL;
409 s390_root_dev_unregister(iucv_root);
410 bus_unregister(&iucv_bus);
413 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
415 /* Initialize irq queue */
416 INIT_LIST_HEAD(&iucv_irq_queue);
418 /* Initialize handler table */
419 INIT_LIST_HEAD(&iucv_handler_table);
426 * iucv_exit - De-Initialization
428 * Frees everything allocated from iucv_init.
430 static int iucv_retrieve_buffer (void);
435 iucv_retrieve_buffer();
436 kfree(iucv_external_int_buffer);
437 iucv_external_int_buffer = NULL;
438 kfree(iucv_param_pool);
439 iucv_param_pool = NULL;
440 s390_root_dev_unregister(iucv_root);
441 bus_unregister(&iucv_bus);
442 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
446 * grab_param: - Get a parameter buffer from the pre-allocated pool.
448 * This function searches for an unused element in the pre-allocated pool
449 * of parameter buffers. If one is found, it marks it "in use" and returns
450 * a pointer to it. The calling function is responsible for releasing it
451 * when it has finished its usage.
453 * Returns: A pointer to iucv_param.
455 static __inline__ iucv_param *
461 ptr = iucv_param_pool + hint;
464 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
465 ptr = iucv_param_pool;
466 } while (atomic_cmpxchg(&ptr->in_use, 0, 1) != 0);
467 hint = ptr - iucv_param_pool;
469 memset(&ptr->param, 0, sizeof(ptr->param));
474 * release_param - Release a parameter buffer.
475 * @p: A pointer to a struct iucv_param, previously obtained by calling
478 * This function marks the specified parameter buffer "unused".
480 static __inline__ void
481 release_param(void *p)
483 atomic_set(&((iucv_param *)p)->in_use, 0);
487 * iucv_add_handler: - Add a new handler
488 * @new_handler: handle that is being entered into chain.
490 * Places new handle on iucv_handler_table, if identical handler is not
493 * Returns: 0 on success, !0 on failure (handler already in chain).
496 iucv_add_handler (handler *new)
500 iucv_debug(1, "entering");
501 iucv_dumpit("handler:", new, sizeof(handler));
503 spin_lock_irqsave (&iucv_lock, flags);
504 if (!list_empty(&iucv_handler_table)) {
505 struct list_head *lh;
508 * Search list for handler with identical id. If one
509 * is found, the new handler is _not_ added.
511 list_for_each(lh, &iucv_handler_table) {
512 handler *h = list_entry(lh, handler, list);
513 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
514 iucv_debug(1, "ret 1");
515 spin_unlock_irqrestore (&iucv_lock, flags);
521 * If we get here, no handler was found.
523 INIT_LIST_HEAD(&new->list);
524 list_add(&new->list, &iucv_handler_table);
525 spin_unlock_irqrestore (&iucv_lock, flags);
527 iucv_debug(1, "exiting");
533 * @code: identifier of IUCV call to CP.
534 * @parm: pointer to 40 byte iparml area passed to CP
536 * Calls CP to execute IUCV commands.
538 * Returns: return code from CP's IUCV call
540 static __inline__ ulong
541 b2f0(__u32 code, void *parm)
543 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
550 : "d" (code), "a" (parm)
554 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
556 return (unsigned long)*((__u8 *)(parm + 3));
560 * Name: iucv_add_pathid
561 * Purpose: Adds a path id to the system.
562 * Input: pathid - pathid that is going to be entered into system
563 * handle - address of handler that the pathid will be associated
565 * pgm_data - token passed in by application.
566 * Output: 0: successful addition of pathid
567 * - EINVAL - pathid entry is being used by another application
568 * - ENOMEM - storage allocation for a new pathid table failed
571 __iucv_add_pathid(__u16 pathid, handler *handler)
574 iucv_debug(1, "entering");
576 iucv_debug(1, "handler is pointing to %p", handler);
578 if (pathid > (max_connections - 1))
581 if (iucv_pathid_table[pathid]) {
582 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
584 "%s: Pathid being used, error.\n", __FUNCTION__);
587 iucv_pathid_table[pathid] = handler;
589 iucv_debug(1, "exiting");
591 } /* end of add_pathid function */
594 iucv_add_pathid(__u16 pathid, handler *handler)
599 spin_lock_irqsave (&iucv_lock, flags);
600 rc = __iucv_add_pathid(pathid, handler);
601 spin_unlock_irqrestore (&iucv_lock, flags);
606 iucv_remove_pathid(__u16 pathid)
610 if (pathid > (max_connections - 1))
613 spin_lock_irqsave (&iucv_lock, flags);
614 iucv_pathid_table[pathid] = NULL;
615 spin_unlock_irqrestore (&iucv_lock, flags);
619 * iucv_declare_buffer_cpuid
620 * Register at VM for subsequent IUCV operations. This is executed
621 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
624 iucv_declare_buffer_cpuid (void *result)
628 parm = (iparml_db *)grab_param();
629 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
630 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
631 *((ulong *)result) = parm->iprcode;
636 * iucv_retrieve_buffer_cpuid:
637 * Unregister IUCV usage at VM. This is always executed on the same
638 * cpu that registered the buffer to VM.
639 * Called from iucv_retrieve_buffer().
642 iucv_retrieve_buffer_cpuid (void *cpu)
644 iparml_control *parm;
646 parm = (iparml_control *)grab_param();
647 b2f0(RETRIEVE_BUFFER, parm);
652 * Name: iucv_declare_buffer
653 * Purpose: Specifies the guests real address of an external
656 * Output: iprcode - return code from b2f0 call
659 iucv_declare_buffer (void)
664 iucv_debug(1, "entering");
665 b2f0_result = -ENODEV;
666 spin_lock_irqsave (&iucv_lock, flags);
667 if (iucv_cpuid == -1) {
668 /* Reserve any cpu for use by iucv. */
669 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
670 spin_unlock_irqrestore (&iucv_lock, flags);
671 smp_call_function_on(iucv_declare_buffer_cpuid,
672 &b2f0_result, 0, 1, iucv_cpuid);
674 smp_put_cpu(iucv_cpuid);
677 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
679 spin_unlock_irqrestore (&iucv_lock, flags);
682 iucv_debug(1, "exiting");
687 * iucv_retrieve_buffer:
689 * Terminates all use of IUCV.
690 * Returns: return code from CP
693 iucv_retrieve_buffer (void)
695 iucv_debug(1, "entering");
696 if (iucv_cpuid != -1) {
697 smp_call_function_on(iucv_retrieve_buffer_cpuid,
698 0, 0, 1, iucv_cpuid);
699 /* Release the cpu reserved by iucv_declare_buffer. */
700 smp_put_cpu(iucv_cpuid);
703 iucv_debug(1, "exiting");
708 * iucv_remove_handler:
709 * @users_handler: handler to be removed
711 * Remove handler when application unregisters.
714 iucv_remove_handler(handler *handler)
718 if ((!iucv_pathid_table) || (!handler))
721 iucv_debug(1, "entering");
723 spin_lock_irqsave (&iucv_lock, flags);
724 list_del(&handler->list);
725 if (list_empty(&iucv_handler_table)) {
727 unregister_external_interrupt(0x4000, iucv_irq_handler);
731 spin_unlock_irqrestore (&iucv_lock, flags);
733 iucv_debug(1, "exiting");
738 * iucv_register_program:
739 * @pgmname: user identification
740 * @userid: machine identification
741 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
742 * used to determine who is given control.
743 * @ops: Address of interrupt handler table.
744 * @pgm_data: Application data to be passed to interrupt handlers.
746 * Registers an application with IUCV.
748 * The address of handler, or NULL on failure.
750 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
752 * If pgmmask is NULL, the internal mask is set to all 0xff's
753 * When userid is NULL, the first 8 bytes of the internal mask are forced
755 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
756 * are forced to 0x00 and the last 16 bytes to 0xff.
760 iucv_register_program (__u8 pgmname[16],
763 iucv_interrupt_ops_t * ops, void *pgm_data)
765 ulong rc = 0; /* return code from function calls */
766 handler *new_handler;
768 iucv_debug(1, "entering");
771 /* interrupt table is not defined */
772 printk(KERN_WARNING "%s: Interrupt table is not defined, "
773 "exiting\n", __FUNCTION__);
777 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
781 /* Allocate handler entry */
782 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
783 if (new_handler == NULL) {
784 printk(KERN_WARNING "%s: storage allocation for new handler "
785 "failed.\n", __FUNCTION__);
789 if (!iucv_pathid_table) {
795 max_connections = iucv_query_maxconn();
796 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
798 if (iucv_pathid_table == NULL) {
799 printk(KERN_WARNING "%s: iucv_pathid_table storage "
800 "allocation failed\n", __FUNCTION__);
804 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
806 memset(new_handler, 0, sizeof (handler));
807 memcpy(new_handler->id.user_data, pgmname,
808 sizeof (new_handler->id.user_data));
810 memcpy (new_handler->id.userid, userid,
811 sizeof (new_handler->id.userid));
812 ASCEBC (new_handler->id.userid,
813 sizeof (new_handler->id.userid));
814 EBC_TOUPPER (new_handler->id.userid,
815 sizeof (new_handler->id.userid));
818 memcpy (new_handler->id.mask, pgmmask,
819 sizeof (new_handler->id.mask));
821 memset (new_handler->id.mask, 0xFF,
822 sizeof (new_handler->id.mask));
826 memcpy (new_handler->id.mask, pgmmask,
827 sizeof (new_handler->id.mask));
829 memset (new_handler->id.mask, 0xFF,
830 sizeof (new_handler->id.mask));
832 memset (new_handler->id.userid, 0x00,
833 sizeof (new_handler->id.userid));
835 /* fill in the rest of handler */
836 new_handler->pgm_data = pgm_data;
837 new_handler->interrupt_table = ops;
840 * Check if someone else is registered with same pgmname, userid
841 * and mask. If someone is already registered with same pgmname,
842 * userid and mask, registration will fail and NULL will be returned
843 * to the application.
844 * If identical handler not found, then handler is added to list.
846 rc = iucv_add_handler(new_handler);
848 printk(KERN_WARNING "%s: Someone already registered with same "
849 "pgmname, userid, pgmmask\n", __FUNCTION__);
854 rc = iucv_declare_buffer();
856 char *err = "Unknown";
857 iucv_remove_handler(new_handler);
861 err = "Directory error";
864 err = "Invalid length";
867 err = "Buffer already exists";
870 err = "Buffer overlap";
873 err = "Paging or storage error";
876 printk(KERN_WARNING "%s: iucv_declare_buffer "
877 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
880 if (!register_flag) {
881 /* request the 0x4000 external interrupt */
882 rc = register_external_interrupt (0x4000, iucv_irq_handler);
884 iucv_remove_handler(new_handler);
886 printk(KERN_WARNING "%s: "
887 "register_external_interrupt returned %ld\n",
894 iucv_debug(1, "exiting");
896 } /* end of register function */
899 * iucv_unregister_program:
900 * @handle: address of handler
902 * Unregister application with IUCV.
904 * 0 on success, -EINVAL, if specified handle is invalid.
908 iucv_unregister_program (iucv_handle_t handle)
911 struct list_head *lh;
915 iucv_debug(1, "entering");
916 iucv_debug(1, "address of handler is %p", h);
918 /* Checking if handle is valid */
919 spin_lock_irqsave (&iucv_lock, flags);
920 list_for_each(lh, &iucv_handler_table) {
921 if ((handler *)handle == list_entry(lh, handler, list)) {
922 h = (handler *)handle;
927 spin_unlock_irqrestore (&iucv_lock, flags);
930 "%s: Handler not found in iucv_handler_table.\n",
934 "%s: NULL handle passed by application.\n",
940 * First, walk thru iucv_pathid_table and sever any pathid which is
941 * still pointing to the handler to be removed.
943 for (i = 0; i < max_connections; i++)
944 if (iucv_pathid_table[i] == h) {
945 spin_unlock_irqrestore (&iucv_lock, flags);
946 iucv_sever(i, h->id.user_data);
947 spin_lock_irqsave(&iucv_lock, flags);
949 spin_unlock_irqrestore (&iucv_lock, flags);
951 iucv_remove_handler(h);
954 iucv_debug(1, "exiting");
960 * @pathid: Path identification number
961 * @msglim_reqstd: The number of outstanding messages requested.
962 * @user_data: Data specified by the iucv_connect function.
963 * @flags1: Contains options for this path.
964 * - IPPRTY (0x20) Specifies if you want to send priority message.
965 * - IPRMDATA (0x80) Specifies whether your program can handle a message
966 * in the parameter list.
967 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
969 * @handle: Address of handler.
970 * @pgm_data: Application data passed to interrupt handlers.
971 * @flags1_out: Pointer to an int. If not NULL, on return the options for
972 * the path are stored at the given location:
973 * - IPPRTY (0x20) Indicates you may send a priority message.
974 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
975 * number of outstanding messages is stored at the given
978 * This function is issued after the user receives a Connection Pending external
979 * interrupt and now wishes to complete the IUCV communication path.
981 * return code from CP
984 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
985 __u8 user_data[16], int flags1,
986 iucv_handle_t handle, void *pgm_data,
987 int *flags1_out, __u16 * msglim)
989 ulong b2f0_result = 0;
991 struct list_head *lh;
993 iparml_control *parm;
995 iucv_debug(1, "entering");
996 iucv_debug(1, "pathid = %d", pathid);
998 /* Checking if handle is valid */
999 spin_lock_irqsave (&iucv_lock, flags);
1000 list_for_each(lh, &iucv_handler_table) {
1001 if ((handler *)handle == list_entry(lh, handler, list)) {
1002 h = (handler *)handle;
1006 spin_unlock_irqrestore (&iucv_lock, flags);
1011 "%s: Handler not found in iucv_handler_table.\n",
1015 "%s: NULL handle passed by application.\n",
1020 parm = (iparml_control *)grab_param();
1022 parm->ippathid = pathid;
1023 parm->ipmsglim = msglim_reqstd;
1025 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1027 parm->ipflags1 = (__u8)flags1;
1028 b2f0_result = b2f0(ACCEPT, parm);
1032 *msglim = parm->ipmsglim;
1034 h->pgm_data = pgm_data;
1036 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1038 release_param(parm);
1040 iucv_debug(1, "exiting");
1046 * @pathid: Path identification number
1047 * @msglim_reqstd: Number of outstanding messages requested
1048 * @user_data: 16-byte user data
1049 * @userid: 8-byte of user identification
1050 * @system_name: 8-byte identifying the system name
1051 * @flags1: Specifies options for this path:
1052 * - IPPRTY (0x20) Specifies if you want to send priority message.
1053 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1054 * in the parameter list.
1055 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1057 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1058 * local system. If local is specified then target class
1059 * cannot be specified.
1060 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1061 * the path are stored at the given location:
1062 * - IPPRTY (0x20) Indicates you may send a priority message.
1063 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1064 * number of outstanding messages is stored at the given
1066 * @handle: Address of handler.
1067 * @pgm_data: Application data to be passed to interrupt handlers.
1069 * This function establishes an IUCV path. Although the connect may complete
1070 * successfully, you are not able to use the path until you receive an IUCV
1071 * Connection Complete external interrupt.
1072 * Returns: return code from CP, or one of the following
1074 * - return code from iucv_declare_buffer
1075 * - EINVAL - invalid handle passed by application
1076 * - EINVAL - pathid address is NULL
1077 * - ENOMEM - pathid table storage allocation failed
1078 * - return code from internal function add_pathid
1081 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1082 __u8 user_data[16], __u8 userid[8],
1083 __u8 system_name[8], int flags1,
1084 int *flags1_out, __u16 * msglim,
1085 iucv_handle_t handle, void *pgm_data)
1087 iparml_control *parm;
1088 iparml_control local_parm;
1089 struct list_head *lh;
1090 ulong b2f0_result = 0;
1092 int add_pathid_result = 0;
1094 __u8 no_memory[16] = "NO MEMORY";
1096 iucv_debug(1, "entering");
1098 /* Checking if handle is valid */
1099 spin_lock_irqsave (&iucv_lock, flags);
1100 list_for_each(lh, &iucv_handler_table) {
1101 if ((handler *)handle == list_entry(lh, handler, list)) {
1102 h = (handler *)handle;
1106 spin_unlock_irqrestore (&iucv_lock, flags);
1111 "%s: Handler not found in iucv_handler_table.\n",
1115 "%s: NULL handle passed by application.\n",
1120 if (pathid == NULL) {
1121 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1126 parm = (iparml_control *)grab_param();
1128 parm->ipmsglim = msglim_reqstd;
1131 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1134 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1135 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1136 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1140 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1141 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1142 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1145 /* In order to establish an IUCV connection, the procedure is:
1148 * take the ippathid from the b2f0 call
1149 * register the handler to the ippathid
1151 * Unfortunately, the ConnectionEstablished message gets sent after the
1152 * b2f0(CONNECT) call but before the register is handled.
1154 * In order for this race condition to be eliminated, the IUCV Control
1155 * Interrupts must be disabled for the above procedure.
1157 * David Kennedy <dkennedy@linuxcare.com>
1160 /* Enable everything but IUCV Control messages */
1161 iucv_setmask(~(AllInterrupts));
1162 messagesDisabled = 1;
1164 spin_lock_irqsave (&iucv_lock, flags);
1165 parm->ipflags1 = (__u8)flags1;
1166 b2f0_result = b2f0(CONNECT, parm);
1167 memcpy(&local_parm, parm, sizeof(local_parm));
1168 release_param(parm);
1171 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1172 spin_unlock_irqrestore (&iucv_lock, flags);
1176 messagesDisabled = 0;
1180 *pathid = parm->ippathid;
1182 /* Enable everything again */
1183 iucv_setmask(IUCVControlInterruptsFlag);
1186 *msglim = parm->ipmsglim;
1188 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1190 if (add_pathid_result) {
1191 iucv_sever(*pathid, no_memory);
1192 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1193 " %d\n", __FUNCTION__, add_pathid_result);
1194 return(add_pathid_result);
1197 iucv_debug(1, "exiting");
1203 * @pathid: Path identification number
1204 * @msgid: Message ID of message to purge.
1205 * @srccls: Message class of the message to purge.
1206 * @audit: Pointer to an __u32. If not NULL, on return, information about
1207 * asynchronous errors that may have affected the normal completion
1208 * of this message ist stored at the given location.
1210 * Cancels a message you have sent.
1211 * Returns: return code from CP
1214 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1217 ulong b2f0_result = 0;
1219 iucv_debug(1, "entering");
1220 iucv_debug(1, "pathid = %d", pathid);
1222 parm = (iparml_purge *)grab_param();
1224 parm->ipmsgid = msgid;
1225 parm->ippathid = pathid;
1226 parm->ipsrccls = srccls;
1227 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1228 b2f0_result = b2f0(PURGE, parm);
1230 if (!b2f0_result && audit) {
1231 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1232 /* parm->ipaudit has only 3 bytes */
1236 release_param(parm);
1238 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1239 iucv_debug(1, "exiting");
1244 * iucv_query_generic:
1245 * @want_maxconn: Flag, describing which value is to be returned.
1247 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1249 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1250 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1253 iucv_query_generic(int want_maxconn)
1255 iparml_purge *parm = (iparml_purge *)grab_param();
1256 int bufsize, maxconn;
1260 * Call b2f0 and store R0 (max buffer size),
1261 * R1 (max connections) and CC.
1266 ".long 0xb2f01000\n\t"
1271 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1272 : "d" (QUERY), "a" (parm)
1275 release_param(parm);
1285 * iucv_query_maxconn:
1287 * Determines the maximum number of connections thay may be established.
1289 * Returns: Maximum number of connections that can be.
1292 iucv_query_maxconn(void)
1294 return iucv_query_generic(1);
1298 * iucv_query_bufsize:
1300 * Determines the size of the external interrupt buffer.
1302 * Returns: Size of external interrupt buffer.
1305 iucv_query_bufsize (void)
1307 return iucv_query_generic(0);
1312 * @pathid: Path identification number
1313 * @user_data: 16-byte user data
1315 * Temporarily suspends incoming messages on an IUCV path.
1316 * You can later reactivate the path by invoking the iucv_resume function.
1317 * Returns: return code from CP
1320 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1322 iparml_control *parm;
1323 ulong b2f0_result = 0;
1325 iucv_debug(1, "entering");
1326 iucv_debug(1, "pathid = %d", pathid);
1328 parm = (iparml_control *)grab_param();
1330 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1331 parm->ippathid = pathid;
1333 b2f0_result = b2f0(QUIESCE, parm);
1334 release_param(parm);
1336 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1337 iucv_debug(1, "exiting");
1344 * @pathid: Path identification number.
1345 * @buffer: Address of buffer to receive. Must be below 2G.
1346 * @buflen: Length of buffer to receive.
1347 * @msgid: Specifies the message ID.
1348 * @trgcls: Specifies target class.
1349 * @flags1_out: Receives options for path on return.
1350 * - IPNORPY (0x10) Specifies whether a reply is required
1351 * - IPPRTY (0x20) Specifies if you want to send priority message
1352 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1353 * @residual_buffer: Receives the address of buffer updated by the number
1354 * of bytes you have received on return.
1355 * @residual_length: On return, receives one of the following values:
1356 * - 0 If the receive buffer is the same length as
1358 * - Remaining bytes in buffer If the receive buffer is longer than the
1360 * - Remaining bytes in message If the receive buffer is shorter than the
1363 * This function receives messages that are being sent to you over established
1365 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1366 * than the message, always 5
1367 * -EINVAL - buffer address is pointing to NULL
1370 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1371 void *buffer, ulong buflen,
1372 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1376 int moved = 0; /* number of bytes moved from parmlist to buffer */
1378 iucv_debug(2, "entering");
1383 parm = (iparml_db *)grab_param();
1385 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1386 parm->ipbfln1f = (__u32) ((ulong) buflen);
1387 parm->ipmsgid = msgid;
1388 parm->ippathid = pathid;
1389 parm->iptrgcls = trgcls;
1390 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1392 b2f0_result = b2f0(RECEIVE, parm);
1394 if (!b2f0_result || b2f0_result == 5) {
1396 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1397 *flags1_out = (parm->ipflags1 & (~0x07));
1398 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1401 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1402 if (residual_length)
1403 *residual_length = parm->ipbfln1f;
1405 if (residual_buffer)
1406 *residual_buffer = parm->ipbfadr1;
1408 moved = min_t (unsigned long, buflen, 8);
1410 memcpy ((char *) buffer,
1411 (char *) &parm->ipbfadr1, moved);
1416 if (residual_length)
1417 *residual_length = abs (buflen - 8);
1419 if (residual_buffer)
1420 *residual_buffer = (ulong) (buffer + moved);
1423 release_param(parm);
1425 iucv_debug(2, "exiting");
1430 * Name: iucv_receive_array
1431 * Purpose: This function receives messages that are being sent to you
1432 * over established paths.
1433 * Input: pathid - path identification number
1434 * buffer - address of array of buffers
1435 * buflen - total length of buffers
1436 * msgid - specifies the message ID.
1437 * trgcls - specifies target class
1439 * flags1_out: Options for path.
1440 * IPNORPY - 0x10 specifies whether a reply is required
1441 * IPPRTY - 0x20 specifies if you want to send priority message
1442 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1443 * residual_buffer - address points to the current list entry IUCV
1446 * Contains one of the following values, if the receive buffer is:
1447 * The same length as the message, this field is zero.
1448 * Longer than the message, this field contains the number of
1449 * bytes remaining in the buffer.
1450 * Shorter than the message, this field contains the residual
1451 * count (that is, the number of bytes remaining in the
1452 * message that does not fit into the buffer. In this case
1454 * Return: b2f0_result - return code from CP
1455 * (-EINVAL) - buffer address is NULL
1458 iucv_receive_array (__u16 pathid,
1459 __u32 msgid, __u32 trgcls,
1460 iucv_array_t * buffer, ulong buflen,
1462 ulong * residual_buffer, ulong * residual_length)
1466 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1468 iucv_debug(2, "entering");
1473 parm = (iparml_db *)grab_param();
1475 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1476 parm->ipbfln1f = (__u32) buflen;
1477 parm->ipmsgid = msgid;
1478 parm->ippathid = pathid;
1479 parm->iptrgcls = trgcls;
1480 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1482 b2f0_result = b2f0(RECEIVE, parm);
1484 if (!b2f0_result || b2f0_result == 5) {
1487 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1488 *flags1_out = (parm->ipflags1 & (~0x07));
1489 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1492 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1494 if (residual_length)
1495 *residual_length = parm->ipbfln1f;
1497 if (residual_buffer)
1498 *residual_buffer = parm->ipbfadr1;
1501 /* copy msg from parmlist to users array. */
1503 while ((moved < 8) && (moved < buflen)) {
1505 min_t (unsigned int,
1506 (buffer + i)->length, need_to_move);
1508 memcpy ((char *)((ulong)((buffer + i)->address)),
1509 ((char *) &parm->ipbfadr1) + moved,
1513 need_to_move -= dyn_len;
1515 (buffer + i)->address =
1517 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1520 (buffer + i)->length -= dyn_len;
1524 if (need_to_move) /* buflen < 8 bytes */
1527 if (residual_length)
1528 *residual_length = abs (buflen - 8);
1530 if (residual_buffer) {
1532 *residual_buffer = (ulong) buffer;
1535 (ulong) (buffer + (i - 1));
1540 release_param(parm);
1542 iucv_debug(2, "exiting");
1548 * @pathid: Path identification number.
1549 * @msgid: Message ID of the message to reject.
1550 * @trgcls: Target class of the message to reject.
1551 * Returns: return code from CP
1553 * Refuses a specified message. Between the time you are notified of a
1554 * message and the time that you complete the message, the message may
1558 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1561 ulong b2f0_result = 0;
1563 iucv_debug(1, "entering");
1564 iucv_debug(1, "pathid = %d", pathid);
1566 parm = (iparml_db *)grab_param();
1568 parm->ippathid = pathid;
1569 parm->ipmsgid = msgid;
1570 parm->iptrgcls = trgcls;
1571 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1573 b2f0_result = b2f0(REJECT, parm);
1574 release_param(parm);
1576 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1577 iucv_debug(1, "exiting");
1584 * Purpose: This function responds to the two-way messages that you
1585 * receive. You must identify completely the message to
1586 * which you wish to reply. ie, pathid, msgid, and trgcls.
1587 * Input: pathid - path identification number
1588 * msgid - specifies the message ID.
1589 * trgcls - specifies target class
1590 * flags1 - option for path
1591 * IPPRTY- 0x20 - specifies if you want to send priority message
1592 * buffer - address of reply buffer
1593 * buflen - length of reply buffer
1594 * Output: ipbfadr2 - Address of buffer updated by the number
1595 * of bytes you have moved.
1596 * ipbfln2f - Contains one of the following values:
1597 * If the answer buffer is the same length as the reply, this field
1599 * If the answer buffer is longer than the reply, this field contains
1600 * the number of bytes remaining in the buffer.
1601 * If the answer buffer is shorter than the reply, this field contains
1602 * a residual count (that is, the number of bytes remianing in the
1603 * reply that does not fit into the buffer. In this
1604 * case b2f0_result = 5.
1605 * Return: b2f0_result - return code from CP
1606 * (-EINVAL) - buffer address is NULL
1609 iucv_reply (__u16 pathid,
1610 __u32 msgid, __u32 trgcls,
1612 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1617 iucv_debug(2, "entering");
1622 parm = (iparml_db *)grab_param();
1624 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1625 parm->ipbfln2f = (__u32) buflen; /* length of message */
1626 parm->ippathid = pathid;
1627 parm->ipmsgid = msgid;
1628 parm->iptrgcls = trgcls;
1629 parm->ipflags1 = (__u8) flags1; /* priority message */
1631 b2f0_result = b2f0(REPLY, parm);
1633 if ((!b2f0_result) || (b2f0_result == 5)) {
1635 *ipbfadr2 = parm->ipbfadr2;
1637 *ipbfln2f = parm->ipbfln2f;
1639 release_param(parm);
1641 iucv_debug(2, "exiting");
1647 * Name: iucv_reply_array
1648 * Purpose: This function responds to the two-way messages that you
1649 * receive. You must identify completely the message to
1650 * which you wish to reply. ie, pathid, msgid, and trgcls.
1651 * The array identifies a list of addresses and lengths of
1652 * discontiguous buffers that contains the reply data.
1653 * Input: pathid - path identification number
1654 * msgid - specifies the message ID.
1655 * trgcls - specifies target class
1656 * flags1 - option for path
1657 * IPPRTY- specifies if you want to send priority message
1658 * buffer - address of array of reply buffers
1659 * buflen - total length of reply buffers
1660 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1661 * ipbfln2f - Contains one of the following values:
1662 * If the answer buffer is the same length as the reply, this field
1664 * If the answer buffer is longer than the reply, this field contains
1665 * the number of bytes remaining in the buffer.
1666 * If the answer buffer is shorter than the reply, this field contains
1667 * a residual count (that is, the number of bytes remianing in the
1668 * reply that does not fit into the buffer. In this
1669 * case b2f0_result = 5.
1670 * Return: b2f0_result - return code from CP
1671 * (-EINVAL) - buffer address is NULL
1674 iucv_reply_array (__u16 pathid,
1675 __u32 msgid, __u32 trgcls,
1677 iucv_array_t * buffer,
1678 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1683 iucv_debug(2, "entering");
1688 parm = (iparml_db *)grab_param();
1690 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1691 parm->ipbfln2f = buflen; /* length of message */
1692 parm->ippathid = pathid;
1693 parm->ipmsgid = msgid;
1694 parm->iptrgcls = trgcls;
1695 parm->ipflags1 = (IPANSLST | flags1);
1697 b2f0_result = b2f0(REPLY, parm);
1699 if ((!b2f0_result) || (b2f0_result == 5)) {
1702 *ipbfadr2 = parm->ipbfadr2;
1704 *ipbfln2f = parm->ipbfln2f;
1706 release_param(parm);
1708 iucv_debug(2, "exiting");
1714 * Name: iucv_reply_prmmsg
1715 * Purpose: This function responds to the two-way messages that you
1716 * receive. You must identify completely the message to
1717 * which you wish to reply. ie, pathid, msgid, and trgcls.
1718 * Prmmsg signifies the data is moved into the
1720 * Input: pathid - path identification number
1721 * msgid - specifies the message ID.
1722 * trgcls - specifies target class
1723 * flags1 - option for path
1724 * IPPRTY- specifies if you want to send priority message
1725 * prmmsg - 8-bytes of data to be placed into the parameter
1728 * Return: b2f0_result - return code from CP
1731 iucv_reply_prmmsg (__u16 pathid,
1732 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1737 iucv_debug(2, "entering");
1739 parm = (iparml_dpl *)grab_param();
1741 parm->ippathid = pathid;
1742 parm->ipmsgid = msgid;
1743 parm->iptrgcls = trgcls;
1744 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1745 parm->ipflags1 = (IPRMDATA | flags1);
1747 b2f0_result = b2f0(REPLY, parm);
1748 release_param(parm);
1750 iucv_debug(2, "exiting");
1757 * @pathid: Path identification number
1758 * @user_data: 16-byte of user data
1760 * This function restores communication over a quiesced path.
1761 * Returns: return code from CP
1764 iucv_resume (__u16 pathid, __u8 user_data[16])
1766 iparml_control *parm;
1767 ulong b2f0_result = 0;
1769 iucv_debug(1, "entering");
1770 iucv_debug(1, "pathid = %d", pathid);
1772 parm = (iparml_control *)grab_param();
1774 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1775 parm->ippathid = pathid;
1777 b2f0_result = b2f0(RESUME, parm);
1778 release_param(parm);
1780 iucv_debug(1, "exiting");
1787 * Purpose: sends messages
1788 * Input: pathid - ushort, pathid
1789 * msgid - ulong *, id of message returned to caller
1790 * trgcls - ulong, target message class
1791 * srccls - ulong, source message class
1792 * msgtag - ulong, message tag
1793 * flags1 - Contains options for this path.
1794 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1795 * buffer - pointer to buffer
1796 * buflen - ulong, length of buffer
1797 * Output: b2f0_result - return code from b2f0 call
1798 * msgid - returns message id
1801 iucv_send (__u16 pathid, __u32 * msgid,
1802 __u32 trgcls, __u32 srccls,
1803 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1808 iucv_debug(2, "entering");
1813 parm = (iparml_db *)grab_param();
1815 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1816 parm->ippathid = pathid;
1817 parm->iptrgcls = trgcls;
1818 parm->ipbfln1f = (__u32) buflen; /* length of message */
1819 parm->ipsrccls = srccls;
1820 parm->ipmsgtag = msgtag;
1821 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1823 b2f0_result = b2f0(SEND, parm);
1825 if ((!b2f0_result) && (msgid))
1826 *msgid = parm->ipmsgid;
1827 release_param(parm);
1829 iucv_debug(2, "exiting");
1835 * Name: iucv_send_array
1836 * Purpose: This function transmits data to another application.
1837 * The contents of buffer is the address of the array of
1838 * addresses and lengths of discontiguous buffers that hold
1839 * the message text. This is a one-way message and the
1840 * receiver will not reply to the message.
1841 * Input: pathid - path identification number
1842 * trgcls - specifies target class
1843 * srccls - specifies the source message class
1844 * msgtag - specifies a tag to be associated witht the message
1845 * flags1 - option for path
1846 * IPPRTY- specifies if you want to send priority message
1847 * buffer - address of array of send buffers
1848 * buflen - total length of send buffers
1849 * Output: msgid - specifies the message ID.
1850 * Return: b2f0_result - return code from CP
1851 * (-EINVAL) - buffer address is NULL
1854 iucv_send_array (__u16 pathid,
1858 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1863 iucv_debug(2, "entering");
1868 parm = (iparml_db *)grab_param();
1870 parm->ippathid = pathid;
1871 parm->iptrgcls = trgcls;
1872 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1873 parm->ipbfln1f = (__u32) buflen; /* length of message */
1874 parm->ipsrccls = srccls;
1875 parm->ipmsgtag = msgtag;
1876 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1877 b2f0_result = b2f0(SEND, parm);
1879 if ((!b2f0_result) && (msgid))
1880 *msgid = parm->ipmsgid;
1881 release_param(parm);
1883 iucv_debug(2, "exiting");
1888 * Name: iucv_send_prmmsg
1889 * Purpose: This function transmits data to another application.
1890 * Prmmsg specifies that the 8-bytes of data are to be moved
1891 * into the parameter list. This is a one-way message and the
1892 * receiver will not reply to the message.
1893 * Input: pathid - path identification number
1894 * trgcls - specifies target class
1895 * srccls - specifies the source message class
1896 * msgtag - specifies a tag to be associated with the message
1897 * flags1 - option for path
1898 * IPPRTY- specifies if you want to send priority message
1899 * prmmsg - 8-bytes of data to be placed into parameter list
1900 * Output: msgid - specifies the message ID.
1901 * Return: b2f0_result - return code from CP
1904 iucv_send_prmmsg (__u16 pathid,
1907 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1912 iucv_debug(2, "entering");
1914 parm = (iparml_dpl *)grab_param();
1916 parm->ippathid = pathid;
1917 parm->iptrgcls = trgcls;
1918 parm->ipsrccls = srccls;
1919 parm->ipmsgtag = msgtag;
1920 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1921 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1923 b2f0_result = b2f0(SEND, parm);
1925 if ((!b2f0_result) && (msgid))
1926 *msgid = parm->ipmsgid;
1927 release_param(parm);
1929 iucv_debug(2, "exiting");
1935 * Name: iucv_send2way
1936 * Purpose: This function transmits data to another application.
1937 * Data to be transmitted is in a buffer. The receiver
1938 * of the send is expected to reply to the message and
1939 * a buffer is provided into which IUCV moves the reply
1941 * Input: pathid - path identification number
1942 * trgcls - specifies target class
1943 * srccls - specifies the source message class
1944 * msgtag - specifies a tag associated with the message
1945 * flags1 - option for path
1946 * IPPRTY- specifies if you want to send priority message
1947 * buffer - address of send buffer
1948 * buflen - length of send buffer
1949 * ansbuf - address of buffer to reply with
1950 * anslen - length of buffer to reply with
1951 * Output: msgid - specifies the message ID.
1952 * Return: b2f0_result - return code from CP
1953 * (-EINVAL) - buffer or ansbuf address is NULL
1956 iucv_send2way (__u16 pathid,
1962 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1967 iucv_debug(2, "entering");
1969 if (!buffer || !ansbuf)
1972 parm = (iparml_db *)grab_param();
1974 parm->ippathid = pathid;
1975 parm->iptrgcls = trgcls;
1976 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1977 parm->ipbfln1f = (__u32) buflen; /* length of message */
1978 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1979 parm->ipbfln2f = (__u32) anslen;
1980 parm->ipsrccls = srccls;
1981 parm->ipmsgtag = msgtag;
1982 parm->ipflags1 = flags1; /* priority message */
1984 b2f0_result = b2f0(SEND, parm);
1986 if ((!b2f0_result) && (msgid))
1987 *msgid = parm->ipmsgid;
1988 release_param(parm);
1990 iucv_debug(2, "exiting");
1996 * Name: iucv_send2way_array
1997 * Purpose: This function transmits data to another application.
1998 * The contents of buffer is the address of the array of
1999 * addresses and lengths of discontiguous buffers that hold
2000 * the message text. The receiver of the send is expected to
2001 * reply to the message and a buffer is provided into which
2002 * IUCV moves the reply to this message.
2003 * Input: pathid - path identification number
2004 * trgcls - specifies target class
2005 * srccls - specifies the source message class
2006 * msgtag - spcifies a tag to be associated with the message
2007 * flags1 - option for path
2008 * IPPRTY- specifies if you want to send priority message
2009 * buffer - address of array of send buffers
2010 * buflen - total length of send buffers
2011 * ansbuf - address of buffer to reply with
2012 * anslen - length of buffer to reply with
2013 * Output: msgid - specifies the message ID.
2014 * Return: b2f0_result - return code from CP
2015 * (-EINVAL) - buffer address is NULL
2018 iucv_send2way_array (__u16 pathid,
2024 iucv_array_t * buffer,
2025 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2030 iucv_debug(2, "entering");
2032 if (!buffer || !ansbuf)
2035 parm = (iparml_db *)grab_param();
2037 parm->ippathid = pathid;
2038 parm->iptrgcls = trgcls;
2039 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2040 parm->ipbfln1f = (__u32) buflen; /* length of message */
2041 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2042 parm->ipbfln2f = (__u32) anslen;
2043 parm->ipsrccls = srccls;
2044 parm->ipmsgtag = msgtag;
2045 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2046 b2f0_result = b2f0(SEND, parm);
2047 if ((!b2f0_result) && (msgid))
2048 *msgid = parm->ipmsgid;
2049 release_param(parm);
2051 iucv_debug(2, "exiting");
2056 * Name: iucv_send2way_prmmsg
2057 * Purpose: This function transmits data to another application.
2058 * Prmmsg specifies that the 8-bytes of data are to be moved
2059 * into the parameter list. This is a two-way message and the
2060 * receiver of the message is expected to reply. A buffer
2061 * is provided into which IUCV moves the reply to this
2063 * Input: pathid - path identification number
2064 * trgcls - specifies target class
2065 * srccls - specifies the source message class
2066 * msgtag - specifies a tag to be associated with the message
2067 * flags1 - option for path
2068 * IPPRTY- specifies if you want to send priority message
2069 * prmmsg - 8-bytes of data to be placed in parameter list
2070 * ansbuf - address of buffer to reply with
2071 * anslen - length of buffer to reply with
2072 * Output: msgid - specifies the message ID.
2073 * Return: b2f0_result - return code from CP
2074 * (-EINVAL) - buffer address is NULL
2077 iucv_send2way_prmmsg (__u16 pathid,
2082 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2087 iucv_debug(2, "entering");
2092 parm = (iparml_dpl *)grab_param();
2094 parm->ippathid = pathid;
2095 parm->iptrgcls = trgcls;
2096 parm->ipsrccls = srccls;
2097 parm->ipmsgtag = msgtag;
2098 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2099 parm->ipbfln2f = (__u32) anslen;
2100 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2101 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2103 b2f0_result = b2f0(SEND, parm);
2105 if ((!b2f0_result) && (msgid))
2106 *msgid = parm->ipmsgid;
2107 release_param(parm);
2109 iucv_debug(2, "exiting");
2115 * Name: iucv_send2way_prmmsg_array
2116 * Purpose: This function transmits data to another application.
2117 * Prmmsg specifies that the 8-bytes of data are to be moved
2118 * into the parameter list. This is a two-way message and the
2119 * receiver of the message is expected to reply. A buffer
2120 * is provided into which IUCV moves the reply to this
2121 * message. The contents of ansbuf is the address of the
2122 * array of addresses and lengths of discontiguous buffers
2123 * that contain the reply.
2124 * Input: pathid - path identification number
2125 * trgcls - specifies target class
2126 * srccls - specifies the source message class
2127 * msgtag - specifies a tag to be associated with the message
2128 * flags1 - option for path
2129 * IPPRTY- specifies if you want to send priority message
2130 * prmmsg - 8-bytes of data to be placed into the parameter list
2131 * ansbuf - address of buffer to reply with
2132 * anslen - length of buffer to reply with
2133 * Output: msgid - specifies the message ID.
2134 * Return: b2f0_result - return code from CP
2135 * (-EINVAL) - ansbuf address is NULL
2138 iucv_send2way_prmmsg_array (__u16 pathid,
2145 iucv_array_t * ansbuf, ulong anslen)
2150 iucv_debug(2, "entering");
2155 parm = (iparml_dpl *)grab_param();
2157 parm->ippathid = pathid;
2158 parm->iptrgcls = trgcls;
2159 parm->ipsrccls = srccls;
2160 parm->ipmsgtag = msgtag;
2161 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2162 parm->ipbfln2f = (__u32) anslen;
2163 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2164 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2165 b2f0_result = b2f0(SEND, parm);
2166 if ((!b2f0_result) && (msgid))
2167 *msgid = parm->ipmsgid;
2168 release_param(parm);
2170 iucv_debug(2, "exiting");
2175 iucv_setmask_cpuid (void *result)
2177 iparml_set_mask *parm;
2179 iucv_debug(1, "entering");
2180 parm = (iparml_set_mask *)grab_param();
2181 parm->ipmask = *((__u8*)result);
2182 *((ulong *)result) = b2f0(SETMASK, parm);
2183 release_param(parm);
2185 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2186 iucv_debug(1, "exiting");
2190 * Name: iucv_setmask
2191 * Purpose: This function enables or disables the following IUCV
2192 * external interruptions: Nonpriority and priority message
2193 * interrupts, nonpriority and priority reply interrupts.
2194 * Input: SetMaskFlag - options for interrupts
2195 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2196 * 0x40 - Priority_MessagePendingInterruptsFlag
2197 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2198 * 0x10 - Priority_MessageCompletionInterruptsFlag
2199 * 0x08 - IUCVControlInterruptsFlag
2201 * Return: b2f0_result - return code from CP
2204 iucv_setmask (int SetMaskFlag)
2212 u.param = SetMaskFlag;
2214 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2222 * @pathid: Path identification number
2223 * @user_data: 16-byte of user data
2225 * This function terminates an iucv path.
2226 * Returns: return code from CP
2229 iucv_sever(__u16 pathid, __u8 user_data[16])
2231 iparml_control *parm;
2232 ulong b2f0_result = 0;
2234 iucv_debug(1, "entering");
2235 parm = (iparml_control *)grab_param();
2237 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2238 parm->ippathid = pathid;
2240 b2f0_result = b2f0(SEVER, parm);
2243 iucv_remove_pathid(pathid);
2244 release_param(parm);
2246 iucv_debug(1, "exiting");
2251 * Interrupt Handlers
2252 *******************************************************************************/
2256 * @regs: Current registers
2259 * Handles external interrupts coming in from CP.
2260 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2263 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2265 iucv_irqdata *irqdata;
2267 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2269 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2273 memcpy(&irqdata->data, iucv_external_int_buffer,
2274 sizeof(iucv_GeneralInterrupt));
2276 spin_lock(&iucv_irq_queue_lock);
2277 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2278 spin_unlock(&iucv_irq_queue_lock);
2280 tasklet_schedule(&iucv_tasklet);
2285 * @int_buf: Pointer to copy of external interrupt buffer
2287 * The workhorse for handling interrupts queued by iucv_irq_handler().
2288 * This function is called from the bottom half iucv_tasklet_handler().
2291 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2294 struct list_head *lh;
2296 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2297 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2299 __u8 no_listener[16] = "NO LISTENER";
2301 iucv_debug(2, "entering, pathid %d, type %02X",
2302 int_buf->ippathid, int_buf->iptype);
2303 iucv_dumpit("External Interrupt Buffer:",
2304 int_buf, sizeof(iucv_GeneralInterrupt));
2306 ASCEBC (no_listener, 16);
2308 if (int_buf->iptype != 01) {
2309 if ((int_buf->ippathid) > (max_connections - 1)) {
2310 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2311 " > max_connections (%ld)\n", __FUNCTION__,
2312 int_buf->ippathid, max_connections - 1);
2314 h = iucv_pathid_table[int_buf->ippathid];
2315 interrupt = h->interrupt_table;
2316 iucv_dumpit("Handler:", h, sizeof(handler));
2320 /* end of if statement */
2321 switch (int_buf->iptype) {
2322 case 0x01: /* connection pending */
2323 if (messagesDisabled) {
2325 messagesDisabled = 0;
2327 spin_lock_irqsave(&iucv_lock, flags);
2328 list_for_each(lh, &iucv_handler_table) {
2329 h = list_entry(lh, handler, list);
2330 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2331 memcpy(temp_buff2, &(h->id.userid), 24);
2332 for (j = 0; j < 24; j++) {
2333 temp_buff1[j] &= (h->id.mask)[j];
2334 temp_buff2[j] &= (h->id.mask)[j];
2337 iucv_dumpit("temp_buff1:",
2338 temp_buff1, sizeof(temp_buff1));
2339 iucv_dumpit("temp_buff2",
2340 temp_buff2, sizeof(temp_buff2));
2342 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2345 "found a matching handler");
2350 spin_unlock_irqrestore (&iucv_lock, flags);
2352 /* ADD PATH TO PATHID TABLE */
2353 rc = iucv_add_pathid(int_buf->ippathid, h);
2355 iucv_sever (int_buf->ippathid,
2358 "add_pathid failed, rc = %d",
2361 interrupt = h->interrupt_table;
2362 if (interrupt->ConnectionPending) {
2363 EBCASC (int_buf->ipvmid, 8);
2364 interrupt->ConnectionPending(
2365 (iucv_ConnectionPending *)int_buf,
2368 iucv_sever(int_buf->ippathid,
2372 iucv_sever(int_buf->ippathid, no_listener);
2375 case 0x02: /*connection complete */
2376 if (messagesDisabled) {
2378 messagesDisabled = 0;
2381 if (interrupt->ConnectionComplete)
2383 interrupt->ConnectionComplete(
2384 (iucv_ConnectionComplete *)int_buf,
2389 "ConnectionComplete not called");
2391 iucv_sever(int_buf->ippathid, no_listener);
2394 case 0x03: /* connection severed */
2395 if (messagesDisabled) {
2397 messagesDisabled = 0;
2400 if (interrupt->ConnectionSevered)
2401 interrupt->ConnectionSevered(
2402 (iucv_ConnectionSevered *)int_buf,
2406 iucv_sever (int_buf->ippathid, no_listener);
2408 iucv_sever(int_buf->ippathid, no_listener);
2411 case 0x04: /* connection quiesced */
2412 if (messagesDisabled) {
2414 messagesDisabled = 0;
2417 if (interrupt->ConnectionQuiesced)
2418 interrupt->ConnectionQuiesced(
2419 (iucv_ConnectionQuiesced *)int_buf,
2423 "ConnectionQuiesced not called");
2427 case 0x05: /* connection resumed */
2428 if (messagesDisabled) {
2430 messagesDisabled = 0;
2433 if (interrupt->ConnectionResumed)
2434 interrupt->ConnectionResumed(
2435 (iucv_ConnectionResumed *)int_buf,
2439 "ConnectionResumed not called");
2443 case 0x06: /* priority message complete */
2444 case 0x07: /* nonpriority message complete */
2446 if (interrupt->MessageComplete)
2447 interrupt->MessageComplete(
2448 (iucv_MessageComplete *)int_buf,
2452 "MessageComplete not called");
2456 case 0x08: /* priority message pending */
2457 case 0x09: /* nonpriority message pending */
2459 if (interrupt->MessagePending)
2460 interrupt->MessagePending(
2461 (iucv_MessagePending *) int_buf,
2465 "MessagePending not called");
2468 default: /* unknown iucv type */
2469 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2474 iucv_debug(2, "exiting pathid %d, type %02X",
2475 int_buf->ippathid, int_buf->iptype);
2481 * iucv_tasklet_handler:
2483 * This function loops over the queue of irq buffers and runs iucv_do_int()
2484 * on every queue element.
2487 iucv_tasklet_handler(unsigned long ignored)
2489 struct list_head head;
2490 struct list_head *next;
2493 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2494 list_add(&head, &iucv_irq_queue);
2495 list_del_init(&iucv_irq_queue);
2496 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2499 while (next != &head) {
2500 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2503 iucv_do_int(&p->data);
2510 subsys_initcall(iucv_init);
2511 module_exit(iucv_exit);
2514 * Export all public stuff
2516 EXPORT_SYMBOL (iucv_bus);
2517 EXPORT_SYMBOL (iucv_root);
2518 EXPORT_SYMBOL (iucv_accept);
2519 EXPORT_SYMBOL (iucv_connect);
2521 EXPORT_SYMBOL (iucv_purge);
2522 EXPORT_SYMBOL (iucv_query_maxconn);
2523 EXPORT_SYMBOL (iucv_query_bufsize);
2524 EXPORT_SYMBOL (iucv_quiesce);
2526 EXPORT_SYMBOL (iucv_receive);
2528 EXPORT_SYMBOL (iucv_receive_array);
2530 EXPORT_SYMBOL (iucv_reject);
2532 EXPORT_SYMBOL (iucv_reply);
2533 EXPORT_SYMBOL (iucv_reply_array);
2534 EXPORT_SYMBOL (iucv_resume);
2536 EXPORT_SYMBOL (iucv_reply_prmmsg);
2537 EXPORT_SYMBOL (iucv_send);
2538 EXPORT_SYMBOL (iucv_send2way);
2539 EXPORT_SYMBOL (iucv_send2way_array);
2540 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2541 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2543 EXPORT_SYMBOL (iucv_send_array);
2544 EXPORT_SYMBOL (iucv_send_prmmsg);
2545 EXPORT_SYMBOL (iucv_setmask);
2547 EXPORT_SYMBOL (iucv_sever);
2548 EXPORT_SYMBOL (iucv_register_program);
2549 EXPORT_SYMBOL (iucv_unregister_program);