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 "../bridge/br_private.h"
39 static unsigned char bridge_ula_lec
[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
43 #include <linux/module.h>
44 #include <linux/init.h>
48 #include "resources.h"
50 #define DUMP_PACKETS 0 /*
56 #define LEC_UNRES_QUE_LEN 8 /*
57 * number of tx packets to queue for a
58 * single destination while waiting for SVC
61 static int lec_open(struct net_device
*dev
);
62 static netdev_tx_t
lec_start_xmit(struct sk_buff
*skb
,
63 struct net_device
*dev
);
64 static int lec_close(struct net_device
*dev
);
65 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
66 const unsigned char *mac_addr
);
67 static int lec_arp_remove(struct lec_priv
*priv
,
68 struct lec_arp_table
*to_remove
);
70 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_address
,
71 const u8
*tlvs
, u32 sizeoftlvs
);
72 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
73 u8
**tlvs
, u32
*sizeoftlvs
);
74 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
75 const u8
*tlvs
, u32 sizeoftlvs
);
77 static int lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
78 unsigned long permanent
);
79 static void lec_arp_check_empties(struct lec_priv
*priv
,
80 struct atm_vcc
*vcc
, struct sk_buff
*skb
);
81 static void lec_arp_destroy(struct lec_priv
*priv
);
82 static void lec_arp_init(struct lec_priv
*priv
);
83 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
84 const unsigned char *mac_to_find
,
86 struct lec_arp_table
**ret_entry
);
87 static void lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
88 const unsigned char *atm_addr
, unsigned long remoteflag
,
89 unsigned int targetless_le_arp
);
90 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
);
91 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
92 static void lec_set_flush_tran_id(struct lec_priv
*priv
,
93 const unsigned char *atm_addr
,
94 unsigned long tran_id
);
95 static void lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
97 void (*old_push
) (struct atm_vcc
*vcc
,
98 struct sk_buff
*skb
));
99 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
);
101 /* must be done under lec_arp_lock */
102 static inline void lec_arp_hold(struct lec_arp_table
*entry
)
104 atomic_inc(&entry
->usage
);
107 static inline void lec_arp_put(struct lec_arp_table
*entry
)
109 if (atomic_dec_and_test(&entry
->usage
))
114 static struct lane2_ops lane2_ops
= {
115 lane2_resolve
, /* resolve, spec 3.1.3 */
116 lane2_associate_req
, /* associate_req, spec 3.1.4 */
117 NULL
/* associate indicator, spec 3.1.5 */
120 static unsigned char bus_mac
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
122 /* Device structures */
123 static struct net_device
*dev_lec
[MAX_LEC_ITF
];
125 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
126 static void lec_handle_bridge(struct sk_buff
*skb
, struct net_device
*dev
)
130 struct lec_priv
*priv
;
133 * Check if this is a BPDU. If so, ask zeppelin to send
134 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
135 * as the Config BPDU has
137 eth
= (struct ethhdr
*)skb
->data
;
138 buff
= skb
->data
+ skb
->dev
->hard_header_len
;
139 if (*buff
++ == 0x42 && *buff
++ == 0x42 && *buff
++ == 0x03) {
141 struct sk_buff
*skb2
;
142 struct atmlec_msg
*mesg
;
144 skb2
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
147 skb2
->len
= sizeof(struct atmlec_msg
);
148 mesg
= (struct atmlec_msg
*)skb2
->data
;
149 mesg
->type
= l_topology_change
;
151 mesg
->content
.normal
.flag
= *buff
& 0x01; /* 0x01 is topology change */
153 priv
= netdev_priv(dev
);
154 atm_force_charge(priv
->lecd
, skb2
->truesize
);
155 sk
= sk_atm(priv
->lecd
);
156 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
157 sk
->sk_data_ready(sk
, skb2
->len
);
162 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165 * Modelled after tr_type_trans
166 * All multicast and ARE or STE frames go to BUS.
167 * Non source routed frames go by destination address.
168 * Last hop source routed frames go by destination address.
169 * Not last hop source routed frames go by _next_ route descriptor.
170 * Returns pointer to destination MAC address or fills in rdesc
174 static unsigned char *get_tr_dst(unsigned char *packet
, unsigned char *rdesc
)
177 unsigned int riflen
, num_rdsc
;
179 trh
= (struct trh_hdr
*)packet
;
180 if (trh
->daddr
[0] & (uint8_t) 0x80)
181 return bus_mac
; /* multicast */
183 if (trh
->saddr
[0] & TR_RII
) {
184 riflen
= (ntohs(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
185 if ((ntohs(trh
->rcf
) >> 13) != 0)
186 return bus_mac
; /* ARE or STE */
188 return trh
->daddr
; /* not source routed */
191 return trh
->daddr
; /* last hop, source routed */
193 /* riflen is 6 or more, packet has more than one route descriptor */
194 num_rdsc
= (riflen
/ 2) - 1;
195 memset(rdesc
, 0, ETH_ALEN
);
196 /* offset 4 comes from LAN destination field in LE control frames */
197 if (trh
->rcf
& htons((uint16_t) TR_RCF_DIR_BIT
))
198 memcpy(&rdesc
[4], &trh
->rseg
[num_rdsc
- 2], sizeof(__be16
));
200 memcpy(&rdesc
[4], &trh
->rseg
[1], sizeof(__be16
));
201 rdesc
[5] = ((ntohs(trh
->rseg
[0]) & 0x000f) | (rdesc
[5] & 0xf0));
206 #endif /* CONFIG_TR */
209 * Open/initialize the netdevice. This is called (in the current kernel)
210 * sometime after booting when the 'ifconfig' program is run.
212 * This routine should set everything up anew at each open, even
213 * registers that "should" only need to be set once at boot, so that
214 * there is non-reboot way to recover if something goes wrong.
217 static int lec_open(struct net_device
*dev
)
219 netif_start_queue(dev
);
220 memset(&dev
->stats
, 0, sizeof(struct net_device_stats
));
226 lec_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
228 struct net_device
*dev
= skb
->dev
;
230 ATM_SKB(skb
)->vcc
= vcc
;
231 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
233 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
234 if (vcc
->send(vcc
, skb
) < 0) {
235 dev
->stats
.tx_dropped
++;
239 dev
->stats
.tx_packets
++;
240 dev
->stats
.tx_bytes
+= skb
->len
;
243 static void lec_tx_timeout(struct net_device
*dev
)
245 printk(KERN_INFO
"%s: tx timeout\n", dev
->name
);
246 dev
->trans_start
= jiffies
;
247 netif_wake_queue(dev
);
250 static netdev_tx_t
lec_start_xmit(struct sk_buff
*skb
,
251 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
);
278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
279 (long)skb
->head
, (long)skb
->data
, (long)skb_tail_pointer(skb
),
280 (long)skb_end_pointer(skb
));
281 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
282 if (memcmp(skb
->data
, bridge_ula_lec
, sizeof(bridge_ula_lec
)) == 0)
283 lec_handle_bridge(skb
, dev
);
286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb
) < 2) {
289 pr_debug("lec_start_xmit: reallocating skb\n");
290 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
298 /* Put le header to place, works for TokenRing too */
299 lec_h
= (struct lecdatahdr_8023
*)skb
->data
;
300 lec_h
->le_header
= htons(priv
->lecid
);
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
307 if (priv
->is_trdev
) {
308 skb2
= skb_realloc_headroom(skb
, LEC_HEADER_LEN
);
317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev
->name
,
318 skb
->len
, priv
->lecid
);
319 #if DUMP_PACKETS >= 2
320 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
321 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
323 #elif DUMP_PACKETS >= 1
324 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
325 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
327 #endif /* DUMP_PACKETS >= 1 */
331 printk("%s...\n", buf
);
332 #endif /* DUMP_PACKETS > 0 */
334 /* Minimum ethernet-frame size */
337 min_frame_size
= LEC_MINIMUM_8025_SIZE
;
340 min_frame_size
= LEC_MINIMUM_8023_SIZE
;
341 if (skb
->len
< min_frame_size
) {
342 if ((skb
->len
+ skb_tailroom(skb
)) < min_frame_size
) {
343 skb2
= skb_copy_expand(skb
, 0,
344 min_frame_size
- skb
->truesize
,
348 dev
->stats
.tx_dropped
++;
353 skb_put(skb
, min_frame_size
- skb
->len
);
356 /* Send to right vcc */
360 if (priv
->is_trdev
) {
361 dst
= get_tr_dst(skb
->data
+ 2, rdesc
);
369 vcc
= lec_arp_resolve(priv
, dst
, is_rdesc
, &entry
);
370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev
->name
,
371 vcc
, vcc
? vcc
->flags
: 0, entry
);
372 if (!vcc
|| !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
373 if (entry
&& (entry
->tx_wait
.qlen
< LEC_UNRES_QUE_LEN
)) {
374 pr_debug("%s:lec_start_xmit: queuing packet, ",
376 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
377 skb_queue_tail(&entry
->tx_wait
, skb
);
380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
382 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
383 dev
->stats
.tx_dropped
++;
389 printk("%s:sending to vpi:%d vci:%d\n", dev
->name
, vcc
->vpi
, vcc
->vci
);
390 #endif /* DUMP_PACKETS > 0 */
392 while (entry
&& (skb2
= skb_dequeue(&entry
->tx_wait
))) {
393 pr_debug("lec.c: emptying tx queue, ");
394 pr_debug("MAC address %pM\n", lec_h
->h_dest
);
400 if (!atm_may_send(vcc
, 0)) {
401 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
404 netif_stop_queue(dev
);
407 * vcc->pop() might have occurred in between, making
408 * the vcc usuable again. Since xmit is serialized,
409 * this is the only situation we have to re-test.
412 if (atm_may_send(vcc
, 0))
413 netif_wake_queue(dev
);
419 dev
->trans_start
= jiffies
;
423 /* The inverse routine to net_open(). */
424 static int lec_close(struct net_device
*dev
)
426 netif_stop_queue(dev
);
430 static int lec_atm_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
433 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
434 struct lec_priv
*priv
= netdev_priv(dev
);
435 struct atmlec_msg
*mesg
;
436 struct lec_arp_table
*entry
;
438 char *tmp
; /* FIXME */
440 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
441 mesg
= (struct atmlec_msg
*)skb
->data
;
443 tmp
+= sizeof(struct atmlec_msg
);
444 pr_debug("%s: msg from zeppelin:%d\n", dev
->name
, mesg
->type
);
445 switch (mesg
->type
) {
447 for (i
= 0; i
< 6; i
++) {
448 dev
->dev_addr
[i
] = mesg
->content
.normal
.mac_addr
[i
];
452 for (i
= 0; i
< 6; i
++) {
453 dev
->dev_addr
[i
] = 0;
457 lec_addr_delete(priv
, mesg
->content
.normal
.atm_addr
,
458 mesg
->content
.normal
.flag
);
460 case l_topology_change
:
461 priv
->topology_change
= mesg
->content
.normal
.flag
;
463 case l_flush_complete
:
464 lec_flush_complete(priv
, mesg
->content
.normal
.flag
);
466 case l_narp_req
: /* LANE2: see 7.1.35 in the lane2 spec */
467 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
468 entry
= lec_arp_find(priv
, mesg
->content
.normal
.mac_addr
);
469 lec_arp_remove(priv
, entry
);
470 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
472 if (mesg
->content
.normal
.no_source_le_narp
)
476 lec_arp_update(priv
, mesg
->content
.normal
.mac_addr
,
477 mesg
->content
.normal
.atm_addr
,
478 mesg
->content
.normal
.flag
,
479 mesg
->content
.normal
.targetless_le_arp
);
480 pr_debug("lec: in l_arp_update\n");
481 if (mesg
->sizeoftlvs
!= 0) { /* LANE2 3.1.5 */
482 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
484 lane2_associate_ind(dev
, mesg
->content
.normal
.mac_addr
,
485 tmp
, mesg
->sizeoftlvs
);
489 priv
->maximum_unknown_frame_count
=
490 mesg
->content
.config
.maximum_unknown_frame_count
;
491 priv
->max_unknown_frame_time
=
492 (mesg
->content
.config
.max_unknown_frame_time
* HZ
);
493 priv
->max_retry_count
= mesg
->content
.config
.max_retry_count
;
494 priv
->aging_time
= (mesg
->content
.config
.aging_time
* HZ
);
495 priv
->forward_delay_time
=
496 (mesg
->content
.config
.forward_delay_time
* HZ
);
497 priv
->arp_response_time
=
498 (mesg
->content
.config
.arp_response_time
* HZ
);
499 priv
->flush_timeout
= (mesg
->content
.config
.flush_timeout
* HZ
);
500 priv
->path_switching_delay
=
501 (mesg
->content
.config
.path_switching_delay
* HZ
);
502 priv
->lane_version
= mesg
->content
.config
.lane_version
; /* LANE2 */
503 priv
->lane2_ops
= NULL
;
504 if (priv
->lane_version
> 1)
505 priv
->lane2_ops
= &lane2_ops
;
506 if (dev_set_mtu(dev
, mesg
->content
.config
.mtu
))
507 printk("%s: change_mtu to %d failed\n", dev
->name
,
508 mesg
->content
.config
.mtu
);
509 priv
->is_proxy
= mesg
->content
.config
.is_proxy
;
511 case l_flush_tran_id
:
512 lec_set_flush_tran_id(priv
, mesg
->content
.normal
.atm_addr
,
513 mesg
->content
.normal
.flag
);
517 (unsigned short)(0xffff & mesg
->content
.normal
.flag
);
519 case l_should_bridge
:
520 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
522 pr_debug("%s: bridge zeppelin asks about %pM\n",
523 dev
->name
, mesg
->content
.proxy
.mac_addr
);
525 if (br_fdb_test_addr_hook
== NULL
)
528 if (br_fdb_test_addr_hook(dev
,
529 mesg
->content
.proxy
.mac_addr
)) {
530 /* hit from bridge table, send LE_ARP_RESPONSE */
531 struct sk_buff
*skb2
;
535 ("%s: entry found, responding to zeppelin\n",
538 alloc_skb(sizeof(struct atmlec_msg
),
542 skb2
->len
= sizeof(struct atmlec_msg
);
543 skb_copy_to_linear_data(skb2
, mesg
,
545 atm_force_charge(priv
->lecd
, skb2
->truesize
);
546 sk
= sk_atm(priv
->lecd
);
547 skb_queue_tail(&sk
->sk_receive_queue
, skb2
);
548 sk
->sk_data_ready(sk
, skb2
->len
);
551 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
554 printk("%s: Unknown message type %d\n", dev
->name
, mesg
->type
);
562 static void lec_atm_close(struct atm_vcc
*vcc
)
565 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
566 struct lec_priv
*priv
= netdev_priv(dev
);
569 /* Do something needful? */
571 netif_stop_queue(dev
);
572 lec_arp_destroy(priv
);
574 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
575 printk("%s lec_atm_close: closing with messages pending\n",
577 while ((skb
= skb_dequeue(&sk_atm(vcc
)->sk_receive_queue
)) != NULL
) {
578 atm_return(vcc
, skb
->truesize
);
582 printk("%s: Shut down!\n", dev
->name
);
583 module_put(THIS_MODULE
);
586 static struct atmdev_ops lecdev_ops
= {
587 .close
= lec_atm_close
,
591 static struct atm_dev lecatm_dev
= {
594 .number
= 999, /* dummy device number */
595 .lock
= __SPIN_LOCK_UNLOCKED(lecatm_dev
.lock
)
599 * LANE2: new argument struct sk_buff *data contains
600 * the LE_ARP based TLVs introduced in the LANE2 spec
603 send_to_lecd(struct lec_priv
*priv
, atmlec_msg_type type
,
604 const unsigned char *mac_addr
, const unsigned char *atm_addr
,
605 struct sk_buff
*data
)
609 struct atmlec_msg
*mesg
;
611 if (!priv
|| !priv
->lecd
) {
614 skb
= alloc_skb(sizeof(struct atmlec_msg
), GFP_ATOMIC
);
617 skb
->len
= sizeof(struct atmlec_msg
);
618 mesg
= (struct atmlec_msg
*)skb
->data
;
619 memset(mesg
, 0, sizeof(struct atmlec_msg
));
622 mesg
->sizeoftlvs
= data
->len
;
624 memcpy(&mesg
->content
.normal
.mac_addr
, mac_addr
, ETH_ALEN
);
626 mesg
->content
.normal
.targetless_le_arp
= 1;
628 memcpy(&mesg
->content
.normal
.atm_addr
, atm_addr
, ATM_ESA_LEN
);
630 atm_force_charge(priv
->lecd
, skb
->truesize
);
631 sk
= sk_atm(priv
->lecd
);
632 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
633 sk
->sk_data_ready(sk
, skb
->len
);
636 pr_debug("lec: about to send %d bytes of data\n", data
->len
);
637 atm_force_charge(priv
->lecd
, data
->truesize
);
638 skb_queue_tail(&sk
->sk_receive_queue
, data
);
639 sk
->sk_data_ready(sk
, skb
->len
);
645 /* shamelessly stolen from drivers/net/net_init.c */
646 static int lec_change_mtu(struct net_device
*dev
, int new_mtu
)
648 if ((new_mtu
< 68) || (new_mtu
> 18190))
654 static void lec_set_multicast_list(struct net_device
*dev
)
657 * by default, all multicast frames arrive over the bus.
658 * eventually support selective multicast service
663 static const struct net_device_ops lec_netdev_ops
= {
664 .ndo_open
= lec_open
,
665 .ndo_stop
= lec_close
,
666 .ndo_start_xmit
= lec_start_xmit
,
667 .ndo_change_mtu
= lec_change_mtu
,
668 .ndo_tx_timeout
= lec_tx_timeout
,
669 .ndo_set_multicast_list
= lec_set_multicast_list
,
672 static const unsigned char lec_ctrl_magic
[] = {
679 #define LEC_DATA_DIRECT_8023 2
680 #define LEC_DATA_DIRECT_8025 3
682 static int lec_is_data_direct(struct atm_vcc
*vcc
)
684 return ((vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8023
) ||
685 (vcc
->sap
.blli
[0].l3
.tr9577
.snap
[4] == LEC_DATA_DIRECT_8025
));
688 static void lec_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
691 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
692 struct lec_priv
*priv
= netdev_priv(dev
);
698 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev
->name
,
702 pr_debug("%s: null skb\n", dev
->name
);
703 lec_vcc_close(priv
, vcc
);
707 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev
->name
,
708 skb
->len
, priv
->lecid
);
709 #if DUMP_PACKETS >= 2
710 for (i
= 0; i
< skb
->len
&& i
< 99; i
++) {
711 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
713 #elif DUMP_PACKETS >= 1
714 for (i
= 0; i
< skb
->len
&& i
< 30; i
++) {
715 sprintf(buf
+ i
* 3, "%2.2x ", 0xff & skb
->data
[i
]);
717 #endif /* DUMP_PACKETS >= 1 */
721 printk("%s...\n", buf
);
722 #endif /* DUMP_PACKETS > 0 */
723 if (memcmp(skb
->data
, lec_ctrl_magic
, 4) == 0) { /* Control frame, to daemon */
724 struct sock
*sk
= sk_atm(vcc
);
726 pr_debug("%s: To daemon\n", dev
->name
);
727 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
728 sk
->sk_data_ready(sk
, skb
->len
);
729 } else { /* Data frame, queue to protocol handlers */
730 struct lec_arp_table
*entry
;
731 unsigned char *src
, *dst
;
733 atm_return(vcc
, skb
->truesize
);
734 if (*(__be16
*) skb
->data
== htons(priv
->lecid
) ||
735 !priv
->lecd
|| !(dev
->flags
& IFF_UP
)) {
737 * Probably looping back, or if lecd is missing,
740 pr_debug("Ignoring frame...\n");
746 dst
= ((struct lecdatahdr_8025
*)skb
->data
)->h_dest
;
749 dst
= ((struct lecdatahdr_8023
*)skb
->data
)->h_dest
;
752 * If this is a Data Direct VCC, and the VCC does not match
753 * the LE_ARP cache entry, delete the LE_ARP cache entry.
755 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
756 if (lec_is_data_direct(vcc
)) {
760 ((struct lecdatahdr_8025
*)skb
->data
)->
765 ((struct lecdatahdr_8023
*)skb
->data
)->
767 entry
= lec_arp_find(priv
, src
);
768 if (entry
&& entry
->vcc
!= vcc
) {
769 lec_arp_remove(priv
, entry
);
773 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
775 if (!(dst
[0] & 0x01) && /* Never filter Multi/Broadcast */
776 !priv
->is_proxy
&& /* Proxy wants all the packets */
777 memcmp(dst
, dev
->dev_addr
, dev
->addr_len
)) {
781 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
782 lec_arp_check_empties(priv
, vcc
, skb
);
784 skb_pull(skb
, 2); /* skip lec_id */
787 skb
->protocol
= tr_type_trans(skb
, dev
);
790 skb
->protocol
= eth_type_trans(skb
, dev
);
791 dev
->stats
.rx_packets
++;
792 dev
->stats
.rx_bytes
+= skb
->len
;
793 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
798 static void lec_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
800 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
801 struct net_device
*dev
= skb
->dev
;
804 printk("lec_pop(): vpriv = NULL!?!?!?\n");
808 vpriv
->old_pop(vcc
, skb
);
810 if (vpriv
->xoff
&& atm_may_send(vcc
, 0)) {
812 if (netif_running(dev
) && netif_queue_stopped(dev
))
813 netif_wake_queue(dev
);
817 static int lec_vcc_attach(struct atm_vcc
*vcc
, void __user
*arg
)
819 struct lec_vcc_priv
*vpriv
;
821 struct atmlec_ioc ioc_data
;
823 /* Lecd must be up in this case */
824 bytes_left
= copy_from_user(&ioc_data
, arg
, sizeof(struct atmlec_ioc
));
825 if (bytes_left
!= 0) {
827 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
830 if (ioc_data
.dev_num
< 0 || ioc_data
.dev_num
>= MAX_LEC_ITF
||
831 !dev_lec
[ioc_data
.dev_num
])
833 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
836 vpriv
->old_pop
= vcc
->pop
;
837 vcc
->user_back
= vpriv
;
839 lec_vcc_added(netdev_priv(dev_lec
[ioc_data
.dev_num
]),
840 &ioc_data
, vcc
, vcc
->push
);
841 vcc
->proto_data
= dev_lec
[ioc_data
.dev_num
];
842 vcc
->push
= lec_push
;
846 static int lec_mcast_attach(struct atm_vcc
*vcc
, int arg
)
848 if (arg
< 0 || arg
>= MAX_LEC_ITF
|| !dev_lec
[arg
])
850 vcc
->proto_data
= dev_lec
[arg
];
851 return lec_mcast_make((struct lec_priv
*)netdev_priv(dev_lec
[arg
]),
855 /* Initialize device. */
856 static int lecd_attach(struct atm_vcc
*vcc
, int arg
)
859 struct lec_priv
*priv
;
866 if (arg
>= MAX_LEC_ITF
)
868 #else /* Reserve the top NUM_TR_DEVS for TR */
869 if (arg
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
876 if (i
>= (MAX_LEC_ITF
- NUM_TR_DEVS
))
879 size
= sizeof(struct lec_priv
);
882 dev_lec
[i
] = alloc_trdev(size
);
885 dev_lec
[i
] = alloc_etherdev(size
);
888 dev_lec
[i
]->netdev_ops
= &lec_netdev_ops
;
889 snprintf(dev_lec
[i
]->name
, IFNAMSIZ
, "lec%d", i
);
890 if (register_netdev(dev_lec
[i
])) {
891 free_netdev(dev_lec
[i
]);
895 priv
= netdev_priv(dev_lec
[i
]);
896 priv
->is_trdev
= is_trdev
;
898 priv
= netdev_priv(dev_lec
[i
]);
903 priv
->itfnum
= i
; /* LANE2 addition */
905 vcc
->dev
= &lecatm_dev
;
906 vcc_insert_socket(sk_atm(vcc
));
908 vcc
->proto_data
= dev_lec
[i
];
909 set_bit(ATM_VF_META
, &vcc
->flags
);
910 set_bit(ATM_VF_READY
, &vcc
->flags
);
912 /* Set default values to these variables */
913 priv
->maximum_unknown_frame_count
= 1;
914 priv
->max_unknown_frame_time
= (1 * HZ
);
915 priv
->vcc_timeout_period
= (1200 * HZ
);
916 priv
->max_retry_count
= 1;
917 priv
->aging_time
= (300 * HZ
);
918 priv
->forward_delay_time
= (15 * HZ
);
919 priv
->topology_change
= 0;
920 priv
->arp_response_time
= (1 * HZ
);
921 priv
->flush_timeout
= (4 * HZ
);
922 priv
->path_switching_delay
= (6 * HZ
);
924 if (dev_lec
[i
]->flags
& IFF_UP
) {
925 netif_start_queue(dev_lec
[i
]);
927 __module_get(THIS_MODULE
);
931 #ifdef CONFIG_PROC_FS
932 static const char *lec_arp_get_status_string(unsigned char status
)
934 static const char *const lec_arp_status_string
[] = {
939 "ESI_FLUSH_PENDING ",
943 if (status
> ESI_FORWARD_DIRECT
)
944 status
= 3; /* ESI_UNDEFINED */
945 return lec_arp_status_string
[status
];
948 static void lec_info(struct seq_file
*seq
, struct lec_arp_table
*entry
)
952 for (i
= 0; i
< ETH_ALEN
; i
++)
953 seq_printf(seq
, "%2.2x", entry
->mac_addr
[i
] & 0xff);
954 seq_printf(seq
, " ");
955 for (i
= 0; i
< ATM_ESA_LEN
; i
++)
956 seq_printf(seq
, "%2.2x", entry
->atm_addr
[i
] & 0xff);
957 seq_printf(seq
, " %s %4.4x", lec_arp_get_status_string(entry
->status
),
958 entry
->flags
& 0xffff);
960 seq_printf(seq
, "%3d %3d ", entry
->vcc
->vpi
, entry
->vcc
->vci
);
962 seq_printf(seq
, " ");
963 if (entry
->recv_vcc
) {
964 seq_printf(seq
, " %3d %3d", entry
->recv_vcc
->vpi
,
965 entry
->recv_vcc
->vci
);
972 struct lec_priv
*locked
;
973 struct hlist_node
*node
;
974 struct net_device
*dev
;
980 static void *lec_tbl_walk(struct lec_state
*state
, struct hlist_head
*tbl
,
983 struct hlist_node
*e
= state
->node
;
984 struct lec_arp_table
*tmp
;
988 if (e
== SEQ_START_TOKEN
) {
993 hlist_for_each_entry_from(tmp
, e
, next
) {
999 return (*l
< 0) ? state
: NULL
;
1002 static void *lec_arp_walk(struct lec_state
*state
, loff_t
*l
,
1003 struct lec_priv
*priv
)
1008 for (p
= state
->arp_table
; p
< LEC_ARP_TABLE_SIZE
; p
++) {
1009 v
= lec_tbl_walk(state
, &priv
->lec_arp_tables
[p
], l
);
1013 state
->arp_table
= p
;
1017 static void *lec_misc_walk(struct lec_state
*state
, loff_t
*l
,
1018 struct lec_priv
*priv
)
1020 struct hlist_head
*lec_misc_tables
[] = {
1021 &priv
->lec_arp_empty_ones
,
1022 &priv
->lec_no_forward
,
1028 for (q
= state
->misc_table
; q
< ARRAY_SIZE(lec_misc_tables
); q
++) {
1029 v
= lec_tbl_walk(state
, lec_misc_tables
[q
], l
);
1033 state
->misc_table
= q
;
1037 static void *lec_priv_walk(struct lec_state
*state
, loff_t
*l
,
1038 struct lec_priv
*priv
)
1040 if (!state
->locked
) {
1041 state
->locked
= priv
;
1042 spin_lock_irqsave(&priv
->lec_arp_lock
, state
->flags
);
1044 if (!lec_arp_walk(state
, l
, priv
) && !lec_misc_walk(state
, l
, priv
)) {
1045 spin_unlock_irqrestore(&priv
->lec_arp_lock
, state
->flags
);
1046 state
->locked
= NULL
;
1047 /* Partial state reset for the next time we get called */
1048 state
->arp_table
= state
->misc_table
= 0;
1050 return state
->locked
;
1053 static void *lec_itf_walk(struct lec_state
*state
, loff_t
*l
)
1055 struct net_device
*dev
;
1058 dev
= state
->dev
? state
->dev
: dev_lec
[state
->itf
];
1059 v
= (dev
&& netdev_priv(dev
)) ?
1060 lec_priv_walk(state
, l
, netdev_priv(dev
)) : NULL
;
1063 /* Partial state reset for the next time we get called */
1070 static void *lec_get_idx(struct lec_state
*state
, loff_t l
)
1074 for (; state
->itf
< MAX_LEC_ITF
; state
->itf
++) {
1075 v
= lec_itf_walk(state
, &l
);
1082 static void *lec_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1084 struct lec_state
*state
= seq
->private;
1088 state
->locked
= NULL
;
1089 state
->arp_table
= 0;
1090 state
->misc_table
= 0;
1091 state
->node
= SEQ_START_TOKEN
;
1093 return *pos
? lec_get_idx(state
, *pos
) : SEQ_START_TOKEN
;
1096 static void lec_seq_stop(struct seq_file
*seq
, void *v
)
1098 struct lec_state
*state
= seq
->private;
1101 spin_unlock_irqrestore(&state
->locked
->lec_arp_lock
,
1103 dev_put(state
->dev
);
1107 static void *lec_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1109 struct lec_state
*state
= seq
->private;
1111 v
= lec_get_idx(state
, 1);
1112 *pos
+= !!PTR_ERR(v
);
1116 static int lec_seq_show(struct seq_file
*seq
, void *v
)
1118 static const char lec_banner
[] =
1119 "Itf MAC ATM destination"
1121 "VPI/VCI Recv VPI/VCI\n";
1123 if (v
== SEQ_START_TOKEN
)
1124 seq_puts(seq
, lec_banner
);
1126 struct lec_state
*state
= seq
->private;
1127 struct net_device
*dev
= state
->dev
;
1128 struct lec_arp_table
*entry
= hlist_entry(state
->node
, struct lec_arp_table
, next
);
1130 seq_printf(seq
, "%s ", dev
->name
);
1131 lec_info(seq
, entry
);
1136 static const struct seq_operations lec_seq_ops
= {
1137 .start
= lec_seq_start
,
1138 .next
= lec_seq_next
,
1139 .stop
= lec_seq_stop
,
1140 .show
= lec_seq_show
,
1143 static int lec_seq_open(struct inode
*inode
, struct file
*file
)
1145 return seq_open_private(file
, &lec_seq_ops
, sizeof(struct lec_state
));
1148 static const struct file_operations lec_seq_fops
= {
1149 .owner
= THIS_MODULE
,
1150 .open
= lec_seq_open
,
1152 .llseek
= seq_lseek
,
1153 .release
= seq_release_private
,
1157 static int lane_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1159 struct atm_vcc
*vcc
= ATM_SD(sock
);
1166 if (!capable(CAP_NET_ADMIN
))
1170 return -ENOIOCTLCMD
;
1175 err
= lecd_attach(vcc
, (int)arg
);
1177 sock
->state
= SS_CONNECTED
;
1180 err
= lec_mcast_attach(vcc
, (int)arg
);
1183 err
= lec_vcc_attach(vcc
, (void __user
*)arg
);
1190 static struct atm_ioctl lane_ioctl_ops
= {
1191 .owner
= THIS_MODULE
,
1192 .ioctl
= lane_ioctl
,
1195 static int __init
lane_module_init(void)
1197 #ifdef CONFIG_PROC_FS
1198 struct proc_dir_entry
*p
;
1200 p
= proc_create("lec", S_IRUGO
, atm_proc_root
, &lec_seq_fops
);
1202 printk(KERN_ERR
"Unable to initialize /proc/net/atm/lec\n");
1207 register_atm_ioctl(&lane_ioctl_ops
);
1208 printk("lec.c: " __DATE__
" " __TIME__
" initialized\n");
1212 static void __exit
lane_module_cleanup(void)
1215 struct lec_priv
*priv
;
1217 remove_proc_entry("lec", atm_proc_root
);
1219 deregister_atm_ioctl(&lane_ioctl_ops
);
1221 for (i
= 0; i
< MAX_LEC_ITF
; i
++) {
1222 if (dev_lec
[i
] != NULL
) {
1223 priv
= netdev_priv(dev_lec
[i
]);
1224 unregister_netdev(dev_lec
[i
]);
1225 free_netdev(dev_lec
[i
]);
1233 module_init(lane_module_init
);
1234 module_exit(lane_module_cleanup
);
1237 * LANE2: 3.1.3, LE_RESOLVE.request
1238 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1239 * If sizeoftlvs == NULL the default TLVs associated with with this
1241 * If dst_mac == NULL, targetless LE_ARP will be sent
1243 static int lane2_resolve(struct net_device
*dev
, const u8
*dst_mac
, int force
,
1244 u8
**tlvs
, u32
*sizeoftlvs
)
1246 unsigned long flags
;
1247 struct lec_priv
*priv
= netdev_priv(dev
);
1248 struct lec_arp_table
*table
;
1249 struct sk_buff
*skb
;
1253 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1254 table
= lec_arp_find(priv
, dst_mac
);
1255 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1259 *tlvs
= kmemdup(table
->tlvs
, table
->sizeoftlvs
, GFP_ATOMIC
);
1263 *sizeoftlvs
= table
->sizeoftlvs
;
1268 if (sizeoftlvs
== NULL
)
1269 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, NULL
);
1272 skb
= alloc_skb(*sizeoftlvs
, GFP_ATOMIC
);
1275 skb
->len
= *sizeoftlvs
;
1276 skb_copy_to_linear_data(skb
, *tlvs
, *sizeoftlvs
);
1277 retval
= send_to_lecd(priv
, l_arp_xmt
, dst_mac
, NULL
, skb
);
1283 * LANE2: 3.1.4, LE_ASSOCIATE.request
1284 * Associate the *tlvs with the *lan_dst address.
1285 * Will overwrite any previous association
1286 * Returns 1 for success, 0 for failure (out of memory)
1289 static int lane2_associate_req(struct net_device
*dev
, const u8
*lan_dst
,
1290 const u8
*tlvs
, u32 sizeoftlvs
)
1293 struct sk_buff
*skb
;
1294 struct lec_priv
*priv
= netdev_priv(dev
);
1296 if (compare_ether_addr(lan_dst
, dev
->dev_addr
))
1297 return (0); /* not our mac address */
1299 kfree(priv
->tlvs
); /* NULL if there was no previous association */
1301 priv
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1302 if (priv
->tlvs
== NULL
)
1304 priv
->sizeoftlvs
= sizeoftlvs
;
1306 skb
= alloc_skb(sizeoftlvs
, GFP_ATOMIC
);
1309 skb
->len
= sizeoftlvs
;
1310 skb_copy_to_linear_data(skb
, tlvs
, sizeoftlvs
);
1311 retval
= send_to_lecd(priv
, l_associate_req
, NULL
, NULL
, skb
);
1313 printk("lec.c: lane2_associate_req() failed\n");
1315 * If the previous association has changed we must
1316 * somehow notify other LANE entities about the change
1322 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1325 static void lane2_associate_ind(struct net_device
*dev
, const u8
*mac_addr
,
1326 const u8
*tlvs
, u32 sizeoftlvs
)
1331 struct lec_priv
*priv
= netdev_priv(dev
);
1333 * Why have the TLVs in LE_ARP entries
1334 * since we do not use them? When you
1335 * uncomment this code, make sure the
1336 * TLVs get freed when entry is killed
1338 struct lec_arp_table
*entry
= lec_arp_find(priv
, mac_addr
);
1341 return; /* should not happen */
1345 entry
->tlvs
= kmemdup(tlvs
, sizeoftlvs
, GFP_KERNEL
);
1346 if (entry
->tlvs
== NULL
)
1348 entry
->sizeoftlvs
= sizeoftlvs
;
1351 printk("lec.c: lane2_associate_ind()\n");
1352 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs
);
1353 while (i
< sizeoftlvs
)
1354 printk("%02x ", tlvs
[i
++]);
1359 /* tell MPOA about the TLVs we saw */
1360 if (priv
->lane2_ops
&& priv
->lane2_ops
->associate_indicator
) {
1361 priv
->lane2_ops
->associate_indicator(dev
, mac_addr
,
1368 * Here starts what used to lec_arpc.c
1370 * lec_arpc.c was added here when making
1371 * lane client modular. October 1997
1374 #include <linux/types.h>
1375 #include <linux/timer.h>
1376 #include <asm/param.h>
1377 #include <asm/atomic.h>
1378 #include <linux/inetdevice.h>
1379 #include <net/route.h>
1382 #define pr_debug(format,args...)
1384 #define pr_debug printk
1387 #define DEBUG_ARP_TABLE 0
1389 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1391 static void lec_arp_check_expire(struct work_struct
*work
);
1392 static void lec_arp_expire_arp(unsigned long data
);
1398 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1401 * Initialization of arp-cache
1403 static void lec_arp_init(struct lec_priv
*priv
)
1407 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1408 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1410 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1411 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1412 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1413 spin_lock_init(&priv
->lec_arp_lock
);
1414 INIT_DELAYED_WORK(&priv
->lec_arp_work
, lec_arp_check_expire
);
1415 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1418 static void lec_arp_clear_vccs(struct lec_arp_table
*entry
)
1421 struct atm_vcc
*vcc
= entry
->vcc
;
1422 struct lec_vcc_priv
*vpriv
= LEC_VCC_PRIV(vcc
);
1423 struct net_device
*dev
= (struct net_device
*)vcc
->proto_data
;
1425 vcc
->pop
= vpriv
->old_pop
;
1427 netif_wake_queue(dev
);
1429 vcc
->user_back
= NULL
;
1430 vcc
->push
= entry
->old_push
;
1431 vcc_release_async(vcc
, -EPIPE
);
1434 if (entry
->recv_vcc
) {
1435 entry
->recv_vcc
->push
= entry
->old_recv_push
;
1436 vcc_release_async(entry
->recv_vcc
, -EPIPE
);
1437 entry
->recv_vcc
= NULL
;
1442 * Insert entry to lec_arp_table
1443 * LANE2: Add to the end of the list to satisfy 8.1.13
1446 lec_arp_add(struct lec_priv
*priv
, struct lec_arp_table
*entry
)
1448 struct hlist_head
*tmp
;
1450 tmp
= &priv
->lec_arp_tables
[HASH(entry
->mac_addr
[ETH_ALEN
- 1])];
1451 hlist_add_head(&entry
->next
, tmp
);
1453 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1454 0xff & entry
->mac_addr
[0], 0xff & entry
->mac_addr
[1],
1455 0xff & entry
->mac_addr
[2], 0xff & entry
->mac_addr
[3],
1456 0xff & entry
->mac_addr
[4], 0xff & entry
->mac_addr
[5]);
1460 * Remove entry from lec_arp_table
1463 lec_arp_remove(struct lec_priv
*priv
, struct lec_arp_table
*to_remove
)
1465 struct hlist_node
*node
;
1466 struct lec_arp_table
*entry
;
1467 int i
, remove_vcc
= 1;
1473 hlist_del(&to_remove
->next
);
1474 del_timer(&to_remove
->timer
);
1476 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1477 if (to_remove
->status
>= ESI_FLUSH_PENDING
) {
1479 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1481 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1482 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
1483 if (memcmp(to_remove
->atm_addr
,
1484 entry
->atm_addr
, ATM_ESA_LEN
) == 0) {
1491 lec_arp_clear_vccs(to_remove
);
1493 skb_queue_purge(&to_remove
->tx_wait
); /* FIXME: good place for this? */
1495 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1496 0xff & to_remove
->mac_addr
[0], 0xff & to_remove
->mac_addr
[1],
1497 0xff & to_remove
->mac_addr
[2], 0xff & to_remove
->mac_addr
[3],
1498 0xff & to_remove
->mac_addr
[4], 0xff & to_remove
->mac_addr
[5]);
1503 static const char *get_status_string(unsigned char st
)
1507 return "ESI_UNKNOWN";
1508 case ESI_ARP_PENDING
:
1509 return "ESI_ARP_PENDING";
1510 case ESI_VC_PENDING
:
1511 return "ESI_VC_PENDING";
1512 case ESI_FLUSH_PENDING
:
1513 return "ESI_FLUSH_PENDING";
1514 case ESI_FORWARD_DIRECT
:
1515 return "ESI_FORWARD_DIRECT";
1521 static void dump_arp_table(struct lec_priv
*priv
)
1523 struct hlist_node
*node
;
1524 struct lec_arp_table
*rulla
;
1528 printk("Dump %p:\n", priv
);
1529 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1530 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_tables
[i
], next
) {
1532 offset
+= sprintf(buf
, "%d: %p\n", i
, rulla
);
1533 offset
+= sprintf(buf
+ offset
, "Mac:");
1534 for (j
= 0; j
< ETH_ALEN
; j
++) {
1535 offset
+= sprintf(buf
+ offset
,
1537 rulla
->mac_addr
[j
] & 0xff);
1539 offset
+= sprintf(buf
+ offset
, "Atm:");
1540 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1541 offset
+= sprintf(buf
+ offset
,
1543 rulla
->atm_addr
[j
] & 0xff);
1545 offset
+= sprintf(buf
+ offset
,
1546 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1547 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1548 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1549 rulla
->recv_vcc
? rulla
->recv_vcc
->
1551 rulla
->recv_vcc
? rulla
->recv_vcc
->
1552 vci
: 0, rulla
->last_used
,
1553 rulla
->timestamp
, rulla
->no_tries
);
1555 sprintf(buf
+ offset
,
1556 "Flags:%x, Packets_flooded:%x, Status: %s ",
1557 rulla
->flags
, rulla
->packets_flooded
,
1558 get_status_string(rulla
->status
));
1559 printk("%s\n", buf
);
1563 if (!hlist_empty(&priv
->lec_no_forward
))
1564 printk("No forward\n");
1565 hlist_for_each_entry(rulla
, node
, &priv
->lec_no_forward
, next
) {
1567 offset
+= sprintf(buf
+ offset
, "Mac:");
1568 for (j
= 0; j
< ETH_ALEN
; j
++) {
1569 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1570 rulla
->mac_addr
[j
] & 0xff);
1572 offset
+= sprintf(buf
+ offset
, "Atm:");
1573 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1574 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1575 rulla
->atm_addr
[j
] & 0xff);
1577 offset
+= sprintf(buf
+ offset
,
1578 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1579 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1580 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1581 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1582 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1584 rulla
->timestamp
, rulla
->no_tries
);
1585 offset
+= sprintf(buf
+ offset
,
1586 "Flags:%x, Packets_flooded:%x, Status: %s ",
1587 rulla
->flags
, rulla
->packets_flooded
,
1588 get_status_string(rulla
->status
));
1589 printk("%s\n", buf
);
1592 if (!hlist_empty(&priv
->lec_arp_empty_ones
))
1593 printk("Empty ones\n");
1594 hlist_for_each_entry(rulla
, node
, &priv
->lec_arp_empty_ones
, next
) {
1596 offset
+= sprintf(buf
+ offset
, "Mac:");
1597 for (j
= 0; j
< ETH_ALEN
; j
++) {
1598 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1599 rulla
->mac_addr
[j
] & 0xff);
1601 offset
+= sprintf(buf
+ offset
, "Atm:");
1602 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1603 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1604 rulla
->atm_addr
[j
] & 0xff);
1606 offset
+= sprintf(buf
+ offset
,
1607 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1608 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1609 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1610 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1611 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1613 rulla
->timestamp
, rulla
->no_tries
);
1614 offset
+= sprintf(buf
+ offset
,
1615 "Flags:%x, Packets_flooded:%x, Status: %s ",
1616 rulla
->flags
, rulla
->packets_flooded
,
1617 get_status_string(rulla
->status
));
1621 if (!hlist_empty(&priv
->mcast_fwds
))
1622 printk("Multicast Forward VCCs\n");
1623 hlist_for_each_entry(rulla
, node
, &priv
->mcast_fwds
, next
) {
1625 offset
+= sprintf(buf
+ offset
, "Mac:");
1626 for (j
= 0; j
< ETH_ALEN
; j
++) {
1627 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1628 rulla
->mac_addr
[j
] & 0xff);
1630 offset
+= sprintf(buf
+ offset
, "Atm:");
1631 for (j
= 0; j
< ATM_ESA_LEN
; j
++) {
1632 offset
+= sprintf(buf
+ offset
, "%2.2x ",
1633 rulla
->atm_addr
[j
] & 0xff);
1635 offset
+= sprintf(buf
+ offset
,
1636 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1637 rulla
->vcc
? rulla
->vcc
->vpi
: 0,
1638 rulla
->vcc
? rulla
->vcc
->vci
: 0,
1639 rulla
->recv_vcc
? rulla
->recv_vcc
->vpi
: 0,
1640 rulla
->recv_vcc
? rulla
->recv_vcc
->vci
: 0,
1642 rulla
->timestamp
, rulla
->no_tries
);
1643 offset
+= sprintf(buf
+ offset
,
1644 "Flags:%x, Packets_flooded:%x, Status: %s ",
1645 rulla
->flags
, rulla
->packets_flooded
,
1646 get_status_string(rulla
->status
));
1647 printk("%s\n", buf
);
1652 #define dump_arp_table(priv) do { } while (0)
1656 * Destruction of arp-cache
1658 static void lec_arp_destroy(struct lec_priv
*priv
)
1660 unsigned long flags
;
1661 struct hlist_node
*node
, *next
;
1662 struct lec_arp_table
*entry
;
1665 cancel_rearming_delayed_work(&priv
->lec_arp_work
);
1668 * Remove all entries
1671 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1672 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1673 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1674 lec_arp_remove(priv
, entry
);
1677 INIT_HLIST_HEAD(&priv
->lec_arp_tables
[i
]);
1680 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
1681 del_timer_sync(&entry
->timer
);
1682 lec_arp_clear_vccs(entry
);
1683 hlist_del(&entry
->next
);
1686 INIT_HLIST_HEAD(&priv
->lec_arp_empty_ones
);
1688 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
1689 del_timer_sync(&entry
->timer
);
1690 lec_arp_clear_vccs(entry
);
1691 hlist_del(&entry
->next
);
1694 INIT_HLIST_HEAD(&priv
->lec_no_forward
);
1696 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
1697 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1698 lec_arp_clear_vccs(entry
);
1699 hlist_del(&entry
->next
);
1702 INIT_HLIST_HEAD(&priv
->mcast_fwds
);
1703 priv
->mcast_vcc
= NULL
;
1704 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1708 * Find entry by mac_address
1710 static struct lec_arp_table
*lec_arp_find(struct lec_priv
*priv
,
1711 const unsigned char *mac_addr
)
1713 struct hlist_node
*node
;
1714 struct hlist_head
*head
;
1715 struct lec_arp_table
*entry
;
1717 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1718 mac_addr
[0] & 0xff, mac_addr
[1] & 0xff, mac_addr
[2] & 0xff,
1719 mac_addr
[3] & 0xff, mac_addr
[4] & 0xff, mac_addr
[5] & 0xff);
1721 head
= &priv
->lec_arp_tables
[HASH(mac_addr
[ETH_ALEN
- 1])];
1722 hlist_for_each_entry(entry
, node
, head
, next
) {
1723 if (!compare_ether_addr(mac_addr
, entry
->mac_addr
)) {
1730 static struct lec_arp_table
*make_entry(struct lec_priv
*priv
,
1731 const unsigned char *mac_addr
)
1733 struct lec_arp_table
*to_return
;
1735 to_return
= kzalloc(sizeof(struct lec_arp_table
), GFP_ATOMIC
);
1737 printk("LEC: Arp entry kmalloc failed\n");
1740 memcpy(to_return
->mac_addr
, mac_addr
, ETH_ALEN
);
1741 INIT_HLIST_NODE(&to_return
->next
);
1742 setup_timer(&to_return
->timer
, lec_arp_expire_arp
,
1743 (unsigned long)to_return
);
1744 to_return
->last_used
= jiffies
;
1745 to_return
->priv
= priv
;
1746 skb_queue_head_init(&to_return
->tx_wait
);
1747 atomic_set(&to_return
->usage
, 1);
1751 /* Arp sent timer expired */
1752 static void lec_arp_expire_arp(unsigned long data
)
1754 struct lec_arp_table
*entry
;
1756 entry
= (struct lec_arp_table
*)data
;
1758 pr_debug("lec_arp_expire_arp\n");
1759 if (entry
->status
== ESI_ARP_PENDING
) {
1760 if (entry
->no_tries
<= entry
->priv
->max_retry_count
) {
1761 if (entry
->is_rdesc
)
1762 send_to_lecd(entry
->priv
, l_rdesc_arp_xmt
,
1763 entry
->mac_addr
, NULL
, NULL
);
1765 send_to_lecd(entry
->priv
, l_arp_xmt
,
1766 entry
->mac_addr
, NULL
, NULL
);
1769 mod_timer(&entry
->timer
, jiffies
+ (1 * HZ
));
1773 /* Unknown/unused vcc expire, remove associated entry */
1774 static void lec_arp_expire_vcc(unsigned long data
)
1776 unsigned long flags
;
1777 struct lec_arp_table
*to_remove
= (struct lec_arp_table
*)data
;
1778 struct lec_priv
*priv
= (struct lec_priv
*)to_remove
->priv
;
1780 del_timer(&to_remove
->timer
);
1782 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1784 to_remove
->vcc
? to_remove
->recv_vcc
->vpi
: 0,
1785 to_remove
->vcc
? to_remove
->recv_vcc
->vci
: 0);
1787 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1788 hlist_del(&to_remove
->next
);
1789 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1791 lec_arp_clear_vccs(to_remove
);
1792 lec_arp_put(to_remove
);
1798 * 2. For each entry, delete entries that have aged past the age limit.
1799 * 3. For each entry, depending on the status of the entry, perform
1800 * the following maintenance.
1801 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1802 * tick_count is above the max_unknown_frame_time, clear
1803 * the tick_count to zero and clear the packets_flooded counter
1804 * to zero. This supports the packet rate limit per address
1805 * while flooding unknowns.
1806 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1807 * than or equal to the path_switching_delay, change the status
1808 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1809 * regardless of the progress of the flush protocol.
1811 static void lec_arp_check_expire(struct work_struct
*work
)
1813 unsigned long flags
;
1814 struct lec_priv
*priv
=
1815 container_of(work
, struct lec_priv
, lec_arp_work
.work
);
1816 struct hlist_node
*node
, *next
;
1817 struct lec_arp_table
*entry
;
1819 unsigned long time_to_check
;
1822 pr_debug("lec_arp_check_expire %p\n", priv
);
1825 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1826 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1827 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1828 if ((entry
->flags
) & LEC_REMOTE_FLAG
&&
1829 priv
->topology_change
)
1830 time_to_check
= priv
->forward_delay_time
;
1832 time_to_check
= priv
->aging_time
;
1834 pr_debug("About to expire: %lx - %lx > %lx\n",
1835 now
, entry
->last_used
, time_to_check
);
1836 if (time_after(now
, entry
->last_used
+ time_to_check
)
1837 && !(entry
->flags
& LEC_PERMANENT_FLAG
)
1838 && !(entry
->mac_addr
[0] & 0x01)) { /* LANE2: 7.1.20 */
1840 pr_debug("LEC:Entry timed out\n");
1841 lec_arp_remove(priv
, entry
);
1844 /* Something else */
1845 if ((entry
->status
== ESI_VC_PENDING
||
1846 entry
->status
== ESI_ARP_PENDING
)
1847 && time_after_eq(now
,
1850 max_unknown_frame_time
)) {
1851 entry
->timestamp
= jiffies
;
1852 entry
->packets_flooded
= 0;
1853 if (entry
->status
== ESI_VC_PENDING
)
1854 send_to_lecd(priv
, l_svc_setup
,
1859 if (entry
->status
== ESI_FLUSH_PENDING
1861 time_after_eq(now
, entry
->timestamp
+
1862 priv
->path_switching_delay
)) {
1863 struct sk_buff
*skb
;
1864 struct atm_vcc
*vcc
= entry
->vcc
;
1866 lec_arp_hold(entry
);
1867 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1868 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
1870 entry
->last_used
= jiffies
;
1871 entry
->status
= ESI_FORWARD_DIRECT
;
1878 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1880 schedule_delayed_work(&priv
->lec_arp_work
, LEC_ARP_REFRESH_INTERVAL
);
1884 * Try to find vcc where mac_address is attached.
1887 static struct atm_vcc
*lec_arp_resolve(struct lec_priv
*priv
,
1888 const unsigned char *mac_to_find
, int is_rdesc
,
1889 struct lec_arp_table
**ret_entry
)
1891 unsigned long flags
;
1892 struct lec_arp_table
*entry
;
1893 struct atm_vcc
*found
;
1895 if (mac_to_find
[0] & 0x01) {
1896 switch (priv
->lane_version
) {
1898 return priv
->mcast_vcc
;
1899 case 2: /* LANE2 wants arp for multicast addresses */
1900 if (!compare_ether_addr(mac_to_find
, bus_mac
))
1901 return priv
->mcast_vcc
;
1908 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1909 entry
= lec_arp_find(priv
, mac_to_find
);
1912 if (entry
->status
== ESI_FORWARD_DIRECT
) {
1914 entry
->last_used
= jiffies
;
1915 lec_arp_hold(entry
);
1921 * If the LE_ARP cache entry is still pending, reset count to 0
1922 * so another LE_ARP request can be made for this frame.
1924 if (entry
->status
== ESI_ARP_PENDING
) {
1925 entry
->no_tries
= 0;
1928 * Data direct VC not yet set up, check to see if the unknown
1929 * frame count is greater than the limit. If the limit has
1930 * not been reached, allow the caller to send packet to
1933 if (entry
->status
!= ESI_FLUSH_PENDING
&&
1934 entry
->packets_flooded
<
1935 priv
->maximum_unknown_frame_count
) {
1936 entry
->packets_flooded
++;
1937 pr_debug("LEC_ARP: Flooding..\n");
1938 found
= priv
->mcast_vcc
;
1942 * We got here because entry->status == ESI_FLUSH_PENDING
1943 * or BUS flood limit was reached for an entry which is
1944 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1946 lec_arp_hold(entry
);
1948 pr_debug("lec: entry->status %d entry->vcc %p\n", entry
->status
,
1952 /* No matching entry was found */
1953 entry
= make_entry(priv
, mac_to_find
);
1954 pr_debug("LEC_ARP: Making entry\n");
1956 found
= priv
->mcast_vcc
;
1959 lec_arp_add(priv
, entry
);
1960 /* We want arp-request(s) to be sent */
1961 entry
->packets_flooded
= 1;
1962 entry
->status
= ESI_ARP_PENDING
;
1963 entry
->no_tries
= 1;
1964 entry
->last_used
= entry
->timestamp
= jiffies
;
1965 entry
->is_rdesc
= is_rdesc
;
1966 if (entry
->is_rdesc
)
1967 send_to_lecd(priv
, l_rdesc_arp_xmt
, mac_to_find
, NULL
,
1970 send_to_lecd(priv
, l_arp_xmt
, mac_to_find
, NULL
, NULL
);
1971 entry
->timer
.expires
= jiffies
+ (1 * HZ
);
1972 entry
->timer
.function
= lec_arp_expire_arp
;
1973 add_timer(&entry
->timer
);
1974 found
= priv
->mcast_vcc
;
1978 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
1983 lec_addr_delete(struct lec_priv
*priv
, const unsigned char *atm_addr
,
1984 unsigned long permanent
)
1986 unsigned long flags
;
1987 struct hlist_node
*node
, *next
;
1988 struct lec_arp_table
*entry
;
1991 pr_debug("lec_addr_delete\n");
1992 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
1993 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
1994 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
1995 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)
1997 !(entry
->flags
& LEC_PERMANENT_FLAG
))) {
1998 lec_arp_remove(priv
, entry
);
2001 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2005 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2010 * Notifies: Response to arp_request (atm_addr != NULL)
2013 lec_arp_update(struct lec_priv
*priv
, const unsigned char *mac_addr
,
2014 const unsigned char *atm_addr
, unsigned long remoteflag
,
2015 unsigned int targetless_le_arp
)
2017 unsigned long flags
;
2018 struct hlist_node
*node
, *next
;
2019 struct lec_arp_table
*entry
, *tmp
;
2022 pr_debug("lec:%s", (targetless_le_arp
) ? "targetless " : " ");
2023 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2024 mac_addr
[0], mac_addr
[1], mac_addr
[2], mac_addr
[3],
2025 mac_addr
[4], mac_addr
[5]);
2027 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2028 entry
= lec_arp_find(priv
, mac_addr
);
2029 if (entry
== NULL
&& targetless_le_arp
)
2031 * LANE2: ignore targetless LE_ARPs for which
2032 * we have no entry in the cache. 7.1.30
2034 if (!hlist_empty(&priv
->lec_arp_empty_ones
)) {
2035 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2036 if (memcmp(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
) == 0) {
2037 hlist_del(&entry
->next
);
2038 del_timer(&entry
->timer
);
2039 tmp
= lec_arp_find(priv
, mac_addr
);
2041 del_timer(&tmp
->timer
);
2042 tmp
->status
= ESI_FORWARD_DIRECT
;
2043 memcpy(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2044 tmp
->vcc
= entry
->vcc
;
2045 tmp
->old_push
= entry
->old_push
;
2046 tmp
->last_used
= jiffies
;
2047 del_timer(&entry
->timer
);
2051 entry
->status
= ESI_FORWARD_DIRECT
;
2052 memcpy(entry
->mac_addr
, mac_addr
, ETH_ALEN
);
2053 entry
->last_used
= jiffies
;
2054 lec_arp_add(priv
, entry
);
2057 entry
->flags
|= LEC_REMOTE_FLAG
;
2059 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2060 pr_debug("After update\n");
2061 dump_arp_table(priv
);
2067 entry
= lec_arp_find(priv
, mac_addr
);
2069 entry
= make_entry(priv
, mac_addr
);
2072 entry
->status
= ESI_UNKNOWN
;
2073 lec_arp_add(priv
, entry
);
2074 /* Temporary, changes before end of function */
2076 memcpy(entry
->atm_addr
, atm_addr
, ATM_ESA_LEN
);
2077 del_timer(&entry
->timer
);
2078 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2079 hlist_for_each_entry(tmp
, node
, &priv
->lec_arp_tables
[i
], next
) {
2081 !memcmp(tmp
->atm_addr
, atm_addr
, ATM_ESA_LEN
)) {
2082 /* Vcc to this host exists */
2083 if (tmp
->status
> ESI_VC_PENDING
) {
2085 * ESI_FLUSH_PENDING,
2086 * ESI_FORWARD_DIRECT
2088 entry
->vcc
= tmp
->vcc
;
2089 entry
->old_push
= tmp
->old_push
;
2091 entry
->status
= tmp
->status
;
2097 entry
->flags
|= LEC_REMOTE_FLAG
;
2099 entry
->flags
&= ~LEC_REMOTE_FLAG
;
2100 if (entry
->status
== ESI_ARP_PENDING
|| entry
->status
== ESI_UNKNOWN
) {
2101 entry
->status
= ESI_VC_PENDING
;
2102 send_to_lecd(priv
, l_svc_setup
, entry
->mac_addr
, atm_addr
, NULL
);
2104 pr_debug("After update2\n");
2105 dump_arp_table(priv
);
2107 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2111 * Notifies: Vcc setup ready
2114 lec_vcc_added(struct lec_priv
*priv
, const struct atmlec_ioc
*ioc_data
,
2115 struct atm_vcc
*vcc
,
2116 void (*old_push
) (struct atm_vcc
*vcc
, struct sk_buff
*skb
))
2118 unsigned long flags
;
2119 struct hlist_node
*node
;
2120 struct lec_arp_table
*entry
;
2121 int i
, found_entry
= 0;
2123 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2124 if (ioc_data
->receive
== 2) {
2125 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2127 pr_debug("LEC_ARP: Attaching mcast forward\n");
2129 entry
= lec_arp_find(priv
, bus_mac
);
2131 printk("LEC_ARP: Multicast entry not found!\n");
2134 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2135 entry
->recv_vcc
= vcc
;
2136 entry
->old_recv_push
= old_push
;
2138 entry
= make_entry(priv
, bus_mac
);
2141 del_timer(&entry
->timer
);
2142 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2143 entry
->recv_vcc
= vcc
;
2144 entry
->old_recv_push
= old_push
;
2145 hlist_add_head(&entry
->next
, &priv
->mcast_fwds
);
2147 } else if (ioc_data
->receive
== 1) {
2149 * Vcc which we don't want to make default vcc,
2153 ("LEC_ARP:Attaching data direct, not default: "
2154 "%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",
2155 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2156 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2157 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2158 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2159 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2160 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2161 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2162 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2163 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2164 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2165 entry
= make_entry(priv
, bus_mac
);
2168 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2169 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2170 entry
->recv_vcc
= vcc
;
2171 entry
->old_recv_push
= old_push
;
2172 entry
->status
= ESI_UNKNOWN
;
2173 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2174 entry
->timer
.function
= lec_arp_expire_vcc
;
2175 hlist_add_head(&entry
->next
, &priv
->lec_no_forward
);
2176 add_timer(&entry
->timer
);
2177 dump_arp_table(priv
);
2181 ("LEC_ARP:Attaching data direct, default: "
2182 "%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",
2183 ioc_data
->atm_addr
[0], ioc_data
->atm_addr
[1],
2184 ioc_data
->atm_addr
[2], ioc_data
->atm_addr
[3],
2185 ioc_data
->atm_addr
[4], ioc_data
->atm_addr
[5],
2186 ioc_data
->atm_addr
[6], ioc_data
->atm_addr
[7],
2187 ioc_data
->atm_addr
[8], ioc_data
->atm_addr
[9],
2188 ioc_data
->atm_addr
[10], ioc_data
->atm_addr
[11],
2189 ioc_data
->atm_addr
[12], ioc_data
->atm_addr
[13],
2190 ioc_data
->atm_addr
[14], ioc_data
->atm_addr
[15],
2191 ioc_data
->atm_addr
[16], ioc_data
->atm_addr
[17],
2192 ioc_data
->atm_addr
[18], ioc_data
->atm_addr
[19]);
2193 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2194 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2196 (ioc_data
->atm_addr
, entry
->atm_addr
,
2197 ATM_ESA_LEN
) == 0) {
2198 pr_debug("LEC_ARP: Attaching data direct\n");
2199 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2200 entry
->vcc
? entry
->vcc
->vci
: 0,
2201 entry
->recv_vcc
? entry
->recv_vcc
->
2204 del_timer(&entry
->timer
);
2206 entry
->old_push
= old_push
;
2207 if (entry
->status
== ESI_VC_PENDING
) {
2208 if (priv
->maximum_unknown_frame_count
2213 entry
->timestamp
= jiffies
;
2217 send_to_lecd(priv
, l_flush_xmt
,
2225 * They were forming a connection
2226 * to us, and we to them. Our
2227 * ATM address is numerically lower
2228 * than theirs, so we make connection
2229 * we formed into default VCC (8.1.11).
2230 * Connection they made gets torn
2231 * down. This might confuse some
2232 * clients. Can be changed if
2233 * someone reports trouble...
2241 pr_debug("After vcc was added\n");
2242 dump_arp_table(priv
);
2246 * Not found, snatch address from first data packet that arrives
2249 entry
= make_entry(priv
, bus_mac
);
2253 entry
->old_push
= old_push
;
2254 memcpy(entry
->atm_addr
, ioc_data
->atm_addr
, ATM_ESA_LEN
);
2255 memset(entry
->mac_addr
, 0, ETH_ALEN
);
2256 entry
->status
= ESI_UNKNOWN
;
2257 hlist_add_head(&entry
->next
, &priv
->lec_arp_empty_ones
);
2258 entry
->timer
.expires
= jiffies
+ priv
->vcc_timeout_period
;
2259 entry
->timer
.function
= lec_arp_expire_vcc
;
2260 add_timer(&entry
->timer
);
2261 pr_debug("After vcc was added\n");
2262 dump_arp_table(priv
);
2264 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2267 static void lec_flush_complete(struct lec_priv
*priv
, unsigned long tran_id
)
2269 unsigned long flags
;
2270 struct hlist_node
*node
;
2271 struct lec_arp_table
*entry
;
2274 pr_debug("LEC:lec_flush_complete %lx\n", tran_id
);
2276 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2277 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2278 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2279 if (entry
->flush_tran_id
== tran_id
2280 && entry
->status
== ESI_FLUSH_PENDING
) {
2281 struct sk_buff
*skb
;
2282 struct atm_vcc
*vcc
= entry
->vcc
;
2284 lec_arp_hold(entry
);
2285 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2286 while ((skb
= skb_dequeue(&entry
->tx_wait
)) != NULL
)
2288 entry
->last_used
= jiffies
;
2289 entry
->status
= ESI_FORWARD_DIRECT
;
2291 pr_debug("LEC_ARP: Flushed\n");
2296 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2297 dump_arp_table(priv
);
2301 lec_set_flush_tran_id(struct lec_priv
*priv
,
2302 const unsigned char *atm_addr
, unsigned long tran_id
)
2304 unsigned long flags
;
2305 struct hlist_node
*node
;
2306 struct lec_arp_table
*entry
;
2309 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2310 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++)
2311 hlist_for_each_entry(entry
, node
, &priv
->lec_arp_tables
[i
], next
) {
2312 if (!memcmp(atm_addr
, entry
->atm_addr
, ATM_ESA_LEN
)) {
2313 entry
->flush_tran_id
= tran_id
;
2314 pr_debug("Set flush transaction id to %lx for %p\n",
2318 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2321 static int lec_mcast_make(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2323 unsigned long flags
;
2324 unsigned char mac_addr
[] = {
2325 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2327 struct lec_arp_table
*to_add
;
2328 struct lec_vcc_priv
*vpriv
;
2331 if (!(vpriv
= kmalloc(sizeof(struct lec_vcc_priv
), GFP_KERNEL
)))
2334 vpriv
->old_pop
= vcc
->pop
;
2335 vcc
->user_back
= vpriv
;
2337 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2338 to_add
= make_entry(priv
, mac_addr
);
2340 vcc
->pop
= vpriv
->old_pop
;
2345 memcpy(to_add
->atm_addr
, vcc
->remote
.sas_addr
.prv
, ATM_ESA_LEN
);
2346 to_add
->status
= ESI_FORWARD_DIRECT
;
2347 to_add
->flags
|= LEC_PERMANENT_FLAG
;
2349 to_add
->old_push
= vcc
->push
;
2350 vcc
->push
= lec_push
;
2351 priv
->mcast_vcc
= vcc
;
2352 lec_arp_add(priv
, to_add
);
2354 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2358 static void lec_vcc_close(struct lec_priv
*priv
, struct atm_vcc
*vcc
)
2360 unsigned long flags
;
2361 struct hlist_node
*node
, *next
;
2362 struct lec_arp_table
*entry
;
2365 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc
->vpi
, vcc
->vci
);
2366 dump_arp_table(priv
);
2368 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2370 for (i
= 0; i
< LEC_ARP_TABLE_SIZE
; i
++) {
2371 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_tables
[i
], next
) {
2372 if (vcc
== entry
->vcc
) {
2373 lec_arp_remove(priv
, entry
);
2375 if (priv
->mcast_vcc
== vcc
) {
2376 priv
->mcast_vcc
= NULL
;
2382 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2383 if (entry
->vcc
== vcc
) {
2384 lec_arp_clear_vccs(entry
);
2385 del_timer(&entry
->timer
);
2386 hlist_del(&entry
->next
);
2391 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_no_forward
, next
) {
2392 if (entry
->recv_vcc
== vcc
) {
2393 lec_arp_clear_vccs(entry
);
2394 del_timer(&entry
->timer
);
2395 hlist_del(&entry
->next
);
2400 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->mcast_fwds
, next
) {
2401 if (entry
->recv_vcc
== vcc
) {
2402 lec_arp_clear_vccs(entry
);
2403 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2404 hlist_del(&entry
->next
);
2409 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2410 dump_arp_table(priv
);
2414 lec_arp_check_empties(struct lec_priv
*priv
,
2415 struct atm_vcc
*vcc
, struct sk_buff
*skb
)
2417 unsigned long flags
;
2418 struct hlist_node
*node
, *next
;
2419 struct lec_arp_table
*entry
, *tmp
;
2420 struct lecdatahdr_8023
*hdr
= (struct lecdatahdr_8023
*)skb
->data
;
2423 struct lecdatahdr_8025
*tr_hdr
= (struct lecdatahdr_8025
*)skb
->data
;
2426 src
= tr_hdr
->h_source
;
2429 src
= hdr
->h_source
;
2431 spin_lock_irqsave(&priv
->lec_arp_lock
, flags
);
2432 hlist_for_each_entry_safe(entry
, node
, next
, &priv
->lec_arp_empty_ones
, next
) {
2433 if (vcc
== entry
->vcc
) {
2434 del_timer(&entry
->timer
);
2435 memcpy(entry
->mac_addr
, src
, ETH_ALEN
);
2436 entry
->status
= ESI_FORWARD_DIRECT
;
2437 entry
->last_used
= jiffies
;
2438 /* We might have got an entry */
2439 if ((tmp
= lec_arp_find(priv
, src
))) {
2440 lec_arp_remove(priv
, tmp
);
2443 hlist_del(&entry
->next
);
2444 lec_arp_add(priv
, entry
);
2448 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2450 spin_unlock_irqrestore(&priv
->lec_arp_lock
, flags
);
2453 MODULE_LICENSE("GPL");