2 * lec.c: Lan Emulation driver
4 * Marko Kiiskila <mkiiskila@yahoo.com>
7 #include <linux/kernel.h>
8 #include <linux/bitops.h>
9 #include <linux/capability.h>
11 /* We are ethernet device */
12 #include <linux/if_ether.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
16 #include <linux/skbuff.h>
18 #include <asm/byteorder.h>
19 #include <asm/uaccess.h>
22 #include <linux/proc_fs.h>
23 #include <linux/spinlock.h>
24 #include <linux/seq_file.h>
26 /* TokenRing if needed */
28 #include <linux/trdevice.h>
32 #include <linux/atmdev.h>
33 #include <linux/atmlec.h>
35 /* Proxy LEC knows about bridging */
36 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37 #include <linux/if_bridge.h>
38 #include "../bridge/br_private.h"
40 static unsigned char bridge_ula_lec
[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
44 #include <linux/module.h>
45 #include <linux/init.h>
49 #include "resources.h"
51 #define DUMP_PACKETS 0 /*
57 #define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
62 static int lec_open(struct net_device
*dev
);
63 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
64 static int lec_close(struct net_device
*dev
);
65 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
);
66 static void lec_init(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
, unsigned long remoteflag
,
91 unsigned int targetless_le_arp
);
92 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
93 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
94 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
95 const unsigned char *atm_addr
,
96 unsigned long tran_id
);
97 static void lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
99 void (*old_push
) (struct atm_vcc
*vcc
,
100 struct sk_buff
*skb
));
101 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
103 /* must be done under lec_arp_lock */
104 static inline void lec_arp_hold(struct lec_arp_table
*entry
)
106 atomic_inc(&entry
->usage
);
109 static inline void lec_arp_put(struct lec_arp_table
*entry
)
111 if (atomic_dec_and_test(&entry
->usage
))
116 static struct lane2_ops lane2_ops
= {
117 lane2_resolve
, /* resolve, spec 3.1.3 */
118 lane2_associate_req
, /* associate_req, spec 3.1.4 */
119 NULL
/* associate indicator, spec 3.1.5 */
122 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
124 /* Device structures */
125 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
127 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
132 struct lec_priv
*priv
;
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
139 eth
= (struct ethhdr
*)skb
->data
;
140 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
141 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
143 struct sk_buff
*skb2
;
144 struct atmlec_msg
*mesg
;
146 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
149 skb2
->len
= sizeof(struct atmlec_msg
);
150 mesg
= (struct atmlec_msg
*)skb2
->data
;
151 mesg
->type
= l_topology_change
;
153 mesg
->content
.normal
.flag
= *buff
& 0x01; /* 0x01 is topology change */
155 priv
= netdev_priv(dev
);
156 atm_force_charge(priv
->lecd
, skb2
->truesize
);
157 sk
= sk_atm(priv
->lecd
);
158 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
159 sk
->sk_data_ready(sk
, skb2
->len
);
164 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
176 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
179 unsigned int riflen
, num_rdsc
;
181 trh
= (struct trh_hdr
*)packet
;
182 if (trh
->daddr
[0] & (uint8_t) 0x80)
183 return bus_mac
; /* multicast */
185 if (trh
->saddr
[0] & TR_RII
) {
186 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
187 if ((ntohs(trh
->rcf
) >> 13) != 0)
188 return bus_mac
; /* ARE or STE */
190 return trh
->daddr
; /* not source routed */
193 return trh
->daddr
; /* last hop, source routed */
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc
= (riflen
/ 2) - 1;
197 memset(rdesc
, 0, ETH_ALEN
);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
200 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(__be16
));
202 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(__be16
));
203 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
208 #endif /* CONFIG_TR */
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
219 static int lec_open(struct net_device
*dev
)
221 struct lec_priv
*priv
= netdev_priv(dev
);
223 netif_start_queue(dev
);
224 memset(&priv
->stats
, 0, sizeof(struct net_device_stats
));
229 static __inline__
void
230 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
, struct lec_priv
*priv
)
232 ATM_SKB(skb
)->vcc
= vcc
;
233 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
235 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
236 if (vcc
->send(vcc
, skb
) < 0) {
237 priv
->stats
.tx_dropped
++;
241 priv
->stats
.tx_packets
++;
242 priv
->stats
.tx_bytes
+= skb
->len
;
245 static void lec_tx_timeout(struct net_device
*dev
)
247 printk(KERN_INFO
"%s: tx timeout\n", dev
->name
);
248 dev
->trans_start
= jiffies
;
249 netif_wake_queue(dev
);
252 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
254 struct sk_buff
*skb2
;
255 struct lec_priv
*priv
= netdev_priv(dev
);
256 struct lecdatahdr_8023
*lec_h
;
258 struct lec_arp_table
*entry
;
262 unsigned char rdesc
[ETH_ALEN
]; /* Token Ring route descriptor */
268 #endif /* DUMP_PACKETS >0 */
270 pr_debug("lec_start_xmit called\n");
272 printk("%s:No lecd attached\n", dev
->name
);
273 priv
->stats
.tx_errors
++;
274 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) {
289 pr_debug("lec_start_xmit: reallocating skb\n");
290 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
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
);
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
307 if (priv
->is_trdev
) {
308 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
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
]);
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
]);
327 #endif /* DUMP_PACKETS >= 1 */
331 printk("%s...\n", buf
);
332 #endif /* DUMP_PACKETS > 0 */
334 /* Minimum ethernet-frame size */
337 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
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
,
348 priv
->stats
.tx_dropped
++;
353 skb_put(skb
, min_frame_size
- skb
->len
);
356 /* Send to right vcc */
360 if (priv
->is_trdev
) {
361 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
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, ",
376 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
377 skb_queue_tail(&entry
->tx_wait
, skb
);
380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
382 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
383 priv
->stats
.tx_dropped
++;
389 printk("%s:sending to vpi:%d vci:%d\n", dev
->name
, vcc
->vpi
, vcc
->vci
);
390 #endif /* DUMP_PACKETS > 0 */
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
, priv
);
398 lec_send(vcc
, skb
, priv
);
400 if (!atm_may_send(vcc
, 0)) {
401 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
404 netif_stop_queue(dev
);
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.
412 if (atm_may_send(vcc
, 0))
413 netif_wake_queue(dev
);
419 dev
->trans_start
= jiffies
;
423 /* The inverse routine to net_open(). */
424 static int lec_close(struct net_device
*dev
)
426 netif_stop_queue(dev
);
431 * Get the current statistics.
432 * This may be called with the card open or closed.
434 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
)
436 return &((struct lec_priv
*)netdev_priv(dev
))->stats
;
439 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
442 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
443 struct lec_priv
*priv
= netdev_priv(dev
);
444 struct atmlec_msg
*mesg
;
445 struct lec_arp_table
*entry
;
447 char *tmp
; /* FIXME */
449 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
450 mesg
= (struct atmlec_msg
*)skb
->data
;
452 tmp
+= sizeof(struct atmlec_msg
);
453 pr_debug("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
454 switch (mesg
->type
) {
456 for (i
= 0; i
< 6; i
++) {
457 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
461 for (i
= 0; i
< 6; i
++) {
462 dev
->dev_addr
[i
] = 0;
466 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
467 mesg
->content
.normal
.flag
);
469 case l_topology_change
:
470 priv
->topology_change
= mesg
->content
.normal
.flag
;
472 case l_flush_complete
:
473 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
475 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
476 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
477 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
478 lec_arp_remove(priv
, entry
);
479 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
481 if (mesg
->content
.normal
.no_source_le_narp
)
485 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
486 mesg
->content
.normal
.atm_addr
,
487 mesg
->content
.normal
.flag
,
488 mesg
->content
.normal
.targetless_le_arp
);
489 pr_debug("lec: in l_arp_update\n");
490 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
491 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
493 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
494 tmp
, mesg
->sizeoftlvs
);
498 priv
->maximum_unknown_frame_count
=
499 mesg
->content
.config
.maximum_unknown_frame_count
;
500 priv
->max_unknown_frame_time
=
501 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
502 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
503 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
504 priv
->forward_delay_time
=
505 (mesg
->content
.config
.forward_delay_time
* HZ
);
506 priv
->arp_response_time
=
507 (mesg
->content
.config
.arp_response_time
* HZ
);
508 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
509 priv
->path_switching_delay
=
510 (mesg
->content
.config
.path_switching_delay
* HZ
);
511 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
512 priv
->lane2_ops
= NULL
;
513 if (priv
->lane_version
> 1)
514 priv
->lane2_ops
= &lane2_ops
;
515 if (dev
->change_mtu(dev
, mesg
->content
.config
.mtu
))
516 printk("%s: change_mtu to %d failed\n", dev
->name
,
517 mesg
->content
.config
.mtu
);
518 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
520 case l_flush_tran_id
:
521 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
522 mesg
->content
.normal
.flag
);
526 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
528 case l_should_bridge
:
529 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
531 struct net_bridge_fdb_entry
*f
;
533 pr_debug("%s: bridge zeppelin asks about %pM\n",
534 dev
->name
, mesg
->content
.proxy
.mac_addr
);
536 if (br_fdb_get_hook
== NULL
|| dev
->br_port
== NULL
)
539 f
= br_fdb_get_hook(dev
->br_port
->br
,
540 mesg
->content
.proxy
.mac_addr
);
541 if (f
!= NULL
&& f
->dst
->dev
!= dev
542 && f
->dst
->state
== BR_STATE_FORWARDING
) {
543 /* hit from bridge table, send LE_ARP_RESPONSE */
544 struct sk_buff
*skb2
;
548 ("%s: entry found, responding to zeppelin\n",
551 alloc_skb(sizeof(struct atmlec_msg
),
557 skb2
->len
= sizeof(struct atmlec_msg
);
558 skb_copy_to_linear_data(skb2
, mesg
,
560 atm_force_charge(priv
->lecd
, skb2
->truesize
);
561 sk
= sk_atm(priv
->lecd
);
562 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
563 sk
->sk_data_ready(sk
, skb2
->len
);
568 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
571 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
579 static void lec_atm_close(struct atm_vcc
*vcc
)
582 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
583 struct lec_priv
*priv
= netdev_priv(dev
);
586 /* Do something needful? */
588 netif_stop_queue(dev
);
589 lec_arp_destroy(priv
);
591 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
592 printk("%s lec_atm_close: closing with messages pending\n",
594 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
595 atm_return(vcc
, skb
->truesize
);
599 printk("%s: Shut down!\n", dev
->name
);
600 module_put(THIS_MODULE
);
603 static struct atmdev_ops lecdev_ops
= {
604 .close
= lec_atm_close
,
608 static struct atm_dev lecatm_dev
= {
611 .number
= 999, /* dummy device number */
612 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
616 * LANE2: new argument struct sk_buff *data contains
617 * the LE_ARP based TLVs introduced in the LANE2 spec
620 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
621 const unsigned char *mac_addr
, const unsigned char *atm_addr
,
622 struct sk_buff
*data
)
626 struct atmlec_msg
*mesg
;
628 if (!priv
|| !priv
->lecd
) {
631 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
634 skb
->len
= sizeof(struct atmlec_msg
);
635 mesg
= (struct atmlec_msg
*)skb
->data
;
636 memset(mesg
, 0, sizeof(struct atmlec_msg
));
639 mesg
->sizeoftlvs
= data
->len
;
641 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
643 mesg
->content
.normal
.targetless_le_arp
= 1;
645 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
647 atm_force_charge(priv
->lecd
, skb
->truesize
);
648 sk
= sk_atm(priv
->lecd
);
649 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
650 sk
->sk_data_ready(sk
, skb
->len
);
653 pr_debug("lec: about to send %d bytes of data\n", data
->len
);
654 atm_force_charge(priv
->lecd
, data
->truesize
);
655 skb_queue_tail(&sk
->sk_receive_queue
, data
);
656 sk
->sk_data_ready(sk
, skb
->len
);
662 /* shamelessly stolen from drivers/net/net_init.c */
663 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
665 if ((new_mtu
< 68) || (new_mtu
> 18190))
671 static void lec_set_multicast_list(struct net_device
*dev
)
674 * by default, all multicast frames arrive over the bus.
675 * eventually support selective multicast service
680 static void lec_init(struct net_device
*dev
)
682 dev
->change_mtu
= lec_change_mtu
;
683 dev
->open
= lec_open
;
684 dev
->stop
= lec_close
;
685 dev
->hard_start_xmit
= lec_start_xmit
;
686 dev
->tx_timeout
= lec_tx_timeout
;
688 dev
->get_stats
= lec_get_stats
;
689 dev
->set_multicast_list
= lec_set_multicast_list
;
690 dev
->do_ioctl
= NULL
;
691 printk("%s: Initialized!\n", dev
->name
);
694 static const unsigned char lec_ctrl_magic
[] = {
701 #define LEC_DATA_DIRECT_8023 2
702 #define LEC_DATA_DIRECT_8025 3
704 static int lec_is_data_direct(struct atm_vcc
*vcc
)
706 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
707 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
710 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
713 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
714 struct lec_priv
*priv
= netdev_priv(dev
);
720 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
724 pr_debug("%s: null skb\n", dev
->name
);
725 lec_vcc_close(priv
, vcc
);
729 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
730 skb
->len
, priv
->lecid
);
731 #if DUMP_PACKETS >= 2
732 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
733 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
735 #elif DUMP_PACKETS >= 1
736 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
737 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
739 #endif /* DUMP_PACKETS >= 1 */
743 printk("%s...\n", buf
);
744 #endif /* DUMP_PACKETS > 0 */
745 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
746 struct sock
*sk
= sk_atm(vcc
);
748 pr_debug("%s: To daemon\n", dev
->name
);
749 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
750 sk
->sk_data_ready(sk
, skb
->len
);
751 } else { /* Data frame, queue to protocol handlers */
752 struct lec_arp_table
*entry
;
753 unsigned char *src
, *dst
;
755 atm_return(vcc
, skb
->truesize
);
756 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
757 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
759 * Probably looping back, or if lecd is missing,
762 pr_debug("Ignoring frame...\n");
768 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
771 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
774 * If this is a Data Direct VCC, and the VCC does not match
775 * the LE_ARP cache entry, delete the LE_ARP cache entry.
777 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
778 if (lec_is_data_direct(vcc
)) {
782 ((struct lecdatahdr_8025
*)skb
->data
)->
787 ((struct lecdatahdr_8023
*)skb
->data
)->
789 entry
= lec_arp_find(priv
, src
);
790 if (entry
&& entry
->vcc
!= vcc
) {
791 lec_arp_remove(priv
, entry
);
795 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
797 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
798 !priv
->is_proxy
&& /* Proxy wants all the packets */
799 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
803 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
804 lec_arp_check_empties(priv
, vcc
, skb
);
806 skb_pull(skb
, 2); /* skip lec_id */
809 skb
->protocol
= tr_type_trans(skb
, dev
);
812 skb
->protocol
= eth_type_trans(skb
, dev
);
813 priv
->stats
.rx_packets
++;
814 priv
->stats
.rx_bytes
+= skb
->len
;
815 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
820 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
822 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
823 struct net_device
*dev
= skb
->dev
;
826 printk("lec_pop(): vpriv = NULL!?!?!?\n");
830 vpriv
->old_pop(vcc
, skb
);
832 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
834 if (netif_running(dev
) && netif_queue_stopped(dev
))
835 netif_wake_queue(dev
);
839 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
841 struct lec_vcc_priv
*vpriv
;
843 struct atmlec_ioc ioc_data
;
845 /* Lecd must be up in this case */
846 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
847 if (bytes_left
!= 0) {
849 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
852 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
853 !dev_lec
[ioc_data
.dev_num
])
855 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
858 vpriv
->old_pop
= vcc
->pop
;
859 vcc
->user_back
= vpriv
;
861 lec_vcc_added(netdev_priv(dev_lec
[ioc_data
.dev_num
]),
862 &ioc_data
, vcc
, vcc
->push
);
863 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
864 vcc
->push
= lec_push
;
868 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
870 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
872 vcc
->proto_data
= dev_lec
[arg
];
873 return lec_mcast_make((struct lec_priv
*)netdev_priv(dev_lec
[arg
]),
877 /* Initialize device. */
878 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
881 struct lec_priv
*priv
;
888 if (arg
>= MAX_LEC_ITF
)
890 #else /* Reserve the top NUM_TR_DEVS for TR */
891 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
898 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
901 size
= sizeof(struct lec_priv
);
904 dev_lec
[i
] = alloc_trdev(size
);
907 dev_lec
[i
] = alloc_etherdev(size
);
910 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
911 if (register_netdev(dev_lec
[i
])) {
912 free_netdev(dev_lec
[i
]);
916 priv
= netdev_priv(dev_lec
[i
]);
917 priv
->is_trdev
= is_trdev
;
918 lec_init(dev_lec
[i
]);
920 priv
= netdev_priv(dev_lec
[i
]);
925 priv
->itfnum
= i
; /* LANE2 addition */
927 vcc
->dev
= &lecatm_dev
;
928 vcc_insert_socket(sk_atm(vcc
));
930 vcc
->proto_data
= dev_lec
[i
];
931 set_bit(ATM_VF_META
, &vcc
->flags
);
932 set_bit(ATM_VF_READY
, &vcc
->flags
);
934 /* Set default values to these variables */
935 priv
->maximum_unknown_frame_count
= 1;
936 priv
->max_unknown_frame_time
= (1 * HZ
);
937 priv
->vcc_timeout_period
= (1200 * HZ
);
938 priv
->max_retry_count
= 1;
939 priv
->aging_time
= (300 * HZ
);
940 priv
->forward_delay_time
= (15 * HZ
);
941 priv
->topology_change
= 0;
942 priv
->arp_response_time
= (1 * HZ
);
943 priv
->flush_timeout
= (4 * HZ
);
944 priv
->path_switching_delay
= (6 * HZ
);
946 if (dev_lec
[i
]->flags
& IFF_UP
) {
947 netif_start_queue(dev_lec
[i
]);
949 __module_get(THIS_MODULE
);
953 #ifdef CONFIG_PROC_FS
954 static char *lec_arp_get_status_string(unsigned char status
)
956 static char *lec_arp_status_string
[] = {
961 "ESI_FLUSH_PENDING ",
965 if (status
> ESI_FORWARD_DIRECT
)
966 status
= 3; /* ESI_UNDEFINED */
967 return lec_arp_status_string
[status
];
970 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
974 for (i
= 0; i
< ETH_ALEN
; i
++)
975 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
976 seq_printf(seq
, " ");
977 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
978 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
979 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
980 entry
->flags
& 0xffff);
982 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
984 seq_printf(seq
, " ");
985 if (entry
->recv_vcc
) {
986 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
987 entry
->recv_vcc
->vci
);
994 struct lec_priv
*locked
;
995 struct hlist_node
*node
;
996 struct net_device
*dev
;
1002 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
1005 struct hlist_node
*e
= state
->node
;
1006 struct lec_arp_table
*tmp
;
1010 if (e
== SEQ_START_TOKEN
) {
1015 hlist_for_each_entry_from(tmp
, e
, next
) {
1021 return (*l
< 0) ? state
: NULL
;
1024 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1025 struct lec_priv
*priv
)
1030 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1031 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1035 state
->arp_table
= p
;
1039 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1040 struct lec_priv
*priv
)
1042 struct hlist_head
*lec_misc_tables
[] = {
1043 &priv
->lec_arp_empty_ones
,
1044 &priv
->lec_no_forward
,
1050 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1051 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1055 state
->misc_table
= q
;
1059 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1060 struct lec_priv
*priv
)
1062 if (!state
->locked
) {
1063 state
->locked
= priv
;
1064 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1066 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1067 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1068 state
->locked
= NULL
;
1069 /* Partial state reset for the next time we get called */
1070 state
->arp_table
= state
->misc_table
= 0;
1072 return state
->locked
;
1075 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1077 struct net_device
*dev
;
1080 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1081 v
= (dev
&& netdev_priv(dev
)) ?
1082 lec_priv_walk(state
, l
, netdev_priv(dev
)) : NULL
;
1085 /* Partial state reset for the next time we get called */
1092 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1096 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1097 v
= lec_itf_walk(state
, &l
);
1104 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1106 struct lec_state
*state
= seq
->private;
1110 state
->locked
= NULL
;
1111 state
->arp_table
= 0;
1112 state
->misc_table
= 0;
1113 state
->node
= SEQ_START_TOKEN
;
1115 return *pos
? lec_get_idx(state
, *pos
) : SEQ_START_TOKEN
;
1118 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1120 struct lec_state
*state
= seq
->private;
1123 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1125 dev_put(state
->dev
);
1129 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1131 struct lec_state
*state
= seq
->private;
1133 v
= lec_get_idx(state
, 1);
1134 *pos
+= !!PTR_ERR(v
);
1138 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1140 static char lec_banner
[] = "Itf MAC ATM destination"
1142 "VPI/VCI Recv VPI/VCI\n";
1144 if (v
== SEQ_START_TOKEN
)
1145 seq_puts(seq
, lec_banner
);
1147 struct lec_state
*state
= seq
->private;
1148 struct net_device
*dev
= state
->dev
;
1149 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1151 seq_printf(seq
, "%s ", dev
->name
);
1152 lec_info(seq
, entry
);
1157 static const struct seq_operations lec_seq_ops
= {
1158 .start
= lec_seq_start
,
1159 .next
= lec_seq_next
,
1160 .stop
= lec_seq_stop
,
1161 .show
= lec_seq_show
,
1164 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1166 return seq_open_private(file
, &lec_seq_ops
, sizeof(struct lec_state
));
1169 static const struct file_operations lec_seq_fops
= {
1170 .owner
= THIS_MODULE
,
1171 .open
= lec_seq_open
,
1173 .llseek
= seq_lseek
,
1174 .release
= seq_release_private
,
1178 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1180 struct atm_vcc
*vcc
= ATM_SD(sock
);
1187 if (!capable(CAP_NET_ADMIN
))
1191 return -ENOIOCTLCMD
;
1196 err
= lecd_attach(vcc
, (int)arg
);
1198 sock
->state
= SS_CONNECTED
;
1201 err
= lec_mcast_attach(vcc
, (int)arg
);
1204 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1211 static struct atm_ioctl lane_ioctl_ops
= {
1212 .owner
= THIS_MODULE
,
1213 .ioctl
= lane_ioctl
,
1216 static int __init
lane_module_init(void)
1218 #ifdef CONFIG_PROC_FS
1219 struct proc_dir_entry
*p
;
1221 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1223 printk(KERN_ERR
"Unable to initialize /proc/net/atm/lec\n");
1228 register_atm_ioctl(&lane_ioctl_ops
);
1229 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1233 static void __exit
lane_module_cleanup(void)
1236 struct lec_priv
*priv
;
1238 remove_proc_entry("lec", atm_proc_root
);
1240 deregister_atm_ioctl(&lane_ioctl_ops
);
1242 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1243 if (dev_lec
[i
] != NULL
) {
1244 priv
= netdev_priv(dev_lec
[i
]);
1245 unregister_netdev(dev_lec
[i
]);
1246 free_netdev(dev_lec
[i
]);
1254 module_init(lane_module_init
);
1255 module_exit(lane_module_cleanup
);
1258 * LANE2: 3.1.3, LE_RESOLVE.request
1259 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1260 * If sizeoftlvs == NULL the default TLVs associated with with this
1262 * If dst_mac == NULL, targetless LE_ARP will be sent
1264 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
1265 u8
**tlvs
, u32
*sizeoftlvs
)
1267 unsigned long flags
;
1268 struct lec_priv
*priv
= netdev_priv(dev
);
1269 struct lec_arp_table
*table
;
1270 struct sk_buff
*skb
;
1274 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1275 table
= lec_arp_find(priv
, dst_mac
);
1276 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1280 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1284 *sizeoftlvs
= table
->sizeoftlvs
;
1289 if (sizeoftlvs
== NULL
)
1290 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1293 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1296 skb
->len
= *sizeoftlvs
;
1297 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1298 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1304 * LANE2: 3.1.4, LE_ASSOCIATE.request
1305 * Associate the *tlvs with the *lan_dst address.
1306 * Will overwrite any previous association
1307 * Returns 1 for success, 0 for failure (out of memory)
1310 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
1311 const u8
*tlvs
, u32 sizeoftlvs
)
1314 struct sk_buff
*skb
;
1315 struct lec_priv
*priv
= netdev_priv(dev
);
1317 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1318 return (0); /* not our mac address */
1320 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1322 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1323 if (priv
->tlvs
== NULL
)
1325 priv
->sizeoftlvs
= sizeoftlvs
;
1327 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1330 skb
->len
= sizeoftlvs
;
1331 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1332 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1334 printk("lec.c: lane2_associate_req() failed\n");
1336 * If the previous association has changed we must
1337 * somehow notify other LANE entities about the change
1343 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1346 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_addr
,
1347 const u8
*tlvs
, u32 sizeoftlvs
)
1352 struct lec_priv
*priv
= netdev_priv(dev
);
1354 * Why have the TLVs in LE_ARP entries
1355 * since we do not use them? When you
1356 * uncomment this code, make sure the
1357 * TLVs get freed when entry is killed
1359 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1362 return; /* should not happen */
1366 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1367 if (entry
->tlvs
== NULL
)
1369 entry
->sizeoftlvs
= sizeoftlvs
;
1372 printk("lec.c: lane2_associate_ind()\n");
1373 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1374 while (i
< sizeoftlvs
)
1375 printk("%02x ", tlvs
[i
++]);
1380 /* tell MPOA about the TLVs we saw */
1381 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1382 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1389 * Here starts what used to lec_arpc.c
1391 * lec_arpc.c was added here when making
1392 * lane client modular. October 1997
1395 #include <linux/types.h>
1396 #include <linux/timer.h>
1397 #include <asm/param.h>
1398 #include <asm/atomic.h>
1399 #include <linux/inetdevice.h>
1400 #include <net/route.h>
1403 #define pr_debug(format,args...)
1405 #define pr_debug printk
1408 #define DEBUG_ARP_TABLE 0
1410 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1412 static void lec_arp_check_expire(struct work_struct
*work
);
1413 static void lec_arp_expire_arp(unsigned long data
);
1419 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1422 * Initialization of arp-cache
1424 static void lec_arp_init(struct lec_priv
*priv
)
1428 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1429 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1431 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1432 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1433 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1434 spin_lock_init(&priv
->lec_arp_lock
);
1435 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1436 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1439 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1442 struct atm_vcc
*vcc
= entry
->vcc
;
1443 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1444 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1446 vcc
->pop
= vpriv
->old_pop
;
1448 netif_wake_queue(dev
);
1450 vcc
->user_back
= NULL
;
1451 vcc
->push
= entry
->old_push
;
1452 vcc_release_async(vcc
, -EPIPE
);
1455 if (entry
->recv_vcc
) {
1456 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1457 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1458 entry
->recv_vcc
= NULL
;
1463 * Insert entry to lec_arp_table
1464 * LANE2: Add to the end of the list to satisfy 8.1.13
1467 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1469 struct hlist_head
*tmp
;
1471 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1472 hlist_add_head(&entry
->next
, tmp
);
1474 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1475 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1476 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1477 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1481 * Remove entry from lec_arp_table
1484 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1486 struct hlist_node
*node
;
1487 struct lec_arp_table
*entry
;
1488 int i
, remove_vcc
= 1;
1494 hlist_del(&to_remove
->next
);
1495 del_timer(&to_remove
->timer
);
1497 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1498 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1500 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1502 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1503 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1504 if (memcmp(to_remove
->atm_addr
,
1505 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1512 lec_arp_clear_vccs(to_remove
);
1514 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1516 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1517 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1518 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1519 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1524 static char *get_status_string(unsigned char st
)
1528 return "ESI_UNKNOWN";
1529 case ESI_ARP_PENDING
:
1530 return "ESI_ARP_PENDING";
1531 case ESI_VC_PENDING
:
1532 return "ESI_VC_PENDING";
1533 case ESI_FLUSH_PENDING
:
1534 return "ESI_FLUSH_PENDING";
1535 case ESI_FORWARD_DIRECT
:
1536 return "ESI_FORWARD_DIRECT";
1542 static void dump_arp_table(struct lec_priv
*priv
)
1544 struct hlist_node
*node
;
1545 struct lec_arp_table
*rulla
;
1549 printk("Dump %p:\n", priv
);
1550 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1551 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1553 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1554 offset
+= sprintf(buf
+ offset
, "Mac:");
1555 for (j
= 0; j
< ETH_ALEN
; j
++) {
1556 offset
+= sprintf(buf
+ offset
,
1558 rulla
->mac_addr
[j
] & 0xff);
1560 offset
+= sprintf(buf
+ offset
, "Atm:");
1561 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1562 offset
+= sprintf(buf
+ offset
,
1564 rulla
->atm_addr
[j
] & 0xff);
1566 offset
+= sprintf(buf
+ offset
,
1567 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1568 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1569 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1570 rulla
->recv_vcc
? rulla
->recv_vcc
->
1572 rulla
->recv_vcc
? rulla
->recv_vcc
->
1573 vci
: 0, rulla
->last_used
,
1574 rulla
->timestamp
, rulla
->no_tries
);
1576 sprintf(buf
+ offset
,
1577 "Flags:%x, Packets_flooded:%x, Status: %s ",
1578 rulla
->flags
, rulla
->packets_flooded
,
1579 get_status_string(rulla
->status
));
1580 printk("%s\n", buf
);
1584 if (!hlist_empty(&priv
->lec_no_forward
))
1585 printk("No forward\n");
1586 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1588 offset
+= sprintf(buf
+ offset
, "Mac:");
1589 for (j
= 0; j
< ETH_ALEN
; j
++) {
1590 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1591 rulla
->mac_addr
[j
] & 0xff);
1593 offset
+= sprintf(buf
+ offset
, "Atm:");
1594 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1595 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1596 rulla
->atm_addr
[j
] & 0xff);
1598 offset
+= sprintf(buf
+ offset
,
1599 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1600 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1601 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1602 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1603 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1605 rulla
->timestamp
, rulla
->no_tries
);
1606 offset
+= sprintf(buf
+ offset
,
1607 "Flags:%x, Packets_flooded:%x, Status: %s ",
1608 rulla
->flags
, rulla
->packets_flooded
,
1609 get_status_string(rulla
->status
));
1610 printk("%s\n", buf
);
1613 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1614 printk("Empty ones\n");
1615 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1617 offset
+= sprintf(buf
+ offset
, "Mac:");
1618 for (j
= 0; j
< ETH_ALEN
; j
++) {
1619 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1620 rulla
->mac_addr
[j
] & 0xff);
1622 offset
+= sprintf(buf
+ offset
, "Atm:");
1623 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1624 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1625 rulla
->atm_addr
[j
] & 0xff);
1627 offset
+= sprintf(buf
+ offset
,
1628 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1629 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1630 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1631 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1632 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1634 rulla
->timestamp
, rulla
->no_tries
);
1635 offset
+= sprintf(buf
+ offset
,
1636 "Flags:%x, Packets_flooded:%x, Status: %s ",
1637 rulla
->flags
, rulla
->packets_flooded
,
1638 get_status_string(rulla
->status
));
1642 if (!hlist_empty(&priv
->mcast_fwds
))
1643 printk("Multicast Forward VCCs\n");
1644 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1646 offset
+= sprintf(buf
+ offset
, "Mac:");
1647 for (j
= 0; j
< ETH_ALEN
; j
++) {
1648 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1649 rulla
->mac_addr
[j
] & 0xff);
1651 offset
+= sprintf(buf
+ offset
, "Atm:");
1652 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1653 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1654 rulla
->atm_addr
[j
] & 0xff);
1656 offset
+= sprintf(buf
+ offset
,
1657 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1658 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1659 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1660 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1661 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1663 rulla
->timestamp
, rulla
->no_tries
);
1664 offset
+= sprintf(buf
+ offset
,
1665 "Flags:%x, Packets_flooded:%x, Status: %s ",
1666 rulla
->flags
, rulla
->packets_flooded
,
1667 get_status_string(rulla
->status
));
1668 printk("%s\n", buf
);
1673 #define dump_arp_table(priv) do { } while (0)
1677 * Destruction of arp-cache
1679 static void lec_arp_destroy(struct lec_priv
*priv
)
1681 unsigned long flags
;
1682 struct hlist_node
*node
, *next
;
1683 struct lec_arp_table
*entry
;
1686 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1689 * Remove all entries
1692 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1693 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1694 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1695 lec_arp_remove(priv
, entry
);
1698 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1701 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1702 del_timer_sync(&entry
->timer
);
1703 lec_arp_clear_vccs(entry
);
1704 hlist_del(&entry
->next
);
1707 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1709 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1710 del_timer_sync(&entry
->timer
);
1711 lec_arp_clear_vccs(entry
);
1712 hlist_del(&entry
->next
);
1715 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1717 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1718 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1719 lec_arp_clear_vccs(entry
);
1720 hlist_del(&entry
->next
);
1723 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1724 priv
->mcast_vcc
= NULL
;
1725 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1729 * Find entry by mac_address
1731 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1732 const unsigned char *mac_addr
)
1734 struct hlist_node
*node
;
1735 struct hlist_head
*head
;
1736 struct lec_arp_table
*entry
;
1738 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1739 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1740 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1742 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1743 hlist_for_each_entry(entry
, node
, head
, next
) {
1744 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1751 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1752 const unsigned char *mac_addr
)
1754 struct lec_arp_table
*to_return
;
1756 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1758 printk("LEC: Arp entry kmalloc failed\n");
1761 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1762 INIT_HLIST_NODE(&to_return
->next
);
1763 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1764 (unsigned long)to_return
);
1765 to_return
->last_used
= jiffies
;
1766 to_return
->priv
= priv
;
1767 skb_queue_head_init(&to_return
->tx_wait
);
1768 atomic_set(&to_return
->usage
, 1);
1772 /* Arp sent timer expired */
1773 static void lec_arp_expire_arp(unsigned long data
)
1775 struct lec_arp_table
*entry
;
1777 entry
= (struct lec_arp_table
*)data
;
1779 pr_debug("lec_arp_expire_arp\n");
1780 if (entry
->status
== ESI_ARP_PENDING
) {
1781 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1782 if (entry
->is_rdesc
)
1783 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1784 entry
->mac_addr
, NULL
, NULL
);
1786 send_to_lecd(entry
->priv
, l_arp_xmt
,
1787 entry
->mac_addr
, NULL
, NULL
);
1790 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1794 /* Unknown/unused vcc expire, remove associated entry */
1795 static void lec_arp_expire_vcc(unsigned long data
)
1797 unsigned long flags
;
1798 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1799 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1801 del_timer(&to_remove
->timer
);
1803 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1805 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1806 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1808 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1809 hlist_del(&to_remove
->next
);
1810 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1812 lec_arp_clear_vccs(to_remove
);
1813 lec_arp_put(to_remove
);
1819 * 2. For each entry, delete entries that have aged past the age limit.
1820 * 3. For each entry, depending on the status of the entry, perform
1821 * the following maintenance.
1822 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1823 * tick_count is above the max_unknown_frame_time, clear
1824 * the tick_count to zero and clear the packets_flooded counter
1825 * to zero. This supports the packet rate limit per address
1826 * while flooding unknowns.
1827 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1828 * than or equal to the path_switching_delay, change the status
1829 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1830 * regardless of the progress of the flush protocol.
1832 static void lec_arp_check_expire(struct work_struct
*work
)
1834 unsigned long flags
;
1835 struct lec_priv
*priv
=
1836 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1837 struct hlist_node
*node
, *next
;
1838 struct lec_arp_table
*entry
;
1840 unsigned long time_to_check
;
1843 pr_debug("lec_arp_check_expire %p\n", priv
);
1846 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1847 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1848 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1849 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1850 priv
->topology_change
)
1851 time_to_check
= priv
->forward_delay_time
;
1853 time_to_check
= priv
->aging_time
;
1855 pr_debug("About to expire: %lx - %lx > %lx\n",
1856 now
, entry
->last_used
, time_to_check
);
1857 if (time_after(now
, entry
->last_used
+ time_to_check
)
1858 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1859 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1861 pr_debug("LEC:Entry timed out\n");
1862 lec_arp_remove(priv
, entry
);
1865 /* Something else */
1866 if ((entry
->status
== ESI_VC_PENDING
||
1867 entry
->status
== ESI_ARP_PENDING
)
1868 && time_after_eq(now
,
1871 max_unknown_frame_time
)) {
1872 entry
->timestamp
= jiffies
;
1873 entry
->packets_flooded
= 0;
1874 if (entry
->status
== ESI_VC_PENDING
)
1875 send_to_lecd(priv
, l_svc_setup
,
1880 if (entry
->status
== ESI_FLUSH_PENDING
1882 time_after_eq(now
, entry
->timestamp
+
1883 priv
->path_switching_delay
)) {
1884 struct sk_buff
*skb
;
1885 struct atm_vcc
*vcc
= entry
->vcc
;
1887 lec_arp_hold(entry
);
1888 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1889 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1890 lec_send(vcc
, skb
, entry
->priv
);
1891 entry
->last_used
= jiffies
;
1892 entry
->status
= ESI_FORWARD_DIRECT
;
1899 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1901 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1905 * Try to find vcc where mac_address is attached.
1908 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1909 const unsigned char *mac_to_find
, int is_rdesc
,
1910 struct lec_arp_table
**ret_entry
)
1912 unsigned long flags
;
1913 struct lec_arp_table
*entry
;
1914 struct atm_vcc
*found
;
1916 if (mac_to_find
[0] & 0x01) {
1917 switch (priv
->lane_version
) {
1919 return priv
->mcast_vcc
;
1920 case 2: /* LANE2 wants arp for multicast addresses */
1921 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1922 return priv
->mcast_vcc
;
1929 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1930 entry
= lec_arp_find(priv
, mac_to_find
);
1933 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1935 entry
->last_used
= jiffies
;
1936 lec_arp_hold(entry
);
1942 * If the LE_ARP cache entry is still pending, reset count to 0
1943 * so another LE_ARP request can be made for this frame.
1945 if (entry
->status
== ESI_ARP_PENDING
) {
1946 entry
->no_tries
= 0;
1949 * Data direct VC not yet set up, check to see if the unknown
1950 * frame count is greater than the limit. If the limit has
1951 * not been reached, allow the caller to send packet to
1954 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1955 entry
->packets_flooded
<
1956 priv
->maximum_unknown_frame_count
) {
1957 entry
->packets_flooded
++;
1958 pr_debug("LEC_ARP: Flooding..\n");
1959 found
= priv
->mcast_vcc
;
1963 * We got here because entry->status == ESI_FLUSH_PENDING
1964 * or BUS flood limit was reached for an entry which is
1965 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1967 lec_arp_hold(entry
);
1969 pr_debug("lec: entry->status %d entry->vcc %p\n", entry
->status
,
1973 /* No matching entry was found */
1974 entry
= make_entry(priv
, mac_to_find
);
1975 pr_debug("LEC_ARP: Making entry\n");
1977 found
= priv
->mcast_vcc
;
1980 lec_arp_add(priv
, entry
);
1981 /* We want arp-request(s) to be sent */
1982 entry
->packets_flooded
= 1;
1983 entry
->status
= ESI_ARP_PENDING
;
1984 entry
->no_tries
= 1;
1985 entry
->last_used
= entry
->timestamp
= jiffies
;
1986 entry
->is_rdesc
= is_rdesc
;
1987 if (entry
->is_rdesc
)
1988 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
1991 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
1992 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
1993 entry
->timer
.function
= lec_arp_expire_arp
;
1994 add_timer(&entry
->timer
);
1995 found
= priv
->mcast_vcc
;
1999 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2004 lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
2005 unsigned long permanent
)
2007 unsigned long flags
;
2008 struct hlist_node
*node
, *next
;
2009 struct lec_arp_table
*entry
;
2012 pr_debug("lec_addr_delete\n");
2013 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2014 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2015 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2016 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2018 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2019 lec_arp_remove(priv
, entry
);
2022 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2026 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2031 * Notifies: Response to arp_request (atm_addr != NULL)
2034 lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
2035 const unsigned char *atm_addr
, unsigned long remoteflag
,
2036 unsigned int targetless_le_arp
)
2038 unsigned long flags
;
2039 struct hlist_node
*node
, *next
;
2040 struct lec_arp_table
*entry
, *tmp
;
2043 pr_debug("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2044 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2045 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2046 mac_addr
[4], mac_addr
[5]);
2048 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2049 entry
= lec_arp_find(priv
, mac_addr
);
2050 if (entry
== NULL
&& targetless_le_arp
)
2052 * LANE2: ignore targetless LE_ARPs for which
2053 * we have no entry in the cache. 7.1.30
2055 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2056 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2057 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2058 hlist_del(&entry
->next
);
2059 del_timer(&entry
->timer
);
2060 tmp
= lec_arp_find(priv
, mac_addr
);
2062 del_timer(&tmp
->timer
);
2063 tmp
->status
= ESI_FORWARD_DIRECT
;
2064 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2065 tmp
->vcc
= entry
->vcc
;
2066 tmp
->old_push
= entry
->old_push
;
2067 tmp
->last_used
= jiffies
;
2068 del_timer(&entry
->timer
);
2072 entry
->status
= ESI_FORWARD_DIRECT
;
2073 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2074 entry
->last_used
= jiffies
;
2075 lec_arp_add(priv
, entry
);
2078 entry
->flags
|= LEC_REMOTE_FLAG
;
2080 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2081 pr_debug("After update\n");
2082 dump_arp_table(priv
);
2088 entry
= lec_arp_find(priv
, mac_addr
);
2090 entry
= make_entry(priv
, mac_addr
);
2093 entry
->status
= ESI_UNKNOWN
;
2094 lec_arp_add(priv
, entry
);
2095 /* Temporary, changes before end of function */
2097 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2098 del_timer(&entry
->timer
);
2099 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2100 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2102 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2103 /* Vcc to this host exists */
2104 if (tmp
->status
> ESI_VC_PENDING
) {
2106 * ESI_FLUSH_PENDING,
2107 * ESI_FORWARD_DIRECT
2109 entry
->vcc
= tmp
->vcc
;
2110 entry
->old_push
= tmp
->old_push
;
2112 entry
->status
= tmp
->status
;
2118 entry
->flags
|= LEC_REMOTE_FLAG
;
2120 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2121 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2122 entry
->status
= ESI_VC_PENDING
;
2123 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2125 pr_debug("After update2\n");
2126 dump_arp_table(priv
);
2128 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2132 * Notifies: Vcc setup ready
2135 lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
2136 struct atm_vcc
*vcc
,
2137 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2139 unsigned long flags
;
2140 struct hlist_node
*node
;
2141 struct lec_arp_table
*entry
;
2142 int i
, found_entry
= 0;
2144 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2145 if (ioc_data
->receive
== 2) {
2146 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2148 pr_debug("LEC_ARP: Attaching mcast forward\n");
2150 entry
= lec_arp_find(priv
, bus_mac
);
2152 printk("LEC_ARP: Multicast entry not found!\n");
2155 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2156 entry
->recv_vcc
= vcc
;
2157 entry
->old_recv_push
= old_push
;
2159 entry
= make_entry(priv
, bus_mac
);
2162 del_timer(&entry
->timer
);
2163 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2164 entry
->recv_vcc
= vcc
;
2165 entry
->old_recv_push
= old_push
;
2166 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2168 } else if (ioc_data
->receive
== 1) {
2170 * Vcc which we don't want to make default vcc,
2174 ("LEC_ARP:Attaching data direct, not default: "
2175 "%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",
2176 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2177 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2178 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2179 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2180 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2181 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2182 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2183 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2184 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2185 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2186 entry
= make_entry(priv
, bus_mac
);
2189 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2190 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2191 entry
->recv_vcc
= vcc
;
2192 entry
->old_recv_push
= old_push
;
2193 entry
->status
= ESI_UNKNOWN
;
2194 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2195 entry
->timer
.function
= lec_arp_expire_vcc
;
2196 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2197 add_timer(&entry
->timer
);
2198 dump_arp_table(priv
);
2202 ("LEC_ARP:Attaching data direct, default: "
2203 "%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",
2204 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2205 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2206 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2207 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2208 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2209 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2210 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2211 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2212 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2213 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2214 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2215 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2217 (ioc_data
->atm_addr
, entry
->atm_addr
,
2218 ATM_ESA_LEN
) == 0) {
2219 pr_debug("LEC_ARP: Attaching data direct\n");
2220 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2221 entry
->vcc
? entry
->vcc
->vci
: 0,
2222 entry
->recv_vcc
? entry
->recv_vcc
->
2225 del_timer(&entry
->timer
);
2227 entry
->old_push
= old_push
;
2228 if (entry
->status
== ESI_VC_PENDING
) {
2229 if (priv
->maximum_unknown_frame_count
2234 entry
->timestamp
= jiffies
;
2238 send_to_lecd(priv
, l_flush_xmt
,
2246 * They were forming a connection
2247 * to us, and we to them. Our
2248 * ATM address is numerically lower
2249 * than theirs, so we make connection
2250 * we formed into default VCC (8.1.11).
2251 * Connection they made gets torn
2252 * down. This might confuse some
2253 * clients. Can be changed if
2254 * someone reports trouble...
2262 pr_debug("After vcc was added\n");
2263 dump_arp_table(priv
);
2267 * Not found, snatch address from first data packet that arrives
2270 entry
= make_entry(priv
, bus_mac
);
2274 entry
->old_push
= old_push
;
2275 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2276 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2277 entry
->status
= ESI_UNKNOWN
;
2278 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2279 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2280 entry
->timer
.function
= lec_arp_expire_vcc
;
2281 add_timer(&entry
->timer
);
2282 pr_debug("After vcc was added\n");
2283 dump_arp_table(priv
);
2285 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2288 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2290 unsigned long flags
;
2291 struct hlist_node
*node
;
2292 struct lec_arp_table
*entry
;
2295 pr_debug("LEC:lec_flush_complete %lx\n", tran_id
);
2297 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2298 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2299 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2300 if (entry
->flush_tran_id
== tran_id
2301 && entry
->status
== ESI_FLUSH_PENDING
) {
2302 struct sk_buff
*skb
;
2303 struct atm_vcc
*vcc
= entry
->vcc
;
2305 lec_arp_hold(entry
);
2306 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2307 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2308 lec_send(vcc
, skb
, entry
->priv
);
2309 entry
->last_used
= jiffies
;
2310 entry
->status
= ESI_FORWARD_DIRECT
;
2312 pr_debug("LEC_ARP: Flushed\n");
2317 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2318 dump_arp_table(priv
);
2322 lec_set_flush_tran_id(struct lec_priv
*priv
,
2323 const unsigned char *atm_addr
, unsigned long tran_id
)
2325 unsigned long flags
;
2326 struct hlist_node
*node
;
2327 struct lec_arp_table
*entry
;
2330 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2331 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2332 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2333 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2334 entry
->flush_tran_id
= tran_id
;
2335 pr_debug("Set flush transaction id to %lx for %p\n",
2339 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2342 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2344 unsigned long flags
;
2345 unsigned char mac_addr
[] = {
2346 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2348 struct lec_arp_table
*to_add
;
2349 struct lec_vcc_priv
*vpriv
;
2352 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2355 vpriv
->old_pop
= vcc
->pop
;
2356 vcc
->user_back
= vpriv
;
2358 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2359 to_add
= make_entry(priv
, mac_addr
);
2361 vcc
->pop
= vpriv
->old_pop
;
2366 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2367 to_add
->status
= ESI_FORWARD_DIRECT
;
2368 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2370 to_add
->old_push
= vcc
->push
;
2371 vcc
->push
= lec_push
;
2372 priv
->mcast_vcc
= vcc
;
2373 lec_arp_add(priv
, to_add
);
2375 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2379 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2381 unsigned long flags
;
2382 struct hlist_node
*node
, *next
;
2383 struct lec_arp_table
*entry
;
2386 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2387 dump_arp_table(priv
);
2389 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2391 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2392 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2393 if (vcc
== entry
->vcc
) {
2394 lec_arp_remove(priv
, entry
);
2396 if (priv
->mcast_vcc
== vcc
) {
2397 priv
->mcast_vcc
= NULL
;
2403 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2404 if (entry
->vcc
== vcc
) {
2405 lec_arp_clear_vccs(entry
);
2406 del_timer(&entry
->timer
);
2407 hlist_del(&entry
->next
);
2412 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2413 if (entry
->recv_vcc
== vcc
) {
2414 lec_arp_clear_vccs(entry
);
2415 del_timer(&entry
->timer
);
2416 hlist_del(&entry
->next
);
2421 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2422 if (entry
->recv_vcc
== vcc
) {
2423 lec_arp_clear_vccs(entry
);
2424 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2425 hlist_del(&entry
->next
);
2430 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2431 dump_arp_table(priv
);
2435 lec_arp_check_empties(struct lec_priv
*priv
,
2436 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2438 unsigned long flags
;
2439 struct hlist_node
*node
, *next
;
2440 struct lec_arp_table
*entry
, *tmp
;
2441 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2444 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2447 src
= tr_hdr
->h_source
;
2450 src
= hdr
->h_source
;
2452 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2453 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2454 if (vcc
== entry
->vcc
) {
2455 del_timer(&entry
->timer
);
2456 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2457 entry
->status
= ESI_FORWARD_DIRECT
;
2458 entry
->last_used
= jiffies
;
2459 /* We might have got an entry */
2460 if ((tmp
= lec_arp_find(priv
, src
))) {
2461 lec_arp_remove(priv
, tmp
);
2464 hlist_del(&entry
->next
);
2465 lec_arp_add(priv
, entry
);
2469 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2471 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2474 MODULE_LICENSE("GPL");