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