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

Subversion Repositories or1k

[/] [or1k/] [tags/] [before_ORP/] [uclinux/] [uClinux-2.0.x/] [drivers/] [isdn/] [hisax/] [isdnl1.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* $Id: isdnl1.c,v 1.1.1.1 2001-09-10 07:44:18 simons Exp $
2
 
3
 * isdnl1.c     common low level stuff for Siemens Chipsetbased isdn cards
4
 *              based on the teles driver from Jan den Ouden
5
 *
6
 * Author       Karsten Keil (keil@isdn4linux.de)
7
 *
8
 *              This file is (c) under GNU PUBLIC LICENSE
9
 *              For changes and modifications please read
10
 *              ../../../Documentation/isdn/HiSax.cert
11
 *
12
 * Thanks to    Jan den Ouden
13
 *              Fritz Elfert
14
 *              Beat Doebeli
15
 *
16
 *
17
 * $Log: not supported by cvs2svn $
18
 * Revision 1.1.1.1  2001/07/02 17:58:32  simons
19
 * Initial revision
20
 *
21
 * Revision 1.15.2.19  1998/11/03 00:06:48  keil
22
 * certification related changes
23
 * fixed logging for smaller stack use
24
 *
25
 * Revision 1.15.2.18  1998/09/30 22:26:35  keil
26
 * Add init of l1.Flags
27
 *
28
 * Revision 1.15.2.17  1998/09/27 23:54:17  keil
29
 * cosmetics
30
 *
31
 * Revision 1.15.2.16  1998/09/27 13:06:22  keil
32
 * Apply most changes from 2.1.X (HiSax 3.1)
33
 *
34
 * Revision 1.15.2.15  1998/09/12 18:44:00  niemann
35
 * Added new card: Sedlbauer ISDN-Controller PC/104
36
 *
37
 * Revision 1.15.2.14  1998/08/25 14:01:35  calle
38
 * Ported driver for AVM Fritz!Card PCI from the 2.1 tree.
39
 * I could not test it.
40
 *
41
 * Revision 1.15.2.13  1998/07/15 14:43:37  calle
42
 * Support for AVM passive PCMCIA cards:
43
 *    A1 PCMCIA, FRITZ!Card PCMCIA and FRITZ!Card PCMCIA 2.0
44
 *
45
 * Revision 1.15.2.12  1998/05/27 18:05:43  keil
46
 * HiSax 3.0
47
 *
48
 * Revision 1.15.2.11  1998/05/26 10:36:51  keil
49
 * fixes from certification
50
 *
51
 * Revision 1.15.2.10  1998/04/11 18:47:45  keil
52
 * Fixed bug which was overwriting nrcards
53
 * New card support
54
 *
55
 * Revision 1.15.2.9  1998/04/08 21:52:00  keil
56
 * new debug
57
 *
58
 * Revision 1.15.2.8  1998/03/07 23:15:26  tsbogend
59
 * made HiSax working on Linux/Alpha
60
 *
61
 * Revision 1.15.2.7  1998/02/11 14:23:14  keil
62
 * support for Dr Neuhaus Niccy PnP and PCI
63
 *
64
 * Revision 1.15.2.6  1998/02/09 11:24:11  keil
65
 * New leased line support (Read README.HiSax!)
66
 *
67
 * Revision 1.15.2.5  1998/01/27 22:33:55  keil
68
 * dynalink ----> asuscom
69
 *
70
 * Revision 1.15.2.4  1998/01/11 22:55:20  keil
71
 * 16.3c support
72
 *
73
 * Revision 1.15.2.3  1997/11/15 18:50:34  keil
74
 * new common init function
75
 *
76
 * Revision 1.15.2.2  1997/10/17 22:13:54  keil
77
 * update to last hisax version
78
 *
79
 * Revision 2.6  1997/09/12 10:05:16  keil
80
 * ISDN_CTRL_DEBUG define
81
 *
82
 * Revision 2.5  1997/09/11 17:24:45  keil
83
 * Add new cards
84
 *
85
 * Revision 2.4  1997/08/15 17:47:09  keil
86
 * avoid oops because a uninitialised timer
87
 *
88
 * Revision 2.3  1997/08/01 11:16:40  keil
89
 * cosmetics
90
 *
91
 * Revision 2.2  1997/07/30 17:11:08  keil
92
 * L1deactivated exported
93
 *
94
 * Revision 2.1  1997/07/27 21:35:38  keil
95
 * new layer1 interface
96
 *
97
 * Revision 2.0  1997/06/26 11:02:53  keil
98
 * New Layer and card interface
99
 *
100
 * Revision 1.15  1997/05/27 15:17:55  fritz
101
 * Added changes for recent 2.1.x kernels:
102
 *   changed return type of isdn_close
103
 *   queue_task_* -> queue_task
104
 *   clear/set_bit -> test_and_... where apropriate.
105
 *   changed type of hard_header_cache parameter.
106
 *
107
 * old changes removed KKe
108
 *
109
 */
110
 
111
const char *l1_revision = "$Revision: 1.1.1.1 $";
112
 
113
#define __NO_VERSION__
114
#include <linux/config.h>
115
#include "hisax.h"
116
#include "isdnl1.h"
117
 
118
#define TIMER3_VALUE 7000
119
 
120
static
121
struct Fsm l1fsm_b =
122
{NULL, 0, 0, NULL, NULL};
123
 
124
static
125
struct Fsm l1fsm_d =
126
{NULL, 0, 0, NULL, NULL};
127
 
128
enum {
129
        ST_L1_F2,
130
        ST_L1_F3,
131
        ST_L1_F4,
132
        ST_L1_F5,
133
        ST_L1_F6,
134
        ST_L1_F7,
135
        ST_L1_F8,
136
};
137
 
138
#define L1D_STATE_COUNT (ST_L1_F8+1)
139
 
140
static char *strL1DState[] =
141
{
142
        "ST_L1_F2",
143
        "ST_L1_F3",
144
        "ST_L1_F4",
145
        "ST_L1_F5",
146
        "ST_L1_F6",
147
        "ST_L1_F7",
148
        "ST_L1_F8",
149
};
150
 
151
enum {
152
        ST_L1_NULL,
153
        ST_L1_WAIT_ACT,
154
        ST_L1_WAIT_DEACT,
155
        ST_L1_ACTIV,
156
};
157
 
158
#define L1B_STATE_COUNT (ST_L1_ACTIV+1)
159
 
160
static char *strL1BState[] =
161
{
162
        "ST_L1_NULL",
163
        "ST_L1_WAIT_ACT",
164
        "ST_L1_WAIT_DEACT",
165
        "ST_L1_ACTIV",
166
};
167
 
168
enum {
169
        EV_PH_ACTIVATE,
170
        EV_PH_DEACTIVATE,
171
        EV_RESET_IND,
172
        EV_DEACT_CNF,
173
        EV_DEACT_IND,
174
        EV_POWER_UP,
175
        EV_RSYNC_IND,
176
        EV_INFO2_IND,
177
        EV_INFO4_IND,
178
        EV_TIMER_DEACT,
179
        EV_TIMER_ACT,
180
        EV_TIMER3,
181
};
182
 
183
#define L1_EVENT_COUNT (EV_TIMER3 + 1)
184
 
185
static char *strL1Event[] =
186
{
187
        "EV_PH_ACTIVATE",
188
        "EV_PH_DEACTIVATE",
189
        "EV_RESET_IND",
190
        "EV_DEACT_CNF",
191
        "EV_DEACT_IND",
192
        "EV_POWER_UP",
193
        "EV_RSYNC_IND",
194
        "EV_INFO2_IND",
195
        "EV_INFO4_IND",
196
        "EV_TIMER_DEACT",
197
        "EV_TIMER_ACT",
198
        "EV_TIMER3",
199
};
200
 
201
void
202
debugl1(struct IsdnCardState *cs, char *fmt, ...)
203
{
204
        va_list args;
205
        char tmp[8];
206
 
207
        va_start(args, fmt);
208
        sprintf(tmp, "Card%d ", cs->cardnr + 1);
209
        VHiSax_putstatus(cs, tmp, fmt, args);
210
        va_end(args);
211
}
212
 
213
static void
214
l1m_debug(struct FsmInst *fi, char *fmt, ...)
215
{
216
        va_list args;
217
        struct PStack *st = fi->userdata;
218
        struct IsdnCardState *cs = st->l1.hardware;
219
        char tmp[8];
220
 
221
        va_start(args, fmt);
222
        sprintf(tmp, "Card%d ", cs->cardnr + 1);
223
        VHiSax_putstatus(cs, tmp, fmt, args);
224
        va_end(args);
225
}
226
 
227
void
228
L1activated(struct IsdnCardState *cs)
229
{
230
        struct PStack *st;
231
 
232
        st = cs->stlist;
233
        while (st) {
234
                if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
235
                        st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
236
                else
237
                        st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
238
                st = st->next;
239
        }
240
}
241
 
242
void
243
L1deactivated(struct IsdnCardState *cs)
244
{
245
        struct PStack *st;
246
 
247
        st = cs->stlist;
248
        while (st) {
249
                if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
250
                        st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
251
                st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
252
                st = st->next;
253
        }
254
        test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
255
}
256
 
257
void
258
DChannel_proc_xmt(struct IsdnCardState *cs)
259
{
260
        struct PStack *stptr;
261
 
262
        if (cs->tx_skb)
263
                return;
264
 
265
        stptr = cs->stlist;
266
        while (stptr != NULL)
267
                if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
268
                        stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
269
                        break;
270
                } else
271
                        stptr = stptr->next;
272
}
273
 
274
void
275
DChannel_proc_rcv(struct IsdnCardState *cs)
276
{
277
        struct sk_buff *skb, *nskb;
278
        struct PStack *stptr = cs->stlist;
279
        int found, tei, sapi;
280
 
281
        if (stptr)
282
                if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
283
                        FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
284
        while ((skb = skb_dequeue(&cs->rq))) {
285
#ifdef L2FRAME_DEBUG            /* psa */
286
                if (cs->debug & L1_DEB_LAPD)
287
                        Logl2Frame(cs, skb, "PH_DATA", 1);
288
#endif
289
                stptr = cs->stlist;
290
                sapi = skb->data[0] >> 2;
291
                tei = skb->data[1] >> 1;
292
 
293
                if (cs->debug & DEB_DLOG_HEX)
294
                        LogFrame(cs, skb->data, skb->len);
295
                if (cs->debug & DEB_DLOG_VERBOSE)
296
                        dlogframe(cs, skb, 1);
297
                if (tei == GROUP_TEI) {
298
                        if (sapi == CTRL_SAPI) { /* sapi 0 */
299
                                while (stptr != NULL) {
300
                                        if ((nskb = skb_clone(skb, GFP_ATOMIC)))
301
                                                stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
302
                                        else
303
                                                printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
304
                                        stptr = stptr->next;
305
                                }
306
                        } else if (sapi == TEI_SAPI) {
307
                                while (stptr != NULL) {
308
                                        if ((nskb = skb_clone(skb, GFP_ATOMIC)))
309
                                                stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
310
                                        else
311
                                                printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
312
                                        stptr = stptr->next;
313
                                }
314
                        }
315
                        dev_kfree_skb(skb, FREE_READ);
316
                } else if (sapi == CTRL_SAPI) { /* sapi 0 */
317
                        found = 0;
318
                        while (stptr != NULL)
319
                                if (tei == stptr->l2.tei) {
320
                                        stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
321
                                        found = !0;
322
                                        break;
323
                                } else
324
                                        stptr = stptr->next;
325
                        if (!found)
326
                                dev_kfree_skb(skb, FREE_READ);
327
                }
328
        }
329
}
330
 
331
static void
332
BChannel_proc_xmt(struct BCState *bcs)
333
{
334
        struct PStack *st = bcs->st;
335
 
336
        if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
337
                debugl1(bcs->cs, "BC_BUSY Error");
338
                return;
339
        }
340
 
341
        if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
342
                st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
343
        if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
344
                if (!test_bit(BC_FLG_BUSY, &bcs->Flag) && (!skb_queue_len(&bcs->squeue))) {
345
                        st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
346
                }
347
        }
348
}
349
 
350
static void
351
BChannel_proc_rcv(struct BCState *bcs)
352
{
353
        struct sk_buff *skb;
354
 
355
        if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
356
                FsmDelTimer(&bcs->st->l1.timer, 4);
357
                FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
358
        }
359
        while ((skb = skb_dequeue(&bcs->rqueue))) {
360
                bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
361
        }
362
}
363
 
364
static void
365
BChannel_bh(struct BCState *bcs)
366
{
367
        if (!bcs)
368
                return;
369
        if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
370
                BChannel_proc_rcv(bcs);
371
        if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
372
                BChannel_proc_xmt(bcs);
373
}
374
 
375
void
376
HiSax_addlist(struct IsdnCardState *cs,
377
              struct PStack *st)
378
{
379
        st->next = cs->stlist;
380
        cs->stlist = st;
381
}
382
 
383
void
384
HiSax_rmlist(struct IsdnCardState *cs,
385
             struct PStack *st)
386
{
387
        struct PStack *p;
388
 
389
        FsmDelTimer(&st->l1.timer, 0);
390
        if (cs->stlist == st)
391
                cs->stlist = st->next;
392
        else {
393
                p = cs->stlist;
394
                while (p)
395
                        if (p->next == st) {
396
                                p->next = st->next;
397
                                return;
398
                        } else
399
                                p = p->next;
400
        }
401
}
402
 
403
void
404
init_bcstate(struct IsdnCardState *cs,
405
             int bc)
406
{
407
        struct BCState *bcs = cs->bcs + bc;
408
 
409
        bcs->cs = cs;
410
        bcs->channel = bc;
411
        bcs->tqueue.next = 0;
412
        bcs->tqueue.sync = 0;
413
        bcs->tqueue.routine = (void *) (void *) BChannel_bh;
414
        bcs->tqueue.data = bcs;
415
        bcs->BC_SetStack = NULL;
416
        bcs->BC_Close = NULL;
417
        bcs->Flag = 0;
418
}
419
 
420
#ifdef L2FRAME_DEBUG            /* psa */
421
 
422
char *
423
l2cmd(u_char cmd)
424
{
425
        switch (cmd & ~0x10) {
426
                case 1:
427
                        return "RR";
428
                case 5:
429
                        return "RNR";
430
                case 9:
431
                        return "REJ";
432
                case 0x6f:
433
                        return "SABME";
434
                case 0x0f:
435
                        return "DM";
436
                case 3:
437
                        return "UI";
438
                case 0x43:
439
                        return "DISC";
440
                case 0x63:
441
                        return "UA";
442
                case 0x87:
443
                        return "FRMR";
444
                case 0xaf:
445
                        return "XID";
446
                default:
447
                        if (!(cmd & 1))
448
                                return "I";
449
                        else
450
                                return "invalid command";
451
        }
452
}
453
 
454
static char tmpdeb[32];
455
 
456
char *
457
l2frames(u_char * ptr)
458
{
459
        switch (ptr[2] & ~0x10) {
460
                case 1:
461
                case 5:
462
                case 9:
463
                        sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
464
                        break;
465
                case 0x6f:
466
                case 0x0f:
467
                case 3:
468
                case 0x43:
469
                case 0x63:
470
                case 0x87:
471
                case 0xaf:
472
                        sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
473
                        break;
474
                default:
475
                        if (!(ptr[2] & 1)) {
476
                                sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
477
                                break;
478
                        } else
479
                                return "invalid command";
480
        }
481
 
482
 
483
        return tmpdeb;
484
}
485
 
486
void
487
Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
488
{
489
        u_char *ptr;
490
 
491
        ptr = skb->data;
492
 
493
        if (ptr[0] & 1 || !(ptr[1] & 1))
494
                debugl1(cs, "Address not LAPD");
495
        else
496
                debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
497
                        (dir ? "<-" : "->"), buf, l2frames(ptr),
498
                        ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
499
}
500
#endif
501
 
502
static void
503
l1_reset(struct FsmInst *fi, int event, void *arg)
504
{
505
        FsmChangeState(fi, ST_L1_F3);
506
}
507
 
508
static void
509
l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
510
{
511
        struct PStack *st = fi->userdata;
512
 
513
        FsmChangeState(fi, ST_L1_F3);
514
        if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
515
                st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
516
}
517
 
518
static void
519
l1_deact_req(struct FsmInst *fi, int event, void *arg)
520
{
521
        struct PStack *st = fi->userdata;
522
 
523
        FsmChangeState(fi, ST_L1_F3);
524
//      if (!test_bit(FLG_L1_T3RUN, &st->l1.Flags)) {
525
                FsmDelTimer(&st->l1.timer, 1);
526
                FsmAddTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
527
                test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
528
//      }
529
}
530
 
531
static void
532
l1_power_up(struct FsmInst *fi, int event, void *arg)
533
{
534
        struct PStack *st = fi->userdata;
535
 
536
        if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
537
                FsmChangeState(fi, ST_L1_F4);
538
                st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
539
                FsmDelTimer(&st->l1.timer, 1);
540
                FsmAddTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
541
                test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
542
        } else
543
                FsmChangeState(fi, ST_L1_F3);
544
}
545
 
546
static void
547
l1_go_F5(struct FsmInst *fi, int event, void *arg)
548
{
549
        FsmChangeState(fi, ST_L1_F5);
550
}
551
 
552
static void
553
l1_go_F8(struct FsmInst *fi, int event, void *arg)
554
{
555
        FsmChangeState(fi, ST_L1_F8);
556
}
557
 
558
static void
559
l1_info2_ind(struct FsmInst *fi, int event, void *arg)
560
{
561
        struct PStack *st = fi->userdata;
562
 
563
        FsmChangeState(fi, ST_L1_F6);
564
        st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
565
}
566
 
567
static void
568
l1_info4_ind(struct FsmInst *fi, int event, void *arg)
569
{
570
        struct PStack *st = fi->userdata;
571
 
572
        FsmChangeState(fi, ST_L1_F7);
573
        st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
574
        if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
575
                FsmDelTimer(&st->l1.timer, 4);
576
        if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
577
                if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
578
                        FsmDelTimer(&st->l1.timer, 3);
579
                FsmAddTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
580
                test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
581
        }
582
}
583
 
584
static void
585
l1_timer3(struct FsmInst *fi, int event, void *arg)
586
{
587
        struct PStack *st = fi->userdata;
588
 
589
        test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
590
        if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
591
                L1deactivated(st->l1.hardware);
592
        if (st->l1.l1m.state != ST_L1_F6) {
593
                FsmChangeState(fi, ST_L1_F3);
594
                st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
595
        }
596
}
597
 
598
static void
599
l1_timer_act(struct FsmInst *fi, int event, void *arg)
600
{
601
        struct PStack *st = fi->userdata;
602
 
603
        test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
604
        test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
605
        L1activated(st->l1.hardware);
606
}
607
 
608
static void
609
l1_timer_deact(struct FsmInst *fi, int event, void *arg)
610
{
611
        struct PStack *st = fi->userdata;
612
 
613
        test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
614
        test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
615
        L1deactivated(st->l1.hardware);
616
        st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
617
}
618
 
619
static void
620
l1_activate(struct FsmInst *fi, int event, void *arg)
621
{
622
        struct PStack *st = fi->userdata;
623
 
624
        st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
625
}
626
 
627
static void
628
l1_activate_no(struct FsmInst *fi, int event, void *arg)
629
{
630
        struct PStack *st = fi->userdata;
631
 
632
        if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
633
                test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
634
                L1deactivated(st->l1.hardware);
635
        }
636
}
637
 
638
static struct FsmNode L1DFnList[] HISAX_INITDATA =
639
{
640
        {ST_L1_F3, EV_PH_ACTIVATE, l1_activate},
641
        {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
642
        {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
643
        {ST_L1_F3, EV_RESET_IND, l1_reset},
644
        {ST_L1_F4, EV_RESET_IND, l1_reset},
645
        {ST_L1_F5, EV_RESET_IND, l1_reset},
646
        {ST_L1_F6, EV_RESET_IND, l1_reset},
647
        {ST_L1_F7, EV_RESET_IND, l1_reset},
648
        {ST_L1_F8, EV_RESET_IND, l1_reset},
649
        {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
650
        {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
651
        {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
652
        {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
653
        {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
654
        {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
655
        {ST_L1_F6, EV_DEACT_IND, l1_deact_req},
656
        {ST_L1_F7, EV_DEACT_IND, l1_deact_req},
657
        {ST_L1_F8, EV_DEACT_IND, l1_deact_req},
658
        {ST_L1_F3, EV_POWER_UP, l1_power_up},
659
        {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
660
        {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
661
        {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
662
        {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
663
        {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
664
        {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
665
        {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
666
        {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
667
        {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
668
        {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
669
        {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
670
        {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
671
        {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
672
        {ST_L1_F3, EV_TIMER3, l1_timer3},
673
        {ST_L1_F4, EV_TIMER3, l1_timer3},
674
        {ST_L1_F5, EV_TIMER3, l1_timer3},
675
        {ST_L1_F6, EV_TIMER3, l1_timer3},
676
        {ST_L1_F8, EV_TIMER3, l1_timer3},
677
        {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
678
        {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
679
        {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
680
        {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
681
        {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
682
        {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
683
        {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
684
};
685
 
686
#define L1D_FN_COUNT (sizeof(L1DFnList)/sizeof(struct FsmNode))
687
 
688
static void
689
l1b_activate(struct FsmInst *fi, int event, void *arg)
690
{
691
        struct PStack *st = fi->userdata;
692
 
693
        FsmChangeState(fi, ST_L1_WAIT_ACT);
694
        FsmAddTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
695
}
696
 
697
static void
698
l1b_deactivate(struct FsmInst *fi, int event, void *arg)
699
{
700
        struct PStack *st = fi->userdata;
701
 
702
        FsmChangeState(fi, ST_L1_WAIT_DEACT);
703
        FsmAddTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
704
}
705
 
706
static void
707
l1b_timer_act(struct FsmInst *fi, int event, void *arg)
708
{
709
        struct PStack *st = fi->userdata;
710
 
711
        FsmChangeState(fi, ST_L1_ACTIV);
712
        st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
713
}
714
 
715
static void
716
l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
717
{
718
        struct PStack *st = fi->userdata;
719
 
720
        FsmChangeState(fi, ST_L1_NULL);
721
        st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
722
}
723
 
724
static struct FsmNode L1BFnList[] HISAX_INITDATA =
725
{
726
        {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
727
        {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
728
        {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
729
        {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
730
};
731
 
732
#define L1B_FN_COUNT (sizeof(L1BFnList)/sizeof(struct FsmNode))
733
 
734
HISAX_INITFUNC(void Isdnl1New(void))
735
{
736
        l1fsm_d.state_count = L1D_STATE_COUNT;
737
        l1fsm_d.event_count = L1_EVENT_COUNT;
738
        l1fsm_d.strEvent = strL1Event;
739
        l1fsm_d.strState = strL1DState;
740
        FsmNew(&l1fsm_d, L1DFnList, L1D_FN_COUNT);
741
        l1fsm_b.state_count = L1B_STATE_COUNT;
742
        l1fsm_b.event_count = L1_EVENT_COUNT;
743
        l1fsm_b.strEvent = strL1Event;
744
        l1fsm_b.strState = strL1BState;
745
        FsmNew(&l1fsm_b, L1BFnList, L1B_FN_COUNT);
746
}
747
 
748
void Isdnl1Free(void)
749
{
750
        FsmFree(&l1fsm_d);
751
        FsmFree(&l1fsm_b);
752
}
753
 
754
static void
755
dch_l2l1(struct PStack *st, int pr, void *arg)
756
{
757
        struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
758
 
759
        switch (pr) {
760
                case (PH_DATA | REQUEST):
761
                case (PH_PULL | REQUEST):
762
                case (PH_PULL |INDICATION):
763
                        st->l1.l1hw(st, pr, arg);
764
                        break;
765
                case (PH_ACTIVATE | REQUEST):
766
                        if (cs->debug)
767
                                debugl1(cs, "PH_ACTIVATE_REQ %s",
768
                                        strL1DState[st->l1.l1m.state]);
769
                        if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
770
                                st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
771
                        else {
772
                                test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
773
                                FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
774
                        }
775
                        break;
776
                case (PH_TESTLOOP | REQUEST):
777
                        if (1 & (long) arg)
778
                                debugl1(cs, "PH_TEST_LOOP B1");
779
                        if (2 & (long) arg)
780
                                debugl1(cs, "PH_TEST_LOOP B2");
781
                        if (!(3 & (long) arg))
782
                                debugl1(cs, "PH_TEST_LOOP DISABLED");
783
                        st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
784
                        break;
785
                default:
786
                        if (cs->debug)
787
                                debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
788
                        break;
789
        }
790
}
791
 
792
void
793
l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
794
        struct PStack *st;
795
 
796
        st = cs->stlist;
797
 
798
        while (st) {
799
                switch(pr) {
800
                        case (HW_RESET | INDICATION):
801
                                FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
802
                                break;
803
                        case (HW_DEACTIVATE | CONFIRM):
804
                                FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
805
                                break;
806
                        case (HW_DEACTIVATE | INDICATION):
807
                                FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
808
                                break;
809
                        case (HW_POWERUP | CONFIRM):
810
                                FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
811
                                break;
812
                        case (HW_RSYNC | INDICATION):
813
                                FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
814
                                break;
815
                        case (HW_INFO2 | INDICATION):
816
                                FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
817
                                break;
818
                        case (HW_INFO4_P8 | INDICATION):
819
                        case (HW_INFO4_P10 | INDICATION):
820
                                FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
821
                                break;
822
                        default:
823
                                if (cs->debug)
824
                                        debugl1(cs, "l1msg %04X unhandled", pr);
825
                                break;
826
                }
827
                st = st->next;
828
        }
829
}
830
 
831
void
832
l1_msg_b(struct PStack *st, int pr, void *arg) {
833
        switch(pr) {
834
                case (PH_ACTIVATE | REQUEST):
835
                        FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
836
                        break;
837
                case (PH_DEACTIVATE | REQUEST):
838
                        FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
839
                        break;
840
        }
841
}
842
 
843
void
844
setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
845
{
846
        st->l1.hardware = cs;
847
        st->protocol = cs->protocol;
848
        st->l1.l1m.fsm = &l1fsm_d;
849
        st->l1.l1m.state = ST_L1_F3;
850
        st->l1.l1m.debug = cs->debug;
851
        st->l1.l1m.userdata = st;
852
        st->l1.l1m.userint = 0;
853
        st->l1.l1m.printdebug = l1m_debug;
854
        FsmInitTimer(&st->l1.l1m, &st->l1.timer);
855
        setstack_tei(st);
856
        setstack_manager(st);
857
        st->l1.stlistp = &(cs->stlist);
858
        st->l2.l2l1  = dch_l2l1;
859
        st->l1.Flags = 0;
860
        cs->setstack_d(st, cs);
861
}
862
 
863
void
864
setstack_l1_B(struct PStack *st)
865
{
866
        struct IsdnCardState *cs = st->l1.hardware;
867
 
868
        st->l1.l1m.fsm = &l1fsm_b;
869
        st->l1.l1m.state = ST_L1_NULL;
870
        st->l1.l1m.debug = cs->debug;
871
        st->l1.l1m.userdata = st;
872
        st->l1.l1m.userint = 0;
873
        st->l1.l1m.printdebug = l1m_debug;
874
        st->l1.Flags = 0;
875
        FsmInitTimer(&st->l1.l1m, &st->l1.timer);
876
}

powered by: WebSVN 2.1.0

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