]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/atm/lec.c
clip: convert to internal network_device_stats
[net-next-2.6.git] / net / atm / lec.c
CommitLineData
1da177e4 1/*
f7d57453 2 * lec.c: Lan Emulation driver
1da177e4 3 *
d44f7746 4 * Marko Kiiskila <mkiiskila@yahoo.com>
1da177e4
LT
5 */
6
1da177e4
LT
7#include <linux/kernel.h>
8#include <linux/bitops.h>
4fc268d2 9#include <linux/capability.h>
1da177e4
LT
10
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>
1da177e4
LT
24#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37#include <linux/if_bridge.h>
38#include "../bridge/br_private.h"
39
d44f7746 40static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
1da177e4
LT
41#endif
42
43/* Modular too */
44#include <linux/module.h>
45#include <linux/init.h>
46
47#include "lec.h"
48#include "lec_arpc.h"
49#include "resources.h"
50
d44f7746
CW
51#define DUMP_PACKETS 0 /*
52 * 0 = None,
53 * 1 = 30 first bytes
54 * 2 = Whole packet
55 */
1da177e4 56
d44f7746
CW
57#define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
60 */
1da177e4
LT
61
62static int lec_open(struct net_device *dev);
63static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
64static int lec_close(struct net_device *dev);
65static struct net_device_stats *lec_get_stats(struct net_device *dev);
66static void lec_init(struct net_device *dev);
d44f7746 67static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
61c33e01 68 const unsigned char *mac_addr);
1da177e4 69static int lec_arp_remove(struct lec_priv *priv,
d44f7746 70 struct lec_arp_table *to_remove);
1da177e4 71/* LANE2 functions */
61c33e01
MBJ
72static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
73 const u8 *tlvs, u32 sizeoftlvs);
74static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
d44f7746 75 u8 **tlvs, u32 *sizeoftlvs);
61c33e01
MBJ
76static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
77 const u8 *tlvs, u32 sizeoftlvs);
1da177e4 78
61c33e01 79static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1da177e4
LT
80 unsigned long permanent);
81static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83static void lec_arp_destroy(struct lec_priv *priv);
84static void lec_arp_init(struct lec_priv *priv);
d44f7746 85static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
61c33e01 86 const unsigned char *mac_to_find,
1da177e4
LT
87 int is_rdesc,
88 struct lec_arp_table **ret_entry);
61c33e01
MBJ
89static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
90 const unsigned char *atm_addr, unsigned long remoteflag,
1da177e4
LT
91 unsigned int targetless_le_arp);
92static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94static void lec_set_flush_tran_id(struct lec_priv *priv,
61c33e01 95 const unsigned char *atm_addr,
1da177e4 96 unsigned long tran_id);
61c33e01 97static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
1da177e4 98 struct atm_vcc *vcc,
d44f7746
CW
99 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
1da177e4
LT
101static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102
33a9c2d4
CW
103/* must be done under lec_arp_lock */
104static inline void lec_arp_hold(struct lec_arp_table *entry)
105{
106 atomic_inc(&entry->usage);
107}
108
109static inline void lec_arp_put(struct lec_arp_table *entry)
110{
111 if (atomic_dec_and_test(&entry->usage))
112 kfree(entry);
113}
114
115
1da177e4 116static struct lane2_ops lane2_ops = {
d44f7746
CW
117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
1da177e4
LT
120};
121
d44f7746 122static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1da177e4
LT
123
124/* Device structures */
125static struct net_device *dev_lec[MAX_LEC_ITF];
126
127#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
129{
d44f7746
CW
130 struct ethhdr *eth;
131 char *buff;
132 struct lec_priv *priv;
133
134 /*
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
138 */
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
1da177e4 142 struct sock *sk;
d44f7746
CW
143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
145
146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
147 if (skb2 == NULL)
148 return;
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
154
524ad0a7 155 priv = netdev_priv(dev);
d44f7746 156 atm_force_charge(priv->lecd, skb2->truesize);
1da177e4 157 sk = sk_atm(priv->lecd);
d44f7746
CW
158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
160 }
1da177e4 161
d44f7746 162 return;
1da177e4
LT
163}
164#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165
166/*
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
173 * and returns NULL.
174 */
175#ifdef CONFIG_TR
176static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177{
d44f7746 178 struct trh_hdr *trh;
5c17d5f1 179 unsigned int riflen, num_rdsc;
d44f7746
CW
180
181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
184
185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
189 } else
190 return trh->daddr; /* not source routed */
191
192 if (riflen < 6)
193 return trh->daddr; /* last hop, source routed */
194
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
30d492da 200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
d44f7746 201 else {
30d492da 202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
d44f7746
CW
203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
204 }
205
206 return NULL;
1da177e4
LT
207}
208#endif /* CONFIG_TR */
209
210/*
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
213 *
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
217 */
218
d44f7746 219static int lec_open(struct net_device *dev)
1da177e4 220{
524ad0a7 221 struct lec_priv *priv = netdev_priv(dev);
d44f7746 222
1da177e4 223 netif_start_queue(dev);
d44f7746
CW
224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
225
226 return 0;
1da177e4
LT
227}
228
229static __inline__ void
230lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
231{
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 priv->stats.tx_dropped++;
238 return;
239 }
240
241 priv->stats.tx_packets++;
242 priv->stats.tx_bytes += skb->len;
243}
244
d44f7746 245static void lec_tx_timeout(struct net_device *dev)
1da177e4
LT
246{
247 printk(KERN_INFO "%s: tx timeout\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
d44f7746 252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
1da177e4 253{
d44f7746 254 struct sk_buff *skb2;
524ad0a7 255 struct lec_priv *priv = netdev_priv(dev);
d44f7746
CW
256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc;
1da177e4 258 struct lec_arp_table *entry;
d44f7746 259 unsigned char *dst;
1da177e4
LT
260 int min_frame_size;
261#ifdef CONFIG_TR
d44f7746 262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
1da177e4 263#endif
d44f7746 264 int is_rdesc;
1da177e4 265#if DUMP_PACKETS > 0
d44f7746
CW
266 char buf[300];
267 int i = 0;
1da177e4 268#endif /* DUMP_PACKETS >0 */
d44f7746 269
52240062 270 pr_debug("lec_start_xmit called\n");
d44f7746
CW
271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
275 return -EUNATCH;
276 }
277
52240062 278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
27a884dc 279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
4305b541 280 (long)skb_end_pointer(skb));
1da177e4 281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
d44f7746
CW
282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
1da177e4
LT
284#endif
285
d44f7746
CW
286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
1da177e4 288
52240062 289 pr_debug("lec_start_xmit: reallocating skb\n");
d44f7746
CW
290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
293 return 0;
294 skb = skb2;
295 }
296 skb_push(skb, 2);
1da177e4 297
d44f7746
CW
298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
1da177e4
LT
301
302#ifdef CONFIG_TR
d44f7746
CW
303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
311 return 0;
312 skb = skb2;
313 }
1da177e4
LT
314#endif
315
316#if DUMP_PACKETS > 0
d44f7746
CW
317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
1da177e4 319#if DUMP_PACKETS >= 2
d44f7746
CW
320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
1da177e4 323#elif DUMP_PACKETS >= 1
d44f7746
CW
324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
1da177e4 327#endif /* DUMP_PACKETS >= 1 */
d44f7746
CW
328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
1da177e4
LT
332#endif /* DUMP_PACKETS > 0 */
333
d44f7746 334 /* Minimum ethernet-frame size */
1da177e4 335#ifdef CONFIG_TR
d44f7746
CW
336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
1da177e4
LT
338 else
339#endif
d44f7746
CW
340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
348 priv->stats.tx_dropped++;
349 return 0;
350 }
351 skb = skb2;
352 }
1da177e4 353 skb_put(skb, min_frame_size - skb->len);
d44f7746
CW
354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
1da177e4 359#ifdef CONFIG_TR
d44f7746
CW
360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
1da177e4 367#endif
d44f7746
CW
368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
58c14a8f 370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
d44f7746
CW
371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
52240062 374 pr_debug("%s:lec_start_xmit: queuing packet, ",
d44f7746 375 dev->name);
e174961c 376 pr_debug("MAC address %pM\n", lec_h->h_dest);
d44f7746
CW
377 skb_queue_tail(&entry->tx_wait, skb);
378 } else {
52240062 379 pr_debug
d44f7746
CW
380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
381 dev->name);
e174961c 382 pr_debug("MAC address %pM\n", lec_h->h_dest);
d44f7746
CW
383 priv->stats.tx_dropped++;
384 dev_kfree_skb(skb);
385 }
6656e3c4 386 goto out;
d44f7746
CW
387 }
388#if DUMP_PACKETS > 0
389 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
1da177e4 390#endif /* DUMP_PACKETS > 0 */
d44f7746
CW
391
392 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
52240062 393 pr_debug("lec.c: emptying tx queue, ");
e174961c 394 pr_debug("MAC address %pM\n", lec_h->h_dest);
1da177e4 395 lec_send(vcc, skb2, priv);
d44f7746 396 }
1da177e4
LT
397
398 lec_send(vcc, skb, priv);
399
400 if (!atm_may_send(vcc, 0)) {
401 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
402
403 vpriv->xoff = 1;
404 netif_stop_queue(dev);
405
406 /*
407 * vcc->pop() might have occurred in between, making
408 * the vcc usuable again. Since xmit is serialized,
409 * this is the only situation we have to re-test.
410 */
411
412 if (atm_may_send(vcc, 0))
413 netif_wake_queue(dev);
414 }
415
6656e3c4
CW
416out:
417 if (entry)
418 lec_arp_put(entry);
1da177e4 419 dev->trans_start = jiffies;
d44f7746 420 return 0;
1da177e4
LT
421}
422
423/* The inverse routine to net_open(). */
d44f7746 424static int lec_close(struct net_device *dev)
1da177e4 425{
d44f7746
CW
426 netif_stop_queue(dev);
427 return 0;
1da177e4
LT
428}
429
430/*
431 * Get the current statistics.
432 * This may be called with the card open or closed.
433 */
d44f7746 434static struct net_device_stats *lec_get_stats(struct net_device *dev)
1da177e4 435{
524ad0a7 436 return &((struct lec_priv *)netdev_priv(dev))->stats;
1da177e4
LT
437}
438
d44f7746 439static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
1da177e4
LT
440{
441 unsigned long flags;
d44f7746 442 struct net_device *dev = (struct net_device *)vcc->proto_data;
524ad0a7 443 struct lec_priv *priv = netdev_priv(dev);
d44f7746
CW
444 struct atmlec_msg *mesg;
445 struct lec_arp_table *entry;
446 int i;
447 char *tmp; /* FIXME */
1da177e4
LT
448
449 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
d44f7746
CW
450 mesg = (struct atmlec_msg *)skb->data;
451 tmp = skb->data;
452 tmp += sizeof(struct atmlec_msg);
52240062 453 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
d44f7746
CW
454 switch (mesg->type) {
455 case l_set_mac_addr:
456 for (i = 0; i < 6; i++) {
457 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
458 }
459 break;
460 case l_del_mac_addr:
461 for (i = 0; i < 6; i++) {
462 dev->dev_addr[i] = 0;
463 }
464 break;
465 case l_addr_delete:
466 lec_addr_delete(priv, mesg->content.normal.atm_addr,
467 mesg->content.normal.flag);
468 break;
469 case l_topology_change:
470 priv->topology_change = mesg->content.normal.flag;
471 break;
472 case l_flush_complete:
473 lec_flush_complete(priv, mesg->content.normal.flag);
474 break;
475 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
1da177e4 476 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d44f7746
CW
477 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
478 lec_arp_remove(priv, entry);
1da177e4
LT
479 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
480
d44f7746
CW
481 if (mesg->content.normal.no_source_le_narp)
482 break;
483 /* FALL THROUGH */
484 case l_arp_update:
485 lec_arp_update(priv, mesg->content.normal.mac_addr,
486 mesg->content.normal.atm_addr,
487 mesg->content.normal.flag,
488 mesg->content.normal.targetless_le_arp);
52240062 489 pr_debug("lec: in l_arp_update\n");
d44f7746 490 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
52240062 491 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
d44f7746
CW
492 mesg->sizeoftlvs);
493 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
494 tmp, mesg->sizeoftlvs);
495 }
496 break;
497 case l_config:
498 priv->maximum_unknown_frame_count =
499 mesg->content.config.maximum_unknown_frame_count;
500 priv->max_unknown_frame_time =
501 (mesg->content.config.max_unknown_frame_time * HZ);
502 priv->max_retry_count = mesg->content.config.max_retry_count;
503 priv->aging_time = (mesg->content.config.aging_time * HZ);
504 priv->forward_delay_time =
505 (mesg->content.config.forward_delay_time * HZ);
506 priv->arp_response_time =
507 (mesg->content.config.arp_response_time * HZ);
508 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
509 priv->path_switching_delay =
510 (mesg->content.config.path_switching_delay * HZ);
511 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
1da177e4
LT
512 priv->lane2_ops = NULL;
513 if (priv->lane_version > 1)
514 priv->lane2_ops = &lane2_ops;
515 if (dev->change_mtu(dev, mesg->content.config.mtu))
516 printk("%s: change_mtu to %d failed\n", dev->name,
d44f7746 517 mesg->content.config.mtu);
1da177e4 518 priv->is_proxy = mesg->content.config.is_proxy;
d44f7746
CW
519 break;
520 case l_flush_tran_id:
521 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
522 mesg->content.normal.flag);
523 break;
524 case l_set_lecid:
525 priv->lecid =
526 (unsigned short)(0xffff & mesg->content.normal.flag);
527 break;
528 case l_should_bridge:
1da177e4 529#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
d44f7746
CW
530 {
531 struct net_bridge_fdb_entry *f;
532
e174961c
JB
533 pr_debug("%s: bridge zeppelin asks about %pM\n",
534 dev->name, mesg->content.proxy.mac_addr);
d44f7746
CW
535
536 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
537 break;
538
539 f = br_fdb_get_hook(dev->br_port->br,
540 mesg->content.proxy.mac_addr);
541 if (f != NULL && f->dst->dev != dev
542 && f->dst->state == BR_STATE_FORWARDING) {
543 /* hit from bridge table, send LE_ARP_RESPONSE */
544 struct sk_buff *skb2;
545 struct sock *sk;
546
52240062 547 pr_debug
d44f7746
CW
548 ("%s: entry found, responding to zeppelin\n",
549 dev->name);
550 skb2 =
551 alloc_skb(sizeof(struct atmlec_msg),
552 GFP_ATOMIC);
553 if (skb2 == NULL) {
554 br_fdb_put_hook(f);
555 break;
556 }
557 skb2->len = sizeof(struct atmlec_msg);
27d7ff46
ACM
558 skb_copy_to_linear_data(skb2, mesg,
559 sizeof(*mesg));
d44f7746
CW
560 atm_force_charge(priv->lecd, skb2->truesize);
561 sk = sk_atm(priv->lecd);
562 skb_queue_tail(&sk->sk_receive_queue, skb2);
563 sk->sk_data_ready(sk, skb2->len);
564 }
565 if (f != NULL)
566 br_fdb_put_hook(f);
567 }
1da177e4 568#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
d44f7746
CW
569 break;
570 default:
571 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
572 dev_kfree_skb(skb);
573 return -EINVAL;
574 }
575 dev_kfree_skb(skb);
576 return 0;
1da177e4
LT
577}
578
d44f7746 579static void lec_atm_close(struct atm_vcc *vcc)
1da177e4 580{
d44f7746
CW
581 struct sk_buff *skb;
582 struct net_device *dev = (struct net_device *)vcc->proto_data;
524ad0a7 583 struct lec_priv *priv = netdev_priv(dev);
1da177e4 584
d44f7746
CW
585 priv->lecd = NULL;
586 /* Do something needful? */
1da177e4 587
d44f7746
CW
588 netif_stop_queue(dev);
589 lec_arp_destroy(priv);
1da177e4 590
d44f7746 591 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
1da177e4 592 printk("%s lec_atm_close: closing with messages pending\n",
d44f7746
CW
593 dev->name);
594 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
595 atm_return(vcc, skb->truesize);
1da177e4 596 dev_kfree_skb(skb);
d44f7746
CW
597 }
598
1da177e4 599 printk("%s: Shut down!\n", dev->name);
d44f7746 600 module_put(THIS_MODULE);
1da177e4
LT
601}
602
603static struct atmdev_ops lecdev_ops = {
d44f7746
CW
604 .close = lec_atm_close,
605 .send = lec_atm_send
1da177e4
LT
606};
607
608static struct atm_dev lecatm_dev = {
d44f7746
CW
609 .ops = &lecdev_ops,
610 .type = "lec",
611 .number = 999, /* dummy device number */
4ef8d0ae 612 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
1da177e4
LT
613};
614
615/*
616 * LANE2: new argument struct sk_buff *data contains
617 * the LE_ARP based TLVs introduced in the LANE2 spec
618 */
d44f7746
CW
619static int
620send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
61c33e01 621 const unsigned char *mac_addr, const unsigned char *atm_addr,
d44f7746 622 struct sk_buff *data)
1da177e4
LT
623{
624 struct sock *sk;
625 struct sk_buff *skb;
626 struct atmlec_msg *mesg;
627
628 if (!priv || !priv->lecd) {
629 return -1;
630 }
631 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
632 if (!skb)
633 return -1;
634 skb->len = sizeof(struct atmlec_msg);
635 mesg = (struct atmlec_msg *)skb->data;
d44f7746 636 memset(mesg, 0, sizeof(struct atmlec_msg));
1da177e4 637 mesg->type = type;
d44f7746
CW
638 if (data != NULL)
639 mesg->sizeoftlvs = data->len;
1da177e4
LT
640 if (mac_addr)
641 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
d44f7746
CW
642 else
643 mesg->content.normal.targetless_le_arp = 1;
1da177e4
LT
644 if (atm_addr)
645 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
646
d44f7746 647 atm_force_charge(priv->lecd, skb->truesize);
1da177e4
LT
648 sk = sk_atm(priv->lecd);
649 skb_queue_tail(&sk->sk_receive_queue, skb);
d44f7746 650 sk->sk_data_ready(sk, skb->len);
1da177e4 651
d44f7746 652 if (data != NULL) {
52240062 653 pr_debug("lec: about to send %d bytes of data\n", data->len);
d44f7746
CW
654 atm_force_charge(priv->lecd, data->truesize);
655 skb_queue_tail(&sk->sk_receive_queue, data);
656 sk->sk_data_ready(sk, skb->len);
657 }
1da177e4 658
d44f7746 659 return 0;
1da177e4
LT
660}
661
662/* shamelessly stolen from drivers/net/net_init.c */
663static int lec_change_mtu(struct net_device *dev, int new_mtu)
664{
d44f7746
CW
665 if ((new_mtu < 68) || (new_mtu > 18190))
666 return -EINVAL;
667 dev->mtu = new_mtu;
668 return 0;
1da177e4
LT
669}
670
671static void lec_set_multicast_list(struct net_device *dev)
672{
d44f7746
CW
673 /*
674 * by default, all multicast frames arrive over the bus.
675 * eventually support selective multicast service
676 */
677 return;
1da177e4
LT
678}
679
d44f7746 680static void lec_init(struct net_device *dev)
1da177e4 681{
d44f7746
CW
682 dev->change_mtu = lec_change_mtu;
683 dev->open = lec_open;
684 dev->stop = lec_close;
685 dev->hard_start_xmit = lec_start_xmit;
1da177e4
LT
686 dev->tx_timeout = lec_tx_timeout;
687
d44f7746
CW
688 dev->get_stats = lec_get_stats;
689 dev->set_multicast_list = lec_set_multicast_list;
690 dev->do_ioctl = NULL;
691 printk("%s: Initialized!\n", dev->name);
1da177e4
LT
692}
693
61c33e01 694static const unsigned char lec_ctrl_magic[] = {
d44f7746
CW
695 0xff,
696 0x00,
697 0x01,
698 0x01
699};
1da177e4 700
4a7097fc
ST
701#define LEC_DATA_DIRECT_8023 2
702#define LEC_DATA_DIRECT_8025 3
703
704static int lec_is_data_direct(struct atm_vcc *vcc)
d44f7746 705{
4a7097fc
ST
706 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
707 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
d44f7746 708}
4a7097fc 709
d44f7746 710static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
1da177e4 711{
4a7097fc 712 unsigned long flags;
d44f7746 713 struct net_device *dev = (struct net_device *)vcc->proto_data;
524ad0a7 714 struct lec_priv *priv = netdev_priv(dev);
1da177e4
LT
715
716#if DUMP_PACKETS >0
d44f7746
CW
717 int i = 0;
718 char buf[300];
1da177e4 719
d44f7746
CW
720 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
721 vcc->vpi, vcc->vci);
1da177e4 722#endif
d44f7746 723 if (!skb) {
52240062 724 pr_debug("%s: null skb\n", dev->name);
d44f7746
CW
725 lec_vcc_close(priv, vcc);
726 return;
727 }
1da177e4 728#if DUMP_PACKETS > 0
d44f7746
CW
729 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
730 skb->len, priv->lecid);
1da177e4 731#if DUMP_PACKETS >= 2
d44f7746
CW
732 for (i = 0; i < skb->len && i < 99; i++) {
733 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
734 }
1da177e4 735#elif DUMP_PACKETS >= 1
d44f7746
CW
736 for (i = 0; i < skb->len && i < 30; i++) {
737 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
738 }
1da177e4 739#endif /* DUMP_PACKETS >= 1 */
d44f7746
CW
740 if (i == skb->len)
741 printk("%s\n", buf);
742 else
743 printk("%s...\n", buf);
1da177e4 744#endif /* DUMP_PACKETS > 0 */
d44f7746 745 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
1da177e4
LT
746 struct sock *sk = sk_atm(vcc);
747
52240062 748 pr_debug("%s: To daemon\n", dev->name);
d44f7746
CW
749 skb_queue_tail(&sk->sk_receive_queue, skb);
750 sk->sk_data_ready(sk, skb->len);
751 } else { /* Data frame, queue to protocol handlers */
4a7097fc 752 struct lec_arp_table *entry;
d44f7746
CW
753 unsigned char *src, *dst;
754
755 atm_return(vcc, skb->truesize);
30d492da 756 if (*(__be16 *) skb->data == htons(priv->lecid) ||
d44f7746
CW
757 !priv->lecd || !(dev->flags & IFF_UP)) {
758 /*
759 * Probably looping back, or if lecd is missing,
760 * lecd has gone down
761 */
52240062 762 pr_debug("Ignoring frame...\n");
d44f7746
CW
763 dev_kfree_skb(skb);
764 return;
765 }
1da177e4 766#ifdef CONFIG_TR
d44f7746
CW
767 if (priv->is_trdev)
768 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
769 else
1da177e4 770#endif
d44f7746 771 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
4a7097fc 772
d44f7746
CW
773 /*
774 * If this is a Data Direct VCC, and the VCC does not match
4a7097fc
ST
775 * the LE_ARP cache entry, delete the LE_ARP cache entry.
776 */
777 spin_lock_irqsave(&priv->lec_arp_lock, flags);
778 if (lec_is_data_direct(vcc)) {
779#ifdef CONFIG_TR
780 if (priv->is_trdev)
d44f7746
CW
781 src =
782 ((struct lecdatahdr_8025 *)skb->data)->
783 h_source;
4a7097fc
ST
784 else
785#endif
d44f7746
CW
786 src =
787 ((struct lecdatahdr_8023 *)skb->data)->
788 h_source;
4a7097fc
ST
789 entry = lec_arp_find(priv, src);
790 if (entry && entry->vcc != vcc) {
791 lec_arp_remove(priv, entry);
33a9c2d4 792 lec_arp_put(entry);
4a7097fc
ST
793 }
794 }
795 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1da177e4 796
d44f7746
CW
797 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
798 !priv->is_proxy && /* Proxy wants all the packets */
1da177e4 799 memcmp(dst, dev->dev_addr, dev->addr_len)) {
d44f7746
CW
800 dev_kfree_skb(skb);
801 return;
802 }
d0732f64 803 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
d44f7746
CW
804 lec_arp_check_empties(priv, vcc, skb);
805 }
d44f7746 806 skb_pull(skb, 2); /* skip lec_id */
1da177e4 807#ifdef CONFIG_TR
d44f7746
CW
808 if (priv->is_trdev)
809 skb->protocol = tr_type_trans(skb, dev);
810 else
1da177e4 811#endif
d44f7746
CW
812 skb->protocol = eth_type_trans(skb, dev);
813 priv->stats.rx_packets++;
814 priv->stats.rx_bytes += skb->len;
815 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
816 netif_rx(skb);
817 }
1da177e4
LT
818}
819
d44f7746 820static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
1da177e4
LT
821{
822 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
823 struct net_device *dev = skb->dev;
824
825 if (vpriv == NULL) {
826 printk("lec_pop(): vpriv = NULL!?!?!?\n");
827 return;
828 }
829
830 vpriv->old_pop(vcc, skb);
831
832 if (vpriv->xoff && atm_may_send(vcc, 0)) {
833 vpriv->xoff = 0;
834 if (netif_running(dev) && netif_queue_stopped(dev))
835 netif_wake_queue(dev);
836 }
837}
838
d44f7746 839static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
1da177e4
LT
840{
841 struct lec_vcc_priv *vpriv;
d44f7746
CW
842 int bytes_left;
843 struct atmlec_ioc ioc_data;
844
845 /* Lecd must be up in this case */
846 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
847 if (bytes_left != 0) {
848 printk
849 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
850 bytes_left);
851 }
852 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
853 !dev_lec[ioc_data.dev_num])
854 return -EINVAL;
1da177e4
LT
855 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
856 return -ENOMEM;
857 vpriv->xoff = 0;
858 vpriv->old_pop = vcc->pop;
859 vcc->user_back = vpriv;
860 vcc->pop = lec_pop;
524ad0a7 861 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
d44f7746
CW
862 &ioc_data, vcc, vcc->push);
863 vcc->proto_data = dev_lec[ioc_data.dev_num];
864 vcc->push = lec_push;
865 return 0;
1da177e4
LT
866}
867
d44f7746 868static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
1da177e4 869{
d44f7746
CW
870 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
871 return -EINVAL;
872 vcc->proto_data = dev_lec[arg];
524ad0a7
WC
873 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
874 vcc);
1da177e4
LT
875}
876
877/* Initialize device. */
d44f7746
CW
878static int lecd_attach(struct atm_vcc *vcc, int arg)
879{
880 int i;
881 struct lec_priv *priv;
882
883 if (arg < 0)
884 i = 0;
885 else
886 i = arg;
1da177e4 887#ifdef CONFIG_TR
d44f7746
CW
888 if (arg >= MAX_LEC_ITF)
889 return -EINVAL;
890#else /* Reserve the top NUM_TR_DEVS for TR */
891 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
892 return -EINVAL;
1da177e4 893#endif
d44f7746
CW
894 if (!dev_lec[i]) {
895 int is_trdev, size;
1da177e4 896
d44f7746
CW
897 is_trdev = 0;
898 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
899 is_trdev = 1;
1da177e4 900
d44f7746 901 size = sizeof(struct lec_priv);
1da177e4 902#ifdef CONFIG_TR
d44f7746
CW
903 if (is_trdev)
904 dev_lec[i] = alloc_trdev(size);
905 else
1da177e4 906#endif
d44f7746
CW
907 dev_lec[i] = alloc_etherdev(size);
908 if (!dev_lec[i])
909 return -ENOMEM;
910 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
911 if (register_netdev(dev_lec[i])) {
912 free_netdev(dev_lec[i]);
913 return -EINVAL;
914 }
915
524ad0a7 916 priv = netdev_priv(dev_lec[i]);
d44f7746
CW
917 priv->is_trdev = is_trdev;
918 lec_init(dev_lec[i]);
919 } else {
524ad0a7 920 priv = netdev_priv(dev_lec[i]);
d44f7746
CW
921 if (priv->lecd)
922 return -EADDRINUSE;
923 }
924 lec_arp_init(priv);
925 priv->itfnum = i; /* LANE2 addition */
926 priv->lecd = vcc;
927 vcc->dev = &lecatm_dev;
928 vcc_insert_socket(sk_atm(vcc));
929
930 vcc->proto_data = dev_lec[i];
931 set_bit(ATM_VF_META, &vcc->flags);
932 set_bit(ATM_VF_READY, &vcc->flags);
933
934 /* Set default values to these variables */
935 priv->maximum_unknown_frame_count = 1;
936 priv->max_unknown_frame_time = (1 * HZ);
937 priv->vcc_timeout_period = (1200 * HZ);
938 priv->max_retry_count = 1;
939 priv->aging_time = (300 * HZ);
940 priv->forward_delay_time = (15 * HZ);
941 priv->topology_change = 0;
942 priv->arp_response_time = (1 * HZ);
943 priv->flush_timeout = (4 * HZ);
944 priv->path_switching_delay = (6 * HZ);
945
946 if (dev_lec[i]->flags & IFF_UP) {
947 netif_start_queue(dev_lec[i]);
948 }
949 __module_get(THIS_MODULE);
950 return i;
1da177e4
LT
951}
952
953#ifdef CONFIG_PROC_FS
d44f7746 954static char *lec_arp_get_status_string(unsigned char status)
1da177e4
LT
955{
956 static char *lec_arp_status_string[] = {
957 "ESI_UNKNOWN ",
958 "ESI_ARP_PENDING ",
959 "ESI_VC_PENDING ",
960 "<Undefined> ",
961 "ESI_FLUSH_PENDING ",
962 "ESI_FORWARD_DIRECT"
963 };
964
965 if (status > ESI_FORWARD_DIRECT)
966 status = 3; /* ESI_UNDEFINED */
967 return lec_arp_status_string[status];
968}
969
970static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
971{
972 int i;
973
974 for (i = 0; i < ETH_ALEN; i++)
975 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
976 seq_printf(seq, " ");
977 for (i = 0; i < ATM_ESA_LEN; i++)
978 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
979 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
980 entry->flags & 0xffff);
981 if (entry->vcc)
982 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
983 else
d44f7746 984 seq_printf(seq, " ");
1da177e4
LT
985 if (entry->recv_vcc) {
986 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
987 entry->recv_vcc->vci);
d44f7746
CW
988 }
989 seq_putc(seq, '\n');
1da177e4
LT
990}
991
1da177e4
LT
992struct lec_state {
993 unsigned long flags;
994 struct lec_priv *locked;
d0732f64 995 struct hlist_node *node;
1da177e4
LT
996 struct net_device *dev;
997 int itf;
998 int arp_table;
999 int misc_table;
1000};
1001
d0732f64 1002static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
1da177e4
LT
1003 loff_t *l)
1004{
d0732f64
CW
1005 struct hlist_node *e = state->node;
1006 struct lec_arp_table *tmp;
1da177e4
LT
1007
1008 if (!e)
d0732f64 1009 e = tbl->first;
2e1e9848 1010 if (e == SEQ_START_TOKEN) {
d0732f64 1011 e = tbl->first;
1da177e4
LT
1012 --*l;
1013 }
d0732f64
CW
1014
1015 hlist_for_each_entry_from(tmp, e, next) {
1da177e4
LT
1016 if (--*l < 0)
1017 break;
1018 }
d0732f64
CW
1019 state->node = e;
1020
1da177e4
LT
1021 return (*l < 0) ? state : NULL;
1022}
1023
1024static void *lec_arp_walk(struct lec_state *state, loff_t *l,
d44f7746 1025 struct lec_priv *priv)
1da177e4
LT
1026{
1027 void *v = NULL;
1028 int p;
1029
1030 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
d0732f64 1031 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1da177e4
LT
1032 if (v)
1033 break;
1034 }
1035 state->arp_table = p;
1036 return v;
1037}
1038
1039static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1040 struct lec_priv *priv)
1041{
d0732f64
CW
1042 struct hlist_head *lec_misc_tables[] = {
1043 &priv->lec_arp_empty_ones,
1044 &priv->lec_no_forward,
1045 &priv->mcast_fwds
1da177e4
LT
1046 };
1047 void *v = NULL;
1048 int q;
1049
1050 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1051 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1052 if (v)
1053 break;
1054 }
1055 state->misc_table = q;
1056 return v;
1057}
1058
1059static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1060 struct lec_priv *priv)
1061{
1062 if (!state->locked) {
1063 state->locked = priv;
1064 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1065 }
d44f7746 1066 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1da177e4
LT
1067 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1068 state->locked = NULL;
1069 /* Partial state reset for the next time we get called */
1070 state->arp_table = state->misc_table = 0;
1071 }
1072 return state->locked;
1073}
1074
1075static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1076{
1077 struct net_device *dev;
1078 void *v;
1079
1080 dev = state->dev ? state->dev : dev_lec[state->itf];
524ad0a7
WC
1081 v = (dev && netdev_priv(dev)) ?
1082 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
1da177e4
LT
1083 if (!v && dev) {
1084 dev_put(dev);
1085 /* Partial state reset for the next time we get called */
1086 dev = NULL;
1087 }
1088 state->dev = dev;
1089 return v;
1090}
1091
1092static void *lec_get_idx(struct lec_state *state, loff_t l)
1093{
1094 void *v = NULL;
1095
1096 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1097 v = lec_itf_walk(state, &l);
1098 if (v)
1099 break;
1100 }
d44f7746 1101 return v;
1da177e4
LT
1102}
1103
1104static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1105{
1106 struct lec_state *state = seq->private;
1107
1108 state->itf = 0;
1109 state->dev = NULL;
1110 state->locked = NULL;
1111 state->arp_table = 0;
1112 state->misc_table = 0;
2e1e9848 1113 state->node = SEQ_START_TOKEN;
1da177e4 1114
2e1e9848 1115 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
1da177e4
LT
1116}
1117
1118static void lec_seq_stop(struct seq_file *seq, void *v)
1119{
1120 struct lec_state *state = seq->private;
1121
1122 if (state->dev) {
1123 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1124 state->flags);
1125 dev_put(state->dev);
1126 }
1127}
1128
1129static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1130{
1131 struct lec_state *state = seq->private;
1132
1133 v = lec_get_idx(state, 1);
1134 *pos += !!PTR_ERR(v);
1135 return v;
1136}
1137
1138static int lec_seq_show(struct seq_file *seq, void *v)
1139{
d44f7746
CW
1140 static char lec_banner[] = "Itf MAC ATM destination"
1141 " Status Flags "
1142 "VPI/VCI Recv VPI/VCI\n";
1da177e4 1143
2e1e9848 1144 if (v == SEQ_START_TOKEN)
1da177e4
LT
1145 seq_puts(seq, lec_banner);
1146 else {
1147 struct lec_state *state = seq->private;
d44f7746 1148 struct net_device *dev = state->dev;
d0732f64 1149 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1da177e4
LT
1150
1151 seq_printf(seq, "%s ", dev->name);
d0732f64 1152 lec_info(seq, entry);
1da177e4
LT
1153 }
1154 return 0;
1155}
1156
56b3d975 1157static const struct seq_operations lec_seq_ops = {
d44f7746
CW
1158 .start = lec_seq_start,
1159 .next = lec_seq_next,
1160 .stop = lec_seq_stop,
1161 .show = lec_seq_show,
1da177e4
LT
1162};
1163
1164static int lec_seq_open(struct inode *inode, struct file *file)
1165{
9a8c09e7 1166 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
1da177e4
LT
1167}
1168
9a32144e 1169static const struct file_operations lec_seq_fops = {
d44f7746
CW
1170 .owner = THIS_MODULE,
1171 .open = lec_seq_open,
1172 .read = seq_read,
1173 .llseek = seq_lseek,
9a8c09e7 1174 .release = seq_release_private,
1da177e4
LT
1175};
1176#endif
1177
1178static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1179{
1180 struct atm_vcc *vcc = ATM_SD(sock);
1181 int err = 0;
d44f7746 1182
1da177e4 1183 switch (cmd) {
d44f7746
CW
1184 case ATMLEC_CTRL:
1185 case ATMLEC_MCAST:
1186 case ATMLEC_DATA:
1187 if (!capable(CAP_NET_ADMIN))
1188 return -EPERM;
1189 break;
1190 default:
1191 return -ENOIOCTLCMD;
1da177e4
LT
1192 }
1193
1194 switch (cmd) {
d44f7746
CW
1195 case ATMLEC_CTRL:
1196 err = lecd_attach(vcc, (int)arg);
1197 if (err >= 0)
1198 sock->state = SS_CONNECTED;
1199 break;
1200 case ATMLEC_MCAST:
1201 err = lec_mcast_attach(vcc, (int)arg);
1202 break;
1203 case ATMLEC_DATA:
1204 err = lec_vcc_attach(vcc, (void __user *)arg);
1205 break;
1da177e4
LT
1206 }
1207
1208 return err;
1209}
1210
1211static struct atm_ioctl lane_ioctl_ops = {
d44f7746
CW
1212 .owner = THIS_MODULE,
1213 .ioctl = lane_ioctl,
1da177e4
LT
1214};
1215
1216static int __init lane_module_init(void)
1217{
1218#ifdef CONFIG_PROC_FS
1219 struct proc_dir_entry *p;
1220
16e297b3 1221 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
dbee0d3f
WC
1222 if (!p) {
1223 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1224 return -ENOMEM;
1225 }
1da177e4
LT
1226#endif
1227
1228 register_atm_ioctl(&lane_ioctl_ops);
d44f7746
CW
1229 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1230 return 0;
1da177e4
LT
1231}
1232
1233static void __exit lane_module_cleanup(void)
1234{
d44f7746
CW
1235 int i;
1236 struct lec_priv *priv;
1da177e4
LT
1237
1238 remove_proc_entry("lec", atm_proc_root);
1239
1240 deregister_atm_ioctl(&lane_ioctl_ops);
1241
d44f7746
CW
1242 for (i = 0; i < MAX_LEC_ITF; i++) {
1243 if (dev_lec[i] != NULL) {
524ad0a7 1244 priv = netdev_priv(dev_lec[i]);
1da177e4 1245 unregister_netdev(dev_lec[i]);
d44f7746
CW
1246 free_netdev(dev_lec[i]);
1247 dev_lec[i] = NULL;
1248 }
1249 }
1da177e4 1250
d44f7746 1251 return;
1da177e4
LT
1252}
1253
1254module_init(lane_module_init);
1255module_exit(lane_module_cleanup);
1256
1257/*
1258 * LANE2: 3.1.3, LE_RESOLVE.request
1259 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1260 * If sizeoftlvs == NULL the default TLVs associated with with this
1261 * lec will be used.
1262 * If dst_mac == NULL, targetless LE_ARP will be sent
1263 */
61c33e01 1264static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
d44f7746 1265 u8 **tlvs, u32 *sizeoftlvs)
1da177e4
LT
1266{
1267 unsigned long flags;
524ad0a7 1268 struct lec_priv *priv = netdev_priv(dev);
d44f7746
CW
1269 struct lec_arp_table *table;
1270 struct sk_buff *skb;
1271 int retval;
1da177e4 1272
d44f7746 1273 if (force == 0) {
1da177e4 1274 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d44f7746 1275 table = lec_arp_find(priv, dst_mac);
1da177e4 1276 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
d44f7746
CW
1277 if (table == NULL)
1278 return -1;
1279
2afe37cd 1280 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
d44f7746
CW
1281 if (*tlvs == NULL)
1282 return -1;
1283
d44f7746
CW
1284 *sizeoftlvs = table->sizeoftlvs;
1285
1286 return 0;
1287 }
1da177e4
LT
1288
1289 if (sizeoftlvs == NULL)
1290 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
d44f7746 1291
1da177e4
LT
1292 else {
1293 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1294 if (skb == NULL)
1295 return -1;
1296 skb->len = *sizeoftlvs;
27d7ff46 1297 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1da177e4
LT
1298 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1299 }
d44f7746
CW
1300 return retval;
1301}
1da177e4
LT
1302
1303/*
1304 * LANE2: 3.1.4, LE_ASSOCIATE.request
1305 * Associate the *tlvs with the *lan_dst address.
1306 * Will overwrite any previous association
1307 * Returns 1 for success, 0 for failure (out of memory)
1308 *
1309 */
61c33e01
MBJ
1310static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1311 const u8 *tlvs, u32 sizeoftlvs)
1da177e4 1312{
d44f7746
CW
1313 int retval;
1314 struct sk_buff *skb;
524ad0a7 1315 struct lec_priv *priv = netdev_priv(dev);
d44f7746
CW
1316
1317 if (compare_ether_addr(lan_dst, dev->dev_addr))
1318 return (0); /* not our mac address */
1319
1320 kfree(priv->tlvs); /* NULL if there was no previous association */
1321
2afe37cd 1322 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
d44f7746
CW
1323 if (priv->tlvs == NULL)
1324 return (0);
1325 priv->sizeoftlvs = sizeoftlvs;
d44f7746
CW
1326
1327 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1328 if (skb == NULL)
1329 return 0;
1330 skb->len = sizeoftlvs;
27d7ff46 1331 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
d44f7746
CW
1332 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1333 if (retval != 0)
1334 printk("lec.c: lane2_associate_req() failed\n");
1335 /*
1336 * If the previous association has changed we must
1337 * somehow notify other LANE entities about the change
1338 */
1339 return (1);
1da177e4
LT
1340}
1341
1342/*
1343 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1344 *
1345 */
61c33e01
MBJ
1346static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1347 const u8 *tlvs, u32 sizeoftlvs)
1da177e4
LT
1348{
1349#if 0
d44f7746 1350 int i = 0;
1da177e4 1351#endif
524ad0a7 1352 struct lec_priv *priv = netdev_priv(dev);
d44f7746
CW
1353#if 0 /*
1354 * Why have the TLVs in LE_ARP entries
1355 * since we do not use them? When you
1356 * uncomment this code, make sure the
1357 * TLVs get freed when entry is killed
1358 */
1359 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1da177e4 1360
d44f7746
CW
1361 if (entry == NULL)
1362 return; /* should not happen */
1da177e4 1363
d44f7746 1364 kfree(entry->tlvs);
1da177e4 1365
2afe37cd 1366 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
d44f7746
CW
1367 if (entry->tlvs == NULL)
1368 return;
d44f7746 1369 entry->sizeoftlvs = sizeoftlvs;
1da177e4
LT
1370#endif
1371#if 0
d44f7746
CW
1372 printk("lec.c: lane2_associate_ind()\n");
1373 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1374 while (i < sizeoftlvs)
1375 printk("%02x ", tlvs[i++]);
1376
1377 printk("\n");
1da177e4
LT
1378#endif
1379
d44f7746
CW
1380 /* tell MPOA about the TLVs we saw */
1381 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1382 priv->lane2_ops->associate_indicator(dev, mac_addr,
1383 tlvs, sizeoftlvs);
1384 }
1385 return;
1da177e4
LT
1386}
1387
1388/*
1389 * Here starts what used to lec_arpc.c
1390 *
1391 * lec_arpc.c was added here when making
1392 * lane client modular. October 1997
1da177e4
LT
1393 */
1394
1395#include <linux/types.h>
1da177e4
LT
1396#include <linux/timer.h>
1397#include <asm/param.h>
1398#include <asm/atomic.h>
1399#include <linux/inetdevice.h>
1400#include <net/route.h>
1401
1da177e4 1402#if 0
52240062 1403#define pr_debug(format,args...)
1da177e4 1404/*
52240062 1405#define pr_debug printk
1da177e4
LT
1406*/
1407#endif
1408#define DEBUG_ARP_TABLE 0
1409
1410#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1411
c4028958 1412static void lec_arp_check_expire(struct work_struct *work);
1da177e4
LT
1413static void lec_arp_expire_arp(unsigned long data);
1414
f7d57453 1415/*
1da177e4
LT
1416 * Arp table funcs
1417 */
1418
1419#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1420
1421/*
1422 * Initialization of arp-cache
1423 */
1fa9961d 1424static void lec_arp_init(struct lec_priv *priv)
1da177e4 1425{
1fa9961d 1426 unsigned short i;
1da177e4 1427
1fa9961d 1428 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1429 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1fa9961d 1430 }
f7d57453
YH
1431 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1432 INIT_HLIST_HEAD(&priv->lec_no_forward);
1433 INIT_HLIST_HEAD(&priv->mcast_fwds);
1da177e4 1434 spin_lock_init(&priv->lec_arp_lock);
c4028958 1435 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
987e46bd 1436 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1da177e4
LT
1437}
1438
1fa9961d 1439static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1da177e4 1440{
1fa9961d 1441 if (entry->vcc) {
1da177e4
LT
1442 struct atm_vcc *vcc = entry->vcc;
1443 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1fa9961d 1444 struct net_device *dev = (struct net_device *)vcc->proto_data;
1da177e4 1445
1fa9961d 1446 vcc->pop = vpriv->old_pop;
1da177e4
LT
1447 if (vpriv->xoff)
1448 netif_wake_queue(dev);
1449 kfree(vpriv);
1450 vcc->user_back = NULL;
1fa9961d 1451 vcc->push = entry->old_push;
1da177e4 1452 vcc_release_async(vcc, -EPIPE);
d0732f64 1453 entry->vcc = NULL;
1fa9961d
CW
1454 }
1455 if (entry->recv_vcc) {
1456 entry->recv_vcc->push = entry->old_recv_push;
1da177e4 1457 vcc_release_async(entry->recv_vcc, -EPIPE);
1fa9961d
CW
1458 entry->recv_vcc = NULL;
1459 }
1da177e4
LT
1460}
1461
1462/*
1463 * Insert entry to lec_arp_table
1464 * LANE2: Add to the end of the list to satisfy 8.1.13
1465 */
1fa9961d 1466static inline void
d0732f64 1467lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1da177e4 1468{
d0732f64 1469 struct hlist_head *tmp;
1fa9961d 1470
d0732f64
CW
1471 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1472 hlist_add_head(&entry->next, tmp);
1fa9961d 1473
52240062 1474 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
d0732f64
CW
1475 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1476 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1477 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1da177e4
LT
1478}
1479
1480/*
1481 * Remove entry from lec_arp_table
1482 */
1fa9961d
CW
1483static int
1484lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1da177e4 1485{
d0732f64
CW
1486 struct hlist_node *node;
1487 struct lec_arp_table *entry;
1488 int i, remove_vcc = 1;
1fa9961d
CW
1489
1490 if (!to_remove) {
1491 return -1;
1492 }
d0732f64
CW
1493
1494 hlist_del(&to_remove->next);
1fa9961d
CW
1495 del_timer(&to_remove->timer);
1496
d0732f64 1497 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1fa9961d
CW
1498 if (to_remove->status >= ESI_FLUSH_PENDING) {
1499 /*
1500 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1501 */
d0732f64
CW
1502 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1503 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1504 if (memcmp(to_remove->atm_addr,
1505 entry->atm_addr, ATM_ESA_LEN) == 0) {
1fa9961d
CW
1506 remove_vcc = 0;
1507 break;
1508 }
1509 }
1510 }
1511 if (remove_vcc)
1512 lec_arp_clear_vccs(to_remove);
1513 }
1514 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1515
52240062 1516 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1fa9961d
CW
1517 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1518 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1519 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1520 return 0;
1da177e4
LT
1521}
1522
1523#if DEBUG_ARP_TABLE
1fa9961d 1524static char *get_status_string(unsigned char st)
1da177e4 1525{
1fa9961d
CW
1526 switch (st) {
1527 case ESI_UNKNOWN:
1528 return "ESI_UNKNOWN";
1529 case ESI_ARP_PENDING:
1530 return "ESI_ARP_PENDING";
1531 case ESI_VC_PENDING:
1532 return "ESI_VC_PENDING";
1533 case ESI_FLUSH_PENDING:
1534 return "ESI_FLUSH_PENDING";
1535 case ESI_FORWARD_DIRECT:
1536 return "ESI_FORWARD_DIRECT";
1537 default:
1538 return "<UNKNOWN>";
1539 }
1da177e4 1540}
1da177e4 1541
1fa9961d 1542static void dump_arp_table(struct lec_priv *priv)
1da177e4 1543{
d0732f64 1544 struct hlist_node *node;
1fa9961d 1545 struct lec_arp_table *rulla;
d0732f64
CW
1546 char buf[256];
1547 int i, j, offset;
1fa9961d
CW
1548
1549 printk("Dump %p:\n", priv);
1550 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64
CW
1551 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1552 offset = 0;
1553 offset += sprintf(buf, "%d: %p\n", i, rulla);
1fa9961d
CW
1554 offset += sprintf(buf + offset, "Mac:");
1555 for (j = 0; j < ETH_ALEN; j++) {
1556 offset += sprintf(buf + offset,
1557 "%2.2x ",
1558 rulla->mac_addr[j] & 0xff);
1559 }
1560 offset += sprintf(buf + offset, "Atm:");
1561 for (j = 0; j < ATM_ESA_LEN; j++) {
1562 offset += sprintf(buf + offset,
1563 "%2.2x ",
1564 rulla->atm_addr[j] & 0xff);
1565 }
1566 offset += sprintf(buf + offset,
1567 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1568 rulla->vcc ? rulla->vcc->vpi : 0,
1569 rulla->vcc ? rulla->vcc->vci : 0,
1570 rulla->recv_vcc ? rulla->recv_vcc->
1571 vpi : 0,
1572 rulla->recv_vcc ? rulla->recv_vcc->
1573 vci : 0, rulla->last_used,
1574 rulla->timestamp, rulla->no_tries);
1575 offset +=
1576 sprintf(buf + offset,
1577 "Flags:%x, Packets_flooded:%x, Status: %s ",
1578 rulla->flags, rulla->packets_flooded,
1579 get_status_string(rulla->status));
d0732f64 1580 printk("%s\n", buf);
1fa9961d 1581 }
1fa9961d 1582 }
d0732f64
CW
1583
1584 if (!hlist_empty(&priv->lec_no_forward))
1fa9961d 1585 printk("No forward\n");
d0732f64 1586 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1fa9961d
CW
1587 offset = 0;
1588 offset += sprintf(buf + offset, "Mac:");
1589 for (j = 0; j < ETH_ALEN; j++) {
1590 offset += sprintf(buf + offset, "%2.2x ",
1591 rulla->mac_addr[j] & 0xff);
1592 }
1593 offset += sprintf(buf + offset, "Atm:");
1594 for (j = 0; j < ATM_ESA_LEN; j++) {
1595 offset += sprintf(buf + offset, "%2.2x ",
1596 rulla->atm_addr[j] & 0xff);
1597 }
1598 offset += sprintf(buf + offset,
1599 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1600 rulla->vcc ? rulla->vcc->vpi : 0,
1601 rulla->vcc ? rulla->vcc->vci : 0,
1602 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1603 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1604 rulla->last_used,
1605 rulla->timestamp, rulla->no_tries);
1606 offset += sprintf(buf + offset,
1607 "Flags:%x, Packets_flooded:%x, Status: %s ",
1608 rulla->flags, rulla->packets_flooded,
1609 get_status_string(rulla->status));
d0732f64 1610 printk("%s\n", buf);
1fa9961d 1611 }
d0732f64
CW
1612
1613 if (!hlist_empty(&priv->lec_arp_empty_ones))
1fa9961d 1614 printk("Empty ones\n");
d0732f64 1615 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1fa9961d
CW
1616 offset = 0;
1617 offset += sprintf(buf + offset, "Mac:");
1618 for (j = 0; j < ETH_ALEN; j++) {
1619 offset += sprintf(buf + offset, "%2.2x ",
1620 rulla->mac_addr[j] & 0xff);
1621 }
1622 offset += sprintf(buf + offset, "Atm:");
1623 for (j = 0; j < ATM_ESA_LEN; j++) {
1624 offset += sprintf(buf + offset, "%2.2x ",
1625 rulla->atm_addr[j] & 0xff);
1626 }
1627 offset += sprintf(buf + offset,
1628 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1629 rulla->vcc ? rulla->vcc->vpi : 0,
1630 rulla->vcc ? rulla->vcc->vci : 0,
1631 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1632 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1633 rulla->last_used,
1634 rulla->timestamp, rulla->no_tries);
1635 offset += sprintf(buf + offset,
1636 "Flags:%x, Packets_flooded:%x, Status: %s ",
1637 rulla->flags, rulla->packets_flooded,
1638 get_status_string(rulla->status));
1fa9961d
CW
1639 printk("%s", buf);
1640 }
1641
d0732f64 1642 if (!hlist_empty(&priv->mcast_fwds))
1fa9961d 1643 printk("Multicast Forward VCCs\n");
d0732f64 1644 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1fa9961d
CW
1645 offset = 0;
1646 offset += sprintf(buf + offset, "Mac:");
1647 for (j = 0; j < ETH_ALEN; j++) {
1648 offset += sprintf(buf + offset, "%2.2x ",
1649 rulla->mac_addr[j] & 0xff);
1650 }
1651 offset += sprintf(buf + offset, "Atm:");
1652 for (j = 0; j < ATM_ESA_LEN; j++) {
1653 offset += sprintf(buf + offset, "%2.2x ",
1654 rulla->atm_addr[j] & 0xff);
1655 }
1656 offset += sprintf(buf + offset,
1657 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1658 rulla->vcc ? rulla->vcc->vpi : 0,
1659 rulla->vcc ? rulla->vcc->vci : 0,
1660 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1661 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1662 rulla->last_used,
1663 rulla->timestamp, rulla->no_tries);
1664 offset += sprintf(buf + offset,
1665 "Flags:%x, Packets_flooded:%x, Status: %s ",
1666 rulla->flags, rulla->packets_flooded,
1667 get_status_string(rulla->status));
d0732f64 1668 printk("%s\n", buf);
1fa9961d 1669 }
1da177e4 1670
1da177e4 1671}
d0732f64
CW
1672#else
1673#define dump_arp_table(priv) do { } while (0)
1674#endif
1da177e4
LT
1675
1676/*
1677 * Destruction of arp-cache
1678 */
1fa9961d 1679static void lec_arp_destroy(struct lec_priv *priv)
1da177e4
LT
1680{
1681 unsigned long flags;
d0732f64
CW
1682 struct hlist_node *node, *next;
1683 struct lec_arp_table *entry;
1fa9961d
CW
1684 int i;
1685
987e46bd 1686 cancel_rearming_delayed_work(&priv->lec_arp_work);
1da177e4 1687
1fa9961d
CW
1688 /*
1689 * Remove all entries
1690 */
1da177e4
LT
1691
1692 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 1693 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1694 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d 1695 lec_arp_remove(priv, entry);
33a9c2d4 1696 lec_arp_put(entry);
1fa9961d 1697 }
d0732f64 1698 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1fa9961d 1699 }
d0732f64
CW
1700
1701 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1fa9961d
CW
1702 del_timer_sync(&entry->timer);
1703 lec_arp_clear_vccs(entry);
d0732f64 1704 hlist_del(&entry->next);
33a9c2d4 1705 lec_arp_put(entry);
1fa9961d 1706 }
d0732f64
CW
1707 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1708
1709 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1fa9961d
CW
1710 del_timer_sync(&entry->timer);
1711 lec_arp_clear_vccs(entry);
d0732f64 1712 hlist_del(&entry->next);
33a9c2d4 1713 lec_arp_put(entry);
1fa9961d 1714 }
d0732f64
CW
1715 INIT_HLIST_HEAD(&priv->lec_no_forward);
1716
1717 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1fa9961d
CW
1718 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1719 lec_arp_clear_vccs(entry);
d0732f64 1720 hlist_del(&entry->next);
33a9c2d4 1721 lec_arp_put(entry);
1fa9961d 1722 }
d0732f64 1723 INIT_HLIST_HEAD(&priv->mcast_fwds);
1fa9961d 1724 priv->mcast_vcc = NULL;
1da177e4
LT
1725 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1726}
1727
f7d57453 1728/*
1da177e4
LT
1729 * Find entry by mac_address
1730 */
1fa9961d 1731static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
61c33e01 1732 const unsigned char *mac_addr)
1da177e4 1733{
d0732f64
CW
1734 struct hlist_node *node;
1735 struct hlist_head *head;
1736 struct lec_arp_table *entry;
1fa9961d 1737
52240062 1738 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1fa9961d
CW
1739 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1740 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1fa9961d 1741
d0732f64
CW
1742 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1743 hlist_for_each_entry(entry, node, head, next) {
1744 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1745 return entry;
1fa9961d 1746 }
1fa9961d
CW
1747 }
1748 return NULL;
1da177e4
LT
1749}
1750
1fa9961d 1751static struct lec_arp_table *make_entry(struct lec_priv *priv,
61c33e01 1752 const unsigned char *mac_addr)
1da177e4 1753{
1fa9961d
CW
1754 struct lec_arp_table *to_return;
1755
1756 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1757 if (!to_return) {
1758 printk("LEC: Arp entry kmalloc failed\n");
1759 return NULL;
1760 }
1761 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
d0732f64 1762 INIT_HLIST_NODE(&to_return->next);
b24b8a24
PE
1763 setup_timer(&to_return->timer, lec_arp_expire_arp,
1764 (unsigned long)to_return);
1fa9961d
CW
1765 to_return->last_used = jiffies;
1766 to_return->priv = priv;
1767 skb_queue_head_init(&to_return->tx_wait);
33a9c2d4 1768 atomic_set(&to_return->usage, 1);
1fa9961d 1769 return to_return;
1da177e4
LT
1770}
1771
1fa9961d
CW
1772/* Arp sent timer expired */
1773static void lec_arp_expire_arp(unsigned long data)
1da177e4 1774{
1fa9961d
CW
1775 struct lec_arp_table *entry;
1776
1777 entry = (struct lec_arp_table *)data;
1778
52240062 1779 pr_debug("lec_arp_expire_arp\n");
1fa9961d
CW
1780 if (entry->status == ESI_ARP_PENDING) {
1781 if (entry->no_tries <= entry->priv->max_retry_count) {
1782 if (entry->is_rdesc)
1783 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1784 entry->mac_addr, NULL, NULL);
1785 else
1786 send_to_lecd(entry->priv, l_arp_xmt,
1787 entry->mac_addr, NULL, NULL);
1788 entry->no_tries++;
1789 }
1790 mod_timer(&entry->timer, jiffies + (1 * HZ));
1791 }
1da177e4
LT
1792}
1793
1fa9961d
CW
1794/* Unknown/unused vcc expire, remove associated entry */
1795static void lec_arp_expire_vcc(unsigned long data)
1da177e4
LT
1796{
1797 unsigned long flags;
1fa9961d
CW
1798 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1799 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1da177e4 1800
1fa9961d 1801 del_timer(&to_remove->timer);
1da177e4 1802
52240062 1803 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1fa9961d
CW
1804 to_remove, priv,
1805 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1806 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1da177e4
LT
1807
1808 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64 1809 hlist_del(&to_remove->next);
1da177e4
LT
1810 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1811
1fa9961d 1812 lec_arp_clear_vccs(to_remove);
33a9c2d4 1813 lec_arp_put(to_remove);
1da177e4
LT
1814}
1815
1816/*
1817 * Expire entries.
1818 * 1. Re-set timer
1819 * 2. For each entry, delete entries that have aged past the age limit.
1820 * 3. For each entry, depending on the status of the entry, perform
1821 * the following maintenance.
1822 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1823 * tick_count is above the max_unknown_frame_time, clear
1824 * the tick_count to zero and clear the packets_flooded counter
1825 * to zero. This supports the packet rate limit per address
1826 * while flooding unknowns.
1827 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1828 * than or equal to the path_switching_delay, change the status
1829 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1830 * regardless of the progress of the flush protocol.
1831 */
c4028958 1832static void lec_arp_check_expire(struct work_struct *work)
1da177e4
LT
1833{
1834 unsigned long flags;
c4028958
DH
1835 struct lec_priv *priv =
1836 container_of(work, struct lec_priv, lec_arp_work.work);
d0732f64
CW
1837 struct hlist_node *node, *next;
1838 struct lec_arp_table *entry;
1fa9961d
CW
1839 unsigned long now;
1840 unsigned long time_to_check;
1841 int i;
1842
52240062 1843 pr_debug("lec_arp_check_expire %p\n", priv);
1da177e4 1844 now = jiffies;
6656e3c4 1845restart:
1da177e4 1846 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 1847 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1848 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d 1849 if ((entry->flags) & LEC_REMOTE_FLAG &&
1da177e4
LT
1850 priv->topology_change)
1851 time_to_check = priv->forward_delay_time;
1852 else
1853 time_to_check = priv->aging_time;
1854
52240062 1855 pr_debug("About to expire: %lx - %lx > %lx\n",
1fa9961d
CW
1856 now, entry->last_used, time_to_check);
1857 if (time_after(now, entry->last_used + time_to_check)
1858 && !(entry->flags & LEC_PERMANENT_FLAG)
1859 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1da177e4 1860 /* Remove entry */
52240062 1861 pr_debug("LEC:Entry timed out\n");
1da177e4 1862 lec_arp_remove(priv, entry);
33a9c2d4 1863 lec_arp_put(entry);
1da177e4
LT
1864 } else {
1865 /* Something else */
1866 if ((entry->status == ESI_VC_PENDING ||
1fa9961d 1867 entry->status == ESI_ARP_PENDING)
1da177e4 1868 && time_after_eq(now,
1fa9961d
CW
1869 entry->timestamp +
1870 priv->
1871 max_unknown_frame_time)) {
1da177e4
LT
1872 entry->timestamp = jiffies;
1873 entry->packets_flooded = 0;
1874 if (entry->status == ESI_VC_PENDING)
1fa9961d
CW
1875 send_to_lecd(priv, l_svc_setup,
1876 entry->mac_addr,
1877 entry->atm_addr,
1878 NULL);
1da177e4 1879 }
1fa9961d
CW
1880 if (entry->status == ESI_FLUSH_PENDING
1881 &&
1882 time_after_eq(now, entry->timestamp +
1883 priv->path_switching_delay)) {
1da177e4 1884 struct sk_buff *skb;
6656e3c4 1885 struct atm_vcc *vcc = entry->vcc;
1da177e4 1886
6656e3c4
CW
1887 lec_arp_hold(entry);
1888 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1889 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1890 lec_send(vcc, skb, entry->priv);
1da177e4 1891 entry->last_used = jiffies;
1fa9961d 1892 entry->status = ESI_FORWARD_DIRECT;
6656e3c4
CW
1893 lec_arp_put(entry);
1894 goto restart;
1da177e4 1895 }
1da177e4
LT
1896 }
1897 }
1898 }
1899 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1900
987e46bd 1901 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1da177e4 1902}
1fa9961d 1903
1da177e4
LT
1904/*
1905 * Try to find vcc where mac_address is attached.
f7d57453 1906 *
1da177e4 1907 */
1fa9961d 1908static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
61c33e01 1909 const unsigned char *mac_to_find, int is_rdesc,
1fa9961d 1910 struct lec_arp_table **ret_entry)
1da177e4
LT
1911{
1912 unsigned long flags;
1fa9961d 1913 struct lec_arp_table *entry;
1da177e4
LT
1914 struct atm_vcc *found;
1915
1fa9961d
CW
1916 if (mac_to_find[0] & 0x01) {
1917 switch (priv->lane_version) {
1918 case 1:
1919 return priv->mcast_vcc;
1fa9961d
CW
1920 case 2: /* LANE2 wants arp for multicast addresses */
1921 if (!compare_ether_addr(mac_to_find, bus_mac))
1922 return priv->mcast_vcc;
1923 break;
1924 default:
1925 break;
1926 }
1927 }
1da177e4
LT
1928
1929 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
1930 entry = lec_arp_find(priv, mac_to_find);
1931
1932 if (entry) {
1933 if (entry->status == ESI_FORWARD_DIRECT) {
1934 /* Connection Ok */
1935 entry->last_used = jiffies;
6656e3c4 1936 lec_arp_hold(entry);
1fa9961d
CW
1937 *ret_entry = entry;
1938 found = entry->vcc;
1da177e4 1939 goto out;
1fa9961d
CW
1940 }
1941 /*
1942 * If the LE_ARP cache entry is still pending, reset count to 0
75b895c1
ST
1943 * so another LE_ARP request can be made for this frame.
1944 */
1945 if (entry->status == ESI_ARP_PENDING) {
1946 entry->no_tries = 0;
1947 }
1fa9961d
CW
1948 /*
1949 * Data direct VC not yet set up, check to see if the unknown
1950 * frame count is greater than the limit. If the limit has
1951 * not been reached, allow the caller to send packet to
1952 * BUS.
1953 */
1954 if (entry->status != ESI_FLUSH_PENDING &&
1955 entry->packets_flooded <
1956 priv->maximum_unknown_frame_count) {
1957 entry->packets_flooded++;
52240062 1958 pr_debug("LEC_ARP: Flooding..\n");
1fa9961d 1959 found = priv->mcast_vcc;
1da177e4 1960 goto out;
1fa9961d
CW
1961 }
1962 /*
1963 * We got here because entry->status == ESI_FLUSH_PENDING
1da177e4
LT
1964 * or BUS flood limit was reached for an entry which is
1965 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1966 */
6656e3c4 1967 lec_arp_hold(entry);
1fa9961d 1968 *ret_entry = entry;
52240062 1969 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
1fa9961d
CW
1970 entry->vcc);
1971 found = NULL;
1972 } else {
1973 /* No matching entry was found */
1974 entry = make_entry(priv, mac_to_find);
52240062 1975 pr_debug("LEC_ARP: Making entry\n");
1fa9961d
CW
1976 if (!entry) {
1977 found = priv->mcast_vcc;
1da177e4 1978 goto out;
1fa9961d
CW
1979 }
1980 lec_arp_add(priv, entry);
1981 /* We want arp-request(s) to be sent */
1982 entry->packets_flooded = 1;
1983 entry->status = ESI_ARP_PENDING;
1984 entry->no_tries = 1;
1985 entry->last_used = entry->timestamp = jiffies;
1986 entry->is_rdesc = is_rdesc;
1987 if (entry->is_rdesc)
1988 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1989 NULL);
1990 else
1991 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1992 entry->timer.expires = jiffies + (1 * HZ);
1993 entry->timer.function = lec_arp_expire_arp;
1994 add_timer(&entry->timer);
1995 found = priv->mcast_vcc;
1996 }
1da177e4
LT
1997
1998out:
1999 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2000 return found;
2001}
2002
2003static int
61c33e01 2004lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1fa9961d 2005 unsigned long permanent)
1da177e4
LT
2006{
2007 unsigned long flags;
d0732f64
CW
2008 struct hlist_node *node, *next;
2009 struct lec_arp_table *entry;
1fa9961d 2010 int i;
1da177e4 2011
52240062 2012 pr_debug("lec_addr_delete\n");
1da177e4 2013 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 2014 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2015 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2016 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2017 && (permanent ||
2018 !(entry->flags & LEC_PERMANENT_FLAG))) {
1da177e4 2019 lec_arp_remove(priv, entry);
33a9c2d4 2020 lec_arp_put(entry);
1fa9961d 2021 }
1da177e4 2022 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d
CW
2023 return 0;
2024 }
2025 }
1da177e4 2026 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2027 return -1;
1da177e4
LT
2028}
2029
2030/*
f7d57453 2031 * Notifies: Response to arp_request (atm_addr != NULL)
1da177e4
LT
2032 */
2033static void
61c33e01
MBJ
2034lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2035 const unsigned char *atm_addr, unsigned long remoteflag,
1fa9961d 2036 unsigned int targetless_le_arp)
1da177e4
LT
2037{
2038 unsigned long flags;
d0732f64 2039 struct hlist_node *node, *next;
1fa9961d
CW
2040 struct lec_arp_table *entry, *tmp;
2041 int i;
1da177e4 2042
52240062
SH
2043 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2044 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1fa9961d
CW
2045 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2046 mac_addr[4], mac_addr[5]);
1da177e4
LT
2047
2048 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2049 entry = lec_arp_find(priv, mac_addr);
2050 if (entry == NULL && targetless_le_arp)
2051 goto out; /*
2052 * LANE2: ignore targetless LE_ARPs for which
2053 * we have no entry in the cache. 7.1.30
2054 */
d0732f64
CW
2055 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2056 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2057 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2058 hlist_del(&entry->next);
1fa9961d 2059 del_timer(&entry->timer);
d0732f64
CW
2060 tmp = lec_arp_find(priv, mac_addr);
2061 if (tmp) {
2062 del_timer(&tmp->timer);
2063 tmp->status = ESI_FORWARD_DIRECT;
2064 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2065 tmp->vcc = entry->vcc;
2066 tmp->old_push = entry->old_push;
2067 tmp->last_used = jiffies;
2068 del_timer(&entry->timer);
33a9c2d4 2069 lec_arp_put(entry);
d0732f64
CW
2070 entry = tmp;
2071 } else {
2072 entry->status = ESI_FORWARD_DIRECT;
2073 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2074 entry->last_used = jiffies;
2075 lec_arp_add(priv, entry);
2076 }
2077 if (remoteflag)
2078 entry->flags |= LEC_REMOTE_FLAG;
2079 else
2080 entry->flags &= ~LEC_REMOTE_FLAG;
52240062 2081 pr_debug("After update\n");
d0732f64
CW
2082 dump_arp_table(priv);
2083 goto out;
1fa9961d 2084 }
1fa9961d
CW
2085 }
2086 }
d0732f64 2087
1fa9961d
CW
2088 entry = lec_arp_find(priv, mac_addr);
2089 if (!entry) {
2090 entry = make_entry(priv, mac_addr);
2091 if (!entry)
2092 goto out;
2093 entry->status = ESI_UNKNOWN;
2094 lec_arp_add(priv, entry);
2095 /* Temporary, changes before end of function */
2096 }
2097 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2098 del_timer(&entry->timer);
2099 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2100 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2101 if (entry != tmp &&
2102 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2103 /* Vcc to this host exists */
2104 if (tmp->status > ESI_VC_PENDING) {
2105 /*
2106 * ESI_FLUSH_PENDING,
2107 * ESI_FORWARD_DIRECT
2108 */
2109 entry->vcc = tmp->vcc;
2110 entry->old_push = tmp->old_push;
2111 }
2112 entry->status = tmp->status;
2113 break;
2114 }
2115 }
2116 }
2117 if (remoteflag)
2118 entry->flags |= LEC_REMOTE_FLAG;
2119 else
2120 entry->flags &= ~LEC_REMOTE_FLAG;
2121 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2122 entry->status = ESI_VC_PENDING;
d0732f64 2123 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
1fa9961d 2124 }
52240062 2125 pr_debug("After update2\n");
1fa9961d 2126 dump_arp_table(priv);
1da177e4
LT
2127out:
2128 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2129}
2130
2131/*
f7d57453 2132 * Notifies: Vcc setup ready
1da177e4
LT
2133 */
2134static void
61c33e01 2135lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
1fa9961d
CW
2136 struct atm_vcc *vcc,
2137 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
1da177e4
LT
2138{
2139 unsigned long flags;
d0732f64 2140 struct hlist_node *node;
1fa9961d
CW
2141 struct lec_arp_table *entry;
2142 int i, found_entry = 0;
1da177e4
LT
2143
2144 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2145 if (ioc_data->receive == 2) {
2146 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
1da177e4 2147
52240062 2148 pr_debug("LEC_ARP: Attaching mcast forward\n");
1da177e4 2149#if 0
1fa9961d
CW
2150 entry = lec_arp_find(priv, bus_mac);
2151 if (!entry) {
2152 printk("LEC_ARP: Multicast entry not found!\n");
1da177e4 2153 goto out;
1fa9961d
CW
2154 }
2155 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2156 entry->recv_vcc = vcc;
2157 entry->old_recv_push = old_push;
1da177e4 2158#endif
1fa9961d
CW
2159 entry = make_entry(priv, bus_mac);
2160 if (entry == NULL)
1da177e4 2161 goto out;
1fa9961d
CW
2162 del_timer(&entry->timer);
2163 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2164 entry->recv_vcc = vcc;
2165 entry->old_recv_push = old_push;
d0732f64 2166 hlist_add_head(&entry->next, &priv->mcast_fwds);
1fa9961d
CW
2167 goto out;
2168 } else if (ioc_data->receive == 1) {
2169 /*
2170 * Vcc which we don't want to make default vcc,
2171 * attach it anyway.
2172 */
52240062 2173 pr_debug
1fa9961d
CW
2174 ("LEC_ARP:Attaching data direct, not default: "
2175 "%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",
2176 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2177 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2178 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2179 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2180 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2181 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2182 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2183 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2184 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2185 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2186 entry = make_entry(priv, bus_mac);
2187 if (entry == NULL)
1da177e4 2188 goto out;
1fa9961d
CW
2189 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2190 memset(entry->mac_addr, 0, ETH_ALEN);
2191 entry->recv_vcc = vcc;
2192 entry->old_recv_push = old_push;
2193 entry->status = ESI_UNKNOWN;
2194 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2195 entry->timer.function = lec_arp_expire_vcc;
d0732f64 2196 hlist_add_head(&entry->next, &priv->lec_no_forward);
1fa9961d 2197 add_timer(&entry->timer);
1da177e4
LT
2198 dump_arp_table(priv);
2199 goto out;
1fa9961d 2200 }
52240062 2201 pr_debug
1fa9961d
CW
2202 ("LEC_ARP:Attaching data direct, default: "
2203 "%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",
2204 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2205 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2206 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2207 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2208 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2209 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2210 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2211 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2212 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2213 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2214 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2215 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2216 if (memcmp
2217 (ioc_data->atm_addr, entry->atm_addr,
2218 ATM_ESA_LEN) == 0) {
52240062
SH
2219 pr_debug("LEC_ARP: Attaching data direct\n");
2220 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
1fa9961d
CW
2221 entry->vcc ? entry->vcc->vci : 0,
2222 entry->recv_vcc ? entry->recv_vcc->
2223 vci : 0);
2224 found_entry = 1;
2225 del_timer(&entry->timer);
2226 entry->vcc = vcc;
2227 entry->old_push = old_push;
2228 if (entry->status == ESI_VC_PENDING) {
2229 if (priv->maximum_unknown_frame_count
2230 == 0)
2231 entry->status =
2232 ESI_FORWARD_DIRECT;
2233 else {
2234 entry->timestamp = jiffies;
2235 entry->status =
2236 ESI_FLUSH_PENDING;
1da177e4 2237#if 0
1fa9961d
CW
2238 send_to_lecd(priv, l_flush_xmt,
2239 NULL,
2240 entry->atm_addr,
2241 NULL);
1da177e4 2242#endif
1fa9961d
CW
2243 }
2244 } else {
2245 /*
2246 * They were forming a connection
2247 * to us, and we to them. Our
2248 * ATM address is numerically lower
2249 * than theirs, so we make connection
2250 * we formed into default VCC (8.1.11).
2251 * Connection they made gets torn
2252 * down. This might confuse some
2253 * clients. Can be changed if
2254 * someone reports trouble...
2255 */
2256 ;
2257 }
2258 }
2259 }
2260 }
2261 if (found_entry) {
52240062 2262 pr_debug("After vcc was added\n");
1fa9961d 2263 dump_arp_table(priv);
1da177e4 2264 goto out;
1fa9961d
CW
2265 }
2266 /*
2267 * Not found, snatch address from first data packet that arrives
2268 * from this vcc
2269 */
2270 entry = make_entry(priv, bus_mac);
2271 if (!entry)
1da177e4 2272 goto out;
1fa9961d
CW
2273 entry->vcc = vcc;
2274 entry->old_push = old_push;
2275 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2276 memset(entry->mac_addr, 0, ETH_ALEN);
2277 entry->status = ESI_UNKNOWN;
d0732f64 2278 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
1fa9961d
CW
2279 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2280 entry->timer.function = lec_arp_expire_vcc;
2281 add_timer(&entry->timer);
52240062 2282 pr_debug("After vcc was added\n");
1da177e4
LT
2283 dump_arp_table(priv);
2284out:
2285 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2286}
2287
1fa9961d 2288static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
1da177e4
LT
2289{
2290 unsigned long flags;
d0732f64 2291 struct hlist_node *node;
1fa9961d
CW
2292 struct lec_arp_table *entry;
2293 int i;
1da177e4 2294
52240062 2295 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
6656e3c4 2296restart:
1fa9961d
CW
2297 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2298 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2299 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2300 if (entry->flush_tran_id == tran_id
2301 && entry->status == ESI_FLUSH_PENDING) {
2302 struct sk_buff *skb;
6656e3c4 2303 struct atm_vcc *vcc = entry->vcc;
1fa9961d 2304
6656e3c4
CW
2305 lec_arp_hold(entry);
2306 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2307 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2308 lec_send(vcc, skb, entry->priv);
2309 entry->last_used = jiffies;
1fa9961d 2310 entry->status = ESI_FORWARD_DIRECT;
6656e3c4 2311 lec_arp_put(entry);
52240062 2312 pr_debug("LEC_ARP: Flushed\n");
6656e3c4 2313 goto restart;
1fa9961d
CW
2314 }
2315 }
2316 }
1da177e4 2317 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2318 dump_arp_table(priv);
1da177e4
LT
2319}
2320
2321static void
2322lec_set_flush_tran_id(struct lec_priv *priv,
61c33e01 2323 const unsigned char *atm_addr, unsigned long tran_id)
1da177e4
LT
2324{
2325 unsigned long flags;
d0732f64 2326 struct hlist_node *node;
1fa9961d
CW
2327 struct lec_arp_table *entry;
2328 int i;
1da177e4
LT
2329
2330 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 2331 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
d0732f64 2332 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2333 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2334 entry->flush_tran_id = tran_id;
52240062 2335 pr_debug("Set flush transaction id to %lx for %p\n",
f7d57453 2336 tran_id, entry);
1fa9961d 2337 }
d0732f64 2338 }
1da177e4
LT
2339 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2340}
2341
1fa9961d 2342static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
1da177e4
LT
2343{
2344 unsigned long flags;
1fa9961d
CW
2345 unsigned char mac_addr[] = {
2346 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2347 };
2348 struct lec_arp_table *to_add;
1da177e4
LT
2349 struct lec_vcc_priv *vpriv;
2350 int err = 0;
1fa9961d 2351
1da177e4
LT
2352 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2353 return -ENOMEM;
2354 vpriv->xoff = 0;
2355 vpriv->old_pop = vcc->pop;
2356 vcc->user_back = vpriv;
1fa9961d 2357 vcc->pop = lec_pop;
1da177e4 2358 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2359 to_add = make_entry(priv, mac_addr);
2360 if (!to_add) {
1da177e4
LT
2361 vcc->pop = vpriv->old_pop;
2362 kfree(vpriv);
1fa9961d 2363 err = -ENOMEM;
1da177e4 2364 goto out;
1fa9961d
CW
2365 }
2366 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2367 to_add->status = ESI_FORWARD_DIRECT;
2368 to_add->flags |= LEC_PERMANENT_FLAG;
2369 to_add->vcc = vcc;
2370 to_add->old_push = vcc->push;
2371 vcc->push = lec_push;
2372 priv->mcast_vcc = vcc;
2373 lec_arp_add(priv, to_add);
1da177e4
LT
2374out:
2375 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2376 return err;
1da177e4
LT
2377}
2378
1fa9961d 2379static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
1da177e4
LT
2380{
2381 unsigned long flags;
d0732f64
CW
2382 struct hlist_node *node, *next;
2383 struct lec_arp_table *entry;
1fa9961d 2384 int i;
1da177e4 2385
52240062 2386 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
1fa9961d 2387 dump_arp_table(priv);
d0732f64 2388
1da177e4 2389 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64 2390
1fa9961d 2391 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2392 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2393 if (vcc == entry->vcc) {
2394 lec_arp_remove(priv, entry);
33a9c2d4 2395 lec_arp_put(entry);
1fa9961d
CW
2396 if (priv->mcast_vcc == vcc) {
2397 priv->mcast_vcc = NULL;
2398 }
2399 }
2400 }
2401 }
2402
d0732f64
CW
2403 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2404 if (entry->vcc == vcc) {
1fa9961d
CW
2405 lec_arp_clear_vccs(entry);
2406 del_timer(&entry->timer);
d0732f64 2407 hlist_del(&entry->next);
33a9c2d4 2408 lec_arp_put(entry);
1fa9961d 2409 }
1fa9961d
CW
2410 }
2411
d0732f64 2412 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1fa9961d
CW
2413 if (entry->recv_vcc == vcc) {
2414 lec_arp_clear_vccs(entry);
2415 del_timer(&entry->timer);
d0732f64 2416 hlist_del(&entry->next);
33a9c2d4 2417 lec_arp_put(entry);
1fa9961d 2418 }
1fa9961d
CW
2419 }
2420
d0732f64 2421 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1fa9961d
CW
2422 if (entry->recv_vcc == vcc) {
2423 lec_arp_clear_vccs(entry);
2424 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
d0732f64 2425 hlist_del(&entry->next);
33a9c2d4 2426 lec_arp_put(entry);
1fa9961d 2427 }
1fa9961d 2428 }
1da177e4
LT
2429
2430 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2431 dump_arp_table(priv);
2432}
2433
2434static void
2435lec_arp_check_empties(struct lec_priv *priv,
1fa9961d 2436 struct atm_vcc *vcc, struct sk_buff *skb)
1da177e4 2437{
1fa9961d 2438 unsigned long flags;
d0732f64
CW
2439 struct hlist_node *node, *next;
2440 struct lec_arp_table *entry, *tmp;
1fa9961d
CW
2441 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2442 unsigned char *src;
1da177e4 2443#ifdef CONFIG_TR
1fa9961d 2444 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
1da177e4 2445
1fa9961d
CW
2446 if (priv->is_trdev)
2447 src = tr_hdr->h_source;
2448 else
1da177e4 2449#endif
1fa9961d 2450 src = hdr->h_source;
1da177e4
LT
2451
2452 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64
CW
2453 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2454 if (vcc == entry->vcc) {
2455 del_timer(&entry->timer);
2456 memcpy(entry->mac_addr, src, ETH_ALEN);
2457 entry->status = ESI_FORWARD_DIRECT;
2458 entry->last_used = jiffies;
2459 /* We might have got an entry */
2460 if ((tmp = lec_arp_find(priv, src))) {
2461 lec_arp_remove(priv, tmp);
33a9c2d4 2462 lec_arp_put(tmp);
d0732f64
CW
2463 }
2464 hlist_del(&entry->next);
2465 lec_arp_add(priv, entry);
2466 goto out;
1fa9961d 2467 }
1fa9961d 2468 }
52240062 2469 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
1da177e4
LT
2470out:
2471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2472}
1fa9961d 2473
1da177e4 2474MODULE_LICENSE("GPL");