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