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

Subversion Repositories or1k

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

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

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

powered by: WebSVN 2.1.0

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