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