blob: 4c141810eb6dc210935f9c12cba875e0912f318d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/types.h>
2#include <linux/atmmpc.h>
3#include <linux/time.h>
4
5#include "mpoa_caches.h"
6#include "mpc.h"
7
8/*
9 * mpoa_caches.c: Implementation of ingress and egress cache
10 * handling functions
11 */
12
13#if 0
Joe Perchesb50c2ea2010-01-26 11:40:20 +000014#define dprintk(format, args...) \
15 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#else
Joe Perchesb50c2ea2010-01-26 11:40:20 +000017#define dprintk(format, args...) \
18 do { if (0) \
19 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
20 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#endif
22
23#if 0
Joe Perchesb50c2ea2010-01-26 11:40:20 +000024#define ddprintk(format, args...) \
25 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#else
Joe Perchesb50c2ea2010-01-26 11:40:20 +000027#define ddprintk(format, args...) \
28 do { if (0) \
29 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
30 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#endif
32
Al Viro30d492d2006-11-14 21:11:29 -080033static in_cache_entry *in_cache_get(__be32 dst_ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct mpoa_client *client)
35{
36 in_cache_entry *entry;
37
38 read_lock_bh(&client->ingress_lock);
39 entry = client->in_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +000040 while (entry != NULL) {
41 if (entry->ctrl_info.in_dst_ip == dst_ip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 atomic_inc(&entry->use);
43 read_unlock_bh(&client->ingress_lock);
44 return entry;
45 }
46 entry = entry->next;
47 }
48 read_unlock_bh(&client->ingress_lock);
49
50 return NULL;
51}
52
Al Viro30d492d2006-11-14 21:11:29 -080053static in_cache_entry *in_cache_get_with_mask(__be32 dst_ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 struct mpoa_client *client,
Al Viro30d492d2006-11-14 21:11:29 -080055 __be32 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 in_cache_entry *entry;
58
59 read_lock_bh(&client->ingress_lock);
60 entry = client->in_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +000061 while (entry != NULL) {
62 if ((entry->ctrl_info.in_dst_ip & mask) == (dst_ip & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 atomic_inc(&entry->use);
64 read_unlock_bh(&client->ingress_lock);
65 return entry;
66 }
67 entry = entry->next;
68 }
69 read_unlock_bh(&client->ingress_lock);
70
71 return NULL;
72
73}
74
75static in_cache_entry *in_cache_get_by_vcc(struct atm_vcc *vcc,
Joe Perchesbee67d32010-01-26 11:40:10 +000076 struct mpoa_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 in_cache_entry *entry;
79
80 read_lock_bh(&client->ingress_lock);
81 entry = client->in_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +000082 while (entry != NULL) {
83 if (entry->shortcut == vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 atomic_inc(&entry->use);
85 read_unlock_bh(&client->ingress_lock);
86 return entry;
87 }
88 entry = entry->next;
89 }
90 read_unlock_bh(&client->ingress_lock);
91
92 return NULL;
93}
94
Al Viro30d492d2006-11-14 21:11:29 -080095static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 struct mpoa_client *client)
97{
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -020098 in_cache_entry *entry = kzalloc(sizeof(in_cache_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 if (entry == NULL) {
Joe Perchesbee67d32010-01-26 11:40:10 +0000101 pr_info("mpoa: mpoa_caches.c: new_in_cache_entry: out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return NULL;
103 }
104
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000105 dprintk("adding an ingress entry, ip = %pI4\n", &dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 atomic_set(&entry->use, 1);
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000108 dprintk("new_in_cache_entry: about to lock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 write_lock_bh(&client->ingress_lock);
110 entry->next = client->in_cache;
111 entry->prev = NULL;
112 if (client->in_cache != NULL)
113 client->in_cache->prev = entry;
114 client->in_cache = entry;
115
116 memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
117 entry->ctrl_info.in_dst_ip = dst_ip;
118 do_gettimeofday(&(entry->tv));
119 entry->retry_time = client->parameters.mpc_p4;
120 entry->count = 1;
121 entry->entry_state = INGRESS_INVALID;
122 entry->ctrl_info.holding_time = HOLDING_TIME_DEFAULT;
123 atomic_inc(&entry->use);
124
125 write_unlock_bh(&client->ingress_lock);
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000126 dprintk("new_in_cache_entry: unlocked\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 return entry;
129}
130
131static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
132{
133 struct atm_mpoa_qos *qos;
134 struct k_message msg;
135
136 entry->count++;
Joe Perchesbee67d32010-01-26 11:40:10 +0000137 if (entry->entry_state == INGRESS_RESOLVED && entry->shortcut != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return OPEN;
139
Joe Perchesbee67d32010-01-26 11:40:10 +0000140 if (entry->entry_state == INGRESS_REFRESHING) {
141 if (entry->count > mpc->parameters.mpc_p1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 msg.type = SND_MPOA_RES_RQST;
143 msg.content.in_info = entry->ctrl_info;
144 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN);
145 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
Joe Perchesbee67d32010-01-26 11:40:10 +0000146 if (qos != NULL)
147 msg.qos = qos->qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 msg_to_mpoad(&msg, mpc);
149 do_gettimeofday(&(entry->reply_wait));
150 entry->entry_state = INGRESS_RESOLVING;
151 }
Joe Perchesbee67d32010-01-26 11:40:10 +0000152 if (entry->shortcut != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return OPEN;
154 return CLOSED;
155 }
156
Joe Perchesbee67d32010-01-26 11:40:10 +0000157 if (entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return OPEN;
159
Joe Perchesbee67d32010-01-26 11:40:10 +0000160 if (entry->count > mpc->parameters.mpc_p1 &&
161 entry->entry_state == INGRESS_INVALID) {
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000162 dprintk("(%s) threshold exceeded for ip %pI4, sending MPOA res req\n",
Harvey Harrison21454aa2008-10-31 00:54:56 -0700163 mpc->dev->name, &entry->ctrl_info.in_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 entry->entry_state = INGRESS_RESOLVING;
Joe Perchesbee67d32010-01-26 11:40:10 +0000165 msg.type = SND_MPOA_RES_RQST;
166 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 msg.content.in_info = entry->ctrl_info;
168 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
Joe Perchesbee67d32010-01-26 11:40:10 +0000169 if (qos != NULL)
170 msg.qos = qos->qos;
171 msg_to_mpoad(&msg, mpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 do_gettimeofday(&(entry->reply_wait));
173 }
174
175 return CLOSED;
176}
177
178static void in_cache_put(in_cache_entry *entry)
179{
180 if (atomic_dec_and_test(&entry->use)) {
181 memset(entry, 0, sizeof(in_cache_entry));
182 kfree(entry);
183 }
184
185 return;
186}
187
188/*
189 * This should be called with write lock on
190 */
191static void in_cache_remove_entry(in_cache_entry *entry,
192 struct mpoa_client *client)
193{
194 struct atm_vcc *vcc;
195 struct k_message msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 vcc = entry->shortcut;
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000198 dprintk("removing an ingress entry, ip = %pI4\n",
Harvey Harrison21454aa2008-10-31 00:54:56 -0700199 &entry->ctrl_info.in_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (entry->prev != NULL)
202 entry->prev->next = entry->next;
203 else
204 client->in_cache = entry->next;
205 if (entry->next != NULL)
206 entry->next->prev = entry->prev;
207 client->in_ops->put(entry);
Joe Perchesbee67d32010-01-26 11:40:10 +0000208 if (client->in_cache == NULL && client->eg_cache == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 msg.type = STOP_KEEP_ALIVE_SM;
Joe Perchesbee67d32010-01-26 11:40:10 +0000210 msg_to_mpoad(&msg, client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
213 /* Check if the egress side still uses this VCC */
214 if (vcc != NULL) {
Joe Perchesbee67d32010-01-26 11:40:10 +0000215 eg_cache_entry *eg_entry = client->eg_ops->get_by_vcc(vcc,
216 client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (eg_entry != NULL) {
218 client->eg_ops->put(eg_entry);
219 return;
220 }
221 vcc_release_async(vcc, -EPIPE);
222 }
223
224 return;
225}
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/* Call this every MPC-p2 seconds... Not exactly correct solution,
228 but an easy one... */
229static void clear_count_and_expired(struct mpoa_client *client)
230{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 in_cache_entry *entry, *next_entry;
232 struct timeval now;
233
234 do_gettimeofday(&now);
235
236 write_lock_bh(&client->ingress_lock);
237 entry = client->in_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000238 while (entry != NULL) {
239 entry->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 next_entry = entry->next;
Joe Perchesbee67d32010-01-26 11:40:10 +0000241 if ((now.tv_sec - entry->tv.tv_sec)
242 > entry->ctrl_info.holding_time) {
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000243 dprintk("holding time expired, ip = %pI4\n",
Harvey Harrison21454aa2008-10-31 00:54:56 -0700244 &entry->ctrl_info.in_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 client->in_ops->remove_entry(entry, client);
246 }
247 entry = next_entry;
248 }
249 write_unlock_bh(&client->ingress_lock);
250
251 return;
252}
253
254/* Call this every MPC-p4 seconds. */
255static void check_resolving_entries(struct mpoa_client *client)
256{
257
258 struct atm_mpoa_qos *qos;
259 in_cache_entry *entry;
260 struct timeval now;
261 struct k_message msg;
262
Joe Perchesbee67d32010-01-26 11:40:10 +0000263 do_gettimeofday(&now);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 read_lock_bh(&client->ingress_lock);
266 entry = client->in_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000267 while (entry != NULL) {
268 if (entry->entry_state == INGRESS_RESOLVING) {
269 if ((now.tv_sec - entry->hold_down.tv_sec) <
270 client->parameters.mpc_p6) {
271 entry = entry->next; /* Entry in hold down */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 continue;
273 }
Joe Perchesbee67d32010-01-26 11:40:10 +0000274 if ((now.tv_sec - entry->reply_wait.tv_sec) >
275 entry->retry_time) {
276 entry->retry_time = MPC_C1 * (entry->retry_time);
277 /*
278 * Retry time maximum exceeded,
279 * put entry in hold down.
280 */
281 if (entry->retry_time > client->parameters.mpc_p5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 do_gettimeofday(&(entry->hold_down));
283 entry->retry_time = client->parameters.mpc_p4;
284 entry = entry->next;
285 continue;
286 }
287 /* Ask daemon to send a resolution request. */
Joe Perchesbee67d32010-01-26 11:40:10 +0000288 memset(&(entry->hold_down), 0, sizeof(struct timeval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 msg.type = SND_MPOA_RES_RTRY;
290 memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN);
291 msg.content.in_info = entry->ctrl_info;
292 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
Joe Perchesbee67d32010-01-26 11:40:10 +0000293 if (qos != NULL)
294 msg.qos = qos->qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 msg_to_mpoad(&msg, client);
296 do_gettimeofday(&(entry->reply_wait));
297 }
298 }
299 entry = entry->next;
300 }
301 read_unlock_bh(&client->ingress_lock);
302}
303
304/* Call this every MPC-p5 seconds. */
305static void refresh_entries(struct mpoa_client *client)
306{
307 struct timeval now;
308 struct in_cache_entry *entry = client->in_cache;
309
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000310 ddprintk("refresh_entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 do_gettimeofday(&now);
312
313 read_lock_bh(&client->ingress_lock);
Joe Perchesbee67d32010-01-26 11:40:10 +0000314 while (entry != NULL) {
315 if (entry->entry_state == INGRESS_RESOLVED) {
316 if (!(entry->refresh_time))
317 entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3;
318 if ((now.tv_sec - entry->reply_wait.tv_sec) >
319 entry->refresh_time) {
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000320 dprintk("refreshing an entry.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 entry->entry_state = INGRESS_REFRESHING;
322
323 }
324 }
325 entry = entry->next;
326 }
327 read_unlock_bh(&client->ingress_lock);
328}
329
330static void in_destroy_cache(struct mpoa_client *mpc)
331{
332 write_lock_irq(&mpc->ingress_lock);
Joe Perchesbee67d32010-01-26 11:40:10 +0000333 while (mpc->in_cache != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 mpc->in_ops->remove_entry(mpc->in_cache, mpc);
335 write_unlock_irq(&mpc->ingress_lock);
336
337 return;
338}
339
Joe Perchesbee67d32010-01-26 11:40:10 +0000340static eg_cache_entry *eg_cache_get_by_cache_id(__be32 cache_id,
341 struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 eg_cache_entry *entry;
344
345 read_lock_irq(&mpc->egress_lock);
346 entry = mpc->eg_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000347 while (entry != NULL) {
348 if (entry->ctrl_info.cache_id == cache_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 atomic_inc(&entry->use);
350 read_unlock_irq(&mpc->egress_lock);
351 return entry;
352 }
353 entry = entry->next;
354 }
355 read_unlock_irq(&mpc->egress_lock);
356
357 return NULL;
358}
359
360/* This can be called from any context since it saves CPU flags */
Al Viro30d492d2006-11-14 21:11:29 -0800361static eg_cache_entry *eg_cache_get_by_tag(__be32 tag, struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 unsigned long flags;
364 eg_cache_entry *entry;
365
366 read_lock_irqsave(&mpc->egress_lock, flags);
367 entry = mpc->eg_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000368 while (entry != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (entry->ctrl_info.tag == tag) {
370 atomic_inc(&entry->use);
371 read_unlock_irqrestore(&mpc->egress_lock, flags);
372 return entry;
373 }
374 entry = entry->next;
375 }
376 read_unlock_irqrestore(&mpc->egress_lock, flags);
377
378 return NULL;
379}
380
381/* This can be called from any context since it saves CPU flags */
Joe Perchesbee67d32010-01-26 11:40:10 +0000382static eg_cache_entry *eg_cache_get_by_vcc(struct atm_vcc *vcc,
383 struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 unsigned long flags;
386 eg_cache_entry *entry;
387
388 read_lock_irqsave(&mpc->egress_lock, flags);
389 entry = mpc->eg_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000390 while (entry != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (entry->shortcut == vcc) {
392 atomic_inc(&entry->use);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900393 read_unlock_irqrestore(&mpc->egress_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return entry;
395 }
396 entry = entry->next;
397 }
398 read_unlock_irqrestore(&mpc->egress_lock, flags);
399
400 return NULL;
401}
402
Joe Perchesbee67d32010-01-26 11:40:10 +0000403static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,
404 struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
406 eg_cache_entry *entry;
407
408 read_lock_irq(&mpc->egress_lock);
409 entry = mpc->eg_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000410 while (entry != NULL) {
411 if (entry->latest_ip_addr == ipaddr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 atomic_inc(&entry->use);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900413 read_unlock_irq(&mpc->egress_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 return entry;
415 }
416 entry = entry->next;
417 }
418 read_unlock_irq(&mpc->egress_lock);
419
420 return NULL;
421}
422
423static void eg_cache_put(eg_cache_entry *entry)
424{
425 if (atomic_dec_and_test(&entry->use)) {
426 memset(entry, 0, sizeof(eg_cache_entry));
427 kfree(entry);
428 }
429
430 return;
431}
432
433/*
434 * This should be called with write lock on
435 */
436static void eg_cache_remove_entry(eg_cache_entry *entry,
437 struct mpoa_client *client)
438{
439 struct atm_vcc *vcc;
440 struct k_message msg;
441
442 vcc = entry->shortcut;
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000443 dprintk("removing an egress entry.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (entry->prev != NULL)
445 entry->prev->next = entry->next;
446 else
447 client->eg_cache = entry->next;
448 if (entry->next != NULL)
449 entry->next->prev = entry->prev;
450 client->eg_ops->put(entry);
Joe Perchesbee67d32010-01-26 11:40:10 +0000451 if (client->in_cache == NULL && client->eg_cache == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 msg.type = STOP_KEEP_ALIVE_SM;
Joe Perchesbee67d32010-01-26 11:40:10 +0000453 msg_to_mpoad(&msg, client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 /* Check if the ingress side still uses this VCC */
457 if (vcc != NULL) {
458 in_cache_entry *in_entry = client->in_ops->get_by_vcc(vcc, client);
459 if (in_entry != NULL) {
460 client->in_ops->put(in_entry);
461 return;
462 }
463 vcc_release_async(vcc, -EPIPE);
464 }
465
466 return;
467}
468
Joe Perchesbee67d32010-01-26 11:40:10 +0000469static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
470 struct mpoa_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -0200472 eg_cache_entry *entry = kzalloc(sizeof(eg_cache_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 if (entry == NULL) {
Joe Perchesbee67d32010-01-26 11:40:10 +0000475 pr_info("out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return NULL;
477 }
478
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000479 dprintk("adding an egress entry, ip = %pI4, this should be our IP\n",
Harvey Harrison21454aa2008-10-31 00:54:56 -0700480 &msg->content.eg_info.eg_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 atomic_set(&entry->use, 1);
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000483 dprintk("new_eg_cache_entry: about to lock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 write_lock_irq(&client->egress_lock);
485 entry->next = client->eg_cache;
486 entry->prev = NULL;
487 if (client->eg_cache != NULL)
488 client->eg_cache->prev = entry;
489 client->eg_cache = entry;
490
491 memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
492 entry->ctrl_info = msg->content.eg_info;
493 do_gettimeofday(&(entry->tv));
494 entry->entry_state = EGRESS_RESOLVED;
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000495 dprintk("new_eg_cache_entry cache_id %u\n",
Joe Perchesbee67d32010-01-26 11:40:10 +0000496 ntohl(entry->ctrl_info.cache_id));
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000497 dprintk("mps_ip = %pI4\n", &entry->ctrl_info.mps_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 atomic_inc(&entry->use);
499
500 write_unlock_irq(&client->egress_lock);
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000501 dprintk("new_eg_cache_entry: unlocked\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 return entry;
504}
505
Joe Perchesbee67d32010-01-26 11:40:10 +0000506static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 do_gettimeofday(&(entry->tv));
509 entry->entry_state = EGRESS_RESOLVED;
510 entry->ctrl_info.holding_time = holding_time;
511
512 return;
513}
514
515static void clear_expired(struct mpoa_client *client)
516{
517 eg_cache_entry *entry, *next_entry;
518 struct timeval now;
519 struct k_message msg;
520
521 do_gettimeofday(&now);
522
523 write_lock_irq(&client->egress_lock);
524 entry = client->eg_cache;
Joe Perchesbee67d32010-01-26 11:40:10 +0000525 while (entry != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 next_entry = entry->next;
Joe Perchesbee67d32010-01-26 11:40:10 +0000527 if ((now.tv_sec - entry->tv.tv_sec)
528 > entry->ctrl_info.holding_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 msg.type = SND_EGRESS_PURGE;
530 msg.content.eg_info = entry->ctrl_info;
Joe Perchesb50c2ea2010-01-26 11:40:20 +0000531 dprintk("egress_cache: holding time expired, cache_id = %u.\n",
Joe Perchesbee67d32010-01-26 11:40:10 +0000532 ntohl(entry->ctrl_info.cache_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 msg_to_mpoad(&msg, client);
534 client->eg_ops->remove_entry(entry, client);
535 }
536 entry = next_entry;
537 }
538 write_unlock_irq(&client->egress_lock);
539
540 return;
541}
542
543static void eg_destroy_cache(struct mpoa_client *mpc)
544{
545 write_lock_irq(&mpc->egress_lock);
Joe Perchesbee67d32010-01-26 11:40:10 +0000546 while (mpc->eg_cache != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 mpc->eg_ops->remove_entry(mpc->eg_cache, mpc);
548 write_unlock_irq(&mpc->egress_lock);
549
550 return;
551}
552
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554static struct in_cache_ops ingress_ops = {
555 in_cache_add_entry, /* add_entry */
556 in_cache_get, /* get */
557 in_cache_get_with_mask, /* get_with_mask */
558 in_cache_get_by_vcc, /* get_by_vcc */
559 in_cache_put, /* put */
560 in_cache_remove_entry, /* remove_entry */
561 cache_hit, /* cache_hit */
562 clear_count_and_expired, /* clear_count */
563 check_resolving_entries, /* check_resolving */
564 refresh_entries, /* refresh */
565 in_destroy_cache /* destroy_cache */
566};
567
568static struct eg_cache_ops egress_ops = {
569 eg_cache_add_entry, /* add_entry */
570 eg_cache_get_by_cache_id, /* get_by_cache_id */
571 eg_cache_get_by_tag, /* get_by_tag */
572 eg_cache_get_by_vcc, /* get_by_vcc */
573 eg_cache_get_by_src_ip, /* get_by_src_ip */
574 eg_cache_put, /* put */
575 eg_cache_remove_entry, /* remove_entry */
576 update_eg_cache_entry, /* update */
577 clear_expired, /* clear_expired */
578 eg_destroy_cache /* destroy_cache */
579};
580
581
582void atm_mpoa_init_cache(struct mpoa_client *mpc)
583{
584 mpc->in_ops = &ingress_ops;
585 mpc->eg_ops = &egress_ops;
586
587 return;
588}