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