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