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
= (struct lec_priv
*)dev
->priv
;
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
= (struct lec_priv
*)dev
->priv
;
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
= (struct lec_priv
*)dev
->priv
;
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
*)dev
->priv
)->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
= (struct lec_priv
*)dev
->priv
;
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
= (struct lec_priv
*)dev
->priv
;
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
= (struct lec_priv
*)dev
->priv
;
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(dev_lec
[ioc_data
.dev_num
]->priv
,
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
*)dev_lec
[arg
]->priv
, vcc
));
876 /* Initialize device. */
877 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
880 struct lec_priv
*priv
;
887 if (arg
>= MAX_LEC_ITF
)
889 #else /* Reserve the top NUM_TR_DEVS for TR */
890 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
897 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
900 size
= sizeof(struct lec_priv
);
903 dev_lec
[i
] = alloc_trdev(size
);
906 dev_lec
[i
] = alloc_etherdev(size
);
909 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
910 if (register_netdev(dev_lec
[i
])) {
911 free_netdev(dev_lec
[i
]);
915 priv
= dev_lec
[i
]->priv
;
916 priv
->is_trdev
= is_trdev
;
917 lec_init(dev_lec
[i
]);
919 priv
= dev_lec
[i
]->priv
;
924 priv
->itfnum
= i
; /* LANE2 addition */
926 vcc
->dev
= &lecatm_dev
;
927 vcc_insert_socket(sk_atm(vcc
));
929 vcc
->proto_data
= dev_lec
[i
];
930 set_bit(ATM_VF_META
, &vcc
->flags
);
931 set_bit(ATM_VF_READY
, &vcc
->flags
);
933 /* Set default values to these variables */
934 priv
->maximum_unknown_frame_count
= 1;
935 priv
->max_unknown_frame_time
= (1 * HZ
);
936 priv
->vcc_timeout_period
= (1200 * HZ
);
937 priv
->max_retry_count
= 1;
938 priv
->aging_time
= (300 * HZ
);
939 priv
->forward_delay_time
= (15 * HZ
);
940 priv
->topology_change
= 0;
941 priv
->arp_response_time
= (1 * HZ
);
942 priv
->flush_timeout
= (4 * HZ
);
943 priv
->path_switching_delay
= (6 * HZ
);
945 if (dev_lec
[i
]->flags
& IFF_UP
) {
946 netif_start_queue(dev_lec
[i
]);
948 __module_get(THIS_MODULE
);
952 #ifdef CONFIG_PROC_FS
953 static char *lec_arp_get_status_string(unsigned char status
)
955 static char *lec_arp_status_string
[] = {
960 "ESI_FLUSH_PENDING ",
964 if (status
> ESI_FORWARD_DIRECT
)
965 status
= 3; /* ESI_UNDEFINED */
966 return lec_arp_status_string
[status
];
969 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
973 for (i
= 0; i
< ETH_ALEN
; i
++)
974 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
975 seq_printf(seq
, " ");
976 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
977 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
978 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
979 entry
->flags
& 0xffff);
981 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
983 seq_printf(seq
, " ");
984 if (entry
->recv_vcc
) {
985 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
986 entry
->recv_vcc
->vci
);
993 struct lec_priv
*locked
;
994 struct hlist_node
*node
;
995 struct net_device
*dev
;
1001 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
1004 struct hlist_node
*e
= state
->node
;
1005 struct lec_arp_table
*tmp
;
1009 if (e
== SEQ_START_TOKEN
) {
1014 hlist_for_each_entry_from(tmp
, e
, next
) {
1020 return (*l
< 0) ? state
: NULL
;
1023 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1024 struct lec_priv
*priv
)
1029 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1030 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1034 state
->arp_table
= p
;
1038 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1039 struct lec_priv
*priv
)
1041 struct hlist_head
*lec_misc_tables
[] = {
1042 &priv
->lec_arp_empty_ones
,
1043 &priv
->lec_no_forward
,
1049 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1050 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1054 state
->misc_table
= q
;
1058 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1059 struct lec_priv
*priv
)
1061 if (!state
->locked
) {
1062 state
->locked
= priv
;
1063 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1065 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1066 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1067 state
->locked
= NULL
;
1068 /* Partial state reset for the next time we get called */
1069 state
->arp_table
= state
->misc_table
= 0;
1071 return state
->locked
;
1074 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1076 struct net_device
*dev
;
1079 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1080 v
= (dev
&& dev
->priv
) ? lec_priv_walk(state
, l
, dev
->priv
) : NULL
;
1083 /* Partial state reset for the next time we get called */
1090 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1094 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1095 v
= lec_itf_walk(state
, &l
);
1102 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1104 struct lec_state
*state
= seq
->private;
1108 state
->locked
= NULL
;
1109 state
->arp_table
= 0;
1110 state
->misc_table
= 0;
1111 state
->node
= SEQ_START_TOKEN
;
1113 return *pos
? lec_get_idx(state
, *pos
) : SEQ_START_TOKEN
;
1116 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1118 struct lec_state
*state
= seq
->private;
1121 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1123 dev_put(state
->dev
);
1127 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1129 struct lec_state
*state
= seq
->private;
1131 v
= lec_get_idx(state
, 1);
1132 *pos
+= !!PTR_ERR(v
);
1136 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1138 static char lec_banner
[] = "Itf MAC ATM destination"
1140 "VPI/VCI Recv VPI/VCI\n";
1142 if (v
== SEQ_START_TOKEN
)
1143 seq_puts(seq
, lec_banner
);
1145 struct lec_state
*state
= seq
->private;
1146 struct net_device
*dev
= state
->dev
;
1147 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1149 seq_printf(seq
, "%s ", dev
->name
);
1150 lec_info(seq
, entry
);
1155 static const struct seq_operations lec_seq_ops
= {
1156 .start
= lec_seq_start
,
1157 .next
= lec_seq_next
,
1158 .stop
= lec_seq_stop
,
1159 .show
= lec_seq_show
,
1162 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1164 return seq_open_private(file
, &lec_seq_ops
, sizeof(struct lec_state
));
1167 static const struct file_operations lec_seq_fops
= {
1168 .owner
= THIS_MODULE
,
1169 .open
= lec_seq_open
,
1171 .llseek
= seq_lseek
,
1172 .release
= seq_release_private
,
1176 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1178 struct atm_vcc
*vcc
= ATM_SD(sock
);
1185 if (!capable(CAP_NET_ADMIN
))
1189 return -ENOIOCTLCMD
;
1194 err
= lecd_attach(vcc
, (int)arg
);
1196 sock
->state
= SS_CONNECTED
;
1199 err
= lec_mcast_attach(vcc
, (int)arg
);
1202 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1209 static struct atm_ioctl lane_ioctl_ops
= {
1210 .owner
= THIS_MODULE
,
1211 .ioctl
= lane_ioctl
,
1214 static int __init
lane_module_init(void)
1216 #ifdef CONFIG_PROC_FS
1217 struct proc_dir_entry
*p
;
1219 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1221 printk(KERN_ERR
"Unable to initialize /proc/net/atm/lec\n");
1226 register_atm_ioctl(&lane_ioctl_ops
);
1227 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1231 static void __exit
lane_module_cleanup(void)
1234 struct lec_priv
*priv
;
1236 remove_proc_entry("lec", atm_proc_root
);
1238 deregister_atm_ioctl(&lane_ioctl_ops
);
1240 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1241 if (dev_lec
[i
] != NULL
) {
1242 priv
= (struct lec_priv
*)dev_lec
[i
]->priv
;
1243 unregister_netdev(dev_lec
[i
]);
1244 free_netdev(dev_lec
[i
]);
1252 module_init(lane_module_init
);
1253 module_exit(lane_module_cleanup
);
1256 * LANE2: 3.1.3, LE_RESOLVE.request
1257 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1258 * If sizeoftlvs == NULL the default TLVs associated with with this
1260 * If dst_mac == NULL, targetless LE_ARP will be sent
1262 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
1263 u8
**tlvs
, u32
*sizeoftlvs
)
1265 unsigned long flags
;
1266 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1267 struct lec_arp_table
*table
;
1268 struct sk_buff
*skb
;
1272 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1273 table
= lec_arp_find(priv
, dst_mac
);
1274 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1278 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1282 *sizeoftlvs
= table
->sizeoftlvs
;
1287 if (sizeoftlvs
== NULL
)
1288 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1291 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1294 skb
->len
= *sizeoftlvs
;
1295 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1296 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1302 * LANE2: 3.1.4, LE_ASSOCIATE.request
1303 * Associate the *tlvs with the *lan_dst address.
1304 * Will overwrite any previous association
1305 * Returns 1 for success, 0 for failure (out of memory)
1308 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
1309 const u8
*tlvs
, u32 sizeoftlvs
)
1312 struct sk_buff
*skb
;
1313 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1315 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1316 return (0); /* not our mac address */
1318 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1320 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1321 if (priv
->tlvs
== NULL
)
1323 priv
->sizeoftlvs
= sizeoftlvs
;
1325 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1328 skb
->len
= sizeoftlvs
;
1329 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1330 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1332 printk("lec.c: lane2_associate_req() failed\n");
1334 * If the previous association has changed we must
1335 * somehow notify other LANE entities about the change
1341 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1344 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_addr
,
1345 const u8
*tlvs
, u32 sizeoftlvs
)
1350 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1352 * Why have the TLVs in LE_ARP entries
1353 * since we do not use them? When you
1354 * uncomment this code, make sure the
1355 * TLVs get freed when entry is killed
1357 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1360 return; /* should not happen */
1364 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1365 if (entry
->tlvs
== NULL
)
1367 entry
->sizeoftlvs
= sizeoftlvs
;
1370 printk("lec.c: lane2_associate_ind()\n");
1371 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1372 while (i
< sizeoftlvs
)
1373 printk("%02x ", tlvs
[i
++]);
1378 /* tell MPOA about the TLVs we saw */
1379 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1380 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1387 * Here starts what used to lec_arpc.c
1389 * lec_arpc.c was added here when making
1390 * lane client modular. October 1997
1393 #include <linux/types.h>
1394 #include <linux/timer.h>
1395 #include <asm/param.h>
1396 #include <asm/atomic.h>
1397 #include <linux/inetdevice.h>
1398 #include <net/route.h>
1401 #define pr_debug(format,args...)
1403 #define pr_debug printk
1406 #define DEBUG_ARP_TABLE 0
1408 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1410 static void lec_arp_check_expire(struct work_struct
*work
);
1411 static void lec_arp_expire_arp(unsigned long data
);
1417 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1420 * Initialization of arp-cache
1422 static void lec_arp_init(struct lec_priv
*priv
)
1426 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1427 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1429 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1430 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1431 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1432 spin_lock_init(&priv
->lec_arp_lock
);
1433 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1434 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1437 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1440 struct atm_vcc
*vcc
= entry
->vcc
;
1441 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1442 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1444 vcc
->pop
= vpriv
->old_pop
;
1446 netif_wake_queue(dev
);
1448 vcc
->user_back
= NULL
;
1449 vcc
->push
= entry
->old_push
;
1450 vcc_release_async(vcc
, -EPIPE
);
1453 if (entry
->recv_vcc
) {
1454 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1455 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1456 entry
->recv_vcc
= NULL
;
1461 * Insert entry to lec_arp_table
1462 * LANE2: Add to the end of the list to satisfy 8.1.13
1465 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1467 struct hlist_head
*tmp
;
1469 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1470 hlist_add_head(&entry
->next
, tmp
);
1472 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1473 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1474 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1475 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1479 * Remove entry from lec_arp_table
1482 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1484 struct hlist_node
*node
;
1485 struct lec_arp_table
*entry
;
1486 int i
, remove_vcc
= 1;
1492 hlist_del(&to_remove
->next
);
1493 del_timer(&to_remove
->timer
);
1495 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1496 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1498 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1500 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1501 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1502 if (memcmp(to_remove
->atm_addr
,
1503 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1510 lec_arp_clear_vccs(to_remove
);
1512 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1514 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1515 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1516 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1517 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1522 static char *get_status_string(unsigned char st
)
1526 return "ESI_UNKNOWN";
1527 case ESI_ARP_PENDING
:
1528 return "ESI_ARP_PENDING";
1529 case ESI_VC_PENDING
:
1530 return "ESI_VC_PENDING";
1531 case ESI_FLUSH_PENDING
:
1532 return "ESI_FLUSH_PENDING";
1533 case ESI_FORWARD_DIRECT
:
1534 return "ESI_FORWARD_DIRECT";
1540 static void dump_arp_table(struct lec_priv
*priv
)
1542 struct hlist_node
*node
;
1543 struct lec_arp_table
*rulla
;
1547 printk("Dump %p:\n", priv
);
1548 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1549 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1551 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1552 offset
+= sprintf(buf
+ offset
, "Mac:");
1553 for (j
= 0; j
< ETH_ALEN
; j
++) {
1554 offset
+= sprintf(buf
+ offset
,
1556 rulla
->mac_addr
[j
] & 0xff);
1558 offset
+= sprintf(buf
+ offset
, "Atm:");
1559 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1560 offset
+= sprintf(buf
+ offset
,
1562 rulla
->atm_addr
[j
] & 0xff);
1564 offset
+= sprintf(buf
+ offset
,
1565 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1566 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1567 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1568 rulla
->recv_vcc
? rulla
->recv_vcc
->
1570 rulla
->recv_vcc
? rulla
->recv_vcc
->
1571 vci
: 0, rulla
->last_used
,
1572 rulla
->timestamp
, rulla
->no_tries
);
1574 sprintf(buf
+ offset
,
1575 "Flags:%x, Packets_flooded:%x, Status: %s ",
1576 rulla
->flags
, rulla
->packets_flooded
,
1577 get_status_string(rulla
->status
));
1578 printk("%s\n", buf
);
1582 if (!hlist_empty(&priv
->lec_no_forward
))
1583 printk("No forward\n");
1584 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1586 offset
+= sprintf(buf
+ offset
, "Mac:");
1587 for (j
= 0; j
< ETH_ALEN
; j
++) {
1588 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1589 rulla
->mac_addr
[j
] & 0xff);
1591 offset
+= sprintf(buf
+ offset
, "Atm:");
1592 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1593 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1594 rulla
->atm_addr
[j
] & 0xff);
1596 offset
+= sprintf(buf
+ offset
,
1597 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1598 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1599 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1600 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1601 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1603 rulla
->timestamp
, rulla
->no_tries
);
1604 offset
+= sprintf(buf
+ offset
,
1605 "Flags:%x, Packets_flooded:%x, Status: %s ",
1606 rulla
->flags
, rulla
->packets_flooded
,
1607 get_status_string(rulla
->status
));
1608 printk("%s\n", buf
);
1611 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1612 printk("Empty ones\n");
1613 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1615 offset
+= sprintf(buf
+ offset
, "Mac:");
1616 for (j
= 0; j
< ETH_ALEN
; j
++) {
1617 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1618 rulla
->mac_addr
[j
] & 0xff);
1620 offset
+= sprintf(buf
+ offset
, "Atm:");
1621 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1622 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1623 rulla
->atm_addr
[j
] & 0xff);
1625 offset
+= sprintf(buf
+ offset
,
1626 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1627 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1628 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1629 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1630 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1632 rulla
->timestamp
, rulla
->no_tries
);
1633 offset
+= sprintf(buf
+ offset
,
1634 "Flags:%x, Packets_flooded:%x, Status: %s ",
1635 rulla
->flags
, rulla
->packets_flooded
,
1636 get_status_string(rulla
->status
));
1640 if (!hlist_empty(&priv
->mcast_fwds
))
1641 printk("Multicast Forward VCCs\n");
1642 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1644 offset
+= sprintf(buf
+ offset
, "Mac:");
1645 for (j
= 0; j
< ETH_ALEN
; j
++) {
1646 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1647 rulla
->mac_addr
[j
] & 0xff);
1649 offset
+= sprintf(buf
+ offset
, "Atm:");
1650 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1651 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1652 rulla
->atm_addr
[j
] & 0xff);
1654 offset
+= sprintf(buf
+ offset
,
1655 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1656 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1657 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1658 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1659 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1661 rulla
->timestamp
, rulla
->no_tries
);
1662 offset
+= sprintf(buf
+ offset
,
1663 "Flags:%x, Packets_flooded:%x, Status: %s ",
1664 rulla
->flags
, rulla
->packets_flooded
,
1665 get_status_string(rulla
->status
));
1666 printk("%s\n", buf
);
1671 #define dump_arp_table(priv) do { } while (0)
1675 * Destruction of arp-cache
1677 static void lec_arp_destroy(struct lec_priv
*priv
)
1679 unsigned long flags
;
1680 struct hlist_node
*node
, *next
;
1681 struct lec_arp_table
*entry
;
1684 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1687 * Remove all entries
1690 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1691 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1692 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1693 lec_arp_remove(priv
, entry
);
1696 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1699 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1700 del_timer_sync(&entry
->timer
);
1701 lec_arp_clear_vccs(entry
);
1702 hlist_del(&entry
->next
);
1705 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1707 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1708 del_timer_sync(&entry
->timer
);
1709 lec_arp_clear_vccs(entry
);
1710 hlist_del(&entry
->next
);
1713 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1715 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1716 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1717 lec_arp_clear_vccs(entry
);
1718 hlist_del(&entry
->next
);
1721 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1722 priv
->mcast_vcc
= NULL
;
1723 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1727 * Find entry by mac_address
1729 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1730 const unsigned char *mac_addr
)
1732 struct hlist_node
*node
;
1733 struct hlist_head
*head
;
1734 struct lec_arp_table
*entry
;
1736 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1737 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1738 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1740 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1741 hlist_for_each_entry(entry
, node
, head
, next
) {
1742 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1749 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1750 const unsigned char *mac_addr
)
1752 struct lec_arp_table
*to_return
;
1754 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1756 printk("LEC: Arp entry kmalloc failed\n");
1759 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1760 INIT_HLIST_NODE(&to_return
->next
);
1761 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1762 (unsigned long)to_return
);
1763 to_return
->last_used
= jiffies
;
1764 to_return
->priv
= priv
;
1765 skb_queue_head_init(&to_return
->tx_wait
);
1766 atomic_set(&to_return
->usage
, 1);
1770 /* Arp sent timer expired */
1771 static void lec_arp_expire_arp(unsigned long data
)
1773 struct lec_arp_table
*entry
;
1775 entry
= (struct lec_arp_table
*)data
;
1777 pr_debug("lec_arp_expire_arp\n");
1778 if (entry
->status
== ESI_ARP_PENDING
) {
1779 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1780 if (entry
->is_rdesc
)
1781 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1782 entry
->mac_addr
, NULL
, NULL
);
1784 send_to_lecd(entry
->priv
, l_arp_xmt
,
1785 entry
->mac_addr
, NULL
, NULL
);
1788 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1792 /* Unknown/unused vcc expire, remove associated entry */
1793 static void lec_arp_expire_vcc(unsigned long data
)
1795 unsigned long flags
;
1796 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1797 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1799 del_timer(&to_remove
->timer
);
1801 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1803 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1804 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1806 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1807 hlist_del(&to_remove
->next
);
1808 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1810 lec_arp_clear_vccs(to_remove
);
1811 lec_arp_put(to_remove
);
1817 * 2. For each entry, delete entries that have aged past the age limit.
1818 * 3. For each entry, depending on the status of the entry, perform
1819 * the following maintenance.
1820 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1821 * tick_count is above the max_unknown_frame_time, clear
1822 * the tick_count to zero and clear the packets_flooded counter
1823 * to zero. This supports the packet rate limit per address
1824 * while flooding unknowns.
1825 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1826 * than or equal to the path_switching_delay, change the status
1827 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1828 * regardless of the progress of the flush protocol.
1830 static void lec_arp_check_expire(struct work_struct
*work
)
1832 unsigned long flags
;
1833 struct lec_priv
*priv
=
1834 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1835 struct hlist_node
*node
, *next
;
1836 struct lec_arp_table
*entry
;
1838 unsigned long time_to_check
;
1841 pr_debug("lec_arp_check_expire %p\n", priv
);
1844 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1845 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1846 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1847 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1848 priv
->topology_change
)
1849 time_to_check
= priv
->forward_delay_time
;
1851 time_to_check
= priv
->aging_time
;
1853 pr_debug("About to expire: %lx - %lx > %lx\n",
1854 now
, entry
->last_used
, time_to_check
);
1855 if (time_after(now
, entry
->last_used
+ time_to_check
)
1856 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1857 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1859 pr_debug("LEC:Entry timed out\n");
1860 lec_arp_remove(priv
, entry
);
1863 /* Something else */
1864 if ((entry
->status
== ESI_VC_PENDING
||
1865 entry
->status
== ESI_ARP_PENDING
)
1866 && time_after_eq(now
,
1869 max_unknown_frame_time
)) {
1870 entry
->timestamp
= jiffies
;
1871 entry
->packets_flooded
= 0;
1872 if (entry
->status
== ESI_VC_PENDING
)
1873 send_to_lecd(priv
, l_svc_setup
,
1878 if (entry
->status
== ESI_FLUSH_PENDING
1880 time_after_eq(now
, entry
->timestamp
+
1881 priv
->path_switching_delay
)) {
1882 struct sk_buff
*skb
;
1883 struct atm_vcc
*vcc
= entry
->vcc
;
1885 lec_arp_hold(entry
);
1886 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1887 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1888 lec_send(vcc
, skb
, entry
->priv
);
1889 entry
->last_used
= jiffies
;
1890 entry
->status
= ESI_FORWARD_DIRECT
;
1897 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1899 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1903 * Try to find vcc where mac_address is attached.
1906 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1907 const unsigned char *mac_to_find
, int is_rdesc
,
1908 struct lec_arp_table
**ret_entry
)
1910 unsigned long flags
;
1911 struct lec_arp_table
*entry
;
1912 struct atm_vcc
*found
;
1914 if (mac_to_find
[0] & 0x01) {
1915 switch (priv
->lane_version
) {
1917 return priv
->mcast_vcc
;
1918 case 2: /* LANE2 wants arp for multicast addresses */
1919 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1920 return priv
->mcast_vcc
;
1927 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1928 entry
= lec_arp_find(priv
, mac_to_find
);
1931 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1933 entry
->last_used
= jiffies
;
1934 lec_arp_hold(entry
);
1940 * If the LE_ARP cache entry is still pending, reset count to 0
1941 * so another LE_ARP request can be made for this frame.
1943 if (entry
->status
== ESI_ARP_PENDING
) {
1944 entry
->no_tries
= 0;
1947 * Data direct VC not yet set up, check to see if the unknown
1948 * frame count is greater than the limit. If the limit has
1949 * not been reached, allow the caller to send packet to
1952 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1953 entry
->packets_flooded
<
1954 priv
->maximum_unknown_frame_count
) {
1955 entry
->packets_flooded
++;
1956 pr_debug("LEC_ARP: Flooding..\n");
1957 found
= priv
->mcast_vcc
;
1961 * We got here because entry->status == ESI_FLUSH_PENDING
1962 * or BUS flood limit was reached for an entry which is
1963 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1965 lec_arp_hold(entry
);
1967 pr_debug("lec: entry->status %d entry->vcc %p\n", entry
->status
,
1971 /* No matching entry was found */
1972 entry
= make_entry(priv
, mac_to_find
);
1973 pr_debug("LEC_ARP: Making entry\n");
1975 found
= priv
->mcast_vcc
;
1978 lec_arp_add(priv
, entry
);
1979 /* We want arp-request(s) to be sent */
1980 entry
->packets_flooded
= 1;
1981 entry
->status
= ESI_ARP_PENDING
;
1982 entry
->no_tries
= 1;
1983 entry
->last_used
= entry
->timestamp
= jiffies
;
1984 entry
->is_rdesc
= is_rdesc
;
1985 if (entry
->is_rdesc
)
1986 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
1989 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
1990 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
1991 entry
->timer
.function
= lec_arp_expire_arp
;
1992 add_timer(&entry
->timer
);
1993 found
= priv
->mcast_vcc
;
1997 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2002 lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
2003 unsigned long permanent
)
2005 unsigned long flags
;
2006 struct hlist_node
*node
, *next
;
2007 struct lec_arp_table
*entry
;
2010 pr_debug("lec_addr_delete\n");
2011 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2012 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2013 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2014 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2016 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2017 lec_arp_remove(priv
, entry
);
2020 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2024 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2029 * Notifies: Response to arp_request (atm_addr != NULL)
2032 lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
2033 const unsigned char *atm_addr
, unsigned long remoteflag
,
2034 unsigned int targetless_le_arp
)
2036 unsigned long flags
;
2037 struct hlist_node
*node
, *next
;
2038 struct lec_arp_table
*entry
, *tmp
;
2041 pr_debug("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2042 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2043 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2044 mac_addr
[4], mac_addr
[5]);
2046 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2047 entry
= lec_arp_find(priv
, mac_addr
);
2048 if (entry
== NULL
&& targetless_le_arp
)
2050 * LANE2: ignore targetless LE_ARPs for which
2051 * we have no entry in the cache. 7.1.30
2053 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2054 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2055 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2056 hlist_del(&entry
->next
);
2057 del_timer(&entry
->timer
);
2058 tmp
= lec_arp_find(priv
, mac_addr
);
2060 del_timer(&tmp
->timer
);
2061 tmp
->status
= ESI_FORWARD_DIRECT
;
2062 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2063 tmp
->vcc
= entry
->vcc
;
2064 tmp
->old_push
= entry
->old_push
;
2065 tmp
->last_used
= jiffies
;
2066 del_timer(&entry
->timer
);
2070 entry
->status
= ESI_FORWARD_DIRECT
;
2071 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2072 entry
->last_used
= jiffies
;
2073 lec_arp_add(priv
, entry
);
2076 entry
->flags
|= LEC_REMOTE_FLAG
;
2078 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2079 pr_debug("After update\n");
2080 dump_arp_table(priv
);
2086 entry
= lec_arp_find(priv
, mac_addr
);
2088 entry
= make_entry(priv
, mac_addr
);
2091 entry
->status
= ESI_UNKNOWN
;
2092 lec_arp_add(priv
, entry
);
2093 /* Temporary, changes before end of function */
2095 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2096 del_timer(&entry
->timer
);
2097 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2098 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2100 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2101 /* Vcc to this host exists */
2102 if (tmp
->status
> ESI_VC_PENDING
) {
2104 * ESI_FLUSH_PENDING,
2105 * ESI_FORWARD_DIRECT
2107 entry
->vcc
= tmp
->vcc
;
2108 entry
->old_push
= tmp
->old_push
;
2110 entry
->status
= tmp
->status
;
2116 entry
->flags
|= LEC_REMOTE_FLAG
;
2118 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2119 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2120 entry
->status
= ESI_VC_PENDING
;
2121 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2123 pr_debug("After update2\n");
2124 dump_arp_table(priv
);
2126 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2130 * Notifies: Vcc setup ready
2133 lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
2134 struct atm_vcc
*vcc
,
2135 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2137 unsigned long flags
;
2138 struct hlist_node
*node
;
2139 struct lec_arp_table
*entry
;
2140 int i
, found_entry
= 0;
2142 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2143 if (ioc_data
->receive
== 2) {
2144 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2146 pr_debug("LEC_ARP: Attaching mcast forward\n");
2148 entry
= lec_arp_find(priv
, bus_mac
);
2150 printk("LEC_ARP: Multicast entry not found!\n");
2153 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2154 entry
->recv_vcc
= vcc
;
2155 entry
->old_recv_push
= old_push
;
2157 entry
= make_entry(priv
, bus_mac
);
2160 del_timer(&entry
->timer
);
2161 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2162 entry
->recv_vcc
= vcc
;
2163 entry
->old_recv_push
= old_push
;
2164 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2166 } else if (ioc_data
->receive
== 1) {
2168 * Vcc which we don't want to make default vcc,
2172 ("LEC_ARP:Attaching data direct, not default: "
2173 "%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",
2174 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2175 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2176 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2177 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2178 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2179 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2180 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2181 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2182 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2183 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2184 entry
= make_entry(priv
, bus_mac
);
2187 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2188 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2189 entry
->recv_vcc
= vcc
;
2190 entry
->old_recv_push
= old_push
;
2191 entry
->status
= ESI_UNKNOWN
;
2192 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2193 entry
->timer
.function
= lec_arp_expire_vcc
;
2194 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2195 add_timer(&entry
->timer
);
2196 dump_arp_table(priv
);
2200 ("LEC_ARP:Attaching data direct, default: "
2201 "%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",
2202 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2203 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2204 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2205 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2206 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2207 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2208 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2209 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2210 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2211 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2212 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2213 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2215 (ioc_data
->atm_addr
, entry
->atm_addr
,
2216 ATM_ESA_LEN
) == 0) {
2217 pr_debug("LEC_ARP: Attaching data direct\n");
2218 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2219 entry
->vcc
? entry
->vcc
->vci
: 0,
2220 entry
->recv_vcc
? entry
->recv_vcc
->
2223 del_timer(&entry
->timer
);
2225 entry
->old_push
= old_push
;
2226 if (entry
->status
== ESI_VC_PENDING
) {
2227 if (priv
->maximum_unknown_frame_count
2232 entry
->timestamp
= jiffies
;
2236 send_to_lecd(priv
, l_flush_xmt
,
2244 * They were forming a connection
2245 * to us, and we to them. Our
2246 * ATM address is numerically lower
2247 * than theirs, so we make connection
2248 * we formed into default VCC (8.1.11).
2249 * Connection they made gets torn
2250 * down. This might confuse some
2251 * clients. Can be changed if
2252 * someone reports trouble...
2260 pr_debug("After vcc was added\n");
2261 dump_arp_table(priv
);
2265 * Not found, snatch address from first data packet that arrives
2268 entry
= make_entry(priv
, bus_mac
);
2272 entry
->old_push
= old_push
;
2273 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2274 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2275 entry
->status
= ESI_UNKNOWN
;
2276 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2277 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2278 entry
->timer
.function
= lec_arp_expire_vcc
;
2279 add_timer(&entry
->timer
);
2280 pr_debug("After vcc was added\n");
2281 dump_arp_table(priv
);
2283 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2286 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2288 unsigned long flags
;
2289 struct hlist_node
*node
;
2290 struct lec_arp_table
*entry
;
2293 pr_debug("LEC:lec_flush_complete %lx\n", tran_id
);
2295 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2296 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2297 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2298 if (entry
->flush_tran_id
== tran_id
2299 && entry
->status
== ESI_FLUSH_PENDING
) {
2300 struct sk_buff
*skb
;
2301 struct atm_vcc
*vcc
= entry
->vcc
;
2303 lec_arp_hold(entry
);
2304 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2305 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2306 lec_send(vcc
, skb
, entry
->priv
);
2307 entry
->last_used
= jiffies
;
2308 entry
->status
= ESI_FORWARD_DIRECT
;
2310 pr_debug("LEC_ARP: Flushed\n");
2315 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2316 dump_arp_table(priv
);
2320 lec_set_flush_tran_id(struct lec_priv
*priv
,
2321 const unsigned char *atm_addr
, unsigned long tran_id
)
2323 unsigned long flags
;
2324 struct hlist_node
*node
;
2325 struct lec_arp_table
*entry
;
2328 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2329 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2330 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2331 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2332 entry
->flush_tran_id
= tran_id
;
2333 pr_debug("Set flush transaction id to %lx for %p\n",
2337 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2340 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2342 unsigned long flags
;
2343 unsigned char mac_addr
[] = {
2344 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2346 struct lec_arp_table
*to_add
;
2347 struct lec_vcc_priv
*vpriv
;
2350 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2353 vpriv
->old_pop
= vcc
->pop
;
2354 vcc
->user_back
= vpriv
;
2356 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2357 to_add
= make_entry(priv
, mac_addr
);
2359 vcc
->pop
= vpriv
->old_pop
;
2364 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2365 to_add
->status
= ESI_FORWARD_DIRECT
;
2366 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2368 to_add
->old_push
= vcc
->push
;
2369 vcc
->push
= lec_push
;
2370 priv
->mcast_vcc
= vcc
;
2371 lec_arp_add(priv
, to_add
);
2373 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2377 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2379 unsigned long flags
;
2380 struct hlist_node
*node
, *next
;
2381 struct lec_arp_table
*entry
;
2384 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2385 dump_arp_table(priv
);
2387 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2389 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2390 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2391 if (vcc
== entry
->vcc
) {
2392 lec_arp_remove(priv
, entry
);
2394 if (priv
->mcast_vcc
== vcc
) {
2395 priv
->mcast_vcc
= NULL
;
2401 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2402 if (entry
->vcc
== vcc
) {
2403 lec_arp_clear_vccs(entry
);
2404 del_timer(&entry
->timer
);
2405 hlist_del(&entry
->next
);
2410 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2411 if (entry
->recv_vcc
== vcc
) {
2412 lec_arp_clear_vccs(entry
);
2413 del_timer(&entry
->timer
);
2414 hlist_del(&entry
->next
);
2419 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2420 if (entry
->recv_vcc
== vcc
) {
2421 lec_arp_clear_vccs(entry
);
2422 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2423 hlist_del(&entry
->next
);
2428 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2429 dump_arp_table(priv
);
2433 lec_arp_check_empties(struct lec_priv
*priv
,
2434 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2436 unsigned long flags
;
2437 struct hlist_node
*node
, *next
;
2438 struct lec_arp_table
*entry
, *tmp
;
2439 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2442 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2445 src
= tr_hdr
->h_source
;
2448 src
= hdr
->h_source
;
2450 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2451 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2452 if (vcc
== entry
->vcc
) {
2453 del_timer(&entry
->timer
);
2454 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2455 entry
->status
= ESI_FORWARD_DIRECT
;
2456 entry
->last_used
= jiffies
;
2457 /* We might have got an entry */
2458 if ((tmp
= lec_arp_find(priv
, src
))) {
2459 lec_arp_remove(priv
, tmp
);
2462 hlist_del(&entry
->next
);
2463 lec_arp_add(priv
, entry
);
2467 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2469 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2472 MODULE_LICENSE("GPL");