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 "../bridge/br_private.h"
39 static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
43 #include <linux/module.h>
44 #include <linux/init.h>
48 #include "resources.h"
50 #define DUMP_PACKETS 0 /*
56 #define LEC_UNRES_QUE_LEN 8 /*
57 * number of tx packets to queue for a
58 * single destination while waiting for SVC
61 static int lec_open(struct net_device *dev);
62 static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
63 struct net_device *dev);
64 static int lec_close(struct net_device *dev);
65 static void lec_init(struct net_device *dev);
66 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
67 const unsigned char *mac_addr);
68 static int lec_arp_remove(struct lec_priv *priv,
69 struct lec_arp_table *to_remove);
71 static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
72 const u8 *tlvs, u32 sizeoftlvs);
73 static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
74 u8 **tlvs, u32 *sizeoftlvs);
75 static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
76 const u8 *tlvs, u32 sizeoftlvs);
78 static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
79 unsigned long permanent);
80 static void lec_arp_check_empties(struct lec_priv *priv,
81 struct atm_vcc *vcc, struct sk_buff *skb);
82 static void lec_arp_destroy(struct lec_priv *priv);
83 static void lec_arp_init(struct lec_priv *priv);
84 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
85 const unsigned char *mac_to_find,
87 struct lec_arp_table **ret_entry);
88 static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
89 const unsigned char *atm_addr, unsigned long remoteflag,
90 unsigned int targetless_le_arp);
91 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
92 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
93 static void lec_set_flush_tran_id(struct lec_priv *priv,
94 const unsigned char *atm_addr,
95 unsigned long tran_id);
96 static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
98 void (*old_push) (struct atm_vcc *vcc,
99 struct sk_buff *skb));
100 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102 /* must be done under lec_arp_lock */
103 static inline void lec_arp_hold(struct lec_arp_table *entry)
105 atomic_inc(&entry->usage);
108 static inline void lec_arp_put(struct lec_arp_table *entry)
110 if (atomic_dec_and_test(&entry->usage))
115 static struct lane2_ops lane2_ops = {
116 lane2_resolve, /* resolve, spec 3.1.3 */
117 lane2_associate_req, /* associate_req, spec 3.1.4 */
118 NULL /* associate indicator, spec 3.1.5 */
121 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
123 /* Device structures */
124 static struct net_device *dev_lec[MAX_LEC_ITF];
126 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
127 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
131 struct lec_priv *priv;
134 * Check if this is a BPDU. If so, ask zeppelin to send
135 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
136 * as the Config BPDU has
138 eth = (struct ethhdr *)skb->data;
139 buff = skb->data + skb->dev->hard_header_len;
140 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
142 struct sk_buff *skb2;
143 struct atmlec_msg *mesg;
145 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
148 skb2->len = sizeof(struct atmlec_msg);
149 mesg = (struct atmlec_msg *)skb2->data;
150 mesg->type = l_topology_change;
152 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
154 priv = netdev_priv(dev);
155 atm_force_charge(priv->lecd, skb2->truesize);
156 sk = sk_atm(priv->lecd);
157 skb_queue_tail(&sk->sk_receive_queue, skb2);
158 sk->sk_data_ready(sk, skb2->len);
163 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
166 * Modelled after tr_type_trans
167 * All multicast and ARE or STE frames go to BUS.
168 * Non source routed frames go by destination address.
169 * Last hop source routed frames go by destination address.
170 * Not last hop source routed frames go by _next_ route descriptor.
171 * Returns pointer to destination MAC address or fills in rdesc
175 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
178 unsigned int riflen, num_rdsc;
180 trh = (struct trh_hdr *)packet;
181 if (trh->daddr[0] & (uint8_t) 0x80)
182 return bus_mac; /* multicast */
184 if (trh->saddr[0] & TR_RII) {
185 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
186 if ((ntohs(trh->rcf) >> 13) != 0)
187 return bus_mac; /* ARE or STE */
189 return trh->daddr; /* not source routed */
192 return trh->daddr; /* last hop, source routed */
194 /* riflen is 6 or more, packet has more than one route descriptor */
195 num_rdsc = (riflen / 2) - 1;
196 memset(rdesc, 0, ETH_ALEN);
197 /* offset 4 comes from LAN destination field in LE control frames */
198 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
199 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
201 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
202 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
207 #endif /* CONFIG_TR */
210 * Open/initialize the netdevice. This is called (in the current kernel)
211 * sometime after booting when the 'ifconfig' program is run.
213 * This routine should set everything up anew at each open, even
214 * registers that "should" only need to be set once at boot, so that
215 * there is non-reboot way to recover if something goes wrong.
218 static int lec_open(struct net_device *dev)
220 netif_start_queue(dev);
221 memset(&dev->stats, 0, sizeof(struct net_device_stats));
227 lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
229 struct net_device *dev = skb->dev;
231 ATM_SKB(skb)->vcc = vcc;
232 ATM_SKB(skb)->atm_options = vcc->atm_options;
234 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
235 if (vcc->send(vcc, skb) < 0) {
236 dev->stats.tx_dropped++;
240 dev->stats.tx_packets++;
241 dev->stats.tx_bytes += skb->len;
244 static void lec_tx_timeout(struct net_device *dev)
246 printk(KERN_INFO "%s: tx timeout\n", dev->name);
247 dev->trans_start = jiffies;
248 netif_wake_queue(dev);
251 static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
252 struct net_device *dev)
254 struct sk_buff *skb2;
255 struct lec_priv *priv = netdev_priv(dev);
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 dev->stats.tx_errors++;
274 netif_stop_queue(dev);
279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
280 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
281 (long)skb_end_pointer(skb));
282 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
283 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
284 lec_handle_bridge(skb, dev);
287 /* Make sure we have room for lec_id */
288 if (skb_headroom(skb) < 2) {
290 pr_debug("lec_start_xmit: reallocating skb\n");
291 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
299 /* Put le header to place, works for TokenRing too */
300 lec_h = (struct lecdatahdr_8023 *)skb->data;
301 lec_h->le_header = htons(priv->lecid);
305 * Ugly. Use this to realign Token Ring packets for
306 * e.g. PCA-200E driver.
308 if (priv->is_trdev) {
309 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
318 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
319 skb->len, priv->lecid);
320 #if DUMP_PACKETS >= 2
321 for (i = 0; i < skb->len && i < 99; i++) {
322 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
324 #elif DUMP_PACKETS >= 1
325 for (i = 0; i < skb->len && i < 30; i++) {
326 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
328 #endif /* DUMP_PACKETS >= 1 */
332 printk("%s...\n", buf);
333 #endif /* DUMP_PACKETS > 0 */
335 /* Minimum ethernet-frame size */
338 min_frame_size = LEC_MINIMUM_8025_SIZE;
341 min_frame_size = LEC_MINIMUM_8023_SIZE;
342 if (skb->len < min_frame_size) {
343 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
344 skb2 = skb_copy_expand(skb, 0,
345 min_frame_size - skb->truesize,
349 dev->stats.tx_dropped++;
354 skb_put(skb, min_frame_size - skb->len);
357 /* Send to right vcc */
361 if (priv->is_trdev) {
362 dst = get_tr_dst(skb->data + 2, rdesc);
370 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
371 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
372 vcc, vcc ? vcc->flags : 0, entry);
373 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
374 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
375 pr_debug("%s:lec_start_xmit: queuing packet, ",
377 pr_debug("MAC address %pM\n", lec_h->h_dest);
378 skb_queue_tail(&entry->tx_wait, skb);
381 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
383 pr_debug("MAC address %pM\n", lec_h->h_dest);
384 dev->stats.tx_dropped++;
390 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
391 #endif /* DUMP_PACKETS > 0 */
393 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
394 pr_debug("lec.c: emptying tx queue, ");
395 pr_debug("MAC address %pM\n", lec_h->h_dest);
401 if (!atm_may_send(vcc, 0)) {
402 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
405 netif_stop_queue(dev);
408 * vcc->pop() might have occurred in between, making
409 * the vcc usuable again. Since xmit is serialized,
410 * this is the only situation we have to re-test.
413 if (atm_may_send(vcc, 0))
414 netif_wake_queue(dev);
420 dev->trans_start = jiffies;
424 /* The inverse routine to net_open(). */
425 static int lec_close(struct net_device *dev)
427 netif_stop_queue(dev);
431 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
434 struct net_device *dev = (struct net_device *)vcc->proto_data;
435 struct lec_priv *priv = netdev_priv(dev);
436 struct atmlec_msg *mesg;
437 struct lec_arp_table *entry;
439 char *tmp; /* FIXME */
441 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
442 mesg = (struct atmlec_msg *)skb->data;
444 tmp += sizeof(struct atmlec_msg);
445 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
446 switch (mesg->type) {
448 for (i = 0; i < 6; i++) {
449 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
453 for (i = 0; i < 6; i++) {
454 dev->dev_addr[i] = 0;
458 lec_addr_delete(priv, mesg->content.normal.atm_addr,
459 mesg->content.normal.flag);
461 case l_topology_change:
462 priv->topology_change = mesg->content.normal.flag;
464 case l_flush_complete:
465 lec_flush_complete(priv, mesg->content.normal.flag);
467 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
468 spin_lock_irqsave(&priv->lec_arp_lock, flags);
469 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
470 lec_arp_remove(priv, entry);
471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
473 if (mesg->content.normal.no_source_le_narp)
477 lec_arp_update(priv, mesg->content.normal.mac_addr,
478 mesg->content.normal.atm_addr,
479 mesg->content.normal.flag,
480 mesg->content.normal.targetless_le_arp);
481 pr_debug("lec: in l_arp_update\n");
482 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
483 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
485 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
486 tmp, mesg->sizeoftlvs);
490 priv->maximum_unknown_frame_count =
491 mesg->content.config.maximum_unknown_frame_count;
492 priv->max_unknown_frame_time =
493 (mesg->content.config.max_unknown_frame_time * HZ);
494 priv->max_retry_count = mesg->content.config.max_retry_count;
495 priv->aging_time = (mesg->content.config.aging_time * HZ);
496 priv->forward_delay_time =
497 (mesg->content.config.forward_delay_time * HZ);
498 priv->arp_response_time =
499 (mesg->content.config.arp_response_time * HZ);
500 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
501 priv->path_switching_delay =
502 (mesg->content.config.path_switching_delay * HZ);
503 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
504 priv->lane2_ops = NULL;
505 if (priv->lane_version > 1)
506 priv->lane2_ops = &lane2_ops;
507 if (dev_set_mtu(dev, mesg->content.config.mtu))
508 printk("%s: change_mtu to %d failed\n", dev->name,
509 mesg->content.config.mtu);
510 priv->is_proxy = mesg->content.config.is_proxy;
512 case l_flush_tran_id:
513 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
514 mesg->content.normal.flag);
518 (unsigned short)(0xffff & mesg->content.normal.flag);
520 case l_should_bridge:
521 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
523 pr_debug("%s: bridge zeppelin asks about %pM\n",
524 dev->name, mesg->content.proxy.mac_addr);
526 if (br_fdb_test_addr_hook == NULL)
529 if (br_fdb_test_addr_hook(dev,
530 mesg->content.proxy.mac_addr)) {
531 /* hit from bridge table, send LE_ARP_RESPONSE */
532 struct sk_buff *skb2;
536 ("%s: entry found, responding to zeppelin\n",
539 alloc_skb(sizeof(struct atmlec_msg),
543 skb2->len = sizeof(struct atmlec_msg);
544 skb_copy_to_linear_data(skb2, mesg,
546 atm_force_charge(priv->lecd, skb2->truesize);
547 sk = sk_atm(priv->lecd);
548 skb_queue_tail(&sk->sk_receive_queue, skb2);
549 sk->sk_data_ready(sk, skb2->len);
552 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
555 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
563 static void lec_atm_close(struct atm_vcc *vcc)
566 struct net_device *dev = (struct net_device *)vcc->proto_data;
567 struct lec_priv *priv = netdev_priv(dev);
570 /* Do something needful? */
572 netif_stop_queue(dev);
573 lec_arp_destroy(priv);
575 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
576 printk("%s lec_atm_close: closing with messages pending\n",
578 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
579 atm_return(vcc, skb->truesize);
583 printk("%s: Shut down!\n", dev->name);
584 module_put(THIS_MODULE);
587 static struct atmdev_ops lecdev_ops = {
588 .close = lec_atm_close,
592 static struct atm_dev lecatm_dev = {
595 .number = 999, /* dummy device number */
596 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
600 * LANE2: new argument struct sk_buff *data contains
601 * the LE_ARP based TLVs introduced in the LANE2 spec
604 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
605 const unsigned char *mac_addr, const unsigned char *atm_addr,
606 struct sk_buff *data)
610 struct atmlec_msg *mesg;
612 if (!priv || !priv->lecd) {
615 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
618 skb->len = sizeof(struct atmlec_msg);
619 mesg = (struct atmlec_msg *)skb->data;
620 memset(mesg, 0, sizeof(struct atmlec_msg));
623 mesg->sizeoftlvs = data->len;
625 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
627 mesg->content.normal.targetless_le_arp = 1;
629 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
631 atm_force_charge(priv->lecd, skb->truesize);
632 sk = sk_atm(priv->lecd);
633 skb_queue_tail(&sk->sk_receive_queue, skb);
634 sk->sk_data_ready(sk, skb->len);
637 pr_debug("lec: about to send %d bytes of data\n", data->len);
638 atm_force_charge(priv->lecd, data->truesize);
639 skb_queue_tail(&sk->sk_receive_queue, data);
640 sk->sk_data_ready(sk, skb->len);
646 /* shamelessly stolen from drivers/net/net_init.c */
647 static int lec_change_mtu(struct net_device *dev, int new_mtu)
649 if ((new_mtu < 68) || (new_mtu > 18190))
655 static void lec_set_multicast_list(struct net_device *dev)
658 * by default, all multicast frames arrive over the bus.
659 * eventually support selective multicast service
664 static const struct net_device_ops lec_netdev_ops = {
665 .ndo_open = lec_open,
666 .ndo_stop = lec_close,
667 .ndo_start_xmit = lec_start_xmit,
668 .ndo_change_mtu = lec_change_mtu,
669 .ndo_tx_timeout = lec_tx_timeout,
670 .ndo_set_multicast_list = lec_set_multicast_list,
674 static void lec_init(struct net_device *dev)
676 dev->netdev_ops = &lec_netdev_ops;
677 printk("%s: Initialized!\n", dev->name);
680 static const unsigned char lec_ctrl_magic[] = {
687 #define LEC_DATA_DIRECT_8023 2
688 #define LEC_DATA_DIRECT_8025 3
690 static int lec_is_data_direct(struct atm_vcc *vcc)
692 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
693 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
696 static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
699 struct net_device *dev = (struct net_device *)vcc->proto_data;
700 struct lec_priv *priv = netdev_priv(dev);
706 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
710 pr_debug("%s: null skb\n", dev->name);
711 lec_vcc_close(priv, vcc);
715 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
716 skb->len, priv->lecid);
717 #if DUMP_PACKETS >= 2
718 for (i = 0; i < skb->len && i < 99; i++) {
719 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
721 #elif DUMP_PACKETS >= 1
722 for (i = 0; i < skb->len && i < 30; i++) {
723 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
725 #endif /* DUMP_PACKETS >= 1 */
729 printk("%s...\n", buf);
730 #endif /* DUMP_PACKETS > 0 */
731 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
732 struct sock *sk = sk_atm(vcc);
734 pr_debug("%s: To daemon\n", dev->name);
735 skb_queue_tail(&sk->sk_receive_queue, skb);
736 sk->sk_data_ready(sk, skb->len);
737 } else { /* Data frame, queue to protocol handlers */
738 struct lec_arp_table *entry;
739 unsigned char *src, *dst;
741 atm_return(vcc, skb->truesize);
742 if (*(__be16 *) skb->data == htons(priv->lecid) ||
743 !priv->lecd || !(dev->flags & IFF_UP)) {
745 * Probably looping back, or if lecd is missing,
748 pr_debug("Ignoring frame...\n");
754 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
757 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
760 * If this is a Data Direct VCC, and the VCC does not match
761 * the LE_ARP cache entry, delete the LE_ARP cache entry.
763 spin_lock_irqsave(&priv->lec_arp_lock, flags);
764 if (lec_is_data_direct(vcc)) {
768 ((struct lecdatahdr_8025 *)skb->data)->
773 ((struct lecdatahdr_8023 *)skb->data)->
775 entry = lec_arp_find(priv, src);
776 if (entry && entry->vcc != vcc) {
777 lec_arp_remove(priv, entry);
781 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
783 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
784 !priv->is_proxy && /* Proxy wants all the packets */
785 memcmp(dst, dev->dev_addr, dev->addr_len)) {
789 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
790 lec_arp_check_empties(priv, vcc, skb);
792 skb_pull(skb, 2); /* skip lec_id */
795 skb->protocol = tr_type_trans(skb, dev);
798 skb->protocol = eth_type_trans(skb, dev);
799 dev->stats.rx_packets++;
800 dev->stats.rx_bytes += skb->len;
801 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
806 static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
808 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
809 struct net_device *dev = skb->dev;
812 printk("lec_pop(): vpriv = NULL!?!?!?\n");
816 vpriv->old_pop(vcc, skb);
818 if (vpriv->xoff && atm_may_send(vcc, 0)) {
820 if (netif_running(dev) && netif_queue_stopped(dev))
821 netif_wake_queue(dev);
825 static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
827 struct lec_vcc_priv *vpriv;
829 struct atmlec_ioc ioc_data;
831 /* Lecd must be up in this case */
832 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
833 if (bytes_left != 0) {
835 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
838 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
839 !dev_lec[ioc_data.dev_num])
841 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
844 vpriv->old_pop = vcc->pop;
845 vcc->user_back = vpriv;
847 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
848 &ioc_data, vcc, vcc->push);
849 vcc->proto_data = dev_lec[ioc_data.dev_num];
850 vcc->push = lec_push;
854 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
856 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
858 vcc->proto_data = dev_lec[arg];
859 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
863 /* Initialize device. */
864 static int lecd_attach(struct atm_vcc *vcc, int arg)
867 struct lec_priv *priv;
874 if (arg >= MAX_LEC_ITF)
876 #else /* Reserve the top NUM_TR_DEVS for TR */
877 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
884 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
887 size = sizeof(struct lec_priv);
890 dev_lec[i] = alloc_trdev(size);
893 dev_lec[i] = alloc_etherdev(size);
896 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
897 if (register_netdev(dev_lec[i])) {
898 free_netdev(dev_lec[i]);
902 priv = netdev_priv(dev_lec[i]);
903 priv->is_trdev = is_trdev;
904 lec_init(dev_lec[i]);
906 priv = netdev_priv(dev_lec[i]);
911 priv->itfnum = i; /* LANE2 addition */
913 vcc->dev = &lecatm_dev;
914 vcc_insert_socket(sk_atm(vcc));
916 vcc->proto_data = dev_lec[i];
917 set_bit(ATM_VF_META, &vcc->flags);
918 set_bit(ATM_VF_READY, &vcc->flags);
920 /* Set default values to these variables */
921 priv->maximum_unknown_frame_count = 1;
922 priv->max_unknown_frame_time = (1 * HZ);
923 priv->vcc_timeout_period = (1200 * HZ);
924 priv->max_retry_count = 1;
925 priv->aging_time = (300 * HZ);
926 priv->forward_delay_time = (15 * HZ);
927 priv->topology_change = 0;
928 priv->arp_response_time = (1 * HZ);
929 priv->flush_timeout = (4 * HZ);
930 priv->path_switching_delay = (6 * HZ);
932 if (dev_lec[i]->flags & IFF_UP) {
933 netif_start_queue(dev_lec[i]);
935 __module_get(THIS_MODULE);
939 #ifdef CONFIG_PROC_FS
940 static const char *lec_arp_get_status_string(unsigned char status)
942 static const char *const lec_arp_status_string[] = {
947 "ESI_FLUSH_PENDING ",
951 if (status > ESI_FORWARD_DIRECT)
952 status = 3; /* ESI_UNDEFINED */
953 return lec_arp_status_string[status];
956 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
960 for (i = 0; i < ETH_ALEN; i++)
961 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
962 seq_printf(seq, " ");
963 for (i = 0; i < ATM_ESA_LEN; i++)
964 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
965 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
966 entry->flags & 0xffff);
968 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
970 seq_printf(seq, " ");
971 if (entry->recv_vcc) {
972 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
973 entry->recv_vcc->vci);
980 struct lec_priv *locked;
981 struct hlist_node *node;
982 struct net_device *dev;
988 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
991 struct hlist_node *e = state->node;
992 struct lec_arp_table *tmp;
996 if (e == SEQ_START_TOKEN) {
1001 hlist_for_each_entry_from(tmp, e, next) {
1007 return (*l < 0) ? state : NULL;
1010 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
1011 struct lec_priv *priv)
1016 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
1017 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1021 state->arp_table = p;
1025 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1026 struct lec_priv *priv)
1028 struct hlist_head *lec_misc_tables[] = {
1029 &priv->lec_arp_empty_ones,
1030 &priv->lec_no_forward,
1036 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1037 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1041 state->misc_table = q;
1045 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1046 struct lec_priv *priv)
1048 if (!state->locked) {
1049 state->locked = priv;
1050 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1052 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1053 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1054 state->locked = NULL;
1055 /* Partial state reset for the next time we get called */
1056 state->arp_table = state->misc_table = 0;
1058 return state->locked;
1061 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1063 struct net_device *dev;
1066 dev = state->dev ? state->dev : dev_lec[state->itf];
1067 v = (dev && netdev_priv(dev)) ?
1068 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
1071 /* Partial state reset for the next time we get called */
1078 static void *lec_get_idx(struct lec_state *state, loff_t l)
1082 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1083 v = lec_itf_walk(state, &l);
1090 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1092 struct lec_state *state = seq->private;
1096 state->locked = NULL;
1097 state->arp_table = 0;
1098 state->misc_table = 0;
1099 state->node = SEQ_START_TOKEN;
1101 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
1104 static void lec_seq_stop(struct seq_file *seq, void *v)
1106 struct lec_state *state = seq->private;
1109 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1111 dev_put(state->dev);
1115 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1117 struct lec_state *state = seq->private;
1119 v = lec_get_idx(state, 1);
1120 *pos += !!PTR_ERR(v);
1124 static int lec_seq_show(struct seq_file *seq, void *v)
1126 static const char lec_banner[] =
1127 "Itf MAC ATM destination"
1129 "VPI/VCI Recv VPI/VCI\n";
1131 if (v == SEQ_START_TOKEN)
1132 seq_puts(seq, lec_banner);
1134 struct lec_state *state = seq->private;
1135 struct net_device *dev = state->dev;
1136 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1138 seq_printf(seq, "%s ", dev->name);
1139 lec_info(seq, entry);
1144 static const struct seq_operations lec_seq_ops = {
1145 .start = lec_seq_start,
1146 .next = lec_seq_next,
1147 .stop = lec_seq_stop,
1148 .show = lec_seq_show,
1151 static int lec_seq_open(struct inode *inode, struct file *file)
1153 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
1156 static const struct file_operations lec_seq_fops = {
1157 .owner = THIS_MODULE,
1158 .open = lec_seq_open,
1160 .llseek = seq_lseek,
1161 .release = seq_release_private,
1165 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1167 struct atm_vcc *vcc = ATM_SD(sock);
1174 if (!capable(CAP_NET_ADMIN))
1178 return -ENOIOCTLCMD;
1183 err = lecd_attach(vcc, (int)arg);
1185 sock->state = SS_CONNECTED;
1188 err = lec_mcast_attach(vcc, (int)arg);
1191 err = lec_vcc_attach(vcc, (void __user *)arg);
1198 static struct atm_ioctl lane_ioctl_ops = {
1199 .owner = THIS_MODULE,
1200 .ioctl = lane_ioctl,
1203 static int __init lane_module_init(void)
1205 #ifdef CONFIG_PROC_FS
1206 struct proc_dir_entry *p;
1208 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
1210 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1215 register_atm_ioctl(&lane_ioctl_ops);
1216 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1220 static void __exit lane_module_cleanup(void)
1223 struct lec_priv *priv;
1225 remove_proc_entry("lec", atm_proc_root);
1227 deregister_atm_ioctl(&lane_ioctl_ops);
1229 for (i = 0; i < MAX_LEC_ITF; i++) {
1230 if (dev_lec[i] != NULL) {
1231 priv = netdev_priv(dev_lec[i]);
1232 unregister_netdev(dev_lec[i]);
1233 free_netdev(dev_lec[i]);
1241 module_init(lane_module_init);
1242 module_exit(lane_module_cleanup);
1245 * LANE2: 3.1.3, LE_RESOLVE.request
1246 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1247 * If sizeoftlvs == NULL the default TLVs associated with with this
1249 * If dst_mac == NULL, targetless LE_ARP will be sent
1251 static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
1252 u8 **tlvs, u32 *sizeoftlvs)
1254 unsigned long flags;
1255 struct lec_priv *priv = netdev_priv(dev);
1256 struct lec_arp_table *table;
1257 struct sk_buff *skb;
1261 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1262 table = lec_arp_find(priv, dst_mac);
1263 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1267 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1271 *sizeoftlvs = table->sizeoftlvs;
1276 if (sizeoftlvs == NULL)
1277 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1280 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1283 skb->len = *sizeoftlvs;
1284 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1285 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1291 * LANE2: 3.1.4, LE_ASSOCIATE.request
1292 * Associate the *tlvs with the *lan_dst address.
1293 * Will overwrite any previous association
1294 * Returns 1 for success, 0 for failure (out of memory)
1297 static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1298 const u8 *tlvs, u32 sizeoftlvs)
1301 struct sk_buff *skb;
1302 struct lec_priv *priv = netdev_priv(dev);
1304 if (compare_ether_addr(lan_dst, dev->dev_addr))
1305 return (0); /* not our mac address */
1307 kfree(priv->tlvs); /* NULL if there was no previous association */
1309 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1310 if (priv->tlvs == NULL)
1312 priv->sizeoftlvs = sizeoftlvs;
1314 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1317 skb->len = sizeoftlvs;
1318 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1319 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1321 printk("lec.c: lane2_associate_req() failed\n");
1323 * If the previous association has changed we must
1324 * somehow notify other LANE entities about the change
1330 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1333 static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1334 const u8 *tlvs, u32 sizeoftlvs)
1339 struct lec_priv *priv = netdev_priv(dev);
1341 * Why have the TLVs in LE_ARP entries
1342 * since we do not use them? When you
1343 * uncomment this code, make sure the
1344 * TLVs get freed when entry is killed
1346 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1349 return; /* should not happen */
1353 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1354 if (entry->tlvs == NULL)
1356 entry->sizeoftlvs = sizeoftlvs;
1359 printk("lec.c: lane2_associate_ind()\n");
1360 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1361 while (i < sizeoftlvs)
1362 printk("%02x ", tlvs[i++]);
1367 /* tell MPOA about the TLVs we saw */
1368 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1369 priv->lane2_ops->associate_indicator(dev, mac_addr,
1376 * Here starts what used to lec_arpc.c
1378 * lec_arpc.c was added here when making
1379 * lane client modular. October 1997
1382 #include <linux/types.h>
1383 #include <linux/timer.h>
1384 #include <asm/param.h>
1385 #include <asm/atomic.h>
1386 #include <linux/inetdevice.h>
1387 #include <net/route.h>
1390 #define pr_debug(format,args...)
1392 #define pr_debug printk
1395 #define DEBUG_ARP_TABLE 0
1397 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1399 static void lec_arp_check_expire(struct work_struct *work);
1400 static void lec_arp_expire_arp(unsigned long data);
1406 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1409 * Initialization of arp-cache
1411 static void lec_arp_init(struct lec_priv *priv)
1415 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1416 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1418 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1419 INIT_HLIST_HEAD(&priv->lec_no_forward);
1420 INIT_HLIST_HEAD(&priv->mcast_fwds);
1421 spin_lock_init(&priv->lec_arp_lock);
1422 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
1423 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1426 static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1429 struct atm_vcc *vcc = entry->vcc;
1430 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1431 struct net_device *dev = (struct net_device *)vcc->proto_data;
1433 vcc->pop = vpriv->old_pop;
1435 netif_wake_queue(dev);
1437 vcc->user_back = NULL;
1438 vcc->push = entry->old_push;
1439 vcc_release_async(vcc, -EPIPE);
1442 if (entry->recv_vcc) {
1443 entry->recv_vcc->push = entry->old_recv_push;
1444 vcc_release_async(entry->recv_vcc, -EPIPE);
1445 entry->recv_vcc = NULL;
1450 * Insert entry to lec_arp_table
1451 * LANE2: Add to the end of the list to satisfy 8.1.13
1454 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1456 struct hlist_head *tmp;
1458 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1459 hlist_add_head(&entry->next, tmp);
1461 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1462 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1463 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1464 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1468 * Remove entry from lec_arp_table
1471 lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1473 struct hlist_node *node;
1474 struct lec_arp_table *entry;
1475 int i, remove_vcc = 1;
1481 hlist_del(&to_remove->next);
1482 del_timer(&to_remove->timer);
1484 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1485 if (to_remove->status >= ESI_FLUSH_PENDING) {
1487 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1489 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1490 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1491 if (memcmp(to_remove->atm_addr,
1492 entry->atm_addr, ATM_ESA_LEN) == 0) {
1499 lec_arp_clear_vccs(to_remove);
1501 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1503 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1504 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1505 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1506 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1511 static const char *get_status_string(unsigned char st)
1515 return "ESI_UNKNOWN";
1516 case ESI_ARP_PENDING:
1517 return "ESI_ARP_PENDING";
1518 case ESI_VC_PENDING:
1519 return "ESI_VC_PENDING";
1520 case ESI_FLUSH_PENDING:
1521 return "ESI_FLUSH_PENDING";
1522 case ESI_FORWARD_DIRECT:
1523 return "ESI_FORWARD_DIRECT";
1529 static void dump_arp_table(struct lec_priv *priv)
1531 struct hlist_node *node;
1532 struct lec_arp_table *rulla;
1536 printk("Dump %p:\n", priv);
1537 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1538 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1540 offset += sprintf(buf, "%d: %p\n", i, rulla);
1541 offset += sprintf(buf + offset, "Mac:");
1542 for (j = 0; j < ETH_ALEN; j++) {
1543 offset += sprintf(buf + offset,
1545 rulla->mac_addr[j] & 0xff);
1547 offset += sprintf(buf + offset, "Atm:");
1548 for (j = 0; j < ATM_ESA_LEN; j++) {
1549 offset += sprintf(buf + offset,
1551 rulla->atm_addr[j] & 0xff);
1553 offset += sprintf(buf + offset,
1554 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1555 rulla->vcc ? rulla->vcc->vpi : 0,
1556 rulla->vcc ? rulla->vcc->vci : 0,
1557 rulla->recv_vcc ? rulla->recv_vcc->
1559 rulla->recv_vcc ? rulla->recv_vcc->
1560 vci : 0, rulla->last_used,
1561 rulla->timestamp, rulla->no_tries);
1563 sprintf(buf + offset,
1564 "Flags:%x, Packets_flooded:%x, Status: %s ",
1565 rulla->flags, rulla->packets_flooded,
1566 get_status_string(rulla->status));
1567 printk("%s\n", buf);
1571 if (!hlist_empty(&priv->lec_no_forward))
1572 printk("No forward\n");
1573 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1575 offset += sprintf(buf + offset, "Mac:");
1576 for (j = 0; j < ETH_ALEN; j++) {
1577 offset += sprintf(buf + offset, "%2.2x ",
1578 rulla->mac_addr[j] & 0xff);
1580 offset += sprintf(buf + offset, "Atm:");
1581 for (j = 0; j < ATM_ESA_LEN; j++) {
1582 offset += sprintf(buf + offset, "%2.2x ",
1583 rulla->atm_addr[j] & 0xff);
1585 offset += sprintf(buf + offset,
1586 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1587 rulla->vcc ? rulla->vcc->vpi : 0,
1588 rulla->vcc ? rulla->vcc->vci : 0,
1589 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1590 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1592 rulla->timestamp, rulla->no_tries);
1593 offset += sprintf(buf + offset,
1594 "Flags:%x, Packets_flooded:%x, Status: %s ",
1595 rulla->flags, rulla->packets_flooded,
1596 get_status_string(rulla->status));
1597 printk("%s\n", buf);
1600 if (!hlist_empty(&priv->lec_arp_empty_ones))
1601 printk("Empty ones\n");
1602 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1604 offset += sprintf(buf + offset, "Mac:");
1605 for (j = 0; j < ETH_ALEN; j++) {
1606 offset += sprintf(buf + offset, "%2.2x ",
1607 rulla->mac_addr[j] & 0xff);
1609 offset += sprintf(buf + offset, "Atm:");
1610 for (j = 0; j < ATM_ESA_LEN; j++) {
1611 offset += sprintf(buf + offset, "%2.2x ",
1612 rulla->atm_addr[j] & 0xff);
1614 offset += sprintf(buf + offset,
1615 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1616 rulla->vcc ? rulla->vcc->vpi : 0,
1617 rulla->vcc ? rulla->vcc->vci : 0,
1618 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1619 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1621 rulla->timestamp, rulla->no_tries);
1622 offset += sprintf(buf + offset,
1623 "Flags:%x, Packets_flooded:%x, Status: %s ",
1624 rulla->flags, rulla->packets_flooded,
1625 get_status_string(rulla->status));
1629 if (!hlist_empty(&priv->mcast_fwds))
1630 printk("Multicast Forward VCCs\n");
1631 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1633 offset += sprintf(buf + offset, "Mac:");
1634 for (j = 0; j < ETH_ALEN; j++) {
1635 offset += sprintf(buf + offset, "%2.2x ",
1636 rulla->mac_addr[j] & 0xff);
1638 offset += sprintf(buf + offset, "Atm:");
1639 for (j = 0; j < ATM_ESA_LEN; j++) {
1640 offset += sprintf(buf + offset, "%2.2x ",
1641 rulla->atm_addr[j] & 0xff);
1643 offset += sprintf(buf + offset,
1644 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1645 rulla->vcc ? rulla->vcc->vpi : 0,
1646 rulla->vcc ? rulla->vcc->vci : 0,
1647 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1648 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1650 rulla->timestamp, rulla->no_tries);
1651 offset += sprintf(buf + offset,
1652 "Flags:%x, Packets_flooded:%x, Status: %s ",
1653 rulla->flags, rulla->packets_flooded,
1654 get_status_string(rulla->status));
1655 printk("%s\n", buf);
1660 #define dump_arp_table(priv) do { } while (0)
1664 * Destruction of arp-cache
1666 static void lec_arp_destroy(struct lec_priv *priv)
1668 unsigned long flags;
1669 struct hlist_node *node, *next;
1670 struct lec_arp_table *entry;
1673 cancel_rearming_delayed_work(&priv->lec_arp_work);
1676 * Remove all entries
1679 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1680 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1681 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1682 lec_arp_remove(priv, entry);
1685 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1688 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1689 del_timer_sync(&entry->timer);
1690 lec_arp_clear_vccs(entry);
1691 hlist_del(&entry->next);
1694 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1696 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1697 del_timer_sync(&entry->timer);
1698 lec_arp_clear_vccs(entry);
1699 hlist_del(&entry->next);
1702 INIT_HLIST_HEAD(&priv->lec_no_forward);
1704 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1705 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1706 lec_arp_clear_vccs(entry);
1707 hlist_del(&entry->next);
1710 INIT_HLIST_HEAD(&priv->mcast_fwds);
1711 priv->mcast_vcc = NULL;
1712 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1716 * Find entry by mac_address
1718 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1719 const unsigned char *mac_addr)
1721 struct hlist_node *node;
1722 struct hlist_head *head;
1723 struct lec_arp_table *entry;
1725 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1726 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1727 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1729 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1730 hlist_for_each_entry(entry, node, head, next) {
1731 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1738 static struct lec_arp_table *make_entry(struct lec_priv *priv,
1739 const unsigned char *mac_addr)
1741 struct lec_arp_table *to_return;
1743 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1745 printk("LEC: Arp entry kmalloc failed\n");
1748 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1749 INIT_HLIST_NODE(&to_return->next);
1750 setup_timer(&to_return->timer, lec_arp_expire_arp,
1751 (unsigned long)to_return);
1752 to_return->last_used = jiffies;
1753 to_return->priv = priv;
1754 skb_queue_head_init(&to_return->tx_wait);
1755 atomic_set(&to_return->usage, 1);
1759 /* Arp sent timer expired */
1760 static void lec_arp_expire_arp(unsigned long data)
1762 struct lec_arp_table *entry;
1764 entry = (struct lec_arp_table *)data;
1766 pr_debug("lec_arp_expire_arp\n");
1767 if (entry->status == ESI_ARP_PENDING) {
1768 if (entry->no_tries <= entry->priv->max_retry_count) {
1769 if (entry->is_rdesc)
1770 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1771 entry->mac_addr, NULL, NULL);
1773 send_to_lecd(entry->priv, l_arp_xmt,
1774 entry->mac_addr, NULL, NULL);
1777 mod_timer(&entry->timer, jiffies + (1 * HZ));
1781 /* Unknown/unused vcc expire, remove associated entry */
1782 static void lec_arp_expire_vcc(unsigned long data)
1784 unsigned long flags;
1785 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1786 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1788 del_timer(&to_remove->timer);
1790 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1792 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1793 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1795 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1796 hlist_del(&to_remove->next);
1797 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1799 lec_arp_clear_vccs(to_remove);
1800 lec_arp_put(to_remove);
1806 * 2. For each entry, delete entries that have aged past the age limit.
1807 * 3. For each entry, depending on the status of the entry, perform
1808 * the following maintenance.
1809 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1810 * tick_count is above the max_unknown_frame_time, clear
1811 * the tick_count to zero and clear the packets_flooded counter
1812 * to zero. This supports the packet rate limit per address
1813 * while flooding unknowns.
1814 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1815 * than or equal to the path_switching_delay, change the status
1816 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1817 * regardless of the progress of the flush protocol.
1819 static void lec_arp_check_expire(struct work_struct *work)
1821 unsigned long flags;
1822 struct lec_priv *priv =
1823 container_of(work, struct lec_priv, lec_arp_work.work);
1824 struct hlist_node *node, *next;
1825 struct lec_arp_table *entry;
1827 unsigned long time_to_check;
1830 pr_debug("lec_arp_check_expire %p\n", priv);
1833 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1834 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1835 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1836 if ((entry->flags) & LEC_REMOTE_FLAG &&
1837 priv->topology_change)
1838 time_to_check = priv->forward_delay_time;
1840 time_to_check = priv->aging_time;
1842 pr_debug("About to expire: %lx - %lx > %lx\n",
1843 now, entry->last_used, time_to_check);
1844 if (time_after(now, entry->last_used + time_to_check)
1845 && !(entry->flags & LEC_PERMANENT_FLAG)
1846 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1848 pr_debug("LEC:Entry timed out\n");
1849 lec_arp_remove(priv, entry);
1852 /* Something else */
1853 if ((entry->status == ESI_VC_PENDING ||
1854 entry->status == ESI_ARP_PENDING)
1855 && time_after_eq(now,
1858 max_unknown_frame_time)) {
1859 entry->timestamp = jiffies;
1860 entry->packets_flooded = 0;
1861 if (entry->status == ESI_VC_PENDING)
1862 send_to_lecd(priv, l_svc_setup,
1867 if (entry->status == ESI_FLUSH_PENDING
1869 time_after_eq(now, entry->timestamp +
1870 priv->path_switching_delay)) {
1871 struct sk_buff *skb;
1872 struct atm_vcc *vcc = entry->vcc;
1874 lec_arp_hold(entry);
1875 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1876 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1878 entry->last_used = jiffies;
1879 entry->status = ESI_FORWARD_DIRECT;
1886 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1888 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1892 * Try to find vcc where mac_address is attached.
1895 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1896 const unsigned char *mac_to_find, int is_rdesc,
1897 struct lec_arp_table **ret_entry)
1899 unsigned long flags;
1900 struct lec_arp_table *entry;
1901 struct atm_vcc *found;
1903 if (mac_to_find[0] & 0x01) {
1904 switch (priv->lane_version) {
1906 return priv->mcast_vcc;
1907 case 2: /* LANE2 wants arp for multicast addresses */
1908 if (!compare_ether_addr(mac_to_find, bus_mac))
1909 return priv->mcast_vcc;
1916 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1917 entry = lec_arp_find(priv, mac_to_find);
1920 if (entry->status == ESI_FORWARD_DIRECT) {
1922 entry->last_used = jiffies;
1923 lec_arp_hold(entry);
1929 * If the LE_ARP cache entry is still pending, reset count to 0
1930 * so another LE_ARP request can be made for this frame.
1932 if (entry->status == ESI_ARP_PENDING) {
1933 entry->no_tries = 0;
1936 * Data direct VC not yet set up, check to see if the unknown
1937 * frame count is greater than the limit. If the limit has
1938 * not been reached, allow the caller to send packet to
1941 if (entry->status != ESI_FLUSH_PENDING &&
1942 entry->packets_flooded <
1943 priv->maximum_unknown_frame_count) {
1944 entry->packets_flooded++;
1945 pr_debug("LEC_ARP: Flooding..\n");
1946 found = priv->mcast_vcc;
1950 * We got here because entry->status == ESI_FLUSH_PENDING
1951 * or BUS flood limit was reached for an entry which is
1952 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1954 lec_arp_hold(entry);
1956 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
1960 /* No matching entry was found */
1961 entry = make_entry(priv, mac_to_find);
1962 pr_debug("LEC_ARP: Making entry\n");
1964 found = priv->mcast_vcc;
1967 lec_arp_add(priv, entry);
1968 /* We want arp-request(s) to be sent */
1969 entry->packets_flooded = 1;
1970 entry->status = ESI_ARP_PENDING;
1971 entry->no_tries = 1;
1972 entry->last_used = entry->timestamp = jiffies;
1973 entry->is_rdesc = is_rdesc;
1974 if (entry->is_rdesc)
1975 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1978 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1979 entry->timer.expires = jiffies + (1 * HZ);
1980 entry->timer.function = lec_arp_expire_arp;
1981 add_timer(&entry->timer);
1982 found = priv->mcast_vcc;
1986 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1991 lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1992 unsigned long permanent)
1994 unsigned long flags;
1995 struct hlist_node *node, *next;
1996 struct lec_arp_table *entry;
1999 pr_debug("lec_addr_delete\n");
2000 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2001 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2002 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2003 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2005 !(entry->flags & LEC_PERMANENT_FLAG))) {
2006 lec_arp_remove(priv, entry);
2009 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2013 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2018 * Notifies: Response to arp_request (atm_addr != NULL)
2021 lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2022 const unsigned char *atm_addr, unsigned long remoteflag,
2023 unsigned int targetless_le_arp)
2025 unsigned long flags;
2026 struct hlist_node *node, *next;
2027 struct lec_arp_table *entry, *tmp;
2030 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2031 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2032 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2033 mac_addr[4], mac_addr[5]);
2035 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2036 entry = lec_arp_find(priv, mac_addr);
2037 if (entry == NULL && targetless_le_arp)
2039 * LANE2: ignore targetless LE_ARPs for which
2040 * we have no entry in the cache. 7.1.30
2042 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2043 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2044 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2045 hlist_del(&entry->next);
2046 del_timer(&entry->timer);
2047 tmp = lec_arp_find(priv, mac_addr);
2049 del_timer(&tmp->timer);
2050 tmp->status = ESI_FORWARD_DIRECT;
2051 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2052 tmp->vcc = entry->vcc;
2053 tmp->old_push = entry->old_push;
2054 tmp->last_used = jiffies;
2055 del_timer(&entry->timer);
2059 entry->status = ESI_FORWARD_DIRECT;
2060 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2061 entry->last_used = jiffies;
2062 lec_arp_add(priv, entry);
2065 entry->flags |= LEC_REMOTE_FLAG;
2067 entry->flags &= ~LEC_REMOTE_FLAG;
2068 pr_debug("After update\n");
2069 dump_arp_table(priv);
2075 entry = lec_arp_find(priv, mac_addr);
2077 entry = make_entry(priv, mac_addr);
2080 entry->status = ESI_UNKNOWN;
2081 lec_arp_add(priv, entry);
2082 /* Temporary, changes before end of function */
2084 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2085 del_timer(&entry->timer);
2086 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2087 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
2089 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2090 /* Vcc to this host exists */
2091 if (tmp->status > ESI_VC_PENDING) {
2093 * ESI_FLUSH_PENDING,
2094 * ESI_FORWARD_DIRECT
2096 entry->vcc = tmp->vcc;
2097 entry->old_push = tmp->old_push;
2099 entry->status = tmp->status;
2105 entry->flags |= LEC_REMOTE_FLAG;
2107 entry->flags &= ~LEC_REMOTE_FLAG;
2108 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2109 entry->status = ESI_VC_PENDING;
2110 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2112 pr_debug("After update2\n");
2113 dump_arp_table(priv);
2115 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2119 * Notifies: Vcc setup ready
2122 lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2123 struct atm_vcc *vcc,
2124 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
2126 unsigned long flags;
2127 struct hlist_node *node;
2128 struct lec_arp_table *entry;
2129 int i, found_entry = 0;
2131 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2132 if (ioc_data->receive == 2) {
2133 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2135 pr_debug("LEC_ARP: Attaching mcast forward\n");
2137 entry = lec_arp_find(priv, bus_mac);
2139 printk("LEC_ARP: Multicast entry not found!\n");
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 entry->recv_vcc = vcc;
2144 entry->old_recv_push = old_push;
2146 entry = make_entry(priv, bus_mac);
2149 del_timer(&entry->timer);
2150 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2151 entry->recv_vcc = vcc;
2152 entry->old_recv_push = old_push;
2153 hlist_add_head(&entry->next, &priv->mcast_fwds);
2155 } else if (ioc_data->receive == 1) {
2157 * Vcc which we don't want to make default vcc,
2161 ("LEC_ARP:Attaching data direct, not default: "
2162 "%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",
2163 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2164 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2165 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2166 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2167 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2168 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2169 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2170 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2171 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2172 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2173 entry = make_entry(priv, bus_mac);
2176 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2177 memset(entry->mac_addr, 0, ETH_ALEN);
2178 entry->recv_vcc = vcc;
2179 entry->old_recv_push = old_push;
2180 entry->status = ESI_UNKNOWN;
2181 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2182 entry->timer.function = lec_arp_expire_vcc;
2183 hlist_add_head(&entry->next, &priv->lec_no_forward);
2184 add_timer(&entry->timer);
2185 dump_arp_table(priv);
2189 ("LEC_ARP:Attaching data direct, default: "
2190 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2191 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2192 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2193 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2194 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2195 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2196 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2197 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2198 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2199 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2200 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2201 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2202 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2204 (ioc_data->atm_addr, entry->atm_addr,
2205 ATM_ESA_LEN) == 0) {
2206 pr_debug("LEC_ARP: Attaching data direct\n");
2207 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2208 entry->vcc ? entry->vcc->vci : 0,
2209 entry->recv_vcc ? entry->recv_vcc->
2212 del_timer(&entry->timer);
2214 entry->old_push = old_push;
2215 if (entry->status == ESI_VC_PENDING) {
2216 if (priv->maximum_unknown_frame_count
2221 entry->timestamp = jiffies;
2225 send_to_lecd(priv, l_flush_xmt,
2233 * They were forming a connection
2234 * to us, and we to them. Our
2235 * ATM address is numerically lower
2236 * than theirs, so we make connection
2237 * we formed into default VCC (8.1.11).
2238 * Connection they made gets torn
2239 * down. This might confuse some
2240 * clients. Can be changed if
2241 * someone reports trouble...
2249 pr_debug("After vcc was added\n");
2250 dump_arp_table(priv);
2254 * Not found, snatch address from first data packet that arrives
2257 entry = make_entry(priv, bus_mac);
2261 entry->old_push = old_push;
2262 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2263 memset(entry->mac_addr, 0, ETH_ALEN);
2264 entry->status = ESI_UNKNOWN;
2265 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
2266 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2267 entry->timer.function = lec_arp_expire_vcc;
2268 add_timer(&entry->timer);
2269 pr_debug("After vcc was added\n");
2270 dump_arp_table(priv);
2272 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2275 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2277 unsigned long flags;
2278 struct hlist_node *node;
2279 struct lec_arp_table *entry;
2282 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
2284 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2285 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2286 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2287 if (entry->flush_tran_id == tran_id
2288 && entry->status == ESI_FLUSH_PENDING) {
2289 struct sk_buff *skb;
2290 struct atm_vcc *vcc = entry->vcc;
2292 lec_arp_hold(entry);
2293 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2294 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2296 entry->last_used = jiffies;
2297 entry->status = ESI_FORWARD_DIRECT;
2299 pr_debug("LEC_ARP: Flushed\n");
2304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2305 dump_arp_table(priv);
2309 lec_set_flush_tran_id(struct lec_priv *priv,
2310 const unsigned char *atm_addr, unsigned long tran_id)
2312 unsigned long flags;
2313 struct hlist_node *node;
2314 struct lec_arp_table *entry;
2317 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2318 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2319 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2320 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2321 entry->flush_tran_id = tran_id;
2322 pr_debug("Set flush transaction id to %lx for %p\n",
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2329 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2331 unsigned long flags;
2332 unsigned char mac_addr[] = {
2333 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2335 struct lec_arp_table *to_add;
2336 struct lec_vcc_priv *vpriv;
2339 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2342 vpriv->old_pop = vcc->pop;
2343 vcc->user_back = vpriv;
2345 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2346 to_add = make_entry(priv, mac_addr);
2348 vcc->pop = vpriv->old_pop;
2353 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2354 to_add->status = ESI_FORWARD_DIRECT;
2355 to_add->flags |= LEC_PERMANENT_FLAG;
2357 to_add->old_push = vcc->push;
2358 vcc->push = lec_push;
2359 priv->mcast_vcc = vcc;
2360 lec_arp_add(priv, to_add);
2362 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2366 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2368 unsigned long flags;
2369 struct hlist_node *node, *next;
2370 struct lec_arp_table *entry;
2373 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2374 dump_arp_table(priv);
2376 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2378 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2379 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2380 if (vcc == entry->vcc) {
2381 lec_arp_remove(priv, entry);
2383 if (priv->mcast_vcc == vcc) {
2384 priv->mcast_vcc = NULL;
2390 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2391 if (entry->vcc == vcc) {
2392 lec_arp_clear_vccs(entry);
2393 del_timer(&entry->timer);
2394 hlist_del(&entry->next);
2399 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
2400 if (entry->recv_vcc == vcc) {
2401 lec_arp_clear_vccs(entry);
2402 del_timer(&entry->timer);
2403 hlist_del(&entry->next);
2408 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
2409 if (entry->recv_vcc == vcc) {
2410 lec_arp_clear_vccs(entry);
2411 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2412 hlist_del(&entry->next);
2417 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2418 dump_arp_table(priv);
2422 lec_arp_check_empties(struct lec_priv *priv,
2423 struct atm_vcc *vcc, struct sk_buff *skb)
2425 unsigned long flags;
2426 struct hlist_node *node, *next;
2427 struct lec_arp_table *entry, *tmp;
2428 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2431 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2434 src = tr_hdr->h_source;
2437 src = hdr->h_source;
2439 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2440 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2441 if (vcc == entry->vcc) {
2442 del_timer(&entry->timer);
2443 memcpy(entry->mac_addr, src, ETH_ALEN);
2444 entry->status = ESI_FORWARD_DIRECT;
2445 entry->last_used = jiffies;
2446 /* We might have got an entry */
2447 if ((tmp = lec_arp_find(priv, src))) {
2448 lec_arp_remove(priv, tmp);
2451 hlist_del(&entry->next);
2452 lec_arp_add(priv, entry);
2456 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2458 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2461 MODULE_LICENSE("GPL");