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/seq_file.h>
26 /* TokenRing if needed */
28 #include <linux/trdevice.h>
32 #include <linux/atmdev.h>
33 #include <linux/atmlec.h>
35 /* Proxy LEC knows about bridging */
36 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37 #include <linux/if_bridge.h>
38 #include "../bridge/br_private.h"
40 static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
44 #include <linux/module.h>
45 #include <linux/init.h>
49 #include "resources.h"
51 #define DUMP_PACKETS 0 /*
57 #define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
62 static int lec_open(struct net_device *dev);
63 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
64 static int lec_close(struct net_device *dev);
65 static struct net_device_stats *lec_get_stats(struct net_device *dev);
66 static void lec_init(struct net_device *dev);
67 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
68 unsigned char *mac_addr);
69 static int lec_arp_remove(struct lec_priv *priv,
70 struct lec_arp_table *to_remove);
72 static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
73 u8 *tlvs, u32 sizeoftlvs);
74 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
75 u8 **tlvs, u32 *sizeoftlvs);
76 static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
77 u8 *tlvs, u32 sizeoftlvs);
79 static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
80 unsigned long permanent);
81 static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83 static void lec_arp_destroy(struct lec_priv *priv);
84 static void lec_arp_init(struct lec_priv *priv);
85 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
86 unsigned char *mac_to_find,
88 struct lec_arp_table **ret_entry);
89 static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
90 unsigned char *atm_addr, unsigned long remoteflag,
91 unsigned int targetless_le_arp);
92 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94 static void lec_set_flush_tran_id(struct lec_priv *priv,
95 unsigned char *atm_addr,
96 unsigned long tran_id);
97 static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
99 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
101 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
103 /* must be done under lec_arp_lock */
104 static inline void lec_arp_hold(struct lec_arp_table *entry)
106 atomic_inc(&entry->usage);
109 static inline void lec_arp_put(struct lec_arp_table *entry)
111 if (atomic_dec_and_test(&entry->usage))
116 static struct lane2_ops lane2_ops = {
117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
122 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
124 /* Device structures */
125 static struct net_device *dev_lec[MAX_LEC_ITF];
127 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
132 struct lec_priv *priv;
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
155 priv = (struct lec_priv *)dev->priv;
156 atm_force_charge(priv->lecd, skb2->truesize);
157 sk = sk_atm(priv->lecd);
158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
164 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
176 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
179 unsigned int riflen, num_rdsc;
181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
190 return trh->daddr; /* not source routed */
193 return trh->daddr; /* last hop, source routed */
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
208 #endif /* CONFIG_TR */
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
219 static int lec_open(struct net_device *dev)
221 struct lec_priv *priv = (struct lec_priv *)dev->priv;
223 netif_start_queue(dev);
224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
229 static __inline__ void
230 lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 priv->stats.tx_dropped++;
241 priv->stats.tx_packets++;
242 priv->stats.tx_bytes += skb->len;
245 static void lec_tx_timeout(struct net_device *dev)
247 printk(KERN_INFO "%s: tx timeout\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
252 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
254 struct sk_buff *skb2;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv;
256 struct lecdatahdr_8023 *lec_h;
258 struct lec_arp_table *entry;
262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
268 #endif /* DUMP_PACKETS >0 */
270 pr_debug("lec_start_xmit called\n");
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
280 (long)skb_end_pointer(skb));
281 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
289 pr_debug("lec_start_xmit: reallocating skb\n");
290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
319 #if DUMP_PACKETS >= 2
320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
323 #elif DUMP_PACKETS >= 1
324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
327 #endif /* DUMP_PACKETS >= 1 */
331 printk("%s...\n", buf);
332 #endif /* DUMP_PACKETS > 0 */
334 /* Minimum ethernet-frame size */
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
348 priv->stats.tx_dropped++;
353 skb_put(skb, min_frame_size - skb->len);
356 /* Send to right vcc */
360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
374 pr_debug("%s:lec_start_xmit: queuing packet, ",
376 pr_debug("MAC address " MAC_FMT "\n",
377 lec_h->h_dest[0], lec_h->h_dest[1],
378 lec_h->h_dest[2], lec_h->h_dest[3],
379 lec_h->h_dest[4], lec_h->h_dest[5]);
380 skb_queue_tail(&entry->tx_wait, skb);
383 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
385 pr_debug("MAC address " MAC_FMT "\n",
386 lec_h->h_dest[0], lec_h->h_dest[1],
387 lec_h->h_dest[2], lec_h->h_dest[3],
388 lec_h->h_dest[4], lec_h->h_dest[5]);
389 priv->stats.tx_dropped++;
395 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
396 #endif /* DUMP_PACKETS > 0 */
398 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
399 pr_debug("lec.c: emptying tx queue, ");
400 pr_debug("MAC address " MAC_FMT "\n",
401 lec_h->h_dest[0], lec_h->h_dest[1],
402 lec_h->h_dest[2], lec_h->h_dest[3],
403 lec_h->h_dest[4], lec_h->h_dest[5]);
404 lec_send(vcc, skb2, priv);
407 lec_send(vcc, skb, priv);
409 if (!atm_may_send(vcc, 0)) {
410 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
413 netif_stop_queue(dev);
416 * vcc->pop() might have occurred in between, making
417 * the vcc usuable again. Since xmit is serialized,
418 * this is the only situation we have to re-test.
421 if (atm_may_send(vcc, 0))
422 netif_wake_queue(dev);
428 dev->trans_start = jiffies;
432 /* The inverse routine to net_open(). */
433 static int lec_close(struct net_device *dev)
435 netif_stop_queue(dev);
440 * Get the current statistics.
441 * This may be called with the card open or closed.
443 static struct net_device_stats *lec_get_stats(struct net_device *dev)
445 return &((struct lec_priv *)dev->priv)->stats;
448 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
451 struct net_device *dev = (struct net_device *)vcc->proto_data;
452 struct lec_priv *priv = (struct lec_priv *)dev->priv;
453 struct atmlec_msg *mesg;
454 struct lec_arp_table *entry;
456 char *tmp; /* FIXME */
458 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
459 mesg = (struct atmlec_msg *)skb->data;
461 tmp += sizeof(struct atmlec_msg);
462 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
463 switch (mesg->type) {
465 for (i = 0; i < 6; i++) {
466 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
470 for (i = 0; i < 6; i++) {
471 dev->dev_addr[i] = 0;
475 lec_addr_delete(priv, mesg->content.normal.atm_addr,
476 mesg->content.normal.flag);
478 case l_topology_change:
479 priv->topology_change = mesg->content.normal.flag;
481 case l_flush_complete:
482 lec_flush_complete(priv, mesg->content.normal.flag);
484 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
485 spin_lock_irqsave(&priv->lec_arp_lock, flags);
486 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
487 lec_arp_remove(priv, entry);
488 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
490 if (mesg->content.normal.no_source_le_narp)
494 lec_arp_update(priv, mesg->content.normal.mac_addr,
495 mesg->content.normal.atm_addr,
496 mesg->content.normal.flag,
497 mesg->content.normal.targetless_le_arp);
498 pr_debug("lec: in l_arp_update\n");
499 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
500 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
502 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
503 tmp, mesg->sizeoftlvs);
507 priv->maximum_unknown_frame_count =
508 mesg->content.config.maximum_unknown_frame_count;
509 priv->max_unknown_frame_time =
510 (mesg->content.config.max_unknown_frame_time * HZ);
511 priv->max_retry_count = mesg->content.config.max_retry_count;
512 priv->aging_time = (mesg->content.config.aging_time * HZ);
513 priv->forward_delay_time =
514 (mesg->content.config.forward_delay_time * HZ);
515 priv->arp_response_time =
516 (mesg->content.config.arp_response_time * HZ);
517 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
518 priv->path_switching_delay =
519 (mesg->content.config.path_switching_delay * HZ);
520 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
521 priv->lane2_ops = NULL;
522 if (priv->lane_version > 1)
523 priv->lane2_ops = &lane2_ops;
524 if (dev->change_mtu(dev, mesg->content.config.mtu))
525 printk("%s: change_mtu to %d failed\n", dev->name,
526 mesg->content.config.mtu);
527 priv->is_proxy = mesg->content.config.is_proxy;
529 case l_flush_tran_id:
530 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
531 mesg->content.normal.flag);
535 (unsigned short)(0xffff & mesg->content.normal.flag);
537 case l_should_bridge:
538 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
540 struct net_bridge_fdb_entry *f;
543 ("%s: bridge zeppelin asks about " MAC_FMT "\n",
545 mesg->content.proxy.mac_addr[0],
546 mesg->content.proxy.mac_addr[1],
547 mesg->content.proxy.mac_addr[2],
548 mesg->content.proxy.mac_addr[3],
549 mesg->content.proxy.mac_addr[4],
550 mesg->content.proxy.mac_addr[5]);
552 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
555 f = br_fdb_get_hook(dev->br_port->br,
556 mesg->content.proxy.mac_addr);
557 if (f != NULL && f->dst->dev != dev
558 && f->dst->state == BR_STATE_FORWARDING) {
559 /* hit from bridge table, send LE_ARP_RESPONSE */
560 struct sk_buff *skb2;
564 ("%s: entry found, responding to zeppelin\n",
567 alloc_skb(sizeof(struct atmlec_msg),
573 skb2->len = sizeof(struct atmlec_msg);
574 skb_copy_to_linear_data(skb2, mesg,
576 atm_force_charge(priv->lecd, skb2->truesize);
577 sk = sk_atm(priv->lecd);
578 skb_queue_tail(&sk->sk_receive_queue, skb2);
579 sk->sk_data_ready(sk, skb2->len);
584 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
587 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
595 static void lec_atm_close(struct atm_vcc *vcc)
598 struct net_device *dev = (struct net_device *)vcc->proto_data;
599 struct lec_priv *priv = (struct lec_priv *)dev->priv;
602 /* Do something needful? */
604 netif_stop_queue(dev);
605 lec_arp_destroy(priv);
607 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
608 printk("%s lec_atm_close: closing with messages pending\n",
610 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
611 atm_return(vcc, skb->truesize);
615 printk("%s: Shut down!\n", dev->name);
616 module_put(THIS_MODULE);
619 static struct atmdev_ops lecdev_ops = {
620 .close = lec_atm_close,
624 static struct atm_dev lecatm_dev = {
627 .number = 999, /* dummy device number */
628 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
632 * LANE2: new argument struct sk_buff *data contains
633 * the LE_ARP based TLVs introduced in the LANE2 spec
636 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
637 unsigned char *mac_addr, unsigned char *atm_addr,
638 struct sk_buff *data)
642 struct atmlec_msg *mesg;
644 if (!priv || !priv->lecd) {
647 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
650 skb->len = sizeof(struct atmlec_msg);
651 mesg = (struct atmlec_msg *)skb->data;
652 memset(mesg, 0, sizeof(struct atmlec_msg));
655 mesg->sizeoftlvs = data->len;
657 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
659 mesg->content.normal.targetless_le_arp = 1;
661 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
663 atm_force_charge(priv->lecd, skb->truesize);
664 sk = sk_atm(priv->lecd);
665 skb_queue_tail(&sk->sk_receive_queue, skb);
666 sk->sk_data_ready(sk, skb->len);
669 pr_debug("lec: about to send %d bytes of data\n", data->len);
670 atm_force_charge(priv->lecd, data->truesize);
671 skb_queue_tail(&sk->sk_receive_queue, data);
672 sk->sk_data_ready(sk, skb->len);
678 /* shamelessly stolen from drivers/net/net_init.c */
679 static int lec_change_mtu(struct net_device *dev, int new_mtu)
681 if ((new_mtu < 68) || (new_mtu > 18190))
687 static void lec_set_multicast_list(struct net_device *dev)
690 * by default, all multicast frames arrive over the bus.
691 * eventually support selective multicast service
696 static void lec_init(struct net_device *dev)
698 dev->change_mtu = lec_change_mtu;
699 dev->open = lec_open;
700 dev->stop = lec_close;
701 dev->hard_start_xmit = lec_start_xmit;
702 dev->tx_timeout = lec_tx_timeout;
704 dev->get_stats = lec_get_stats;
705 dev->set_multicast_list = lec_set_multicast_list;
706 dev->do_ioctl = NULL;
707 printk("%s: Initialized!\n", dev->name);
711 static unsigned char lec_ctrl_magic[] = {
718 #define LEC_DATA_DIRECT_8023 2
719 #define LEC_DATA_DIRECT_8025 3
721 static int lec_is_data_direct(struct atm_vcc *vcc)
723 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
724 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
727 static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
730 struct net_device *dev = (struct net_device *)vcc->proto_data;
731 struct lec_priv *priv = (struct lec_priv *)dev->priv;
737 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
741 pr_debug("%s: null skb\n", dev->name);
742 lec_vcc_close(priv, vcc);
746 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
747 skb->len, priv->lecid);
748 #if DUMP_PACKETS >= 2
749 for (i = 0; i < skb->len && i < 99; i++) {
750 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
752 #elif DUMP_PACKETS >= 1
753 for (i = 0; i < skb->len && i < 30; i++) {
754 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
756 #endif /* DUMP_PACKETS >= 1 */
760 printk("%s...\n", buf);
761 #endif /* DUMP_PACKETS > 0 */
762 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
763 struct sock *sk = sk_atm(vcc);
765 pr_debug("%s: To daemon\n", dev->name);
766 skb_queue_tail(&sk->sk_receive_queue, skb);
767 sk->sk_data_ready(sk, skb->len);
768 } else { /* Data frame, queue to protocol handlers */
769 struct lec_arp_table *entry;
770 unsigned char *src, *dst;
772 atm_return(vcc, skb->truesize);
773 if (*(__be16 *) skb->data == htons(priv->lecid) ||
774 !priv->lecd || !(dev->flags & IFF_UP)) {
776 * Probably looping back, or if lecd is missing,
779 pr_debug("Ignoring frame...\n");
785 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
788 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
791 * If this is a Data Direct VCC, and the VCC does not match
792 * the LE_ARP cache entry, delete the LE_ARP cache entry.
794 spin_lock_irqsave(&priv->lec_arp_lock, flags);
795 if (lec_is_data_direct(vcc)) {
799 ((struct lecdatahdr_8025 *)skb->data)->
804 ((struct lecdatahdr_8023 *)skb->data)->
806 entry = lec_arp_find(priv, src);
807 if (entry && entry->vcc != vcc) {
808 lec_arp_remove(priv, entry);
812 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
814 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
815 !priv->is_proxy && /* Proxy wants all the packets */
816 memcmp(dst, dev->dev_addr, dev->addr_len)) {
820 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
821 lec_arp_check_empties(priv, vcc, skb);
823 skb_pull(skb, 2); /* skip lec_id */
826 skb->protocol = tr_type_trans(skb, dev);
829 skb->protocol = eth_type_trans(skb, dev);
830 priv->stats.rx_packets++;
831 priv->stats.rx_bytes += skb->len;
832 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
837 static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
839 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
840 struct net_device *dev = skb->dev;
843 printk("lec_pop(): vpriv = NULL!?!?!?\n");
847 vpriv->old_pop(vcc, skb);
849 if (vpriv->xoff && atm_may_send(vcc, 0)) {
851 if (netif_running(dev) && netif_queue_stopped(dev))
852 netif_wake_queue(dev);
856 static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
858 struct lec_vcc_priv *vpriv;
860 struct atmlec_ioc ioc_data;
862 /* Lecd must be up in this case */
863 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
864 if (bytes_left != 0) {
866 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
869 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
870 !dev_lec[ioc_data.dev_num])
872 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
875 vpriv->old_pop = vcc->pop;
876 vcc->user_back = vpriv;
878 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
879 &ioc_data, vcc, vcc->push);
880 vcc->proto_data = dev_lec[ioc_data.dev_num];
881 vcc->push = lec_push;
885 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
887 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
889 vcc->proto_data = dev_lec[arg];
890 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
893 /* Initialize device. */
894 static int lecd_attach(struct atm_vcc *vcc, int arg)
897 struct lec_priv *priv;
904 if (arg >= MAX_LEC_ITF)
906 #else /* Reserve the top NUM_TR_DEVS for TR */
907 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
914 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
917 size = sizeof(struct lec_priv);
920 dev_lec[i] = alloc_trdev(size);
923 dev_lec[i] = alloc_etherdev(size);
926 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
927 if (register_netdev(dev_lec[i])) {
928 free_netdev(dev_lec[i]);
932 priv = dev_lec[i]->priv;
933 priv->is_trdev = is_trdev;
934 lec_init(dev_lec[i]);
936 priv = dev_lec[i]->priv;
941 priv->itfnum = i; /* LANE2 addition */
943 vcc->dev = &lecatm_dev;
944 vcc_insert_socket(sk_atm(vcc));
946 vcc->proto_data = dev_lec[i];
947 set_bit(ATM_VF_META, &vcc->flags);
948 set_bit(ATM_VF_READY, &vcc->flags);
950 /* Set default values to these variables */
951 priv->maximum_unknown_frame_count = 1;
952 priv->max_unknown_frame_time = (1 * HZ);
953 priv->vcc_timeout_period = (1200 * HZ);
954 priv->max_retry_count = 1;
955 priv->aging_time = (300 * HZ);
956 priv->forward_delay_time = (15 * HZ);
957 priv->topology_change = 0;
958 priv->arp_response_time = (1 * HZ);
959 priv->flush_timeout = (4 * HZ);
960 priv->path_switching_delay = (6 * HZ);
962 if (dev_lec[i]->flags & IFF_UP) {
963 netif_start_queue(dev_lec[i]);
965 __module_get(THIS_MODULE);
969 #ifdef CONFIG_PROC_FS
970 static char *lec_arp_get_status_string(unsigned char status)
972 static char *lec_arp_status_string[] = {
977 "ESI_FLUSH_PENDING ",
981 if (status > ESI_FORWARD_DIRECT)
982 status = 3; /* ESI_UNDEFINED */
983 return lec_arp_status_string[status];
986 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
990 for (i = 0; i < ETH_ALEN; i++)
991 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
992 seq_printf(seq, " ");
993 for (i = 0; i < ATM_ESA_LEN; i++)
994 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
995 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
996 entry->flags & 0xffff);
998 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
1000 seq_printf(seq, " ");
1001 if (entry->recv_vcc) {
1002 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1003 entry->recv_vcc->vci);
1005 seq_putc(seq, '\n');
1009 unsigned long flags;
1010 struct lec_priv *locked;
1011 struct hlist_node *node;
1012 struct net_device *dev;
1018 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
1021 struct hlist_node *e = state->node;
1022 struct lec_arp_table *tmp;
1026 if (e == (void *)1) {
1031 hlist_for_each_entry_from(tmp, e, next) {
1037 return (*l < 0) ? state : NULL;
1040 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
1041 struct lec_priv *priv)
1046 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
1047 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1051 state->arp_table = p;
1055 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1056 struct lec_priv *priv)
1058 struct hlist_head *lec_misc_tables[] = {
1059 &priv->lec_arp_empty_ones,
1060 &priv->lec_no_forward,
1066 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1067 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1071 state->misc_table = q;
1075 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1076 struct lec_priv *priv)
1078 if (!state->locked) {
1079 state->locked = priv;
1080 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1082 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1083 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1084 state->locked = NULL;
1085 /* Partial state reset for the next time we get called */
1086 state->arp_table = state->misc_table = 0;
1088 return state->locked;
1091 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1093 struct net_device *dev;
1096 dev = state->dev ? state->dev : dev_lec[state->itf];
1097 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1100 /* Partial state reset for the next time we get called */
1107 static void *lec_get_idx(struct lec_state *state, loff_t l)
1111 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1112 v = lec_itf_walk(state, &l);
1119 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1121 struct lec_state *state = seq->private;
1125 state->locked = NULL;
1126 state->arp_table = 0;
1127 state->misc_table = 0;
1128 state->node = (void *)1;
1130 return *pos ? lec_get_idx(state, *pos) : (void *)1;
1133 static void lec_seq_stop(struct seq_file *seq, void *v)
1135 struct lec_state *state = seq->private;
1138 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1140 dev_put(state->dev);
1144 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1146 struct lec_state *state = seq->private;
1148 v = lec_get_idx(state, 1);
1149 *pos += !!PTR_ERR(v);
1153 static int lec_seq_show(struct seq_file *seq, void *v)
1155 static char lec_banner[] = "Itf MAC ATM destination"
1157 "VPI/VCI Recv VPI/VCI\n";
1160 seq_puts(seq, lec_banner);
1162 struct lec_state *state = seq->private;
1163 struct net_device *dev = state->dev;
1164 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1166 seq_printf(seq, "%s ", dev->name);
1167 lec_info(seq, entry);
1172 static const struct seq_operations lec_seq_ops = {
1173 .start = lec_seq_start,
1174 .next = lec_seq_next,
1175 .stop = lec_seq_stop,
1176 .show = lec_seq_show,
1179 static int lec_seq_open(struct inode *inode, struct file *file)
1181 struct lec_state *state;
1182 struct seq_file *seq;
1185 state = kmalloc(sizeof(*state), GFP_KERNEL);
1191 rc = seq_open(file, &lec_seq_ops);
1194 seq = file->private_data;
1195 seq->private = state;
1204 static int lec_seq_release(struct inode *inode, struct file *file)
1206 return seq_release_private(inode, file);
1209 static const struct file_operations lec_seq_fops = {
1210 .owner = THIS_MODULE,
1211 .open = lec_seq_open,
1213 .llseek = seq_lseek,
1214 .release = lec_seq_release,
1218 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1220 struct atm_vcc *vcc = ATM_SD(sock);
1227 if (!capable(CAP_NET_ADMIN))
1231 return -ENOIOCTLCMD;
1236 err = lecd_attach(vcc, (int)arg);
1238 sock->state = SS_CONNECTED;
1241 err = lec_mcast_attach(vcc, (int)arg);
1244 err = lec_vcc_attach(vcc, (void __user *)arg);
1251 static struct atm_ioctl lane_ioctl_ops = {
1252 .owner = THIS_MODULE,
1253 .ioctl = lane_ioctl,
1256 static int __init lane_module_init(void)
1258 #ifdef CONFIG_PROC_FS
1259 struct proc_dir_entry *p;
1261 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
1263 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1268 register_atm_ioctl(&lane_ioctl_ops);
1269 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1273 static void __exit lane_module_cleanup(void)
1276 struct lec_priv *priv;
1278 remove_proc_entry("lec", atm_proc_root);
1280 deregister_atm_ioctl(&lane_ioctl_ops);
1282 for (i = 0; i < MAX_LEC_ITF; i++) {
1283 if (dev_lec[i] != NULL) {
1284 priv = (struct lec_priv *)dev_lec[i]->priv;
1285 unregister_netdev(dev_lec[i]);
1286 free_netdev(dev_lec[i]);
1294 module_init(lane_module_init);
1295 module_exit(lane_module_cleanup);
1298 * LANE2: 3.1.3, LE_RESOLVE.request
1299 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1300 * If sizeoftlvs == NULL the default TLVs associated with with this
1302 * If dst_mac == NULL, targetless LE_ARP will be sent
1304 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1305 u8 **tlvs, u32 *sizeoftlvs)
1307 unsigned long flags;
1308 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1309 struct lec_arp_table *table;
1310 struct sk_buff *skb;
1314 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1315 table = lec_arp_find(priv, dst_mac);
1316 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1320 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1324 *sizeoftlvs = table->sizeoftlvs;
1329 if (sizeoftlvs == NULL)
1330 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1333 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1336 skb->len = *sizeoftlvs;
1337 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1338 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1344 * LANE2: 3.1.4, LE_ASSOCIATE.request
1345 * Associate the *tlvs with the *lan_dst address.
1346 * Will overwrite any previous association
1347 * Returns 1 for success, 0 for failure (out of memory)
1350 static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1351 u8 *tlvs, u32 sizeoftlvs)
1354 struct sk_buff *skb;
1355 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1357 if (compare_ether_addr(lan_dst, dev->dev_addr))
1358 return (0); /* not our mac address */
1360 kfree(priv->tlvs); /* NULL if there was no previous association */
1362 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1363 if (priv->tlvs == NULL)
1365 priv->sizeoftlvs = sizeoftlvs;
1367 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1370 skb->len = sizeoftlvs;
1371 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1372 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1374 printk("lec.c: lane2_associate_req() failed\n");
1376 * If the previous association has changed we must
1377 * somehow notify other LANE entities about the change
1383 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1386 static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1387 u8 *tlvs, u32 sizeoftlvs)
1392 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1394 * Why have the TLVs in LE_ARP entries
1395 * since we do not use them? When you
1396 * uncomment this code, make sure the
1397 * TLVs get freed when entry is killed
1399 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1402 return; /* should not happen */
1406 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1407 if (entry->tlvs == NULL)
1409 entry->sizeoftlvs = sizeoftlvs;
1412 printk("lec.c: lane2_associate_ind()\n");
1413 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1414 while (i < sizeoftlvs)
1415 printk("%02x ", tlvs[i++]);
1420 /* tell MPOA about the TLVs we saw */
1421 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1422 priv->lane2_ops->associate_indicator(dev, mac_addr,
1429 * Here starts what used to lec_arpc.c
1431 * lec_arpc.c was added here when making
1432 * lane client modular. October 1997
1435 #include <linux/types.h>
1436 #include <linux/timer.h>
1437 #include <asm/param.h>
1438 #include <asm/atomic.h>
1439 #include <linux/inetdevice.h>
1440 #include <net/route.h>
1443 #define pr_debug(format,args...)
1445 #define pr_debug printk
1448 #define DEBUG_ARP_TABLE 0
1450 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1452 static void lec_arp_check_expire(struct work_struct *work);
1453 static void lec_arp_expire_arp(unsigned long data);
1459 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1462 * Initialization of arp-cache
1464 static void lec_arp_init(struct lec_priv *priv)
1468 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1469 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1471 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1472 INIT_HLIST_HEAD(&priv->lec_no_forward);
1473 INIT_HLIST_HEAD(&priv->mcast_fwds);
1474 spin_lock_init(&priv->lec_arp_lock);
1475 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
1476 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1479 static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1482 struct atm_vcc *vcc = entry->vcc;
1483 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1484 struct net_device *dev = (struct net_device *)vcc->proto_data;
1486 vcc->pop = vpriv->old_pop;
1488 netif_wake_queue(dev);
1490 vcc->user_back = NULL;
1491 vcc->push = entry->old_push;
1492 vcc_release_async(vcc, -EPIPE);
1495 if (entry->recv_vcc) {
1496 entry->recv_vcc->push = entry->old_recv_push;
1497 vcc_release_async(entry->recv_vcc, -EPIPE);
1498 entry->recv_vcc = NULL;
1503 * Insert entry to lec_arp_table
1504 * LANE2: Add to the end of the list to satisfy 8.1.13
1507 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1509 struct hlist_head *tmp;
1511 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1512 hlist_add_head(&entry->next, tmp);
1514 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1515 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1516 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1517 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1521 * Remove entry from lec_arp_table
1524 lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1526 struct hlist_node *node;
1527 struct lec_arp_table *entry;
1528 int i, remove_vcc = 1;
1534 hlist_del(&to_remove->next);
1535 del_timer(&to_remove->timer);
1537 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1538 if (to_remove->status >= ESI_FLUSH_PENDING) {
1540 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1542 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1543 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1544 if (memcmp(to_remove->atm_addr,
1545 entry->atm_addr, ATM_ESA_LEN) == 0) {
1552 lec_arp_clear_vccs(to_remove);
1554 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1556 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1557 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1558 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1559 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1564 static char *get_status_string(unsigned char st)
1568 return "ESI_UNKNOWN";
1569 case ESI_ARP_PENDING:
1570 return "ESI_ARP_PENDING";
1571 case ESI_VC_PENDING:
1572 return "ESI_VC_PENDING";
1573 case ESI_FLUSH_PENDING:
1574 return "ESI_FLUSH_PENDING";
1575 case ESI_FORWARD_DIRECT:
1576 return "ESI_FORWARD_DIRECT";
1582 static void dump_arp_table(struct lec_priv *priv)
1584 struct hlist_node *node;
1585 struct lec_arp_table *rulla;
1589 printk("Dump %p:\n", priv);
1590 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1591 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1593 offset += sprintf(buf, "%d: %p\n", i, rulla);
1594 offset += sprintf(buf + offset, "Mac:");
1595 for (j = 0; j < ETH_ALEN; j++) {
1596 offset += sprintf(buf + offset,
1598 rulla->mac_addr[j] & 0xff);
1600 offset += sprintf(buf + offset, "Atm:");
1601 for (j = 0; j < ATM_ESA_LEN; j++) {
1602 offset += sprintf(buf + offset,
1604 rulla->atm_addr[j] & 0xff);
1606 offset += sprintf(buf + offset,
1607 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1608 rulla->vcc ? rulla->vcc->vpi : 0,
1609 rulla->vcc ? rulla->vcc->vci : 0,
1610 rulla->recv_vcc ? rulla->recv_vcc->
1612 rulla->recv_vcc ? rulla->recv_vcc->
1613 vci : 0, rulla->last_used,
1614 rulla->timestamp, rulla->no_tries);
1616 sprintf(buf + offset,
1617 "Flags:%x, Packets_flooded:%x, Status: %s ",
1618 rulla->flags, rulla->packets_flooded,
1619 get_status_string(rulla->status));
1620 printk("%s\n", buf);
1624 if (!hlist_empty(&priv->lec_no_forward))
1625 printk("No forward\n");
1626 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1628 offset += sprintf(buf + offset, "Mac:");
1629 for (j = 0; j < ETH_ALEN; j++) {
1630 offset += sprintf(buf + offset, "%2.2x ",
1631 rulla->mac_addr[j] & 0xff);
1633 offset += sprintf(buf + offset, "Atm:");
1634 for (j = 0; j < ATM_ESA_LEN; j++) {
1635 offset += sprintf(buf + offset, "%2.2x ",
1636 rulla->atm_addr[j] & 0xff);
1638 offset += sprintf(buf + offset,
1639 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1640 rulla->vcc ? rulla->vcc->vpi : 0,
1641 rulla->vcc ? rulla->vcc->vci : 0,
1642 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1643 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1645 rulla->timestamp, rulla->no_tries);
1646 offset += sprintf(buf + offset,
1647 "Flags:%x, Packets_flooded:%x, Status: %s ",
1648 rulla->flags, rulla->packets_flooded,
1649 get_status_string(rulla->status));
1650 printk("%s\n", buf);
1653 if (!hlist_empty(&priv->lec_arp_empty_ones))
1654 printk("Empty ones\n");
1655 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1657 offset += sprintf(buf + offset, "Mac:");
1658 for (j = 0; j < ETH_ALEN; j++) {
1659 offset += sprintf(buf + offset, "%2.2x ",
1660 rulla->mac_addr[j] & 0xff);
1662 offset += sprintf(buf + offset, "Atm:");
1663 for (j = 0; j < ATM_ESA_LEN; j++) {
1664 offset += sprintf(buf + offset, "%2.2x ",
1665 rulla->atm_addr[j] & 0xff);
1667 offset += sprintf(buf + offset,
1668 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1669 rulla->vcc ? rulla->vcc->vpi : 0,
1670 rulla->vcc ? rulla->vcc->vci : 0,
1671 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1672 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1674 rulla->timestamp, rulla->no_tries);
1675 offset += sprintf(buf + offset,
1676 "Flags:%x, Packets_flooded:%x, Status: %s ",
1677 rulla->flags, rulla->packets_flooded,
1678 get_status_string(rulla->status));
1682 if (!hlist_empty(&priv->mcast_fwds))
1683 printk("Multicast Forward VCCs\n");
1684 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1686 offset += sprintf(buf + offset, "Mac:");
1687 for (j = 0; j < ETH_ALEN; j++) {
1688 offset += sprintf(buf + offset, "%2.2x ",
1689 rulla->mac_addr[j] & 0xff);
1691 offset += sprintf(buf + offset, "Atm:");
1692 for (j = 0; j < ATM_ESA_LEN; j++) {
1693 offset += sprintf(buf + offset, "%2.2x ",
1694 rulla->atm_addr[j] & 0xff);
1696 offset += sprintf(buf + offset,
1697 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1698 rulla->vcc ? rulla->vcc->vpi : 0,
1699 rulla->vcc ? rulla->vcc->vci : 0,
1700 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1701 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1703 rulla->timestamp, rulla->no_tries);
1704 offset += sprintf(buf + offset,
1705 "Flags:%x, Packets_flooded:%x, Status: %s ",
1706 rulla->flags, rulla->packets_flooded,
1707 get_status_string(rulla->status));
1708 printk("%s\n", buf);
1713 #define dump_arp_table(priv) do { } while (0)
1717 * Destruction of arp-cache
1719 static void lec_arp_destroy(struct lec_priv *priv)
1721 unsigned long flags;
1722 struct hlist_node *node, *next;
1723 struct lec_arp_table *entry;
1726 cancel_rearming_delayed_work(&priv->lec_arp_work);
1729 * Remove all entries
1732 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1733 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1734 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1735 lec_arp_remove(priv, entry);
1738 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1741 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1742 del_timer_sync(&entry->timer);
1743 lec_arp_clear_vccs(entry);
1744 hlist_del(&entry->next);
1747 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1749 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1750 del_timer_sync(&entry->timer);
1751 lec_arp_clear_vccs(entry);
1752 hlist_del(&entry->next);
1755 INIT_HLIST_HEAD(&priv->lec_no_forward);
1757 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1758 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1759 lec_arp_clear_vccs(entry);
1760 hlist_del(&entry->next);
1763 INIT_HLIST_HEAD(&priv->mcast_fwds);
1764 priv->mcast_vcc = NULL;
1765 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1769 * Find entry by mac_address
1771 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1772 unsigned char *mac_addr)
1774 struct hlist_node *node;
1775 struct hlist_head *head;
1776 struct lec_arp_table *entry;
1778 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1779 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1780 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1782 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1783 hlist_for_each_entry(entry, node, head, next) {
1784 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1791 static struct lec_arp_table *make_entry(struct lec_priv *priv,
1792 unsigned char *mac_addr)
1794 struct lec_arp_table *to_return;
1796 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1798 printk("LEC: Arp entry kmalloc failed\n");
1801 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1802 INIT_HLIST_NODE(&to_return->next);
1803 setup_timer(&to_return->timer, lec_arp_expire_arp,
1804 (unsigned long)to_return);
1805 to_return->last_used = jiffies;
1806 to_return->priv = priv;
1807 skb_queue_head_init(&to_return->tx_wait);
1808 atomic_set(&to_return->usage, 1);
1812 /* Arp sent timer expired */
1813 static void lec_arp_expire_arp(unsigned long data)
1815 struct lec_arp_table *entry;
1817 entry = (struct lec_arp_table *)data;
1819 pr_debug("lec_arp_expire_arp\n");
1820 if (entry->status == ESI_ARP_PENDING) {
1821 if (entry->no_tries <= entry->priv->max_retry_count) {
1822 if (entry->is_rdesc)
1823 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1824 entry->mac_addr, NULL, NULL);
1826 send_to_lecd(entry->priv, l_arp_xmt,
1827 entry->mac_addr, NULL, NULL);
1830 mod_timer(&entry->timer, jiffies + (1 * HZ));
1834 /* Unknown/unused vcc expire, remove associated entry */
1835 static void lec_arp_expire_vcc(unsigned long data)
1837 unsigned long flags;
1838 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1839 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1841 del_timer(&to_remove->timer);
1843 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1845 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1846 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1848 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1849 hlist_del(&to_remove->next);
1850 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1852 lec_arp_clear_vccs(to_remove);
1853 lec_arp_put(to_remove);
1859 * 2. For each entry, delete entries that have aged past the age limit.
1860 * 3. For each entry, depending on the status of the entry, perform
1861 * the following maintenance.
1862 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1863 * tick_count is above the max_unknown_frame_time, clear
1864 * the tick_count to zero and clear the packets_flooded counter
1865 * to zero. This supports the packet rate limit per address
1866 * while flooding unknowns.
1867 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1868 * than or equal to the path_switching_delay, change the status
1869 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1870 * regardless of the progress of the flush protocol.
1872 static void lec_arp_check_expire(struct work_struct *work)
1874 unsigned long flags;
1875 struct lec_priv *priv =
1876 container_of(work, struct lec_priv, lec_arp_work.work);
1877 struct hlist_node *node, *next;
1878 struct lec_arp_table *entry;
1880 unsigned long time_to_check;
1883 pr_debug("lec_arp_check_expire %p\n", priv);
1886 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1887 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1888 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1889 if ((entry->flags) & LEC_REMOTE_FLAG &&
1890 priv->topology_change)
1891 time_to_check = priv->forward_delay_time;
1893 time_to_check = priv->aging_time;
1895 pr_debug("About to expire: %lx - %lx > %lx\n",
1896 now, entry->last_used, time_to_check);
1897 if (time_after(now, entry->last_used + time_to_check)
1898 && !(entry->flags & LEC_PERMANENT_FLAG)
1899 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1901 pr_debug("LEC:Entry timed out\n");
1902 lec_arp_remove(priv, entry);
1905 /* Something else */
1906 if ((entry->status == ESI_VC_PENDING ||
1907 entry->status == ESI_ARP_PENDING)
1908 && time_after_eq(now,
1911 max_unknown_frame_time)) {
1912 entry->timestamp = jiffies;
1913 entry->packets_flooded = 0;
1914 if (entry->status == ESI_VC_PENDING)
1915 send_to_lecd(priv, l_svc_setup,
1920 if (entry->status == ESI_FLUSH_PENDING
1922 time_after_eq(now, entry->timestamp +
1923 priv->path_switching_delay)) {
1924 struct sk_buff *skb;
1925 struct atm_vcc *vcc = entry->vcc;
1927 lec_arp_hold(entry);
1928 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1929 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1930 lec_send(vcc, skb, entry->priv);
1931 entry->last_used = jiffies;
1932 entry->status = ESI_FORWARD_DIRECT;
1939 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1941 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1945 * Try to find vcc where mac_address is attached.
1948 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1949 unsigned char *mac_to_find, int is_rdesc,
1950 struct lec_arp_table **ret_entry)
1952 unsigned long flags;
1953 struct lec_arp_table *entry;
1954 struct atm_vcc *found;
1956 if (mac_to_find[0] & 0x01) {
1957 switch (priv->lane_version) {
1959 return priv->mcast_vcc;
1961 case 2: /* LANE2 wants arp for multicast addresses */
1962 if (!compare_ether_addr(mac_to_find, bus_mac))
1963 return priv->mcast_vcc;
1970 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1971 entry = lec_arp_find(priv, mac_to_find);
1974 if (entry->status == ESI_FORWARD_DIRECT) {
1976 entry->last_used = jiffies;
1977 lec_arp_hold(entry);
1983 * If the LE_ARP cache entry is still pending, reset count to 0
1984 * so another LE_ARP request can be made for this frame.
1986 if (entry->status == ESI_ARP_PENDING) {
1987 entry->no_tries = 0;
1990 * Data direct VC not yet set up, check to see if the unknown
1991 * frame count is greater than the limit. If the limit has
1992 * not been reached, allow the caller to send packet to
1995 if (entry->status != ESI_FLUSH_PENDING &&
1996 entry->packets_flooded <
1997 priv->maximum_unknown_frame_count) {
1998 entry->packets_flooded++;
1999 pr_debug("LEC_ARP: Flooding..\n");
2000 found = priv->mcast_vcc;
2004 * We got here because entry->status == ESI_FLUSH_PENDING
2005 * or BUS flood limit was reached for an entry which is
2006 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2008 lec_arp_hold(entry);
2010 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
2014 /* No matching entry was found */
2015 entry = make_entry(priv, mac_to_find);
2016 pr_debug("LEC_ARP: Making entry\n");
2018 found = priv->mcast_vcc;
2021 lec_arp_add(priv, entry);
2022 /* We want arp-request(s) to be sent */
2023 entry->packets_flooded = 1;
2024 entry->status = ESI_ARP_PENDING;
2025 entry->no_tries = 1;
2026 entry->last_used = entry->timestamp = jiffies;
2027 entry->is_rdesc = is_rdesc;
2028 if (entry->is_rdesc)
2029 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2032 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2033 entry->timer.expires = jiffies + (1 * HZ);
2034 entry->timer.function = lec_arp_expire_arp;
2035 add_timer(&entry->timer);
2036 found = priv->mcast_vcc;
2040 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2045 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2046 unsigned long permanent)
2048 unsigned long flags;
2049 struct hlist_node *node, *next;
2050 struct lec_arp_table *entry;
2053 pr_debug("lec_addr_delete\n");
2054 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2055 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2056 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2057 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2059 !(entry->flags & LEC_PERMANENT_FLAG))) {
2060 lec_arp_remove(priv, entry);
2063 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2067 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2072 * Notifies: Response to arp_request (atm_addr != NULL)
2075 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2076 unsigned char *atm_addr, unsigned long remoteflag,
2077 unsigned int targetless_le_arp)
2079 unsigned long flags;
2080 struct hlist_node *node, *next;
2081 struct lec_arp_table *entry, *tmp;
2084 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2085 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2086 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2087 mac_addr[4], mac_addr[5]);
2089 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2090 entry = lec_arp_find(priv, mac_addr);
2091 if (entry == NULL && targetless_le_arp)
2093 * LANE2: ignore targetless LE_ARPs for which
2094 * we have no entry in the cache. 7.1.30
2096 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2097 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2098 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2099 hlist_del(&entry->next);
2100 del_timer(&entry->timer);
2101 tmp = lec_arp_find(priv, mac_addr);
2103 del_timer(&tmp->timer);
2104 tmp->status = ESI_FORWARD_DIRECT;
2105 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2106 tmp->vcc = entry->vcc;
2107 tmp->old_push = entry->old_push;
2108 tmp->last_used = jiffies;
2109 del_timer(&entry->timer);
2113 entry->status = ESI_FORWARD_DIRECT;
2114 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2115 entry->last_used = jiffies;
2116 lec_arp_add(priv, entry);
2119 entry->flags |= LEC_REMOTE_FLAG;
2121 entry->flags &= ~LEC_REMOTE_FLAG;
2122 pr_debug("After update\n");
2123 dump_arp_table(priv);
2129 entry = lec_arp_find(priv, mac_addr);
2131 entry = make_entry(priv, mac_addr);
2134 entry->status = ESI_UNKNOWN;
2135 lec_arp_add(priv, entry);
2136 /* Temporary, changes before end of function */
2138 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2139 del_timer(&entry->timer);
2140 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2141 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
2143 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2144 /* Vcc to this host exists */
2145 if (tmp->status > ESI_VC_PENDING) {
2147 * ESI_FLUSH_PENDING,
2148 * ESI_FORWARD_DIRECT
2150 entry->vcc = tmp->vcc;
2151 entry->old_push = tmp->old_push;
2153 entry->status = tmp->status;
2159 entry->flags |= LEC_REMOTE_FLAG;
2161 entry->flags &= ~LEC_REMOTE_FLAG;
2162 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2163 entry->status = ESI_VC_PENDING;
2164 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2166 pr_debug("After update2\n");
2167 dump_arp_table(priv);
2169 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2173 * Notifies: Vcc setup ready
2176 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2177 struct atm_vcc *vcc,
2178 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
2180 unsigned long flags;
2181 struct hlist_node *node;
2182 struct lec_arp_table *entry;
2183 int i, found_entry = 0;
2185 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2186 if (ioc_data->receive == 2) {
2187 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2189 pr_debug("LEC_ARP: Attaching mcast forward\n");
2191 entry = lec_arp_find(priv, bus_mac);
2193 printk("LEC_ARP: Multicast entry not found!\n");
2196 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2197 entry->recv_vcc = vcc;
2198 entry->old_recv_push = old_push;
2200 entry = make_entry(priv, bus_mac);
2203 del_timer(&entry->timer);
2204 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2205 entry->recv_vcc = vcc;
2206 entry->old_recv_push = old_push;
2207 hlist_add_head(&entry->next, &priv->mcast_fwds);
2209 } else if (ioc_data->receive == 1) {
2211 * Vcc which we don't want to make default vcc,
2215 ("LEC_ARP:Attaching data direct, not default: "
2216 "%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",
2217 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2218 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2219 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2220 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2221 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2222 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2223 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2224 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2225 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2226 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2227 entry = make_entry(priv, bus_mac);
2230 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2231 memset(entry->mac_addr, 0, ETH_ALEN);
2232 entry->recv_vcc = vcc;
2233 entry->old_recv_push = old_push;
2234 entry->status = ESI_UNKNOWN;
2235 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2236 entry->timer.function = lec_arp_expire_vcc;
2237 hlist_add_head(&entry->next, &priv->lec_no_forward);
2238 add_timer(&entry->timer);
2239 dump_arp_table(priv);
2243 ("LEC_ARP:Attaching data direct, default: "
2244 "%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",
2245 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2246 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2247 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2248 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2249 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2250 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2251 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2252 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2253 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2254 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2255 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2256 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2258 (ioc_data->atm_addr, entry->atm_addr,
2259 ATM_ESA_LEN) == 0) {
2260 pr_debug("LEC_ARP: Attaching data direct\n");
2261 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2262 entry->vcc ? entry->vcc->vci : 0,
2263 entry->recv_vcc ? entry->recv_vcc->
2266 del_timer(&entry->timer);
2268 entry->old_push = old_push;
2269 if (entry->status == ESI_VC_PENDING) {
2270 if (priv->maximum_unknown_frame_count
2275 entry->timestamp = jiffies;
2279 send_to_lecd(priv, l_flush_xmt,
2287 * They were forming a connection
2288 * to us, and we to them. Our
2289 * ATM address is numerically lower
2290 * than theirs, so we make connection
2291 * we formed into default VCC (8.1.11).
2292 * Connection they made gets torn
2293 * down. This might confuse some
2294 * clients. Can be changed if
2295 * someone reports trouble...
2303 pr_debug("After vcc was added\n");
2304 dump_arp_table(priv);
2308 * Not found, snatch address from first data packet that arrives
2311 entry = make_entry(priv, bus_mac);
2315 entry->old_push = old_push;
2316 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2317 memset(entry->mac_addr, 0, ETH_ALEN);
2318 entry->status = ESI_UNKNOWN;
2319 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
2320 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2321 entry->timer.function = lec_arp_expire_vcc;
2322 add_timer(&entry->timer);
2323 pr_debug("After vcc was added\n");
2324 dump_arp_table(priv);
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2329 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2331 unsigned long flags;
2332 struct hlist_node *node;
2333 struct lec_arp_table *entry;
2336 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
2338 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2339 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2340 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2341 if (entry->flush_tran_id == tran_id
2342 && entry->status == ESI_FLUSH_PENDING) {
2343 struct sk_buff *skb;
2344 struct atm_vcc *vcc = entry->vcc;
2346 lec_arp_hold(entry);
2347 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2348 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2349 lec_send(vcc, skb, entry->priv);
2350 entry->last_used = jiffies;
2351 entry->status = ESI_FORWARD_DIRECT;
2353 pr_debug("LEC_ARP: Flushed\n");
2358 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2359 dump_arp_table(priv);
2363 lec_set_flush_tran_id(struct lec_priv *priv,
2364 unsigned char *atm_addr, unsigned long tran_id)
2366 unsigned long flags;
2367 struct hlist_node *node;
2368 struct lec_arp_table *entry;
2371 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2372 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2373 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2374 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2375 entry->flush_tran_id = tran_id;
2376 pr_debug("Set flush transaction id to %lx for %p\n",
2380 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2383 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2385 unsigned long flags;
2386 unsigned char mac_addr[] = {
2387 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2389 struct lec_arp_table *to_add;
2390 struct lec_vcc_priv *vpriv;
2393 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2396 vpriv->old_pop = vcc->pop;
2397 vcc->user_back = vpriv;
2399 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2400 to_add = make_entry(priv, mac_addr);
2402 vcc->pop = vpriv->old_pop;
2407 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2408 to_add->status = ESI_FORWARD_DIRECT;
2409 to_add->flags |= LEC_PERMANENT_FLAG;
2411 to_add->old_push = vcc->push;
2412 vcc->push = lec_push;
2413 priv->mcast_vcc = vcc;
2414 lec_arp_add(priv, to_add);
2416 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2420 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2422 unsigned long flags;
2423 struct hlist_node *node, *next;
2424 struct lec_arp_table *entry;
2427 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2428 dump_arp_table(priv);
2430 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2432 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2433 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2434 if (vcc == entry->vcc) {
2435 lec_arp_remove(priv, entry);
2437 if (priv->mcast_vcc == vcc) {
2438 priv->mcast_vcc = NULL;
2444 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2445 if (entry->vcc == vcc) {
2446 lec_arp_clear_vccs(entry);
2447 del_timer(&entry->timer);
2448 hlist_del(&entry->next);
2453 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
2454 if (entry->recv_vcc == vcc) {
2455 lec_arp_clear_vccs(entry);
2456 del_timer(&entry->timer);
2457 hlist_del(&entry->next);
2462 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
2463 if (entry->recv_vcc == vcc) {
2464 lec_arp_clear_vccs(entry);
2465 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2466 hlist_del(&entry->next);
2471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2472 dump_arp_table(priv);
2476 lec_arp_check_empties(struct lec_priv *priv,
2477 struct atm_vcc *vcc, struct sk_buff *skb)
2479 unsigned long flags;
2480 struct hlist_node *node, *next;
2481 struct lec_arp_table *entry, *tmp;
2482 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2485 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2488 src = tr_hdr->h_source;
2491 src = hdr->h_source;
2493 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2494 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2495 if (vcc == entry->vcc) {
2496 del_timer(&entry->timer);
2497 memcpy(entry->mac_addr, src, ETH_ALEN);
2498 entry->status = ESI_FORWARD_DIRECT;
2499 entry->last_used = jiffies;
2500 /* We might have got an entry */
2501 if ((tmp = lec_arp_find(priv, src))) {
2502 lec_arp_remove(priv, tmp);
2505 hlist_del(&entry->next);
2506 lec_arp_add(priv, entry);
2510 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2512 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2515 MODULE_LICENSE("GPL");