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