+- add patches.fixes/linux-post-2.6.3-20040220
[linux-flexiantxendom0-3.2.10.git] / net / atm / lec.c
1 /*
2  * lec.c: Lan Emulation driver 
3  * Marko Kiiskila carnil@cs.tut.fi
4  *
5  */
6
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/bitops.h>
10
11 /* We are ethernet device */
12 #include <linux/if_ether.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <net/sock.h>
16 #include <linux/skbuff.h>
17 #include <linux/ip.h>
18 #include <asm/byteorder.h>
19 #include <asm/uaccess.h>
20 #include <net/arp.h>
21 #include <net/dst.h>
22 #include <linux/proc_fs.h>
23 #include <linux/spinlock.h>
24 #include <linux/proc_fs.h>
25 #include <linux/seq_file.h>
26
27 /* TokenRing if needed */
28 #ifdef CONFIG_TR
29 #include <linux/trdevice.h>
30 #endif
31
32 /* And atm device */
33 #include <linux/atmdev.h>
34 #include <linux/atmlec.h>
35
36 /* Proxy LEC knows about bridging */
37 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38 #include <linux/if_bridge.h>
39 #include "../bridge/br_private.h"
40 static unsigned char bridge_ula_lec[] = {0x01, 0x80, 0xc2, 0x00, 0x00};
41
42 extern struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
43        unsigned char *addr);
44 extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
45 #endif
46
47 /* Modular too */
48 #include <linux/module.h>
49 #include <linux/init.h>
50
51 #include "lec.h"
52 #include "lec_arpc.h"
53 #include "resources.h"
54
55 #if 0
56 #define DPRINTK printk
57 #else
58 #define DPRINTK(format,args...)
59 #endif
60
61 #define DUMP_PACKETS 0 /* 0 = None,
62                         * 1 = 30 first bytes
63                         * 2 = Whole packet
64                         */
65
66 #define LEC_UNRES_QUE_LEN 8 /* number of tx packets to queue for a
67                                single destination while waiting for SVC */
68
69 static int lec_open(struct net_device *dev);
70 static int lec_send_packet(struct sk_buff *skb, struct net_device *dev);
71 static int lec_close(struct net_device *dev);
72 static struct net_device_stats *lec_get_stats(struct net_device *dev);
73 static void lec_init(struct net_device *dev);
74 static inline struct lec_arp_table* lec_arp_find(struct lec_priv *priv,
75                                                      unsigned char *mac_addr);
76 static inline int lec_arp_remove(struct lec_priv *priv,
77                                      struct lec_arp_table *to_remove);
78 /* LANE2 functions */
79 static void lane2_associate_ind (struct net_device *dev, u8 *mac_address,
80                           u8 *tlvs, u32 sizeoftlvs);
81 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
82                   u8 **tlvs, u32 *sizeoftlvs);
83 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
84                          u8 *tlvs, u32 sizeoftlvs);
85
86 static struct lane2_ops lane2_ops = {
87         lane2_resolve,         /* resolve,             spec 3.1.3 */
88         lane2_associate_req,   /* associate_req,       spec 3.1.4 */
89         NULL                  /* associate indicator, spec 3.1.5 */
90 };
91
92 static unsigned char bus_mac[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
93
94 /* Device structures */
95 static struct net_device *dev_lec[MAX_LEC_ITF];
96
97 /* This will be called from proc.c via function pointer */
98 struct net_device *get_dev_lec(int itf)
99 {
100         struct net_device *dev;
101
102         if (itf >= MAX_LEC_ITF)
103                 return NULL;
104         rtnl_lock();
105         dev = dev_lec[itf];
106         if (dev)
107                 dev_hold(dev);
108         rtnl_unlock();
109         return dev;
110 }
111
112 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
113 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
114 {
115         struct ethhdr *eth;
116         char *buff;
117         struct lec_priv *priv;
118
119         /* Check if this is a BPDU. If so, ask zeppelin to send
120          * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
121          * as the Config BPDU has */
122         eth = (struct ethhdr *)skb->data;
123         buff = skb->data + skb->dev->hard_header_len;
124         if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
125                 struct sk_buff *skb2;
126                 struct atmlec_msg *mesg;
127
128                 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
129                 if (skb2 == NULL) return;
130                 skb2->len = sizeof(struct atmlec_msg);
131                 mesg = (struct atmlec_msg *)skb2->data;
132                 mesg->type = l_topology_change;
133                 buff += 4;
134                 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
135
136                 priv = (struct lec_priv *)dev->priv;
137                 atm_force_charge(priv->lecd, skb2->truesize);
138                 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb2);
139                 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb2->len);
140         }
141
142         return;
143 }
144 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
145
146 /*
147  * Modelled after tr_type_trans
148  * All multicast and ARE or STE frames go to BUS.
149  * Non source routed frames go by destination address.
150  * Last hop source routed frames go by destination address.
151  * Not last hop source routed frames go by _next_ route descriptor.
152  * Returns pointer to destination MAC address or fills in rdesc
153  * and returns NULL.
154  */
155 #ifdef CONFIG_TR
156 unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
157 {
158         struct trh_hdr *trh;
159         int riflen, num_rdsc;
160         
161         trh = (struct trh_hdr *)packet;
162         if (trh->daddr[0] & (uint8_t)0x80)
163                 return bus_mac; /* multicast */
164
165         if (trh->saddr[0] & TR_RII) {
166                 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
167                 if ((ntohs(trh->rcf) >> 13) != 0)
168                         return bus_mac; /* ARE or STE */
169         }
170         else
171                 return trh->daddr; /* not source routed */
172
173         if (riflen < 6)
174                 return trh->daddr; /* last hop, source routed */
175                 
176         /* riflen is 6 or more, packet has more than one route descriptor */
177         num_rdsc = (riflen/2) - 1;
178         memset(rdesc, 0, ETH_ALEN);
179         /* offset 4 comes from LAN destination field in LE control frames */
180         if (trh->rcf & htons((uint16_t)TR_RCF_DIR_BIT))
181                 memcpy(&rdesc[4], &trh->rseg[num_rdsc-2], sizeof(uint16_t));
182         else {
183                 memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
184                 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
185         }
186
187         return NULL;
188 }
189 #endif /* CONFIG_TR */
190
191 /*
192  * Open/initialize the netdevice. This is called (in the current kernel)
193  * sometime after booting when the 'ifconfig' program is run.
194  *
195  * This routine should set everything up anew at each open, even
196  * registers that "should" only need to be set once at boot, so that
197  * there is non-reboot way to recover if something goes wrong.
198  */
199
200 static int 
201 lec_open(struct net_device *dev)
202 {
203         struct lec_priv *priv = (struct lec_priv *)dev->priv;
204         
205         netif_start_queue(dev);
206         memset(&priv->stats,0,sizeof(struct net_device_stats));
207         
208         return 0;
209 }
210
211 static __inline__ void
212 lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
213 {
214         if (atm_may_send(vcc, skb->len)) {
215                 atomic_add(skb->truesize, &vcc->sk->sk_wmem_alloc);
216                 ATM_SKB(skb)->vcc = vcc;
217                 ATM_SKB(skb)->atm_options = vcc->atm_options;
218                 priv->stats.tx_packets++;
219                 priv->stats.tx_bytes += skb->len;
220                 vcc->send(vcc, skb);
221         } else {
222                 priv->stats.tx_dropped++;
223                 dev_kfree_skb(skb);
224         }
225 }
226
227 static int 
228 lec_send_packet(struct sk_buff *skb, struct net_device *dev)
229 {
230         struct sk_buff *skb2;
231         struct lec_priv *priv = (struct lec_priv *)dev->priv;
232         struct lecdatahdr_8023 *lec_h;
233         struct atm_vcc *send_vcc;
234         struct lec_arp_table *entry;
235         unsigned char *dst;
236         int min_frame_size;
237 #ifdef CONFIG_TR
238         unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
239 #endif
240         int is_rdesc;
241 #if DUMP_PACKETS > 0
242         char buf[300];
243         int i=0;
244 #endif /* DUMP_PACKETS >0 */
245         
246         DPRINTK("Lec_send_packet called\n");  
247         if (!priv->lecd) {
248                 printk("%s:No lecd attached\n",dev->name);
249                 priv->stats.tx_errors++;
250                 netif_stop_queue(dev);
251                 return -EUNATCH;
252         } 
253
254         DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
255                 (long)skb->head, (long)skb->data, (long)skb->tail,
256                 (long)skb->end);
257 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
258         if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
259                 lec_handle_bridge(skb, dev);
260 #endif
261
262         /* Make sure we have room for lec_id */
263         if (skb_headroom(skb) < 2) {
264
265                 DPRINTK("lec_send_packet: reallocating skb\n");
266                 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
267                 kfree_skb(skb);
268                 if (skb2 == NULL) return 0;
269                 skb = skb2;
270         }
271         skb_push(skb, 2);
272
273         /* Put le header to place, works for TokenRing too */
274         lec_h = (struct lecdatahdr_8023*)skb->data;
275         lec_h->le_header = htons(priv->lecid); 
276
277 #ifdef CONFIG_TR
278         /* Ugly. Use this to realign Token Ring packets for
279          * e.g. PCA-200E driver. */
280         if (priv->is_trdev) {
281                 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
282                 kfree_skb(skb);
283                 if (skb2 == NULL) return 0;
284                 skb = skb2;
285         }
286 #endif
287
288 #if DUMP_PACKETS > 0
289         printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
290                skb->len, priv->lecid);
291 #if DUMP_PACKETS >= 2
292         for(i=0;i<skb->len && i <99;i++) {
293                 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
294         }
295 #elif DUMP_PACKETS >= 1
296         for(i=0;i<skb->len && i < 30;i++) {
297                 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
298         }
299 #endif /* DUMP_PACKETS >= 1 */
300         if (i==skb->len)
301                 printk("%s\n",buf);
302         else
303                 printk("%s...\n",buf);
304 #endif /* DUMP_PACKETS > 0 */
305
306         /* Minimum ethernet-frame size */
307 #ifdef CONFIG_TR
308         if (priv->is_trdev)
309                 min_frame_size = LEC_MINIMUM_8025_SIZE;
310         else
311 #endif
312         min_frame_size = LEC_MINIMUM_8023_SIZE;
313         if (skb->len < min_frame_size) {
314                 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
315                         skb2 = skb_copy_expand(skb, 0,
316                             min_frame_size - skb->truesize, GFP_ATOMIC);
317                                 dev_kfree_skb(skb);
318                         if (skb2 == NULL) {
319                                 priv->stats.tx_dropped++;
320                                 return 0;
321                         }
322                         skb = skb2;
323                 }
324                 skb_put(skb, min_frame_size - skb->len);
325         }
326         
327         /* Send to right vcc */
328         is_rdesc = 0;
329         dst = lec_h->h_dest;
330 #ifdef CONFIG_TR
331         if (priv->is_trdev) {
332                 dst = get_tr_dst(skb->data+2, rdesc);
333                 if (dst == NULL) {
334                         dst = rdesc;
335                         is_rdesc = 1;
336                 }
337         }
338 #endif
339         entry = NULL;
340         send_vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
341         DPRINTK("%s:send_vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
342                 send_vcc, send_vcc?send_vcc->flags:0, entry);
343         if (!send_vcc || !test_bit(ATM_VF_READY,&send_vcc->flags)) {    
344                 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
345                         DPRINTK("%s:lec_send_packet: queuing packet, ", dev->name);
346                         DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
347                                 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
348                                 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
349                         skb_queue_tail(&entry->tx_wait, skb);
350                 } else {
351                         DPRINTK("%s:lec_send_packet: tx queue full or no arp entry, dropping, ", dev->name);
352                         DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
353                                 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
354                                 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
355                         priv->stats.tx_dropped++;
356                         dev_kfree_skb(skb);
357                 }
358                 return 0;
359         }
360                 
361 #if DUMP_PACKETS > 0                    
362         printk("%s:sending to vpi:%d vci:%d\n", dev->name,
363                send_vcc->vpi, send_vcc->vci);       
364 #endif /* DUMP_PACKETS > 0 */
365                 
366         while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
367                 DPRINTK("lec.c: emptying tx queue, ");
368                 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
369                         lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
370                         lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
371                 lec_send(send_vcc, skb2, priv);
372         }
373
374         lec_send(send_vcc, skb, priv);
375
376 #if 0
377         /* Should we wait for card's device driver to notify us? */
378         dev->tbusy=0;
379 #endif        
380         return 0;
381 }
382
383 /* The inverse routine to net_open(). */
384 static int 
385 lec_close(struct net_device *dev) 
386 {
387         netif_stop_queue(dev);
388         return 0;
389 }
390
391 /*
392  * Get the current statistics.
393  * This may be called with the card open or closed.
394  */
395 static struct net_device_stats *
396 lec_get_stats(struct net_device *dev)
397 {
398         return &((struct lec_priv *)dev->priv)->stats;
399 }
400
401 static int 
402 lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
403 {
404         struct net_device *dev = (struct net_device*)vcc->proto_data;
405         struct lec_priv *priv = (struct lec_priv*)dev->priv;
406         struct atmlec_msg *mesg;
407         struct lec_arp_table *entry;
408         int i;
409         char *tmp; /* FIXME */
410
411         atomic_sub(skb->truesize, &vcc->sk->sk_wmem_alloc);
412         mesg = (struct atmlec_msg *)skb->data;
413         tmp = skb->data;
414         tmp += sizeof(struct atmlec_msg);
415         DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
416         switch(mesg->type) {
417         case l_set_mac_addr:
418                 for (i=0;i<6;i++) {
419                         dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
420                 }    
421                 break;
422         case l_del_mac_addr:
423                 for(i=0;i<6;i++) {
424                         dev->dev_addr[i] = 0;
425                 }
426                 break;
427         case l_addr_delete:
428                 lec_addr_delete(priv, mesg->content.normal.atm_addr, 
429                                 mesg->content.normal.flag);
430                 break;
431         case l_topology_change:
432                 priv->topology_change = mesg->content.normal.flag;  
433                 break;
434         case l_flush_complete:
435                 lec_flush_complete(priv, mesg->content.normal.flag);
436                 break;
437         case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
438                 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
439                 lec_arp_remove(priv, entry);
440
441                 if (mesg->content.normal.no_source_le_narp)
442                         break;
443                 /* FALL THROUGH */
444         case l_arp_update:
445                 lec_arp_update(priv, mesg->content.normal.mac_addr,
446                                mesg->content.normal.atm_addr,
447                                mesg->content.normal.flag,
448                                mesg->content.normal.targetless_le_arp);
449                 DPRINTK("lec: in l_arp_update\n");
450                 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
451                         DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n", mesg->sizeoftlvs);
452                         lane2_associate_ind(dev,
453                                             mesg->content.normal.mac_addr,
454                                             tmp, mesg->sizeoftlvs);
455                 }
456                 break;
457         case l_config:
458                 priv->maximum_unknown_frame_count = 
459                         mesg->content.config.maximum_unknown_frame_count;
460                 priv->max_unknown_frame_time = 
461                         (mesg->content.config.max_unknown_frame_time*HZ);
462                 priv->max_retry_count = 
463                         mesg->content.config.max_retry_count;
464                 priv->aging_time = (mesg->content.config.aging_time*HZ);
465                 priv->forward_delay_time = 
466                         (mesg->content.config.forward_delay_time*HZ);
467                 priv->arp_response_time = 
468                         (mesg->content.config.arp_response_time*HZ);
469                 priv->flush_timeout = (mesg->content.config.flush_timeout*HZ);
470                 priv->path_switching_delay = 
471                         (mesg->content.config.path_switching_delay*HZ);
472                 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
473                 priv->lane2_ops = NULL;
474                 if (priv->lane_version > 1)
475                         priv->lane2_ops = &lane2_ops;
476                 if (dev->change_mtu(dev, mesg->content.config.mtu))
477                         printk("%s: change_mtu to %d failed\n", dev->name,
478                             mesg->content.config.mtu);
479                 priv->is_proxy = mesg->content.config.is_proxy;
480                 break;
481         case l_flush_tran_id:
482                 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
483                                       mesg->content.normal.flag);
484                 break;
485         case l_set_lecid:
486                 priv->lecid=(unsigned short)(0xffff&mesg->content.normal.flag);
487                 break;
488         case l_should_bridge: {
489 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
490                 struct net_bridge_fdb_entry *f;
491
492                 DPRINTK("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
493                         dev->name,
494                         mesg->content.proxy.mac_addr[0], mesg->content.proxy.mac_addr[1],
495                         mesg->content.proxy.mac_addr[2], mesg->content.proxy.mac_addr[3],
496                         mesg->content.proxy.mac_addr[4], mesg->content.proxy.mac_addr[5]);
497
498                 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
499                         break;
500
501                 f = br_fdb_get_hook(dev->br_port->br, mesg->content.proxy.mac_addr);
502                 if (f != NULL &&
503                     f->dst->dev != dev &&
504                     f->dst->state == BR_STATE_FORWARDING) {
505                                 /* hit from bridge table, send LE_ARP_RESPONSE */
506                         struct sk_buff *skb2;
507
508                         DPRINTK("%s: entry found, responding to zeppelin\n", dev->name);
509                         skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
510                         if (skb2 == NULL) {
511                                 br_fdb_put_hook(f);
512                                 break;
513                         }
514                         skb2->len = sizeof(struct atmlec_msg);
515                         memcpy(skb2->data, mesg, sizeof(struct atmlec_msg));
516                         atm_force_charge(priv->lecd, skb2->truesize);
517                         skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb2);
518                         priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb2->len);
519                 }
520                 if (f != NULL) br_fdb_put_hook(f);
521 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
522                 }
523                 break;
524         default:
525                 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
526                 dev_kfree_skb(skb);
527                 return -EINVAL;
528         }
529         dev_kfree_skb(skb);
530         return 0;
531 }
532
533 static void 
534 lec_atm_close(struct atm_vcc *vcc)
535 {
536         struct sk_buff *skb;
537         struct net_device *dev = (struct net_device *)vcc->proto_data;
538         struct lec_priv *priv = (struct lec_priv *)dev->priv;
539
540         priv->lecd = NULL;
541         /* Do something needful? */
542
543         netif_stop_queue(dev);
544         lec_arp_destroy(priv);
545
546         if (skb_peek(&vcc->sk->sk_receive_queue))
547                 printk("%s lec_atm_close: closing with messages pending\n",
548                        dev->name);
549         while ((skb = skb_dequeue(&vcc->sk->sk_receive_queue))) {
550                 atm_return(vcc, skb->truesize);
551                 dev_kfree_skb(skb);
552         }
553   
554         printk("%s: Shut down!\n", dev->name);
555         module_put(THIS_MODULE);
556 }
557
558 static struct atmdev_ops lecdev_ops = {
559         .close  = lec_atm_close,
560         .send   = lec_atm_send
561 };
562
563 static struct atm_dev lecatm_dev = {
564         .ops    = &lecdev_ops,
565         .type   = "lec",
566         .number = 999,  /* dummy device number */
567         .lock   = SPIN_LOCK_UNLOCKED
568 };
569
570 /*
571  * LANE2: new argument struct sk_buff *data contains
572  * the LE_ARP based TLVs introduced in the LANE2 spec
573  */
574 int 
575 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type, 
576              unsigned char *mac_addr, unsigned char *atm_addr,
577              struct sk_buff *data)
578 {
579         struct sk_buff *skb;
580         struct atmlec_msg *mesg;
581
582         if (!priv || !priv->lecd) {
583                 return -1;
584         }
585         skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
586         if (!skb)
587                 return -1;
588         skb->len = sizeof(struct atmlec_msg);
589         mesg = (struct atmlec_msg *)skb->data;
590         memset(mesg, 0, sizeof(struct atmlec_msg));
591         mesg->type = type;
592         if (data != NULL)
593                 mesg->sizeoftlvs = data->len;
594         if (mac_addr)
595                 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
596         else
597                 mesg->content.normal.targetless_le_arp = 1;
598         if (atm_addr)
599                 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
600
601         atm_force_charge(priv->lecd, skb->truesize);
602         skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb);
603         priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
604
605         if (data != NULL) {
606                 DPRINTK("lec: about to send %d bytes of data\n", data->len);
607                 atm_force_charge(priv->lecd, data->truesize);
608                 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, data);
609                 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
610         }
611
612         return 0;
613 }
614
615 /* shamelessly stolen from drivers/net/net_init.c */
616 static int lec_change_mtu(struct net_device *dev, int new_mtu)
617 {
618         if ((new_mtu < 68) || (new_mtu > 18190))
619                 return -EINVAL;
620         dev->mtu = new_mtu;
621         return 0;
622 }
623
624 static void lec_set_multicast_list(struct net_device *dev)
625 {
626         /* by default, all multicast frames arrive over the bus.
627          * eventually support selective multicast service
628          */
629         return;
630 }
631
632 static void 
633 lec_init(struct net_device *dev)
634 {
635         dev->change_mtu = lec_change_mtu;
636         dev->open = lec_open;
637         dev->stop = lec_close;
638         dev->hard_start_xmit = lec_send_packet;
639
640         dev->get_stats = lec_get_stats;
641         dev->set_multicast_list = lec_set_multicast_list;
642         dev->do_ioctl  = NULL;
643         printk("%s: Initialized!\n",dev->name);
644         return;
645 }
646
647 static unsigned char lec_ctrl_magic[] = {
648         0xff,
649         0x00,
650         0x01,
651         0x01 };
652
653 void 
654 lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
655 {
656         struct net_device *dev = (struct net_device *)vcc->proto_data;
657         struct lec_priv *priv = (struct lec_priv *)dev->priv; 
658
659 #if DUMP_PACKETS >0
660         int i=0;
661         char buf[300];
662
663         printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
664                vcc->vpi, vcc->vci);
665 #endif
666         if (!skb) {
667                 DPRINTK("%s: null skb\n",dev->name);
668                 lec_vcc_close(priv, vcc);
669                 return;
670         }
671 #if DUMP_PACKETS > 0
672         printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
673                skb->len, priv->lecid);
674 #if DUMP_PACKETS >= 2
675         for(i=0;i<skb->len && i <99;i++) {
676                 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
677         }
678 #elif DUMP_PACKETS >= 1
679         for(i=0;i<skb->len && i < 30;i++) {
680                 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
681         }
682 #endif /* DUMP_PACKETS >= 1 */
683         if (i==skb->len)
684                 printk("%s\n",buf);
685         else
686                 printk("%s...\n",buf);
687 #endif /* DUMP_PACKETS > 0 */
688         if (memcmp(skb->data, lec_ctrl_magic, 4) ==0) { /* Control frame, to daemon*/
689                 DPRINTK("%s: To daemon\n",dev->name);
690                 skb_queue_tail(&vcc->sk->sk_receive_queue, skb);
691                 vcc->sk->sk_data_ready(vcc->sk, skb->len);
692         } else { /* Data frame, queue to protocol handlers */
693                 unsigned char *dst;
694
695                 atm_return(vcc,skb->truesize);
696                 if (*(uint16_t *)skb->data == htons(priv->lecid) ||
697                     !priv->lecd ||
698                     !(dev->flags & IFF_UP)) { 
699                         /* Probably looping back, or if lecd is missing,
700                            lecd has gone down */
701                         DPRINTK("Ignoring frame...\n");
702                         dev_kfree_skb(skb);
703                         return;
704                 }
705 #ifdef CONFIG_TR
706                 if (priv->is_trdev) dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
707                 else
708 #endif
709                 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
710
711                 if (!(dst[0]&0x01) &&   /* Never filter Multi/Broadcast */
712                     !priv->is_proxy &&  /* Proxy wants all the packets */
713                     memcmp(dst, dev->dev_addr, dev->addr_len)) {
714                         dev_kfree_skb(skb);
715                         return;
716                 }
717                 if (priv->lec_arp_empty_ones) {
718                         lec_arp_check_empties(priv, vcc, skb);
719                 }
720                 skb->dev = dev;
721                 skb_pull(skb, 2); /* skip lec_id */
722 #ifdef CONFIG_TR
723                 if (priv->is_trdev) skb->protocol = tr_type_trans(skb, dev);
724                 else
725 #endif
726                 skb->protocol = eth_type_trans(skb, dev);
727                 priv->stats.rx_packets++;
728                 priv->stats.rx_bytes += skb->len;
729                 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
730                 netif_rx(skb);
731         }
732 }
733
734 int 
735 lec_vcc_attach(struct atm_vcc *vcc, void *arg)
736 {
737         int bytes_left;
738         struct atmlec_ioc ioc_data;
739
740         /* Lecd must be up in this case */
741         bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
742         if (bytes_left != 0) {
743                 printk("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
744                        bytes_left);
745         }
746         if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF || 
747             !dev_lec[ioc_data.dev_num])
748                 return -EINVAL;
749         lec_vcc_added(dev_lec[ioc_data.dev_num]->priv, 
750                       &ioc_data, vcc, vcc->push);
751         vcc->push = lec_push;
752         vcc->proto_data = dev_lec[ioc_data.dev_num];
753         return 0;
754 }
755
756 int 
757 lec_mcast_attach(struct atm_vcc *vcc, int arg)
758 {
759         if (arg <0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
760                 return -EINVAL;
761         vcc->proto_data = dev_lec[arg];
762         return (lec_mcast_make((struct lec_priv*)dev_lec[arg]->priv, vcc));
763 }
764
765 /* Initialize device. */
766 int 
767 lecd_attach(struct atm_vcc *vcc, int arg)
768 {  
769         int i;
770         struct lec_priv *priv;
771
772         if (arg<0)
773                 i = 0;
774         else
775                 i = arg;
776 #ifdef CONFIG_TR
777         if (arg >= MAX_LEC_ITF)
778                 return -EINVAL;
779 #else /* Reserve the top NUM_TR_DEVS for TR */
780         if (arg >= (MAX_LEC_ITF-NUM_TR_DEVS))
781                 return -EINVAL;
782 #endif
783         if (!dev_lec[i]) {
784                 int is_trdev, size;
785
786                 is_trdev = 0;
787                 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
788                         is_trdev = 1;
789
790                 size = sizeof(struct lec_priv);
791 #ifdef CONFIG_TR
792                 if (is_trdev)
793                         dev_lec[i] = alloc_trdev(size);
794                 else
795 #endif
796                 dev_lec[i] = alloc_etherdev(size);
797                 if (!dev_lec[i])
798                         return -ENOMEM;
799                 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
800                 if (register_netdev(dev_lec[i])) {
801                         free_netdev(dev_lec[i]);
802                         return -EINVAL;
803                 }
804
805                 priv = dev_lec[i]->priv;
806                 priv->is_trdev = is_trdev;
807                 lec_init(dev_lec[i]);
808         } else {
809                 priv = dev_lec[i]->priv;
810                 if (priv->lecd)
811                         return -EADDRINUSE;
812         }
813         lec_arp_init(priv);
814         priv->itfnum = i;  /* LANE2 addition */
815         priv->lecd = vcc;
816         vcc->dev = &lecatm_dev;
817         vcc_insert_socket(vcc->sk);
818         
819         vcc->proto_data = dev_lec[i];
820         set_bit(ATM_VF_META,&vcc->flags);
821         set_bit(ATM_VF_READY,&vcc->flags);
822
823         /* Set default values to these variables */
824         priv->maximum_unknown_frame_count = 1;
825         priv->max_unknown_frame_time = (1*HZ);
826         priv->vcc_timeout_period = (1200*HZ);
827         priv->max_retry_count = 1;
828         priv->aging_time = (300*HZ);
829         priv->forward_delay_time = (15*HZ);
830         priv->topology_change = 0;
831         priv->arp_response_time = (1*HZ);
832         priv->flush_timeout = (4*HZ);
833         priv->path_switching_delay = (6*HZ);
834
835         if (dev_lec[i]->flags & IFF_UP) {
836                 netif_start_queue(dev_lec[i]);
837         }
838         __module_get(THIS_MODULE);
839         return i;
840 }
841
842 #ifdef CONFIG_PROC_FS
843 static char* lec_arp_get_status_string(unsigned char status)
844 {
845         static char *lec_arp_status_string[] = {
846                 "ESI_UNKNOWN       ",
847                 "ESI_ARP_PENDING   ",
848                 "ESI_VC_PENDING    ",
849                 "<Undefined>       ",
850                 "ESI_FLUSH_PENDING ",
851                 "ESI_FORWARD_DIRECT"
852         };
853
854         if (status > ESI_FORWARD_DIRECT)
855                 status = 3;     /* ESI_UNDEFINED */
856         return lec_arp_status_string[status];
857 }
858
859 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
860 {
861         int i;
862
863         for (i = 0; i < ETH_ALEN; i++)
864                 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
865         seq_printf(seq, " ");
866         for (i = 0; i < ATM_ESA_LEN; i++)
867                 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
868         seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
869                    entry->flags & 0xffff);
870         if (entry->vcc)
871                 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
872         else
873                 seq_printf(seq, "        ");
874         if (entry->recv_vcc) {
875                 seq_printf(seq, "     %3d %3d", entry->recv_vcc->vpi,
876                            entry->recv_vcc->vci);
877         }
878         seq_putc(seq, '\n');
879 }
880
881
882 struct lec_state {
883         unsigned long flags;
884         struct lec_priv *locked;
885         struct lec_arp_table *entry;
886         struct net_device *dev;
887         int itf;
888         int arp_table;
889         int misc_table;
890 };
891
892 static void *lec_tbl_walk(struct lec_state *state, struct lec_arp_table *tbl,
893                           loff_t *l)
894 {
895         struct lec_arp_table *e = state->entry;
896
897         if (!e)
898                 e = tbl;
899         if (e == (void *)1) {
900                 e = tbl;
901                 --*l;
902         }
903         for (; e; e = e->next) {
904                 if (--*l < 0)
905                         break;
906         }
907         state->entry = e;
908         return (*l < 0) ? state : NULL;
909 }
910
911 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
912                               struct lec_priv *priv)
913 {
914         void *v = NULL;
915         int p;
916
917         for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
918                 v = lec_tbl_walk(state, priv->lec_arp_tables[p], l);
919                 if (v)
920                         break;
921         }
922         state->arp_table = p;
923         return v;
924 }
925
926 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
927                            struct lec_priv *priv)
928 {
929         struct lec_arp_table *lec_misc_tables[] = {
930                 priv->lec_arp_empty_ones,
931                 priv->lec_no_forward,
932                 priv->mcast_fwds
933         };
934         void *v = NULL;
935         int q;
936
937         for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
938                 v = lec_tbl_walk(state, lec_misc_tables[q], l);
939                 if (v)
940                         break;
941         }
942         state->misc_table = q;
943         return v;
944 }
945
946 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
947                            struct lec_priv *priv)
948 {
949         if (!state->locked) {
950                 state->locked = priv;
951                 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
952         }
953         if (!lec_arp_walk(state, l, priv) &&
954             !lec_misc_walk(state, l, priv)) {
955                 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
956                 state->locked = NULL;
957                 /* Partial state reset for the next time we get called */
958                 state->arp_table = state->misc_table = 0;
959         }
960         return state->locked;
961 }
962
963 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
964 {
965         struct net_device *dev;
966         void *v;
967
968         dev = state->dev ? state->dev : dev_lec[state->itf];
969         v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
970         if (!v && dev) {
971                 dev_put(dev);
972                 /* Partial state reset for the next time we get called */
973                 dev = NULL;
974         }
975         state->dev = dev;
976         return v;
977 }
978
979 static void *lec_get_idx(struct lec_state *state, loff_t l)
980 {
981         void *v = NULL;
982
983         for (; state->itf < MAX_LEC_ITF; state->itf++) {
984                 v = lec_itf_walk(state, &l);
985                 if (v)
986                         break;
987         }
988         return v; 
989 }
990
991 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
992 {
993         struct lec_state *state = seq->private;
994
995         state->itf = 0;
996         state->dev = NULL;
997         state->locked = NULL;
998         state->arp_table = 0;
999         state->misc_table = 0;
1000         state->entry = (void *)1;
1001
1002         return *pos ? lec_get_idx(state, *pos) : (void*)1;
1003 }
1004
1005 static void lec_seq_stop(struct seq_file *seq, void *v)
1006 {
1007         struct lec_state *state = seq->private;
1008
1009         if (state->dev) {
1010                 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1011                                        state->flags);
1012                 dev_put(state->dev);
1013         }
1014 }
1015
1016 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1017 {
1018         struct lec_state *state = seq->private;
1019
1020         v = lec_get_idx(state, 1);
1021         *pos += !!PTR_ERR(v);
1022         return v;
1023 }
1024
1025 static int lec_seq_show(struct seq_file *seq, void *v)
1026 {
1027         static char lec_banner[] = "Itf  MAC          ATM destination" 
1028                 "                          Status            Flags "
1029                 "VPI/VCI Recv VPI/VCI\n";
1030
1031         if (v == (void *)1)
1032                 seq_puts(seq, lec_banner);
1033         else {
1034                 struct lec_state *state = seq->private;
1035                 struct net_device *dev = state->dev; 
1036
1037                 seq_printf(seq, "%s ", dev->name);
1038                 lec_info(seq, state->entry);
1039         }
1040         return 0;
1041 }
1042
1043 static struct seq_operations lec_seq_ops = {
1044         .start  = lec_seq_start,
1045         .next   = lec_seq_next,
1046         .stop   = lec_seq_stop,
1047         .show   = lec_seq_show,
1048 };
1049
1050 static int lec_seq_open(struct inode *inode, struct file *file)
1051 {
1052         struct lec_state *state;
1053         struct seq_file *seq;
1054         int rc = -EAGAIN;
1055
1056         state = kmalloc(sizeof(*state), GFP_KERNEL);
1057         if (!state) {
1058                 rc = -ENOMEM;
1059                 goto out;
1060         }
1061
1062         rc = seq_open(file, &lec_seq_ops);
1063         if (rc)
1064                 goto out_kfree;
1065         seq = file->private_data;
1066         seq->private = state;
1067 out:
1068         return rc;
1069
1070 out_kfree:
1071         kfree(state);
1072         goto out;
1073 }
1074
1075 static int lec_seq_release(struct inode *inode, struct file *file)
1076 {
1077         return seq_release_private(inode, file);
1078 }
1079
1080 static struct file_operations lec_seq_fops = {
1081         .owner          = THIS_MODULE,
1082         .open           = lec_seq_open,
1083         .read           = seq_read,
1084         .llseek         = seq_lseek,
1085         .release        = lec_seq_release,
1086 };
1087 #endif
1088
1089 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1090 {
1091         struct atm_vcc *vcc = ATM_SD(sock);
1092         int err = 0;
1093         
1094         switch (cmd) {
1095                 case ATMLEC_CTRL: 
1096                 case ATMLEC_MCAST:
1097                 case ATMLEC_DATA:
1098                         if (!capable(CAP_NET_ADMIN))
1099                                 return -EPERM;
1100                         break;
1101                 default:
1102                         return -ENOIOCTLCMD;
1103         }
1104
1105         switch (cmd) {
1106                 case ATMLEC_CTRL:
1107                         err = lecd_attach(vcc, (int) arg);
1108                         if (err >= 0)
1109                                 sock->state = SS_CONNECTED;
1110                         break;
1111                 case ATMLEC_MCAST:
1112                         err = lec_mcast_attach(vcc, (int) arg);
1113                         break;
1114                 case ATMLEC_DATA:
1115                         err = lec_vcc_attach(vcc, (void *) arg);
1116                         break;
1117         }
1118
1119         return err;
1120 }
1121
1122 static struct atm_ioctl lane_ioctl_ops = {
1123         .owner  = THIS_MODULE,
1124         .ioctl  = lane_ioctl,
1125 };
1126
1127 static int __init lane_module_init(void)
1128 {
1129 #ifdef CONFIG_PROC_FS
1130         struct proc_dir_entry *p;
1131
1132         p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1133         if (p)
1134                 p->proc_fops = &lec_seq_fops;
1135 #endif
1136
1137         register_atm_ioctl(&lane_ioctl_ops);
1138         printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1139         return 0;
1140 }
1141
1142 static void __exit lane_module_cleanup(void)
1143 {
1144         int i;
1145         struct lec_priv *priv;
1146
1147         remove_proc_entry("lec", atm_proc_root);
1148
1149         deregister_atm_ioctl(&lane_ioctl_ops);
1150
1151         for (i = 0; i < MAX_LEC_ITF; i++) {
1152                 if (dev_lec[i] != NULL) {
1153                         priv = (struct lec_priv *)dev_lec[i]->priv;
1154                         unregister_netdev(dev_lec[i]);
1155                         free_netdev(dev_lec[i]);
1156                         dev_lec[i] = NULL;
1157                 }
1158         }
1159
1160         return;                                    
1161 }
1162
1163 module_init(lane_module_init);
1164 module_exit(lane_module_cleanup);
1165
1166 /*
1167  * LANE2: 3.1.3, LE_RESOLVE.request
1168  * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1169  * If sizeoftlvs == NULL the default TLVs associated with with this
1170  * lec will be used.
1171  * If dst_mac == NULL, targetless LE_ARP will be sent
1172  */
1173 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1174     u8 **tlvs, u32 *sizeoftlvs)
1175 {
1176         struct lec_priv *priv = (struct lec_priv *)dev->priv;
1177         struct lec_arp_table *table;
1178         struct sk_buff *skb;
1179         int retval;
1180
1181         if (force == 0) {
1182                 table = lec_arp_find(priv, dst_mac);
1183                 if(table == NULL)
1184                         return -1;
1185                 
1186                 *tlvs = kmalloc(table->sizeoftlvs, GFP_KERNEL);
1187                 if (*tlvs == NULL)
1188                         return -1;
1189                 
1190                 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
1191                 *sizeoftlvs = table->sizeoftlvs;
1192                 
1193                 return 0;
1194         }
1195
1196         if (sizeoftlvs == NULL)
1197                 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1198                 
1199         else {
1200                 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1201                 if (skb == NULL)
1202                         return -1;
1203                 skb->len = *sizeoftlvs;
1204                 memcpy(skb->data, *tlvs, *sizeoftlvs);
1205                 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1206         }
1207         return retval;
1208 }        
1209
1210
1211 /*
1212  * LANE2: 3.1.4, LE_ASSOCIATE.request
1213  * Associate the *tlvs with the *lan_dst address.
1214  * Will overwrite any previous association
1215  * Returns 1 for success, 0 for failure (out of memory)
1216  *
1217  */
1218 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
1219                          u8 *tlvs, u32 sizeoftlvs)
1220 {
1221         int retval;
1222         struct sk_buff *skb;
1223         struct lec_priv *priv = (struct lec_priv*)dev->priv;
1224
1225         if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
1226                 return (0);       /* not our mac address */
1227
1228         kfree(priv->tlvs); /* NULL if there was no previous association */
1229
1230         priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1231         if (priv->tlvs == NULL)
1232                 return (0);
1233         priv->sizeoftlvs = sizeoftlvs;
1234         memcpy(priv->tlvs, tlvs, sizeoftlvs);
1235
1236         skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1237         if (skb == NULL)
1238                 return 0;
1239         skb->len = sizeoftlvs;
1240         memcpy(skb->data, tlvs, sizeoftlvs);
1241         retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1242         if (retval != 0)
1243                 printk("lec.c: lane2_associate_req() failed\n");
1244         /* If the previous association has changed we must
1245          * somehow notify other LANE entities about the change
1246          */
1247         return (1);
1248 }
1249
1250 /*
1251  * LANE2: 3.1.5, LE_ASSOCIATE.indication
1252  *
1253  */
1254 static void lane2_associate_ind (struct net_device *dev, u8 *mac_addr,
1255     u8 *tlvs, u32 sizeoftlvs)
1256 {
1257 #if 0
1258         int i = 0;
1259 #endif
1260         struct lec_priv *priv = (struct lec_priv *)dev->priv;
1261 #if 0 /* Why have the TLVs in LE_ARP entries since we do not use them? When you
1262          uncomment this code, make sure the TLVs get freed when entry is killed */
1263         struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1264
1265         if (entry == NULL)
1266                 return;     /* should not happen */
1267
1268         kfree(entry->tlvs);
1269
1270         entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1271         if (entry->tlvs == NULL)
1272                 return;
1273
1274         entry->sizeoftlvs = sizeoftlvs;
1275         memcpy(entry->tlvs, tlvs, sizeoftlvs);
1276 #endif
1277 #if 0
1278         printk("lec.c: lane2_associate_ind()\n");
1279         printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1280         while (i < sizeoftlvs)
1281                 printk("%02x ", tlvs[i++]);
1282         
1283         printk("\n");
1284 #endif
1285
1286         /* tell MPOA about the TLVs we saw */
1287         if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1288                 priv->lane2_ops->associate_indicator(dev, mac_addr,
1289                                                      tlvs, sizeoftlvs);
1290         }
1291         return;
1292 }
1293
1294 /*
1295  * Here starts what used to lec_arpc.c
1296  *
1297  * lec_arpc.c was added here when making
1298  * lane client modular. October 1997
1299  *
1300  */
1301
1302 #include <linux/types.h>
1303 #include <linux/sched.h>
1304 #include <linux/timer.h>
1305 #include <asm/param.h>
1306 #include <asm/atomic.h>
1307 #include <linux/inetdevice.h>
1308 #include <net/route.h>
1309
1310
1311 #if 0
1312 #define DPRINTK(format,args...)
1313 /*
1314 #define DPRINTK printk
1315 */
1316 #endif
1317 #define DEBUG_ARP_TABLE 0
1318
1319 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1320
1321 static void lec_arp_check_expire(unsigned long data);
1322 static void lec_arp_expire_arp(unsigned long data);
1323 void dump_arp_table(struct lec_priv *priv);
1324
1325 /* 
1326  * Arp table funcs
1327  */
1328
1329 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1330
1331 static __inline__ void 
1332 lec_arp_get(struct lec_priv *priv)
1333 {
1334         atomic_inc(&priv->lec_arp_users);
1335 }
1336
1337 static __inline__ void 
1338 lec_arp_put(struct lec_priv *priv)
1339 {
1340         atomic_dec(&priv->lec_arp_users);
1341 }
1342
1343 /*
1344  * Initialization of arp-cache
1345  */
1346 void 
1347 lec_arp_init(struct lec_priv *priv)
1348 {
1349         unsigned short i;
1350
1351         for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1352                 priv->lec_arp_tables[i] = NULL;
1353         }        
1354         spin_lock_init(&priv->lec_arp_lock);
1355         init_timer(&priv->lec_arp_timer);
1356         priv->lec_arp_timer.expires = jiffies+LEC_ARP_REFRESH_INTERVAL;
1357         priv->lec_arp_timer.data = (unsigned long)priv;
1358         priv->lec_arp_timer.function = lec_arp_check_expire;
1359         add_timer(&priv->lec_arp_timer);
1360 }
1361
1362 void
1363 lec_arp_clear_vccs(struct lec_arp_table *entry)
1364 {
1365         if (entry->vcc) {
1366                 entry->vcc->push = entry->old_push;
1367 #if 0 /* August 6, 1998 */
1368                 set_bit(ATM_VF_RELEASED,&entry->vcc->flags);
1369                 clear_bit(ATM_VF_READY,&entry->vcc->flags);
1370                 entry->vcc->push(entry->vcc, NULL);
1371 #endif
1372                 vcc_release_async(entry->vcc, -EPIPE);
1373                 entry->vcc = NULL;
1374         }
1375         if (entry->recv_vcc) {
1376                 entry->recv_vcc->push = entry->old_recv_push;
1377 #if 0
1378                 set_bit(ATM_VF_RELEASED,&entry->recv_vcc->flags);
1379                 clear_bit(ATM_VF_READY,&entry->recv_vcc->flags);
1380                 entry->recv_vcc->push(entry->recv_vcc, NULL);
1381 #endif
1382                 vcc_release_async(entry->recv_vcc, -EPIPE);
1383                 entry->recv_vcc = NULL;
1384         }        
1385 }
1386
1387 /*
1388  * Insert entry to lec_arp_table
1389  * LANE2: Add to the end of the list to satisfy 8.1.13
1390  */
1391 static inline void 
1392 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *to_add)
1393 {
1394         unsigned long flags;
1395         unsigned short place;
1396         struct lec_arp_table *tmp;
1397
1398         spin_lock_irqsave(&priv->lec_arp_lock, flags);
1399
1400         place = HASH(to_add->mac_addr[ETH_ALEN-1]);
1401         tmp = priv->lec_arp_tables[place];
1402         to_add->next = NULL;
1403         if (tmp == NULL)
1404                 priv->lec_arp_tables[place] = to_add;
1405   
1406         else {  /* add to the end */
1407                 while (tmp->next)
1408                         tmp = tmp->next;
1409                 tmp->next = to_add;
1410         }
1411
1412         spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1413
1414         DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1415                 0xff&to_add->mac_addr[0], 0xff&to_add->mac_addr[1],
1416                 0xff&to_add->mac_addr[2], 0xff&to_add->mac_addr[3],
1417                 0xff&to_add->mac_addr[4], 0xff&to_add->mac_addr[5]);
1418 }
1419
1420 /*
1421  * Remove entry from lec_arp_table
1422  */
1423 static inline int 
1424 lec_arp_remove(struct lec_priv *priv,
1425                struct lec_arp_table *to_remove)
1426 {
1427         unsigned long flags;
1428         unsigned short place;
1429         struct lec_arp_table *tmp;
1430         int remove_vcc=1;
1431
1432         spin_lock_irqsave(&priv->lec_arp_lock, flags);
1433
1434         if (!to_remove) {
1435                 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1436                 return -1;
1437         }
1438         place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
1439         tmp = priv->lec_arp_tables[place];
1440         if (tmp == to_remove) {
1441                 priv->lec_arp_tables[place] = tmp->next;
1442         } else {
1443                 while(tmp && tmp->next != to_remove) {
1444                         tmp = tmp->next;
1445                 }
1446                 if (!tmp) {/* Entry was not found */
1447                         spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1448                         return -1;
1449                 }
1450         }
1451         tmp->next = to_remove->next;
1452         del_timer(&to_remove->timer);
1453   
1454         /* If this is the only MAC connected to this VCC, also tear down
1455            the VCC */
1456         if (to_remove->status >= ESI_FLUSH_PENDING) {
1457                 /*
1458                  * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1459                  */
1460                 for(place=0;place<LEC_ARP_TABLE_SIZE;place++) {
1461                         for(tmp = priv->lec_arp_tables[place]; tmp != NULL; tmp = tmp->next) {
1462                                 if (memcmp(tmp->atm_addr, to_remove->atm_addr,
1463                                            ATM_ESA_LEN)==0) {
1464                                         remove_vcc=0;
1465                                         break;
1466                                 }
1467                         }
1468                 }
1469                 if (remove_vcc)
1470                         lec_arp_clear_vccs(to_remove);
1471         }
1472         skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1473
1474         spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1475
1476         DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1477                 0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
1478                 0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
1479                 0xff&to_remove->mac_addr[4], 0xff&to_remove->mac_addr[5]);
1480         return 0;
1481 }
1482
1483 #if DEBUG_ARP_TABLE
1484 static char*
1485 get_status_string(unsigned char st)
1486 {
1487         switch(st) {
1488         case ESI_UNKNOWN:
1489                 return "ESI_UNKNOWN";
1490         case ESI_ARP_PENDING:
1491                 return "ESI_ARP_PENDING";
1492         case ESI_VC_PENDING:
1493                 return "ESI_VC_PENDING";
1494         case ESI_FLUSH_PENDING:
1495                 return "ESI_FLUSH_PENDING";
1496         case ESI_FORWARD_DIRECT:
1497                 return "ESI_FORWARD_DIRECT";
1498         default:
1499                 return "<UNKNOWN>";
1500         }
1501 }
1502 #endif
1503
1504 void
1505 dump_arp_table(struct lec_priv *priv)
1506 {
1507 #if DEBUG_ARP_TABLE
1508         int i,j, offset;
1509         struct lec_arp_table *rulla;
1510         char buf[1024];
1511         struct lec_arp_table **lec_arp_tables =
1512                 (struct lec_arp_table **)priv->lec_arp_tables;
1513         struct lec_arp_table *lec_arp_empty_ones =
1514                 (struct lec_arp_table *)priv->lec_arp_empty_ones;
1515         struct lec_arp_table *lec_no_forward =
1516                 (struct lec_arp_table *)priv->lec_no_forward;
1517         struct lec_arp_table *mcast_fwds = priv->mcast_fwds;
1518
1519
1520         printk("Dump %p:\n",priv);
1521         for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1522                 rulla = lec_arp_tables[i];
1523                 offset = 0;
1524                 offset += sprintf(buf,"%d: %p\n",i, rulla);
1525                 while (rulla) {
1526                         offset += sprintf(buf+offset,"Mac:");
1527                         for(j=0;j<ETH_ALEN;j++) {
1528                                 offset+=sprintf(buf+offset,
1529                                                 "%2.2x ",
1530                                                 rulla->mac_addr[j]&0xff);
1531                         }
1532                         offset +=sprintf(buf+offset,"Atm:");
1533                         for(j=0;j<ATM_ESA_LEN;j++) {
1534                                 offset+=sprintf(buf+offset,
1535                                                 "%2.2x ",
1536                                                 rulla->atm_addr[j]&0xff);
1537                         }      
1538                         offset+=sprintf(buf+offset,
1539                                         "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1540                                         rulla->vcc?rulla->vcc->vpi:0, 
1541                                         rulla->vcc?rulla->vcc->vci:0,
1542                                         rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1543                                         rulla->recv_vcc?rulla->recv_vcc->vci:0,
1544                                         rulla->last_used,
1545                                         rulla->timestamp, rulla->no_tries);
1546                         offset+=sprintf(buf+offset,
1547                                         "Flags:%x, Packets_flooded:%x, Status: %s ",
1548                                         rulla->flags, rulla->packets_flooded, 
1549                                         get_status_string(rulla->status));
1550                         offset+=sprintf(buf+offset,"->%p\n",rulla->next);
1551                         rulla = rulla->next;
1552                 }
1553                 printk("%s",buf);
1554         }
1555         rulla = lec_no_forward;
1556         if (rulla)
1557                 printk("No forward\n");  
1558         while(rulla) {
1559                 offset=0;
1560                 offset += sprintf(buf+offset,"Mac:");
1561                 for(j=0;j<ETH_ALEN;j++) {
1562                         offset+=sprintf(buf+offset,"%2.2x ",
1563                                         rulla->mac_addr[j]&0xff);
1564                 }
1565                 offset +=sprintf(buf+offset,"Atm:");
1566                 for(j=0;j<ATM_ESA_LEN;j++) {
1567                         offset+=sprintf(buf+offset,"%2.2x ",
1568                                         rulla->atm_addr[j]&0xff);
1569                 }      
1570                 offset+=sprintf(buf+offset,
1571                                 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1572                                 rulla->vcc?rulla->vcc->vpi:0, 
1573                                 rulla->vcc?rulla->vcc->vci:0, 
1574                                 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1575                                 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1576                                 rulla->last_used, 
1577                                 rulla->timestamp, rulla->no_tries);
1578                 offset+=sprintf(buf+offset,
1579                                 "Flags:%x, Packets_flooded:%x, Status: %s ",
1580                                 rulla->flags, rulla->packets_flooded, 
1581                                 get_status_string(rulla->status));
1582                 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1583                 rulla = rulla->next;
1584                 printk("%s",buf);
1585         }
1586         rulla = lec_arp_empty_ones;
1587         if (rulla)
1588                 printk("Empty ones\n");  
1589         while(rulla) {
1590                 offset=0;
1591                 offset += sprintf(buf+offset,"Mac:");
1592                 for(j=0;j<ETH_ALEN;j++) {
1593                         offset+=sprintf(buf+offset,"%2.2x ",
1594                                         rulla->mac_addr[j]&0xff);
1595                 }
1596                 offset +=sprintf(buf+offset,"Atm:");
1597                 for(j=0;j<ATM_ESA_LEN;j++) {
1598                         offset+=sprintf(buf+offset,"%2.2x ",
1599                                         rulla->atm_addr[j]&0xff);
1600                 }      
1601                 offset+=sprintf(buf+offset,
1602                                 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1603                                 rulla->vcc?rulla->vcc->vpi:0, 
1604                                 rulla->vcc?rulla->vcc->vci:0, 
1605                                 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1606                                 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1607                                 rulla->last_used, 
1608                                 rulla->timestamp, rulla->no_tries);
1609                 offset+=sprintf(buf+offset,
1610                                 "Flags:%x, Packets_flooded:%x, Status: %s ",
1611                                 rulla->flags, rulla->packets_flooded, 
1612                                 get_status_string(rulla->status));
1613                 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1614                 rulla = rulla->next;
1615                 printk("%s",buf);
1616         }
1617
1618         rulla = mcast_fwds;
1619         if (rulla)
1620                 printk("Multicast Forward VCCs\n");  
1621         while(rulla) {
1622                 offset=0;
1623                 offset += sprintf(buf+offset,"Mac:");
1624                 for(j=0;j<ETH_ALEN;j++) {
1625                         offset+=sprintf(buf+offset,"%2.2x ",
1626                                         rulla->mac_addr[j]&0xff);
1627                 }
1628                 offset +=sprintf(buf+offset,"Atm:");
1629                 for(j=0;j<ATM_ESA_LEN;j++) {
1630                         offset+=sprintf(buf+offset,"%2.2x ",
1631                                         rulla->atm_addr[j]&0xff);
1632                 }      
1633                 offset+=sprintf(buf+offset,
1634                                 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1635                                 rulla->vcc?rulla->vcc->vpi:0, 
1636                                 rulla->vcc?rulla->vcc->vci:0, 
1637                                 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1638                                 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1639                                 rulla->last_used, 
1640                                 rulla->timestamp, rulla->no_tries);
1641                 offset+=sprintf(buf+offset,
1642                                 "Flags:%x, Packets_flooded:%x, Status: %s ",
1643                                 rulla->flags, rulla->packets_flooded, 
1644                                 get_status_string(rulla->status));
1645                 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1646                 rulla = rulla->next;
1647                 printk("%s",buf);
1648         }
1649
1650 #endif
1651 }
1652
1653 /*
1654  * Destruction of arp-cache
1655  */
1656 void
1657 lec_arp_destroy(struct lec_priv *priv)
1658 {
1659         struct lec_arp_table *entry, *next;
1660         int i;
1661
1662         del_timer_sync(&priv->lec_arp_timer);
1663         
1664         /*
1665          * Remove all entries
1666          */
1667         for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1668                 for(entry =priv->lec_arp_tables[i];entry != NULL; entry=next) {
1669                         next = entry->next;
1670                         lec_arp_remove(priv, entry);
1671                         kfree(entry);
1672                 }
1673         }
1674         entry = priv->lec_arp_empty_ones;
1675         while(entry) {
1676                 next = entry->next;
1677                 del_timer_sync(&entry->timer);
1678                 lec_arp_clear_vccs(entry);
1679                 kfree(entry);
1680                 entry = next;
1681         }
1682         priv->lec_arp_empty_ones = NULL;
1683         entry = priv->lec_no_forward;
1684         while(entry) {
1685                 next = entry->next;
1686                 del_timer_sync(&entry->timer);
1687                 lec_arp_clear_vccs(entry);
1688                 kfree(entry);
1689                 entry = next;
1690         }
1691         priv->lec_no_forward = NULL;
1692         entry = priv->mcast_fwds;
1693         while(entry) {
1694                 next = entry->next;
1695                 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1696                 lec_arp_clear_vccs(entry);
1697                 kfree(entry);
1698                 entry = next;
1699         }
1700         priv->mcast_fwds = NULL;
1701         priv->mcast_vcc = NULL;
1702         memset(priv->lec_arp_tables, 0, 
1703                sizeof(struct lec_arp_table*)*LEC_ARP_TABLE_SIZE);
1704 }
1705
1706
1707 /* 
1708  * Find entry by mac_address
1709  */
1710 static inline struct lec_arp_table*
1711 lec_arp_find(struct lec_priv *priv,
1712              unsigned char *mac_addr)
1713 {
1714         unsigned short place;
1715         struct lec_arp_table *to_return;
1716
1717         DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1718                 mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff, 
1719                 mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
1720         lec_arp_get(priv);
1721         place = HASH(mac_addr[ETH_ALEN-1]);
1722   
1723         to_return = priv->lec_arp_tables[place];
1724         while(to_return) {
1725                 if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
1726                         lec_arp_put(priv);
1727                         return to_return;
1728                 }
1729                 to_return = to_return->next;
1730         }
1731         lec_arp_put(priv);
1732         return NULL;
1733 }
1734
1735 static struct lec_arp_table*
1736 make_entry(struct lec_priv *priv, unsigned char *mac_addr)
1737 {
1738         struct lec_arp_table *to_return;
1739
1740         to_return=(struct lec_arp_table *)kmalloc(sizeof(struct lec_arp_table),
1741                                                   GFP_ATOMIC);
1742         if (!to_return) {
1743                 printk("LEC: Arp entry kmalloc failed\n");
1744                 return NULL;
1745         }
1746         memset(to_return,0,sizeof(struct lec_arp_table));
1747         memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1748         init_timer(&to_return->timer);
1749         to_return->timer.function = lec_arp_expire_arp;
1750         to_return->timer.data = (unsigned long)to_return;
1751         to_return->last_used = jiffies;
1752         to_return->priv = priv;
1753         skb_queue_head_init(&to_return->tx_wait);
1754         return to_return;
1755 }
1756
1757 /*
1758  *
1759  * Arp sent timer expired
1760  *
1761  */
1762 static void
1763 lec_arp_expire_arp(unsigned long data)
1764 {
1765         struct lec_arp_table *entry;
1766
1767         entry = (struct lec_arp_table *)data;
1768
1769         DPRINTK("lec_arp_expire_arp\n");
1770         if (entry->status == ESI_ARP_PENDING) {
1771                 if (entry->no_tries <= entry->priv->max_retry_count) {
1772                         if (entry->is_rdesc)
1773                                 send_to_lecd(entry->priv, l_rdesc_arp_xmt, entry->mac_addr, NULL, NULL);
1774                         else
1775                                 send_to_lecd(entry->priv, l_arp_xmt, entry->mac_addr, NULL, NULL);
1776                         entry->no_tries++;
1777                 }
1778                 mod_timer(&entry->timer, jiffies + (1*HZ));
1779         }
1780 }
1781
1782 /*
1783  *
1784  * Unknown/unused vcc expire, remove associated entry
1785  *
1786  */
1787 static void
1788 lec_arp_expire_vcc(unsigned long data)
1789 {
1790         struct lec_arp_table *to_remove = (struct lec_arp_table*)data;
1791         struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1792         struct lec_arp_table *entry = NULL;
1793
1794         del_timer(&to_remove->timer);
1795
1796         DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1797                 to_remove, priv, 
1798                 to_remove->vcc?to_remove->recv_vcc->vpi:0,
1799                 to_remove->vcc?to_remove->recv_vcc->vci:0);
1800         DPRINTK("eo:%p nf:%p\n",priv->lec_arp_empty_ones,priv->lec_no_forward);
1801         if (to_remove == priv->lec_arp_empty_ones)
1802                 priv->lec_arp_empty_ones = to_remove->next;
1803         else {
1804                 entry = priv->lec_arp_empty_ones;
1805                 while (entry && entry->next != to_remove)
1806                         entry = entry->next;
1807                 if (entry)
1808                         entry->next = to_remove->next;
1809         }
1810         if (!entry) {
1811                 if (to_remove == priv->lec_no_forward) {
1812                         priv->lec_no_forward = to_remove->next;
1813                 } else {
1814                         entry = priv->lec_no_forward;
1815                         while (entry && entry->next != to_remove)
1816                                 entry = entry->next;
1817                         if (entry)
1818                                 entry->next = to_remove->next;
1819                 }
1820         }
1821         lec_arp_clear_vccs(to_remove);
1822         kfree(to_remove);
1823 }
1824
1825 /*
1826  * Expire entries.
1827  * 1. Re-set timer
1828  * 2. For each entry, delete entries that have aged past the age limit.
1829  * 3. For each entry, depending on the status of the entry, perform
1830  *    the following maintenance.
1831  *    a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1832  *       tick_count is above the max_unknown_frame_time, clear
1833  *       the tick_count to zero and clear the packets_flooded counter
1834  *       to zero. This supports the packet rate limit per address
1835  *       while flooding unknowns.
1836  *    b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1837  *       than or equal to the path_switching_delay, change the status
1838  *       to ESI_FORWARD_DIRECT. This causes the flush period to end
1839  *       regardless of the progress of the flush protocol.
1840  */
1841 static void
1842 lec_arp_check_expire(unsigned long data)
1843 {
1844         struct lec_priv *priv = (struct lec_priv *)data;
1845         struct lec_arp_table *entry, *next;
1846         unsigned long now;
1847         unsigned long time_to_check;
1848         int i;
1849
1850         DPRINTK("lec_arp_check_expire %p,%d\n",priv,
1851                 atomic_read(&priv->lec_arp_users));
1852         DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
1853                 priv->lec_no_forward);
1854         if (!atomic_read(&priv->lec_arp_users)) {
1855                 lec_arp_get(priv);
1856                 now = jiffies;
1857                 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1858                         for(entry = priv->lec_arp_tables[i]; entry != NULL; ) {
1859                                 if ((entry->flags) & LEC_REMOTE_FLAG && 
1860                                     priv->topology_change)
1861                                         time_to_check=priv->forward_delay_time;
1862                                 else
1863                                         time_to_check = priv->aging_time;
1864
1865                                 DPRINTK("About to expire: %lx - %lx > %lx\n",
1866                                         now,entry->last_used, time_to_check);
1867                                 if( time_after(now, entry->last_used+
1868                                    time_to_check) && 
1869                                     !(entry->flags & LEC_PERMANENT_FLAG) &&
1870                                     !(entry->mac_addr[0] & 0x01) ) { /* LANE2: 7.1.20 */
1871                                         /* Remove entry */
1872                                         DPRINTK("LEC:Entry timed out\n");
1873                                         next = entry->next;      
1874                                         lec_arp_remove(priv, entry);
1875                                         kfree(entry);
1876                                         entry = next;
1877                                 } else {
1878                                         /* Something else */
1879                                         if ((entry->status == ESI_VC_PENDING ||
1880                                              entry->status == ESI_ARP_PENDING) 
1881                                             && time_after_eq(now,
1882                                             entry->timestamp +
1883                                             priv->max_unknown_frame_time)) {
1884                                                 entry->timestamp = jiffies;
1885                                                 entry->packets_flooded = 0;
1886                                                 if (entry->status == ESI_VC_PENDING)
1887                                                         send_to_lecd(priv, l_svc_setup, entry->mac_addr, entry->atm_addr, NULL);
1888                                         }
1889                                         if (entry->status == ESI_FLUSH_PENDING 
1890                                            &&
1891                                            time_after_eq(now, entry->timestamp+
1892                                            priv->path_switching_delay)) {
1893                                                 struct sk_buff *skb;
1894
1895                                                 while ((skb = skb_dequeue(&entry->tx_wait)))
1896                                                         lec_send(entry->vcc, skb, entry->priv);
1897                                                 entry->last_used = jiffies;
1898                                                 entry->status = 
1899                                                         ESI_FORWARD_DIRECT;
1900                                         }
1901                                         entry = entry->next;
1902                                 }
1903                         }
1904                 }
1905                 lec_arp_put(priv);
1906         }
1907
1908         mod_timer(&priv->lec_arp_timer, jiffies + LEC_ARP_REFRESH_INTERVAL);
1909 }
1910 /*
1911  * Try to find vcc where mac_address is attached.
1912  * 
1913  */
1914 struct atm_vcc*
1915 lec_arp_resolve(struct lec_priv *priv, unsigned char *mac_to_find, int is_rdesc,
1916                 struct lec_arp_table **ret_entry)
1917 {
1918         struct lec_arp_table *entry;
1919
1920         if (mac_to_find[0]&0x01) {
1921                 switch (priv->lane_version) {
1922                 case 1:
1923                         return priv->mcast_vcc;
1924                         break;
1925                 case 2:  /* LANE2 wants arp for multicast addresses */
1926                         if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
1927                                 return priv->mcast_vcc;
1928                         break;
1929                 default:
1930                         break;
1931                 }
1932         }
1933
1934         entry = lec_arp_find(priv, mac_to_find);
1935   
1936         if (entry) {
1937                 if (entry->status == ESI_FORWARD_DIRECT) {
1938                         /* Connection Ok */
1939                         entry->last_used = jiffies;
1940                         *ret_entry = entry;
1941                         return entry->vcc;
1942                 }
1943                 /* Data direct VC not yet set up, check to see if the unknown
1944                    frame count is greater than the limit. If the limit has
1945                    not been reached, allow the caller to send packet to
1946                    BUS. */
1947                 if (entry->status != ESI_FLUSH_PENDING &&
1948                     entry->packets_flooded<priv->maximum_unknown_frame_count) {
1949                         entry->packets_flooded++;
1950                         DPRINTK("LEC_ARP: Flooding..\n");
1951                         return priv->mcast_vcc;
1952                 }
1953                 /* We got here because entry->status == ESI_FLUSH_PENDING
1954                  * or BUS flood limit was reached for an entry which is
1955                  * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1956                  */
1957                 *ret_entry = entry;
1958                 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status, entry->vcc);
1959                 return NULL;
1960         } else {
1961                 /* No matching entry was found */
1962                 entry = make_entry(priv, mac_to_find);
1963                 DPRINTK("LEC_ARP: Making entry\n");
1964                 if (!entry) {
1965                         return priv->mcast_vcc;
1966                 }
1967                 lec_arp_add(priv, entry);
1968                 /* We want arp-request(s) to be sent */
1969                 entry->packets_flooded =1;
1970                 entry->status = ESI_ARP_PENDING;
1971                 entry->no_tries = 1;
1972                 entry->last_used = entry->timestamp = jiffies;
1973                 entry->is_rdesc = is_rdesc;
1974                 if (entry->is_rdesc)
1975                         send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, NULL);
1976                 else
1977                         send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1978                 entry->timer.expires = jiffies + (1*HZ);
1979                 entry->timer.function = lec_arp_expire_arp;
1980                 add_timer(&entry->timer);
1981                 return priv->mcast_vcc;
1982         }
1983 }
1984
1985 int
1986 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr, 
1987                 unsigned long permanent)
1988 {
1989         struct lec_arp_table *entry, *next;
1990         int i;
1991
1992         lec_arp_get(priv);
1993         DPRINTK("lec_addr_delete\n");
1994         for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1995                 for(entry=priv->lec_arp_tables[i];entry != NULL; entry=next) {
1996                         next = entry->next;
1997                         if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
1998                             && (permanent || 
1999                                 !(entry->flags & LEC_PERMANENT_FLAG))) {
2000                                 lec_arp_remove(priv, entry);
2001                                 kfree(entry);
2002                         }
2003                         lec_arp_put(priv);
2004                         return 0;
2005                 }
2006         }
2007         lec_arp_put(priv);
2008         return -1;
2009 }
2010
2011 /*
2012  * Notifies:  Response to arp_request (atm_addr != NULL) 
2013  */
2014 void
2015 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2016                unsigned char *atm_addr, unsigned long remoteflag,
2017                unsigned int targetless_le_arp)
2018 {
2019         struct lec_arp_table *entry, *tmp;
2020         int i;
2021
2022         DPRINTK("lec:%s", (targetless_le_arp) ? "targetless ": " ");
2023         DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2024                 mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],
2025                 mac_addr[4],mac_addr[5]);
2026
2027         entry = lec_arp_find(priv, mac_addr);
2028         if (entry == NULL && targetless_le_arp)
2029                 return;   /* LANE2: ignore targetless LE_ARPs for which
2030                            * we have no entry in the cache. 7.1.30
2031                            */
2032         lec_arp_get(priv);
2033         if (priv->lec_arp_empty_ones) {
2034                 entry = priv->lec_arp_empty_ones;
2035                 if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
2036                         priv->lec_arp_empty_ones = entry->next;
2037                 } else {
2038                         while(entry->next && memcmp(entry->next->atm_addr, 
2039                                                     atm_addr, ATM_ESA_LEN))
2040                                 entry = entry->next;
2041                         if (entry->next) {
2042                                 tmp = entry;
2043                                 entry = entry->next;
2044                                 tmp->next = entry->next;
2045                         } else
2046                                 entry = NULL;
2047                         
2048                 }
2049                 if (entry) {
2050                         del_timer(&entry->timer);
2051                         tmp = lec_arp_find(priv, mac_addr);
2052                         if (tmp) {
2053                                 del_timer(&tmp->timer);
2054                                 tmp->status = ESI_FORWARD_DIRECT;
2055                                 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2056                                 tmp->vcc = entry->vcc;
2057                                 tmp->old_push = entry->old_push;
2058                                 tmp->last_used = jiffies;
2059                                 del_timer(&entry->timer);
2060                                 kfree(entry);
2061                                 entry=tmp;
2062                         } else {
2063                                 entry->status = ESI_FORWARD_DIRECT;
2064                                 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2065                                 entry->last_used = jiffies;
2066                                 lec_arp_add(priv, entry);
2067                         }
2068                         if (remoteflag)
2069                                 entry->flags|=LEC_REMOTE_FLAG;
2070                         else
2071                                 entry->flags&=~LEC_REMOTE_FLAG;
2072                         lec_arp_put(priv);
2073                         DPRINTK("After update\n");
2074                         dump_arp_table(priv);
2075                         return;
2076                 }
2077         }
2078         entry = lec_arp_find(priv, mac_addr);
2079         if (!entry) {
2080                 entry = make_entry(priv, mac_addr);
2081                 if (!entry) {
2082                         lec_arp_put(priv);
2083                         return;
2084                 }
2085                 entry->status = ESI_UNKNOWN;
2086                 lec_arp_add(priv, entry);
2087                 /* Temporary, changes before end of function */
2088         }
2089         memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2090         del_timer(&entry->timer);
2091         for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2092                 for(tmp=priv->lec_arp_tables[i];tmp;tmp=tmp->next) {
2093                         if (entry != tmp &&
2094                             !memcmp(tmp->atm_addr, atm_addr,
2095                                     ATM_ESA_LEN)) { 
2096                                 /* Vcc to this host exists */
2097                                 if (tmp->status > ESI_VC_PENDING) {
2098                                         /*
2099                                          * ESI_FLUSH_PENDING,
2100                                          * ESI_FORWARD_DIRECT
2101                                          */
2102                                         entry->vcc = tmp->vcc;
2103                                         entry->old_push=tmp->old_push;
2104                                 }
2105                                 entry->status=tmp->status;
2106                                 break;
2107                         }
2108                 }
2109         }
2110         if (remoteflag)
2111                 entry->flags|=LEC_REMOTE_FLAG;
2112         else
2113                 entry->flags&=~LEC_REMOTE_FLAG;
2114         if (entry->status == ESI_ARP_PENDING ||
2115             entry->status == ESI_UNKNOWN) {
2116                 entry->status = ESI_VC_PENDING;
2117                 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2118         }
2119         DPRINTK("After update2\n");
2120         dump_arp_table(priv);
2121         lec_arp_put(priv);
2122 }
2123
2124 /*
2125  * Notifies: Vcc setup ready 
2126  */
2127 void
2128 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2129               struct atm_vcc *vcc,
2130               void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb))
2131 {
2132         struct lec_arp_table *entry;
2133         int i, found_entry=0;
2134
2135         lec_arp_get(priv);
2136         if (ioc_data->receive == 2) {
2137                 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2138
2139                 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2140 #if 0
2141                 entry = lec_arp_find(priv, bus_mac);
2142                 if (!entry) {
2143                         printk("LEC_ARP: Multicast entry not found!\n");
2144                         lec_arp_put(priv);
2145                         return;
2146                 }
2147                 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2148                 entry->recv_vcc = vcc;
2149                 entry->old_recv_push = old_push;
2150 #endif
2151                 entry = make_entry(priv, bus_mac);
2152                 if (entry == NULL) {
2153                         lec_arp_put(priv);
2154                         return;
2155                 }
2156                 del_timer(&entry->timer);
2157                 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2158                 entry->recv_vcc = vcc;
2159                 entry->old_recv_push = old_push;
2160                 entry->next = priv->mcast_fwds;
2161                 priv->mcast_fwds = entry;
2162                 lec_arp_put(priv);
2163                 return;
2164         } else if (ioc_data->receive == 1) {
2165                 /* Vcc which we don't want to make default vcc, attach it
2166                    anyway. */
2167                 DPRINTK("LEC_ARP:Attaching data direct, not default :%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2168                         ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2169                         ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2170                         ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2171                         ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2172                         ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2173                         ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2174                         ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2175                         ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2176                         ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2177                         ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2178                 entry = make_entry(priv, bus_mac);
2179                 if (entry == NULL) {
2180                         lec_arp_put(priv);
2181                         return;
2182                 }
2183                 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2184                 memset(entry->mac_addr, 0, ETH_ALEN);
2185                 entry->recv_vcc = vcc;
2186                 entry->old_recv_push = old_push;
2187                 entry->status = ESI_UNKNOWN;
2188                 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2189                 entry->timer.function = lec_arp_expire_vcc;
2190                 add_timer(&entry->timer);
2191                 entry->next = priv->lec_no_forward;
2192                 priv->lec_no_forward = entry;
2193                 lec_arp_put(priv);
2194                 dump_arp_table(priv);
2195                 return;
2196         }
2197         DPRINTK("LEC_ARP:Attaching data direct, default:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2198                 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2199                 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2200                 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2201                 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2202                 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2203                 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2204                 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2205                 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2206                 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2207                 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2208         for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2209                 for (entry = priv->lec_arp_tables[i];entry;entry=entry->next) {
2210                         if (memcmp(ioc_data->atm_addr, entry->atm_addr, 
2211                                    ATM_ESA_LEN)==0) {
2212                                 DPRINTK("LEC_ARP: Attaching data direct\n");
2213                                 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2214                                         entry->vcc?entry->vcc->vci:0,
2215                                         entry->recv_vcc?entry->recv_vcc->vci:0);
2216                                 found_entry=1;
2217                                 del_timer(&entry->timer);
2218                                 entry->vcc = vcc;
2219                                 entry->old_push = old_push;
2220                                 if (entry->status == ESI_VC_PENDING) {
2221                                         if(priv->maximum_unknown_frame_count
2222                                            ==0)
2223                                                 entry->status = 
2224                                                         ESI_FORWARD_DIRECT;
2225                                         else {
2226                                                 entry->timestamp = jiffies;
2227                                                 entry->status = 
2228                                                         ESI_FLUSH_PENDING;
2229 #if 0
2230                                                 send_to_lecd(priv,l_flush_xmt,
2231                                                              NULL,
2232                                                              entry->atm_addr,
2233                                                              NULL);
2234 #endif
2235                                         }
2236                                 } else {
2237                                         /* They were forming a connection
2238                                            to us, and we to them. Our
2239                                            ATM address is numerically lower
2240                                            than theirs, so we make connection
2241                                            we formed into default VCC (8.1.11).
2242                                            Connection they made gets torn
2243                                            down. This might confuse some
2244                                            clients. Can be changed if
2245                                            someone reports trouble... */
2246                                         ;
2247                                 }
2248                         }
2249                 }
2250         }
2251         if (found_entry) {
2252                 lec_arp_put(priv);
2253                 DPRINTK("After vcc was added\n");
2254                 dump_arp_table(priv);
2255                 return;
2256         }
2257         /* Not found, snatch address from first data packet that arrives from
2258            this vcc */
2259         entry = make_entry(priv, bus_mac);
2260         if (!entry) {
2261                 lec_arp_put(priv);
2262                 return;
2263         }
2264         entry->vcc = vcc;
2265         entry->old_push = old_push;
2266         memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2267         memset(entry->mac_addr, 0, ETH_ALEN);
2268         entry->status = ESI_UNKNOWN;
2269         entry->next = priv->lec_arp_empty_ones;
2270         priv->lec_arp_empty_ones = entry;
2271         entry->timer.expires = jiffies + priv->vcc_timeout_period;
2272         entry->timer.function = lec_arp_expire_vcc;
2273         add_timer(&entry->timer);
2274         lec_arp_put(priv);
2275         DPRINTK("After vcc was added\n");
2276         dump_arp_table(priv);
2277 }
2278
2279 void
2280 lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2281 {
2282         struct lec_arp_table *entry;
2283         int i;
2284   
2285         DPRINTK("LEC:lec_flush_complete %lx\n",tran_id);
2286         for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2287                 for (entry=priv->lec_arp_tables[i];entry;entry=entry->next) {
2288                         if (entry->flush_tran_id == tran_id &&
2289                             entry->status == ESI_FLUSH_PENDING) {
2290                                 struct sk_buff *skb;
2291
2292                                 while ((skb = skb_dequeue(&entry->tx_wait)))
2293                                         lec_send(entry->vcc, skb, entry->priv);
2294                                 entry->status = ESI_FORWARD_DIRECT;
2295                                 DPRINTK("LEC_ARP: Flushed\n");
2296                         }
2297                 }
2298         }
2299         dump_arp_table(priv);
2300 }
2301
2302 void
2303 lec_set_flush_tran_id(struct lec_priv *priv,
2304                       unsigned char *atm_addr, unsigned long tran_id)
2305 {
2306         struct lec_arp_table *entry;
2307         int i;
2308
2309         for (i=0;i<LEC_ARP_TABLE_SIZE;i++)
2310                 for(entry=priv->lec_arp_tables[i];entry;entry=entry->next)
2311                         if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2312                                 entry->flush_tran_id = tran_id;
2313                                 DPRINTK("Set flush transaction id to %lx for %p\n",tran_id,entry);
2314                         }
2315 }
2316
2317 int 
2318 lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2319 {
2320         unsigned char mac_addr[] = {
2321                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2322         struct lec_arp_table *to_add;
2323   
2324         lec_arp_get(priv);
2325         to_add = make_entry(priv, mac_addr);
2326         if (!to_add) {
2327                 lec_arp_put(priv);
2328                 return -ENOMEM;
2329         }
2330         memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2331         to_add->status = ESI_FORWARD_DIRECT;
2332         to_add->flags |= LEC_PERMANENT_FLAG;
2333         to_add->vcc = vcc;
2334         to_add->old_push = vcc->push;
2335         vcc->push = lec_push;
2336         priv->mcast_vcc = vcc;
2337         lec_arp_add(priv, to_add);
2338         lec_arp_put(priv);
2339         return 0;
2340 }
2341
2342 void
2343 lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2344 {
2345         struct lec_arp_table *entry, *next;
2346         int i;
2347
2348         DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
2349         dump_arp_table(priv);
2350         lec_arp_get(priv);
2351         for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2352                 for(entry = priv->lec_arp_tables[i];entry; entry=next) {
2353                         next = entry->next;
2354                         if (vcc == entry->vcc) {
2355                                 lec_arp_remove(priv, entry);
2356                                 kfree(entry);
2357                                 if (priv->mcast_vcc == vcc) {
2358                                         priv->mcast_vcc = NULL;
2359                                 }
2360                         }
2361                 }
2362         }
2363
2364         entry = priv->lec_arp_empty_ones;
2365         priv->lec_arp_empty_ones = NULL;
2366         while (entry != NULL) {
2367                 next = entry->next;
2368                 if (entry->vcc == vcc) { /* leave it out from the list */
2369                         lec_arp_clear_vccs(entry);
2370                         del_timer(&entry->timer);
2371                         kfree(entry);
2372                 }
2373                 else {              /* put it back to the list */
2374                         entry->next = priv->lec_arp_empty_ones;
2375                         priv->lec_arp_empty_ones = entry;
2376                 }
2377                 entry = next;
2378         }
2379         
2380         entry = priv->lec_no_forward;
2381         priv->lec_no_forward = NULL;
2382         while (entry != NULL) {
2383                 next = entry->next;
2384                 if (entry->recv_vcc == vcc) {
2385                         lec_arp_clear_vccs(entry);
2386                         del_timer(&entry->timer);
2387                         kfree(entry);
2388                 }
2389                 else {
2390                         entry->next = priv->lec_no_forward;
2391                         priv->lec_no_forward = entry;
2392                 }
2393                 entry = next;
2394         }
2395
2396         entry = priv->mcast_fwds;
2397         priv->mcast_fwds = NULL;
2398         while (entry != NULL) {
2399                 next = entry->next;
2400                 if (entry->recv_vcc == vcc) {
2401                         lec_arp_clear_vccs(entry);
2402                         /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2403                         kfree(entry);
2404                 }
2405                 else {
2406                         entry->next = priv->mcast_fwds;
2407                         priv->mcast_fwds = entry;
2408                 }
2409                 entry = next;
2410         }
2411
2412         lec_arp_put(priv);
2413         dump_arp_table(priv);
2414 }
2415
2416 void
2417 lec_arp_check_empties(struct lec_priv *priv,
2418                       struct atm_vcc *vcc, struct sk_buff *skb)
2419 {
2420         unsigned long flags;
2421         struct lec_arp_table *entry, *prev;
2422         struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2423         unsigned char *src;
2424 #ifdef CONFIG_TR
2425         struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2426
2427         if (priv->is_trdev) src = tr_hdr->h_source;
2428         else
2429 #endif
2430         src = hdr->h_source;
2431
2432         lec_arp_get(priv);
2433         entry = priv->lec_arp_empty_ones;
2434         if (vcc == entry->vcc) {
2435                 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2436                 del_timer(&entry->timer);
2437                 memcpy(entry->mac_addr, src, ETH_ALEN);
2438                 entry->status = ESI_FORWARD_DIRECT;
2439                 entry->last_used = jiffies;
2440                 priv->lec_arp_empty_ones = entry->next;
2441                 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2442                 /* We might have got an entry */
2443                 if ((prev=lec_arp_find(priv,src))) {
2444                         lec_arp_remove(priv, prev);
2445                         kfree(prev);
2446                 }
2447                 lec_arp_add(priv, entry);
2448                 lec_arp_put(priv);
2449                 return;
2450         }
2451         spin_lock_irqsave(&priv->lec_arp_lock, flags);
2452         prev = entry;
2453         entry = entry->next;
2454         while (entry && entry->vcc != vcc) {
2455                 prev= entry;
2456                 entry = entry->next;
2457         }
2458         if (!entry) {
2459                 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2460                 lec_arp_put(priv);
2461                 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2462                 return;
2463         }
2464         del_timer(&entry->timer);
2465         memcpy(entry->mac_addr, src, ETH_ALEN);
2466         entry->status = ESI_FORWARD_DIRECT;
2467         entry->last_used = jiffies;
2468         prev->next = entry->next;
2469         spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2470         if ((prev = lec_arp_find(priv, src))) {
2471                 lec_arp_remove(priv, prev);
2472                 kfree(prev);
2473         }
2474         lec_arp_add(priv, entry);
2475         lec_arp_put(priv);  
2476 }
2477 MODULE_LICENSE("GPL");