blob: 59d5aa3366f229636ec7ca7a1ab8d821e8d97b41 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37#include <linux/if_bridge.h>
38#include "../bridge/br_private.h"
39
Chas Williamsd44f7742006-09-29 17:11:14 -070040static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42
43/* Modular too */
44#include <linux/module.h>
45#include <linux/init.h>
46
47#include "lec.h"
48#include "lec_arpc.h"
49#include "resources.h"
50
51#if 0
52#define DPRINTK printk
53#else
54#define DPRINTK(format,args...)
55#endif
56
Chas Williamsd44f7742006-09-29 17:11:14 -070057#define DUMP_PACKETS 0 /*
58 * 0 = None,
59 * 1 = 30 first bytes
60 * 2 = Whole packet
61 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Chas Williamsd44f7742006-09-29 17:11:14 -070063#define LEC_UNRES_QUE_LEN 8 /*
64 * number of tx packets to queue for a
65 * single destination while waiting for SVC
66 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68static int lec_open(struct net_device *dev);
69static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
70static int lec_close(struct net_device *dev);
71static struct net_device_stats *lec_get_stats(struct net_device *dev);
72static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070073static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
74 unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070076 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* LANE2 functions */
Chas Williamsd44f7742006-09-29 17:11:14 -070078static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
79 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070081 u8 **tlvs, u32 *sizeoftlvs);
82static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
83 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Chas Williamsd44f7742006-09-29 17:11:14 -070085static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned long permanent);
87static void lec_arp_check_empties(struct lec_priv *priv,
88 struct atm_vcc *vcc, struct sk_buff *skb);
89static void lec_arp_destroy(struct lec_priv *priv);
90static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070091static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 unsigned char *mac_to_find,
93 int is_rdesc,
94 struct lec_arp_table **ret_entry);
95static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
96 unsigned char *atm_addr, unsigned long remoteflag,
97 unsigned int targetless_le_arp);
98static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
99static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
100static void lec_set_flush_tran_id(struct lec_priv *priv,
101 unsigned char *atm_addr,
102 unsigned long tran_id);
103static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
104 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -0700105 void (*old_push) (struct atm_vcc *vcc,
106 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
108
Chas Williams33a9c2d2006-09-29 17:16:48 -0700109/* must be done under lec_arp_lock */
110static inline void lec_arp_hold(struct lec_arp_table *entry)
111{
112 atomic_inc(&entry->usage);
113}
114
115static inline void lec_arp_put(struct lec_arp_table *entry)
116{
117 if (atomic_dec_and_test(&entry->usage))
118 kfree(entry);
119}
120
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700123 lane2_resolve, /* resolve, spec 3.1.3 */
124 lane2_associate_req, /* associate_req, spec 3.1.4 */
125 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
Chas Williamsd44f7742006-09-29 17:11:14 -0700128static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/* Device structures */
131static struct net_device *dev_lec[MAX_LEC_ITF];
132
133#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
134static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
135{
Chas Williamsd44f7742006-09-29 17:11:14 -0700136 struct ethhdr *eth;
137 char *buff;
138 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Chas Williamsd44f7742006-09-29 17:11:14 -0700140 /*
141 * Check if this is a BPDU. If so, ask zeppelin to send
142 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
143 * as the Config BPDU has
144 */
145 eth = (struct ethhdr *)skb->data;
146 buff = skb->data + skb->dev->hard_header_len;
147 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700149 struct sk_buff *skb2;
150 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Chas Williamsd44f7742006-09-29 17:11:14 -0700152 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
153 if (skb2 == NULL)
154 return;
155 skb2->len = sizeof(struct atmlec_msg);
156 mesg = (struct atmlec_msg *)skb2->data;
157 mesg->type = l_topology_change;
158 buff += 4;
159 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Chas Williamsd44f7742006-09-29 17:11:14 -0700161 priv = (struct lec_priv *)dev->priv;
162 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700164 skb_queue_tail(&sk->sk_receive_queue, skb2);
165 sk->sk_data_ready(sk, skb2->len);
166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Chas Williamsd44f7742006-09-29 17:11:14 -0700168 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
171
172/*
173 * Modelled after tr_type_trans
174 * All multicast and ARE or STE frames go to BUS.
175 * Non source routed frames go by destination address.
176 * Last hop source routed frames go by destination address.
177 * Not last hop source routed frames go by _next_ route descriptor.
178 * Returns pointer to destination MAC address or fills in rdesc
179 * and returns NULL.
180 */
181#ifdef CONFIG_TR
182static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
183{
Chas Williamsd44f7742006-09-29 17:11:14 -0700184 struct trh_hdr *trh;
185 int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Chas Williamsd44f7742006-09-29 17:11:14 -0700187 trh = (struct trh_hdr *)packet;
188 if (trh->daddr[0] & (uint8_t) 0x80)
189 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Chas Williamsd44f7742006-09-29 17:11:14 -0700191 if (trh->saddr[0] & TR_RII) {
192 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
193 if ((ntohs(trh->rcf) >> 13) != 0)
194 return bus_mac; /* ARE or STE */
195 } else
196 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Chas Williamsd44f7742006-09-29 17:11:14 -0700198 if (riflen < 6)
199 return trh->daddr; /* last hop, source routed */
200
201 /* riflen is 6 or more, packet has more than one route descriptor */
202 num_rdsc = (riflen / 2) - 1;
203 memset(rdesc, 0, ETH_ALEN);
204 /* offset 4 comes from LAN destination field in LE control frames */
205 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800206 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700207 else {
Al Viro30d492d2006-11-14 21:11:29 -0800208 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700209 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
210 }
211
212 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214#endif /* CONFIG_TR */
215
216/*
217 * Open/initialize the netdevice. This is called (in the current kernel)
218 * sometime after booting when the 'ifconfig' program is run.
219 *
220 * This routine should set everything up anew at each open, even
221 * registers that "should" only need to be set once at boot, so that
222 * there is non-reboot way to recover if something goes wrong.
223 */
224
Chas Williamsd44f7742006-09-29 17:11:14 -0700225static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Chas Williamsd44f7742006-09-29 17:11:14 -0700227 struct lec_priv *priv = (struct lec_priv *)dev->priv;
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700230 memset(&priv->stats, 0, sizeof(struct net_device_stats));
231
232 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235static __inline__ void
236lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
237{
238 ATM_SKB(skb)->vcc = vcc;
239 ATM_SKB(skb)->atm_options = vcc->atm_options;
240
241 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
242 if (vcc->send(vcc, skb) < 0) {
243 priv->stats.tx_dropped++;
244 return;
245 }
246
247 priv->stats.tx_packets++;
248 priv->stats.tx_bytes += skb->len;
249}
250
Chas Williamsd44f7742006-09-29 17:11:14 -0700251static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 printk(KERN_INFO "%s: tx timeout\n", dev->name);
254 dev->trans_start = jiffies;
255 netif_wake_queue(dev);
256}
257
Chas Williamsd44f7742006-09-29 17:11:14 -0700258static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 struct sk_buff *skb2;
261 struct lec_priv *priv = (struct lec_priv *)dev->priv;
262 struct lecdatahdr_8023 *lec_h;
263 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 int min_frame_size;
267#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700268 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700270 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700272 char buf[300];
273 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Chas Williamsd44f7742006-09-29 17:11:14 -0700276 DPRINTK("lec_start_xmit called\n");
277 if (!priv->lecd) {
278 printk("%s:No lecd attached\n", dev->name);
279 priv->stats.tx_errors++;
280 netif_stop_queue(dev);
281 return -EUNATCH;
282 }
283
284 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700285 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700286 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700288 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
289 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#endif
291
Chas Williamsd44f7742006-09-29 17:11:14 -0700292 /* Make sure we have room for lec_id */
293 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Chas Williamsd44f7742006-09-29 17:11:14 -0700295 DPRINTK("lec_start_xmit: reallocating skb\n");
296 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
297 kfree_skb(skb);
298 if (skb2 == NULL)
299 return 0;
300 skb = skb2;
301 }
302 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Chas Williamsd44f7742006-09-29 17:11:14 -0700304 /* Put le header to place, works for TokenRing too */
305 lec_h = (struct lecdatahdr_8023 *)skb->data;
306 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700309 /*
310 * Ugly. Use this to realign Token Ring packets for
311 * e.g. PCA-200E driver.
312 */
313 if (priv->is_trdev) {
314 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
315 kfree_skb(skb);
316 if (skb2 == NULL)
317 return 0;
318 skb = skb2;
319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#endif
321
322#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700323 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
324 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700326 for (i = 0; i < skb->len && i < 99; i++) {
327 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700330 for (i = 0; i < skb->len && i < 30; i++) {
331 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 if (i == skb->len)
335 printk("%s\n", buf);
336 else
337 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#endif /* DUMP_PACKETS > 0 */
339
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700342 if (priv->is_trdev)
343 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 else
345#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700346 min_frame_size = LEC_MINIMUM_8023_SIZE;
347 if (skb->len < min_frame_size) {
348 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
349 skb2 = skb_copy_expand(skb, 0,
350 min_frame_size - skb->truesize,
351 GFP_ATOMIC);
352 dev_kfree_skb(skb);
353 if (skb2 == NULL) {
354 priv->stats.tx_dropped++;
355 return 0;
356 }
357 skb = skb2;
358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 }
361
362 /* Send to right vcc */
363 is_rdesc = 0;
364 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700366 if (priv->is_trdev) {
367 dst = get_tr_dst(skb->data + 2, rdesc);
368 if (dst == NULL) {
369 dst = rdesc;
370 is_rdesc = 1;
371 }
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700374 entry = NULL;
375 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
376 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
377 vcc, vcc ? vcc->flags : 0, entry);
378 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
379 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
380 DPRINTK("%s:lec_start_xmit: queuing packet, ",
381 dev->name);
382 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
383 lec_h->h_dest[0], lec_h->h_dest[1],
384 lec_h->h_dest[2], lec_h->h_dest[3],
385 lec_h->h_dest[4], lec_h->h_dest[5]);
386 skb_queue_tail(&entry->tx_wait, skb);
387 } else {
388 DPRINTK
389 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
390 dev->name);
391 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
392 lec_h->h_dest[0], lec_h->h_dest[1],
393 lec_h->h_dest[2], lec_h->h_dest[3],
394 lec_h->h_dest[4], lec_h->h_dest[5]);
395 priv->stats.tx_dropped++;
396 dev_kfree_skb(skb);
397 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700398 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700399 }
400#if DUMP_PACKETS > 0
401 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700403
404 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
405 DPRINTK("lec.c: emptying tx queue, ");
406 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
407 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
408 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 lec_send(vcc, skb, priv);
413
414 if (!atm_may_send(vcc, 0)) {
415 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
416
417 vpriv->xoff = 1;
418 netif_stop_queue(dev);
419
420 /*
421 * vcc->pop() might have occurred in between, making
422 * the vcc usuable again. Since xmit is serialized,
423 * this is the only situation we have to re-test.
424 */
425
426 if (atm_may_send(vcc, 0))
427 netif_wake_queue(dev);
428 }
429
Chas Williams6656e3c2006-09-29 17:17:17 -0700430out:
431 if (entry)
432 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700434 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700438static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Chas Williamsd44f7742006-09-29 17:11:14 -0700440 netif_stop_queue(dev);
441 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
444/*
445 * Get the current statistics.
446 * This may be called with the card open or closed.
447 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700448static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Chas Williamsd44f7742006-09-29 17:11:14 -0700450 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451}
452
Chas Williamsd44f7742006-09-29 17:11:14 -0700453static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
455 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700456 struct net_device *dev = (struct net_device *)vcc->proto_data;
457 struct lec_priv *priv = (struct lec_priv *)dev->priv;
458 struct atmlec_msg *mesg;
459 struct lec_arp_table *entry;
460 int i;
461 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700464 mesg = (struct atmlec_msg *)skb->data;
465 tmp = skb->data;
466 tmp += sizeof(struct atmlec_msg);
467 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
468 switch (mesg->type) {
469 case l_set_mac_addr:
470 for (i = 0; i < 6; i++) {
471 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
472 }
473 break;
474 case l_del_mac_addr:
475 for (i = 0; i < 6; i++) {
476 dev->dev_addr[i] = 0;
477 }
478 break;
479 case l_addr_delete:
480 lec_addr_delete(priv, mesg->content.normal.atm_addr,
481 mesg->content.normal.flag);
482 break;
483 case l_topology_change:
484 priv->topology_change = mesg->content.normal.flag;
485 break;
486 case l_flush_complete:
487 lec_flush_complete(priv, mesg->content.normal.flag);
488 break;
489 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700491 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
492 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
494
Chas Williamsd44f7742006-09-29 17:11:14 -0700495 if (mesg->content.normal.no_source_le_narp)
496 break;
497 /* FALL THROUGH */
498 case l_arp_update:
499 lec_arp_update(priv, mesg->content.normal.mac_addr,
500 mesg->content.normal.atm_addr,
501 mesg->content.normal.flag,
502 mesg->content.normal.targetless_le_arp);
503 DPRINTK("lec: in l_arp_update\n");
504 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
505 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
506 mesg->sizeoftlvs);
507 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
508 tmp, mesg->sizeoftlvs);
509 }
510 break;
511 case l_config:
512 priv->maximum_unknown_frame_count =
513 mesg->content.config.maximum_unknown_frame_count;
514 priv->max_unknown_frame_time =
515 (mesg->content.config.max_unknown_frame_time * HZ);
516 priv->max_retry_count = mesg->content.config.max_retry_count;
517 priv->aging_time = (mesg->content.config.aging_time * HZ);
518 priv->forward_delay_time =
519 (mesg->content.config.forward_delay_time * HZ);
520 priv->arp_response_time =
521 (mesg->content.config.arp_response_time * HZ);
522 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
523 priv->path_switching_delay =
524 (mesg->content.config.path_switching_delay * HZ);
525 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 priv->lane2_ops = NULL;
527 if (priv->lane_version > 1)
528 priv->lane2_ops = &lane2_ops;
529 if (dev->change_mtu(dev, mesg->content.config.mtu))
530 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700531 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700533 break;
534 case l_flush_tran_id:
535 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
536 mesg->content.normal.flag);
537 break;
538 case l_set_lecid:
539 priv->lecid =
540 (unsigned short)(0xffff & mesg->content.normal.flag);
541 break;
542 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700544 {
545 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Chas Williamsd44f7742006-09-29 17:11:14 -0700547 DPRINTK
548 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
549 dev->name, mesg->content.proxy.mac_addr[0],
550 mesg->content.proxy.mac_addr[1],
551 mesg->content.proxy.mac_addr[2],
552 mesg->content.proxy.mac_addr[3],
553 mesg->content.proxy.mac_addr[4],
554 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Chas Williamsd44f7742006-09-29 17:11:14 -0700556 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
557 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Chas Williamsd44f7742006-09-29 17:11:14 -0700559 f = br_fdb_get_hook(dev->br_port->br,
560 mesg->content.proxy.mac_addr);
561 if (f != NULL && f->dst->dev != dev
562 && f->dst->state == BR_STATE_FORWARDING) {
563 /* hit from bridge table, send LE_ARP_RESPONSE */
564 struct sk_buff *skb2;
565 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Chas Williamsd44f7742006-09-29 17:11:14 -0700567 DPRINTK
568 ("%s: entry found, responding to zeppelin\n",
569 dev->name);
570 skb2 =
571 alloc_skb(sizeof(struct atmlec_msg),
572 GFP_ATOMIC);
573 if (skb2 == NULL) {
574 br_fdb_put_hook(f);
575 break;
576 }
577 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300578 skb_copy_to_linear_data(skb2, mesg,
579 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700580 atm_force_charge(priv->lecd, skb2->truesize);
581 sk = sk_atm(priv->lecd);
582 skb_queue_tail(&sk->sk_receive_queue, skb2);
583 sk->sk_data_ready(sk, skb2->len);
584 }
585 if (f != NULL)
586 br_fdb_put_hook(f);
587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700589 break;
590 default:
591 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
592 dev_kfree_skb(skb);
593 return -EINVAL;
594 }
595 dev_kfree_skb(skb);
596 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Chas Williamsd44f7742006-09-29 17:11:14 -0700599static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Chas Williamsd44f7742006-09-29 17:11:14 -0700601 struct sk_buff *skb;
602 struct net_device *dev = (struct net_device *)vcc->proto_data;
603 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 priv->lecd = NULL;
606 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Chas Williamsd44f7742006-09-29 17:11:14 -0700608 netif_stop_queue(dev);
609 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Chas Williamsd44f7742006-09-29 17:11:14 -0700611 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700613 dev->name);
614 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
615 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700617 }
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700620 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
623static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700624 .close = lec_atm_close,
625 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626};
627
628static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700629 .ops = &lecdev_ops,
630 .type = "lec",
631 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700632 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633};
634
635/*
636 * LANE2: new argument struct sk_buff *data contains
637 * the LE_ARP based TLVs introduced in the LANE2 spec
638 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700639static int
640send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
641 unsigned char *mac_addr, unsigned char *atm_addr,
642 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 struct sock *sk;
645 struct sk_buff *skb;
646 struct atmlec_msg *mesg;
647
648 if (!priv || !priv->lecd) {
649 return -1;
650 }
651 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
652 if (!skb)
653 return -1;
654 skb->len = sizeof(struct atmlec_msg);
655 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700656 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700658 if (data != NULL)
659 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (mac_addr)
661 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700662 else
663 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if (atm_addr)
665 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
666
Chas Williamsd44f7742006-09-29 17:11:14 -0700667 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 sk = sk_atm(priv->lecd);
669 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Chas Williamsd44f7742006-09-29 17:11:14 -0700672 if (data != NULL) {
673 DPRINTK("lec: about to send %d bytes of data\n", data->len);
674 atm_force_charge(priv->lecd, data->truesize);
675 skb_queue_tail(&sk->sk_receive_queue, data);
676 sk->sk_data_ready(sk, skb->len);
677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Chas Williamsd44f7742006-09-29 17:11:14 -0700679 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682/* shamelessly stolen from drivers/net/net_init.c */
683static int lec_change_mtu(struct net_device *dev, int new_mtu)
684{
Chas Williamsd44f7742006-09-29 17:11:14 -0700685 if ((new_mtu < 68) || (new_mtu > 18190))
686 return -EINVAL;
687 dev->mtu = new_mtu;
688 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691static void lec_set_multicast_list(struct net_device *dev)
692{
Chas Williamsd44f7742006-09-29 17:11:14 -0700693 /*
694 * by default, all multicast frames arrive over the bus.
695 * eventually support selective multicast service
696 */
697 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Chas Williamsd44f7742006-09-29 17:11:14 -0700700static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Chas Williamsd44f7742006-09-29 17:11:14 -0700702 dev->change_mtu = lec_change_mtu;
703 dev->open = lec_open;
704 dev->stop = lec_close;
705 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 dev->tx_timeout = lec_tx_timeout;
707
Chas Williamsd44f7742006-09-29 17:11:14 -0700708 dev->get_stats = lec_get_stats;
709 dev->set_multicast_list = lec_set_multicast_list;
710 dev->do_ioctl = NULL;
711 printk("%s: Initialized!\n", dev->name);
712 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700716 0xff,
717 0x00,
718 0x01,
719 0x01
720};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Scott Talbert4a7097f2005-09-29 17:30:54 -0700722#define LEC_DATA_DIRECT_8023 2
723#define LEC_DATA_DIRECT_8025 3
724
725static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700726{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700727 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
728 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700729}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700730
Chas Williamsd44f7742006-09-29 17:11:14 -0700731static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700733 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700734 struct net_device *dev = (struct net_device *)vcc->proto_data;
735 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 int i = 0;
739 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
742 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700744 if (!skb) {
745 DPRINTK("%s: null skb\n", dev->name);
746 lec_vcc_close(priv, vcc);
747 return;
748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700750 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
751 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 for (i = 0; i < skb->len && i < 99; i++) {
754 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 for (i = 0; i < skb->len && i < 30; i++) {
758 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700761 if (i == skb->len)
762 printk("%s\n", buf);
763 else
764 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700766 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 struct sock *sk = sk_atm(vcc);
768
Chas Williamsd44f7742006-09-29 17:11:14 -0700769 DPRINTK("%s: To daemon\n", dev->name);
770 skb_queue_tail(&sk->sk_receive_queue, skb);
771 sk->sk_data_ready(sk, skb->len);
772 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700773 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700774 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Chas Williamsd44f7742006-09-29 17:11:14 -0700776 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800777 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700778 !priv->lecd || !(dev->flags & IFF_UP)) {
779 /*
780 * Probably looping back, or if lecd is missing,
781 * lecd has gone down
782 */
783 DPRINTK("Ignoring frame...\n");
784 dev_kfree_skb(skb);
785 return;
786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700788 if (priv->is_trdev)
789 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
790 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700792 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700793
Chas Williamsd44f7742006-09-29 17:11:14 -0700794 /*
795 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700796 * the LE_ARP cache entry, delete the LE_ARP cache entry.
797 */
798 spin_lock_irqsave(&priv->lec_arp_lock, flags);
799 if (lec_is_data_direct(vcc)) {
800#ifdef CONFIG_TR
801 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700802 src =
803 ((struct lecdatahdr_8025 *)skb->data)->
804 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700805 else
806#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700807 src =
808 ((struct lecdatahdr_8023 *)skb->data)->
809 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700810 entry = lec_arp_find(priv, src);
811 if (entry && entry->vcc != vcc) {
812 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700813 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700814 }
815 }
816 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Chas Williamsd44f7742006-09-29 17:11:14 -0700818 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
819 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700821 dev_kfree_skb(skb);
822 return;
823 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700824 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700825 lec_arp_check_empties(priv, vcc, skb);
826 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700827 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700829 if (priv->is_trdev)
830 skb->protocol = tr_type_trans(skb, dev);
831 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700833 skb->protocol = eth_type_trans(skb, dev);
834 priv->stats.rx_packets++;
835 priv->stats.rx_bytes += skb->len;
836 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
837 netif_rx(skb);
838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
Chas Williamsd44f7742006-09-29 17:11:14 -0700841static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
843 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
844 struct net_device *dev = skb->dev;
845
846 if (vpriv == NULL) {
847 printk("lec_pop(): vpriv = NULL!?!?!?\n");
848 return;
849 }
850
851 vpriv->old_pop(vcc, skb);
852
853 if (vpriv->xoff && atm_may_send(vcc, 0)) {
854 vpriv->xoff = 0;
855 if (netif_running(dev) && netif_queue_stopped(dev))
856 netif_wake_queue(dev);
857 }
858}
859
Chas Williamsd44f7742006-09-29 17:11:14 -0700860static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
862 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700863 int bytes_left;
864 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Chas Williamsd44f7742006-09-29 17:11:14 -0700866 /* Lecd must be up in this case */
867 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
868 if (bytes_left != 0) {
869 printk
870 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
871 bytes_left);
872 }
873 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
874 !dev_lec[ioc_data.dev_num])
875 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
877 return -ENOMEM;
878 vpriv->xoff = 0;
879 vpriv->old_pop = vcc->pop;
880 vcc->user_back = vpriv;
881 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700882 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
883 &ioc_data, vcc, vcc->push);
884 vcc->proto_data = dev_lec[ioc_data.dev_num];
885 vcc->push = lec_push;
886 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
Chas Williamsd44f7742006-09-29 17:11:14 -0700889static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
Chas Williamsd44f7742006-09-29 17:11:14 -0700891 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
892 return -EINVAL;
893 vcc->proto_data = dev_lec[arg];
894 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700898static int lecd_attach(struct atm_vcc *vcc, int arg)
899{
900 int i;
901 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Chas Williamsd44f7742006-09-29 17:11:14 -0700903 if (arg < 0)
904 i = 0;
905 else
906 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700908 if (arg >= MAX_LEC_ITF)
909 return -EINVAL;
910#else /* Reserve the top NUM_TR_DEVS for TR */
911 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
912 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700914 if (!dev_lec[i]) {
915 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Chas Williamsd44f7742006-09-29 17:11:14 -0700917 is_trdev = 0;
918 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
919 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Chas Williamsd44f7742006-09-29 17:11:14 -0700921 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700923 if (is_trdev)
924 dev_lec[i] = alloc_trdev(size);
925 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700927 dev_lec[i] = alloc_etherdev(size);
928 if (!dev_lec[i])
929 return -ENOMEM;
930 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
931 if (register_netdev(dev_lec[i])) {
932 free_netdev(dev_lec[i]);
933 return -EINVAL;
934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Chas Williamsd44f7742006-09-29 17:11:14 -0700936 priv = dev_lec[i]->priv;
937 priv->is_trdev = is_trdev;
938 lec_init(dev_lec[i]);
939 } else {
940 priv = dev_lec[i]->priv;
941 if (priv->lecd)
942 return -EADDRINUSE;
943 }
944 lec_arp_init(priv);
945 priv->itfnum = i; /* LANE2 addition */
946 priv->lecd = vcc;
947 vcc->dev = &lecatm_dev;
948 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Chas Williamsd44f7742006-09-29 17:11:14 -0700950 vcc->proto_data = dev_lec[i];
951 set_bit(ATM_VF_META, &vcc->flags);
952 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Chas Williamsd44f7742006-09-29 17:11:14 -0700954 /* Set default values to these variables */
955 priv->maximum_unknown_frame_count = 1;
956 priv->max_unknown_frame_time = (1 * HZ);
957 priv->vcc_timeout_period = (1200 * HZ);
958 priv->max_retry_count = 1;
959 priv->aging_time = (300 * HZ);
960 priv->forward_delay_time = (15 * HZ);
961 priv->topology_change = 0;
962 priv->arp_response_time = (1 * HZ);
963 priv->flush_timeout = (4 * HZ);
964 priv->path_switching_delay = (6 * HZ);
965
966 if (dev_lec[i]->flags & IFF_UP) {
967 netif_start_queue(dev_lec[i]);
968 }
969 __module_get(THIS_MODULE);
970 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
972
973#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700974static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
976 static char *lec_arp_status_string[] = {
977 "ESI_UNKNOWN ",
978 "ESI_ARP_PENDING ",
979 "ESI_VC_PENDING ",
980 "<Undefined> ",
981 "ESI_FLUSH_PENDING ",
982 "ESI_FORWARD_DIRECT"
983 };
984
985 if (status > ESI_FORWARD_DIRECT)
986 status = 3; /* ESI_UNDEFINED */
987 return lec_arp_status_string[status];
988}
989
990static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
991{
992 int i;
993
994 for (i = 0; i < ETH_ALEN; i++)
995 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
996 seq_printf(seq, " ");
997 for (i = 0; i < ATM_ESA_LEN; i++)
998 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
999 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
1000 entry->flags & 0xffff);
1001 if (entry->vcc)
1002 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
1003 else
Chas Williamsd44f7742006-09-29 17:11:14 -07001004 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (entry->recv_vcc) {
1006 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1007 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -07001008 }
1009 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012struct lec_state {
1013 unsigned long flags;
1014 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001015 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 struct net_device *dev;
1017 int itf;
1018 int arp_table;
1019 int misc_table;
1020};
1021
Chas Williamsd0732f62006-09-29 17:14:27 -07001022static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 loff_t *l)
1024{
Chas Williamsd0732f62006-09-29 17:14:27 -07001025 struct hlist_node *e = state->node;
1026 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001029 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001031 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 --*l;
1033 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001034
1035 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (--*l < 0)
1037 break;
1038 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001039 state->node = e;
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return (*l < 0) ? state : NULL;
1042}
1043
1044static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001045 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
1047 void *v = NULL;
1048 int p;
1049
1050 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001051 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if (v)
1053 break;
1054 }
1055 state->arp_table = p;
1056 return v;
1057}
1058
1059static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1060 struct lec_priv *priv)
1061{
Chas Williamsd0732f62006-09-29 17:14:27 -07001062 struct hlist_head *lec_misc_tables[] = {
1063 &priv->lec_arp_empty_ones,
1064 &priv->lec_no_forward,
1065 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 };
1067 void *v = NULL;
1068 int q;
1069
1070 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1071 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1072 if (v)
1073 break;
1074 }
1075 state->misc_table = q;
1076 return v;
1077}
1078
1079static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1080 struct lec_priv *priv)
1081{
1082 if (!state->locked) {
1083 state->locked = priv;
1084 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1085 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001086 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1088 state->locked = NULL;
1089 /* Partial state reset for the next time we get called */
1090 state->arp_table = state->misc_table = 0;
1091 }
1092 return state->locked;
1093}
1094
1095static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1096{
1097 struct net_device *dev;
1098 void *v;
1099
1100 dev = state->dev ? state->dev : dev_lec[state->itf];
1101 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1102 if (!v && dev) {
1103 dev_put(dev);
1104 /* Partial state reset for the next time we get called */
1105 dev = NULL;
1106 }
1107 state->dev = dev;
1108 return v;
1109}
1110
1111static void *lec_get_idx(struct lec_state *state, loff_t l)
1112{
1113 void *v = NULL;
1114
1115 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1116 v = lec_itf_walk(state, &l);
1117 if (v)
1118 break;
1119 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001120 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
1123static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1124{
1125 struct lec_state *state = seq->private;
1126
1127 state->itf = 0;
1128 state->dev = NULL;
1129 state->locked = NULL;
1130 state->arp_table = 0;
1131 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001132 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Chas Williamsd44f7742006-09-29 17:11:14 -07001134 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
1137static void lec_seq_stop(struct seq_file *seq, void *v)
1138{
1139 struct lec_state *state = seq->private;
1140
1141 if (state->dev) {
1142 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1143 state->flags);
1144 dev_put(state->dev);
1145 }
1146}
1147
1148static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1149{
1150 struct lec_state *state = seq->private;
1151
1152 v = lec_get_idx(state, 1);
1153 *pos += !!PTR_ERR(v);
1154 return v;
1155}
1156
1157static int lec_seq_show(struct seq_file *seq, void *v)
1158{
Chas Williamsd44f7742006-09-29 17:11:14 -07001159 static char lec_banner[] = "Itf MAC ATM destination"
1160 " Status Flags "
1161 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 if (v == (void *)1)
1164 seq_puts(seq, lec_banner);
1165 else {
1166 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001167 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001168 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001171 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
1173 return 0;
1174}
1175
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001176static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001177 .start = lec_seq_start,
1178 .next = lec_seq_next,
1179 .stop = lec_seq_stop,
1180 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181};
1182
1183static int lec_seq_open(struct inode *inode, struct file *file)
1184{
1185 struct lec_state *state;
1186 struct seq_file *seq;
1187 int rc = -EAGAIN;
1188
1189 state = kmalloc(sizeof(*state), GFP_KERNEL);
1190 if (!state) {
1191 rc = -ENOMEM;
1192 goto out;
1193 }
1194
1195 rc = seq_open(file, &lec_seq_ops);
1196 if (rc)
1197 goto out_kfree;
1198 seq = file->private_data;
1199 seq->private = state;
1200out:
1201 return rc;
1202
1203out_kfree:
1204 kfree(state);
1205 goto out;
1206}
1207
1208static int lec_seq_release(struct inode *inode, struct file *file)
1209{
1210 return seq_release_private(inode, file);
1211}
1212
Arjan van de Ven9a321442007-02-12 00:55:35 -08001213static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001214 .owner = THIS_MODULE,
1215 .open = lec_seq_open,
1216 .read = seq_read,
1217 .llseek = seq_lseek,
1218 .release = lec_seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219};
1220#endif
1221
1222static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1223{
1224 struct atm_vcc *vcc = ATM_SD(sock);
1225 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001228 case ATMLEC_CTRL:
1229 case ATMLEC_MCAST:
1230 case ATMLEC_DATA:
1231 if (!capable(CAP_NET_ADMIN))
1232 return -EPERM;
1233 break;
1234 default:
1235 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237
1238 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001239 case ATMLEC_CTRL:
1240 err = lecd_attach(vcc, (int)arg);
1241 if (err >= 0)
1242 sock->state = SS_CONNECTED;
1243 break;
1244 case ATMLEC_MCAST:
1245 err = lec_mcast_attach(vcc, (int)arg);
1246 break;
1247 case ATMLEC_DATA:
1248 err = lec_vcc_attach(vcc, (void __user *)arg);
1249 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251
1252 return err;
1253}
1254
1255static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001256 .owner = THIS_MODULE,
1257 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258};
1259
1260static int __init lane_module_init(void)
1261{
1262#ifdef CONFIG_PROC_FS
1263 struct proc_dir_entry *p;
1264
1265 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1266 if (p)
1267 p->proc_fops = &lec_seq_fops;
1268#endif
1269
1270 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
1275static void __exit lane_module_cleanup(void)
1276{
Chas Williamsd44f7742006-09-29 17:11:14 -07001277 int i;
1278 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 remove_proc_entry("lec", atm_proc_root);
1281
1282 deregister_atm_ioctl(&lane_ioctl_ops);
1283
Chas Williamsd44f7742006-09-29 17:11:14 -07001284 for (i = 0; i < MAX_LEC_ITF; i++) {
1285 if (dev_lec[i] != NULL) {
1286 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001288 free_netdev(dev_lec[i]);
1289 dev_lec[i] = NULL;
1290 }
1291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Chas Williamsd44f7742006-09-29 17:11:14 -07001293 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
1296module_init(lane_module_init);
1297module_exit(lane_module_cleanup);
1298
1299/*
1300 * LANE2: 3.1.3, LE_RESOLVE.request
1301 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1302 * If sizeoftlvs == NULL the default TLVs associated with with this
1303 * lec will be used.
1304 * If dst_mac == NULL, targetless LE_ARP will be sent
1305 */
1306static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001307 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
1309 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001310 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1311 struct lec_arp_table *table;
1312 struct sk_buff *skb;
1313 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001317 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 if (table == NULL)
1320 return -1;
1321
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001322 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001323 if (*tlvs == NULL)
1324 return -1;
1325
Chas Williamsd44f7742006-09-29 17:11:14 -07001326 *sizeoftlvs = table->sizeoftlvs;
1327
1328 return 0;
1329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 if (sizeoftlvs == NULL)
1332 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 else {
1335 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1336 if (skb == NULL)
1337 return -1;
1338 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001339 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1341 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001342 return retval;
1343}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345/*
1346 * LANE2: 3.1.4, LE_ASSOCIATE.request
1347 * Associate the *tlvs with the *lan_dst address.
1348 * Will overwrite any previous association
1349 * Returns 1 for success, 0 for failure (out of memory)
1350 *
1351 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001352static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1353 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Chas Williamsd44f7742006-09-29 17:11:14 -07001355 int retval;
1356 struct sk_buff *skb;
1357 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 if (compare_ether_addr(lan_dst, dev->dev_addr))
1360 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Chas Williamsd44f7742006-09-29 17:11:14 -07001362 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001364 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001365 if (priv->tlvs == NULL)
1366 return (0);
1367 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Chas Williamsd44f7742006-09-29 17:11:14 -07001369 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1370 if (skb == NULL)
1371 return 0;
1372 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001373 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001374 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1375 if (retval != 0)
1376 printk("lec.c: lane2_associate_req() failed\n");
1377 /*
1378 * If the previous association has changed we must
1379 * somehow notify other LANE entities about the change
1380 */
1381 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
1384/*
1385 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1386 *
1387 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001388static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1389 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001392 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393#endif
1394 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001395#if 0 /*
1396 * Why have the TLVs in LE_ARP entries
1397 * since we do not use them? When you
1398 * uncomment this code, make sure the
1399 * TLVs get freed when entry is killed
1400 */
1401 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Chas Williamsd44f7742006-09-29 17:11:14 -07001403 if (entry == NULL)
1404 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Chas Williamsd44f7742006-09-29 17:11:14 -07001406 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001408 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001409 if (entry->tlvs == NULL)
1410 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001411 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#endif
1413#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001414 printk("lec.c: lane2_associate_ind()\n");
1415 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1416 while (i < sizeoftlvs)
1417 printk("%02x ", tlvs[i++]);
1418
1419 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420#endif
1421
Chas Williamsd44f7742006-09-29 17:11:14 -07001422 /* tell MPOA about the TLVs we saw */
1423 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1424 priv->lane2_ops->associate_indicator(dev, mac_addr,
1425 tlvs, sizeoftlvs);
1426 }
1427 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
1430/*
1431 * Here starts what used to lec_arpc.c
1432 *
1433 * lec_arpc.c was added here when making
1434 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 */
1436
1437#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438#include <linux/timer.h>
1439#include <asm/param.h>
1440#include <asm/atomic.h>
1441#include <linux/inetdevice.h>
1442#include <net/route.h>
1443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444#if 0
1445#define DPRINTK(format,args...)
1446/*
1447#define DPRINTK printk
1448*/
1449#endif
1450#define DEBUG_ARP_TABLE 0
1451
1452#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1453
David Howellsc4028952006-11-22 14:57:56 +00001454static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455static void lec_arp_expire_arp(unsigned long data);
1456
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001457/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 * Arp table funcs
1459 */
1460
1461#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1462
1463/*
1464 * Initialization of arp-cache
1465 */
Chas Williams1fa99612006-09-29 17:11:47 -07001466static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Chas Williams1fa99612006-09-29 17:11:47 -07001468 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Chas Williams1fa99612006-09-29 17:11:47 -07001470 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001471 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001472 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001473 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1474 INIT_HLIST_HEAD(&priv->lec_no_forward);
1475 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001477 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001478 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Chas Williams1fa99612006-09-29 17:11:47 -07001481static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Chas Williams1fa99612006-09-29 17:11:47 -07001483 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 struct atm_vcc *vcc = entry->vcc;
1485 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001486 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Chas Williams1fa99612006-09-29 17:11:47 -07001488 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 if (vpriv->xoff)
1490 netif_wake_queue(dev);
1491 kfree(vpriv);
1492 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001493 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001495 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001496 }
1497 if (entry->recv_vcc) {
1498 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001500 entry->recv_vcc = NULL;
1501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
1504/*
1505 * Insert entry to lec_arp_table
1506 * LANE2: Add to the end of the list to satisfy 8.1.13
1507 */
Chas Williams1fa99612006-09-29 17:11:47 -07001508static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001509lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Chas Williamsd0732f62006-09-29 17:14:27 -07001511 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Chas Williamsd0732f62006-09-29 17:14:27 -07001513 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1514 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001515
1516 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 -07001517 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1518 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1519 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
1522/*
1523 * Remove entry from lec_arp_table
1524 */
Chas Williams1fa99612006-09-29 17:11:47 -07001525static int
1526lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Chas Williamsd0732f62006-09-29 17:14:27 -07001528 struct hlist_node *node;
1529 struct lec_arp_table *entry;
1530 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Chas Williams1fa99612006-09-29 17:11:47 -07001532 if (!to_remove) {
1533 return -1;
1534 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001535
1536 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001537 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Chas Williamsd0732f62006-09-29 17:14:27 -07001539 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001540 if (to_remove->status >= ESI_FLUSH_PENDING) {
1541 /*
1542 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1543 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001544 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1545 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1546 if (memcmp(to_remove->atm_addr,
1547 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001548 remove_vcc = 0;
1549 break;
1550 }
1551 }
1552 }
1553 if (remove_vcc)
1554 lec_arp_clear_vccs(to_remove);
1555 }
1556 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1557
1558 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1559 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1560 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1561 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
1565#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001566static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Chas Williams1fa99612006-09-29 17:11:47 -07001568 switch (st) {
1569 case ESI_UNKNOWN:
1570 return "ESI_UNKNOWN";
1571 case ESI_ARP_PENDING:
1572 return "ESI_ARP_PENDING";
1573 case ESI_VC_PENDING:
1574 return "ESI_VC_PENDING";
1575 case ESI_FLUSH_PENDING:
1576 return "ESI_FLUSH_PENDING";
1577 case ESI_FORWARD_DIRECT:
1578 return "ESI_FORWARD_DIRECT";
1579 default:
1580 return "<UNKNOWN>";
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Chas Williams1fa99612006-09-29 17:11:47 -07001584static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
Chas Williamsd0732f62006-09-29 17:14:27 -07001586 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001587 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001588 char buf[256];
1589 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Chas Williams1fa99612006-09-29 17:11:47 -07001591 printk("Dump %p:\n", priv);
1592 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001593 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1594 offset = 0;
1595 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001596 offset += sprintf(buf + offset, "Mac:");
1597 for (j = 0; j < ETH_ALEN; j++) {
1598 offset += sprintf(buf + offset,
1599 "%2.2x ",
1600 rulla->mac_addr[j] & 0xff);
1601 }
1602 offset += sprintf(buf + offset, "Atm:");
1603 for (j = 0; j < ATM_ESA_LEN; j++) {
1604 offset += sprintf(buf + offset,
1605 "%2.2x ",
1606 rulla->atm_addr[j] & 0xff);
1607 }
1608 offset += sprintf(buf + offset,
1609 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1610 rulla->vcc ? rulla->vcc->vpi : 0,
1611 rulla->vcc ? rulla->vcc->vci : 0,
1612 rulla->recv_vcc ? rulla->recv_vcc->
1613 vpi : 0,
1614 rulla->recv_vcc ? rulla->recv_vcc->
1615 vci : 0, rulla->last_used,
1616 rulla->timestamp, rulla->no_tries);
1617 offset +=
1618 sprintf(buf + offset,
1619 "Flags:%x, Packets_flooded:%x, Status: %s ",
1620 rulla->flags, rulla->packets_flooded,
1621 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001622 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001623 }
Chas Williams1fa99612006-09-29 17:11:47 -07001624 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001625
1626 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001627 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001628 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001629 offset = 0;
1630 offset += sprintf(buf + offset, "Mac:");
1631 for (j = 0; j < ETH_ALEN; j++) {
1632 offset += sprintf(buf + offset, "%2.2x ",
1633 rulla->mac_addr[j] & 0xff);
1634 }
1635 offset += sprintf(buf + offset, "Atm:");
1636 for (j = 0; j < ATM_ESA_LEN; j++) {
1637 offset += sprintf(buf + offset, "%2.2x ",
1638 rulla->atm_addr[j] & 0xff);
1639 }
1640 offset += sprintf(buf + offset,
1641 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1642 rulla->vcc ? rulla->vcc->vpi : 0,
1643 rulla->vcc ? rulla->vcc->vci : 0,
1644 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1645 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1646 rulla->last_used,
1647 rulla->timestamp, rulla->no_tries);
1648 offset += sprintf(buf + offset,
1649 "Flags:%x, Packets_flooded:%x, Status: %s ",
1650 rulla->flags, rulla->packets_flooded,
1651 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001652 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001653 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001654
1655 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001656 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001657 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001658 offset = 0;
1659 offset += sprintf(buf + offset, "Mac:");
1660 for (j = 0; j < ETH_ALEN; j++) {
1661 offset += sprintf(buf + offset, "%2.2x ",
1662 rulla->mac_addr[j] & 0xff);
1663 }
1664 offset += sprintf(buf + offset, "Atm:");
1665 for (j = 0; j < ATM_ESA_LEN; j++) {
1666 offset += sprintf(buf + offset, "%2.2x ",
1667 rulla->atm_addr[j] & 0xff);
1668 }
1669 offset += sprintf(buf + offset,
1670 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1671 rulla->vcc ? rulla->vcc->vpi : 0,
1672 rulla->vcc ? rulla->vcc->vci : 0,
1673 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1674 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1675 rulla->last_used,
1676 rulla->timestamp, rulla->no_tries);
1677 offset += sprintf(buf + offset,
1678 "Flags:%x, Packets_flooded:%x, Status: %s ",
1679 rulla->flags, rulla->packets_flooded,
1680 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001681 printk("%s", buf);
1682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Chas Williamsd0732f62006-09-29 17:14:27 -07001684 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001685 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001686 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001687 offset = 0;
1688 offset += sprintf(buf + offset, "Mac:");
1689 for (j = 0; j < ETH_ALEN; j++) {
1690 offset += sprintf(buf + offset, "%2.2x ",
1691 rulla->mac_addr[j] & 0xff);
1692 }
1693 offset += sprintf(buf + offset, "Atm:");
1694 for (j = 0; j < ATM_ESA_LEN; j++) {
1695 offset += sprintf(buf + offset, "%2.2x ",
1696 rulla->atm_addr[j] & 0xff);
1697 }
1698 offset += sprintf(buf + offset,
1699 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1700 rulla->vcc ? rulla->vcc->vpi : 0,
1701 rulla->vcc ? rulla->vcc->vci : 0,
1702 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1703 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1704 rulla->last_used,
1705 rulla->timestamp, rulla->no_tries);
1706 offset += sprintf(buf + offset,
1707 "Flags:%x, Packets_flooded:%x, Status: %s ",
1708 rulla->flags, rulla->packets_flooded,
1709 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001710 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
Chas Williamsd0732f62006-09-29 17:14:27 -07001714#else
1715#define dump_arp_table(priv) do { } while (0)
1716#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
1718/*
1719 * Destruction of arp-cache
1720 */
Chas Williams1fa99612006-09-29 17:11:47 -07001721static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722{
1723 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001724 struct hlist_node *node, *next;
1725 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001726 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Chas Williams987e46b2006-09-29 17:15:59 -07001728 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001729
1730 /*
1731 * Remove all entries
1732 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001735 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001736 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001737 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001738 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001739 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001741 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001742
1743 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001744 del_timer_sync(&entry->timer);
1745 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001746 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001747 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001748 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001749 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1750
1751 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001752 del_timer_sync(&entry->timer);
1753 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001754 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001755 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001756 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001757 INIT_HLIST_HEAD(&priv->lec_no_forward);
1758
1759 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001760 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1761 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001762 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001763 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001764 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001765 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001766 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1768}
1769
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001770/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 * Find entry by mac_address
1772 */
Chas Williams1fa99612006-09-29 17:11:47 -07001773static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1774 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
Chas Williamsd0732f62006-09-29 17:14:27 -07001776 struct hlist_node *node;
1777 struct hlist_head *head;
1778 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Chas Williams1fa99612006-09-29 17:11:47 -07001780 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1781 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1782 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001783
Chas Williamsd0732f62006-09-29 17:14:27 -07001784 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1785 hlist_for_each_entry(entry, node, head, next) {
1786 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1787 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001788 }
Chas Williams1fa99612006-09-29 17:11:47 -07001789 }
1790 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791}
1792
Chas Williams1fa99612006-09-29 17:11:47 -07001793static struct lec_arp_table *make_entry(struct lec_priv *priv,
1794 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Chas Williams1fa99612006-09-29 17:11:47 -07001796 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Chas Williams1fa99612006-09-29 17:11:47 -07001798 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1799 if (!to_return) {
1800 printk("LEC: Arp entry kmalloc failed\n");
1801 return NULL;
1802 }
1803 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001804 INIT_HLIST_NODE(&to_return->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001805 init_timer(&to_return->timer);
1806 to_return->timer.function = lec_arp_expire_arp;
1807 to_return->timer.data = (unsigned long)to_return;
1808 to_return->last_used = jiffies;
1809 to_return->priv = priv;
1810 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001811 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001812 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813}
1814
Chas Williams1fa99612006-09-29 17:11:47 -07001815/* Arp sent timer expired */
1816static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
Chas Williams1fa99612006-09-29 17:11:47 -07001818 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Chas Williams1fa99612006-09-29 17:11:47 -07001820 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Chas Williams1fa99612006-09-29 17:11:47 -07001822 DPRINTK("lec_arp_expire_arp\n");
1823 if (entry->status == ESI_ARP_PENDING) {
1824 if (entry->no_tries <= entry->priv->max_retry_count) {
1825 if (entry->is_rdesc)
1826 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1827 entry->mac_addr, NULL, NULL);
1828 else
1829 send_to_lecd(entry->priv, l_arp_xmt,
1830 entry->mac_addr, NULL, NULL);
1831 entry->no_tries++;
1832 }
1833 mod_timer(&entry->timer, jiffies + (1 * HZ));
1834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
Chas Williams1fa99612006-09-29 17:11:47 -07001837/* Unknown/unused vcc expire, remove associated entry */
1838static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
1840 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001841 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1842 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Chas Williams1fa99612006-09-29 17:11:47 -07001844 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
Chas Williams1fa99612006-09-29 17:11:47 -07001846 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1847 to_remove, priv,
1848 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1849 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001852 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1854
Chas Williams1fa99612006-09-29 17:11:47 -07001855 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001856 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857}
1858
1859/*
1860 * Expire entries.
1861 * 1. Re-set timer
1862 * 2. For each entry, delete entries that have aged past the age limit.
1863 * 3. For each entry, depending on the status of the entry, perform
1864 * the following maintenance.
1865 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1866 * tick_count is above the max_unknown_frame_time, clear
1867 * the tick_count to zero and clear the packets_flooded counter
1868 * to zero. This supports the packet rate limit per address
1869 * while flooding unknowns.
1870 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1871 * than or equal to the path_switching_delay, change the status
1872 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1873 * regardless of the progress of the flush protocol.
1874 */
David Howellsc4028952006-11-22 14:57:56 +00001875static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
1877 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001878 struct lec_priv *priv =
1879 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001880 struct hlist_node *node, *next;
1881 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001882 unsigned long now;
1883 unsigned long time_to_check;
1884 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Chas Williams1fa99612006-09-29 17:11:47 -07001886 DPRINTK("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001888restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001890 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001891 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001892 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 priv->topology_change)
1894 time_to_check = priv->forward_delay_time;
1895 else
1896 time_to_check = priv->aging_time;
1897
1898 DPRINTK("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001899 now, entry->last_used, time_to_check);
1900 if (time_after(now, entry->last_used + time_to_check)
1901 && !(entry->flags & LEC_PERMANENT_FLAG)
1902 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 /* Remove entry */
1904 DPRINTK("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001906 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 } else {
1908 /* Something else */
1909 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001910 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001912 entry->timestamp +
1913 priv->
1914 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 entry->timestamp = jiffies;
1916 entry->packets_flooded = 0;
1917 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001918 send_to_lecd(priv, l_svc_setup,
1919 entry->mac_addr,
1920 entry->atm_addr,
1921 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 }
Chas Williams1fa99612006-09-29 17:11:47 -07001923 if (entry->status == ESI_FLUSH_PENDING
1924 &&
1925 time_after_eq(now, entry->timestamp +
1926 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001928 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
Chas Williams6656e3c2006-09-29 17:17:17 -07001930 lec_arp_hold(entry);
1931 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1932 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1933 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001935 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001936 lec_arp_put(entry);
1937 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940 }
1941 }
1942 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1943
Chas Williams987e46b2006-09-29 17:15:59 -07001944 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945}
Chas Williams1fa99612006-09-29 17:11:47 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947/*
1948 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001949 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 */
Chas Williams1fa99612006-09-29 17:11:47 -07001951static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1952 unsigned char *mac_to_find, int is_rdesc,
1953 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
1955 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001956 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 struct atm_vcc *found;
1958
Chas Williams1fa99612006-09-29 17:11:47 -07001959 if (mac_to_find[0] & 0x01) {
1960 switch (priv->lane_version) {
1961 case 1:
1962 return priv->mcast_vcc;
1963 break;
1964 case 2: /* LANE2 wants arp for multicast addresses */
1965 if (!compare_ether_addr(mac_to_find, bus_mac))
1966 return priv->mcast_vcc;
1967 break;
1968 default:
1969 break;
1970 }
1971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001974 entry = lec_arp_find(priv, mac_to_find);
1975
1976 if (entry) {
1977 if (entry->status == ESI_FORWARD_DIRECT) {
1978 /* Connection Ok */
1979 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001980 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001981 *ret_entry = entry;
1982 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001984 }
1985 /*
1986 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001987 * so another LE_ARP request can be made for this frame.
1988 */
1989 if (entry->status == ESI_ARP_PENDING) {
1990 entry->no_tries = 0;
1991 }
Chas Williams1fa99612006-09-29 17:11:47 -07001992 /*
1993 * Data direct VC not yet set up, check to see if the unknown
1994 * frame count is greater than the limit. If the limit has
1995 * not been reached, allow the caller to send packet to
1996 * BUS.
1997 */
1998 if (entry->status != ESI_FLUSH_PENDING &&
1999 entry->packets_flooded <
2000 priv->maximum_unknown_frame_count) {
2001 entry->packets_flooded++;
2002 DPRINTK("LEC_ARP: Flooding..\n");
2003 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002005 }
2006 /*
2007 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 * or BUS flood limit was reached for an entry which is
2009 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2010 */
Chas Williams6656e3c2006-09-29 17:17:17 -07002011 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002012 *ret_entry = entry;
2013 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
2014 entry->vcc);
2015 found = NULL;
2016 } else {
2017 /* No matching entry was found */
2018 entry = make_entry(priv, mac_to_find);
2019 DPRINTK("LEC_ARP: Making entry\n");
2020 if (!entry) {
2021 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002023 }
2024 lec_arp_add(priv, entry);
2025 /* We want arp-request(s) to be sent */
2026 entry->packets_flooded = 1;
2027 entry->status = ESI_ARP_PENDING;
2028 entry->no_tries = 1;
2029 entry->last_used = entry->timestamp = jiffies;
2030 entry->is_rdesc = is_rdesc;
2031 if (entry->is_rdesc)
2032 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2033 NULL);
2034 else
2035 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2036 entry->timer.expires = jiffies + (1 * HZ);
2037 entry->timer.function = lec_arp_expire_arp;
2038 add_timer(&entry->timer);
2039 found = priv->mcast_vcc;
2040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
2042out:
2043 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2044 return found;
2045}
2046
2047static int
Chas Williams1fa99612006-09-29 17:11:47 -07002048lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2049 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050{
2051 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002052 struct hlist_node *node, *next;
2053 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002054 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Chas Williams1fa99612006-09-29 17:11:47 -07002056 DPRINTK("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002058 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002059 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002060 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2061 && (permanent ||
2062 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002064 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002067 return 0;
2068 }
2069 }
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 -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
2074/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002075 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 */
2077static void
2078lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002079 unsigned char *atm_addr, unsigned long remoteflag,
2080 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081{
2082 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002083 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002084 struct lec_arp_table *entry, *tmp;
2085 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Chas Williams1fa99612006-09-29 17:11:47 -07002087 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2088 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2089 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2090 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002093 entry = lec_arp_find(priv, mac_addr);
2094 if (entry == NULL && targetless_le_arp)
2095 goto out; /*
2096 * LANE2: ignore targetless LE_ARPs for which
2097 * we have no entry in the cache. 7.1.30
2098 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002099 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2100 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2101 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2102 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002103 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002104 tmp = lec_arp_find(priv, mac_addr);
2105 if (tmp) {
2106 del_timer(&tmp->timer);
2107 tmp->status = ESI_FORWARD_DIRECT;
2108 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2109 tmp->vcc = entry->vcc;
2110 tmp->old_push = entry->old_push;
2111 tmp->last_used = jiffies;
2112 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002113 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002114 entry = tmp;
2115 } else {
2116 entry->status = ESI_FORWARD_DIRECT;
2117 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2118 entry->last_used = jiffies;
2119 lec_arp_add(priv, entry);
2120 }
2121 if (remoteflag)
2122 entry->flags |= LEC_REMOTE_FLAG;
2123 else
2124 entry->flags &= ~LEC_REMOTE_FLAG;
2125 DPRINTK("After update\n");
2126 dump_arp_table(priv);
2127 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002128 }
Chas Williams1fa99612006-09-29 17:11:47 -07002129 }
2130 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002131
Chas Williams1fa99612006-09-29 17:11:47 -07002132 entry = lec_arp_find(priv, mac_addr);
2133 if (!entry) {
2134 entry = make_entry(priv, mac_addr);
2135 if (!entry)
2136 goto out;
2137 entry->status = ESI_UNKNOWN;
2138 lec_arp_add(priv, entry);
2139 /* Temporary, changes before end of function */
2140 }
2141 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2142 del_timer(&entry->timer);
2143 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002144 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002145 if (entry != tmp &&
2146 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2147 /* Vcc to this host exists */
2148 if (tmp->status > ESI_VC_PENDING) {
2149 /*
2150 * ESI_FLUSH_PENDING,
2151 * ESI_FORWARD_DIRECT
2152 */
2153 entry->vcc = tmp->vcc;
2154 entry->old_push = tmp->old_push;
2155 }
2156 entry->status = tmp->status;
2157 break;
2158 }
2159 }
2160 }
2161 if (remoteflag)
2162 entry->flags |= LEC_REMOTE_FLAG;
2163 else
2164 entry->flags &= ~LEC_REMOTE_FLAG;
2165 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2166 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002167 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002168 }
2169 DPRINTK("After update2\n");
2170 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171out:
2172 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2173}
2174
2175/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002176 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 */
2178static void
2179lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002180 struct atm_vcc *vcc,
2181 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
2183 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002184 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002185 struct lec_arp_table *entry;
2186 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
2188 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002189 if (ioc_data->receive == 2) {
2190 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Chas Williams1fa99612006-09-29 17:11:47 -07002192 DPRINTK("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002194 entry = lec_arp_find(priv, bus_mac);
2195 if (!entry) {
2196 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002198 }
2199 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2200 entry->recv_vcc = vcc;
2201 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002203 entry = make_entry(priv, bus_mac);
2204 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002206 del_timer(&entry->timer);
2207 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2208 entry->recv_vcc = vcc;
2209 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002210 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002211 goto out;
2212 } else if (ioc_data->receive == 1) {
2213 /*
2214 * Vcc which we don't want to make default vcc,
2215 * attach it anyway.
2216 */
2217 DPRINTK
2218 ("LEC_ARP:Attaching data direct, not default: "
2219 "%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",
2220 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2221 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2222 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2223 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2224 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2225 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2226 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2227 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2228 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2229 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2230 entry = make_entry(priv, bus_mac);
2231 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002233 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2234 memset(entry->mac_addr, 0, ETH_ALEN);
2235 entry->recv_vcc = vcc;
2236 entry->old_recv_push = old_push;
2237 entry->status = ESI_UNKNOWN;
2238 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2239 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002240 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002241 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 dump_arp_table(priv);
2243 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002244 }
2245 DPRINTK
2246 ("LEC_ARP:Attaching data direct, default: "
2247 "%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",
2248 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2249 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2250 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2251 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2252 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2253 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2254 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2255 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2256 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2257 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2258 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002259 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002260 if (memcmp
2261 (ioc_data->atm_addr, entry->atm_addr,
2262 ATM_ESA_LEN) == 0) {
2263 DPRINTK("LEC_ARP: Attaching data direct\n");
2264 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2265 entry->vcc ? entry->vcc->vci : 0,
2266 entry->recv_vcc ? entry->recv_vcc->
2267 vci : 0);
2268 found_entry = 1;
2269 del_timer(&entry->timer);
2270 entry->vcc = vcc;
2271 entry->old_push = old_push;
2272 if (entry->status == ESI_VC_PENDING) {
2273 if (priv->maximum_unknown_frame_count
2274 == 0)
2275 entry->status =
2276 ESI_FORWARD_DIRECT;
2277 else {
2278 entry->timestamp = jiffies;
2279 entry->status =
2280 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002282 send_to_lecd(priv, l_flush_xmt,
2283 NULL,
2284 entry->atm_addr,
2285 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002287 }
2288 } else {
2289 /*
2290 * They were forming a connection
2291 * to us, and we to them. Our
2292 * ATM address is numerically lower
2293 * than theirs, so we make connection
2294 * we formed into default VCC (8.1.11).
2295 * Connection they made gets torn
2296 * down. This might confuse some
2297 * clients. Can be changed if
2298 * someone reports trouble...
2299 */
2300 ;
2301 }
2302 }
2303 }
2304 }
2305 if (found_entry) {
2306 DPRINTK("After vcc was added\n");
2307 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002309 }
2310 /*
2311 * Not found, snatch address from first data packet that arrives
2312 * from this vcc
2313 */
2314 entry = make_entry(priv, bus_mac);
2315 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002317 entry->vcc = vcc;
2318 entry->old_push = old_push;
2319 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2320 memset(entry->mac_addr, 0, ETH_ALEN);
2321 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002322 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002323 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2324 entry->timer.function = lec_arp_expire_vcc;
2325 add_timer(&entry->timer);
2326 DPRINTK("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 dump_arp_table(priv);
2328out:
2329 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2330}
2331
Chas Williams1fa99612006-09-29 17:11:47 -07002332static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
2334 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002335 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002336 struct lec_arp_table *entry;
2337 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chas Williams1fa99612006-09-29 17:11:47 -07002339 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002340restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002341 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2342 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002343 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002344 if (entry->flush_tran_id == tran_id
2345 && entry->status == ESI_FLUSH_PENDING) {
2346 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002347 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002348
Chas Williams6656e3c2006-09-29 17:17:17 -07002349 lec_arp_hold(entry);
2350 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2351 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2352 lec_send(vcc, skb, entry->priv);
2353 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002354 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002355 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002356 DPRINTK("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002357 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002358 }
2359 }
2360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002362 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365static void
2366lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002367 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
2369 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002370 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002371 struct lec_arp_table *entry;
2372 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
2374 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002375 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002376 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002377 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2378 entry->flush_tran_id = tran_id;
Chas Williamsd0732f62006-09-29 17:14:27 -07002379 DPRINTK("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002380 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002381 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2384}
2385
Chas Williams1fa99612006-09-29 17:11:47 -07002386static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
2388 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002389 unsigned char mac_addr[] = {
2390 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2391 };
2392 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 struct lec_vcc_priv *vpriv;
2394 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002395
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2397 return -ENOMEM;
2398 vpriv->xoff = 0;
2399 vpriv->old_pop = vcc->pop;
2400 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002401 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002403 to_add = make_entry(priv, mac_addr);
2404 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 vcc->pop = vpriv->old_pop;
2406 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002407 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002409 }
2410 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2411 to_add->status = ESI_FORWARD_DIRECT;
2412 to_add->flags |= LEC_PERMANENT_FLAG;
2413 to_add->vcc = vcc;
2414 to_add->old_push = vcc->push;
2415 vcc->push = lec_push;
2416 priv->mcast_vcc = vcc;
2417 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418out:
2419 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002420 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421}
2422
Chas Williams1fa99612006-09-29 17:11:47 -07002423static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
2425 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002426 struct hlist_node *node, *next;
2427 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002428 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Chas Williams1fa99612006-09-29 17:11:47 -07002430 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2431 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002434
Chas Williams1fa99612006-09-29 17:11:47 -07002435 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002436 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002437 if (vcc == entry->vcc) {
2438 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002439 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002440 if (priv->mcast_vcc == vcc) {
2441 priv->mcast_vcc = NULL;
2442 }
2443 }
2444 }
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Chas Williamsd0732f62006-09-29 17:14:27 -07002447 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2448 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002449 lec_arp_clear_vccs(entry);
2450 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002451 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002452 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002453 }
Chas Williams1fa99612006-09-29 17:11:47 -07002454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Chas Williamsd0732f62006-09-29 17:14:27 -07002456 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002457 if (entry->recv_vcc == vcc) {
2458 lec_arp_clear_vccs(entry);
2459 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002460 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002461 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002462 }
Chas Williams1fa99612006-09-29 17:11:47 -07002463 }
2464
Chas Williamsd0732f62006-09-29 17:14:27 -07002465 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002466 if (entry->recv_vcc == vcc) {
2467 lec_arp_clear_vccs(entry);
2468 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002469 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002470 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002471 }
Chas Williams1fa99612006-09-29 17:11:47 -07002472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
2474 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2475 dump_arp_table(priv);
2476}
2477
2478static void
2479lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002480 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Chas Williams1fa99612006-09-29 17:11:47 -07002482 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002483 struct hlist_node *node, *next;
2484 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002485 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2486 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002488 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Chas Williams1fa99612006-09-29 17:11:47 -07002490 if (priv->is_trdev)
2491 src = tr_hdr->h_source;
2492 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002494 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
2496 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002497 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2498 if (vcc == entry->vcc) {
2499 del_timer(&entry->timer);
2500 memcpy(entry->mac_addr, src, ETH_ALEN);
2501 entry->status = ESI_FORWARD_DIRECT;
2502 entry->last_used = jiffies;
2503 /* We might have got an entry */
2504 if ((tmp = lec_arp_find(priv, src))) {
2505 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002506 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002507 }
2508 hlist_del(&entry->next);
2509 lec_arp_add(priv, entry);
2510 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002511 }
Chas Williams1fa99612006-09-29 17:11:47 -07002512 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002513 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514out:
2515 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2516}
Chas Williams1fa99612006-09-29 17:11:47 -07002517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518MODULE_LICENSE("GPL");