[PATCH] kfree cleanup: drivers/s390
[deliverable/linux.git] / drivers / s390 / net / iucv.c
1 /*
2 * $Id: iucv.c,v 1.45 2005/04/26 22:59:06 braunu Exp $
3 *
4 * IUCV network driver
5 *
6 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s):
8 * Original source:
9 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
10 * Xenia Tkatschow (xenia@us.ibm.com)
11 * 2Gb awareness and general cleanup:
12 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
13 *
14 * Documentation used:
15 * The original source
16 * CP Programming Service, IBM document # SC24-5760
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *
32 * RELEASE-TAG: IUCV lowlevel driver $Revision: 1.45 $
33 *
34 */
35 \f
36 /* #define DEBUG */
37
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/config.h>
41
42 #include <linux/spinlock.h>
43 #include <linux/kernel.h>
44 #include <linux/slab.h>
45 #include <linux/init.h>
46 #include <linux/interrupt.h>
47 #include <linux/list.h>
48 #include <linux/errno.h>
49 #include <linux/err.h>
50 #include <linux/device.h>
51 #include <asm/atomic.h>
52 #include "iucv.h"
53 #include <asm/io.h>
54 #include <asm/s390_ext.h>
55 #include <asm/ebcdic.h>
56 #include <asm/smp.h>
57 #include <asm/ccwdev.h> //for root device stuff
58
59 /* FLAGS:
60 * All flags are defined in the field IPFLAGS1 of each function
61 * and can be found in CP Programming Services.
62 * IPSRCCLS - Indicates you have specified a source class
63 * IPFGMCL - Indicates you have specified a target class
64 * IPFGPID - Indicates you have specified a pathid
65 * IPFGMID - Indicates you have specified a message ID
66 * IPANSLST - Indicates that you are using an address list for
67 * reply data
68 * IPBUFLST - Indicates that you are using an address list for
69 * message data
70 */
71
72 #define IPSRCCLS 0x01
73 #define IPFGMCL 0x01
74 #define IPFGPID 0x02
75 #define IPFGMID 0x04
76 #define IPANSLST 0x08
77 #define IPBUFLST 0x40
78
79 static int
80 iucv_bus_match (struct device *dev, struct device_driver *drv)
81 {
82 return 0;
83 }
84
85 struct bus_type iucv_bus = {
86 .name = "iucv",
87 .match = iucv_bus_match,
88 };
89
90 struct device *iucv_root;
91
92 /* General IUCV interrupt structure */
93 typedef struct {
94 __u16 ippathid;
95 __u8 res1;
96 __u8 iptype;
97 __u32 res2;
98 __u8 ipvmid[8];
99 __u8 res3[24];
100 } iucv_GeneralInterrupt;
101
102 static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
103
104 /* Spin Lock declaration */
105
106 static DEFINE_SPINLOCK(iucv_lock);
107
108 static int messagesDisabled = 0;
109
110 /***************INTERRUPT HANDLING ***************/
111
112 typedef struct {
113 struct list_head queue;
114 iucv_GeneralInterrupt data;
115 } iucv_irqdata;
116
117 static struct list_head iucv_irq_queue;
118 static DEFINE_SPINLOCK(iucv_irq_queue_lock);
119
120 /*
121 *Internal function prototypes
122 */
123 static void iucv_tasklet_handler(unsigned long);
124 static void iucv_irq_handler(struct pt_regs *, __u16);
125
126 static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
127
128 /************ FUNCTION ID'S ****************************/
129
130 #define ACCEPT 10
131 #define CONNECT 11
132 #define DECLARE_BUFFER 12
133 #define PURGE 9
134 #define QUERY 0
135 #define QUIESCE 13
136 #define RECEIVE 5
137 #define REJECT 8
138 #define REPLY 6
139 #define RESUME 14
140 #define RETRIEVE_BUFFER 2
141 #define SEND 4
142 #define SETMASK 16
143 #define SEVER 15
144
145 /**
146 * Structure: handler
147 * members: list - list management.
148 * structure: id
149 * userid - 8 char array of machine identification
150 * user_data - 16 char array for user identification
151 * mask - 24 char array used to compare the 2 previous
152 * interrupt_table - vector of interrupt functions.
153 * pgm_data - ulong, application data that is passed
154 * to the interrupt handlers
155 */
156 typedef struct handler_t {
157 struct list_head list;
158 struct {
159 __u8 userid[8];
160 __u8 user_data[16];
161 __u8 mask[24];
162 } id;
163 iucv_interrupt_ops_t *interrupt_table;
164 void *pgm_data;
165 } handler;
166
167 /**
168 * iucv_handler_table: List of registered handlers.
169 */
170 static struct list_head iucv_handler_table;
171
172 /**
173 * iucv_pathid_table: an array of *handler pointing into
174 * iucv_handler_table for fast indexing by pathid;
175 */
176 static handler **iucv_pathid_table;
177
178 static unsigned long max_connections;
179
180 /**
181 * iucv_cpuid: contains the logical cpu number of the cpu which
182 * has declared the iucv buffer by issuing DECLARE_BUFFER.
183 * If no cpu has done the initialization iucv_cpuid contains -1.
184 */
185 static int iucv_cpuid = -1;
186 /**
187 * register_flag: is 0 when external interrupt has not been registered
188 */
189 static int register_flag;
190
191 /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
192 /* Data struct 1: iparml_control
193 * Used for iucv_accept
194 * iucv_connect
195 * iucv_quiesce
196 * iucv_resume
197 * iucv_sever
198 * iucv_retrieve_buffer
199 * Data struct 2: iparml_dpl (data in parameter list)
200 * Used for iucv_send_prmmsg
201 * iucv_send2way_prmmsg
202 * iucv_send2way_prmmsg_array
203 * iucv_reply_prmmsg
204 * Data struct 3: iparml_db (data in a buffer)
205 * Used for iucv_receive
206 * iucv_receive_array
207 * iucv_reject
208 * iucv_reply
209 * iucv_reply_array
210 * iucv_send
211 * iucv_send_array
212 * iucv_send2way
213 * iucv_send2way_array
214 * iucv_declare_buffer
215 * Data struct 4: iparml_purge
216 * Used for iucv_purge
217 * iucv_query
218 * Data struct 5: iparml_set_mask
219 * Used for iucv_set_mask
220 */
221
222 typedef struct {
223 __u16 ippathid;
224 __u8 ipflags1;
225 __u8 iprcode;
226 __u16 ipmsglim;
227 __u16 res1;
228 __u8 ipvmid[8];
229 __u8 ipuser[16];
230 __u8 iptarget[8];
231 } iparml_control;
232
233 typedef struct {
234 __u16 ippathid;
235 __u8 ipflags1;
236 __u8 iprcode;
237 __u32 ipmsgid;
238 __u32 iptrgcls;
239 __u8 iprmmsg[8];
240 __u32 ipsrccls;
241 __u32 ipmsgtag;
242 __u32 ipbfadr2;
243 __u32 ipbfln2f;
244 __u32 res;
245 } iparml_dpl;
246
247 typedef struct {
248 __u16 ippathid;
249 __u8 ipflags1;
250 __u8 iprcode;
251 __u32 ipmsgid;
252 __u32 iptrgcls;
253 __u32 ipbfadr1;
254 __u32 ipbfln1f;
255 __u32 ipsrccls;
256 __u32 ipmsgtag;
257 __u32 ipbfadr2;
258 __u32 ipbfln2f;
259 __u32 res;
260 } iparml_db;
261
262 typedef struct {
263 __u16 ippathid;
264 __u8 ipflags1;
265 __u8 iprcode;
266 __u32 ipmsgid;
267 __u8 ipaudit[3];
268 __u8 res1[5];
269 __u32 res2;
270 __u32 ipsrccls;
271 __u32 ipmsgtag;
272 __u32 res3[3];
273 } iparml_purge;
274
275 typedef struct {
276 __u8 ipmask;
277 __u8 res1[2];
278 __u8 iprcode;
279 __u32 res2[9];
280 } iparml_set_mask;
281
282 typedef struct {
283 union {
284 iparml_control p_ctrl;
285 iparml_dpl p_dpl;
286 iparml_db p_db;
287 iparml_purge p_purge;
288 iparml_set_mask p_set_mask;
289 } param;
290 atomic_t in_use;
291 __u32 res;
292 } __attribute__ ((aligned(8))) iucv_param;
293 #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
294
295 static iucv_param * iucv_param_pool;
296
297 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
298 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
299 MODULE_LICENSE("GPL");
300
301 /*
302 * Debugging stuff
303 *******************************************************************************/
304 \f
305
306 #ifdef DEBUG
307 static int debuglevel = 0;
308
309 module_param(debuglevel, int, 0);
310 MODULE_PARM_DESC(debuglevel,
311 "Specifies the debug level (0=off ... 3=all)");
312
313 static void
314 iucv_dumpit(char *title, void *buf, int len)
315 {
316 int i;
317 __u8 *p = (__u8 *)buf;
318
319 if (debuglevel < 3)
320 return;
321
322 printk(KERN_DEBUG "%s\n", title);
323 printk(" ");
324 for (i = 0; i < len; i++) {
325 if (!(i % 16) && i != 0)
326 printk ("\n ");
327 else if (!(i % 4) && i != 0)
328 printk(" ");
329 printk("%02X", *p++);
330 }
331 if (len % 16)
332 printk ("\n");
333 return;
334 }
335 #define iucv_debug(lvl, fmt, args...) \
336 do { \
337 if (debuglevel >= lvl) \
338 printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
339 } while (0)
340
341 #else
342
343 #define iucv_debug(lvl, fmt, args...)
344 #define iucv_dumpit(title, buf, len)
345
346 #endif
347
348 /*
349 * Internal functions
350 *******************************************************************************/
351 \f
352 /**
353 * print start banner
354 */
355 static void
356 iucv_banner(void)
357 {
358 char vbuf[] = "$Revision: 1.45 $";
359 char *version = vbuf;
360
361 if ((version = strchr(version, ':'))) {
362 char *p = strchr(version + 1, '$');
363 if (p)
364 *p = '\0';
365 } else
366 version = " ??? ";
367 printk(KERN_INFO
368 "IUCV lowlevel driver Version%s initialized\n", version);
369 }
370
371 /**
372 * iucv_init - Initialization
373 *
374 * Allocates and initializes various data structures.
375 */
376 static int
377 iucv_init(void)
378 {
379 int ret;
380
381 if (iucv_external_int_buffer)
382 return 0;
383
384 if (!MACHINE_IS_VM) {
385 printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
386 return -EPROTONOSUPPORT;
387 }
388
389 ret = bus_register(&iucv_bus);
390 if (ret) {
391 printk(KERN_ERR "IUCV: failed to register bus.\n");
392 return ret;
393 }
394
395 iucv_root = s390_root_dev_register("iucv");
396 if (IS_ERR(iucv_root)) {
397 printk(KERN_ERR "IUCV: failed to register iucv root.\n");
398 bus_unregister(&iucv_bus);
399 return PTR_ERR(iucv_root);
400 }
401
402 /* Note: GFP_DMA used used to get memory below 2G */
403 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt),
404 GFP_KERNEL|GFP_DMA);
405 if (!iucv_external_int_buffer) {
406 printk(KERN_WARNING
407 "%s: Could not allocate external interrupt buffer\n",
408 __FUNCTION__);
409 s390_root_dev_unregister(iucv_root);
410 bus_unregister(&iucv_bus);
411 return -ENOMEM;
412 }
413 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
414
415 /* Initialize parameter pool */
416 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
417 GFP_KERNEL|GFP_DMA);
418 if (!iucv_param_pool) {
419 printk(KERN_WARNING "%s: Could not allocate param pool\n",
420 __FUNCTION__);
421 kfree(iucv_external_int_buffer);
422 iucv_external_int_buffer = NULL;
423 s390_root_dev_unregister(iucv_root);
424 bus_unregister(&iucv_bus);
425 return -ENOMEM;
426 }
427 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
428
429 /* Initialize irq queue */
430 INIT_LIST_HEAD(&iucv_irq_queue);
431
432 /* Initialize handler table */
433 INIT_LIST_HEAD(&iucv_handler_table);
434
435 iucv_banner();
436 return 0;
437 }
438
439 /**
440 * iucv_exit - De-Initialization
441 *
442 * Frees everything allocated from iucv_init.
443 */
444 static int iucv_retrieve_buffer (void);
445
446 static void
447 iucv_exit(void)
448 {
449 iucv_retrieve_buffer();
450 kfree(iucv_external_int_buffer);
451 iucv_external_int_buffer = NULL;
452 kfree(iucv_param_pool);
453 iucv_param_pool = NULL;
454 s390_root_dev_unregister(iucv_root);
455 bus_unregister(&iucv_bus);
456 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
457 }
458
459 /**
460 * grab_param: - Get a parameter buffer from the pre-allocated pool.
461 *
462 * This function searches for an unused element in the pre-allocated pool
463 * of parameter buffers. If one is found, it marks it "in use" and returns
464 * a pointer to it. The calling function is responsible for releasing it
465 * when it has finished its usage.
466 *
467 * Returns: A pointer to iucv_param.
468 */
469 static __inline__ iucv_param *
470 grab_param(void)
471 {
472 iucv_param *ptr;
473 static int hint = 0;
474
475 ptr = iucv_param_pool + hint;
476 do {
477 ptr++;
478 if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
479 ptr = iucv_param_pool;
480 } while (atomic_compare_and_swap(0, 1, &ptr->in_use));
481 hint = ptr - iucv_param_pool;
482
483 memset(&ptr->param, 0, sizeof(ptr->param));
484 return ptr;
485 }
486
487 /**
488 * release_param - Release a parameter buffer.
489 * @p: A pointer to a struct iucv_param, previously obtained by calling
490 * grab_param().
491 *
492 * This function marks the specified parameter buffer "unused".
493 */
494 static __inline__ void
495 release_param(void *p)
496 {
497 atomic_set(&((iucv_param *)p)->in_use, 0);
498 }
499
500 /**
501 * iucv_add_handler: - Add a new handler
502 * @new_handler: handle that is being entered into chain.
503 *
504 * Places new handle on iucv_handler_table, if identical handler is not
505 * found.
506 *
507 * Returns: 0 on success, !0 on failure (handler already in chain).
508 */
509 static int
510 iucv_add_handler (handler *new)
511 {
512 ulong flags;
513
514 iucv_debug(1, "entering");
515 iucv_dumpit("handler:", new, sizeof(handler));
516
517 spin_lock_irqsave (&iucv_lock, flags);
518 if (!list_empty(&iucv_handler_table)) {
519 struct list_head *lh;
520
521 /**
522 * Search list for handler with identical id. If one
523 * is found, the new handler is _not_ added.
524 */
525 list_for_each(lh, &iucv_handler_table) {
526 handler *h = list_entry(lh, handler, list);
527 if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
528 iucv_debug(1, "ret 1");
529 spin_unlock_irqrestore (&iucv_lock, flags);
530 return 1;
531 }
532 }
533 }
534 /**
535 * If we get here, no handler was found.
536 */
537 INIT_LIST_HEAD(&new->list);
538 list_add(&new->list, &iucv_handler_table);
539 spin_unlock_irqrestore (&iucv_lock, flags);
540
541 iucv_debug(1, "exiting");
542 return 0;
543 }
544
545 /**
546 * b2f0:
547 * @code: identifier of IUCV call to CP.
548 * @parm: pointer to 40 byte iparml area passed to CP
549 *
550 * Calls CP to execute IUCV commands.
551 *
552 * Returns: return code from CP's IUCV call
553 */
554 static __inline__ ulong
555 b2f0(__u32 code, void *parm)
556 {
557 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
558
559 asm volatile (
560 "LRA 1,0(%1)\n\t"
561 "LR 0,%0\n\t"
562 ".long 0xb2f01000"
563 :
564 : "d" (code), "a" (parm)
565 : "0", "1"
566 );
567
568 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
569
570 return (unsigned long)*((__u8 *)(parm + 3));
571 }
572
573 /*
574 * Name: iucv_add_pathid
575 * Purpose: Adds a path id to the system.
576 * Input: pathid - pathid that is going to be entered into system
577 * handle - address of handler that the pathid will be associated
578 * with.
579 * pgm_data - token passed in by application.
580 * Output: 0: successful addition of pathid
581 * - EINVAL - pathid entry is being used by another application
582 * - ENOMEM - storage allocation for a new pathid table failed
583 */
584 static int
585 __iucv_add_pathid(__u16 pathid, handler *handler)
586 {
587
588 iucv_debug(1, "entering");
589
590 iucv_debug(1, "handler is pointing to %p", handler);
591
592 if (pathid > (max_connections - 1))
593 return -EINVAL;
594
595 if (iucv_pathid_table[pathid]) {
596 iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
597 printk(KERN_WARNING
598 "%s: Pathid being used, error.\n", __FUNCTION__);
599 return -EINVAL;
600 }
601 iucv_pathid_table[pathid] = handler;
602
603 iucv_debug(1, "exiting");
604 return 0;
605 } /* end of add_pathid function */
606
607 static int
608 iucv_add_pathid(__u16 pathid, handler *handler)
609 {
610 ulong flags;
611 int rc;
612
613 spin_lock_irqsave (&iucv_lock, flags);
614 rc = __iucv_add_pathid(pathid, handler);
615 spin_unlock_irqrestore (&iucv_lock, flags);
616 return rc;
617 }
618
619 static void
620 iucv_remove_pathid(__u16 pathid)
621 {
622 ulong flags;
623
624 if (pathid > (max_connections - 1))
625 return;
626
627 spin_lock_irqsave (&iucv_lock, flags);
628 iucv_pathid_table[pathid] = NULL;
629 spin_unlock_irqrestore (&iucv_lock, flags);
630 }
631
632 /**
633 * iucv_declare_buffer_cpuid
634 * Register at VM for subsequent IUCV operations. This is executed
635 * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
636 */
637 static void
638 iucv_declare_buffer_cpuid (void *result)
639 {
640 iparml_db *parm;
641
642 parm = (iparml_db *)grab_param();
643 parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
644 if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
645 *((ulong *)result) = parm->iprcode;
646 release_param(parm);
647 }
648
649 /**
650 * iucv_retrieve_buffer_cpuid:
651 * Unregister IUCV usage at VM. This is always executed on the same
652 * cpu that registered the buffer to VM.
653 * Called from iucv_retrieve_buffer().
654 */
655 static void
656 iucv_retrieve_buffer_cpuid (void *cpu)
657 {
658 iparml_control *parm;
659
660 parm = (iparml_control *)grab_param();
661 b2f0(RETRIEVE_BUFFER, parm);
662 release_param(parm);
663 }
664
665 /**
666 * Name: iucv_declare_buffer
667 * Purpose: Specifies the guests real address of an external
668 * interrupt.
669 * Input: void
670 * Output: iprcode - return code from b2f0 call
671 */
672 static int
673 iucv_declare_buffer (void)
674 {
675 unsigned long flags;
676 ulong b2f0_result;
677
678 iucv_debug(1, "entering");
679 b2f0_result = -ENODEV;
680 spin_lock_irqsave (&iucv_lock, flags);
681 if (iucv_cpuid == -1) {
682 /* Reserve any cpu for use by iucv. */
683 iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
684 spin_unlock_irqrestore (&iucv_lock, flags);
685 smp_call_function_on(iucv_declare_buffer_cpuid,
686 &b2f0_result, 0, 1, iucv_cpuid);
687 if (b2f0_result) {
688 smp_put_cpu(iucv_cpuid);
689 iucv_cpuid = -1;
690 }
691 iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
692 } else {
693 spin_unlock_irqrestore (&iucv_lock, flags);
694 b2f0_result = 0;
695 }
696 iucv_debug(1, "exiting");
697 return b2f0_result;
698 }
699
700 /**
701 * iucv_retrieve_buffer:
702 *
703 * Terminates all use of IUCV.
704 * Returns: return code from CP
705 */
706 static int
707 iucv_retrieve_buffer (void)
708 {
709 iucv_debug(1, "entering");
710 if (iucv_cpuid != -1) {
711 smp_call_function_on(iucv_retrieve_buffer_cpuid,
712 0, 0, 1, iucv_cpuid);
713 /* Release the cpu reserved by iucv_declare_buffer. */
714 smp_put_cpu(iucv_cpuid);
715 iucv_cpuid = -1;
716 }
717 iucv_debug(1, "exiting");
718 return 0;
719 }
720
721 /**
722 * iucv_remove_handler:
723 * @users_handler: handler to be removed
724 *
725 * Remove handler when application unregisters.
726 */
727 static void
728 iucv_remove_handler(handler *handler)
729 {
730 unsigned long flags;
731
732 if ((!iucv_pathid_table) || (!handler))
733 return;
734
735 iucv_debug(1, "entering");
736
737 spin_lock_irqsave (&iucv_lock, flags);
738 list_del(&handler->list);
739 if (list_empty(&iucv_handler_table)) {
740 if (register_flag) {
741 unregister_external_interrupt(0x4000, iucv_irq_handler);
742 register_flag = 0;
743 }
744 }
745 spin_unlock_irqrestore (&iucv_lock, flags);
746
747 iucv_debug(1, "exiting");
748 return;
749 }
750
751 /**
752 * iucv_register_program:
753 * @pgmname: user identification
754 * @userid: machine identification
755 * @pgmmask: Indicates which bits in the pgmname and userid combined will be
756 * used to determine who is given control.
757 * @ops: Address of interrupt handler table.
758 * @pgm_data: Application data to be passed to interrupt handlers.
759 *
760 * Registers an application with IUCV.
761 * Returns:
762 * The address of handler, or NULL on failure.
763 * NOTE on pgmmask:
764 * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
765 * handler as is.
766 * If pgmmask is NULL, the internal mask is set to all 0xff's
767 * When userid is NULL, the first 8 bytes of the internal mask are forced
768 * to 0x00.
769 * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
770 * are forced to 0x00 and the last 16 bytes to 0xff.
771 */
772
773 iucv_handle_t
774 iucv_register_program (__u8 pgmname[16],
775 __u8 userid[8],
776 __u8 pgmmask[24],
777 iucv_interrupt_ops_t * ops, void *pgm_data)
778 {
779 ulong rc = 0; /* return code from function calls */
780 handler *new_handler;
781
782 iucv_debug(1, "entering");
783
784 if (ops == NULL) {
785 /* interrupt table is not defined */
786 printk(KERN_WARNING "%s: Interrupt table is not defined, "
787 "exiting\n", __FUNCTION__);
788 return NULL;
789 }
790 if (!pgmname) {
791 printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
792 return NULL;
793 }
794
795 /* Allocate handler entry */
796 new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
797 if (new_handler == NULL) {
798 printk(KERN_WARNING "%s: storage allocation for new handler "
799 "failed.\n", __FUNCTION__);
800 return NULL;
801 }
802
803 if (!iucv_pathid_table) {
804 if (iucv_init()) {
805 kfree(new_handler);
806 return NULL;
807 }
808
809 max_connections = iucv_query_maxconn();
810 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *),
811 GFP_ATOMIC);
812 if (iucv_pathid_table == NULL) {
813 printk(KERN_WARNING "%s: iucv_pathid_table storage "
814 "allocation failed\n", __FUNCTION__);
815 kfree(new_handler);
816 return NULL;
817 }
818 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
819 }
820 memset(new_handler, 0, sizeof (handler));
821 memcpy(new_handler->id.user_data, pgmname,
822 sizeof (new_handler->id.user_data));
823 if (userid) {
824 memcpy (new_handler->id.userid, userid,
825 sizeof (new_handler->id.userid));
826 ASCEBC (new_handler->id.userid,
827 sizeof (new_handler->id.userid));
828 EBC_TOUPPER (new_handler->id.userid,
829 sizeof (new_handler->id.userid));
830
831 if (pgmmask) {
832 memcpy (new_handler->id.mask, pgmmask,
833 sizeof (new_handler->id.mask));
834 } else {
835 memset (new_handler->id.mask, 0xFF,
836 sizeof (new_handler->id.mask));
837 }
838 } else {
839 if (pgmmask) {
840 memcpy (new_handler->id.mask, pgmmask,
841 sizeof (new_handler->id.mask));
842 } else {
843 memset (new_handler->id.mask, 0xFF,
844 sizeof (new_handler->id.mask));
845 }
846 memset (new_handler->id.userid, 0x00,
847 sizeof (new_handler->id.userid));
848 }
849 /* fill in the rest of handler */
850 new_handler->pgm_data = pgm_data;
851 new_handler->interrupt_table = ops;
852
853 /*
854 * Check if someone else is registered with same pgmname, userid
855 * and mask. If someone is already registered with same pgmname,
856 * userid and mask, registration will fail and NULL will be returned
857 * to the application.
858 * If identical handler not found, then handler is added to list.
859 */
860 rc = iucv_add_handler(new_handler);
861 if (rc) {
862 printk(KERN_WARNING "%s: Someone already registered with same "
863 "pgmname, userid, pgmmask\n", __FUNCTION__);
864 kfree (new_handler);
865 return NULL;
866 }
867
868 rc = iucv_declare_buffer();
869 if (rc) {
870 char *err = "Unknown";
871 iucv_remove_handler(new_handler);
872 kfree(new_handler);
873 switch(rc) {
874 case 0x03:
875 err = "Directory error";
876 break;
877 case 0x0a:
878 err = "Invalid length";
879 break;
880 case 0x13:
881 err = "Buffer already exists";
882 break;
883 case 0x3e:
884 err = "Buffer overlap";
885 break;
886 case 0x5c:
887 err = "Paging or storage error";
888 break;
889 }
890 printk(KERN_WARNING "%s: iucv_declare_buffer "
891 "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
892 return NULL;
893 }
894 if (!register_flag) {
895 /* request the 0x4000 external interrupt */
896 rc = register_external_interrupt (0x4000, iucv_irq_handler);
897 if (rc) {
898 iucv_remove_handler(new_handler);
899 kfree (new_handler);
900 printk(KERN_WARNING "%s: "
901 "register_external_interrupt returned %ld\n",
902 __FUNCTION__, rc);
903 return NULL;
904
905 }
906 register_flag = 1;
907 }
908 iucv_debug(1, "exiting");
909 return new_handler;
910 } /* end of register function */
911
912 /**
913 * iucv_unregister_program:
914 * @handle: address of handler
915 *
916 * Unregister application with IUCV.
917 * Returns:
918 * 0 on success, -EINVAL, if specified handle is invalid.
919 */
920
921 int
922 iucv_unregister_program (iucv_handle_t handle)
923 {
924 handler *h = NULL;
925 struct list_head *lh;
926 int i;
927 ulong flags;
928
929 iucv_debug(1, "entering");
930 iucv_debug(1, "address of handler is %p", h);
931
932 /* Checking if handle is valid */
933 spin_lock_irqsave (&iucv_lock, flags);
934 list_for_each(lh, &iucv_handler_table) {
935 if ((handler *)handle == list_entry(lh, handler, list)) {
936 h = (handler *)handle;
937 break;
938 }
939 }
940 if (!h) {
941 spin_unlock_irqrestore (&iucv_lock, flags);
942 if (handle)
943 printk(KERN_WARNING
944 "%s: Handler not found in iucv_handler_table.\n",
945 __FUNCTION__);
946 else
947 printk(KERN_WARNING
948 "%s: NULL handle passed by application.\n",
949 __FUNCTION__);
950 return -EINVAL;
951 }
952
953 /**
954 * First, walk thru iucv_pathid_table and sever any pathid which is
955 * still pointing to the handler to be removed.
956 */
957 for (i = 0; i < max_connections; i++)
958 if (iucv_pathid_table[i] == h) {
959 spin_unlock_irqrestore (&iucv_lock, flags);
960 iucv_sever(i, h->id.user_data);
961 spin_lock_irqsave(&iucv_lock, flags);
962 }
963 spin_unlock_irqrestore (&iucv_lock, flags);
964
965 iucv_remove_handler(h);
966 kfree(h);
967
968 iucv_debug(1, "exiting");
969 return 0;
970 }
971
972 /**
973 * iucv_accept:
974 * @pathid: Path identification number
975 * @msglim_reqstd: The number of outstanding messages requested.
976 * @user_data: Data specified by the iucv_connect function.
977 * @flags1: Contains options for this path.
978 * - IPPRTY (0x20) Specifies if you want to send priority message.
979 * - IPRMDATA (0x80) Specifies whether your program can handle a message
980 * in the parameter list.
981 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
982 * established.
983 * @handle: Address of handler.
984 * @pgm_data: Application data passed to interrupt handlers.
985 * @flags1_out: Pointer to an int. If not NULL, on return the options for
986 * the path are stored at the given location:
987 * - IPPRTY (0x20) Indicates you may send a priority message.
988 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
989 * number of outstanding messages is stored at the given
990 * location.
991 *
992 * This function is issued after the user receives a Connection Pending external
993 * interrupt and now wishes to complete the IUCV communication path.
994 * Returns:
995 * return code from CP
996 */
997 int
998 iucv_accept(__u16 pathid, __u16 msglim_reqstd,
999 __u8 user_data[16], int flags1,
1000 iucv_handle_t handle, void *pgm_data,
1001 int *flags1_out, __u16 * msglim)
1002 {
1003 ulong b2f0_result = 0;
1004 ulong flags;
1005 struct list_head *lh;
1006 handler *h = NULL;
1007 iparml_control *parm;
1008
1009 iucv_debug(1, "entering");
1010 iucv_debug(1, "pathid = %d", pathid);
1011
1012 /* Checking if handle is valid */
1013 spin_lock_irqsave (&iucv_lock, flags);
1014 list_for_each(lh, &iucv_handler_table) {
1015 if ((handler *)handle == list_entry(lh, handler, list)) {
1016 h = (handler *)handle;
1017 break;
1018 }
1019 }
1020 spin_unlock_irqrestore (&iucv_lock, flags);
1021
1022 if (!h) {
1023 if (handle)
1024 printk(KERN_WARNING
1025 "%s: Handler not found in iucv_handler_table.\n",
1026 __FUNCTION__);
1027 else
1028 printk(KERN_WARNING
1029 "%s: NULL handle passed by application.\n",
1030 __FUNCTION__);
1031 return -EINVAL;
1032 }
1033
1034 parm = (iparml_control *)grab_param();
1035
1036 parm->ippathid = pathid;
1037 parm->ipmsglim = msglim_reqstd;
1038 if (user_data)
1039 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1040
1041 parm->ipflags1 = (__u8)flags1;
1042 b2f0_result = b2f0(ACCEPT, parm);
1043
1044 if (!b2f0_result) {
1045 if (msglim)
1046 *msglim = parm->ipmsglim;
1047 if (pgm_data)
1048 h->pgm_data = pgm_data;
1049 if (flags1_out)
1050 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1051 }
1052 release_param(parm);
1053
1054 iucv_debug(1, "exiting");
1055 return b2f0_result;
1056 }
1057
1058 /**
1059 * iucv_connect:
1060 * @pathid: Path identification number
1061 * @msglim_reqstd: Number of outstanding messages requested
1062 * @user_data: 16-byte user data
1063 * @userid: 8-byte of user identification
1064 * @system_name: 8-byte identifying the system name
1065 * @flags1: Specifies options for this path:
1066 * - IPPRTY (0x20) Specifies if you want to send priority message.
1067 * - IPRMDATA (0x80) Specifies whether your program can handle a message
1068 * in the parameter list.
1069 * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
1070 * established.
1071 * - IPLOCAL (0x01) Allows an application to force the partner to be on the
1072 * local system. If local is specified then target class
1073 * cannot be specified.
1074 * @flags1_out: Pointer to an int. If not NULL, on return the options for
1075 * the path are stored at the given location:
1076 * - IPPRTY (0x20) Indicates you may send a priority message.
1077 * @msglim: Pointer to an __u16. If not NULL, on return the maximum
1078 * number of outstanding messages is stored at the given
1079 * location.
1080 * @handle: Address of handler.
1081 * @pgm_data: Application data to be passed to interrupt handlers.
1082 *
1083 * This function establishes an IUCV path. Although the connect may complete
1084 * successfully, you are not able to use the path until you receive an IUCV
1085 * Connection Complete external interrupt.
1086 * Returns: return code from CP, or one of the following
1087 * - ENOMEM
1088 * - return code from iucv_declare_buffer
1089 * - EINVAL - invalid handle passed by application
1090 * - EINVAL - pathid address is NULL
1091 * - ENOMEM - pathid table storage allocation failed
1092 * - return code from internal function add_pathid
1093 */
1094 int
1095 iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
1096 __u8 user_data[16], __u8 userid[8],
1097 __u8 system_name[8], int flags1,
1098 int *flags1_out, __u16 * msglim,
1099 iucv_handle_t handle, void *pgm_data)
1100 {
1101 iparml_control *parm;
1102 iparml_control local_parm;
1103 struct list_head *lh;
1104 ulong b2f0_result = 0;
1105 ulong flags;
1106 int add_pathid_result = 0;
1107 handler *h = NULL;
1108 __u8 no_memory[16] = "NO MEMORY";
1109
1110 iucv_debug(1, "entering");
1111
1112 /* Checking if handle is valid */
1113 spin_lock_irqsave (&iucv_lock, flags);
1114 list_for_each(lh, &iucv_handler_table) {
1115 if ((handler *)handle == list_entry(lh, handler, list)) {
1116 h = (handler *)handle;
1117 break;
1118 }
1119 }
1120 spin_unlock_irqrestore (&iucv_lock, flags);
1121
1122 if (!h) {
1123 if (handle)
1124 printk(KERN_WARNING
1125 "%s: Handler not found in iucv_handler_table.\n",
1126 __FUNCTION__);
1127 else
1128 printk(KERN_WARNING
1129 "%s: NULL handle passed by application.\n",
1130 __FUNCTION__);
1131 return -EINVAL;
1132 }
1133
1134 if (pathid == NULL) {
1135 printk(KERN_WARNING "%s: NULL pathid pointer\n",
1136 __FUNCTION__);
1137 return -EINVAL;
1138 }
1139
1140 parm = (iparml_control *)grab_param();
1141
1142 parm->ipmsglim = msglim_reqstd;
1143
1144 if (user_data)
1145 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1146
1147 if (userid) {
1148 memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
1149 ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
1150 EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
1151 }
1152
1153 if (system_name) {
1154 memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
1155 ASCEBC(parm->iptarget, sizeof(parm->iptarget));
1156 EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
1157 }
1158
1159 /* In order to establish an IUCV connection, the procedure is:
1160 *
1161 * b2f0(CONNECT)
1162 * take the ippathid from the b2f0 call
1163 * register the handler to the ippathid
1164 *
1165 * Unfortunately, the ConnectionEstablished message gets sent after the
1166 * b2f0(CONNECT) call but before the register is handled.
1167 *
1168 * In order for this race condition to be eliminated, the IUCV Control
1169 * Interrupts must be disabled for the above procedure.
1170 *
1171 * David Kennedy <dkennedy@linuxcare.com>
1172 */
1173
1174 /* Enable everything but IUCV Control messages */
1175 iucv_setmask(~(AllInterrupts));
1176 messagesDisabled = 1;
1177
1178 spin_lock_irqsave (&iucv_lock, flags);
1179 parm->ipflags1 = (__u8)flags1;
1180 b2f0_result = b2f0(CONNECT, parm);
1181 memcpy(&local_parm, parm, sizeof(local_parm));
1182 release_param(parm);
1183 parm = &local_parm;
1184 if (!b2f0_result)
1185 add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
1186 spin_unlock_irqrestore (&iucv_lock, flags);
1187
1188 if (b2f0_result) {
1189 iucv_setmask(~0);
1190 messagesDisabled = 0;
1191 return b2f0_result;
1192 }
1193
1194 *pathid = parm->ippathid;
1195
1196 /* Enable everything again */
1197 iucv_setmask(IUCVControlInterruptsFlag);
1198
1199 if (msglim)
1200 *msglim = parm->ipmsglim;
1201 if (flags1_out)
1202 *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
1203
1204 if (add_pathid_result) {
1205 iucv_sever(*pathid, no_memory);
1206 printk(KERN_WARNING "%s: add_pathid failed with rc ="
1207 " %d\n", __FUNCTION__, add_pathid_result);
1208 return(add_pathid_result);
1209 }
1210
1211 iucv_debug(1, "exiting");
1212 return b2f0_result;
1213 }
1214
1215 /**
1216 * iucv_purge:
1217 * @pathid: Path identification number
1218 * @msgid: Message ID of message to purge.
1219 * @srccls: Message class of the message to purge.
1220 * @audit: Pointer to an __u32. If not NULL, on return, information about
1221 * asynchronous errors that may have affected the normal completion
1222 * of this message ist stored at the given location.
1223 *
1224 * Cancels a message you have sent.
1225 * Returns: return code from CP
1226 */
1227 int
1228 iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1229 {
1230 iparml_purge *parm;
1231 ulong b2f0_result = 0;
1232
1233 iucv_debug(1, "entering");
1234 iucv_debug(1, "pathid = %d", pathid);
1235
1236 parm = (iparml_purge *)grab_param();
1237
1238 parm->ipmsgid = msgid;
1239 parm->ippathid = pathid;
1240 parm->ipsrccls = srccls;
1241 parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
1242 b2f0_result = b2f0(PURGE, parm);
1243
1244 if (!b2f0_result && audit) {
1245 memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
1246 /* parm->ipaudit has only 3 bytes */
1247 *audit >>= 8;
1248 }
1249
1250 release_param(parm);
1251
1252 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1253 iucv_debug(1, "exiting");
1254 return b2f0_result;
1255 }
1256
1257 /**
1258 * iucv_query_generic:
1259 * @want_maxconn: Flag, describing which value is to be returned.
1260 *
1261 * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
1262 *
1263 * Returns: The buffersize, if want_maxconn is 0; the maximum number of
1264 * connections, if want_maxconn is 1 or an error-code < 0 on failure.
1265 */
1266 static int
1267 iucv_query_generic(int want_maxconn)
1268 {
1269 iparml_purge *parm = (iparml_purge *)grab_param();
1270 int bufsize, maxconn;
1271 int ccode;
1272
1273 /**
1274 * Call b2f0 and store R0 (max buffer size),
1275 * R1 (max connections) and CC.
1276 */
1277 asm volatile (
1278 "LRA 1,0(%4)\n\t"
1279 "LR 0,%3\n\t"
1280 ".long 0xb2f01000\n\t"
1281 "IPM %0\n\t"
1282 "SRL %0,28\n\t"
1283 "ST 0,%1\n\t"
1284 "ST 1,%2\n\t"
1285 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
1286 : "d" (QUERY), "a" (parm)
1287 : "0", "1", "cc"
1288 );
1289 release_param(parm);
1290
1291 if (ccode)
1292 return -EPERM;
1293 if (want_maxconn)
1294 return maxconn;
1295 return bufsize;
1296 }
1297
1298 /**
1299 * iucv_query_maxconn:
1300 *
1301 * Determines the maximum number of connections thay may be established.
1302 *
1303 * Returns: Maximum number of connections that can be.
1304 */
1305 ulong
1306 iucv_query_maxconn(void)
1307 {
1308 return iucv_query_generic(1);
1309 }
1310
1311 /**
1312 * iucv_query_bufsize:
1313 *
1314 * Determines the size of the external interrupt buffer.
1315 *
1316 * Returns: Size of external interrupt buffer.
1317 */
1318 ulong
1319 iucv_query_bufsize (void)
1320 {
1321 return iucv_query_generic(0);
1322 }
1323
1324 /**
1325 * iucv_quiesce:
1326 * @pathid: Path identification number
1327 * @user_data: 16-byte user data
1328 *
1329 * Temporarily suspends incoming messages on an IUCV path.
1330 * You can later reactivate the path by invoking the iucv_resume function.
1331 * Returns: return code from CP
1332 */
1333 int
1334 iucv_quiesce (__u16 pathid, __u8 user_data[16])
1335 {
1336 iparml_control *parm;
1337 ulong b2f0_result = 0;
1338
1339 iucv_debug(1, "entering");
1340 iucv_debug(1, "pathid = %d", pathid);
1341
1342 parm = (iparml_control *)grab_param();
1343
1344 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
1345 parm->ippathid = pathid;
1346
1347 b2f0_result = b2f0(QUIESCE, parm);
1348 release_param(parm);
1349
1350 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1351 iucv_debug(1, "exiting");
1352
1353 return b2f0_result;
1354 }
1355
1356 /**
1357 * iucv_receive:
1358 * @pathid: Path identification number.
1359 * @buffer: Address of buffer to receive. Must be below 2G.
1360 * @buflen: Length of buffer to receive.
1361 * @msgid: Specifies the message ID.
1362 * @trgcls: Specifies target class.
1363 * @flags1_out: Receives options for path on return.
1364 * - IPNORPY (0x10) Specifies whether a reply is required
1365 * - IPPRTY (0x20) Specifies if you want to send priority message
1366 * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
1367 * @residual_buffer: Receives the address of buffer updated by the number
1368 * of bytes you have received on return.
1369 * @residual_length: On return, receives one of the following values:
1370 * - 0 If the receive buffer is the same length as
1371 * the message.
1372 * - Remaining bytes in buffer If the receive buffer is longer than the
1373 * message.
1374 * - Remaining bytes in message If the receive buffer is shorter than the
1375 * message.
1376 *
1377 * This function receives messages that are being sent to you over established
1378 * paths.
1379 * Returns: return code from CP IUCV call; If the receive buffer is shorter
1380 * than the message, always 5
1381 * -EINVAL - buffer address is pointing to NULL
1382 */
1383 int
1384 iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
1385 void *buffer, ulong buflen,
1386 int *flags1_out, ulong * residual_buffer, ulong * residual_length)
1387 {
1388 iparml_db *parm;
1389 ulong b2f0_result;
1390 int moved = 0; /* number of bytes moved from parmlist to buffer */
1391
1392 iucv_debug(2, "entering");
1393
1394 if (!buffer)
1395 return -EINVAL;
1396
1397 parm = (iparml_db *)grab_param();
1398
1399 parm->ipbfadr1 = (__u32) (addr_t) buffer;
1400 parm->ipbfln1f = (__u32) ((ulong) buflen);
1401 parm->ipmsgid = msgid;
1402 parm->ippathid = pathid;
1403 parm->iptrgcls = trgcls;
1404 parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
1405
1406 b2f0_result = b2f0(RECEIVE, parm);
1407
1408 if (!b2f0_result || b2f0_result == 5) {
1409 if (flags1_out) {
1410 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1411 *flags1_out = (parm->ipflags1 & (~0x07));
1412 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1413 }
1414
1415 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1416 if (residual_length)
1417 *residual_length = parm->ipbfln1f;
1418
1419 if (residual_buffer)
1420 *residual_buffer = parm->ipbfadr1;
1421 } else {
1422 moved = min_t (unsigned long, buflen, 8);
1423
1424 memcpy ((char *) buffer,
1425 (char *) &parm->ipbfadr1, moved);
1426
1427 if (buflen < 8)
1428 b2f0_result = 5;
1429
1430 if (residual_length)
1431 *residual_length = abs (buflen - 8);
1432
1433 if (residual_buffer)
1434 *residual_buffer = (ulong) (buffer + moved);
1435 }
1436 }
1437 release_param(parm);
1438
1439 iucv_debug(2, "exiting");
1440 return b2f0_result;
1441 }
1442
1443 /*
1444 * Name: iucv_receive_array
1445 * Purpose: This function receives messages that are being sent to you
1446 * over established paths.
1447 * Input: pathid - path identification number
1448 * buffer - address of array of buffers
1449 * buflen - total length of buffers
1450 * msgid - specifies the message ID.
1451 * trgcls - specifies target class
1452 * Output:
1453 * flags1_out: Options for path.
1454 * IPNORPY - 0x10 specifies whether a reply is required
1455 * IPPRTY - 0x20 specifies if you want to send priority message
1456 * IPRMDATA - 0x80 specifies the data is contained in the parameter list
1457 * residual_buffer - address points to the current list entry IUCV
1458 * is working on.
1459 * residual_length -
1460 * Contains one of the following values, if the receive buffer is:
1461 * The same length as the message, this field is zero.
1462 * Longer than the message, this field contains the number of
1463 * bytes remaining in the buffer.
1464 * Shorter than the message, this field contains the residual
1465 * count (that is, the number of bytes remaining in the
1466 * message that does not fit into the buffer. In this case
1467 * b2f0_result = 5.
1468 * Return: b2f0_result - return code from CP
1469 * (-EINVAL) - buffer address is NULL
1470 */
1471 int
1472 iucv_receive_array (__u16 pathid,
1473 __u32 msgid, __u32 trgcls,
1474 iucv_array_t * buffer, ulong buflen,
1475 int *flags1_out,
1476 ulong * residual_buffer, ulong * residual_length)
1477 {
1478 iparml_db *parm;
1479 ulong b2f0_result;
1480 int i = 0, moved = 0, need_to_move = 8, dyn_len;
1481
1482 iucv_debug(2, "entering");
1483
1484 if (!buffer)
1485 return -EINVAL;
1486
1487 parm = (iparml_db *)grab_param();
1488
1489 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1490 parm->ipbfln1f = (__u32) buflen;
1491 parm->ipmsgid = msgid;
1492 parm->ippathid = pathid;
1493 parm->iptrgcls = trgcls;
1494 parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
1495
1496 b2f0_result = b2f0(RECEIVE, parm);
1497
1498 if (!b2f0_result || b2f0_result == 5) {
1499
1500 if (flags1_out) {
1501 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1502 *flags1_out = (parm->ipflags1 & (~0x07));
1503 iucv_debug(2, "*flags1_out = %d", *flags1_out);
1504 }
1505
1506 if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
1507
1508 if (residual_length)
1509 *residual_length = parm->ipbfln1f;
1510
1511 if (residual_buffer)
1512 *residual_buffer = parm->ipbfadr1;
1513
1514 } else {
1515 /* copy msg from parmlist to users array. */
1516
1517 while ((moved < 8) && (moved < buflen)) {
1518 dyn_len =
1519 min_t (unsigned int,
1520 (buffer + i)->length, need_to_move);
1521
1522 memcpy ((char *)((ulong)((buffer + i)->address)),
1523 ((char *) &parm->ipbfadr1) + moved,
1524 dyn_len);
1525
1526 moved += dyn_len;
1527 need_to_move -= dyn_len;
1528
1529 (buffer + i)->address =
1530 (__u32)
1531 ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
1532 + dyn_len);
1533
1534 (buffer + i)->length -= dyn_len;
1535 i++;
1536 }
1537
1538 if (need_to_move) /* buflen < 8 bytes */
1539 b2f0_result = 5;
1540
1541 if (residual_length)
1542 *residual_length = abs (buflen - 8);
1543
1544 if (residual_buffer) {
1545 if (!moved)
1546 *residual_buffer = (ulong) buffer;
1547 else
1548 *residual_buffer =
1549 (ulong) (buffer + (i - 1));
1550 }
1551
1552 }
1553 }
1554 release_param(parm);
1555
1556 iucv_debug(2, "exiting");
1557 return b2f0_result;
1558 }
1559
1560 /**
1561 * iucv_reject:
1562 * @pathid: Path identification number.
1563 * @msgid: Message ID of the message to reject.
1564 * @trgcls: Target class of the message to reject.
1565 * Returns: return code from CP
1566 *
1567 * Refuses a specified message. Between the time you are notified of a
1568 * message and the time that you complete the message, the message may
1569 * be rejected.
1570 */
1571 int
1572 iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
1573 {
1574 iparml_db *parm;
1575 ulong b2f0_result = 0;
1576
1577 iucv_debug(1, "entering");
1578 iucv_debug(1, "pathid = %d", pathid);
1579
1580 parm = (iparml_db *)grab_param();
1581
1582 parm->ippathid = pathid;
1583 parm->ipmsgid = msgid;
1584 parm->iptrgcls = trgcls;
1585 parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
1586
1587 b2f0_result = b2f0(REJECT, parm);
1588 release_param(parm);
1589
1590 iucv_debug(1, "b2f0_result = %ld", b2f0_result);
1591 iucv_debug(1, "exiting");
1592
1593 return b2f0_result;
1594 }
1595
1596 /*
1597 * Name: iucv_reply
1598 * Purpose: This function responds to the two-way messages that you
1599 * receive. You must identify completely the message to
1600 * which you wish to reply. ie, pathid, msgid, and trgcls.
1601 * Input: pathid - path identification number
1602 * msgid - specifies the message ID.
1603 * trgcls - specifies target class
1604 * flags1 - option for path
1605 * IPPRTY- 0x20 - specifies if you want to send priority message
1606 * buffer - address of reply buffer
1607 * buflen - length of reply buffer
1608 * Output: ipbfadr2 - Address of buffer updated by the number
1609 * of bytes you have moved.
1610 * ipbfln2f - Contains one of the following values:
1611 * If the answer buffer is the same length as the reply, this field
1612 * contains zero.
1613 * If the answer buffer is longer than the reply, this field contains
1614 * the number of bytes remaining in the buffer.
1615 * If the answer buffer is shorter than the reply, this field contains
1616 * a residual count (that is, the number of bytes remianing in the
1617 * reply that does not fit into the buffer. In this
1618 * case b2f0_result = 5.
1619 * Return: b2f0_result - return code from CP
1620 * (-EINVAL) - buffer address is NULL
1621 */
1622 int
1623 iucv_reply (__u16 pathid,
1624 __u32 msgid, __u32 trgcls,
1625 int flags1,
1626 void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1627 {
1628 iparml_db *parm;
1629 ulong b2f0_result;
1630
1631 iucv_debug(2, "entering");
1632
1633 if (!buffer)
1634 return -EINVAL;
1635
1636 parm = (iparml_db *)grab_param();
1637
1638 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1639 parm->ipbfln2f = (__u32) buflen; /* length of message */
1640 parm->ippathid = pathid;
1641 parm->ipmsgid = msgid;
1642 parm->iptrgcls = trgcls;
1643 parm->ipflags1 = (__u8) flags1; /* priority message */
1644
1645 b2f0_result = b2f0(REPLY, parm);
1646
1647 if ((!b2f0_result) || (b2f0_result == 5)) {
1648 if (ipbfadr2)
1649 *ipbfadr2 = parm->ipbfadr2;
1650 if (ipbfln2f)
1651 *ipbfln2f = parm->ipbfln2f;
1652 }
1653 release_param(parm);
1654
1655 iucv_debug(2, "exiting");
1656
1657 return b2f0_result;
1658 }
1659
1660 /*
1661 * Name: iucv_reply_array
1662 * Purpose: This function responds to the two-way messages that you
1663 * receive. You must identify completely the message to
1664 * which you wish to reply. ie, pathid, msgid, and trgcls.
1665 * The array identifies a list of addresses and lengths of
1666 * discontiguous buffers that contains the reply data.
1667 * Input: pathid - path identification number
1668 * msgid - specifies the message ID.
1669 * trgcls - specifies target class
1670 * flags1 - option for path
1671 * IPPRTY- specifies if you want to send priority message
1672 * buffer - address of array of reply buffers
1673 * buflen - total length of reply buffers
1674 * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
1675 * ipbfln2f - Contains one of the following values:
1676 * If the answer buffer is the same length as the reply, this field
1677 * contains zero.
1678 * If the answer buffer is longer than the reply, this field contains
1679 * the number of bytes remaining in the buffer.
1680 * If the answer buffer is shorter than the reply, this field contains
1681 * a residual count (that is, the number of bytes remianing in the
1682 * reply that does not fit into the buffer. In this
1683 * case b2f0_result = 5.
1684 * Return: b2f0_result - return code from CP
1685 * (-EINVAL) - buffer address is NULL
1686 */
1687 int
1688 iucv_reply_array (__u16 pathid,
1689 __u32 msgid, __u32 trgcls,
1690 int flags1,
1691 iucv_array_t * buffer,
1692 ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
1693 {
1694 iparml_db *parm;
1695 ulong b2f0_result;
1696
1697 iucv_debug(2, "entering");
1698
1699 if (!buffer)
1700 return -EINVAL;
1701
1702 parm = (iparml_db *)grab_param();
1703
1704 parm->ipbfadr2 = (__u32) ((ulong) buffer);
1705 parm->ipbfln2f = buflen; /* length of message */
1706 parm->ippathid = pathid;
1707 parm->ipmsgid = msgid;
1708 parm->iptrgcls = trgcls;
1709 parm->ipflags1 = (IPANSLST | flags1);
1710
1711 b2f0_result = b2f0(REPLY, parm);
1712
1713 if ((!b2f0_result) || (b2f0_result == 5)) {
1714
1715 if (ipbfadr2)
1716 *ipbfadr2 = parm->ipbfadr2;
1717 if (ipbfln2f)
1718 *ipbfln2f = parm->ipbfln2f;
1719 }
1720 release_param(parm);
1721
1722 iucv_debug(2, "exiting");
1723
1724 return b2f0_result;
1725 }
1726
1727 /*
1728 * Name: iucv_reply_prmmsg
1729 * Purpose: This function responds to the two-way messages that you
1730 * receive. You must identify completely the message to
1731 * which you wish to reply. ie, pathid, msgid, and trgcls.
1732 * Prmmsg signifies the data is moved into the
1733 * parameter list.
1734 * Input: pathid - path identification number
1735 * msgid - specifies the message ID.
1736 * trgcls - specifies target class
1737 * flags1 - option for path
1738 * IPPRTY- specifies if you want to send priority message
1739 * prmmsg - 8-bytes of data to be placed into the parameter
1740 * list.
1741 * Output: NA
1742 * Return: b2f0_result - return code from CP
1743 */
1744 int
1745 iucv_reply_prmmsg (__u16 pathid,
1746 __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
1747 {
1748 iparml_dpl *parm;
1749 ulong b2f0_result;
1750
1751 iucv_debug(2, "entering");
1752
1753 parm = (iparml_dpl *)grab_param();
1754
1755 parm->ippathid = pathid;
1756 parm->ipmsgid = msgid;
1757 parm->iptrgcls = trgcls;
1758 memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
1759 parm->ipflags1 = (IPRMDATA | flags1);
1760
1761 b2f0_result = b2f0(REPLY, parm);
1762 release_param(parm);
1763
1764 iucv_debug(2, "exiting");
1765
1766 return b2f0_result;
1767 }
1768
1769 /**
1770 * iucv_resume:
1771 * @pathid: Path identification number
1772 * @user_data: 16-byte of user data
1773 *
1774 * This function restores communication over a quiesced path.
1775 * Returns: return code from CP
1776 */
1777 int
1778 iucv_resume (__u16 pathid, __u8 user_data[16])
1779 {
1780 iparml_control *parm;
1781 ulong b2f0_result = 0;
1782
1783 iucv_debug(1, "entering");
1784 iucv_debug(1, "pathid = %d", pathid);
1785
1786 parm = (iparml_control *)grab_param();
1787
1788 memcpy (parm->ipuser, user_data, sizeof (*user_data));
1789 parm->ippathid = pathid;
1790
1791 b2f0_result = b2f0(RESUME, parm);
1792 release_param(parm);
1793
1794 iucv_debug(1, "exiting");
1795
1796 return b2f0_result;
1797 }
1798
1799 /*
1800 * Name: iucv_send
1801 * Purpose: sends messages
1802 * Input: pathid - ushort, pathid
1803 * msgid - ulong *, id of message returned to caller
1804 * trgcls - ulong, target message class
1805 * srccls - ulong, source message class
1806 * msgtag - ulong, message tag
1807 * flags1 - Contains options for this path.
1808 * IPPRTY - Ox20 - specifies if you want to send a priority message.
1809 * buffer - pointer to buffer
1810 * buflen - ulong, length of buffer
1811 * Output: b2f0_result - return code from b2f0 call
1812 * msgid - returns message id
1813 */
1814 int
1815 iucv_send (__u16 pathid, __u32 * msgid,
1816 __u32 trgcls, __u32 srccls,
1817 __u32 msgtag, int flags1, void *buffer, ulong buflen)
1818 {
1819 iparml_db *parm;
1820 ulong b2f0_result;
1821
1822 iucv_debug(2, "entering");
1823
1824 if (!buffer)
1825 return -EINVAL;
1826
1827 parm = (iparml_db *)grab_param();
1828
1829 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1830 parm->ippathid = pathid;
1831 parm->iptrgcls = trgcls;
1832 parm->ipbfln1f = (__u32) buflen; /* length of message */
1833 parm->ipsrccls = srccls;
1834 parm->ipmsgtag = msgtag;
1835 parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
1836
1837 b2f0_result = b2f0(SEND, parm);
1838
1839 if ((!b2f0_result) && (msgid))
1840 *msgid = parm->ipmsgid;
1841 release_param(parm);
1842
1843 iucv_debug(2, "exiting");
1844
1845 return b2f0_result;
1846 }
1847
1848 /*
1849 * Name: iucv_send_array
1850 * Purpose: This function transmits data to another application.
1851 * The contents of buffer is the address of the array of
1852 * addresses and lengths of discontiguous buffers that hold
1853 * the message text. This is a one-way message and the
1854 * receiver will not reply to the message.
1855 * Input: pathid - path identification number
1856 * trgcls - specifies target class
1857 * srccls - specifies the source message class
1858 * msgtag - specifies a tag to be associated witht the message
1859 * flags1 - option for path
1860 * IPPRTY- specifies if you want to send priority message
1861 * buffer - address of array of send buffers
1862 * buflen - total length of send buffers
1863 * Output: msgid - specifies the message ID.
1864 * Return: b2f0_result - return code from CP
1865 * (-EINVAL) - buffer address is NULL
1866 */
1867 int
1868 iucv_send_array (__u16 pathid,
1869 __u32 * msgid,
1870 __u32 trgcls,
1871 __u32 srccls,
1872 __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
1873 {
1874 iparml_db *parm;
1875 ulong b2f0_result;
1876
1877 iucv_debug(2, "entering");
1878
1879 if (!buffer)
1880 return -EINVAL;
1881
1882 parm = (iparml_db *)grab_param();
1883
1884 parm->ippathid = pathid;
1885 parm->iptrgcls = trgcls;
1886 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1887 parm->ipbfln1f = (__u32) buflen; /* length of message */
1888 parm->ipsrccls = srccls;
1889 parm->ipmsgtag = msgtag;
1890 parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
1891 b2f0_result = b2f0(SEND, parm);
1892
1893 if ((!b2f0_result) && (msgid))
1894 *msgid = parm->ipmsgid;
1895 release_param(parm);
1896
1897 iucv_debug(2, "exiting");
1898 return b2f0_result;
1899 }
1900
1901 /*
1902 * Name: iucv_send_prmmsg
1903 * Purpose: This function transmits data to another application.
1904 * Prmmsg specifies that the 8-bytes of data are to be moved
1905 * into the parameter list. This is a one-way message and the
1906 * receiver will not reply to the message.
1907 * Input: pathid - path identification number
1908 * trgcls - specifies target class
1909 * srccls - specifies the source message class
1910 * msgtag - specifies a tag to be associated with the message
1911 * flags1 - option for path
1912 * IPPRTY- specifies if you want to send priority message
1913 * prmmsg - 8-bytes of data to be placed into parameter list
1914 * Output: msgid - specifies the message ID.
1915 * Return: b2f0_result - return code from CP
1916 */
1917 int
1918 iucv_send_prmmsg (__u16 pathid,
1919 __u32 * msgid,
1920 __u32 trgcls,
1921 __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
1922 {
1923 iparml_dpl *parm;
1924 ulong b2f0_result;
1925
1926 iucv_debug(2, "entering");
1927
1928 parm = (iparml_dpl *)grab_param();
1929
1930 parm->ippathid = pathid;
1931 parm->iptrgcls = trgcls;
1932 parm->ipsrccls = srccls;
1933 parm->ipmsgtag = msgtag;
1934 parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
1935 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
1936
1937 b2f0_result = b2f0(SEND, parm);
1938
1939 if ((!b2f0_result) && (msgid))
1940 *msgid = parm->ipmsgid;
1941 release_param(parm);
1942
1943 iucv_debug(2, "exiting");
1944
1945 return b2f0_result;
1946 }
1947
1948 /*
1949 * Name: iucv_send2way
1950 * Purpose: This function transmits data to another application.
1951 * Data to be transmitted is in a buffer. The receiver
1952 * of the send is expected to reply to the message and
1953 * a buffer is provided into which IUCV moves the reply
1954 * to this message.
1955 * Input: pathid - path identification number
1956 * trgcls - specifies target class
1957 * srccls - specifies the source message class
1958 * msgtag - specifies a tag associated with the message
1959 * flags1 - option for path
1960 * IPPRTY- specifies if you want to send priority message
1961 * buffer - address of send buffer
1962 * buflen - length of send buffer
1963 * ansbuf - address of buffer to reply with
1964 * anslen - length of buffer to reply with
1965 * Output: msgid - specifies the message ID.
1966 * Return: b2f0_result - return code from CP
1967 * (-EINVAL) - buffer or ansbuf address is NULL
1968 */
1969 int
1970 iucv_send2way (__u16 pathid,
1971 __u32 * msgid,
1972 __u32 trgcls,
1973 __u32 srccls,
1974 __u32 msgtag,
1975 int flags1,
1976 void *buffer, ulong buflen, void *ansbuf, ulong anslen)
1977 {
1978 iparml_db *parm;
1979 ulong b2f0_result;
1980
1981 iucv_debug(2, "entering");
1982
1983 if (!buffer || !ansbuf)
1984 return -EINVAL;
1985
1986 parm = (iparml_db *)grab_param();
1987
1988 parm->ippathid = pathid;
1989 parm->iptrgcls = trgcls;
1990 parm->ipbfadr1 = (__u32) ((ulong) buffer);
1991 parm->ipbfln1f = (__u32) buflen; /* length of message */
1992 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
1993 parm->ipbfln2f = (__u32) anslen;
1994 parm->ipsrccls = srccls;
1995 parm->ipmsgtag = msgtag;
1996 parm->ipflags1 = flags1; /* priority message */
1997
1998 b2f0_result = b2f0(SEND, parm);
1999
2000 if ((!b2f0_result) && (msgid))
2001 *msgid = parm->ipmsgid;
2002 release_param(parm);
2003
2004 iucv_debug(2, "exiting");
2005
2006 return b2f0_result;
2007 }
2008
2009 /*
2010 * Name: iucv_send2way_array
2011 * Purpose: This function transmits data to another application.
2012 * The contents of buffer is the address of the array of
2013 * addresses and lengths of discontiguous buffers that hold
2014 * the message text. The receiver of the send is expected to
2015 * reply to the message and a buffer is provided into which
2016 * IUCV moves the reply to this message.
2017 * Input: pathid - path identification number
2018 * trgcls - specifies target class
2019 * srccls - specifies the source message class
2020 * msgtag - spcifies a tag to be associated with the message
2021 * flags1 - option for path
2022 * IPPRTY- specifies if you want to send priority message
2023 * buffer - address of array of send buffers
2024 * buflen - total length of send buffers
2025 * ansbuf - address of buffer to reply with
2026 * anslen - length of buffer to reply with
2027 * Output: msgid - specifies the message ID.
2028 * Return: b2f0_result - return code from CP
2029 * (-EINVAL) - buffer address is NULL
2030 */
2031 int
2032 iucv_send2way_array (__u16 pathid,
2033 __u32 * msgid,
2034 __u32 trgcls,
2035 __u32 srccls,
2036 __u32 msgtag,
2037 int flags1,
2038 iucv_array_t * buffer,
2039 ulong buflen, iucv_array_t * ansbuf, ulong anslen)
2040 {
2041 iparml_db *parm;
2042 ulong b2f0_result;
2043
2044 iucv_debug(2, "entering");
2045
2046 if (!buffer || !ansbuf)
2047 return -EINVAL;
2048
2049 parm = (iparml_db *)grab_param();
2050
2051 parm->ippathid = pathid;
2052 parm->iptrgcls = trgcls;
2053 parm->ipbfadr1 = (__u32) ((ulong) buffer);
2054 parm->ipbfln1f = (__u32) buflen; /* length of message */
2055 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2056 parm->ipbfln2f = (__u32) anslen;
2057 parm->ipsrccls = srccls;
2058 parm->ipmsgtag = msgtag;
2059 parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
2060 b2f0_result = b2f0(SEND, parm);
2061 if ((!b2f0_result) && (msgid))
2062 *msgid = parm->ipmsgid;
2063 release_param(parm);
2064
2065 iucv_debug(2, "exiting");
2066 return b2f0_result;
2067 }
2068
2069 /*
2070 * Name: iucv_send2way_prmmsg
2071 * Purpose: This function transmits data to another application.
2072 * Prmmsg specifies that the 8-bytes of data are to be moved
2073 * into the parameter list. This is a two-way message and the
2074 * receiver of the message is expected to reply. A buffer
2075 * is provided into which IUCV moves the reply to this
2076 * message.
2077 * Input: pathid - path identification number
2078 * trgcls - specifies target class
2079 * srccls - specifies the source message class
2080 * msgtag - specifies a tag to be associated with the message
2081 * flags1 - option for path
2082 * IPPRTY- specifies if you want to send priority message
2083 * prmmsg - 8-bytes of data to be placed in parameter list
2084 * ansbuf - address of buffer to reply with
2085 * anslen - length of buffer to reply with
2086 * Output: msgid - specifies the message ID.
2087 * Return: b2f0_result - return code from CP
2088 * (-EINVAL) - buffer address is NULL
2089 */
2090 int
2091 iucv_send2way_prmmsg (__u16 pathid,
2092 __u32 * msgid,
2093 __u32 trgcls,
2094 __u32 srccls,
2095 __u32 msgtag,
2096 ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
2097 {
2098 iparml_dpl *parm;
2099 ulong b2f0_result;
2100
2101 iucv_debug(2, "entering");
2102
2103 if (!ansbuf)
2104 return -EINVAL;
2105
2106 parm = (iparml_dpl *)grab_param();
2107
2108 parm->ippathid = pathid;
2109 parm->iptrgcls = trgcls;
2110 parm->ipsrccls = srccls;
2111 parm->ipmsgtag = msgtag;
2112 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2113 parm->ipbfln2f = (__u32) anslen;
2114 parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
2115 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2116
2117 b2f0_result = b2f0(SEND, parm);
2118
2119 if ((!b2f0_result) && (msgid))
2120 *msgid = parm->ipmsgid;
2121 release_param(parm);
2122
2123 iucv_debug(2, "exiting");
2124
2125 return b2f0_result;
2126 }
2127
2128 /*
2129 * Name: iucv_send2way_prmmsg_array
2130 * Purpose: This function transmits data to another application.
2131 * Prmmsg specifies that the 8-bytes of data are to be moved
2132 * into the parameter list. This is a two-way message and the
2133 * receiver of the message is expected to reply. A buffer
2134 * is provided into which IUCV moves the reply to this
2135 * message. The contents of ansbuf is the address of the
2136 * array of addresses and lengths of discontiguous buffers
2137 * that contain the reply.
2138 * Input: pathid - path identification number
2139 * trgcls - specifies target class
2140 * srccls - specifies the source message class
2141 * msgtag - specifies a tag to be associated with the message
2142 * flags1 - option for path
2143 * IPPRTY- specifies if you want to send priority message
2144 * prmmsg - 8-bytes of data to be placed into the parameter list
2145 * ansbuf - address of buffer to reply with
2146 * anslen - length of buffer to reply with
2147 * Output: msgid - specifies the message ID.
2148 * Return: b2f0_result - return code from CP
2149 * (-EINVAL) - ansbuf address is NULL
2150 */
2151 int
2152 iucv_send2way_prmmsg_array (__u16 pathid,
2153 __u32 * msgid,
2154 __u32 trgcls,
2155 __u32 srccls,
2156 __u32 msgtag,
2157 int flags1,
2158 __u8 prmmsg[8],
2159 iucv_array_t * ansbuf, ulong anslen)
2160 {
2161 iparml_dpl *parm;
2162 ulong b2f0_result;
2163
2164 iucv_debug(2, "entering");
2165
2166 if (!ansbuf)
2167 return -EINVAL;
2168
2169 parm = (iparml_dpl *)grab_param();
2170
2171 parm->ippathid = pathid;
2172 parm->iptrgcls = trgcls;
2173 parm->ipsrccls = srccls;
2174 parm->ipmsgtag = msgtag;
2175 parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
2176 parm->ipbfln2f = (__u32) anslen;
2177 parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
2178 memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
2179 b2f0_result = b2f0(SEND, parm);
2180 if ((!b2f0_result) && (msgid))
2181 *msgid = parm->ipmsgid;
2182 release_param(parm);
2183
2184 iucv_debug(2, "exiting");
2185 return b2f0_result;
2186 }
2187
2188 void
2189 iucv_setmask_cpuid (void *result)
2190 {
2191 iparml_set_mask *parm;
2192
2193 iucv_debug(1, "entering");
2194 parm = (iparml_set_mask *)grab_param();
2195 parm->ipmask = *((__u8*)result);
2196 *((ulong *)result) = b2f0(SETMASK, parm);
2197 release_param(parm);
2198
2199 iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
2200 iucv_debug(1, "exiting");
2201 }
2202
2203 /*
2204 * Name: iucv_setmask
2205 * Purpose: This function enables or disables the following IUCV
2206 * external interruptions: Nonpriority and priority message
2207 * interrupts, nonpriority and priority reply interrupts.
2208 * Input: SetMaskFlag - options for interrupts
2209 * 0x80 - Nonpriority_MessagePendingInterruptsFlag
2210 * 0x40 - Priority_MessagePendingInterruptsFlag
2211 * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
2212 * 0x10 - Priority_MessageCompletionInterruptsFlag
2213 * 0x08 - IUCVControlInterruptsFlag
2214 * Output: NA
2215 * Return: b2f0_result - return code from CP
2216 */
2217 int
2218 iucv_setmask (int SetMaskFlag)
2219 {
2220 union {
2221 ulong result;
2222 __u8 param;
2223 } u;
2224 int cpu;
2225
2226 u.param = SetMaskFlag;
2227 cpu = get_cpu();
2228 smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
2229 put_cpu();
2230
2231 return u.result;
2232 }
2233
2234 /**
2235 * iucv_sever:
2236 * @pathid: Path identification number
2237 * @user_data: 16-byte of user data
2238 *
2239 * This function terminates an iucv path.
2240 * Returns: return code from CP
2241 */
2242 int
2243 iucv_sever(__u16 pathid, __u8 user_data[16])
2244 {
2245 iparml_control *parm;
2246 ulong b2f0_result = 0;
2247
2248 iucv_debug(1, "entering");
2249 parm = (iparml_control *)grab_param();
2250
2251 memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
2252 parm->ippathid = pathid;
2253
2254 b2f0_result = b2f0(SEVER, parm);
2255
2256 if (!b2f0_result)
2257 iucv_remove_pathid(pathid);
2258 release_param(parm);
2259
2260 iucv_debug(1, "exiting");
2261 return b2f0_result;
2262 }
2263
2264 /*
2265 * Interrupt Handlers
2266 *******************************************************************************/
2267
2268 /**
2269 * iucv_irq_handler:
2270 * @regs: Current registers
2271 * @code: irq code
2272 *
2273 * Handles external interrupts coming in from CP.
2274 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
2275 */
2276 static void
2277 iucv_irq_handler(struct pt_regs *regs, __u16 code)
2278 {
2279 iucv_irqdata *irqdata;
2280
2281 irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
2282 if (!irqdata) {
2283 printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
2284 return;
2285 }
2286
2287 memcpy(&irqdata->data, iucv_external_int_buffer,
2288 sizeof(iucv_GeneralInterrupt));
2289
2290 spin_lock(&iucv_irq_queue_lock);
2291 list_add_tail(&irqdata->queue, &iucv_irq_queue);
2292 spin_unlock(&iucv_irq_queue_lock);
2293
2294 tasklet_schedule(&iucv_tasklet);
2295 }
2296
2297 /**
2298 * iucv_do_int:
2299 * @int_buf: Pointer to copy of external interrupt buffer
2300 *
2301 * The workhorse for handling interrupts queued by iucv_irq_handler().
2302 * This function is called from the bottom half iucv_tasklet_handler().
2303 */
2304 static void
2305 iucv_do_int(iucv_GeneralInterrupt * int_buf)
2306 {
2307 handler *h = NULL;
2308 struct list_head *lh;
2309 ulong flags;
2310 iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
2311 __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
2312 int rc = 0, j = 0;
2313 __u8 no_listener[16] = "NO LISTENER";
2314
2315 iucv_debug(2, "entering, pathid %d, type %02X",
2316 int_buf->ippathid, int_buf->iptype);
2317 iucv_dumpit("External Interrupt Buffer:",
2318 int_buf, sizeof(iucv_GeneralInterrupt));
2319
2320 ASCEBC (no_listener, 16);
2321
2322 if (int_buf->iptype != 01) {
2323 if ((int_buf->ippathid) > (max_connections - 1)) {
2324 printk(KERN_WARNING "%s: Got interrupt with pathid %d"
2325 " > max_connections (%ld)\n", __FUNCTION__,
2326 int_buf->ippathid, max_connections - 1);
2327 } else {
2328 h = iucv_pathid_table[int_buf->ippathid];
2329 interrupt = h->interrupt_table;
2330 iucv_dumpit("Handler:", h, sizeof(handler));
2331 }
2332 }
2333
2334 /* end of if statement */
2335 switch (int_buf->iptype) {
2336 case 0x01: /* connection pending */
2337 if (messagesDisabled) {
2338 iucv_setmask(~0);
2339 messagesDisabled = 0;
2340 }
2341 spin_lock_irqsave(&iucv_lock, flags);
2342 list_for_each(lh, &iucv_handler_table) {
2343 h = list_entry(lh, handler, list);
2344 memcpy(temp_buff1, &(int_buf->ipvmid), 24);
2345 memcpy(temp_buff2, &(h->id.userid), 24);
2346 for (j = 0; j < 24; j++) {
2347 temp_buff1[j] &= (h->id.mask)[j];
2348 temp_buff2[j] &= (h->id.mask)[j];
2349 }
2350
2351 iucv_dumpit("temp_buff1:",
2352 temp_buff1, sizeof(temp_buff1));
2353 iucv_dumpit("temp_buff2",
2354 temp_buff2, sizeof(temp_buff2));
2355
2356 if (!memcmp (temp_buff1, temp_buff2, 24)) {
2357
2358 iucv_debug(2,
2359 "found a matching handler");
2360 break;
2361 } else
2362 h = NULL;
2363 }
2364 spin_unlock_irqrestore (&iucv_lock, flags);
2365 if (h) {
2366 /* ADD PATH TO PATHID TABLE */
2367 rc = iucv_add_pathid(int_buf->ippathid, h);
2368 if (rc) {
2369 iucv_sever (int_buf->ippathid,
2370 no_listener);
2371 iucv_debug(1,
2372 "add_pathid failed, rc = %d",
2373 rc);
2374 } else {
2375 interrupt = h->interrupt_table;
2376 if (interrupt->ConnectionPending) {
2377 EBCASC (int_buf->ipvmid, 8);
2378 interrupt->ConnectionPending(
2379 (iucv_ConnectionPending *)int_buf,
2380 h->pgm_data);
2381 } else
2382 iucv_sever(int_buf->ippathid,
2383 no_listener);
2384 }
2385 } else
2386 iucv_sever(int_buf->ippathid, no_listener);
2387 break;
2388
2389 case 0x02: /*connection complete */
2390 if (messagesDisabled) {
2391 iucv_setmask(~0);
2392 messagesDisabled = 0;
2393 }
2394 if (h) {
2395 if (interrupt->ConnectionComplete)
2396 {
2397 interrupt->ConnectionComplete(
2398 (iucv_ConnectionComplete *)int_buf,
2399 h->pgm_data);
2400 }
2401 else
2402 iucv_debug(1,
2403 "ConnectionComplete not called");
2404 } else
2405 iucv_sever(int_buf->ippathid, no_listener);
2406 break;
2407
2408 case 0x03: /* connection severed */
2409 if (messagesDisabled) {
2410 iucv_setmask(~0);
2411 messagesDisabled = 0;
2412 }
2413 if (h) {
2414 if (interrupt->ConnectionSevered)
2415 interrupt->ConnectionSevered(
2416 (iucv_ConnectionSevered *)int_buf,
2417 h->pgm_data);
2418
2419 else
2420 iucv_sever (int_buf->ippathid, no_listener);
2421 } else
2422 iucv_sever(int_buf->ippathid, no_listener);
2423 break;
2424
2425 case 0x04: /* connection quiesced */
2426 if (messagesDisabled) {
2427 iucv_setmask(~0);
2428 messagesDisabled = 0;
2429 }
2430 if (h) {
2431 if (interrupt->ConnectionQuiesced)
2432 interrupt->ConnectionQuiesced(
2433 (iucv_ConnectionQuiesced *)int_buf,
2434 h->pgm_data);
2435 else
2436 iucv_debug(1,
2437 "ConnectionQuiesced not called");
2438 }
2439 break;
2440
2441 case 0x05: /* connection resumed */
2442 if (messagesDisabled) {
2443 iucv_setmask(~0);
2444 messagesDisabled = 0;
2445 }
2446 if (h) {
2447 if (interrupt->ConnectionResumed)
2448 interrupt->ConnectionResumed(
2449 (iucv_ConnectionResumed *)int_buf,
2450 h->pgm_data);
2451 else
2452 iucv_debug(1,
2453 "ConnectionResumed not called");
2454 }
2455 break;
2456
2457 case 0x06: /* priority message complete */
2458 case 0x07: /* nonpriority message complete */
2459 if (h) {
2460 if (interrupt->MessageComplete)
2461 interrupt->MessageComplete(
2462 (iucv_MessageComplete *)int_buf,
2463 h->pgm_data);
2464 else
2465 iucv_debug(2,
2466 "MessageComplete not called");
2467 }
2468 break;
2469
2470 case 0x08: /* priority message pending */
2471 case 0x09: /* nonpriority message pending */
2472 if (h) {
2473 if (interrupt->MessagePending)
2474 interrupt->MessagePending(
2475 (iucv_MessagePending *) int_buf,
2476 h->pgm_data);
2477 else
2478 iucv_debug(2,
2479 "MessagePending not called");
2480 }
2481 break;
2482 default: /* unknown iucv type */
2483 printk(KERN_WARNING "%s: unknown iucv interrupt\n",
2484 __FUNCTION__);
2485 break;
2486 } /* end switch */
2487
2488 iucv_debug(2, "exiting pathid %d, type %02X",
2489 int_buf->ippathid, int_buf->iptype);
2490
2491 return;
2492 }
2493
2494 /**
2495 * iucv_tasklet_handler:
2496 *
2497 * This function loops over the queue of irq buffers and runs iucv_do_int()
2498 * on every queue element.
2499 */
2500 static void
2501 iucv_tasklet_handler(unsigned long ignored)
2502 {
2503 struct list_head head;
2504 struct list_head *next;
2505 ulong flags;
2506
2507 spin_lock_irqsave(&iucv_irq_queue_lock, flags);
2508 list_add(&head, &iucv_irq_queue);
2509 list_del_init(&iucv_irq_queue);
2510 spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
2511
2512 next = head.next;
2513 while (next != &head) {
2514 iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
2515
2516 next = next->next;
2517 iucv_do_int(&p->data);
2518 kfree(p);
2519 }
2520
2521 return;
2522 }
2523
2524 subsys_initcall(iucv_init);
2525 module_exit(iucv_exit);
2526
2527 /**
2528 * Export all public stuff
2529 */
2530 EXPORT_SYMBOL (iucv_bus);
2531 EXPORT_SYMBOL (iucv_root);
2532 EXPORT_SYMBOL (iucv_accept);
2533 EXPORT_SYMBOL (iucv_connect);
2534 #if 0
2535 EXPORT_SYMBOL (iucv_purge);
2536 EXPORT_SYMBOL (iucv_query_maxconn);
2537 EXPORT_SYMBOL (iucv_query_bufsize);
2538 EXPORT_SYMBOL (iucv_quiesce);
2539 #endif
2540 EXPORT_SYMBOL (iucv_receive);
2541 #if 0
2542 EXPORT_SYMBOL (iucv_receive_array);
2543 #endif
2544 EXPORT_SYMBOL (iucv_reject);
2545 #if 0
2546 EXPORT_SYMBOL (iucv_reply);
2547 EXPORT_SYMBOL (iucv_reply_array);
2548 EXPORT_SYMBOL (iucv_resume);
2549 #endif
2550 EXPORT_SYMBOL (iucv_reply_prmmsg);
2551 EXPORT_SYMBOL (iucv_send);
2552 EXPORT_SYMBOL (iucv_send2way);
2553 EXPORT_SYMBOL (iucv_send2way_array);
2554 EXPORT_SYMBOL (iucv_send2way_prmmsg);
2555 EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
2556 #if 0
2557 EXPORT_SYMBOL (iucv_send_array);
2558 EXPORT_SYMBOL (iucv_send_prmmsg);
2559 EXPORT_SYMBOL (iucv_setmask);
2560 #endif
2561 EXPORT_SYMBOL (iucv_sever);
2562 EXPORT_SYMBOL (iucv_register_program);
2563 EXPORT_SYMBOL (iucv_unregister_program);
This page took 0.087696 seconds and 5 git commands to generate.