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 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
, u8
*mac_address
,
73 u8
*tlvs
, u32 sizeoftlvs
);
74 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
75 u8
**tlvs
, u32
*sizeoftlvs
);
76 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
77 u8
*tlvs
, u32 sizeoftlvs
);
79 static int lec_addr_delete(struct lec_priv
*priv
, 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 unsigned char *mac_to_find
,
88 struct lec_arp_table
**ret_entry
);
89 static void lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
90 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 unsigned char *atm_addr
,
96 unsigned long tran_id
);
97 static void lec_vcc_added(struct lec_priv
*priv
, 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 */
269 DECLARE_MAC_BUF(mac
);
271 pr_debug("lec_start_xmit called\n");
273 printk("%s:No lecd attached\n", dev
->name
);
274 priv
->stats
.tx_errors
++;
275 netif_stop_queue(dev
);
279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
280 (long)skb
->head
, (long)skb
->data
, (long)skb_tail_pointer(skb
),
281 (long)skb_end_pointer(skb
));
282 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
283 if (memcmp(skb
->data
, bridge_ula_lec
, sizeof(bridge_ula_lec
)) == 0)
284 lec_handle_bridge(skb
, dev
);
287 /* Make sure we have room for lec_id */
288 if (skb_headroom(skb
) < 2) {
290 pr_debug("lec_start_xmit: reallocating skb\n");
291 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
299 /* Put le header to place, works for TokenRing too */
300 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
301 lec_h
->le_header
= htons(priv
->lecid
);
305 * Ugly. Use this to realign Token Ring packets for
306 * e.g. PCA-200E driver.
308 if (priv
->is_trdev
) {
309 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
318 printk("%s: send datalen:%ld lecid:%4.4x\n", dev
->name
,
319 skb
->len
, priv
->lecid
);
320 #if DUMP_PACKETS >= 2
321 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
322 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
324 #elif DUMP_PACKETS >= 1
325 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
326 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
328 #endif /* DUMP_PACKETS >= 1 */
332 printk("%s...\n", buf
);
333 #endif /* DUMP_PACKETS > 0 */
335 /* Minimum ethernet-frame size */
338 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
341 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
342 if (skb
->len
< min_frame_size
) {
343 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
344 skb2
= skb_copy_expand(skb
, 0,
345 min_frame_size
- skb
->truesize
,
349 priv
->stats
.tx_dropped
++;
354 skb_put(skb
, min_frame_size
- skb
->len
);
357 /* Send to right vcc */
361 if (priv
->is_trdev
) {
362 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
370 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
371 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev
->name
,
372 vcc
, vcc
? vcc
->flags
: 0, entry
);
373 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
374 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
375 pr_debug("%s:lec_start_xmit: queuing packet, ",
377 pr_debug("MAC address %s\n",
378 print_mac(mac
, lec_h
->h_dest
));
379 skb_queue_tail(&entry
->tx_wait
, skb
);
382 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
384 pr_debug("MAC address %s\n",
385 print_mac(mac
, lec_h
->h_dest
));
386 priv
->stats
.tx_dropped
++;
392 printk("%s:sending to vpi:%d vci:%d\n", dev
->name
, vcc
->vpi
, vcc
->vci
);
393 #endif /* DUMP_PACKETS > 0 */
395 while (entry
&& (skb2
= skb_dequeue(&entry
->tx_wait
))) {
396 pr_debug("lec.c: emptying tx queue, ");
397 pr_debug("MAC address %s\n",
398 print_mac(mac
, lec_h
->h_dest
));
399 lec_send(vcc
, skb2
, priv
);
402 lec_send(vcc
, skb
, priv
);
404 if (!atm_may_send(vcc
, 0)) {
405 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
408 netif_stop_queue(dev
);
411 * vcc->pop() might have occurred in between, making
412 * the vcc usuable again. Since xmit is serialized,
413 * this is the only situation we have to re-test.
416 if (atm_may_send(vcc
, 0))
417 netif_wake_queue(dev
);
423 dev
->trans_start
= jiffies
;
427 /* The inverse routine to net_open(). */
428 static int lec_close(struct net_device
*dev
)
430 netif_stop_queue(dev
);
435 * Get the current statistics.
436 * This may be called with the card open or closed.
438 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
)
440 return &((struct lec_priv
*)dev
->priv
)->stats
;
443 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
446 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
447 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
448 struct atmlec_msg
*mesg
;
449 struct lec_arp_table
*entry
;
451 char *tmp
; /* FIXME */
452 DECLARE_MAC_BUF(mac
);
454 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
455 mesg
= (struct atmlec_msg
*)skb
->data
;
457 tmp
+= sizeof(struct atmlec_msg
);
458 pr_debug("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
459 switch (mesg
->type
) {
461 for (i
= 0; i
< 6; i
++) {
462 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
466 for (i
= 0; i
< 6; i
++) {
467 dev
->dev_addr
[i
] = 0;
471 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
472 mesg
->content
.normal
.flag
);
474 case l_topology_change
:
475 priv
->topology_change
= mesg
->content
.normal
.flag
;
477 case l_flush_complete
:
478 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
480 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
481 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
482 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
483 lec_arp_remove(priv
, entry
);
484 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
486 if (mesg
->content
.normal
.no_source_le_narp
)
490 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
491 mesg
->content
.normal
.atm_addr
,
492 mesg
->content
.normal
.flag
,
493 mesg
->content
.normal
.targetless_le_arp
);
494 pr_debug("lec: in l_arp_update\n");
495 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
496 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
498 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
499 tmp
, mesg
->sizeoftlvs
);
503 priv
->maximum_unknown_frame_count
=
504 mesg
->content
.config
.maximum_unknown_frame_count
;
505 priv
->max_unknown_frame_time
=
506 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
507 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
508 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
509 priv
->forward_delay_time
=
510 (mesg
->content
.config
.forward_delay_time
* HZ
);
511 priv
->arp_response_time
=
512 (mesg
->content
.config
.arp_response_time
* HZ
);
513 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
514 priv
->path_switching_delay
=
515 (mesg
->content
.config
.path_switching_delay
* HZ
);
516 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
517 priv
->lane2_ops
= NULL
;
518 if (priv
->lane_version
> 1)
519 priv
->lane2_ops
= &lane2_ops
;
520 if (dev
->change_mtu(dev
, mesg
->content
.config
.mtu
))
521 printk("%s: change_mtu to %d failed\n", dev
->name
,
522 mesg
->content
.config
.mtu
);
523 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
525 case l_flush_tran_id
:
526 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
527 mesg
->content
.normal
.flag
);
531 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
533 case l_should_bridge
:
534 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
536 struct net_bridge_fdb_entry
*f
;
539 ("%s: bridge zeppelin asks about %s\n",
541 print_mac(mac
, mesg
->content
.proxy
.mac_addr
));
543 if (br_fdb_get_hook
== NULL
|| dev
->br_port
== NULL
)
546 f
= br_fdb_get_hook(dev
->br_port
->br
,
547 mesg
->content
.proxy
.mac_addr
);
548 if (f
!= NULL
&& f
->dst
->dev
!= dev
549 && f
->dst
->state
== BR_STATE_FORWARDING
) {
550 /* hit from bridge table, send LE_ARP_RESPONSE */
551 struct sk_buff
*skb2
;
555 ("%s: entry found, responding to zeppelin\n",
558 alloc_skb(sizeof(struct atmlec_msg
),
564 skb2
->len
= sizeof(struct atmlec_msg
);
565 skb_copy_to_linear_data(skb2
, mesg
,
567 atm_force_charge(priv
->lecd
, skb2
->truesize
);
568 sk
= sk_atm(priv
->lecd
);
569 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
570 sk
->sk_data_ready(sk
, skb2
->len
);
575 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
578 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
586 static void lec_atm_close(struct atm_vcc
*vcc
)
589 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
590 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
593 /* Do something needful? */
595 netif_stop_queue(dev
);
596 lec_arp_destroy(priv
);
598 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
599 printk("%s lec_atm_close: closing with messages pending\n",
601 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
602 atm_return(vcc
, skb
->truesize
);
606 printk("%s: Shut down!\n", dev
->name
);
607 module_put(THIS_MODULE
);
610 static struct atmdev_ops lecdev_ops
= {
611 .close
= lec_atm_close
,
615 static struct atm_dev lecatm_dev
= {
618 .number
= 999, /* dummy device number */
619 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
623 * LANE2: new argument struct sk_buff *data contains
624 * the LE_ARP based TLVs introduced in the LANE2 spec
627 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
628 unsigned char *mac_addr
, unsigned char *atm_addr
,
629 struct sk_buff
*data
)
633 struct atmlec_msg
*mesg
;
635 if (!priv
|| !priv
->lecd
) {
638 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
641 skb
->len
= sizeof(struct atmlec_msg
);
642 mesg
= (struct atmlec_msg
*)skb
->data
;
643 memset(mesg
, 0, sizeof(struct atmlec_msg
));
646 mesg
->sizeoftlvs
= data
->len
;
648 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
650 mesg
->content
.normal
.targetless_le_arp
= 1;
652 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
654 atm_force_charge(priv
->lecd
, skb
->truesize
);
655 sk
= sk_atm(priv
->lecd
);
656 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
657 sk
->sk_data_ready(sk
, skb
->len
);
660 pr_debug("lec: about to send %d bytes of data\n", data
->len
);
661 atm_force_charge(priv
->lecd
, data
->truesize
);
662 skb_queue_tail(&sk
->sk_receive_queue
, data
);
663 sk
->sk_data_ready(sk
, skb
->len
);
669 /* shamelessly stolen from drivers/net/net_init.c */
670 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
672 if ((new_mtu
< 68) || (new_mtu
> 18190))
678 static void lec_set_multicast_list(struct net_device
*dev
)
681 * by default, all multicast frames arrive over the bus.
682 * eventually support selective multicast service
687 static void lec_init(struct net_device
*dev
)
689 dev
->change_mtu
= lec_change_mtu
;
690 dev
->open
= lec_open
;
691 dev
->stop
= lec_close
;
692 dev
->hard_start_xmit
= lec_start_xmit
;
693 dev
->tx_timeout
= lec_tx_timeout
;
695 dev
->get_stats
= lec_get_stats
;
696 dev
->set_multicast_list
= lec_set_multicast_list
;
697 dev
->do_ioctl
= NULL
;
698 printk("%s: Initialized!\n", dev
->name
);
702 static unsigned char lec_ctrl_magic
[] = {
709 #define LEC_DATA_DIRECT_8023 2
710 #define LEC_DATA_DIRECT_8025 3
712 static int lec_is_data_direct(struct atm_vcc
*vcc
)
714 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
715 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
718 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
721 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
722 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
728 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
732 pr_debug("%s: null skb\n", dev
->name
);
733 lec_vcc_close(priv
, vcc
);
737 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
738 skb
->len
, priv
->lecid
);
739 #if DUMP_PACKETS >= 2
740 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
741 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
743 #elif DUMP_PACKETS >= 1
744 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
745 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
747 #endif /* DUMP_PACKETS >= 1 */
751 printk("%s...\n", buf
);
752 #endif /* DUMP_PACKETS > 0 */
753 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
754 struct sock
*sk
= sk_atm(vcc
);
756 pr_debug("%s: To daemon\n", dev
->name
);
757 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
758 sk
->sk_data_ready(sk
, skb
->len
);
759 } else { /* Data frame, queue to protocol handlers */
760 struct lec_arp_table
*entry
;
761 unsigned char *src
, *dst
;
763 atm_return(vcc
, skb
->truesize
);
764 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
765 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
767 * Probably looping back, or if lecd is missing,
770 pr_debug("Ignoring frame...\n");
776 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
779 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
782 * If this is a Data Direct VCC, and the VCC does not match
783 * the LE_ARP cache entry, delete the LE_ARP cache entry.
785 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
786 if (lec_is_data_direct(vcc
)) {
790 ((struct lecdatahdr_8025
*)skb
->data
)->
795 ((struct lecdatahdr_8023
*)skb
->data
)->
797 entry
= lec_arp_find(priv
, src
);
798 if (entry
&& entry
->vcc
!= vcc
) {
799 lec_arp_remove(priv
, entry
);
803 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
805 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
806 !priv
->is_proxy
&& /* Proxy wants all the packets */
807 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
811 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
812 lec_arp_check_empties(priv
, vcc
, skb
);
814 skb_pull(skb
, 2); /* skip lec_id */
817 skb
->protocol
= tr_type_trans(skb
, dev
);
820 skb
->protocol
= eth_type_trans(skb
, dev
);
821 priv
->stats
.rx_packets
++;
822 priv
->stats
.rx_bytes
+= skb
->len
;
823 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
828 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
830 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
831 struct net_device
*dev
= skb
->dev
;
834 printk("lec_pop(): vpriv = NULL!?!?!?\n");
838 vpriv
->old_pop(vcc
, skb
);
840 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
842 if (netif_running(dev
) && netif_queue_stopped(dev
))
843 netif_wake_queue(dev
);
847 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
849 struct lec_vcc_priv
*vpriv
;
851 struct atmlec_ioc ioc_data
;
853 /* Lecd must be up in this case */
854 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
855 if (bytes_left
!= 0) {
857 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
860 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
861 !dev_lec
[ioc_data
.dev_num
])
863 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
866 vpriv
->old_pop
= vcc
->pop
;
867 vcc
->user_back
= vpriv
;
869 lec_vcc_added(dev_lec
[ioc_data
.dev_num
]->priv
,
870 &ioc_data
, vcc
, vcc
->push
);
871 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
872 vcc
->push
= lec_push
;
876 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
878 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
880 vcc
->proto_data
= dev_lec
[arg
];
881 return (lec_mcast_make((struct lec_priv
*)dev_lec
[arg
]->priv
, vcc
));
884 /* Initialize device. */
885 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
888 struct lec_priv
*priv
;
895 if (arg
>= MAX_LEC_ITF
)
897 #else /* Reserve the top NUM_TR_DEVS for TR */
898 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
905 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
908 size
= sizeof(struct lec_priv
);
911 dev_lec
[i
] = alloc_trdev(size
);
914 dev_lec
[i
] = alloc_etherdev(size
);
917 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
918 if (register_netdev(dev_lec
[i
])) {
919 free_netdev(dev_lec
[i
]);
923 priv
= dev_lec
[i
]->priv
;
924 priv
->is_trdev
= is_trdev
;
925 lec_init(dev_lec
[i
]);
927 priv
= dev_lec
[i
]->priv
;
932 priv
->itfnum
= i
; /* LANE2 addition */
934 vcc
->dev
= &lecatm_dev
;
935 vcc_insert_socket(sk_atm(vcc
));
937 vcc
->proto_data
= dev_lec
[i
];
938 set_bit(ATM_VF_META
, &vcc
->flags
);
939 set_bit(ATM_VF_READY
, &vcc
->flags
);
941 /* Set default values to these variables */
942 priv
->maximum_unknown_frame_count
= 1;
943 priv
->max_unknown_frame_time
= (1 * HZ
);
944 priv
->vcc_timeout_period
= (1200 * HZ
);
945 priv
->max_retry_count
= 1;
946 priv
->aging_time
= (300 * HZ
);
947 priv
->forward_delay_time
= (15 * HZ
);
948 priv
->topology_change
= 0;
949 priv
->arp_response_time
= (1 * HZ
);
950 priv
->flush_timeout
= (4 * HZ
);
951 priv
->path_switching_delay
= (6 * HZ
);
953 if (dev_lec
[i
]->flags
& IFF_UP
) {
954 netif_start_queue(dev_lec
[i
]);
956 __module_get(THIS_MODULE
);
960 #ifdef CONFIG_PROC_FS
961 static char *lec_arp_get_status_string(unsigned char status
)
963 static char *lec_arp_status_string
[] = {
968 "ESI_FLUSH_PENDING ",
972 if (status
> ESI_FORWARD_DIRECT
)
973 status
= 3; /* ESI_UNDEFINED */
974 return lec_arp_status_string
[status
];
977 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
981 for (i
= 0; i
< ETH_ALEN
; i
++)
982 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
983 seq_printf(seq
, " ");
984 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
985 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
986 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
987 entry
->flags
& 0xffff);
989 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
991 seq_printf(seq
, " ");
992 if (entry
->recv_vcc
) {
993 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
994 entry
->recv_vcc
->vci
);
1000 unsigned long flags
;
1001 struct lec_priv
*locked
;
1002 struct hlist_node
*node
;
1003 struct net_device
*dev
;
1009 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
1012 struct hlist_node
*e
= state
->node
;
1013 struct lec_arp_table
*tmp
;
1017 if (e
== (void *)1) {
1022 hlist_for_each_entry_from(tmp
, e
, next
) {
1028 return (*l
< 0) ? state
: NULL
;
1031 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1032 struct lec_priv
*priv
)
1037 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1038 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1042 state
->arp_table
= p
;
1046 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1047 struct lec_priv
*priv
)
1049 struct hlist_head
*lec_misc_tables
[] = {
1050 &priv
->lec_arp_empty_ones
,
1051 &priv
->lec_no_forward
,
1057 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1058 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1062 state
->misc_table
= q
;
1066 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1067 struct lec_priv
*priv
)
1069 if (!state
->locked
) {
1070 state
->locked
= priv
;
1071 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1073 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1074 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1075 state
->locked
= NULL
;
1076 /* Partial state reset for the next time we get called */
1077 state
->arp_table
= state
->misc_table
= 0;
1079 return state
->locked
;
1082 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1084 struct net_device
*dev
;
1087 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1088 v
= (dev
&& dev
->priv
) ? lec_priv_walk(state
, l
, dev
->priv
) : NULL
;
1091 /* Partial state reset for the next time we get called */
1098 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1102 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1103 v
= lec_itf_walk(state
, &l
);
1110 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1112 struct lec_state
*state
= seq
->private;
1116 state
->locked
= NULL
;
1117 state
->arp_table
= 0;
1118 state
->misc_table
= 0;
1119 state
->node
= (void *)1;
1121 return *pos
? lec_get_idx(state
, *pos
) : (void *)1;
1124 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1126 struct lec_state
*state
= seq
->private;
1129 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1131 dev_put(state
->dev
);
1135 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1137 struct lec_state
*state
= seq
->private;
1139 v
= lec_get_idx(state
, 1);
1140 *pos
+= !!PTR_ERR(v
);
1144 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1146 static char lec_banner
[] = "Itf MAC ATM destination"
1148 "VPI/VCI Recv VPI/VCI\n";
1151 seq_puts(seq
, lec_banner
);
1153 struct lec_state
*state
= seq
->private;
1154 struct net_device
*dev
= state
->dev
;
1155 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1157 seq_printf(seq
, "%s ", dev
->name
);
1158 lec_info(seq
, entry
);
1163 static const struct seq_operations lec_seq_ops
= {
1164 .start
= lec_seq_start
,
1165 .next
= lec_seq_next
,
1166 .stop
= lec_seq_stop
,
1167 .show
= lec_seq_show
,
1170 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1172 struct lec_state
*state
;
1173 struct seq_file
*seq
;
1176 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
1182 rc
= seq_open(file
, &lec_seq_ops
);
1185 seq
= file
->private_data
;
1186 seq
->private = state
;
1195 static int lec_seq_release(struct inode
*inode
, struct file
*file
)
1197 return seq_release_private(inode
, file
);
1200 static const struct file_operations lec_seq_fops
= {
1201 .owner
= THIS_MODULE
,
1202 .open
= lec_seq_open
,
1204 .llseek
= seq_lseek
,
1205 .release
= lec_seq_release
,
1209 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1211 struct atm_vcc
*vcc
= ATM_SD(sock
);
1218 if (!capable(CAP_NET_ADMIN
))
1222 return -ENOIOCTLCMD
;
1227 err
= lecd_attach(vcc
, (int)arg
);
1229 sock
->state
= SS_CONNECTED
;
1232 err
= lec_mcast_attach(vcc
, (int)arg
);
1235 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1242 static struct atm_ioctl lane_ioctl_ops
= {
1243 .owner
= THIS_MODULE
,
1244 .ioctl
= lane_ioctl
,
1247 static int __init
lane_module_init(void)
1249 #ifdef CONFIG_PROC_FS
1250 struct proc_dir_entry
*p
;
1252 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1254 printk(KERN_ERR
"Unable to initialize /proc/net/atm/lec\n");
1259 register_atm_ioctl(&lane_ioctl_ops
);
1260 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1264 static void __exit
lane_module_cleanup(void)
1267 struct lec_priv
*priv
;
1269 remove_proc_entry("lec", atm_proc_root
);
1271 deregister_atm_ioctl(&lane_ioctl_ops
);
1273 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1274 if (dev_lec
[i
] != NULL
) {
1275 priv
= (struct lec_priv
*)dev_lec
[i
]->priv
;
1276 unregister_netdev(dev_lec
[i
]);
1277 free_netdev(dev_lec
[i
]);
1285 module_init(lane_module_init
);
1286 module_exit(lane_module_cleanup
);
1289 * LANE2: 3.1.3, LE_RESOLVE.request
1290 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1291 * If sizeoftlvs == NULL the default TLVs associated with with this
1293 * If dst_mac == NULL, targetless LE_ARP will be sent
1295 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
1296 u8
**tlvs
, u32
*sizeoftlvs
)
1298 unsigned long flags
;
1299 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1300 struct lec_arp_table
*table
;
1301 struct sk_buff
*skb
;
1305 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1306 table
= lec_arp_find(priv
, dst_mac
);
1307 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1311 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1315 *sizeoftlvs
= table
->sizeoftlvs
;
1320 if (sizeoftlvs
== NULL
)
1321 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1324 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1327 skb
->len
= *sizeoftlvs
;
1328 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1329 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1335 * LANE2: 3.1.4, LE_ASSOCIATE.request
1336 * Associate the *tlvs with the *lan_dst address.
1337 * Will overwrite any previous association
1338 * Returns 1 for success, 0 for failure (out of memory)
1341 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
1342 u8
*tlvs
, u32 sizeoftlvs
)
1345 struct sk_buff
*skb
;
1346 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1348 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1349 return (0); /* not our mac address */
1351 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1353 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1354 if (priv
->tlvs
== NULL
)
1356 priv
->sizeoftlvs
= sizeoftlvs
;
1358 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1361 skb
->len
= sizeoftlvs
;
1362 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1363 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1365 printk("lec.c: lane2_associate_req() failed\n");
1367 * If the previous association has changed we must
1368 * somehow notify other LANE entities about the change
1374 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1377 static void lane2_associate_ind(struct net_device
*dev
, u8
*mac_addr
,
1378 u8
*tlvs
, u32 sizeoftlvs
)
1383 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1385 * Why have the TLVs in LE_ARP entries
1386 * since we do not use them? When you
1387 * uncomment this code, make sure the
1388 * TLVs get freed when entry is killed
1390 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1393 return; /* should not happen */
1397 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1398 if (entry
->tlvs
== NULL
)
1400 entry
->sizeoftlvs
= sizeoftlvs
;
1403 printk("lec.c: lane2_associate_ind()\n");
1404 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1405 while (i
< sizeoftlvs
)
1406 printk("%02x ", tlvs
[i
++]);
1411 /* tell MPOA about the TLVs we saw */
1412 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1413 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1420 * Here starts what used to lec_arpc.c
1422 * lec_arpc.c was added here when making
1423 * lane client modular. October 1997
1426 #include <linux/types.h>
1427 #include <linux/timer.h>
1428 #include <asm/param.h>
1429 #include <asm/atomic.h>
1430 #include <linux/inetdevice.h>
1431 #include <net/route.h>
1434 #define pr_debug(format,args...)
1436 #define pr_debug printk
1439 #define DEBUG_ARP_TABLE 0
1441 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1443 static void lec_arp_check_expire(struct work_struct
*work
);
1444 static void lec_arp_expire_arp(unsigned long data
);
1450 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1453 * Initialization of arp-cache
1455 static void lec_arp_init(struct lec_priv
*priv
)
1459 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1460 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1462 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1463 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1464 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1465 spin_lock_init(&priv
->lec_arp_lock
);
1466 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1467 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1470 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1473 struct atm_vcc
*vcc
= entry
->vcc
;
1474 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1475 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1477 vcc
->pop
= vpriv
->old_pop
;
1479 netif_wake_queue(dev
);
1481 vcc
->user_back
= NULL
;
1482 vcc
->push
= entry
->old_push
;
1483 vcc_release_async(vcc
, -EPIPE
);
1486 if (entry
->recv_vcc
) {
1487 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1488 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1489 entry
->recv_vcc
= NULL
;
1494 * Insert entry to lec_arp_table
1495 * LANE2: Add to the end of the list to satisfy 8.1.13
1498 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1500 struct hlist_head
*tmp
;
1502 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1503 hlist_add_head(&entry
->next
, tmp
);
1505 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1506 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1507 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1508 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1512 * Remove entry from lec_arp_table
1515 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1517 struct hlist_node
*node
;
1518 struct lec_arp_table
*entry
;
1519 int i
, remove_vcc
= 1;
1525 hlist_del(&to_remove
->next
);
1526 del_timer(&to_remove
->timer
);
1528 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1529 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1531 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1533 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1534 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1535 if (memcmp(to_remove
->atm_addr
,
1536 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1543 lec_arp_clear_vccs(to_remove
);
1545 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1547 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1548 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1549 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1550 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1555 static char *get_status_string(unsigned char st
)
1559 return "ESI_UNKNOWN";
1560 case ESI_ARP_PENDING
:
1561 return "ESI_ARP_PENDING";
1562 case ESI_VC_PENDING
:
1563 return "ESI_VC_PENDING";
1564 case ESI_FLUSH_PENDING
:
1565 return "ESI_FLUSH_PENDING";
1566 case ESI_FORWARD_DIRECT
:
1567 return "ESI_FORWARD_DIRECT";
1573 static void dump_arp_table(struct lec_priv
*priv
)
1575 struct hlist_node
*node
;
1576 struct lec_arp_table
*rulla
;
1580 printk("Dump %p:\n", priv
);
1581 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1582 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1584 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1585 offset
+= sprintf(buf
+ offset
, "Mac:");
1586 for (j
= 0; j
< ETH_ALEN
; j
++) {
1587 offset
+= sprintf(buf
+ offset
,
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
,
1595 rulla
->atm_addr
[j
] & 0xff);
1597 offset
+= sprintf(buf
+ offset
,
1598 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1599 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1600 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1601 rulla
->recv_vcc
? rulla
->recv_vcc
->
1603 rulla
->recv_vcc
? rulla
->recv_vcc
->
1604 vci
: 0, rulla
->last_used
,
1605 rulla
->timestamp
, rulla
->no_tries
);
1607 sprintf(buf
+ offset
,
1608 "Flags:%x, Packets_flooded:%x, Status: %s ",
1609 rulla
->flags
, rulla
->packets_flooded
,
1610 get_status_string(rulla
->status
));
1611 printk("%s\n", buf
);
1615 if (!hlist_empty(&priv
->lec_no_forward
))
1616 printk("No forward\n");
1617 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1619 offset
+= sprintf(buf
+ offset
, "Mac:");
1620 for (j
= 0; j
< ETH_ALEN
; j
++) {
1621 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1622 rulla
->mac_addr
[j
] & 0xff);
1624 offset
+= sprintf(buf
+ offset
, "Atm:");
1625 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1626 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1627 rulla
->atm_addr
[j
] & 0xff);
1629 offset
+= sprintf(buf
+ offset
,
1630 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1631 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1632 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1633 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1634 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1636 rulla
->timestamp
, rulla
->no_tries
);
1637 offset
+= sprintf(buf
+ offset
,
1638 "Flags:%x, Packets_flooded:%x, Status: %s ",
1639 rulla
->flags
, rulla
->packets_flooded
,
1640 get_status_string(rulla
->status
));
1641 printk("%s\n", buf
);
1644 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1645 printk("Empty ones\n");
1646 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1648 offset
+= sprintf(buf
+ offset
, "Mac:");
1649 for (j
= 0; j
< ETH_ALEN
; j
++) {
1650 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1651 rulla
->mac_addr
[j
] & 0xff);
1653 offset
+= sprintf(buf
+ offset
, "Atm:");
1654 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1655 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1656 rulla
->atm_addr
[j
] & 0xff);
1658 offset
+= sprintf(buf
+ offset
,
1659 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1660 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1661 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1662 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1663 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1665 rulla
->timestamp
, rulla
->no_tries
);
1666 offset
+= sprintf(buf
+ offset
,
1667 "Flags:%x, Packets_flooded:%x, Status: %s ",
1668 rulla
->flags
, rulla
->packets_flooded
,
1669 get_status_string(rulla
->status
));
1673 if (!hlist_empty(&priv
->mcast_fwds
))
1674 printk("Multicast Forward VCCs\n");
1675 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1677 offset
+= sprintf(buf
+ offset
, "Mac:");
1678 for (j
= 0; j
< ETH_ALEN
; j
++) {
1679 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1680 rulla
->mac_addr
[j
] & 0xff);
1682 offset
+= sprintf(buf
+ offset
, "Atm:");
1683 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1684 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1685 rulla
->atm_addr
[j
] & 0xff);
1687 offset
+= sprintf(buf
+ offset
,
1688 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1689 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1690 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1691 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1692 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1694 rulla
->timestamp
, rulla
->no_tries
);
1695 offset
+= sprintf(buf
+ offset
,
1696 "Flags:%x, Packets_flooded:%x, Status: %s ",
1697 rulla
->flags
, rulla
->packets_flooded
,
1698 get_status_string(rulla
->status
));
1699 printk("%s\n", buf
);
1704 #define dump_arp_table(priv) do { } while (0)
1708 * Destruction of arp-cache
1710 static void lec_arp_destroy(struct lec_priv
*priv
)
1712 unsigned long flags
;
1713 struct hlist_node
*node
, *next
;
1714 struct lec_arp_table
*entry
;
1717 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1720 * Remove all entries
1723 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1724 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1725 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1726 lec_arp_remove(priv
, entry
);
1729 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1732 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1733 del_timer_sync(&entry
->timer
);
1734 lec_arp_clear_vccs(entry
);
1735 hlist_del(&entry
->next
);
1738 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1740 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1741 del_timer_sync(&entry
->timer
);
1742 lec_arp_clear_vccs(entry
);
1743 hlist_del(&entry
->next
);
1746 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1748 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1749 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1750 lec_arp_clear_vccs(entry
);
1751 hlist_del(&entry
->next
);
1754 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1755 priv
->mcast_vcc
= NULL
;
1756 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1760 * Find entry by mac_address
1762 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1763 unsigned char *mac_addr
)
1765 struct hlist_node
*node
;
1766 struct hlist_head
*head
;
1767 struct lec_arp_table
*entry
;
1769 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1770 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1771 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1773 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1774 hlist_for_each_entry(entry
, node
, head
, next
) {
1775 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1782 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1783 unsigned char *mac_addr
)
1785 struct lec_arp_table
*to_return
;
1787 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1789 printk("LEC: Arp entry kmalloc failed\n");
1792 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1793 INIT_HLIST_NODE(&to_return
->next
);
1794 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1795 (unsigned long)to_return
);
1796 to_return
->last_used
= jiffies
;
1797 to_return
->priv
= priv
;
1798 skb_queue_head_init(&to_return
->tx_wait
);
1799 atomic_set(&to_return
->usage
, 1);
1803 /* Arp sent timer expired */
1804 static void lec_arp_expire_arp(unsigned long data
)
1806 struct lec_arp_table
*entry
;
1808 entry
= (struct lec_arp_table
*)data
;
1810 pr_debug("lec_arp_expire_arp\n");
1811 if (entry
->status
== ESI_ARP_PENDING
) {
1812 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1813 if (entry
->is_rdesc
)
1814 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1815 entry
->mac_addr
, NULL
, NULL
);
1817 send_to_lecd(entry
->priv
, l_arp_xmt
,
1818 entry
->mac_addr
, NULL
, NULL
);
1821 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1825 /* Unknown/unused vcc expire, remove associated entry */
1826 static void lec_arp_expire_vcc(unsigned long data
)
1828 unsigned long flags
;
1829 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1830 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1832 del_timer(&to_remove
->timer
);
1834 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1836 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1837 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1839 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1840 hlist_del(&to_remove
->next
);
1841 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1843 lec_arp_clear_vccs(to_remove
);
1844 lec_arp_put(to_remove
);
1850 * 2. For each entry, delete entries that have aged past the age limit.
1851 * 3. For each entry, depending on the status of the entry, perform
1852 * the following maintenance.
1853 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1854 * tick_count is above the max_unknown_frame_time, clear
1855 * the tick_count to zero and clear the packets_flooded counter
1856 * to zero. This supports the packet rate limit per address
1857 * while flooding unknowns.
1858 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1859 * than or equal to the path_switching_delay, change the status
1860 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1861 * regardless of the progress of the flush protocol.
1863 static void lec_arp_check_expire(struct work_struct
*work
)
1865 unsigned long flags
;
1866 struct lec_priv
*priv
=
1867 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1868 struct hlist_node
*node
, *next
;
1869 struct lec_arp_table
*entry
;
1871 unsigned long time_to_check
;
1874 pr_debug("lec_arp_check_expire %p\n", priv
);
1877 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1878 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1879 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1880 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1881 priv
->topology_change
)
1882 time_to_check
= priv
->forward_delay_time
;
1884 time_to_check
= priv
->aging_time
;
1886 pr_debug("About to expire: %lx - %lx > %lx\n",
1887 now
, entry
->last_used
, time_to_check
);
1888 if (time_after(now
, entry
->last_used
+ time_to_check
)
1889 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1890 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1892 pr_debug("LEC:Entry timed out\n");
1893 lec_arp_remove(priv
, entry
);
1896 /* Something else */
1897 if ((entry
->status
== ESI_VC_PENDING
||
1898 entry
->status
== ESI_ARP_PENDING
)
1899 && time_after_eq(now
,
1902 max_unknown_frame_time
)) {
1903 entry
->timestamp
= jiffies
;
1904 entry
->packets_flooded
= 0;
1905 if (entry
->status
== ESI_VC_PENDING
)
1906 send_to_lecd(priv
, l_svc_setup
,
1911 if (entry
->status
== ESI_FLUSH_PENDING
1913 time_after_eq(now
, entry
->timestamp
+
1914 priv
->path_switching_delay
)) {
1915 struct sk_buff
*skb
;
1916 struct atm_vcc
*vcc
= entry
->vcc
;
1918 lec_arp_hold(entry
);
1919 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1920 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1921 lec_send(vcc
, skb
, entry
->priv
);
1922 entry
->last_used
= jiffies
;
1923 entry
->status
= ESI_FORWARD_DIRECT
;
1930 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1932 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1936 * Try to find vcc where mac_address is attached.
1939 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1940 unsigned char *mac_to_find
, int is_rdesc
,
1941 struct lec_arp_table
**ret_entry
)
1943 unsigned long flags
;
1944 struct lec_arp_table
*entry
;
1945 struct atm_vcc
*found
;
1947 if (mac_to_find
[0] & 0x01) {
1948 switch (priv
->lane_version
) {
1950 return priv
->mcast_vcc
;
1952 case 2: /* LANE2 wants arp for multicast addresses */
1953 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1954 return priv
->mcast_vcc
;
1961 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1962 entry
= lec_arp_find(priv
, mac_to_find
);
1965 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1967 entry
->last_used
= jiffies
;
1968 lec_arp_hold(entry
);
1974 * If the LE_ARP cache entry is still pending, reset count to 0
1975 * so another LE_ARP request can be made for this frame.
1977 if (entry
->status
== ESI_ARP_PENDING
) {
1978 entry
->no_tries
= 0;
1981 * Data direct VC not yet set up, check to see if the unknown
1982 * frame count is greater than the limit. If the limit has
1983 * not been reached, allow the caller to send packet to
1986 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1987 entry
->packets_flooded
<
1988 priv
->maximum_unknown_frame_count
) {
1989 entry
->packets_flooded
++;
1990 pr_debug("LEC_ARP: Flooding..\n");
1991 found
= priv
->mcast_vcc
;
1995 * We got here because entry->status == ESI_FLUSH_PENDING
1996 * or BUS flood limit was reached for an entry which is
1997 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1999 lec_arp_hold(entry
);
2001 pr_debug("lec: entry->status %d entry->vcc %p\n", entry
->status
,
2005 /* No matching entry was found */
2006 entry
= make_entry(priv
, mac_to_find
);
2007 pr_debug("LEC_ARP: Making entry\n");
2009 found
= priv
->mcast_vcc
;
2012 lec_arp_add(priv
, entry
);
2013 /* We want arp-request(s) to be sent */
2014 entry
->packets_flooded
= 1;
2015 entry
->status
= ESI_ARP_PENDING
;
2016 entry
->no_tries
= 1;
2017 entry
->last_used
= entry
->timestamp
= jiffies
;
2018 entry
->is_rdesc
= is_rdesc
;
2019 if (entry
->is_rdesc
)
2020 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
2023 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
2024 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
2025 entry
->timer
.function
= lec_arp_expire_arp
;
2026 add_timer(&entry
->timer
);
2027 found
= priv
->mcast_vcc
;
2031 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2036 lec_addr_delete(struct lec_priv
*priv
, unsigned char *atm_addr
,
2037 unsigned long permanent
)
2039 unsigned long flags
;
2040 struct hlist_node
*node
, *next
;
2041 struct lec_arp_table
*entry
;
2044 pr_debug("lec_addr_delete\n");
2045 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2046 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2047 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2048 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2050 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2051 lec_arp_remove(priv
, entry
);
2054 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2058 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2063 * Notifies: Response to arp_request (atm_addr != NULL)
2066 lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
2067 unsigned char *atm_addr
, unsigned long remoteflag
,
2068 unsigned int targetless_le_arp
)
2070 unsigned long flags
;
2071 struct hlist_node
*node
, *next
;
2072 struct lec_arp_table
*entry
, *tmp
;
2075 pr_debug("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2076 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2077 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2078 mac_addr
[4], mac_addr
[5]);
2080 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2081 entry
= lec_arp_find(priv
, mac_addr
);
2082 if (entry
== NULL
&& targetless_le_arp
)
2084 * LANE2: ignore targetless LE_ARPs for which
2085 * we have no entry in the cache. 7.1.30
2087 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2088 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2089 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2090 hlist_del(&entry
->next
);
2091 del_timer(&entry
->timer
);
2092 tmp
= lec_arp_find(priv
, mac_addr
);
2094 del_timer(&tmp
->timer
);
2095 tmp
->status
= ESI_FORWARD_DIRECT
;
2096 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2097 tmp
->vcc
= entry
->vcc
;
2098 tmp
->old_push
= entry
->old_push
;
2099 tmp
->last_used
= jiffies
;
2100 del_timer(&entry
->timer
);
2104 entry
->status
= ESI_FORWARD_DIRECT
;
2105 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2106 entry
->last_used
= jiffies
;
2107 lec_arp_add(priv
, entry
);
2110 entry
->flags
|= LEC_REMOTE_FLAG
;
2112 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2113 pr_debug("After update\n");
2114 dump_arp_table(priv
);
2120 entry
= lec_arp_find(priv
, mac_addr
);
2122 entry
= make_entry(priv
, mac_addr
);
2125 entry
->status
= ESI_UNKNOWN
;
2126 lec_arp_add(priv
, entry
);
2127 /* Temporary, changes before end of function */
2129 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2130 del_timer(&entry
->timer
);
2131 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2132 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2134 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2135 /* Vcc to this host exists */
2136 if (tmp
->status
> ESI_VC_PENDING
) {
2138 * ESI_FLUSH_PENDING,
2139 * ESI_FORWARD_DIRECT
2141 entry
->vcc
= tmp
->vcc
;
2142 entry
->old_push
= tmp
->old_push
;
2144 entry
->status
= tmp
->status
;
2150 entry
->flags
|= LEC_REMOTE_FLAG
;
2152 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2153 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2154 entry
->status
= ESI_VC_PENDING
;
2155 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2157 pr_debug("After update2\n");
2158 dump_arp_table(priv
);
2160 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2164 * Notifies: Vcc setup ready
2167 lec_vcc_added(struct lec_priv
*priv
, struct atmlec_ioc
*ioc_data
,
2168 struct atm_vcc
*vcc
,
2169 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2171 unsigned long flags
;
2172 struct hlist_node
*node
;
2173 struct lec_arp_table
*entry
;
2174 int i
, found_entry
= 0;
2176 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2177 if (ioc_data
->receive
== 2) {
2178 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2180 pr_debug("LEC_ARP: Attaching mcast forward\n");
2182 entry
= lec_arp_find(priv
, bus_mac
);
2184 printk("LEC_ARP: Multicast entry not found!\n");
2187 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2188 entry
->recv_vcc
= vcc
;
2189 entry
->old_recv_push
= old_push
;
2191 entry
= make_entry(priv
, bus_mac
);
2194 del_timer(&entry
->timer
);
2195 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2196 entry
->recv_vcc
= vcc
;
2197 entry
->old_recv_push
= old_push
;
2198 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2200 } else if (ioc_data
->receive
== 1) {
2202 * Vcc which we don't want to make default vcc,
2206 ("LEC_ARP:Attaching data direct, not default: "
2207 "%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",
2208 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2209 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2210 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2211 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2212 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2213 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2214 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2215 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2216 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2217 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2218 entry
= make_entry(priv
, bus_mac
);
2221 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2222 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2223 entry
->recv_vcc
= vcc
;
2224 entry
->old_recv_push
= old_push
;
2225 entry
->status
= ESI_UNKNOWN
;
2226 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2227 entry
->timer
.function
= lec_arp_expire_vcc
;
2228 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2229 add_timer(&entry
->timer
);
2230 dump_arp_table(priv
);
2234 ("LEC_ARP:Attaching data direct, default: "
2235 "%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",
2236 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2237 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2238 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2239 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2240 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2241 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2242 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2243 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2244 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2245 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2246 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2247 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2249 (ioc_data
->atm_addr
, entry
->atm_addr
,
2250 ATM_ESA_LEN
) == 0) {
2251 pr_debug("LEC_ARP: Attaching data direct\n");
2252 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2253 entry
->vcc
? entry
->vcc
->vci
: 0,
2254 entry
->recv_vcc
? entry
->recv_vcc
->
2257 del_timer(&entry
->timer
);
2259 entry
->old_push
= old_push
;
2260 if (entry
->status
== ESI_VC_PENDING
) {
2261 if (priv
->maximum_unknown_frame_count
2266 entry
->timestamp
= jiffies
;
2270 send_to_lecd(priv
, l_flush_xmt
,
2278 * They were forming a connection
2279 * to us, and we to them. Our
2280 * ATM address is numerically lower
2281 * than theirs, so we make connection
2282 * we formed into default VCC (8.1.11).
2283 * Connection they made gets torn
2284 * down. This might confuse some
2285 * clients. Can be changed if
2286 * someone reports trouble...
2294 pr_debug("After vcc was added\n");
2295 dump_arp_table(priv
);
2299 * Not found, snatch address from first data packet that arrives
2302 entry
= make_entry(priv
, bus_mac
);
2306 entry
->old_push
= old_push
;
2307 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2308 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2309 entry
->status
= ESI_UNKNOWN
;
2310 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2311 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2312 entry
->timer
.function
= lec_arp_expire_vcc
;
2313 add_timer(&entry
->timer
);
2314 pr_debug("After vcc was added\n");
2315 dump_arp_table(priv
);
2317 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2320 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2322 unsigned long flags
;
2323 struct hlist_node
*node
;
2324 struct lec_arp_table
*entry
;
2327 pr_debug("LEC:lec_flush_complete %lx\n", tran_id
);
2329 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2330 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2331 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2332 if (entry
->flush_tran_id
== tran_id
2333 && entry
->status
== ESI_FLUSH_PENDING
) {
2334 struct sk_buff
*skb
;
2335 struct atm_vcc
*vcc
= entry
->vcc
;
2337 lec_arp_hold(entry
);
2338 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2339 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2340 lec_send(vcc
, skb
, entry
->priv
);
2341 entry
->last_used
= jiffies
;
2342 entry
->status
= ESI_FORWARD_DIRECT
;
2344 pr_debug("LEC_ARP: Flushed\n");
2349 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2350 dump_arp_table(priv
);
2354 lec_set_flush_tran_id(struct lec_priv
*priv
,
2355 unsigned char *atm_addr
, unsigned long tran_id
)
2357 unsigned long flags
;
2358 struct hlist_node
*node
;
2359 struct lec_arp_table
*entry
;
2362 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2363 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2364 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2365 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2366 entry
->flush_tran_id
= tran_id
;
2367 pr_debug("Set flush transaction id to %lx for %p\n",
2371 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2374 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2376 unsigned long flags
;
2377 unsigned char mac_addr
[] = {
2378 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2380 struct lec_arp_table
*to_add
;
2381 struct lec_vcc_priv
*vpriv
;
2384 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2387 vpriv
->old_pop
= vcc
->pop
;
2388 vcc
->user_back
= vpriv
;
2390 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2391 to_add
= make_entry(priv
, mac_addr
);
2393 vcc
->pop
= vpriv
->old_pop
;
2398 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2399 to_add
->status
= ESI_FORWARD_DIRECT
;
2400 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2402 to_add
->old_push
= vcc
->push
;
2403 vcc
->push
= lec_push
;
2404 priv
->mcast_vcc
= vcc
;
2405 lec_arp_add(priv
, to_add
);
2407 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2411 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2413 unsigned long flags
;
2414 struct hlist_node
*node
, *next
;
2415 struct lec_arp_table
*entry
;
2418 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2419 dump_arp_table(priv
);
2421 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2423 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2424 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2425 if (vcc
== entry
->vcc
) {
2426 lec_arp_remove(priv
, entry
);
2428 if (priv
->mcast_vcc
== vcc
) {
2429 priv
->mcast_vcc
= NULL
;
2435 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2436 if (entry
->vcc
== vcc
) {
2437 lec_arp_clear_vccs(entry
);
2438 del_timer(&entry
->timer
);
2439 hlist_del(&entry
->next
);
2444 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2445 if (entry
->recv_vcc
== vcc
) {
2446 lec_arp_clear_vccs(entry
);
2447 del_timer(&entry
->timer
);
2448 hlist_del(&entry
->next
);
2453 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2454 if (entry
->recv_vcc
== vcc
) {
2455 lec_arp_clear_vccs(entry
);
2456 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2457 hlist_del(&entry
->next
);
2462 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2463 dump_arp_table(priv
);
2467 lec_arp_check_empties(struct lec_priv
*priv
,
2468 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2470 unsigned long flags
;
2471 struct hlist_node
*node
, *next
;
2472 struct lec_arp_table
*entry
, *tmp
;
2473 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2476 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2479 src
= tr_hdr
->h_source
;
2482 src
= hdr
->h_source
;
2484 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2485 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2486 if (vcc
== entry
->vcc
) {
2487 del_timer(&entry
->timer
);
2488 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2489 entry
->status
= ESI_FORWARD_DIRECT
;
2490 entry
->last_used
= jiffies
;
2491 /* We might have got an entry */
2492 if ((tmp
= lec_arp_find(priv
, src
))) {
2493 lec_arp_remove(priv
, tmp
);
2496 hlist_del(&entry
->next
);
2497 lec_arp_add(priv
, entry
);
2501 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2503 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2506 MODULE_LICENSE("GPL");