2 * Copyright (c) 1997, 2000 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_ifpi2_l1fsm.c - AVM Fritz PCI layer 1 I.430 state machine
28 * ------------------------------------------------------------
32 * $FreeBSD: src/sys/i4b/layer1/ifpi2/i4b_ifpi2_l1fsm.c,v 1.1.2.1 2002/04/25 20:26:50 gj Exp $
33 * $DragonFly: src/sys/net/i4b/layer1/ifpi2/i4b_ifpi2_l1fsm.c,v 1.3 2003/08/07 21:17:25 dillon Exp $
35 * last edit-date: [Mon May 29 15:23:15 2000]
37 *---------------------------------------------------------------------------*/
39 #include "use_ifpi2.h"
42 #if (NIFPI2 > 0) && (NPCI > 0)
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/socket.h>
52 #include <net/i4b/include/machine/i4b_debug.h>
53 #include <net/i4b/include/machine/i4b_ioctl.h>
54 #include <net/i4b/include/machine/i4b_trace.h>
56 #include "../isic/i4b_isic.h"
57 #include "../i4b_l1.h"
58 #include "../../include/i4b_global.h"
59 #include "../../include/i4b_mbuf.h"
61 #include "i4b_ifpi2_ext.h"
64 static char *state_text[N_STATES] = {
67 "F5 Identifying Input",
74 static char *event_text[N_EVENTS] = {
76 "EV_T3 Timer 3 expired",
77 "EV_INFO0 INFO0 received",
78 "EV_RSY Level Detected",
79 "EV_INFO2 INFO2 received",
80 "EV_INFO48 INFO4 received",
81 "EV_INFO410 INFO4 received",
82 "EV_DR Deactivate Req",
84 "EV_DIS Disconnected",
90 /* Function prototypes */
92 static void timer3_expired (struct l1_softc *sc);
93 static void T3_start (struct l1_softc *sc);
94 static void T3_stop (struct l1_softc *sc);
95 static void F_T3ex (struct l1_softc *sc);
96 static void timer4_expired (struct l1_softc *sc);
97 static void T4_start (struct l1_softc *sc);
98 static void T4_stop (struct l1_softc *sc);
99 static void F_AI8 (struct l1_softc *sc);
100 static void F_AI10 (struct l1_softc *sc);
101 static void F_I01 (struct l1_softc *sc);
102 static void F_I02 (struct l1_softc *sc);
103 static void F_I03 (struct l1_softc *sc);
104 static void F_I2 (struct l1_softc *sc);
105 static void F_ill (struct l1_softc *sc);
106 static void F_NULL (struct l1_softc *sc);
108 /*---------------------------------------------------------------------------*
109 * I.430 Timer T3 expire function
110 *---------------------------------------------------------------------------*/
112 timer3_expired(struct l1_softc *sc)
116 NDBGL1(L1_T_ERR, "state = %s", ifpi2_printstate(sc));
119 /* XXX try some recovery here XXX */
123 sc->sc_init_tries++; /* increment retry count */
125 /*XXX*/ if(sc->sc_init_tries > 4)
129 sc->sc_init_tries = 0;
131 if(sc->sc_obuf2 != NULL)
133 i4b_Dfreembuf(sc->sc_obuf2);
136 if(sc->sc_obuf != NULL)
138 i4b_Dfreembuf(sc->sc_obuf);
147 i4b_l1_mph_status_ind(L0IFPI2UNIT(sc->sc_unit), STI_NOL1ACC, 0, NULL);
150 ifpi2_next_state(sc, EV_T3);
154 NDBGL1(L1_T_ERR, "expired without starting it ....");
158 /*---------------------------------------------------------------------------*
159 * I.430 Timer T3 start
160 *---------------------------------------------------------------------------*/
162 T3_start(struct l1_softc *sc)
164 NDBGL1(L1_T_MSG, "state = %s", ifpi2_printstate(sc));
166 sc->sc_T3_callout = timeout((TIMEOUT_FUNC_T)timer3_expired,(struct l1_softc *)sc, 2*hz);
169 /*---------------------------------------------------------------------------*
170 * I.430 Timer T3 stop
171 *---------------------------------------------------------------------------*/
173 T3_stop(struct l1_softc *sc)
175 NDBGL1(L1_T_MSG, "state = %s", ifpi2_printstate(sc));
177 sc->sc_init_tries = 0; /* init connect retry count */
182 untimeout((TIMEOUT_FUNC_T)timer3_expired,(struct l1_softc *)sc, sc->sc_T3_callout);
186 /*---------------------------------------------------------------------------*
187 * I.430 Timer T3 expiry
188 *---------------------------------------------------------------------------*/
190 F_T3ex(struct l1_softc *sc)
192 NDBGL1(L1_F_MSG, "FSM function F_T3ex executing");
193 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
194 i4b_l1_ph_deactivate_ind(L0IFPI2UNIT(sc->sc_unit));
197 /*---------------------------------------------------------------------------*
198 * Timer T4 expire function
199 *---------------------------------------------------------------------------*/
201 timer4_expired(struct l1_softc *sc)
205 NDBGL1(L1_T_MSG, "state = %s", ifpi2_printstate(sc));
207 i4b_l1_mph_status_ind(L0IFPI2UNIT(sc->sc_unit), STI_PDEACT, 0, NULL);
211 NDBGL1(L1_T_ERR, "expired without starting it ....");
215 /*---------------------------------------------------------------------------*
217 *---------------------------------------------------------------------------*/
219 T4_start(struct l1_softc *sc)
221 NDBGL1(L1_T_MSG, "state = %s", ifpi2_printstate(sc));
223 sc->sc_T4_callout = timeout((TIMEOUT_FUNC_T)timer4_expired,(struct l1_softc *)sc, hz);
226 /*---------------------------------------------------------------------------*
228 *---------------------------------------------------------------------------*/
230 T4_stop(struct l1_softc *sc)
232 NDBGL1(L1_T_MSG, "state = %s", ifpi2_printstate(sc));
237 untimeout((TIMEOUT_FUNC_T)timer4_expired,(struct l1_softc *)sc, sc->sc_T4_callout);
241 /*---------------------------------------------------------------------------*
242 * FSM function: received AI8
243 *---------------------------------------------------------------------------*/
245 F_AI8(struct l1_softc *sc)
249 NDBGL1(L1_F_MSG, "FSM function F_AI8 executing");
251 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
252 i4b_l1_ph_activate_ind(L0IFPI2UNIT(sc->sc_unit));
256 if(sc->sc_trace & TRACE_I)
261 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
266 i4b_l1_trace_ind(&hdr, 1, &info);
270 /*---------------------------------------------------------------------------*
271 * FSM function: received AI10
272 *---------------------------------------------------------------------------*/
274 F_AI10(struct l1_softc *sc)
278 NDBGL1(L1_F_MSG, "FSM function F_AI10 executing");
280 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
281 i4b_l1_ph_activate_ind(L0IFPI2UNIT(sc->sc_unit));
285 if(sc->sc_trace & TRACE_I)
288 char info = INFO4_10;
290 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
295 i4b_l1_trace_ind(&hdr, 1, &info);
299 /*---------------------------------------------------------------------------*
300 * FSM function: received INFO 0 in states F3 .. F5
301 *---------------------------------------------------------------------------*/
303 F_I01(struct l1_softc *sc)
305 NDBGL1(L1_F_MSG, "FSM function F_I01 executing");
307 if(sc->sc_trace & TRACE_I)
312 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
317 i4b_l1_trace_ind(&hdr, 1, &info);
321 /*---------------------------------------------------------------------------*
322 * FSM function: received INFO 0 in state F6
323 *---------------------------------------------------------------------------*/
325 F_I02(struct l1_softc *sc)
327 NDBGL1(L1_F_MSG, "FSM function F_I02 executing");
329 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
330 i4b_l1_ph_deactivate_ind(L0IFPI2UNIT(sc->sc_unit));
332 if(sc->sc_trace & TRACE_I)
337 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
342 i4b_l1_trace_ind(&hdr, 1, &info);
346 /*---------------------------------------------------------------------------*
347 * FSM function: received INFO 0 in state F7 or F8
348 *---------------------------------------------------------------------------*/
350 F_I03(struct l1_softc *sc)
352 NDBGL1(L1_F_MSG, "FSM function F_I03 executing");
354 if(ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S)
355 i4b_l1_ph_deactivate_ind(L0IFPI2UNIT(sc->sc_unit));
359 if(sc->sc_trace & TRACE_I)
364 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
369 i4b_l1_trace_ind(&hdr, 1, &info);
373 /*---------------------------------------------------------------------------*
374 * FSM function: activate request
375 *---------------------------------------------------------------------------*/
377 F_AR(struct l1_softc *sc)
379 NDBGL1(L1_F_MSG, "FSM function F_AR executing");
381 if(sc->sc_trace & TRACE_I)
386 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
391 i4b_l1_trace_ind(&hdr, 1, &info);
394 ifpi2_isacsx_l1_cmd(sc, CMD_AR8);
399 /*---------------------------------------------------------------------------*
400 * FSM function: received INFO2
401 *---------------------------------------------------------------------------*/
403 F_I2(struct l1_softc *sc)
405 NDBGL1(L1_F_MSG, "FSM function F_I2 executing");
407 if(sc->sc_trace & TRACE_I)
412 hdr.unit = L0IFPI2UNIT(sc->sc_unit);
417 i4b_l1_trace_ind(&hdr, 1, &info);
422 /*---------------------------------------------------------------------------*
423 * illegal state default action
424 *---------------------------------------------------------------------------*/
426 F_ill(struct l1_softc *sc)
428 NDBGL1(L1_F_ERR, "FSM function F_ill executing");
431 /*---------------------------------------------------------------------------*
433 *---------------------------------------------------------------------------*/
435 F_NULL(struct l1_softc *sc)
437 NDBGL1(L1_F_MSG, "FSM function F_NULL executing");
441 /*---------------------------------------------------------------------------*
442 * layer 1 state transition table
443 *---------------------------------------------------------------------------*/
444 struct ifpi2_state_tab {
445 void (*func) (struct l1_softc *sc); /* function to execute */
446 int newstate; /* next state */
447 } ifpi2_state_tab[N_EVENTS][N_STATES] = {
449 /* STATE: F3 F4 F5 F6 F7 F8 ILLEGAL STATE */
450 /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
451 /* 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}},
452 /* 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}},
453 /* 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}},
454 /* 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}},
455 /* 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}},
456 /* 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}},
457 /* 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}},
458 /* 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}},
459 /* 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}},
460 /* 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}},
461 /* 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}},
462 /* 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}}
465 /*---------------------------------------------------------------------------*
467 *---------------------------------------------------------------------------*/
469 ifpi2_next_state(struct l1_softc *sc, int event)
471 int currstate, newstate;
473 if(event >= N_EVENTS)
474 panic("i4b_l1fsm.c: event >= N_EVENTS\n");
476 currstate = sc->sc_I430state;
478 if(currstate >= N_STATES)
479 panic("i4b_l1fsm.c: currstate >= N_STATES\n");
481 newstate = ifpi2_state_tab[event][currstate].newstate;
483 if(newstate >= N_STATES)
484 panic("i4b_l1fsm.c: newstate >= N_STATES\n");
486 NDBGL1(L1_F_MSG, "FSM event [%s]: [%s => %s]", event_text[event],
487 state_text[currstate],
488 state_text[newstate]);
490 (*ifpi2_state_tab[event][currstate].func)(sc);
492 if(newstate == ST_ILL)
495 NDBGL1(L1_F_ERR, "FSM Illegal State ERROR, oldstate = %s, newstate = %s, event = %s!",
496 state_text[currstate],
497 state_text[newstate],
501 sc->sc_I430state = newstate;
505 /*---------------------------------------------------------------------------*
506 * return pointer to current state description
507 *---------------------------------------------------------------------------*/
509 ifpi2_printstate(struct l1_softc *sc)
511 return((char *) state_text[sc->sc_I430state]);
515 #endif /* NIFPI2 > 0 */