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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [isdn/] [avmb1/] [b1lli.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * $Id: b1lli.c,v 1.1.1.1 2001-09-10 07:44:18 simons Exp $
3
 *
4
 * ISDN lowlevel-module for AVM B1-card.
5
 *
6
 * (c) Copyright 1997 by Carsten Paeth (calle@calle.in-berlin.de)
7
 *
8
 * $Log: not supported by cvs2svn $
9
 * Revision 1.1.1.1  2001/07/02 17:58:32  simons
10
 * Initial revision
11
 *
12
 * Revision 1.1.2.11  1998/10/25 14:36:18  fritz
13
 * Backported from MIPS (Cobalt).
14
 *
15
 * Revision 1.1.2.10  1998/03/20 20:34:41  calle
16
 * port valid check now only for T1, because of the PCI and PCMCIA cards.
17
 *
18
 * Revision 1.1.2.9  1998/03/20 14:38:20  calle
19
 * capidrv: prepared state machines for suspend/resume/hold
20
 * capidrv: fix bug in state machine if B1/T1 is out of nccis
21
 * b1capi: changed some errno returns.
22
 * b1capi: detect if you try to add same T1 to different io address.
23
 * b1capi: change number of nccis depending on number of channels.
24
 * b1lli: cosmetics
25
 *
26
 * Revision 1.1.2.8  1998/03/18 17:43:29  calle
27
 * T1 with fastlink, bugfix for multicontroller support in capidrv.c
28
 *
29
 * Revision 1.1.2.7  1998/03/04 17:33:50  calle
30
 * Changes for T1.
31
 *
32
 * Revision 1.1.2.6  1998/02/27 15:40:44  calle
33
 * T1 running with slow link. bugfix in capi_release.
34
 *
35
 * Revision 1.1.2.5  1998/02/13 16:28:28  calle
36
 * first step for T1
37
 *
38
 * Revision 1.1.2.4  1998/01/27 16:12:51  calle
39
 * Support for PCMCIA B1/M1/M2 ready.
40
 *
41
 * Revision 1.1.2.3  1998/01/15 15:33:37  calle
42
 * print cardtype, d2 protocol and linetype after load.
43
 *
44
 * Revision 1.1.2.2  1997/11/26 10:46:55  calle
45
 * prepared for M1 (Mobile) and T1 (PMX) cards.
46
 * prepared to set configuration after load to support other D-channel
47
 * protocols, point-to-point and leased lines.
48
 *
49
 * Revision 1.1.2.1  1997/07/13 12:16:46  calle
50
 * bug fix for more than one controller in connect_req.
51
 *
52
 * Revision 1.1  1997/03/04 21:50:28  calle
53
 * Frirst version in isdn4linux
54
 *
55
 * Revision 2.2  1997/02/12 09:31:39  calle
56
 * new version
57
 *
58
 * Revision 1.1  1997/01/31 10:32:20  calle
59
 * Initial revision
60
 *
61
 *
62
 */
63
/* #define FASTLINK_DEBUG */
64
 
65
#include <linux/kernel.h>
66
#include <linux/skbuff.h>
67
#include <linux/delay.h>
68
#include <linux/mm.h>
69
#include <asm/segment.h>
70
#include <asm/io.h>
71
#include <linux/capi.h>
72
#include <linux/b1lli.h>
73
 
74
#include "compat.h"
75
#include "capicmd.h"
76
#include "capiutil.h"
77
 
78
extern int showcapimsgs;
79
 
80
/*
81
 * LLI Messages to the ISDN-ControllerISDN Controller
82
 */
83
 
84
#define SEND_POLL               0x72    /*
85
                                           * after load <- RECEIVE_POLL
86
                                         */
87
#define SEND_INIT               0x11    /*
88
                                           * first message <- RECEIVE_INIT
89
                                           * int32 NumApplications  int32
90
                                           * NumNCCIs int32 BoardNumber
91
                                         */
92
#define SEND_REGISTER           0x12    /*
93
                                           * register an application int32
94
                                           * ApplIDId int32 NumMessages
95
                                           * int32 NumB3Connections int32
96
                                           * NumB3Blocks int32 B3Size
97
                                           *
98
                                           * AnzB3Connection != 0 &&
99
                                           * AnzB3Blocks >= 1 && B3Size >= 1
100
                                         */
101
#define SEND_RELEASE            0x14    /*
102
                                           * deregister an application int32
103
                                           * ApplID
104
                                         */
105
#define SEND_MESSAGE            0x15    /*
106
                                           * send capi-message int32 length
107
                                           * capi-data ...
108
                                         */
109
#define SEND_DATA_B3_REQ        0x13    /*
110
                                           * send capi-data-message int32
111
                                           * MsgLength capi-data ... int32
112
                                           * B3Length data ....
113
                                         */
114
 
115
#define SEND_CONFIG             0x21    /*
116
                                         */
117
 
118
#define SEND_POLLACK            0x73    /* T1 Watchdog */
119
 
120
/*
121
 * LLI Messages from the ISDN-ControllerISDN Controller
122
 */
123
 
124
#define RECEIVE_POLL            0x32    /*
125
                                           * <- after SEND_POLL
126
                                         */
127
#define RECEIVE_INIT            0x27    /*
128
                                           * <- after SEND_INIT int32 length
129
                                           * byte total length b1struct board
130
                                           * driver revision b1struct card
131
                                           * type b1struct reserved b1struct
132
                                           * serial number b1struct driver
133
                                           * capability b1struct d-channel
134
                                           * protocol b1struct CAPI-2.0
135
                                           * profile b1struct capi version
136
                                         */
137
#define RECEIVE_MESSAGE         0x21    /*
138
                                           * <- after SEND_MESSAGE int32
139
                                           * AppllID int32 Length capi-data
140
                                           * ....
141
                                         */
142
#define RECEIVE_DATA_B3_IND     0x22    /*
143
                                           * received data int32 AppllID
144
                                           * int32 Length capi-data ...
145
                                           * int32 B3Length data ...
146
                                         */
147
#define RECEIVE_START           0x23    /*
148
                                           * Handshake
149
                                         */
150
#define RECEIVE_STOP            0x24    /*
151
                                           * Handshake
152
                                         */
153
#define RECEIVE_NEW_NCCI        0x25    /*
154
                                           * int32 AppllID int32 NCCI int32
155
                                           * WindowSize
156
                                         */
157
#define RECEIVE_FREE_NCCI       0x26    /*
158
                                           * int32 AppllID int32 NCCI
159
                                         */
160
#define RECEIVE_RELEASE         0x26    /*
161
                                           * int32 AppllID int32 0xffffffff
162
                                         */
163
#define RECEIVE_TASK_READY      0x31    /*
164
                                           * int32 tasknr
165
                                           * int32 Length Taskname ...
166
                                         */
167
 
168
#define WRITE_REGISTER          0x00
169
#define READ_REGISTER           0x01
170
 
171
/*
172
 * port offsets
173
 */
174
 
175
#define B1_READ                 0x00
176
#define B1_WRITE                0x01
177
#define B1_INSTAT               0x02
178
#define B1_OUTSTAT              0x03
179
#define B1_RESET                0x10
180
#define B1_ANALYSE              0x04
181
 
182
/* Hema card T1 */
183
 
184
#define T1_FASTLINK             0x00
185
#define T1_SLOWLINK             0x08
186
 
187
#define T1_READ                 B1_READ
188
#define T1_WRITE                B1_WRITE
189
#define T1_INSTAT               B1_INSTAT
190
#define T1_OUTSTAT              B1_OUTSTAT
191
#define T1_IRQENABLE            0x05
192
#define T1_FIFOSTAT             0x06
193
#define T1_RESETLINK            0x10
194
#define T1_ANALYSE              0x11
195
#define T1_IRQMASTER            0x12
196
#define T1_IDENT                0x17
197
#define T1_RESETBOARD           0x1f
198
 
199
#define T1F_IREADY              0x01
200
#define T1F_IHALF               0x02
201
#define T1F_IFULL               0x04
202
#define T1F_IEMPTY              0x08
203
#define T1F_IFLAGS              0xF0
204
 
205
#define T1F_OREADY              0x10
206
#define T1F_OHALF               0x20
207
#define T1F_OEMPTY              0x40
208
#define T1F_OFULL               0x80
209
#define T1F_OFLAGS              0xF0
210
 
211
/* there are HEMA cards with 1k and 4k FIFO out */
212
#define FIFO_OUTBSIZE           256
213
#define FIFO_INPBSIZE           512
214
 
215
#define HEMA_VERSION_ID         0
216
#define HEMA_PAL_ID             0
217
 
218
#define B1_STAT0(cardtype)  ((cardtype) == AVM_CARDTYPE_M1 ? 0x81200000l : 0x80A00000l)
219
#define B1_STAT1(cardtype)  (0x80E00000l)
220
 
221
 
222
static inline unsigned char b1outp(unsigned int base,
223
                                   unsigned short offset,
224
                                   unsigned char value)
225
{
226
        outb(value, base + offset);
227
        return inb(base + B1_ANALYSE);
228
}
229
 
230
static inline void t1outp(unsigned int base,
231
                          unsigned short offset,
232
                          unsigned char value)
233
{
234
        outb(value, base + offset);
235
}
236
 
237
static inline unsigned char t1inp(unsigned int base,
238
                                  unsigned short offset)
239
{
240
        return inb(base + offset);
241
}
242
 
243
static inline int B1_isfastlink(unsigned int base)
244
{
245
        return (inb(base + T1_IDENT) & ~0x82) == 1;
246
}
247
static inline unsigned char B1_fifostatus(unsigned int base)
248
{
249
        return inb(base + T1_FIFOSTAT);
250
}
251
 
252
static inline int B1_rx_full(unsigned int base)
253
{
254
        return inb(base + B1_INSTAT) & 0x1;
255
}
256
 
257
static inline unsigned char B1_get_byte(unsigned int base)
258
{
259
        unsigned long i = jiffies + 1 * HZ;     /* maximum wait time 1 sec */
260
        while (!B1_rx_full(base) && i > jiffies);
261
        if (B1_rx_full(base))
262
                return inb(base + B1_READ);
263
        printk(KERN_CRIT "b1lli(0x%x): rx not full after 1 second\n", base);
264
        return 0;
265
}
266
 
267
static inline unsigned int B1_get_word(unsigned int base)
268
{
269
        unsigned int val = 0;
270
        val |= B1_get_byte(base);
271
        val |= (B1_get_byte(base) << 8);
272
        val |= (B1_get_byte(base) << 16);
273
        val |= (B1_get_byte(base) << 24);
274
        return val;
275
}
276
 
277
static inline int B1_tx_empty(unsigned int base)
278
{
279
        return inb(base + B1_OUTSTAT) & 0x1;
280
}
281
 
282
static inline void B1_put_byte(unsigned int base, unsigned char val)
283
{
284
        while (!B1_tx_empty(base));
285
        b1outp(base, B1_WRITE, val);
286
}
287
 
288
static inline void B1_put_word(unsigned int base, unsigned int val)
289
{
290
        B1_put_byte(base, val & 0xff);
291
        B1_put_byte(base, (val >> 8) & 0xff);
292
        B1_put_byte(base, (val >> 16) & 0xff);
293
        B1_put_byte(base, (val >> 24) & 0xff);
294
}
295
 
296
static inline unsigned int B1_get_slice(unsigned int base,
297
                                        unsigned char *dp)
298
{
299
        unsigned int len, i;
300
#ifdef FASTLINK_DEBUG
301
        unsigned wcnt = 0, bcnt = 0;
302
#endif
303
 
304
        len = i = B1_get_word(base);
305
        if (B1_isfastlink(base)) {
306
                int status;
307
                while (i > 0) {
308
                        status = B1_fifostatus(base) & (T1F_IREADY|T1F_IHALF);
309
                        if (i >= FIFO_INPBSIZE) status |= T1F_IFULL;
310
 
311
                        switch (status) {
312
                                case T1F_IREADY|T1F_IHALF|T1F_IFULL:
313
                                        insb(base+B1_READ, dp, FIFO_INPBSIZE);
314
                                        dp += FIFO_INPBSIZE;
315
                                        i -= FIFO_INPBSIZE;
316
#ifdef FASTLINK_DEBUG
317
                                        wcnt += FIFO_INPBSIZE;
318
#endif
319
                                        break;
320
                                case T1F_IREADY|T1F_IHALF:
321
                                        insb(base+B1_READ,dp, i);
322
#ifdef FASTLINK_DEBUG
323
                                        wcnt += i;
324
#endif
325
                                        dp += i;
326
                                        i = 0;
327
                                        if (i == 0)
328
                                                break;
329
                                        /* fall through */
330
                                default:
331
                                        *dp++ = B1_get_byte(base);
332
                                        i--;
333
#ifdef FASTLINK_DEBUG
334
                                        bcnt++;
335
#endif
336
                                        break;
337
                        }
338
            }
339
#ifdef FASTLINK_DEBUG
340
            if (wcnt)
341
            printk(KERN_DEBUG "b1lli(0x%x): get_slice l=%d w=%d b=%d\n",
342
                                base, len, wcnt, bcnt);
343
#endif
344
        } else {
345
                while (i-- > 0)
346
                        *dp++ = B1_get_byte(base);
347
        }
348
        return len;
349
}
350
 
351
static inline void B1_put_slice(unsigned int base,
352
                                unsigned char *dp, unsigned int len)
353
{
354
        unsigned i = len;
355
        B1_put_word(base, i);
356
        if (B1_isfastlink(base)) {
357
                int status;
358
                while (i > 0) {
359
                        status = B1_fifostatus(base) & (T1F_OREADY|T1F_OHALF);
360
                        if (i >= FIFO_OUTBSIZE) status |= T1F_OEMPTY;
361
                        switch (status) {
362
                                case T1F_OREADY|T1F_OHALF|T1F_OEMPTY:
363
                                        outsb(base+B1_WRITE, dp, FIFO_OUTBSIZE);
364
                                        dp += FIFO_OUTBSIZE;
365
                                        i -= FIFO_OUTBSIZE;
366
                                        break;
367
                                case T1F_OREADY|T1F_OHALF:
368
                                        outsb(base+B1_WRITE, dp, i);
369
                                        dp += i;
370
                                        i = 0;
371
                                        break;
372
                                default:
373
                                        B1_put_byte(base, *dp++);
374
                                        i--;
375
                                        break;
376
                        }
377
                }
378
        } else {
379
                while (i-- > 0)
380
                        B1_put_byte(base, *dp++);
381
        }
382
}
383
 
384
static void b1_wr_reg(unsigned int base,
385
                      unsigned int reg,
386
                      unsigned int value)
387
{
388
        B1_put_byte(base, WRITE_REGISTER);
389
        B1_put_word(base, reg);
390
        B1_put_word(base, value);
391
}
392
 
393
static inline unsigned int b1_rd_reg(unsigned int base,
394
                                     unsigned int reg)
395
{
396
        B1_put_byte(base, READ_REGISTER);
397
        B1_put_word(base, reg);
398
        return B1_get_word(base);
399
 
400
}
401
 
402
static inline void b1_set_test_bit(unsigned int base,
403
                                   int cardtype,
404
                                   int onoff)
405
{
406
    b1_wr_reg(base, B1_STAT0(cardtype), onoff ? 0x21 : 0x20);
407
}
408
 
409
static inline int b1_get_test_bit(unsigned int base,
410
                                  int cardtype)
411
{
412
    return (b1_rd_reg(base, B1_STAT0(cardtype)) & 0x01) != 0;
413
}
414
 
415
static int irq_table[16] =
416
{0,
417
 0,
418
 0,
419
 192,                           /* irq 3 */
420
 32,                            /* irq 4 */
421
 160,                           /* irq 5 */
422
 96,                            /* irq 6 */
423
 224,                           /* irq 7 */
424
 0,
425
 64,                            /* irq 9 */
426
 80,                            /* irq 10 */
427
 208,                           /* irq 11 */
428
 48,                            /* irq 12 */
429
 0,
430
 0,
431
 112,                           /* irq 15 */
432
};
433
 
434
static int hema_irq_table[16] =
435
{0,
436
 0,
437
 0,
438
 0x80,                          /* irq 3 */
439
 0,
440
 0x90,                          /* irq 5 */
441
 0,
442
 0xA0,                          /* irq 7 */
443
 0,
444
 0xB0,                          /* irq 9 */
445
 0xC0,                          /* irq 10 */
446
 0xD0,                          /* irq 11 */
447
 0xE0,                          /* irq 12 */
448
 0,
449
 0,
450
 0xF0,                          /* irq 15 */
451
};
452
 
453
 
454
int B1_valid_irq(unsigned irq, int cardtype)
455
{
456
        switch (cardtype) {
457
           default:
458
           case AVM_CARDTYPE_M1:
459
           case AVM_CARDTYPE_M2:
460
           case AVM_CARDTYPE_B1:
461
                return irq_table[irq & 0xf] != 0;
462
           case AVM_CARDTYPE_T1:
463
                return hema_irq_table[irq & 0xf] != 0;
464
        }
465
}
466
 
467
int B1_valid_port(unsigned port, int cardtype)
468
{
469
   switch (cardtype) {
470
           default:
471
           case AVM_CARDTYPE_M1:
472
           case AVM_CARDTYPE_M2:
473
           case AVM_CARDTYPE_B1:
474
#if 0   /* problem with PCMCIA and PCI cards */
475
                switch (port) {
476
                        case 0x150:
477
                        case 0x250:
478
                        case 0x300:
479
                        case 0x340:
480
                                return 1;
481
                }
482
                return 0;
483
#else
484
                return 1;
485
#endif
486
           case AVM_CARDTYPE_T1:
487
                return ((port & 0x7) == 0) && ((port & 0x30) != 0x30);
488
   }
489
}
490
 
491
void B1_setinterrupt(unsigned int base,
492
                                 unsigned irq, int cardtype)
493
{
494
        switch (cardtype) {
495
           case AVM_CARDTYPE_T1:
496
              t1outp(base, B1_INSTAT, 0x00);
497
              t1outp(base, B1_INSTAT, 0x02);
498
              t1outp(base, T1_IRQMASTER, 0x08);
499
           default:
500
           case AVM_CARDTYPE_M1:
501
           case AVM_CARDTYPE_M2:
502
           case AVM_CARDTYPE_B1:
503
              b1outp(base, B1_INSTAT, 0x00);
504
              b1outp(base, B1_RESET, irq_table[irq]);
505
              b1outp(base, B1_INSTAT, 0x02);
506
         }
507
}
508
 
509
unsigned char B1_disable_irq(unsigned int base)
510
{
511
        return b1outp(base, B1_INSTAT, 0x00);
512
}
513
 
514
void T1_disable_irq(unsigned int base)
515
{
516
      t1outp(base, T1_IRQMASTER, 0x00);
517
}
518
 
519
void B1_reset(unsigned int base)
520
{
521
        b1outp(base, B1_RESET, 0);
522
        udelay(55 * 2 * 1000);  /* 2 TIC's */
523
 
524
        b1outp(base, B1_RESET, 1);
525
        udelay(55 * 2 * 1000);  /* 2 TIC's */
526
 
527
        b1outp(base, B1_RESET, 0);
528
        udelay(55 * 2 * 1000);  /* 2 TIC's */
529
}
530
 
531
void T1_reset(unsigned int base)
532
{
533
        /* reset T1 Controller */
534
        B1_reset(base);
535
        /* disable irq on HEMA */
536
        t1outp(base, B1_INSTAT, 0x00);
537
        t1outp(base, B1_OUTSTAT, 0x00);
538
        t1outp(base, T1_IRQMASTER, 0x00);
539
        /* reset HEMA board configuration */
540
        t1outp(base, T1_RESETBOARD, 0xf);
541
}
542
 
543
int B1_detect(unsigned int base, int cardtype)
544
{
545
        int onoff, i;
546
 
547
        if (cardtype == AVM_CARDTYPE_T1)
548
           return 0;
549
 
550
        /*
551
         * Statusregister 0000 00xx
552
         */
553
        if ((inb(base + B1_INSTAT) & 0xfc)
554
            || (inb(base + B1_OUTSTAT) & 0xfc))
555
                return 1;
556
        /*
557
         * Statusregister 0000 001x
558
         */
559
        b1outp(base, B1_INSTAT, 0x2);   /* enable irq */
560
        /* b1outp(base, B1_OUTSTAT, 0x2); */
561
        if ((inb(base + B1_INSTAT) & 0xfe) != 0x2
562
            /* || (inb(base + B1_OUTSTAT) & 0xfe) != 0x2 */)
563
                return 2;
564
        /*
565
         * Statusregister 0000 000x
566
         */
567
        b1outp(base, B1_INSTAT, 0x0);   /* disable irq */
568
        b1outp(base, B1_OUTSTAT, 0x0);
569
        if ((inb(base + B1_INSTAT) & 0xfe)
570
            || (inb(base + B1_OUTSTAT) & 0xfe))
571
                return 3;
572
 
573
        for (onoff = !0, i= 0; i < 10 ; i++) {
574
                b1_set_test_bit(base, cardtype, onoff);
575
                if (b1_get_test_bit(base, cardtype) != onoff)
576
                   return 4;
577
                onoff = !onoff;
578
        }
579
 
580
        if (cardtype == AVM_CARDTYPE_M1)
581
           return 0;
582
 
583
        if ((b1_rd_reg(base, B1_STAT1(cardtype)) & 0x0f) != 0x01)
584
           return 5;
585
 
586
        return 0;
587
}
588
 
589
int T1_detectandinit(unsigned int base, unsigned irq, int cardnr)
590
{
591
        unsigned char cregs[8];
592
        unsigned char reverse_cardnr;
593
        unsigned long flags;
594
        unsigned char dummy;
595
        int i;
596
 
597
        reverse_cardnr =   ((cardnr & 0x01) << 3) | ((cardnr & 0x02) << 1)
598
                         | ((cardnr & 0x04) >> 1) | ((cardnr & 0x08) >> 3);
599
        cregs[0] = (HEMA_VERSION_ID << 4) | (reverse_cardnr & 0xf);
600
        cregs[1] = 0x00; /* fast & slow link connected to CON1 */
601
        cregs[2] = 0x05; /* fast link 20MBit, slow link 20 MBit */
602
        cregs[3] = 0;
603
        cregs[4] = 0x11; /* zero wait state */
604
        cregs[5] = hema_irq_table[irq & 0xf];
605
        cregs[6] = 0;
606
        cregs[7] = 0;
607
 
608
        save_flags(flags);
609
        cli();
610
        /* board reset */
611
        t1outp(base, T1_RESETBOARD, 0xf);
612
        udelay(100 * 1000);
613
        dummy = t1inp(base, T1_FASTLINK+T1_OUTSTAT); /* first read */
614
 
615
        /* write config */
616
        dummy = (base >> 4) & 0xff;
617
        for (i=1;i<=0xf;i++) t1outp(base, i, dummy);
618
        t1outp(base, HEMA_PAL_ID & 0xf, dummy);
619
        t1outp(base, HEMA_PAL_ID >> 4, cregs[0]);
620
        for(i=1;i<7;i++) t1outp(base, 0, cregs[i]);
621
        t1outp(base, ((base >> 4)) & 0x3, cregs[7]);
622
        restore_flags(flags);
623
 
624
        udelay(100 * 1000);
625
        t1outp(base, T1_FASTLINK+T1_RESETLINK, 0);
626
        t1outp(base, T1_SLOWLINK+T1_RESETLINK, 0);
627
        udelay(10 * 1000);
628
        t1outp(base, T1_FASTLINK+T1_RESETLINK, 1);
629
        t1outp(base, T1_SLOWLINK+T1_RESETLINK, 1);
630
        udelay(100 * 1000);
631
        t1outp(base, T1_FASTLINK+T1_RESETLINK, 0);
632
        t1outp(base, T1_SLOWLINK+T1_RESETLINK, 0);
633
        udelay(10 * 1000);
634
        t1outp(base, T1_FASTLINK+T1_ANALYSE, 0);
635
        udelay(5 * 1000);
636
        t1outp(base, T1_SLOWLINK+T1_ANALYSE, 0);
637
 
638
        if (t1inp(base, T1_FASTLINK+T1_OUTSTAT) != 0x1) /* tx empty */
639
                return 1;
640
        if (t1inp(base, T1_FASTLINK+T1_INSTAT) != 0x0) /* rx empty */
641
                return 2;
642
        if (t1inp(base, T1_FASTLINK+T1_IRQENABLE) != 0x0)
643
                return 3;
644
        if ((t1inp(base, T1_FASTLINK+T1_FIFOSTAT) & 0xf0) != 0x70)
645
                return 4;
646
        if ((t1inp(base, T1_FASTLINK+T1_IRQMASTER) & 0x0e) != 0)
647
                return 5;
648
        if ((t1inp(base, T1_FASTLINK+T1_IDENT) & 0x7d) != 1)
649
                return 6;
650
        if (t1inp(base, T1_SLOWLINK+T1_OUTSTAT) != 0x1) /* tx empty */
651
                return 7;
652
        if ((t1inp(base, T1_SLOWLINK+T1_IRQMASTER) & 0x0e) != 0)
653
                return 8;
654
        if ((t1inp(base, T1_SLOWLINK+T1_IDENT) & 0x7d) != 0)
655
                return 9;
656
        return 0;
657
}
658
 
659
extern int loaddebug;
660
 
661
int B1_load_t4file(unsigned int base, avmb1_t4file * t4file)
662
{
663
        /*
664
         * Data is in user space !!!
665
         */
666
        unsigned char buf[256];
667
        unsigned char *dp;
668
        int i, left, retval;
669
 
670
 
671
        dp = t4file->data;
672
        left = t4file->len;
673
        while (left > sizeof(buf)) {
674
                retval = copy_from_user(buf, dp, sizeof(buf));
675
                if (retval)
676
                        return -EFAULT;
677
                if (loaddebug)
678
                        printk(KERN_DEBUG "b1capi: loading: %d bytes ..", sizeof(buf));
679
                for (i = 0; i < sizeof(buf); i++)
680
                        B1_put_byte(base, buf[i]);
681
                if (loaddebug)
682
                   printk("ok\n");
683
                left -= sizeof(buf);
684
                dp += sizeof(buf);
685
        }
686
        if (left) {
687
                retval = copy_from_user(buf, dp, left);
688
                if (retval)
689
                        return -EFAULT;
690
                if (loaddebug)
691
                        printk(KERN_DEBUG "b1capi: loading: %d bytes ..", left);
692
                for (i = 0; i < left; i++)
693
                        B1_put_byte(base, buf[i]);
694
                if (loaddebug)
695
                   printk("ok\n");
696
        }
697
        return 0;
698
}
699
 
700
int B1_load_config(unsigned int base, avmb1_t4file * config)
701
{
702
        /*
703
         * Data is in user space !!!
704
         */
705
        unsigned char buf[256];
706
        unsigned char *dp;
707
        int i, j, left, retval;
708
 
709
 
710
        dp = config->data;
711
        left = config->len;
712
        if (left) {
713
                B1_put_byte(base, SEND_CONFIG);
714
                B1_put_word(base, 1);
715
                B1_put_byte(base, SEND_CONFIG);
716
                B1_put_word(base, left);
717
        }
718
        while (left > sizeof(buf)) {
719
                retval = copy_from_user(buf, dp, sizeof(buf));
720
                if (retval)
721
                        return -EFAULT;
722
                if (loaddebug)
723
                        printk(KERN_DEBUG "b1capi: conf load: %d bytes ..", sizeof(buf));
724
                for (i = 0; i < sizeof(buf); ) {
725
                        B1_put_byte(base, SEND_CONFIG);
726
                        for (j=0; j < 4; j++) {
727
                                B1_put_byte(base, buf[i++]);
728
                        }
729
                }
730
                if (loaddebug)
731
                   printk("ok\n");
732
                left -= sizeof(buf);
733
                dp += sizeof(buf);
734
        }
735
        if (left) {
736
                retval = copy_from_user(buf, dp, left);
737
                if (retval)
738
                        return -EFAULT;
739
                if (loaddebug)
740
                        printk(KERN_DEBUG "b1capi: conf load: %d bytes ..", left);
741
                for (i = 0; i < left; ) {
742
                        B1_put_byte(base, SEND_CONFIG);
743
                        for (j=0; j < 4; j++) {
744
                                if (i < left)
745
                                        B1_put_byte(base, buf[i++]);
746
                                else
747
                                        B1_put_byte(base, 0);
748
                        }
749
                }
750
                if (loaddebug)
751
                   printk("ok\n");
752
        }
753
        return 0;
754
}
755
 
756
int B1_loaded(unsigned int base)
757
{
758
        int i;
759
        unsigned char ans;
760
 
761
        if (loaddebug)
762
                printk(KERN_DEBUG "b1capi: loaded: wait 1 ..\n");
763
        for (i = jiffies + 10 * HZ; i > jiffies;) {
764
                if (B1_tx_empty(base))
765
                        break;
766
        }
767
        if (!B1_tx_empty(base)) {
768
                printk(KERN_ERR "b1lli(0x%x): B1_loaded: timeout tx\n", base);
769
                return 0;
770
        }
771
        B1_put_byte(base, SEND_POLL);
772
        printk(KERN_DEBUG "b1capi: loaded: wait 2 ..\n");
773
        for (i = jiffies + 10 * HZ; i > jiffies;) {
774
                if (B1_rx_full(base)) {
775
                        if ((ans = B1_get_byte(base)) == RECEIVE_POLL) {
776
                                if (loaddebug)
777
                                        printk(KERN_DEBUG "b1capi: loaded: ok\n");
778
                                return 1;
779
                        }
780
                        printk(KERN_ERR "b1lli(0x%x): B1_loaded: got 0x%x ???\n",
781
                                base, ans);
782
                        return 0;
783
                }
784
        }
785
        printk(KERN_ERR "b1lli(0x%x): B1_loaded: timeout rx\n", base);
786
        return 0;
787
}
788
 
789
/*
790
 * -------------------------------------------------------------------
791
 */
792
static inline void parse_version(avmb1_card * card)
793
{
794
        int i, j;
795
        for (j = 0; j < AVM_MAXVERSION; j++)
796
                card->version[j] = "\0\0" + 1;
797
        for (i = 0, j = 0;
798
             j < AVM_MAXVERSION && i < card->versionlen;
799
             j++, i += card->versionbuf[i] + 1)
800
                card->version[j] = &card->versionbuf[i + 1];
801
}
802
/*
803
 * -------------------------------------------------------------------
804
 */
805
 
806
void B1_send_init(unsigned int port,
807
             unsigned int napps, unsigned int nncci, unsigned int cardnr)
808
{
809
        unsigned long flags;
810
 
811
        save_flags(flags);
812
        cli();
813
        B1_put_byte(port, SEND_INIT);
814
        B1_put_word(port, napps);
815
        B1_put_word(port, nncci);
816
        B1_put_word(port, cardnr);
817
        restore_flags(flags);
818
}
819
 
820
void B1_send_register(unsigned int port,
821
                      __u16 appid, __u32 nmsg,
822
                      __u32 nb3conn, __u32 nb3blocks, __u32 b3bsize)
823
{
824
        unsigned long flags;
825
 
826
        save_flags(flags);
827
        cli();
828
        B1_put_byte(port, SEND_REGISTER);
829
        B1_put_word(port, appid);
830
        B1_put_word(port, nmsg);
831
        B1_put_word(port, nb3conn);
832
        B1_put_word(port, nb3blocks);
833
        B1_put_word(port, b3bsize);
834
        restore_flags(flags);
835
}
836
 
837
void B1_send_release(unsigned int port,
838
                     __u16 appid)
839
{
840
        unsigned long flags;
841
 
842
        save_flags(flags);
843
        cli();
844
        B1_put_byte(port, SEND_RELEASE);
845
        B1_put_word(port, appid);
846
        restore_flags(flags);
847
}
848
 
849
void B1_send_message(unsigned int port, struct sk_buff *skb)
850
{
851
        unsigned long flags;
852
        __u16 len = CAPIMSG_LEN(skb->data);
853
        __u8 cmd = CAPIMSG_COMMAND(skb->data);
854
        __u8 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
855
        __u32 contr = CAPIMSG_CONTROL(skb->data);
856
 
857
        if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
858
                __u16 dlen = CAPIMSG_DATALEN(skb->data);
859
 
860
                if (showcapimsgs > 2) {
861
                        if (showcapimsgs & 1) {
862
                                printk(KERN_DEBUG "b1lli: Put [0x%lx] id#%d %s len=%u\n",
863
                                       (unsigned long) contr,
864
                                       CAPIMSG_APPID(skb->data),
865
                                       capi_cmd2str(cmd, subcmd), len);
866
                        } else {
867
                                printk(KERN_DEBUG "b1lli: Put [0x%lx] %s\n",
868
                                                (unsigned long) contr,
869
                                                capi_message2str(skb->data));
870
                        }
871
 
872
                }
873
                save_flags(flags);
874
                cli();
875
                B1_put_byte(port, SEND_DATA_B3_REQ);
876
                B1_put_slice(port, skb->data, len);
877
                B1_put_slice(port, skb->data + len, dlen);
878
                restore_flags(flags);
879
        } else {
880
                if (showcapimsgs) {
881
 
882
                        if (showcapimsgs & 1) {
883
                                printk(KERN_DEBUG "b1lli: Put [0x%lx] id#%d %s len=%u\n",
884
                                       (unsigned long) contr,
885
                                       CAPIMSG_APPID(skb->data),
886
                                       capi_cmd2str(cmd, subcmd), len);
887
                        } else {
888
                                printk(KERN_DEBUG "b1lli: Put [0x%lx] %s\n", (unsigned long)contr, capi_message2str(skb->data));
889
                        }
890
                }
891
                save_flags(flags);
892
                cli();
893
                B1_put_byte(port, SEND_MESSAGE);
894
                B1_put_slice(port, skb->data, len);
895
                restore_flags(flags);
896
        }
897
        dev_kfree_skb(skb, FREE_WRITE);
898
}
899
 
900
/*
901
 * -------------------------------------------------------------------
902
 */
903
 
904
void B1_handle_interrupt(avmb1_card * card)
905
{
906
        unsigned char b1cmd;
907
        struct sk_buff *skb;
908
 
909
        unsigned ApplId;
910
        unsigned MsgLen;
911
        unsigned DataB3Len;
912
        unsigned NCCI;
913
        unsigned WindowSize;
914
 
915
t1retry:
916
        if (!B1_rx_full(card->port))
917
                return;
918
 
919
        b1cmd = B1_get_byte(card->port);
920
 
921
        switch (b1cmd) {
922
 
923
        case RECEIVE_DATA_B3_IND:
924
 
925
                ApplId = (unsigned) B1_get_word(card->port);
926
                MsgLen = B1_get_slice(card->port, card->msgbuf);
927
                DataB3Len = B1_get_slice(card->port, card->databuf);
928
 
929
                if (showcapimsgs > 2) {
930
                        __u8 cmd = CAPIMSG_COMMAND(card->msgbuf);
931
                        __u8 subcmd = CAPIMSG_SUBCOMMAND(card->msgbuf);
932
                        __u32 contr = CAPIMSG_CONTROL(card->msgbuf);
933
                        CAPIMSG_SETDATA(card->msgbuf, card->databuf);
934
                        if (showcapimsgs & 1) {
935
                                printk(KERN_DEBUG "b1lli: Got [0x%lx] id#%d %s len=%u/%u\n",
936
                                       (unsigned long) contr,
937
                                       CAPIMSG_APPID(card->msgbuf),
938
                                       capi_cmd2str(cmd, subcmd),
939
                                       MsgLen, DataB3Len);
940
                        } else {
941
                                printk(KERN_DEBUG "b1lli: Got [0x%lx] %s\n", (unsigned long)contr, capi_message2str(card->msgbuf));
942
                        }
943
                }
944
                if (!(skb = dev_alloc_skb(DataB3Len + MsgLen))) {
945
                        printk(KERN_ERR "b1lli: incoming packet dropped\n");
946
                } else {
947
                        SET_SKB_FREE(skb);
948
                        memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
949
                        memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len);
950
                        CAPIMSG_SETDATA(skb->data, skb->data + MsgLen);
951
                        avmb1_handle_capimsg(card, ApplId, skb);
952
                }
953
                break;
954
 
955
        case RECEIVE_MESSAGE:
956
 
957
                ApplId = (unsigned) B1_get_word(card->port);
958
                MsgLen = B1_get_slice(card->port, card->msgbuf);
959
                if (showcapimsgs) {
960
                        __u8 cmd = CAPIMSG_COMMAND(card->msgbuf);
961
                        __u8 subcmd = CAPIMSG_SUBCOMMAND(card->msgbuf);
962
                        __u32 contr = CAPIMSG_CONTROL(card->msgbuf);
963
                        if (showcapimsgs & 1) {
964
                                printk(KERN_DEBUG "b1lli: Got [0x%lx] id#%d %s len=%u\n",
965
                                       (unsigned long) contr,
966
                                       CAPIMSG_APPID(card->msgbuf),
967
                                       capi_cmd2str(cmd, subcmd),
968
                                       MsgLen);
969
                        } else {
970
                                printk(KERN_DEBUG "b1lli: Got [0x%lx] %s\n",
971
                                                (unsigned long) contr,
972
                                                capi_message2str(card->msgbuf));
973
                        }
974
 
975
                }
976
                if (!(skb = dev_alloc_skb(MsgLen))) {
977
                        printk(KERN_ERR "b1lli: incoming packet dropped\n");
978
                } else {
979
                        SET_SKB_FREE(skb);
980
                        memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
981
                        avmb1_handle_capimsg(card, ApplId, skb);
982
                }
983
                break;
984
 
985
        case RECEIVE_NEW_NCCI:
986
 
987
                ApplId = B1_get_word(card->port);
988
                NCCI = B1_get_word(card->port);
989
                WindowSize = B1_get_word(card->port);
990
 
991
                if (showcapimsgs)
992
                        printk(KERN_DEBUG "b1lli(0x%x): NEW_NCCI app %u ncci 0x%x\n", card->port, ApplId, NCCI);
993
 
994
                avmb1_handle_new_ncci(card, ApplId, NCCI, WindowSize);
995
 
996
                break;
997
 
998
        case RECEIVE_FREE_NCCI:
999
 
1000
                ApplId = B1_get_word(card->port);
1001
                NCCI = B1_get_word(card->port);
1002
 
1003
                if (showcapimsgs)
1004
                        printk(KERN_DEBUG "b1lli(0x%x): FREE_NCCI app %u ncci 0x%x\n", card->port, ApplId, NCCI);
1005
 
1006
                avmb1_handle_free_ncci(card, ApplId, NCCI);
1007
                break;
1008
 
1009
        case RECEIVE_START:
1010
                if (card->cardtype == AVM_CARDTYPE_T1) {
1011
                   B1_put_byte(card->port, SEND_POLLACK);
1012
                   /* printk(KERN_DEBUG "b1lli: T1 watchdog\n"); */
1013
                }
1014
                if (card->blocked)
1015
                        printk(KERN_DEBUG "b1lli(0x%x): RESTART\n", card->port);
1016
                card->blocked = 0;
1017
                break;
1018
 
1019
        case RECEIVE_STOP:
1020
                printk(KERN_DEBUG "b1lli(0x%x): STOP\n", card->port);
1021
                card->blocked = 1;
1022
                break;
1023
 
1024
        case RECEIVE_INIT:
1025
 
1026
                card->versionlen = B1_get_slice(card->port, card->versionbuf);
1027
                card->cardstate = CARD_ACTIVE;
1028
                parse_version(card);
1029
                printk(KERN_INFO "b1lli(0x%x): %s-card (%s) now active\n",
1030
                       card->port,
1031
                       card->version[VER_CARDTYPE],
1032
                       card->version[VER_DRIVER]);
1033
                avmb1_card_ready(card);
1034
                break;
1035
        case RECEIVE_TASK_READY:
1036
                ApplId = (unsigned) B1_get_word(card->port);
1037
                MsgLen = B1_get_slice(card->port, card->msgbuf);
1038
                card->msgbuf[MsgLen] = 0;
1039
                printk(KERN_INFO "b1lli(0x%x): Task %d \"%s\" ready.\n",
1040
                                card->port, ApplId, card->msgbuf);
1041
                break;
1042
        default:
1043
                printk(KERN_ERR "b1lli(0x%x): B1_handle_interrupt: 0x%x ???\n",
1044
                                card->port, b1cmd);
1045
                break;
1046
        }
1047
        if (card->cardtype == AVM_CARDTYPE_T1)
1048
                goto t1retry;
1049
}

powered by: WebSVN 2.1.0

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