blob: e5ed878c8825225da1e67bb4d360268c272e788b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26
27/* TokenRing if needed */
28#ifdef CONFIG_TR
29#include <linux/trdevice.h>
30#endif
31
32/* And atm device */
33#include <linux/atmdev.h>
34#include <linux/atmlec.h>
35
36/* Proxy LEC knows about bridging */
37#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38#include <linux/if_bridge.h>
39#include "../bridge/br_private.h"
40
Chas Williamsd44f7742006-09-29 17:11:14 -070041static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#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
52#if 0
53#define DPRINTK printk
54#else
55#define DPRINTK(format,args...)
56#endif
57
Chas Williamsd44f7742006-09-29 17:11:14 -070058#define DUMP_PACKETS 0 /*
59 * 0 = None,
60 * 1 = 30 first bytes
61 * 2 = Whole packet
62 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Chas Williamsd44f7742006-09-29 17:11:14 -070064#define LEC_UNRES_QUE_LEN 8 /*
65 * number of tx packets to queue for a
66 * single destination while waiting for SVC
67 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static int lec_open(struct net_device *dev);
70static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
71static int lec_close(struct net_device *dev);
72static struct net_device_stats *lec_get_stats(struct net_device *dev);
73static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070074static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
75 unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070077 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/* LANE2 functions */
Chas Williamsd44f7742006-09-29 17:11:14 -070079static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
80 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070082 u8 **tlvs, u32 *sizeoftlvs);
83static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
84 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Chas Williamsd44f7742006-09-29 17:11:14 -070086static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 unsigned long permanent);
88static void lec_arp_check_empties(struct lec_priv *priv,
89 struct atm_vcc *vcc, struct sk_buff *skb);
90static void lec_arp_destroy(struct lec_priv *priv);
91static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070092static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 unsigned char *mac_to_find,
94 int is_rdesc,
95 struct lec_arp_table **ret_entry);
96static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
97 unsigned char *atm_addr, unsigned long remoteflag,
98 unsigned int targetless_le_arp);
99static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
100static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
101static void lec_set_flush_tran_id(struct lec_priv *priv,
102 unsigned char *atm_addr,
103 unsigned long tran_id);
104static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
105 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -0700106 void (*old_push) (struct atm_vcc *vcc,
107 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
109
Chas Williams33a9c2d2006-09-29 17:16:48 -0700110/* must be done under lec_arp_lock */
111static inline void lec_arp_hold(struct lec_arp_table *entry)
112{
113 atomic_inc(&entry->usage);
114}
115
116static inline void lec_arp_put(struct lec_arp_table *entry)
117{
118 if (atomic_dec_and_test(&entry->usage))
119 kfree(entry);
120}
121
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700124 lane2_resolve, /* resolve, spec 3.1.3 */
125 lane2_associate_req, /* associate_req, spec 3.1.4 */
126 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
Chas Williamsd44f7742006-09-29 17:11:14 -0700129static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/* Device structures */
132static struct net_device *dev_lec[MAX_LEC_ITF];
133
134#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
135static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
136{
Chas Williamsd44f7742006-09-29 17:11:14 -0700137 struct ethhdr *eth;
138 char *buff;
139 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Chas Williamsd44f7742006-09-29 17:11:14 -0700141 /*
142 * Check if this is a BPDU. If so, ask zeppelin to send
143 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
144 * as the Config BPDU has
145 */
146 eth = (struct ethhdr *)skb->data;
147 buff = skb->data + skb->dev->hard_header_len;
148 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700150 struct sk_buff *skb2;
151 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Chas Williamsd44f7742006-09-29 17:11:14 -0700153 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
154 if (skb2 == NULL)
155 return;
156 skb2->len = sizeof(struct atmlec_msg);
157 mesg = (struct atmlec_msg *)skb2->data;
158 mesg->type = l_topology_change;
159 buff += 4;
160 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Chas Williamsd44f7742006-09-29 17:11:14 -0700162 priv = (struct lec_priv *)dev->priv;
163 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700165 skb_queue_tail(&sk->sk_receive_queue, skb2);
166 sk->sk_data_ready(sk, skb2->len);
167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Chas Williamsd44f7742006-09-29 17:11:14 -0700169 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
172
173/*
174 * Modelled after tr_type_trans
175 * All multicast and ARE or STE frames go to BUS.
176 * Non source routed frames go by destination address.
177 * Last hop source routed frames go by destination address.
178 * Not last hop source routed frames go by _next_ route descriptor.
179 * Returns pointer to destination MAC address or fills in rdesc
180 * and returns NULL.
181 */
182#ifdef CONFIG_TR
183static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
184{
Chas Williamsd44f7742006-09-29 17:11:14 -0700185 struct trh_hdr *trh;
186 int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Chas Williamsd44f7742006-09-29 17:11:14 -0700188 trh = (struct trh_hdr *)packet;
189 if (trh->daddr[0] & (uint8_t) 0x80)
190 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chas Williamsd44f7742006-09-29 17:11:14 -0700192 if (trh->saddr[0] & TR_RII) {
193 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
194 if ((ntohs(trh->rcf) >> 13) != 0)
195 return bus_mac; /* ARE or STE */
196 } else
197 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Chas Williamsd44f7742006-09-29 17:11:14 -0700199 if (riflen < 6)
200 return trh->daddr; /* last hop, source routed */
201
202 /* riflen is 6 or more, packet has more than one route descriptor */
203 num_rdsc = (riflen / 2) - 1;
204 memset(rdesc, 0, ETH_ALEN);
205 /* offset 4 comes from LAN destination field in LE control frames */
206 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800207 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700208 else {
Al Viro30d492d2006-11-14 21:11:29 -0800209 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700210 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
211 }
212
213 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215#endif /* CONFIG_TR */
216
217/*
218 * Open/initialize the netdevice. This is called (in the current kernel)
219 * sometime after booting when the 'ifconfig' program is run.
220 *
221 * This routine should set everything up anew at each open, even
222 * registers that "should" only need to be set once at boot, so that
223 * there is non-reboot way to recover if something goes wrong.
224 */
225
Chas Williamsd44f7742006-09-29 17:11:14 -0700226static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Chas Williamsd44f7742006-09-29 17:11:14 -0700228 struct lec_priv *priv = (struct lec_priv *)dev->priv;
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700231 memset(&priv->stats, 0, sizeof(struct net_device_stats));
232
233 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236static __inline__ void
237lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
238{
239 ATM_SKB(skb)->vcc = vcc;
240 ATM_SKB(skb)->atm_options = vcc->atm_options;
241
242 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
243 if (vcc->send(vcc, skb) < 0) {
244 priv->stats.tx_dropped++;
245 return;
246 }
247
248 priv->stats.tx_packets++;
249 priv->stats.tx_bytes += skb->len;
250}
251
Chas Williamsd44f7742006-09-29 17:11:14 -0700252static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 printk(KERN_INFO "%s: tx timeout\n", dev->name);
255 dev->trans_start = jiffies;
256 netif_wake_queue(dev);
257}
258
Chas Williamsd44f7742006-09-29 17:11:14 -0700259static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Chas Williamsd44f7742006-09-29 17:11:14 -0700261 struct sk_buff *skb2;
262 struct lec_priv *priv = (struct lec_priv *)dev->priv;
263 struct lecdatahdr_8023 *lec_h;
264 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700266 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 int min_frame_size;
268#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700269 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700273 char buf[300];
274 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Chas Williamsd44f7742006-09-29 17:11:14 -0700277 DPRINTK("lec_start_xmit called\n");
278 if (!priv->lecd) {
279 printk("%s:No lecd attached\n", dev->name);
280 priv->stats.tx_errors++;
281 netif_stop_queue(dev);
282 return -EUNATCH;
283 }
284
285 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
286 (long)skb->head, (long)skb->data, (long)skb->tail,
287 (long)skb->end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700289 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
290 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif
292
Chas Williamsd44f7742006-09-29 17:11:14 -0700293 /* Make sure we have room for lec_id */
294 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Chas Williamsd44f7742006-09-29 17:11:14 -0700296 DPRINTK("lec_start_xmit: reallocating skb\n");
297 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
298 kfree_skb(skb);
299 if (skb2 == NULL)
300 return 0;
301 skb = skb2;
302 }
303 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Chas Williamsd44f7742006-09-29 17:11:14 -0700305 /* Put le header to place, works for TokenRing too */
306 lec_h = (struct lecdatahdr_8023 *)skb->data;
307 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700310 /*
311 * Ugly. Use this to realign Token Ring packets for
312 * e.g. PCA-200E driver.
313 */
314 if (priv->is_trdev) {
315 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
316 kfree_skb(skb);
317 if (skb2 == NULL)
318 return 0;
319 skb = skb2;
320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#endif
322
323#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
325 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700327 for (i = 0; i < skb->len && i < 99; i++) {
328 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700331 for (i = 0; i < skb->len && i < 30; i++) {
332 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700335 if (i == skb->len)
336 printk("%s\n", buf);
337 else
338 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#endif /* DUMP_PACKETS > 0 */
340
Chas Williamsd44f7742006-09-29 17:11:14 -0700341 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700343 if (priv->is_trdev)
344 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 else
346#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700347 min_frame_size = LEC_MINIMUM_8023_SIZE;
348 if (skb->len < min_frame_size) {
349 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
350 skb2 = skb_copy_expand(skb, 0,
351 min_frame_size - skb->truesize,
352 GFP_ATOMIC);
353 dev_kfree_skb(skb);
354 if (skb2 == NULL) {
355 priv->stats.tx_dropped++;
356 return 0;
357 }
358 skb = skb2;
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700361 }
362
363 /* Send to right vcc */
364 is_rdesc = 0;
365 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700367 if (priv->is_trdev) {
368 dst = get_tr_dst(skb->data + 2, rdesc);
369 if (dst == NULL) {
370 dst = rdesc;
371 is_rdesc = 1;
372 }
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 entry = NULL;
376 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
377 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
378 vcc, vcc ? vcc->flags : 0, entry);
379 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
380 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
381 DPRINTK("%s:lec_start_xmit: queuing packet, ",
382 dev->name);
383 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
384 lec_h->h_dest[0], lec_h->h_dest[1],
385 lec_h->h_dest[2], lec_h->h_dest[3],
386 lec_h->h_dest[4], lec_h->h_dest[5]);
387 skb_queue_tail(&entry->tx_wait, skb);
388 } else {
389 DPRINTK
390 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
391 dev->name);
392 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
393 lec_h->h_dest[0], lec_h->h_dest[1],
394 lec_h->h_dest[2], lec_h->h_dest[3],
395 lec_h->h_dest[4], lec_h->h_dest[5]);
396 priv->stats.tx_dropped++;
397 dev_kfree_skb(skb);
398 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700399 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700400 }
401#if DUMP_PACKETS > 0
402 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700404
405 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
406 DPRINTK("lec.c: emptying tx queue, ");
407 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
408 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
409 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 lec_send(vcc, skb, priv);
414
415 if (!atm_may_send(vcc, 0)) {
416 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
417
418 vpriv->xoff = 1;
419 netif_stop_queue(dev);
420
421 /*
422 * vcc->pop() might have occurred in between, making
423 * the vcc usuable again. Since xmit is serialized,
424 * this is the only situation we have to re-test.
425 */
426
427 if (atm_may_send(vcc, 0))
428 netif_wake_queue(dev);
429 }
430
Chas Williams6656e3c2006-09-29 17:17:17 -0700431out:
432 if (entry)
433 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
438/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700439static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Chas Williamsd44f7742006-09-29 17:11:14 -0700441 netif_stop_queue(dev);
442 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
445/*
446 * Get the current statistics.
447 * This may be called with the card open or closed.
448 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700449static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Chas Williamsd44f7742006-09-29 17:11:14 -0700451 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
Chas Williamsd44f7742006-09-29 17:11:14 -0700454static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700457 struct net_device *dev = (struct net_device *)vcc->proto_data;
458 struct lec_priv *priv = (struct lec_priv *)dev->priv;
459 struct atmlec_msg *mesg;
460 struct lec_arp_table *entry;
461 int i;
462 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700465 mesg = (struct atmlec_msg *)skb->data;
466 tmp = skb->data;
467 tmp += sizeof(struct atmlec_msg);
468 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
469 switch (mesg->type) {
470 case l_set_mac_addr:
471 for (i = 0; i < 6; i++) {
472 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
473 }
474 break;
475 case l_del_mac_addr:
476 for (i = 0; i < 6; i++) {
477 dev->dev_addr[i] = 0;
478 }
479 break;
480 case l_addr_delete:
481 lec_addr_delete(priv, mesg->content.normal.atm_addr,
482 mesg->content.normal.flag);
483 break;
484 case l_topology_change:
485 priv->topology_change = mesg->content.normal.flag;
486 break;
487 case l_flush_complete:
488 lec_flush_complete(priv, mesg->content.normal.flag);
489 break;
490 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700492 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
493 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
495
Chas Williamsd44f7742006-09-29 17:11:14 -0700496 if (mesg->content.normal.no_source_le_narp)
497 break;
498 /* FALL THROUGH */
499 case l_arp_update:
500 lec_arp_update(priv, mesg->content.normal.mac_addr,
501 mesg->content.normal.atm_addr,
502 mesg->content.normal.flag,
503 mesg->content.normal.targetless_le_arp);
504 DPRINTK("lec: in l_arp_update\n");
505 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
506 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
507 mesg->sizeoftlvs);
508 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
509 tmp, mesg->sizeoftlvs);
510 }
511 break;
512 case l_config:
513 priv->maximum_unknown_frame_count =
514 mesg->content.config.maximum_unknown_frame_count;
515 priv->max_unknown_frame_time =
516 (mesg->content.config.max_unknown_frame_time * HZ);
517 priv->max_retry_count = mesg->content.config.max_retry_count;
518 priv->aging_time = (mesg->content.config.aging_time * HZ);
519 priv->forward_delay_time =
520 (mesg->content.config.forward_delay_time * HZ);
521 priv->arp_response_time =
522 (mesg->content.config.arp_response_time * HZ);
523 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
524 priv->path_switching_delay =
525 (mesg->content.config.path_switching_delay * HZ);
526 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 priv->lane2_ops = NULL;
528 if (priv->lane_version > 1)
529 priv->lane2_ops = &lane2_ops;
530 if (dev->change_mtu(dev, mesg->content.config.mtu))
531 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700532 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700534 break;
535 case l_flush_tran_id:
536 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
537 mesg->content.normal.flag);
538 break;
539 case l_set_lecid:
540 priv->lecid =
541 (unsigned short)(0xffff & mesg->content.normal.flag);
542 break;
543 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700545 {
546 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Chas Williamsd44f7742006-09-29 17:11:14 -0700548 DPRINTK
549 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
550 dev->name, mesg->content.proxy.mac_addr[0],
551 mesg->content.proxy.mac_addr[1],
552 mesg->content.proxy.mac_addr[2],
553 mesg->content.proxy.mac_addr[3],
554 mesg->content.proxy.mac_addr[4],
555 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Chas Williamsd44f7742006-09-29 17:11:14 -0700557 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
558 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Chas Williamsd44f7742006-09-29 17:11:14 -0700560 f = br_fdb_get_hook(dev->br_port->br,
561 mesg->content.proxy.mac_addr);
562 if (f != NULL && f->dst->dev != dev
563 && f->dst->state == BR_STATE_FORWARDING) {
564 /* hit from bridge table, send LE_ARP_RESPONSE */
565 struct sk_buff *skb2;
566 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Chas Williamsd44f7742006-09-29 17:11:14 -0700568 DPRINTK
569 ("%s: entry found, responding to zeppelin\n",
570 dev->name);
571 skb2 =
572 alloc_skb(sizeof(struct atmlec_msg),
573 GFP_ATOMIC);
574 if (skb2 == NULL) {
575 br_fdb_put_hook(f);
576 break;
577 }
578 skb2->len = sizeof(struct atmlec_msg);
579 memcpy(skb2->data, mesg,
580 sizeof(struct atmlec_msg));
581 atm_force_charge(priv->lecd, skb2->truesize);
582 sk = sk_atm(priv->lecd);
583 skb_queue_tail(&sk->sk_receive_queue, skb2);
584 sk->sk_data_ready(sk, skb2->len);
585 }
586 if (f != NULL)
587 br_fdb_put_hook(f);
588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700590 break;
591 default:
592 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
593 dev_kfree_skb(skb);
594 return -EINVAL;
595 }
596 dev_kfree_skb(skb);
597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
Chas Williamsd44f7742006-09-29 17:11:14 -0700600static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Chas Williamsd44f7742006-09-29 17:11:14 -0700602 struct sk_buff *skb;
603 struct net_device *dev = (struct net_device *)vcc->proto_data;
604 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Chas Williamsd44f7742006-09-29 17:11:14 -0700606 priv->lecd = NULL;
607 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 netif_stop_queue(dev);
610 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Chas Williamsd44f7742006-09-29 17:11:14 -0700612 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700614 dev->name);
615 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
616 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700618 }
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700621 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
624static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700625 .close = lec_atm_close,
626 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627};
628
629static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700630 .ops = &lecdev_ops,
631 .type = "lec",
632 .number = 999, /* dummy device number */
633 .lock = SPIN_LOCK_UNLOCKED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634};
635
636/*
637 * LANE2: new argument struct sk_buff *data contains
638 * the LE_ARP based TLVs introduced in the LANE2 spec
639 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700640static int
641send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
642 unsigned char *mac_addr, unsigned char *atm_addr,
643 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
645 struct sock *sk;
646 struct sk_buff *skb;
647 struct atmlec_msg *mesg;
648
649 if (!priv || !priv->lecd) {
650 return -1;
651 }
652 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
653 if (!skb)
654 return -1;
655 skb->len = sizeof(struct atmlec_msg);
656 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700657 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700659 if (data != NULL)
660 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if (mac_addr)
662 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700663 else
664 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (atm_addr)
666 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
667
Chas Williamsd44f7742006-09-29 17:11:14 -0700668 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 sk = sk_atm(priv->lecd);
670 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700671 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 if (data != NULL) {
674 DPRINTK("lec: about to send %d bytes of data\n", data->len);
675 atm_force_charge(priv->lecd, data->truesize);
676 skb_queue_tail(&sk->sk_receive_queue, data);
677 sk->sk_data_ready(sk, skb->len);
678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Chas Williamsd44f7742006-09-29 17:11:14 -0700680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/* shamelessly stolen from drivers/net/net_init.c */
684static int lec_change_mtu(struct net_device *dev, int new_mtu)
685{
Chas Williamsd44f7742006-09-29 17:11:14 -0700686 if ((new_mtu < 68) || (new_mtu > 18190))
687 return -EINVAL;
688 dev->mtu = new_mtu;
689 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
692static void lec_set_multicast_list(struct net_device *dev)
693{
Chas Williamsd44f7742006-09-29 17:11:14 -0700694 /*
695 * by default, all multicast frames arrive over the bus.
696 * eventually support selective multicast service
697 */
698 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Chas Williamsd44f7742006-09-29 17:11:14 -0700701static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Chas Williamsd44f7742006-09-29 17:11:14 -0700703 dev->change_mtu = lec_change_mtu;
704 dev->open = lec_open;
705 dev->stop = lec_close;
706 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 dev->tx_timeout = lec_tx_timeout;
708
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 dev->get_stats = lec_get_stats;
710 dev->set_multicast_list = lec_set_multicast_list;
711 dev->do_ioctl = NULL;
712 printk("%s: Initialized!\n", dev->name);
713 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714}
715
716static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700717 0xff,
718 0x00,
719 0x01,
720 0x01
721};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Scott Talbert4a7097f2005-09-29 17:30:54 -0700723#define LEC_DATA_DIRECT_8023 2
724#define LEC_DATA_DIRECT_8025 3
725
726static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700727{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700728 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
729 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700730}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700731
Chas Williamsd44f7742006-09-29 17:11:14 -0700732static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700734 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 struct net_device *dev = (struct net_device *)vcc->proto_data;
736 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700739 int i = 0;
740 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Chas Williamsd44f7742006-09-29 17:11:14 -0700742 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
743 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 if (!skb) {
746 DPRINTK("%s: null skb\n", dev->name);
747 lec_vcc_close(priv, vcc);
748 return;
749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700751 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
752 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700754 for (i = 0; i < skb->len && i < 99; i++) {
755 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700758 for (i = 0; i < skb->len && i < 30; i++) {
759 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700762 if (i == skb->len)
763 printk("%s\n", buf);
764 else
765 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 struct sock *sk = sk_atm(vcc);
769
Chas Williamsd44f7742006-09-29 17:11:14 -0700770 DPRINTK("%s: To daemon\n", dev->name);
771 skb_queue_tail(&sk->sk_receive_queue, skb);
772 sk->sk_data_ready(sk, skb->len);
773 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700774 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700775 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Chas Williamsd44f7742006-09-29 17:11:14 -0700777 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800778 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700779 !priv->lecd || !(dev->flags & IFF_UP)) {
780 /*
781 * Probably looping back, or if lecd is missing,
782 * lecd has gone down
783 */
784 DPRINTK("Ignoring frame...\n");
785 dev_kfree_skb(skb);
786 return;
787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700789 if (priv->is_trdev)
790 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
791 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700793 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700794
Chas Williamsd44f7742006-09-29 17:11:14 -0700795 /*
796 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700797 * the LE_ARP cache entry, delete the LE_ARP cache entry.
798 */
799 spin_lock_irqsave(&priv->lec_arp_lock, flags);
800 if (lec_is_data_direct(vcc)) {
801#ifdef CONFIG_TR
802 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700803 src =
804 ((struct lecdatahdr_8025 *)skb->data)->
805 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700806 else
807#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700808 src =
809 ((struct lecdatahdr_8023 *)skb->data)->
810 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700811 entry = lec_arp_find(priv, src);
812 if (entry && entry->vcc != vcc) {
813 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700814 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700815 }
816 }
817 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Chas Williamsd44f7742006-09-29 17:11:14 -0700819 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
820 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700822 dev_kfree_skb(skb);
823 return;
824 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700825 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700826 lec_arp_check_empties(priv, vcc, skb);
827 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700828 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700830 if (priv->is_trdev)
831 skb->protocol = tr_type_trans(skb, dev);
832 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833#endif
Arnaldo Carvalho de Meloc8fb7942007-03-19 15:29:16 -0700834 {
835 skb->dev = dev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700836 skb->protocol = eth_type_trans(skb, dev);
Arnaldo Carvalho de Meloc8fb7942007-03-19 15:29:16 -0700837 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700838 priv->stats.rx_packets++;
839 priv->stats.rx_bytes += skb->len;
840 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
841 netif_rx(skb);
842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Chas Williamsd44f7742006-09-29 17:11:14 -0700845static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
847 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
848 struct net_device *dev = skb->dev;
849
850 if (vpriv == NULL) {
851 printk("lec_pop(): vpriv = NULL!?!?!?\n");
852 return;
853 }
854
855 vpriv->old_pop(vcc, skb);
856
857 if (vpriv->xoff && atm_may_send(vcc, 0)) {
858 vpriv->xoff = 0;
859 if (netif_running(dev) && netif_queue_stopped(dev))
860 netif_wake_queue(dev);
861 }
862}
863
Chas Williamsd44f7742006-09-29 17:11:14 -0700864static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
866 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700867 int bytes_left;
868 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Chas Williamsd44f7742006-09-29 17:11:14 -0700870 /* Lecd must be up in this case */
871 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
872 if (bytes_left != 0) {
873 printk
874 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
875 bytes_left);
876 }
877 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
878 !dev_lec[ioc_data.dev_num])
879 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
881 return -ENOMEM;
882 vpriv->xoff = 0;
883 vpriv->old_pop = vcc->pop;
884 vcc->user_back = vpriv;
885 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700886 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
887 &ioc_data, vcc, vcc->push);
888 vcc->proto_data = dev_lec[ioc_data.dev_num];
889 vcc->push = lec_push;
890 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Chas Williamsd44f7742006-09-29 17:11:14 -0700893static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Chas Williamsd44f7742006-09-29 17:11:14 -0700895 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
896 return -EINVAL;
897 vcc->proto_data = dev_lec[arg];
898 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700902static int lecd_attach(struct atm_vcc *vcc, int arg)
903{
904 int i;
905 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Chas Williamsd44f7742006-09-29 17:11:14 -0700907 if (arg < 0)
908 i = 0;
909 else
910 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700912 if (arg >= MAX_LEC_ITF)
913 return -EINVAL;
914#else /* Reserve the top NUM_TR_DEVS for TR */
915 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
916 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700918 if (!dev_lec[i]) {
919 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Chas Williamsd44f7742006-09-29 17:11:14 -0700921 is_trdev = 0;
922 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
923 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Chas Williamsd44f7742006-09-29 17:11:14 -0700925 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700927 if (is_trdev)
928 dev_lec[i] = alloc_trdev(size);
929 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700931 dev_lec[i] = alloc_etherdev(size);
932 if (!dev_lec[i])
933 return -ENOMEM;
934 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
935 if (register_netdev(dev_lec[i])) {
936 free_netdev(dev_lec[i]);
937 return -EINVAL;
938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Chas Williamsd44f7742006-09-29 17:11:14 -0700940 priv = dev_lec[i]->priv;
941 priv->is_trdev = is_trdev;
942 lec_init(dev_lec[i]);
943 } else {
944 priv = dev_lec[i]->priv;
945 if (priv->lecd)
946 return -EADDRINUSE;
947 }
948 lec_arp_init(priv);
949 priv->itfnum = i; /* LANE2 addition */
950 priv->lecd = vcc;
951 vcc->dev = &lecatm_dev;
952 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Chas Williamsd44f7742006-09-29 17:11:14 -0700954 vcc->proto_data = dev_lec[i];
955 set_bit(ATM_VF_META, &vcc->flags);
956 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Chas Williamsd44f7742006-09-29 17:11:14 -0700958 /* Set default values to these variables */
959 priv->maximum_unknown_frame_count = 1;
960 priv->max_unknown_frame_time = (1 * HZ);
961 priv->vcc_timeout_period = (1200 * HZ);
962 priv->max_retry_count = 1;
963 priv->aging_time = (300 * HZ);
964 priv->forward_delay_time = (15 * HZ);
965 priv->topology_change = 0;
966 priv->arp_response_time = (1 * HZ);
967 priv->flush_timeout = (4 * HZ);
968 priv->path_switching_delay = (6 * HZ);
969
970 if (dev_lec[i]->flags & IFF_UP) {
971 netif_start_queue(dev_lec[i]);
972 }
973 __module_get(THIS_MODULE);
974 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
977#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700978static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
980 static char *lec_arp_status_string[] = {
981 "ESI_UNKNOWN ",
982 "ESI_ARP_PENDING ",
983 "ESI_VC_PENDING ",
984 "<Undefined> ",
985 "ESI_FLUSH_PENDING ",
986 "ESI_FORWARD_DIRECT"
987 };
988
989 if (status > ESI_FORWARD_DIRECT)
990 status = 3; /* ESI_UNDEFINED */
991 return lec_arp_status_string[status];
992}
993
994static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
995{
996 int i;
997
998 for (i = 0; i < ETH_ALEN; i++)
999 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
1000 seq_printf(seq, " ");
1001 for (i = 0; i < ATM_ESA_LEN; i++)
1002 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
1003 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
1004 entry->flags & 0xffff);
1005 if (entry->vcc)
1006 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
1007 else
Chas Williamsd44f7742006-09-29 17:11:14 -07001008 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (entry->recv_vcc) {
1010 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1011 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -07001012 }
1013 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014}
1015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016struct lec_state {
1017 unsigned long flags;
1018 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001019 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 struct net_device *dev;
1021 int itf;
1022 int arp_table;
1023 int misc_table;
1024};
1025
Chas Williamsd0732f62006-09-29 17:14:27 -07001026static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 loff_t *l)
1028{
Chas Williamsd0732f62006-09-29 17:14:27 -07001029 struct hlist_node *e = state->node;
1030 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001033 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001035 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 --*l;
1037 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001038
1039 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (--*l < 0)
1041 break;
1042 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001043 state->node = e;
1044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 return (*l < 0) ? state : NULL;
1046}
1047
1048static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001049 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
1051 void *v = NULL;
1052 int p;
1053
1054 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001055 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 if (v)
1057 break;
1058 }
1059 state->arp_table = p;
1060 return v;
1061}
1062
1063static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1064 struct lec_priv *priv)
1065{
Chas Williamsd0732f62006-09-29 17:14:27 -07001066 struct hlist_head *lec_misc_tables[] = {
1067 &priv->lec_arp_empty_ones,
1068 &priv->lec_no_forward,
1069 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 };
1071 void *v = NULL;
1072 int q;
1073
1074 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1075 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1076 if (v)
1077 break;
1078 }
1079 state->misc_table = q;
1080 return v;
1081}
1082
1083static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1084 struct lec_priv *priv)
1085{
1086 if (!state->locked) {
1087 state->locked = priv;
1088 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1089 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001090 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1092 state->locked = NULL;
1093 /* Partial state reset for the next time we get called */
1094 state->arp_table = state->misc_table = 0;
1095 }
1096 return state->locked;
1097}
1098
1099static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1100{
1101 struct net_device *dev;
1102 void *v;
1103
1104 dev = state->dev ? state->dev : dev_lec[state->itf];
1105 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1106 if (!v && dev) {
1107 dev_put(dev);
1108 /* Partial state reset for the next time we get called */
1109 dev = NULL;
1110 }
1111 state->dev = dev;
1112 return v;
1113}
1114
1115static void *lec_get_idx(struct lec_state *state, loff_t l)
1116{
1117 void *v = NULL;
1118
1119 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1120 v = lec_itf_walk(state, &l);
1121 if (v)
1122 break;
1123 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001124 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
1127static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1128{
1129 struct lec_state *state = seq->private;
1130
1131 state->itf = 0;
1132 state->dev = NULL;
1133 state->locked = NULL;
1134 state->arp_table = 0;
1135 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001136 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Chas Williamsd44f7742006-09-29 17:11:14 -07001138 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
1141static void lec_seq_stop(struct seq_file *seq, void *v)
1142{
1143 struct lec_state *state = seq->private;
1144
1145 if (state->dev) {
1146 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1147 state->flags);
1148 dev_put(state->dev);
1149 }
1150}
1151
1152static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1153{
1154 struct lec_state *state = seq->private;
1155
1156 v = lec_get_idx(state, 1);
1157 *pos += !!PTR_ERR(v);
1158 return v;
1159}
1160
1161static int lec_seq_show(struct seq_file *seq, void *v)
1162{
Chas Williamsd44f7742006-09-29 17:11:14 -07001163 static char lec_banner[] = "Itf MAC ATM destination"
1164 " Status Flags "
1165 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 if (v == (void *)1)
1168 seq_puts(seq, lec_banner);
1169 else {
1170 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001171 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001172 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001175 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
1177 return 0;
1178}
1179
1180static struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001181 .start = lec_seq_start,
1182 .next = lec_seq_next,
1183 .stop = lec_seq_stop,
1184 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185};
1186
1187static int lec_seq_open(struct inode *inode, struct file *file)
1188{
1189 struct lec_state *state;
1190 struct seq_file *seq;
1191 int rc = -EAGAIN;
1192
1193 state = kmalloc(sizeof(*state), GFP_KERNEL);
1194 if (!state) {
1195 rc = -ENOMEM;
1196 goto out;
1197 }
1198
1199 rc = seq_open(file, &lec_seq_ops);
1200 if (rc)
1201 goto out_kfree;
1202 seq = file->private_data;
1203 seq->private = state;
1204out:
1205 return rc;
1206
1207out_kfree:
1208 kfree(state);
1209 goto out;
1210}
1211
1212static int lec_seq_release(struct inode *inode, struct file *file)
1213{
1214 return seq_release_private(inode, file);
1215}
1216
Arjan van de Ven9a321442007-02-12 00:55:35 -08001217static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001218 .owner = THIS_MODULE,
1219 .open = lec_seq_open,
1220 .read = seq_read,
1221 .llseek = seq_lseek,
1222 .release = lec_seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223};
1224#endif
1225
1226static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1227{
1228 struct atm_vcc *vcc = ATM_SD(sock);
1229 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001232 case ATMLEC_CTRL:
1233 case ATMLEC_MCAST:
1234 case ATMLEC_DATA:
1235 if (!capable(CAP_NET_ADMIN))
1236 return -EPERM;
1237 break;
1238 default:
1239 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 }
1241
1242 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001243 case ATMLEC_CTRL:
1244 err = lecd_attach(vcc, (int)arg);
1245 if (err >= 0)
1246 sock->state = SS_CONNECTED;
1247 break;
1248 case ATMLEC_MCAST:
1249 err = lec_mcast_attach(vcc, (int)arg);
1250 break;
1251 case ATMLEC_DATA:
1252 err = lec_vcc_attach(vcc, (void __user *)arg);
1253 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 }
1255
1256 return err;
1257}
1258
1259static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 .owner = THIS_MODULE,
1261 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262};
1263
1264static int __init lane_module_init(void)
1265{
1266#ifdef CONFIG_PROC_FS
1267 struct proc_dir_entry *p;
1268
1269 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1270 if (p)
1271 p->proc_fops = &lec_seq_fops;
1272#endif
1273
1274 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1276 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
1279static void __exit lane_module_cleanup(void)
1280{
Chas Williamsd44f7742006-09-29 17:11:14 -07001281 int i;
1282 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 remove_proc_entry("lec", atm_proc_root);
1285
1286 deregister_atm_ioctl(&lane_ioctl_ops);
1287
Chas Williamsd44f7742006-09-29 17:11:14 -07001288 for (i = 0; i < MAX_LEC_ITF; i++) {
1289 if (dev_lec[i] != NULL) {
1290 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001292 free_netdev(dev_lec[i]);
1293 dev_lec[i] = NULL;
1294 }
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Chas Williamsd44f7742006-09-29 17:11:14 -07001297 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
1300module_init(lane_module_init);
1301module_exit(lane_module_cleanup);
1302
1303/*
1304 * LANE2: 3.1.3, LE_RESOLVE.request
1305 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1306 * If sizeoftlvs == NULL the default TLVs associated with with this
1307 * lec will be used.
1308 * If dst_mac == NULL, targetless LE_ARP will be sent
1309 */
1310static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001311 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
1313 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001314 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1315 struct lec_arp_table *table;
1316 struct sk_buff *skb;
1317 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001321 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001323 if (table == NULL)
1324 return -1;
1325
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001326 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001327 if (*tlvs == NULL)
1328 return -1;
1329
Chas Williamsd44f7742006-09-29 17:11:14 -07001330 *sizeoftlvs = table->sizeoftlvs;
1331
1332 return 0;
1333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 if (sizeoftlvs == NULL)
1336 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 else {
1339 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1340 if (skb == NULL)
1341 return -1;
1342 skb->len = *sizeoftlvs;
1343 memcpy(skb->data, *tlvs, *sizeoftlvs);
1344 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1345 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001346 return retval;
1347}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349/*
1350 * LANE2: 3.1.4, LE_ASSOCIATE.request
1351 * Associate the *tlvs with the *lan_dst address.
1352 * Will overwrite any previous association
1353 * Returns 1 for success, 0 for failure (out of memory)
1354 *
1355 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001356static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1357 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 int retval;
1360 struct sk_buff *skb;
1361 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Chas Williamsd44f7742006-09-29 17:11:14 -07001363 if (compare_ether_addr(lan_dst, dev->dev_addr))
1364 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Chas Williamsd44f7742006-09-29 17:11:14 -07001366 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001368 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001369 if (priv->tlvs == NULL)
1370 return (0);
1371 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Chas Williamsd44f7742006-09-29 17:11:14 -07001373 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1374 if (skb == NULL)
1375 return 0;
1376 skb->len = sizeoftlvs;
1377 memcpy(skb->data, tlvs, sizeoftlvs);
1378 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1379 if (retval != 0)
1380 printk("lec.c: lane2_associate_req() failed\n");
1381 /*
1382 * If the previous association has changed we must
1383 * somehow notify other LANE entities about the change
1384 */
1385 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
1388/*
1389 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1390 *
1391 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001392static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1393 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
1395#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001396 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397#endif
1398 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001399#if 0 /*
1400 * Why have the TLVs in LE_ARP entries
1401 * since we do not use them? When you
1402 * uncomment this code, make sure the
1403 * TLVs get freed when entry is killed
1404 */
1405 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Chas Williamsd44f7742006-09-29 17:11:14 -07001407 if (entry == NULL)
1408 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Chas Williamsd44f7742006-09-29 17:11:14 -07001410 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001412 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001413 if (entry->tlvs == NULL)
1414 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001415 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416#endif
1417#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001418 printk("lec.c: lane2_associate_ind()\n");
1419 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1420 while (i < sizeoftlvs)
1421 printk("%02x ", tlvs[i++]);
1422
1423 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424#endif
1425
Chas Williamsd44f7742006-09-29 17:11:14 -07001426 /* tell MPOA about the TLVs we saw */
1427 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1428 priv->lane2_ops->associate_indicator(dev, mac_addr,
1429 tlvs, sizeoftlvs);
1430 }
1431 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
1434/*
1435 * Here starts what used to lec_arpc.c
1436 *
1437 * lec_arpc.c was added here when making
1438 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 */
1440
1441#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442#include <linux/timer.h>
1443#include <asm/param.h>
1444#include <asm/atomic.h>
1445#include <linux/inetdevice.h>
1446#include <net/route.h>
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448#if 0
1449#define DPRINTK(format,args...)
1450/*
1451#define DPRINTK printk
1452*/
1453#endif
1454#define DEBUG_ARP_TABLE 0
1455
1456#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1457
David Howellsc4028952006-11-22 14:57:56 +00001458static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459static void lec_arp_expire_arp(unsigned long data);
1460
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001461/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 * Arp table funcs
1463 */
1464
1465#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1466
1467/*
1468 * Initialization of arp-cache
1469 */
Chas Williams1fa99612006-09-29 17:11:47 -07001470static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
Chas Williams1fa99612006-09-29 17:11:47 -07001472 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Chas Williams1fa99612006-09-29 17:11:47 -07001474 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001475 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001476 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001477 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1478 INIT_HLIST_HEAD(&priv->lec_no_forward);
1479 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001481 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001482 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
Chas Williams1fa99612006-09-29 17:11:47 -07001485static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Chas Williams1fa99612006-09-29 17:11:47 -07001487 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 struct atm_vcc *vcc = entry->vcc;
1489 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001490 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Chas Williams1fa99612006-09-29 17:11:47 -07001492 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 if (vpriv->xoff)
1494 netif_wake_queue(dev);
1495 kfree(vpriv);
1496 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001497 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001499 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001500 }
1501 if (entry->recv_vcc) {
1502 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001504 entry->recv_vcc = NULL;
1505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
1508/*
1509 * Insert entry to lec_arp_table
1510 * LANE2: Add to the end of the list to satisfy 8.1.13
1511 */
Chas Williams1fa99612006-09-29 17:11:47 -07001512static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001513lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
Chas Williamsd0732f62006-09-29 17:14:27 -07001515 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Chas Williamsd0732f62006-09-29 17:14:27 -07001517 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1518 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001519
1520 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williamsd0732f62006-09-29 17:14:27 -07001521 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1522 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1523 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
1526/*
1527 * Remove entry from lec_arp_table
1528 */
Chas Williams1fa99612006-09-29 17:11:47 -07001529static int
1530lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Chas Williamsd0732f62006-09-29 17:14:27 -07001532 struct hlist_node *node;
1533 struct lec_arp_table *entry;
1534 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Chas Williams1fa99612006-09-29 17:11:47 -07001536 if (!to_remove) {
1537 return -1;
1538 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001539
1540 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001541 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Chas Williamsd0732f62006-09-29 17:14:27 -07001543 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001544 if (to_remove->status >= ESI_FLUSH_PENDING) {
1545 /*
1546 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1547 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001548 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1549 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1550 if (memcmp(to_remove->atm_addr,
1551 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001552 remove_vcc = 0;
1553 break;
1554 }
1555 }
1556 }
1557 if (remove_vcc)
1558 lec_arp_clear_vccs(to_remove);
1559 }
1560 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1561
1562 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1563 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1564 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1565 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
1569#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001570static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
Chas Williams1fa99612006-09-29 17:11:47 -07001572 switch (st) {
1573 case ESI_UNKNOWN:
1574 return "ESI_UNKNOWN";
1575 case ESI_ARP_PENDING:
1576 return "ESI_ARP_PENDING";
1577 case ESI_VC_PENDING:
1578 return "ESI_VC_PENDING";
1579 case ESI_FLUSH_PENDING:
1580 return "ESI_FLUSH_PENDING";
1581 case ESI_FORWARD_DIRECT:
1582 return "ESI_FORWARD_DIRECT";
1583 default:
1584 return "<UNKNOWN>";
1585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Chas Williams1fa99612006-09-29 17:11:47 -07001588static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
Chas Williamsd0732f62006-09-29 17:14:27 -07001590 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001591 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001592 char buf[256];
1593 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Chas Williams1fa99612006-09-29 17:11:47 -07001595 printk("Dump %p:\n", priv);
1596 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001597 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1598 offset = 0;
1599 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001600 offset += sprintf(buf + offset, "Mac:");
1601 for (j = 0; j < ETH_ALEN; j++) {
1602 offset += sprintf(buf + offset,
1603 "%2.2x ",
1604 rulla->mac_addr[j] & 0xff);
1605 }
1606 offset += sprintf(buf + offset, "Atm:");
1607 for (j = 0; j < ATM_ESA_LEN; j++) {
1608 offset += sprintf(buf + offset,
1609 "%2.2x ",
1610 rulla->atm_addr[j] & 0xff);
1611 }
1612 offset += sprintf(buf + offset,
1613 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1614 rulla->vcc ? rulla->vcc->vpi : 0,
1615 rulla->vcc ? rulla->vcc->vci : 0,
1616 rulla->recv_vcc ? rulla->recv_vcc->
1617 vpi : 0,
1618 rulla->recv_vcc ? rulla->recv_vcc->
1619 vci : 0, rulla->last_used,
1620 rulla->timestamp, rulla->no_tries);
1621 offset +=
1622 sprintf(buf + offset,
1623 "Flags:%x, Packets_flooded:%x, Status: %s ",
1624 rulla->flags, rulla->packets_flooded,
1625 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001626 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001627 }
Chas Williams1fa99612006-09-29 17:11:47 -07001628 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001629
1630 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001631 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001632 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001633 offset = 0;
1634 offset += sprintf(buf + offset, "Mac:");
1635 for (j = 0; j < ETH_ALEN; j++) {
1636 offset += sprintf(buf + offset, "%2.2x ",
1637 rulla->mac_addr[j] & 0xff);
1638 }
1639 offset += sprintf(buf + offset, "Atm:");
1640 for (j = 0; j < ATM_ESA_LEN; j++) {
1641 offset += sprintf(buf + offset, "%2.2x ",
1642 rulla->atm_addr[j] & 0xff);
1643 }
1644 offset += sprintf(buf + offset,
1645 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1646 rulla->vcc ? rulla->vcc->vpi : 0,
1647 rulla->vcc ? rulla->vcc->vci : 0,
1648 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1649 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1650 rulla->last_used,
1651 rulla->timestamp, rulla->no_tries);
1652 offset += sprintf(buf + offset,
1653 "Flags:%x, Packets_flooded:%x, Status: %s ",
1654 rulla->flags, rulla->packets_flooded,
1655 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001656 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001657 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001658
1659 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001660 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001661 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001662 offset = 0;
1663 offset += sprintf(buf + offset, "Mac:");
1664 for (j = 0; j < ETH_ALEN; j++) {
1665 offset += sprintf(buf + offset, "%2.2x ",
1666 rulla->mac_addr[j] & 0xff);
1667 }
1668 offset += sprintf(buf + offset, "Atm:");
1669 for (j = 0; j < ATM_ESA_LEN; j++) {
1670 offset += sprintf(buf + offset, "%2.2x ",
1671 rulla->atm_addr[j] & 0xff);
1672 }
1673 offset += sprintf(buf + offset,
1674 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1675 rulla->vcc ? rulla->vcc->vpi : 0,
1676 rulla->vcc ? rulla->vcc->vci : 0,
1677 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1678 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1679 rulla->last_used,
1680 rulla->timestamp, rulla->no_tries);
1681 offset += sprintf(buf + offset,
1682 "Flags:%x, Packets_flooded:%x, Status: %s ",
1683 rulla->flags, rulla->packets_flooded,
1684 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001685 printk("%s", buf);
1686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Chas Williamsd0732f62006-09-29 17:14:27 -07001688 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001689 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001690 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001691 offset = 0;
1692 offset += sprintf(buf + offset, "Mac:");
1693 for (j = 0; j < ETH_ALEN; j++) {
1694 offset += sprintf(buf + offset, "%2.2x ",
1695 rulla->mac_addr[j] & 0xff);
1696 }
1697 offset += sprintf(buf + offset, "Atm:");
1698 for (j = 0; j < ATM_ESA_LEN; j++) {
1699 offset += sprintf(buf + offset, "%2.2x ",
1700 rulla->atm_addr[j] & 0xff);
1701 }
1702 offset += sprintf(buf + offset,
1703 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1704 rulla->vcc ? rulla->vcc->vpi : 0,
1705 rulla->vcc ? rulla->vcc->vci : 0,
1706 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1707 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1708 rulla->last_used,
1709 rulla->timestamp, rulla->no_tries);
1710 offset += sprintf(buf + offset,
1711 "Flags:%x, Packets_flooded:%x, Status: %s ",
1712 rulla->flags, rulla->packets_flooded,
1713 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001714 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
Chas Williamsd0732f62006-09-29 17:14:27 -07001718#else
1719#define dump_arp_table(priv) do { } while (0)
1720#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722/*
1723 * Destruction of arp-cache
1724 */
Chas Williams1fa99612006-09-29 17:11:47 -07001725static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
1727 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001728 struct hlist_node *node, *next;
1729 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001730 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Chas Williams987e46b2006-09-29 17:15:59 -07001732 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001733
1734 /*
1735 * Remove all entries
1736 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001739 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001741 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001742 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001743 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001744 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001745 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001746
1747 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001748 del_timer_sync(&entry->timer);
1749 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001750 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001751 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001752 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001753 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1754
1755 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001756 del_timer_sync(&entry->timer);
1757 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001758 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001759 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001760 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001761 INIT_HLIST_HEAD(&priv->lec_no_forward);
1762
1763 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001764 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1765 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001766 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001767 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001768 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001769 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001770 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1772}
1773
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001774/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * Find entry by mac_address
1776 */
Chas Williams1fa99612006-09-29 17:11:47 -07001777static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1778 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Chas Williamsd0732f62006-09-29 17:14:27 -07001780 struct hlist_node *node;
1781 struct hlist_head *head;
1782 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Chas Williams1fa99612006-09-29 17:11:47 -07001784 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1785 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1786 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001787
Chas Williamsd0732f62006-09-29 17:14:27 -07001788 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1789 hlist_for_each_entry(entry, node, head, next) {
1790 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1791 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001792 }
Chas Williams1fa99612006-09-29 17:11:47 -07001793 }
1794 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
Chas Williams1fa99612006-09-29 17:11:47 -07001797static struct lec_arp_table *make_entry(struct lec_priv *priv,
1798 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
Chas Williams1fa99612006-09-29 17:11:47 -07001800 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Chas Williams1fa99612006-09-29 17:11:47 -07001802 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1803 if (!to_return) {
1804 printk("LEC: Arp entry kmalloc failed\n");
1805 return NULL;
1806 }
1807 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001808 INIT_HLIST_NODE(&to_return->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001809 init_timer(&to_return->timer);
1810 to_return->timer.function = lec_arp_expire_arp;
1811 to_return->timer.data = (unsigned long)to_return;
1812 to_return->last_used = jiffies;
1813 to_return->priv = priv;
1814 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001815 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001816 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817}
1818
Chas Williams1fa99612006-09-29 17:11:47 -07001819/* Arp sent timer expired */
1820static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
Chas Williams1fa99612006-09-29 17:11:47 -07001822 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
Chas Williams1fa99612006-09-29 17:11:47 -07001824 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Chas Williams1fa99612006-09-29 17:11:47 -07001826 DPRINTK("lec_arp_expire_arp\n");
1827 if (entry->status == ESI_ARP_PENDING) {
1828 if (entry->no_tries <= entry->priv->max_retry_count) {
1829 if (entry->is_rdesc)
1830 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1831 entry->mac_addr, NULL, NULL);
1832 else
1833 send_to_lecd(entry->priv, l_arp_xmt,
1834 entry->mac_addr, NULL, NULL);
1835 entry->no_tries++;
1836 }
1837 mod_timer(&entry->timer, jiffies + (1 * HZ));
1838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
Chas Williams1fa99612006-09-29 17:11:47 -07001841/* Unknown/unused vcc expire, remove associated entry */
1842static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
1844 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001845 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1846 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Chas Williams1fa99612006-09-29 17:11:47 -07001848 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Chas Williams1fa99612006-09-29 17:11:47 -07001850 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1851 to_remove, priv,
1852 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1853 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001856 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1858
Chas Williams1fa99612006-09-29 17:11:47 -07001859 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001860 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861}
1862
1863/*
1864 * Expire entries.
1865 * 1. Re-set timer
1866 * 2. For each entry, delete entries that have aged past the age limit.
1867 * 3. For each entry, depending on the status of the entry, perform
1868 * the following maintenance.
1869 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1870 * tick_count is above the max_unknown_frame_time, clear
1871 * the tick_count to zero and clear the packets_flooded counter
1872 * to zero. This supports the packet rate limit per address
1873 * while flooding unknowns.
1874 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1875 * than or equal to the path_switching_delay, change the status
1876 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1877 * regardless of the progress of the flush protocol.
1878 */
David Howellsc4028952006-11-22 14:57:56 +00001879static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
1881 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001882 struct lec_priv *priv =
1883 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001884 struct hlist_node *node, *next;
1885 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001886 unsigned long now;
1887 unsigned long time_to_check;
1888 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Chas Williams1fa99612006-09-29 17:11:47 -07001890 DPRINTK("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001892restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001894 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001895 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001896 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 priv->topology_change)
1898 time_to_check = priv->forward_delay_time;
1899 else
1900 time_to_check = priv->aging_time;
1901
1902 DPRINTK("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001903 now, entry->last_used, time_to_check);
1904 if (time_after(now, entry->last_used + time_to_check)
1905 && !(entry->flags & LEC_PERMANENT_FLAG)
1906 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 /* Remove entry */
1908 DPRINTK("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001910 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 } else {
1912 /* Something else */
1913 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001914 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001916 entry->timestamp +
1917 priv->
1918 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 entry->timestamp = jiffies;
1920 entry->packets_flooded = 0;
1921 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001922 send_to_lecd(priv, l_svc_setup,
1923 entry->mac_addr,
1924 entry->atm_addr,
1925 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
Chas Williams1fa99612006-09-29 17:11:47 -07001927 if (entry->status == ESI_FLUSH_PENDING
1928 &&
1929 time_after_eq(now, entry->timestamp +
1930 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001932 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
Chas Williams6656e3c2006-09-29 17:17:17 -07001934 lec_arp_hold(entry);
1935 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1936 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1937 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001939 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001940 lec_arp_put(entry);
1941 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 }
1944 }
1945 }
1946 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1947
Chas Williams987e46b2006-09-29 17:15:59 -07001948 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949}
Chas Williams1fa99612006-09-29 17:11:47 -07001950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951/*
1952 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001953 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 */
Chas Williams1fa99612006-09-29 17:11:47 -07001955static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1956 unsigned char *mac_to_find, int is_rdesc,
1957 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
1959 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001960 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 struct atm_vcc *found;
1962
Chas Williams1fa99612006-09-29 17:11:47 -07001963 if (mac_to_find[0] & 0x01) {
1964 switch (priv->lane_version) {
1965 case 1:
1966 return priv->mcast_vcc;
1967 break;
1968 case 2: /* LANE2 wants arp for multicast addresses */
1969 if (!compare_ether_addr(mac_to_find, bus_mac))
1970 return priv->mcast_vcc;
1971 break;
1972 default:
1973 break;
1974 }
1975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001978 entry = lec_arp_find(priv, mac_to_find);
1979
1980 if (entry) {
1981 if (entry->status == ESI_FORWARD_DIRECT) {
1982 /* Connection Ok */
1983 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001984 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001985 *ret_entry = entry;
1986 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001988 }
1989 /*
1990 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001991 * so another LE_ARP request can be made for this frame.
1992 */
1993 if (entry->status == ESI_ARP_PENDING) {
1994 entry->no_tries = 0;
1995 }
Chas Williams1fa99612006-09-29 17:11:47 -07001996 /*
1997 * Data direct VC not yet set up, check to see if the unknown
1998 * frame count is greater than the limit. If the limit has
1999 * not been reached, allow the caller to send packet to
2000 * BUS.
2001 */
2002 if (entry->status != ESI_FLUSH_PENDING &&
2003 entry->packets_flooded <
2004 priv->maximum_unknown_frame_count) {
2005 entry->packets_flooded++;
2006 DPRINTK("LEC_ARP: Flooding..\n");
2007 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002009 }
2010 /*
2011 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 * or BUS flood limit was reached for an entry which is
2013 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2014 */
Chas Williams6656e3c2006-09-29 17:17:17 -07002015 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002016 *ret_entry = entry;
2017 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
2018 entry->vcc);
2019 found = NULL;
2020 } else {
2021 /* No matching entry was found */
2022 entry = make_entry(priv, mac_to_find);
2023 DPRINTK("LEC_ARP: Making entry\n");
2024 if (!entry) {
2025 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002027 }
2028 lec_arp_add(priv, entry);
2029 /* We want arp-request(s) to be sent */
2030 entry->packets_flooded = 1;
2031 entry->status = ESI_ARP_PENDING;
2032 entry->no_tries = 1;
2033 entry->last_used = entry->timestamp = jiffies;
2034 entry->is_rdesc = is_rdesc;
2035 if (entry->is_rdesc)
2036 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2037 NULL);
2038 else
2039 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2040 entry->timer.expires = jiffies + (1 * HZ);
2041 entry->timer.function = lec_arp_expire_arp;
2042 add_timer(&entry->timer);
2043 found = priv->mcast_vcc;
2044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046out:
2047 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2048 return found;
2049}
2050
2051static int
Chas Williams1fa99612006-09-29 17:11:47 -07002052lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2053 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054{
2055 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002056 struct hlist_node *node, *next;
2057 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002058 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Chas Williams1fa99612006-09-29 17:11:47 -07002060 DPRINTK("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002062 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002063 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002064 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2065 && (permanent ||
2066 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002068 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002071 return 0;
2072 }
2073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002075 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076}
2077
2078/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002079 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 */
2081static void
2082lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002083 unsigned char *atm_addr, unsigned long remoteflag,
2084 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002087 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002088 struct lec_arp_table *entry, *tmp;
2089 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Chas Williams1fa99612006-09-29 17:11:47 -07002091 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2092 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2093 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2094 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
2096 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002097 entry = lec_arp_find(priv, mac_addr);
2098 if (entry == NULL && targetless_le_arp)
2099 goto out; /*
2100 * LANE2: ignore targetless LE_ARPs for which
2101 * we have no entry in the cache. 7.1.30
2102 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002103 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2104 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2105 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2106 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002107 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002108 tmp = lec_arp_find(priv, mac_addr);
2109 if (tmp) {
2110 del_timer(&tmp->timer);
2111 tmp->status = ESI_FORWARD_DIRECT;
2112 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2113 tmp->vcc = entry->vcc;
2114 tmp->old_push = entry->old_push;
2115 tmp->last_used = jiffies;
2116 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002117 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002118 entry = tmp;
2119 } else {
2120 entry->status = ESI_FORWARD_DIRECT;
2121 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2122 entry->last_used = jiffies;
2123 lec_arp_add(priv, entry);
2124 }
2125 if (remoteflag)
2126 entry->flags |= LEC_REMOTE_FLAG;
2127 else
2128 entry->flags &= ~LEC_REMOTE_FLAG;
2129 DPRINTK("After update\n");
2130 dump_arp_table(priv);
2131 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002132 }
Chas Williams1fa99612006-09-29 17:11:47 -07002133 }
2134 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002135
Chas Williams1fa99612006-09-29 17:11:47 -07002136 entry = lec_arp_find(priv, mac_addr);
2137 if (!entry) {
2138 entry = make_entry(priv, mac_addr);
2139 if (!entry)
2140 goto out;
2141 entry->status = ESI_UNKNOWN;
2142 lec_arp_add(priv, entry);
2143 /* Temporary, changes before end of function */
2144 }
2145 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2146 del_timer(&entry->timer);
2147 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002148 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002149 if (entry != tmp &&
2150 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2151 /* Vcc to this host exists */
2152 if (tmp->status > ESI_VC_PENDING) {
2153 /*
2154 * ESI_FLUSH_PENDING,
2155 * ESI_FORWARD_DIRECT
2156 */
2157 entry->vcc = tmp->vcc;
2158 entry->old_push = tmp->old_push;
2159 }
2160 entry->status = tmp->status;
2161 break;
2162 }
2163 }
2164 }
2165 if (remoteflag)
2166 entry->flags |= LEC_REMOTE_FLAG;
2167 else
2168 entry->flags &= ~LEC_REMOTE_FLAG;
2169 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2170 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002171 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002172 }
2173 DPRINTK("After update2\n");
2174 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175out:
2176 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2177}
2178
2179/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002180 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 */
2182static void
2183lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002184 struct atm_vcc *vcc,
2185 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186{
2187 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002188 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002189 struct lec_arp_table *entry;
2190 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
2192 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002193 if (ioc_data->receive == 2) {
2194 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chas Williams1fa99612006-09-29 17:11:47 -07002196 DPRINTK("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002198 entry = lec_arp_find(priv, bus_mac);
2199 if (!entry) {
2200 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002202 }
2203 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2204 entry->recv_vcc = vcc;
2205 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002207 entry = make_entry(priv, bus_mac);
2208 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002210 del_timer(&entry->timer);
2211 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2212 entry->recv_vcc = vcc;
2213 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002214 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002215 goto out;
2216 } else if (ioc_data->receive == 1) {
2217 /*
2218 * Vcc which we don't want to make default vcc,
2219 * attach it anyway.
2220 */
2221 DPRINTK
2222 ("LEC_ARP:Attaching data direct, not default: "
2223 "%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",
2224 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2225 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2226 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2227 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2228 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2229 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2230 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2231 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2232 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2233 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2234 entry = make_entry(priv, bus_mac);
2235 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002237 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2238 memset(entry->mac_addr, 0, ETH_ALEN);
2239 entry->recv_vcc = vcc;
2240 entry->old_recv_push = old_push;
2241 entry->status = ESI_UNKNOWN;
2242 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2243 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002244 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002245 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 dump_arp_table(priv);
2247 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002248 }
2249 DPRINTK
2250 ("LEC_ARP:Attaching data direct, default: "
2251 "%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",
2252 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2253 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2254 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2255 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2256 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2257 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2258 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2259 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2260 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2261 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2262 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002263 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002264 if (memcmp
2265 (ioc_data->atm_addr, entry->atm_addr,
2266 ATM_ESA_LEN) == 0) {
2267 DPRINTK("LEC_ARP: Attaching data direct\n");
2268 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2269 entry->vcc ? entry->vcc->vci : 0,
2270 entry->recv_vcc ? entry->recv_vcc->
2271 vci : 0);
2272 found_entry = 1;
2273 del_timer(&entry->timer);
2274 entry->vcc = vcc;
2275 entry->old_push = old_push;
2276 if (entry->status == ESI_VC_PENDING) {
2277 if (priv->maximum_unknown_frame_count
2278 == 0)
2279 entry->status =
2280 ESI_FORWARD_DIRECT;
2281 else {
2282 entry->timestamp = jiffies;
2283 entry->status =
2284 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002286 send_to_lecd(priv, l_flush_xmt,
2287 NULL,
2288 entry->atm_addr,
2289 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002291 }
2292 } else {
2293 /*
2294 * They were forming a connection
2295 * to us, and we to them. Our
2296 * ATM address is numerically lower
2297 * than theirs, so we make connection
2298 * we formed into default VCC (8.1.11).
2299 * Connection they made gets torn
2300 * down. This might confuse some
2301 * clients. Can be changed if
2302 * someone reports trouble...
2303 */
2304 ;
2305 }
2306 }
2307 }
2308 }
2309 if (found_entry) {
2310 DPRINTK("After vcc was added\n");
2311 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002313 }
2314 /*
2315 * Not found, snatch address from first data packet that arrives
2316 * from this vcc
2317 */
2318 entry = make_entry(priv, bus_mac);
2319 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002321 entry->vcc = vcc;
2322 entry->old_push = old_push;
2323 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2324 memset(entry->mac_addr, 0, ETH_ALEN);
2325 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002326 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002327 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2328 entry->timer.function = lec_arp_expire_vcc;
2329 add_timer(&entry->timer);
2330 DPRINTK("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 dump_arp_table(priv);
2332out:
2333 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2334}
2335
Chas Williams1fa99612006-09-29 17:11:47 -07002336static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
2338 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002339 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002340 struct lec_arp_table *entry;
2341 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chas Williams1fa99612006-09-29 17:11:47 -07002343 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002344restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002345 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2346 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002347 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002348 if (entry->flush_tran_id == tran_id
2349 && entry->status == ESI_FLUSH_PENDING) {
2350 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002351 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002352
Chas Williams6656e3c2006-09-29 17:17:17 -07002353 lec_arp_hold(entry);
2354 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2355 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2356 lec_send(vcc, skb, entry->priv);
2357 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002358 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002359 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002360 DPRINTK("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002361 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002362 }
2363 }
2364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002366 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369static void
2370lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002371 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002374 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002375 struct lec_arp_table *entry;
2376 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
2378 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002379 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002380 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002381 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2382 entry->flush_tran_id = tran_id;
Chas Williamsd0732f62006-09-29 17:14:27 -07002383 DPRINTK("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002384 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002385 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2388}
2389
Chas Williams1fa99612006-09-29 17:11:47 -07002390static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
2392 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002393 unsigned char mac_addr[] = {
2394 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2395 };
2396 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct lec_vcc_priv *vpriv;
2398 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2401 return -ENOMEM;
2402 vpriv->xoff = 0;
2403 vpriv->old_pop = vcc->pop;
2404 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002405 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002407 to_add = make_entry(priv, mac_addr);
2408 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 vcc->pop = vpriv->old_pop;
2410 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002411 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002413 }
2414 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2415 to_add->status = ESI_FORWARD_DIRECT;
2416 to_add->flags |= LEC_PERMANENT_FLAG;
2417 to_add->vcc = vcc;
2418 to_add->old_push = vcc->push;
2419 vcc->push = lec_push;
2420 priv->mcast_vcc = vcc;
2421 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422out:
2423 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002424 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425}
2426
Chas Williams1fa99612006-09-29 17:11:47 -07002427static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428{
2429 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002430 struct hlist_node *node, *next;
2431 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002432 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Chas Williams1fa99612006-09-29 17:11:47 -07002434 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2435 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002436
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002438
Chas Williams1fa99612006-09-29 17:11:47 -07002439 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002440 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002441 if (vcc == entry->vcc) {
2442 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002443 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002444 if (priv->mcast_vcc == vcc) {
2445 priv->mcast_vcc = NULL;
2446 }
2447 }
2448 }
2449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chas Williamsd0732f62006-09-29 17:14:27 -07002451 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2452 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002453 lec_arp_clear_vccs(entry);
2454 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002455 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002456 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002457 }
Chas Williams1fa99612006-09-29 17:11:47 -07002458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Chas Williamsd0732f62006-09-29 17:14:27 -07002460 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002461 if (entry->recv_vcc == vcc) {
2462 lec_arp_clear_vccs(entry);
2463 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002464 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002465 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002466 }
Chas Williams1fa99612006-09-29 17:11:47 -07002467 }
2468
Chas Williamsd0732f62006-09-29 17:14:27 -07002469 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002470 if (entry->recv_vcc == vcc) {
2471 lec_arp_clear_vccs(entry);
2472 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002473 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002474 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002475 }
Chas Williams1fa99612006-09-29 17:11:47 -07002476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
2478 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2479 dump_arp_table(priv);
2480}
2481
2482static void
2483lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002484 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Chas Williams1fa99612006-09-29 17:11:47 -07002486 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002487 struct hlist_node *node, *next;
2488 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002489 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2490 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002492 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Chas Williams1fa99612006-09-29 17:11:47 -07002494 if (priv->is_trdev)
2495 src = tr_hdr->h_source;
2496 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002498 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
2500 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002501 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2502 if (vcc == entry->vcc) {
2503 del_timer(&entry->timer);
2504 memcpy(entry->mac_addr, src, ETH_ALEN);
2505 entry->status = ESI_FORWARD_DIRECT;
2506 entry->last_used = jiffies;
2507 /* We might have got an entry */
2508 if ((tmp = lec_arp_find(priv, src))) {
2509 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002510 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002511 }
2512 hlist_del(&entry->next);
2513 lec_arp_add(priv, entry);
2514 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002515 }
Chas Williams1fa99612006-09-29 17:11:47 -07002516 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002517 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518out:
2519 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2520}
Chas Williams1fa99612006-09-29 17:11:47 -07002521
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522MODULE_LICENSE("GPL");