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