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