* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / isdn / hisax / isdnl1.c
blobc819c4811b5822255c4c6e74cc6e94be73bddcb8
1 /* $Id: isdnl1.c,v 2.36 1999/08/25 16:50:57 keil Exp $
3 * isdnl1.c common low level stuff for Siemens Chipsetbased isdn cards
4 * based on the teles driver from Jan den Ouden
6 * Author Karsten Keil (keil@isdn4linux.de)
8 * This file is (c) under GNU PUBLIC LICENSE
9 * For changes and modifications please read
10 * ../../../Documentation/isdn/HiSax.cert
12 * Thanks to Jan den Ouden
13 * Fritz Elfert
14 * Beat Doebeli
17 * $Log: isdnl1.c,v $
18 * Revision 2.36 1999/08/25 16:50:57 keil
19 * Fix bugs which cause 2.3.14 hangs (waitqueue init)
21 * Revision 2.35 1999/08/22 20:27:07 calle
22 * backported changes from kernel 2.3.14:
23 * - several #include "config.h" gone, others come.
24 * - "struct device" changed to "struct net_device" in 2.3.14, added a
25 * define in isdn_compat.h for older kernel versions.
27 * Revision 2.34 1999/07/09 13:50:15 keil
28 * remove unused variable
30 * Revision 2.33 1999/07/09 13:34:33 keil
31 * remove debug code
33 * Revision 2.32 1999/07/01 08:11:47 keil
34 * Common HiSax version for 2.0, 2.1, 2.2 and 2.3 kernel
36 * Revision 2.31 1998/11/15 23:54:56 keil
37 * changes from 2.0
39 * Revision 2.30 1998/09/30 22:27:00 keil
40 * Add init of l1.Flags
42 * Revision 2.29 1998/09/27 23:54:43 keil
43 * cosmetics
45 * Revision 2.28 1998/09/27 12:52:23 keil
46 * Fix against segfault, if the driver cannot allocate an IRQ channel
48 * Revision 2.27 1998/08/13 23:36:39 keil
49 * HiSax 3.1 - don't work stable with current LinkLevel
51 * Revision 2.26 1998/07/15 15:01:31 calle
52 * Support for AVM passive PCMCIA cards:
53 * A1 PCMCIA, FRITZ!Card PCMCIA and FRITZ!Card PCMCIA 2.0
55 * Revision 2.25 1998/05/25 14:10:09 keil
56 * HiSax 3.0
57 * X.75 and leased are working again.
59 * Revision 2.24 1998/05/25 12:58:04 keil
60 * HiSax golden code from certification, Don't use !!!
61 * No leased lines, no X75, but many changes.
63 * Revision 2.22 1998/04/15 16:40:13 keil
64 * Add S0Box and Teles PCI support
65 * Fix cardnr overwrite bug
67 * Revision 2.21 1998/04/10 10:35:28 paul
68 * fixed (silly?) warnings from egcs on Alpha.
70 * Revision 2.20 1998/03/09 23:19:27 keil
71 * Changes for PCMCIA
73 * Revision 2.18 1998/02/12 23:07:42 keil
74 * change for 2.1.86 (removing FREE_READ/FREE_WRITE from [dev]_kfree_skb()
76 * Revision 2.17 1998/02/11 17:28:07 keil
77 * Niccy PnP/PCI support
79 * Revision 2.16 1998/02/09 18:46:08 keil
80 * Support for Sedlbauer PCMCIA (Marcus Niemann)
82 * Revision 2.15 1998/02/09 10:54:51 keil
83 * fixes for leased mode
85 * Revision 2.14 1998/02/03 23:31:31 keil
86 * add AMD7930 support
88 * Revision 2.13 1998/02/02 13:33:02 keil
89 * New card support
91 * Revision 2.12 1998/01/31 21:41:48 keil
92 * changes for newer 2.1 kernels
94 * Revision 2.11 1997/11/12 15:01:23 keil
95 * COMPAQ_ISA changes
97 * Revision 2.10 1997/11/08 21:35:48 keil
98 * new l1 init
100 * Revision 2.9 1997/11/06 17:09:18 keil
101 * New 2.1 init code
103 * Revision 2.8 1997/10/29 19:00:05 keil
104 * new layer1,changes for 2.1
106 * Revision 2.7 1997/10/10 20:56:50 fritz
107 * New HL interface.
109 * Revision 2.6 1997/09/12 10:05:16 keil
110 * ISDN_CTRL_DEBUG define
112 * Revision 2.5 1997/09/11 17:24:45 keil
113 * Add new cards
115 * Revision 2.4 1997/08/15 17:47:09 keil
116 * avoid oops because a uninitialised timer
118 * Revision 2.3 1997/08/01 11:16:40 keil
119 * cosmetics
121 * Revision 2.2 1997/07/30 17:11:08 keil
122 * L1deactivated exported
124 * Revision 2.1 1997/07/27 21:35:38 keil
125 * new layer1 interface
127 * Revision 2.0 1997/06/26 11:02:53 keil
128 * New Layer and card interface
130 * Revision 1.15 1997/05/27 15:17:55 fritz
131 * Added changes for recent 2.1.x kernels:
132 * changed return type of isdn_close
133 * queue_task_* -> queue_task
134 * clear/set_bit -> test_and_... where apropriate.
135 * changed type of hard_header_cache parameter.
137 * old changes removed KKe
141 const char *l1_revision = "$Revision: 2.36 $";
143 #define __NO_VERSION__
144 #include "hisax.h"
145 #include "isdnl1.h"
147 #define TIMER3_VALUE 7000
149 static
150 struct Fsm l1fsm_b =
151 {NULL, 0, 0, NULL, NULL};
153 static
154 struct Fsm l1fsm_d =
155 {NULL, 0, 0, NULL, NULL};
157 enum {
158 ST_L1_F2,
159 ST_L1_F3,
160 ST_L1_F4,
161 ST_L1_F5,
162 ST_L1_F6,
163 ST_L1_F7,
164 ST_L1_F8,
167 #define L1D_STATE_COUNT (ST_L1_F8+1)
169 static char *strL1DState[] =
171 "ST_L1_F2",
172 "ST_L1_F3",
173 "ST_L1_F4",
174 "ST_L1_F5",
175 "ST_L1_F6",
176 "ST_L1_F7",
177 "ST_L1_F8",
180 enum {
181 ST_L1_NULL,
182 ST_L1_WAIT_ACT,
183 ST_L1_WAIT_DEACT,
184 ST_L1_ACTIV,
187 #define L1B_STATE_COUNT (ST_L1_ACTIV+1)
189 static char *strL1BState[] =
191 "ST_L1_NULL",
192 "ST_L1_WAIT_ACT",
193 "ST_L1_WAIT_DEACT",
194 "ST_L1_ACTIV",
197 enum {
198 EV_PH_ACTIVATE,
199 EV_PH_DEACTIVATE,
200 EV_RESET_IND,
201 EV_DEACT_CNF,
202 EV_DEACT_IND,
203 EV_POWER_UP,
204 EV_RSYNC_IND,
205 EV_INFO2_IND,
206 EV_INFO4_IND,
207 EV_TIMER_DEACT,
208 EV_TIMER_ACT,
209 EV_TIMER3,
212 #define L1_EVENT_COUNT (EV_TIMER3 + 1)
214 static char *strL1Event[] =
216 "EV_PH_ACTIVATE",
217 "EV_PH_DEACTIVATE",
218 "EV_RESET_IND",
219 "EV_DEACT_CNF",
220 "EV_DEACT_IND",
221 "EV_POWER_UP",
222 "EV_RSYNC_IND",
223 "EV_INFO2_IND",
224 "EV_INFO4_IND",
225 "EV_TIMER_DEACT",
226 "EV_TIMER_ACT",
227 "EV_TIMER3",
230 void
231 debugl1(struct IsdnCardState *cs, char *fmt, ...)
233 va_list args;
234 char tmp[8];
236 va_start(args, fmt);
237 sprintf(tmp, "Card%d ", cs->cardnr + 1);
238 VHiSax_putstatus(cs, tmp, fmt, args);
239 va_end(args);
242 static void
243 l1m_debug(struct FsmInst *fi, char *fmt, ...)
245 va_list args;
246 struct PStack *st = fi->userdata;
247 struct IsdnCardState *cs = st->l1.hardware;
248 char tmp[8];
250 va_start(args, fmt);
251 sprintf(tmp, "Card%d ", cs->cardnr + 1);
252 VHiSax_putstatus(cs, tmp, fmt, args);
253 va_end(args);
256 void
257 L1activated(struct IsdnCardState *cs)
259 struct PStack *st;
261 st = cs->stlist;
262 while (st) {
263 if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
264 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
265 else
266 st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
267 st = st->next;
271 void
272 L1deactivated(struct IsdnCardState *cs)
274 struct PStack *st;
276 st = cs->stlist;
277 while (st) {
278 if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
279 st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
280 st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
281 st = st->next;
283 test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
286 void
287 DChannel_proc_xmt(struct IsdnCardState *cs)
289 struct PStack *stptr;
291 if (cs->tx_skb)
292 return;
294 stptr = cs->stlist;
295 while (stptr != NULL)
296 if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
297 stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
298 break;
299 } else
300 stptr = stptr->next;
303 void
304 DChannel_proc_rcv(struct IsdnCardState *cs)
306 struct sk_buff *skb, *nskb;
307 struct PStack *stptr = cs->stlist;
308 int found, tei, sapi;
310 if (stptr)
311 if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
312 FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
313 while ((skb = skb_dequeue(&cs->rq))) {
314 #ifdef L2FRAME_DEBUG /* psa */
315 if (cs->debug & L1_DEB_LAPD)
316 Logl2Frame(cs, skb, "PH_DATA", 1);
317 #endif
318 stptr = cs->stlist;
319 if (skb->len<3) {
320 debugl1(cs, "D-channel frame too short(%d)",skb->len);
321 idev_kfree_skb(skb, FREE_READ);
322 return;
324 if ((skb->data[0] & 1) || !(skb->data[1] &1)) {
325 debugl1(cs, "D-channel frame wrong EA0/EA1");
326 idev_kfree_skb(skb, FREE_READ);
327 return;
329 sapi = skb->data[0] >> 2;
330 tei = skb->data[1] >> 1;
331 if (cs->debug & DEB_DLOG_HEX)
332 LogFrame(cs, skb->data, skb->len);
333 if (cs->debug & DEB_DLOG_VERBOSE)
334 dlogframe(cs, skb, 1);
335 if (tei == GROUP_TEI) {
336 if (sapi == CTRL_SAPI) { /* sapi 0 */
337 while (stptr != NULL) {
338 if ((nskb = skb_clone(skb, GFP_ATOMIC)))
339 stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
340 else
341 printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
342 stptr = stptr->next;
344 } else if (sapi == TEI_SAPI) {
345 while (stptr != NULL) {
346 if ((nskb = skb_clone(skb, GFP_ATOMIC)))
347 stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
348 else
349 printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
350 stptr = stptr->next;
353 idev_kfree_skb(skb, FREE_READ);
354 } else if (sapi == CTRL_SAPI) { /* sapi 0 */
355 found = 0;
356 while (stptr != NULL)
357 if (tei == stptr->l2.tei) {
358 stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
359 found = !0;
360 break;
361 } else
362 stptr = stptr->next;
363 if (!found)
364 idev_kfree_skb(skb, FREE_READ);
369 static void
370 BChannel_proc_xmt(struct BCState *bcs)
372 struct PStack *st = bcs->st;
374 if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
375 debugl1(bcs->cs, "BC_BUSY Error");
376 return;
379 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
380 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
381 if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
382 if (!test_bit(BC_FLG_BUSY, &bcs->Flag) && (!skb_queue_len(&bcs->squeue))) {
383 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
388 static void
389 BChannel_proc_rcv(struct BCState *bcs)
391 struct sk_buff *skb;
393 if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
394 FsmDelTimer(&bcs->st->l1.timer, 4);
395 FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
397 while ((skb = skb_dequeue(&bcs->rqueue))) {
398 bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
402 void
403 BChannel_bh(struct BCState *bcs)
405 if (!bcs)
406 return;
407 if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
408 BChannel_proc_rcv(bcs);
409 if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
410 BChannel_proc_xmt(bcs);
413 void
414 HiSax_addlist(struct IsdnCardState *cs,
415 struct PStack *st)
417 st->next = cs->stlist;
418 cs->stlist = st;
421 void
422 HiSax_rmlist(struct IsdnCardState *cs,
423 struct PStack *st)
425 struct PStack *p;
427 FsmDelTimer(&st->l1.timer, 0);
428 if (cs->stlist == st)
429 cs->stlist = st->next;
430 else {
431 p = cs->stlist;
432 while (p)
433 if (p->next == st) {
434 p->next = st->next;
435 return;
436 } else
437 p = p->next;
441 void
442 init_bcstate(struct IsdnCardState *cs,
443 int bc)
445 struct BCState *bcs = cs->bcs + bc;
447 bcs->cs = cs;
448 bcs->channel = bc;
449 bcs->tqueue.next = 0;
450 bcs->tqueue.sync = 0;
451 bcs->tqueue.routine = (void *) (void *) BChannel_bh;
452 bcs->tqueue.data = bcs;
453 bcs->BC_SetStack = NULL;
454 bcs->BC_Close = NULL;
455 bcs->Flag = 0;
458 #ifdef L2FRAME_DEBUG /* psa */
460 char *
461 l2cmd(u_char cmd)
463 switch (cmd & ~0x10) {
464 case 1:
465 return "RR";
466 case 5:
467 return "RNR";
468 case 9:
469 return "REJ";
470 case 0x6f:
471 return "SABME";
472 case 0x0f:
473 return "DM";
474 case 3:
475 return "UI";
476 case 0x43:
477 return "DISC";
478 case 0x63:
479 return "UA";
480 case 0x87:
481 return "FRMR";
482 case 0xaf:
483 return "XID";
484 default:
485 if (!(cmd & 1))
486 return "I";
487 else
488 return "invalid command";
492 static char tmpdeb[32];
494 char *
495 l2frames(u_char * ptr)
497 switch (ptr[2] & ~0x10) {
498 case 1:
499 case 5:
500 case 9:
501 sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
502 break;
503 case 0x6f:
504 case 0x0f:
505 case 3:
506 case 0x43:
507 case 0x63:
508 case 0x87:
509 case 0xaf:
510 sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
511 break;
512 default:
513 if (!(ptr[2] & 1)) {
514 sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
515 break;
516 } else
517 return "invalid command";
521 return tmpdeb;
524 void
525 Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
527 u_char *ptr;
529 ptr = skb->data;
531 if (ptr[0] & 1 || !(ptr[1] & 1))
532 debugl1(cs, "Address not LAPD");
533 else
534 debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
535 (dir ? "<-" : "->"), buf, l2frames(ptr),
536 ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
538 #endif
540 static void
541 l1_reset(struct FsmInst *fi, int event, void *arg)
543 FsmChangeState(fi, ST_L1_F3);
546 static void
547 l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
549 struct PStack *st = fi->userdata;
551 FsmChangeState(fi, ST_L1_F3);
552 if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
553 st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
556 static void
557 l1_deact_req(struct FsmInst *fi, int event, void *arg)
559 struct PStack *st = fi->userdata;
561 FsmChangeState(fi, ST_L1_F3);
562 // if (!test_bit(FLG_L1_T3RUN, &st->l1.Flags)) {
563 FsmDelTimer(&st->l1.timer, 1);
564 FsmAddTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
565 test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
566 // }
569 static void
570 l1_power_up(struct FsmInst *fi, int event, void *arg)
572 struct PStack *st = fi->userdata;
574 if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
575 FsmChangeState(fi, ST_L1_F4);
576 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
577 FsmDelTimer(&st->l1.timer, 1);
578 FsmAddTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
579 test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
580 } else
581 FsmChangeState(fi, ST_L1_F3);
584 static void
585 l1_go_F5(struct FsmInst *fi, int event, void *arg)
587 FsmChangeState(fi, ST_L1_F5);
590 static void
591 l1_go_F8(struct FsmInst *fi, int event, void *arg)
593 FsmChangeState(fi, ST_L1_F8);
596 static void
597 l1_info2_ind(struct FsmInst *fi, int event, void *arg)
599 struct PStack *st = fi->userdata;
601 FsmChangeState(fi, ST_L1_F6);
602 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
605 static void
606 l1_info4_ind(struct FsmInst *fi, int event, void *arg)
608 struct PStack *st = fi->userdata;
610 FsmChangeState(fi, ST_L1_F7);
611 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
612 if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
613 FsmDelTimer(&st->l1.timer, 4);
614 if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
615 if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
616 FsmDelTimer(&st->l1.timer, 3);
617 FsmAddTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
618 test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
622 static void
623 l1_timer3(struct FsmInst *fi, int event, void *arg)
625 struct PStack *st = fi->userdata;
627 test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
628 if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
629 L1deactivated(st->l1.hardware);
630 if (st->l1.l1m.state != ST_L1_F6) {
631 FsmChangeState(fi, ST_L1_F3);
632 st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
636 static void
637 l1_timer_act(struct FsmInst *fi, int event, void *arg)
639 struct PStack *st = fi->userdata;
641 test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
642 test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
643 L1activated(st->l1.hardware);
646 static void
647 l1_timer_deact(struct FsmInst *fi, int event, void *arg)
649 struct PStack *st = fi->userdata;
651 test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
652 test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
653 L1deactivated(st->l1.hardware);
654 st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
657 static void
658 l1_activate(struct FsmInst *fi, int event, void *arg)
660 struct PStack *st = fi->userdata;
662 st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
665 static void
666 l1_activate_no(struct FsmInst *fi, int event, void *arg)
668 struct PStack *st = fi->userdata;
670 if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
671 test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
672 L1deactivated(st->l1.hardware);
676 static struct FsmNode L1DFnList[] HISAX_INITDATA =
678 {ST_L1_F3, EV_PH_ACTIVATE, l1_activate},
679 {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
680 {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
681 {ST_L1_F3, EV_RESET_IND, l1_reset},
682 {ST_L1_F4, EV_RESET_IND, l1_reset},
683 {ST_L1_F5, EV_RESET_IND, l1_reset},
684 {ST_L1_F6, EV_RESET_IND, l1_reset},
685 {ST_L1_F7, EV_RESET_IND, l1_reset},
686 {ST_L1_F8, EV_RESET_IND, l1_reset},
687 {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
688 {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
689 {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
690 {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
691 {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
692 {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
693 {ST_L1_F6, EV_DEACT_IND, l1_deact_req},
694 {ST_L1_F7, EV_DEACT_IND, l1_deact_req},
695 {ST_L1_F8, EV_DEACT_IND, l1_deact_req},
696 {ST_L1_F3, EV_POWER_UP, l1_power_up},
697 {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
698 {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
699 {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
700 {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
701 {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
702 {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
703 {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
704 {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
705 {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
706 {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
707 {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
708 {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
709 {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
710 {ST_L1_F3, EV_TIMER3, l1_timer3},
711 {ST_L1_F4, EV_TIMER3, l1_timer3},
712 {ST_L1_F5, EV_TIMER3, l1_timer3},
713 {ST_L1_F6, EV_TIMER3, l1_timer3},
714 {ST_L1_F8, EV_TIMER3, l1_timer3},
715 {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
716 {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
717 {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
718 {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
719 {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
720 {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
721 {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
724 #define L1D_FN_COUNT (sizeof(L1DFnList)/sizeof(struct FsmNode))
726 static void
727 l1b_activate(struct FsmInst *fi, int event, void *arg)
729 struct PStack *st = fi->userdata;
731 FsmChangeState(fi, ST_L1_WAIT_ACT);
732 FsmAddTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
735 static void
736 l1b_deactivate(struct FsmInst *fi, int event, void *arg)
738 struct PStack *st = fi->userdata;
740 FsmChangeState(fi, ST_L1_WAIT_DEACT);
741 FsmAddTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
744 static void
745 l1b_timer_act(struct FsmInst *fi, int event, void *arg)
747 struct PStack *st = fi->userdata;
749 FsmChangeState(fi, ST_L1_ACTIV);
750 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
753 static void
754 l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
756 struct PStack *st = fi->userdata;
758 FsmChangeState(fi, ST_L1_NULL);
759 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
762 static struct FsmNode L1BFnList[] HISAX_INITDATA =
764 {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
765 {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
766 {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
767 {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
770 #define L1B_FN_COUNT (sizeof(L1BFnList)/sizeof(struct FsmNode))
772 HISAX_INITFUNC(void Isdnl1New(void))
774 l1fsm_d.state_count = L1D_STATE_COUNT;
775 l1fsm_d.event_count = L1_EVENT_COUNT;
776 l1fsm_d.strEvent = strL1Event;
777 l1fsm_d.strState = strL1DState;
778 FsmNew(&l1fsm_d, L1DFnList, L1D_FN_COUNT);
779 l1fsm_b.state_count = L1B_STATE_COUNT;
780 l1fsm_b.event_count = L1_EVENT_COUNT;
781 l1fsm_b.strEvent = strL1Event;
782 l1fsm_b.strState = strL1BState;
783 FsmNew(&l1fsm_b, L1BFnList, L1B_FN_COUNT);
786 void Isdnl1Free(void)
788 FsmFree(&l1fsm_d);
789 FsmFree(&l1fsm_b);
792 static void
793 dch_l2l1(struct PStack *st, int pr, void *arg)
795 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
797 switch (pr) {
798 case (PH_DATA | REQUEST):
799 case (PH_PULL | REQUEST):
800 case (PH_PULL |INDICATION):
801 st->l1.l1hw(st, pr, arg);
802 break;
803 case (PH_ACTIVATE | REQUEST):
804 if (cs->debug)
805 debugl1(cs, "PH_ACTIVATE_REQ %s",
806 strL1DState[st->l1.l1m.state]);
807 if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
808 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
809 else {
810 test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
811 FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
813 break;
814 case (PH_TESTLOOP | REQUEST):
815 if (1 & (long) arg)
816 debugl1(cs, "PH_TEST_LOOP B1");
817 if (2 & (long) arg)
818 debugl1(cs, "PH_TEST_LOOP B2");
819 if (!(3 & (long) arg))
820 debugl1(cs, "PH_TEST_LOOP DISABLED");
821 st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
822 break;
823 default:
824 if (cs->debug)
825 debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
826 break;
830 void
831 l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
832 struct PStack *st;
834 st = cs->stlist;
836 while (st) {
837 switch(pr) {
838 case (HW_RESET | INDICATION):
839 FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
840 break;
841 case (HW_DEACTIVATE | CONFIRM):
842 FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
843 break;
844 case (HW_DEACTIVATE | INDICATION):
845 FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
846 break;
847 case (HW_POWERUP | CONFIRM):
848 FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
849 break;
850 case (HW_RSYNC | INDICATION):
851 FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
852 break;
853 case (HW_INFO2 | INDICATION):
854 FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
855 break;
856 case (HW_INFO4_P8 | INDICATION):
857 case (HW_INFO4_P10 | INDICATION):
858 FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
859 break;
860 default:
861 if (cs->debug)
862 debugl1(cs, "l1msg %04X unhandled", pr);
863 break;
865 st = st->next;
869 void
870 l1_msg_b(struct PStack *st, int pr, void *arg) {
871 switch(pr) {
872 case (PH_ACTIVATE | REQUEST):
873 FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
874 break;
875 case (PH_DEACTIVATE | REQUEST):
876 FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
877 break;
881 void
882 setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
884 st->l1.hardware = cs;
885 st->protocol = cs->protocol;
886 st->l1.l1m.fsm = &l1fsm_d;
887 st->l1.l1m.state = ST_L1_F3;
888 st->l1.l1m.debug = cs->debug;
889 st->l1.l1m.userdata = st;
890 st->l1.l1m.userint = 0;
891 st->l1.l1m.printdebug = l1m_debug;
892 FsmInitTimer(&st->l1.l1m, &st->l1.timer);
893 setstack_tei(st);
894 setstack_manager(st);
895 st->l1.stlistp = &(cs->stlist);
896 st->l2.l2l1 = dch_l2l1;
897 st->l1.Flags = 0;
898 cs->setstack_d(st, cs);
901 void
902 setstack_l1_B(struct PStack *st)
904 struct IsdnCardState *cs = st->l1.hardware;
906 st->l1.l1m.fsm = &l1fsm_b;
907 st->l1.l1m.state = ST_L1_NULL;
908 st->l1.l1m.debug = cs->debug;
909 st->l1.l1m.userdata = st;
910 st->l1.l1m.userint = 0;
911 st->l1.l1m.printdebug = l1m_debug;
912 st->l1.Flags = 0;
913 FsmInitTimer(&st->l1.l1m, &st->l1.timer);