Initial import from FreeBSD RELENG_4:
[games.git] / sys / net / i4b / layer2 / i4b_l2timer.c
1 /*
2  * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_l2timer.c - layer 2 timer handling
28  *      --------------------------------------
29  *
30  *      $Id: i4b_l2timer.c,v 1.20 2000/08/24 11:48:58 hm Exp $ 
31  *
32  * $FreeBSD: src/sys/i4b/layer2/i4b_l2timer.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
33  *
34  *      last edit-date: [Thu Aug 24 12:48:52 2000]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifdef __FreeBSD__
39 #include "i4bq921.h"
40 #else
41 #define NI4BQ921        1
42 #endif
43 #if NI4BQ921 > 0
44
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 #include <sys/socket.h>
49 #include <net/if.h>
50
51 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
52 #include <sys/callout.h>
53 #endif
54
55 #ifdef __FreeBSD__
56 #include <machine/i4b_debug.h>
57 #else
58 #include <i4b/i4b_debug.h>
59 #include <i4b/i4b_ioctl.h>
60 #endif
61
62 #include <i4b/include/i4b_global.h>
63
64 #include <i4b/layer2/i4b_l2.h>
65 #include <i4b/layer2/i4b_l2fsm.h>
66
67 /*---------------------------------------------------------------------------*
68  *      Q.921 timer T200 timeout function
69  *---------------------------------------------------------------------------*/
70 static void
71 i4b_T200_timeout(l2_softc_t *l2sc)
72 {
73         NDBGL2(L2_T_ERR, "unit %d, RC = %d", l2sc->unit, l2sc->RC);
74         i4b_next_l2state(l2sc, EV_T200EXP);
75 }
76
77 /*---------------------------------------------------------------------------*
78  *      Q.921 timer T200 start
79  *---------------------------------------------------------------------------*/
80 void
81 i4b_T200_start(l2_softc_t *l2sc)
82 {
83         if(l2sc->T200 == TIMER_ACTIVE)
84                 return;
85                 
86         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
87         l2sc->T200 = TIMER_ACTIVE;
88
89         START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
90 }
91
92 /*---------------------------------------------------------------------------*
93  *      Q.921 timer T200 stop
94  *---------------------------------------------------------------------------*/
95 void
96 i4b_T200_stop(l2_softc_t *l2sc)
97 {
98         CRIT_VAR;
99         CRIT_BEG;
100         if(l2sc->T200 != TIMER_IDLE)
101         {
102                 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
103                 l2sc->T200 = TIMER_IDLE;
104         }
105         CRIT_END;
106         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
107 }
108
109 /*---------------------------------------------------------------------------*
110  *      Q.921 timer T200 restart
111  *---------------------------------------------------------------------------*/
112 void
113 i4b_T200_restart(l2_softc_t *l2sc)
114 {
115         CRIT_VAR;
116         CRIT_BEG;
117         if(l2sc->T200 != TIMER_IDLE)
118         {
119                 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
120         }
121         else
122         {
123                 l2sc->T200 = TIMER_ACTIVE;
124         }
125
126         START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
127         CRIT_END;
128         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
129 }
130
131 /*---------------------------------------------------------------------------*
132  *      Q.921 timer T202 timeout function
133  *---------------------------------------------------------------------------*/
134 static void
135 i4b_T202_timeout(l2_softc_t *l2sc)
136 {
137         NDBGL2(L2_T_ERR, "unit %d, N202 = %d", l2sc->unit, l2sc->N202);
138         
139         if(--(l2sc->N202))
140         {
141                 (*l2sc->T202func)(l2sc);
142         }
143 }
144
145 /*---------------------------------------------------------------------------*
146  *      Q.921 timer T202 start
147  *---------------------------------------------------------------------------*/
148 void
149 i4b_T202_start(l2_softc_t *l2sc)
150 {
151         if (l2sc->N202 == TIMER_ACTIVE)
152                 return;
153
154         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
155         l2sc->N202 = N202DEF;   
156         l2sc->T202 = TIMER_ACTIVE;
157
158         START_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc, T202DEF);
159 }
160
161 /*---------------------------------------------------------------------------*
162  *      Q.921 timer T202 stop
163  *---------------------------------------------------------------------------*/
164 void
165 i4b_T202_stop(l2_softc_t *l2sc)
166 {
167         CRIT_VAR;
168         CRIT_BEG;
169         if(l2sc->T202 != TIMER_IDLE)
170         {
171                 STOP_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc);
172                 l2sc->T202 = TIMER_IDLE;
173         }
174         CRIT_END;
175         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
176 }
177
178 /*---------------------------------------------------------------------------*
179  *      Q.921 timer T203 timeout function
180  *---------------------------------------------------------------------------*/
181 #if I4B_T203_ACTIVE
182 static void
183 i4b_T203_timeout(l2_softc_t *l2sc)
184 {
185         NDBGL2(L2_T_ERR, "unit %d", l2sc->unit);
186         i4b_next_l2state(l2sc, EV_T203EXP);
187 }
188 #endif
189
190 /*---------------------------------------------------------------------------*
191  *      Q.921 timer T203 start
192  *---------------------------------------------------------------------------*/
193 void
194 i4b_T203_start(l2_softc_t *l2sc)
195 {
196 #if I4B_T203_ACTIVE
197         if (l2sc->T203 == TIMER_ACTIVE)
198                 return;
199                 
200         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
201         l2sc->T203 = TIMER_ACTIVE;
202
203         START_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc, T203DEF);
204 #endif
205 }
206
207 /*---------------------------------------------------------------------------*
208  *      Q.921 timer T203 stop
209  *---------------------------------------------------------------------------*/
210 void
211 i4b_T203_stop(l2_softc_t *l2sc)
212 {
213 #if I4B_T203_ACTIVE
214         CRIT_VAR;
215         CRIT_BEG;
216         if(l2sc->T203 != TIMER_IDLE)
217         {
218                 STOP_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc);
219                 l2sc->T203 = TIMER_IDLE;
220         }
221         CRIT_END;
222         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
223 #endif
224 }
225
226 /*---------------------------------------------------------------------------*
227  *      Q.921 timer T203 restart
228  *---------------------------------------------------------------------------*/
229 void
230 i4b_T203_restart(l2_softc_t *l2sc)
231 {
232 #if I4B_T203_ACTIVE
233         CRIT_VAR;
234         CRIT_BEG;
235
236         if(l2sc->T203 != TIMER_IDLE)
237         {
238                 STOP_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc);
239         }
240         else
241         {
242                 l2sc->T203 = TIMER_ACTIVE;
243         }
244
245         START_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc, T203DEF);      
246         CRIT_END;
247         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
248 #endif
249 }
250
251 #endif /* NI4BQ921 > 0 */