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