2 * lec.c: Lan Emulation driver
3 * Marko Kiiskila carnil@cs.tut.fi
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/bitops.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>
24 /* TokenRing if needed */
26 #include <linux/trdevice.h>
30 #include <linux/atmdev.h>
31 #include <linux/atmlec.h>
33 /* Proxy LEC knows about bridging */
34 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
35 #include <linux/if_bridge.h>
36 #include "../bridge/br_private.h"
37 static unsigned char bridge_ula_lec[] = {0x01, 0x80, 0xc2, 0x00, 0x00};
41 #include <linux/module.h>
42 #include <linux/init.h>
46 #include "resources.h" /* for bind_vcc() */
49 #define DPRINTK printk
51 #define DPRINTK(format,args...)
54 extern struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
56 extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
59 #define DUMP_PACKETS 0 /* 0 = None,
64 #define LEC_UNRES_QUE_LEN 8 /* number of tx packets to queue for a
65 single destination while waiting for SVC */
67 static int lec_open(struct net_device *dev);
68 static int lec_send_packet(struct sk_buff *skb, struct net_device *dev);
69 static int lec_close(struct net_device *dev);
70 static struct net_device_stats *lec_get_stats(struct net_device *dev);
71 static void lec_init(struct net_device *dev);
72 static __inline__ struct lec_arp_table* lec_arp_find(struct lec_priv *priv,
73 unsigned char *mac_addr);
74 static __inline__ int lec_arp_remove(struct lec_arp_table **lec_arp_tables,
75 struct lec_arp_table *to_remove);
77 static void lane2_associate_ind (struct net_device *dev, u8 *mac_address,
78 u8 *tlvs, u32 sizeoftlvs);
79 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
80 u8 **tlvs, u32 *sizeoftlvs);
81 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
82 u8 *tlvs, u32 sizeoftlvs);
84 static struct lane2_ops lane2_ops = {
85 lane2_resolve, /* resolve, spec 3.1.3 */
86 lane2_associate_req, /* associate_req, spec 3.1.4 */
87 NULL /* associate indicator, spec 3.1.5 */
90 static unsigned char bus_mac[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
92 /* Device structures */
93 static struct net_device *dev_lec[MAX_LEC_ITF];
95 /* This will be called from proc.c via function pointer */
96 struct net_device **get_dev_lec (void) {
100 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
101 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
105 struct lec_priv *priv;
107 /* Check if this is a BPDU. If so, ask zeppelin to send
108 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
109 * as the Config BPDU has */
110 eth = (struct ethhdr *)skb->data;
111 buff = skb->data + skb->dev->hard_header_len;
112 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
113 struct sk_buff *skb2;
114 struct atmlec_msg *mesg;
116 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
117 if (skb2 == NULL) return;
118 skb2->len = sizeof(struct atmlec_msg);
119 mesg = (struct atmlec_msg *)skb2->data;
120 mesg->type = l_topology_change;
122 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
124 priv = (struct lec_priv *)dev->priv;
125 atm_force_charge(priv->lecd, skb2->truesize);
126 skb_queue_tail(&priv->lecd->recvq, skb2);
127 wake_up(&priv->lecd->sleep);
132 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
135 * Modelled after tr_type_trans
136 * All multicast and ARE or STE frames go to BUS.
137 * Non source routed frames go by destination address.
138 * Last hop source routed frames go by destination address.
139 * Not last hop source routed frames go by _next_ route descriptor.
140 * Returns pointer to destination MAC address or fills in rdesc
144 unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
147 int riflen, num_rdsc;
149 trh = (struct trh_hdr *)packet;
150 if (trh->daddr[0] & (uint8_t)0x80)
151 return bus_mac; /* multicast */
153 if (trh->saddr[0] & TR_RII) {
154 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
155 if ((ntohs(trh->rcf) >> 13) != 0)
156 return bus_mac; /* ARE or STE */
159 return trh->daddr; /* not source routed */
162 return trh->daddr; /* last hop, source routed */
164 /* riflen is 6 or more, packet has more than one route descriptor */
165 num_rdsc = (riflen/2) - 1;
166 memset(rdesc, 0, ETH_ALEN);
167 /* offset 4 comes from LAN destination field in LE control frames */
168 if (trh->rcf & htons((uint16_t)TR_RCF_DIR_BIT))
169 memcpy(&rdesc[4], &trh->rseg[num_rdsc-2], sizeof(uint16_t));
171 memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
172 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
177 #endif /* CONFIG_TR */
180 * Open/initialize the netdevice. This is called (in the current kernel)
181 * sometime after booting when the 'ifconfig' program is run.
183 * This routine should set everything up anew at each open, even
184 * registers that "should" only need to be set once at boot, so that
185 * there is non-reboot way to recover if something goes wrong.
189 lec_open(struct net_device *dev)
191 struct lec_priv *priv = (struct lec_priv *)dev->priv;
193 netif_start_queue(dev);
194 memset(&priv->stats,0,sizeof(struct net_device_stats));
200 lec_send_packet(struct sk_buff *skb, struct net_device *dev)
202 struct sk_buff *skb2;
203 struct lec_priv *priv = (struct lec_priv *)dev->priv;
204 struct lecdatahdr_8023 *lec_h;
205 struct atm_vcc *send_vcc;
206 struct lec_arp_table *entry;
207 unsigned char *nb, *dst;
209 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
215 #endif /* DUMP_PACKETS >0 */
217 DPRINTK("Lec_send_packet called\n");
219 printk("%s:No lecd attached\n",dev->name);
220 priv->stats.tx_errors++;
221 netif_stop_queue(dev);
225 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
226 (long)skb->head, (long)skb->data, (long)skb->tail,
228 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
229 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
230 lec_handle_bridge(skb, dev);
233 /* Make sure we have room for lec_id */
234 if (skb_headroom(skb) < 2) {
236 DPRINTK("lec_send_packet: reallocating skb\n");
237 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
239 if (skb2 == NULL) return 0;
244 /* Put le header to place, works for TokenRing too */
245 lec_h = (struct lecdatahdr_8023*)skb->data;
246 lec_h->le_header = htons(priv->lecid);
249 /* Ugly. Use this to realign Token Ring packets for
250 * e.g. PCA-200E driver. */
251 if (priv->is_trdev) {
252 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
254 if (skb2 == NULL) return 0;
260 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
261 skb->len, priv->lecid);
262 #if DUMP_PACKETS >= 2
263 for(i=0;i<skb->len && i <99;i++) {
264 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
266 #elif DUMP_PACKETS >= 1
267 for(i=0;i<skb->len && i < 30;i++) {
268 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
270 #endif /* DUMP_PACKETS >= 1 */
274 printk("%s...\n",buf);
275 #endif /* DUMP_PACKETS > 0 */
277 /* Minimum ethernet-frame size */
279 if (skb->truesize < 62) {
280 printk("%s:data packet %d / %d\n",
282 skb->len,skb->truesize);
283 nb=(unsigned char*)kmalloc(64, GFP_ATOMIC);
288 memcpy(nb,skb->data,skb->len);
290 skb->head = skb->data = nb;
300 /* Send to right vcc */
304 if (priv->is_trdev) {
305 dst = get_tr_dst(skb->data+2, rdesc);
313 send_vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
314 DPRINTK("%s:send_vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
315 send_vcc, send_vcc?send_vcc->flags:0, entry);
316 if (!send_vcc || !test_bit(ATM_VF_READY,&send_vcc->flags)) {
317 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
318 DPRINTK("%s:lec_send_packet: queuing packet, ", dev->name);
319 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
320 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
321 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
322 skb_queue_tail(&entry->tx_wait, skb);
324 DPRINTK("%s:lec_send_packet: tx queue full or no arp entry, dropping, ", dev->name);
325 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
326 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
327 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
328 priv->stats.tx_dropped++;
335 printk("%s:sending to vpi:%d vci:%d\n", dev->name,
336 send_vcc->vpi, send_vcc->vci);
337 #endif /* DUMP_PACKETS > 0 */
339 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
340 DPRINTK("lec.c: emptying tx queue, ");
341 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
342 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
343 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
344 ATM_SKB(skb2)->vcc = send_vcc;
345 ATM_SKB(skb2)->iovcnt = 0;
346 ATM_SKB(skb2)->atm_options = send_vcc->atm_options;
347 DPRINTK("%s:sending to vpi:%d vci:%d\n", dev->name,
348 send_vcc->vpi, send_vcc->vci);
349 if (atm_may_send(send_vcc, skb2->len)) {
350 atomic_add(skb2->truesize, &send_vcc->tx_inuse);
351 priv->stats.tx_packets++;
352 priv->stats.tx_bytes += skb2->len;
353 send_vcc->send(send_vcc, skb2);
355 priv->stats.tx_dropped++;
360 ATM_SKB(skb)->vcc = send_vcc;
361 ATM_SKB(skb)->iovcnt = 0;
362 ATM_SKB(skb)->atm_options = send_vcc->atm_options;
363 if (atm_may_send(send_vcc, skb->len)) {
364 atomic_add(skb->truesize, &send_vcc->tx_inuse);
365 priv->stats.tx_packets++;
366 priv->stats.tx_bytes += skb->len;
367 send_vcc->send(send_vcc, skb);
369 priv->stats.tx_dropped++;
374 /* Should we wait for card's device driver to notify us? */
380 /* The inverse routine to net_open(). */
382 lec_close(struct net_device *dev)
384 netif_stop_queue(dev);
389 * Get the current statistics.
390 * This may be called with the card open or closed.
392 static struct net_device_stats *
393 lec_get_stats(struct net_device *dev)
395 return &((struct lec_priv *)dev->priv)->stats;
399 lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
401 struct net_device *dev = (struct net_device*)vcc->proto_data;
402 struct lec_priv *priv = (struct lec_priv*)dev->priv;
403 struct atmlec_msg *mesg;
404 struct lec_arp_table *entry;
406 char *tmp; /* FIXME */
408 atomic_sub(skb->truesize+ATM_PDU_OVHD, &vcc->tx_inuse);
409 mesg = (struct atmlec_msg *)skb->data;
411 tmp += sizeof(struct atmlec_msg);
412 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
416 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
421 dev->dev_addr[i] = 0;
425 lec_addr_delete(priv, mesg->content.normal.atm_addr,
426 mesg->content.normal.flag);
428 case l_topology_change:
429 priv->topology_change = mesg->content.normal.flag;
431 case l_flush_complete:
432 lec_flush_complete(priv, mesg->content.normal.flag);
434 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
435 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
436 lec_arp_remove(priv->lec_arp_tables, entry);
438 if (mesg->content.normal.no_source_le_narp)
442 lec_arp_update(priv, mesg->content.normal.mac_addr,
443 mesg->content.normal.atm_addr,
444 mesg->content.normal.flag,
445 mesg->content.normal.targetless_le_arp);
446 DPRINTK("lec: in l_arp_update\n");
447 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
448 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n", mesg->sizeoftlvs);
449 lane2_associate_ind(dev,
450 mesg->content.normal.mac_addr,
451 tmp, mesg->sizeoftlvs);
455 priv->maximum_unknown_frame_count =
456 mesg->content.config.maximum_unknown_frame_count;
457 priv->max_unknown_frame_time =
458 (mesg->content.config.max_unknown_frame_time*HZ);
459 priv->max_retry_count =
460 mesg->content.config.max_retry_count;
461 priv->aging_time = (mesg->content.config.aging_time*HZ);
462 priv->forward_delay_time =
463 (mesg->content.config.forward_delay_time*HZ);
464 priv->arp_response_time =
465 (mesg->content.config.arp_response_time*HZ);
466 priv->flush_timeout = (mesg->content.config.flush_timeout*HZ);
467 priv->path_switching_delay =
468 (mesg->content.config.path_switching_delay*HZ);
469 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
470 priv->lane2_ops = NULL;
471 if (priv->lane_version > 1)
472 priv->lane2_ops = &lane2_ops;
473 if (dev->change_mtu(dev, mesg->content.config.mtu))
474 printk("%s: change_mtu to %d failed\n", dev->name,
475 mesg->content.config.mtu);
476 priv->is_proxy = mesg->content.config.is_proxy;
478 case l_flush_tran_id:
479 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
480 mesg->content.normal.flag);
483 priv->lecid=(unsigned short)(0xffff&mesg->content.normal.flag);
485 case l_should_bridge: {
486 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
487 struct net_bridge_fdb_entry *f;
489 DPRINTK("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
491 mesg->content.proxy.mac_addr[0], mesg->content.proxy.mac_addr[1],
492 mesg->content.proxy.mac_addr[2], mesg->content.proxy.mac_addr[3],
493 mesg->content.proxy.mac_addr[4], mesg->content.proxy.mac_addr[5]);
495 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
498 f = br_fdb_get_hook(dev->br_port->br, mesg->content.proxy.mac_addr);
500 f->dst->dev != dev &&
501 f->dst->state == BR_STATE_FORWARDING) {
502 /* hit from bridge table, send LE_ARP_RESPONSE */
503 struct sk_buff *skb2;
505 DPRINTK("%s: entry found, responding to zeppelin\n", dev->name);
506 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
511 skb2->len = sizeof(struct atmlec_msg);
512 memcpy(skb2->data, mesg, sizeof(struct atmlec_msg));
513 atm_force_charge(priv->lecd, skb2->truesize);
514 skb_queue_tail(&priv->lecd->recvq, skb2);
515 wake_up(&priv->lecd->sleep);
517 if (f != NULL) br_fdb_put_hook(f);
518 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
522 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
531 lec_atm_close(struct atm_vcc *vcc)
534 struct net_device *dev = (struct net_device *)vcc->proto_data;
535 struct lec_priv *priv = (struct lec_priv *)dev->priv;
538 /* Do something needful? */
540 netif_stop_queue(dev);
541 lec_arp_destroy(priv);
543 if (skb_peek(&vcc->recvq))
544 printk("%s lec_atm_close: closing with messages pending\n",
546 while ((skb = skb_dequeue(&vcc->recvq))) {
547 atm_return(vcc, skb->truesize);
551 printk("%s: Shut down!\n", dev->name);
555 static struct atmdev_ops lecdev_ops = {
556 close: lec_atm_close,
560 static struct atm_dev lecatm_dev = {
564 999, /*dummy device number*/
565 NULL,NULL, /*no VCCs*/
566 NULL,NULL, /*no data*/
568 NULL, /* no local address*/
569 { 0 } /*no ESI or rest of the atm_dev struct things*/
573 * LANE2: new argument struct sk_buff *data contains
574 * the LE_ARP based TLVs introduced in the LANE2 spec
577 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
578 unsigned char *mac_addr, unsigned char *atm_addr,
579 struct sk_buff *data)
582 struct atmlec_msg *mesg;
584 if (!priv || !priv->lecd) {
587 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
590 skb->len = sizeof(struct atmlec_msg);
591 mesg = (struct atmlec_msg *)skb->data;
592 memset(mesg, 0, sizeof(struct atmlec_msg));
595 mesg->sizeoftlvs = data->len;
597 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
599 mesg->content.normal.targetless_le_arp = 1;
601 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
603 atm_force_charge(priv->lecd, skb->truesize);
604 skb_queue_tail(&priv->lecd->recvq, skb);
605 wake_up(&priv->lecd->sleep);
608 DPRINTK("lec: about to send %d bytes of data\n", data->len);
609 atm_force_charge(priv->lecd, data->truesize);
610 skb_queue_tail(&priv->lecd->recvq, data);
611 wake_up(&priv->lecd->sleep);
617 /* shamelessly stolen from drivers/net/net_init.c */
618 static int lec_change_mtu(struct net_device *dev, int new_mtu)
620 if ((new_mtu < 68) || (new_mtu > 18190))
627 lec_init(struct net_device *dev)
629 dev->change_mtu = lec_change_mtu;
630 dev->open = lec_open;
631 dev->stop = lec_close;
632 dev->hard_start_xmit = lec_send_packet;
634 dev->get_stats = lec_get_stats;
635 dev->set_multicast_list = NULL;
636 dev->do_ioctl = NULL;
637 printk("%s: Initialized!\n",dev->name);
641 static unsigned char lec_ctrl_magic[] = {
648 lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
650 struct net_device *dev = (struct net_device *)vcc->proto_data;
651 struct lec_priv *priv = (struct lec_priv *)dev->priv;
657 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
661 DPRINTK("%s: null skb\n",dev->name);
662 lec_vcc_close(priv, vcc);
666 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
667 skb->len, priv->lecid);
668 #if DUMP_PACKETS >= 2
669 for(i=0;i<skb->len && i <99;i++) {
670 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
672 #elif DUMP_PACKETS >= 1
673 for(i=0;i<skb->len && i < 30;i++) {
674 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
676 #endif /* DUMP_PACKETS >= 1 */
680 printk("%s...\n",buf);
681 #endif /* DUMP_PACKETS > 0 */
682 if (memcmp(skb->data, lec_ctrl_magic, 4) ==0) { /* Control frame, to daemon*/
683 DPRINTK("%s: To daemon\n",dev->name);
684 skb_queue_tail(&vcc->recvq, skb);
685 wake_up(&vcc->sleep);
686 } else { /* Data frame, queue to protocol handlers */
689 atm_return(vcc,skb->truesize);
690 if (*(uint16_t *)skb->data == htons(priv->lecid) ||
692 /* Probably looping back, or if lecd is missing,
693 lecd has gone down */
694 DPRINTK("Ignoring loopback frame...\n");
699 if (priv->is_trdev) dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
702 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
704 if (!(dst[0]&0x01) && /* Never filter Multi/Broadcast */
705 !priv->is_proxy && /* Proxy wants all the packets */
706 memcmp(dst, dev->dev_addr, dev->addr_len)) {
710 if (priv->lec_arp_empty_ones) {
711 lec_arp_check_empties(priv, vcc, skb);
714 skb->data += 2; /* skip lec_id */
716 if (priv->is_trdev) skb->protocol = tr_type_trans(skb, dev);
719 skb->protocol = eth_type_trans(skb, dev);
720 priv->stats.rx_packets++;
721 priv->stats.rx_bytes += skb->len;
727 lec_vcc_attach(struct atm_vcc *vcc, void *arg)
730 struct atmlec_ioc ioc_data;
732 /* Lecd must be up in this case */
733 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
734 if (bytes_left != 0) {
735 printk("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
738 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
739 !dev_lec[ioc_data.dev_num])
741 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
742 &ioc_data, vcc, vcc->push);
743 vcc->push = lec_push;
744 vcc->proto_data = dev_lec[ioc_data.dev_num];
749 lec_mcast_attach(struct atm_vcc *vcc, int arg)
751 if (arg <0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
753 vcc->proto_data = dev_lec[arg];
754 return (lec_mcast_make((struct lec_priv*)dev_lec[arg]->priv, vcc));
757 /* Initialize device. */
759 lecd_attach(struct atm_vcc *vcc, int arg)
762 struct lec_priv *priv;
769 if (arg >= MAX_LEC_ITF)
771 #else /* Reserve the top NUM_TR_DEVS for TR */
772 if (arg >= (MAX_LEC_ITF-NUM_TR_DEVS))
779 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
782 size = sizeof(struct lec_priv);
785 dev_lec[i] = init_trdev(NULL, size);
788 dev_lec[i] = init_etherdev(NULL, size);
792 priv = dev_lec[i]->priv;
793 priv->is_trdev = is_trdev;
794 sprintf(dev_lec[i]->name, "lec%d", i);
795 lec_init(dev_lec[i]);
797 priv = dev_lec[i]->priv;
802 priv->itfnum = i; /* LANE2 addition */
804 bind_vcc(vcc, &lecatm_dev);
806 vcc->proto_data = dev_lec[i];
807 set_bit(ATM_VF_META,&vcc->flags);
808 set_bit(ATM_VF_READY,&vcc->flags);
810 /* Set default values to these variables */
811 priv->maximum_unknown_frame_count = 1;
812 priv->max_unknown_frame_time = (1*HZ);
813 priv->vcc_timeout_period = (1200*HZ);
814 priv->max_retry_count = 1;
815 priv->aging_time = (300*HZ);
816 priv->forward_delay_time = (15*HZ);
817 priv->topology_change = 0;
818 priv->arp_response_time = (1*HZ);
819 priv->flush_timeout = (4*HZ);
820 priv->path_switching_delay = (6*HZ);
822 if (dev_lec[i]->flags & IFF_UP) {
823 netif_start_queue(dev_lec[i]);
829 void atm_lane_init_ops(struct atm_lane_ops *ops)
831 ops->lecd_attach = lecd_attach;
832 ops->mcast_attach = lec_mcast_attach;
833 ops->vcc_attach = lec_vcc_attach;
834 ops->get_lecs = get_dev_lec;
836 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
841 static int __init lane_module_init(void)
843 extern struct atm_lane_ops atm_lane_ops;
845 atm_lane_init_ops(&atm_lane_ops);
850 static void __exit lane_module_cleanup(void)
853 extern struct atm_lane_ops atm_lane_ops;
854 struct lec_priv *priv;
856 atm_lane_ops.lecd_attach = NULL;
857 atm_lane_ops.mcast_attach = NULL;
858 atm_lane_ops.vcc_attach = NULL;
859 atm_lane_ops.get_lecs = NULL;
861 for (i = 0; i < MAX_LEC_ITF; i++) {
862 if (dev_lec[i] != NULL) {
863 priv = (struct lec_priv *)dev_lec[i]->priv;
864 #if defined(CONFIG_TR)
866 unregister_trdev(dev_lec[i]);
869 unregister_netdev(dev_lec[i]);
878 module_init(lane_module_init);
879 module_exit(lane_module_cleanup);
882 * LANE2: 3.1.3, LE_RESOLVE.request
883 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
884 * If sizeoftlvs == NULL the default TLVs associated with with this
886 * If dst_mac == NULL, targetless LE_ARP will be sent
888 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
889 u8 **tlvs, u32 *sizeoftlvs)
891 struct lec_priv *priv = (struct lec_priv *)dev->priv;
892 struct lec_arp_table *table;
897 table = lec_arp_find(priv, dst_mac);
901 *tlvs = kmalloc(table->sizeoftlvs, GFP_KERNEL);
905 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
906 *sizeoftlvs = table->sizeoftlvs;
911 if (sizeoftlvs == NULL)
912 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
915 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
918 skb->len = *sizeoftlvs;
919 memcpy(skb->data, *tlvs, *sizeoftlvs);
920 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
927 * LANE2: 3.1.4, LE_ASSOCIATE.request
928 * Associate the *tlvs with the *lan_dst address.
929 * Will overwrite any previous association
930 * Returns 1 for success, 0 for failure (out of memory)
933 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
934 u8 *tlvs, u32 sizeoftlvs)
938 struct lec_priv *priv = (struct lec_priv*)dev->priv;
940 if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
941 return (0); /* not our mac address */
943 kfree(priv->tlvs); /* NULL if there was no previous association */
945 priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
946 if (priv->tlvs == NULL)
948 priv->sizeoftlvs = sizeoftlvs;
949 memcpy(priv->tlvs, tlvs, sizeoftlvs);
951 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
954 skb->len = sizeoftlvs;
955 memcpy(skb->data, tlvs, sizeoftlvs);
956 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
958 printk("lec.c: lane2_associate_req() failed\n");
959 /* If the previous association has changed we must
960 * somehow notify other LANE entities about the change
966 * LANE2: 3.1.5, LE_ASSOCIATE.indication
969 static void lane2_associate_ind (struct net_device *dev, u8 *mac_addr,
970 u8 *tlvs, u32 sizeoftlvs)
975 struct lec_priv *priv = (struct lec_priv *)dev->priv;
976 #if 0 /* Why have the TLVs in LE_ARP entries since we do not use them? When you
977 uncomment this code, make sure the TLVs get freed when entry is killed */
978 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
981 return; /* should not happen */
985 entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
986 if (entry->tlvs == NULL)
989 entry->sizeoftlvs = sizeoftlvs;
990 memcpy(entry->tlvs, tlvs, sizeoftlvs);
993 printk("lec.c: lane2_associate_ind()\n");
994 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
995 while (i < sizeoftlvs)
996 printk("%02x ", tlvs[i++]);
1001 /* tell MPOA about the TLVs we saw */
1002 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1003 priv->lane2_ops->associate_indicator(dev, mac_addr,
1010 * Here starts what used to lec_arpc.c
1012 * lec_arpc.c was added here when making
1013 * lane client modular. October 1997
1017 #include <linux/types.h>
1018 #include <linux/sched.h>
1019 #include <linux/timer.h>
1020 #include <asm/param.h>
1021 #include <asm/atomic.h>
1022 #include <linux/inetdevice.h>
1023 #include <net/route.h>
1027 #define DPRINTK(format,args...)
1029 #define DPRINTK printk
1032 #define DEBUG_ARP_TABLE 0
1034 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1036 static void lec_arp_check_expire(unsigned long data);
1037 static __inline__ void lec_arp_expire_arp(unsigned long data);
1038 void dump_arp_table(struct lec_priv *priv);
1044 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1046 static __inline__ void
1047 lec_arp_lock(struct lec_priv *priv)
1049 atomic_inc(&priv->lec_arp_lock_var);
1052 static __inline__ void
1053 lec_arp_unlock(struct lec_priv *priv)
1055 atomic_dec(&priv->lec_arp_lock_var);
1059 * Initialization of arp-cache
1062 lec_arp_init(struct lec_priv *priv)
1066 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1067 priv->lec_arp_tables[i] = NULL;
1069 init_timer(&priv->lec_arp_timer);
1070 priv->lec_arp_timer.expires = jiffies+LEC_ARP_REFRESH_INTERVAL;
1071 priv->lec_arp_timer.data = (unsigned long)priv;
1072 priv->lec_arp_timer.function = lec_arp_check_expire;
1073 add_timer(&priv->lec_arp_timer);
1077 lec_arp_clear_vccs(struct lec_arp_table *entry)
1080 entry->vcc->push = entry->old_push;
1081 #if 0 /* August 6, 1998 */
1082 set_bit(ATM_VF_RELEASED,&entry->vcc->flags);
1083 clear_bit(ATM_VF_READY,&entry->vcc->flags);
1084 entry->vcc->push(entry->vcc, NULL);
1086 atm_async_release_vcc(entry->vcc, -EPIPE);
1089 if (entry->recv_vcc) {
1090 entry->recv_vcc->push = entry->old_recv_push;
1092 set_bit(ATM_VF_RELEASED,&entry->recv_vcc->flags);
1093 clear_bit(ATM_VF_READY,&entry->recv_vcc->flags);
1094 entry->recv_vcc->push(entry->recv_vcc, NULL);
1096 atm_async_release_vcc(entry->recv_vcc, -EPIPE);
1097 entry->recv_vcc = NULL;
1102 * Insert entry to lec_arp_table
1103 * LANE2: Add to the end of the list to satisfy 8.1.13
1105 static __inline__ void
1106 lec_arp_put(struct lec_arp_table **lec_arp_tables,
1107 struct lec_arp_table *to_put)
1109 unsigned short place;
1110 unsigned long flags;
1111 struct lec_arp_table *tmp;
1116 place = HASH(to_put->mac_addr[ETH_ALEN-1]);
1117 tmp = lec_arp_tables[place];
1118 to_put->next = NULL;
1120 lec_arp_tables[place] = to_put;
1122 else { /* add to the end */
1128 restore_flags(flags);
1129 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1130 0xff&to_put->mac_addr[0], 0xff&to_put->mac_addr[1],
1131 0xff&to_put->mac_addr[2], 0xff&to_put->mac_addr[3],
1132 0xff&to_put->mac_addr[4], 0xff&to_put->mac_addr[5]);
1136 * Remove entry from lec_arp_table
1138 static __inline__ int
1139 lec_arp_remove(struct lec_arp_table **lec_arp_tables,
1140 struct lec_arp_table *to_remove)
1142 unsigned short place;
1143 struct lec_arp_table *tmp;
1144 unsigned long flags;
1151 restore_flags(flags);
1154 place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
1155 tmp = lec_arp_tables[place];
1156 if (tmp == to_remove) {
1157 lec_arp_tables[place] = tmp->next;
1159 while(tmp && tmp->next != to_remove) {
1162 if (!tmp) {/* Entry was not found */
1163 restore_flags(flags);
1167 tmp->next = to_remove->next;
1168 del_timer(&to_remove->timer);
1170 /* If this is the only MAC connected to this VCC, also tear down
1172 if (to_remove->status >= ESI_FLUSH_PENDING) {
1174 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1176 for(place=0;place<LEC_ARP_TABLE_SIZE;place++) {
1177 for(tmp=lec_arp_tables[place];tmp!=NULL;tmp=tmp->next){
1178 if (memcmp(tmp->atm_addr, to_remove->atm_addr,
1186 lec_arp_clear_vccs(to_remove);
1188 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1189 restore_flags(flags);
1190 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1191 0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
1192 0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
1193 0xff&to_remove->mac_addr[4], 0xff&to_remove->mac_addr[5]);
1199 get_status_string(unsigned char st)
1203 return "ESI_UNKNOWN";
1204 case ESI_ARP_PENDING:
1205 return "ESI_ARP_PENDING";
1206 case ESI_VC_PENDING:
1207 return "ESI_VC_PENDING";
1208 case ESI_FLUSH_PENDING:
1209 return "ESI_FLUSH_PENDING";
1210 case ESI_FORWARD_DIRECT:
1211 return "ESI_FORWARD_DIRECT";
1219 dump_arp_table(struct lec_priv *priv)
1223 struct lec_arp_table *rulla;
1225 struct lec_arp_table **lec_arp_tables =
1226 (struct lec_arp_table **)priv->lec_arp_tables;
1227 struct lec_arp_table *lec_arp_empty_ones =
1228 (struct lec_arp_table *)priv->lec_arp_empty_ones;
1229 struct lec_arp_table *lec_no_forward =
1230 (struct lec_arp_table *)priv->lec_no_forward;
1231 struct lec_arp_table *mcast_fwds = priv->mcast_fwds;
1234 printk("Dump %p:\n",priv);
1235 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1236 rulla = lec_arp_tables[i];
1238 offset += sprintf(buf,"%d: %p\n",i, rulla);
1240 offset += sprintf(buf+offset,"Mac:");
1241 for(j=0;j<ETH_ALEN;j++) {
1242 offset+=sprintf(buf+offset,
1244 rulla->mac_addr[j]&0xff);
1246 offset +=sprintf(buf+offset,"Atm:");
1247 for(j=0;j<ATM_ESA_LEN;j++) {
1248 offset+=sprintf(buf+offset,
1250 rulla->atm_addr[j]&0xff);
1252 offset+=sprintf(buf+offset,
1253 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1254 rulla->vcc?rulla->vcc->vpi:0,
1255 rulla->vcc?rulla->vcc->vci:0,
1256 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1257 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1259 rulla->timestamp, rulla->no_tries);
1260 offset+=sprintf(buf+offset,
1261 "Flags:%x, Packets_flooded:%x, Status: %s ",
1262 rulla->flags, rulla->packets_flooded,
1263 get_status_string(rulla->status));
1264 offset+=sprintf(buf+offset,"->%p\n",rulla->next);
1265 rulla = rulla->next;
1269 rulla = lec_no_forward;
1271 printk("No forward\n");
1274 offset += sprintf(buf+offset,"Mac:");
1275 for(j=0;j<ETH_ALEN;j++) {
1276 offset+=sprintf(buf+offset,"%2.2x ",
1277 rulla->mac_addr[j]&0xff);
1279 offset +=sprintf(buf+offset,"Atm:");
1280 for(j=0;j<ATM_ESA_LEN;j++) {
1281 offset+=sprintf(buf+offset,"%2.2x ",
1282 rulla->atm_addr[j]&0xff);
1284 offset+=sprintf(buf+offset,
1285 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1286 rulla->vcc?rulla->vcc->vpi:0,
1287 rulla->vcc?rulla->vcc->vci:0,
1288 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1289 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1291 rulla->timestamp, rulla->no_tries);
1292 offset+=sprintf(buf+offset,
1293 "Flags:%x, Packets_flooded:%x, Status: %s ",
1294 rulla->flags, rulla->packets_flooded,
1295 get_status_string(rulla->status));
1296 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1297 rulla = rulla->next;
1300 rulla = lec_arp_empty_ones;
1302 printk("Empty ones\n");
1305 offset += sprintf(buf+offset,"Mac:");
1306 for(j=0;j<ETH_ALEN;j++) {
1307 offset+=sprintf(buf+offset,"%2.2x ",
1308 rulla->mac_addr[j]&0xff);
1310 offset +=sprintf(buf+offset,"Atm:");
1311 for(j=0;j<ATM_ESA_LEN;j++) {
1312 offset+=sprintf(buf+offset,"%2.2x ",
1313 rulla->atm_addr[j]&0xff);
1315 offset+=sprintf(buf+offset,
1316 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1317 rulla->vcc?rulla->vcc->vpi:0,
1318 rulla->vcc?rulla->vcc->vci:0,
1319 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1320 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1322 rulla->timestamp, rulla->no_tries);
1323 offset+=sprintf(buf+offset,
1324 "Flags:%x, Packets_flooded:%x, Status: %s ",
1325 rulla->flags, rulla->packets_flooded,
1326 get_status_string(rulla->status));
1327 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1328 rulla = rulla->next;
1334 printk("Multicast Forward VCCs\n");
1337 offset += sprintf(buf+offset,"Mac:");
1338 for(j=0;j<ETH_ALEN;j++) {
1339 offset+=sprintf(buf+offset,"%2.2x ",
1340 rulla->mac_addr[j]&0xff);
1342 offset +=sprintf(buf+offset,"Atm:");
1343 for(j=0;j<ATM_ESA_LEN;j++) {
1344 offset+=sprintf(buf+offset,"%2.2x ",
1345 rulla->atm_addr[j]&0xff);
1347 offset+=sprintf(buf+offset,
1348 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1349 rulla->vcc?rulla->vcc->vpi:0,
1350 rulla->vcc?rulla->vcc->vci:0,
1351 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1352 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1354 rulla->timestamp, rulla->no_tries);
1355 offset+=sprintf(buf+offset,
1356 "Flags:%x, Packets_flooded:%x, Status: %s ",
1357 rulla->flags, rulla->packets_flooded,
1358 get_status_string(rulla->status));
1359 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1360 rulla = rulla->next;
1368 * Destruction of arp-cache
1371 lec_arp_destroy(struct lec_priv *priv)
1373 struct lec_arp_table *entry, *next;
1374 unsigned long flags;
1380 del_timer(&priv->lec_arp_timer);
1383 * Remove all entries
1385 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1386 for(entry =priv->lec_arp_tables[i];entry != NULL; entry=next) {
1388 lec_arp_remove(priv->lec_arp_tables, entry);
1392 entry = priv->lec_arp_empty_ones;
1395 del_timer(&entry->timer);
1396 lec_arp_clear_vccs(entry);
1400 priv->lec_arp_empty_ones = NULL;
1401 entry = priv->lec_no_forward;
1404 del_timer(&entry->timer);
1405 lec_arp_clear_vccs(entry);
1409 priv->lec_no_forward = NULL;
1410 entry = priv->mcast_fwds;
1413 del_timer(&entry->timer);
1414 lec_arp_clear_vccs(entry);
1418 priv->mcast_fwds = NULL;
1419 priv->mcast_vcc = NULL;
1420 memset(priv->lec_arp_tables, 0,
1421 sizeof(struct lec_arp_table*)*LEC_ARP_TABLE_SIZE);
1422 restore_flags(flags);
1427 * Find entry by mac_address
1429 static __inline__ struct lec_arp_table*
1430 lec_arp_find(struct lec_priv *priv,
1431 unsigned char *mac_addr)
1433 unsigned short place;
1434 struct lec_arp_table *to_return;
1436 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1437 mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff,
1438 mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
1440 place = HASH(mac_addr[ETH_ALEN-1]);
1442 to_return = priv->lec_arp_tables[place];
1444 if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
1445 lec_arp_unlock(priv);
1448 to_return = to_return->next;
1450 lec_arp_unlock(priv);
1454 static struct lec_arp_table*
1455 make_entry(struct lec_priv *priv, unsigned char *mac_addr)
1457 struct lec_arp_table *to_return;
1459 to_return=(struct lec_arp_table *)kmalloc(sizeof(struct lec_arp_table),
1462 printk("LEC: Arp entry kmalloc failed\n");
1465 memset(to_return,0,sizeof(struct lec_arp_table));
1466 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1467 init_timer(&to_return->timer);
1468 to_return->timer.function = lec_arp_expire_arp;
1469 to_return->timer.data = (unsigned long)to_return;
1470 to_return->last_used = jiffies;
1471 to_return->priv = priv;
1472 skb_queue_head_init(&to_return->tx_wait);
1478 * Arp sent timer expired
1482 lec_arp_expire_arp(unsigned long data)
1484 struct lec_arp_table *entry;
1486 entry = (struct lec_arp_table *)data;
1488 del_timer(&entry->timer);
1490 DPRINTK("lec_arp_expire_arp\n");
1491 if (entry->status == ESI_ARP_PENDING) {
1492 if (entry->no_tries <= entry->priv->max_retry_count) {
1493 if (entry->is_rdesc)
1494 send_to_lecd(entry->priv, l_rdesc_arp_xmt, entry->mac_addr, NULL, NULL);
1496 send_to_lecd(entry->priv, l_arp_xmt, entry->mac_addr, NULL, NULL);
1499 entry->timer.expires = jiffies + (1*HZ);
1500 add_timer(&entry->timer);
1506 * Unknown/unused vcc expire, remove associated entry
1510 lec_arp_expire_vcc(unsigned long data)
1512 struct lec_arp_table *to_remove = (struct lec_arp_table*)data;
1513 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1514 struct lec_arp_table *entry = NULL;
1516 del_timer(&to_remove->timer);
1518 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1520 to_remove->vcc?to_remove->recv_vcc->vpi:0,
1521 to_remove->vcc?to_remove->recv_vcc->vci:0);
1522 DPRINTK("eo:%p nf:%p\n",priv->lec_arp_empty_ones,priv->lec_no_forward);
1523 if (to_remove == priv->lec_arp_empty_ones)
1524 priv->lec_arp_empty_ones = to_remove->next;
1526 entry = priv->lec_arp_empty_ones;
1527 while (entry && entry->next != to_remove)
1528 entry = entry->next;
1530 entry->next = to_remove->next;
1533 if (to_remove == priv->lec_no_forward) {
1534 priv->lec_no_forward = to_remove->next;
1536 entry = priv->lec_no_forward;
1537 while (entry && entry->next != to_remove)
1538 entry = entry->next;
1540 entry->next = to_remove->next;
1543 lec_arp_clear_vccs(to_remove);
1550 * 2. For each entry, delete entries that have aged past the age limit.
1551 * 3. For each entry, depending on the status of the entry, perform
1552 * the following maintenance.
1553 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1554 * tick_count is above the max_unknown_frame_time, clear
1555 * the tick_count to zero and clear the packets_flooded counter
1556 * to zero. This supports the packet rate limit per address
1557 * while flooding unknowns.
1558 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1559 * than or equal to the path_switching_delay, change the status
1560 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1561 * regardless of the progress of the flush protocol.
1564 lec_arp_check_expire(unsigned long data)
1566 struct lec_priv *priv = (struct lec_priv *)data;
1567 struct lec_arp_table **lec_arp_tables =
1568 (struct lec_arp_table **)priv->lec_arp_tables;
1569 struct lec_arp_table *entry, *next;
1571 unsigned long time_to_check;
1574 del_timer(&priv->lec_arp_timer);
1576 DPRINTK("lec_arp_check_expire %p,%d\n",priv,
1577 priv->lec_arp_lock_var.counter);
1578 DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
1579 priv->lec_no_forward);
1580 if (!priv->lec_arp_lock_var.counter) {
1583 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1584 for(entry = lec_arp_tables[i];entry != NULL;) {
1585 if ((entry->flags) & LEC_REMOTE_FLAG &&
1586 priv->topology_change)
1587 time_to_check=priv->forward_delay_time;
1589 time_to_check = priv->aging_time;
1591 DPRINTK("About to expire: %lx - %lx > %lx\n",
1592 now,entry->last_used, time_to_check);
1593 if( time_after(now, entry->last_used+
1595 !(entry->flags & LEC_PERMANENT_FLAG) &&
1596 !(entry->mac_addr[0] & 0x01) ) { /* LANE2: 7.1.20 */
1598 DPRINTK("LEC:Entry timed out\n");
1600 lec_arp_remove(lec_arp_tables, entry);
1604 /* Something else */
1605 if ((entry->status == ESI_VC_PENDING ||
1606 entry->status == ESI_ARP_PENDING)
1607 && time_after_eq(now,
1609 priv->max_unknown_frame_time)) {
1610 entry->timestamp = jiffies;
1611 entry->packets_flooded = 0;
1612 if (entry->status == ESI_VC_PENDING)
1613 send_to_lecd(priv, l_svc_setup, entry->mac_addr, entry->atm_addr, NULL);
1615 if (entry->status == ESI_FLUSH_PENDING
1617 time_after_eq(now, entry->timestamp+
1618 priv->path_switching_delay)) {
1619 entry->last_used = jiffies;
1623 entry = entry->next;
1627 lec_arp_unlock(priv);
1629 priv->lec_arp_timer.expires = jiffies + LEC_ARP_REFRESH_INTERVAL;
1630 add_timer(&priv->lec_arp_timer);
1633 * Try to find vcc where mac_address is attached.
1637 lec_arp_resolve(struct lec_priv *priv, unsigned char *mac_to_find, int is_rdesc,
1638 struct lec_arp_table **ret_entry)
1640 struct lec_arp_table *entry;
1642 if (mac_to_find[0]&0x01) {
1643 switch (priv->lane_version) {
1645 return priv->mcast_vcc;
1647 case 2: /* LANE2 wants arp for multicast addresses */
1648 if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
1649 return priv->mcast_vcc;
1656 entry = lec_arp_find(priv, mac_to_find);
1659 if (entry->status == ESI_FORWARD_DIRECT) {
1661 entry->last_used = jiffies;
1665 /* Data direct VC not yet set up, check to see if the unknown
1666 frame count is greater than the limit. If the limit has
1667 not been reached, allow the caller to send packet to
1669 if (entry->status != ESI_FLUSH_PENDING &&
1670 entry->packets_flooded<priv->maximum_unknown_frame_count) {
1671 entry->packets_flooded++;
1672 DPRINTK("LEC_ARP: Flooding..\n");
1673 return priv->mcast_vcc;
1675 /* We got here because entry->status == ESI_FLUSH_PENDING
1676 * or BUS flood limit was reached for an entry which is
1677 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1680 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status, entry->vcc);
1683 /* No matching entry was found */
1684 entry = make_entry(priv, mac_to_find);
1685 DPRINTK("LEC_ARP: Making entry\n");
1687 return priv->mcast_vcc;
1689 lec_arp_put(priv->lec_arp_tables, entry);
1690 /* We want arp-request(s) to be sent */
1691 entry->packets_flooded =1;
1692 entry->status = ESI_ARP_PENDING;
1693 entry->no_tries = 1;
1694 entry->last_used = entry->timestamp = jiffies;
1695 entry->is_rdesc = is_rdesc;
1696 if (entry->is_rdesc)
1697 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, NULL);
1699 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1700 entry->timer.expires = jiffies + (1*HZ);
1701 entry->timer.function = lec_arp_expire_arp;
1702 add_timer(&entry->timer);
1703 return priv->mcast_vcc;
1708 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
1709 unsigned long permanent)
1711 struct lec_arp_table *entry, *next;
1715 DPRINTK("lec_addr_delete\n");
1716 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1717 for(entry=priv->lec_arp_tables[i];entry != NULL; entry=next) {
1719 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
1721 !(entry->flags & LEC_PERMANENT_FLAG))) {
1722 lec_arp_remove(priv->lec_arp_tables, entry);
1725 lec_arp_unlock(priv);
1729 lec_arp_unlock(priv);
1734 * Notifies: Response to arp_request (atm_addr != NULL)
1737 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
1738 unsigned char *atm_addr, unsigned long remoteflag,
1739 unsigned int targetless_le_arp)
1741 struct lec_arp_table *entry, *tmp;
1744 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless ": " ");
1745 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1746 mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],
1747 mac_addr[4],mac_addr[5]);
1749 entry = lec_arp_find(priv, mac_addr);
1750 if (entry == NULL && targetless_le_arp)
1751 return; /* LANE2: ignore targetless LE_ARPs for which
1752 * we have no entry in the cache. 7.1.30
1755 if (priv->lec_arp_empty_ones) {
1756 entry = priv->lec_arp_empty_ones;
1757 if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
1758 priv->lec_arp_empty_ones = entry->next;
1760 while(entry->next && memcmp(entry->next->atm_addr,
1761 atm_addr, ATM_ESA_LEN))
1762 entry = entry->next;
1765 entry = entry->next;
1766 tmp->next = entry->next;
1772 del_timer(&entry->timer);
1773 tmp = lec_arp_find(priv, mac_addr);
1775 del_timer(&tmp->timer);
1776 tmp->status = ESI_FORWARD_DIRECT;
1777 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
1778 tmp->vcc = entry->vcc;
1779 tmp->old_push = entry->old_push;
1780 tmp->last_used = jiffies;
1781 del_timer(&entry->timer);
1785 entry->status = ESI_FORWARD_DIRECT;
1786 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
1787 entry->last_used = jiffies;
1788 lec_arp_put(priv->lec_arp_tables, entry);
1791 entry->flags|=LEC_REMOTE_FLAG;
1793 entry->flags&=~LEC_REMOTE_FLAG;
1794 lec_arp_unlock(priv);
1795 DPRINTK("After update\n");
1796 dump_arp_table(priv);
1800 entry = lec_arp_find(priv, mac_addr);
1802 entry = make_entry(priv, mac_addr);
1804 lec_arp_unlock(priv);
1807 entry->status = ESI_UNKNOWN;
1808 lec_arp_put(priv->lec_arp_tables, entry);
1809 /* Temporary, changes before end of function */
1811 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
1812 del_timer(&entry->timer);
1813 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1814 for(tmp=priv->lec_arp_tables[i];tmp;tmp=tmp->next) {
1816 !memcmp(tmp->atm_addr, atm_addr,
1818 /* Vcc to this host exists */
1819 if (tmp->status > ESI_VC_PENDING) {
1821 * ESI_FLUSH_PENDING,
1822 * ESI_FORWARD_DIRECT
1824 entry->vcc = tmp->vcc;
1825 entry->old_push=tmp->old_push;
1827 entry->status=tmp->status;
1833 entry->flags|=LEC_REMOTE_FLAG;
1835 entry->flags&=~LEC_REMOTE_FLAG;
1836 if (entry->status == ESI_ARP_PENDING ||
1837 entry->status == ESI_UNKNOWN) {
1838 entry->status = ESI_VC_PENDING;
1839 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
1841 DPRINTK("After update2\n");
1842 dump_arp_table(priv);
1843 lec_arp_unlock(priv);
1847 * Notifies: Vcc setup ready
1850 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
1851 struct atm_vcc *vcc,
1852 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb))
1854 struct lec_arp_table *entry;
1855 int i, found_entry=0;
1858 if (ioc_data->receive == 2) {
1859 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
1861 DPRINTK("LEC_ARP: Attaching mcast forward\n");
1863 entry = lec_arp_find(priv, bus_mac);
1865 printk("LEC_ARP: Multicast entry not found!\n");
1866 lec_arp_unlock(priv);
1869 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
1870 entry->recv_vcc = vcc;
1871 entry->old_recv_push = old_push;
1873 entry = make_entry(priv, bus_mac);
1874 if (entry == NULL) {
1875 lec_arp_unlock(priv);
1878 del_timer(&entry->timer);
1879 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
1880 entry->recv_vcc = vcc;
1881 entry->old_recv_push = old_push;
1882 entry->next = priv->mcast_fwds;
1883 priv->mcast_fwds = entry;
1884 lec_arp_unlock(priv);
1886 } else if (ioc_data->receive == 1) {
1887 /* Vcc which we don't want to make default vcc, attach it
1889 DPRINTK("LEC_ARP:Attaching data direct, not default :%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1890 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
1891 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
1892 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
1893 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
1894 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
1895 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
1896 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
1897 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
1898 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
1899 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
1900 entry = make_entry(priv, bus_mac);
1901 if (entry == NULL) {
1902 lec_arp_unlock(priv);
1905 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
1906 memset(entry->mac_addr, 0, ETH_ALEN);
1907 entry->recv_vcc = vcc;
1908 entry->old_recv_push = old_push;
1909 entry->status = ESI_UNKNOWN;
1910 entry->timer.expires = jiffies + priv->vcc_timeout_period;
1911 entry->timer.function = lec_arp_expire_vcc;
1912 add_timer(&entry->timer);
1913 entry->next = priv->lec_no_forward;
1914 priv->lec_no_forward = entry;
1915 lec_arp_unlock(priv);
1916 dump_arp_table(priv);
1919 DPRINTK("LEC_ARP:Attaching data direct, default:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1920 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
1921 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
1922 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
1923 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
1924 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
1925 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
1926 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
1927 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
1928 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
1929 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
1930 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1931 for (entry = priv->lec_arp_tables[i];entry;entry=entry->next) {
1932 if (memcmp(ioc_data->atm_addr, entry->atm_addr,
1934 DPRINTK("LEC_ARP: Attaching data direct\n");
1935 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
1936 entry->vcc?entry->vcc->vci:0,
1937 entry->recv_vcc?entry->recv_vcc->vci:0);
1939 del_timer(&entry->timer);
1941 entry->old_push = old_push;
1942 if (entry->status == ESI_VC_PENDING) {
1943 if(priv->maximum_unknown_frame_count
1948 entry->timestamp = jiffies;
1952 send_to_lecd(priv,l_flush_xmt,
1959 /* They were forming a connection
1960 to us, and we to them. Our
1961 ATM address is numerically lower
1962 than theirs, so we make connection
1963 we formed into default VCC (8.1.11).
1964 Connection they made gets torn
1965 down. This might confuse some
1966 clients. Can be changed if
1967 someone reports trouble... */
1974 lec_arp_unlock(priv);
1975 DPRINTK("After vcc was added\n");
1976 dump_arp_table(priv);
1979 /* Not found, snatch address from first data packet that arrives from
1981 entry = make_entry(priv, bus_mac);
1983 lec_arp_unlock(priv);
1987 entry->old_push = old_push;
1988 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
1989 memset(entry->mac_addr, 0, ETH_ALEN);
1990 entry->status = ESI_UNKNOWN;
1991 entry->next = priv->lec_arp_empty_ones;
1992 priv->lec_arp_empty_ones = entry;
1993 entry->timer.expires = jiffies + priv->vcc_timeout_period;
1994 entry->timer.function = lec_arp_expire_vcc;
1995 add_timer(&entry->timer);
1996 lec_arp_unlock(priv);
1997 DPRINTK("After vcc was added\n");
1998 dump_arp_table(priv);
2002 lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2004 struct lec_arp_table *entry;
2007 DPRINTK("LEC:lec_flush_complete %lx\n",tran_id);
2008 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2009 for (entry=priv->lec_arp_tables[i];entry;entry=entry->next) {
2010 if (entry->flush_tran_id == tran_id &&
2011 entry->status == ESI_FLUSH_PENDING) {
2012 entry->status = ESI_FORWARD_DIRECT;
2013 DPRINTK("LEC_ARP: Flushed\n");
2017 dump_arp_table(priv);
2021 lec_set_flush_tran_id(struct lec_priv *priv,
2022 unsigned char *atm_addr, unsigned long tran_id)
2024 struct lec_arp_table *entry;
2027 for (i=0;i<LEC_ARP_TABLE_SIZE;i++)
2028 for(entry=priv->lec_arp_tables[i];entry;entry=entry->next)
2029 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2030 entry->flush_tran_id = tran_id;
2031 DPRINTK("Set flush transaction id to %lx for %p\n",tran_id,entry);
2036 lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2038 unsigned char mac_addr[] = {
2039 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2040 struct lec_arp_table *to_add;
2043 to_add = make_entry(priv, mac_addr);
2045 lec_arp_unlock(priv);
2048 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2049 to_add->status = ESI_FORWARD_DIRECT;
2050 to_add->flags |= LEC_PERMANENT_FLAG;
2052 to_add->old_push = vcc->push;
2053 vcc->push = lec_push;
2054 priv->mcast_vcc = vcc;
2055 lec_arp_put(priv->lec_arp_tables, to_add);
2056 lec_arp_unlock(priv);
2061 lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2063 struct lec_arp_table *entry, *next;
2066 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
2067 dump_arp_table(priv);
2069 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2070 for(entry = priv->lec_arp_tables[i];entry; entry=next) {
2072 if (vcc == entry->vcc) {
2073 lec_arp_remove(priv->lec_arp_tables,entry);
2075 if (priv->mcast_vcc == vcc) {
2076 priv->mcast_vcc = NULL;
2082 entry = priv->lec_arp_empty_ones;
2083 priv->lec_arp_empty_ones = NULL;
2084 while (entry != NULL) {
2086 if (entry->vcc == vcc) { /* leave it out from the list */
2087 lec_arp_clear_vccs(entry);
2088 del_timer(&entry->timer);
2091 else { /* put it back to the list */
2092 entry->next = priv->lec_arp_empty_ones;
2093 priv->lec_arp_empty_ones = entry;
2098 entry = priv->lec_no_forward;
2099 priv->lec_no_forward = NULL;
2100 while (entry != NULL) {
2102 if (entry->recv_vcc == vcc) {
2103 lec_arp_clear_vccs(entry);
2104 del_timer(&entry->timer);
2108 entry->next = priv->lec_no_forward;
2109 priv->lec_no_forward = entry;
2114 entry = priv->mcast_fwds;
2115 priv->mcast_fwds = NULL;
2116 while (entry != NULL) {
2118 if (entry->recv_vcc == vcc) {
2119 lec_arp_clear_vccs(entry);
2120 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2124 entry->next = priv->mcast_fwds;
2125 priv->mcast_fwds = entry;
2130 lec_arp_unlock(priv);
2131 dump_arp_table(priv);
2135 lec_arp_check_empties(struct lec_priv *priv,
2136 struct atm_vcc *vcc, struct sk_buff *skb)
2138 struct lec_arp_table *entry, *prev;
2139 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2140 unsigned long flags;
2143 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2145 if (priv->is_trdev) src = tr_hdr->h_source;
2148 src = hdr->h_source;
2151 entry = priv->lec_arp_empty_ones;
2152 if (vcc == entry->vcc) {
2155 del_timer(&entry->timer);
2156 memcpy(entry->mac_addr, src, ETH_ALEN);
2157 entry->status = ESI_FORWARD_DIRECT;
2158 entry->last_used = jiffies;
2159 priv->lec_arp_empty_ones = entry->next;
2160 restore_flags(flags);
2161 /* We might have got an entry */
2162 if ((prev=lec_arp_find(priv,src))) {
2163 lec_arp_remove(priv->lec_arp_tables, prev);
2166 lec_arp_put(priv->lec_arp_tables, entry);
2167 lec_arp_unlock(priv);
2171 entry = entry->next;
2172 while (entry && entry->vcc != vcc) {
2174 entry = entry->next;
2177 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2178 lec_arp_unlock(priv);
2183 del_timer(&entry->timer);
2184 memcpy(entry->mac_addr, src, ETH_ALEN);
2185 entry->status = ESI_FORWARD_DIRECT;
2186 entry->last_used = jiffies;
2187 prev->next = entry->next;
2188 restore_flags(flags);
2189 if ((prev = lec_arp_find(priv, src))) {
2190 lec_arp_remove(priv->lec_arp_tables,prev);
2193 lec_arp_put(priv->lec_arp_tables,entry);
2194 lec_arp_unlock(priv);
2196 MODULE_LICENSE("GPL");