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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [isdn/] [hisax/] [hfc_2bds0.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/* $Id: hfc_2bds0.c,v 1.1 2005-12-20 10:17:01 jcastillo Exp $
2
 *
3
 *  specific routines for CCD's HFC 2BDS0
4
 *
5
 * Author       Karsten Keil (keil@temic-ech.spacenet.de)
6
 *
7
 *
8
 * $Log: not supported by cvs2svn $
9
 * Revision 1.1.1.1  2001/09/10 07:44:18  simons
10
 * Initial import
11
 *
12
 * Revision 1.1.1.1  2001/07/02 17:58:32  simons
13
 * Initial revision
14
 *
15
 * Revision 1.1.2.9  1998/11/03 00:06:24  keil
16
 * certification related changes
17
 * fixed logging for smaller stack use
18
 *
19
 * Revision 1.1.2.8  1998/09/30 22:23:55  keil
20
 * Fix missing line in setstack*
21
 *
22
 * Revision 1.1.2.7  1998/09/27 13:06:01  keil
23
 * Apply most changes from 2.1.X (HiSax 3.1)
24
 *
25
 * Revision 1.1.2.6  1998/06/27 22:54:07  keil
26
 * make 16.3c working with 3.0
27
 *
28
 * Revision 1.1.2.5  1998/05/27 18:05:23  keil
29
 * HiSax 3.0
30
 *
31
 * Revision 1.1.2.4  1998/04/08 21:54:35  keil
32
 * Fix "ll_trans ..." message
33
 *
34
 * Revision 1.1.2.3  1998/04/04 21:59:20  keil
35
 * Fixed B-channel access
36
 *
37
 * Revision 1.1.2.2  1998/01/27 22:40:35  keil
38
 * fixed IRQ latency, B-channel selection and more
39
 *
40
 * Revision 1.1.2.1  1998/01/11 22:54:00  keil
41
 * Teles 16.3c (HFC 2BDS0) first version
42
 *
43
 *
44
 */
45
#define __NO_VERSION__
46
#include "hisax.h"
47
#include "hfc_2bds0.h"
48
#include "isdnl1.h"
49
#include <linux/interrupt.h>
50
/*
51
#define KDEBUG_DEF
52
#include "kdebug.h"
53
*/
54
 
55
#define byteout(addr,val) outb(val,addr)
56
#define bytein(addr) inb(addr)
57
 
58
static void
59
dummyf(struct IsdnCardState *cs, u_char * data, int size)
60
{
61
        printk(KERN_WARNING "HiSax: hfcd dummy fifo called\n");
62
}
63
 
64
static inline u_char
65
ReadReg(struct IsdnCardState *cs, int data, u_char reg)
66
{
67
        register u_char ret;
68
 
69
        if (data) {
70
                if (cs->hw.hfcD.cip != reg) {
71
                        cs->hw.hfcD.cip = reg;
72
                        byteout(cs->hw.hfcD.addr | 1, reg);
73
                }
74
                ret = bytein(cs->hw.hfcD.addr);
75
#if HFC_REG_DEBUG
76
                if (cs->debug & L1_DEB_HSCX_FIFO && (data != 2))
77
                        debugl1(cs, "t3c RD %02x %02x", reg, ret);
78
#endif
79
        } else
80
                ret = bytein(cs->hw.hfcD.addr | 1);
81
        return (ret);
82
}
83
 
84
static inline void
85
WriteReg(struct IsdnCardState *cs, int data, u_char reg, u_char value)
86
{
87
        if (cs->hw.hfcD.cip != reg) {
88
                cs->hw.hfcD.cip = reg;
89
                byteout(cs->hw.hfcD.addr | 1, reg);
90
        }
91
        if (data)
92
                byteout(cs->hw.hfcD.addr, value);
93
#if HFC_REG_DEBUG
94
        if (cs->debug & L1_DEB_HSCX_FIFO && (data != HFCD_DATA_NODEB))
95
                debugl1(cs, "t3c W%c %02x %02x", data ? 'D' : 'C', reg, value);
96
#endif
97
}
98
 
99
/* Interface functions */
100
 
101
static u_char
102
readreghfcd(struct IsdnCardState *cs, u_char offset)
103
{
104
        return(ReadReg(cs, HFCD_DATA, offset));
105
}
106
 
107
static void
108
writereghfcd(struct IsdnCardState *cs, u_char offset, u_char value)
109
{
110
        WriteReg(cs, HFCD_DATA, offset, value);
111
}
112
 
113
void
114
set_cs_func(struct IsdnCardState *cs)
115
{
116
        cs->readisac = &readreghfcd;
117
        cs->writeisac = &writereghfcd;
118
        cs->readisacfifo = &dummyf;
119
        cs->writeisacfifo = &dummyf;
120
        cs->BC_Read_Reg = &ReadReg;
121
        cs->BC_Write_Reg = &WriteReg;
122
}
123
 
124
static inline int
125
WaitForBusy(struct IsdnCardState *cs)
126
{
127
        int to = 130;
128
 
129
        while (!(ReadReg(cs, HFCD_DATA, HFCD_STAT) & HFCD_BUSY) && to) {
130
                udelay(1);
131
                to--;
132
        }
133
        if (!to)
134
                printk(KERN_WARNING "HiSax: WaitForBusy timeout\n");
135
        return (to);
136
}
137
 
138
static inline int
139
WaitNoBusy(struct IsdnCardState *cs)
140
{
141
        long flags;
142
        int to = 130;
143
 
144
        while ((ReadReg(cs, HFCD_STATUS, HFCD_STATUS) & HFCD_BUSY) && to) {
145
                save_flags(flags);
146
                sti();
147
                udelay(1);
148
                to--;
149
                restore_flags(flags);
150
        }
151
        if (!to)
152
                printk(KERN_WARNING "HiSax: WaitNoBusy timeout\n");
153
        return (to);
154
}
155
 
156
static int
157
SelFiFo(struct IsdnCardState *cs, u_char FiFo)
158
{
159
        u_char cip;
160
        long flags;
161
 
162
 
163
        if (cs->hw.hfcD.fifo == FiFo)
164
                return(1);
165
        save_flags(flags);
166
        cli();
167
        switch(FiFo) {
168
                case 0: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B1;
169
                        break;
170
                case 1: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B1;
171
                        break;
172
                case 2: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B2;
173
                        break;
174
                case 3: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B2;
175
                        break;
176
                case 4: cip = HFCD_FIFO | HFCD_Z1 | HFCD_SEND;
177
                        break;
178
                case 5: cip = HFCD_FIFO | HFCD_Z1 | HFCD_REC;
179
                        break;
180
                default:
181
                        restore_flags(flags);
182
                        debugl1(cs, "SelFiFo Error");
183
                        return(0);
184
        }
185
        cs->hw.hfcD.fifo = FiFo;
186
        WaitNoBusy(cs);
187
        cs->BC_Write_Reg(cs, HFCD_DATA, cip, 0);
188
        sti();
189
        WaitForBusy(cs);
190
        restore_flags(flags);
191
        return(2);
192
}
193
static int
194
GetFreeFifoBytes_B(struct BCState *bcs)
195
{
196
        int s;
197
 
198
        if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
199
                return (bcs->cs->hw.hfcD.bfifosize);
200
        s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
201
        if (s <= 0)
202
                s += bcs->cs->hw.hfcD.bfifosize;
203
        s = bcs->cs->hw.hfcD.bfifosize - s;
204
        return (s);
205
}
206
 
207
static int
208
GetFreeFifoBytes_D(struct IsdnCardState *cs)
209
{
210
        int s;
211
 
212
        if (cs->hw.hfcD.f1 == cs->hw.hfcD.f2)
213
                return (cs->hw.hfcD.dfifosize);
214
        s = cs->hw.hfcD.send[cs->hw.hfcD.f1] - cs->hw.hfcD.send[cs->hw.hfcD.f2];
215
        if (s <= 0)
216
                s += cs->hw.hfcD.dfifosize;
217
        s = cs->hw.hfcD.dfifosize - s;
218
        return (s);
219
}
220
 
221
static int
222
ReadZReg(struct IsdnCardState *cs, u_char reg)
223
{
224
        int val;
225
 
226
        WaitNoBusy(cs);
227
        val = 256 * ReadReg(cs, HFCD_DATA, reg | HFCB_Z_HIGH);
228
        WaitNoBusy(cs);
229
        val += ReadReg(cs, HFCD_DATA, reg | HFCB_Z_LOW);
230
        return (val);
231
}
232
 
233
static void
234
hfc_sched_event(struct BCState *bcs, int event)
235
{
236
        bcs->event |= 1 << event;
237
        queue_task(&bcs->tqueue, &tq_immediate);
238
        mark_bh(IMMEDIATE_BH);
239
}
240
 
241
static struct sk_buff
242
*hfc_empty_fifo(struct BCState *bcs, int count)
243
{
244
        u_char *ptr;
245
        struct sk_buff *skb;
246
        struct IsdnCardState *cs = bcs->cs;
247
        int idx;
248
        int chksum;
249
        long flags;
250
        u_char stat, cip;
251
 
252
        if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
253
                debugl1(cs, "hfc_empty_fifo");
254
        idx = 0;
255
        save_flags(flags);
256
        if (count > HSCX_BUFMAX + 3) {
257
                if (cs->debug & L1_DEB_WARN)
258
                        debugl1(cs, "hfc_empty_fifo: incoming packet too large");
259
                cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
260
                while (idx++ < count) {
261
                        cli();
262
                        WaitNoBusy(cs);
263
                        ReadReg(cs, HFCD_DATA_NODEB, cip);
264
                        sti();
265
                }
266
                skb = NULL;
267
        } else if (count < 4) {
268
                if (cs->debug & L1_DEB_WARN)
269
                        debugl1(cs, "hfc_empty_fifo: incoming packet too small");
270
                cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
271
                cli();
272
                while ((idx++ < count) && WaitNoBusy(cs))
273
                        ReadReg(cs, HFCD_DATA_NODEB, cip);
274
                skb = NULL;
275
        } else if (!(skb = dev_alloc_skb(count - 3)))
276
                printk(KERN_WARNING "HFC: receive out of memory\n");
277
        else {
278
                SET_SKB_FREE(skb);
279
                ptr = skb_put(skb, count - 3);
280
                idx = 0;
281
                cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
282
                cli();
283
                while (idx < (count - 3)) {
284
                        cli();
285
                        if (!WaitNoBusy(cs))
286
                                break;
287
                        *ptr = ReadReg(cs,  HFCD_DATA_NODEB, cip);
288
                        sti();
289
                        ptr++;
290
                        idx++;
291
                }
292
                if (idx != count - 3) {
293
                        sti();
294
                        debugl1(cs, "RFIFO BUSY error");
295
                        printk(KERN_WARNING "HFC FIFO channel %d BUSY Error\n", bcs->channel);
296
                        dev_kfree_skb(skb, FREE_READ);
297
                        skb = NULL;
298
                } else {
299
                        cli();
300
                        WaitNoBusy(cs);
301
                        chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
302
                        WaitNoBusy(cs);
303
                        chksum += ReadReg(cs, HFCD_DATA, cip);
304
                        WaitNoBusy(cs);
305
                        stat = ReadReg(cs, HFCD_DATA, cip);
306
                        sti();
307
                        if (cs->debug & L1_DEB_HSCX)
308
                                debugl1(cs, "hfc_empty_fifo %d chksum %x stat %x",
309
                                        bcs->channel, chksum, stat);
310
                        if (stat) {
311
                                debugl1(cs, "FIFO CRC error");
312
                                dev_kfree_skb(skb, FREE_READ);
313
                                skb = NULL;
314
                        }
315
                }
316
        }
317
        sti();
318
        WaitForBusy(cs);
319
        cli();
320
        WaitNoBusy(cs);
321
        stat = ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F2_INC |
322
                HFCB_REC | HFCB_CHANNEL(bcs->channel));
323
        sti();
324
        WaitForBusy(cs);
325
        restore_flags(flags);
326
        return (skb);
327
}
328
 
329
static void
330
hfc_fill_fifo(struct BCState *bcs)
331
{
332
        struct IsdnCardState *cs = bcs->cs;
333
        long flags;
334
        int idx, fcnt;
335
        int count;
336
        u_char cip;
337
 
338
        if (!bcs->tx_skb)
339
                return;
340
        if (bcs->tx_skb->len <= 0)
341
                return;
342
        save_flags(flags);
343
        cli();
344
        SelFiFo(cs, HFCB_SEND | HFCB_CHANNEL(bcs->channel));
345
        cip = HFCB_FIFO | HFCB_F1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
346
        WaitNoBusy(cs);
347
        bcs->hw.hfc.f1 = ReadReg(cs, HFCD_DATA, cip);
348
        WaitNoBusy(cs);
349
        cip = HFCB_FIFO | HFCB_F2 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
350
        WaitNoBusy(cs);
351
        bcs->hw.hfc.f2 = ReadReg(cs, HFCD_DATA, cip);
352
        bcs->hw.hfc.send[bcs->hw.hfc.f1] = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
353
        sti();
354
        if (cs->debug & L1_DEB_HSCX)
355
                debugl1(cs, "hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
356
                        bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
357
                        bcs->hw.hfc.send[bcs->hw.hfc.f1]);
358
        fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
359
        if (fcnt < 0)
360
                fcnt += 32;
361
        if (fcnt > 30) {
362
                if (cs->debug & L1_DEB_HSCX)
363
                        debugl1(cs, "hfc_fill_fifo more as 30 frames");
364
                restore_flags(flags);
365
                return;
366
        }
367
        count = GetFreeFifoBytes_B(bcs);
368
        if (cs->debug & L1_DEB_HSCX)
369
                debugl1(cs, "hfc_fill_fifo %d count(%ld/%d),%lx",
370
                        bcs->channel, bcs->tx_skb->len,
371
                        count, current->state);
372
        if (count < bcs->tx_skb->len) {
373
                if (cs->debug & L1_DEB_HSCX)
374
                        debugl1(cs, "hfc_fill_fifo no fifo mem");
375
                restore_flags(flags);
376
                return;
377
        }
378
        cip = HFCB_FIFO | HFCB_FIFO_IN | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
379
        idx = 0;
380
        cli();
381
        WaitForBusy(cs);
382
        WaitNoBusy(cs);
383
        WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
384
        while (idx < bcs->tx_skb->len) {
385
                cli();
386
                if (!WaitNoBusy(cs))
387
                        break;
388
                WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx]);
389
                sti();
390
                idx++;
391
        }
392
        if (idx != bcs->tx_skb->len) {
393
                sti();
394
                debugl1(cs, "FIFO Send BUSY error");
395
                printk(KERN_WARNING "HFC S FIFO channel %d BUSY Error\n", bcs->channel);
396
        } else {
397
                bcs->tx_cnt -= bcs->tx_skb->len;
398
                if (bcs->st->lli.l1writewakeup &&
399
                        (PACKET_NOACK != bcs->tx_skb->pkt_type))
400
                        bcs->st->lli.l1writewakeup(bcs->st, bcs->tx_skb->len);
401
                dev_kfree_skb(bcs->tx_skb, FREE_WRITE);
402
                bcs->tx_skb = NULL;
403
        }
404
        WaitForBusy(cs);
405
        cli();
406
        WaitNoBusy(cs);
407
        ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F1_INC | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
408
        sti();
409
        WaitForBusy(cs);
410
        test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
411
        restore_flags(flags);
412
        return;
413
}
414
 
415
static void
416
hfc_send_data(struct BCState *bcs)
417
{
418
        struct IsdnCardState *cs = bcs->cs;
419
 
420
        if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
421
                hfc_fill_fifo(bcs);
422
                test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
423
        } else
424
                debugl1(cs,"send_data %d blocked", bcs->channel);
425
}
426
 
427
void
428
main_rec_2bds0(struct BCState *bcs)
429
{
430
        long flags;
431
        struct IsdnCardState *cs = bcs->cs;
432
        int z1, z2, rcnt;
433
        u_char f1, f2, cip;
434
        int receive, count = 5;
435
        struct sk_buff *skb;
436
 
437
        save_flags(flags);
438
    Begin:
439
        count--;
440
        cli();
441
        if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
442
                debugl1(cs,"rec_data %d blocked", bcs->channel);
443
                restore_flags(flags);
444
                return;
445
        }
446
        SelFiFo(cs, HFCB_REC | HFCB_CHANNEL(bcs->channel));
447
        cip = HFCB_FIFO | HFCB_F1 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
448
        WaitNoBusy(cs);
449
        f1 = ReadReg(cs, HFCD_DATA, cip);
450
        cip = HFCB_FIFO | HFCB_F2 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
451
        WaitNoBusy(cs);
452
        f2 = ReadReg(cs, HFCD_DATA, cip);
453
        sti();
454
        if (f1 != f2) {
455
                if (cs->debug & L1_DEB_HSCX)
456
                        debugl1(cs, "hfc rec %d f1(%d) f2(%d)",
457
                                bcs->channel, f1, f2);
458
                cli();
459
                z1 = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
460
                z2 = ReadZReg(cs, HFCB_FIFO | HFCB_Z2 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
461
                sti();
462
                rcnt = z1 - z2;
463
                if (rcnt < 0)
464
                        rcnt += cs->hw.hfcD.bfifosize;
465
                rcnt++;
466
                if (cs->debug & L1_DEB_HSCX)
467
                        debugl1(cs, "hfc rec %d z1(%x) z2(%x) cnt(%d)",
468
                                bcs->channel, z1, z2, rcnt);
469
                if ((skb = hfc_empty_fifo(bcs, rcnt))) {
470
                        cli();
471
                        skb_queue_tail(&bcs->rqueue, skb);
472
                        sti();
473
                        hfc_sched_event(bcs, B_RCVBUFREADY);
474
                }
475
                rcnt = f1 -f2;
476
                if (rcnt<0)
477
                        rcnt += 32;
478
                if (rcnt>1)
479
                        receive = 1;
480
                else
481
                        receive = 0;
482
        } else
483
                receive = 0;
484
        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
485
        if (count && receive)
486
                goto Begin;
487
        restore_flags(flags);
488
        return;
489
}
490
 
491
void
492
mode_2bs0(struct BCState *bcs, int mode, int bc)
493
{
494
        struct IsdnCardState *cs = bcs->cs;
495
 
496
        if (cs->debug & L1_DEB_HSCX)
497
                debugl1(cs, "HFCD bchannel mode %d bchan %d/%d",
498
                        mode, bc, bcs->channel);
499
        bcs->mode = mode;
500
        bcs->channel = bc;
501
        switch (mode) {
502
                case (L1_MODE_NULL):
503
                        if (bc) {
504
                                cs->hw.hfcD.conn |= 0x18;
505
                                cs->hw.hfcD.sctrl &= ~SCTRL_B2_ENA;
506
                        } else {
507
                                cs->hw.hfcD.conn |= 0x3;
508
                                cs->hw.hfcD.sctrl &= ~SCTRL_B1_ENA;
509
                        }
510
                        break;
511
                case (L1_MODE_TRANS):
512
                        if (bc) {
513
                                cs->hw.hfcD.ctmt |= 2;
514
                                cs->hw.hfcD.conn &= ~0x18;
515
                                cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
516
                        } else {
517
                                cs->hw.hfcD.ctmt |= 1;
518
                                cs->hw.hfcD.conn &= ~0x3;
519
                                cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
520
                        }
521
                        break;
522
                case (L1_MODE_HDLC):
523
                        if (bc) {
524
                                cs->hw.hfcD.ctmt &= ~2;
525
                                cs->hw.hfcD.conn &= ~0x18;
526
                                cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
527
                        } else {
528
                                cs->hw.hfcD.ctmt &= ~1;
529
                                cs->hw.hfcD.conn &= ~0x3;
530
                                cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
531
                        }
532
                        break;
533
        }
534
        WriteReg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl);
535
        WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt);
536
        WriteReg(cs, HFCD_DATA, HFCD_CONN, cs->hw.hfcD.conn);
537
}
538
 
539
static void
540
hfc_l2l1(struct PStack *st, int pr, void *arg)
541
{
542
        struct sk_buff *skb = arg;
543
        long flags;
544
 
545
        switch (pr) {
546
                case (PH_DATA | REQUEST):
547
                        save_flags(flags);
548
                        cli();
549
                        if (st->l1.bcs->tx_skb) {
550
                                skb_queue_tail(&st->l1.bcs->squeue, skb);
551
                                restore_flags(flags);
552
                        } else {
553
                                st->l1.bcs->tx_skb = skb;
554
/*                              test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
555
*/                              st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
556
                                restore_flags(flags);
557
                        }
558
                        break;
559
                case (PH_PULL | INDICATION):
560
                        if (st->l1.bcs->tx_skb) {
561
                                printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
562
                                break;
563
                        }
564
                        save_flags(flags);
565
                        cli();
566
/*                      test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
567
*/                      st->l1.bcs->tx_skb = skb;
568
                        st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
569
                        restore_flags(flags);
570
                        break;
571
                case (PH_PULL | REQUEST):
572
                        if (!st->l1.bcs->tx_skb) {
573
                                test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
574
                                st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
575
                        } else
576
                                test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
577
                        break;
578
                case (PH_ACTIVATE | REQUEST):
579
                        test_and_set_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
580
                        mode_2bs0(st->l1.bcs, st->l1.mode, st->l1.bc);
581
                        l1_msg_b(st, pr, arg);
582
                        break;
583
                case (PH_DEACTIVATE | REQUEST):
584
                        l1_msg_b(st, pr, arg);
585
                        break;
586
                case (PH_DEACTIVATE | CONFIRM):
587
                        test_and_clear_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
588
                        test_and_clear_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
589
                        mode_2bs0(st->l1.bcs, 0, st->l1.bc);
590
                        st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
591
                        break;
592
        }
593
}
594
 
595
void
596
close_2bs0(struct BCState *bcs)
597
{
598
        mode_2bs0(bcs, 0, bcs->channel);
599
        if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
600
                discard_queue(&bcs->rqueue);
601
                discard_queue(&bcs->squeue);
602
                if (bcs->tx_skb) {
603
                        dev_kfree_skb(bcs->tx_skb, FREE_WRITE);
604
                        bcs->tx_skb = NULL;
605
                        test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
606
                }
607
        }
608
}
609
 
610
static int
611
open_hfcstate(struct IsdnCardState *cs, struct BCState *bcs)
612
{
613
        if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
614
                skb_queue_head_init(&bcs->rqueue);
615
                skb_queue_head_init(&bcs->squeue);
616
        }
617
        bcs->tx_skb = NULL;
618
        test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
619
        bcs->event = 0;
620
        bcs->tx_cnt = 0;
621
        return (0);
622
}
623
 
624
int
625
setstack_2b(struct PStack *st, struct BCState *bcs)
626
{
627
        bcs->channel = st->l1.bc;
628
        if (open_hfcstate(st->l1.hardware, bcs))
629
                return (-1);
630
        st->l1.bcs = bcs;
631
        st->l2.l2l1 = hfc_l2l1;
632
        setstack_manager(st);
633
        bcs->st = st;
634
        setstack_l1_B(st);
635
        return (0);
636
}
637
 
638
static void
639
hfcd_bh(struct IsdnCardState *cs)
640
{
641
/*      struct PStack *stptr;
642
*/
643
        if (!cs)
644
                return;
645
#if 0   
646
        if (test_and_clear_bit(D_CLEARBUSY, &cs->event)) {
647
                if (cs->debug)
648
                        debugl1(cs, "D-Channel Busy cleared");
649
                stptr = cs->stlist;
650
                while (stptr != NULL) {
651
                        stptr->l1.l1l2(stptr, PH_PAUSE | CONFIRM, NULL);
652
                        stptr = stptr->next;
653
                }
654
        }
655
#endif
656
        if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
657
                switch (cs->ph_state) {
658
                        case (0):
659
                                l1_msg(cs, HW_RESET | INDICATION, NULL);
660
                                break;
661
                        case (3):
662
                                l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
663
                                break;
664
                        case (8):
665
                                l1_msg(cs, HW_RSYNC | INDICATION, NULL);
666
                                break;
667
                        case (6):
668
                                l1_msg(cs, HW_INFO2 | INDICATION, NULL);
669
                                break;
670
                        case (7):
671
                                l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
672
                                break;
673
                        default:
674
                                break;
675
                }
676
        }
677
        if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
678
                DChannel_proc_rcv(cs);
679
        if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
680
                DChannel_proc_xmt(cs);
681
}
682
 
683
void
684
sched_event_D(struct IsdnCardState *cs, int event)
685
{
686
        test_and_set_bit(event, &cs->event);
687
        queue_task(&cs->tqueue, &tq_immediate);
688
        mark_bh(IMMEDIATE_BH);
689
}
690
 
691
static
692
int receive_dmsg(struct IsdnCardState *cs)
693
{
694
        struct sk_buff *skb;
695
        long flags;
696
        int idx;
697
        int rcnt, z1, z2;
698
        u_char stat, cip, f1, f2;
699
        int chksum;
700
        int count=5;
701
        u_char *ptr;
702
 
703
        save_flags(flags);
704
        cli();
705
        if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
706
                debugl1(cs, "rec_dmsg blocked");
707
                restore_flags(flags);
708
                return(1);
709
        }
710
        SelFiFo(cs, 4 | HFCD_REC);
711
        cip = HFCD_FIFO | HFCD_F1 | HFCD_REC;
712
        WaitNoBusy(cs);
713
        f1 = cs->readisac(cs, cip) & 0xf;
714
        cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
715
        WaitNoBusy(cs);
716
        f2 = cs->readisac(cs, cip) & 0xf;
717
        while ((f1 != f2) && count--) {
718
                z1 = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_REC);
719
                z2 = ReadZReg(cs, HFCD_FIFO | HFCD_Z2 | HFCD_REC);
720
                rcnt = z1 - z2;
721
                if (rcnt < 0)
722
                        rcnt += cs->hw.hfcD.dfifosize;
723
                rcnt++;
724
                if (cs->debug & L1_DEB_ISAC)
725
                        debugl1(cs, "hfcd recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
726
                                f1, f2, z1, z2, rcnt);
727
                sti();
728
                idx = 0;
729
                cip = HFCD_FIFO | HFCD_FIFO_OUT | HFCD_REC;
730
                if (rcnt > MAX_DFRAME_LEN + 3) {
731
                        if (cs->debug & L1_DEB_WARN)
732
                                debugl1(cs, "empty_fifo d: incoming packet too large");
733
                        while (idx < rcnt) {
734
                                cli();
735
                                if (!(WaitNoBusy(cs)))
736
                                        break;
737
                                ReadReg(cs, HFCD_DATA_NODEB, cip);
738
                                sti();
739
                                idx++;
740
                        }
741
                } else if (rcnt < 4) {
742
                        if (cs->debug & L1_DEB_WARN)
743
                                debugl1(cs, "empty_fifo d: incoming packet too small");
744
                        cli();
745
                        while ((idx++ < rcnt) && WaitNoBusy(cs))
746
                                ReadReg(cs, HFCD_DATA_NODEB, cip);
747
                } else if ((skb = dev_alloc_skb(rcnt - 3))) {
748
                        SET_SKB_FREE(skb);
749
                        ptr = skb_put(skb, rcnt - 3);
750
                        while (idx < (rcnt - 3)) {
751
                                cli();
752
                                if (!(WaitNoBusy(cs)))
753
                                        break;
754
                                *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
755
                                sti();
756
                                idx++;
757
                                ptr++;
758
                        }
759
                        if (idx != (rcnt - 3)) {
760
                                sti();
761
                                debugl1(cs, "RFIFO D BUSY error");
762
                                printk(KERN_WARNING "HFC DFIFO channel BUSY Error\n");
763
                                dev_kfree_skb(skb, FREE_READ);
764
                                skb = NULL;
765
                        } else {
766
                                cli();
767
                                WaitNoBusy(cs);
768
                                chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
769
                                WaitNoBusy(cs);
770
                                chksum += ReadReg(cs, HFCD_DATA, cip);
771
                                WaitNoBusy(cs);
772
                                stat = ReadReg(cs, HFCD_DATA, cip);
773
                                sti();
774
                                if (cs->debug & L1_DEB_ISAC)
775
                                        debugl1(cs, "empty_dfifo chksum %x stat %x",
776
                                                chksum, stat);
777
                                if (stat) {
778
                                        debugl1(cs, "FIFO CRC error");
779
                                        dev_kfree_skb(skb, FREE_READ);
780
                                        skb = NULL;
781
                                } else {
782
                                        skb_queue_tail(&cs->rq, skb);
783
                                        sched_event_D(cs, D_RCVBUFREADY);
784
                                }
785
                        }
786
                } else
787
                        printk(KERN_WARNING "HFC: D receive out of memory\n");
788
                sti();
789
                WaitForBusy(cs);
790
                cip = HFCD_FIFO | HFCD_F2_INC | HFCD_REC;
791
                cli();
792
                WaitNoBusy(cs);
793
                stat = ReadReg(cs, HFCD_DATA, cip);
794
                sti();
795
                WaitForBusy(cs);
796
                cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
797
                cli();
798
                WaitNoBusy(cs);
799
                f2 = cs->readisac(cs, cip) & 0xf;
800
        }
801
        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
802
        restore_flags(flags);
803
        return(1);
804
}
805
 
806
static void
807
hfc_fill_dfifo(struct IsdnCardState *cs)
808
{
809
        long flags;
810
        int idx, fcnt;
811
        int count;
812
        u_char cip;
813
 
814
        if (!cs->tx_skb)
815
                return;
816
        if (cs->tx_skb->len <= 0)
817
                return;
818
 
819
        save_flags(flags);
820
        cli();
821
        SelFiFo(cs, 4 | HFCD_SEND);
822
        cip = HFCD_FIFO | HFCD_F1 | HFCD_SEND;
823
        WaitNoBusy(cs);
824
        cs->hw.hfcD.f1 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
825
        WaitNoBusy(cs);
826
        cip = HFCD_FIFO | HFCD_F2 | HFCD_SEND;
827
        cs->hw.hfcD.f2 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
828
        cs->hw.hfcD.send[cs->hw.hfcD.f1] = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_SEND);
829
        sti();
830
        if (cs->debug & L1_DEB_ISAC)
831
                debugl1(cs, "hfc_fill_Dfifo f1(%d) f2(%d) z1(%x)",
832
                        cs->hw.hfcD.f1, cs->hw.hfcD.f2,
833
                        cs->hw.hfcD.send[cs->hw.hfcD.f1]);
834
        fcnt = cs->hw.hfcD.f1 - cs->hw.hfcD.f2;
835
        if (fcnt < 0)
836
                fcnt += 16;
837
        if (fcnt > 14) {
838
                if (cs->debug & L1_DEB_HSCX)
839
                        debugl1(cs, "hfc_fill_Dfifo more as 14 frames");
840
                restore_flags(flags);
841
                return;
842
        }
843
        count = GetFreeFifoBytes_D(cs);
844
        if (cs->debug & L1_DEB_ISAC)
845
                debugl1(cs, "hfc_fill_Dfifo count(%ld/%d)",
846
                        cs->tx_skb->len, count);
847
        if (count < cs->tx_skb->len) {
848
                if (cs->debug & L1_DEB_ISAC)
849
                        debugl1(cs, "hfc_fill_Dfifo no fifo mem");
850
                restore_flags(flags);
851
                return;
852
        }
853
        cip = HFCD_FIFO | HFCD_FIFO_IN | HFCD_SEND;
854
        idx = 0;
855
        cli();
856
        WaitForBusy(cs);
857
        WaitNoBusy(cs);
858
        WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx++]);
859
        while (idx < cs->tx_skb->len) {
860
                cli();
861
                if (!(WaitNoBusy(cs)))
862
                        break;
863
                WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx]);
864
                sti();
865
                idx++;
866
        }
867
        if (idx != cs->tx_skb->len) {
868
                sti();
869
                debugl1(cs, "DFIFO Send BUSY error");
870
                printk(KERN_WARNING "HFC S DFIFO channel BUSY Error\n");
871
        }
872
        WaitForBusy(cs);
873
        cli();
874
        WaitNoBusy(cs);
875
        ReadReg(cs, HFCD_DATA, HFCD_FIFO | HFCD_F1_INC | HFCD_SEND);
876
        dev_kfree_skb(cs->tx_skb, FREE_WRITE);
877
        cs->tx_skb = NULL;
878
        sti();
879
        WaitForBusy(cs);
880
        restore_flags(flags);
881
        return;
882
}
883
 
884
static
885
struct BCState *Sel_BCS(struct IsdnCardState *cs, int channel)
886
{
887
        if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
888
                return(&cs->bcs[0]);
889
        else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
890
                return(&cs->bcs[1]);
891
        else
892
                return(NULL);
893
}
894
 
895
void
896
hfc2bds0_interrupt(struct IsdnCardState *cs, u_char val)
897
{
898
        u_char exval;
899
        struct BCState *bcs;
900
        int count=15;
901
        long flags;
902
 
903
        if (cs->debug & L1_DEB_ISAC)
904
                debugl1(cs, "HFCD irq %x %s", val,
905
                        test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
906
                        "locked" : "unlocked");
907
        val &= cs->hw.hfcD.int_m1;
908
        if (val & 0x40) { /* TE state machine irq */
909
                exval = cs->readisac(cs, HFCD_STATES) & 0xf;
910
                if (cs->debug & L1_DEB_ISAC)
911
                        debugl1(cs, "ph_state chg %d->%d", cs->ph_state,
912
                                exval);
913
                cs->ph_state = exval;
914
                sched_event_D(cs, D_L1STATECHANGE);
915
                val &= ~0x40;
916
        }
917
        while (val) {
918
                save_flags(flags);
919
                cli();
920
                if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
921
                        cs->hw.hfcD.int_s1 |= val;
922
                        restore_flags(flags);
923
                        return;
924
                }
925
                if (cs->hw.hfcD.int_s1 & 0x18) {
926
                        exval = val;
927
                        val =  cs->hw.hfcD.int_s1;
928
                        cs->hw.hfcD.int_s1 = exval;
929
                }
930
                if (val & 0x08) {
931
                        if (!(bcs=Sel_BCS(cs, 0))) {
932
                                if (cs->debug)
933
                                        debugl1(cs, "hfcd spurious 0x08 IRQ");
934
                        } else
935
                                main_rec_2bds0(bcs);
936
                }
937
                if (val & 0x10) {
938
                        if (!(bcs=Sel_BCS(cs, 1))) {
939
                                if (cs->debug)
940
                                        debugl1(cs, "hfcd spurious 0x10 IRQ");
941
                        } else
942
                                main_rec_2bds0(bcs);
943
                }
944
                if (val & 0x01) {
945
                        if (!(bcs=Sel_BCS(cs, 0))) {
946
                                if (cs->debug)
947
                                        debugl1(cs, "hfcd spurious 0x01 IRQ");
948
                        } else {
949
                                if (bcs->tx_skb) {
950
                                        if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
951
                                                hfc_fill_fifo(bcs);
952
                                                test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
953
                                        } else
954
                                                debugl1(cs,"fill_data %d blocked", bcs->channel);
955
                                } else {
956
                                        if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
957
                                                if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
958
                                                        hfc_fill_fifo(bcs);
959
                                                        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
960
                                                } else
961
                                                        debugl1(cs,"fill_data %d blocked", bcs->channel);
962
                                        } else {
963
                                                hfc_sched_event(bcs, B_XMTBUFREADY);
964
                                        }
965
                                }
966
                        }
967
                }
968
                if (val & 0x02) {
969
                        if (!(bcs=Sel_BCS(cs, 1))) {
970
                                if (cs->debug)
971
                                        debugl1(cs, "hfcd spurious 0x02 IRQ");
972
                        } else {
973
                                if (bcs->tx_skb) {
974
                                        if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
975
                                                hfc_fill_fifo(bcs);
976
                                                test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
977
                                        } else
978
                                                debugl1(cs,"fill_data %d blocked", bcs->channel);
979
                                } else {
980
                                        if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
981
                                                if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
982
                                                        hfc_fill_fifo(bcs);
983
                                                        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
984
                                                } else
985
                                                        debugl1(cs,"fill_data %d blocked", bcs->channel);
986
                                        } else {
987
                                                hfc_sched_event(bcs, B_XMTBUFREADY);
988
                                        }
989
                                }
990
                        }
991
                }
992
                if (val & 0x20) {       /* receive dframe */
993
                        receive_dmsg(cs);
994
                }
995
                if (val & 0x04) {       /* dframe transmitted */
996
                        if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
997
                                del_timer(&cs->dbusytimer);
998
                        if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
999
                                sched_event_D(cs, D_CLEARBUSY);
1000
                        if (cs->tx_skb)
1001
                                if (cs->tx_skb->len) {
1002
                                        if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1003
                                                hfc_fill_dfifo(cs);
1004
                                                test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1005
                                        } else {
1006
                                                debugl1(cs, "hfc_fill_dfifo irq blocked");
1007
                                        }
1008
                                        goto afterXPR;
1009
                                } else {
1010
                                        dev_kfree_skb(cs->tx_skb, FREE_WRITE);
1011
                                        cs->tx_cnt = 0;
1012
                                        cs->tx_skb = NULL;
1013
                                }
1014
                        if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
1015
                                cs->tx_cnt = 0;
1016
                                if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1017
                                        hfc_fill_dfifo(cs);
1018
                                        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1019
                                } else {
1020
                                        debugl1(cs, "hfc_fill_dfifo irq blocked");
1021
                                }
1022
                        } else
1023
                                sched_event_D(cs, D_XMTBUFREADY);
1024
                }
1025
      afterXPR:
1026
                if (cs->hw.hfcD.int_s1 && count--) {
1027
                        val = cs->hw.hfcD.int_s1;
1028
                        cs->hw.hfcD.int_s1 = 0;
1029
                        if (cs->debug & L1_DEB_ISAC)
1030
                                debugl1(cs, "HFCD irq %x loop %d", val, 15-count);
1031
                } else
1032
                        val = 0;
1033
                restore_flags(flags);
1034
        }
1035
}
1036
 
1037
static void
1038
HFCD_l1hw(struct PStack *st, int pr, void *arg)
1039
{
1040
        struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
1041
        struct sk_buff *skb = arg;
1042
 
1043
        switch (pr) {
1044
                case (PH_DATA | REQUEST):
1045
                        if (cs->debug & DEB_DLOG_HEX)
1046
                                LogFrame(cs, skb->data, skb->len);
1047
                        if (cs->debug & DEB_DLOG_VERBOSE)
1048
                                dlogframe(cs, skb, 0);
1049
                        if (cs->tx_skb) {
1050
                                skb_queue_tail(&cs->sq, skb);
1051
#ifdef L2FRAME_DEBUG            /* psa */
1052
                                if (cs->debug & L1_DEB_LAPD)
1053
                                        Logl2Frame(cs, skb, "PH_DATA Queued", 0);
1054
#endif
1055
                        } else {
1056
                                cs->tx_skb = skb;
1057
                                cs->tx_cnt = 0;
1058
#ifdef L2FRAME_DEBUG            /* psa */
1059
                                if (cs->debug & L1_DEB_LAPD)
1060
                                        Logl2Frame(cs, skb, "PH_DATA", 0);
1061
#endif
1062
                                if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1063
                                        hfc_fill_dfifo(cs);
1064
                                        test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1065
                                } else
1066
                                        debugl1(cs, "hfc_fill_dfifo blocked");
1067
 
1068
                        }
1069
                        break;
1070
                case (PH_PULL | INDICATION):
1071
                        if (cs->tx_skb) {
1072
                                if (cs->debug & L1_DEB_WARN)
1073
                                        debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
1074
                                skb_queue_tail(&cs->sq, skb);
1075
                                break;
1076
                        }
1077
                        if (cs->debug & DEB_DLOG_HEX)
1078
                                LogFrame(cs, skb->data, skb->len);
1079
                        if (cs->debug & DEB_DLOG_VERBOSE)
1080
                                dlogframe(cs, skb, 0);
1081
                        cs->tx_skb = skb;
1082
                        cs->tx_cnt = 0;
1083
#ifdef L2FRAME_DEBUG            /* psa */
1084
                        if (cs->debug & L1_DEB_LAPD)
1085
                                Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
1086
#endif
1087
                        if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1088
                                hfc_fill_dfifo(cs);
1089
                                test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1090
                        } else
1091
                                debugl1(cs, "hfc_fill_dfifo blocked");
1092
                        break;
1093
                case (PH_PULL | REQUEST):
1094
#ifdef L2FRAME_DEBUG            /* psa */
1095
                        if (cs->debug & L1_DEB_LAPD)
1096
                                debugl1(cs, "-> PH_REQUEST_PULL");
1097
#endif
1098
                        if (!cs->tx_skb) {
1099
                                test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1100
                                st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1101
                        } else
1102
                                test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1103
                        break;
1104
                case (HW_RESET | REQUEST):
1105
                        cs->writeisac(cs, HFCD_STATES, HFCD_LOAD_STATE | 3); /* HFC ST 3 */
1106
                        udelay(6);
1107
                        cs->writeisac(cs, HFCD_STATES, 3); /* HFC ST 2 */
1108
                        cs->hw.hfcD.mst_m |= HFCD_MASTER;
1109
                        cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1110
                        cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
1111
                        l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
1112
                        break;
1113
                case (HW_ENABLE | REQUEST):
1114
                        cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
1115
                        break;
1116
                case (HW_DEACTIVATE | REQUEST):
1117
                        cs->hw.hfcD.mst_m &= ~HFCD_MASTER;
1118
                        cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1119
                        break;
1120
                case (HW_INFO3 | REQUEST):
1121
                        cs->hw.hfcD.mst_m |= HFCD_MASTER;
1122
                        cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1123
                        break;
1124
#if 0
1125
                case (HW_TESTLOOP | REQUEST):
1126
                        u_char val = 0;
1127
                        if (1 & (int) arg)
1128
                                val |= 0x0c;
1129
                        if (2 & (int) arg)
1130
                                val |= 0x3;
1131
                        if (test_bit(HW_IOM1, &cs->HW_Flags)) {
1132
                                /* IOM 1 Mode */
1133
                                if (!val) {
1134
                                        cs->writeisac(cs, ISAC_SPCR, 0xa);
1135
                                        cs->writeisac(cs, ISAC_ADF1, 0x2);
1136
                                } else {
1137
                                        cs->writeisac(cs, ISAC_SPCR, val);
1138
                                        cs->writeisac(cs, ISAC_ADF1, 0xa);
1139
                                }
1140
                        } else {
1141
                                /* IOM 2 Mode */
1142
                                cs->writeisac(cs, ISAC_SPCR, val);
1143
                                if (val)
1144
                                        cs->writeisac(cs, ISAC_ADF1, 0x8);
1145
                                else
1146
                                        cs->writeisac(cs, ISAC_ADF1, 0x0);
1147
                        }
1148
                        break;
1149
#endif
1150
                default:
1151
                        if (cs->debug & L1_DEB_WARN)
1152
                                debugl1(cs, "hfcd_l1hw unknown pr %4x", pr);
1153
                        break;
1154
        }
1155
}
1156
 
1157
void
1158
setstack_hfcd(struct PStack *st, struct IsdnCardState *cs)
1159
{
1160
        st->l1.l1hw = HFCD_l1hw;
1161
}
1162
 
1163
static void
1164
hfc_dbusy_timer(struct IsdnCardState *cs)
1165
{
1166
#if 0
1167
        struct PStack *stptr;
1168
        if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
1169
                if (cs->debug)
1170
                        debugl1(cs, "D-Channel Busy");
1171
                test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
1172
                stptr = cs->stlist;
1173
 
1174
                while (stptr != NULL) {
1175
                        stptr->l1.l1l2(stptr, PH_PAUSE | INDICATION, NULL);
1176
                        stptr = stptr->next;
1177
                }
1178
        }
1179
#endif
1180
}
1181
 
1182
__initfunc(unsigned int
1183
*init_send_hfcd(int cnt))
1184
{
1185
        int i, *send;
1186
 
1187
        if (!(send = kmalloc(cnt * sizeof(unsigned int), GFP_ATOMIC))) {
1188
                printk(KERN_WARNING
1189
                       "HiSax: No memory for hfcd.send\n");
1190
                return(NULL);
1191
        }
1192
        for (i = 0; i < cnt; i++)
1193
                send[i] = 0x1fff;
1194
        return(send);
1195
}
1196
 
1197
__initfunc(void
1198
init2bds0(struct IsdnCardState *cs))
1199
{
1200
        cs->setstack_d = setstack_hfcd;
1201
        cs->dbusytimer.function = (void *) hfc_dbusy_timer;
1202
        cs->dbusytimer.data = (long) cs;
1203
        init_timer(&cs->dbusytimer);
1204
        cs->tqueue.routine = (void *) (void *) hfcd_bh;
1205
        if (!cs->hw.hfcD.send)
1206
                cs->hw.hfcD.send = init_send_hfcd(16);
1207
        if (!cs->bcs[0].hw.hfc.send)
1208
                cs->bcs[0].hw.hfc.send = init_send_hfcd(32);
1209
        if (!cs->bcs[1].hw.hfc.send)
1210
                cs->bcs[1].hw.hfc.send = init_send_hfcd(32);
1211
        cs->BC_Send_Data = &hfc_send_data;
1212
        cs->bcs[0].BC_SetStack = setstack_2b;
1213
        cs->bcs[1].BC_SetStack = setstack_2b;
1214
        cs->bcs[0].BC_Close = close_2bs0;
1215
        cs->bcs[1].BC_Close = close_2bs0;
1216
        mode_2bs0(cs->bcs, 0, 0);
1217
        mode_2bs0(cs->bcs + 1, 0, 1);
1218
}
1219
 
1220
void
1221
release2bds0(struct IsdnCardState *cs)
1222
{
1223
        if (cs->bcs[0].hw.hfc.send) {
1224
                kfree(cs->bcs[0].hw.hfc.send);
1225
                cs->bcs[0].hw.hfc.send = NULL;
1226
        }
1227
        if (cs->bcs[1].hw.hfc.send) {
1228
                kfree(cs->bcs[1].hw.hfc.send);
1229
                cs->bcs[1].hw.hfc.send = NULL;
1230
        }
1231
        if (cs->hw.hfcD.send) {
1232
                kfree(cs->hw.hfcD.send);
1233
                cs->hw.hfcD.send = NULL;
1234
        }
1235
}

powered by: WebSVN 2.1.0

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