blob: 9ce6abe05b1a242ad1508a97dffc14babc676091 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: isdnl1.c,v 2.46.2.5 2004/02/11 13:21:34 keil Exp $
2 *
3 * common low level stuff for Siemens Chipsetbased isdn cards
4 *
5 * Author Karsten Keil
6 * based on the teles driver from Jan den Ouden
7 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 *
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
11 *
12 * For changes and modifications please read
13 * Documentation/isdn/HiSax.cert
14 *
15 * Thanks to Jan den Ouden
16 * Fritz Elfert
17 * Beat Doebeli
18 *
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22#include "hisax.h"
23#include "isdnl1.h"
24
Hannes Edere86a6a12009-02-25 13:11:03 +000025const char *l1_revision = "$Revision: 2.46.2.5 $";
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define TIMER3_VALUE 7000
28
29static struct Fsm l1fsm_b;
30static struct Fsm l1fsm_s;
31
32enum {
33 ST_L1_F2,
34 ST_L1_F3,
35 ST_L1_F4,
36 ST_L1_F5,
37 ST_L1_F6,
38 ST_L1_F7,
39 ST_L1_F8,
40};
41
42#define L1S_STATE_COUNT (ST_L1_F8+1)
43
44static char *strL1SState[] =
45{
46 "ST_L1_F2",
47 "ST_L1_F3",
48 "ST_L1_F4",
49 "ST_L1_F5",
50 "ST_L1_F6",
51 "ST_L1_F7",
52 "ST_L1_F8",
53};
54
55#ifdef HISAX_UINTERFACE
56static
57struct Fsm l1fsm_u =
58{NULL, 0, 0, NULL, NULL};
59
60enum {
61 ST_L1_RESET,
62 ST_L1_DEACT,
63 ST_L1_SYNC2,
64 ST_L1_TRANS,
65};
66
67#define L1U_STATE_COUNT (ST_L1_TRANS+1)
68
69static char *strL1UState[] =
70{
71 "ST_L1_RESET",
72 "ST_L1_DEACT",
73 "ST_L1_SYNC2",
74 "ST_L1_TRANS",
75};
76#endif
77
78enum {
79 ST_L1_NULL,
80 ST_L1_WAIT_ACT,
81 ST_L1_WAIT_DEACT,
82 ST_L1_ACTIV,
83};
84
85#define L1B_STATE_COUNT (ST_L1_ACTIV+1)
86
87static char *strL1BState[] =
88{
89 "ST_L1_NULL",
90 "ST_L1_WAIT_ACT",
91 "ST_L1_WAIT_DEACT",
92 "ST_L1_ACTIV",
93};
94
95enum {
96 EV_PH_ACTIVATE,
97 EV_PH_DEACTIVATE,
98 EV_RESET_IND,
99 EV_DEACT_CNF,
100 EV_DEACT_IND,
101 EV_POWER_UP,
102 EV_RSYNC_IND,
103 EV_INFO2_IND,
104 EV_INFO4_IND,
105 EV_TIMER_DEACT,
106 EV_TIMER_ACT,
107 EV_TIMER3,
108};
109
110#define L1_EVENT_COUNT (EV_TIMER3 + 1)
111
112static char *strL1Event[] =
113{
114 "EV_PH_ACTIVATE",
115 "EV_PH_DEACTIVATE",
116 "EV_RESET_IND",
117 "EV_DEACT_CNF",
118 "EV_DEACT_IND",
119 "EV_POWER_UP",
120 "EV_RSYNC_IND",
121 "EV_INFO2_IND",
122 "EV_INFO4_IND",
123 "EV_TIMER_DEACT",
124 "EV_TIMER_ACT",
125 "EV_TIMER3",
126};
127
128void
129debugl1(struct IsdnCardState *cs, char *fmt, ...)
130{
131 va_list args;
132 char tmp[8];
133
134 va_start(args, fmt);
135 sprintf(tmp, "Card%d ", cs->cardnr + 1);
136 VHiSax_putstatus(cs, tmp, fmt, args);
137 va_end(args);
138}
139
140static void
141l1m_debug(struct FsmInst *fi, char *fmt, ...)
142{
143 va_list args;
144 struct PStack *st = fi->userdata;
145 struct IsdnCardState *cs = st->l1.hardware;
146 char tmp[8];
147
148 va_start(args, fmt);
149 sprintf(tmp, "Card%d ", cs->cardnr + 1);
150 VHiSax_putstatus(cs, tmp, fmt, args);
151 va_end(args);
152}
153
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700154static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155L1activated(struct IsdnCardState *cs)
156{
157 struct PStack *st;
158
159 st = cs->stlist;
160 while (st) {
161 if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
162 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
163 else
164 st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
165 st = st->next;
166 }
167}
168
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700169static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170L1deactivated(struct IsdnCardState *cs)
171{
172 struct PStack *st;
173
174 st = cs->stlist;
175 while (st) {
176 if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
177 st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
178 st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
179 st = st->next;
180 }
181 test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
182}
183
184void
185DChannel_proc_xmt(struct IsdnCardState *cs)
186{
187 struct PStack *stptr;
188
189 if (cs->tx_skb)
190 return;
191
192 stptr = cs->stlist;
193 while (stptr != NULL) {
194 if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
195 stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
196 break;
197 } else
198 stptr = stptr->next;
199 }
200}
201
202void
203DChannel_proc_rcv(struct IsdnCardState *cs)
204{
205 struct sk_buff *skb, *nskb;
206 struct PStack *stptr = cs->stlist;
207 int found, tei, sapi;
208
209 if (stptr)
210 if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
211 FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
212 while ((skb = skb_dequeue(&cs->rq))) {
213#ifdef L2FRAME_DEBUG /* psa */
214 if (cs->debug & L1_DEB_LAPD)
215 Logl2Frame(cs, skb, "PH_DATA", 1);
216#endif
217 stptr = cs->stlist;
218 if (skb->len<3) {
219 debugl1(cs, "D-channel frame too short(%d)",skb->len);
220 dev_kfree_skb(skb);
221 return;
222 }
223 if ((skb->data[0] & 1) || !(skb->data[1] &1)) {
224 debugl1(cs, "D-channel frame wrong EA0/EA1");
225 dev_kfree_skb(skb);
226 return;
227 }
228 sapi = skb->data[0] >> 2;
229 tei = skb->data[1] >> 1;
230 if (cs->debug & DEB_DLOG_HEX)
231 LogFrame(cs, skb->data, skb->len);
232 if (cs->debug & DEB_DLOG_VERBOSE)
233 dlogframe(cs, skb, 1);
234 if (tei == GROUP_TEI) {
235 if (sapi == CTRL_SAPI) { /* sapi 0 */
236 while (stptr != NULL) {
237 if ((nskb = skb_clone(skb, GFP_ATOMIC)))
238 stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
239 else
240 printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
241 stptr = stptr->next;
242 }
243 } else if (sapi == TEI_SAPI) {
244 while (stptr != NULL) {
245 if ((nskb = skb_clone(skb, GFP_ATOMIC)))
246 stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
247 else
248 printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
249 stptr = stptr->next;
250 }
251 }
252 dev_kfree_skb(skb);
253 } else if (sapi == CTRL_SAPI) { /* sapi 0 */
254 found = 0;
255 while (stptr != NULL)
256 if (tei == stptr->l2.tei) {
257 stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
258 found = !0;
259 break;
260 } else
261 stptr = stptr->next;
262 if (!found)
263 dev_kfree_skb(skb);
264 } else
265 dev_kfree_skb(skb);
266 }
267}
268
269static void
270BChannel_proc_xmt(struct BCState *bcs)
271{
272 struct PStack *st = bcs->st;
273
274 if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
275 debugl1(bcs->cs, "BC_BUSY Error");
276 return;
277 }
278
279 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
280 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
281 if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
David S. Millerb03efcf2005-07-08 14:57:23 -0700282 if (!test_bit(BC_FLG_BUSY, &bcs->Flag) &&
283 skb_queue_empty(&bcs->squeue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
285 }
286 }
287}
288
289static void
290BChannel_proc_rcv(struct BCState *bcs)
291{
292 struct sk_buff *skb;
293
294 if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
295 FsmDelTimer(&bcs->st->l1.timer, 4);
296 FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
297 }
298 while ((skb = skb_dequeue(&bcs->rqueue))) {
299 bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
300 }
301}
302
303static void
304BChannel_proc_ack(struct BCState *bcs)
305{
306 u_long flags;
307 int ack;
308
309 spin_lock_irqsave(&bcs->aclock, flags);
310 ack = bcs->ackcnt;
311 bcs->ackcnt = 0;
312 spin_unlock_irqrestore(&bcs->aclock, flags);
313 if (ack)
314 lli_writewakeup(bcs->st, ack);
315}
316
317void
David Howellsc4028952006-11-22 14:57:56 +0000318BChannel_bh(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
David Howellsc4028952006-11-22 14:57:56 +0000320 struct BCState *bcs = container_of(work, struct BCState, tqueue);
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (!bcs)
323 return;
324 if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
325 BChannel_proc_rcv(bcs);
326 if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
327 BChannel_proc_xmt(bcs);
328 if (test_and_clear_bit(B_ACKPENDING, &bcs->event))
329 BChannel_proc_ack(bcs);
330}
331
332void
333HiSax_addlist(struct IsdnCardState *cs,
334 struct PStack *st)
335{
336 st->next = cs->stlist;
337 cs->stlist = st;
338}
339
340void
341HiSax_rmlist(struct IsdnCardState *cs,
342 struct PStack *st)
343{
344 struct PStack *p;
345
346 FsmDelTimer(&st->l1.timer, 0);
347 if (cs->stlist == st)
348 cs->stlist = st->next;
349 else {
350 p = cs->stlist;
351 while (p)
352 if (p->next == st) {
353 p->next = st->next;
354 return;
355 } else
356 p = p->next;
357 }
358}
359
360void
361init_bcstate(struct IsdnCardState *cs, int bc)
362{
363 struct BCState *bcs = cs->bcs + bc;
364
365 bcs->cs = cs;
366 bcs->channel = bc;
David Howellsc4028952006-11-22 14:57:56 +0000367 INIT_WORK(&bcs->tqueue, BChannel_bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 spin_lock_init(&bcs->aclock);
369 bcs->BC_SetStack = NULL;
370 bcs->BC_Close = NULL;
371 bcs->Flag = 0;
372}
373
374#ifdef L2FRAME_DEBUG /* psa */
375
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700376static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377l2cmd(u_char cmd)
378{
379 switch (cmd & ~0x10) {
380 case 1:
381 return "RR";
382 case 5:
383 return "RNR";
384 case 9:
385 return "REJ";
386 case 0x6f:
387 return "SABME";
388 case 0x0f:
389 return "DM";
390 case 3:
391 return "UI";
392 case 0x43:
393 return "DISC";
394 case 0x63:
395 return "UA";
396 case 0x87:
397 return "FRMR";
398 case 0xaf:
399 return "XID";
400 default:
401 if (!(cmd & 1))
402 return "I";
403 else
404 return "invalid command";
405 }
406}
407
408static char tmpdeb[32];
409
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700410static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411l2frames(u_char * ptr)
412{
413 switch (ptr[2] & ~0x10) {
414 case 1:
415 case 5:
416 case 9:
417 sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
418 break;
419 case 0x6f:
420 case 0x0f:
421 case 3:
422 case 0x43:
423 case 0x63:
424 case 0x87:
425 case 0xaf:
426 sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
427 break;
428 default:
429 if (!(ptr[2] & 1)) {
430 sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
431 break;
432 } else
433 return "invalid command";
434 }
435
436
437 return tmpdeb;
438}
439
440void
441Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
442{
443 u_char *ptr;
444
445 ptr = skb->data;
446
447 if (ptr[0] & 1 || !(ptr[1] & 1))
448 debugl1(cs, "Address not LAPD");
449 else
450 debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
451 (dir ? "<-" : "->"), buf, l2frames(ptr),
452 ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
453}
454#endif
455
456static void
457l1_reset(struct FsmInst *fi, int event, void *arg)
458{
459 FsmChangeState(fi, ST_L1_F3);
460}
461
462static void
463l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
464{
465 struct PStack *st = fi->userdata;
466
467 FsmChangeState(fi, ST_L1_F3);
468 if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
469 st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
470}
471
472static void
473l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
474{
475 struct PStack *st = fi->userdata;
476
477 FsmChangeState(fi, ST_L1_F3);
478 FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
479 test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
480}
481
482static void
483l1_power_up_s(struct FsmInst *fi, int event, void *arg)
484{
485 struct PStack *st = fi->userdata;
486
487 if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
488 FsmChangeState(fi, ST_L1_F4);
489 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
490 FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
491 test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
492 } else
493 FsmChangeState(fi, ST_L1_F3);
494}
495
496static void
497l1_go_F5(struct FsmInst *fi, int event, void *arg)
498{
499 FsmChangeState(fi, ST_L1_F5);
500}
501
502static void
503l1_go_F8(struct FsmInst *fi, int event, void *arg)
504{
505 FsmChangeState(fi, ST_L1_F8);
506}
507
508static void
509l1_info2_ind(struct FsmInst *fi, int event, void *arg)
510{
511 struct PStack *st = fi->userdata;
512
513#ifdef HISAX_UINTERFACE
514 if (test_bit(FLG_L1_UINT, &st->l1.Flags))
515 FsmChangeState(fi, ST_L1_SYNC2);
516 else
517#endif
518 FsmChangeState(fi, ST_L1_F6);
519 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
520}
521
522static void
523l1_info4_ind(struct FsmInst *fi, int event, void *arg)
524{
525 struct PStack *st = fi->userdata;
526
527#ifdef HISAX_UINTERFACE
528 if (test_bit(FLG_L1_UINT, &st->l1.Flags))
529 FsmChangeState(fi, ST_L1_TRANS);
530 else
531#endif
532 FsmChangeState(fi, ST_L1_F7);
533 st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
534 if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
535 FsmDelTimer(&st->l1.timer, 4);
536 if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
537 if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
538 FsmDelTimer(&st->l1.timer, 3);
539 FsmRestartTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
540 test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
541 }
542}
543
544static void
545l1_timer3(struct FsmInst *fi, int event, void *arg)
546{
547 struct PStack *st = fi->userdata;
548
549 test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
550 if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
551 L1deactivated(st->l1.hardware);
552
553#ifdef HISAX_UINTERFACE
554 if (!test_bit(FLG_L1_UINT, &st->l1.Flags))
555#endif
556 if (st->l1.l1m.state != ST_L1_F6) {
557 FsmChangeState(fi, ST_L1_F3);
558 st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
559 }
560}
561
562static void
563l1_timer_act(struct FsmInst *fi, int event, void *arg)
564{
565 struct PStack *st = fi->userdata;
566
567 test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
568 test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
569 L1activated(st->l1.hardware);
570}
571
572static void
573l1_timer_deact(struct FsmInst *fi, int event, void *arg)
574{
575 struct PStack *st = fi->userdata;
576
577 test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
578 test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
579 L1deactivated(st->l1.hardware);
580 st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
581}
582
583static void
584l1_activate_s(struct FsmInst *fi, int event, void *arg)
585{
586 struct PStack *st = fi->userdata;
587
588 st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
589}
590
591static void
592l1_activate_no(struct FsmInst *fi, int event, void *arg)
593{
594 struct PStack *st = fi->userdata;
595
596 if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
597 test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
598 L1deactivated(st->l1.hardware);
599 }
600}
601
602static struct FsmNode L1SFnList[] __initdata =
603{
604 {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
605 {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
606 {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
607 {ST_L1_F3, EV_RESET_IND, l1_reset},
608 {ST_L1_F4, EV_RESET_IND, l1_reset},
609 {ST_L1_F5, EV_RESET_IND, l1_reset},
610 {ST_L1_F6, EV_RESET_IND, l1_reset},
611 {ST_L1_F7, EV_RESET_IND, l1_reset},
612 {ST_L1_F8, EV_RESET_IND, l1_reset},
613 {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
614 {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
615 {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
616 {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
617 {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
618 {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
619 {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
620 {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
621 {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
622 {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
623 {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
624 {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
625 {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
626 {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
627 {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
628 {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
629 {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
630 {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
631 {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
632 {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
633 {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
634 {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
635 {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
636 {ST_L1_F3, EV_TIMER3, l1_timer3},
637 {ST_L1_F4, EV_TIMER3, l1_timer3},
638 {ST_L1_F5, EV_TIMER3, l1_timer3},
639 {ST_L1_F6, EV_TIMER3, l1_timer3},
640 {ST_L1_F8, EV_TIMER3, l1_timer3},
641 {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
642 {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
643 {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
644 {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
645 {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
646 {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
647 {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
648};
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#ifdef HISAX_UINTERFACE
651static void
652l1_deact_req_u(struct FsmInst *fi, int event, void *arg)
653{
654 struct PStack *st = fi->userdata;
655
656 FsmChangeState(fi, ST_L1_RESET);
657 FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
658 test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
659 st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
660}
661
662static void
663l1_power_up_u(struct FsmInst *fi, int event, void *arg)
664{
665 struct PStack *st = fi->userdata;
666
667 FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
668 test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
669}
670
671static void
672l1_info0_ind(struct FsmInst *fi, int event, void *arg)
673{
674 FsmChangeState(fi, ST_L1_DEACT);
675}
676
677static void
678l1_activate_u(struct FsmInst *fi, int event, void *arg)
679{
680 struct PStack *st = fi->userdata;
681
682 st->l1.l1hw(st, HW_INFO1 | REQUEST, NULL);
683}
684
685static struct FsmNode L1UFnList[] __initdata =
686{
687 {ST_L1_RESET, EV_DEACT_IND, l1_deact_req_u},
688 {ST_L1_DEACT, EV_DEACT_IND, l1_deact_req_u},
689 {ST_L1_SYNC2, EV_DEACT_IND, l1_deact_req_u},
690 {ST_L1_TRANS, EV_DEACT_IND, l1_deact_req_u},
691 {ST_L1_DEACT, EV_PH_ACTIVATE, l1_activate_u},
692 {ST_L1_DEACT, EV_POWER_UP, l1_power_up_u},
693 {ST_L1_DEACT, EV_INFO2_IND, l1_info2_ind},
694 {ST_L1_TRANS, EV_INFO2_IND, l1_info2_ind},
695 {ST_L1_RESET, EV_DEACT_CNF, l1_info0_ind},
696 {ST_L1_DEACT, EV_INFO4_IND, l1_info4_ind},
697 {ST_L1_SYNC2, EV_INFO4_IND, l1_info4_ind},
698 {ST_L1_RESET, EV_INFO4_IND, l1_info4_ind},
699 {ST_L1_DEACT, EV_TIMER3, l1_timer3},
700 {ST_L1_SYNC2, EV_TIMER3, l1_timer3},
701 {ST_L1_TRANS, EV_TIMER_ACT, l1_timer_act},
702 {ST_L1_DEACT, EV_TIMER_DEACT, l1_timer_deact},
703 {ST_L1_SYNC2, EV_TIMER_DEACT, l1_timer_deact},
704 {ST_L1_RESET, EV_TIMER_DEACT, l1_timer_deact},
705};
706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707#endif
708
709static void
710l1b_activate(struct FsmInst *fi, int event, void *arg)
711{
712 struct PStack *st = fi->userdata;
713
714 FsmChangeState(fi, ST_L1_WAIT_ACT);
715 FsmRestartTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
716}
717
718static void
719l1b_deactivate(struct FsmInst *fi, int event, void *arg)
720{
721 struct PStack *st = fi->userdata;
722
723 FsmChangeState(fi, ST_L1_WAIT_DEACT);
724 FsmRestartTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
725}
726
727static void
728l1b_timer_act(struct FsmInst *fi, int event, void *arg)
729{
730 struct PStack *st = fi->userdata;
731
732 FsmChangeState(fi, ST_L1_ACTIV);
733 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
734}
735
736static void
737l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
738{
739 struct PStack *st = fi->userdata;
740
741 FsmChangeState(fi, ST_L1_NULL);
742 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
743}
744
745static struct FsmNode L1BFnList[] __initdata =
746{
747 {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
748 {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
749 {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
750 {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
751};
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753int __init
754Isdnl1New(void)
755{
756 int retval;
757
758 l1fsm_s.state_count = L1S_STATE_COUNT;
759 l1fsm_s.event_count = L1_EVENT_COUNT;
760 l1fsm_s.strEvent = strL1Event;
761 l1fsm_s.strState = strL1SState;
Karsten Keilba2d6cc2009-07-24 18:26:08 +0200762 retval = FsmNew(&l1fsm_s, L1SFnList, ARRAY_SIZE(L1SFnList));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (retval)
764 return retval;
765
766 l1fsm_b.state_count = L1B_STATE_COUNT;
767 l1fsm_b.event_count = L1_EVENT_COUNT;
768 l1fsm_b.strEvent = strL1Event;
769 l1fsm_b.strState = strL1BState;
Karsten Keilba2d6cc2009-07-24 18:26:08 +0200770 retval = FsmNew(&l1fsm_b, L1BFnList, ARRAY_SIZE(L1BFnList));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 if (retval) {
772 FsmFree(&l1fsm_s);
773 return retval;
774 }
775#ifdef HISAX_UINTERFACE
776 l1fsm_u.state_count = L1U_STATE_COUNT;
777 l1fsm_u.event_count = L1_EVENT_COUNT;
778 l1fsm_u.strEvent = strL1Event;
779 l1fsm_u.strState = strL1UState;
Karsten Keilba2d6cc2009-07-24 18:26:08 +0200780 retval = FsmNew(&l1fsm_u, L1UFnList, ARRAY_SIZE(L1UFnList));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (retval) {
782 FsmFree(&l1fsm_s);
783 FsmFree(&l1fsm_b);
784 return retval;
785 }
786#endif
787 return 0;
788}
789
790void Isdnl1Free(void)
791{
792#ifdef HISAX_UINTERFACE
793 FsmFree(&l1fsm_u);
794#endif
795 FsmFree(&l1fsm_s);
796 FsmFree(&l1fsm_b);
797}
798
799static void
800dch_l2l1(struct PStack *st, int pr, void *arg)
801{
802 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
803
804 switch (pr) {
805 case (PH_DATA | REQUEST):
806 case (PH_PULL | REQUEST):
807 case (PH_PULL |INDICATION):
808 st->l1.l1hw(st, pr, arg);
809 break;
810 case (PH_ACTIVATE | REQUEST):
811 if (cs->debug)
812 debugl1(cs, "PH_ACTIVATE_REQ %s",
813 st->l1.l1m.fsm->strState[st->l1.l1m.state]);
814 if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
815 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
816 else {
817 test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
818 FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
819 }
820 break;
821 case (PH_TESTLOOP | REQUEST):
822 if (1 & (long) arg)
823 debugl1(cs, "PH_TEST_LOOP B1");
824 if (2 & (long) arg)
825 debugl1(cs, "PH_TEST_LOOP B2");
826 if (!(3 & (long) arg))
827 debugl1(cs, "PH_TEST_LOOP DISABLED");
828 st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
829 break;
830 default:
831 if (cs->debug)
832 debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
833 break;
834 }
835}
836
837void
838l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
839 struct PStack *st;
840
841 st = cs->stlist;
842
843 while (st) {
844 switch(pr) {
845 case (HW_RESET | INDICATION):
846 FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
847 break;
848 case (HW_DEACTIVATE | CONFIRM):
849 FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
850 break;
851 case (HW_DEACTIVATE | INDICATION):
852 FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
853 break;
854 case (HW_POWERUP | CONFIRM):
855 FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
856 break;
857 case (HW_RSYNC | INDICATION):
858 FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
859 break;
860 case (HW_INFO2 | INDICATION):
861 FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
862 break;
863 case (HW_INFO4_P8 | INDICATION):
864 case (HW_INFO4_P10 | INDICATION):
865 FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
866 break;
867 default:
868 if (cs->debug)
869 debugl1(cs, "l1msg %04X unhandled", pr);
870 break;
871 }
872 st = st->next;
873 }
874}
875
876void
877l1_msg_b(struct PStack *st, int pr, void *arg) {
878 switch(pr) {
879 case (PH_ACTIVATE | REQUEST):
880 FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
881 break;
882 case (PH_DEACTIVATE | REQUEST):
883 FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
884 break;
885 }
886}
887
888void
889setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
890{
891 st->l1.hardware = cs;
892 st->protocol = cs->protocol;
893 st->l1.l1m.fsm = &l1fsm_s;
894 st->l1.l1m.state = ST_L1_F3;
895 st->l1.Flags = 0;
896#ifdef HISAX_UINTERFACE
897 if (test_bit(FLG_HW_L1_UINT, &cs->HW_Flags)) {
898 st->l1.l1m.fsm = &l1fsm_u;
899 st->l1.l1m.state = ST_L1_RESET;
900 st->l1.Flags = FLG_L1_UINT;
901 }
902#endif
903 st->l1.l1m.debug = cs->debug;
904 st->l1.l1m.userdata = st;
905 st->l1.l1m.userint = 0;
906 st->l1.l1m.printdebug = l1m_debug;
907 FsmInitTimer(&st->l1.l1m, &st->l1.timer);
908 setstack_tei(st);
909 setstack_manager(st);
910 st->l1.stlistp = &(cs->stlist);
911 st->l2.l2l1 = dch_l2l1;
912 if (cs->setstack_d)
913 cs->setstack_d(st, cs);
914}
915
916void
917setstack_l1_B(struct PStack *st)
918{
919 struct IsdnCardState *cs = st->l1.hardware;
920
921 st->l1.l1m.fsm = &l1fsm_b;
922 st->l1.l1m.state = ST_L1_NULL;
923 st->l1.l1m.debug = cs->debug;
924 st->l1.l1m.userdata = st;
925 st->l1.l1m.userint = 0;
926 st->l1.l1m.printdebug = l1m_debug;
927 st->l1.Flags = 0;
928 FsmInitTimer(&st->l1.l1m, &st->l1.timer);
929}