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