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