2 * lec.c: Lan Emulation driver
4 * Marko Kiiskila <mkiiskila@yahoo.com>
7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
9 #include <linux/kernel.h>
10 #include <linux/bitops.h>
11 #include <linux/capability.h>
13 /* We are ethernet device */
14 #include <linux/if_ether.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
18 #include <linux/skbuff.h>
20 #include <asm/byteorder.h>
21 #include <linux/uaccess.h>
24 #include <linux/proc_fs.h>
25 #include <linux/spinlock.h>
26 #include <linux/seq_file.h>
28 /* TokenRing if needed */
30 #include <linux/trdevice.h>
34 #include <linux/atmdev.h>
35 #include <linux/atmlec.h>
37 /* Proxy LEC knows about bridging */
38 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
39 #include "../bridge/br_private.h"
41 static unsigned char bridge_ula_lec
[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
45 #include <linux/module.h>
46 #include <linux/init.h>
50 #include "resources.h"
52 #define DUMP_PACKETS 0 /*
58 #define LEC_UNRES_QUE_LEN 8 /*
59 * number of tx packets to queue for a
60 * single destination while waiting for SVC
63 static int lec_open(struct net_device
*dev
);
64 static netdev_tx_t
lec_start_xmit(struct sk_buff
*skb
,
65 struct net_device
*dev
);
66 static int lec_close(struct net_device
*dev
);
67 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
68 const unsigned char *mac_addr
);
69 static int lec_arp_remove(struct lec_priv
*priv
,
70 struct lec_arp_table
*to_remove
);
72 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_address
,
73 const u8
*tlvs
, u32 sizeoftlvs
);
74 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
75 u8
**tlvs
, u32
*sizeoftlvs
);
76 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
77 const u8
*tlvs
, u32 sizeoftlvs
);
79 static int lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
80 unsigned long permanent
);
81 static void lec_arp_check_empties(struct lec_priv
*priv
,
82 struct atm_vcc
*vcc
, struct sk_buff
*skb
);
83 static void lec_arp_destroy(struct lec_priv
*priv
);
84 static void lec_arp_init(struct lec_priv
*priv
);
85 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
86 const unsigned char *mac_to_find
,
88 struct lec_arp_table
**ret_entry
);
89 static void lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
90 const unsigned char *atm_addr
,
91 unsigned long remoteflag
,
92 unsigned int targetless_le_arp
);
93 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
94 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
95 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
96 const unsigned char *atm_addr
,
97 unsigned long tran_id
);
98 static void lec_vcc_added(struct lec_priv
*priv
,
99 const struct atmlec_ioc
*ioc_data
,
101 void (*old_push
)(struct atm_vcc
*vcc
,
102 struct sk_buff
*skb
));
103 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
105 /* must be done under lec_arp_lock */
106 static inline void lec_arp_hold(struct lec_arp_table
*entry
)
108 atomic_inc(&entry
->usage
);
111 static inline void lec_arp_put(struct lec_arp_table
*entry
)
113 if (atomic_dec_and_test(&entry
->usage
))
117 static struct lane2_ops lane2_ops
= {
118 lane2_resolve
, /* resolve, spec 3.1.3 */
119 lane2_associate_req
, /* associate_req, spec 3.1.4 */
120 NULL
/* associate indicator, spec 3.1.5 */
123 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
125 /* Device structures */
126 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
128 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
129 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
133 struct lec_priv
*priv
;
136 * Check if this is a BPDU. If so, ask zeppelin to send
137 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
138 * as the Config BPDU has
140 eth
= (struct ethhdr
*)skb
->data
;
141 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
142 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
144 struct sk_buff
*skb2
;
145 struct atmlec_msg
*mesg
;
147 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
150 skb2
->len
= sizeof(struct atmlec_msg
);
151 mesg
= (struct atmlec_msg
*)skb2
->data
;
152 mesg
->type
= l_topology_change
;
154 mesg
->content
.normal
.flag
= *buff
& 0x01;
155 /* 0x01 is topology change */
157 priv
= netdev_priv(dev
);
158 atm_force_charge(priv
->lecd
, skb2
->truesize
);
159 sk
= sk_atm(priv
->lecd
);
160 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
161 sk
->sk_data_ready(sk
, skb2
->len
);
166 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
169 * Modelled after tr_type_trans
170 * All multicast and ARE or STE frames go to BUS.
171 * Non source routed frames go by destination address.
172 * Last hop source routed frames go by destination address.
173 * Not last hop source routed frames go by _next_ route descriptor.
174 * Returns pointer to destination MAC address or fills in rdesc
178 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
181 unsigned int riflen
, num_rdsc
;
183 trh
= (struct trh_hdr
*)packet
;
184 if (trh
->daddr
[0] & (uint8_t) 0x80)
185 return bus_mac
; /* multicast */
187 if (trh
->saddr
[0] & TR_RII
) {
188 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
189 if ((ntohs(trh
->rcf
) >> 13) != 0)
190 return bus_mac
; /* ARE or STE */
192 return trh
->daddr
; /* not source routed */
195 return trh
->daddr
; /* last hop, source routed */
197 /* riflen is 6 or more, packet has more than one route descriptor */
198 num_rdsc
= (riflen
/ 2) - 1;
199 memset(rdesc
, 0, ETH_ALEN
);
200 /* offset 4 comes from LAN destination field in LE control frames */
201 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
202 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(__be16
));
204 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(__be16
));
205 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
210 #endif /* CONFIG_TR */
213 * Open/initialize the netdevice. This is called (in the current kernel)
214 * sometime after booting when the 'ifconfig' program is run.
216 * This routine should set everything up anew at each open, even
217 * registers that "should" only need to be set once at boot, so that
218 * there is non-reboot way to recover if something goes wrong.
221 static int lec_open(struct net_device
*dev
)
223 netif_start_queue(dev
);
224 memset(&dev
->stats
, 0, sizeof(struct net_device_stats
));
230 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
232 struct net_device
*dev
= skb
->dev
;
234 ATM_SKB(skb
)->vcc
= vcc
;
235 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
237 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
238 if (vcc
->send(vcc
, skb
) < 0) {
239 dev
->stats
.tx_dropped
++;
243 dev
->stats
.tx_packets
++;
244 dev
->stats
.tx_bytes
+= skb
->len
;
247 static void lec_tx_timeout(struct net_device
*dev
)
249 pr_info("%s\n", dev
->name
);
250 dev
->trans_start
= jiffies
;
251 netif_wake_queue(dev
);
254 static netdev_tx_t
lec_start_xmit(struct sk_buff
*skb
,
255 struct net_device
*dev
)
257 struct sk_buff
*skb2
;
258 struct lec_priv
*priv
= netdev_priv(dev
);
259 struct lecdatahdr_8023
*lec_h
;
261 struct lec_arp_table
*entry
;
265 unsigned char rdesc
[ETH_ALEN
]; /* Token Ring route descriptor */
269 pr_debug("called\n");
271 pr_info("%s:No lecd attached\n", dev
->name
);
272 dev
->stats
.tx_errors
++;
273 netif_stop_queue(dev
);
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
);
286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb
) < 2) {
288 pr_debug("reallocating skb\n");
289 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
297 /* Put le header to place, works for TokenRing too */
298 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
299 lec_h
->le_header
= htons(priv
->lecid
);
303 * Ugly. Use this to realign Token Ring packets for
304 * e.g. PCA-200E driver.
306 if (priv
->is_trdev
) {
307 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
315 #if DUMP_PACKETS >= 2
316 #define MAX_DUMP_SKB 99
317 #elif DUMP_PACKETS >= 1
318 #define MAX_DUMP_SKB 30
320 #if DUMP_PACKETS >= 1
321 printk(KERN_DEBUG
"%s: send datalen:%ld lecid:%4.4x\n",
322 dev
->name
, skb
->len
, priv
->lecid
);
323 print_hex_dump(KERN_DEBUG
, "", DUMP_OFFSET
, 16, 1,
324 skb
->data
, min(skb
->len
, MAX_DUMP_SKB
), true);
325 #endif /* DUMP_PACKETS >= 1 */
327 /* Minimum ethernet-frame size */
330 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
333 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
334 if (skb
->len
< min_frame_size
) {
335 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
336 skb2
= skb_copy_expand(skb
, 0,
337 min_frame_size
- skb
->truesize
,
341 dev
->stats
.tx_dropped
++;
346 skb_put(skb
, min_frame_size
- skb
->len
);
349 /* Send to right vcc */
353 if (priv
->is_trdev
) {
354 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
362 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
363 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
364 dev
->name
, vcc
, vcc
? vcc
->flags
: 0, entry
);
365 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
366 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
367 pr_debug("%s:queuing packet, MAC address %pM\n",
368 dev
->name
, lec_h
->h_dest
);
369 skb_queue_tail(&entry
->tx_wait
, skb
);
371 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
372 dev
->name
, lec_h
->h_dest
);
373 dev
->stats
.tx_dropped
++;
379 printk(KERN_DEBUG
"%s:sending to vpi:%d vci:%d\n",
380 dev
->name
, vcc
->vpi
, vcc
->vci
);
381 #endif /* DUMP_PACKETS > 0 */
383 while (entry
&& (skb2
= skb_dequeue(&entry
->tx_wait
))) {
384 pr_debug("emptying tx queue, MAC address %pM\n", lec_h
->h_dest
);
390 if (!atm_may_send(vcc
, 0)) {
391 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
394 netif_stop_queue(dev
);
397 * vcc->pop() might have occurred in between, making
398 * the vcc usuable again. Since xmit is serialized,
399 * this is the only situation we have to re-test.
402 if (atm_may_send(vcc
, 0))
403 netif_wake_queue(dev
);
409 dev
->trans_start
= jiffies
;
413 /* The inverse routine to net_open(). */
414 static int lec_close(struct net_device
*dev
)
416 netif_stop_queue(dev
);
420 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
423 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
424 struct lec_priv
*priv
= netdev_priv(dev
);
425 struct atmlec_msg
*mesg
;
426 struct lec_arp_table
*entry
;
428 char *tmp
; /* FIXME */
430 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
431 mesg
= (struct atmlec_msg
*)skb
->data
;
433 tmp
+= sizeof(struct atmlec_msg
);
434 pr_debug("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
435 switch (mesg
->type
) {
437 for (i
= 0; i
< 6; i
++)
438 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
441 for (i
= 0; i
< 6; i
++)
442 dev
->dev_addr
[i
] = 0;
445 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
446 mesg
->content
.normal
.flag
);
448 case l_topology_change
:
449 priv
->topology_change
= mesg
->content
.normal
.flag
;
451 case l_flush_complete
:
452 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
454 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
455 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
456 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
457 lec_arp_remove(priv
, entry
);
458 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
460 if (mesg
->content
.normal
.no_source_le_narp
)
464 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
465 mesg
->content
.normal
.atm_addr
,
466 mesg
->content
.normal
.flag
,
467 mesg
->content
.normal
.targetless_le_arp
);
468 pr_debug("in l_arp_update\n");
469 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
470 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
472 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
473 tmp
, mesg
->sizeoftlvs
);
477 priv
->maximum_unknown_frame_count
=
478 mesg
->content
.config
.maximum_unknown_frame_count
;
479 priv
->max_unknown_frame_time
=
480 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
481 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
482 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
483 priv
->forward_delay_time
=
484 (mesg
->content
.config
.forward_delay_time
* HZ
);
485 priv
->arp_response_time
=
486 (mesg
->content
.config
.arp_response_time
* HZ
);
487 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
488 priv
->path_switching_delay
=
489 (mesg
->content
.config
.path_switching_delay
* HZ
);
490 priv
->lane_version
= mesg
->content
.config
.lane_version
;
492 priv
->lane2_ops
= NULL
;
493 if (priv
->lane_version
> 1)
494 priv
->lane2_ops
= &lane2_ops
;
495 if (dev_set_mtu(dev
, mesg
->content
.config
.mtu
))
496 pr_info("%s: change_mtu to %d failed\n",
497 dev
->name
, mesg
->content
.config
.mtu
);
498 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
500 case l_flush_tran_id
:
501 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
502 mesg
->content
.normal
.flag
);
506 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
508 case l_should_bridge
:
509 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
511 pr_debug("%s: bridge zeppelin asks about %pM\n",
512 dev
->name
, mesg
->content
.proxy
.mac_addr
);
514 if (br_fdb_test_addr_hook
== NULL
)
517 if (br_fdb_test_addr_hook(dev
, mesg
->content
.proxy
.mac_addr
)) {
518 /* hit from bridge table, send LE_ARP_RESPONSE */
519 struct sk_buff
*skb2
;
522 pr_debug("%s: entry found, responding to zeppelin\n",
524 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
527 skb2
->len
= sizeof(struct atmlec_msg
);
528 skb_copy_to_linear_data(skb2
, mesg
, sizeof(*mesg
));
529 atm_force_charge(priv
->lecd
, skb2
->truesize
);
530 sk
= sk_atm(priv
->lecd
);
531 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
532 sk
->sk_data_ready(sk
, skb2
->len
);
535 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
538 pr_info("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
546 static void lec_atm_close(struct atm_vcc
*vcc
)
549 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
550 struct lec_priv
*priv
= netdev_priv(dev
);
553 /* Do something needful? */
555 netif_stop_queue(dev
);
556 lec_arp_destroy(priv
);
558 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
559 pr_info("%s closing with messages pending\n", dev
->name
);
560 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
))) {
561 atm_return(vcc
, skb
->truesize
);
565 pr_info("%s: Shut down!\n", dev
->name
);
566 module_put(THIS_MODULE
);
569 static struct atmdev_ops lecdev_ops
= {
570 .close
= lec_atm_close
,
574 static struct atm_dev lecatm_dev
= {
577 .number
= 999, /* dummy device number */
578 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
582 * LANE2: new argument struct sk_buff *data contains
583 * the LE_ARP based TLVs introduced in the LANE2 spec
586 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
587 const unsigned char *mac_addr
, const unsigned char *atm_addr
,
588 struct sk_buff
*data
)
592 struct atmlec_msg
*mesg
;
594 if (!priv
|| !priv
->lecd
)
596 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
599 skb
->len
= sizeof(struct atmlec_msg
);
600 mesg
= (struct atmlec_msg
*)skb
->data
;
601 memset(mesg
, 0, sizeof(struct atmlec_msg
));
604 mesg
->sizeoftlvs
= data
->len
;
606 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
608 mesg
->content
.normal
.targetless_le_arp
= 1;
610 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
612 atm_force_charge(priv
->lecd
, skb
->truesize
);
613 sk
= sk_atm(priv
->lecd
);
614 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
615 sk
->sk_data_ready(sk
, skb
->len
);
618 pr_debug("about to send %d bytes of data\n", data
->len
);
619 atm_force_charge(priv
->lecd
, data
->truesize
);
620 skb_queue_tail(&sk
->sk_receive_queue
, data
);
621 sk
->sk_data_ready(sk
, skb
->len
);
627 /* shamelessly stolen from drivers/net/net_init.c */
628 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
630 if ((new_mtu
< 68) || (new_mtu
> 18190))
636 static void lec_set_multicast_list(struct net_device
*dev
)
639 * by default, all multicast frames arrive over the bus.
640 * eventually support selective multicast service
645 static const struct net_device_ops lec_netdev_ops
= {
646 .ndo_open
= lec_open
,
647 .ndo_stop
= lec_close
,
648 .ndo_start_xmit
= lec_start_xmit
,
649 .ndo_change_mtu
= lec_change_mtu
,
650 .ndo_tx_timeout
= lec_tx_timeout
,
651 .ndo_set_multicast_list
= lec_set_multicast_list
,
654 static const unsigned char lec_ctrl_magic
[] = {
661 #define LEC_DATA_DIRECT_8023 2
662 #define LEC_DATA_DIRECT_8025 3
664 static int lec_is_data_direct(struct atm_vcc
*vcc
)
666 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
667 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
670 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
673 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
674 struct lec_priv
*priv
= netdev_priv(dev
);
677 printk(KERN_DEBUG
"%s: vcc vpi:%d vci:%d\n",
678 dev
->name
, vcc
->vpi
, vcc
->vci
);
681 pr_debug("%s: null skb\n", dev
->name
);
682 lec_vcc_close(priv
, vcc
);
685 #if DUMP_PACKETS >= 2
686 #define MAX_SKB_DUMP 99
687 #elif DUMP_PACKETS >= 1
688 #define MAX_SKB_DUMP 30
691 printk(KERN_DEBUG
"%s: rcv datalen:%ld lecid:%4.4x\n",
692 dev
->name
, skb
->len
, priv
->lecid
);
693 print_hex_dump(KERN_DEBUG
, "", DUMP_OFFSET
, 16, 1,
694 skb
->data
, min(MAX_SKB_DUMP
, skb
->len
), true);
695 #endif /* DUMP_PACKETS > 0 */
696 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) {
697 /* Control frame, to daemon */
698 struct sock
*sk
= sk_atm(vcc
);
700 pr_debug("%s: To daemon\n", dev
->name
);
701 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
702 sk
->sk_data_ready(sk
, skb
->len
);
703 } else { /* Data frame, queue to protocol handlers */
704 struct lec_arp_table
*entry
;
705 unsigned char *src
, *dst
;
707 atm_return(vcc
, skb
->truesize
);
708 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
709 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
711 * Probably looping back, or if lecd is missing,
714 pr_debug("Ignoring frame...\n");
720 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
723 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
726 * If this is a Data Direct VCC, and the VCC does not match
727 * the LE_ARP cache entry, delete the LE_ARP cache entry.
729 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
730 if (lec_is_data_direct(vcc
)) {
734 ((struct lecdatahdr_8025
*)skb
->data
)->
739 ((struct lecdatahdr_8023
*)skb
->data
)->
741 entry
= lec_arp_find(priv
, src
);
742 if (entry
&& entry
->vcc
!= vcc
) {
743 lec_arp_remove(priv
, entry
);
747 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
749 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
750 !priv
->is_proxy
&& /* Proxy wants all the packets */
751 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
755 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
756 lec_arp_check_empties(priv
, vcc
, skb
);
757 skb_pull(skb
, 2); /* skip lec_id */
760 skb
->protocol
= tr_type_trans(skb
, dev
);
763 skb
->protocol
= eth_type_trans(skb
, dev
);
764 dev
->stats
.rx_packets
++;
765 dev
->stats
.rx_bytes
+= skb
->len
;
766 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
771 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
773 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
774 struct net_device
*dev
= skb
->dev
;
777 pr_info("vpriv = NULL!?!?!?\n");
781 vpriv
->old_pop(vcc
, skb
);
783 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
785 if (netif_running(dev
) && netif_queue_stopped(dev
))
786 netif_wake_queue(dev
);
790 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
792 struct lec_vcc_priv
*vpriv
;
794 struct atmlec_ioc ioc_data
;
796 /* Lecd must be up in this case */
797 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
799 pr_info("copy from user failed for %d bytes\n", bytes_left
);
800 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
801 !dev_lec
[ioc_data
.dev_num
])
803 vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
);
807 vpriv
->old_pop
= vcc
->pop
;
808 vcc
->user_back
= vpriv
;
810 lec_vcc_added(netdev_priv(dev_lec
[ioc_data
.dev_num
]),
811 &ioc_data
, vcc
, vcc
->push
);
812 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
813 vcc
->push
= lec_push
;
817 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
819 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
821 vcc
->proto_data
= dev_lec
[arg
];
822 return lec_mcast_make((struct lec_priv
*)netdev_priv(dev_lec
[arg
]),
826 /* Initialize device. */
827 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
830 struct lec_priv
*priv
;
837 if (arg
>= MAX_LEC_ITF
)
839 #else /* Reserve the top NUM_TR_DEVS for TR */
840 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
847 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
850 size
= sizeof(struct lec_priv
);
853 dev_lec
[i
] = alloc_trdev(size
);
856 dev_lec
[i
] = alloc_etherdev(size
);
859 dev_lec
[i
]->netdev_ops
= &lec_netdev_ops
;
860 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
861 if (register_netdev(dev_lec
[i
])) {
862 free_netdev(dev_lec
[i
]);
866 priv
= netdev_priv(dev_lec
[i
]);
867 priv
->is_trdev
= is_trdev
;
869 priv
= netdev_priv(dev_lec
[i
]);
874 priv
->itfnum
= i
; /* LANE2 addition */
876 vcc
->dev
= &lecatm_dev
;
877 vcc_insert_socket(sk_atm(vcc
));
879 vcc
->proto_data
= dev_lec
[i
];
880 set_bit(ATM_VF_META
, &vcc
->flags
);
881 set_bit(ATM_VF_READY
, &vcc
->flags
);
883 /* Set default values to these variables */
884 priv
->maximum_unknown_frame_count
= 1;
885 priv
->max_unknown_frame_time
= (1 * HZ
);
886 priv
->vcc_timeout_period
= (1200 * HZ
);
887 priv
->max_retry_count
= 1;
888 priv
->aging_time
= (300 * HZ
);
889 priv
->forward_delay_time
= (15 * HZ
);
890 priv
->topology_change
= 0;
891 priv
->arp_response_time
= (1 * HZ
);
892 priv
->flush_timeout
= (4 * HZ
);
893 priv
->path_switching_delay
= (6 * HZ
);
895 if (dev_lec
[i
]->flags
& IFF_UP
)
896 netif_start_queue(dev_lec
[i
]);
897 __module_get(THIS_MODULE
);
901 #ifdef CONFIG_PROC_FS
902 static const char *lec_arp_get_status_string(unsigned char status
)
904 static const char *const lec_arp_status_string
[] = {
909 "ESI_FLUSH_PENDING ",
913 if (status
> ESI_FORWARD_DIRECT
)
914 status
= 3; /* ESI_UNDEFINED */
915 return lec_arp_status_string
[status
];
918 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
922 for (i
= 0; i
< ETH_ALEN
; i
++)
923 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
924 seq_printf(seq
, " ");
925 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
926 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
927 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
928 entry
->flags
& 0xffff);
930 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
932 seq_printf(seq
, " ");
933 if (entry
->recv_vcc
) {
934 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
935 entry
->recv_vcc
->vci
);
942 struct lec_priv
*locked
;
943 struct hlist_node
*node
;
944 struct net_device
*dev
;
950 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
953 struct hlist_node
*e
= state
->node
;
954 struct lec_arp_table
*tmp
;
958 if (e
== SEQ_START_TOKEN
) {
963 hlist_for_each_entry_from(tmp
, e
, next
) {
969 return (*l
< 0) ? state
: NULL
;
972 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
973 struct lec_priv
*priv
)
978 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
979 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
983 state
->arp_table
= p
;
987 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
988 struct lec_priv
*priv
)
990 struct hlist_head
*lec_misc_tables
[] = {
991 &priv
->lec_arp_empty_ones
,
992 &priv
->lec_no_forward
,
998 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
999 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1003 state
->misc_table
= q
;
1007 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1008 struct lec_priv
*priv
)
1010 if (!state
->locked
) {
1011 state
->locked
= priv
;
1012 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1014 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1015 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1016 state
->locked
= NULL
;
1017 /* Partial state reset for the next time we get called */
1018 state
->arp_table
= state
->misc_table
= 0;
1020 return state
->locked
;
1023 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1025 struct net_device
*dev
;
1028 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1029 v
= (dev
&& netdev_priv(dev
)) ?
1030 lec_priv_walk(state
, l
, netdev_priv(dev
)) : NULL
;
1033 /* Partial state reset for the next time we get called */
1040 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1044 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1045 v
= lec_itf_walk(state
, &l
);
1052 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1054 struct lec_state
*state
= seq
->private;
1058 state
->locked
= NULL
;
1059 state
->arp_table
= 0;
1060 state
->misc_table
= 0;
1061 state
->node
= SEQ_START_TOKEN
;
1063 return *pos
? lec_get_idx(state
, *pos
) : SEQ_START_TOKEN
;
1066 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1068 struct lec_state
*state
= seq
->private;
1071 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1073 dev_put(state
->dev
);
1077 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1079 struct lec_state
*state
= seq
->private;
1081 v
= lec_get_idx(state
, 1);
1082 *pos
+= !!PTR_ERR(v
);
1086 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1088 static const char lec_banner
[] =
1089 "Itf MAC ATM destination"
1091 "VPI/VCI Recv VPI/VCI\n";
1093 if (v
== SEQ_START_TOKEN
)
1094 seq_puts(seq
, lec_banner
);
1096 struct lec_state
*state
= seq
->private;
1097 struct net_device
*dev
= state
->dev
;
1098 struct lec_arp_table
*entry
= hlist_entry(state
->node
,
1099 struct lec_arp_table
,
1102 seq_printf(seq
, "%s ", dev
->name
);
1103 lec_info(seq
, entry
);
1108 static const struct seq_operations lec_seq_ops
= {
1109 .start
= lec_seq_start
,
1110 .next
= lec_seq_next
,
1111 .stop
= lec_seq_stop
,
1112 .show
= lec_seq_show
,
1115 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1117 return seq_open_private(file
, &lec_seq_ops
, sizeof(struct lec_state
));
1120 static const struct file_operations lec_seq_fops
= {
1121 .owner
= THIS_MODULE
,
1122 .open
= lec_seq_open
,
1124 .llseek
= seq_lseek
,
1125 .release
= seq_release_private
,
1129 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1131 struct atm_vcc
*vcc
= ATM_SD(sock
);
1138 if (!capable(CAP_NET_ADMIN
))
1142 return -ENOIOCTLCMD
;
1147 err
= lecd_attach(vcc
, (int)arg
);
1149 sock
->state
= SS_CONNECTED
;
1152 err
= lec_mcast_attach(vcc
, (int)arg
);
1155 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1162 static struct atm_ioctl lane_ioctl_ops
= {
1163 .owner
= THIS_MODULE
,
1164 .ioctl
= lane_ioctl
,
1167 static int __init
lane_module_init(void)
1169 #ifdef CONFIG_PROC_FS
1170 struct proc_dir_entry
*p
;
1172 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1174 pr_err("Unable to initialize /proc/net/atm/lec\n");
1179 register_atm_ioctl(&lane_ioctl_ops
);
1180 pr_info("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1184 static void __exit
lane_module_cleanup(void)
1187 struct lec_priv
*priv
;
1189 remove_proc_entry("lec", atm_proc_root
);
1191 deregister_atm_ioctl(&lane_ioctl_ops
);
1193 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1194 if (dev_lec
[i
] != NULL
) {
1195 priv
= netdev_priv(dev_lec
[i
]);
1196 unregister_netdev(dev_lec
[i
]);
1197 free_netdev(dev_lec
[i
]);
1205 module_init(lane_module_init
);
1206 module_exit(lane_module_cleanup
);
1209 * LANE2: 3.1.3, LE_RESOLVE.request
1210 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1211 * If sizeoftlvs == NULL the default TLVs associated with with this
1213 * If dst_mac == NULL, targetless LE_ARP will be sent
1215 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
1216 u8
**tlvs
, u32
*sizeoftlvs
)
1218 unsigned long flags
;
1219 struct lec_priv
*priv
= netdev_priv(dev
);
1220 struct lec_arp_table
*table
;
1221 struct sk_buff
*skb
;
1225 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1226 table
= lec_arp_find(priv
, dst_mac
);
1227 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1231 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1235 *sizeoftlvs
= table
->sizeoftlvs
;
1240 if (sizeoftlvs
== NULL
)
1241 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1244 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1247 skb
->len
= *sizeoftlvs
;
1248 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1249 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1255 * LANE2: 3.1.4, LE_ASSOCIATE.request
1256 * Associate the *tlvs with the *lan_dst address.
1257 * Will overwrite any previous association
1258 * Returns 1 for success, 0 for failure (out of memory)
1261 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
1262 const u8
*tlvs
, u32 sizeoftlvs
)
1265 struct sk_buff
*skb
;
1266 struct lec_priv
*priv
= netdev_priv(dev
);
1268 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1269 return 0; /* not our mac address */
1271 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1273 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1274 if (priv
->tlvs
== NULL
)
1276 priv
->sizeoftlvs
= sizeoftlvs
;
1278 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1281 skb
->len
= sizeoftlvs
;
1282 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1283 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1285 pr_info("lec.c: lane2_associate_req() failed\n");
1287 * If the previous association has changed we must
1288 * somehow notify other LANE entities about the change
1294 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1297 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_addr
,
1298 const u8
*tlvs
, u32 sizeoftlvs
)
1303 struct lec_priv
*priv
= netdev_priv(dev
);
1305 * Why have the TLVs in LE_ARP entries
1306 * since we do not use them? When you
1307 * uncomment this code, make sure the
1308 * TLVs get freed when entry is killed
1310 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1313 return; /* should not happen */
1317 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1318 if (entry
->tlvs
== NULL
)
1320 entry
->sizeoftlvs
= sizeoftlvs
;
1324 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1325 while (i
< sizeoftlvs
)
1326 pr_cont("%02x ", tlvs
[i
++]);
1331 /* tell MPOA about the TLVs we saw */
1332 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1333 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1340 * Here starts what used to lec_arpc.c
1342 * lec_arpc.c was added here when making
1343 * lane client modular. October 1997
1346 #include <linux/types.h>
1347 #include <linux/timer.h>
1348 #include <linux/param.h>
1349 #include <asm/atomic.h>
1350 #include <linux/inetdevice.h>
1351 #include <net/route.h>
1354 #define pr_debug(format, args...)
1356 #define pr_debug printk
1359 #define DEBUG_ARP_TABLE 0
1361 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1363 static void lec_arp_check_expire(struct work_struct
*work
);
1364 static void lec_arp_expire_arp(unsigned long data
);
1370 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
1373 * Initialization of arp-cache
1375 static void lec_arp_init(struct lec_priv
*priv
)
1379 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
1380 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1381 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1382 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1383 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1384 spin_lock_init(&priv
->lec_arp_lock
);
1385 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1386 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1389 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1392 struct atm_vcc
*vcc
= entry
->vcc
;
1393 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1394 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1396 vcc
->pop
= vpriv
->old_pop
;
1398 netif_wake_queue(dev
);
1400 vcc
->user_back
= NULL
;
1401 vcc
->push
= entry
->old_push
;
1402 vcc_release_async(vcc
, -EPIPE
);
1405 if (entry
->recv_vcc
) {
1406 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1407 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1408 entry
->recv_vcc
= NULL
;
1413 * Insert entry to lec_arp_table
1414 * LANE2: Add to the end of the list to satisfy 8.1.13
1417 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1419 struct hlist_head
*tmp
;
1421 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1422 hlist_add_head(&entry
->next
, tmp
);
1424 pr_debug("Added entry:%pM\n", entry
->mac_addr
);
1428 * Remove entry from lec_arp_table
1431 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1433 struct hlist_node
*node
;
1434 struct lec_arp_table
*entry
;
1435 int i
, remove_vcc
= 1;
1440 hlist_del(&to_remove
->next
);
1441 del_timer(&to_remove
->timer
);
1444 * If this is the only MAC connected to this VCC,
1445 * also tear down the VCC
1447 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1449 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1451 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1452 hlist_for_each_entry(entry
, node
,
1453 &priv
->lec_arp_tables
[i
], next
) {
1454 if (memcmp(to_remove
->atm_addr
,
1455 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1462 lec_arp_clear_vccs(to_remove
);
1464 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1466 pr_debug("Removed entry:%pM\n", to_remove
->mac_addr
);
1471 static const char *get_status_string(unsigned char st
)
1475 return "ESI_UNKNOWN";
1476 case ESI_ARP_PENDING
:
1477 return "ESI_ARP_PENDING";
1478 case ESI_VC_PENDING
:
1479 return "ESI_VC_PENDING";
1480 case ESI_FLUSH_PENDING
:
1481 return "ESI_FLUSH_PENDING";
1482 case ESI_FORWARD_DIRECT
:
1483 return "ESI_FORWARD_DIRECT";
1488 static void dump_arp_table(struct lec_priv
*priv
)
1490 struct hlist_node
*node
;
1491 struct lec_arp_table
*rulla
;
1495 pr_info("Dump %p:\n", priv
);
1496 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1497 hlist_for_each_entry(rulla
, node
,
1498 &priv
->lec_arp_tables
[i
], next
) {
1500 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1501 offset
+= sprintf(buf
+ offset
, "Mac: %pM",
1503 offset
+= sprintf(buf
+ offset
, " Atm:");
1504 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1505 offset
+= sprintf(buf
+ offset
,
1507 rulla
->atm_addr
[j
] & 0xff);
1509 offset
+= sprintf(buf
+ offset
,
1510 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1511 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1512 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1513 rulla
->recv_vcc
? rulla
->recv_vcc
->
1515 rulla
->recv_vcc
? rulla
->recv_vcc
->
1516 vci
: 0, rulla
->last_used
,
1517 rulla
->timestamp
, rulla
->no_tries
);
1519 sprintf(buf
+ offset
,
1520 "Flags:%x, Packets_flooded:%x, Status: %s ",
1521 rulla
->flags
, rulla
->packets_flooded
,
1522 get_status_string(rulla
->status
));
1523 pr_info("%s\n", buf
);
1527 if (!hlist_empty(&priv
->lec_no_forward
))
1528 pr_info("No forward\n");
1529 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1531 offset
+= sprintf(buf
+ offset
, "Mac: %pM", rulla
->mac_addr
);
1532 offset
+= sprintf(buf
+ offset
, " Atm:");
1533 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1534 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1535 rulla
->atm_addr
[j
] & 0xff);
1537 offset
+= sprintf(buf
+ offset
,
1538 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1539 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1540 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1541 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1542 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1544 rulla
->timestamp
, rulla
->no_tries
);
1545 offset
+= sprintf(buf
+ offset
,
1546 "Flags:%x, Packets_flooded:%x, Status: %s ",
1547 rulla
->flags
, rulla
->packets_flooded
,
1548 get_status_string(rulla
->status
));
1549 pr_info("%s\n", buf
);
1552 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1553 pr_info("Empty ones\n");
1554 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1556 offset
+= sprintf(buf
+ offset
, "Mac: %pM", rulla
->mac_addr
);
1557 offset
+= sprintf(buf
+ offset
, " Atm:");
1558 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1559 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1560 rulla
->atm_addr
[j
] & 0xff);
1562 offset
+= sprintf(buf
+ offset
,
1563 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1564 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1565 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1566 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1567 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1569 rulla
->timestamp
, rulla
->no_tries
);
1570 offset
+= sprintf(buf
+ offset
,
1571 "Flags:%x, Packets_flooded:%x, Status: %s ",
1572 rulla
->flags
, rulla
->packets_flooded
,
1573 get_status_string(rulla
->status
));
1577 if (!hlist_empty(&priv
->mcast_fwds
))
1578 pr_info("Multicast Forward VCCs\n");
1579 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1581 offset
+= sprintf(buf
+ offset
, "Mac: %pM", rulla
->mac_addr
);
1582 offset
+= sprintf(buf
+ offset
, " Atm:");
1583 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1584 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1585 rulla
->atm_addr
[j
] & 0xff);
1587 offset
+= sprintf(buf
+ offset
,
1588 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1589 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1590 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1591 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1592 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1594 rulla
->timestamp
, rulla
->no_tries
);
1595 offset
+= sprintf(buf
+ offset
,
1596 "Flags:%x, Packets_flooded:%x, Status: %s ",
1597 rulla
->flags
, rulla
->packets_flooded
,
1598 get_status_string(rulla
->status
));
1599 pr_info("%s\n", buf
);
1604 #define dump_arp_table(priv) do { } while (0)
1608 * Destruction of arp-cache
1610 static void lec_arp_destroy(struct lec_priv
*priv
)
1612 unsigned long flags
;
1613 struct hlist_node
*node
, *next
;
1614 struct lec_arp_table
*entry
;
1617 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1620 * Remove all entries
1623 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1624 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1625 hlist_for_each_entry_safe(entry
, node
, next
,
1626 &priv
->lec_arp_tables
[i
], next
) {
1627 lec_arp_remove(priv
, entry
);
1630 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1633 hlist_for_each_entry_safe(entry
, node
, next
,
1634 &priv
->lec_arp_empty_ones
, next
) {
1635 del_timer_sync(&entry
->timer
);
1636 lec_arp_clear_vccs(entry
);
1637 hlist_del(&entry
->next
);
1640 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1642 hlist_for_each_entry_safe(entry
, node
, next
,
1643 &priv
->lec_no_forward
, next
) {
1644 del_timer_sync(&entry
->timer
);
1645 lec_arp_clear_vccs(entry
);
1646 hlist_del(&entry
->next
);
1649 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1651 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1652 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1653 lec_arp_clear_vccs(entry
);
1654 hlist_del(&entry
->next
);
1657 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1658 priv
->mcast_vcc
= NULL
;
1659 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1663 * Find entry by mac_address
1665 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1666 const unsigned char *mac_addr
)
1668 struct hlist_node
*node
;
1669 struct hlist_head
*head
;
1670 struct lec_arp_table
*entry
;
1672 pr_debug("%pM\n", mac_addr
);
1674 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1675 hlist_for_each_entry(entry
, node
, head
, next
) {
1676 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
))
1682 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1683 const unsigned char *mac_addr
)
1685 struct lec_arp_table
*to_return
;
1687 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1689 pr_info("LEC: Arp entry kmalloc failed\n");
1692 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1693 INIT_HLIST_NODE(&to_return
->next
);
1694 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1695 (unsigned long)to_return
);
1696 to_return
->last_used
= jiffies
;
1697 to_return
->priv
= priv
;
1698 skb_queue_head_init(&to_return
->tx_wait
);
1699 atomic_set(&to_return
->usage
, 1);
1703 /* Arp sent timer expired */
1704 static void lec_arp_expire_arp(unsigned long data
)
1706 struct lec_arp_table
*entry
;
1708 entry
= (struct lec_arp_table
*)data
;
1711 if (entry
->status
== ESI_ARP_PENDING
) {
1712 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1713 if (entry
->is_rdesc
)
1714 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1715 entry
->mac_addr
, NULL
, NULL
);
1717 send_to_lecd(entry
->priv
, l_arp_xmt
,
1718 entry
->mac_addr
, NULL
, NULL
);
1721 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1725 /* Unknown/unused vcc expire, remove associated entry */
1726 static void lec_arp_expire_vcc(unsigned long data
)
1728 unsigned long flags
;
1729 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1730 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1732 del_timer(&to_remove
->timer
);
1734 pr_debug("%p %p: vpi:%d vci:%d\n",
1736 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1737 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1739 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1740 hlist_del(&to_remove
->next
);
1741 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1743 lec_arp_clear_vccs(to_remove
);
1744 lec_arp_put(to_remove
);
1747 static bool __lec_arp_check_expire(struct lec_arp_table
*entry
,
1749 struct lec_priv
*priv
)
1751 unsigned long time_to_check
;
1753 if ((entry
->flags
) & LEC_REMOTE_FLAG
&& priv
->topology_change
)
1754 time_to_check
= priv
->forward_delay_time
;
1756 time_to_check
= priv
->aging_time
;
1758 pr_debug("About to expire: %lx - %lx > %lx\n",
1759 now
, entry
->last_used
, time_to_check
);
1760 if (time_after(now
, entry
->last_used
+ time_to_check
) &&
1761 !(entry
->flags
& LEC_PERMANENT_FLAG
) &&
1762 !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1764 pr_debug("Entry timed out\n");
1765 lec_arp_remove(priv
, entry
);
1768 /* Something else */
1769 if ((entry
->status
== ESI_VC_PENDING
||
1770 entry
->status
== ESI_ARP_PENDING
) &&
1771 time_after_eq(now
, entry
->timestamp
+
1772 priv
->max_unknown_frame_time
)) {
1773 entry
->timestamp
= jiffies
;
1774 entry
->packets_flooded
= 0;
1775 if (entry
->status
== ESI_VC_PENDING
)
1776 send_to_lecd(priv
, l_svc_setup
,
1781 if (entry
->status
== ESI_FLUSH_PENDING
&&
1782 time_after_eq(now
, entry
->timestamp
+
1783 priv
->path_switching_delay
)) {
1784 lec_arp_hold(entry
);
1794 * 2. For each entry, delete entries that have aged past the age limit.
1795 * 3. For each entry, depending on the status of the entry, perform
1796 * the following maintenance.
1797 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1798 * tick_count is above the max_unknown_frame_time, clear
1799 * the tick_count to zero and clear the packets_flooded counter
1800 * to zero. This supports the packet rate limit per address
1801 * while flooding unknowns.
1802 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1803 * than or equal to the path_switching_delay, change the status
1804 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1805 * regardless of the progress of the flush protocol.
1807 static void lec_arp_check_expire(struct work_struct
*work
)
1809 unsigned long flags
;
1810 struct lec_priv
*priv
=
1811 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1812 struct hlist_node
*node
, *next
;
1813 struct lec_arp_table
*entry
;
1817 pr_debug("%p\n", priv
);
1820 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1821 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1822 hlist_for_each_entry_safe(entry
, node
, next
,
1823 &priv
->lec_arp_tables
[i
], next
) {
1824 if (__lec_arp_check_expire(entry
, now
, priv
)) {
1825 struct sk_buff
*skb
;
1826 struct atm_vcc
*vcc
= entry
->vcc
;
1828 spin_unlock_irqrestore(&priv
->lec_arp_lock
,
1830 while ((skb
= skb_dequeue(&entry
->tx_wait
)))
1832 entry
->last_used
= jiffies
;
1833 entry
->status
= ESI_FORWARD_DIRECT
;
1840 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1842 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1846 * Try to find vcc where mac_address is attached.
1849 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1850 const unsigned char *mac_to_find
,
1852 struct lec_arp_table
**ret_entry
)
1854 unsigned long flags
;
1855 struct lec_arp_table
*entry
;
1856 struct atm_vcc
*found
;
1858 if (mac_to_find
[0] & 0x01) {
1859 switch (priv
->lane_version
) {
1861 return priv
->mcast_vcc
;
1862 case 2: /* LANE2 wants arp for multicast addresses */
1863 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1864 return priv
->mcast_vcc
;
1871 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1872 entry
= lec_arp_find(priv
, mac_to_find
);
1875 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1877 entry
->last_used
= jiffies
;
1878 lec_arp_hold(entry
);
1884 * If the LE_ARP cache entry is still pending, reset count to 0
1885 * so another LE_ARP request can be made for this frame.
1887 if (entry
->status
== ESI_ARP_PENDING
)
1888 entry
->no_tries
= 0;
1890 * Data direct VC not yet set up, check to see if the unknown
1891 * frame count is greater than the limit. If the limit has
1892 * not been reached, allow the caller to send packet to
1895 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1896 entry
->packets_flooded
<
1897 priv
->maximum_unknown_frame_count
) {
1898 entry
->packets_flooded
++;
1899 pr_debug("Flooding..\n");
1900 found
= priv
->mcast_vcc
;
1904 * We got here because entry->status == ESI_FLUSH_PENDING
1905 * or BUS flood limit was reached for an entry which is
1906 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1908 lec_arp_hold(entry
);
1910 pr_debug("entry->status %d entry->vcc %p\n", entry
->status
,
1914 /* No matching entry was found */
1915 entry
= make_entry(priv
, mac_to_find
);
1916 pr_debug("Making entry\n");
1918 found
= priv
->mcast_vcc
;
1921 lec_arp_add(priv
, entry
);
1922 /* We want arp-request(s) to be sent */
1923 entry
->packets_flooded
= 1;
1924 entry
->status
= ESI_ARP_PENDING
;
1925 entry
->no_tries
= 1;
1926 entry
->last_used
= entry
->timestamp
= jiffies
;
1927 entry
->is_rdesc
= is_rdesc
;
1928 if (entry
->is_rdesc
)
1929 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
1932 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
1933 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
1934 entry
->timer
.function
= lec_arp_expire_arp
;
1935 add_timer(&entry
->timer
);
1936 found
= priv
->mcast_vcc
;
1940 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1945 lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
1946 unsigned long permanent
)
1948 unsigned long flags
;
1949 struct hlist_node
*node
, *next
;
1950 struct lec_arp_table
*entry
;
1954 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1955 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1956 hlist_for_each_entry_safe(entry
, node
, next
,
1957 &priv
->lec_arp_tables
[i
], next
) {
1958 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
) &&
1960 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
1961 lec_arp_remove(priv
, entry
);
1964 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1968 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1973 * Notifies: Response to arp_request (atm_addr != NULL)
1976 lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
1977 const unsigned char *atm_addr
, unsigned long remoteflag
,
1978 unsigned int targetless_le_arp
)
1980 unsigned long flags
;
1981 struct hlist_node
*node
, *next
;
1982 struct lec_arp_table
*entry
, *tmp
;
1985 pr_debug("%smac:%pM\n",
1986 (targetless_le_arp
) ? "targetless " : "", mac_addr
);
1988 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1989 entry
= lec_arp_find(priv
, mac_addr
);
1990 if (entry
== NULL
&& targetless_le_arp
)
1992 * LANE2: ignore targetless LE_ARPs for which
1993 * we have no entry in the cache. 7.1.30
1995 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
1996 hlist_for_each_entry_safe(entry
, node
, next
,
1997 &priv
->lec_arp_empty_ones
, next
) {
1998 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
1999 hlist_del(&entry
->next
);
2000 del_timer(&entry
->timer
);
2001 tmp
= lec_arp_find(priv
, mac_addr
);
2003 del_timer(&tmp
->timer
);
2004 tmp
->status
= ESI_FORWARD_DIRECT
;
2005 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2006 tmp
->vcc
= entry
->vcc
;
2007 tmp
->old_push
= entry
->old_push
;
2008 tmp
->last_used
= jiffies
;
2009 del_timer(&entry
->timer
);
2013 entry
->status
= ESI_FORWARD_DIRECT
;
2014 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2015 entry
->last_used
= jiffies
;
2016 lec_arp_add(priv
, entry
);
2019 entry
->flags
|= LEC_REMOTE_FLAG
;
2021 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2022 pr_debug("After update\n");
2023 dump_arp_table(priv
);
2029 entry
= lec_arp_find(priv
, mac_addr
);
2031 entry
= make_entry(priv
, mac_addr
);
2034 entry
->status
= ESI_UNKNOWN
;
2035 lec_arp_add(priv
, entry
);
2036 /* Temporary, changes before end of function */
2038 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2039 del_timer(&entry
->timer
);
2040 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2041 hlist_for_each_entry(tmp
, node
,
2042 &priv
->lec_arp_tables
[i
], next
) {
2044 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2045 /* Vcc to this host exists */
2046 if (tmp
->status
> ESI_VC_PENDING
) {
2048 * ESI_FLUSH_PENDING,
2049 * ESI_FORWARD_DIRECT
2051 entry
->vcc
= tmp
->vcc
;
2052 entry
->old_push
= tmp
->old_push
;
2054 entry
->status
= tmp
->status
;
2060 entry
->flags
|= LEC_REMOTE_FLAG
;
2062 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2063 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2064 entry
->status
= ESI_VC_PENDING
;
2065 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2067 pr_debug("After update2\n");
2068 dump_arp_table(priv
);
2070 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2074 * Notifies: Vcc setup ready
2077 lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
2078 struct atm_vcc
*vcc
,
2079 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2081 unsigned long flags
;
2082 struct hlist_node
*node
;
2083 struct lec_arp_table
*entry
;
2084 int i
, found_entry
= 0;
2086 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2087 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2088 if (ioc_data
->receive
== 2) {
2089 pr_debug("LEC_ARP: Attaching mcast forward\n");
2091 entry
= lec_arp_find(priv
, bus_mac
);
2093 pr_info("LEC_ARP: Multicast entry not found!\n");
2096 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2097 entry
->recv_vcc
= vcc
;
2098 entry
->old_recv_push
= old_push
;
2100 entry
= make_entry(priv
, bus_mac
);
2103 del_timer(&entry
->timer
);
2104 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2105 entry
->recv_vcc
= vcc
;
2106 entry
->old_recv_push
= old_push
;
2107 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2109 } else if (ioc_data
->receive
== 1) {
2111 * Vcc which we don't want to make default vcc,
2114 pr_debug("LEC_ARP:Attaching data direct, not default: %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",
2115 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2116 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2117 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2118 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2119 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2120 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2121 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2122 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2123 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2124 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2125 entry
= make_entry(priv
, bus_mac
);
2128 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2129 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2130 entry
->recv_vcc
= vcc
;
2131 entry
->old_recv_push
= old_push
;
2132 entry
->status
= ESI_UNKNOWN
;
2133 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2134 entry
->timer
.function
= lec_arp_expire_vcc
;
2135 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2136 add_timer(&entry
->timer
);
2137 dump_arp_table(priv
);
2140 pr_debug("LEC_ARP:Attaching data direct, default: %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",
2141 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2142 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2143 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2144 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2145 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2146 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2147 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2148 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2149 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2150 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2151 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2152 hlist_for_each_entry(entry
, node
,
2153 &priv
->lec_arp_tables
[i
], next
) {
2155 (ioc_data
->atm_addr
, entry
->atm_addr
,
2156 ATM_ESA_LEN
) == 0) {
2157 pr_debug("LEC_ARP: Attaching data direct\n");
2158 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2159 entry
->vcc
? entry
->vcc
->vci
: 0,
2160 entry
->recv_vcc
? entry
->recv_vcc
->
2163 del_timer(&entry
->timer
);
2165 entry
->old_push
= old_push
;
2166 if (entry
->status
== ESI_VC_PENDING
) {
2167 if (priv
->maximum_unknown_frame_count
2172 entry
->timestamp
= jiffies
;
2176 send_to_lecd(priv
, l_flush_xmt
,
2184 * They were forming a connection
2185 * to us, and we to them. Our
2186 * ATM address is numerically lower
2187 * than theirs, so we make connection
2188 * we formed into default VCC (8.1.11).
2189 * Connection they made gets torn
2190 * down. This might confuse some
2191 * clients. Can be changed if
2192 * someone reports trouble...
2200 pr_debug("After vcc was added\n");
2201 dump_arp_table(priv
);
2205 * Not found, snatch address from first data packet that arrives
2208 entry
= make_entry(priv
, bus_mac
);
2212 entry
->old_push
= old_push
;
2213 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2214 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2215 entry
->status
= ESI_UNKNOWN
;
2216 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2217 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2218 entry
->timer
.function
= lec_arp_expire_vcc
;
2219 add_timer(&entry
->timer
);
2220 pr_debug("After vcc was added\n");
2221 dump_arp_table(priv
);
2223 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2226 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2228 unsigned long flags
;
2229 struct hlist_node
*node
;
2230 struct lec_arp_table
*entry
;
2233 pr_debug("%lx\n", tran_id
);
2235 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2236 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2237 hlist_for_each_entry(entry
, node
,
2238 &priv
->lec_arp_tables
[i
], next
) {
2239 if (entry
->flush_tran_id
== tran_id
&&
2240 entry
->status
== ESI_FLUSH_PENDING
) {
2241 struct sk_buff
*skb
;
2242 struct atm_vcc
*vcc
= entry
->vcc
;
2244 lec_arp_hold(entry
);
2245 spin_unlock_irqrestore(&priv
->lec_arp_lock
,
2247 while ((skb
= skb_dequeue(&entry
->tx_wait
)))
2249 entry
->last_used
= jiffies
;
2250 entry
->status
= ESI_FORWARD_DIRECT
;
2252 pr_debug("LEC_ARP: Flushed\n");
2257 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2258 dump_arp_table(priv
);
2262 lec_set_flush_tran_id(struct lec_priv
*priv
,
2263 const unsigned char *atm_addr
, unsigned long tran_id
)
2265 unsigned long flags
;
2266 struct hlist_node
*node
;
2267 struct lec_arp_table
*entry
;
2270 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2271 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2272 hlist_for_each_entry(entry
, node
,
2273 &priv
->lec_arp_tables
[i
], next
) {
2274 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2275 entry
->flush_tran_id
= tran_id
;
2276 pr_debug("Set flush transaction id to %lx for %p\n",
2280 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2283 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2285 unsigned long flags
;
2286 unsigned char mac_addr
[] = {
2287 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2289 struct lec_arp_table
*to_add
;
2290 struct lec_vcc_priv
*vpriv
;
2293 vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
);
2297 vpriv
->old_pop
= vcc
->pop
;
2298 vcc
->user_back
= vpriv
;
2300 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2301 to_add
= make_entry(priv
, mac_addr
);
2303 vcc
->pop
= vpriv
->old_pop
;
2308 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2309 to_add
->status
= ESI_FORWARD_DIRECT
;
2310 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2312 to_add
->old_push
= vcc
->push
;
2313 vcc
->push
= lec_push
;
2314 priv
->mcast_vcc
= vcc
;
2315 lec_arp_add(priv
, to_add
);
2317 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2321 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2323 unsigned long flags
;
2324 struct hlist_node
*node
, *next
;
2325 struct lec_arp_table
*entry
;
2328 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2329 dump_arp_table(priv
);
2331 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2333 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2334 hlist_for_each_entry_safe(entry
, node
, next
,
2335 &priv
->lec_arp_tables
[i
], next
) {
2336 if (vcc
== entry
->vcc
) {
2337 lec_arp_remove(priv
, entry
);
2339 if (priv
->mcast_vcc
== vcc
)
2340 priv
->mcast_vcc
= NULL
;
2345 hlist_for_each_entry_safe(entry
, node
, next
,
2346 &priv
->lec_arp_empty_ones
, next
) {
2347 if (entry
->vcc
== vcc
) {
2348 lec_arp_clear_vccs(entry
);
2349 del_timer(&entry
->timer
);
2350 hlist_del(&entry
->next
);
2355 hlist_for_each_entry_safe(entry
, node
, next
,
2356 &priv
->lec_no_forward
, next
) {
2357 if (entry
->recv_vcc
== vcc
) {
2358 lec_arp_clear_vccs(entry
);
2359 del_timer(&entry
->timer
);
2360 hlist_del(&entry
->next
);
2365 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2366 if (entry
->recv_vcc
== vcc
) {
2367 lec_arp_clear_vccs(entry
);
2368 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2369 hlist_del(&entry
->next
);
2374 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2375 dump_arp_table(priv
);
2379 lec_arp_check_empties(struct lec_priv
*priv
,
2380 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2382 unsigned long flags
;
2383 struct hlist_node
*node
, *next
;
2384 struct lec_arp_table
*entry
, *tmp
;
2385 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2388 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2391 src
= tr_hdr
->h_source
;
2394 src
= hdr
->h_source
;
2396 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2397 hlist_for_each_entry_safe(entry
, node
, next
,
2398 &priv
->lec_arp_empty_ones
, next
) {
2399 if (vcc
== entry
->vcc
) {
2400 del_timer(&entry
->timer
);
2401 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2402 entry
->status
= ESI_FORWARD_DIRECT
;
2403 entry
->last_used
= jiffies
;
2404 /* We might have got an entry */
2405 tmp
= lec_arp_find(priv
, src
);
2407 lec_arp_remove(priv
, tmp
);
2410 hlist_del(&entry
->next
);
2411 lec_arp_add(priv
, entry
);
2415 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2417 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2420 MODULE_LICENSE("GPL");