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"
52 #define DPRINTK printk
54 #define DPRINTK(format,args...)
57 #define DUMP_PACKETS 0 /*
63 #define LEC_UNRES_QUE_LEN 8 /*
64 * number of tx packets to queue for a
65 * single destination while waiting for SVC
68 static int lec_open(struct net_device
*dev
);
69 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
70 static int lec_close(struct net_device
*dev
);
71 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
);
72 static void lec_init(struct net_device
*dev
);
73 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
74 unsigned char *mac_addr
);
75 static int lec_arp_remove(struct lec_priv
*priv
,
76 struct lec_arp_table
*to_remove
);
78 static void lane2_associate_ind(struct net_device
*dev
, u8
*mac_address
,
79 u8
*tlvs
, u32 sizeoftlvs
);
80 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
81 u8
**tlvs
, u32
*sizeoftlvs
);
82 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
83 u8
*tlvs
, u32 sizeoftlvs
);
85 static int lec_addr_delete(struct lec_priv
*priv
, unsigned char *atm_addr
,
86 unsigned long permanent
);
87 static void lec_arp_check_empties(struct lec_priv
*priv
,
88 struct atm_vcc
*vcc
, struct sk_buff
*skb
);
89 static void lec_arp_destroy(struct lec_priv
*priv
);
90 static void lec_arp_init(struct lec_priv
*priv
);
91 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
92 unsigned char *mac_to_find
,
94 struct lec_arp_table
**ret_entry
);
95 static void lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
96 unsigned char *atm_addr
, unsigned long remoteflag
,
97 unsigned int targetless_le_arp
);
98 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
99 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
100 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
101 unsigned char *atm_addr
,
102 unsigned long tran_id
);
103 static void lec_vcc_added(struct lec_priv
*priv
, struct atmlec_ioc
*ioc_data
,
105 void (*old_push
) (struct atm_vcc
*vcc
,
106 struct sk_buff
*skb
));
107 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
109 /* must be done under lec_arp_lock */
110 static inline void lec_arp_hold(struct lec_arp_table
*entry
)
112 atomic_inc(&entry
->usage
);
115 static inline void lec_arp_put(struct lec_arp_table
*entry
)
117 if (atomic_dec_and_test(&entry
->usage
))
122 static struct lane2_ops lane2_ops
= {
123 lane2_resolve
, /* resolve, spec 3.1.3 */
124 lane2_associate_req
, /* associate_req, spec 3.1.4 */
125 NULL
/* associate indicator, spec 3.1.5 */
128 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
130 /* Device structures */
131 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
133 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
134 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
138 struct lec_priv
*priv
;
141 * Check if this is a BPDU. If so, ask zeppelin to send
142 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
143 * as the Config BPDU has
145 eth
= (struct ethhdr
*)skb
->data
;
146 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
147 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
149 struct sk_buff
*skb2
;
150 struct atmlec_msg
*mesg
;
152 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
155 skb2
->len
= sizeof(struct atmlec_msg
);
156 mesg
= (struct atmlec_msg
*)skb2
->data
;
157 mesg
->type
= l_topology_change
;
159 mesg
->content
.normal
.flag
= *buff
& 0x01; /* 0x01 is topology change */
161 priv
= (struct lec_priv
*)dev
->priv
;
162 atm_force_charge(priv
->lecd
, skb2
->truesize
);
163 sk
= sk_atm(priv
->lecd
);
164 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
165 sk
->sk_data_ready(sk
, skb2
->len
);
170 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
173 * Modelled after tr_type_trans
174 * All multicast and ARE or STE frames go to BUS.
175 * Non source routed frames go by destination address.
176 * Last hop source routed frames go by destination address.
177 * Not last hop source routed frames go by _next_ route descriptor.
178 * Returns pointer to destination MAC address or fills in rdesc
182 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
185 int riflen
, num_rdsc
;
187 trh
= (struct trh_hdr
*)packet
;
188 if (trh
->daddr
[0] & (uint8_t) 0x80)
189 return bus_mac
; /* multicast */
191 if (trh
->saddr
[0] & TR_RII
) {
192 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
193 if ((ntohs(trh
->rcf
) >> 13) != 0)
194 return bus_mac
; /* ARE or STE */
196 return trh
->daddr
; /* not source routed */
199 return trh
->daddr
; /* last hop, source routed */
201 /* riflen is 6 or more, packet has more than one route descriptor */
202 num_rdsc
= (riflen
/ 2) - 1;
203 memset(rdesc
, 0, ETH_ALEN
);
204 /* offset 4 comes from LAN destination field in LE control frames */
205 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
206 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(__be16
));
208 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(__be16
));
209 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
214 #endif /* CONFIG_TR */
217 * Open/initialize the netdevice. This is called (in the current kernel)
218 * sometime after booting when the 'ifconfig' program is run.
220 * This routine should set everything up anew at each open, even
221 * registers that "should" only need to be set once at boot, so that
222 * there is non-reboot way to recover if something goes wrong.
225 static int lec_open(struct net_device
*dev
)
227 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
229 netif_start_queue(dev
);
230 memset(&priv
->stats
, 0, sizeof(struct net_device_stats
));
235 static __inline__
void
236 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
, struct lec_priv
*priv
)
238 ATM_SKB(skb
)->vcc
= vcc
;
239 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
241 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
242 if (vcc
->send(vcc
, skb
) < 0) {
243 priv
->stats
.tx_dropped
++;
247 priv
->stats
.tx_packets
++;
248 priv
->stats
.tx_bytes
+= skb
->len
;
251 static void lec_tx_timeout(struct net_device
*dev
)
253 printk(KERN_INFO
"%s: tx timeout\n", dev
->name
);
254 dev
->trans_start
= jiffies
;
255 netif_wake_queue(dev
);
258 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
260 struct sk_buff
*skb2
;
261 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
262 struct lecdatahdr_8023
*lec_h
;
264 struct lec_arp_table
*entry
;
268 unsigned char rdesc
[ETH_ALEN
]; /* Token Ring route descriptor */
274 #endif /* DUMP_PACKETS >0 */
276 DPRINTK("lec_start_xmit called\n");
278 printk("%s:No lecd attached\n", dev
->name
);
279 priv
->stats
.tx_errors
++;
280 netif_stop_queue(dev
);
284 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
285 (long)skb
->head
, (long)skb
->data
, (long)skb_tail_pointer(skb
),
286 (long)skb_end_pointer(skb
));
287 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
288 if (memcmp(skb
->data
, bridge_ula_lec
, sizeof(bridge_ula_lec
)) == 0)
289 lec_handle_bridge(skb
, dev
);
292 /* Make sure we have room for lec_id */
293 if (skb_headroom(skb
) < 2) {
295 DPRINTK("lec_start_xmit: reallocating skb\n");
296 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
304 /* Put le header to place, works for TokenRing too */
305 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
306 lec_h
->le_header
= htons(priv
->lecid
);
310 * Ugly. Use this to realign Token Ring packets for
311 * e.g. PCA-200E driver.
313 if (priv
->is_trdev
) {
314 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
323 printk("%s: send datalen:%ld lecid:%4.4x\n", dev
->name
,
324 skb
->len
, priv
->lecid
);
325 #if DUMP_PACKETS >= 2
326 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
327 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
329 #elif DUMP_PACKETS >= 1
330 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
331 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
333 #endif /* DUMP_PACKETS >= 1 */
337 printk("%s...\n", buf
);
338 #endif /* DUMP_PACKETS > 0 */
340 /* Minimum ethernet-frame size */
343 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
346 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
347 if (skb
->len
< min_frame_size
) {
348 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
349 skb2
= skb_copy_expand(skb
, 0,
350 min_frame_size
- skb
->truesize
,
354 priv
->stats
.tx_dropped
++;
359 skb_put(skb
, min_frame_size
- skb
->len
);
362 /* Send to right vcc */
366 if (priv
->is_trdev
) {
367 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
375 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
376 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev
->name
,
377 vcc
, vcc
? vcc
->flags
: 0, entry
);
378 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
379 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
380 DPRINTK("%s:lec_start_xmit: queuing packet, ",
382 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
383 lec_h
->h_dest
[0], lec_h
->h_dest
[1],
384 lec_h
->h_dest
[2], lec_h
->h_dest
[3],
385 lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
386 skb_queue_tail(&entry
->tx_wait
, skb
);
389 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
391 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
392 lec_h
->h_dest
[0], lec_h
->h_dest
[1],
393 lec_h
->h_dest
[2], lec_h
->h_dest
[3],
394 lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
395 priv
->stats
.tx_dropped
++;
401 printk("%s:sending to vpi:%d vci:%d\n", dev
->name
, vcc
->vpi
, vcc
->vci
);
402 #endif /* DUMP_PACKETS > 0 */
404 while (entry
&& (skb2
= skb_dequeue(&entry
->tx_wait
))) {
405 DPRINTK("lec.c: emptying tx queue, ");
406 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
407 lec_h
->h_dest
[0], lec_h
->h_dest
[1], lec_h
->h_dest
[2],
408 lec_h
->h_dest
[3], lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
409 lec_send(vcc
, skb2
, priv
);
412 lec_send(vcc
, skb
, priv
);
414 if (!atm_may_send(vcc
, 0)) {
415 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
418 netif_stop_queue(dev
);
421 * vcc->pop() might have occurred in between, making
422 * the vcc usuable again. Since xmit is serialized,
423 * this is the only situation we have to re-test.
426 if (atm_may_send(vcc
, 0))
427 netif_wake_queue(dev
);
433 dev
->trans_start
= jiffies
;
437 /* The inverse routine to net_open(). */
438 static int lec_close(struct net_device
*dev
)
440 netif_stop_queue(dev
);
445 * Get the current statistics.
446 * This may be called with the card open or closed.
448 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
)
450 return &((struct lec_priv
*)dev
->priv
)->stats
;
453 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
456 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
457 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
458 struct atmlec_msg
*mesg
;
459 struct lec_arp_table
*entry
;
461 char *tmp
; /* FIXME */
463 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
464 mesg
= (struct atmlec_msg
*)skb
->data
;
466 tmp
+= sizeof(struct atmlec_msg
);
467 DPRINTK("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
468 switch (mesg
->type
) {
470 for (i
= 0; i
< 6; i
++) {
471 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
475 for (i
= 0; i
< 6; i
++) {
476 dev
->dev_addr
[i
] = 0;
480 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
481 mesg
->content
.normal
.flag
);
483 case l_topology_change
:
484 priv
->topology_change
= mesg
->content
.normal
.flag
;
486 case l_flush_complete
:
487 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
489 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
490 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
491 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
492 lec_arp_remove(priv
, entry
);
493 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
495 if (mesg
->content
.normal
.no_source_le_narp
)
499 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
500 mesg
->content
.normal
.atm_addr
,
501 mesg
->content
.normal
.flag
,
502 mesg
->content
.normal
.targetless_le_arp
);
503 DPRINTK("lec: in l_arp_update\n");
504 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
505 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
507 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
508 tmp
, mesg
->sizeoftlvs
);
512 priv
->maximum_unknown_frame_count
=
513 mesg
->content
.config
.maximum_unknown_frame_count
;
514 priv
->max_unknown_frame_time
=
515 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
516 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
517 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
518 priv
->forward_delay_time
=
519 (mesg
->content
.config
.forward_delay_time
* HZ
);
520 priv
->arp_response_time
=
521 (mesg
->content
.config
.arp_response_time
* HZ
);
522 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
523 priv
->path_switching_delay
=
524 (mesg
->content
.config
.path_switching_delay
* HZ
);
525 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
526 priv
->lane2_ops
= NULL
;
527 if (priv
->lane_version
> 1)
528 priv
->lane2_ops
= &lane2_ops
;
529 if (dev
->change_mtu(dev
, mesg
->content
.config
.mtu
))
530 printk("%s: change_mtu to %d failed\n", dev
->name
,
531 mesg
->content
.config
.mtu
);
532 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
534 case l_flush_tran_id
:
535 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
536 mesg
->content
.normal
.flag
);
540 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
542 case l_should_bridge
:
543 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
545 struct net_bridge_fdb_entry
*f
;
548 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
549 dev
->name
, mesg
->content
.proxy
.mac_addr
[0],
550 mesg
->content
.proxy
.mac_addr
[1],
551 mesg
->content
.proxy
.mac_addr
[2],
552 mesg
->content
.proxy
.mac_addr
[3],
553 mesg
->content
.proxy
.mac_addr
[4],
554 mesg
->content
.proxy
.mac_addr
[5]);
556 if (br_fdb_get_hook
== NULL
|| dev
->br_port
== NULL
)
559 f
= br_fdb_get_hook(dev
->br_port
->br
,
560 mesg
->content
.proxy
.mac_addr
);
561 if (f
!= NULL
&& f
->dst
->dev
!= dev
562 && f
->dst
->state
== BR_STATE_FORWARDING
) {
563 /* hit from bridge table, send LE_ARP_RESPONSE */
564 struct sk_buff
*skb2
;
568 ("%s: entry found, responding to zeppelin\n",
571 alloc_skb(sizeof(struct atmlec_msg
),
577 skb2
->len
= sizeof(struct atmlec_msg
);
578 skb_copy_to_linear_data(skb2
, mesg
,
580 atm_force_charge(priv
->lecd
, skb2
->truesize
);
581 sk
= sk_atm(priv
->lecd
);
582 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
583 sk
->sk_data_ready(sk
, skb2
->len
);
588 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
591 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
599 static void lec_atm_close(struct atm_vcc
*vcc
)
602 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
603 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
606 /* Do something needful? */
608 netif_stop_queue(dev
);
609 lec_arp_destroy(priv
);
611 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
612 printk("%s lec_atm_close: closing with messages pending\n",
614 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
615 atm_return(vcc
, skb
->truesize
);
619 printk("%s: Shut down!\n", dev
->name
);
620 module_put(THIS_MODULE
);
623 static struct atmdev_ops lecdev_ops
= {
624 .close
= lec_atm_close
,
628 static struct atm_dev lecatm_dev
= {
631 .number
= 999, /* dummy device number */
632 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
636 * LANE2: new argument struct sk_buff *data contains
637 * the LE_ARP based TLVs introduced in the LANE2 spec
640 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
641 unsigned char *mac_addr
, unsigned char *atm_addr
,
642 struct sk_buff
*data
)
646 struct atmlec_msg
*mesg
;
648 if (!priv
|| !priv
->lecd
) {
651 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
654 skb
->len
= sizeof(struct atmlec_msg
);
655 mesg
= (struct atmlec_msg
*)skb
->data
;
656 memset(mesg
, 0, sizeof(struct atmlec_msg
));
659 mesg
->sizeoftlvs
= data
->len
;
661 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
663 mesg
->content
.normal
.targetless_le_arp
= 1;
665 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
667 atm_force_charge(priv
->lecd
, skb
->truesize
);
668 sk
= sk_atm(priv
->lecd
);
669 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
670 sk
->sk_data_ready(sk
, skb
->len
);
673 DPRINTK("lec: about to send %d bytes of data\n", data
->len
);
674 atm_force_charge(priv
->lecd
, data
->truesize
);
675 skb_queue_tail(&sk
->sk_receive_queue
, data
);
676 sk
->sk_data_ready(sk
, skb
->len
);
682 /* shamelessly stolen from drivers/net/net_init.c */
683 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
685 if ((new_mtu
< 68) || (new_mtu
> 18190))
691 static void lec_set_multicast_list(struct net_device
*dev
)
694 * by default, all multicast frames arrive over the bus.
695 * eventually support selective multicast service
700 static void lec_init(struct net_device
*dev
)
702 dev
->change_mtu
= lec_change_mtu
;
703 dev
->open
= lec_open
;
704 dev
->stop
= lec_close
;
705 dev
->hard_start_xmit
= lec_start_xmit
;
706 dev
->tx_timeout
= lec_tx_timeout
;
708 dev
->get_stats
= lec_get_stats
;
709 dev
->set_multicast_list
= lec_set_multicast_list
;
710 dev
->do_ioctl
= NULL
;
711 printk("%s: Initialized!\n", dev
->name
);
715 static unsigned char lec_ctrl_magic
[] = {
722 #define LEC_DATA_DIRECT_8023 2
723 #define LEC_DATA_DIRECT_8025 3
725 static int lec_is_data_direct(struct atm_vcc
*vcc
)
727 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
728 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
731 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
734 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
735 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
741 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
745 DPRINTK("%s: null skb\n", dev
->name
);
746 lec_vcc_close(priv
, vcc
);
750 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
751 skb
->len
, priv
->lecid
);
752 #if DUMP_PACKETS >= 2
753 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
754 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
756 #elif DUMP_PACKETS >= 1
757 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
758 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
760 #endif /* DUMP_PACKETS >= 1 */
764 printk("%s...\n", buf
);
765 #endif /* DUMP_PACKETS > 0 */
766 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
767 struct sock
*sk
= sk_atm(vcc
);
769 DPRINTK("%s: To daemon\n", dev
->name
);
770 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
771 sk
->sk_data_ready(sk
, skb
->len
);
772 } else { /* Data frame, queue to protocol handlers */
773 struct lec_arp_table
*entry
;
774 unsigned char *src
, *dst
;
776 atm_return(vcc
, skb
->truesize
);
777 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
778 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
780 * Probably looping back, or if lecd is missing,
783 DPRINTK("Ignoring frame...\n");
789 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
792 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
795 * If this is a Data Direct VCC, and the VCC does not match
796 * the LE_ARP cache entry, delete the LE_ARP cache entry.
798 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
799 if (lec_is_data_direct(vcc
)) {
803 ((struct lecdatahdr_8025
*)skb
->data
)->
808 ((struct lecdatahdr_8023
*)skb
->data
)->
810 entry
= lec_arp_find(priv
, src
);
811 if (entry
&& entry
->vcc
!= vcc
) {
812 lec_arp_remove(priv
, entry
);
816 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
818 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
819 !priv
->is_proxy
&& /* Proxy wants all the packets */
820 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
824 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
825 lec_arp_check_empties(priv
, vcc
, skb
);
827 skb_pull(skb
, 2); /* skip lec_id */
830 skb
->protocol
= tr_type_trans(skb
, dev
);
833 skb
->protocol
= eth_type_trans(skb
, dev
);
834 priv
->stats
.rx_packets
++;
835 priv
->stats
.rx_bytes
+= skb
->len
;
836 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
841 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
843 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
844 struct net_device
*dev
= skb
->dev
;
847 printk("lec_pop(): vpriv = NULL!?!?!?\n");
851 vpriv
->old_pop(vcc
, skb
);
853 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
855 if (netif_running(dev
) && netif_queue_stopped(dev
))
856 netif_wake_queue(dev
);
860 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
862 struct lec_vcc_priv
*vpriv
;
864 struct atmlec_ioc ioc_data
;
866 /* Lecd must be up in this case */
867 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
868 if (bytes_left
!= 0) {
870 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
873 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
874 !dev_lec
[ioc_data
.dev_num
])
876 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
879 vpriv
->old_pop
= vcc
->pop
;
880 vcc
->user_back
= vpriv
;
882 lec_vcc_added(dev_lec
[ioc_data
.dev_num
]->priv
,
883 &ioc_data
, vcc
, vcc
->push
);
884 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
885 vcc
->push
= lec_push
;
889 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
891 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
893 vcc
->proto_data
= dev_lec
[arg
];
894 return (lec_mcast_make((struct lec_priv
*)dev_lec
[arg
]->priv
, vcc
));
897 /* Initialize device. */
898 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
901 struct lec_priv
*priv
;
908 if (arg
>= MAX_LEC_ITF
)
910 #else /* Reserve the top NUM_TR_DEVS for TR */
911 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
918 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
921 size
= sizeof(struct lec_priv
);
924 dev_lec
[i
] = alloc_trdev(size
);
927 dev_lec
[i
] = alloc_etherdev(size
);
930 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
931 if (register_netdev(dev_lec
[i
])) {
932 free_netdev(dev_lec
[i
]);
936 priv
= dev_lec
[i
]->priv
;
937 priv
->is_trdev
= is_trdev
;
938 lec_init(dev_lec
[i
]);
940 priv
= dev_lec
[i
]->priv
;
945 priv
->itfnum
= i
; /* LANE2 addition */
947 vcc
->dev
= &lecatm_dev
;
948 vcc_insert_socket(sk_atm(vcc
));
950 vcc
->proto_data
= dev_lec
[i
];
951 set_bit(ATM_VF_META
, &vcc
->flags
);
952 set_bit(ATM_VF_READY
, &vcc
->flags
);
954 /* Set default values to these variables */
955 priv
->maximum_unknown_frame_count
= 1;
956 priv
->max_unknown_frame_time
= (1 * HZ
);
957 priv
->vcc_timeout_period
= (1200 * HZ
);
958 priv
->max_retry_count
= 1;
959 priv
->aging_time
= (300 * HZ
);
960 priv
->forward_delay_time
= (15 * HZ
);
961 priv
->topology_change
= 0;
962 priv
->arp_response_time
= (1 * HZ
);
963 priv
->flush_timeout
= (4 * HZ
);
964 priv
->path_switching_delay
= (6 * HZ
);
966 if (dev_lec
[i
]->flags
& IFF_UP
) {
967 netif_start_queue(dev_lec
[i
]);
969 __module_get(THIS_MODULE
);
973 #ifdef CONFIG_PROC_FS
974 static char *lec_arp_get_status_string(unsigned char status
)
976 static char *lec_arp_status_string
[] = {
981 "ESI_FLUSH_PENDING ",
985 if (status
> ESI_FORWARD_DIRECT
)
986 status
= 3; /* ESI_UNDEFINED */
987 return lec_arp_status_string
[status
];
990 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
994 for (i
= 0; i
< ETH_ALEN
; i
++)
995 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
996 seq_printf(seq
, " ");
997 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
998 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
999 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
1000 entry
->flags
& 0xffff);
1002 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
1004 seq_printf(seq
, " ");
1005 if (entry
->recv_vcc
) {
1006 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
1007 entry
->recv_vcc
->vci
);
1009 seq_putc(seq
, '\n');
1013 unsigned long flags
;
1014 struct lec_priv
*locked
;
1015 struct hlist_node
*node
;
1016 struct net_device
*dev
;
1022 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
1025 struct hlist_node
*e
= state
->node
;
1026 struct lec_arp_table
*tmp
;
1030 if (e
== (void *)1) {
1035 hlist_for_each_entry_from(tmp
, e
, next
) {
1041 return (*l
< 0) ? state
: NULL
;
1044 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1045 struct lec_priv
*priv
)
1050 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1051 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1055 state
->arp_table
= p
;
1059 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1060 struct lec_priv
*priv
)
1062 struct hlist_head
*lec_misc_tables
[] = {
1063 &priv
->lec_arp_empty_ones
,
1064 &priv
->lec_no_forward
,
1070 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1071 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1075 state
->misc_table
= q
;
1079 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1080 struct lec_priv
*priv
)
1082 if (!state
->locked
) {
1083 state
->locked
= priv
;
1084 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1086 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1087 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1088 state
->locked
= NULL
;
1089 /* Partial state reset for the next time we get called */
1090 state
->arp_table
= state
->misc_table
= 0;
1092 return state
->locked
;
1095 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1097 struct net_device
*dev
;
1100 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1101 v
= (dev
&& dev
->priv
) ? lec_priv_walk(state
, l
, dev
->priv
) : NULL
;
1104 /* Partial state reset for the next time we get called */
1111 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1115 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1116 v
= lec_itf_walk(state
, &l
);
1123 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1125 struct lec_state
*state
= seq
->private;
1129 state
->locked
= NULL
;
1130 state
->arp_table
= 0;
1131 state
->misc_table
= 0;
1132 state
->node
= (void *)1;
1134 return *pos
? lec_get_idx(state
, *pos
) : (void *)1;
1137 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1139 struct lec_state
*state
= seq
->private;
1142 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1144 dev_put(state
->dev
);
1148 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1150 struct lec_state
*state
= seq
->private;
1152 v
= lec_get_idx(state
, 1);
1153 *pos
+= !!PTR_ERR(v
);
1157 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1159 static char lec_banner
[] = "Itf MAC ATM destination"
1161 "VPI/VCI Recv VPI/VCI\n";
1164 seq_puts(seq
, lec_banner
);
1166 struct lec_state
*state
= seq
->private;
1167 struct net_device
*dev
= state
->dev
;
1168 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1170 seq_printf(seq
, "%s ", dev
->name
);
1171 lec_info(seq
, entry
);
1176 static const struct seq_operations lec_seq_ops
= {
1177 .start
= lec_seq_start
,
1178 .next
= lec_seq_next
,
1179 .stop
= lec_seq_stop
,
1180 .show
= lec_seq_show
,
1183 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1185 struct lec_state
*state
;
1186 struct seq_file
*seq
;
1189 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
1195 rc
= seq_open(file
, &lec_seq_ops
);
1198 seq
= file
->private_data
;
1199 seq
->private = state
;
1208 static int lec_seq_release(struct inode
*inode
, struct file
*file
)
1210 return seq_release_private(inode
, file
);
1213 static const struct file_operations lec_seq_fops
= {
1214 .owner
= THIS_MODULE
,
1215 .open
= lec_seq_open
,
1217 .llseek
= seq_lseek
,
1218 .release
= lec_seq_release
,
1222 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1224 struct atm_vcc
*vcc
= ATM_SD(sock
);
1231 if (!capable(CAP_NET_ADMIN
))
1235 return -ENOIOCTLCMD
;
1240 err
= lecd_attach(vcc
, (int)arg
);
1242 sock
->state
= SS_CONNECTED
;
1245 err
= lec_mcast_attach(vcc
, (int)arg
);
1248 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1255 static struct atm_ioctl lane_ioctl_ops
= {
1256 .owner
= THIS_MODULE
,
1257 .ioctl
= lane_ioctl
,
1260 static int __init
lane_module_init(void)
1262 #ifdef CONFIG_PROC_FS
1263 struct proc_dir_entry
*p
;
1265 p
= create_proc_entry("lec", S_IRUGO
, atm_proc_root
);
1267 p
->proc_fops
= &lec_seq_fops
;
1270 register_atm_ioctl(&lane_ioctl_ops
);
1271 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1275 static void __exit
lane_module_cleanup(void)
1278 struct lec_priv
*priv
;
1280 remove_proc_entry("lec", atm_proc_root
);
1282 deregister_atm_ioctl(&lane_ioctl_ops
);
1284 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1285 if (dev_lec
[i
] != NULL
) {
1286 priv
= (struct lec_priv
*)dev_lec
[i
]->priv
;
1287 unregister_netdev(dev_lec
[i
]);
1288 free_netdev(dev_lec
[i
]);
1296 module_init(lane_module_init
);
1297 module_exit(lane_module_cleanup
);
1300 * LANE2: 3.1.3, LE_RESOLVE.request
1301 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1302 * If sizeoftlvs == NULL the default TLVs associated with with this
1304 * If dst_mac == NULL, targetless LE_ARP will be sent
1306 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
1307 u8
**tlvs
, u32
*sizeoftlvs
)
1309 unsigned long flags
;
1310 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1311 struct lec_arp_table
*table
;
1312 struct sk_buff
*skb
;
1316 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1317 table
= lec_arp_find(priv
, dst_mac
);
1318 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1322 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1326 *sizeoftlvs
= table
->sizeoftlvs
;
1331 if (sizeoftlvs
== NULL
)
1332 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1335 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1338 skb
->len
= *sizeoftlvs
;
1339 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1340 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1346 * LANE2: 3.1.4, LE_ASSOCIATE.request
1347 * Associate the *tlvs with the *lan_dst address.
1348 * Will overwrite any previous association
1349 * Returns 1 for success, 0 for failure (out of memory)
1352 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
1353 u8
*tlvs
, u32 sizeoftlvs
)
1356 struct sk_buff
*skb
;
1357 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1359 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1360 return (0); /* not our mac address */
1362 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1364 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1365 if (priv
->tlvs
== NULL
)
1367 priv
->sizeoftlvs
= sizeoftlvs
;
1369 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1372 skb
->len
= sizeoftlvs
;
1373 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1374 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1376 printk("lec.c: lane2_associate_req() failed\n");
1378 * If the previous association has changed we must
1379 * somehow notify other LANE entities about the change
1385 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1388 static void lane2_associate_ind(struct net_device
*dev
, u8
*mac_addr
,
1389 u8
*tlvs
, u32 sizeoftlvs
)
1394 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1396 * Why have the TLVs in LE_ARP entries
1397 * since we do not use them? When you
1398 * uncomment this code, make sure the
1399 * TLVs get freed when entry is killed
1401 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1404 return; /* should not happen */
1408 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1409 if (entry
->tlvs
== NULL
)
1411 entry
->sizeoftlvs
= sizeoftlvs
;
1414 printk("lec.c: lane2_associate_ind()\n");
1415 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1416 while (i
< sizeoftlvs
)
1417 printk("%02x ", tlvs
[i
++]);
1422 /* tell MPOA about the TLVs we saw */
1423 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1424 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1431 * Here starts what used to lec_arpc.c
1433 * lec_arpc.c was added here when making
1434 * lane client modular. October 1997
1437 #include <linux/types.h>
1438 #include <linux/timer.h>
1439 #include <asm/param.h>
1440 #include <asm/atomic.h>
1441 #include <linux/inetdevice.h>
1442 #include <net/route.h>
1445 #define DPRINTK(format,args...)
1447 #define DPRINTK printk
1450 #define DEBUG_ARP_TABLE 0
1452 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1454 static void lec_arp_check_expire(struct work_struct
*work
);
1455 static void lec_arp_expire_arp(unsigned long data
);
1461 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1464 * Initialization of arp-cache
1466 static void lec_arp_init(struct lec_priv
*priv
)
1470 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1471 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1473 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1474 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1475 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1476 spin_lock_init(&priv
->lec_arp_lock
);
1477 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1478 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1481 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1484 struct atm_vcc
*vcc
= entry
->vcc
;
1485 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1486 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1488 vcc
->pop
= vpriv
->old_pop
;
1490 netif_wake_queue(dev
);
1492 vcc
->user_back
= NULL
;
1493 vcc
->push
= entry
->old_push
;
1494 vcc_release_async(vcc
, -EPIPE
);
1497 if (entry
->recv_vcc
) {
1498 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1499 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1500 entry
->recv_vcc
= NULL
;
1505 * Insert entry to lec_arp_table
1506 * LANE2: Add to the end of the list to satisfy 8.1.13
1509 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1511 struct hlist_head
*tmp
;
1513 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1514 hlist_add_head(&entry
->next
, tmp
);
1516 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1517 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1518 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1519 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1523 * Remove entry from lec_arp_table
1526 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1528 struct hlist_node
*node
;
1529 struct lec_arp_table
*entry
;
1530 int i
, remove_vcc
= 1;
1536 hlist_del(&to_remove
->next
);
1537 del_timer(&to_remove
->timer
);
1539 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1540 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1542 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1544 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1545 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1546 if (memcmp(to_remove
->atm_addr
,
1547 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1554 lec_arp_clear_vccs(to_remove
);
1556 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1558 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1559 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1560 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1561 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1566 static char *get_status_string(unsigned char st
)
1570 return "ESI_UNKNOWN";
1571 case ESI_ARP_PENDING
:
1572 return "ESI_ARP_PENDING";
1573 case ESI_VC_PENDING
:
1574 return "ESI_VC_PENDING";
1575 case ESI_FLUSH_PENDING
:
1576 return "ESI_FLUSH_PENDING";
1577 case ESI_FORWARD_DIRECT
:
1578 return "ESI_FORWARD_DIRECT";
1584 static void dump_arp_table(struct lec_priv
*priv
)
1586 struct hlist_node
*node
;
1587 struct lec_arp_table
*rulla
;
1591 printk("Dump %p:\n", priv
);
1592 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1593 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1595 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1596 offset
+= sprintf(buf
+ offset
, "Mac:");
1597 for (j
= 0; j
< ETH_ALEN
; j
++) {
1598 offset
+= sprintf(buf
+ offset
,
1600 rulla
->mac_addr
[j
] & 0xff);
1602 offset
+= sprintf(buf
+ offset
, "Atm:");
1603 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1604 offset
+= sprintf(buf
+ offset
,
1606 rulla
->atm_addr
[j
] & 0xff);
1608 offset
+= sprintf(buf
+ offset
,
1609 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1610 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1611 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1612 rulla
->recv_vcc
? rulla
->recv_vcc
->
1614 rulla
->recv_vcc
? rulla
->recv_vcc
->
1615 vci
: 0, rulla
->last_used
,
1616 rulla
->timestamp
, rulla
->no_tries
);
1618 sprintf(buf
+ offset
,
1619 "Flags:%x, Packets_flooded:%x, Status: %s ",
1620 rulla
->flags
, rulla
->packets_flooded
,
1621 get_status_string(rulla
->status
));
1622 printk("%s\n", buf
);
1626 if (!hlist_empty(&priv
->lec_no_forward
))
1627 printk("No forward\n");
1628 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1630 offset
+= sprintf(buf
+ offset
, "Mac:");
1631 for (j
= 0; j
< ETH_ALEN
; j
++) {
1632 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1633 rulla
->mac_addr
[j
] & 0xff);
1635 offset
+= sprintf(buf
+ offset
, "Atm:");
1636 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1637 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1638 rulla
->atm_addr
[j
] & 0xff);
1640 offset
+= sprintf(buf
+ offset
,
1641 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1642 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1643 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1644 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1645 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1647 rulla
->timestamp
, rulla
->no_tries
);
1648 offset
+= sprintf(buf
+ offset
,
1649 "Flags:%x, Packets_flooded:%x, Status: %s ",
1650 rulla
->flags
, rulla
->packets_flooded
,
1651 get_status_string(rulla
->status
));
1652 printk("%s\n", buf
);
1655 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1656 printk("Empty ones\n");
1657 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1659 offset
+= sprintf(buf
+ offset
, "Mac:");
1660 for (j
= 0; j
< ETH_ALEN
; j
++) {
1661 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1662 rulla
->mac_addr
[j
] & 0xff);
1664 offset
+= sprintf(buf
+ offset
, "Atm:");
1665 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1666 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1667 rulla
->atm_addr
[j
] & 0xff);
1669 offset
+= sprintf(buf
+ offset
,
1670 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1671 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1672 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1673 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1674 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1676 rulla
->timestamp
, rulla
->no_tries
);
1677 offset
+= sprintf(buf
+ offset
,
1678 "Flags:%x, Packets_flooded:%x, Status: %s ",
1679 rulla
->flags
, rulla
->packets_flooded
,
1680 get_status_string(rulla
->status
));
1684 if (!hlist_empty(&priv
->mcast_fwds
))
1685 printk("Multicast Forward VCCs\n");
1686 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1688 offset
+= sprintf(buf
+ offset
, "Mac:");
1689 for (j
= 0; j
< ETH_ALEN
; j
++) {
1690 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1691 rulla
->mac_addr
[j
] & 0xff);
1693 offset
+= sprintf(buf
+ offset
, "Atm:");
1694 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1695 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1696 rulla
->atm_addr
[j
] & 0xff);
1698 offset
+= sprintf(buf
+ offset
,
1699 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1700 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1701 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1702 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1703 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1705 rulla
->timestamp
, rulla
->no_tries
);
1706 offset
+= sprintf(buf
+ offset
,
1707 "Flags:%x, Packets_flooded:%x, Status: %s ",
1708 rulla
->flags
, rulla
->packets_flooded
,
1709 get_status_string(rulla
->status
));
1710 printk("%s\n", buf
);
1715 #define dump_arp_table(priv) do { } while (0)
1719 * Destruction of arp-cache
1721 static void lec_arp_destroy(struct lec_priv
*priv
)
1723 unsigned long flags
;
1724 struct hlist_node
*node
, *next
;
1725 struct lec_arp_table
*entry
;
1728 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1731 * Remove all entries
1734 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1735 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1736 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1737 lec_arp_remove(priv
, entry
);
1740 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1743 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1744 del_timer_sync(&entry
->timer
);
1745 lec_arp_clear_vccs(entry
);
1746 hlist_del(&entry
->next
);
1749 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1751 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1752 del_timer_sync(&entry
->timer
);
1753 lec_arp_clear_vccs(entry
);
1754 hlist_del(&entry
->next
);
1757 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1759 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1760 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1761 lec_arp_clear_vccs(entry
);
1762 hlist_del(&entry
->next
);
1765 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1766 priv
->mcast_vcc
= NULL
;
1767 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1771 * Find entry by mac_address
1773 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1774 unsigned char *mac_addr
)
1776 struct hlist_node
*node
;
1777 struct hlist_head
*head
;
1778 struct lec_arp_table
*entry
;
1780 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1781 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1782 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1784 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1785 hlist_for_each_entry(entry
, node
, head
, next
) {
1786 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1793 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1794 unsigned char *mac_addr
)
1796 struct lec_arp_table
*to_return
;
1798 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1800 printk("LEC: Arp entry kmalloc failed\n");
1803 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1804 INIT_HLIST_NODE(&to_return
->next
);
1805 init_timer(&to_return
->timer
);
1806 to_return
->timer
.function
= lec_arp_expire_arp
;
1807 to_return
->timer
.data
= (unsigned long)to_return
;
1808 to_return
->last_used
= jiffies
;
1809 to_return
->priv
= priv
;
1810 skb_queue_head_init(&to_return
->tx_wait
);
1811 atomic_set(&to_return
->usage
, 1);
1815 /* Arp sent timer expired */
1816 static void lec_arp_expire_arp(unsigned long data
)
1818 struct lec_arp_table
*entry
;
1820 entry
= (struct lec_arp_table
*)data
;
1822 DPRINTK("lec_arp_expire_arp\n");
1823 if (entry
->status
== ESI_ARP_PENDING
) {
1824 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1825 if (entry
->is_rdesc
)
1826 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1827 entry
->mac_addr
, NULL
, NULL
);
1829 send_to_lecd(entry
->priv
, l_arp_xmt
,
1830 entry
->mac_addr
, NULL
, NULL
);
1833 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1837 /* Unknown/unused vcc expire, remove associated entry */
1838 static void lec_arp_expire_vcc(unsigned long data
)
1840 unsigned long flags
;
1841 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1842 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1844 del_timer(&to_remove
->timer
);
1846 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1848 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1849 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1851 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1852 hlist_del(&to_remove
->next
);
1853 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1855 lec_arp_clear_vccs(to_remove
);
1856 lec_arp_put(to_remove
);
1862 * 2. For each entry, delete entries that have aged past the age limit.
1863 * 3. For each entry, depending on the status of the entry, perform
1864 * the following maintenance.
1865 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1866 * tick_count is above the max_unknown_frame_time, clear
1867 * the tick_count to zero and clear the packets_flooded counter
1868 * to zero. This supports the packet rate limit per address
1869 * while flooding unknowns.
1870 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1871 * than or equal to the path_switching_delay, change the status
1872 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1873 * regardless of the progress of the flush protocol.
1875 static void lec_arp_check_expire(struct work_struct
*work
)
1877 unsigned long flags
;
1878 struct lec_priv
*priv
=
1879 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1880 struct hlist_node
*node
, *next
;
1881 struct lec_arp_table
*entry
;
1883 unsigned long time_to_check
;
1886 DPRINTK("lec_arp_check_expire %p\n", priv
);
1889 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1890 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1891 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1892 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1893 priv
->topology_change
)
1894 time_to_check
= priv
->forward_delay_time
;
1896 time_to_check
= priv
->aging_time
;
1898 DPRINTK("About to expire: %lx - %lx > %lx\n",
1899 now
, entry
->last_used
, time_to_check
);
1900 if (time_after(now
, entry
->last_used
+ time_to_check
)
1901 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1902 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1904 DPRINTK("LEC:Entry timed out\n");
1905 lec_arp_remove(priv
, entry
);
1908 /* Something else */
1909 if ((entry
->status
== ESI_VC_PENDING
||
1910 entry
->status
== ESI_ARP_PENDING
)
1911 && time_after_eq(now
,
1914 max_unknown_frame_time
)) {
1915 entry
->timestamp
= jiffies
;
1916 entry
->packets_flooded
= 0;
1917 if (entry
->status
== ESI_VC_PENDING
)
1918 send_to_lecd(priv
, l_svc_setup
,
1923 if (entry
->status
== ESI_FLUSH_PENDING
1925 time_after_eq(now
, entry
->timestamp
+
1926 priv
->path_switching_delay
)) {
1927 struct sk_buff
*skb
;
1928 struct atm_vcc
*vcc
= entry
->vcc
;
1930 lec_arp_hold(entry
);
1931 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1932 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1933 lec_send(vcc
, skb
, entry
->priv
);
1934 entry
->last_used
= jiffies
;
1935 entry
->status
= ESI_FORWARD_DIRECT
;
1942 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1944 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1948 * Try to find vcc where mac_address is attached.
1951 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1952 unsigned char *mac_to_find
, int is_rdesc
,
1953 struct lec_arp_table
**ret_entry
)
1955 unsigned long flags
;
1956 struct lec_arp_table
*entry
;
1957 struct atm_vcc
*found
;
1959 if (mac_to_find
[0] & 0x01) {
1960 switch (priv
->lane_version
) {
1962 return priv
->mcast_vcc
;
1964 case 2: /* LANE2 wants arp for multicast addresses */
1965 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1966 return priv
->mcast_vcc
;
1973 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1974 entry
= lec_arp_find(priv
, mac_to_find
);
1977 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1979 entry
->last_used
= jiffies
;
1980 lec_arp_hold(entry
);
1986 * If the LE_ARP cache entry is still pending, reset count to 0
1987 * so another LE_ARP request can be made for this frame.
1989 if (entry
->status
== ESI_ARP_PENDING
) {
1990 entry
->no_tries
= 0;
1993 * Data direct VC not yet set up, check to see if the unknown
1994 * frame count is greater than the limit. If the limit has
1995 * not been reached, allow the caller to send packet to
1998 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1999 entry
->packets_flooded
<
2000 priv
->maximum_unknown_frame_count
) {
2001 entry
->packets_flooded
++;
2002 DPRINTK("LEC_ARP: Flooding..\n");
2003 found
= priv
->mcast_vcc
;
2007 * We got here because entry->status == ESI_FLUSH_PENDING
2008 * or BUS flood limit was reached for an entry which is
2009 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2011 lec_arp_hold(entry
);
2013 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry
->status
,
2017 /* No matching entry was found */
2018 entry
= make_entry(priv
, mac_to_find
);
2019 DPRINTK("LEC_ARP: Making entry\n");
2021 found
= priv
->mcast_vcc
;
2024 lec_arp_add(priv
, entry
);
2025 /* We want arp-request(s) to be sent */
2026 entry
->packets_flooded
= 1;
2027 entry
->status
= ESI_ARP_PENDING
;
2028 entry
->no_tries
= 1;
2029 entry
->last_used
= entry
->timestamp
= jiffies
;
2030 entry
->is_rdesc
= is_rdesc
;
2031 if (entry
->is_rdesc
)
2032 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
2035 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
2036 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
2037 entry
->timer
.function
= lec_arp_expire_arp
;
2038 add_timer(&entry
->timer
);
2039 found
= priv
->mcast_vcc
;
2043 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2048 lec_addr_delete(struct lec_priv
*priv
, unsigned char *atm_addr
,
2049 unsigned long permanent
)
2051 unsigned long flags
;
2052 struct hlist_node
*node
, *next
;
2053 struct lec_arp_table
*entry
;
2056 DPRINTK("lec_addr_delete\n");
2057 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2058 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2059 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2060 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2062 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2063 lec_arp_remove(priv
, entry
);
2066 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2070 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2075 * Notifies: Response to arp_request (atm_addr != NULL)
2078 lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
2079 unsigned char *atm_addr
, unsigned long remoteflag
,
2080 unsigned int targetless_le_arp
)
2082 unsigned long flags
;
2083 struct hlist_node
*node
, *next
;
2084 struct lec_arp_table
*entry
, *tmp
;
2087 DPRINTK("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2088 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2089 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2090 mac_addr
[4], mac_addr
[5]);
2092 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2093 entry
= lec_arp_find(priv
, mac_addr
);
2094 if (entry
== NULL
&& targetless_le_arp
)
2096 * LANE2: ignore targetless LE_ARPs for which
2097 * we have no entry in the cache. 7.1.30
2099 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2100 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2101 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2102 hlist_del(&entry
->next
);
2103 del_timer(&entry
->timer
);
2104 tmp
= lec_arp_find(priv
, mac_addr
);
2106 del_timer(&tmp
->timer
);
2107 tmp
->status
= ESI_FORWARD_DIRECT
;
2108 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2109 tmp
->vcc
= entry
->vcc
;
2110 tmp
->old_push
= entry
->old_push
;
2111 tmp
->last_used
= jiffies
;
2112 del_timer(&entry
->timer
);
2116 entry
->status
= ESI_FORWARD_DIRECT
;
2117 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2118 entry
->last_used
= jiffies
;
2119 lec_arp_add(priv
, entry
);
2122 entry
->flags
|= LEC_REMOTE_FLAG
;
2124 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2125 DPRINTK("After update\n");
2126 dump_arp_table(priv
);
2132 entry
= lec_arp_find(priv
, mac_addr
);
2134 entry
= make_entry(priv
, mac_addr
);
2137 entry
->status
= ESI_UNKNOWN
;
2138 lec_arp_add(priv
, entry
);
2139 /* Temporary, changes before end of function */
2141 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2142 del_timer(&entry
->timer
);
2143 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2144 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2146 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2147 /* Vcc to this host exists */
2148 if (tmp
->status
> ESI_VC_PENDING
) {
2150 * ESI_FLUSH_PENDING,
2151 * ESI_FORWARD_DIRECT
2153 entry
->vcc
= tmp
->vcc
;
2154 entry
->old_push
= tmp
->old_push
;
2156 entry
->status
= tmp
->status
;
2162 entry
->flags
|= LEC_REMOTE_FLAG
;
2164 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2165 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2166 entry
->status
= ESI_VC_PENDING
;
2167 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2169 DPRINTK("After update2\n");
2170 dump_arp_table(priv
);
2172 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2176 * Notifies: Vcc setup ready
2179 lec_vcc_added(struct lec_priv
*priv
, struct atmlec_ioc
*ioc_data
,
2180 struct atm_vcc
*vcc
,
2181 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2183 unsigned long flags
;
2184 struct hlist_node
*node
;
2185 struct lec_arp_table
*entry
;
2186 int i
, found_entry
= 0;
2188 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2189 if (ioc_data
->receive
== 2) {
2190 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2192 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2194 entry
= lec_arp_find(priv
, bus_mac
);
2196 printk("LEC_ARP: Multicast entry not found!\n");
2199 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2200 entry
->recv_vcc
= vcc
;
2201 entry
->old_recv_push
= old_push
;
2203 entry
= make_entry(priv
, bus_mac
);
2206 del_timer(&entry
->timer
);
2207 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2208 entry
->recv_vcc
= vcc
;
2209 entry
->old_recv_push
= old_push
;
2210 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2212 } else if (ioc_data
->receive
== 1) {
2214 * Vcc which we don't want to make default vcc,
2218 ("LEC_ARP:Attaching data direct, not default: "
2219 "%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",
2220 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2221 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2222 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2223 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2224 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2225 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2226 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2227 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2228 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2229 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2230 entry
= make_entry(priv
, bus_mac
);
2233 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2234 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2235 entry
->recv_vcc
= vcc
;
2236 entry
->old_recv_push
= old_push
;
2237 entry
->status
= ESI_UNKNOWN
;
2238 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2239 entry
->timer
.function
= lec_arp_expire_vcc
;
2240 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2241 add_timer(&entry
->timer
);
2242 dump_arp_table(priv
);
2246 ("LEC_ARP:Attaching data direct, default: "
2247 "%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",
2248 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2249 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2250 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2251 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2252 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2253 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2254 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2255 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2256 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2257 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2258 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2259 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2261 (ioc_data
->atm_addr
, entry
->atm_addr
,
2262 ATM_ESA_LEN
) == 0) {
2263 DPRINTK("LEC_ARP: Attaching data direct\n");
2264 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2265 entry
->vcc
? entry
->vcc
->vci
: 0,
2266 entry
->recv_vcc
? entry
->recv_vcc
->
2269 del_timer(&entry
->timer
);
2271 entry
->old_push
= old_push
;
2272 if (entry
->status
== ESI_VC_PENDING
) {
2273 if (priv
->maximum_unknown_frame_count
2278 entry
->timestamp
= jiffies
;
2282 send_to_lecd(priv
, l_flush_xmt
,
2290 * They were forming a connection
2291 * to us, and we to them. Our
2292 * ATM address is numerically lower
2293 * than theirs, so we make connection
2294 * we formed into default VCC (8.1.11).
2295 * Connection they made gets torn
2296 * down. This might confuse some
2297 * clients. Can be changed if
2298 * someone reports trouble...
2306 DPRINTK("After vcc was added\n");
2307 dump_arp_table(priv
);
2311 * Not found, snatch address from first data packet that arrives
2314 entry
= make_entry(priv
, bus_mac
);
2318 entry
->old_push
= old_push
;
2319 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2320 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2321 entry
->status
= ESI_UNKNOWN
;
2322 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2323 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2324 entry
->timer
.function
= lec_arp_expire_vcc
;
2325 add_timer(&entry
->timer
);
2326 DPRINTK("After vcc was added\n");
2327 dump_arp_table(priv
);
2329 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2332 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2334 unsigned long flags
;
2335 struct hlist_node
*node
;
2336 struct lec_arp_table
*entry
;
2339 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id
);
2341 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2342 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2343 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2344 if (entry
->flush_tran_id
== tran_id
2345 && entry
->status
== ESI_FLUSH_PENDING
) {
2346 struct sk_buff
*skb
;
2347 struct atm_vcc
*vcc
= entry
->vcc
;
2349 lec_arp_hold(entry
);
2350 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2351 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2352 lec_send(vcc
, skb
, entry
->priv
);
2353 entry
->last_used
= jiffies
;
2354 entry
->status
= ESI_FORWARD_DIRECT
;
2356 DPRINTK("LEC_ARP: Flushed\n");
2361 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2362 dump_arp_table(priv
);
2366 lec_set_flush_tran_id(struct lec_priv
*priv
,
2367 unsigned char *atm_addr
, unsigned long tran_id
)
2369 unsigned long flags
;
2370 struct hlist_node
*node
;
2371 struct lec_arp_table
*entry
;
2374 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2375 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2376 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2377 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2378 entry
->flush_tran_id
= tran_id
;
2379 DPRINTK("Set flush transaction id to %lx for %p\n",
2383 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2386 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2388 unsigned long flags
;
2389 unsigned char mac_addr
[] = {
2390 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2392 struct lec_arp_table
*to_add
;
2393 struct lec_vcc_priv
*vpriv
;
2396 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2399 vpriv
->old_pop
= vcc
->pop
;
2400 vcc
->user_back
= vpriv
;
2402 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2403 to_add
= make_entry(priv
, mac_addr
);
2405 vcc
->pop
= vpriv
->old_pop
;
2410 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2411 to_add
->status
= ESI_FORWARD_DIRECT
;
2412 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2414 to_add
->old_push
= vcc
->push
;
2415 vcc
->push
= lec_push
;
2416 priv
->mcast_vcc
= vcc
;
2417 lec_arp_add(priv
, to_add
);
2419 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2423 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2425 unsigned long flags
;
2426 struct hlist_node
*node
, *next
;
2427 struct lec_arp_table
*entry
;
2430 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2431 dump_arp_table(priv
);
2433 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2435 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2436 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2437 if (vcc
== entry
->vcc
) {
2438 lec_arp_remove(priv
, entry
);
2440 if (priv
->mcast_vcc
== vcc
) {
2441 priv
->mcast_vcc
= NULL
;
2447 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2448 if (entry
->vcc
== vcc
) {
2449 lec_arp_clear_vccs(entry
);
2450 del_timer(&entry
->timer
);
2451 hlist_del(&entry
->next
);
2456 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2457 if (entry
->recv_vcc
== vcc
) {
2458 lec_arp_clear_vccs(entry
);
2459 del_timer(&entry
->timer
);
2460 hlist_del(&entry
->next
);
2465 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2466 if (entry
->recv_vcc
== vcc
) {
2467 lec_arp_clear_vccs(entry
);
2468 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2469 hlist_del(&entry
->next
);
2474 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2475 dump_arp_table(priv
);
2479 lec_arp_check_empties(struct lec_priv
*priv
,
2480 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2482 unsigned long flags
;
2483 struct hlist_node
*node
, *next
;
2484 struct lec_arp_table
*entry
, *tmp
;
2485 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2488 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2491 src
= tr_hdr
->h_source
;
2494 src
= hdr
->h_source
;
2496 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2497 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2498 if (vcc
== entry
->vcc
) {
2499 del_timer(&entry
->timer
);
2500 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2501 entry
->status
= ESI_FORWARD_DIRECT
;
2502 entry
->last_used
= jiffies
;
2503 /* We might have got an entry */
2504 if ((tmp
= lec_arp_find(priv
, src
))) {
2505 lec_arp_remove(priv
, tmp
);
2508 hlist_del(&entry
->next
);
2509 lec_arp_add(priv
, entry
);
2513 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2515 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2518 MODULE_LICENSE("GPL");