aboutsummaryrefslogtreecommitdiffstats
path: root/net/irda/timer.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/irda/timer.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/irda/timer.c')
-rw-r--r--net/irda/timer.c233
1 files changed, 233 insertions, 0 deletions
diff --git a/net/irda/timer.c b/net/irda/timer.c
new file mode 100644
index 000000000000..0e17f976add6
--- /dev/null
+++ b/net/irda/timer.c
@@ -0,0 +1,233 @@
1/*********************************************************************
2 *
3 * Filename: timer.c
4 * Version:
5 * Description:
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Aug 16 00:59:29 1997
9 * Modified at: Wed Dec 8 12:50:34 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1997, 1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 * Copyright (c) 2000-2002 Jean Tourrilhes <jt@hpl.hp.com>
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * Neither Dag Brattli nor University of Tromsų admit liability nor
22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge.
24 *
25 ********************************************************************/
26
27#include <asm/system.h>
28#include <linux/config.h>
29#include <linux/delay.h>
30
31#include <net/irda/timer.h>
32#include <net/irda/irda.h>
33#include <net/irda/irda_device.h>
34#include <net/irda/irlap.h>
35#include <net/irda/irlmp.h>
36
37extern int sysctl_slot_timeout;
38
39static void irlap_slot_timer_expired(void* data);
40static void irlap_query_timer_expired(void* data);
41static void irlap_final_timer_expired(void* data);
42static void irlap_wd_timer_expired(void* data);
43static void irlap_backoff_timer_expired(void* data);
44static void irlap_media_busy_expired(void* data);
45
46void irlap_start_slot_timer(struct irlap_cb *self, int timeout)
47{
48 irda_start_timer(&self->slot_timer, timeout, (void *) self,
49 irlap_slot_timer_expired);
50}
51
52void irlap_start_query_timer(struct irlap_cb *self, int S, int s)
53{
54 int timeout;
55
56 /* Calculate when the peer discovery should end. Normally, we
57 * get the end-of-discovery frame, so this is just in case
58 * we miss it.
59 * Basically, we multiply the number of remaining slots by our
60 * slot time, plus add some extra time to properly receive the last
61 * discovery packet (which is longer due to extra discovery info),
62 * to avoid messing with for incomming connections requests and
63 * to accomodate devices that perform discovery slower than us.
64 * Jean II */
65 timeout = ((sysctl_slot_timeout * HZ / 1000) * (S - s)
66 + XIDEXTRA_TIMEOUT + SMALLBUSY_TIMEOUT);
67
68 /* Set or re-set the timer. We reset the timer for each received
69 * discovery query, which allow us to automatically adjust to
70 * the speed of the peer discovery (faster or slower). Jean II */
71 irda_start_timer( &self->query_timer, timeout, (void *) self,
72 irlap_query_timer_expired);
73}
74
75void irlap_start_final_timer(struct irlap_cb *self, int timeout)
76{
77 irda_start_timer(&self->final_timer, timeout, (void *) self,
78 irlap_final_timer_expired);
79}
80
81void irlap_start_wd_timer(struct irlap_cb *self, int timeout)
82{
83 irda_start_timer(&self->wd_timer, timeout, (void *) self,
84 irlap_wd_timer_expired);
85}
86
87void irlap_start_backoff_timer(struct irlap_cb *self, int timeout)
88{
89 irda_start_timer(&self->backoff_timer, timeout, (void *) self,
90 irlap_backoff_timer_expired);
91}
92
93void irlap_start_mbusy_timer(struct irlap_cb *self, int timeout)
94{
95 irda_start_timer(&self->media_busy_timer, timeout,
96 (void *) self, irlap_media_busy_expired);
97}
98
99void irlap_stop_mbusy_timer(struct irlap_cb *self)
100{
101 /* If timer is activated, kill it! */
102 del_timer(&self->media_busy_timer);
103
104 /* If we are in NDM, there is a bunch of events in LAP that
105 * that be pending due to the media_busy condition, such as
106 * CONNECT_REQUEST and SEND_UI_FRAME. If we don't generate
107 * an event, they will wait forever...
108 * Jean II */
109 if (self->state == LAP_NDM)
110 irlap_do_event(self, MEDIA_BUSY_TIMER_EXPIRED, NULL, NULL);
111}
112
113void irlmp_start_watchdog_timer(struct lsap_cb *self, int timeout)
114{
115 irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
116 irlmp_watchdog_timer_expired);
117}
118
119void irlmp_start_discovery_timer(struct irlmp_cb *self, int timeout)
120{
121 irda_start_timer(&self->discovery_timer, timeout, (void *) self,
122 irlmp_discovery_timer_expired);
123}
124
125void irlmp_start_idle_timer(struct lap_cb *self, int timeout)
126{
127 irda_start_timer(&self->idle_timer, timeout, (void *) self,
128 irlmp_idle_timer_expired);
129}
130
131void irlmp_stop_idle_timer(struct lap_cb *self)
132{
133 /* If timer is activated, kill it! */
134 del_timer(&self->idle_timer);
135}
136
137/*
138 * Function irlap_slot_timer_expired (data)
139 *
140 * IrLAP slot timer has expired
141 *
142 */
143static void irlap_slot_timer_expired(void *data)
144{
145 struct irlap_cb *self = (struct irlap_cb *) data;
146
147 IRDA_ASSERT(self != NULL, return;);
148 IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
149
150 irlap_do_event(self, SLOT_TIMER_EXPIRED, NULL, NULL);
151}
152
153/*
154 * Function irlap_query_timer_expired (data)
155 *
156 * IrLAP query timer has expired
157 *
158 */
159static void irlap_query_timer_expired(void *data)
160{
161 struct irlap_cb *self = (struct irlap_cb *) data;
162
163 IRDA_ASSERT(self != NULL, return;);
164 IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
165
166 irlap_do_event(self, QUERY_TIMER_EXPIRED, NULL, NULL);
167}
168
169/*
170 * Function irda_final_timer_expired (data)
171 *
172 *
173 *
174 */
175static void irlap_final_timer_expired(void *data)
176{
177 struct irlap_cb *self = (struct irlap_cb *) data;
178
179 IRDA_ASSERT(self != NULL, return;);
180 IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
181
182 irlap_do_event(self, FINAL_TIMER_EXPIRED, NULL, NULL);
183}
184
185/*
186 * Function irda_wd_timer_expired (data)
187 *
188 *
189 *
190 */
191static void irlap_wd_timer_expired(void *data)
192{
193 struct irlap_cb *self = (struct irlap_cb *) data;
194
195 IRDA_ASSERT(self != NULL, return;);
196 IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
197
198 irlap_do_event(self, WD_TIMER_EXPIRED, NULL, NULL);
199}
200
201/*
202 * Function irda_backoff_timer_expired (data)
203 *
204 *
205 *
206 */
207static void irlap_backoff_timer_expired(void *data)
208{
209 struct irlap_cb *self = (struct irlap_cb *) data;
210
211 IRDA_ASSERT(self != NULL, return;);
212 IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
213
214 irlap_do_event(self, BACKOFF_TIMER_EXPIRED, NULL, NULL);
215}
216
217
218/*
219 * Function irtty_media_busy_expired (data)
220 *
221 *
222 */
223void irlap_media_busy_expired(void* data)
224{
225 struct irlap_cb *self = (struct irlap_cb *) data;
226
227 IRDA_ASSERT(self != NULL, return;);
228
229 irda_device_set_media_busy(self->netdev, FALSE);
230 /* Note : the LAP event will be send in irlap_stop_mbusy_timer(),
231 * to catch other cases where the flag is cleared (for example
232 * after a discovery) - Jean II */
233}