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