[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / net / x25 / x25_timer.c
blobd6a21a3ad80e78b2b9299b4d52817266b1cc1b9f
1 /*
2 * X.25 Packet Layer release 002
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
6 * screw up. It might even work.
8 * This code REQUIRES 2.1.15 or higher
10 * This module:
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
16 * History
17 * X.25 001 Jonathan Naylor Started coding.
18 * X.25 002 Jonathan Naylor New timer architecture.
19 * Centralised disconnection processing.
22 #include <linux/errno.h>
23 #include <linux/jiffies.h>
24 #include <linux/timer.h>
25 #include <net/sock.h>
26 #include <net/tcp.h>
27 #include <net/x25.h>
29 static void x25_heartbeat_expiry(unsigned long);
30 static void x25_timer_expiry(unsigned long);
32 void x25_init_timers(struct sock *sk)
34 struct x25_sock *x25 = x25_sk(sk);
36 init_timer(&x25->timer);
37 x25->timer.data = (unsigned long)sk;
38 x25->timer.function = &x25_timer_expiry;
40 /* initialized by sock_init_data */
41 sk->sk_timer.data = (unsigned long)sk;
42 sk->sk_timer.function = &x25_heartbeat_expiry;
45 void x25_start_heartbeat(struct sock *sk)
47 mod_timer(&sk->sk_timer, jiffies + 5 * HZ);
50 void x25_stop_heartbeat(struct sock *sk)
52 del_timer(&sk->sk_timer);
55 void x25_start_t2timer(struct sock *sk)
57 struct x25_sock *x25 = x25_sk(sk);
59 mod_timer(&x25->timer, jiffies + x25->t2);
62 void x25_start_t21timer(struct sock *sk)
64 struct x25_sock *x25 = x25_sk(sk);
66 mod_timer(&x25->timer, jiffies + x25->t21);
69 void x25_start_t22timer(struct sock *sk)
71 struct x25_sock *x25 = x25_sk(sk);
73 mod_timer(&x25->timer, jiffies + x25->t22);
76 void x25_start_t23timer(struct sock *sk)
78 struct x25_sock *x25 = x25_sk(sk);
80 mod_timer(&x25->timer, jiffies + x25->t23);
83 void x25_stop_timer(struct sock *sk)
85 del_timer(&x25_sk(sk)->timer);
88 unsigned long x25_display_timer(struct sock *sk)
90 struct x25_sock *x25 = x25_sk(sk);
92 if (!timer_pending(&x25->timer))
93 return 0;
95 return x25->timer.expires - jiffies;
98 static void x25_heartbeat_expiry(unsigned long param)
100 struct sock *sk = (struct sock *)param;
102 bh_lock_sock(sk);
103 if (sock_owned_by_user(sk)) /* can currently only occur in state 3 */
104 goto restart_heartbeat;
106 switch (x25_sk(sk)->state) {
108 case X25_STATE_0:
110 * Magic here: If we listen() and a new link dies
111 * before it is accepted() it isn't 'dead' so doesn't
112 * get removed.
114 if (sock_flag(sk, SOCK_DESTROY) ||
115 (sk->sk_state == TCP_LISTEN &&
116 sock_flag(sk, SOCK_DEAD))) {
117 x25_destroy_socket(sk);
118 goto unlock;
120 break;
122 case X25_STATE_3:
124 * Check for the state of the receive buffer.
126 x25_check_rbuf(sk);
127 break;
129 restart_heartbeat:
130 x25_start_heartbeat(sk);
131 unlock:
132 bh_unlock_sock(sk);
136 * Timer has expired, it may have been T2, T21, T22, or T23. We can tell
137 * by the state machine state.
139 static inline void x25_do_timer_expiry(struct sock * sk)
141 struct x25_sock *x25 = x25_sk(sk);
143 switch (x25->state) {
145 case X25_STATE_3: /* T2 */
146 if (x25->condition & X25_COND_ACK_PENDING) {
147 x25->condition &= ~X25_COND_ACK_PENDING;
148 x25_enquiry_response(sk);
150 break;
152 case X25_STATE_1: /* T21 */
153 case X25_STATE_4: /* T22 */
154 x25_write_internal(sk, X25_CLEAR_REQUEST);
155 x25->state = X25_STATE_2;
156 x25_start_t23timer(sk);
157 break;
159 case X25_STATE_2: /* T23 */
160 x25_disconnect(sk, ETIMEDOUT, 0, 0);
161 break;
165 static void x25_timer_expiry(unsigned long param)
167 struct sock *sk = (struct sock *)param;
169 bh_lock_sock(sk);
170 if (sock_owned_by_user(sk)) { /* can currently only occur in state 3 */
171 if (x25_sk(sk)->state == X25_STATE_3)
172 x25_start_t2timer(sk);
173 } else
174 x25_do_timer_expiry(sk);
175 bh_unlock_sock(sk);