OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [s390/] [net/] [iucv.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.