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 void lec_init(struct net_device
*dev
);
66 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
67 const unsigned char *mac_addr
);
68 static int lec_arp_remove(struct lec_priv
*priv
,
69 struct lec_arp_table
*to_remove
);
71 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_address
,
72 const u8
*tlvs
, u32 sizeoftlvs
);
73 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
74 u8
**tlvs
, u32
*sizeoftlvs
);
75 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
76 const u8
*tlvs
, u32 sizeoftlvs
);
78 static int lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
79 unsigned long permanent
);
80 static void lec_arp_check_empties(struct lec_priv
*priv
,
81 struct atm_vcc
*vcc
, struct sk_buff
*skb
);
82 static void lec_arp_destroy(struct lec_priv
*priv
);
83 static void lec_arp_init(struct lec_priv
*priv
);
84 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
85 const unsigned char *mac_to_find
,
87 struct lec_arp_table
**ret_entry
);
88 static void lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
89 const unsigned char *atm_addr
, unsigned long remoteflag
,
90 unsigned int targetless_le_arp
);
91 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
92 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
93 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
94 const unsigned char *atm_addr
,
95 unsigned long tran_id
);
96 static void lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
98 void (*old_push
) (struct atm_vcc
*vcc
,
99 struct sk_buff
*skb
));
100 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
102 /* must be done under lec_arp_lock */
103 static inline void lec_arp_hold(struct lec_arp_table
*entry
)
105 atomic_inc(&entry
->usage
);
108 static inline void lec_arp_put(struct lec_arp_table
*entry
)
110 if (atomic_dec_and_test(&entry
->usage
))
115 static struct lane2_ops lane2_ops
= {
116 lane2_resolve
, /* resolve, spec 3.1.3 */
117 lane2_associate_req
, /* associate_req, spec 3.1.4 */
118 NULL
/* associate indicator, spec 3.1.5 */
121 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
123 /* Device structures */
124 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
126 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
127 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
131 struct lec_priv
*priv
;
134 * Check if this is a BPDU. If so, ask zeppelin to send
135 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
136 * as the Config BPDU has
138 eth
= (struct ethhdr
*)skb
->data
;
139 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
140 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
142 struct sk_buff
*skb2
;
143 struct atmlec_msg
*mesg
;
145 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
148 skb2
->len
= sizeof(struct atmlec_msg
);
149 mesg
= (struct atmlec_msg
*)skb2
->data
;
150 mesg
->type
= l_topology_change
;
152 mesg
->content
.normal
.flag
= *buff
& 0x01; /* 0x01 is topology change */
154 priv
= netdev_priv(dev
);
155 atm_force_charge(priv
->lecd
, skb2
->truesize
);
156 sk
= sk_atm(priv
->lecd
);
157 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
158 sk
->sk_data_ready(sk
, skb2
->len
);
163 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
166 * Modelled after tr_type_trans
167 * All multicast and ARE or STE frames go to BUS.
168 * Non source routed frames go by destination address.
169 * Last hop source routed frames go by destination address.
170 * Not last hop source routed frames go by _next_ route descriptor.
171 * Returns pointer to destination MAC address or fills in rdesc
175 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
178 unsigned int riflen
, num_rdsc
;
180 trh
= (struct trh_hdr
*)packet
;
181 if (trh
->daddr
[0] & (uint8_t) 0x80)
182 return bus_mac
; /* multicast */
184 if (trh
->saddr
[0] & TR_RII
) {
185 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
186 if ((ntohs(trh
->rcf
) >> 13) != 0)
187 return bus_mac
; /* ARE or STE */
189 return trh
->daddr
; /* not source routed */
192 return trh
->daddr
; /* last hop, source routed */
194 /* riflen is 6 or more, packet has more than one route descriptor */
195 num_rdsc
= (riflen
/ 2) - 1;
196 memset(rdesc
, 0, ETH_ALEN
);
197 /* offset 4 comes from LAN destination field in LE control frames */
198 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
199 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(__be16
));
201 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(__be16
));
202 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
207 #endif /* CONFIG_TR */
210 * Open/initialize the netdevice. This is called (in the current kernel)
211 * sometime after booting when the 'ifconfig' program is run.
213 * This routine should set everything up anew at each open, even
214 * registers that "should" only need to be set once at boot, so that
215 * there is non-reboot way to recover if something goes wrong.
218 static int lec_open(struct net_device
*dev
)
220 netif_start_queue(dev
);
221 memset(&dev
->stats
, 0, sizeof(struct net_device_stats
));
227 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
229 struct net_device
*dev
= skb
->dev
;
231 ATM_SKB(skb
)->vcc
= vcc
;
232 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
234 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
235 if (vcc
->send(vcc
, skb
) < 0) {
236 dev
->stats
.tx_dropped
++;
240 dev
->stats
.tx_packets
++;
241 dev
->stats
.tx_bytes
+= skb
->len
;
244 static void lec_tx_timeout(struct net_device
*dev
)
246 printk(KERN_INFO
"%s: tx timeout\n", dev
->name
);
247 dev
->trans_start
= jiffies
;
248 netif_wake_queue(dev
);
251 static int lec_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
253 struct sk_buff
*skb2
;
254 struct lec_priv
*priv
= netdev_priv(dev
);
255 struct lecdatahdr_8023
*lec_h
;
257 struct lec_arp_table
*entry
;
261 unsigned char rdesc
[ETH_ALEN
]; /* Token Ring route descriptor */
267 #endif /* DUMP_PACKETS >0 */
269 pr_debug("lec_start_xmit called\n");
271 printk("%s:No lecd attached\n", dev
->name
);
272 dev
->stats
.tx_errors
++;
273 netif_stop_queue(dev
);
277 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
278 (long)skb
->head
, (long)skb
->data
, (long)skb_tail_pointer(skb
),
279 (long)skb_end_pointer(skb
));
280 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
281 if (memcmp(skb
->data
, bridge_ula_lec
, sizeof(bridge_ula_lec
)) == 0)
282 lec_handle_bridge(skb
, dev
);
285 /* Make sure we have room for lec_id */
286 if (skb_headroom(skb
) < 2) {
288 pr_debug("lec_start_xmit: reallocating skb\n");
289 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
297 /* Put le header to place, works for TokenRing too */
298 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
299 lec_h
->le_header
= htons(priv
->lecid
);
303 * Ugly. Use this to realign Token Ring packets for
304 * e.g. PCA-200E driver.
306 if (priv
->is_trdev
) {
307 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
316 printk("%s: send datalen:%ld lecid:%4.4x\n", dev
->name
,
317 skb
->len
, priv
->lecid
);
318 #if DUMP_PACKETS >= 2
319 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
320 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
322 #elif DUMP_PACKETS >= 1
323 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
324 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
326 #endif /* DUMP_PACKETS >= 1 */
330 printk("%s...\n", buf
);
331 #endif /* DUMP_PACKETS > 0 */
333 /* Minimum ethernet-frame size */
336 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
339 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
340 if (skb
->len
< min_frame_size
) {
341 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
342 skb2
= skb_copy_expand(skb
, 0,
343 min_frame_size
- skb
->truesize
,
347 dev
->stats
.tx_dropped
++;
352 skb_put(skb
, min_frame_size
- skb
->len
);
355 /* Send to right vcc */
359 if (priv
->is_trdev
) {
360 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
368 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
369 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev
->name
,
370 vcc
, vcc
? vcc
->flags
: 0, entry
);
371 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
372 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
373 pr_debug("%s:lec_start_xmit: queuing packet, ",
375 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
376 skb_queue_tail(&entry
->tx_wait
, skb
);
379 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
381 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
382 dev
->stats
.tx_dropped
++;
388 printk("%s:sending to vpi:%d vci:%d\n", dev
->name
, vcc
->vpi
, vcc
->vci
);
389 #endif /* DUMP_PACKETS > 0 */
391 while (entry
&& (skb2
= skb_dequeue(&entry
->tx_wait
))) {
392 pr_debug("lec.c: emptying tx queue, ");
393 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
399 if (!atm_may_send(vcc
, 0)) {
400 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
403 netif_stop_queue(dev
);
406 * vcc->pop() might have occurred in between, making
407 * the vcc usuable again. Since xmit is serialized,
408 * this is the only situation we have to re-test.
411 if (atm_may_send(vcc
, 0))
412 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
);
429 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
432 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
433 struct lec_priv
*priv
= netdev_priv(dev
);
434 struct atmlec_msg
*mesg
;
435 struct lec_arp_table
*entry
;
437 char *tmp
; /* FIXME */
439 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
440 mesg
= (struct atmlec_msg
*)skb
->data
;
442 tmp
+= sizeof(struct atmlec_msg
);
443 pr_debug("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
444 switch (mesg
->type
) {
446 for (i
= 0; i
< 6; i
++) {
447 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
451 for (i
= 0; i
< 6; i
++) {
452 dev
->dev_addr
[i
] = 0;
456 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
457 mesg
->content
.normal
.flag
);
459 case l_topology_change
:
460 priv
->topology_change
= mesg
->content
.normal
.flag
;
462 case l_flush_complete
:
463 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
465 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
466 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
467 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
468 lec_arp_remove(priv
, entry
);
469 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
471 if (mesg
->content
.normal
.no_source_le_narp
)
475 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
476 mesg
->content
.normal
.atm_addr
,
477 mesg
->content
.normal
.flag
,
478 mesg
->content
.normal
.targetless_le_arp
);
479 pr_debug("lec: in l_arp_update\n");
480 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
481 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
483 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
484 tmp
, mesg
->sizeoftlvs
);
488 priv
->maximum_unknown_frame_count
=
489 mesg
->content
.config
.maximum_unknown_frame_count
;
490 priv
->max_unknown_frame_time
=
491 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
492 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
493 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
494 priv
->forward_delay_time
=
495 (mesg
->content
.config
.forward_delay_time
* HZ
);
496 priv
->arp_response_time
=
497 (mesg
->content
.config
.arp_response_time
* HZ
);
498 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
499 priv
->path_switching_delay
=
500 (mesg
->content
.config
.path_switching_delay
* HZ
);
501 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
502 priv
->lane2_ops
= NULL
;
503 if (priv
->lane_version
> 1)
504 priv
->lane2_ops
= &lane2_ops
;
505 if (dev_set_mtu(dev
, mesg
->content
.config
.mtu
))
506 printk("%s: change_mtu to %d failed\n", dev
->name
,
507 mesg
->content
.config
.mtu
);
508 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
510 case l_flush_tran_id
:
511 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
512 mesg
->content
.normal
.flag
);
516 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
518 case l_should_bridge
:
519 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
521 struct net_bridge_fdb_entry
*f
;
523 pr_debug("%s: bridge zeppelin asks about %pM\n",
524 dev
->name
, mesg
->content
.proxy
.mac_addr
);
526 if (br_fdb_get_hook
== NULL
|| dev
->br_port
== NULL
)
529 f
= br_fdb_get_hook(dev
->br_port
->br
,
530 mesg
->content
.proxy
.mac_addr
);
531 if (f
!= NULL
&& f
->dst
->dev
!= dev
532 && f
->dst
->state
== BR_STATE_FORWARDING
) {
533 /* hit from bridge table, send LE_ARP_RESPONSE */
534 struct sk_buff
*skb2
;
538 ("%s: entry found, responding to zeppelin\n",
541 alloc_skb(sizeof(struct atmlec_msg
),
547 skb2
->len
= sizeof(struct atmlec_msg
);
548 skb_copy_to_linear_data(skb2
, mesg
,
550 atm_force_charge(priv
->lecd
, skb2
->truesize
);
551 sk
= sk_atm(priv
->lecd
);
552 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
553 sk
->sk_data_ready(sk
, skb2
->len
);
558 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
561 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
569 static void lec_atm_close(struct atm_vcc
*vcc
)
572 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
573 struct lec_priv
*priv
= netdev_priv(dev
);
576 /* Do something needful? */
578 netif_stop_queue(dev
);
579 lec_arp_destroy(priv
);
581 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
582 printk("%s lec_atm_close: closing with messages pending\n",
584 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
585 atm_return(vcc
, skb
->truesize
);
589 printk("%s: Shut down!\n", dev
->name
);
590 module_put(THIS_MODULE
);
593 static struct atmdev_ops lecdev_ops
= {
594 .close
= lec_atm_close
,
598 static struct atm_dev lecatm_dev
= {
601 .number
= 999, /* dummy device number */
602 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
606 * LANE2: new argument struct sk_buff *data contains
607 * the LE_ARP based TLVs introduced in the LANE2 spec
610 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
611 const unsigned char *mac_addr
, const unsigned char *atm_addr
,
612 struct sk_buff
*data
)
616 struct atmlec_msg
*mesg
;
618 if (!priv
|| !priv
->lecd
) {
621 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
624 skb
->len
= sizeof(struct atmlec_msg
);
625 mesg
= (struct atmlec_msg
*)skb
->data
;
626 memset(mesg
, 0, sizeof(struct atmlec_msg
));
629 mesg
->sizeoftlvs
= data
->len
;
631 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
633 mesg
->content
.normal
.targetless_le_arp
= 1;
635 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
637 atm_force_charge(priv
->lecd
, skb
->truesize
);
638 sk
= sk_atm(priv
->lecd
);
639 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
640 sk
->sk_data_ready(sk
, skb
->len
);
643 pr_debug("lec: about to send %d bytes of data\n", data
->len
);
644 atm_force_charge(priv
->lecd
, data
->truesize
);
645 skb_queue_tail(&sk
->sk_receive_queue
, data
);
646 sk
->sk_data_ready(sk
, skb
->len
);
652 /* shamelessly stolen from drivers/net/net_init.c */
653 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
655 if ((new_mtu
< 68) || (new_mtu
> 18190))
661 static void lec_set_multicast_list(struct net_device
*dev
)
664 * by default, all multicast frames arrive over the bus.
665 * eventually support selective multicast service
670 static const struct net_device_ops lec_netdev_ops
= {
671 .ndo_open
= lec_open
,
672 .ndo_stop
= lec_close
,
673 .ndo_start_xmit
= lec_start_xmit
,
674 .ndo_change_mtu
= lec_change_mtu
,
675 .ndo_tx_timeout
= lec_tx_timeout
,
676 .ndo_set_multicast_list
= lec_set_multicast_list
,
680 static void lec_init(struct net_device
*dev
)
682 dev
->netdev_ops
= &lec_netdev_ops
;
683 printk("%s: Initialized!\n", dev
->name
);
686 static const unsigned char lec_ctrl_magic
[] = {
693 #define LEC_DATA_DIRECT_8023 2
694 #define LEC_DATA_DIRECT_8025 3
696 static int lec_is_data_direct(struct atm_vcc
*vcc
)
698 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
699 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
702 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
705 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
706 struct lec_priv
*priv
= netdev_priv(dev
);
712 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
716 pr_debug("%s: null skb\n", dev
->name
);
717 lec_vcc_close(priv
, vcc
);
721 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
722 skb
->len
, priv
->lecid
);
723 #if DUMP_PACKETS >= 2
724 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
725 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
727 #elif DUMP_PACKETS >= 1
728 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
729 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
731 #endif /* DUMP_PACKETS >= 1 */
735 printk("%s...\n", buf
);
736 #endif /* DUMP_PACKETS > 0 */
737 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
738 struct sock
*sk
= sk_atm(vcc
);
740 pr_debug("%s: To daemon\n", dev
->name
);
741 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
742 sk
->sk_data_ready(sk
, skb
->len
);
743 } else { /* Data frame, queue to protocol handlers */
744 struct lec_arp_table
*entry
;
745 unsigned char *src
, *dst
;
747 atm_return(vcc
, skb
->truesize
);
748 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
749 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
751 * Probably looping back, or if lecd is missing,
754 pr_debug("Ignoring frame...\n");
760 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
763 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
766 * If this is a Data Direct VCC, and the VCC does not match
767 * the LE_ARP cache entry, delete the LE_ARP cache entry.
769 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
770 if (lec_is_data_direct(vcc
)) {
774 ((struct lecdatahdr_8025
*)skb
->data
)->
779 ((struct lecdatahdr_8023
*)skb
->data
)->
781 entry
= lec_arp_find(priv
, src
);
782 if (entry
&& entry
->vcc
!= vcc
) {
783 lec_arp_remove(priv
, entry
);
787 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
789 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
790 !priv
->is_proxy
&& /* Proxy wants all the packets */
791 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
795 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
796 lec_arp_check_empties(priv
, vcc
, skb
);
798 skb_pull(skb
, 2); /* skip lec_id */
801 skb
->protocol
= tr_type_trans(skb
, dev
);
804 skb
->protocol
= eth_type_trans(skb
, dev
);
805 dev
->stats
.rx_packets
++;
806 dev
->stats
.rx_bytes
+= skb
->len
;
807 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
812 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
814 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
815 struct net_device
*dev
= skb
->dev
;
818 printk("lec_pop(): vpriv = NULL!?!?!?\n");
822 vpriv
->old_pop(vcc
, skb
);
824 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
826 if (netif_running(dev
) && netif_queue_stopped(dev
))
827 netif_wake_queue(dev
);
831 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
833 struct lec_vcc_priv
*vpriv
;
835 struct atmlec_ioc ioc_data
;
837 /* Lecd must be up in this case */
838 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
839 if (bytes_left
!= 0) {
841 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
844 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
845 !dev_lec
[ioc_data
.dev_num
])
847 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
850 vpriv
->old_pop
= vcc
->pop
;
851 vcc
->user_back
= vpriv
;
853 lec_vcc_added(netdev_priv(dev_lec
[ioc_data
.dev_num
]),
854 &ioc_data
, vcc
, vcc
->push
);
855 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
856 vcc
->push
= lec_push
;
860 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
862 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
864 vcc
->proto_data
= dev_lec
[arg
];
865 return lec_mcast_make((struct lec_priv
*)netdev_priv(dev_lec
[arg
]),
869 /* Initialize device. */
870 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
873 struct lec_priv
*priv
;
880 if (arg
>= MAX_LEC_ITF
)
882 #else /* Reserve the top NUM_TR_DEVS for TR */
883 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
890 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
893 size
= sizeof(struct lec_priv
);
896 dev_lec
[i
] = alloc_trdev(size
);
899 dev_lec
[i
] = alloc_etherdev(size
);
902 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
903 if (register_netdev(dev_lec
[i
])) {
904 free_netdev(dev_lec
[i
]);
908 priv
= netdev_priv(dev_lec
[i
]);
909 priv
->is_trdev
= is_trdev
;
910 lec_init(dev_lec
[i
]);
912 priv
= netdev_priv(dev_lec
[i
]);
917 priv
->itfnum
= i
; /* LANE2 addition */
919 vcc
->dev
= &lecatm_dev
;
920 vcc_insert_socket(sk_atm(vcc
));
922 vcc
->proto_data
= dev_lec
[i
];
923 set_bit(ATM_VF_META
, &vcc
->flags
);
924 set_bit(ATM_VF_READY
, &vcc
->flags
);
926 /* Set default values to these variables */
927 priv
->maximum_unknown_frame_count
= 1;
928 priv
->max_unknown_frame_time
= (1 * HZ
);
929 priv
->vcc_timeout_period
= (1200 * HZ
);
930 priv
->max_retry_count
= 1;
931 priv
->aging_time
= (300 * HZ
);
932 priv
->forward_delay_time
= (15 * HZ
);
933 priv
->topology_change
= 0;
934 priv
->arp_response_time
= (1 * HZ
);
935 priv
->flush_timeout
= (4 * HZ
);
936 priv
->path_switching_delay
= (6 * HZ
);
938 if (dev_lec
[i
]->flags
& IFF_UP
) {
939 netif_start_queue(dev_lec
[i
]);
941 __module_get(THIS_MODULE
);
945 #ifdef CONFIG_PROC_FS
946 static char *lec_arp_get_status_string(unsigned char status
)
948 static char *lec_arp_status_string
[] = {
953 "ESI_FLUSH_PENDING ",
957 if (status
> ESI_FORWARD_DIRECT
)
958 status
= 3; /* ESI_UNDEFINED */
959 return lec_arp_status_string
[status
];
962 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
966 for (i
= 0; i
< ETH_ALEN
; i
++)
967 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
968 seq_printf(seq
, " ");
969 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
970 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
971 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
972 entry
->flags
& 0xffff);
974 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
976 seq_printf(seq
, " ");
977 if (entry
->recv_vcc
) {
978 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
979 entry
->recv_vcc
->vci
);
986 struct lec_priv
*locked
;
987 struct hlist_node
*node
;
988 struct net_device
*dev
;
994 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
997 struct hlist_node
*e
= state
->node
;
998 struct lec_arp_table
*tmp
;
1002 if (e
== SEQ_START_TOKEN
) {
1007 hlist_for_each_entry_from(tmp
, e
, next
) {
1013 return (*l
< 0) ? state
: NULL
;
1016 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1017 struct lec_priv
*priv
)
1022 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1023 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1027 state
->arp_table
= p
;
1031 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1032 struct lec_priv
*priv
)
1034 struct hlist_head
*lec_misc_tables
[] = {
1035 &priv
->lec_arp_empty_ones
,
1036 &priv
->lec_no_forward
,
1042 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1043 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1047 state
->misc_table
= q
;
1051 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1052 struct lec_priv
*priv
)
1054 if (!state
->locked
) {
1055 state
->locked
= priv
;
1056 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1058 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1059 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1060 state
->locked
= NULL
;
1061 /* Partial state reset for the next time we get called */
1062 state
->arp_table
= state
->misc_table
= 0;
1064 return state
->locked
;
1067 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1069 struct net_device
*dev
;
1072 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1073 v
= (dev
&& netdev_priv(dev
)) ?
1074 lec_priv_walk(state
, l
, netdev_priv(dev
)) : NULL
;
1077 /* Partial state reset for the next time we get called */
1084 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1088 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1089 v
= lec_itf_walk(state
, &l
);
1096 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1098 struct lec_state
*state
= seq
->private;
1102 state
->locked
= NULL
;
1103 state
->arp_table
= 0;
1104 state
->misc_table
= 0;
1105 state
->node
= SEQ_START_TOKEN
;
1107 return *pos
? lec_get_idx(state
, *pos
) : SEQ_START_TOKEN
;
1110 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1112 struct lec_state
*state
= seq
->private;
1115 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1117 dev_put(state
->dev
);
1121 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1123 struct lec_state
*state
= seq
->private;
1125 v
= lec_get_idx(state
, 1);
1126 *pos
+= !!PTR_ERR(v
);
1130 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1132 static char lec_banner
[] = "Itf MAC ATM destination"
1134 "VPI/VCI Recv VPI/VCI\n";
1136 if (v
== SEQ_START_TOKEN
)
1137 seq_puts(seq
, lec_banner
);
1139 struct lec_state
*state
= seq
->private;
1140 struct net_device
*dev
= state
->dev
;
1141 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1143 seq_printf(seq
, "%s ", dev
->name
);
1144 lec_info(seq
, entry
);
1149 static const struct seq_operations lec_seq_ops
= {
1150 .start
= lec_seq_start
,
1151 .next
= lec_seq_next
,
1152 .stop
= lec_seq_stop
,
1153 .show
= lec_seq_show
,
1156 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1158 return seq_open_private(file
, &lec_seq_ops
, sizeof(struct lec_state
));
1161 static const struct file_operations lec_seq_fops
= {
1162 .owner
= THIS_MODULE
,
1163 .open
= lec_seq_open
,
1165 .llseek
= seq_lseek
,
1166 .release
= seq_release_private
,
1170 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1172 struct atm_vcc
*vcc
= ATM_SD(sock
);
1179 if (!capable(CAP_NET_ADMIN
))
1183 return -ENOIOCTLCMD
;
1188 err
= lecd_attach(vcc
, (int)arg
);
1190 sock
->state
= SS_CONNECTED
;
1193 err
= lec_mcast_attach(vcc
, (int)arg
);
1196 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1203 static struct atm_ioctl lane_ioctl_ops
= {
1204 .owner
= THIS_MODULE
,
1205 .ioctl
= lane_ioctl
,
1208 static int __init
lane_module_init(void)
1210 #ifdef CONFIG_PROC_FS
1211 struct proc_dir_entry
*p
;
1213 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1215 printk(KERN_ERR
"Unable to initialize /proc/net/atm/lec\n");
1220 register_atm_ioctl(&lane_ioctl_ops
);
1221 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1225 static void __exit
lane_module_cleanup(void)
1228 struct lec_priv
*priv
;
1230 remove_proc_entry("lec", atm_proc_root
);
1232 deregister_atm_ioctl(&lane_ioctl_ops
);
1234 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1235 if (dev_lec
[i
] != NULL
) {
1236 priv
= netdev_priv(dev_lec
[i
]);
1237 unregister_netdev(dev_lec
[i
]);
1238 free_netdev(dev_lec
[i
]);
1246 module_init(lane_module_init
);
1247 module_exit(lane_module_cleanup
);
1250 * LANE2: 3.1.3, LE_RESOLVE.request
1251 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1252 * If sizeoftlvs == NULL the default TLVs associated with with this
1254 * If dst_mac == NULL, targetless LE_ARP will be sent
1256 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
1257 u8
**tlvs
, u32
*sizeoftlvs
)
1259 unsigned long flags
;
1260 struct lec_priv
*priv
= netdev_priv(dev
);
1261 struct lec_arp_table
*table
;
1262 struct sk_buff
*skb
;
1266 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1267 table
= lec_arp_find(priv
, dst_mac
);
1268 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1272 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1276 *sizeoftlvs
= table
->sizeoftlvs
;
1281 if (sizeoftlvs
== NULL
)
1282 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1285 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1288 skb
->len
= *sizeoftlvs
;
1289 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1290 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1296 * LANE2: 3.1.4, LE_ASSOCIATE.request
1297 * Associate the *tlvs with the *lan_dst address.
1298 * Will overwrite any previous association
1299 * Returns 1 for success, 0 for failure (out of memory)
1302 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
1303 const u8
*tlvs
, u32 sizeoftlvs
)
1306 struct sk_buff
*skb
;
1307 struct lec_priv
*priv
= netdev_priv(dev
);
1309 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1310 return (0); /* not our mac address */
1312 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1314 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1315 if (priv
->tlvs
== NULL
)
1317 priv
->sizeoftlvs
= sizeoftlvs
;
1319 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1322 skb
->len
= sizeoftlvs
;
1323 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1324 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1326 printk("lec.c: lane2_associate_req() failed\n");
1328 * If the previous association has changed we must
1329 * somehow notify other LANE entities about the change
1335 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1338 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_addr
,
1339 const u8
*tlvs
, u32 sizeoftlvs
)
1344 struct lec_priv
*priv
= netdev_priv(dev
);
1346 * Why have the TLVs in LE_ARP entries
1347 * since we do not use them? When you
1348 * uncomment this code, make sure the
1349 * TLVs get freed when entry is killed
1351 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1354 return; /* should not happen */
1358 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1359 if (entry
->tlvs
== NULL
)
1361 entry
->sizeoftlvs
= sizeoftlvs
;
1364 printk("lec.c: lane2_associate_ind()\n");
1365 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1366 while (i
< sizeoftlvs
)
1367 printk("%02x ", tlvs
[i
++]);
1372 /* tell MPOA about the TLVs we saw */
1373 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1374 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1381 * Here starts what used to lec_arpc.c
1383 * lec_arpc.c was added here when making
1384 * lane client modular. October 1997
1387 #include <linux/types.h>
1388 #include <linux/timer.h>
1389 #include <asm/param.h>
1390 #include <asm/atomic.h>
1391 #include <linux/inetdevice.h>
1392 #include <net/route.h>
1395 #define pr_debug(format,args...)
1397 #define pr_debug printk
1400 #define DEBUG_ARP_TABLE 0
1402 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1404 static void lec_arp_check_expire(struct work_struct
*work
);
1405 static void lec_arp_expire_arp(unsigned long data
);
1411 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1414 * Initialization of arp-cache
1416 static void lec_arp_init(struct lec_priv
*priv
)
1420 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1421 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1423 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1424 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1425 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1426 spin_lock_init(&priv
->lec_arp_lock
);
1427 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1428 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1431 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1434 struct atm_vcc
*vcc
= entry
->vcc
;
1435 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1436 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1438 vcc
->pop
= vpriv
->old_pop
;
1440 netif_wake_queue(dev
);
1442 vcc
->user_back
= NULL
;
1443 vcc
->push
= entry
->old_push
;
1444 vcc_release_async(vcc
, -EPIPE
);
1447 if (entry
->recv_vcc
) {
1448 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1449 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1450 entry
->recv_vcc
= NULL
;
1455 * Insert entry to lec_arp_table
1456 * LANE2: Add to the end of the list to satisfy 8.1.13
1459 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1461 struct hlist_head
*tmp
;
1463 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1464 hlist_add_head(&entry
->next
, tmp
);
1466 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1467 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1468 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1469 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1473 * Remove entry from lec_arp_table
1476 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1478 struct hlist_node
*node
;
1479 struct lec_arp_table
*entry
;
1480 int i
, remove_vcc
= 1;
1486 hlist_del(&to_remove
->next
);
1487 del_timer(&to_remove
->timer
);
1489 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1490 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1492 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1494 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1495 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1496 if (memcmp(to_remove
->atm_addr
,
1497 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1504 lec_arp_clear_vccs(to_remove
);
1506 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1508 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1509 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1510 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1511 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1516 static char *get_status_string(unsigned char st
)
1520 return "ESI_UNKNOWN";
1521 case ESI_ARP_PENDING
:
1522 return "ESI_ARP_PENDING";
1523 case ESI_VC_PENDING
:
1524 return "ESI_VC_PENDING";
1525 case ESI_FLUSH_PENDING
:
1526 return "ESI_FLUSH_PENDING";
1527 case ESI_FORWARD_DIRECT
:
1528 return "ESI_FORWARD_DIRECT";
1534 static void dump_arp_table(struct lec_priv
*priv
)
1536 struct hlist_node
*node
;
1537 struct lec_arp_table
*rulla
;
1541 printk("Dump %p:\n", priv
);
1542 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1543 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1545 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1546 offset
+= sprintf(buf
+ offset
, "Mac:");
1547 for (j
= 0; j
< ETH_ALEN
; j
++) {
1548 offset
+= sprintf(buf
+ offset
,
1550 rulla
->mac_addr
[j
] & 0xff);
1552 offset
+= sprintf(buf
+ offset
, "Atm:");
1553 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1554 offset
+= sprintf(buf
+ offset
,
1556 rulla
->atm_addr
[j
] & 0xff);
1558 offset
+= sprintf(buf
+ offset
,
1559 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1560 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1561 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1562 rulla
->recv_vcc
? rulla
->recv_vcc
->
1564 rulla
->recv_vcc
? rulla
->recv_vcc
->
1565 vci
: 0, rulla
->last_used
,
1566 rulla
->timestamp
, rulla
->no_tries
);
1568 sprintf(buf
+ offset
,
1569 "Flags:%x, Packets_flooded:%x, Status: %s ",
1570 rulla
->flags
, rulla
->packets_flooded
,
1571 get_status_string(rulla
->status
));
1572 printk("%s\n", buf
);
1576 if (!hlist_empty(&priv
->lec_no_forward
))
1577 printk("No forward\n");
1578 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1580 offset
+= sprintf(buf
+ offset
, "Mac:");
1581 for (j
= 0; j
< ETH_ALEN
; j
++) {
1582 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1583 rulla
->mac_addr
[j
] & 0xff);
1585 offset
+= sprintf(buf
+ offset
, "Atm:");
1586 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1587 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1588 rulla
->atm_addr
[j
] & 0xff);
1590 offset
+= sprintf(buf
+ offset
,
1591 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1592 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1593 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1594 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1595 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1597 rulla
->timestamp
, rulla
->no_tries
);
1598 offset
+= sprintf(buf
+ offset
,
1599 "Flags:%x, Packets_flooded:%x, Status: %s ",
1600 rulla
->flags
, rulla
->packets_flooded
,
1601 get_status_string(rulla
->status
));
1602 printk("%s\n", buf
);
1605 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1606 printk("Empty ones\n");
1607 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1609 offset
+= sprintf(buf
+ offset
, "Mac:");
1610 for (j
= 0; j
< ETH_ALEN
; j
++) {
1611 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1612 rulla
->mac_addr
[j
] & 0xff);
1614 offset
+= sprintf(buf
+ offset
, "Atm:");
1615 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1616 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1617 rulla
->atm_addr
[j
] & 0xff);
1619 offset
+= sprintf(buf
+ offset
,
1620 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1621 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1622 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1623 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1624 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1626 rulla
->timestamp
, rulla
->no_tries
);
1627 offset
+= sprintf(buf
+ offset
,
1628 "Flags:%x, Packets_flooded:%x, Status: %s ",
1629 rulla
->flags
, rulla
->packets_flooded
,
1630 get_status_string(rulla
->status
));
1634 if (!hlist_empty(&priv
->mcast_fwds
))
1635 printk("Multicast Forward VCCs\n");
1636 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1638 offset
+= sprintf(buf
+ offset
, "Mac:");
1639 for (j
= 0; j
< ETH_ALEN
; j
++) {
1640 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1641 rulla
->mac_addr
[j
] & 0xff);
1643 offset
+= sprintf(buf
+ offset
, "Atm:");
1644 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1645 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1646 rulla
->atm_addr
[j
] & 0xff);
1648 offset
+= sprintf(buf
+ offset
,
1649 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1650 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1651 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1652 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1653 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1655 rulla
->timestamp
, rulla
->no_tries
);
1656 offset
+= sprintf(buf
+ offset
,
1657 "Flags:%x, Packets_flooded:%x, Status: %s ",
1658 rulla
->flags
, rulla
->packets_flooded
,
1659 get_status_string(rulla
->status
));
1660 printk("%s\n", buf
);
1665 #define dump_arp_table(priv) do { } while (0)
1669 * Destruction of arp-cache
1671 static void lec_arp_destroy(struct lec_priv
*priv
)
1673 unsigned long flags
;
1674 struct hlist_node
*node
, *next
;
1675 struct lec_arp_table
*entry
;
1678 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1681 * Remove all entries
1684 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1685 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1686 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1687 lec_arp_remove(priv
, entry
);
1690 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1693 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1694 del_timer_sync(&entry
->timer
);
1695 lec_arp_clear_vccs(entry
);
1696 hlist_del(&entry
->next
);
1699 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1701 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1702 del_timer_sync(&entry
->timer
);
1703 lec_arp_clear_vccs(entry
);
1704 hlist_del(&entry
->next
);
1707 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1709 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1710 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1711 lec_arp_clear_vccs(entry
);
1712 hlist_del(&entry
->next
);
1715 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1716 priv
->mcast_vcc
= NULL
;
1717 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1721 * Find entry by mac_address
1723 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1724 const unsigned char *mac_addr
)
1726 struct hlist_node
*node
;
1727 struct hlist_head
*head
;
1728 struct lec_arp_table
*entry
;
1730 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1731 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1732 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1734 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1735 hlist_for_each_entry(entry
, node
, head
, next
) {
1736 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1743 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1744 const unsigned char *mac_addr
)
1746 struct lec_arp_table
*to_return
;
1748 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1750 printk("LEC: Arp entry kmalloc failed\n");
1753 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1754 INIT_HLIST_NODE(&to_return
->next
);
1755 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1756 (unsigned long)to_return
);
1757 to_return
->last_used
= jiffies
;
1758 to_return
->priv
= priv
;
1759 skb_queue_head_init(&to_return
->tx_wait
);
1760 atomic_set(&to_return
->usage
, 1);
1764 /* Arp sent timer expired */
1765 static void lec_arp_expire_arp(unsigned long data
)
1767 struct lec_arp_table
*entry
;
1769 entry
= (struct lec_arp_table
*)data
;
1771 pr_debug("lec_arp_expire_arp\n");
1772 if (entry
->status
== ESI_ARP_PENDING
) {
1773 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1774 if (entry
->is_rdesc
)
1775 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1776 entry
->mac_addr
, NULL
, NULL
);
1778 send_to_lecd(entry
->priv
, l_arp_xmt
,
1779 entry
->mac_addr
, NULL
, NULL
);
1782 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1786 /* Unknown/unused vcc expire, remove associated entry */
1787 static void lec_arp_expire_vcc(unsigned long data
)
1789 unsigned long flags
;
1790 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1791 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1793 del_timer(&to_remove
->timer
);
1795 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1797 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1798 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1800 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1801 hlist_del(&to_remove
->next
);
1802 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1804 lec_arp_clear_vccs(to_remove
);
1805 lec_arp_put(to_remove
);
1811 * 2. For each entry, delete entries that have aged past the age limit.
1812 * 3. For each entry, depending on the status of the entry, perform
1813 * the following maintenance.
1814 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1815 * tick_count is above the max_unknown_frame_time, clear
1816 * the tick_count to zero and clear the packets_flooded counter
1817 * to zero. This supports the packet rate limit per address
1818 * while flooding unknowns.
1819 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1820 * than or equal to the path_switching_delay, change the status
1821 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1822 * regardless of the progress of the flush protocol.
1824 static void lec_arp_check_expire(struct work_struct
*work
)
1826 unsigned long flags
;
1827 struct lec_priv
*priv
=
1828 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1829 struct hlist_node
*node
, *next
;
1830 struct lec_arp_table
*entry
;
1832 unsigned long time_to_check
;
1835 pr_debug("lec_arp_check_expire %p\n", priv
);
1838 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1839 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1840 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1841 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1842 priv
->topology_change
)
1843 time_to_check
= priv
->forward_delay_time
;
1845 time_to_check
= priv
->aging_time
;
1847 pr_debug("About to expire: %lx - %lx > %lx\n",
1848 now
, entry
->last_used
, time_to_check
);
1849 if (time_after(now
, entry
->last_used
+ time_to_check
)
1850 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1851 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1853 pr_debug("LEC:Entry timed out\n");
1854 lec_arp_remove(priv
, entry
);
1857 /* Something else */
1858 if ((entry
->status
== ESI_VC_PENDING
||
1859 entry
->status
== ESI_ARP_PENDING
)
1860 && time_after_eq(now
,
1863 max_unknown_frame_time
)) {
1864 entry
->timestamp
= jiffies
;
1865 entry
->packets_flooded
= 0;
1866 if (entry
->status
== ESI_VC_PENDING
)
1867 send_to_lecd(priv
, l_svc_setup
,
1872 if (entry
->status
== ESI_FLUSH_PENDING
1874 time_after_eq(now
, entry
->timestamp
+
1875 priv
->path_switching_delay
)) {
1876 struct sk_buff
*skb
;
1877 struct atm_vcc
*vcc
= entry
->vcc
;
1879 lec_arp_hold(entry
);
1880 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1881 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1883 entry
->last_used
= jiffies
;
1884 entry
->status
= ESI_FORWARD_DIRECT
;
1891 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1893 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1897 * Try to find vcc where mac_address is attached.
1900 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1901 const unsigned char *mac_to_find
, int is_rdesc
,
1902 struct lec_arp_table
**ret_entry
)
1904 unsigned long flags
;
1905 struct lec_arp_table
*entry
;
1906 struct atm_vcc
*found
;
1908 if (mac_to_find
[0] & 0x01) {
1909 switch (priv
->lane_version
) {
1911 return priv
->mcast_vcc
;
1912 case 2: /* LANE2 wants arp for multicast addresses */
1913 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1914 return priv
->mcast_vcc
;
1921 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1922 entry
= lec_arp_find(priv
, mac_to_find
);
1925 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1927 entry
->last_used
= jiffies
;
1928 lec_arp_hold(entry
);
1934 * If the LE_ARP cache entry is still pending, reset count to 0
1935 * so another LE_ARP request can be made for this frame.
1937 if (entry
->status
== ESI_ARP_PENDING
) {
1938 entry
->no_tries
= 0;
1941 * Data direct VC not yet set up, check to see if the unknown
1942 * frame count is greater than the limit. If the limit has
1943 * not been reached, allow the caller to send packet to
1946 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1947 entry
->packets_flooded
<
1948 priv
->maximum_unknown_frame_count
) {
1949 entry
->packets_flooded
++;
1950 pr_debug("LEC_ARP: Flooding..\n");
1951 found
= priv
->mcast_vcc
;
1955 * We got here because entry->status == ESI_FLUSH_PENDING
1956 * or BUS flood limit was reached for an entry which is
1957 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1959 lec_arp_hold(entry
);
1961 pr_debug("lec: entry->status %d entry->vcc %p\n", entry
->status
,
1965 /* No matching entry was found */
1966 entry
= make_entry(priv
, mac_to_find
);
1967 pr_debug("LEC_ARP: Making entry\n");
1969 found
= priv
->mcast_vcc
;
1972 lec_arp_add(priv
, entry
);
1973 /* We want arp-request(s) to be sent */
1974 entry
->packets_flooded
= 1;
1975 entry
->status
= ESI_ARP_PENDING
;
1976 entry
->no_tries
= 1;
1977 entry
->last_used
= entry
->timestamp
= jiffies
;
1978 entry
->is_rdesc
= is_rdesc
;
1979 if (entry
->is_rdesc
)
1980 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
1983 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
1984 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
1985 entry
->timer
.function
= lec_arp_expire_arp
;
1986 add_timer(&entry
->timer
);
1987 found
= priv
->mcast_vcc
;
1991 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1996 lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
1997 unsigned long permanent
)
1999 unsigned long flags
;
2000 struct hlist_node
*node
, *next
;
2001 struct lec_arp_table
*entry
;
2004 pr_debug("lec_addr_delete\n");
2005 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2006 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2007 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2008 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
2010 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
2011 lec_arp_remove(priv
, entry
);
2014 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2018 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2023 * Notifies: Response to arp_request (atm_addr != NULL)
2026 lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
2027 const unsigned char *atm_addr
, unsigned long remoteflag
,
2028 unsigned int targetless_le_arp
)
2030 unsigned long flags
;
2031 struct hlist_node
*node
, *next
;
2032 struct lec_arp_table
*entry
, *tmp
;
2035 pr_debug("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2036 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2037 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2038 mac_addr
[4], mac_addr
[5]);
2040 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2041 entry
= lec_arp_find(priv
, mac_addr
);
2042 if (entry
== NULL
&& targetless_le_arp
)
2044 * LANE2: ignore targetless LE_ARPs for which
2045 * we have no entry in the cache. 7.1.30
2047 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2048 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2049 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2050 hlist_del(&entry
->next
);
2051 del_timer(&entry
->timer
);
2052 tmp
= lec_arp_find(priv
, mac_addr
);
2054 del_timer(&tmp
->timer
);
2055 tmp
->status
= ESI_FORWARD_DIRECT
;
2056 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2057 tmp
->vcc
= entry
->vcc
;
2058 tmp
->old_push
= entry
->old_push
;
2059 tmp
->last_used
= jiffies
;
2060 del_timer(&entry
->timer
);
2064 entry
->status
= ESI_FORWARD_DIRECT
;
2065 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2066 entry
->last_used
= jiffies
;
2067 lec_arp_add(priv
, entry
);
2070 entry
->flags
|= LEC_REMOTE_FLAG
;
2072 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2073 pr_debug("After update\n");
2074 dump_arp_table(priv
);
2080 entry
= lec_arp_find(priv
, mac_addr
);
2082 entry
= make_entry(priv
, mac_addr
);
2085 entry
->status
= ESI_UNKNOWN
;
2086 lec_arp_add(priv
, entry
);
2087 /* Temporary, changes before end of function */
2089 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2090 del_timer(&entry
->timer
);
2091 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2092 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2094 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2095 /* Vcc to this host exists */
2096 if (tmp
->status
> ESI_VC_PENDING
) {
2098 * ESI_FLUSH_PENDING,
2099 * ESI_FORWARD_DIRECT
2101 entry
->vcc
= tmp
->vcc
;
2102 entry
->old_push
= tmp
->old_push
;
2104 entry
->status
= tmp
->status
;
2110 entry
->flags
|= LEC_REMOTE_FLAG
;
2112 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2113 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2114 entry
->status
= ESI_VC_PENDING
;
2115 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2117 pr_debug("After update2\n");
2118 dump_arp_table(priv
);
2120 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2124 * Notifies: Vcc setup ready
2127 lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
2128 struct atm_vcc
*vcc
,
2129 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2131 unsigned long flags
;
2132 struct hlist_node
*node
;
2133 struct lec_arp_table
*entry
;
2134 int i
, found_entry
= 0;
2136 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2137 if (ioc_data
->receive
== 2) {
2138 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2140 pr_debug("LEC_ARP: Attaching mcast forward\n");
2142 entry
= lec_arp_find(priv
, bus_mac
);
2144 printk("LEC_ARP: Multicast entry not found!\n");
2147 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2148 entry
->recv_vcc
= vcc
;
2149 entry
->old_recv_push
= old_push
;
2151 entry
= make_entry(priv
, bus_mac
);
2154 del_timer(&entry
->timer
);
2155 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2156 entry
->recv_vcc
= vcc
;
2157 entry
->old_recv_push
= old_push
;
2158 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2160 } else if (ioc_data
->receive
== 1) {
2162 * Vcc which we don't want to make default vcc,
2166 ("LEC_ARP:Attaching data direct, not default: "
2167 "%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",
2168 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2169 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2170 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2171 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2172 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2173 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2174 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2175 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2176 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2177 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2178 entry
= make_entry(priv
, bus_mac
);
2181 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2182 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2183 entry
->recv_vcc
= vcc
;
2184 entry
->old_recv_push
= old_push
;
2185 entry
->status
= ESI_UNKNOWN
;
2186 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2187 entry
->timer
.function
= lec_arp_expire_vcc
;
2188 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2189 add_timer(&entry
->timer
);
2190 dump_arp_table(priv
);
2194 ("LEC_ARP:Attaching data direct, default: "
2195 "%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",
2196 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2197 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2198 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2199 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2200 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2201 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2202 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2203 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2204 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2205 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2206 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2207 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2209 (ioc_data
->atm_addr
, entry
->atm_addr
,
2210 ATM_ESA_LEN
) == 0) {
2211 pr_debug("LEC_ARP: Attaching data direct\n");
2212 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2213 entry
->vcc
? entry
->vcc
->vci
: 0,
2214 entry
->recv_vcc
? entry
->recv_vcc
->
2217 del_timer(&entry
->timer
);
2219 entry
->old_push
= old_push
;
2220 if (entry
->status
== ESI_VC_PENDING
) {
2221 if (priv
->maximum_unknown_frame_count
2226 entry
->timestamp
= jiffies
;
2230 send_to_lecd(priv
, l_flush_xmt
,
2238 * They were forming a connection
2239 * to us, and we to them. Our
2240 * ATM address is numerically lower
2241 * than theirs, so we make connection
2242 * we formed into default VCC (8.1.11).
2243 * Connection they made gets torn
2244 * down. This might confuse some
2245 * clients. Can be changed if
2246 * someone reports trouble...
2254 pr_debug("After vcc was added\n");
2255 dump_arp_table(priv
);
2259 * Not found, snatch address from first data packet that arrives
2262 entry
= make_entry(priv
, bus_mac
);
2266 entry
->old_push
= old_push
;
2267 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2268 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2269 entry
->status
= ESI_UNKNOWN
;
2270 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2271 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2272 entry
->timer
.function
= lec_arp_expire_vcc
;
2273 add_timer(&entry
->timer
);
2274 pr_debug("After vcc was added\n");
2275 dump_arp_table(priv
);
2277 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2280 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2282 unsigned long flags
;
2283 struct hlist_node
*node
;
2284 struct lec_arp_table
*entry
;
2287 pr_debug("LEC:lec_flush_complete %lx\n", tran_id
);
2289 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2290 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2291 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2292 if (entry
->flush_tran_id
== tran_id
2293 && entry
->status
== ESI_FLUSH_PENDING
) {
2294 struct sk_buff
*skb
;
2295 struct atm_vcc
*vcc
= entry
->vcc
;
2297 lec_arp_hold(entry
);
2298 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2299 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2301 entry
->last_used
= jiffies
;
2302 entry
->status
= ESI_FORWARD_DIRECT
;
2304 pr_debug("LEC_ARP: Flushed\n");
2309 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2310 dump_arp_table(priv
);
2314 lec_set_flush_tran_id(struct lec_priv
*priv
,
2315 const unsigned char *atm_addr
, unsigned long tran_id
)
2317 unsigned long flags
;
2318 struct hlist_node
*node
;
2319 struct lec_arp_table
*entry
;
2322 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2323 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2324 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2325 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2326 entry
->flush_tran_id
= tran_id
;
2327 pr_debug("Set flush transaction id to %lx for %p\n",
2331 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2334 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2336 unsigned long flags
;
2337 unsigned char mac_addr
[] = {
2338 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2340 struct lec_arp_table
*to_add
;
2341 struct lec_vcc_priv
*vpriv
;
2344 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2347 vpriv
->old_pop
= vcc
->pop
;
2348 vcc
->user_back
= vpriv
;
2350 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2351 to_add
= make_entry(priv
, mac_addr
);
2353 vcc
->pop
= vpriv
->old_pop
;
2358 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2359 to_add
->status
= ESI_FORWARD_DIRECT
;
2360 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2362 to_add
->old_push
= vcc
->push
;
2363 vcc
->push
= lec_push
;
2364 priv
->mcast_vcc
= vcc
;
2365 lec_arp_add(priv
, to_add
);
2367 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2371 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2373 unsigned long flags
;
2374 struct hlist_node
*node
, *next
;
2375 struct lec_arp_table
*entry
;
2378 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2379 dump_arp_table(priv
);
2381 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2383 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2384 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2385 if (vcc
== entry
->vcc
) {
2386 lec_arp_remove(priv
, entry
);
2388 if (priv
->mcast_vcc
== vcc
) {
2389 priv
->mcast_vcc
= NULL
;
2395 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2396 if (entry
->vcc
== vcc
) {
2397 lec_arp_clear_vccs(entry
);
2398 del_timer(&entry
->timer
);
2399 hlist_del(&entry
->next
);
2404 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2405 if (entry
->recv_vcc
== vcc
) {
2406 lec_arp_clear_vccs(entry
);
2407 del_timer(&entry
->timer
);
2408 hlist_del(&entry
->next
);
2413 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2414 if (entry
->recv_vcc
== vcc
) {
2415 lec_arp_clear_vccs(entry
);
2416 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2417 hlist_del(&entry
->next
);
2422 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2423 dump_arp_table(priv
);
2427 lec_arp_check_empties(struct lec_priv
*priv
,
2428 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2430 unsigned long flags
;
2431 struct hlist_node
*node
, *next
;
2432 struct lec_arp_table
*entry
, *tmp
;
2433 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2436 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2439 src
= tr_hdr
->h_source
;
2442 src
= hdr
->h_source
;
2444 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2445 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2446 if (vcc
== entry
->vcc
) {
2447 del_timer(&entry
->timer
);
2448 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2449 entry
->status
= ESI_FORWARD_DIRECT
;
2450 entry
->last_used
= jiffies
;
2451 /* We might have got an entry */
2452 if ((tmp
= lec_arp_find(priv
, src
))) {
2453 lec_arp_remove(priv
, tmp
);
2456 hlist_del(&entry
->next
);
2457 lec_arp_add(priv
, entry
);
2461 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2463 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2466 MODULE_LICENSE("GPL");