USB: isp1362: fix pulldown register defines and conf logic
[linux-2.6/next.git] / net / atm / lec.c
blobb2d644560323c945da9019cdba493212d9dd20e9
1 /*
2 * lec.c: Lan Emulation driver
4 * Marko Kiiskila <mkiiskila@yahoo.com>
5 */
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>
15 #include <net/sock.h>
16 #include <linux/skbuff.h>
17 #include <linux/ip.h>
18 #include <asm/byteorder.h>
19 #include <asm/uaccess.h>
20 #include <net/arp.h>
21 #include <net/dst.h>
22 #include <linux/proc_fs.h>
23 #include <linux/spinlock.h>
24 #include <linux/seq_file.h>
26 /* TokenRing if needed */
27 #ifdef CONFIG_TR
28 #include <linux/trdevice.h>
29 #endif
31 /* And atm device */
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 };
40 #endif
42 /* Modular too */
43 #include <linux/module.h>
44 #include <linux/init.h>
46 #include "lec.h"
47 #include "lec_arpc.h"
48 #include "resources.h"
50 #define DUMP_PACKETS 0 /*
51 * 0 = None,
52 * 1 = 30 first bytes
53 * 2 = Whole packet
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);
70 /* LANE2 functions */
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,
86 int is_rdesc,
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,
97 struct atm_vcc *vcc,
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))
111 kfree(entry);
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)
129 struct ethhdr *eth;
130 char *buff;
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) {
141 struct sock *sk;
142 struct sk_buff *skb2;
143 struct atmlec_msg *mesg;
145 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
146 if (skb2 == NULL)
147 return;
148 skb2->len = sizeof(struct atmlec_msg);
149 mesg = (struct atmlec_msg *)skb2->data;
150 mesg->type = l_topology_change;
151 buff += 4;
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);
161 return;
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
172 * and returns NULL.
174 #ifdef CONFIG_TR
175 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177 struct trh_hdr *trh;
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 */
188 } else
189 return trh->daddr; /* not source routed */
191 if (riflen < 6)
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));
200 else {
201 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
202 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
205 return NULL;
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));
223 return 0;
226 static void
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++;
237 return;
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;
257 struct atm_vcc *vcc;
258 struct lec_arp_table *entry;
259 unsigned char *dst;
260 int min_frame_size;
261 #ifdef CONFIG_TR
262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
263 #endif
264 int is_rdesc;
265 #if DUMP_PACKETS > 0
266 char buf[300];
267 int i = 0;
268 #endif /* DUMP_PACKETS >0 */
270 pr_debug("lec_start_xmit called\n");
271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 dev->stats.tx_errors++;
274 netif_stop_queue(dev);
275 kfree_skb(skb);
276 return NETDEV_TX_OK;
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);
285 #endif
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);
292 kfree_skb(skb);
293 if (skb2 == NULL)
294 return NETDEV_TX_OK;
295 skb = skb2;
297 skb_push(skb, 2);
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);
303 #ifdef CONFIG_TR
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);
310 kfree_skb(skb);
311 if (skb2 == NULL)
312 return NETDEV_TX_OK;
313 skb = skb2;
315 #endif
317 #if DUMP_PACKETS > 0
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 */
329 if (i == skb->len)
330 printk("%s\n", buf);
331 else
332 printk("%s...\n", buf);
333 #endif /* DUMP_PACKETS > 0 */
335 /* Minimum ethernet-frame size */
336 #ifdef CONFIG_TR
337 if (priv->is_trdev)
338 min_frame_size = LEC_MINIMUM_8025_SIZE;
339 else
340 #endif
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,
346 GFP_ATOMIC);
347 dev_kfree_skb(skb);
348 if (skb2 == NULL) {
349 dev->stats.tx_dropped++;
350 return NETDEV_TX_OK;
352 skb = skb2;
354 skb_put(skb, min_frame_size - skb->len);
357 /* Send to right vcc */
358 is_rdesc = 0;
359 dst = lec_h->h_dest;
360 #ifdef CONFIG_TR
361 if (priv->is_trdev) {
362 dst = get_tr_dst(skb->data + 2, rdesc);
363 if (dst == NULL) {
364 dst = rdesc;
365 is_rdesc = 1;
368 #endif
369 entry = NULL;
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, ",
376 dev->name);
377 pr_debug("MAC address %pM\n", lec_h->h_dest);
378 skb_queue_tail(&entry->tx_wait, skb);
379 } else {
380 pr_debug
381 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
382 dev->name);
383 pr_debug("MAC address %pM\n", lec_h->h_dest);
384 dev->stats.tx_dropped++;
385 dev_kfree_skb(skb);
387 goto out;
389 #if DUMP_PACKETS > 0
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);
396 lec_send(vcc, skb2);
399 lec_send(vcc, skb);
401 if (!atm_may_send(vcc, 0)) {
402 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
404 vpriv->xoff = 1;
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);
417 out:
418 if (entry)
419 lec_arp_put(entry);
420 dev->trans_start = jiffies;
421 return NETDEV_TX_OK;
424 /* The inverse routine to net_open(). */
425 static int lec_close(struct net_device *dev)
427 netif_stop_queue(dev);
428 return 0;
431 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
433 unsigned long flags;
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;
438 int i;
439 char *tmp; /* FIXME */
441 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
442 mesg = (struct atmlec_msg *)skb->data;
443 tmp = 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) {
447 case l_set_mac_addr:
448 for (i = 0; i < 6; i++) {
449 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
451 break;
452 case l_del_mac_addr:
453 for (i = 0; i < 6; i++) {
454 dev->dev_addr[i] = 0;
456 break;
457 case l_addr_delete:
458 lec_addr_delete(priv, mesg->content.normal.atm_addr,
459 mesg->content.normal.flag);
460 break;
461 case l_topology_change:
462 priv->topology_change = mesg->content.normal.flag;
463 break;
464 case l_flush_complete:
465 lec_flush_complete(priv, mesg->content.normal.flag);
466 break;
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)
474 break;
475 /* FALL THROUGH */
476 case l_arp_update:
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",
484 mesg->sizeoftlvs);
485 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
486 tmp, mesg->sizeoftlvs);
488 break;
489 case l_config:
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;
511 break;
512 case l_flush_tran_id:
513 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
514 mesg->content.normal.flag);
515 break;
516 case l_set_lecid:
517 priv->lecid =
518 (unsigned short)(0xffff & mesg->content.normal.flag);
519 break;
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)
527 break;
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;
533 struct sock *sk;
535 pr_debug
536 ("%s: entry found, responding to zeppelin\n",
537 dev->name);
538 skb2 =
539 alloc_skb(sizeof(struct atmlec_msg),
540 GFP_ATOMIC);
541 if (skb2 == NULL)
542 break;
543 skb2->len = sizeof(struct atmlec_msg);
544 skb_copy_to_linear_data(skb2, mesg,
545 sizeof(*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) */
553 break;
554 default:
555 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
556 dev_kfree_skb(skb);
557 return -EINVAL;
559 dev_kfree_skb(skb);
560 return 0;
563 static void lec_atm_close(struct atm_vcc *vcc)
565 struct sk_buff *skb;
566 struct net_device *dev = (struct net_device *)vcc->proto_data;
567 struct lec_priv *priv = netdev_priv(dev);
569 priv->lecd = NULL;
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",
577 dev->name);
578 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
579 atm_return(vcc, skb->truesize);
580 dev_kfree_skb(skb);
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,
589 .send = lec_atm_send
592 static struct atm_dev lecatm_dev = {
593 .ops = &lecdev_ops,
594 .type = "lec",
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
603 static int
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)
608 struct sock *sk;
609 struct sk_buff *skb;
610 struct atmlec_msg *mesg;
612 if (!priv || !priv->lecd) {
613 return -1;
615 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
616 if (!skb)
617 return -1;
618 skb->len = sizeof(struct atmlec_msg);
619 mesg = (struct atmlec_msg *)skb->data;
620 memset(mesg, 0, sizeof(struct atmlec_msg));
621 mesg->type = type;
622 if (data != NULL)
623 mesg->sizeoftlvs = data->len;
624 if (mac_addr)
625 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
626 else
627 mesg->content.normal.targetless_le_arp = 1;
628 if (atm_addr)
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);
636 if (data != NULL) {
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);
643 return 0;
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))
650 return -EINVAL;
651 dev->mtu = new_mtu;
652 return 0;
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
661 return;
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[] = {
681 0xff,
682 0x00,
683 0x01,
684 0x01
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)
698 unsigned long flags;
699 struct net_device *dev = (struct net_device *)vcc->proto_data;
700 struct lec_priv *priv = netdev_priv(dev);
702 #if DUMP_PACKETS >0
703 int i = 0;
704 char buf[300];
706 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
707 vcc->vpi, vcc->vci);
708 #endif
709 if (!skb) {
710 pr_debug("%s: null skb\n", dev->name);
711 lec_vcc_close(priv, vcc);
712 return;
714 #if DUMP_PACKETS > 0
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 */
726 if (i == skb->len)
727 printk("%s\n", buf);
728 else
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,
746 * lecd has gone down
748 pr_debug("Ignoring frame...\n");
749 dev_kfree_skb(skb);
750 return;
752 #ifdef CONFIG_TR
753 if (priv->is_trdev)
754 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
755 else
756 #endif
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)) {
765 #ifdef CONFIG_TR
766 if (priv->is_trdev)
767 src =
768 ((struct lecdatahdr_8025 *)skb->data)->
769 h_source;
770 else
771 #endif
772 src =
773 ((struct lecdatahdr_8023 *)skb->data)->
774 h_source;
775 entry = lec_arp_find(priv, src);
776 if (entry && entry->vcc != vcc) {
777 lec_arp_remove(priv, entry);
778 lec_arp_put(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)) {
786 dev_kfree_skb(skb);
787 return;
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 */
793 #ifdef CONFIG_TR
794 if (priv->is_trdev)
795 skb->protocol = tr_type_trans(skb, dev);
796 else
797 #endif
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));
802 netif_rx(skb);
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;
811 if (vpriv == NULL) {
812 printk("lec_pop(): vpriv = NULL!?!?!?\n");
813 return;
816 vpriv->old_pop(vcc, skb);
818 if (vpriv->xoff && atm_may_send(vcc, 0)) {
819 vpriv->xoff = 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;
828 int bytes_left;
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) {
834 printk
835 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
836 bytes_left);
838 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
839 !dev_lec[ioc_data.dev_num])
840 return -EINVAL;
841 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
842 return -ENOMEM;
843 vpriv->xoff = 0;
844 vpriv->old_pop = vcc->pop;
845 vcc->user_back = vpriv;
846 vcc->pop = lec_pop;
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;
851 return 0;
854 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
856 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
857 return -EINVAL;
858 vcc->proto_data = dev_lec[arg];
859 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
860 vcc);
863 /* Initialize device. */
864 static int lecd_attach(struct atm_vcc *vcc, int arg)
866 int i;
867 struct lec_priv *priv;
869 if (arg < 0)
870 i = 0;
871 else
872 i = arg;
873 #ifdef CONFIG_TR
874 if (arg >= MAX_LEC_ITF)
875 return -EINVAL;
876 #else /* Reserve the top NUM_TR_DEVS for TR */
877 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
878 return -EINVAL;
879 #endif
880 if (!dev_lec[i]) {
881 int is_trdev, size;
883 is_trdev = 0;
884 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
885 is_trdev = 1;
887 size = sizeof(struct lec_priv);
888 #ifdef CONFIG_TR
889 if (is_trdev)
890 dev_lec[i] = alloc_trdev(size);
891 else
892 #endif
893 dev_lec[i] = alloc_etherdev(size);
894 if (!dev_lec[i])
895 return -ENOMEM;
896 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
897 if (register_netdev(dev_lec[i])) {
898 free_netdev(dev_lec[i]);
899 return -EINVAL;
902 priv = netdev_priv(dev_lec[i]);
903 priv->is_trdev = is_trdev;
904 lec_init(dev_lec[i]);
905 } else {
906 priv = netdev_priv(dev_lec[i]);
907 if (priv->lecd)
908 return -EADDRINUSE;
910 lec_arp_init(priv);
911 priv->itfnum = i; /* LANE2 addition */
912 priv->lecd = vcc;
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);
936 return i;
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[] = {
943 "ESI_UNKNOWN ",
944 "ESI_ARP_PENDING ",
945 "ESI_VC_PENDING ",
946 "<Undefined> ",
947 "ESI_FLUSH_PENDING ",
948 "ESI_FORWARD_DIRECT"
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)
958 int i;
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);
967 if (entry->vcc)
968 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
969 else
970 seq_printf(seq, " ");
971 if (entry->recv_vcc) {
972 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
973 entry->recv_vcc->vci);
975 seq_putc(seq, '\n');
978 struct lec_state {
979 unsigned long flags;
980 struct lec_priv *locked;
981 struct hlist_node *node;
982 struct net_device *dev;
983 int itf;
984 int arp_table;
985 int misc_table;
988 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
989 loff_t *l)
991 struct hlist_node *e = state->node;
992 struct lec_arp_table *tmp;
994 if (!e)
995 e = tbl->first;
996 if (e == SEQ_START_TOKEN) {
997 e = tbl->first;
998 --*l;
1001 hlist_for_each_entry_from(tmp, e, next) {
1002 if (--*l < 0)
1003 break;
1005 state->node = e;
1007 return (*l < 0) ? state : NULL;
1010 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
1011 struct lec_priv *priv)
1013 void *v = NULL;
1014 int p;
1016 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
1017 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1018 if (v)
1019 break;
1021 state->arp_table = p;
1022 return v;
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,
1031 &priv->mcast_fwds
1033 void *v = NULL;
1034 int q;
1036 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1037 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1038 if (v)
1039 break;
1041 state->misc_table = q;
1042 return v;
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;
1064 void *v;
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;
1069 if (!v && dev) {
1070 dev_put(dev);
1071 /* Partial state reset for the next time we get called */
1072 dev = NULL;
1074 state->dev = dev;
1075 return v;
1078 static void *lec_get_idx(struct lec_state *state, loff_t l)
1080 void *v = NULL;
1082 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1083 v = lec_itf_walk(state, &l);
1084 if (v)
1085 break;
1087 return v;
1090 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1092 struct lec_state *state = seq->private;
1094 state->itf = 0;
1095 state->dev = NULL;
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;
1108 if (state->dev) {
1109 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1110 state->flags);
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);
1121 return v;
1124 static int lec_seq_show(struct seq_file *seq, void *v)
1126 static const char lec_banner[] =
1127 "Itf MAC ATM destination"
1128 " Status Flags "
1129 "VPI/VCI Recv VPI/VCI\n";
1131 if (v == SEQ_START_TOKEN)
1132 seq_puts(seq, lec_banner);
1133 else {
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);
1141 return 0;
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,
1159 .read = seq_read,
1160 .llseek = seq_lseek,
1161 .release = seq_release_private,
1163 #endif
1165 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1167 struct atm_vcc *vcc = ATM_SD(sock);
1168 int err = 0;
1170 switch (cmd) {
1171 case ATMLEC_CTRL:
1172 case ATMLEC_MCAST:
1173 case ATMLEC_DATA:
1174 if (!capable(CAP_NET_ADMIN))
1175 return -EPERM;
1176 break;
1177 default:
1178 return -ENOIOCTLCMD;
1181 switch (cmd) {
1182 case ATMLEC_CTRL:
1183 err = lecd_attach(vcc, (int)arg);
1184 if (err >= 0)
1185 sock->state = SS_CONNECTED;
1186 break;
1187 case ATMLEC_MCAST:
1188 err = lec_mcast_attach(vcc, (int)arg);
1189 break;
1190 case ATMLEC_DATA:
1191 err = lec_vcc_attach(vcc, (void __user *)arg);
1192 break;
1195 return err;
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);
1209 if (!p) {
1210 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1211 return -ENOMEM;
1213 #endif
1215 register_atm_ioctl(&lane_ioctl_ops);
1216 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1217 return 0;
1220 static void __exit lane_module_cleanup(void)
1222 int i;
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]);
1234 dev_lec[i] = NULL;
1238 return;
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
1248 * lec will be used.
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;
1258 int retval;
1260 if (force == 0) {
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);
1264 if (table == NULL)
1265 return -1;
1267 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1268 if (*tlvs == NULL)
1269 return -1;
1271 *sizeoftlvs = table->sizeoftlvs;
1273 return 0;
1276 if (sizeoftlvs == NULL)
1277 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1279 else {
1280 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1281 if (skb == NULL)
1282 return -1;
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);
1287 return retval;
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)
1300 int retval;
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)
1311 return (0);
1312 priv->sizeoftlvs = sizeoftlvs;
1314 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1315 if (skb == NULL)
1316 return 0;
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);
1320 if (retval != 0)
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
1326 return (1);
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)
1336 #if 0
1337 int i = 0;
1338 #endif
1339 struct lec_priv *priv = netdev_priv(dev);
1340 #if 0 /*
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);
1348 if (entry == NULL)
1349 return; /* should not happen */
1351 kfree(entry->tlvs);
1353 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1354 if (entry->tlvs == NULL)
1355 return;
1356 entry->sizeoftlvs = sizeoftlvs;
1357 #endif
1358 #if 0
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++]);
1364 printk("\n");
1365 #endif
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,
1370 tlvs, sizeoftlvs);
1372 return;
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>
1389 #if 0
1390 #define pr_debug(format,args...)
1392 #define pr_debug printk
1394 #endif
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);
1403 * Arp table funcs
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)
1413 unsigned short i;
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)
1428 if (entry->vcc) {
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;
1434 if (vpriv->xoff)
1435 netif_wake_queue(dev);
1436 kfree(vpriv);
1437 vcc->user_back = NULL;
1438 vcc->push = entry->old_push;
1439 vcc_release_async(vcc, -EPIPE);
1440 entry->vcc = NULL;
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
1453 static inline void
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
1470 static int
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;
1477 if (!to_remove) {
1478 return -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) {
1493 remove_vcc = 0;
1494 break;
1498 if (remove_vcc)
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]);
1507 return 0;
1510 #if DEBUG_ARP_TABLE
1511 static const char *get_status_string(unsigned char st)
1513 switch (st) {
1514 case ESI_UNKNOWN:
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";
1524 default:
1525 return "<UNKNOWN>";
1529 static void dump_arp_table(struct lec_priv *priv)
1531 struct hlist_node *node;
1532 struct lec_arp_table *rulla;
1533 char buf[256];
1534 int i, j, offset;
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) {
1539 offset = 0;
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,
1544 "%2.2x ",
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,
1550 "%2.2x ",
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->
1558 vpi : 0,
1559 rulla->recv_vcc ? rulla->recv_vcc->
1560 vci : 0, rulla->last_used,
1561 rulla->timestamp, rulla->no_tries);
1562 offset +=
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) {
1574 offset = 0;
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,
1591 rulla->last_used,
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) {
1603 offset = 0;
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,
1620 rulla->last_used,
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));
1626 printk("%s", buf);
1629 if (!hlist_empty(&priv->mcast_fwds))
1630 printk("Multicast Forward VCCs\n");
1631 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1632 offset = 0;
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,
1649 rulla->last_used,
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);
1659 #else
1660 #define dump_arp_table(priv) do { } while (0)
1661 #endif
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;
1671 int i;
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);
1683 lec_arp_put(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);
1692 lec_arp_put(entry);
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);
1700 lec_arp_put(entry);
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);
1708 lec_arp_put(entry);
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)) {
1732 return entry;
1735 return NULL;
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);
1744 if (!to_return) {
1745 printk("LEC: Arp entry kmalloc failed\n");
1746 return NULL;
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);
1756 return to_return;
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);
1772 else
1773 send_to_lecd(entry->priv, l_arp_xmt,
1774 entry->mac_addr, NULL, NULL);
1775 entry->no_tries++;
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",
1791 to_remove, priv,
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);
1804 * Expire entries.
1805 * 1. Re-set timer
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;
1826 unsigned long now;
1827 unsigned long time_to_check;
1828 int i;
1830 pr_debug("lec_arp_check_expire %p\n", priv);
1831 now = jiffies;
1832 restart:
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;
1839 else
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 */
1847 /* Remove entry */
1848 pr_debug("LEC:Entry timed out\n");
1849 lec_arp_remove(priv, entry);
1850 lec_arp_put(entry);
1851 } else {
1852 /* Something else */
1853 if ((entry->status == ESI_VC_PENDING ||
1854 entry->status == ESI_ARP_PENDING)
1855 && time_after_eq(now,
1856 entry->timestamp +
1857 priv->
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,
1863 entry->mac_addr,
1864 entry->atm_addr,
1865 NULL);
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)
1877 lec_send(vcc, skb);
1878 entry->last_used = jiffies;
1879 entry->status = ESI_FORWARD_DIRECT;
1880 lec_arp_put(entry);
1881 goto restart;
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) {
1905 case 1:
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;
1910 break;
1911 default:
1912 break;
1916 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1917 entry = lec_arp_find(priv, mac_to_find);
1919 if (entry) {
1920 if (entry->status == ESI_FORWARD_DIRECT) {
1921 /* Connection Ok */
1922 entry->last_used = jiffies;
1923 lec_arp_hold(entry);
1924 *ret_entry = entry;
1925 found = entry->vcc;
1926 goto out;
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
1939 * BUS.
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;
1947 goto out;
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);
1955 *ret_entry = entry;
1956 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
1957 entry->vcc);
1958 found = NULL;
1959 } else {
1960 /* No matching entry was found */
1961 entry = make_entry(priv, mac_to_find);
1962 pr_debug("LEC_ARP: Making entry\n");
1963 if (!entry) {
1964 found = priv->mcast_vcc;
1965 goto out;
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,
1976 NULL);
1977 else
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;
1985 out:
1986 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1987 return found;
1990 static int
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;
1997 int i;
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)
2004 && (permanent ||
2005 !(entry->flags & LEC_PERMANENT_FLAG))) {
2006 lec_arp_remove(priv, entry);
2007 lec_arp_put(entry);
2009 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2010 return 0;
2013 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2014 return -1;
2018 * Notifies: Response to arp_request (atm_addr != NULL)
2020 static void
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;
2028 int i;
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)
2038 goto out; /*
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);
2048 if (tmp) {
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);
2056 lec_arp_put(entry);
2057 entry = tmp;
2058 } else {
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);
2064 if (remoteflag)
2065 entry->flags |= LEC_REMOTE_FLAG;
2066 else
2067 entry->flags &= ~LEC_REMOTE_FLAG;
2068 pr_debug("After update\n");
2069 dump_arp_table(priv);
2070 goto out;
2075 entry = lec_arp_find(priv, mac_addr);
2076 if (!entry) {
2077 entry = make_entry(priv, mac_addr);
2078 if (!entry)
2079 goto out;
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) {
2088 if (entry != tmp &&
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;
2100 break;
2104 if (remoteflag)
2105 entry->flags |= LEC_REMOTE_FLAG;
2106 else
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);
2114 out:
2115 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2119 * Notifies: Vcc setup ready
2121 static void
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");
2136 #if 0
2137 entry = lec_arp_find(priv, bus_mac);
2138 if (!entry) {
2139 printk("LEC_ARP: Multicast entry not found!\n");
2140 goto out;
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 entry->recv_vcc = vcc;
2144 entry->old_recv_push = old_push;
2145 #endif
2146 entry = make_entry(priv, bus_mac);
2147 if (entry == NULL)
2148 goto out;
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);
2154 goto out;
2155 } else if (ioc_data->receive == 1) {
2157 * Vcc which we don't want to make default vcc,
2158 * attach it anyway.
2160 pr_debug
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);
2174 if (entry == NULL)
2175 goto out;
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);
2186 goto out;
2188 pr_debug
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) {
2203 if (memcmp
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->
2210 vci : 0);
2211 found_entry = 1;
2212 del_timer(&entry->timer);
2213 entry->vcc = vcc;
2214 entry->old_push = old_push;
2215 if (entry->status == ESI_VC_PENDING) {
2216 if (priv->maximum_unknown_frame_count
2217 == 0)
2218 entry->status =
2219 ESI_FORWARD_DIRECT;
2220 else {
2221 entry->timestamp = jiffies;
2222 entry->status =
2223 ESI_FLUSH_PENDING;
2224 #if 0
2225 send_to_lecd(priv, l_flush_xmt,
2226 NULL,
2227 entry->atm_addr,
2228 NULL);
2229 #endif
2231 } else {
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...
2248 if (found_entry) {
2249 pr_debug("After vcc was added\n");
2250 dump_arp_table(priv);
2251 goto out;
2254 * Not found, snatch address from first data packet that arrives
2255 * from this vcc
2257 entry = make_entry(priv, bus_mac);
2258 if (!entry)
2259 goto out;
2260 entry->vcc = vcc;
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);
2271 out:
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;
2280 int i;
2282 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
2283 restart:
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)
2295 lec_send(vcc, skb);
2296 entry->last_used = jiffies;
2297 entry->status = ESI_FORWARD_DIRECT;
2298 lec_arp_put(entry);
2299 pr_debug("LEC_ARP: Flushed\n");
2300 goto restart;
2304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2305 dump_arp_table(priv);
2308 static void
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;
2315 int i;
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",
2323 tran_id, entry);
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;
2337 int err = 0;
2339 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2340 return -ENOMEM;
2341 vpriv->xoff = 0;
2342 vpriv->old_pop = vcc->pop;
2343 vcc->user_back = vpriv;
2344 vcc->pop = lec_pop;
2345 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2346 to_add = make_entry(priv, mac_addr);
2347 if (!to_add) {
2348 vcc->pop = vpriv->old_pop;
2349 kfree(vpriv);
2350 err = -ENOMEM;
2351 goto out;
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;
2356 to_add->vcc = vcc;
2357 to_add->old_push = vcc->push;
2358 vcc->push = lec_push;
2359 priv->mcast_vcc = vcc;
2360 lec_arp_add(priv, to_add);
2361 out:
2362 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2363 return err;
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;
2371 int i;
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);
2382 lec_arp_put(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);
2395 lec_arp_put(entry);
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);
2404 lec_arp_put(entry);
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);
2413 lec_arp_put(entry);
2417 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2418 dump_arp_table(priv);
2421 static void
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;
2429 unsigned char *src;
2430 #ifdef CONFIG_TR
2431 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2433 if (priv->is_trdev)
2434 src = tr_hdr->h_source;
2435 else
2436 #endif
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);
2449 lec_arp_put(tmp);
2451 hlist_del(&entry->next);
2452 lec_arp_add(priv, entry);
2453 goto out;
2456 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2457 out:
2458 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2461 MODULE_LICENSE("GPL");