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/proc_fs.h>
25 #include <linux/seq_file.h>
27 /* TokenRing if needed */
29 #include <linux/trdevice.h>
33 #include <linux/atmdev.h>
34 #include <linux/atmlec.h>
36 /* Proxy LEC knows about bridging */
37 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38 #include <linux/if_bridge.h>
39 #include "../bridge/br_private.h"
41 static unsigned char bridge_ula_lec
[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
45 #include <linux/module.h>
46 #include <linux/init.h>
50 #include "resources.h"
53 #define DPRINTK printk
55 #define DPRINTK(format,args...)
58 #define DUMP_PACKETS 0 /*
64 #define LEC_UNRES_QUE_LEN 8 /*
65 * number of tx packets to queue for a
66 * single destination while waiting for SVC
69 static int lec_open(struct net_device
*dev
);
70 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
71 static int lec_close(struct net_device
*dev
);
72 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
);
73 static void lec_init(struct net_device
*dev
);
74 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
75 unsigned char *mac_addr
);
76 static int lec_arp_remove(struct lec_priv
*priv
,
77 struct lec_arp_table
*to_remove
);
79 static void lane2_associate_ind(struct net_device
*dev
, u8
*mac_address
,
80 u8
*tlvs
, u32 sizeoftlvs
);
81 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
82 u8
**tlvs
, u32
*sizeoftlvs
);
83 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
84 u8
*tlvs
, u32 sizeoftlvs
);
86 static int lec_addr_delete(struct lec_priv
*priv
, unsigned char *atm_addr
,
87 unsigned long permanent
);
88 static void lec_arp_check_empties(struct lec_priv
*priv
,
89 struct atm_vcc
*vcc
, struct sk_buff
*skb
);
90 static void lec_arp_destroy(struct lec_priv
*priv
);
91 static void lec_arp_init(struct lec_priv
*priv
);
92 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
93 unsigned char *mac_to_find
,
95 struct lec_arp_table
**ret_entry
);
96 static void lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
97 unsigned char *atm_addr
, unsigned long remoteflag
,
98 unsigned int targetless_le_arp
);
99 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
100 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
101 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
102 unsigned char *atm_addr
,
103 unsigned long tran_id
);
104 static void lec_vcc_added(struct lec_priv
*priv
, struct atmlec_ioc
*ioc_data
,
106 void (*old_push
) (struct atm_vcc
*vcc
,
107 struct sk_buff
*skb
));
108 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
110 static struct lane2_ops lane2_ops
= {
111 lane2_resolve
, /* resolve, spec 3.1.3 */
112 lane2_associate_req
, /* associate_req, spec 3.1.4 */
113 NULL
/* associate indicator, spec 3.1.5 */
116 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
118 /* Device structures */
119 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
121 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
122 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
126 struct lec_priv
*priv
;
129 * Check if this is a BPDU. If so, ask zeppelin to send
130 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
131 * as the Config BPDU has
133 eth
= (struct ethhdr
*)skb
->data
;
134 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
135 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
137 struct sk_buff
*skb2
;
138 struct atmlec_msg
*mesg
;
140 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
143 skb2
->len
= sizeof(struct atmlec_msg
);
144 mesg
= (struct atmlec_msg
*)skb2
->data
;
145 mesg
->type
= l_topology_change
;
147 mesg
->content
.normal
.flag
= *buff
& 0x01; /* 0x01 is topology change */
149 priv
= (struct lec_priv
*)dev
->priv
;
150 atm_force_charge(priv
->lecd
, skb2
->truesize
);
151 sk
= sk_atm(priv
->lecd
);
152 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
153 sk
->sk_data_ready(sk
, skb2
->len
);
158 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
161 * Modelled after tr_type_trans
162 * All multicast and ARE or STE frames go to BUS.
163 * Non source routed frames go by destination address.
164 * Last hop source routed frames go by destination address.
165 * Not last hop source routed frames go by _next_ route descriptor.
166 * Returns pointer to destination MAC address or fills in rdesc
170 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
173 int riflen
, num_rdsc
;
175 trh
= (struct trh_hdr
*)packet
;
176 if (trh
->daddr
[0] & (uint8_t) 0x80)
177 return bus_mac
; /* multicast */
179 if (trh
->saddr
[0] & TR_RII
) {
180 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
181 if ((ntohs(trh
->rcf
) >> 13) != 0)
182 return bus_mac
; /* ARE or STE */
184 return trh
->daddr
; /* not source routed */
187 return trh
->daddr
; /* last hop, source routed */
189 /* riflen is 6 or more, packet has more than one route descriptor */
190 num_rdsc
= (riflen
/ 2) - 1;
191 memset(rdesc
, 0, ETH_ALEN
);
192 /* offset 4 comes from LAN destination field in LE control frames */
193 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
194 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(uint16_t));
196 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(uint16_t));
197 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
202 #endif /* CONFIG_TR */
205 * Open/initialize the netdevice. This is called (in the current kernel)
206 * sometime after booting when the 'ifconfig' program is run.
208 * This routine should set everything up anew at each open, even
209 * registers that "should" only need to be set once at boot, so that
210 * there is non-reboot way to recover if something goes wrong.
213 static int lec_open(struct net_device
*dev
)
215 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
217 netif_start_queue(dev
);
218 memset(&priv
->stats
, 0, sizeof(struct net_device_stats
));
223 static __inline__
void
224 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
, struct lec_priv
*priv
)
226 ATM_SKB(skb
)->vcc
= vcc
;
227 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
229 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
230 if (vcc
->send(vcc
, skb
) < 0) {
231 priv
->stats
.tx_dropped
++;
235 priv
->stats
.tx_packets
++;
236 priv
->stats
.tx_bytes
+= skb
->len
;
239 static void lec_tx_timeout(struct net_device
*dev
)
241 printk(KERN_INFO
"%s: tx timeout\n", dev
->name
);
242 dev
->trans_start
= jiffies
;
243 netif_wake_queue(dev
);
246 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
248 struct sk_buff
*skb2
;
249 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
250 struct lecdatahdr_8023
*lec_h
;
252 struct lec_arp_table
*entry
;
256 unsigned char rdesc
[ETH_ALEN
]; /* Token Ring route descriptor */
262 #endif /* DUMP_PACKETS >0 */
264 DPRINTK("lec_start_xmit called\n");
266 printk("%s:No lecd attached\n", dev
->name
);
267 priv
->stats
.tx_errors
++;
268 netif_stop_queue(dev
);
272 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
273 (long)skb
->head
, (long)skb
->data
, (long)skb
->tail
,
275 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
276 if (memcmp(skb
->data
, bridge_ula_lec
, sizeof(bridge_ula_lec
)) == 0)
277 lec_handle_bridge(skb
, dev
);
280 /* Make sure we have room for lec_id */
281 if (skb_headroom(skb
) < 2) {
283 DPRINTK("lec_start_xmit: reallocating skb\n");
284 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
292 /* Put le header to place, works for TokenRing too */
293 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
294 lec_h
->le_header
= htons(priv
->lecid
);
298 * Ugly. Use this to realign Token Ring packets for
299 * e.g. PCA-200E driver.
301 if (priv
->is_trdev
) {
302 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
311 printk("%s: send datalen:%ld lecid:%4.4x\n", dev
->name
,
312 skb
->len
, priv
->lecid
);
313 #if DUMP_PACKETS >= 2
314 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
315 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
317 #elif DUMP_PACKETS >= 1
318 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
319 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
321 #endif /* DUMP_PACKETS >= 1 */
325 printk("%s...\n", buf
);
326 #endif /* DUMP_PACKETS > 0 */
328 /* Minimum ethernet-frame size */
331 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
334 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
335 if (skb
->len
< min_frame_size
) {
336 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
337 skb2
= skb_copy_expand(skb
, 0,
338 min_frame_size
- skb
->truesize
,
342 priv
->stats
.tx_dropped
++;
347 skb_put(skb
, min_frame_size
- skb
->len
);
350 /* Send to right vcc */
354 if (priv
->is_trdev
) {
355 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
363 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
364 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev
->name
,
365 vcc
, vcc
? vcc
->flags
: 0, entry
);
366 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
367 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
368 DPRINTK("%s:lec_start_xmit: queuing packet, ",
370 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
371 lec_h
->h_dest
[0], lec_h
->h_dest
[1],
372 lec_h
->h_dest
[2], lec_h
->h_dest
[3],
373 lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
374 skb_queue_tail(&entry
->tx_wait
, skb
);
377 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
379 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
380 lec_h
->h_dest
[0], lec_h
->h_dest
[1],
381 lec_h
->h_dest
[2], lec_h
->h_dest
[3],
382 lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
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 DPRINTK("lec.c: emptying tx queue, ");
394 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
395 lec_h
->h_dest
[0], lec_h
->h_dest
[1], lec_h
->h_dest
[2],
396 lec_h
->h_dest
[3], lec_h
->h_dest
[4], lec_h
->h_dest
[5]);
397 lec_send(vcc
, skb2
, priv
);
400 lec_send(vcc
, skb
, priv
);
402 if (!atm_may_send(vcc
, 0)) {
403 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
406 netif_stop_queue(dev
);
409 * vcc->pop() might have occurred in between, making
410 * the vcc usuable again. Since xmit is serialized,
411 * this is the only situation we have to re-test.
414 if (atm_may_send(vcc
, 0))
415 netif_wake_queue(dev
);
418 dev
->trans_start
= jiffies
;
422 /* The inverse routine to net_open(). */
423 static int lec_close(struct net_device
*dev
)
425 netif_stop_queue(dev
);
430 * Get the current statistics.
431 * This may be called with the card open or closed.
433 static struct net_device_stats
*lec_get_stats(struct net_device
*dev
)
435 return &((struct lec_priv
*)dev
->priv
)->stats
;
438 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
441 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
442 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
443 struct atmlec_msg
*mesg
;
444 struct lec_arp_table
*entry
;
446 char *tmp
; /* FIXME */
448 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
449 mesg
= (struct atmlec_msg
*)skb
->data
;
451 tmp
+= sizeof(struct atmlec_msg
);
452 DPRINTK("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
453 switch (mesg
->type
) {
455 for (i
= 0; i
< 6; i
++) {
456 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
460 for (i
= 0; i
< 6; i
++) {
461 dev
->dev_addr
[i
] = 0;
465 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
466 mesg
->content
.normal
.flag
);
468 case l_topology_change
:
469 priv
->topology_change
= mesg
->content
.normal
.flag
;
471 case l_flush_complete
:
472 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
474 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
475 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
476 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
477 lec_arp_remove(priv
, entry
);
478 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
480 if (mesg
->content
.normal
.no_source_le_narp
)
484 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
485 mesg
->content
.normal
.atm_addr
,
486 mesg
->content
.normal
.flag
,
487 mesg
->content
.normal
.targetless_le_arp
);
488 DPRINTK("lec: in l_arp_update\n");
489 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
490 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
492 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
493 tmp
, mesg
->sizeoftlvs
);
497 priv
->maximum_unknown_frame_count
=
498 mesg
->content
.config
.maximum_unknown_frame_count
;
499 priv
->max_unknown_frame_time
=
500 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
501 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
502 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
503 priv
->forward_delay_time
=
504 (mesg
->content
.config
.forward_delay_time
* HZ
);
505 priv
->arp_response_time
=
506 (mesg
->content
.config
.arp_response_time
* HZ
);
507 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
508 priv
->path_switching_delay
=
509 (mesg
->content
.config
.path_switching_delay
* HZ
);
510 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
511 priv
->lane2_ops
= NULL
;
512 if (priv
->lane_version
> 1)
513 priv
->lane2_ops
= &lane2_ops
;
514 if (dev
->change_mtu(dev
, mesg
->content
.config
.mtu
))
515 printk("%s: change_mtu to %d failed\n", dev
->name
,
516 mesg
->content
.config
.mtu
);
517 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
519 case l_flush_tran_id
:
520 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
521 mesg
->content
.normal
.flag
);
525 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
527 case l_should_bridge
:
528 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
530 struct net_bridge_fdb_entry
*f
;
533 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
534 dev
->name
, mesg
->content
.proxy
.mac_addr
[0],
535 mesg
->content
.proxy
.mac_addr
[1],
536 mesg
->content
.proxy
.mac_addr
[2],
537 mesg
->content
.proxy
.mac_addr
[3],
538 mesg
->content
.proxy
.mac_addr
[4],
539 mesg
->content
.proxy
.mac_addr
[5]);
541 if (br_fdb_get_hook
== NULL
|| dev
->br_port
== NULL
)
544 f
= br_fdb_get_hook(dev
->br_port
->br
,
545 mesg
->content
.proxy
.mac_addr
);
546 if (f
!= NULL
&& f
->dst
->dev
!= dev
547 && f
->dst
->state
== BR_STATE_FORWARDING
) {
548 /* hit from bridge table, send LE_ARP_RESPONSE */
549 struct sk_buff
*skb2
;
553 ("%s: entry found, responding to zeppelin\n",
556 alloc_skb(sizeof(struct atmlec_msg
),
562 skb2
->len
= sizeof(struct atmlec_msg
);
563 memcpy(skb2
->data
, mesg
,
564 sizeof(struct atmlec_msg
));
565 atm_force_charge(priv
->lecd
, skb2
->truesize
);
566 sk
= sk_atm(priv
->lecd
);
567 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
568 sk
->sk_data_ready(sk
, skb2
->len
);
573 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
576 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
584 static void lec_atm_close(struct atm_vcc
*vcc
)
587 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
588 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
591 /* Do something needful? */
593 netif_stop_queue(dev
);
594 lec_arp_destroy(priv
);
596 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
597 printk("%s lec_atm_close: closing with messages pending\n",
599 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
600 atm_return(vcc
, skb
->truesize
);
604 printk("%s: Shut down!\n", dev
->name
);
605 module_put(THIS_MODULE
);
608 static struct atmdev_ops lecdev_ops
= {
609 .close
= lec_atm_close
,
613 static struct atm_dev lecatm_dev
= {
616 .number
= 999, /* dummy device number */
617 .lock
= SPIN_LOCK_UNLOCKED
621 * LANE2: new argument struct sk_buff *data contains
622 * the LE_ARP based TLVs introduced in the LANE2 spec
625 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
626 unsigned char *mac_addr
, unsigned char *atm_addr
,
627 struct sk_buff
*data
)
631 struct atmlec_msg
*mesg
;
633 if (!priv
|| !priv
->lecd
) {
636 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
639 skb
->len
= sizeof(struct atmlec_msg
);
640 mesg
= (struct atmlec_msg
*)skb
->data
;
641 memset(mesg
, 0, sizeof(struct atmlec_msg
));
644 mesg
->sizeoftlvs
= data
->len
;
646 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
648 mesg
->content
.normal
.targetless_le_arp
= 1;
650 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
652 atm_force_charge(priv
->lecd
, skb
->truesize
);
653 sk
= sk_atm(priv
->lecd
);
654 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
655 sk
->sk_data_ready(sk
, skb
->len
);
658 DPRINTK("lec: about to send %d bytes of data\n", data
->len
);
659 atm_force_charge(priv
->lecd
, data
->truesize
);
660 skb_queue_tail(&sk
->sk_receive_queue
, data
);
661 sk
->sk_data_ready(sk
, skb
->len
);
667 /* shamelessly stolen from drivers/net/net_init.c */
668 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
670 if ((new_mtu
< 68) || (new_mtu
> 18190))
676 static void lec_set_multicast_list(struct net_device
*dev
)
679 * by default, all multicast frames arrive over the bus.
680 * eventually support selective multicast service
685 static void lec_init(struct net_device
*dev
)
687 dev
->change_mtu
= lec_change_mtu
;
688 dev
->open
= lec_open
;
689 dev
->stop
= lec_close
;
690 dev
->hard_start_xmit
= lec_start_xmit
;
691 dev
->tx_timeout
= lec_tx_timeout
;
693 dev
->get_stats
= lec_get_stats
;
694 dev
->set_multicast_list
= lec_set_multicast_list
;
695 dev
->do_ioctl
= NULL
;
696 printk("%s: Initialized!\n", dev
->name
);
700 static unsigned char lec_ctrl_magic
[] = {
707 #define LEC_DATA_DIRECT_8023 2
708 #define LEC_DATA_DIRECT_8025 3
710 static int lec_is_data_direct(struct atm_vcc
*vcc
)
712 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
713 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
716 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
719 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
720 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
726 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
730 DPRINTK("%s: null skb\n", dev
->name
);
731 lec_vcc_close(priv
, vcc
);
735 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
736 skb
->len
, priv
->lecid
);
737 #if DUMP_PACKETS >= 2
738 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
739 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
741 #elif DUMP_PACKETS >= 1
742 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
743 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
745 #endif /* DUMP_PACKETS >= 1 */
749 printk("%s...\n", buf
);
750 #endif /* DUMP_PACKETS > 0 */
751 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
752 struct sock
*sk
= sk_atm(vcc
);
754 DPRINTK("%s: To daemon\n", dev
->name
);
755 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
756 sk
->sk_data_ready(sk
, skb
->len
);
757 } else { /* Data frame, queue to protocol handlers */
758 struct lec_arp_table
*entry
;
759 unsigned char *src
, *dst
;
761 atm_return(vcc
, skb
->truesize
);
762 if (*(uint16_t *) skb
->data
== htons(priv
->lecid
) ||
763 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
765 * Probably looping back, or if lecd is missing,
768 DPRINTK("Ignoring frame...\n");
774 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
777 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
780 * If this is a Data Direct VCC, and the VCC does not match
781 * the LE_ARP cache entry, delete the LE_ARP cache entry.
783 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
784 if (lec_is_data_direct(vcc
)) {
788 ((struct lecdatahdr_8025
*)skb
->data
)->
793 ((struct lecdatahdr_8023
*)skb
->data
)->
795 entry
= lec_arp_find(priv
, src
);
796 if (entry
&& entry
->vcc
!= vcc
) {
797 lec_arp_remove(priv
, entry
);
801 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
803 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
804 !priv
->is_proxy
&& /* Proxy wants all the packets */
805 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
809 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
810 lec_arp_check_empties(priv
, vcc
, skb
);
813 skb_pull(skb
, 2); /* skip lec_id */
816 skb
->protocol
= tr_type_trans(skb
, dev
);
819 skb
->protocol
= eth_type_trans(skb
, dev
);
820 priv
->stats
.rx_packets
++;
821 priv
->stats
.rx_bytes
+= skb
->len
;
822 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
827 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
829 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
830 struct net_device
*dev
= skb
->dev
;
833 printk("lec_pop(): vpriv = NULL!?!?!?\n");
837 vpriv
->old_pop(vcc
, skb
);
839 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
841 if (netif_running(dev
) && netif_queue_stopped(dev
))
842 netif_wake_queue(dev
);
846 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
848 struct lec_vcc_priv
*vpriv
;
850 struct atmlec_ioc ioc_data
;
852 /* Lecd must be up in this case */
853 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
854 if (bytes_left
!= 0) {
856 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
859 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
860 !dev_lec
[ioc_data
.dev_num
])
862 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
865 vpriv
->old_pop
= vcc
->pop
;
866 vcc
->user_back
= vpriv
;
868 lec_vcc_added(dev_lec
[ioc_data
.dev_num
]->priv
,
869 &ioc_data
, vcc
, vcc
->push
);
870 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
871 vcc
->push
= lec_push
;
875 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
877 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
879 vcc
->proto_data
= dev_lec
[arg
];
880 return (lec_mcast_make((struct lec_priv
*)dev_lec
[arg
]->priv
, vcc
));
883 /* Initialize device. */
884 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
887 struct lec_priv
*priv
;
894 if (arg
>= MAX_LEC_ITF
)
896 #else /* Reserve the top NUM_TR_DEVS for TR */
897 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
904 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
907 size
= sizeof(struct lec_priv
);
910 dev_lec
[i
] = alloc_trdev(size
);
913 dev_lec
[i
] = alloc_etherdev(size
);
916 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
917 if (register_netdev(dev_lec
[i
])) {
918 free_netdev(dev_lec
[i
]);
922 priv
= dev_lec
[i
]->priv
;
923 priv
->is_trdev
= is_trdev
;
924 lec_init(dev_lec
[i
]);
926 priv
= dev_lec
[i
]->priv
;
931 priv
->itfnum
= i
; /* LANE2 addition */
933 vcc
->dev
= &lecatm_dev
;
934 vcc_insert_socket(sk_atm(vcc
));
936 vcc
->proto_data
= dev_lec
[i
];
937 set_bit(ATM_VF_META
, &vcc
->flags
);
938 set_bit(ATM_VF_READY
, &vcc
->flags
);
940 /* Set default values to these variables */
941 priv
->maximum_unknown_frame_count
= 1;
942 priv
->max_unknown_frame_time
= (1 * HZ
);
943 priv
->vcc_timeout_period
= (1200 * HZ
);
944 priv
->max_retry_count
= 1;
945 priv
->aging_time
= (300 * HZ
);
946 priv
->forward_delay_time
= (15 * HZ
);
947 priv
->topology_change
= 0;
948 priv
->arp_response_time
= (1 * HZ
);
949 priv
->flush_timeout
= (4 * HZ
);
950 priv
->path_switching_delay
= (6 * HZ
);
952 if (dev_lec
[i
]->flags
& IFF_UP
) {
953 netif_start_queue(dev_lec
[i
]);
955 __module_get(THIS_MODULE
);
959 #ifdef CONFIG_PROC_FS
960 static char *lec_arp_get_status_string(unsigned char status
)
962 static char *lec_arp_status_string
[] = {
967 "ESI_FLUSH_PENDING ",
971 if (status
> ESI_FORWARD_DIRECT
)
972 status
= 3; /* ESI_UNDEFINED */
973 return lec_arp_status_string
[status
];
976 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
980 for (i
= 0; i
< ETH_ALEN
; i
++)
981 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
982 seq_printf(seq
, " ");
983 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
984 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
985 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
986 entry
->flags
& 0xffff);
988 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
990 seq_printf(seq
, " ");
991 if (entry
->recv_vcc
) {
992 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
993 entry
->recv_vcc
->vci
);
1000 struct lec_priv
*locked
;
1001 struct hlist_node
*node
;
1002 struct net_device
*dev
;
1008 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
1011 struct hlist_node
*e
= state
->node
;
1012 struct lec_arp_table
*tmp
;
1016 if (e
== (void *)1) {
1021 hlist_for_each_entry_from(tmp
, e
, next
) {
1027 return (*l
< 0) ? state
: NULL
;
1030 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1031 struct lec_priv
*priv
)
1036 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1037 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1041 state
->arp_table
= p
;
1045 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1046 struct lec_priv
*priv
)
1048 struct hlist_head
*lec_misc_tables
[] = {
1049 &priv
->lec_arp_empty_ones
,
1050 &priv
->lec_no_forward
,
1056 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1057 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1061 state
->misc_table
= q
;
1065 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1066 struct lec_priv
*priv
)
1068 if (!state
->locked
) {
1069 state
->locked
= priv
;
1070 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1072 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1073 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1074 state
->locked
= NULL
;
1075 /* Partial state reset for the next time we get called */
1076 state
->arp_table
= state
->misc_table
= 0;
1078 return state
->locked
;
1081 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1083 struct net_device
*dev
;
1086 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1087 v
= (dev
&& dev
->priv
) ? lec_priv_walk(state
, l
, dev
->priv
) : NULL
;
1090 /* Partial state reset for the next time we get called */
1097 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1101 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1102 v
= lec_itf_walk(state
, &l
);
1109 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1111 struct lec_state
*state
= seq
->private;
1115 state
->locked
= NULL
;
1116 state
->arp_table
= 0;
1117 state
->misc_table
= 0;
1118 state
->node
= (void *)1;
1120 return *pos
? lec_get_idx(state
, *pos
) : (void *)1;
1123 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1125 struct lec_state
*state
= seq
->private;
1128 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1130 dev_put(state
->dev
);
1134 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1136 struct lec_state
*state
= seq
->private;
1138 v
= lec_get_idx(state
, 1);
1139 *pos
+= !!PTR_ERR(v
);
1143 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1145 static char lec_banner
[] = "Itf MAC ATM destination"
1147 "VPI/VCI Recv VPI/VCI\n";
1150 seq_puts(seq
, lec_banner
);
1152 struct lec_state
*state
= seq
->private;
1153 struct net_device
*dev
= state
->dev
;
1154 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1156 seq_printf(seq
, "%s ", dev
->name
);
1157 lec_info(seq
, entry
);
1162 static struct seq_operations lec_seq_ops
= {
1163 .start
= lec_seq_start
,
1164 .next
= lec_seq_next
,
1165 .stop
= lec_seq_stop
,
1166 .show
= lec_seq_show
,
1169 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1171 struct lec_state
*state
;
1172 struct seq_file
*seq
;
1175 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
1181 rc
= seq_open(file
, &lec_seq_ops
);
1184 seq
= file
->private_data
;
1185 seq
->private = state
;
1194 static int lec_seq_release(struct inode
*inode
, struct file
*file
)
1196 return seq_release_private(inode
, file
);
1199 static struct file_operations lec_seq_fops
= {
1200 .owner
= THIS_MODULE
,
1201 .open
= lec_seq_open
,
1203 .llseek
= seq_lseek
,
1204 .release
= lec_seq_release
,
1208 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1210 struct atm_vcc
*vcc
= ATM_SD(sock
);
1217 if (!capable(CAP_NET_ADMIN
))
1221 return -ENOIOCTLCMD
;
1226 err
= lecd_attach(vcc
, (int)arg
);
1228 sock
->state
= SS_CONNECTED
;
1231 err
= lec_mcast_attach(vcc
, (int)arg
);
1234 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1241 static struct atm_ioctl lane_ioctl_ops
= {
1242 .owner
= THIS_MODULE
,
1243 .ioctl
= lane_ioctl
,
1246 static int __init
lane_module_init(void)
1248 #ifdef CONFIG_PROC_FS
1249 struct proc_dir_entry
*p
;
1251 p
= create_proc_entry("lec", S_IRUGO
, atm_proc_root
);
1253 p
->proc_fops
= &lec_seq_fops
;
1256 register_atm_ioctl(&lane_ioctl_ops
);
1257 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1261 static void __exit
lane_module_cleanup(void)
1264 struct lec_priv
*priv
;
1266 remove_proc_entry("lec", atm_proc_root
);
1268 deregister_atm_ioctl(&lane_ioctl_ops
);
1270 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1271 if (dev_lec
[i
] != NULL
) {
1272 priv
= (struct lec_priv
*)dev_lec
[i
]->priv
;
1273 unregister_netdev(dev_lec
[i
]);
1274 free_netdev(dev_lec
[i
]);
1282 module_init(lane_module_init
);
1283 module_exit(lane_module_cleanup
);
1286 * LANE2: 3.1.3, LE_RESOLVE.request
1287 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1288 * If sizeoftlvs == NULL the default TLVs associated with with this
1290 * If dst_mac == NULL, targetless LE_ARP will be sent
1292 static int lane2_resolve(struct net_device
*dev
, u8
*dst_mac
, int force
,
1293 u8
**tlvs
, u32
*sizeoftlvs
)
1295 unsigned long flags
;
1296 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1297 struct lec_arp_table
*table
;
1298 struct sk_buff
*skb
;
1302 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1303 table
= lec_arp_find(priv
, dst_mac
);
1304 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1308 *tlvs
= kmalloc(table
->sizeoftlvs
, GFP_ATOMIC
);
1312 memcpy(*tlvs
, table
->tlvs
, table
->sizeoftlvs
);
1313 *sizeoftlvs
= table
->sizeoftlvs
;
1318 if (sizeoftlvs
== NULL
)
1319 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1322 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1325 skb
->len
= *sizeoftlvs
;
1326 memcpy(skb
->data
, *tlvs
, *sizeoftlvs
);
1327 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1333 * LANE2: 3.1.4, LE_ASSOCIATE.request
1334 * Associate the *tlvs with the *lan_dst address.
1335 * Will overwrite any previous association
1336 * Returns 1 for success, 0 for failure (out of memory)
1339 static int lane2_associate_req(struct net_device
*dev
, u8
*lan_dst
,
1340 u8
*tlvs
, u32 sizeoftlvs
)
1343 struct sk_buff
*skb
;
1344 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1346 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1347 return (0); /* not our mac address */
1349 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1351 priv
->tlvs
= kmalloc(sizeoftlvs
, GFP_KERNEL
);
1352 if (priv
->tlvs
== NULL
)
1354 priv
->sizeoftlvs
= sizeoftlvs
;
1355 memcpy(priv
->tlvs
, tlvs
, sizeoftlvs
);
1357 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1360 skb
->len
= sizeoftlvs
;
1361 memcpy(skb
->data
, tlvs
, sizeoftlvs
);
1362 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1364 printk("lec.c: lane2_associate_req() failed\n");
1366 * If the previous association has changed we must
1367 * somehow notify other LANE entities about the change
1373 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1376 static void lane2_associate_ind(struct net_device
*dev
, u8
*mac_addr
,
1377 u8
*tlvs
, u32 sizeoftlvs
)
1382 struct lec_priv
*priv
= (struct lec_priv
*)dev
->priv
;
1384 * Why have the TLVs in LE_ARP entries
1385 * since we do not use them? When you
1386 * uncomment this code, make sure the
1387 * TLVs get freed when entry is killed
1389 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1392 return; /* should not happen */
1396 entry
->tlvs
= kmalloc(sizeoftlvs
, GFP_KERNEL
);
1397 if (entry
->tlvs
== NULL
)
1400 entry
->sizeoftlvs
= sizeoftlvs
;
1401 memcpy(entry
->tlvs
, tlvs
, sizeoftlvs
);
1404 printk("lec.c: lane2_associate_ind()\n");
1405 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1406 while (i
< sizeoftlvs
)
1407 printk("%02x ", tlvs
[i
++]);
1412 /* tell MPOA about the TLVs we saw */
1413 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1414 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1421 * Here starts what used to lec_arpc.c
1423 * lec_arpc.c was added here when making
1424 * lane client modular. October 1997
1427 #include <linux/types.h>
1428 #include <linux/sched.h>
1429 #include <linux/timer.h>
1430 #include <asm/param.h>
1431 #include <asm/atomic.h>
1432 #include <linux/inetdevice.h>
1433 #include <net/route.h>
1436 #define DPRINTK(format,args...)
1438 #define DPRINTK printk
1441 #define DEBUG_ARP_TABLE 0
1443 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1445 static void lec_arp_check_expire(void *data
);
1446 static void lec_arp_expire_arp(unsigned long data
);
1452 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1455 * Initialization of arp-cache
1457 static void lec_arp_init(struct lec_priv
*priv
)
1461 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1462 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1464 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1465 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1466 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1467 spin_lock_init(&priv
->lec_arp_lock
);
1468 INIT_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
, priv
);
1469 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1472 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1475 struct atm_vcc
*vcc
= entry
->vcc
;
1476 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1477 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1479 vcc
->pop
= vpriv
->old_pop
;
1481 netif_wake_queue(dev
);
1483 vcc
->user_back
= NULL
;
1484 vcc
->push
= entry
->old_push
;
1485 vcc_release_async(vcc
, -EPIPE
);
1488 if (entry
->recv_vcc
) {
1489 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1490 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1491 entry
->recv_vcc
= NULL
;
1496 * Insert entry to lec_arp_table
1497 * LANE2: Add to the end of the list to satisfy 8.1.13
1500 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1502 struct hlist_head
*tmp
;
1504 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1505 hlist_add_head(&entry
->next
, tmp
);
1507 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1508 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1509 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1510 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1514 * Remove entry from lec_arp_table
1517 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1519 struct hlist_node
*node
;
1520 struct lec_arp_table
*entry
;
1521 int i
, remove_vcc
= 1;
1527 hlist_del(&to_remove
->next
);
1528 del_timer(&to_remove
->timer
);
1530 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1531 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1533 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1535 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1536 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1537 if (memcmp(to_remove
->atm_addr
,
1538 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1545 lec_arp_clear_vccs(to_remove
);
1547 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1549 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1550 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1551 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1552 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1557 static char *get_status_string(unsigned char st
)
1561 return "ESI_UNKNOWN";
1562 case ESI_ARP_PENDING
:
1563 return "ESI_ARP_PENDING";
1564 case ESI_VC_PENDING
:
1565 return "ESI_VC_PENDING";
1566 case ESI_FLUSH_PENDING
:
1567 return "ESI_FLUSH_PENDING";
1568 case ESI_FORWARD_DIRECT
:
1569 return "ESI_FORWARD_DIRECT";
1575 static void dump_arp_table(struct lec_priv
*priv
)
1577 struct hlist_node
*node
;
1578 struct lec_arp_table
*rulla
;
1582 printk("Dump %p:\n", priv
);
1583 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1584 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1586 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1587 offset
+= sprintf(buf
+ offset
, "Mac:");
1588 for (j
= 0; j
< ETH_ALEN
; j
++) {
1589 offset
+= sprintf(buf
+ offset
,
1591 rulla
->mac_addr
[j
] & 0xff);
1593 offset
+= sprintf(buf
+ offset
, "Atm:");
1594 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1595 offset
+= sprintf(buf
+ offset
,
1597 rulla
->atm_addr
[j
] & 0xff);
1599 offset
+= sprintf(buf
+ offset
,
1600 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1601 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1602 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1603 rulla
->recv_vcc
? rulla
->recv_vcc
->
1605 rulla
->recv_vcc
? rulla
->recv_vcc
->
1606 vci
: 0, rulla
->last_used
,
1607 rulla
->timestamp
, rulla
->no_tries
);
1609 sprintf(buf
+ offset
,
1610 "Flags:%x, Packets_flooded:%x, Status: %s ",
1611 rulla
->flags
, rulla
->packets_flooded
,
1612 get_status_string(rulla
->status
));
1613 printk("%s\n", buf
);
1617 if (!hlist_empty(&priv
->lec_no_forward
))
1618 printk("No forward\n");
1619 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1621 offset
+= sprintf(buf
+ offset
, "Mac:");
1622 for (j
= 0; j
< ETH_ALEN
; j
++) {
1623 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1624 rulla
->mac_addr
[j
] & 0xff);
1626 offset
+= sprintf(buf
+ offset
, "Atm:");
1627 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1628 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1629 rulla
->atm_addr
[j
] & 0xff);
1631 offset
+= sprintf(buf
+ offset
,
1632 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1633 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1634 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1635 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1636 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1638 rulla
->timestamp
, rulla
->no_tries
);
1639 offset
+= sprintf(buf
+ offset
,
1640 "Flags:%x, Packets_flooded:%x, Status: %s ",
1641 rulla
->flags
, rulla
->packets_flooded
,
1642 get_status_string(rulla
->status
));
1643 printk("%s\n", buf
);
1646 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1647 printk("Empty ones\n");
1648 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1650 offset
+= sprintf(buf
+ offset
, "Mac:");
1651 for (j
= 0; j
< ETH_ALEN
; j
++) {
1652 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1653 rulla
->mac_addr
[j
] & 0xff);
1655 offset
+= sprintf(buf
+ offset
, "Atm:");
1656 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1657 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1658 rulla
->atm_addr
[j
] & 0xff);
1660 offset
+= sprintf(buf
+ offset
,
1661 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1662 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1663 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1664 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1665 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1667 rulla
->timestamp
, rulla
->no_tries
);
1668 offset
+= sprintf(buf
+ offset
,
1669 "Flags:%x, Packets_flooded:%x, Status: %s ",
1670 rulla
->flags
, rulla
->packets_flooded
,
1671 get_status_string(rulla
->status
));
1675 if (!hlist_empty(&priv
->mcast_fwds
))
1676 printk("Multicast Forward VCCs\n");
1677 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1679 offset
+= sprintf(buf
+ offset
, "Mac:");
1680 for (j
= 0; j
< ETH_ALEN
; j
++) {
1681 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1682 rulla
->mac_addr
[j
] & 0xff);
1684 offset
+= sprintf(buf
+ offset
, "Atm:");
1685 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1686 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1687 rulla
->atm_addr
[j
] & 0xff);
1689 offset
+= sprintf(buf
+ offset
,
1690 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1691 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1692 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1693 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1694 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1696 rulla
->timestamp
, rulla
->no_tries
);
1697 offset
+= sprintf(buf
+ offset
,
1698 "Flags:%x, Packets_flooded:%x, Status: %s ",
1699 rulla
->flags
, rulla
->packets_flooded
,
1700 get_status_string(rulla
->status
));
1701 printk("%s\n", buf
);
1706 #define dump_arp_table(priv) do { } while (0)
1710 * Destruction of arp-cache
1712 static void lec_arp_destroy(struct lec_priv
*priv
)
1714 unsigned long flags
;
1715 struct hlist_node
*node
, *next
;
1716 struct lec_arp_table
*entry
;
1719 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1722 * Remove all entries
1725 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1726 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1727 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1728 lec_arp_remove(priv
, entry
);
1731 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1734 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1735 del_timer_sync(&entry
->timer
);
1736 lec_arp_clear_vccs(entry
);
1737 hlist_del(&entry
->next
);
1740 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1742 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1743 del_timer_sync(&entry
->timer
);
1744 lec_arp_clear_vccs(entry
);
1745 hlist_del(&entry
->next
);
1748 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1750 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1751 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1752 lec_arp_clear_vccs(entry
);
1753 hlist_del(&entry
->next
);
1756 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1757 priv
->mcast_vcc
= NULL
;
1758 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1762 * Find entry by mac_address
1764 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1765 unsigned char *mac_addr
)
1767 struct hlist_node
*node
;
1768 struct hlist_head
*head
;
1769 struct lec_arp_table
*entry
;
1771 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1772 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1773 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1775 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1776 hlist_for_each_entry(entry
, node
, head
, next
) {
1777 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1784 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1785 unsigned char *mac_addr
)
1787 struct lec_arp_table
*to_return
;
1789 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1791 printk("LEC: Arp entry kmalloc failed\n");
1794 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1795 INIT_HLIST_NODE(&to_return
->next
);
1796 init_timer(&to_return
->timer
);
1797 to_return
->timer
.function
= lec_arp_expire_arp
;
1798 to_return
->timer
.data
= (unsigned long)to_return
;
1799 to_return
->last_used
= jiffies
;
1800 to_return
->priv
= priv
;
1801 skb_queue_head_init(&to_return
->tx_wait
);
1805 /* Arp sent timer expired */
1806 static void lec_arp_expire_arp(unsigned long data
)
1808 struct lec_arp_table
*entry
;
1810 entry
= (struct lec_arp_table
*)data
;
1812 DPRINTK("lec_arp_expire_arp\n");
1813 if (entry
->status
== ESI_ARP_PENDING
) {
1814 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1815 if (entry
->is_rdesc
)
1816 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1817 entry
->mac_addr
, NULL
, NULL
);
1819 send_to_lecd(entry
->priv
, l_arp_xmt
,
1820 entry
->mac_addr
, NULL
, NULL
);
1823 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1827 /* Unknown/unused vcc expire, remove associated entry */
1828 static void lec_arp_expire_vcc(unsigned long data
)
1830 unsigned long flags
;
1831 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1832 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1834 del_timer(&to_remove
->timer
);
1836 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1838 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1839 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1841 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1842 hlist_del(&to_remove
->next
);
1843 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1845 lec_arp_clear_vccs(to_remove
);
1852 * 2. For each entry, delete entries that have aged past the age limit.
1853 * 3. For each entry, depending on the status of the entry, perform
1854 * the following maintenance.
1855 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1856 * tick_count is above the max_unknown_frame_time, clear
1857 * the tick_count to zero and clear the packets_flooded counter
1858 * to zero. This supports the packet rate limit per address
1859 * while flooding unknowns.
1860 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1861 * than or equal to the path_switching_delay, change the status
1862 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1863 * regardless of the progress of the flush protocol.
1865 static void lec_arp_check_expire(void *data
)
1867 unsigned long flags
;
1868 struct lec_priv
*priv
= data
;
1869 struct hlist_node
*node
, *next
;
1870 struct lec_arp_table
*entry
;
1872 unsigned long time_to_check
;
1875 DPRINTK("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 DPRINTK("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 DPRINTK("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
;
1918 skb_dequeue(&entry
->tx_wait
)) !=
1920 lec_send(entry
->vcc
, skb
,
1922 entry
->last_used
= jiffies
;
1923 entry
->status
= ESI_FORWARD_DIRECT
;
1928 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1930 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1934 * Try to find vcc where mac_address is attached.
1937 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1938 unsigned char *mac_to_find
, int is_rdesc
,
1939 struct lec_arp_table
**ret_entry
)
1941 unsigned long flags
;
1942 struct lec_arp_table
*entry
;
1943 struct atm_vcc
*found
;
1945 if (mac_to_find
[0] & 0x01) {
1946 switch (priv
->lane_version
) {
1948 return priv
->mcast_vcc
;
1950 case 2: /* LANE2 wants arp for multicast addresses */
1951 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1952 return priv
->mcast_vcc
;
1959 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1960 entry
= lec_arp_find(priv
, mac_to_find
);
1963 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1965 entry
->last_used
= jiffies
;
1971 * If the LE_ARP cache entry is still pending, reset count to 0
1972 * so another LE_ARP request can be made for this frame.
1974 if (entry
->status
== ESI_ARP_PENDING
) {
1975 entry
->no_tries
= 0;
1978 * Data direct VC not yet set up, check to see if the unknown
1979 * frame count is greater than the limit. If the limit has
1980 * not been reached, allow the caller to send packet to
1983 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1984 entry
->packets_flooded
<
1985 priv
->maximum_unknown_frame_count
) {
1986 entry
->packets_flooded
++;
1987 DPRINTK("LEC_ARP: Flooding..\n");
1988 found
= priv
->mcast_vcc
;
1992 * We got here because entry->status == ESI_FLUSH_PENDING
1993 * or BUS flood limit was reached for an entry which is
1994 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1997 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry
->status
,
2001 /* No matching entry was found */
2002 entry
= make_entry(priv
, mac_to_find
);
2003 DPRINTK("LEC_ARP: Making entry\n");
2005 found
= priv
->mcast_vcc
;
2008 lec_arp_add(priv
, entry
);
2009 /* We want arp-request(s) to be sent */
2010 entry
->packets_flooded
= 1;
2011 entry
->status
= ESI_ARP_PENDING
;
2012 entry
->no_tries
= 1;
2013 entry
->last_used
= entry
->timestamp
= jiffies
;
2014 entry
->is_rdesc
= is_rdesc
;
2015 if (entry
->is_rdesc
)
2016 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
2019 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
2020 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
2021 entry
->timer
.function
= lec_arp_expire_arp
;
2022 add_timer(&entry
->timer
);
2023 found
= priv
->mcast_vcc
;
2027 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2032 lec_addr_delete(struct lec_priv
*priv
, unsigned char *atm_addr
,
2033 unsigned long permanent
)
2035 unsigned long flags
;
2036 struct hlist_node
*node
, *next
;
2037 struct lec_arp_table
*entry
;
2040 DPRINTK("lec_addr_delete\n");
2041 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2042 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2043 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2044 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2046 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2047 lec_arp_remove(priv
, entry
);
2050 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2054 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2059 * Notifies: Response to arp_request (atm_addr != NULL)
2062 lec_arp_update(struct lec_priv
*priv
, unsigned char *mac_addr
,
2063 unsigned char *atm_addr
, unsigned long remoteflag
,
2064 unsigned int targetless_le_arp
)
2066 unsigned long flags
;
2067 struct hlist_node
*node
, *next
;
2068 struct lec_arp_table
*entry
, *tmp
;
2071 DPRINTK("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2072 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2073 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2074 mac_addr
[4], mac_addr
[5]);
2076 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2077 entry
= lec_arp_find(priv
, mac_addr
);
2078 if (entry
== NULL
&& targetless_le_arp
)
2080 * LANE2: ignore targetless LE_ARPs for which
2081 * we have no entry in the cache. 7.1.30
2083 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2084 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2085 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2086 hlist_del(&entry
->next
);
2087 del_timer(&entry
->timer
);
2088 tmp
= lec_arp_find(priv
, mac_addr
);
2090 del_timer(&tmp
->timer
);
2091 tmp
->status
= ESI_FORWARD_DIRECT
;
2092 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2093 tmp
->vcc
= entry
->vcc
;
2094 tmp
->old_push
= entry
->old_push
;
2095 tmp
->last_used
= jiffies
;
2096 del_timer(&entry
->timer
);
2100 entry
->status
= ESI_FORWARD_DIRECT
;
2101 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2102 entry
->last_used
= jiffies
;
2103 lec_arp_add(priv
, entry
);
2106 entry
->flags
|= LEC_REMOTE_FLAG
;
2108 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2109 DPRINTK("After update\n");
2110 dump_arp_table(priv
);
2116 entry
= lec_arp_find(priv
, mac_addr
);
2118 entry
= make_entry(priv
, mac_addr
);
2121 entry
->status
= ESI_UNKNOWN
;
2122 lec_arp_add(priv
, entry
);
2123 /* Temporary, changes before end of function */
2125 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2126 del_timer(&entry
->timer
);
2127 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2128 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2130 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2131 /* Vcc to this host exists */
2132 if (tmp
->status
> ESI_VC_PENDING
) {
2134 * ESI_FLUSH_PENDING,
2135 * ESI_FORWARD_DIRECT
2137 entry
->vcc
= tmp
->vcc
;
2138 entry
->old_push
= tmp
->old_push
;
2140 entry
->status
= tmp
->status
;
2146 entry
->flags
|= LEC_REMOTE_FLAG
;
2148 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2149 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2150 entry
->status
= ESI_VC_PENDING
;
2151 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2153 DPRINTK("After update2\n");
2154 dump_arp_table(priv
);
2156 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2160 * Notifies: Vcc setup ready
2163 lec_vcc_added(struct lec_priv
*priv
, struct atmlec_ioc
*ioc_data
,
2164 struct atm_vcc
*vcc
,
2165 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2167 unsigned long flags
;
2168 struct hlist_node
*node
;
2169 struct lec_arp_table
*entry
;
2170 int i
, found_entry
= 0;
2172 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2173 if (ioc_data
->receive
== 2) {
2174 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2176 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2178 entry
= lec_arp_find(priv
, bus_mac
);
2180 printk("LEC_ARP: Multicast entry not found!\n");
2183 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2184 entry
->recv_vcc
= vcc
;
2185 entry
->old_recv_push
= old_push
;
2187 entry
= make_entry(priv
, bus_mac
);
2190 del_timer(&entry
->timer
);
2191 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2192 entry
->recv_vcc
= vcc
;
2193 entry
->old_recv_push
= old_push
;
2194 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2196 } else if (ioc_data
->receive
== 1) {
2198 * Vcc which we don't want to make default vcc,
2202 ("LEC_ARP:Attaching data direct, not default: "
2203 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2204 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2205 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2206 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2207 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2208 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2209 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2210 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2211 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2212 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2213 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2214 entry
= make_entry(priv
, bus_mac
);
2217 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2218 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2219 entry
->recv_vcc
= vcc
;
2220 entry
->old_recv_push
= old_push
;
2221 entry
->status
= ESI_UNKNOWN
;
2222 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2223 entry
->timer
.function
= lec_arp_expire_vcc
;
2224 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2225 add_timer(&entry
->timer
);
2226 dump_arp_table(priv
);
2230 ("LEC_ARP:Attaching data direct, default: "
2231 "%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",
2232 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2233 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2234 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2235 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2236 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2237 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2238 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2239 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2240 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2241 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2242 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2243 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2245 (ioc_data
->atm_addr
, entry
->atm_addr
,
2246 ATM_ESA_LEN
) == 0) {
2247 DPRINTK("LEC_ARP: Attaching data direct\n");
2248 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2249 entry
->vcc
? entry
->vcc
->vci
: 0,
2250 entry
->recv_vcc
? entry
->recv_vcc
->
2253 del_timer(&entry
->timer
);
2255 entry
->old_push
= old_push
;
2256 if (entry
->status
== ESI_VC_PENDING
) {
2257 if (priv
->maximum_unknown_frame_count
2262 entry
->timestamp
= jiffies
;
2266 send_to_lecd(priv
, l_flush_xmt
,
2274 * They were forming a connection
2275 * to us, and we to them. Our
2276 * ATM address is numerically lower
2277 * than theirs, so we make connection
2278 * we formed into default VCC (8.1.11).
2279 * Connection they made gets torn
2280 * down. This might confuse some
2281 * clients. Can be changed if
2282 * someone reports trouble...
2290 DPRINTK("After vcc was added\n");
2291 dump_arp_table(priv
);
2295 * Not found, snatch address from first data packet that arrives
2298 entry
= make_entry(priv
, bus_mac
);
2302 entry
->old_push
= old_push
;
2303 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2304 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2305 entry
->status
= ESI_UNKNOWN
;
2306 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2307 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2308 entry
->timer
.function
= lec_arp_expire_vcc
;
2309 add_timer(&entry
->timer
);
2310 DPRINTK("After vcc was added\n");
2311 dump_arp_table(priv
);
2313 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2316 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2318 unsigned long flags
;
2319 struct hlist_node
*node
;
2320 struct lec_arp_table
*entry
;
2323 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id
);
2324 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2325 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2326 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2327 if (entry
->flush_tran_id
== tran_id
2328 && entry
->status
== ESI_FLUSH_PENDING
) {
2329 struct sk_buff
*skb
;
2332 skb_dequeue(&entry
->tx_wait
)) != NULL
)
2333 lec_send(entry
->vcc
, skb
, entry
->priv
);
2334 entry
->status
= ESI_FORWARD_DIRECT
;
2335 DPRINTK("LEC_ARP: Flushed\n");
2339 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2340 dump_arp_table(priv
);
2344 lec_set_flush_tran_id(struct lec_priv
*priv
,
2345 unsigned char *atm_addr
, unsigned long tran_id
)
2347 unsigned long flags
;
2348 struct hlist_node
*node
;
2349 struct lec_arp_table
*entry
;
2352 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2353 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2354 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2355 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2356 entry
->flush_tran_id
= tran_id
;
2357 DPRINTK("Set flush transaction id to %lx for %p\n",
2361 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2364 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2366 unsigned long flags
;
2367 unsigned char mac_addr
[] = {
2368 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2370 struct lec_arp_table
*to_add
;
2371 struct lec_vcc_priv
*vpriv
;
2374 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2377 vpriv
->old_pop
= vcc
->pop
;
2378 vcc
->user_back
= vpriv
;
2380 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2381 to_add
= make_entry(priv
, mac_addr
);
2383 vcc
->pop
= vpriv
->old_pop
;
2388 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2389 to_add
->status
= ESI_FORWARD_DIRECT
;
2390 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2392 to_add
->old_push
= vcc
->push
;
2393 vcc
->push
= lec_push
;
2394 priv
->mcast_vcc
= vcc
;
2395 lec_arp_add(priv
, to_add
);
2397 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2401 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2403 unsigned long flags
;
2404 struct hlist_node
*node
, *next
;
2405 struct lec_arp_table
*entry
;
2408 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2409 dump_arp_table(priv
);
2411 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2413 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2414 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2415 if (vcc
== entry
->vcc
) {
2416 lec_arp_remove(priv
, entry
);
2418 if (priv
->mcast_vcc
== vcc
) {
2419 priv
->mcast_vcc
= NULL
;
2425 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2426 if (entry
->vcc
== vcc
) {
2427 lec_arp_clear_vccs(entry
);
2428 del_timer(&entry
->timer
);
2429 hlist_del(&entry
->next
);
2434 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2435 if (entry
->recv_vcc
== vcc
) {
2436 lec_arp_clear_vccs(entry
);
2437 del_timer(&entry
->timer
);
2438 hlist_del(&entry
->next
);
2443 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2444 if (entry
->recv_vcc
== vcc
) {
2445 lec_arp_clear_vccs(entry
);
2446 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2447 hlist_del(&entry
->next
);
2452 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2453 dump_arp_table(priv
);
2457 lec_arp_check_empties(struct lec_priv
*priv
,
2458 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2460 unsigned long flags
;
2461 struct hlist_node
*node
, *next
;
2462 struct lec_arp_table
*entry
, *tmp
;
2463 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2466 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2469 src
= tr_hdr
->h_source
;
2472 src
= hdr
->h_source
;
2474 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2475 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2476 if (vcc
== entry
->vcc
) {
2477 del_timer(&entry
->timer
);
2478 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2479 entry
->status
= ESI_FORWARD_DIRECT
;
2480 entry
->last_used
= jiffies
;
2481 /* We might have got an entry */
2482 if ((tmp
= lec_arp_find(priv
, src
))) {
2483 lec_arp_remove(priv
, tmp
);
2486 hlist_del(&entry
->next
);
2487 lec_arp_add(priv
, entry
);
2491 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2493 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2496 MODULE_LICENSE("GPL");