Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
f7d57453 | 2 | * lec.c: Lan Emulation driver |
1da177e4 | 3 | * |
d44f7746 | 4 | * Marko Kiiskila <mkiiskila@yahoo.com> |
1da177e4 LT |
5 | */ |
6 | ||
1da177e4 LT |
7 | #include <linux/kernel.h> |
8 | #include <linux/bitops.h> | |
4fc268d2 | 9 | #include <linux/capability.h> |
1da177e4 LT |
10 | |
11 | /* We are ethernet device */ | |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/netdevice.h> | |
14 | #include <linux/etherdevice.h> | |
15 | #include <net/sock.h> | |
16 | #include <linux/skbuff.h> | |
17 | #include <linux/ip.h> | |
18 | #include <asm/byteorder.h> | |
19 | #include <asm/uaccess.h> | |
20 | #include <net/arp.h> | |
21 | #include <net/dst.h> | |
22 | #include <linux/proc_fs.h> | |
23 | #include <linux/spinlock.h> | |
1da177e4 LT |
24 | #include <linux/seq_file.h> |
25 | ||
26 | /* TokenRing if needed */ | |
27 | #ifdef CONFIG_TR | |
28 | #include <linux/trdevice.h> | |
29 | #endif | |
30 | ||
31 | /* And atm device */ | |
32 | #include <linux/atmdev.h> | |
33 | #include <linux/atmlec.h> | |
34 | ||
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" | |
39 | ||
d44f7746 | 40 | static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 }; |
1da177e4 LT |
41 | #endif |
42 | ||
43 | /* Modular too */ | |
44 | #include <linux/module.h> | |
45 | #include <linux/init.h> | |
46 | ||
47 | #include "lec.h" | |
48 | #include "lec_arpc.h" | |
49 | #include "resources.h" | |
50 | ||
d44f7746 CW |
51 | #define DUMP_PACKETS 0 /* |
52 | * 0 = None, | |
53 | * 1 = 30 first bytes | |
54 | * 2 = Whole packet | |
55 | */ | |
1da177e4 | 56 | |
d44f7746 CW |
57 | #define LEC_UNRES_QUE_LEN 8 /* |
58 | * number of tx packets to queue for a | |
59 | * single destination while waiting for SVC | |
60 | */ | |
1da177e4 LT |
61 | |
62 | static int lec_open(struct net_device *dev); | |
63 | static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
64 | static int lec_close(struct net_device *dev); | |
65 | static struct net_device_stats *lec_get_stats(struct net_device *dev); | |
66 | static void lec_init(struct net_device *dev); | |
d44f7746 CW |
67 | static struct lec_arp_table *lec_arp_find(struct lec_priv *priv, |
68 | unsigned char *mac_addr); | |
1da177e4 | 69 | static int lec_arp_remove(struct lec_priv *priv, |
d44f7746 | 70 | struct lec_arp_table *to_remove); |
1da177e4 | 71 | /* LANE2 functions */ |
d44f7746 CW |
72 | static void lane2_associate_ind(struct net_device *dev, u8 *mac_address, |
73 | u8 *tlvs, u32 sizeoftlvs); | |
1da177e4 | 74 | static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force, |
d44f7746 CW |
75 | u8 **tlvs, u32 *sizeoftlvs); |
76 | static int lane2_associate_req(struct net_device *dev, u8 *lan_dst, | |
77 | u8 *tlvs, u32 sizeoftlvs); | |
1da177e4 | 78 | |
d44f7746 | 79 | static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr, |
1da177e4 LT |
80 | unsigned long permanent); |
81 | static void lec_arp_check_empties(struct lec_priv *priv, | |
82 | struct atm_vcc *vcc, struct sk_buff *skb); | |
83 | static void lec_arp_destroy(struct lec_priv *priv); | |
84 | static void lec_arp_init(struct lec_priv *priv); | |
d44f7746 | 85 | static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv, |
1da177e4 LT |
86 | unsigned char *mac_to_find, |
87 | int is_rdesc, | |
88 | struct lec_arp_table **ret_entry); | |
89 | static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr, | |
90 | unsigned char *atm_addr, unsigned long remoteflag, | |
91 | unsigned int targetless_le_arp); | |
92 | static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id); | |
93 | static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc); | |
94 | static void lec_set_flush_tran_id(struct lec_priv *priv, | |
95 | unsigned char *atm_addr, | |
96 | unsigned long tran_id); | |
97 | static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data, | |
98 | struct atm_vcc *vcc, | |
d44f7746 CW |
99 | void (*old_push) (struct atm_vcc *vcc, |
100 | struct sk_buff *skb)); | |
1da177e4 LT |
101 | static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc); |
102 | ||
33a9c2d4 CW |
103 | /* must be done under lec_arp_lock */ |
104 | static inline void lec_arp_hold(struct lec_arp_table *entry) | |
105 | { | |
106 | atomic_inc(&entry->usage); | |
107 | } | |
108 | ||
109 | static inline void lec_arp_put(struct lec_arp_table *entry) | |
110 | { | |
111 | if (atomic_dec_and_test(&entry->usage)) | |
112 | kfree(entry); | |
113 | } | |
114 | ||
115 | ||
1da177e4 | 116 | static struct lane2_ops lane2_ops = { |
d44f7746 CW |
117 | lane2_resolve, /* resolve, spec 3.1.3 */ |
118 | lane2_associate_req, /* associate_req, spec 3.1.4 */ | |
119 | NULL /* associate indicator, spec 3.1.5 */ | |
1da177e4 LT |
120 | }; |
121 | ||
d44f7746 | 122 | static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
1da177e4 LT |
123 | |
124 | /* Device structures */ | |
125 | static struct net_device *dev_lec[MAX_LEC_ITF]; | |
126 | ||
127 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) | |
128 | static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev) | |
129 | { | |
d44f7746 CW |
130 | struct ethhdr *eth; |
131 | char *buff; | |
132 | struct lec_priv *priv; | |
133 | ||
134 | /* | |
135 | * Check if this is a BPDU. If so, ask zeppelin to send | |
136 | * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit | |
137 | * as the Config BPDU has | |
138 | */ | |
139 | eth = (struct ethhdr *)skb->data; | |
140 | buff = skb->data + skb->dev->hard_header_len; | |
141 | if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) { | |
1da177e4 | 142 | struct sock *sk; |
d44f7746 CW |
143 | struct sk_buff *skb2; |
144 | struct atmlec_msg *mesg; | |
145 | ||
146 | skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); | |
147 | if (skb2 == NULL) | |
148 | return; | |
149 | skb2->len = sizeof(struct atmlec_msg); | |
150 | mesg = (struct atmlec_msg *)skb2->data; | |
151 | mesg->type = l_topology_change; | |
152 | buff += 4; | |
153 | mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */ | |
154 | ||
155 | priv = (struct lec_priv *)dev->priv; | |
156 | atm_force_charge(priv->lecd, skb2->truesize); | |
1da177e4 | 157 | sk = sk_atm(priv->lecd); |
d44f7746 CW |
158 | skb_queue_tail(&sk->sk_receive_queue, skb2); |
159 | sk->sk_data_ready(sk, skb2->len); | |
160 | } | |
1da177e4 | 161 | |
d44f7746 | 162 | return; |
1da177e4 LT |
163 | } |
164 | #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ | |
165 | ||
166 | /* | |
167 | * Modelled after tr_type_trans | |
168 | * All multicast and ARE or STE frames go to BUS. | |
169 | * Non source routed frames go by destination address. | |
170 | * Last hop source routed frames go by destination address. | |
171 | * Not last hop source routed frames go by _next_ route descriptor. | |
172 | * Returns pointer to destination MAC address or fills in rdesc | |
173 | * and returns NULL. | |
174 | */ | |
175 | #ifdef CONFIG_TR | |
176 | static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc) | |
177 | { | |
d44f7746 | 178 | struct trh_hdr *trh; |
5c17d5f1 | 179 | unsigned int riflen, num_rdsc; |
d44f7746 CW |
180 | |
181 | trh = (struct trh_hdr *)packet; | |
182 | if (trh->daddr[0] & (uint8_t) 0x80) | |
183 | return bus_mac; /* multicast */ | |
184 | ||
185 | if (trh->saddr[0] & TR_RII) { | |
186 | riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8; | |
187 | if ((ntohs(trh->rcf) >> 13) != 0) | |
188 | return bus_mac; /* ARE or STE */ | |
189 | } else | |
190 | return trh->daddr; /* not source routed */ | |
191 | ||
192 | if (riflen < 6) | |
193 | return trh->daddr; /* last hop, source routed */ | |
194 | ||
195 | /* riflen is 6 or more, packet has more than one route descriptor */ | |
196 | num_rdsc = (riflen / 2) - 1; | |
197 | memset(rdesc, 0, ETH_ALEN); | |
198 | /* offset 4 comes from LAN destination field in LE control frames */ | |
199 | if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT)) | |
30d492da | 200 | memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16)); |
d44f7746 | 201 | else { |
30d492da | 202 | memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16)); |
d44f7746 CW |
203 | rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0)); |
204 | } | |
205 | ||
206 | return NULL; | |
1da177e4 LT |
207 | } |
208 | #endif /* CONFIG_TR */ | |
209 | ||
210 | /* | |
211 | * Open/initialize the netdevice. This is called (in the current kernel) | |
212 | * sometime after booting when the 'ifconfig' program is run. | |
213 | * | |
214 | * This routine should set everything up anew at each open, even | |
215 | * registers that "should" only need to be set once at boot, so that | |
216 | * there is non-reboot way to recover if something goes wrong. | |
217 | */ | |
218 | ||
d44f7746 | 219 | static int lec_open(struct net_device *dev) |
1da177e4 | 220 | { |
d44f7746 CW |
221 | struct lec_priv *priv = (struct lec_priv *)dev->priv; |
222 | ||
1da177e4 | 223 | netif_start_queue(dev); |
d44f7746 CW |
224 | memset(&priv->stats, 0, sizeof(struct net_device_stats)); |
225 | ||
226 | return 0; | |
1da177e4 LT |
227 | } |
228 | ||
229 | static __inline__ void | |
230 | lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv) | |
231 | { | |
232 | ATM_SKB(skb)->vcc = vcc; | |
233 | ATM_SKB(skb)->atm_options = vcc->atm_options; | |
234 | ||
235 | atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); | |
236 | if (vcc->send(vcc, skb) < 0) { | |
237 | priv->stats.tx_dropped++; | |
238 | return; | |
239 | } | |
240 | ||
241 | priv->stats.tx_packets++; | |
242 | priv->stats.tx_bytes += skb->len; | |
243 | } | |
244 | ||
d44f7746 | 245 | static void lec_tx_timeout(struct net_device *dev) |
1da177e4 LT |
246 | { |
247 | printk(KERN_INFO "%s: tx timeout\n", dev->name); | |
248 | dev->trans_start = jiffies; | |
249 | netif_wake_queue(dev); | |
250 | } | |
251 | ||
d44f7746 | 252 | static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev) |
1da177e4 | 253 | { |
d44f7746 CW |
254 | struct sk_buff *skb2; |
255 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
256 | struct lecdatahdr_8023 *lec_h; | |
257 | struct atm_vcc *vcc; | |
1da177e4 | 258 | struct lec_arp_table *entry; |
d44f7746 | 259 | unsigned char *dst; |
1da177e4 LT |
260 | int min_frame_size; |
261 | #ifdef CONFIG_TR | |
d44f7746 | 262 | unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */ |
1da177e4 | 263 | #endif |
d44f7746 | 264 | int is_rdesc; |
1da177e4 | 265 | #if DUMP_PACKETS > 0 |
d44f7746 CW |
266 | char buf[300]; |
267 | int i = 0; | |
1da177e4 | 268 | #endif /* DUMP_PACKETS >0 */ |
0795af57 | 269 | DECLARE_MAC_BUF(mac); |
d44f7746 | 270 | |
52240062 | 271 | pr_debug("lec_start_xmit called\n"); |
d44f7746 CW |
272 | if (!priv->lecd) { |
273 | printk("%s:No lecd attached\n", dev->name); | |
274 | priv->stats.tx_errors++; | |
275 | netif_stop_queue(dev); | |
276 | return -EUNATCH; | |
277 | } | |
278 | ||
52240062 | 279 | pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n", |
27a884dc | 280 | (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb), |
4305b541 | 281 | (long)skb_end_pointer(skb)); |
1da177e4 | 282 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
d44f7746 CW |
283 | if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0) |
284 | lec_handle_bridge(skb, dev); | |
1da177e4 LT |
285 | #endif |
286 | ||
d44f7746 CW |
287 | /* Make sure we have room for lec_id */ |
288 | if (skb_headroom(skb) < 2) { | |
1da177e4 | 289 | |
52240062 | 290 | pr_debug("lec_start_xmit: reallocating skb\n"); |
d44f7746 CW |
291 | skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); |
292 | kfree_skb(skb); | |
293 | if (skb2 == NULL) | |
294 | return 0; | |
295 | skb = skb2; | |
296 | } | |
297 | skb_push(skb, 2); | |
1da177e4 | 298 | |
d44f7746 CW |
299 | /* Put le header to place, works for TokenRing too */ |
300 | lec_h = (struct lecdatahdr_8023 *)skb->data; | |
301 | lec_h->le_header = htons(priv->lecid); | |
1da177e4 LT |
302 | |
303 | #ifdef CONFIG_TR | |
d44f7746 CW |
304 | /* |
305 | * Ugly. Use this to realign Token Ring packets for | |
306 | * e.g. PCA-200E driver. | |
307 | */ | |
308 | if (priv->is_trdev) { | |
309 | skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); | |
310 | kfree_skb(skb); | |
311 | if (skb2 == NULL) | |
312 | return 0; | |
313 | skb = skb2; | |
314 | } | |
1da177e4 LT |
315 | #endif |
316 | ||
317 | #if DUMP_PACKETS > 0 | |
d44f7746 CW |
318 | printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name, |
319 | skb->len, priv->lecid); | |
1da177e4 | 320 | #if DUMP_PACKETS >= 2 |
d44f7746 CW |
321 | for (i = 0; i < skb->len && i < 99; i++) { |
322 | sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); | |
323 | } | |
1da177e4 | 324 | #elif DUMP_PACKETS >= 1 |
d44f7746 CW |
325 | for (i = 0; i < skb->len && i < 30; i++) { |
326 | sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); | |
327 | } | |
1da177e4 | 328 | #endif /* DUMP_PACKETS >= 1 */ |
d44f7746 CW |
329 | if (i == skb->len) |
330 | printk("%s\n", buf); | |
331 | else | |
332 | printk("%s...\n", buf); | |
1da177e4 LT |
333 | #endif /* DUMP_PACKETS > 0 */ |
334 | ||
d44f7746 | 335 | /* Minimum ethernet-frame size */ |
1da177e4 | 336 | #ifdef CONFIG_TR |
d44f7746 CW |
337 | if (priv->is_trdev) |
338 | min_frame_size = LEC_MINIMUM_8025_SIZE; | |
1da177e4 LT |
339 | else |
340 | #endif | |
d44f7746 CW |
341 | min_frame_size = LEC_MINIMUM_8023_SIZE; |
342 | if (skb->len < min_frame_size) { | |
343 | if ((skb->len + skb_tailroom(skb)) < min_frame_size) { | |
344 | skb2 = skb_copy_expand(skb, 0, | |
345 | min_frame_size - skb->truesize, | |
346 | GFP_ATOMIC); | |
347 | dev_kfree_skb(skb); | |
348 | if (skb2 == NULL) { | |
349 | priv->stats.tx_dropped++; | |
350 | return 0; | |
351 | } | |
352 | skb = skb2; | |
353 | } | |
1da177e4 | 354 | skb_put(skb, min_frame_size - skb->len); |
d44f7746 CW |
355 | } |
356 | ||
357 | /* Send to right vcc */ | |
358 | is_rdesc = 0; | |
359 | dst = lec_h->h_dest; | |
1da177e4 | 360 | #ifdef CONFIG_TR |
d44f7746 CW |
361 | if (priv->is_trdev) { |
362 | dst = get_tr_dst(skb->data + 2, rdesc); | |
363 | if (dst == NULL) { | |
364 | dst = rdesc; | |
365 | is_rdesc = 1; | |
366 | } | |
367 | } | |
1da177e4 | 368 | #endif |
d44f7746 CW |
369 | entry = NULL; |
370 | vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry); | |
58c14a8f | 371 | pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name, |
d44f7746 CW |
372 | vcc, vcc ? vcc->flags : 0, entry); |
373 | if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) { | |
374 | if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) { | |
52240062 | 375 | pr_debug("%s:lec_start_xmit: queuing packet, ", |
d44f7746 | 376 | dev->name); |
0795af57 JP |
377 | pr_debug("MAC address %s\n", |
378 | print_mac(mac, lec_h->h_dest)); | |
d44f7746 CW |
379 | skb_queue_tail(&entry->tx_wait, skb); |
380 | } else { | |
52240062 | 381 | pr_debug |
d44f7746 CW |
382 | ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ", |
383 | dev->name); | |
0795af57 JP |
384 | pr_debug("MAC address %s\n", |
385 | print_mac(mac, lec_h->h_dest)); | |
d44f7746 CW |
386 | priv->stats.tx_dropped++; |
387 | dev_kfree_skb(skb); | |
388 | } | |
6656e3c4 | 389 | goto out; |
d44f7746 CW |
390 | } |
391 | #if DUMP_PACKETS > 0 | |
392 | printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci); | |
1da177e4 | 393 | #endif /* DUMP_PACKETS > 0 */ |
d44f7746 CW |
394 | |
395 | while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) { | |
52240062 | 396 | pr_debug("lec.c: emptying tx queue, "); |
0795af57 JP |
397 | pr_debug("MAC address %s\n", |
398 | print_mac(mac, lec_h->h_dest)); | |
1da177e4 | 399 | lec_send(vcc, skb2, priv); |
d44f7746 | 400 | } |
1da177e4 LT |
401 | |
402 | lec_send(vcc, skb, priv); | |
403 | ||
404 | if (!atm_may_send(vcc, 0)) { | |
405 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); | |
406 | ||
407 | vpriv->xoff = 1; | |
408 | netif_stop_queue(dev); | |
409 | ||
410 | /* | |
411 | * vcc->pop() might have occurred in between, making | |
412 | * the vcc usuable again. Since xmit is serialized, | |
413 | * this is the only situation we have to re-test. | |
414 | */ | |
415 | ||
416 | if (atm_may_send(vcc, 0)) | |
417 | netif_wake_queue(dev); | |
418 | } | |
419 | ||
6656e3c4 CW |
420 | out: |
421 | if (entry) | |
422 | lec_arp_put(entry); | |
1da177e4 | 423 | dev->trans_start = jiffies; |
d44f7746 | 424 | return 0; |
1da177e4 LT |
425 | } |
426 | ||
427 | /* The inverse routine to net_open(). */ | |
d44f7746 | 428 | static int lec_close(struct net_device *dev) |
1da177e4 | 429 | { |
d44f7746 CW |
430 | netif_stop_queue(dev); |
431 | return 0; | |
1da177e4 LT |
432 | } |
433 | ||
434 | /* | |
435 | * Get the current statistics. | |
436 | * This may be called with the card open or closed. | |
437 | */ | |
d44f7746 | 438 | static struct net_device_stats *lec_get_stats(struct net_device *dev) |
1da177e4 | 439 | { |
d44f7746 | 440 | return &((struct lec_priv *)dev->priv)->stats; |
1da177e4 LT |
441 | } |
442 | ||
d44f7746 | 443 | static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) |
1da177e4 LT |
444 | { |
445 | unsigned long flags; | |
d44f7746 CW |
446 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
447 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
448 | struct atmlec_msg *mesg; | |
449 | struct lec_arp_table *entry; | |
450 | int i; | |
451 | char *tmp; /* FIXME */ | |
0795af57 | 452 | DECLARE_MAC_BUF(mac); |
1da177e4 LT |
453 | |
454 | atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); | |
d44f7746 CW |
455 | mesg = (struct atmlec_msg *)skb->data; |
456 | tmp = skb->data; | |
457 | tmp += sizeof(struct atmlec_msg); | |
52240062 | 458 | pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type); |
d44f7746 CW |
459 | switch (mesg->type) { |
460 | case l_set_mac_addr: | |
461 | for (i = 0; i < 6; i++) { | |
462 | dev->dev_addr[i] = mesg->content.normal.mac_addr[i]; | |
463 | } | |
464 | break; | |
465 | case l_del_mac_addr: | |
466 | for (i = 0; i < 6; i++) { | |
467 | dev->dev_addr[i] = 0; | |
468 | } | |
469 | break; | |
470 | case l_addr_delete: | |
471 | lec_addr_delete(priv, mesg->content.normal.atm_addr, | |
472 | mesg->content.normal.flag); | |
473 | break; | |
474 | case l_topology_change: | |
475 | priv->topology_change = mesg->content.normal.flag; | |
476 | break; | |
477 | case l_flush_complete: | |
478 | lec_flush_complete(priv, mesg->content.normal.flag); | |
479 | break; | |
480 | case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */ | |
1da177e4 | 481 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
d44f7746 CW |
482 | entry = lec_arp_find(priv, mesg->content.normal.mac_addr); |
483 | lec_arp_remove(priv, entry); | |
1da177e4 LT |
484 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
485 | ||
d44f7746 CW |
486 | if (mesg->content.normal.no_source_le_narp) |
487 | break; | |
488 | /* FALL THROUGH */ | |
489 | case l_arp_update: | |
490 | lec_arp_update(priv, mesg->content.normal.mac_addr, | |
491 | mesg->content.normal.atm_addr, | |
492 | mesg->content.normal.flag, | |
493 | mesg->content.normal.targetless_le_arp); | |
52240062 | 494 | pr_debug("lec: in l_arp_update\n"); |
d44f7746 | 495 | if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */ |
52240062 | 496 | pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n", |
d44f7746 CW |
497 | mesg->sizeoftlvs); |
498 | lane2_associate_ind(dev, mesg->content.normal.mac_addr, | |
499 | tmp, mesg->sizeoftlvs); | |
500 | } | |
501 | break; | |
502 | case l_config: | |
503 | priv->maximum_unknown_frame_count = | |
504 | mesg->content.config.maximum_unknown_frame_count; | |
505 | priv->max_unknown_frame_time = | |
506 | (mesg->content.config.max_unknown_frame_time * HZ); | |
507 | priv->max_retry_count = mesg->content.config.max_retry_count; | |
508 | priv->aging_time = (mesg->content.config.aging_time * HZ); | |
509 | priv->forward_delay_time = | |
510 | (mesg->content.config.forward_delay_time * HZ); | |
511 | priv->arp_response_time = | |
512 | (mesg->content.config.arp_response_time * HZ); | |
513 | priv->flush_timeout = (mesg->content.config.flush_timeout * HZ); | |
514 | priv->path_switching_delay = | |
515 | (mesg->content.config.path_switching_delay * HZ); | |
516 | priv->lane_version = mesg->content.config.lane_version; /* LANE2 */ | |
1da177e4 LT |
517 | priv->lane2_ops = NULL; |
518 | if (priv->lane_version > 1) | |
519 | priv->lane2_ops = &lane2_ops; | |
520 | if (dev->change_mtu(dev, mesg->content.config.mtu)) | |
521 | printk("%s: change_mtu to %d failed\n", dev->name, | |
d44f7746 | 522 | mesg->content.config.mtu); |
1da177e4 | 523 | priv->is_proxy = mesg->content.config.is_proxy; |
d44f7746 CW |
524 | break; |
525 | case l_flush_tran_id: | |
526 | lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr, | |
527 | mesg->content.normal.flag); | |
528 | break; | |
529 | case l_set_lecid: | |
530 | priv->lecid = | |
531 | (unsigned short)(0xffff & mesg->content.normal.flag); | |
532 | break; | |
533 | case l_should_bridge: | |
1da177e4 | 534 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
d44f7746 CW |
535 | { |
536 | struct net_bridge_fdb_entry *f; | |
537 | ||
52240062 | 538 | pr_debug |
0795af57 JP |
539 | ("%s: bridge zeppelin asks about %s\n", |
540 | dev->name, | |
541 | print_mac(mac, mesg->content.proxy.mac_addr)); | |
d44f7746 CW |
542 | |
543 | if (br_fdb_get_hook == NULL || dev->br_port == NULL) | |
544 | break; | |
545 | ||
546 | f = br_fdb_get_hook(dev->br_port->br, | |
547 | mesg->content.proxy.mac_addr); | |
548 | if (f != NULL && f->dst->dev != dev | |
549 | && f->dst->state == BR_STATE_FORWARDING) { | |
550 | /* hit from bridge table, send LE_ARP_RESPONSE */ | |
551 | struct sk_buff *skb2; | |
552 | struct sock *sk; | |
553 | ||
52240062 | 554 | pr_debug |
d44f7746 CW |
555 | ("%s: entry found, responding to zeppelin\n", |
556 | dev->name); | |
557 | skb2 = | |
558 | alloc_skb(sizeof(struct atmlec_msg), | |
559 | GFP_ATOMIC); | |
560 | if (skb2 == NULL) { | |
561 | br_fdb_put_hook(f); | |
562 | break; | |
563 | } | |
564 | skb2->len = sizeof(struct atmlec_msg); | |
27d7ff46 ACM |
565 | skb_copy_to_linear_data(skb2, mesg, |
566 | sizeof(*mesg)); | |
d44f7746 CW |
567 | atm_force_charge(priv->lecd, skb2->truesize); |
568 | sk = sk_atm(priv->lecd); | |
569 | skb_queue_tail(&sk->sk_receive_queue, skb2); | |
570 | sk->sk_data_ready(sk, skb2->len); | |
571 | } | |
572 | if (f != NULL) | |
573 | br_fdb_put_hook(f); | |
574 | } | |
1da177e4 | 575 | #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ |
d44f7746 CW |
576 | break; |
577 | default: | |
578 | printk("%s: Unknown message type %d\n", dev->name, mesg->type); | |
579 | dev_kfree_skb(skb); | |
580 | return -EINVAL; | |
581 | } | |
582 | dev_kfree_skb(skb); | |
583 | return 0; | |
1da177e4 LT |
584 | } |
585 | ||
d44f7746 | 586 | static void lec_atm_close(struct atm_vcc *vcc) |
1da177e4 | 587 | { |
d44f7746 CW |
588 | struct sk_buff *skb; |
589 | struct net_device *dev = (struct net_device *)vcc->proto_data; | |
590 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
1da177e4 | 591 | |
d44f7746 CW |
592 | priv->lecd = NULL; |
593 | /* Do something needful? */ | |
1da177e4 | 594 | |
d44f7746 CW |
595 | netif_stop_queue(dev); |
596 | lec_arp_destroy(priv); | |
1da177e4 | 597 | |
d44f7746 | 598 | if (skb_peek(&sk_atm(vcc)->sk_receive_queue)) |
1da177e4 | 599 | printk("%s lec_atm_close: closing with messages pending\n", |
d44f7746 CW |
600 | dev->name); |
601 | while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) { | |
602 | atm_return(vcc, skb->truesize); | |
1da177e4 | 603 | dev_kfree_skb(skb); |
d44f7746 CW |
604 | } |
605 | ||
1da177e4 | 606 | printk("%s: Shut down!\n", dev->name); |
d44f7746 | 607 | module_put(THIS_MODULE); |
1da177e4 LT |
608 | } |
609 | ||
610 | static struct atmdev_ops lecdev_ops = { | |
d44f7746 CW |
611 | .close = lec_atm_close, |
612 | .send = lec_atm_send | |
1da177e4 LT |
613 | }; |
614 | ||
615 | static struct atm_dev lecatm_dev = { | |
d44f7746 CW |
616 | .ops = &lecdev_ops, |
617 | .type = "lec", | |
618 | .number = 999, /* dummy device number */ | |
4ef8d0ae | 619 | .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock) |
1da177e4 LT |
620 | }; |
621 | ||
622 | /* | |
623 | * LANE2: new argument struct sk_buff *data contains | |
624 | * the LE_ARP based TLVs introduced in the LANE2 spec | |
625 | */ | |
d44f7746 CW |
626 | static int |
627 | send_to_lecd(struct lec_priv *priv, atmlec_msg_type type, | |
628 | unsigned char *mac_addr, unsigned char *atm_addr, | |
629 | struct sk_buff *data) | |
1da177e4 LT |
630 | { |
631 | struct sock *sk; | |
632 | struct sk_buff *skb; | |
633 | struct atmlec_msg *mesg; | |
634 | ||
635 | if (!priv || !priv->lecd) { | |
636 | return -1; | |
637 | } | |
638 | skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); | |
639 | if (!skb) | |
640 | return -1; | |
641 | skb->len = sizeof(struct atmlec_msg); | |
642 | mesg = (struct atmlec_msg *)skb->data; | |
d44f7746 | 643 | memset(mesg, 0, sizeof(struct atmlec_msg)); |
1da177e4 | 644 | mesg->type = type; |
d44f7746 CW |
645 | if (data != NULL) |
646 | mesg->sizeoftlvs = data->len; | |
1da177e4 LT |
647 | if (mac_addr) |
648 | memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN); | |
d44f7746 CW |
649 | else |
650 | mesg->content.normal.targetless_le_arp = 1; | |
1da177e4 LT |
651 | if (atm_addr) |
652 | memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN); | |
653 | ||
d44f7746 | 654 | atm_force_charge(priv->lecd, skb->truesize); |
1da177e4 LT |
655 | sk = sk_atm(priv->lecd); |
656 | skb_queue_tail(&sk->sk_receive_queue, skb); | |
d44f7746 | 657 | sk->sk_data_ready(sk, skb->len); |
1da177e4 | 658 | |
d44f7746 | 659 | if (data != NULL) { |
52240062 | 660 | pr_debug("lec: about to send %d bytes of data\n", data->len); |
d44f7746 CW |
661 | atm_force_charge(priv->lecd, data->truesize); |
662 | skb_queue_tail(&sk->sk_receive_queue, data); | |
663 | sk->sk_data_ready(sk, skb->len); | |
664 | } | |
1da177e4 | 665 | |
d44f7746 | 666 | return 0; |
1da177e4 LT |
667 | } |
668 | ||
669 | /* shamelessly stolen from drivers/net/net_init.c */ | |
670 | static int lec_change_mtu(struct net_device *dev, int new_mtu) | |
671 | { | |
d44f7746 CW |
672 | if ((new_mtu < 68) || (new_mtu > 18190)) |
673 | return -EINVAL; | |
674 | dev->mtu = new_mtu; | |
675 | return 0; | |
1da177e4 LT |
676 | } |
677 | ||
678 | static void lec_set_multicast_list(struct net_device *dev) | |
679 | { | |
d44f7746 CW |
680 | /* |
681 | * by default, all multicast frames arrive over the bus. | |
682 | * eventually support selective multicast service | |
683 | */ | |
684 | return; | |
1da177e4 LT |
685 | } |
686 | ||
d44f7746 | 687 | static void lec_init(struct net_device *dev) |
1da177e4 | 688 | { |
d44f7746 CW |
689 | dev->change_mtu = lec_change_mtu; |
690 | dev->open = lec_open; | |
691 | dev->stop = lec_close; | |
692 | dev->hard_start_xmit = lec_start_xmit; | |
1da177e4 LT |
693 | dev->tx_timeout = lec_tx_timeout; |
694 | ||
d44f7746 CW |
695 | dev->get_stats = lec_get_stats; |
696 | dev->set_multicast_list = lec_set_multicast_list; | |
697 | dev->do_ioctl = NULL; | |
698 | printk("%s: Initialized!\n", dev->name); | |
699 | return; | |
1da177e4 LT |
700 | } |
701 | ||
702 | static unsigned char lec_ctrl_magic[] = { | |
d44f7746 CW |
703 | 0xff, |
704 | 0x00, | |
705 | 0x01, | |
706 | 0x01 | |
707 | }; | |
1da177e4 | 708 | |
4a7097fc ST |
709 | #define LEC_DATA_DIRECT_8023 2 |
710 | #define LEC_DATA_DIRECT_8025 3 | |
711 | ||
712 | static int lec_is_data_direct(struct atm_vcc *vcc) | |
d44f7746 | 713 | { |
4a7097fc ST |
714 | return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) || |
715 | (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025)); | |
d44f7746 | 716 | } |
4a7097fc | 717 | |
d44f7746 | 718 | static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb) |
1da177e4 | 719 | { |
4a7097fc | 720 | unsigned long flags; |
d44f7746 CW |
721 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
722 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
1da177e4 LT |
723 | |
724 | #if DUMP_PACKETS >0 | |
d44f7746 CW |
725 | int i = 0; |
726 | char buf[300]; | |
1da177e4 | 727 | |
d44f7746 CW |
728 | printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name, |
729 | vcc->vpi, vcc->vci); | |
1da177e4 | 730 | #endif |
d44f7746 | 731 | if (!skb) { |
52240062 | 732 | pr_debug("%s: null skb\n", dev->name); |
d44f7746 CW |
733 | lec_vcc_close(priv, vcc); |
734 | return; | |
735 | } | |
1da177e4 | 736 | #if DUMP_PACKETS > 0 |
d44f7746 CW |
737 | printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name, |
738 | skb->len, priv->lecid); | |
1da177e4 | 739 | #if DUMP_PACKETS >= 2 |
d44f7746 CW |
740 | for (i = 0; i < skb->len && i < 99; i++) { |
741 | sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); | |
742 | } | |
1da177e4 | 743 | #elif DUMP_PACKETS >= 1 |
d44f7746 CW |
744 | for (i = 0; i < skb->len && i < 30; i++) { |
745 | sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); | |
746 | } | |
1da177e4 | 747 | #endif /* DUMP_PACKETS >= 1 */ |
d44f7746 CW |
748 | if (i == skb->len) |
749 | printk("%s\n", buf); | |
750 | else | |
751 | printk("%s...\n", buf); | |
1da177e4 | 752 | #endif /* DUMP_PACKETS > 0 */ |
d44f7746 | 753 | if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */ |
1da177e4 LT |
754 | struct sock *sk = sk_atm(vcc); |
755 | ||
52240062 | 756 | pr_debug("%s: To daemon\n", dev->name); |
d44f7746 CW |
757 | skb_queue_tail(&sk->sk_receive_queue, skb); |
758 | sk->sk_data_ready(sk, skb->len); | |
759 | } else { /* Data frame, queue to protocol handlers */ | |
4a7097fc | 760 | struct lec_arp_table *entry; |
d44f7746 CW |
761 | unsigned char *src, *dst; |
762 | ||
763 | atm_return(vcc, skb->truesize); | |
30d492da | 764 | if (*(__be16 *) skb->data == htons(priv->lecid) || |
d44f7746 CW |
765 | !priv->lecd || !(dev->flags & IFF_UP)) { |
766 | /* | |
767 | * Probably looping back, or if lecd is missing, | |
768 | * lecd has gone down | |
769 | */ | |
52240062 | 770 | pr_debug("Ignoring frame...\n"); |
d44f7746 CW |
771 | dev_kfree_skb(skb); |
772 | return; | |
773 | } | |
1da177e4 | 774 | #ifdef CONFIG_TR |
d44f7746 CW |
775 | if (priv->is_trdev) |
776 | dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest; | |
777 | else | |
1da177e4 | 778 | #endif |
d44f7746 | 779 | dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest; |
4a7097fc | 780 | |
d44f7746 CW |
781 | /* |
782 | * If this is a Data Direct VCC, and the VCC does not match | |
4a7097fc ST |
783 | * the LE_ARP cache entry, delete the LE_ARP cache entry. |
784 | */ | |
785 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
786 | if (lec_is_data_direct(vcc)) { | |
787 | #ifdef CONFIG_TR | |
788 | if (priv->is_trdev) | |
d44f7746 CW |
789 | src = |
790 | ((struct lecdatahdr_8025 *)skb->data)-> | |
791 | h_source; | |
4a7097fc ST |
792 | else |
793 | #endif | |
d44f7746 CW |
794 | src = |
795 | ((struct lecdatahdr_8023 *)skb->data)-> | |
796 | h_source; | |
4a7097fc ST |
797 | entry = lec_arp_find(priv, src); |
798 | if (entry && entry->vcc != vcc) { | |
799 | lec_arp_remove(priv, entry); | |
33a9c2d4 | 800 | lec_arp_put(entry); |
4a7097fc ST |
801 | } |
802 | } | |
803 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
1da177e4 | 804 | |
d44f7746 CW |
805 | if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */ |
806 | !priv->is_proxy && /* Proxy wants all the packets */ | |
1da177e4 | 807 | memcmp(dst, dev->dev_addr, dev->addr_len)) { |
d44f7746 CW |
808 | dev_kfree_skb(skb); |
809 | return; | |
810 | } | |
d0732f64 | 811 | if (!hlist_empty(&priv->lec_arp_empty_ones)) { |
d44f7746 CW |
812 | lec_arp_check_empties(priv, vcc, skb); |
813 | } | |
d44f7746 | 814 | skb_pull(skb, 2); /* skip lec_id */ |
1da177e4 | 815 | #ifdef CONFIG_TR |
d44f7746 CW |
816 | if (priv->is_trdev) |
817 | skb->protocol = tr_type_trans(skb, dev); | |
818 | else | |
1da177e4 | 819 | #endif |
d44f7746 CW |
820 | skb->protocol = eth_type_trans(skb, dev); |
821 | priv->stats.rx_packets++; | |
822 | priv->stats.rx_bytes += skb->len; | |
823 | memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data)); | |
824 | netif_rx(skb); | |
825 | } | |
1da177e4 LT |
826 | } |
827 | ||
d44f7746 | 828 | static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb) |
1da177e4 LT |
829 | { |
830 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); | |
831 | struct net_device *dev = skb->dev; | |
832 | ||
833 | if (vpriv == NULL) { | |
834 | printk("lec_pop(): vpriv = NULL!?!?!?\n"); | |
835 | return; | |
836 | } | |
837 | ||
838 | vpriv->old_pop(vcc, skb); | |
839 | ||
840 | if (vpriv->xoff && atm_may_send(vcc, 0)) { | |
841 | vpriv->xoff = 0; | |
842 | if (netif_running(dev) && netif_queue_stopped(dev)) | |
843 | netif_wake_queue(dev); | |
844 | } | |
845 | } | |
846 | ||
d44f7746 | 847 | static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg) |
1da177e4 LT |
848 | { |
849 | struct lec_vcc_priv *vpriv; | |
d44f7746 CW |
850 | int bytes_left; |
851 | struct atmlec_ioc ioc_data; | |
852 | ||
853 | /* Lecd must be up in this case */ | |
854 | bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc)); | |
855 | if (bytes_left != 0) { | |
856 | printk | |
857 | ("lec: lec_vcc_attach, copy from user failed for %d bytes\n", | |
858 | bytes_left); | |
859 | } | |
860 | if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF || | |
861 | !dev_lec[ioc_data.dev_num]) | |
862 | return -EINVAL; | |
1da177e4 LT |
863 | if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL))) |
864 | return -ENOMEM; | |
865 | vpriv->xoff = 0; | |
866 | vpriv->old_pop = vcc->pop; | |
867 | vcc->user_back = vpriv; | |
868 | vcc->pop = lec_pop; | |
d44f7746 CW |
869 | lec_vcc_added(dev_lec[ioc_data.dev_num]->priv, |
870 | &ioc_data, vcc, vcc->push); | |
871 | vcc->proto_data = dev_lec[ioc_data.dev_num]; | |
872 | vcc->push = lec_push; | |
873 | return 0; | |
1da177e4 LT |
874 | } |
875 | ||
d44f7746 | 876 | static int lec_mcast_attach(struct atm_vcc *vcc, int arg) |
1da177e4 | 877 | { |
d44f7746 CW |
878 | if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg]) |
879 | return -EINVAL; | |
880 | vcc->proto_data = dev_lec[arg]; | |
881 | return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc)); | |
1da177e4 LT |
882 | } |
883 | ||
884 | /* Initialize device. */ | |
d44f7746 CW |
885 | static int lecd_attach(struct atm_vcc *vcc, int arg) |
886 | { | |
887 | int i; | |
888 | struct lec_priv *priv; | |
889 | ||
890 | if (arg < 0) | |
891 | i = 0; | |
892 | else | |
893 | i = arg; | |
1da177e4 | 894 | #ifdef CONFIG_TR |
d44f7746 CW |
895 | if (arg >= MAX_LEC_ITF) |
896 | return -EINVAL; | |
897 | #else /* Reserve the top NUM_TR_DEVS for TR */ | |
898 | if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS)) | |
899 | return -EINVAL; | |
1da177e4 | 900 | #endif |
d44f7746 CW |
901 | if (!dev_lec[i]) { |
902 | int is_trdev, size; | |
1da177e4 | 903 | |
d44f7746 CW |
904 | is_trdev = 0; |
905 | if (i >= (MAX_LEC_ITF - NUM_TR_DEVS)) | |
906 | is_trdev = 1; | |
1da177e4 | 907 | |
d44f7746 | 908 | size = sizeof(struct lec_priv); |
1da177e4 | 909 | #ifdef CONFIG_TR |
d44f7746 CW |
910 | if (is_trdev) |
911 | dev_lec[i] = alloc_trdev(size); | |
912 | else | |
1da177e4 | 913 | #endif |
d44f7746 CW |
914 | dev_lec[i] = alloc_etherdev(size); |
915 | if (!dev_lec[i]) | |
916 | return -ENOMEM; | |
917 | snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i); | |
918 | if (register_netdev(dev_lec[i])) { | |
919 | free_netdev(dev_lec[i]); | |
920 | return -EINVAL; | |
921 | } | |
922 | ||
923 | priv = dev_lec[i]->priv; | |
924 | priv->is_trdev = is_trdev; | |
925 | lec_init(dev_lec[i]); | |
926 | } else { | |
927 | priv = dev_lec[i]->priv; | |
928 | if (priv->lecd) | |
929 | return -EADDRINUSE; | |
930 | } | |
931 | lec_arp_init(priv); | |
932 | priv->itfnum = i; /* LANE2 addition */ | |
933 | priv->lecd = vcc; | |
934 | vcc->dev = &lecatm_dev; | |
935 | vcc_insert_socket(sk_atm(vcc)); | |
936 | ||
937 | vcc->proto_data = dev_lec[i]; | |
938 | set_bit(ATM_VF_META, &vcc->flags); | |
939 | set_bit(ATM_VF_READY, &vcc->flags); | |
940 | ||
941 | /* Set default values to these variables */ | |
942 | priv->maximum_unknown_frame_count = 1; | |
943 | priv->max_unknown_frame_time = (1 * HZ); | |
944 | priv->vcc_timeout_period = (1200 * HZ); | |
945 | priv->max_retry_count = 1; | |
946 | priv->aging_time = (300 * HZ); | |
947 | priv->forward_delay_time = (15 * HZ); | |
948 | priv->topology_change = 0; | |
949 | priv->arp_response_time = (1 * HZ); | |
950 | priv->flush_timeout = (4 * HZ); | |
951 | priv->path_switching_delay = (6 * HZ); | |
952 | ||
953 | if (dev_lec[i]->flags & IFF_UP) { | |
954 | netif_start_queue(dev_lec[i]); | |
955 | } | |
956 | __module_get(THIS_MODULE); | |
957 | return i; | |
1da177e4 LT |
958 | } |
959 | ||
960 | #ifdef CONFIG_PROC_FS | |
d44f7746 | 961 | static char *lec_arp_get_status_string(unsigned char status) |
1da177e4 LT |
962 | { |
963 | static char *lec_arp_status_string[] = { | |
964 | "ESI_UNKNOWN ", | |
965 | "ESI_ARP_PENDING ", | |
966 | "ESI_VC_PENDING ", | |
967 | "<Undefined> ", | |
968 | "ESI_FLUSH_PENDING ", | |
969 | "ESI_FORWARD_DIRECT" | |
970 | }; | |
971 | ||
972 | if (status > ESI_FORWARD_DIRECT) | |
973 | status = 3; /* ESI_UNDEFINED */ | |
974 | return lec_arp_status_string[status]; | |
975 | } | |
976 | ||
977 | static void lec_info(struct seq_file *seq, struct lec_arp_table *entry) | |
978 | { | |
979 | int i; | |
980 | ||
981 | for (i = 0; i < ETH_ALEN; i++) | |
982 | seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff); | |
983 | seq_printf(seq, " "); | |
984 | for (i = 0; i < ATM_ESA_LEN; i++) | |
985 | seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff); | |
986 | seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status), | |
987 | entry->flags & 0xffff); | |
988 | if (entry->vcc) | |
989 | seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci); | |
990 | else | |
d44f7746 | 991 | seq_printf(seq, " "); |
1da177e4 LT |
992 | if (entry->recv_vcc) { |
993 | seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi, | |
994 | entry->recv_vcc->vci); | |
d44f7746 CW |
995 | } |
996 | seq_putc(seq, '\n'); | |
1da177e4 LT |
997 | } |
998 | ||
1da177e4 LT |
999 | struct lec_state { |
1000 | unsigned long flags; | |
1001 | struct lec_priv *locked; | |
d0732f64 | 1002 | struct hlist_node *node; |
1da177e4 LT |
1003 | struct net_device *dev; |
1004 | int itf; | |
1005 | int arp_table; | |
1006 | int misc_table; | |
1007 | }; | |
1008 | ||
d0732f64 | 1009 | static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl, |
1da177e4 LT |
1010 | loff_t *l) |
1011 | { | |
d0732f64 CW |
1012 | struct hlist_node *e = state->node; |
1013 | struct lec_arp_table *tmp; | |
1da177e4 LT |
1014 | |
1015 | if (!e) | |
d0732f64 | 1016 | e = tbl->first; |
1da177e4 | 1017 | if (e == (void *)1) { |
d0732f64 | 1018 | e = tbl->first; |
1da177e4 LT |
1019 | --*l; |
1020 | } | |
d0732f64 CW |
1021 | |
1022 | hlist_for_each_entry_from(tmp, e, next) { | |
1da177e4 LT |
1023 | if (--*l < 0) |
1024 | break; | |
1025 | } | |
d0732f64 CW |
1026 | state->node = e; |
1027 | ||
1da177e4 LT |
1028 | return (*l < 0) ? state : NULL; |
1029 | } | |
1030 | ||
1031 | static void *lec_arp_walk(struct lec_state *state, loff_t *l, | |
d44f7746 | 1032 | struct lec_priv *priv) |
1da177e4 LT |
1033 | { |
1034 | void *v = NULL; | |
1035 | int p; | |
1036 | ||
1037 | for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) { | |
d0732f64 | 1038 | v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l); |
1da177e4 LT |
1039 | if (v) |
1040 | break; | |
1041 | } | |
1042 | state->arp_table = p; | |
1043 | return v; | |
1044 | } | |
1045 | ||
1046 | static void *lec_misc_walk(struct lec_state *state, loff_t *l, | |
1047 | struct lec_priv *priv) | |
1048 | { | |
d0732f64 CW |
1049 | struct hlist_head *lec_misc_tables[] = { |
1050 | &priv->lec_arp_empty_ones, | |
1051 | &priv->lec_no_forward, | |
1052 | &priv->mcast_fwds | |
1da177e4 LT |
1053 | }; |
1054 | void *v = NULL; | |
1055 | int q; | |
1056 | ||
1057 | for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) { | |
1058 | v = lec_tbl_walk(state, lec_misc_tables[q], l); | |
1059 | if (v) | |
1060 | break; | |
1061 | } | |
1062 | state->misc_table = q; | |
1063 | return v; | |
1064 | } | |
1065 | ||
1066 | static void *lec_priv_walk(struct lec_state *state, loff_t *l, | |
1067 | struct lec_priv *priv) | |
1068 | { | |
1069 | if (!state->locked) { | |
1070 | state->locked = priv; | |
1071 | spin_lock_irqsave(&priv->lec_arp_lock, state->flags); | |
1072 | } | |
d44f7746 | 1073 | if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) { |
1da177e4 LT |
1074 | spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags); |
1075 | state->locked = NULL; | |
1076 | /* Partial state reset for the next time we get called */ | |
1077 | state->arp_table = state->misc_table = 0; | |
1078 | } | |
1079 | return state->locked; | |
1080 | } | |
1081 | ||
1082 | static void *lec_itf_walk(struct lec_state *state, loff_t *l) | |
1083 | { | |
1084 | struct net_device *dev; | |
1085 | void *v; | |
1086 | ||
1087 | dev = state->dev ? state->dev : dev_lec[state->itf]; | |
1088 | v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL; | |
1089 | if (!v && dev) { | |
1090 | dev_put(dev); | |
1091 | /* Partial state reset for the next time we get called */ | |
1092 | dev = NULL; | |
1093 | } | |
1094 | state->dev = dev; | |
1095 | return v; | |
1096 | } | |
1097 | ||
1098 | static void *lec_get_idx(struct lec_state *state, loff_t l) | |
1099 | { | |
1100 | void *v = NULL; | |
1101 | ||
1102 | for (; state->itf < MAX_LEC_ITF; state->itf++) { | |
1103 | v = lec_itf_walk(state, &l); | |
1104 | if (v) | |
1105 | break; | |
1106 | } | |
d44f7746 | 1107 | return v; |
1da177e4 LT |
1108 | } |
1109 | ||
1110 | static void *lec_seq_start(struct seq_file *seq, loff_t *pos) | |
1111 | { | |
1112 | struct lec_state *state = seq->private; | |
1113 | ||
1114 | state->itf = 0; | |
1115 | state->dev = NULL; | |
1116 | state->locked = NULL; | |
1117 | state->arp_table = 0; | |
1118 | state->misc_table = 0; | |
d0732f64 | 1119 | state->node = (void *)1; |
1da177e4 | 1120 | |
d44f7746 | 1121 | return *pos ? lec_get_idx(state, *pos) : (void *)1; |
1da177e4 LT |
1122 | } |
1123 | ||
1124 | static void lec_seq_stop(struct seq_file *seq, void *v) | |
1125 | { | |
1126 | struct lec_state *state = seq->private; | |
1127 | ||
1128 | if (state->dev) { | |
1129 | spin_unlock_irqrestore(&state->locked->lec_arp_lock, | |
1130 | state->flags); | |
1131 | dev_put(state->dev); | |
1132 | } | |
1133 | } | |
1134 | ||
1135 | static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
1136 | { | |
1137 | struct lec_state *state = seq->private; | |
1138 | ||
1139 | v = lec_get_idx(state, 1); | |
1140 | *pos += !!PTR_ERR(v); | |
1141 | return v; | |
1142 | } | |
1143 | ||
1144 | static int lec_seq_show(struct seq_file *seq, void *v) | |
1145 | { | |
d44f7746 CW |
1146 | static char lec_banner[] = "Itf MAC ATM destination" |
1147 | " Status Flags " | |
1148 | "VPI/VCI Recv VPI/VCI\n"; | |
1da177e4 LT |
1149 | |
1150 | if (v == (void *)1) | |
1151 | seq_puts(seq, lec_banner); | |
1152 | else { | |
1153 | struct lec_state *state = seq->private; | |
d44f7746 | 1154 | struct net_device *dev = state->dev; |
d0732f64 | 1155 | struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next); |
1da177e4 LT |
1156 | |
1157 | seq_printf(seq, "%s ", dev->name); | |
d0732f64 | 1158 | lec_info(seq, entry); |
1da177e4 LT |
1159 | } |
1160 | return 0; | |
1161 | } | |
1162 | ||
56b3d975 | 1163 | static const struct seq_operations lec_seq_ops = { |
d44f7746 CW |
1164 | .start = lec_seq_start, |
1165 | .next = lec_seq_next, | |
1166 | .stop = lec_seq_stop, | |
1167 | .show = lec_seq_show, | |
1da177e4 LT |
1168 | }; |
1169 | ||
1170 | static int lec_seq_open(struct inode *inode, struct file *file) | |
1171 | { | |
9a8c09e7 | 1172 | return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state)); |
1da177e4 LT |
1173 | } |
1174 | ||
9a32144e | 1175 | static const struct file_operations lec_seq_fops = { |
d44f7746 CW |
1176 | .owner = THIS_MODULE, |
1177 | .open = lec_seq_open, | |
1178 | .read = seq_read, | |
1179 | .llseek = seq_lseek, | |
9a8c09e7 | 1180 | .release = seq_release_private, |
1da177e4 LT |
1181 | }; |
1182 | #endif | |
1183 | ||
1184 | static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) | |
1185 | { | |
1186 | struct atm_vcc *vcc = ATM_SD(sock); | |
1187 | int err = 0; | |
d44f7746 | 1188 | |
1da177e4 | 1189 | switch (cmd) { |
d44f7746 CW |
1190 | case ATMLEC_CTRL: |
1191 | case ATMLEC_MCAST: | |
1192 | case ATMLEC_DATA: | |
1193 | if (!capable(CAP_NET_ADMIN)) | |
1194 | return -EPERM; | |
1195 | break; | |
1196 | default: | |
1197 | return -ENOIOCTLCMD; | |
1da177e4 LT |
1198 | } |
1199 | ||
1200 | switch (cmd) { | |
d44f7746 CW |
1201 | case ATMLEC_CTRL: |
1202 | err = lecd_attach(vcc, (int)arg); | |
1203 | if (err >= 0) | |
1204 | sock->state = SS_CONNECTED; | |
1205 | break; | |
1206 | case ATMLEC_MCAST: | |
1207 | err = lec_mcast_attach(vcc, (int)arg); | |
1208 | break; | |
1209 | case ATMLEC_DATA: | |
1210 | err = lec_vcc_attach(vcc, (void __user *)arg); | |
1211 | break; | |
1da177e4 LT |
1212 | } |
1213 | ||
1214 | return err; | |
1215 | } | |
1216 | ||
1217 | static struct atm_ioctl lane_ioctl_ops = { | |
d44f7746 CW |
1218 | .owner = THIS_MODULE, |
1219 | .ioctl = lane_ioctl, | |
1da177e4 LT |
1220 | }; |
1221 | ||
1222 | static int __init lane_module_init(void) | |
1223 | { | |
1224 | #ifdef CONFIG_PROC_FS | |
1225 | struct proc_dir_entry *p; | |
1226 | ||
16e297b3 | 1227 | p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops); |
dbee0d3f WC |
1228 | if (!p) { |
1229 | printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n"); | |
1230 | return -ENOMEM; | |
1231 | } | |
1da177e4 LT |
1232 | #endif |
1233 | ||
1234 | register_atm_ioctl(&lane_ioctl_ops); | |
d44f7746 CW |
1235 | printk("lec.c: " __DATE__ " " __TIME__ " initialized\n"); |
1236 | return 0; | |
1da177e4 LT |
1237 | } |
1238 | ||
1239 | static void __exit lane_module_cleanup(void) | |
1240 | { | |
d44f7746 CW |
1241 | int i; |
1242 | struct lec_priv *priv; | |
1da177e4 LT |
1243 | |
1244 | remove_proc_entry("lec", atm_proc_root); | |
1245 | ||
1246 | deregister_atm_ioctl(&lane_ioctl_ops); | |
1247 | ||
d44f7746 CW |
1248 | for (i = 0; i < MAX_LEC_ITF; i++) { |
1249 | if (dev_lec[i] != NULL) { | |
1250 | priv = (struct lec_priv *)dev_lec[i]->priv; | |
1da177e4 | 1251 | unregister_netdev(dev_lec[i]); |
d44f7746 CW |
1252 | free_netdev(dev_lec[i]); |
1253 | dev_lec[i] = NULL; | |
1254 | } | |
1255 | } | |
1da177e4 | 1256 | |
d44f7746 | 1257 | return; |
1da177e4 LT |
1258 | } |
1259 | ||
1260 | module_init(lane_module_init); | |
1261 | module_exit(lane_module_cleanup); | |
1262 | ||
1263 | /* | |
1264 | * LANE2: 3.1.3, LE_RESOLVE.request | |
1265 | * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs. | |
1266 | * If sizeoftlvs == NULL the default TLVs associated with with this | |
1267 | * lec will be used. | |
1268 | * If dst_mac == NULL, targetless LE_ARP will be sent | |
1269 | */ | |
1270 | static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force, | |
d44f7746 | 1271 | u8 **tlvs, u32 *sizeoftlvs) |
1da177e4 LT |
1272 | { |
1273 | unsigned long flags; | |
d44f7746 CW |
1274 | struct lec_priv *priv = (struct lec_priv *)dev->priv; |
1275 | struct lec_arp_table *table; | |
1276 | struct sk_buff *skb; | |
1277 | int retval; | |
1da177e4 | 1278 | |
d44f7746 | 1279 | if (force == 0) { |
1da177e4 | 1280 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
d44f7746 | 1281 | table = lec_arp_find(priv, dst_mac); |
1da177e4 | 1282 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
d44f7746 CW |
1283 | if (table == NULL) |
1284 | return -1; | |
1285 | ||
2afe37cd | 1286 | *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC); |
d44f7746 CW |
1287 | if (*tlvs == NULL) |
1288 | return -1; | |
1289 | ||
d44f7746 CW |
1290 | *sizeoftlvs = table->sizeoftlvs; |
1291 | ||
1292 | return 0; | |
1293 | } | |
1da177e4 LT |
1294 | |
1295 | if (sizeoftlvs == NULL) | |
1296 | retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL); | |
d44f7746 | 1297 | |
1da177e4 LT |
1298 | else { |
1299 | skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC); | |
1300 | if (skb == NULL) | |
1301 | return -1; | |
1302 | skb->len = *sizeoftlvs; | |
27d7ff46 | 1303 | skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs); |
1da177e4 LT |
1304 | retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb); |
1305 | } | |
d44f7746 CW |
1306 | return retval; |
1307 | } | |
1da177e4 LT |
1308 | |
1309 | /* | |
1310 | * LANE2: 3.1.4, LE_ASSOCIATE.request | |
1311 | * Associate the *tlvs with the *lan_dst address. | |
1312 | * Will overwrite any previous association | |
1313 | * Returns 1 for success, 0 for failure (out of memory) | |
1314 | * | |
1315 | */ | |
d44f7746 CW |
1316 | static int lane2_associate_req(struct net_device *dev, u8 *lan_dst, |
1317 | u8 *tlvs, u32 sizeoftlvs) | |
1da177e4 | 1318 | { |
d44f7746 CW |
1319 | int retval; |
1320 | struct sk_buff *skb; | |
1321 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
1322 | ||
1323 | if (compare_ether_addr(lan_dst, dev->dev_addr)) | |
1324 | return (0); /* not our mac address */ | |
1325 | ||
1326 | kfree(priv->tlvs); /* NULL if there was no previous association */ | |
1327 | ||
2afe37cd | 1328 | priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL); |
d44f7746 CW |
1329 | if (priv->tlvs == NULL) |
1330 | return (0); | |
1331 | priv->sizeoftlvs = sizeoftlvs; | |
d44f7746 CW |
1332 | |
1333 | skb = alloc_skb(sizeoftlvs, GFP_ATOMIC); | |
1334 | if (skb == NULL) | |
1335 | return 0; | |
1336 | skb->len = sizeoftlvs; | |
27d7ff46 | 1337 | skb_copy_to_linear_data(skb, tlvs, sizeoftlvs); |
d44f7746 CW |
1338 | retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb); |
1339 | if (retval != 0) | |
1340 | printk("lec.c: lane2_associate_req() failed\n"); | |
1341 | /* | |
1342 | * If the previous association has changed we must | |
1343 | * somehow notify other LANE entities about the change | |
1344 | */ | |
1345 | return (1); | |
1da177e4 LT |
1346 | } |
1347 | ||
1348 | /* | |
1349 | * LANE2: 3.1.5, LE_ASSOCIATE.indication | |
1350 | * | |
1351 | */ | |
d44f7746 CW |
1352 | static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr, |
1353 | u8 *tlvs, u32 sizeoftlvs) | |
1da177e4 LT |
1354 | { |
1355 | #if 0 | |
d44f7746 | 1356 | int i = 0; |
1da177e4 LT |
1357 | #endif |
1358 | struct lec_priv *priv = (struct lec_priv *)dev->priv; | |
d44f7746 CW |
1359 | #if 0 /* |
1360 | * Why have the TLVs in LE_ARP entries | |
1361 | * since we do not use them? When you | |
1362 | * uncomment this code, make sure the | |
1363 | * TLVs get freed when entry is killed | |
1364 | */ | |
1365 | struct lec_arp_table *entry = lec_arp_find(priv, mac_addr); | |
1da177e4 | 1366 | |
d44f7746 CW |
1367 | if (entry == NULL) |
1368 | return; /* should not happen */ | |
1da177e4 | 1369 | |
d44f7746 | 1370 | kfree(entry->tlvs); |
1da177e4 | 1371 | |
2afe37cd | 1372 | entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL); |
d44f7746 CW |
1373 | if (entry->tlvs == NULL) |
1374 | return; | |
d44f7746 | 1375 | entry->sizeoftlvs = sizeoftlvs; |
1da177e4 LT |
1376 | #endif |
1377 | #if 0 | |
d44f7746 CW |
1378 | printk("lec.c: lane2_associate_ind()\n"); |
1379 | printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs); | |
1380 | while (i < sizeoftlvs) | |
1381 | printk("%02x ", tlvs[i++]); | |
1382 | ||
1383 | printk("\n"); | |
1da177e4 LT |
1384 | #endif |
1385 | ||
d44f7746 CW |
1386 | /* tell MPOA about the TLVs we saw */ |
1387 | if (priv->lane2_ops && priv->lane2_ops->associate_indicator) { | |
1388 | priv->lane2_ops->associate_indicator(dev, mac_addr, | |
1389 | tlvs, sizeoftlvs); | |
1390 | } | |
1391 | return; | |
1da177e4 LT |
1392 | } |
1393 | ||
1394 | /* | |
1395 | * Here starts what used to lec_arpc.c | |
1396 | * | |
1397 | * lec_arpc.c was added here when making | |
1398 | * lane client modular. October 1997 | |
1da177e4 LT |
1399 | */ |
1400 | ||
1401 | #include <linux/types.h> | |
1da177e4 LT |
1402 | #include <linux/timer.h> |
1403 | #include <asm/param.h> | |
1404 | #include <asm/atomic.h> | |
1405 | #include <linux/inetdevice.h> | |
1406 | #include <net/route.h> | |
1407 | ||
1da177e4 | 1408 | #if 0 |
52240062 | 1409 | #define pr_debug(format,args...) |
1da177e4 | 1410 | /* |
52240062 | 1411 | #define pr_debug printk |
1da177e4 LT |
1412 | */ |
1413 | #endif | |
1414 | #define DEBUG_ARP_TABLE 0 | |
1415 | ||
1416 | #define LEC_ARP_REFRESH_INTERVAL (3*HZ) | |
1417 | ||
c4028958 | 1418 | static void lec_arp_check_expire(struct work_struct *work); |
1da177e4 LT |
1419 | static void lec_arp_expire_arp(unsigned long data); |
1420 | ||
f7d57453 | 1421 | /* |
1da177e4 LT |
1422 | * Arp table funcs |
1423 | */ | |
1424 | ||
1425 | #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1)) | |
1426 | ||
1427 | /* | |
1428 | * Initialization of arp-cache | |
1429 | */ | |
1fa9961d | 1430 | static void lec_arp_init(struct lec_priv *priv) |
1da177e4 | 1431 | { |
1fa9961d | 1432 | unsigned short i; |
1da177e4 | 1433 | |
1fa9961d | 1434 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
d0732f64 | 1435 | INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); |
1fa9961d | 1436 | } |
f7d57453 YH |
1437 | INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); |
1438 | INIT_HLIST_HEAD(&priv->lec_no_forward); | |
1439 | INIT_HLIST_HEAD(&priv->mcast_fwds); | |
1da177e4 | 1440 | spin_lock_init(&priv->lec_arp_lock); |
c4028958 | 1441 | INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire); |
987e46bd | 1442 | schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL); |
1da177e4 LT |
1443 | } |
1444 | ||
1fa9961d | 1445 | static void lec_arp_clear_vccs(struct lec_arp_table *entry) |
1da177e4 | 1446 | { |
1fa9961d | 1447 | if (entry->vcc) { |
1da177e4 LT |
1448 | struct atm_vcc *vcc = entry->vcc; |
1449 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); | |
1fa9961d | 1450 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
1da177e4 | 1451 | |
1fa9961d | 1452 | vcc->pop = vpriv->old_pop; |
1da177e4 LT |
1453 | if (vpriv->xoff) |
1454 | netif_wake_queue(dev); | |
1455 | kfree(vpriv); | |
1456 | vcc->user_back = NULL; | |
1fa9961d | 1457 | vcc->push = entry->old_push; |
1da177e4 | 1458 | vcc_release_async(vcc, -EPIPE); |
d0732f64 | 1459 | entry->vcc = NULL; |
1fa9961d CW |
1460 | } |
1461 | if (entry->recv_vcc) { | |
1462 | entry->recv_vcc->push = entry->old_recv_push; | |
1da177e4 | 1463 | vcc_release_async(entry->recv_vcc, -EPIPE); |
1fa9961d CW |
1464 | entry->recv_vcc = NULL; |
1465 | } | |
1da177e4 LT |
1466 | } |
1467 | ||
1468 | /* | |
1469 | * Insert entry to lec_arp_table | |
1470 | * LANE2: Add to the end of the list to satisfy 8.1.13 | |
1471 | */ | |
1fa9961d | 1472 | static inline void |
d0732f64 | 1473 | lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry) |
1da177e4 | 1474 | { |
d0732f64 | 1475 | struct hlist_head *tmp; |
1fa9961d | 1476 | |
d0732f64 CW |
1477 | tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])]; |
1478 | hlist_add_head(&entry->next, tmp); | |
1fa9961d | 1479 | |
52240062 | 1480 | pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", |
d0732f64 CW |
1481 | 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1], |
1482 | 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3], | |
1483 | 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]); | |
1da177e4 LT |
1484 | } |
1485 | ||
1486 | /* | |
1487 | * Remove entry from lec_arp_table | |
1488 | */ | |
1fa9961d CW |
1489 | static int |
1490 | lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove) | |
1da177e4 | 1491 | { |
d0732f64 CW |
1492 | struct hlist_node *node; |
1493 | struct lec_arp_table *entry; | |
1494 | int i, remove_vcc = 1; | |
1fa9961d CW |
1495 | |
1496 | if (!to_remove) { | |
1497 | return -1; | |
1498 | } | |
d0732f64 CW |
1499 | |
1500 | hlist_del(&to_remove->next); | |
1fa9961d CW |
1501 | del_timer(&to_remove->timer); |
1502 | ||
d0732f64 | 1503 | /* If this is the only MAC connected to this VCC, also tear down the VCC */ |
1fa9961d CW |
1504 | if (to_remove->status >= ESI_FLUSH_PENDING) { |
1505 | /* | |
1506 | * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT | |
1507 | */ | |
d0732f64 CW |
1508 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
1509 | hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { | |
1510 | if (memcmp(to_remove->atm_addr, | |
1511 | entry->atm_addr, ATM_ESA_LEN) == 0) { | |
1fa9961d CW |
1512 | remove_vcc = 0; |
1513 | break; | |
1514 | } | |
1515 | } | |
1516 | } | |
1517 | if (remove_vcc) | |
1518 | lec_arp_clear_vccs(to_remove); | |
1519 | } | |
1520 | skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */ | |
1521 | ||
52240062 | 1522 | pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", |
1fa9961d CW |
1523 | 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1], |
1524 | 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3], | |
1525 | 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]); | |
1526 | return 0; | |
1da177e4 LT |
1527 | } |
1528 | ||
1529 | #if DEBUG_ARP_TABLE | |
1fa9961d | 1530 | static char *get_status_string(unsigned char st) |
1da177e4 | 1531 | { |
1fa9961d CW |
1532 | switch (st) { |
1533 | case ESI_UNKNOWN: | |
1534 | return "ESI_UNKNOWN"; | |
1535 | case ESI_ARP_PENDING: | |
1536 | return "ESI_ARP_PENDING"; | |
1537 | case ESI_VC_PENDING: | |
1538 | return "ESI_VC_PENDING"; | |
1539 | case ESI_FLUSH_PENDING: | |
1540 | return "ESI_FLUSH_PENDING"; | |
1541 | case ESI_FORWARD_DIRECT: | |
1542 | return "ESI_FORWARD_DIRECT"; | |
1543 | default: | |
1544 | return "<UNKNOWN>"; | |
1545 | } | |
1da177e4 | 1546 | } |
1da177e4 | 1547 | |
1fa9961d | 1548 | static void dump_arp_table(struct lec_priv *priv) |
1da177e4 | 1549 | { |
d0732f64 | 1550 | struct hlist_node *node; |
1fa9961d | 1551 | struct lec_arp_table *rulla; |
d0732f64 CW |
1552 | char buf[256]; |
1553 | int i, j, offset; | |
1fa9961d CW |
1554 | |
1555 | printk("Dump %p:\n", priv); | |
1556 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { | |
d0732f64 CW |
1557 | hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) { |
1558 | offset = 0; | |
1559 | offset += sprintf(buf, "%d: %p\n", i, rulla); | |
1fa9961d CW |
1560 | offset += sprintf(buf + offset, "Mac:"); |
1561 | for (j = 0; j < ETH_ALEN; j++) { | |
1562 | offset += sprintf(buf + offset, | |
1563 | "%2.2x ", | |
1564 | rulla->mac_addr[j] & 0xff); | |
1565 | } | |
1566 | offset += sprintf(buf + offset, "Atm:"); | |
1567 | for (j = 0; j < ATM_ESA_LEN; j++) { | |
1568 | offset += sprintf(buf + offset, | |
1569 | "%2.2x ", | |
1570 | rulla->atm_addr[j] & 0xff); | |
1571 | } | |
1572 | offset += sprintf(buf + offset, | |
1573 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", | |
1574 | rulla->vcc ? rulla->vcc->vpi : 0, | |
1575 | rulla->vcc ? rulla->vcc->vci : 0, | |
1576 | rulla->recv_vcc ? rulla->recv_vcc-> | |
1577 | vpi : 0, | |
1578 | rulla->recv_vcc ? rulla->recv_vcc-> | |
1579 | vci : 0, rulla->last_used, | |
1580 | rulla->timestamp, rulla->no_tries); | |
1581 | offset += | |
1582 | sprintf(buf + offset, | |
1583 | "Flags:%x, Packets_flooded:%x, Status: %s ", | |
1584 | rulla->flags, rulla->packets_flooded, | |
1585 | get_status_string(rulla->status)); | |
d0732f64 | 1586 | printk("%s\n", buf); |
1fa9961d | 1587 | } |
1fa9961d | 1588 | } |
d0732f64 CW |
1589 | |
1590 | if (!hlist_empty(&priv->lec_no_forward)) | |
1fa9961d | 1591 | printk("No forward\n"); |
d0732f64 | 1592 | hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) { |
1fa9961d CW |
1593 | offset = 0; |
1594 | offset += sprintf(buf + offset, "Mac:"); | |
1595 | for (j = 0; j < ETH_ALEN; j++) { | |
1596 | offset += sprintf(buf + offset, "%2.2x ", | |
1597 | rulla->mac_addr[j] & 0xff); | |
1598 | } | |
1599 | offset += sprintf(buf + offset, "Atm:"); | |
1600 | for (j = 0; j < ATM_ESA_LEN; j++) { | |
1601 | offset += sprintf(buf + offset, "%2.2x ", | |
1602 | rulla->atm_addr[j] & 0xff); | |
1603 | } | |
1604 | offset += sprintf(buf + offset, | |
1605 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", | |
1606 | rulla->vcc ? rulla->vcc->vpi : 0, | |
1607 | rulla->vcc ? rulla->vcc->vci : 0, | |
1608 | rulla->recv_vcc ? rulla->recv_vcc->vpi : 0, | |
1609 | rulla->recv_vcc ? rulla->recv_vcc->vci : 0, | |
1610 | rulla->last_used, | |
1611 | rulla->timestamp, rulla->no_tries); | |
1612 | offset += sprintf(buf + offset, | |
1613 | "Flags:%x, Packets_flooded:%x, Status: %s ", | |
1614 | rulla->flags, rulla->packets_flooded, | |
1615 | get_status_string(rulla->status)); | |
d0732f64 | 1616 | printk("%s\n", buf); |
1fa9961d | 1617 | } |
d0732f64 CW |
1618 | |
1619 | if (!hlist_empty(&priv->lec_arp_empty_ones)) | |
1fa9961d | 1620 | printk("Empty ones\n"); |
d0732f64 | 1621 | hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) { |
1fa9961d CW |
1622 | offset = 0; |
1623 | offset += sprintf(buf + offset, "Mac:"); | |
1624 | for (j = 0; j < ETH_ALEN; j++) { | |
1625 | offset += sprintf(buf + offset, "%2.2x ", | |
1626 | rulla->mac_addr[j] & 0xff); | |
1627 | } | |
1628 | offset += sprintf(buf + offset, "Atm:"); | |
1629 | for (j = 0; j < ATM_ESA_LEN; j++) { | |
1630 | offset += sprintf(buf + offset, "%2.2x ", | |
1631 | rulla->atm_addr[j] & 0xff); | |
1632 | } | |
1633 | offset += sprintf(buf + offset, | |
1634 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", | |
1635 | rulla->vcc ? rulla->vcc->vpi : 0, | |
1636 | rulla->vcc ? rulla->vcc->vci : 0, | |
1637 | rulla->recv_vcc ? rulla->recv_vcc->vpi : 0, | |
1638 | rulla->recv_vcc ? rulla->recv_vcc->vci : 0, | |
1639 | rulla->last_used, | |
1640 | rulla->timestamp, rulla->no_tries); | |
1641 | offset += sprintf(buf + offset, | |
1642 | "Flags:%x, Packets_flooded:%x, Status: %s ", | |
1643 | rulla->flags, rulla->packets_flooded, | |
1644 | get_status_string(rulla->status)); | |
1fa9961d CW |
1645 | printk("%s", buf); |
1646 | } | |
1647 | ||
d0732f64 | 1648 | if (!hlist_empty(&priv->mcast_fwds)) |
1fa9961d | 1649 | printk("Multicast Forward VCCs\n"); |
d0732f64 | 1650 | hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) { |
1fa9961d CW |
1651 | offset = 0; |
1652 | offset += sprintf(buf + offset, "Mac:"); | |
1653 | for (j = 0; j < ETH_ALEN; j++) { | |
1654 | offset += sprintf(buf + offset, "%2.2x ", | |
1655 | rulla->mac_addr[j] & 0xff); | |
1656 | } | |
1657 | offset += sprintf(buf + offset, "Atm:"); | |
1658 | for (j = 0; j < ATM_ESA_LEN; j++) { | |
1659 | offset += sprintf(buf + offset, "%2.2x ", | |
1660 | rulla->atm_addr[j] & 0xff); | |
1661 | } | |
1662 | offset += sprintf(buf + offset, | |
1663 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", | |
1664 | rulla->vcc ? rulla->vcc->vpi : 0, | |
1665 | rulla->vcc ? rulla->vcc->vci : 0, | |
1666 | rulla->recv_vcc ? rulla->recv_vcc->vpi : 0, | |
1667 | rulla->recv_vcc ? rulla->recv_vcc->vci : 0, | |
1668 | rulla->last_used, | |
1669 | rulla->timestamp, rulla->no_tries); | |
1670 | offset += sprintf(buf + offset, | |
1671 | "Flags:%x, Packets_flooded:%x, Status: %s ", | |
1672 | rulla->flags, rulla->packets_flooded, | |
1673 | get_status_string(rulla->status)); | |
d0732f64 | 1674 | printk("%s\n", buf); |
1fa9961d | 1675 | } |
1da177e4 | 1676 | |
1da177e4 | 1677 | } |
d0732f64 CW |
1678 | #else |
1679 | #define dump_arp_table(priv) do { } while (0) | |
1680 | #endif | |
1da177e4 LT |
1681 | |
1682 | /* | |
1683 | * Destruction of arp-cache | |
1684 | */ | |
1fa9961d | 1685 | static void lec_arp_destroy(struct lec_priv *priv) |
1da177e4 LT |
1686 | { |
1687 | unsigned long flags; | |
d0732f64 CW |
1688 | struct hlist_node *node, *next; |
1689 | struct lec_arp_table *entry; | |
1fa9961d CW |
1690 | int i; |
1691 | ||
987e46bd | 1692 | cancel_rearming_delayed_work(&priv->lec_arp_work); |
1da177e4 | 1693 | |
1fa9961d CW |
1694 | /* |
1695 | * Remove all entries | |
1696 | */ | |
1da177e4 LT |
1697 | |
1698 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
1fa9961d | 1699 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
d0732f64 | 1700 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { |
1fa9961d | 1701 | lec_arp_remove(priv, entry); |
33a9c2d4 | 1702 | lec_arp_put(entry); |
1fa9961d | 1703 | } |
d0732f64 | 1704 | INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); |
1fa9961d | 1705 | } |
d0732f64 CW |
1706 | |
1707 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { | |
1fa9961d CW |
1708 | del_timer_sync(&entry->timer); |
1709 | lec_arp_clear_vccs(entry); | |
d0732f64 | 1710 | hlist_del(&entry->next); |
33a9c2d4 | 1711 | lec_arp_put(entry); |
1fa9961d | 1712 | } |
d0732f64 CW |
1713 | INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); |
1714 | ||
1715 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) { | |
1fa9961d CW |
1716 | del_timer_sync(&entry->timer); |
1717 | lec_arp_clear_vccs(entry); | |
d0732f64 | 1718 | hlist_del(&entry->next); |
33a9c2d4 | 1719 | lec_arp_put(entry); |
1fa9961d | 1720 | } |
d0732f64 CW |
1721 | INIT_HLIST_HEAD(&priv->lec_no_forward); |
1722 | ||
1723 | hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) { | |
1fa9961d CW |
1724 | /* No timer, LANEv2 7.1.20 and 2.3.5.3 */ |
1725 | lec_arp_clear_vccs(entry); | |
d0732f64 | 1726 | hlist_del(&entry->next); |
33a9c2d4 | 1727 | lec_arp_put(entry); |
1fa9961d | 1728 | } |
d0732f64 | 1729 | INIT_HLIST_HEAD(&priv->mcast_fwds); |
1fa9961d | 1730 | priv->mcast_vcc = NULL; |
1da177e4 LT |
1731 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
1732 | } | |
1733 | ||
f7d57453 | 1734 | /* |
1da177e4 LT |
1735 | * Find entry by mac_address |
1736 | */ | |
1fa9961d CW |
1737 | static struct lec_arp_table *lec_arp_find(struct lec_priv *priv, |
1738 | unsigned char *mac_addr) | |
1da177e4 | 1739 | { |
d0732f64 CW |
1740 | struct hlist_node *node; |
1741 | struct hlist_head *head; | |
1742 | struct lec_arp_table *entry; | |
1fa9961d | 1743 | |
52240062 | 1744 | pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", |
1fa9961d CW |
1745 | mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff, |
1746 | mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff); | |
1fa9961d | 1747 | |
d0732f64 CW |
1748 | head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])]; |
1749 | hlist_for_each_entry(entry, node, head, next) { | |
1750 | if (!compare_ether_addr(mac_addr, entry->mac_addr)) { | |
1751 | return entry; | |
1fa9961d | 1752 | } |
1fa9961d CW |
1753 | } |
1754 | return NULL; | |
1da177e4 LT |
1755 | } |
1756 | ||
1fa9961d CW |
1757 | static struct lec_arp_table *make_entry(struct lec_priv *priv, |
1758 | unsigned char *mac_addr) | |
1da177e4 | 1759 | { |
1fa9961d CW |
1760 | struct lec_arp_table *to_return; |
1761 | ||
1762 | to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC); | |
1763 | if (!to_return) { | |
1764 | printk("LEC: Arp entry kmalloc failed\n"); | |
1765 | return NULL; | |
1766 | } | |
1767 | memcpy(to_return->mac_addr, mac_addr, ETH_ALEN); | |
d0732f64 | 1768 | INIT_HLIST_NODE(&to_return->next); |
b24b8a24 PE |
1769 | setup_timer(&to_return->timer, lec_arp_expire_arp, |
1770 | (unsigned long)to_return); | |
1fa9961d CW |
1771 | to_return->last_used = jiffies; |
1772 | to_return->priv = priv; | |
1773 | skb_queue_head_init(&to_return->tx_wait); | |
33a9c2d4 | 1774 | atomic_set(&to_return->usage, 1); |
1fa9961d | 1775 | return to_return; |
1da177e4 LT |
1776 | } |
1777 | ||
1fa9961d CW |
1778 | /* Arp sent timer expired */ |
1779 | static void lec_arp_expire_arp(unsigned long data) | |
1da177e4 | 1780 | { |
1fa9961d CW |
1781 | struct lec_arp_table *entry; |
1782 | ||
1783 | entry = (struct lec_arp_table *)data; | |
1784 | ||
52240062 | 1785 | pr_debug("lec_arp_expire_arp\n"); |
1fa9961d CW |
1786 | if (entry->status == ESI_ARP_PENDING) { |
1787 | if (entry->no_tries <= entry->priv->max_retry_count) { | |
1788 | if (entry->is_rdesc) | |
1789 | send_to_lecd(entry->priv, l_rdesc_arp_xmt, | |
1790 | entry->mac_addr, NULL, NULL); | |
1791 | else | |
1792 | send_to_lecd(entry->priv, l_arp_xmt, | |
1793 | entry->mac_addr, NULL, NULL); | |
1794 | entry->no_tries++; | |
1795 | } | |
1796 | mod_timer(&entry->timer, jiffies + (1 * HZ)); | |
1797 | } | |
1da177e4 LT |
1798 | } |
1799 | ||
1fa9961d CW |
1800 | /* Unknown/unused vcc expire, remove associated entry */ |
1801 | static void lec_arp_expire_vcc(unsigned long data) | |
1da177e4 LT |
1802 | { |
1803 | unsigned long flags; | |
1fa9961d CW |
1804 | struct lec_arp_table *to_remove = (struct lec_arp_table *)data; |
1805 | struct lec_priv *priv = (struct lec_priv *)to_remove->priv; | |
1da177e4 | 1806 | |
1fa9961d | 1807 | del_timer(&to_remove->timer); |
1da177e4 | 1808 | |
52240062 | 1809 | pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n", |
1fa9961d CW |
1810 | to_remove, priv, |
1811 | to_remove->vcc ? to_remove->recv_vcc->vpi : 0, | |
1812 | to_remove->vcc ? to_remove->recv_vcc->vci : 0); | |
1da177e4 LT |
1813 | |
1814 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
d0732f64 | 1815 | hlist_del(&to_remove->next); |
1da177e4 LT |
1816 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
1817 | ||
1fa9961d | 1818 | lec_arp_clear_vccs(to_remove); |
33a9c2d4 | 1819 | lec_arp_put(to_remove); |
1da177e4 LT |
1820 | } |
1821 | ||
1822 | /* | |
1823 | * Expire entries. | |
1824 | * 1. Re-set timer | |
1825 | * 2. For each entry, delete entries that have aged past the age limit. | |
1826 | * 3. For each entry, depending on the status of the entry, perform | |
1827 | * the following maintenance. | |
1828 | * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the | |
1829 | * tick_count is above the max_unknown_frame_time, clear | |
1830 | * the tick_count to zero and clear the packets_flooded counter | |
1831 | * to zero. This supports the packet rate limit per address | |
1832 | * while flooding unknowns. | |
1833 | * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater | |
1834 | * than or equal to the path_switching_delay, change the status | |
1835 | * to ESI_FORWARD_DIRECT. This causes the flush period to end | |
1836 | * regardless of the progress of the flush protocol. | |
1837 | */ | |
c4028958 | 1838 | static void lec_arp_check_expire(struct work_struct *work) |
1da177e4 LT |
1839 | { |
1840 | unsigned long flags; | |
c4028958 DH |
1841 | struct lec_priv *priv = |
1842 | container_of(work, struct lec_priv, lec_arp_work.work); | |
d0732f64 CW |
1843 | struct hlist_node *node, *next; |
1844 | struct lec_arp_table *entry; | |
1fa9961d CW |
1845 | unsigned long now; |
1846 | unsigned long time_to_check; | |
1847 | int i; | |
1848 | ||
52240062 | 1849 | pr_debug("lec_arp_check_expire %p\n", priv); |
1da177e4 | 1850 | now = jiffies; |
6656e3c4 | 1851 | restart: |
1da177e4 | 1852 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
1fa9961d | 1853 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
d0732f64 | 1854 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { |
1fa9961d | 1855 | if ((entry->flags) & LEC_REMOTE_FLAG && |
1da177e4 LT |
1856 | priv->topology_change) |
1857 | time_to_check = priv->forward_delay_time; | |
1858 | else | |
1859 | time_to_check = priv->aging_time; | |
1860 | ||
52240062 | 1861 | pr_debug("About to expire: %lx - %lx > %lx\n", |
1fa9961d CW |
1862 | now, entry->last_used, time_to_check); |
1863 | if (time_after(now, entry->last_used + time_to_check) | |
1864 | && !(entry->flags & LEC_PERMANENT_FLAG) | |
1865 | && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */ | |
1da177e4 | 1866 | /* Remove entry */ |
52240062 | 1867 | pr_debug("LEC:Entry timed out\n"); |
1da177e4 | 1868 | lec_arp_remove(priv, entry); |
33a9c2d4 | 1869 | lec_arp_put(entry); |
1da177e4 LT |
1870 | } else { |
1871 | /* Something else */ | |
1872 | if ((entry->status == ESI_VC_PENDING || | |
1fa9961d | 1873 | entry->status == ESI_ARP_PENDING) |
1da177e4 | 1874 | && time_after_eq(now, |
1fa9961d CW |
1875 | entry->timestamp + |
1876 | priv-> | |
1877 | max_unknown_frame_time)) { | |
1da177e4 LT |
1878 | entry->timestamp = jiffies; |
1879 | entry->packets_flooded = 0; | |
1880 | if (entry->status == ESI_VC_PENDING) | |
1fa9961d CW |
1881 | send_to_lecd(priv, l_svc_setup, |
1882 | entry->mac_addr, | |
1883 | entry->atm_addr, | |
1884 | NULL); | |
1da177e4 | 1885 | } |
1fa9961d CW |
1886 | if (entry->status == ESI_FLUSH_PENDING |
1887 | && | |
1888 | time_after_eq(now, entry->timestamp + | |
1889 | priv->path_switching_delay)) { | |
1da177e4 | 1890 | struct sk_buff *skb; |
6656e3c4 | 1891 | struct atm_vcc *vcc = entry->vcc; |
1da177e4 | 1892 | |
6656e3c4 CW |
1893 | lec_arp_hold(entry); |
1894 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
1895 | while ((skb = skb_dequeue(&entry->tx_wait)) != NULL) | |
1896 | lec_send(vcc, skb, entry->priv); | |
1da177e4 | 1897 | entry->last_used = jiffies; |
1fa9961d | 1898 | entry->status = ESI_FORWARD_DIRECT; |
6656e3c4 CW |
1899 | lec_arp_put(entry); |
1900 | goto restart; | |
1da177e4 | 1901 | } |
1da177e4 LT |
1902 | } |
1903 | } | |
1904 | } | |
1905 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
1906 | ||
987e46bd | 1907 | schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL); |
1da177e4 | 1908 | } |
1fa9961d | 1909 | |
1da177e4 LT |
1910 | /* |
1911 | * Try to find vcc where mac_address is attached. | |
f7d57453 | 1912 | * |
1da177e4 | 1913 | */ |
1fa9961d CW |
1914 | static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv, |
1915 | unsigned char *mac_to_find, int is_rdesc, | |
1916 | struct lec_arp_table **ret_entry) | |
1da177e4 LT |
1917 | { |
1918 | unsigned long flags; | |
1fa9961d | 1919 | struct lec_arp_table *entry; |
1da177e4 LT |
1920 | struct atm_vcc *found; |
1921 | ||
1fa9961d CW |
1922 | if (mac_to_find[0] & 0x01) { |
1923 | switch (priv->lane_version) { | |
1924 | case 1: | |
1925 | return priv->mcast_vcc; | |
1926 | break; | |
1927 | case 2: /* LANE2 wants arp for multicast addresses */ | |
1928 | if (!compare_ether_addr(mac_to_find, bus_mac)) | |
1929 | return priv->mcast_vcc; | |
1930 | break; | |
1931 | default: | |
1932 | break; | |
1933 | } | |
1934 | } | |
1da177e4 LT |
1935 | |
1936 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
1fa9961d CW |
1937 | entry = lec_arp_find(priv, mac_to_find); |
1938 | ||
1939 | if (entry) { | |
1940 | if (entry->status == ESI_FORWARD_DIRECT) { | |
1941 | /* Connection Ok */ | |
1942 | entry->last_used = jiffies; | |
6656e3c4 | 1943 | lec_arp_hold(entry); |
1fa9961d CW |
1944 | *ret_entry = entry; |
1945 | found = entry->vcc; | |
1da177e4 | 1946 | goto out; |
1fa9961d CW |
1947 | } |
1948 | /* | |
1949 | * If the LE_ARP cache entry is still pending, reset count to 0 | |
75b895c1 ST |
1950 | * so another LE_ARP request can be made for this frame. |
1951 | */ | |
1952 | if (entry->status == ESI_ARP_PENDING) { | |
1953 | entry->no_tries = 0; | |
1954 | } | |
1fa9961d CW |
1955 | /* |
1956 | * Data direct VC not yet set up, check to see if the unknown | |
1957 | * frame count is greater than the limit. If the limit has | |
1958 | * not been reached, allow the caller to send packet to | |
1959 | * BUS. | |
1960 | */ | |
1961 | if (entry->status != ESI_FLUSH_PENDING && | |
1962 | entry->packets_flooded < | |
1963 | priv->maximum_unknown_frame_count) { | |
1964 | entry->packets_flooded++; | |
52240062 | 1965 | pr_debug("LEC_ARP: Flooding..\n"); |
1fa9961d | 1966 | found = priv->mcast_vcc; |
1da177e4 | 1967 | goto out; |
1fa9961d CW |
1968 | } |
1969 | /* | |
1970 | * We got here because entry->status == ESI_FLUSH_PENDING | |
1da177e4 LT |
1971 | * or BUS flood limit was reached for an entry which is |
1972 | * in ESI_ARP_PENDING or ESI_VC_PENDING state. | |
1973 | */ | |
6656e3c4 | 1974 | lec_arp_hold(entry); |
1fa9961d | 1975 | *ret_entry = entry; |
52240062 | 1976 | pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status, |
1fa9961d CW |
1977 | entry->vcc); |
1978 | found = NULL; | |
1979 | } else { | |
1980 | /* No matching entry was found */ | |
1981 | entry = make_entry(priv, mac_to_find); | |
52240062 | 1982 | pr_debug("LEC_ARP: Making entry\n"); |
1fa9961d CW |
1983 | if (!entry) { |
1984 | found = priv->mcast_vcc; | |
1da177e4 | 1985 | goto out; |
1fa9961d CW |
1986 | } |
1987 | lec_arp_add(priv, entry); | |
1988 | /* We want arp-request(s) to be sent */ | |
1989 | entry->packets_flooded = 1; | |
1990 | entry->status = ESI_ARP_PENDING; | |
1991 | entry->no_tries = 1; | |
1992 | entry->last_used = entry->timestamp = jiffies; | |
1993 | entry->is_rdesc = is_rdesc; | |
1994 | if (entry->is_rdesc) | |
1995 | send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, | |
1996 | NULL); | |
1997 | else | |
1998 | send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL); | |
1999 | entry->timer.expires = jiffies + (1 * HZ); | |
2000 | entry->timer.function = lec_arp_expire_arp; | |
2001 | add_timer(&entry->timer); | |
2002 | found = priv->mcast_vcc; | |
2003 | } | |
1da177e4 LT |
2004 | |
2005 | out: | |
2006 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2007 | return found; | |
2008 | } | |
2009 | ||
2010 | static int | |
1fa9961d CW |
2011 | lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr, |
2012 | unsigned long permanent) | |
1da177e4 LT |
2013 | { |
2014 | unsigned long flags; | |
d0732f64 CW |
2015 | struct hlist_node *node, *next; |
2016 | struct lec_arp_table *entry; | |
1fa9961d | 2017 | int i; |
1da177e4 | 2018 | |
52240062 | 2019 | pr_debug("lec_addr_delete\n"); |
1da177e4 | 2020 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
1fa9961d | 2021 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
d0732f64 | 2022 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2023 | if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) |
2024 | && (permanent || | |
2025 | !(entry->flags & LEC_PERMANENT_FLAG))) { | |
1da177e4 | 2026 | lec_arp_remove(priv, entry); |
33a9c2d4 | 2027 | lec_arp_put(entry); |
1fa9961d | 2028 | } |
1da177e4 | 2029 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
1fa9961d CW |
2030 | return 0; |
2031 | } | |
2032 | } | |
1da177e4 | 2033 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
1fa9961d | 2034 | return -1; |
1da177e4 LT |
2035 | } |
2036 | ||
2037 | /* | |
f7d57453 | 2038 | * Notifies: Response to arp_request (atm_addr != NULL) |
1da177e4 LT |
2039 | */ |
2040 | static void | |
2041 | lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr, | |
1fa9961d CW |
2042 | unsigned char *atm_addr, unsigned long remoteflag, |
2043 | unsigned int targetless_le_arp) | |
1da177e4 LT |
2044 | { |
2045 | unsigned long flags; | |
d0732f64 | 2046 | struct hlist_node *node, *next; |
1fa9961d CW |
2047 | struct lec_arp_table *entry, *tmp; |
2048 | int i; | |
1da177e4 | 2049 | |
52240062 SH |
2050 | pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " "); |
2051 | pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n", | |
1fa9961d CW |
2052 | mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], |
2053 | mac_addr[4], mac_addr[5]); | |
1da177e4 LT |
2054 | |
2055 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
1fa9961d CW |
2056 | entry = lec_arp_find(priv, mac_addr); |
2057 | if (entry == NULL && targetless_le_arp) | |
2058 | goto out; /* | |
2059 | * LANE2: ignore targetless LE_ARPs for which | |
2060 | * we have no entry in the cache. 7.1.30 | |
2061 | */ | |
d0732f64 CW |
2062 | if (!hlist_empty(&priv->lec_arp_empty_ones)) { |
2063 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { | |
2064 | if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) { | |
2065 | hlist_del(&entry->next); | |
1fa9961d | 2066 | del_timer(&entry->timer); |
d0732f64 CW |
2067 | tmp = lec_arp_find(priv, mac_addr); |
2068 | if (tmp) { | |
2069 | del_timer(&tmp->timer); | |
2070 | tmp->status = ESI_FORWARD_DIRECT; | |
2071 | memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN); | |
2072 | tmp->vcc = entry->vcc; | |
2073 | tmp->old_push = entry->old_push; | |
2074 | tmp->last_used = jiffies; | |
2075 | del_timer(&entry->timer); | |
33a9c2d4 | 2076 | lec_arp_put(entry); |
d0732f64 CW |
2077 | entry = tmp; |
2078 | } else { | |
2079 | entry->status = ESI_FORWARD_DIRECT; | |
2080 | memcpy(entry->mac_addr, mac_addr, ETH_ALEN); | |
2081 | entry->last_used = jiffies; | |
2082 | lec_arp_add(priv, entry); | |
2083 | } | |
2084 | if (remoteflag) | |
2085 | entry->flags |= LEC_REMOTE_FLAG; | |
2086 | else | |
2087 | entry->flags &= ~LEC_REMOTE_FLAG; | |
52240062 | 2088 | pr_debug("After update\n"); |
d0732f64 CW |
2089 | dump_arp_table(priv); |
2090 | goto out; | |
1fa9961d | 2091 | } |
1fa9961d CW |
2092 | } |
2093 | } | |
d0732f64 | 2094 | |
1fa9961d CW |
2095 | entry = lec_arp_find(priv, mac_addr); |
2096 | if (!entry) { | |
2097 | entry = make_entry(priv, mac_addr); | |
2098 | if (!entry) | |
2099 | goto out; | |
2100 | entry->status = ESI_UNKNOWN; | |
2101 | lec_arp_add(priv, entry); | |
2102 | /* Temporary, changes before end of function */ | |
2103 | } | |
2104 | memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN); | |
2105 | del_timer(&entry->timer); | |
2106 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { | |
d0732f64 | 2107 | hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2108 | if (entry != tmp && |
2109 | !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) { | |
2110 | /* Vcc to this host exists */ | |
2111 | if (tmp->status > ESI_VC_PENDING) { | |
2112 | /* | |
2113 | * ESI_FLUSH_PENDING, | |
2114 | * ESI_FORWARD_DIRECT | |
2115 | */ | |
2116 | entry->vcc = tmp->vcc; | |
2117 | entry->old_push = tmp->old_push; | |
2118 | } | |
2119 | entry->status = tmp->status; | |
2120 | break; | |
2121 | } | |
2122 | } | |
2123 | } | |
2124 | if (remoteflag) | |
2125 | entry->flags |= LEC_REMOTE_FLAG; | |
2126 | else | |
2127 | entry->flags &= ~LEC_REMOTE_FLAG; | |
2128 | if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) { | |
2129 | entry->status = ESI_VC_PENDING; | |
d0732f64 | 2130 | send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL); |
1fa9961d | 2131 | } |
52240062 | 2132 | pr_debug("After update2\n"); |
1fa9961d | 2133 | dump_arp_table(priv); |
1da177e4 LT |
2134 | out: |
2135 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2136 | } | |
2137 | ||
2138 | /* | |
f7d57453 | 2139 | * Notifies: Vcc setup ready |
1da177e4 LT |
2140 | */ |
2141 | static void | |
2142 | lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data, | |
1fa9961d CW |
2143 | struct atm_vcc *vcc, |
2144 | void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb)) | |
1da177e4 LT |
2145 | { |
2146 | unsigned long flags; | |
d0732f64 | 2147 | struct hlist_node *node; |
1fa9961d CW |
2148 | struct lec_arp_table *entry; |
2149 | int i, found_entry = 0; | |
1da177e4 LT |
2150 | |
2151 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
1fa9961d CW |
2152 | if (ioc_data->receive == 2) { |
2153 | /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */ | |
1da177e4 | 2154 | |
52240062 | 2155 | pr_debug("LEC_ARP: Attaching mcast forward\n"); |
1da177e4 | 2156 | #if 0 |
1fa9961d CW |
2157 | entry = lec_arp_find(priv, bus_mac); |
2158 | if (!entry) { | |
2159 | printk("LEC_ARP: Multicast entry not found!\n"); | |
1da177e4 | 2160 | goto out; |
1fa9961d CW |
2161 | } |
2162 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); | |
2163 | entry->recv_vcc = vcc; | |
2164 | entry->old_recv_push = old_push; | |
1da177e4 | 2165 | #endif |
1fa9961d CW |
2166 | entry = make_entry(priv, bus_mac); |
2167 | if (entry == NULL) | |
1da177e4 | 2168 | goto out; |
1fa9961d CW |
2169 | del_timer(&entry->timer); |
2170 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); | |
2171 | entry->recv_vcc = vcc; | |
2172 | entry->old_recv_push = old_push; | |
d0732f64 | 2173 | hlist_add_head(&entry->next, &priv->mcast_fwds); |
1fa9961d CW |
2174 | goto out; |
2175 | } else if (ioc_data->receive == 1) { | |
2176 | /* | |
2177 | * Vcc which we don't want to make default vcc, | |
2178 | * attach it anyway. | |
2179 | */ | |
52240062 | 2180 | pr_debug |
1fa9961d CW |
2181 | ("LEC_ARP:Attaching data direct, not 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 | entry = make_entry(priv, bus_mac); | |
2194 | if (entry == NULL) | |
1da177e4 | 2195 | goto out; |
1fa9961d CW |
2196 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); |
2197 | memset(entry->mac_addr, 0, ETH_ALEN); | |
2198 | entry->recv_vcc = vcc; | |
2199 | entry->old_recv_push = old_push; | |
2200 | entry->status = ESI_UNKNOWN; | |
2201 | entry->timer.expires = jiffies + priv->vcc_timeout_period; | |
2202 | entry->timer.function = lec_arp_expire_vcc; | |
d0732f64 | 2203 | hlist_add_head(&entry->next, &priv->lec_no_forward); |
1fa9961d | 2204 | add_timer(&entry->timer); |
1da177e4 LT |
2205 | dump_arp_table(priv); |
2206 | goto out; | |
1fa9961d | 2207 | } |
52240062 | 2208 | pr_debug |
1fa9961d CW |
2209 | ("LEC_ARP:Attaching data direct, default: " |
2210 | "%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", | |
2211 | ioc_data->atm_addr[0], ioc_data->atm_addr[1], | |
2212 | ioc_data->atm_addr[2], ioc_data->atm_addr[3], | |
2213 | ioc_data->atm_addr[4], ioc_data->atm_addr[5], | |
2214 | ioc_data->atm_addr[6], ioc_data->atm_addr[7], | |
2215 | ioc_data->atm_addr[8], ioc_data->atm_addr[9], | |
2216 | ioc_data->atm_addr[10], ioc_data->atm_addr[11], | |
2217 | ioc_data->atm_addr[12], ioc_data->atm_addr[13], | |
2218 | ioc_data->atm_addr[14], ioc_data->atm_addr[15], | |
2219 | ioc_data->atm_addr[16], ioc_data->atm_addr[17], | |
2220 | ioc_data->atm_addr[18], ioc_data->atm_addr[19]); | |
2221 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { | |
d0732f64 | 2222 | hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2223 | if (memcmp |
2224 | (ioc_data->atm_addr, entry->atm_addr, | |
2225 | ATM_ESA_LEN) == 0) { | |
52240062 SH |
2226 | pr_debug("LEC_ARP: Attaching data direct\n"); |
2227 | pr_debug("Currently -> Vcc: %d, Rvcc:%d\n", | |
1fa9961d CW |
2228 | entry->vcc ? entry->vcc->vci : 0, |
2229 | entry->recv_vcc ? entry->recv_vcc-> | |
2230 | vci : 0); | |
2231 | found_entry = 1; | |
2232 | del_timer(&entry->timer); | |
2233 | entry->vcc = vcc; | |
2234 | entry->old_push = old_push; | |
2235 | if (entry->status == ESI_VC_PENDING) { | |
2236 | if (priv->maximum_unknown_frame_count | |
2237 | == 0) | |
2238 | entry->status = | |
2239 | ESI_FORWARD_DIRECT; | |
2240 | else { | |
2241 | entry->timestamp = jiffies; | |
2242 | entry->status = | |
2243 | ESI_FLUSH_PENDING; | |
1da177e4 | 2244 | #if 0 |
1fa9961d CW |
2245 | send_to_lecd(priv, l_flush_xmt, |
2246 | NULL, | |
2247 | entry->atm_addr, | |
2248 | NULL); | |
1da177e4 | 2249 | #endif |
1fa9961d CW |
2250 | } |
2251 | } else { | |
2252 | /* | |
2253 | * They were forming a connection | |
2254 | * to us, and we to them. Our | |
2255 | * ATM address is numerically lower | |
2256 | * than theirs, so we make connection | |
2257 | * we formed into default VCC (8.1.11). | |
2258 | * Connection they made gets torn | |
2259 | * down. This might confuse some | |
2260 | * clients. Can be changed if | |
2261 | * someone reports trouble... | |
2262 | */ | |
2263 | ; | |
2264 | } | |
2265 | } | |
2266 | } | |
2267 | } | |
2268 | if (found_entry) { | |
52240062 | 2269 | pr_debug("After vcc was added\n"); |
1fa9961d | 2270 | dump_arp_table(priv); |
1da177e4 | 2271 | goto out; |
1fa9961d CW |
2272 | } |
2273 | /* | |
2274 | * Not found, snatch address from first data packet that arrives | |
2275 | * from this vcc | |
2276 | */ | |
2277 | entry = make_entry(priv, bus_mac); | |
2278 | if (!entry) | |
1da177e4 | 2279 | goto out; |
1fa9961d CW |
2280 | entry->vcc = vcc; |
2281 | entry->old_push = old_push; | |
2282 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); | |
2283 | memset(entry->mac_addr, 0, ETH_ALEN); | |
2284 | entry->status = ESI_UNKNOWN; | |
d0732f64 | 2285 | hlist_add_head(&entry->next, &priv->lec_arp_empty_ones); |
1fa9961d CW |
2286 | entry->timer.expires = jiffies + priv->vcc_timeout_period; |
2287 | entry->timer.function = lec_arp_expire_vcc; | |
2288 | add_timer(&entry->timer); | |
52240062 | 2289 | pr_debug("After vcc was added\n"); |
1da177e4 LT |
2290 | dump_arp_table(priv); |
2291 | out: | |
2292 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2293 | } | |
2294 | ||
1fa9961d | 2295 | static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id) |
1da177e4 LT |
2296 | { |
2297 | unsigned long flags; | |
d0732f64 | 2298 | struct hlist_node *node; |
1fa9961d CW |
2299 | struct lec_arp_table *entry; |
2300 | int i; | |
1da177e4 | 2301 | |
52240062 | 2302 | pr_debug("LEC:lec_flush_complete %lx\n", tran_id); |
6656e3c4 | 2303 | restart: |
1fa9961d CW |
2304 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
2305 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { | |
d0732f64 | 2306 | hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2307 | if (entry->flush_tran_id == tran_id |
2308 | && entry->status == ESI_FLUSH_PENDING) { | |
2309 | struct sk_buff *skb; | |
6656e3c4 | 2310 | struct atm_vcc *vcc = entry->vcc; |
1fa9961d | 2311 | |
6656e3c4 CW |
2312 | lec_arp_hold(entry); |
2313 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2314 | while ((skb = skb_dequeue(&entry->tx_wait)) != NULL) | |
2315 | lec_send(vcc, skb, entry->priv); | |
2316 | entry->last_used = jiffies; | |
1fa9961d | 2317 | entry->status = ESI_FORWARD_DIRECT; |
6656e3c4 | 2318 | lec_arp_put(entry); |
52240062 | 2319 | pr_debug("LEC_ARP: Flushed\n"); |
6656e3c4 | 2320 | goto restart; |
1fa9961d CW |
2321 | } |
2322 | } | |
2323 | } | |
1da177e4 | 2324 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
1fa9961d | 2325 | dump_arp_table(priv); |
1da177e4 LT |
2326 | } |
2327 | ||
2328 | static void | |
2329 | lec_set_flush_tran_id(struct lec_priv *priv, | |
1fa9961d | 2330 | unsigned char *atm_addr, unsigned long tran_id) |
1da177e4 LT |
2331 | { |
2332 | unsigned long flags; | |
d0732f64 | 2333 | struct hlist_node *node; |
1fa9961d CW |
2334 | struct lec_arp_table *entry; |
2335 | int i; | |
1da177e4 LT |
2336 | |
2337 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
1fa9961d | 2338 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) |
d0732f64 | 2339 | hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2340 | if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) { |
2341 | entry->flush_tran_id = tran_id; | |
52240062 | 2342 | pr_debug("Set flush transaction id to %lx for %p\n", |
f7d57453 | 2343 | tran_id, entry); |
1fa9961d | 2344 | } |
d0732f64 | 2345 | } |
1da177e4 LT |
2346 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
2347 | } | |
2348 | ||
1fa9961d | 2349 | static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc) |
1da177e4 LT |
2350 | { |
2351 | unsigned long flags; | |
1fa9961d CW |
2352 | unsigned char mac_addr[] = { |
2353 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
2354 | }; | |
2355 | struct lec_arp_table *to_add; | |
1da177e4 LT |
2356 | struct lec_vcc_priv *vpriv; |
2357 | int err = 0; | |
1fa9961d | 2358 | |
1da177e4 LT |
2359 | if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL))) |
2360 | return -ENOMEM; | |
2361 | vpriv->xoff = 0; | |
2362 | vpriv->old_pop = vcc->pop; | |
2363 | vcc->user_back = vpriv; | |
1fa9961d | 2364 | vcc->pop = lec_pop; |
1da177e4 | 2365 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
1fa9961d CW |
2366 | to_add = make_entry(priv, mac_addr); |
2367 | if (!to_add) { | |
1da177e4 LT |
2368 | vcc->pop = vpriv->old_pop; |
2369 | kfree(vpriv); | |
1fa9961d | 2370 | err = -ENOMEM; |
1da177e4 | 2371 | goto out; |
1fa9961d CW |
2372 | } |
2373 | memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN); | |
2374 | to_add->status = ESI_FORWARD_DIRECT; | |
2375 | to_add->flags |= LEC_PERMANENT_FLAG; | |
2376 | to_add->vcc = vcc; | |
2377 | to_add->old_push = vcc->push; | |
2378 | vcc->push = lec_push; | |
2379 | priv->mcast_vcc = vcc; | |
2380 | lec_arp_add(priv, to_add); | |
1da177e4 LT |
2381 | out: |
2382 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
1fa9961d | 2383 | return err; |
1da177e4 LT |
2384 | } |
2385 | ||
1fa9961d | 2386 | static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc) |
1da177e4 LT |
2387 | { |
2388 | unsigned long flags; | |
d0732f64 CW |
2389 | struct hlist_node *node, *next; |
2390 | struct lec_arp_table *entry; | |
1fa9961d | 2391 | int i; |
1da177e4 | 2392 | |
52240062 | 2393 | pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci); |
1fa9961d | 2394 | dump_arp_table(priv); |
d0732f64 | 2395 | |
1da177e4 | 2396 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
d0732f64 | 2397 | |
1fa9961d | 2398 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
d0732f64 | 2399 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { |
1fa9961d CW |
2400 | if (vcc == entry->vcc) { |
2401 | lec_arp_remove(priv, entry); | |
33a9c2d4 | 2402 | lec_arp_put(entry); |
1fa9961d CW |
2403 | if (priv->mcast_vcc == vcc) { |
2404 | priv->mcast_vcc = NULL; | |
2405 | } | |
2406 | } | |
2407 | } | |
2408 | } | |
2409 | ||
d0732f64 CW |
2410 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { |
2411 | if (entry->vcc == vcc) { | |
1fa9961d CW |
2412 | lec_arp_clear_vccs(entry); |
2413 | del_timer(&entry->timer); | |
d0732f64 | 2414 | hlist_del(&entry->next); |
33a9c2d4 | 2415 | lec_arp_put(entry); |
1fa9961d | 2416 | } |
1fa9961d CW |
2417 | } |
2418 | ||
d0732f64 | 2419 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) { |
1fa9961d CW |
2420 | if (entry->recv_vcc == vcc) { |
2421 | lec_arp_clear_vccs(entry); | |
2422 | del_timer(&entry->timer); | |
d0732f64 | 2423 | hlist_del(&entry->next); |
33a9c2d4 | 2424 | lec_arp_put(entry); |
1fa9961d | 2425 | } |
1fa9961d CW |
2426 | } |
2427 | ||
d0732f64 | 2428 | hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) { |
1fa9961d CW |
2429 | if (entry->recv_vcc == vcc) { |
2430 | lec_arp_clear_vccs(entry); | |
2431 | /* No timer, LANEv2 7.1.20 and 2.3.5.3 */ | |
d0732f64 | 2432 | hlist_del(&entry->next); |
33a9c2d4 | 2433 | lec_arp_put(entry); |
1fa9961d | 2434 | } |
1fa9961d | 2435 | } |
1da177e4 LT |
2436 | |
2437 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2438 | dump_arp_table(priv); | |
2439 | } | |
2440 | ||
2441 | static void | |
2442 | lec_arp_check_empties(struct lec_priv *priv, | |
1fa9961d | 2443 | struct atm_vcc *vcc, struct sk_buff *skb) |
1da177e4 | 2444 | { |
1fa9961d | 2445 | unsigned long flags; |
d0732f64 CW |
2446 | struct hlist_node *node, *next; |
2447 | struct lec_arp_table *entry, *tmp; | |
1fa9961d CW |
2448 | struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data; |
2449 | unsigned char *src; | |
1da177e4 | 2450 | #ifdef CONFIG_TR |
1fa9961d | 2451 | struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data; |
1da177e4 | 2452 | |
1fa9961d CW |
2453 | if (priv->is_trdev) |
2454 | src = tr_hdr->h_source; | |
2455 | else | |
1da177e4 | 2456 | #endif |
1fa9961d | 2457 | src = hdr->h_source; |
1da177e4 LT |
2458 | |
2459 | spin_lock_irqsave(&priv->lec_arp_lock, flags); | |
d0732f64 CW |
2460 | hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { |
2461 | if (vcc == entry->vcc) { | |
2462 | del_timer(&entry->timer); | |
2463 | memcpy(entry->mac_addr, src, ETH_ALEN); | |
2464 | entry->status = ESI_FORWARD_DIRECT; | |
2465 | entry->last_used = jiffies; | |
2466 | /* We might have got an entry */ | |
2467 | if ((tmp = lec_arp_find(priv, src))) { | |
2468 | lec_arp_remove(priv, tmp); | |
33a9c2d4 | 2469 | lec_arp_put(tmp); |
d0732f64 CW |
2470 | } |
2471 | hlist_del(&entry->next); | |
2472 | lec_arp_add(priv, entry); | |
2473 | goto out; | |
1fa9961d | 2474 | } |
1fa9961d | 2475 | } |
52240062 | 2476 | pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n"); |
1da177e4 LT |
2477 | out: |
2478 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); | |
2479 | } | |
1fa9961d | 2480 | |
1da177e4 | 2481 | MODULE_LICENSE("GPL"); |