1 /* $NetBSD: iwic_fsm.c,v 1.3 2005/12/11 12:22:50 christos Exp $ */
4 * Copyright (c) 1999, 2000 Dave Boyce. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 *---------------------------------------------------------------------------
29 * i4b_iwic - isdn4bsd Winbond W6692 driver
30 * ----------------------------------------
34 * last edit-date: [Sun Jan 21 11:09:24 2001]
36 *---------------------------------------------------------------------------*/
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: iwic_fsm.c,v 1.3 2005/12/11 12:22:50 christos Exp $");
41 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/systm.h>
45 #include <sys/callout.h>
46 #include <sys/socket.h>
47 #include <sys/device.h>
52 #include <dev/pci/pcireg.h>
53 #include <dev/pci/pcivar.h>
54 #include <dev/pci/pcidevs.h>
56 #include <dev/pci/iwicreg.h>
57 #include <dev/pci/iwicvar.h>
60 static const char *state_names
[] = {
71 static const char *event_names
[] = {
88 /*---------------------------------------------------------------------------*
90 *---------------------------------------------------------------------------*/
92 F_NULL(struct iwic_softc
*sc
)
94 NDBGL1(L1_F_MSG
, "FSM function F_NULL executing");
97 /*---------------------------------------------------------------------------*
99 *---------------------------------------------------------------------------*/
101 F_AR(struct iwic_softc
*sc
)
103 NDBGL1(L1_F_MSG
, "FSM function F_AR executing");
104 IWIC_WRITE(sc
, CIX
, CIX_ECK
);
107 /*---------------------------------------------------------------------------*
109 *---------------------------------------------------------------------------*/
111 F_AR3(struct iwic_softc
*sc
)
113 NDBGL1(L1_F_MSG
, "FSM function F_AR3 executing");
114 IWIC_WRITE(sc
, CIX
, CIX_AR8
);
117 /*---------------------------------------------------------------------------*
119 *---------------------------------------------------------------------------*/
121 F_I0I(struct iwic_softc
*sc
)
123 NDBGL1(L1_F_MSG
, "FSM function F_IOI executing");
126 /*---------------------------------------------------------------------------*
128 *---------------------------------------------------------------------------*/
130 F_I0A(struct iwic_softc
*sc
)
132 NDBGL1(L1_F_MSG
, "FSM function F_IOA executing");
133 iwic_dchan_disable(sc
);
134 isdn_layer2_activate_ind(&sc
->sc_l2
, sc
->sc_l3token
, 0);
137 /*---------------------------------------------------------------------------*
139 *---------------------------------------------------------------------------*/
141 F_AI8(struct iwic_softc
*sc
)
143 NDBGL1(L1_F_MSG
, "FSM function F_AI8 executing");
144 iwic_dchan_transmit(sc
);
145 isdn_layer2_activate_ind(&sc
->sc_l2
, sc
->sc_l3token
, 1);
148 /*---------------------------------------------------------------------------*
150 *---------------------------------------------------------------------------*/
152 F_AI10(struct iwic_softc
*sc
)
154 NDBGL1(L1_F_MSG
, "FSM function F_AI10 executing");
155 iwic_dchan_transmit(sc
);
156 isdn_layer2_activate_ind(&sc
->sc_l2
, sc
->sc_l3token
, 1);
159 /*---------------------------------------------------------------------------*
161 *---------------------------------------------------------------------------*/
162 struct iwic_state_tab
{
163 void (*func
) (struct iwic_softc
*sc
); /* function to execute */
164 int newstate
; /* next state */
165 } iwic_state_tab
[N_EVENTS
][N_STATES
] = {
167 /* STATE: F3N F3 F4 F5 F6 F7 F8 ILLEGAL STATE */
168 /* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ */
169 /* EV_PHAR */ {{F_AR
, ST_F3
}, {F_AR3
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_F5
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F7
}, {F_NULL
, ST_F8
}, {F_NULL
, ST_ILL
}},
170 /* EV_CE */ {{F_NULL
, ST_F3
}, {F_AR3
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_F4
}, {F_NULL
, ST_ILL
}},
171 /* EV_T3 */ {{F_NULL
, ST_F3N
}, {F_NULL
, ST_F3
}, {F_NULL
, ST_F3
}, {F_NULL
, ST_F3
}, {F_NULL
, ST_F3
}, {F_NULL
, ST_F7
}, {F_NULL
, ST_F8
}, {F_NULL
, ST_ILL
}},
172 /* EV_INFO0 */ {{F_I0I
, ST_F3
}, {F_I0I
, ST_F3
}, {F_I0I
, ST_F3
}, {F_I0I
, ST_F3
}, {F_I0A
, ST_F3
}, {F_I0A
, ST_F3
}, {F_I0A
, ST_F3
}, {F_NULL
, ST_ILL
}},
173 /* EV_RSY */ {{F_NULL
, ST_F3
}, {F_NULL
, ST_F5
}, {F_NULL
, ST_F5
}, {F_NULL
, ST_F5
}, {F_NULL
, ST_F8
}, {F_NULL
, ST_F8
}, {F_NULL
, ST_F8
}, {F_NULL
, ST_ILL
}},
174 /* EV_INFO2 */ {{F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_F6
}, {F_NULL
, ST_ILL
}},
175 /* EV_INFO48 */ {{F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_AI8
, ST_F7
}, {F_NULL
, ST_ILL
}},
176 /* EV_INFO410*/ {{F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_AI10
, ST_F7
}, {F_NULL
, ST_ILL
}},
177 /* EV_DR */ {{F_NULL
, ST_F3
}, {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_NULL
, ST_ILL
}},
178 /* EV_PU */ {{F_NULL
, ST_F3
}, {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_NULL
, ST_ILL
}},
179 /* EV_DIS */ {{F_NULL
, ST_F3N
}, {F_NULL
, ST_F3N
}, {F_NULL
, ST_F3N
}, {F_NULL
, ST_F3N
}, {F_NULL
, ST_F3N
}, {F_I0A
, ST_F3N
}, {F_I0A
, ST_F3N
}, {F_NULL
, ST_ILL
}},
180 /* 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_NULL
, ST_F3
}, {F_NULL
, ST_ILL
}},
181 /* EV_ILL */ {{F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}, {F_NULL
, ST_ILL
}},
184 /*---------------------------------------------------------------------------*
186 *---------------------------------------------------------------------------*/
188 iwic_next_state(struct iwic_softc
*sc
, int event
)
190 int currstate
, newstate
;
192 NDBGL1(L1_F_MSG
, "event %s", event_names
[event
]);
194 if (event
>= N_EVENTS
)
196 printf("iwic_next_state: event >= N_EVENTS\n");
200 currstate
= sc
->sc_I430state
;
202 newstate
= iwic_state_tab
[event
][currstate
].newstate
;
203 if (newstate
>= N_STATES
)
205 printf("iwic_next_state: newstate >= N_STATES\n");
209 NDBGL1(L1_F_MSG
, "state %s -> %s",
210 state_names
[currstate
], state_names
[newstate
]);
212 sc
->sc_I430state
= newstate
;
214 (*iwic_state_tab
[event
][currstate
].func
) (sc
);
218 /*---------------------------------------------------------------------------*
219 * return pointer to current state description
220 *---------------------------------------------------------------------------*/
222 iwic_printstate(struct iwic_softc
*sc
)
224 return state_names
[sc
->sc_I430state
];