]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/atm/lec.c
net: convert print_mac to %pM
[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
155 priv = (struct lec_priv *)dev->priv;
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{
d44f7746
CW
221 struct lec_priv *priv = (struct lec_priv *)dev->priv;
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
CW
254 struct sk_buff *skb2;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv;
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{
d44f7746 436 return &((struct lec_priv *)dev->priv)->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
CW
442 struct net_device *dev = (struct net_device *)vcc->proto_data;
443 struct lec_priv *priv = (struct lec_priv *)dev->priv;
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;
583 struct lec_priv *priv = (struct lec_priv *)dev->priv;
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
CW
713 struct net_device *dev = (struct net_device *)vcc->proto_data;
714 struct lec_priv *priv = (struct lec_priv *)dev->priv;
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;
d44f7746
CW
861 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
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];
873 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
1da177e4
LT
874}
875
876/* Initialize device. */
d44f7746
CW
877static int lecd_attach(struct atm_vcc *vcc, int arg)
878{
879 int i;
880 struct lec_priv *priv;
881
882 if (arg < 0)
883 i = 0;
884 else
885 i = arg;
1da177e4 886#ifdef CONFIG_TR
d44f7746
CW
887 if (arg >= MAX_LEC_ITF)
888 return -EINVAL;
889#else /* Reserve the top NUM_TR_DEVS for TR */
890 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
891 return -EINVAL;
1da177e4 892#endif
d44f7746
CW
893 if (!dev_lec[i]) {
894 int is_trdev, size;
1da177e4 895
d44f7746
CW
896 is_trdev = 0;
897 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
898 is_trdev = 1;
1da177e4 899
d44f7746 900 size = sizeof(struct lec_priv);
1da177e4 901#ifdef CONFIG_TR
d44f7746
CW
902 if (is_trdev)
903 dev_lec[i] = alloc_trdev(size);
904 else
1da177e4 905#endif
d44f7746
CW
906 dev_lec[i] = alloc_etherdev(size);
907 if (!dev_lec[i])
908 return -ENOMEM;
909 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
910 if (register_netdev(dev_lec[i])) {
911 free_netdev(dev_lec[i]);
912 return -EINVAL;
913 }
914
915 priv = dev_lec[i]->priv;
916 priv->is_trdev = is_trdev;
917 lec_init(dev_lec[i]);
918 } else {
919 priv = dev_lec[i]->priv;
920 if (priv->lecd)
921 return -EADDRINUSE;
922 }
923 lec_arp_init(priv);
924 priv->itfnum = i; /* LANE2 addition */
925 priv->lecd = vcc;
926 vcc->dev = &lecatm_dev;
927 vcc_insert_socket(sk_atm(vcc));
928
929 vcc->proto_data = dev_lec[i];
930 set_bit(ATM_VF_META, &vcc->flags);
931 set_bit(ATM_VF_READY, &vcc->flags);
932
933 /* Set default values to these variables */
934 priv->maximum_unknown_frame_count = 1;
935 priv->max_unknown_frame_time = (1 * HZ);
936 priv->vcc_timeout_period = (1200 * HZ);
937 priv->max_retry_count = 1;
938 priv->aging_time = (300 * HZ);
939 priv->forward_delay_time = (15 * HZ);
940 priv->topology_change = 0;
941 priv->arp_response_time = (1 * HZ);
942 priv->flush_timeout = (4 * HZ);
943 priv->path_switching_delay = (6 * HZ);
944
945 if (dev_lec[i]->flags & IFF_UP) {
946 netif_start_queue(dev_lec[i]);
947 }
948 __module_get(THIS_MODULE);
949 return i;
1da177e4
LT
950}
951
952#ifdef CONFIG_PROC_FS
d44f7746 953static char *lec_arp_get_status_string(unsigned char status)
1da177e4
LT
954{
955 static char *lec_arp_status_string[] = {
956 "ESI_UNKNOWN ",
957 "ESI_ARP_PENDING ",
958 "ESI_VC_PENDING ",
959 "<Undefined> ",
960 "ESI_FLUSH_PENDING ",
961 "ESI_FORWARD_DIRECT"
962 };
963
964 if (status > ESI_FORWARD_DIRECT)
965 status = 3; /* ESI_UNDEFINED */
966 return lec_arp_status_string[status];
967}
968
969static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
970{
971 int i;
972
973 for (i = 0; i < ETH_ALEN; i++)
974 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
975 seq_printf(seq, " ");
976 for (i = 0; i < ATM_ESA_LEN; i++)
977 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
978 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
979 entry->flags & 0xffff);
980 if (entry->vcc)
981 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
982 else
d44f7746 983 seq_printf(seq, " ");
1da177e4
LT
984 if (entry->recv_vcc) {
985 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
986 entry->recv_vcc->vci);
d44f7746
CW
987 }
988 seq_putc(seq, '\n');
1da177e4
LT
989}
990
1da177e4
LT
991struct lec_state {
992 unsigned long flags;
993 struct lec_priv *locked;
d0732f64 994 struct hlist_node *node;
1da177e4
LT
995 struct net_device *dev;
996 int itf;
997 int arp_table;
998 int misc_table;
999};
1000
d0732f64 1001static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
1da177e4
LT
1002 loff_t *l)
1003{
d0732f64
CW
1004 struct hlist_node *e = state->node;
1005 struct lec_arp_table *tmp;
1da177e4
LT
1006
1007 if (!e)
d0732f64 1008 e = tbl->first;
2e1e9848 1009 if (e == SEQ_START_TOKEN) {
d0732f64 1010 e = tbl->first;
1da177e4
LT
1011 --*l;
1012 }
d0732f64
CW
1013
1014 hlist_for_each_entry_from(tmp, e, next) {
1da177e4
LT
1015 if (--*l < 0)
1016 break;
1017 }
d0732f64
CW
1018 state->node = e;
1019
1da177e4
LT
1020 return (*l < 0) ? state : NULL;
1021}
1022
1023static void *lec_arp_walk(struct lec_state *state, loff_t *l,
d44f7746 1024 struct lec_priv *priv)
1da177e4
LT
1025{
1026 void *v = NULL;
1027 int p;
1028
1029 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
d0732f64 1030 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
1da177e4
LT
1031 if (v)
1032 break;
1033 }
1034 state->arp_table = p;
1035 return v;
1036}
1037
1038static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1039 struct lec_priv *priv)
1040{
d0732f64
CW
1041 struct hlist_head *lec_misc_tables[] = {
1042 &priv->lec_arp_empty_ones,
1043 &priv->lec_no_forward,
1044 &priv->mcast_fwds
1da177e4
LT
1045 };
1046 void *v = NULL;
1047 int q;
1048
1049 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1050 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1051 if (v)
1052 break;
1053 }
1054 state->misc_table = q;
1055 return v;
1056}
1057
1058static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1059 struct lec_priv *priv)
1060{
1061 if (!state->locked) {
1062 state->locked = priv;
1063 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1064 }
d44f7746 1065 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1da177e4
LT
1066 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1067 state->locked = NULL;
1068 /* Partial state reset for the next time we get called */
1069 state->arp_table = state->misc_table = 0;
1070 }
1071 return state->locked;
1072}
1073
1074static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1075{
1076 struct net_device *dev;
1077 void *v;
1078
1079 dev = state->dev ? state->dev : dev_lec[state->itf];
1080 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1081 if (!v && dev) {
1082 dev_put(dev);
1083 /* Partial state reset for the next time we get called */
1084 dev = NULL;
1085 }
1086 state->dev = dev;
1087 return v;
1088}
1089
1090static void *lec_get_idx(struct lec_state *state, loff_t l)
1091{
1092 void *v = NULL;
1093
1094 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1095 v = lec_itf_walk(state, &l);
1096 if (v)
1097 break;
1098 }
d44f7746 1099 return v;
1da177e4
LT
1100}
1101
1102static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1103{
1104 struct lec_state *state = seq->private;
1105
1106 state->itf = 0;
1107 state->dev = NULL;
1108 state->locked = NULL;
1109 state->arp_table = 0;
1110 state->misc_table = 0;
2e1e9848 1111 state->node = SEQ_START_TOKEN;
1da177e4 1112
2e1e9848 1113 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
1da177e4
LT
1114}
1115
1116static void lec_seq_stop(struct seq_file *seq, void *v)
1117{
1118 struct lec_state *state = seq->private;
1119
1120 if (state->dev) {
1121 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1122 state->flags);
1123 dev_put(state->dev);
1124 }
1125}
1126
1127static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1128{
1129 struct lec_state *state = seq->private;
1130
1131 v = lec_get_idx(state, 1);
1132 *pos += !!PTR_ERR(v);
1133 return v;
1134}
1135
1136static int lec_seq_show(struct seq_file *seq, void *v)
1137{
d44f7746
CW
1138 static char lec_banner[] = "Itf MAC ATM destination"
1139 " Status Flags "
1140 "VPI/VCI Recv VPI/VCI\n";
1da177e4 1141
2e1e9848 1142 if (v == SEQ_START_TOKEN)
1da177e4
LT
1143 seq_puts(seq, lec_banner);
1144 else {
1145 struct lec_state *state = seq->private;
d44f7746 1146 struct net_device *dev = state->dev;
d0732f64 1147 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1da177e4
LT
1148
1149 seq_printf(seq, "%s ", dev->name);
d0732f64 1150 lec_info(seq, entry);
1da177e4
LT
1151 }
1152 return 0;
1153}
1154
56b3d975 1155static const struct seq_operations lec_seq_ops = {
d44f7746
CW
1156 .start = lec_seq_start,
1157 .next = lec_seq_next,
1158 .stop = lec_seq_stop,
1159 .show = lec_seq_show,
1da177e4
LT
1160};
1161
1162static int lec_seq_open(struct inode *inode, struct file *file)
1163{
9a8c09e7 1164 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
1da177e4
LT
1165}
1166
9a32144e 1167static const struct file_operations lec_seq_fops = {
d44f7746
CW
1168 .owner = THIS_MODULE,
1169 .open = lec_seq_open,
1170 .read = seq_read,
1171 .llseek = seq_lseek,
9a8c09e7 1172 .release = seq_release_private,
1da177e4
LT
1173};
1174#endif
1175
1176static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1177{
1178 struct atm_vcc *vcc = ATM_SD(sock);
1179 int err = 0;
d44f7746 1180
1da177e4 1181 switch (cmd) {
d44f7746
CW
1182 case ATMLEC_CTRL:
1183 case ATMLEC_MCAST:
1184 case ATMLEC_DATA:
1185 if (!capable(CAP_NET_ADMIN))
1186 return -EPERM;
1187 break;
1188 default:
1189 return -ENOIOCTLCMD;
1da177e4
LT
1190 }
1191
1192 switch (cmd) {
d44f7746
CW
1193 case ATMLEC_CTRL:
1194 err = lecd_attach(vcc, (int)arg);
1195 if (err >= 0)
1196 sock->state = SS_CONNECTED;
1197 break;
1198 case ATMLEC_MCAST:
1199 err = lec_mcast_attach(vcc, (int)arg);
1200 break;
1201 case ATMLEC_DATA:
1202 err = lec_vcc_attach(vcc, (void __user *)arg);
1203 break;
1da177e4
LT
1204 }
1205
1206 return err;
1207}
1208
1209static struct atm_ioctl lane_ioctl_ops = {
d44f7746
CW
1210 .owner = THIS_MODULE,
1211 .ioctl = lane_ioctl,
1da177e4
LT
1212};
1213
1214static int __init lane_module_init(void)
1215{
1216#ifdef CONFIG_PROC_FS
1217 struct proc_dir_entry *p;
1218
16e297b3 1219 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
dbee0d3f
WC
1220 if (!p) {
1221 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1222 return -ENOMEM;
1223 }
1da177e4
LT
1224#endif
1225
1226 register_atm_ioctl(&lane_ioctl_ops);
d44f7746
CW
1227 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1228 return 0;
1da177e4
LT
1229}
1230
1231static void __exit lane_module_cleanup(void)
1232{
d44f7746
CW
1233 int i;
1234 struct lec_priv *priv;
1da177e4
LT
1235
1236 remove_proc_entry("lec", atm_proc_root);
1237
1238 deregister_atm_ioctl(&lane_ioctl_ops);
1239
d44f7746
CW
1240 for (i = 0; i < MAX_LEC_ITF; i++) {
1241 if (dev_lec[i] != NULL) {
1242 priv = (struct lec_priv *)dev_lec[i]->priv;
1da177e4 1243 unregister_netdev(dev_lec[i]);
d44f7746
CW
1244 free_netdev(dev_lec[i]);
1245 dev_lec[i] = NULL;
1246 }
1247 }
1da177e4 1248
d44f7746 1249 return;
1da177e4
LT
1250}
1251
1252module_init(lane_module_init);
1253module_exit(lane_module_cleanup);
1254
1255/*
1256 * LANE2: 3.1.3, LE_RESOLVE.request
1257 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1258 * If sizeoftlvs == NULL the default TLVs associated with with this
1259 * lec will be used.
1260 * If dst_mac == NULL, targetless LE_ARP will be sent
1261 */
61c33e01 1262static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
d44f7746 1263 u8 **tlvs, u32 *sizeoftlvs)
1da177e4
LT
1264{
1265 unsigned long flags;
d44f7746
CW
1266 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1267 struct lec_arp_table *table;
1268 struct sk_buff *skb;
1269 int retval;
1da177e4 1270
d44f7746 1271 if (force == 0) {
1da177e4 1272 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d44f7746 1273 table = lec_arp_find(priv, dst_mac);
1da177e4 1274 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
d44f7746
CW
1275 if (table == NULL)
1276 return -1;
1277
2afe37cd 1278 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
d44f7746
CW
1279 if (*tlvs == NULL)
1280 return -1;
1281
d44f7746
CW
1282 *sizeoftlvs = table->sizeoftlvs;
1283
1284 return 0;
1285 }
1da177e4
LT
1286
1287 if (sizeoftlvs == NULL)
1288 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
d44f7746 1289
1da177e4
LT
1290 else {
1291 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1292 if (skb == NULL)
1293 return -1;
1294 skb->len = *sizeoftlvs;
27d7ff46 1295 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1da177e4
LT
1296 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1297 }
d44f7746
CW
1298 return retval;
1299}
1da177e4
LT
1300
1301/*
1302 * LANE2: 3.1.4, LE_ASSOCIATE.request
1303 * Associate the *tlvs with the *lan_dst address.
1304 * Will overwrite any previous association
1305 * Returns 1 for success, 0 for failure (out of memory)
1306 *
1307 */
61c33e01
MBJ
1308static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1309 const u8 *tlvs, u32 sizeoftlvs)
1da177e4 1310{
d44f7746
CW
1311 int retval;
1312 struct sk_buff *skb;
1313 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1314
1315 if (compare_ether_addr(lan_dst, dev->dev_addr))
1316 return (0); /* not our mac address */
1317
1318 kfree(priv->tlvs); /* NULL if there was no previous association */
1319
2afe37cd 1320 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
d44f7746
CW
1321 if (priv->tlvs == NULL)
1322 return (0);
1323 priv->sizeoftlvs = sizeoftlvs;
d44f7746
CW
1324
1325 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1326 if (skb == NULL)
1327 return 0;
1328 skb->len = sizeoftlvs;
27d7ff46 1329 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
d44f7746
CW
1330 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1331 if (retval != 0)
1332 printk("lec.c: lane2_associate_req() failed\n");
1333 /*
1334 * If the previous association has changed we must
1335 * somehow notify other LANE entities about the change
1336 */
1337 return (1);
1da177e4
LT
1338}
1339
1340/*
1341 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1342 *
1343 */
61c33e01
MBJ
1344static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1345 const u8 *tlvs, u32 sizeoftlvs)
1da177e4
LT
1346{
1347#if 0
d44f7746 1348 int i = 0;
1da177e4
LT
1349#endif
1350 struct lec_priv *priv = (struct lec_priv *)dev->priv;
d44f7746
CW
1351#if 0 /*
1352 * Why have the TLVs in LE_ARP entries
1353 * since we do not use them? When you
1354 * uncomment this code, make sure the
1355 * TLVs get freed when entry is killed
1356 */
1357 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1da177e4 1358
d44f7746
CW
1359 if (entry == NULL)
1360 return; /* should not happen */
1da177e4 1361
d44f7746 1362 kfree(entry->tlvs);
1da177e4 1363
2afe37cd 1364 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
d44f7746
CW
1365 if (entry->tlvs == NULL)
1366 return;
d44f7746 1367 entry->sizeoftlvs = sizeoftlvs;
1da177e4
LT
1368#endif
1369#if 0
d44f7746
CW
1370 printk("lec.c: lane2_associate_ind()\n");
1371 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1372 while (i < sizeoftlvs)
1373 printk("%02x ", tlvs[i++]);
1374
1375 printk("\n");
1da177e4
LT
1376#endif
1377
d44f7746
CW
1378 /* tell MPOA about the TLVs we saw */
1379 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1380 priv->lane2_ops->associate_indicator(dev, mac_addr,
1381 tlvs, sizeoftlvs);
1382 }
1383 return;
1da177e4
LT
1384}
1385
1386/*
1387 * Here starts what used to lec_arpc.c
1388 *
1389 * lec_arpc.c was added here when making
1390 * lane client modular. October 1997
1da177e4
LT
1391 */
1392
1393#include <linux/types.h>
1da177e4
LT
1394#include <linux/timer.h>
1395#include <asm/param.h>
1396#include <asm/atomic.h>
1397#include <linux/inetdevice.h>
1398#include <net/route.h>
1399
1da177e4 1400#if 0
52240062 1401#define pr_debug(format,args...)
1da177e4 1402/*
52240062 1403#define pr_debug printk
1da177e4
LT
1404*/
1405#endif
1406#define DEBUG_ARP_TABLE 0
1407
1408#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1409
c4028958 1410static void lec_arp_check_expire(struct work_struct *work);
1da177e4
LT
1411static void lec_arp_expire_arp(unsigned long data);
1412
f7d57453 1413/*
1da177e4
LT
1414 * Arp table funcs
1415 */
1416
1417#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1418
1419/*
1420 * Initialization of arp-cache
1421 */
1fa9961d 1422static void lec_arp_init(struct lec_priv *priv)
1da177e4 1423{
1fa9961d 1424 unsigned short i;
1da177e4 1425
1fa9961d 1426 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1427 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1fa9961d 1428 }
f7d57453
YH
1429 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1430 INIT_HLIST_HEAD(&priv->lec_no_forward);
1431 INIT_HLIST_HEAD(&priv->mcast_fwds);
1da177e4 1432 spin_lock_init(&priv->lec_arp_lock);
c4028958 1433 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
987e46bd 1434 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1da177e4
LT
1435}
1436
1fa9961d 1437static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1da177e4 1438{
1fa9961d 1439 if (entry->vcc) {
1da177e4
LT
1440 struct atm_vcc *vcc = entry->vcc;
1441 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1fa9961d 1442 struct net_device *dev = (struct net_device *)vcc->proto_data;
1da177e4 1443
1fa9961d 1444 vcc->pop = vpriv->old_pop;
1da177e4
LT
1445 if (vpriv->xoff)
1446 netif_wake_queue(dev);
1447 kfree(vpriv);
1448 vcc->user_back = NULL;
1fa9961d 1449 vcc->push = entry->old_push;
1da177e4 1450 vcc_release_async(vcc, -EPIPE);
d0732f64 1451 entry->vcc = NULL;
1fa9961d
CW
1452 }
1453 if (entry->recv_vcc) {
1454 entry->recv_vcc->push = entry->old_recv_push;
1da177e4 1455 vcc_release_async(entry->recv_vcc, -EPIPE);
1fa9961d
CW
1456 entry->recv_vcc = NULL;
1457 }
1da177e4
LT
1458}
1459
1460/*
1461 * Insert entry to lec_arp_table
1462 * LANE2: Add to the end of the list to satisfy 8.1.13
1463 */
1fa9961d 1464static inline void
d0732f64 1465lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1da177e4 1466{
d0732f64 1467 struct hlist_head *tmp;
1fa9961d 1468
d0732f64
CW
1469 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1470 hlist_add_head(&entry->next, tmp);
1fa9961d 1471
52240062 1472 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
d0732f64
CW
1473 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1474 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1475 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1da177e4
LT
1476}
1477
1478/*
1479 * Remove entry from lec_arp_table
1480 */
1fa9961d
CW
1481static int
1482lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1da177e4 1483{
d0732f64
CW
1484 struct hlist_node *node;
1485 struct lec_arp_table *entry;
1486 int i, remove_vcc = 1;
1fa9961d
CW
1487
1488 if (!to_remove) {
1489 return -1;
1490 }
d0732f64
CW
1491
1492 hlist_del(&to_remove->next);
1fa9961d
CW
1493 del_timer(&to_remove->timer);
1494
d0732f64 1495 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1fa9961d
CW
1496 if (to_remove->status >= ESI_FLUSH_PENDING) {
1497 /*
1498 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1499 */
d0732f64
CW
1500 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1501 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1502 if (memcmp(to_remove->atm_addr,
1503 entry->atm_addr, ATM_ESA_LEN) == 0) {
1fa9961d
CW
1504 remove_vcc = 0;
1505 break;
1506 }
1507 }
1508 }
1509 if (remove_vcc)
1510 lec_arp_clear_vccs(to_remove);
1511 }
1512 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1513
52240062 1514 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1fa9961d
CW
1515 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1516 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1517 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1518 return 0;
1da177e4
LT
1519}
1520
1521#if DEBUG_ARP_TABLE
1fa9961d 1522static char *get_status_string(unsigned char st)
1da177e4 1523{
1fa9961d
CW
1524 switch (st) {
1525 case ESI_UNKNOWN:
1526 return "ESI_UNKNOWN";
1527 case ESI_ARP_PENDING:
1528 return "ESI_ARP_PENDING";
1529 case ESI_VC_PENDING:
1530 return "ESI_VC_PENDING";
1531 case ESI_FLUSH_PENDING:
1532 return "ESI_FLUSH_PENDING";
1533 case ESI_FORWARD_DIRECT:
1534 return "ESI_FORWARD_DIRECT";
1535 default:
1536 return "<UNKNOWN>";
1537 }
1da177e4 1538}
1da177e4 1539
1fa9961d 1540static void dump_arp_table(struct lec_priv *priv)
1da177e4 1541{
d0732f64 1542 struct hlist_node *node;
1fa9961d 1543 struct lec_arp_table *rulla;
d0732f64
CW
1544 char buf[256];
1545 int i, j, offset;
1fa9961d
CW
1546
1547 printk("Dump %p:\n", priv);
1548 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64
CW
1549 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1550 offset = 0;
1551 offset += sprintf(buf, "%d: %p\n", i, rulla);
1fa9961d
CW
1552 offset += sprintf(buf + offset, "Mac:");
1553 for (j = 0; j < ETH_ALEN; j++) {
1554 offset += sprintf(buf + offset,
1555 "%2.2x ",
1556 rulla->mac_addr[j] & 0xff);
1557 }
1558 offset += sprintf(buf + offset, "Atm:");
1559 for (j = 0; j < ATM_ESA_LEN; j++) {
1560 offset += sprintf(buf + offset,
1561 "%2.2x ",
1562 rulla->atm_addr[j] & 0xff);
1563 }
1564 offset += sprintf(buf + offset,
1565 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1566 rulla->vcc ? rulla->vcc->vpi : 0,
1567 rulla->vcc ? rulla->vcc->vci : 0,
1568 rulla->recv_vcc ? rulla->recv_vcc->
1569 vpi : 0,
1570 rulla->recv_vcc ? rulla->recv_vcc->
1571 vci : 0, rulla->last_used,
1572 rulla->timestamp, rulla->no_tries);
1573 offset +=
1574 sprintf(buf + offset,
1575 "Flags:%x, Packets_flooded:%x, Status: %s ",
1576 rulla->flags, rulla->packets_flooded,
1577 get_status_string(rulla->status));
d0732f64 1578 printk("%s\n", buf);
1fa9961d 1579 }
1fa9961d 1580 }
d0732f64
CW
1581
1582 if (!hlist_empty(&priv->lec_no_forward))
1fa9961d 1583 printk("No forward\n");
d0732f64 1584 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1fa9961d
CW
1585 offset = 0;
1586 offset += sprintf(buf + offset, "Mac:");
1587 for (j = 0; j < ETH_ALEN; j++) {
1588 offset += sprintf(buf + offset, "%2.2x ",
1589 rulla->mac_addr[j] & 0xff);
1590 }
1591 offset += sprintf(buf + offset, "Atm:");
1592 for (j = 0; j < ATM_ESA_LEN; j++) {
1593 offset += sprintf(buf + offset, "%2.2x ",
1594 rulla->atm_addr[j] & 0xff);
1595 }
1596 offset += sprintf(buf + offset,
1597 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1598 rulla->vcc ? rulla->vcc->vpi : 0,
1599 rulla->vcc ? rulla->vcc->vci : 0,
1600 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1601 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1602 rulla->last_used,
1603 rulla->timestamp, rulla->no_tries);
1604 offset += sprintf(buf + offset,
1605 "Flags:%x, Packets_flooded:%x, Status: %s ",
1606 rulla->flags, rulla->packets_flooded,
1607 get_status_string(rulla->status));
d0732f64 1608 printk("%s\n", buf);
1fa9961d 1609 }
d0732f64
CW
1610
1611 if (!hlist_empty(&priv->lec_arp_empty_ones))
1fa9961d 1612 printk("Empty ones\n");
d0732f64 1613 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1fa9961d
CW
1614 offset = 0;
1615 offset += sprintf(buf + offset, "Mac:");
1616 for (j = 0; j < ETH_ALEN; j++) {
1617 offset += sprintf(buf + offset, "%2.2x ",
1618 rulla->mac_addr[j] & 0xff);
1619 }
1620 offset += sprintf(buf + offset, "Atm:");
1621 for (j = 0; j < ATM_ESA_LEN; j++) {
1622 offset += sprintf(buf + offset, "%2.2x ",
1623 rulla->atm_addr[j] & 0xff);
1624 }
1625 offset += sprintf(buf + offset,
1626 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1627 rulla->vcc ? rulla->vcc->vpi : 0,
1628 rulla->vcc ? rulla->vcc->vci : 0,
1629 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1630 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1631 rulla->last_used,
1632 rulla->timestamp, rulla->no_tries);
1633 offset += sprintf(buf + offset,
1634 "Flags:%x, Packets_flooded:%x, Status: %s ",
1635 rulla->flags, rulla->packets_flooded,
1636 get_status_string(rulla->status));
1fa9961d
CW
1637 printk("%s", buf);
1638 }
1639
d0732f64 1640 if (!hlist_empty(&priv->mcast_fwds))
1fa9961d 1641 printk("Multicast Forward VCCs\n");
d0732f64 1642 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1fa9961d
CW
1643 offset = 0;
1644 offset += sprintf(buf + offset, "Mac:");
1645 for (j = 0; j < ETH_ALEN; j++) {
1646 offset += sprintf(buf + offset, "%2.2x ",
1647 rulla->mac_addr[j] & 0xff);
1648 }
1649 offset += sprintf(buf + offset, "Atm:");
1650 for (j = 0; j < ATM_ESA_LEN; j++) {
1651 offset += sprintf(buf + offset, "%2.2x ",
1652 rulla->atm_addr[j] & 0xff);
1653 }
1654 offset += sprintf(buf + offset,
1655 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1656 rulla->vcc ? rulla->vcc->vpi : 0,
1657 rulla->vcc ? rulla->vcc->vci : 0,
1658 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1659 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1660 rulla->last_used,
1661 rulla->timestamp, rulla->no_tries);
1662 offset += sprintf(buf + offset,
1663 "Flags:%x, Packets_flooded:%x, Status: %s ",
1664 rulla->flags, rulla->packets_flooded,
1665 get_status_string(rulla->status));
d0732f64 1666 printk("%s\n", buf);
1fa9961d 1667 }
1da177e4 1668
1da177e4 1669}
d0732f64
CW
1670#else
1671#define dump_arp_table(priv) do { } while (0)
1672#endif
1da177e4
LT
1673
1674/*
1675 * Destruction of arp-cache
1676 */
1fa9961d 1677static void lec_arp_destroy(struct lec_priv *priv)
1da177e4
LT
1678{
1679 unsigned long flags;
d0732f64
CW
1680 struct hlist_node *node, *next;
1681 struct lec_arp_table *entry;
1fa9961d
CW
1682 int i;
1683
987e46bd 1684 cancel_rearming_delayed_work(&priv->lec_arp_work);
1da177e4 1685
1fa9961d
CW
1686 /*
1687 * Remove all entries
1688 */
1da177e4
LT
1689
1690 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 1691 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1692 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d 1693 lec_arp_remove(priv, entry);
33a9c2d4 1694 lec_arp_put(entry);
1fa9961d 1695 }
d0732f64 1696 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1fa9961d 1697 }
d0732f64
CW
1698
1699 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1fa9961d
CW
1700 del_timer_sync(&entry->timer);
1701 lec_arp_clear_vccs(entry);
d0732f64 1702 hlist_del(&entry->next);
33a9c2d4 1703 lec_arp_put(entry);
1fa9961d 1704 }
d0732f64
CW
1705 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1706
1707 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1fa9961d
CW
1708 del_timer_sync(&entry->timer);
1709 lec_arp_clear_vccs(entry);
d0732f64 1710 hlist_del(&entry->next);
33a9c2d4 1711 lec_arp_put(entry);
1fa9961d 1712 }
d0732f64
CW
1713 INIT_HLIST_HEAD(&priv->lec_no_forward);
1714
1715 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1fa9961d
CW
1716 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1717 lec_arp_clear_vccs(entry);
d0732f64 1718 hlist_del(&entry->next);
33a9c2d4 1719 lec_arp_put(entry);
1fa9961d 1720 }
d0732f64 1721 INIT_HLIST_HEAD(&priv->mcast_fwds);
1fa9961d 1722 priv->mcast_vcc = NULL;
1da177e4
LT
1723 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1724}
1725
f7d57453 1726/*
1da177e4
LT
1727 * Find entry by mac_address
1728 */
1fa9961d 1729static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
61c33e01 1730 const unsigned char *mac_addr)
1da177e4 1731{
d0732f64
CW
1732 struct hlist_node *node;
1733 struct hlist_head *head;
1734 struct lec_arp_table *entry;
1fa9961d 1735
52240062 1736 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1fa9961d
CW
1737 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1738 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1fa9961d 1739
d0732f64
CW
1740 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1741 hlist_for_each_entry(entry, node, head, next) {
1742 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1743 return entry;
1fa9961d 1744 }
1fa9961d
CW
1745 }
1746 return NULL;
1da177e4
LT
1747}
1748
1fa9961d 1749static struct lec_arp_table *make_entry(struct lec_priv *priv,
61c33e01 1750 const unsigned char *mac_addr)
1da177e4 1751{
1fa9961d
CW
1752 struct lec_arp_table *to_return;
1753
1754 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1755 if (!to_return) {
1756 printk("LEC: Arp entry kmalloc failed\n");
1757 return NULL;
1758 }
1759 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
d0732f64 1760 INIT_HLIST_NODE(&to_return->next);
b24b8a24
PE
1761 setup_timer(&to_return->timer, lec_arp_expire_arp,
1762 (unsigned long)to_return);
1fa9961d
CW
1763 to_return->last_used = jiffies;
1764 to_return->priv = priv;
1765 skb_queue_head_init(&to_return->tx_wait);
33a9c2d4 1766 atomic_set(&to_return->usage, 1);
1fa9961d 1767 return to_return;
1da177e4
LT
1768}
1769
1fa9961d
CW
1770/* Arp sent timer expired */
1771static void lec_arp_expire_arp(unsigned long data)
1da177e4 1772{
1fa9961d
CW
1773 struct lec_arp_table *entry;
1774
1775 entry = (struct lec_arp_table *)data;
1776
52240062 1777 pr_debug("lec_arp_expire_arp\n");
1fa9961d
CW
1778 if (entry->status == ESI_ARP_PENDING) {
1779 if (entry->no_tries <= entry->priv->max_retry_count) {
1780 if (entry->is_rdesc)
1781 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1782 entry->mac_addr, NULL, NULL);
1783 else
1784 send_to_lecd(entry->priv, l_arp_xmt,
1785 entry->mac_addr, NULL, NULL);
1786 entry->no_tries++;
1787 }
1788 mod_timer(&entry->timer, jiffies + (1 * HZ));
1789 }
1da177e4
LT
1790}
1791
1fa9961d
CW
1792/* Unknown/unused vcc expire, remove associated entry */
1793static void lec_arp_expire_vcc(unsigned long data)
1da177e4
LT
1794{
1795 unsigned long flags;
1fa9961d
CW
1796 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1797 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1da177e4 1798
1fa9961d 1799 del_timer(&to_remove->timer);
1da177e4 1800
52240062 1801 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1fa9961d
CW
1802 to_remove, priv,
1803 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1804 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1da177e4
LT
1805
1806 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64 1807 hlist_del(&to_remove->next);
1da177e4
LT
1808 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1809
1fa9961d 1810 lec_arp_clear_vccs(to_remove);
33a9c2d4 1811 lec_arp_put(to_remove);
1da177e4
LT
1812}
1813
1814/*
1815 * Expire entries.
1816 * 1. Re-set timer
1817 * 2. For each entry, delete entries that have aged past the age limit.
1818 * 3. For each entry, depending on the status of the entry, perform
1819 * the following maintenance.
1820 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1821 * tick_count is above the max_unknown_frame_time, clear
1822 * the tick_count to zero and clear the packets_flooded counter
1823 * to zero. This supports the packet rate limit per address
1824 * while flooding unknowns.
1825 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1826 * than or equal to the path_switching_delay, change the status
1827 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1828 * regardless of the progress of the flush protocol.
1829 */
c4028958 1830static void lec_arp_check_expire(struct work_struct *work)
1da177e4
LT
1831{
1832 unsigned long flags;
c4028958
DH
1833 struct lec_priv *priv =
1834 container_of(work, struct lec_priv, lec_arp_work.work);
d0732f64
CW
1835 struct hlist_node *node, *next;
1836 struct lec_arp_table *entry;
1fa9961d
CW
1837 unsigned long now;
1838 unsigned long time_to_check;
1839 int i;
1840
52240062 1841 pr_debug("lec_arp_check_expire %p\n", priv);
1da177e4 1842 now = jiffies;
6656e3c4 1843restart:
1da177e4 1844 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 1845 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 1846 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d 1847 if ((entry->flags) & LEC_REMOTE_FLAG &&
1da177e4
LT
1848 priv->topology_change)
1849 time_to_check = priv->forward_delay_time;
1850 else
1851 time_to_check = priv->aging_time;
1852
52240062 1853 pr_debug("About to expire: %lx - %lx > %lx\n",
1fa9961d
CW
1854 now, entry->last_used, time_to_check);
1855 if (time_after(now, entry->last_used + time_to_check)
1856 && !(entry->flags & LEC_PERMANENT_FLAG)
1857 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1da177e4 1858 /* Remove entry */
52240062 1859 pr_debug("LEC:Entry timed out\n");
1da177e4 1860 lec_arp_remove(priv, entry);
33a9c2d4 1861 lec_arp_put(entry);
1da177e4
LT
1862 } else {
1863 /* Something else */
1864 if ((entry->status == ESI_VC_PENDING ||
1fa9961d 1865 entry->status == ESI_ARP_PENDING)
1da177e4 1866 && time_after_eq(now,
1fa9961d
CW
1867 entry->timestamp +
1868 priv->
1869 max_unknown_frame_time)) {
1da177e4
LT
1870 entry->timestamp = jiffies;
1871 entry->packets_flooded = 0;
1872 if (entry->status == ESI_VC_PENDING)
1fa9961d
CW
1873 send_to_lecd(priv, l_svc_setup,
1874 entry->mac_addr,
1875 entry->atm_addr,
1876 NULL);
1da177e4 1877 }
1fa9961d
CW
1878 if (entry->status == ESI_FLUSH_PENDING
1879 &&
1880 time_after_eq(now, entry->timestamp +
1881 priv->path_switching_delay)) {
1da177e4 1882 struct sk_buff *skb;
6656e3c4 1883 struct atm_vcc *vcc = entry->vcc;
1da177e4 1884
6656e3c4
CW
1885 lec_arp_hold(entry);
1886 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1887 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1888 lec_send(vcc, skb, entry->priv);
1da177e4 1889 entry->last_used = jiffies;
1fa9961d 1890 entry->status = ESI_FORWARD_DIRECT;
6656e3c4
CW
1891 lec_arp_put(entry);
1892 goto restart;
1da177e4 1893 }
1da177e4
LT
1894 }
1895 }
1896 }
1897 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1898
987e46bd 1899 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1da177e4 1900}
1fa9961d 1901
1da177e4
LT
1902/*
1903 * Try to find vcc where mac_address is attached.
f7d57453 1904 *
1da177e4 1905 */
1fa9961d 1906static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
61c33e01 1907 const unsigned char *mac_to_find, int is_rdesc,
1fa9961d 1908 struct lec_arp_table **ret_entry)
1da177e4
LT
1909{
1910 unsigned long flags;
1fa9961d 1911 struct lec_arp_table *entry;
1da177e4
LT
1912 struct atm_vcc *found;
1913
1fa9961d
CW
1914 if (mac_to_find[0] & 0x01) {
1915 switch (priv->lane_version) {
1916 case 1:
1917 return priv->mcast_vcc;
1fa9961d
CW
1918 case 2: /* LANE2 wants arp for multicast addresses */
1919 if (!compare_ether_addr(mac_to_find, bus_mac))
1920 return priv->mcast_vcc;
1921 break;
1922 default:
1923 break;
1924 }
1925 }
1da177e4
LT
1926
1927 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
1928 entry = lec_arp_find(priv, mac_to_find);
1929
1930 if (entry) {
1931 if (entry->status == ESI_FORWARD_DIRECT) {
1932 /* Connection Ok */
1933 entry->last_used = jiffies;
6656e3c4 1934 lec_arp_hold(entry);
1fa9961d
CW
1935 *ret_entry = entry;
1936 found = entry->vcc;
1da177e4 1937 goto out;
1fa9961d
CW
1938 }
1939 /*
1940 * If the LE_ARP cache entry is still pending, reset count to 0
75b895c1
ST
1941 * so another LE_ARP request can be made for this frame.
1942 */
1943 if (entry->status == ESI_ARP_PENDING) {
1944 entry->no_tries = 0;
1945 }
1fa9961d
CW
1946 /*
1947 * Data direct VC not yet set up, check to see if the unknown
1948 * frame count is greater than the limit. If the limit has
1949 * not been reached, allow the caller to send packet to
1950 * BUS.
1951 */
1952 if (entry->status != ESI_FLUSH_PENDING &&
1953 entry->packets_flooded <
1954 priv->maximum_unknown_frame_count) {
1955 entry->packets_flooded++;
52240062 1956 pr_debug("LEC_ARP: Flooding..\n");
1fa9961d 1957 found = priv->mcast_vcc;
1da177e4 1958 goto out;
1fa9961d
CW
1959 }
1960 /*
1961 * We got here because entry->status == ESI_FLUSH_PENDING
1da177e4
LT
1962 * or BUS flood limit was reached for an entry which is
1963 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1964 */
6656e3c4 1965 lec_arp_hold(entry);
1fa9961d 1966 *ret_entry = entry;
52240062 1967 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
1fa9961d
CW
1968 entry->vcc);
1969 found = NULL;
1970 } else {
1971 /* No matching entry was found */
1972 entry = make_entry(priv, mac_to_find);
52240062 1973 pr_debug("LEC_ARP: Making entry\n");
1fa9961d
CW
1974 if (!entry) {
1975 found = priv->mcast_vcc;
1da177e4 1976 goto out;
1fa9961d
CW
1977 }
1978 lec_arp_add(priv, entry);
1979 /* We want arp-request(s) to be sent */
1980 entry->packets_flooded = 1;
1981 entry->status = ESI_ARP_PENDING;
1982 entry->no_tries = 1;
1983 entry->last_used = entry->timestamp = jiffies;
1984 entry->is_rdesc = is_rdesc;
1985 if (entry->is_rdesc)
1986 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1987 NULL);
1988 else
1989 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1990 entry->timer.expires = jiffies + (1 * HZ);
1991 entry->timer.function = lec_arp_expire_arp;
1992 add_timer(&entry->timer);
1993 found = priv->mcast_vcc;
1994 }
1da177e4
LT
1995
1996out:
1997 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1998 return found;
1999}
2000
2001static int
61c33e01 2002lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1fa9961d 2003 unsigned long permanent)
1da177e4
LT
2004{
2005 unsigned long flags;
d0732f64
CW
2006 struct hlist_node *node, *next;
2007 struct lec_arp_table *entry;
1fa9961d 2008 int i;
1da177e4 2009
52240062 2010 pr_debug("lec_addr_delete\n");
1da177e4 2011 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 2012 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2013 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2014 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2015 && (permanent ||
2016 !(entry->flags & LEC_PERMANENT_FLAG))) {
1da177e4 2017 lec_arp_remove(priv, entry);
33a9c2d4 2018 lec_arp_put(entry);
1fa9961d 2019 }
1da177e4 2020 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d
CW
2021 return 0;
2022 }
2023 }
1da177e4 2024 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2025 return -1;
1da177e4
LT
2026}
2027
2028/*
f7d57453 2029 * Notifies: Response to arp_request (atm_addr != NULL)
1da177e4
LT
2030 */
2031static void
61c33e01
MBJ
2032lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2033 const unsigned char *atm_addr, unsigned long remoteflag,
1fa9961d 2034 unsigned int targetless_le_arp)
1da177e4
LT
2035{
2036 unsigned long flags;
d0732f64 2037 struct hlist_node *node, *next;
1fa9961d
CW
2038 struct lec_arp_table *entry, *tmp;
2039 int i;
1da177e4 2040
52240062
SH
2041 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2042 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1fa9961d
CW
2043 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2044 mac_addr[4], mac_addr[5]);
1da177e4
LT
2045
2046 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2047 entry = lec_arp_find(priv, mac_addr);
2048 if (entry == NULL && targetless_le_arp)
2049 goto out; /*
2050 * LANE2: ignore targetless LE_ARPs for which
2051 * we have no entry in the cache. 7.1.30
2052 */
d0732f64
CW
2053 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2054 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2055 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2056 hlist_del(&entry->next);
1fa9961d 2057 del_timer(&entry->timer);
d0732f64
CW
2058 tmp = lec_arp_find(priv, mac_addr);
2059 if (tmp) {
2060 del_timer(&tmp->timer);
2061 tmp->status = ESI_FORWARD_DIRECT;
2062 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2063 tmp->vcc = entry->vcc;
2064 tmp->old_push = entry->old_push;
2065 tmp->last_used = jiffies;
2066 del_timer(&entry->timer);
33a9c2d4 2067 lec_arp_put(entry);
d0732f64
CW
2068 entry = tmp;
2069 } else {
2070 entry->status = ESI_FORWARD_DIRECT;
2071 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2072 entry->last_used = jiffies;
2073 lec_arp_add(priv, entry);
2074 }
2075 if (remoteflag)
2076 entry->flags |= LEC_REMOTE_FLAG;
2077 else
2078 entry->flags &= ~LEC_REMOTE_FLAG;
52240062 2079 pr_debug("After update\n");
d0732f64
CW
2080 dump_arp_table(priv);
2081 goto out;
1fa9961d 2082 }
1fa9961d
CW
2083 }
2084 }
d0732f64 2085
1fa9961d
CW
2086 entry = lec_arp_find(priv, mac_addr);
2087 if (!entry) {
2088 entry = make_entry(priv, mac_addr);
2089 if (!entry)
2090 goto out;
2091 entry->status = ESI_UNKNOWN;
2092 lec_arp_add(priv, entry);
2093 /* Temporary, changes before end of function */
2094 }
2095 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2096 del_timer(&entry->timer);
2097 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2098 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2099 if (entry != tmp &&
2100 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2101 /* Vcc to this host exists */
2102 if (tmp->status > ESI_VC_PENDING) {
2103 /*
2104 * ESI_FLUSH_PENDING,
2105 * ESI_FORWARD_DIRECT
2106 */
2107 entry->vcc = tmp->vcc;
2108 entry->old_push = tmp->old_push;
2109 }
2110 entry->status = tmp->status;
2111 break;
2112 }
2113 }
2114 }
2115 if (remoteflag)
2116 entry->flags |= LEC_REMOTE_FLAG;
2117 else
2118 entry->flags &= ~LEC_REMOTE_FLAG;
2119 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2120 entry->status = ESI_VC_PENDING;
d0732f64 2121 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
1fa9961d 2122 }
52240062 2123 pr_debug("After update2\n");
1fa9961d 2124 dump_arp_table(priv);
1da177e4
LT
2125out:
2126 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2127}
2128
2129/*
f7d57453 2130 * Notifies: Vcc setup ready
1da177e4
LT
2131 */
2132static void
61c33e01 2133lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
1fa9961d
CW
2134 struct atm_vcc *vcc,
2135 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
1da177e4
LT
2136{
2137 unsigned long flags;
d0732f64 2138 struct hlist_node *node;
1fa9961d
CW
2139 struct lec_arp_table *entry;
2140 int i, found_entry = 0;
1da177e4
LT
2141
2142 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2143 if (ioc_data->receive == 2) {
2144 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
1da177e4 2145
52240062 2146 pr_debug("LEC_ARP: Attaching mcast forward\n");
1da177e4 2147#if 0
1fa9961d
CW
2148 entry = lec_arp_find(priv, bus_mac);
2149 if (!entry) {
2150 printk("LEC_ARP: Multicast entry not found!\n");
1da177e4 2151 goto out;
1fa9961d
CW
2152 }
2153 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2154 entry->recv_vcc = vcc;
2155 entry->old_recv_push = old_push;
1da177e4 2156#endif
1fa9961d
CW
2157 entry = make_entry(priv, bus_mac);
2158 if (entry == NULL)
1da177e4 2159 goto out;
1fa9961d
CW
2160 del_timer(&entry->timer);
2161 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2162 entry->recv_vcc = vcc;
2163 entry->old_recv_push = old_push;
d0732f64 2164 hlist_add_head(&entry->next, &priv->mcast_fwds);
1fa9961d
CW
2165 goto out;
2166 } else if (ioc_data->receive == 1) {
2167 /*
2168 * Vcc which we don't want to make default vcc,
2169 * attach it anyway.
2170 */
52240062 2171 pr_debug
1fa9961d
CW
2172 ("LEC_ARP:Attaching data direct, not default: "
2173 "%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",
2174 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2175 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2176 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2177 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2178 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2179 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2180 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2181 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2182 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2183 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2184 entry = make_entry(priv, bus_mac);
2185 if (entry == NULL)
1da177e4 2186 goto out;
1fa9961d
CW
2187 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2188 memset(entry->mac_addr, 0, ETH_ALEN);
2189 entry->recv_vcc = vcc;
2190 entry->old_recv_push = old_push;
2191 entry->status = ESI_UNKNOWN;
2192 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2193 entry->timer.function = lec_arp_expire_vcc;
d0732f64 2194 hlist_add_head(&entry->next, &priv->lec_no_forward);
1fa9961d 2195 add_timer(&entry->timer);
1da177e4
LT
2196 dump_arp_table(priv);
2197 goto out;
1fa9961d 2198 }
52240062 2199 pr_debug
1fa9961d
CW
2200 ("LEC_ARP:Attaching data direct, default: "
2201 "%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",
2202 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2203 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2204 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2205 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2206 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2207 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2208 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2209 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2210 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2211 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2212 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2213 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2214 if (memcmp
2215 (ioc_data->atm_addr, entry->atm_addr,
2216 ATM_ESA_LEN) == 0) {
52240062
SH
2217 pr_debug("LEC_ARP: Attaching data direct\n");
2218 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
1fa9961d
CW
2219 entry->vcc ? entry->vcc->vci : 0,
2220 entry->recv_vcc ? entry->recv_vcc->
2221 vci : 0);
2222 found_entry = 1;
2223 del_timer(&entry->timer);
2224 entry->vcc = vcc;
2225 entry->old_push = old_push;
2226 if (entry->status == ESI_VC_PENDING) {
2227 if (priv->maximum_unknown_frame_count
2228 == 0)
2229 entry->status =
2230 ESI_FORWARD_DIRECT;
2231 else {
2232 entry->timestamp = jiffies;
2233 entry->status =
2234 ESI_FLUSH_PENDING;
1da177e4 2235#if 0
1fa9961d
CW
2236 send_to_lecd(priv, l_flush_xmt,
2237 NULL,
2238 entry->atm_addr,
2239 NULL);
1da177e4 2240#endif
1fa9961d
CW
2241 }
2242 } else {
2243 /*
2244 * They were forming a connection
2245 * to us, and we to them. Our
2246 * ATM address is numerically lower
2247 * than theirs, so we make connection
2248 * we formed into default VCC (8.1.11).
2249 * Connection they made gets torn
2250 * down. This might confuse some
2251 * clients. Can be changed if
2252 * someone reports trouble...
2253 */
2254 ;
2255 }
2256 }
2257 }
2258 }
2259 if (found_entry) {
52240062 2260 pr_debug("After vcc was added\n");
1fa9961d 2261 dump_arp_table(priv);
1da177e4 2262 goto out;
1fa9961d
CW
2263 }
2264 /*
2265 * Not found, snatch address from first data packet that arrives
2266 * from this vcc
2267 */
2268 entry = make_entry(priv, bus_mac);
2269 if (!entry)
1da177e4 2270 goto out;
1fa9961d
CW
2271 entry->vcc = vcc;
2272 entry->old_push = old_push;
2273 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2274 memset(entry->mac_addr, 0, ETH_ALEN);
2275 entry->status = ESI_UNKNOWN;
d0732f64 2276 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
1fa9961d
CW
2277 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2278 entry->timer.function = lec_arp_expire_vcc;
2279 add_timer(&entry->timer);
52240062 2280 pr_debug("After vcc was added\n");
1da177e4
LT
2281 dump_arp_table(priv);
2282out:
2283 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2284}
2285
1fa9961d 2286static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
1da177e4
LT
2287{
2288 unsigned long flags;
d0732f64 2289 struct hlist_node *node;
1fa9961d
CW
2290 struct lec_arp_table *entry;
2291 int i;
1da177e4 2292
52240062 2293 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
6656e3c4 2294restart:
1fa9961d
CW
2295 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2296 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2297 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2298 if (entry->flush_tran_id == tran_id
2299 && entry->status == ESI_FLUSH_PENDING) {
2300 struct sk_buff *skb;
6656e3c4 2301 struct atm_vcc *vcc = entry->vcc;
1fa9961d 2302
6656e3c4
CW
2303 lec_arp_hold(entry);
2304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2305 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2306 lec_send(vcc, skb, entry->priv);
2307 entry->last_used = jiffies;
1fa9961d 2308 entry->status = ESI_FORWARD_DIRECT;
6656e3c4 2309 lec_arp_put(entry);
52240062 2310 pr_debug("LEC_ARP: Flushed\n");
6656e3c4 2311 goto restart;
1fa9961d
CW
2312 }
2313 }
2314 }
1da177e4 2315 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2316 dump_arp_table(priv);
1da177e4
LT
2317}
2318
2319static void
2320lec_set_flush_tran_id(struct lec_priv *priv,
61c33e01 2321 const unsigned char *atm_addr, unsigned long tran_id)
1da177e4
LT
2322{
2323 unsigned long flags;
d0732f64 2324 struct hlist_node *node;
1fa9961d
CW
2325 struct lec_arp_table *entry;
2326 int i;
1da177e4
LT
2327
2328 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d 2329 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
d0732f64 2330 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2331 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2332 entry->flush_tran_id = tran_id;
52240062 2333 pr_debug("Set flush transaction id to %lx for %p\n",
f7d57453 2334 tran_id, entry);
1fa9961d 2335 }
d0732f64 2336 }
1da177e4
LT
2337 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2338}
2339
1fa9961d 2340static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
1da177e4
LT
2341{
2342 unsigned long flags;
1fa9961d
CW
2343 unsigned char mac_addr[] = {
2344 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2345 };
2346 struct lec_arp_table *to_add;
1da177e4
LT
2347 struct lec_vcc_priv *vpriv;
2348 int err = 0;
1fa9961d 2349
1da177e4
LT
2350 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2351 return -ENOMEM;
2352 vpriv->xoff = 0;
2353 vpriv->old_pop = vcc->pop;
2354 vcc->user_back = vpriv;
1fa9961d 2355 vcc->pop = lec_pop;
1da177e4 2356 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1fa9961d
CW
2357 to_add = make_entry(priv, mac_addr);
2358 if (!to_add) {
1da177e4
LT
2359 vcc->pop = vpriv->old_pop;
2360 kfree(vpriv);
1fa9961d 2361 err = -ENOMEM;
1da177e4 2362 goto out;
1fa9961d
CW
2363 }
2364 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2365 to_add->status = ESI_FORWARD_DIRECT;
2366 to_add->flags |= LEC_PERMANENT_FLAG;
2367 to_add->vcc = vcc;
2368 to_add->old_push = vcc->push;
2369 vcc->push = lec_push;
2370 priv->mcast_vcc = vcc;
2371 lec_arp_add(priv, to_add);
1da177e4
LT
2372out:
2373 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1fa9961d 2374 return err;
1da177e4
LT
2375}
2376
1fa9961d 2377static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
1da177e4
LT
2378{
2379 unsigned long flags;
d0732f64
CW
2380 struct hlist_node *node, *next;
2381 struct lec_arp_table *entry;
1fa9961d 2382 int i;
1da177e4 2383
52240062 2384 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
1fa9961d 2385 dump_arp_table(priv);
d0732f64 2386
1da177e4 2387 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64 2388
1fa9961d 2389 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
d0732f64 2390 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1fa9961d
CW
2391 if (vcc == entry->vcc) {
2392 lec_arp_remove(priv, entry);
33a9c2d4 2393 lec_arp_put(entry);
1fa9961d
CW
2394 if (priv->mcast_vcc == vcc) {
2395 priv->mcast_vcc = NULL;
2396 }
2397 }
2398 }
2399 }
2400
d0732f64
CW
2401 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2402 if (entry->vcc == vcc) {
1fa9961d
CW
2403 lec_arp_clear_vccs(entry);
2404 del_timer(&entry->timer);
d0732f64 2405 hlist_del(&entry->next);
33a9c2d4 2406 lec_arp_put(entry);
1fa9961d 2407 }
1fa9961d
CW
2408 }
2409
d0732f64 2410 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1fa9961d
CW
2411 if (entry->recv_vcc == vcc) {
2412 lec_arp_clear_vccs(entry);
2413 del_timer(&entry->timer);
d0732f64 2414 hlist_del(&entry->next);
33a9c2d4 2415 lec_arp_put(entry);
1fa9961d 2416 }
1fa9961d
CW
2417 }
2418
d0732f64 2419 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1fa9961d
CW
2420 if (entry->recv_vcc == vcc) {
2421 lec_arp_clear_vccs(entry);
2422 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
d0732f64 2423 hlist_del(&entry->next);
33a9c2d4 2424 lec_arp_put(entry);
1fa9961d 2425 }
1fa9961d 2426 }
1da177e4
LT
2427
2428 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2429 dump_arp_table(priv);
2430}
2431
2432static void
2433lec_arp_check_empties(struct lec_priv *priv,
1fa9961d 2434 struct atm_vcc *vcc, struct sk_buff *skb)
1da177e4 2435{
1fa9961d 2436 unsigned long flags;
d0732f64
CW
2437 struct hlist_node *node, *next;
2438 struct lec_arp_table *entry, *tmp;
1fa9961d
CW
2439 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2440 unsigned char *src;
1da177e4 2441#ifdef CONFIG_TR
1fa9961d 2442 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
1da177e4 2443
1fa9961d
CW
2444 if (priv->is_trdev)
2445 src = tr_hdr->h_source;
2446 else
1da177e4 2447#endif
1fa9961d 2448 src = hdr->h_source;
1da177e4
LT
2449
2450 spin_lock_irqsave(&priv->lec_arp_lock, flags);
d0732f64
CW
2451 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2452 if (vcc == entry->vcc) {
2453 del_timer(&entry->timer);
2454 memcpy(entry->mac_addr, src, ETH_ALEN);
2455 entry->status = ESI_FORWARD_DIRECT;
2456 entry->last_used = jiffies;
2457 /* We might have got an entry */
2458 if ((tmp = lec_arp_find(priv, src))) {
2459 lec_arp_remove(priv, tmp);
33a9c2d4 2460 lec_arp_put(tmp);
d0732f64
CW
2461 }
2462 hlist_del(&entry->next);
2463 lec_arp_add(priv, entry);
2464 goto out;
1fa9961d 2465 }
1fa9961d 2466 }
52240062 2467 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
1da177e4
LT
2468out:
2469 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2470}
1fa9961d 2471
1da177e4 2472MODULE_LICENSE("GPL");