11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21b2b03f8SKarsten Keil /*
31b2b03f8SKarsten Keil *
41b2b03f8SKarsten Keil * Author Karsten Keil <kkeil@novell.com>
51b2b03f8SKarsten Keil *
61b2b03f8SKarsten Keil * Copyright 2008 by Karsten Keil <kkeil@novell.com>
71b2b03f8SKarsten Keil */
81b2b03f8SKarsten Keil
91b2b03f8SKarsten Keil
105a0e3ad6STejun Heo #include <linux/slab.h>
111b2b03f8SKarsten Keil #include <linux/module.h>
121b2b03f8SKarsten Keil #include <linux/mISDNhw.h>
135b834354SHannes Eder #include "core.h"
141b2b03f8SKarsten Keil #include "layer1.h"
151b2b03f8SKarsten Keil #include "fsm.h"
161b2b03f8SKarsten Keil
17dfa96ec1SHannes Eder static u_int *debug;
181b2b03f8SKarsten Keil
191b2b03f8SKarsten Keil struct layer1 {
201b2b03f8SKarsten Keil u_long Flags;
211b2b03f8SKarsten Keil struct FsmInst l1m;
221ea52fbdSKarsten Keil struct FsmTimer timer3;
231ea52fbdSKarsten Keil struct FsmTimer timerX;
241b2b03f8SKarsten Keil int delay;
25c626c127SKarsten Keil int t3_value;
261b2b03f8SKarsten Keil struct dchannel *dch;
271b2b03f8SKarsten Keil dchannel_l1callback *dcb;
281b2b03f8SKarsten Keil };
291b2b03f8SKarsten Keil
30c626c127SKarsten Keil #define TIMER3_DEFAULT_VALUE 7000
311b2b03f8SKarsten Keil
321b2b03f8SKarsten Keil static
331b2b03f8SKarsten Keil struct Fsm l1fsm_s = {NULL, 0, 0, NULL, NULL};
341b2b03f8SKarsten Keil
351b2b03f8SKarsten Keil enum {
361b2b03f8SKarsten Keil ST_L1_F2,
371b2b03f8SKarsten Keil ST_L1_F3,
381b2b03f8SKarsten Keil ST_L1_F4,
391b2b03f8SKarsten Keil ST_L1_F5,
401b2b03f8SKarsten Keil ST_L1_F6,
411b2b03f8SKarsten Keil ST_L1_F7,
421b2b03f8SKarsten Keil ST_L1_F8,
431b2b03f8SKarsten Keil };
441b2b03f8SKarsten Keil
451b2b03f8SKarsten Keil #define L1S_STATE_COUNT (ST_L1_F8 + 1)
461b2b03f8SKarsten Keil
471b2b03f8SKarsten Keil static char *strL1SState[] =
481b2b03f8SKarsten Keil {
491b2b03f8SKarsten Keil "ST_L1_F2",
501b2b03f8SKarsten Keil "ST_L1_F3",
511b2b03f8SKarsten Keil "ST_L1_F4",
521b2b03f8SKarsten Keil "ST_L1_F5",
531b2b03f8SKarsten Keil "ST_L1_F6",
541b2b03f8SKarsten Keil "ST_L1_F7",
551b2b03f8SKarsten Keil "ST_L1_F8",
561b2b03f8SKarsten Keil };
571b2b03f8SKarsten Keil
581b2b03f8SKarsten Keil enum {
591b2b03f8SKarsten Keil EV_PH_ACTIVATE,
601b2b03f8SKarsten Keil EV_PH_DEACTIVATE,
611b2b03f8SKarsten Keil EV_RESET_IND,
621b2b03f8SKarsten Keil EV_DEACT_CNF,
631b2b03f8SKarsten Keil EV_DEACT_IND,
641b2b03f8SKarsten Keil EV_POWER_UP,
651b2b03f8SKarsten Keil EV_ANYSIG_IND,
661b2b03f8SKarsten Keil EV_INFO2_IND,
671b2b03f8SKarsten Keil EV_INFO4_IND,
681b2b03f8SKarsten Keil EV_TIMER_DEACT,
691b2b03f8SKarsten Keil EV_TIMER_ACT,
701b2b03f8SKarsten Keil EV_TIMER3,
711b2b03f8SKarsten Keil };
721b2b03f8SKarsten Keil
731b2b03f8SKarsten Keil #define L1_EVENT_COUNT (EV_TIMER3 + 1)
741b2b03f8SKarsten Keil
751b2b03f8SKarsten Keil static char *strL1Event[] =
761b2b03f8SKarsten Keil {
771b2b03f8SKarsten Keil "EV_PH_ACTIVATE",
781b2b03f8SKarsten Keil "EV_PH_DEACTIVATE",
791b2b03f8SKarsten Keil "EV_RESET_IND",
801b2b03f8SKarsten Keil "EV_DEACT_CNF",
811b2b03f8SKarsten Keil "EV_DEACT_IND",
821b2b03f8SKarsten Keil "EV_POWER_UP",
831b2b03f8SKarsten Keil "EV_ANYSIG_IND",
841b2b03f8SKarsten Keil "EV_INFO2_IND",
851b2b03f8SKarsten Keil "EV_INFO4_IND",
861b2b03f8SKarsten Keil "EV_TIMER_DEACT",
871b2b03f8SKarsten Keil "EV_TIMER_ACT",
881b2b03f8SKarsten Keil "EV_TIMER3",
891b2b03f8SKarsten Keil };
901b2b03f8SKarsten Keil
911b2b03f8SKarsten Keil static void
l1m_debug(struct FsmInst * fi,char * fmt,...)921b2b03f8SKarsten Keil l1m_debug(struct FsmInst *fi, char *fmt, ...)
931b2b03f8SKarsten Keil {
941b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
95020f01ebSJoe Perches struct va_format vaf;
961b2b03f8SKarsten Keil va_list va;
971b2b03f8SKarsten Keil
981b2b03f8SKarsten Keil va_start(va, fmt);
99020f01ebSJoe Perches
100020f01ebSJoe Perches vaf.fmt = fmt;
101020f01ebSJoe Perches vaf.va = &va;
102020f01ebSJoe Perches
103020f01ebSJoe Perches printk(KERN_DEBUG "%s: %pV\n", dev_name(&l1->dch->dev.dev), &vaf);
104020f01ebSJoe Perches
1051b2b03f8SKarsten Keil va_end(va);
1061b2b03f8SKarsten Keil }
1071b2b03f8SKarsten Keil
1081b2b03f8SKarsten Keil static void
l1_reset(struct FsmInst * fi,int event,void * arg)1091b2b03f8SKarsten Keil l1_reset(struct FsmInst *fi, int event, void *arg)
1101b2b03f8SKarsten Keil {
1111b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F3);
1121b2b03f8SKarsten Keil }
1131b2b03f8SKarsten Keil
1141b2b03f8SKarsten Keil static void
l1_deact_cnf(struct FsmInst * fi,int event,void * arg)1151b2b03f8SKarsten Keil l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
1161b2b03f8SKarsten Keil {
1171b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1181b2b03f8SKarsten Keil
1191b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F3);
1201b2b03f8SKarsten Keil if (test_bit(FLG_L1_ACTIVATING, &l1->Flags))
1211b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_POWERUP_REQ);
1221b2b03f8SKarsten Keil }
1231b2b03f8SKarsten Keil
1241b2b03f8SKarsten Keil static void
l1_deact_req_s(struct FsmInst * fi,int event,void * arg)1251b2b03f8SKarsten Keil l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
1261b2b03f8SKarsten Keil {
1271b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1281b2b03f8SKarsten Keil
1291b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F3);
1301ea52fbdSKarsten Keil mISDN_FsmRestartTimer(&l1->timerX, 550, EV_TIMER_DEACT, NULL, 2);
1311b2b03f8SKarsten Keil test_and_set_bit(FLG_L1_DEACTTIMER, &l1->Flags);
1321b2b03f8SKarsten Keil }
1331b2b03f8SKarsten Keil
1341b2b03f8SKarsten Keil static void
l1_power_up_s(struct FsmInst * fi,int event,void * arg)1351b2b03f8SKarsten Keil l1_power_up_s(struct FsmInst *fi, int event, void *arg)
1361b2b03f8SKarsten Keil {
1371b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1381b2b03f8SKarsten Keil
1391b2b03f8SKarsten Keil if (test_bit(FLG_L1_ACTIVATING, &l1->Flags)) {
1401b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F4);
1411b2b03f8SKarsten Keil l1->dcb(l1->dch, INFO3_P8);
1421b2b03f8SKarsten Keil } else
1431b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F3);
1441b2b03f8SKarsten Keil }
1451b2b03f8SKarsten Keil
1461b2b03f8SKarsten Keil static void
l1_go_F5(struct FsmInst * fi,int event,void * arg)1471b2b03f8SKarsten Keil l1_go_F5(struct FsmInst *fi, int event, void *arg)
1481b2b03f8SKarsten Keil {
1491b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F5);
1501b2b03f8SKarsten Keil }
1511b2b03f8SKarsten Keil
1521b2b03f8SKarsten Keil static void
l1_go_F8(struct FsmInst * fi,int event,void * arg)1531b2b03f8SKarsten Keil l1_go_F8(struct FsmInst *fi, int event, void *arg)
1541b2b03f8SKarsten Keil {
1551b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F8);
1561b2b03f8SKarsten Keil }
1571b2b03f8SKarsten Keil
1581b2b03f8SKarsten Keil static void
l1_info2_ind(struct FsmInst * fi,int event,void * arg)1591b2b03f8SKarsten Keil l1_info2_ind(struct FsmInst *fi, int event, void *arg)
1601b2b03f8SKarsten Keil {
1611b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1621b2b03f8SKarsten Keil
1631b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F6);
1641b2b03f8SKarsten Keil l1->dcb(l1->dch, INFO3_P8);
1651b2b03f8SKarsten Keil }
1661b2b03f8SKarsten Keil
1671b2b03f8SKarsten Keil static void
l1_info4_ind(struct FsmInst * fi,int event,void * arg)1681b2b03f8SKarsten Keil l1_info4_ind(struct FsmInst *fi, int event, void *arg)
1691b2b03f8SKarsten Keil {
1701b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1711b2b03f8SKarsten Keil
1721b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F7);
1731b2b03f8SKarsten Keil l1->dcb(l1->dch, INFO3_P8);
1741b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_DEACTTIMER, &l1->Flags))
1751ea52fbdSKarsten Keil mISDN_FsmDelTimer(&l1->timerX, 4);
1761b2b03f8SKarsten Keil if (!test_bit(FLG_L1_ACTIVATED, &l1->Flags)) {
1771b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_T3RUN, &l1->Flags))
1781ea52fbdSKarsten Keil mISDN_FsmDelTimer(&l1->timer3, 3);
1791ea52fbdSKarsten Keil mISDN_FsmRestartTimer(&l1->timerX, 110, EV_TIMER_ACT, NULL, 2);
1801b2b03f8SKarsten Keil test_and_set_bit(FLG_L1_ACTTIMER, &l1->Flags);
1811b2b03f8SKarsten Keil }
1821b2b03f8SKarsten Keil }
1831b2b03f8SKarsten Keil
1841b2b03f8SKarsten Keil static void
l1_timer3(struct FsmInst * fi,int event,void * arg)1851b2b03f8SKarsten Keil l1_timer3(struct FsmInst *fi, int event, void *arg)
1861b2b03f8SKarsten Keil {
1871b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
1881b2b03f8SKarsten Keil
1891b2b03f8SKarsten Keil test_and_clear_bit(FLG_L1_T3RUN, &l1->Flags);
1901b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_ACTIVATING, &l1->Flags)) {
1911b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
1921b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_D_NOBLOCKED);
1931b2b03f8SKarsten Keil l1->dcb(l1->dch, PH_DEACTIVATE_IND);
1941b2b03f8SKarsten Keil }
1951b2b03f8SKarsten Keil if (l1->l1m.state != ST_L1_F6) {
1961b2b03f8SKarsten Keil mISDN_FsmChangeState(fi, ST_L1_F3);
1971ea52fbdSKarsten Keil /* do not force anything here, we need send INFO 0 */
1981b2b03f8SKarsten Keil }
1991b2b03f8SKarsten Keil }
2001b2b03f8SKarsten Keil
2011b2b03f8SKarsten Keil static void
l1_timer_act(struct FsmInst * fi,int event,void * arg)2021b2b03f8SKarsten Keil l1_timer_act(struct FsmInst *fi, int event, void *arg)
2031b2b03f8SKarsten Keil {
2041b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
2051b2b03f8SKarsten Keil
2061b2b03f8SKarsten Keil test_and_clear_bit(FLG_L1_ACTTIMER, &l1->Flags);
2071b2b03f8SKarsten Keil test_and_set_bit(FLG_L1_ACTIVATED, &l1->Flags);
2081b2b03f8SKarsten Keil l1->dcb(l1->dch, PH_ACTIVATE_IND);
2091b2b03f8SKarsten Keil }
2101b2b03f8SKarsten Keil
2111b2b03f8SKarsten Keil static void
l1_timer_deact(struct FsmInst * fi,int event,void * arg)2121b2b03f8SKarsten Keil l1_timer_deact(struct FsmInst *fi, int event, void *arg)
2131b2b03f8SKarsten Keil {
2141b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
2151b2b03f8SKarsten Keil
2161b2b03f8SKarsten Keil test_and_clear_bit(FLG_L1_DEACTTIMER, &l1->Flags);
2171b2b03f8SKarsten Keil test_and_clear_bit(FLG_L1_ACTIVATED, &l1->Flags);
2181b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
2191b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_D_NOBLOCKED);
2201b2b03f8SKarsten Keil l1->dcb(l1->dch, PH_DEACTIVATE_IND);
2211b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_DEACT_REQ);
2221b2b03f8SKarsten Keil }
2231b2b03f8SKarsten Keil
2241b2b03f8SKarsten Keil static void
l1_activate_s(struct FsmInst * fi,int event,void * arg)2251b2b03f8SKarsten Keil l1_activate_s(struct FsmInst *fi, int event, void *arg)
2261b2b03f8SKarsten Keil {
2271b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
2281b2b03f8SKarsten Keil
2291ea52fbdSKarsten Keil mISDN_FsmRestartTimer(&l1->timer3, l1->t3_value, EV_TIMER3, NULL, 2);
2301b2b03f8SKarsten Keil test_and_set_bit(FLG_L1_T3RUN, &l1->Flags);
2311ea52fbdSKarsten Keil /* Tell HW to send INFO 1 */
2321b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_RESET_REQ);
2331b2b03f8SKarsten Keil }
2341b2b03f8SKarsten Keil
2351b2b03f8SKarsten Keil static void
l1_activate_no(struct FsmInst * fi,int event,void * arg)2361b2b03f8SKarsten Keil l1_activate_no(struct FsmInst *fi, int event, void *arg)
2371b2b03f8SKarsten Keil {
2381b2b03f8SKarsten Keil struct layer1 *l1 = fi->userdata;
2391b2b03f8SKarsten Keil
2401b2b03f8SKarsten Keil if ((!test_bit(FLG_L1_DEACTTIMER, &l1->Flags)) &&
2411b2b03f8SKarsten Keil (!test_bit(FLG_L1_T3RUN, &l1->Flags))) {
2421b2b03f8SKarsten Keil test_and_clear_bit(FLG_L1_ACTIVATING, &l1->Flags);
2431b2b03f8SKarsten Keil if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
2441b2b03f8SKarsten Keil l1->dcb(l1->dch, HW_D_NOBLOCKED);
2451b2b03f8SKarsten Keil l1->dcb(l1->dch, PH_DEACTIVATE_IND);
2461b2b03f8SKarsten Keil }
2471b2b03f8SKarsten Keil }
2481b2b03f8SKarsten Keil
2491b2b03f8SKarsten Keil static struct FsmNode L1SFnList[] =
2501b2b03f8SKarsten Keil {
2511b2b03f8SKarsten Keil {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
2521b2b03f8SKarsten Keil {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
2531b2b03f8SKarsten Keil {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
2541b2b03f8SKarsten Keil {ST_L1_F3, EV_RESET_IND, l1_reset},
2551b2b03f8SKarsten Keil {ST_L1_F4, EV_RESET_IND, l1_reset},
2561b2b03f8SKarsten Keil {ST_L1_F5, EV_RESET_IND, l1_reset},
2571b2b03f8SKarsten Keil {ST_L1_F6, EV_RESET_IND, l1_reset},
2581b2b03f8SKarsten Keil {ST_L1_F7, EV_RESET_IND, l1_reset},
2591b2b03f8SKarsten Keil {ST_L1_F8, EV_RESET_IND, l1_reset},
2601b2b03f8SKarsten Keil {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
2611b2b03f8SKarsten Keil {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
2621b2b03f8SKarsten Keil {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
2631b2b03f8SKarsten Keil {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
2641b2b03f8SKarsten Keil {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
2651b2b03f8SKarsten Keil {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
2661b2b03f8SKarsten Keil {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
2671b2b03f8SKarsten Keil {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
2681b2b03f8SKarsten Keil {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
2691b2b03f8SKarsten Keil {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
2701b2b03f8SKarsten Keil {ST_L1_F4, EV_ANYSIG_IND, l1_go_F5},
2711b2b03f8SKarsten Keil {ST_L1_F6, EV_ANYSIG_IND, l1_go_F8},
2721b2b03f8SKarsten Keil {ST_L1_F7, EV_ANYSIG_IND, l1_go_F8},
2731b2b03f8SKarsten Keil {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
2741b2b03f8SKarsten Keil {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
2751b2b03f8SKarsten Keil {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
2761b2b03f8SKarsten Keil {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
2771b2b03f8SKarsten Keil {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
2781b2b03f8SKarsten Keil {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
2791b2b03f8SKarsten Keil {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
2801b2b03f8SKarsten Keil {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
2811b2b03f8SKarsten Keil {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
2821b2b03f8SKarsten Keil {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
2831b2b03f8SKarsten Keil {ST_L1_F3, EV_TIMER3, l1_timer3},
2841b2b03f8SKarsten Keil {ST_L1_F4, EV_TIMER3, l1_timer3},
2851b2b03f8SKarsten Keil {ST_L1_F5, EV_TIMER3, l1_timer3},
2861b2b03f8SKarsten Keil {ST_L1_F6, EV_TIMER3, l1_timer3},
2871b2b03f8SKarsten Keil {ST_L1_F8, EV_TIMER3, l1_timer3},
2881b2b03f8SKarsten Keil {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
2891b2b03f8SKarsten Keil {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
2901b2b03f8SKarsten Keil {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
2911b2b03f8SKarsten Keil {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
2921b2b03f8SKarsten Keil {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
2931b2b03f8SKarsten Keil {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
2941b2b03f8SKarsten Keil {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
2951b2b03f8SKarsten Keil };
2961b2b03f8SKarsten Keil
2971b2b03f8SKarsten Keil static void
release_l1(struct layer1 * l1)2981b2b03f8SKarsten Keil release_l1(struct layer1 *l1) {
2991ea52fbdSKarsten Keil mISDN_FsmDelTimer(&l1->timerX, 0);
3001ea52fbdSKarsten Keil mISDN_FsmDelTimer(&l1->timer3, 0);
3011b2b03f8SKarsten Keil if (l1->dch)
3021b2b03f8SKarsten Keil l1->dch->l1 = NULL;
3031b2b03f8SKarsten Keil module_put(THIS_MODULE);
3041b2b03f8SKarsten Keil kfree(l1);
3051b2b03f8SKarsten Keil }
3061b2b03f8SKarsten Keil
3071b2b03f8SKarsten Keil int
l1_event(struct layer1 * l1,u_int event)3081b2b03f8SKarsten Keil l1_event(struct layer1 *l1, u_int event)
3091b2b03f8SKarsten Keil {
3101b2b03f8SKarsten Keil int err = 0;
3111b2b03f8SKarsten Keil
3121b2b03f8SKarsten Keil if (!l1)
3131b2b03f8SKarsten Keil return -EINVAL;
3141b2b03f8SKarsten Keil switch (event) {
3151b2b03f8SKarsten Keil case HW_RESET_IND:
3161b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_RESET_IND, NULL);
3171b2b03f8SKarsten Keil break;
3181b2b03f8SKarsten Keil case HW_DEACT_IND:
3191b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_DEACT_IND, NULL);
3201b2b03f8SKarsten Keil break;
3211b2b03f8SKarsten Keil case HW_POWERUP_IND:
3221b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_POWER_UP, NULL);
3231b2b03f8SKarsten Keil break;
3241b2b03f8SKarsten Keil case HW_DEACT_CNF:
3251b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_DEACT_CNF, NULL);
3261b2b03f8SKarsten Keil break;
3271b2b03f8SKarsten Keil case ANYSIGNAL:
3281b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_ANYSIG_IND, NULL);
3291b2b03f8SKarsten Keil break;
3301b2b03f8SKarsten Keil case LOSTFRAMING:
3311b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_ANYSIG_IND, NULL);
3321b2b03f8SKarsten Keil break;
3331b2b03f8SKarsten Keil case INFO2:
3341b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_INFO2_IND, NULL);
3351b2b03f8SKarsten Keil break;
3361b2b03f8SKarsten Keil case INFO4_P8:
3371b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_INFO4_IND, NULL);
3381b2b03f8SKarsten Keil break;
3391b2b03f8SKarsten Keil case INFO4_P10:
3401b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_INFO4_IND, NULL);
3411b2b03f8SKarsten Keil break;
3421b2b03f8SKarsten Keil case PH_ACTIVATE_REQ:
3431b2b03f8SKarsten Keil if (test_bit(FLG_L1_ACTIVATED, &l1->Flags))
3441b2b03f8SKarsten Keil l1->dcb(l1->dch, PH_ACTIVATE_IND);
3451b2b03f8SKarsten Keil else {
3461b2b03f8SKarsten Keil test_and_set_bit(FLG_L1_ACTIVATING, &l1->Flags);
3471b2b03f8SKarsten Keil mISDN_FsmEvent(&l1->l1m, EV_PH_ACTIVATE, NULL);
3481b2b03f8SKarsten Keil }
3491b2b03f8SKarsten Keil break;
3501b2b03f8SKarsten Keil case CLOSE_CHANNEL:
3511b2b03f8SKarsten Keil release_l1(l1);
3521b2b03f8SKarsten Keil break;
3531b2b03f8SKarsten Keil default:
354c626c127SKarsten Keil if ((event & ~HW_TIMER3_VMASK) == HW_TIMER3_VALUE) {
355c626c127SKarsten Keil int val = event & HW_TIMER3_VMASK;
356c626c127SKarsten Keil
357c626c127SKarsten Keil if (val < 5)
358c626c127SKarsten Keil val = 5;
359c626c127SKarsten Keil if (val > 30)
360c626c127SKarsten Keil val = 30;
361c626c127SKarsten Keil l1->t3_value = val;
362c626c127SKarsten Keil break;
363c626c127SKarsten Keil }
3641b2b03f8SKarsten Keil if (*debug & DEBUG_L1)
3651b2b03f8SKarsten Keil printk(KERN_DEBUG "%s %x unhandled\n",
3661b2b03f8SKarsten Keil __func__, event);
3671b2b03f8SKarsten Keil err = -EINVAL;
3681b2b03f8SKarsten Keil }
3691b2b03f8SKarsten Keil return err;
3701b2b03f8SKarsten Keil }
3711b2b03f8SKarsten Keil EXPORT_SYMBOL(l1_event);
3721b2b03f8SKarsten Keil
3731b2b03f8SKarsten Keil int
create_l1(struct dchannel * dch,dchannel_l1callback * dcb)3741b2b03f8SKarsten Keil create_l1(struct dchannel *dch, dchannel_l1callback *dcb) {
3751b2b03f8SKarsten Keil struct layer1 *nl1;
3761b2b03f8SKarsten Keil
3771b2b03f8SKarsten Keil nl1 = kzalloc(sizeof(struct layer1), GFP_ATOMIC);
3781b2b03f8SKarsten Keil if (!nl1) {
3791b2b03f8SKarsten Keil printk(KERN_ERR "kmalloc struct layer1 failed\n");
3801b2b03f8SKarsten Keil return -ENOMEM;
3811b2b03f8SKarsten Keil }
3821b2b03f8SKarsten Keil nl1->l1m.fsm = &l1fsm_s;
3831b2b03f8SKarsten Keil nl1->l1m.state = ST_L1_F3;
3841b2b03f8SKarsten Keil nl1->Flags = 0;
385c626c127SKarsten Keil nl1->t3_value = TIMER3_DEFAULT_VALUE;
3861b2b03f8SKarsten Keil nl1->l1m.debug = *debug & DEBUG_L1_FSM;
3871b2b03f8SKarsten Keil nl1->l1m.userdata = nl1;
3881b2b03f8SKarsten Keil nl1->l1m.userint = 0;
3891b2b03f8SKarsten Keil nl1->l1m.printdebug = l1m_debug;
3901b2b03f8SKarsten Keil nl1->dch = dch;
3911b2b03f8SKarsten Keil nl1->dcb = dcb;
3921ea52fbdSKarsten Keil mISDN_FsmInitTimer(&nl1->l1m, &nl1->timer3);
3931ea52fbdSKarsten Keil mISDN_FsmInitTimer(&nl1->l1m, &nl1->timerX);
3941b2b03f8SKarsten Keil __module_get(THIS_MODULE);
3951b2b03f8SKarsten Keil dch->l1 = nl1;
3961b2b03f8SKarsten Keil return 0;
3971b2b03f8SKarsten Keil }
3981b2b03f8SKarsten Keil EXPORT_SYMBOL(create_l1);
3991b2b03f8SKarsten Keil
4001b2b03f8SKarsten Keil int
Isdnl1_Init(u_int * deb)401*9964f084Swolfgang huang Isdnl1_Init(u_int *deb)
4021b2b03f8SKarsten Keil {
4031b2b03f8SKarsten Keil debug = deb;
4041b2b03f8SKarsten Keil l1fsm_s.state_count = L1S_STATE_COUNT;
4051b2b03f8SKarsten Keil l1fsm_s.event_count = L1_EVENT_COUNT;
4061b2b03f8SKarsten Keil l1fsm_s.strEvent = strL1Event;
4071b2b03f8SKarsten Keil l1fsm_s.strState = strL1SState;
40854a6a043SAnton Vasilyev return mISDN_FsmNew(&l1fsm_s, L1SFnList, ARRAY_SIZE(L1SFnList));
4091b2b03f8SKarsten Keil }
4101b2b03f8SKarsten Keil
4111b2b03f8SKarsten Keil void
Isdnl1_cleanup(void)412*9964f084Swolfgang huang Isdnl1_cleanup(void)
4131b2b03f8SKarsten Keil {
4141b2b03f8SKarsten Keil mISDN_FsmFree(&l1fsm_s);
4151b2b03f8SKarsten Keil }
416