3 * Author Karsten Keil <kkeil@novell.com>
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/mISDNhw.h>
31 struct FsmTimer timer
;
34 dchannel_l1callback
*dcb
;
37 #define TIMER3_VALUE 7000
40 struct Fsm l1fsm_s
= {NULL
, 0, 0, NULL
, NULL
};
52 #define L1S_STATE_COUNT (ST_L1_F8+1)
54 static char *strL1SState
[] =
80 #define L1_EVENT_COUNT (EV_TIMER3 + 1)
82 static char *strL1Event
[] =
99 l1m_debug(struct FsmInst
*fi
, char *fmt
, ...)
101 struct layer1
*l1
= fi
->userdata
;
105 printk(KERN_DEBUG
"%s: ", dev_name(&l1
->dch
->dev
.dev
));
112 l1_reset(struct FsmInst
*fi
, int event
, void *arg
)
114 mISDN_FsmChangeState(fi
, ST_L1_F3
);
118 l1_deact_cnf(struct FsmInst
*fi
, int event
, void *arg
)
120 struct layer1
*l1
= fi
->userdata
;
122 mISDN_FsmChangeState(fi
, ST_L1_F3
);
123 if (test_bit(FLG_L1_ACTIVATING
, &l1
->Flags
))
124 l1
->dcb(l1
->dch
, HW_POWERUP_REQ
);
128 l1_deact_req_s(struct FsmInst
*fi
, int event
, void *arg
)
130 struct layer1
*l1
= fi
->userdata
;
132 mISDN_FsmChangeState(fi
, ST_L1_F3
);
133 mISDN_FsmRestartTimer(&l1
->timer
, 550, EV_TIMER_DEACT
, NULL
, 2);
134 test_and_set_bit(FLG_L1_DEACTTIMER
, &l1
->Flags
);
138 l1_power_up_s(struct FsmInst
*fi
, int event
, void *arg
)
140 struct layer1
*l1
= fi
->userdata
;
142 if (test_bit(FLG_L1_ACTIVATING
, &l1
->Flags
)) {
143 mISDN_FsmChangeState(fi
, ST_L1_F4
);
144 l1
->dcb(l1
->dch
, INFO3_P8
);
146 mISDN_FsmChangeState(fi
, ST_L1_F3
);
150 l1_go_F5(struct FsmInst
*fi
, int event
, void *arg
)
152 mISDN_FsmChangeState(fi
, ST_L1_F5
);
156 l1_go_F8(struct FsmInst
*fi
, int event
, void *arg
)
158 mISDN_FsmChangeState(fi
, ST_L1_F8
);
162 l1_info2_ind(struct FsmInst
*fi
, int event
, void *arg
)
164 struct layer1
*l1
= fi
->userdata
;
166 mISDN_FsmChangeState(fi
, ST_L1_F6
);
167 l1
->dcb(l1
->dch
, INFO3_P8
);
171 l1_info4_ind(struct FsmInst
*fi
, int event
, void *arg
)
173 struct layer1
*l1
= fi
->userdata
;
175 mISDN_FsmChangeState(fi
, ST_L1_F7
);
176 l1
->dcb(l1
->dch
, INFO3_P8
);
177 if (test_and_clear_bit(FLG_L1_DEACTTIMER
, &l1
->Flags
))
178 mISDN_FsmDelTimer(&l1
->timer
, 4);
179 if (!test_bit(FLG_L1_ACTIVATED
, &l1
->Flags
)) {
180 if (test_and_clear_bit(FLG_L1_T3RUN
, &l1
->Flags
))
181 mISDN_FsmDelTimer(&l1
->timer
, 3);
182 mISDN_FsmRestartTimer(&l1
->timer
, 110, EV_TIMER_ACT
, NULL
, 2);
183 test_and_set_bit(FLG_L1_ACTTIMER
, &l1
->Flags
);
188 l1_timer3(struct FsmInst
*fi
, int event
, void *arg
)
190 struct layer1
*l1
= fi
->userdata
;
192 test_and_clear_bit(FLG_L1_T3RUN
, &l1
->Flags
);
193 if (test_and_clear_bit(FLG_L1_ACTIVATING
, &l1
->Flags
)) {
194 if (test_and_clear_bit(FLG_L1_DBLOCKED
, &l1
->Flags
))
195 l1
->dcb(l1
->dch
, HW_D_NOBLOCKED
);
196 l1
->dcb(l1
->dch
, PH_DEACTIVATE_IND
);
198 if (l1
->l1m
.state
!= ST_L1_F6
) {
199 mISDN_FsmChangeState(fi
, ST_L1_F3
);
200 l1
->dcb(l1
->dch
, HW_POWERUP_REQ
);
205 l1_timer_act(struct FsmInst
*fi
, int event
, void *arg
)
207 struct layer1
*l1
= fi
->userdata
;
209 test_and_clear_bit(FLG_L1_ACTTIMER
, &l1
->Flags
);
210 test_and_set_bit(FLG_L1_ACTIVATED
, &l1
->Flags
);
211 l1
->dcb(l1
->dch
, PH_ACTIVATE_IND
);
215 l1_timer_deact(struct FsmInst
*fi
, int event
, void *arg
)
217 struct layer1
*l1
= fi
->userdata
;
219 test_and_clear_bit(FLG_L1_DEACTTIMER
, &l1
->Flags
);
220 test_and_clear_bit(FLG_L1_ACTIVATED
, &l1
->Flags
);
221 if (test_and_clear_bit(FLG_L1_DBLOCKED
, &l1
->Flags
))
222 l1
->dcb(l1
->dch
, HW_D_NOBLOCKED
);
223 l1
->dcb(l1
->dch
, PH_DEACTIVATE_IND
);
224 l1
->dcb(l1
->dch
, HW_DEACT_REQ
);
228 l1_activate_s(struct FsmInst
*fi
, int event
, void *arg
)
230 struct layer1
*l1
= fi
->userdata
;
232 mISDN_FsmRestartTimer(&l1
->timer
, TIMER3_VALUE
, EV_TIMER3
, NULL
, 2);
233 test_and_set_bit(FLG_L1_T3RUN
, &l1
->Flags
);
234 l1
->dcb(l1
->dch
, HW_RESET_REQ
);
238 l1_activate_no(struct FsmInst
*fi
, int event
, void *arg
)
240 struct layer1
*l1
= fi
->userdata
;
242 if ((!test_bit(FLG_L1_DEACTTIMER
, &l1
->Flags
)) &&
243 (!test_bit(FLG_L1_T3RUN
, &l1
->Flags
))) {
244 test_and_clear_bit(FLG_L1_ACTIVATING
, &l1
->Flags
);
245 if (test_and_clear_bit(FLG_L1_DBLOCKED
, &l1
->Flags
))
246 l1
->dcb(l1
->dch
, HW_D_NOBLOCKED
);
247 l1
->dcb(l1
->dch
, PH_DEACTIVATE_IND
);
251 static struct FsmNode L1SFnList
[] =
253 {ST_L1_F3
, EV_PH_ACTIVATE
, l1_activate_s
},
254 {ST_L1_F6
, EV_PH_ACTIVATE
, l1_activate_no
},
255 {ST_L1_F8
, EV_PH_ACTIVATE
, l1_activate_no
},
256 {ST_L1_F3
, EV_RESET_IND
, l1_reset
},
257 {ST_L1_F4
, EV_RESET_IND
, l1_reset
},
258 {ST_L1_F5
, EV_RESET_IND
, l1_reset
},
259 {ST_L1_F6
, EV_RESET_IND
, l1_reset
},
260 {ST_L1_F7
, EV_RESET_IND
, l1_reset
},
261 {ST_L1_F8
, EV_RESET_IND
, l1_reset
},
262 {ST_L1_F3
, EV_DEACT_CNF
, l1_deact_cnf
},
263 {ST_L1_F4
, EV_DEACT_CNF
, l1_deact_cnf
},
264 {ST_L1_F5
, EV_DEACT_CNF
, l1_deact_cnf
},
265 {ST_L1_F6
, EV_DEACT_CNF
, l1_deact_cnf
},
266 {ST_L1_F7
, EV_DEACT_CNF
, l1_deact_cnf
},
267 {ST_L1_F8
, EV_DEACT_CNF
, l1_deact_cnf
},
268 {ST_L1_F6
, EV_DEACT_IND
, l1_deact_req_s
},
269 {ST_L1_F7
, EV_DEACT_IND
, l1_deact_req_s
},
270 {ST_L1_F8
, EV_DEACT_IND
, l1_deact_req_s
},
271 {ST_L1_F3
, EV_POWER_UP
, l1_power_up_s
},
272 {ST_L1_F4
, EV_ANYSIG_IND
, l1_go_F5
},
273 {ST_L1_F6
, EV_ANYSIG_IND
, l1_go_F8
},
274 {ST_L1_F7
, EV_ANYSIG_IND
, l1_go_F8
},
275 {ST_L1_F3
, EV_INFO2_IND
, l1_info2_ind
},
276 {ST_L1_F4
, EV_INFO2_IND
, l1_info2_ind
},
277 {ST_L1_F5
, EV_INFO2_IND
, l1_info2_ind
},
278 {ST_L1_F7
, EV_INFO2_IND
, l1_info2_ind
},
279 {ST_L1_F8
, EV_INFO2_IND
, l1_info2_ind
},
280 {ST_L1_F3
, EV_INFO4_IND
, l1_info4_ind
},
281 {ST_L1_F4
, EV_INFO4_IND
, l1_info4_ind
},
282 {ST_L1_F5
, EV_INFO4_IND
, l1_info4_ind
},
283 {ST_L1_F6
, EV_INFO4_IND
, l1_info4_ind
},
284 {ST_L1_F8
, EV_INFO4_IND
, l1_info4_ind
},
285 {ST_L1_F3
, EV_TIMER3
, l1_timer3
},
286 {ST_L1_F4
, EV_TIMER3
, l1_timer3
},
287 {ST_L1_F5
, EV_TIMER3
, l1_timer3
},
288 {ST_L1_F6
, EV_TIMER3
, l1_timer3
},
289 {ST_L1_F8
, EV_TIMER3
, l1_timer3
},
290 {ST_L1_F7
, EV_TIMER_ACT
, l1_timer_act
},
291 {ST_L1_F3
, EV_TIMER_DEACT
, l1_timer_deact
},
292 {ST_L1_F4
, EV_TIMER_DEACT
, l1_timer_deact
},
293 {ST_L1_F5
, EV_TIMER_DEACT
, l1_timer_deact
},
294 {ST_L1_F6
, EV_TIMER_DEACT
, l1_timer_deact
},
295 {ST_L1_F7
, EV_TIMER_DEACT
, l1_timer_deact
},
296 {ST_L1_F8
, EV_TIMER_DEACT
, l1_timer_deact
},
300 release_l1(struct layer1
*l1
) {
301 mISDN_FsmDelTimer(&l1
->timer
, 0);
304 module_put(THIS_MODULE
);
309 l1_event(struct layer1
*l1
, u_int event
)
317 mISDN_FsmEvent(&l1
->l1m
, EV_RESET_IND
, NULL
);
320 mISDN_FsmEvent(&l1
->l1m
, EV_DEACT_IND
, NULL
);
323 mISDN_FsmEvent(&l1
->l1m
, EV_POWER_UP
, NULL
);
326 mISDN_FsmEvent(&l1
->l1m
, EV_DEACT_CNF
, NULL
);
329 mISDN_FsmEvent(&l1
->l1m
, EV_ANYSIG_IND
, NULL
);
332 mISDN_FsmEvent(&l1
->l1m
, EV_ANYSIG_IND
, NULL
);
335 mISDN_FsmEvent(&l1
->l1m
, EV_INFO2_IND
, NULL
);
338 mISDN_FsmEvent(&l1
->l1m
, EV_INFO4_IND
, NULL
);
341 mISDN_FsmEvent(&l1
->l1m
, EV_INFO4_IND
, NULL
);
343 case PH_ACTIVATE_REQ
:
344 if (test_bit(FLG_L1_ACTIVATED
, &l1
->Flags
))
345 l1
->dcb(l1
->dch
, PH_ACTIVATE_IND
);
347 test_and_set_bit(FLG_L1_ACTIVATING
, &l1
->Flags
);
348 mISDN_FsmEvent(&l1
->l1m
, EV_PH_ACTIVATE
, NULL
);
355 if (*debug
& DEBUG_L1
)
356 printk(KERN_DEBUG
"%s %x unhandled\n",
362 EXPORT_SYMBOL(l1_event
);
365 create_l1(struct dchannel
*dch
, dchannel_l1callback
*dcb
) {
368 nl1
= kzalloc(sizeof(struct layer1
), GFP_ATOMIC
);
370 printk(KERN_ERR
"kmalloc struct layer1 failed\n");
373 nl1
->l1m
.fsm
= &l1fsm_s
;
374 nl1
->l1m
.state
= ST_L1_F3
;
376 nl1
->l1m
.debug
= *debug
& DEBUG_L1_FSM
;
377 nl1
->l1m
.userdata
= nl1
;
378 nl1
->l1m
.userint
= 0;
379 nl1
->l1m
.printdebug
= l1m_debug
;
382 mISDN_FsmInitTimer(&nl1
->l1m
, &nl1
->timer
);
383 __module_get(THIS_MODULE
);
387 EXPORT_SYMBOL(create_l1
);
393 l1fsm_s
.state_count
= L1S_STATE_COUNT
;
394 l1fsm_s
.event_count
= L1_EVENT_COUNT
;
395 l1fsm_s
.strEvent
= strL1Event
;
396 l1fsm_s
.strState
= strL1SState
;
397 mISDN_FsmNew(&l1fsm_s
, L1SFnList
, ARRAY_SIZE(L1SFnList
));
404 mISDN_FsmFree(&l1fsm_s
);