2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b_itjc_l1fsm.c - NetJet-S layer 1 I.430 state machine
28 * ------------------------------------------------------------
30 * $FreeBSD: src/sys/i4b/layer1/itjc/i4b_itjc_l1fsm.c,v 1.1.2.1 2001/08/10 14:08:39 obrien Exp $
31 * $DragonFly: src/sys/net/i4b/layer1/itjc/i4b_itjc_l1fsm.c,v 1.5 2005/06/03 16:50:07 dillon Exp $
33 * last edit-date: [Wed Jan 10 17:16:33 2001]
35 *---------------------------------------------------------------------------*/
40 #if (NITJC > 0) && (NPCI > 0)
42 #include <sys/param.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/thread2.h>
49 #include <machine/stdarg.h>
50 #include <machine/clock.h>
54 #include <net/i4b/include/machine/i4b_debug.h>
55 #include <net/i4b/include/machine/i4b_ioctl.h>
56 #include <net/i4b/include/machine/i4b_trace.h>
58 #include "../isic/i4b_isic.h"
59 #include "../isic/i4b_isac.h"
60 #include "../isic/i4b_hscx.h"
62 #include "../i4b_l1.h"
64 #include "../../include/i4b_global.h"
65 #include "../../include/i4b_mbuf.h"
67 #include "i4b_itjc_ext.h"
70 static char *state_text[N_STATES] = {
73 "F5 Identifying Input",
80 static char *event_text[N_EVENTS] = {
82 "EV_T3 Timer 3 expired",
83 "EV_INFO0 INFO0 received",
84 "EV_RSY Level Detected",
85 "EV_INFO2 INFO2 received",
86 "EV_INFO48 INFO4 received",
87 "EV_INFO410 INFO4 received",
88 "EV_DR Deactivate Req",
90 "EV_DIS Disconnected",
96 /* Function prototypes */
98 static void timer3_expired (struct l1_softc *sc);
99 static void T3_start (struct l1_softc *sc);
100 static void T3_stop (struct l1_softc *sc);
101 static void F_T3ex (struct l1_softc *sc);
102 static void timer4_expired (struct l1_softc *sc);
103 static void T4_start (struct l1_softc *sc);
104 static void T4_stop (struct l1_softc *sc);
105 static void F_AI8 (struct l1_softc *sc);
106 static void F_AI10 (struct l1_softc *sc);
107 static void F_I01 (struct l1_softc *sc);
108 static void F_I02 (struct l1_softc *sc);
109 static void F_I03 (struct l1_softc *sc);
110 static void F_I2 (struct l1_softc *sc);
111 static void F_ill (struct l1_softc *sc);
112 static void F_NULL (struct l1_softc *sc);
114 /*---------------------------------------------------------------------------*
115 * I.430 Timer T3 expire function
116 *---------------------------------------------------------------------------*/
118 timer3_expired(struct l1_softc *sc)
122 NDBGL1(L1_T_ERR, "state = %s", itjc_printstate(sc));
125 /* XXX try some recovery here XXX */
129 sc->sc_init_tries++; /* increment retry count */
131 /*XXX*/ if(sc->sc_init_tries > 4)
135 sc->sc_init_tries = 0;
137 if(sc->sc_obuf2 != NULL)
139 i4b_Dfreembuf(sc->sc_obuf2);
142 if(sc->sc_obuf != NULL)
144 i4b_Dfreembuf(sc->sc_obuf);
153 i4b_l1_mph_status_ind(L0ITJCUNIT(sc->sc_unit), STI_NOL1ACC, 0, NULL);
156 itjc_next_state(sc, EV_T3);
160 NDBGL1(L1_T_ERR, "expired without starting it ....");
164 /*---------------------------------------------------------------------------*
165 * I.430 Timer T3 start
166 *---------------------------------------------------------------------------*/
168 T3_start(struct l1_softc *sc)
170 NDBGL1(L1_T_MSG, "state = %s", itjc_printstate(sc));
172 callout_reset(&sc->sc_T3_timeout, 2 * hz,
173 (TIMEOUT_FUNC_T)timer3_expired, (struct l1_softc *)sc);
176 /*---------------------------------------------------------------------------*
177 * I.430 Timer T3 stop
178 *---------------------------------------------------------------------------*/
180 T3_stop(struct l1_softc *sc)
182 NDBGL1(L1_T_MSG, "state = %s", itjc_printstate(sc));
184 sc->sc_init_tries = 0; /* init connect retry count */
189 callout_stop(&sc->sc_T3_timeout);
193 /*---------------------------------------------------------------------------*
194 * I.430 Timer T3 expiry
195 *---------------------------------------------------------------------------*/
197 F_T3ex(struct l1_softc *sc)
199 NDBGL1(L1_F_MSG, "FSM function F_T3ex executing");
200 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
201 i4b_l1_ph_deactivate_ind(L0ITJCUNIT(sc->sc_unit));
204 /*---------------------------------------------------------------------------*
205 * Timer T4 expire function
206 *---------------------------------------------------------------------------*/
208 timer4_expired(struct l1_softc *sc)
212 NDBGL1(L1_T_MSG, "state = %s", itjc_printstate(sc));
214 i4b_l1_mph_status_ind(L0ITJCUNIT(sc->sc_unit), STI_PDEACT, 0, NULL);
218 NDBGL1(L1_T_ERR, "expired without starting it ....");
222 /*---------------------------------------------------------------------------*
224 *---------------------------------------------------------------------------*/
226 T4_start(struct l1_softc *sc)
228 NDBGL1(L1_T_MSG, "state = %s", itjc_printstate(sc));
230 callout_reset(&sc->sc_T4_timeout, hz,
231 (TIMEOUT_FUNC_T)timer4_expired, (struct l1_softc *)sc);
234 /*---------------------------------------------------------------------------*
236 *---------------------------------------------------------------------------*/
238 T4_stop(struct l1_softc *sc)
240 NDBGL1(L1_T_MSG, "state = %s", itjc_printstate(sc));
245 callout_stop(&sc->sc_T4_timeout);
249 /*---------------------------------------------------------------------------*
250 * FSM function: received AI8
251 *---------------------------------------------------------------------------*/
253 F_AI8(struct l1_softc *sc)
257 NDBGL1(L1_F_MSG, "FSM function F_AI8 executing");
259 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
260 i4b_l1_ph_activate_ind(L0ITJCUNIT(sc->sc_unit));
264 if(sc->sc_trace & TRACE_I)
269 hdr.unit = L0ITJCUNIT(sc->sc_unit);
274 i4b_l1_trace_ind(&hdr, 1, &info);
278 /*---------------------------------------------------------------------------*
279 * FSM function: received AI10
280 *---------------------------------------------------------------------------*/
282 F_AI10(struct l1_softc *sc)
286 NDBGL1(L1_F_MSG, "FSM function F_AI10 executing");
288 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
289 i4b_l1_ph_activate_ind(L0ITJCUNIT(sc->sc_unit));
293 if(sc->sc_trace & TRACE_I)
296 char info = INFO4_10;
298 hdr.unit = L0ITJCUNIT(sc->sc_unit);
303 i4b_l1_trace_ind(&hdr, 1, &info);
307 /*---------------------------------------------------------------------------*
308 * FSM function: received INFO 0 in states F3 .. F5
309 *---------------------------------------------------------------------------*/
311 F_I01(struct l1_softc *sc)
313 NDBGL1(L1_F_MSG, "FSM function F_I01 executing");
315 if(sc->sc_trace & TRACE_I)
320 hdr.unit = L0ITJCUNIT(sc->sc_unit);
325 i4b_l1_trace_ind(&hdr, 1, &info);
329 /*---------------------------------------------------------------------------*
330 * FSM function: received INFO 0 in state F6
331 *---------------------------------------------------------------------------*/
333 F_I02(struct l1_softc *sc)
335 NDBGL1(L1_F_MSG, "FSM function F_I02 executing");
337 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
338 i4b_l1_ph_deactivate_ind(L0ITJCUNIT(sc->sc_unit));
340 if(sc->sc_trace & TRACE_I)
345 hdr.unit = L0ITJCUNIT(sc->sc_unit);
350 i4b_l1_trace_ind(&hdr, 1, &info);
354 /*---------------------------------------------------------------------------*
355 * FSM function: received INFO 0 in state F7 or F8
356 *---------------------------------------------------------------------------*/
358 F_I03(struct l1_softc *sc)
360 NDBGL1(L1_F_MSG, "FSM function F_I03 executing");
362 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
363 i4b_l1_ph_deactivate_ind(L0ITJCUNIT(sc->sc_unit));
367 if(sc->sc_trace & TRACE_I)
372 hdr.unit = L0ITJCUNIT(sc->sc_unit);
377 i4b_l1_trace_ind(&hdr, 1, &info);
381 /*---------------------------------------------------------------------------*
382 * FSM function: activate request
383 *---------------------------------------------------------------------------*/
385 F_AR(struct l1_softc *sc)
387 NDBGL1(L1_F_MSG, "FSM function F_AR executing");
389 if(sc->sc_trace & TRACE_I)
394 hdr.unit = L0ITJCUNIT(sc->sc_unit);
399 i4b_l1_trace_ind(&hdr, 1, &info);
402 itjc_isac_l1_cmd(sc, CMD_AR8);
407 /*---------------------------------------------------------------------------*
408 * FSM function: received INFO2
409 *---------------------------------------------------------------------------*/
411 F_I2(struct l1_softc *sc)
413 NDBGL1(L1_F_MSG, "FSM function F_I2 executing");
415 if(sc->sc_trace & TRACE_I)
420 hdr.unit = L0ITJCUNIT(sc->sc_unit);
425 i4b_l1_trace_ind(&hdr, 1, &info);
430 /*---------------------------------------------------------------------------*
431 * illegal state default action
432 *---------------------------------------------------------------------------*/
434 F_ill(struct l1_softc *sc)
436 NDBGL1(L1_F_ERR, "FSM function F_ill executing");
439 /*---------------------------------------------------------------------------*
441 *---------------------------------------------------------------------------*/
443 F_NULL(struct l1_softc *sc)
445 NDBGL1(L1_F_MSG, "FSM function F_NULL executing");
449 /*---------------------------------------------------------------------------*
450 * layer 1 state transition table
451 *---------------------------------------------------------------------------*/
452 struct itjc_state_tab {
453 void (*func) (struct l1_softc *sc); /* function to execute */
454 int newstate; /* next state */
455 } itjc_state_tab[N_EVENTS][N_STATES] = {
457 /* STATE: F3 F4 F5 F6 F7 F8 ILLEGAL STATE */
458 /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
459 /* EV_PHAR x*/ {{F_AR, ST_F4}, {F_NULL, ST_F4}, {F_NULL, ST_F5}, {F_NULL, ST_F6}, {F_ill, ST_ILL}, {F_NULL, ST_F8}, {F_ill, ST_ILL}},
460 /* EV_T3 x*/ {{F_NULL, ST_F3}, {F_T3ex, ST_F3}, {F_T3ex, ST_F3}, {F_T3ex, ST_F3}, {F_NULL, ST_F7}, {F_NULL, ST_F8}, {F_ill, ST_ILL}},
461 /* EV_INFO0 */ {{F_I01, ST_F3}, {F_I01, ST_F4}, {F_I01, ST_F5}, {F_I02, ST_F3}, {F_I03, ST_F3}, {F_I03, ST_F3}, {F_ill, ST_ILL}},
462 /* EV_RSY x*/ {{F_NULL, ST_F3}, {F_NULL, ST_F5}, {F_NULL, ST_F5}, {F_NULL, ST_F8}, {F_NULL, ST_F8}, {F_NULL, ST_F8}, {F_ill, ST_ILL}},
463 /* EV_INFO2 */ {{F_I2, ST_F6}, {F_I2, ST_F6}, {F_I2, ST_F6}, {F_I2, ST_F6}, {F_I2, ST_F6}, {F_I2, ST_F6}, {F_ill, ST_ILL}},
464 /* EV_INFO48*/ {{F_AI8, ST_F7}, {F_AI8, ST_F7}, {F_AI8, ST_F7}, {F_AI8, ST_F7}, {F_NULL, ST_F7}, {F_AI8, ST_F7}, {F_ill, ST_ILL}},
465 /* EV_INFO41*/ {{F_AI10, ST_F7}, {F_AI10, ST_F7}, {F_AI10, ST_F7}, {F_AI10, ST_F7}, {F_NULL, ST_F7}, {F_AI10, ST_F7}, {F_ill, ST_ILL}},
466 /* EV_DR */ {{F_NULL, ST_F3}, {F_NULL, ST_F4}, {F_NULL, ST_F5}, {F_NULL, ST_F6}, {F_NULL, ST_F7}, {F_NULL, ST_F8}, {F_ill, ST_ILL}},
467 /* EV_PU */ {{F_NULL, ST_F3}, {F_NULL, ST_F4}, {F_NULL, ST_F5}, {F_NULL, ST_F6}, {F_NULL, ST_F7}, {F_NULL, ST_F8}, {F_ill, ST_ILL}},
468 /* EV_DIS */ {{F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}},
469 /* EV_EI */ {{F_NULL, ST_F3}, {F_NULL, ST_F3}, {F_NULL, ST_F3}, {F_NULL, ST_F3}, {F_NULL, ST_F3}, {F_NULL, ST_F3}, {F_ill, ST_ILL}},
470 /* EV_ILL */ {{F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}, {F_ill, ST_ILL}}
473 /*---------------------------------------------------------------------------*
475 *---------------------------------------------------------------------------*/
477 itjc_next_state(struct l1_softc *sc, int event)
479 int currstate, newstate;
481 if(event >= N_EVENTS)
482 panic("i4b_l1fsm.c: event >= N_EVENTS\n");
484 currstate = sc->sc_I430state;
486 if(currstate >= N_STATES)
487 panic("i4b_l1fsm.c: currstate >= N_STATES\n");
489 newstate = itjc_state_tab[event][currstate].newstate;
491 if(newstate >= N_STATES)
492 panic("i4b_l1fsm.c: newstate >= N_STATES\n");
494 NDBGL1(L1_F_MSG, "FSM event [%s]: [%s => %s]", event_text[event],
495 state_text[currstate],
496 state_text[newstate]);
498 (*itjc_state_tab[event][currstate].func)(sc);
500 if(newstate == ST_ILL)
503 NDBGL1(L1_F_ERR, "FSM Illegal State ERROR, oldstate = %s, newstate = %s, event = %s!",
504 state_text[currstate],
505 state_text[newstate],
509 sc->sc_I430state = newstate;
513 /*---------------------------------------------------------------------------*
514 * return pointer to current state description
515 *---------------------------------------------------------------------------*/
517 itjc_printstate(struct l1_softc *sc)
519 return((char *) state_text[sc->sc_I430state]);
523 #endif /* NITJC > 0 */