2 * lec.c: Lan Emulation driver
4 * Marko Kiiskila <mkiiskila@yahoo.com>
7 #include <linux/kernel.h>
8 #include <linux/bitops.h>
9 #include <linux/capability.h>
11 /* We are ethernet device */
12 #include <linux/if_ether.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
16 #include <linux/skbuff.h>
18 #include <asm/byteorder.h>
19 #include <asm/uaccess.h>
22 #include <linux/proc_fs.h>
23 #include <linux/spinlock.h>
24 #include <linux/proc_fs.h>
25 #include <linux/seq_file.h>
27 /* TokenRing if needed */
29 #include <linux/trdevice.h>
33 #include <linux/atmdev.h>
34 #include <linux/atmlec.h>
36 /* Proxy LEC knows about bridging */
37 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38 #include <linux/if_bridge.h>
39 #include "../bridge/br_private.h"
41 static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
45 #include <linux/module.h>
46 #include <linux/init.h>
50 #include "resources.h"
53 #define DPRINTK printk
55 #define DPRINTK(format,args...)
58 #define DUMP_PACKETS 0 /*
64 #define LEC_UNRES_QUE_LEN 8 /*
65 * number of tx packets to queue for a
66 * single destination while waiting for SVC
69 static int lec_open(struct net_device *dev);
70 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
71 static int lec_close(struct net_device *dev);
72 static struct net_device_stats *lec_get_stats(struct net_device *dev);
73 static void lec_init(struct net_device *dev);
74 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
75 unsigned char *mac_addr);
76 static int lec_arp_remove(struct lec_priv *priv,
77 struct lec_arp_table *to_remove);
79 static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
80 u8 *tlvs, u32 sizeoftlvs);
81 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
82 u8 **tlvs, u32 *sizeoftlvs);
83 static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
84 u8 *tlvs, u32 sizeoftlvs);
86 static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
87 unsigned long permanent);
88 static void lec_arp_check_empties(struct lec_priv *priv,
89 struct atm_vcc *vcc, struct sk_buff *skb);
90 static void lec_arp_destroy(struct lec_priv *priv);
91 static void lec_arp_init(struct lec_priv *priv);
92 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
93 unsigned char *mac_to_find,
95 struct lec_arp_table **ret_entry);
96 static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
97 unsigned char *atm_addr, unsigned long remoteflag,
98 unsigned int targetless_le_arp);
99 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
100 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
101 static void lec_set_flush_tran_id(struct lec_priv *priv,
102 unsigned char *atm_addr,
103 unsigned long tran_id);
104 static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
106 void (*old_push) (struct atm_vcc *vcc,
107 struct sk_buff *skb));
108 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
110 /* must be done under lec_arp_lock */
111 static inline void lec_arp_hold(struct lec_arp_table *entry)
113 atomic_inc(&entry->usage);
116 static inline void lec_arp_put(struct lec_arp_table *entry)
118 if (atomic_dec_and_test(&entry->usage))
123 static struct lane2_ops lane2_ops = {
124 lane2_resolve, /* resolve, spec 3.1.3 */
125 lane2_associate_req, /* associate_req, spec 3.1.4 */
126 NULL /* associate indicator, spec 3.1.5 */
129 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
131 /* Device structures */
132 static struct net_device *dev_lec[MAX_LEC_ITF];
134 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
135 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
139 struct lec_priv *priv;
142 * Check if this is a BPDU. If so, ask zeppelin to send
143 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
144 * as the Config BPDU has
146 eth = (struct ethhdr *)skb->data;
147 buff = skb->data + skb->dev->hard_header_len;
148 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
150 struct sk_buff *skb2;
151 struct atmlec_msg *mesg;
153 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
156 skb2->len = sizeof(struct atmlec_msg);
157 mesg = (struct atmlec_msg *)skb2->data;
158 mesg->type = l_topology_change;
160 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
162 priv = (struct lec_priv *)dev->priv;
163 atm_force_charge(priv->lecd, skb2->truesize);
164 sk = sk_atm(priv->lecd);
165 skb_queue_tail(&sk->sk_receive_queue, skb2);
166 sk->sk_data_ready(sk, skb2->len);
171 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
174 * Modelled after tr_type_trans
175 * All multicast and ARE or STE frames go to BUS.
176 * Non source routed frames go by destination address.
177 * Last hop source routed frames go by destination address.
178 * Not last hop source routed frames go by _next_ route descriptor.
179 * Returns pointer to destination MAC address or fills in rdesc
183 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
186 int riflen, num_rdsc;
188 trh = (struct trh_hdr *)packet;
189 if (trh->daddr[0] & (uint8_t) 0x80)
190 return bus_mac; /* multicast */
192 if (trh->saddr[0] & TR_RII) {
193 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
194 if ((ntohs(trh->rcf) >> 13) != 0)
195 return bus_mac; /* ARE or STE */
197 return trh->daddr; /* not source routed */
200 return trh->daddr; /* last hop, source routed */
202 /* riflen is 6 or more, packet has more than one route descriptor */
203 num_rdsc = (riflen / 2) - 1;
204 memset(rdesc, 0, ETH_ALEN);
205 /* offset 4 comes from LAN destination field in LE control frames */
206 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
207 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
209 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
210 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
215 #endif /* CONFIG_TR */
218 * Open/initialize the netdevice. This is called (in the current kernel)
219 * sometime after booting when the 'ifconfig' program is run.
221 * This routine should set everything up anew at each open, even
222 * registers that "should" only need to be set once at boot, so that
223 * there is non-reboot way to recover if something goes wrong.
226 static int lec_open(struct net_device *dev)
228 struct lec_priv *priv = (struct lec_priv *)dev->priv;
230 netif_start_queue(dev);
231 memset(&priv->stats, 0, sizeof(struct net_device_stats));
236 static __inline__ void
237 lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
239 ATM_SKB(skb)->vcc = vcc;
240 ATM_SKB(skb)->atm_options = vcc->atm_options;
242 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
243 if (vcc->send(vcc, skb) < 0) {
244 priv->stats.tx_dropped++;
248 priv->stats.tx_packets++;
249 priv->stats.tx_bytes += skb->len;
252 static void lec_tx_timeout(struct net_device *dev)
254 printk(KERN_INFO "%s: tx timeout\n", dev->name);
255 dev->trans_start = jiffies;
256 netif_wake_queue(dev);
259 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
261 struct sk_buff *skb2;
262 struct lec_priv *priv = (struct lec_priv *)dev->priv;
263 struct lecdatahdr_8023 *lec_h;
265 struct lec_arp_table *entry;
269 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
275 #endif /* DUMP_PACKETS >0 */
277 DPRINTK("lec_start_xmit called\n");
279 printk("%s:No lecd attached\n", dev->name);
280 priv->stats.tx_errors++;
281 netif_stop_queue(dev);
285 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
286 (long)skb->head, (long)skb->data, (long)skb->tail,
288 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
289 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
290 lec_handle_bridge(skb, dev);
293 /* Make sure we have room for lec_id */
294 if (skb_headroom(skb) < 2) {
296 DPRINTK("lec_start_xmit: reallocating skb\n");
297 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
305 /* Put le header to place, works for TokenRing too */
306 lec_h = (struct lecdatahdr_8023 *)skb->data;
307 lec_h->le_header = htons(priv->lecid);
311 * Ugly. Use this to realign Token Ring packets for
312 * e.g. PCA-200E driver.
314 if (priv->is_trdev) {
315 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
324 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
325 skb->len, priv->lecid);
326 #if DUMP_PACKETS >= 2
327 for (i = 0; i < skb->len && i < 99; i++) {
328 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
330 #elif DUMP_PACKETS >= 1
331 for (i = 0; i < skb->len && i < 30; i++) {
332 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
334 #endif /* DUMP_PACKETS >= 1 */
338 printk("%s...\n", buf);
339 #endif /* DUMP_PACKETS > 0 */
341 /* Minimum ethernet-frame size */
344 min_frame_size = LEC_MINIMUM_8025_SIZE;
347 min_frame_size = LEC_MINIMUM_8023_SIZE;
348 if (skb->len < min_frame_size) {
349 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
350 skb2 = skb_copy_expand(skb, 0,
351 min_frame_size - skb->truesize,
355 priv->stats.tx_dropped++;
360 skb_put(skb, min_frame_size - skb->len);
363 /* Send to right vcc */
367 if (priv->is_trdev) {
368 dst = get_tr_dst(skb->data + 2, rdesc);
376 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
377 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
378 vcc, vcc ? vcc->flags : 0, entry);
379 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
380 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
381 DPRINTK("%s:lec_start_xmit: queuing packet, ",
383 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
384 lec_h->h_dest[0], lec_h->h_dest[1],
385 lec_h->h_dest[2], lec_h->h_dest[3],
386 lec_h->h_dest[4], lec_h->h_dest[5]);
387 skb_queue_tail(&entry->tx_wait, skb);
390 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
392 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
393 lec_h->h_dest[0], lec_h->h_dest[1],
394 lec_h->h_dest[2], lec_h->h_dest[3],
395 lec_h->h_dest[4], lec_h->h_dest[5]);
396 priv->stats.tx_dropped++;
402 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
403 #endif /* DUMP_PACKETS > 0 */
405 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
406 DPRINTK("lec.c: emptying tx queue, ");
407 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
408 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
409 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
410 lec_send(vcc, skb2, priv);
413 lec_send(vcc, skb, priv);
415 if (!atm_may_send(vcc, 0)) {
416 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
419 netif_stop_queue(dev);
422 * vcc->pop() might have occurred in between, making
423 * the vcc usuable again. Since xmit is serialized,
424 * this is the only situation we have to re-test.
427 if (atm_may_send(vcc, 0))
428 netif_wake_queue(dev);
434 dev->trans_start = jiffies;
438 /* The inverse routine to net_open(). */
439 static int lec_close(struct net_device *dev)
441 netif_stop_queue(dev);
446 * Get the current statistics.
447 * This may be called with the card open or closed.
449 static struct net_device_stats *lec_get_stats(struct net_device *dev)
451 return &((struct lec_priv *)dev->priv)->stats;
454 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
457 struct net_device *dev = (struct net_device *)vcc->proto_data;
458 struct lec_priv *priv = (struct lec_priv *)dev->priv;
459 struct atmlec_msg *mesg;
460 struct lec_arp_table *entry;
462 char *tmp; /* FIXME */
464 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
465 mesg = (struct atmlec_msg *)skb->data;
467 tmp += sizeof(struct atmlec_msg);
468 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
469 switch (mesg->type) {
471 for (i = 0; i < 6; i++) {
472 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
476 for (i = 0; i < 6; i++) {
477 dev->dev_addr[i] = 0;
481 lec_addr_delete(priv, mesg->content.normal.atm_addr,
482 mesg->content.normal.flag);
484 case l_topology_change:
485 priv->topology_change = mesg->content.normal.flag;
487 case l_flush_complete:
488 lec_flush_complete(priv, mesg->content.normal.flag);
490 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
491 spin_lock_irqsave(&priv->lec_arp_lock, flags);
492 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
493 lec_arp_remove(priv, entry);
494 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
496 if (mesg->content.normal.no_source_le_narp)
500 lec_arp_update(priv, mesg->content.normal.mac_addr,
501 mesg->content.normal.atm_addr,
502 mesg->content.normal.flag,
503 mesg->content.normal.targetless_le_arp);
504 DPRINTK("lec: in l_arp_update\n");
505 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
506 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
508 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
509 tmp, mesg->sizeoftlvs);
513 priv->maximum_unknown_frame_count =
514 mesg->content.config.maximum_unknown_frame_count;
515 priv->max_unknown_frame_time =
516 (mesg->content.config.max_unknown_frame_time * HZ);
517 priv->max_retry_count = mesg->content.config.max_retry_count;
518 priv->aging_time = (mesg->content.config.aging_time * HZ);
519 priv->forward_delay_time =
520 (mesg->content.config.forward_delay_time * HZ);
521 priv->arp_response_time =
522 (mesg->content.config.arp_response_time * HZ);
523 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
524 priv->path_switching_delay =
525 (mesg->content.config.path_switching_delay * HZ);
526 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
527 priv->lane2_ops = NULL;
528 if (priv->lane_version > 1)
529 priv->lane2_ops = &lane2_ops;
530 if (dev->change_mtu(dev, mesg->content.config.mtu))
531 printk("%s: change_mtu to %d failed\n", dev->name,
532 mesg->content.config.mtu);
533 priv->is_proxy = mesg->content.config.is_proxy;
535 case l_flush_tran_id:
536 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
537 mesg->content.normal.flag);
541 (unsigned short)(0xffff & mesg->content.normal.flag);
543 case l_should_bridge:
544 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
546 struct net_bridge_fdb_entry *f;
549 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
550 dev->name, mesg->content.proxy.mac_addr[0],
551 mesg->content.proxy.mac_addr[1],
552 mesg->content.proxy.mac_addr[2],
553 mesg->content.proxy.mac_addr[3],
554 mesg->content.proxy.mac_addr[4],
555 mesg->content.proxy.mac_addr[5]);
557 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
560 f = br_fdb_get_hook(dev->br_port->br,
561 mesg->content.proxy.mac_addr);
562 if (f != NULL && f->dst->dev != dev
563 && f->dst->state == BR_STATE_FORWARDING) {
564 /* hit from bridge table, send LE_ARP_RESPONSE */
565 struct sk_buff *skb2;
569 ("%s: entry found, responding to zeppelin\n",
572 alloc_skb(sizeof(struct atmlec_msg),
578 skb2->len = sizeof(struct atmlec_msg);
579 memcpy(skb2->data, mesg,
580 sizeof(struct atmlec_msg));
581 atm_force_charge(priv->lecd, skb2->truesize);
582 sk = sk_atm(priv->lecd);
583 skb_queue_tail(&sk->sk_receive_queue, skb2);
584 sk->sk_data_ready(sk, skb2->len);
589 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
592 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
600 static void lec_atm_close(struct atm_vcc *vcc)
603 struct net_device *dev = (struct net_device *)vcc->proto_data;
604 struct lec_priv *priv = (struct lec_priv *)dev->priv;
607 /* Do something needful? */
609 netif_stop_queue(dev);
610 lec_arp_destroy(priv);
612 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
613 printk("%s lec_atm_close: closing with messages pending\n",
615 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
616 atm_return(vcc, skb->truesize);
620 printk("%s: Shut down!\n", dev->name);
621 module_put(THIS_MODULE);
624 static struct atmdev_ops lecdev_ops = {
625 .close = lec_atm_close,
629 static struct atm_dev lecatm_dev = {
632 .number = 999, /* dummy device number */
633 .lock = SPIN_LOCK_UNLOCKED
637 * LANE2: new argument struct sk_buff *data contains
638 * the LE_ARP based TLVs introduced in the LANE2 spec
641 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
642 unsigned char *mac_addr, unsigned char *atm_addr,
643 struct sk_buff *data)
647 struct atmlec_msg *mesg;
649 if (!priv || !priv->lecd) {
652 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
655 skb->len = sizeof(struct atmlec_msg);
656 mesg = (struct atmlec_msg *)skb->data;
657 memset(mesg, 0, sizeof(struct atmlec_msg));
660 mesg->sizeoftlvs = data->len;
662 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
664 mesg->content.normal.targetless_le_arp = 1;
666 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
668 atm_force_charge(priv->lecd, skb->truesize);
669 sk = sk_atm(priv->lecd);
670 skb_queue_tail(&sk->sk_receive_queue, skb);
671 sk->sk_data_ready(sk, skb->len);
674 DPRINTK("lec: about to send %d bytes of data\n", data->len);
675 atm_force_charge(priv->lecd, data->truesize);
676 skb_queue_tail(&sk->sk_receive_queue, data);
677 sk->sk_data_ready(sk, skb->len);
683 /* shamelessly stolen from drivers/net/net_init.c */
684 static int lec_change_mtu(struct net_device *dev, int new_mtu)
686 if ((new_mtu < 68) || (new_mtu > 18190))
692 static void lec_set_multicast_list(struct net_device *dev)
695 * by default, all multicast frames arrive over the bus.
696 * eventually support selective multicast service
701 static void lec_init(struct net_device *dev)
703 dev->change_mtu = lec_change_mtu;
704 dev->open = lec_open;
705 dev->stop = lec_close;
706 dev->hard_start_xmit = lec_start_xmit;
707 dev->tx_timeout = lec_tx_timeout;
709 dev->get_stats = lec_get_stats;
710 dev->set_multicast_list = lec_set_multicast_list;
711 dev->do_ioctl = NULL;
712 printk("%s: Initialized!\n", dev->name);
716 static unsigned char lec_ctrl_magic[] = {
723 #define LEC_DATA_DIRECT_8023 2
724 #define LEC_DATA_DIRECT_8025 3
726 static int lec_is_data_direct(struct atm_vcc *vcc)
728 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
729 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
732 static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
735 struct net_device *dev = (struct net_device *)vcc->proto_data;
736 struct lec_priv *priv = (struct lec_priv *)dev->priv;
742 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
746 DPRINTK("%s: null skb\n", dev->name);
747 lec_vcc_close(priv, vcc);
751 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
752 skb->len, priv->lecid);
753 #if DUMP_PACKETS >= 2
754 for (i = 0; i < skb->len && i < 99; i++) {
755 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
757 #elif DUMP_PACKETS >= 1
758 for (i = 0; i < skb->len && i < 30; i++) {
759 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
761 #endif /* DUMP_PACKETS >= 1 */
765 printk("%s...\n", buf);
766 #endif /* DUMP_PACKETS > 0 */
767 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
768 struct sock *sk = sk_atm(vcc);
770 DPRINTK("%s: To daemon\n", dev->name);
771 skb_queue_tail(&sk->sk_receive_queue, skb);
772 sk->sk_data_ready(sk, skb->len);
773 } else { /* Data frame, queue to protocol handlers */
774 struct lec_arp_table *entry;
775 unsigned char *src, *dst;
777 atm_return(vcc, skb->truesize);
778 if (*(__be16 *) skb->data == htons(priv->lecid) ||
779 !priv->lecd || !(dev->flags & IFF_UP)) {
781 * Probably looping back, or if lecd is missing,
784 DPRINTK("Ignoring frame...\n");
790 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
793 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
796 * If this is a Data Direct VCC, and the VCC does not match
797 * the LE_ARP cache entry, delete the LE_ARP cache entry.
799 spin_lock_irqsave(&priv->lec_arp_lock, flags);
800 if (lec_is_data_direct(vcc)) {
804 ((struct lecdatahdr_8025 *)skb->data)->
809 ((struct lecdatahdr_8023 *)skb->data)->
811 entry = lec_arp_find(priv, src);
812 if (entry && entry->vcc != vcc) {
813 lec_arp_remove(priv, entry);
817 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
819 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
820 !priv->is_proxy && /* Proxy wants all the packets */
821 memcmp(dst, dev->dev_addr, dev->addr_len)) {
825 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
826 lec_arp_check_empties(priv, vcc, skb);
828 skb_pull(skb, 2); /* skip lec_id */
831 skb->protocol = tr_type_trans(skb, dev);
836 skb->protocol = eth_type_trans(skb, dev);
838 priv->stats.rx_packets++;
839 priv->stats.rx_bytes += skb->len;
840 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
845 static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
847 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
848 struct net_device *dev = skb->dev;
851 printk("lec_pop(): vpriv = NULL!?!?!?\n");
855 vpriv->old_pop(vcc, skb);
857 if (vpriv->xoff && atm_may_send(vcc, 0)) {
859 if (netif_running(dev) && netif_queue_stopped(dev))
860 netif_wake_queue(dev);
864 static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
866 struct lec_vcc_priv *vpriv;
868 struct atmlec_ioc ioc_data;
870 /* Lecd must be up in this case */
871 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
872 if (bytes_left != 0) {
874 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
877 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
878 !dev_lec[ioc_data.dev_num])
880 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
883 vpriv->old_pop = vcc->pop;
884 vcc->user_back = vpriv;
886 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
887 &ioc_data, vcc, vcc->push);
888 vcc->proto_data = dev_lec[ioc_data.dev_num];
889 vcc->push = lec_push;
893 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
895 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
897 vcc->proto_data = dev_lec[arg];
898 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
901 /* Initialize device. */
902 static int lecd_attach(struct atm_vcc *vcc, int arg)
905 struct lec_priv *priv;
912 if (arg >= MAX_LEC_ITF)
914 #else /* Reserve the top NUM_TR_DEVS for TR */
915 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
922 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
925 size = sizeof(struct lec_priv);
928 dev_lec[i] = alloc_trdev(size);
931 dev_lec[i] = alloc_etherdev(size);
934 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
935 if (register_netdev(dev_lec[i])) {
936 free_netdev(dev_lec[i]);
940 priv = dev_lec[i]->priv;
941 priv->is_trdev = is_trdev;
942 lec_init(dev_lec[i]);
944 priv = dev_lec[i]->priv;
949 priv->itfnum = i; /* LANE2 addition */
951 vcc->dev = &lecatm_dev;
952 vcc_insert_socket(sk_atm(vcc));
954 vcc->proto_data = dev_lec[i];
955 set_bit(ATM_VF_META, &vcc->flags);
956 set_bit(ATM_VF_READY, &vcc->flags);
958 /* Set default values to these variables */
959 priv->maximum_unknown_frame_count = 1;
960 priv->max_unknown_frame_time = (1 * HZ);
961 priv->vcc_timeout_period = (1200 * HZ);
962 priv->max_retry_count = 1;
963 priv->aging_time = (300 * HZ);
964 priv->forward_delay_time = (15 * HZ);
965 priv->topology_change = 0;
966 priv->arp_response_time = (1 * HZ);
967 priv->flush_timeout = (4 * HZ);
968 priv->path_switching_delay = (6 * HZ);
970 if (dev_lec[i]->flags & IFF_UP) {
971 netif_start_queue(dev_lec[i]);
973 __module_get(THIS_MODULE);
977 #ifdef CONFIG_PROC_FS
978 static char *lec_arp_get_status_string(unsigned char status)
980 static char *lec_arp_status_string[] = {
985 "ESI_FLUSH_PENDING ",
989 if (status > ESI_FORWARD_DIRECT)
990 status = 3; /* ESI_UNDEFINED */
991 return lec_arp_status_string[status];
994 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
998 for (i = 0; i < ETH_ALEN; i++)
999 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
1000 seq_printf(seq, " ");
1001 for (i = 0; i < ATM_ESA_LEN; i++)
1002 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
1003 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
1004 entry->flags & 0xffff);
1006 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
1008 seq_printf(seq, " ");
1009 if (entry->recv_vcc) {
1010 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1011 entry->recv_vcc->vci);
1013 seq_putc(seq, '\n');
1017 unsigned long flags;
1018 struct lec_priv *locked;
1019 struct hlist_node *node;
1020 struct net_device *dev;
1026 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
1029 struct hlist_node *e = state->node;
1030 struct lec_arp_table *tmp;
1034 if (e == (void *)1) {
1039 hlist_for_each_entry_from(tmp, e, next) {
1045 return (*l < 0) ? state : NULL;
1048 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
1049 struct lec_priv *priv)
1054 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
1055 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1059 state->arp_table = p;
1063 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1064 struct lec_priv *priv)
1066 struct hlist_head *lec_misc_tables[] = {
1067 &priv->lec_arp_empty_ones,
1068 &priv->lec_no_forward,
1074 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1075 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1079 state->misc_table = q;
1083 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1084 struct lec_priv *priv)
1086 if (!state->locked) {
1087 state->locked = priv;
1088 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1090 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1091 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1092 state->locked = NULL;
1093 /* Partial state reset for the next time we get called */
1094 state->arp_table = state->misc_table = 0;
1096 return state->locked;
1099 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1101 struct net_device *dev;
1104 dev = state->dev ? state->dev : dev_lec[state->itf];
1105 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1108 /* Partial state reset for the next time we get called */
1115 static void *lec_get_idx(struct lec_state *state, loff_t l)
1119 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1120 v = lec_itf_walk(state, &l);
1127 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1129 struct lec_state *state = seq->private;
1133 state->locked = NULL;
1134 state->arp_table = 0;
1135 state->misc_table = 0;
1136 state->node = (void *)1;
1138 return *pos ? lec_get_idx(state, *pos) : (void *)1;
1141 static void lec_seq_stop(struct seq_file *seq, void *v)
1143 struct lec_state *state = seq->private;
1146 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1148 dev_put(state->dev);
1152 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1154 struct lec_state *state = seq->private;
1156 v = lec_get_idx(state, 1);
1157 *pos += !!PTR_ERR(v);
1161 static int lec_seq_show(struct seq_file *seq, void *v)
1163 static char lec_banner[] = "Itf MAC ATM destination"
1165 "VPI/VCI Recv VPI/VCI\n";
1168 seq_puts(seq, lec_banner);
1170 struct lec_state *state = seq->private;
1171 struct net_device *dev = state->dev;
1172 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1174 seq_printf(seq, "%s ", dev->name);
1175 lec_info(seq, entry);
1180 static struct seq_operations lec_seq_ops = {
1181 .start = lec_seq_start,
1182 .next = lec_seq_next,
1183 .stop = lec_seq_stop,
1184 .show = lec_seq_show,
1187 static int lec_seq_open(struct inode *inode, struct file *file)
1189 struct lec_state *state;
1190 struct seq_file *seq;
1193 state = kmalloc(sizeof(*state), GFP_KERNEL);
1199 rc = seq_open(file, &lec_seq_ops);
1202 seq = file->private_data;
1203 seq->private = state;
1212 static int lec_seq_release(struct inode *inode, struct file *file)
1214 return seq_release_private(inode, file);
1217 static const struct file_operations lec_seq_fops = {
1218 .owner = THIS_MODULE,
1219 .open = lec_seq_open,
1221 .llseek = seq_lseek,
1222 .release = lec_seq_release,
1226 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1228 struct atm_vcc *vcc = ATM_SD(sock);
1235 if (!capable(CAP_NET_ADMIN))
1239 return -ENOIOCTLCMD;
1244 err = lecd_attach(vcc, (int)arg);
1246 sock->state = SS_CONNECTED;
1249 err = lec_mcast_attach(vcc, (int)arg);
1252 err = lec_vcc_attach(vcc, (void __user *)arg);
1259 static struct atm_ioctl lane_ioctl_ops = {
1260 .owner = THIS_MODULE,
1261 .ioctl = lane_ioctl,
1264 static int __init lane_module_init(void)
1266 #ifdef CONFIG_PROC_FS
1267 struct proc_dir_entry *p;
1269 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1271 p->proc_fops = &lec_seq_fops;
1274 register_atm_ioctl(&lane_ioctl_ops);
1275 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1279 static void __exit lane_module_cleanup(void)
1282 struct lec_priv *priv;
1284 remove_proc_entry("lec", atm_proc_root);
1286 deregister_atm_ioctl(&lane_ioctl_ops);
1288 for (i = 0; i < MAX_LEC_ITF; i++) {
1289 if (dev_lec[i] != NULL) {
1290 priv = (struct lec_priv *)dev_lec[i]->priv;
1291 unregister_netdev(dev_lec[i]);
1292 free_netdev(dev_lec[i]);
1300 module_init(lane_module_init);
1301 module_exit(lane_module_cleanup);
1304 * LANE2: 3.1.3, LE_RESOLVE.request
1305 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1306 * If sizeoftlvs == NULL the default TLVs associated with with this
1308 * If dst_mac == NULL, targetless LE_ARP will be sent
1310 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1311 u8 **tlvs, u32 *sizeoftlvs)
1313 unsigned long flags;
1314 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1315 struct lec_arp_table *table;
1316 struct sk_buff *skb;
1320 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1321 table = lec_arp_find(priv, dst_mac);
1322 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1326 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1330 *sizeoftlvs = table->sizeoftlvs;
1335 if (sizeoftlvs == NULL)
1336 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1339 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1342 skb->len = *sizeoftlvs;
1343 memcpy(skb->data, *tlvs, *sizeoftlvs);
1344 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1350 * LANE2: 3.1.4, LE_ASSOCIATE.request
1351 * Associate the *tlvs with the *lan_dst address.
1352 * Will overwrite any previous association
1353 * Returns 1 for success, 0 for failure (out of memory)
1356 static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1357 u8 *tlvs, u32 sizeoftlvs)
1360 struct sk_buff *skb;
1361 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1363 if (compare_ether_addr(lan_dst, dev->dev_addr))
1364 return (0); /* not our mac address */
1366 kfree(priv->tlvs); /* NULL if there was no previous association */
1368 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1369 if (priv->tlvs == NULL)
1371 priv->sizeoftlvs = sizeoftlvs;
1373 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1376 skb->len = sizeoftlvs;
1377 memcpy(skb->data, tlvs, sizeoftlvs);
1378 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1380 printk("lec.c: lane2_associate_req() failed\n");
1382 * If the previous association has changed we must
1383 * somehow notify other LANE entities about the change
1389 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1392 static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1393 u8 *tlvs, u32 sizeoftlvs)
1398 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1400 * Why have the TLVs in LE_ARP entries
1401 * since we do not use them? When you
1402 * uncomment this code, make sure the
1403 * TLVs get freed when entry is killed
1405 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1408 return; /* should not happen */
1412 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1413 if (entry->tlvs == NULL)
1415 entry->sizeoftlvs = sizeoftlvs;
1418 printk("lec.c: lane2_associate_ind()\n");
1419 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1420 while (i < sizeoftlvs)
1421 printk("%02x ", tlvs[i++]);
1426 /* tell MPOA about the TLVs we saw */
1427 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1428 priv->lane2_ops->associate_indicator(dev, mac_addr,
1435 * Here starts what used to lec_arpc.c
1437 * lec_arpc.c was added here when making
1438 * lane client modular. October 1997
1441 #include <linux/types.h>
1442 #include <linux/timer.h>
1443 #include <asm/param.h>
1444 #include <asm/atomic.h>
1445 #include <linux/inetdevice.h>
1446 #include <net/route.h>
1449 #define DPRINTK(format,args...)
1451 #define DPRINTK printk
1454 #define DEBUG_ARP_TABLE 0
1456 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1458 static void lec_arp_check_expire(struct work_struct *work);
1459 static void lec_arp_expire_arp(unsigned long data);
1465 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1468 * Initialization of arp-cache
1470 static void lec_arp_init(struct lec_priv *priv)
1474 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1475 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1477 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1478 INIT_HLIST_HEAD(&priv->lec_no_forward);
1479 INIT_HLIST_HEAD(&priv->mcast_fwds);
1480 spin_lock_init(&priv->lec_arp_lock);
1481 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
1482 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1485 static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1488 struct atm_vcc *vcc = entry->vcc;
1489 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1490 struct net_device *dev = (struct net_device *)vcc->proto_data;
1492 vcc->pop = vpriv->old_pop;
1494 netif_wake_queue(dev);
1496 vcc->user_back = NULL;
1497 vcc->push = entry->old_push;
1498 vcc_release_async(vcc, -EPIPE);
1501 if (entry->recv_vcc) {
1502 entry->recv_vcc->push = entry->old_recv_push;
1503 vcc_release_async(entry->recv_vcc, -EPIPE);
1504 entry->recv_vcc = NULL;
1509 * Insert entry to lec_arp_table
1510 * LANE2: Add to the end of the list to satisfy 8.1.13
1513 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1515 struct hlist_head *tmp;
1517 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1518 hlist_add_head(&entry->next, tmp);
1520 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1521 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1522 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1523 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1527 * Remove entry from lec_arp_table
1530 lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1532 struct hlist_node *node;
1533 struct lec_arp_table *entry;
1534 int i, remove_vcc = 1;
1540 hlist_del(&to_remove->next);
1541 del_timer(&to_remove->timer);
1543 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1544 if (to_remove->status >= ESI_FLUSH_PENDING) {
1546 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1548 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1549 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1550 if (memcmp(to_remove->atm_addr,
1551 entry->atm_addr, ATM_ESA_LEN) == 0) {
1558 lec_arp_clear_vccs(to_remove);
1560 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1562 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1563 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1564 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1565 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1570 static char *get_status_string(unsigned char st)
1574 return "ESI_UNKNOWN";
1575 case ESI_ARP_PENDING:
1576 return "ESI_ARP_PENDING";
1577 case ESI_VC_PENDING:
1578 return "ESI_VC_PENDING";
1579 case ESI_FLUSH_PENDING:
1580 return "ESI_FLUSH_PENDING";
1581 case ESI_FORWARD_DIRECT:
1582 return "ESI_FORWARD_DIRECT";
1588 static void dump_arp_table(struct lec_priv *priv)
1590 struct hlist_node *node;
1591 struct lec_arp_table *rulla;
1595 printk("Dump %p:\n", priv);
1596 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1597 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1599 offset += sprintf(buf, "%d: %p\n", i, rulla);
1600 offset += sprintf(buf + offset, "Mac:");
1601 for (j = 0; j < ETH_ALEN; j++) {
1602 offset += sprintf(buf + offset,
1604 rulla->mac_addr[j] & 0xff);
1606 offset += sprintf(buf + offset, "Atm:");
1607 for (j = 0; j < ATM_ESA_LEN; j++) {
1608 offset += sprintf(buf + offset,
1610 rulla->atm_addr[j] & 0xff);
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->
1618 rulla->recv_vcc ? rulla->recv_vcc->
1619 vci : 0, rulla->last_used,
1620 rulla->timestamp, rulla->no_tries);
1622 sprintf(buf + offset,
1623 "Flags:%x, Packets_flooded:%x, Status: %s ",
1624 rulla->flags, rulla->packets_flooded,
1625 get_status_string(rulla->status));
1626 printk("%s\n", buf);
1630 if (!hlist_empty(&priv->lec_no_forward))
1631 printk("No forward\n");
1632 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1634 offset += sprintf(buf + offset, "Mac:");
1635 for (j = 0; j < ETH_ALEN; j++) {
1636 offset += sprintf(buf + offset, "%2.2x ",
1637 rulla->mac_addr[j] & 0xff);
1639 offset += sprintf(buf + offset, "Atm:");
1640 for (j = 0; j < ATM_ESA_LEN; j++) {
1641 offset += sprintf(buf + offset, "%2.2x ",
1642 rulla->atm_addr[j] & 0xff);
1644 offset += sprintf(buf + offset,
1645 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1646 rulla->vcc ? rulla->vcc->vpi : 0,
1647 rulla->vcc ? rulla->vcc->vci : 0,
1648 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1649 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1651 rulla->timestamp, rulla->no_tries);
1652 offset += sprintf(buf + offset,
1653 "Flags:%x, Packets_flooded:%x, Status: %s ",
1654 rulla->flags, rulla->packets_flooded,
1655 get_status_string(rulla->status));
1656 printk("%s\n", buf);
1659 if (!hlist_empty(&priv->lec_arp_empty_ones))
1660 printk("Empty ones\n");
1661 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1663 offset += sprintf(buf + offset, "Mac:");
1664 for (j = 0; j < ETH_ALEN; j++) {
1665 offset += sprintf(buf + offset, "%2.2x ",
1666 rulla->mac_addr[j] & 0xff);
1668 offset += sprintf(buf + offset, "Atm:");
1669 for (j = 0; j < ATM_ESA_LEN; j++) {
1670 offset += sprintf(buf + offset, "%2.2x ",
1671 rulla->atm_addr[j] & 0xff);
1673 offset += sprintf(buf + offset,
1674 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1675 rulla->vcc ? rulla->vcc->vpi : 0,
1676 rulla->vcc ? rulla->vcc->vci : 0,
1677 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1678 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1680 rulla->timestamp, rulla->no_tries);
1681 offset += sprintf(buf + offset,
1682 "Flags:%x, Packets_flooded:%x, Status: %s ",
1683 rulla->flags, rulla->packets_flooded,
1684 get_status_string(rulla->status));
1688 if (!hlist_empty(&priv->mcast_fwds))
1689 printk("Multicast Forward VCCs\n");
1690 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1692 offset += sprintf(buf + offset, "Mac:");
1693 for (j = 0; j < ETH_ALEN; j++) {
1694 offset += sprintf(buf + offset, "%2.2x ",
1695 rulla->mac_addr[j] & 0xff);
1697 offset += sprintf(buf + offset, "Atm:");
1698 for (j = 0; j < ATM_ESA_LEN; j++) {
1699 offset += sprintf(buf + offset, "%2.2x ",
1700 rulla->atm_addr[j] & 0xff);
1702 offset += sprintf(buf + offset,
1703 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1704 rulla->vcc ? rulla->vcc->vpi : 0,
1705 rulla->vcc ? rulla->vcc->vci : 0,
1706 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1707 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1709 rulla->timestamp, rulla->no_tries);
1710 offset += sprintf(buf + offset,
1711 "Flags:%x, Packets_flooded:%x, Status: %s ",
1712 rulla->flags, rulla->packets_flooded,
1713 get_status_string(rulla->status));
1714 printk("%s\n", buf);
1719 #define dump_arp_table(priv) do { } while (0)
1723 * Destruction of arp-cache
1725 static void lec_arp_destroy(struct lec_priv *priv)
1727 unsigned long flags;
1728 struct hlist_node *node, *next;
1729 struct lec_arp_table *entry;
1732 cancel_rearming_delayed_work(&priv->lec_arp_work);
1735 * Remove all entries
1738 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1739 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1740 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1741 lec_arp_remove(priv, entry);
1744 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1747 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1748 del_timer_sync(&entry->timer);
1749 lec_arp_clear_vccs(entry);
1750 hlist_del(&entry->next);
1753 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1755 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1756 del_timer_sync(&entry->timer);
1757 lec_arp_clear_vccs(entry);
1758 hlist_del(&entry->next);
1761 INIT_HLIST_HEAD(&priv->lec_no_forward);
1763 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1764 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1765 lec_arp_clear_vccs(entry);
1766 hlist_del(&entry->next);
1769 INIT_HLIST_HEAD(&priv->mcast_fwds);
1770 priv->mcast_vcc = NULL;
1771 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1775 * Find entry by mac_address
1777 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1778 unsigned char *mac_addr)
1780 struct hlist_node *node;
1781 struct hlist_head *head;
1782 struct lec_arp_table *entry;
1784 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1785 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1786 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1788 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1789 hlist_for_each_entry(entry, node, head, next) {
1790 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1797 static struct lec_arp_table *make_entry(struct lec_priv *priv,
1798 unsigned char *mac_addr)
1800 struct lec_arp_table *to_return;
1802 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1804 printk("LEC: Arp entry kmalloc failed\n");
1807 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1808 INIT_HLIST_NODE(&to_return->next);
1809 init_timer(&to_return->timer);
1810 to_return->timer.function = lec_arp_expire_arp;
1811 to_return->timer.data = (unsigned long)to_return;
1812 to_return->last_used = jiffies;
1813 to_return->priv = priv;
1814 skb_queue_head_init(&to_return->tx_wait);
1815 atomic_set(&to_return->usage, 1);
1819 /* Arp sent timer expired */
1820 static void lec_arp_expire_arp(unsigned long data)
1822 struct lec_arp_table *entry;
1824 entry = (struct lec_arp_table *)data;
1826 DPRINTK("lec_arp_expire_arp\n");
1827 if (entry->status == ESI_ARP_PENDING) {
1828 if (entry->no_tries <= entry->priv->max_retry_count) {
1829 if (entry->is_rdesc)
1830 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1831 entry->mac_addr, NULL, NULL);
1833 send_to_lecd(entry->priv, l_arp_xmt,
1834 entry->mac_addr, NULL, NULL);
1837 mod_timer(&entry->timer, jiffies + (1 * HZ));
1841 /* Unknown/unused vcc expire, remove associated entry */
1842 static void lec_arp_expire_vcc(unsigned long data)
1844 unsigned long flags;
1845 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1846 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1848 del_timer(&to_remove->timer);
1850 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1852 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1853 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1855 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1856 hlist_del(&to_remove->next);
1857 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1859 lec_arp_clear_vccs(to_remove);
1860 lec_arp_put(to_remove);
1866 * 2. For each entry, delete entries that have aged past the age limit.
1867 * 3. For each entry, depending on the status of the entry, perform
1868 * the following maintenance.
1869 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1870 * tick_count is above the max_unknown_frame_time, clear
1871 * the tick_count to zero and clear the packets_flooded counter
1872 * to zero. This supports the packet rate limit per address
1873 * while flooding unknowns.
1874 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1875 * than or equal to the path_switching_delay, change the status
1876 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1877 * regardless of the progress of the flush protocol.
1879 static void lec_arp_check_expire(struct work_struct *work)
1881 unsigned long flags;
1882 struct lec_priv *priv =
1883 container_of(work, struct lec_priv, lec_arp_work.work);
1884 struct hlist_node *node, *next;
1885 struct lec_arp_table *entry;
1887 unsigned long time_to_check;
1890 DPRINTK("lec_arp_check_expire %p\n", priv);
1893 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1894 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1895 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1896 if ((entry->flags) & LEC_REMOTE_FLAG &&
1897 priv->topology_change)
1898 time_to_check = priv->forward_delay_time;
1900 time_to_check = priv->aging_time;
1902 DPRINTK("About to expire: %lx - %lx > %lx\n",
1903 now, entry->last_used, time_to_check);
1904 if (time_after(now, entry->last_used + time_to_check)
1905 && !(entry->flags & LEC_PERMANENT_FLAG)
1906 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1908 DPRINTK("LEC:Entry timed out\n");
1909 lec_arp_remove(priv, entry);
1912 /* Something else */
1913 if ((entry->status == ESI_VC_PENDING ||
1914 entry->status == ESI_ARP_PENDING)
1915 && time_after_eq(now,
1918 max_unknown_frame_time)) {
1919 entry->timestamp = jiffies;
1920 entry->packets_flooded = 0;
1921 if (entry->status == ESI_VC_PENDING)
1922 send_to_lecd(priv, l_svc_setup,
1927 if (entry->status == ESI_FLUSH_PENDING
1929 time_after_eq(now, entry->timestamp +
1930 priv->path_switching_delay)) {
1931 struct sk_buff *skb;
1932 struct atm_vcc *vcc = entry->vcc;
1934 lec_arp_hold(entry);
1935 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1936 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1937 lec_send(vcc, skb, entry->priv);
1938 entry->last_used = jiffies;
1939 entry->status = ESI_FORWARD_DIRECT;
1946 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1948 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1952 * Try to find vcc where mac_address is attached.
1955 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1956 unsigned char *mac_to_find, int is_rdesc,
1957 struct lec_arp_table **ret_entry)
1959 unsigned long flags;
1960 struct lec_arp_table *entry;
1961 struct atm_vcc *found;
1963 if (mac_to_find[0] & 0x01) {
1964 switch (priv->lane_version) {
1966 return priv->mcast_vcc;
1968 case 2: /* LANE2 wants arp for multicast addresses */
1969 if (!compare_ether_addr(mac_to_find, bus_mac))
1970 return priv->mcast_vcc;
1977 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1978 entry = lec_arp_find(priv, mac_to_find);
1981 if (entry->status == ESI_FORWARD_DIRECT) {
1983 entry->last_used = jiffies;
1984 lec_arp_hold(entry);
1990 * If the LE_ARP cache entry is still pending, reset count to 0
1991 * so another LE_ARP request can be made for this frame.
1993 if (entry->status == ESI_ARP_PENDING) {
1994 entry->no_tries = 0;
1997 * Data direct VC not yet set up, check to see if the unknown
1998 * frame count is greater than the limit. If the limit has
1999 * not been reached, allow the caller to send packet to
2002 if (entry->status != ESI_FLUSH_PENDING &&
2003 entry->packets_flooded <
2004 priv->maximum_unknown_frame_count) {
2005 entry->packets_flooded++;
2006 DPRINTK("LEC_ARP: Flooding..\n");
2007 found = priv->mcast_vcc;
2011 * We got here because entry->status == ESI_FLUSH_PENDING
2012 * or BUS flood limit was reached for an entry which is
2013 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2015 lec_arp_hold(entry);
2017 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
2021 /* No matching entry was found */
2022 entry = make_entry(priv, mac_to_find);
2023 DPRINTK("LEC_ARP: Making entry\n");
2025 found = priv->mcast_vcc;
2028 lec_arp_add(priv, entry);
2029 /* We want arp-request(s) to be sent */
2030 entry->packets_flooded = 1;
2031 entry->status = ESI_ARP_PENDING;
2032 entry->no_tries = 1;
2033 entry->last_used = entry->timestamp = jiffies;
2034 entry->is_rdesc = is_rdesc;
2035 if (entry->is_rdesc)
2036 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2039 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2040 entry->timer.expires = jiffies + (1 * HZ);
2041 entry->timer.function = lec_arp_expire_arp;
2042 add_timer(&entry->timer);
2043 found = priv->mcast_vcc;
2047 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2052 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2053 unsigned long permanent)
2055 unsigned long flags;
2056 struct hlist_node *node, *next;
2057 struct lec_arp_table *entry;
2060 DPRINTK("lec_addr_delete\n");
2061 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2062 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2063 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2064 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2066 !(entry->flags & LEC_PERMANENT_FLAG))) {
2067 lec_arp_remove(priv, entry);
2070 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2074 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2079 * Notifies: Response to arp_request (atm_addr != NULL)
2082 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2083 unsigned char *atm_addr, unsigned long remoteflag,
2084 unsigned int targetless_le_arp)
2086 unsigned long flags;
2087 struct hlist_node *node, *next;
2088 struct lec_arp_table *entry, *tmp;
2091 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2092 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2093 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2094 mac_addr[4], mac_addr[5]);
2096 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2097 entry = lec_arp_find(priv, mac_addr);
2098 if (entry == NULL && targetless_le_arp)
2100 * LANE2: ignore targetless LE_ARPs for which
2101 * we have no entry in the cache. 7.1.30
2103 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2104 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2105 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2106 hlist_del(&entry->next);
2107 del_timer(&entry->timer);
2108 tmp = lec_arp_find(priv, mac_addr);
2110 del_timer(&tmp->timer);
2111 tmp->status = ESI_FORWARD_DIRECT;
2112 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2113 tmp->vcc = entry->vcc;
2114 tmp->old_push = entry->old_push;
2115 tmp->last_used = jiffies;
2116 del_timer(&entry->timer);
2120 entry->status = ESI_FORWARD_DIRECT;
2121 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2122 entry->last_used = jiffies;
2123 lec_arp_add(priv, entry);
2126 entry->flags |= LEC_REMOTE_FLAG;
2128 entry->flags &= ~LEC_REMOTE_FLAG;
2129 DPRINTK("After update\n");
2130 dump_arp_table(priv);
2136 entry = lec_arp_find(priv, mac_addr);
2138 entry = make_entry(priv, mac_addr);
2141 entry->status = ESI_UNKNOWN;
2142 lec_arp_add(priv, entry);
2143 /* Temporary, changes before end of function */
2145 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2146 del_timer(&entry->timer);
2147 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2148 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
2150 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2151 /* Vcc to this host exists */
2152 if (tmp->status > ESI_VC_PENDING) {
2154 * ESI_FLUSH_PENDING,
2155 * ESI_FORWARD_DIRECT
2157 entry->vcc = tmp->vcc;
2158 entry->old_push = tmp->old_push;
2160 entry->status = tmp->status;
2166 entry->flags |= LEC_REMOTE_FLAG;
2168 entry->flags &= ~LEC_REMOTE_FLAG;
2169 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2170 entry->status = ESI_VC_PENDING;
2171 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2173 DPRINTK("After update2\n");
2174 dump_arp_table(priv);
2176 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2180 * Notifies: Vcc setup ready
2183 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2184 struct atm_vcc *vcc,
2185 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
2187 unsigned long flags;
2188 struct hlist_node *node;
2189 struct lec_arp_table *entry;
2190 int i, found_entry = 0;
2192 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2193 if (ioc_data->receive == 2) {
2194 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2196 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2198 entry = lec_arp_find(priv, bus_mac);
2200 printk("LEC_ARP: Multicast entry not found!\n");
2203 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2204 entry->recv_vcc = vcc;
2205 entry->old_recv_push = old_push;
2207 entry = make_entry(priv, bus_mac);
2210 del_timer(&entry->timer);
2211 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2212 entry->recv_vcc = vcc;
2213 entry->old_recv_push = old_push;
2214 hlist_add_head(&entry->next, &priv->mcast_fwds);
2216 } else if (ioc_data->receive == 1) {
2218 * Vcc which we don't want to make default vcc,
2222 ("LEC_ARP:Attaching data direct, not default: "
2223 "%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",
2224 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2225 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2226 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2227 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2228 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2229 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2230 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2231 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2232 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2233 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2234 entry = make_entry(priv, bus_mac);
2237 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2238 memset(entry->mac_addr, 0, ETH_ALEN);
2239 entry->recv_vcc = vcc;
2240 entry->old_recv_push = old_push;
2241 entry->status = ESI_UNKNOWN;
2242 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2243 entry->timer.function = lec_arp_expire_vcc;
2244 hlist_add_head(&entry->next, &priv->lec_no_forward);
2245 add_timer(&entry->timer);
2246 dump_arp_table(priv);
2250 ("LEC_ARP:Attaching data direct, default: "
2251 "%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",
2252 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2253 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2254 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2255 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2256 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2257 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2258 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2259 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2260 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2261 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2262 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2263 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2265 (ioc_data->atm_addr, entry->atm_addr,
2266 ATM_ESA_LEN) == 0) {
2267 DPRINTK("LEC_ARP: Attaching data direct\n");
2268 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2269 entry->vcc ? entry->vcc->vci : 0,
2270 entry->recv_vcc ? entry->recv_vcc->
2273 del_timer(&entry->timer);
2275 entry->old_push = old_push;
2276 if (entry->status == ESI_VC_PENDING) {
2277 if (priv->maximum_unknown_frame_count
2282 entry->timestamp = jiffies;
2286 send_to_lecd(priv, l_flush_xmt,
2294 * They were forming a connection
2295 * to us, and we to them. Our
2296 * ATM address is numerically lower
2297 * than theirs, so we make connection
2298 * we formed into default VCC (8.1.11).
2299 * Connection they made gets torn
2300 * down. This might confuse some
2301 * clients. Can be changed if
2302 * someone reports trouble...
2310 DPRINTK("After vcc was added\n");
2311 dump_arp_table(priv);
2315 * Not found, snatch address from first data packet that arrives
2318 entry = make_entry(priv, bus_mac);
2322 entry->old_push = old_push;
2323 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2324 memset(entry->mac_addr, 0, ETH_ALEN);
2325 entry->status = ESI_UNKNOWN;
2326 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
2327 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2328 entry->timer.function = lec_arp_expire_vcc;
2329 add_timer(&entry->timer);
2330 DPRINTK("After vcc was added\n");
2331 dump_arp_table(priv);
2333 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2336 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2338 unsigned long flags;
2339 struct hlist_node *node;
2340 struct lec_arp_table *entry;
2343 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
2345 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2346 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2347 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2348 if (entry->flush_tran_id == tran_id
2349 && entry->status == ESI_FLUSH_PENDING) {
2350 struct sk_buff *skb;
2351 struct atm_vcc *vcc = entry->vcc;
2353 lec_arp_hold(entry);
2354 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2355 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2356 lec_send(vcc, skb, entry->priv);
2357 entry->last_used = jiffies;
2358 entry->status = ESI_FORWARD_DIRECT;
2360 DPRINTK("LEC_ARP: Flushed\n");
2365 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2366 dump_arp_table(priv);
2370 lec_set_flush_tran_id(struct lec_priv *priv,
2371 unsigned char *atm_addr, unsigned long tran_id)
2373 unsigned long flags;
2374 struct hlist_node *node;
2375 struct lec_arp_table *entry;
2378 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2379 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2380 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2381 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2382 entry->flush_tran_id = tran_id;
2383 DPRINTK("Set flush transaction id to %lx for %p\n",
2387 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2390 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2392 unsigned long flags;
2393 unsigned char mac_addr[] = {
2394 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2396 struct lec_arp_table *to_add;
2397 struct lec_vcc_priv *vpriv;
2400 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2403 vpriv->old_pop = vcc->pop;
2404 vcc->user_back = vpriv;
2406 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2407 to_add = make_entry(priv, mac_addr);
2409 vcc->pop = vpriv->old_pop;
2414 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2415 to_add->status = ESI_FORWARD_DIRECT;
2416 to_add->flags |= LEC_PERMANENT_FLAG;
2418 to_add->old_push = vcc->push;
2419 vcc->push = lec_push;
2420 priv->mcast_vcc = vcc;
2421 lec_arp_add(priv, to_add);
2423 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2427 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2429 unsigned long flags;
2430 struct hlist_node *node, *next;
2431 struct lec_arp_table *entry;
2434 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2435 dump_arp_table(priv);
2437 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2439 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2440 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2441 if (vcc == entry->vcc) {
2442 lec_arp_remove(priv, entry);
2444 if (priv->mcast_vcc == vcc) {
2445 priv->mcast_vcc = NULL;
2451 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2452 if (entry->vcc == vcc) {
2453 lec_arp_clear_vccs(entry);
2454 del_timer(&entry->timer);
2455 hlist_del(&entry->next);
2460 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
2461 if (entry->recv_vcc == vcc) {
2462 lec_arp_clear_vccs(entry);
2463 del_timer(&entry->timer);
2464 hlist_del(&entry->next);
2469 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
2470 if (entry->recv_vcc == vcc) {
2471 lec_arp_clear_vccs(entry);
2472 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2473 hlist_del(&entry->next);
2478 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2479 dump_arp_table(priv);
2483 lec_arp_check_empties(struct lec_priv *priv,
2484 struct atm_vcc *vcc, struct sk_buff *skb)
2486 unsigned long flags;
2487 struct hlist_node *node, *next;
2488 struct lec_arp_table *entry, *tmp;
2489 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2492 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2495 src = tr_hdr->h_source;
2498 src = hdr->h_source;
2500 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2501 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2502 if (vcc == entry->vcc) {
2503 del_timer(&entry->timer);
2504 memcpy(entry->mac_addr, src, ETH_ALEN);
2505 entry->status = ESI_FORWARD_DIRECT;
2506 entry->last_used = jiffies;
2507 /* We might have got an entry */
2508 if ((tmp = lec_arp_find(priv, src))) {
2509 lec_arp_remove(priv, tmp);
2512 hlist_del(&entry->next);
2513 lec_arp_add(priv, entry);
2517 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2519 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2522 MODULE_LICENSE("GPL");