blob: eb94e94bffa9792c7c7eee5450aab02e09d07fc0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26
27/* TokenRing if needed */
28#ifdef CONFIG_TR
29#include <linux/trdevice.h>
30#endif
31
32/* And atm device */
33#include <linux/atmdev.h>
34#include <linux/atmlec.h>
35
36/* Proxy LEC knows about bridging */
37#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38#include <linux/if_bridge.h>
39#include "../bridge/br_private.h"
40
Chas Williamsd44f7742006-09-29 17:11:14 -070041static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43
44/* Modular too */
45#include <linux/module.h>
46#include <linux/init.h>
47
48#include "lec.h"
49#include "lec_arpc.h"
50#include "resources.h"
51
52#if 0
53#define DPRINTK printk
54#else
55#define DPRINTK(format,args...)
56#endif
57
Chas Williamsd44f7742006-09-29 17:11:14 -070058#define DUMP_PACKETS 0 /*
59 * 0 = None,
60 * 1 = 30 first bytes
61 * 2 = Whole packet
62 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Chas Williamsd44f7742006-09-29 17:11:14 -070064#define LEC_UNRES_QUE_LEN 8 /*
65 * number of tx packets to queue for a
66 * single destination while waiting for SVC
67 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static int lec_open(struct net_device *dev);
70static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
71static int lec_close(struct net_device *dev);
72static struct net_device_stats *lec_get_stats(struct net_device *dev);
73static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070074static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
75 unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070077 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/* LANE2 functions */
Chas Williamsd44f7742006-09-29 17:11:14 -070079static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
80 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070082 u8 **tlvs, u32 *sizeoftlvs);
83static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
84 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Chas Williamsd44f7742006-09-29 17:11:14 -070086static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 unsigned long permanent);
88static void lec_arp_check_empties(struct lec_priv *priv,
89 struct atm_vcc *vcc, struct sk_buff *skb);
90static void lec_arp_destroy(struct lec_priv *priv);
91static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070092static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 unsigned char *mac_to_find,
94 int is_rdesc,
95 struct lec_arp_table **ret_entry);
96static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
97 unsigned char *atm_addr, unsigned long remoteflag,
98 unsigned int targetless_le_arp);
99static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
100static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
101static void lec_set_flush_tran_id(struct lec_priv *priv,
102 unsigned char *atm_addr,
103 unsigned long tran_id);
104static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
105 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -0700106 void (*old_push) (struct atm_vcc *vcc,
107 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
109
110static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700111 lane2_resolve, /* resolve, spec 3.1.3 */
112 lane2_associate_req, /* associate_req, spec 3.1.4 */
113 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
Chas Williamsd44f7742006-09-29 17:11:14 -0700116static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/* Device structures */
119static struct net_device *dev_lec[MAX_LEC_ITF];
120
121#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
122static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
123{
Chas Williamsd44f7742006-09-29 17:11:14 -0700124 struct ethhdr *eth;
125 char *buff;
126 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Chas Williamsd44f7742006-09-29 17:11:14 -0700128 /*
129 * Check if this is a BPDU. If so, ask zeppelin to send
130 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
131 * as the Config BPDU has
132 */
133 eth = (struct ethhdr *)skb->data;
134 buff = skb->data + skb->dev->hard_header_len;
135 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700137 struct sk_buff *skb2;
138 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Chas Williamsd44f7742006-09-29 17:11:14 -0700140 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
141 if (skb2 == NULL)
142 return;
143 skb2->len = sizeof(struct atmlec_msg);
144 mesg = (struct atmlec_msg *)skb2->data;
145 mesg->type = l_topology_change;
146 buff += 4;
147 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Chas Williamsd44f7742006-09-29 17:11:14 -0700149 priv = (struct lec_priv *)dev->priv;
150 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700152 skb_queue_tail(&sk->sk_receive_queue, skb2);
153 sk->sk_data_ready(sk, skb2->len);
154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Chas Williamsd44f7742006-09-29 17:11:14 -0700156 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
159
160/*
161 * Modelled after tr_type_trans
162 * All multicast and ARE or STE frames go to BUS.
163 * Non source routed frames go by destination address.
164 * Last hop source routed frames go by destination address.
165 * Not last hop source routed frames go by _next_ route descriptor.
166 * Returns pointer to destination MAC address or fills in rdesc
167 * and returns NULL.
168 */
169#ifdef CONFIG_TR
170static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
171{
Chas Williamsd44f7742006-09-29 17:11:14 -0700172 struct trh_hdr *trh;
173 int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Chas Williamsd44f7742006-09-29 17:11:14 -0700175 trh = (struct trh_hdr *)packet;
176 if (trh->daddr[0] & (uint8_t) 0x80)
177 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Chas Williamsd44f7742006-09-29 17:11:14 -0700179 if (trh->saddr[0] & TR_RII) {
180 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
181 if ((ntohs(trh->rcf) >> 13) != 0)
182 return bus_mac; /* ARE or STE */
183 } else
184 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Chas Williamsd44f7742006-09-29 17:11:14 -0700186 if (riflen < 6)
187 return trh->daddr; /* last hop, source routed */
188
189 /* riflen is 6 or more, packet has more than one route descriptor */
190 num_rdsc = (riflen / 2) - 1;
191 memset(rdesc, 0, ETH_ALEN);
192 /* offset 4 comes from LAN destination field in LE control frames */
193 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
194 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(uint16_t));
195 else {
196 memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
197 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
198 }
199
200 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202#endif /* CONFIG_TR */
203
204/*
205 * Open/initialize the netdevice. This is called (in the current kernel)
206 * sometime after booting when the 'ifconfig' program is run.
207 *
208 * This routine should set everything up anew at each open, even
209 * registers that "should" only need to be set once at boot, so that
210 * there is non-reboot way to recover if something goes wrong.
211 */
212
Chas Williamsd44f7742006-09-29 17:11:14 -0700213static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Chas Williamsd44f7742006-09-29 17:11:14 -0700215 struct lec_priv *priv = (struct lec_priv *)dev->priv;
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700218 memset(&priv->stats, 0, sizeof(struct net_device_stats));
219
220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
223static __inline__ void
224lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
225{
226 ATM_SKB(skb)->vcc = vcc;
227 ATM_SKB(skb)->atm_options = vcc->atm_options;
228
229 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
230 if (vcc->send(vcc, skb) < 0) {
231 priv->stats.tx_dropped++;
232 return;
233 }
234
235 priv->stats.tx_packets++;
236 priv->stats.tx_bytes += skb->len;
237}
238
Chas Williamsd44f7742006-09-29 17:11:14 -0700239static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 printk(KERN_INFO "%s: tx timeout\n", dev->name);
242 dev->trans_start = jiffies;
243 netif_wake_queue(dev);
244}
245
Chas Williamsd44f7742006-09-29 17:11:14 -0700246static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Chas Williamsd44f7742006-09-29 17:11:14 -0700248 struct sk_buff *skb2;
249 struct lec_priv *priv = (struct lec_priv *)dev->priv;
250 struct lecdatahdr_8023 *lec_h;
251 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700253 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 int min_frame_size;
255#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700256 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700258 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 char buf[300];
261 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 DPRINTK("lec_start_xmit called\n");
265 if (!priv->lecd) {
266 printk("%s:No lecd attached\n", dev->name);
267 priv->stats.tx_errors++;
268 netif_stop_queue(dev);
269 return -EUNATCH;
270 }
271
272 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
273 (long)skb->head, (long)skb->data, (long)skb->tail,
274 (long)skb->end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700276 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
277 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#endif
279
Chas Williamsd44f7742006-09-29 17:11:14 -0700280 /* Make sure we have room for lec_id */
281 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Chas Williamsd44f7742006-09-29 17:11:14 -0700283 DPRINTK("lec_start_xmit: reallocating skb\n");
284 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
285 kfree_skb(skb);
286 if (skb2 == NULL)
287 return 0;
288 skb = skb2;
289 }
290 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Chas Williamsd44f7742006-09-29 17:11:14 -0700292 /* Put le header to place, works for TokenRing too */
293 lec_h = (struct lecdatahdr_8023 *)skb->data;
294 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700297 /*
298 * Ugly. Use this to realign Token Ring packets for
299 * e.g. PCA-200E driver.
300 */
301 if (priv->is_trdev) {
302 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
303 kfree_skb(skb);
304 if (skb2 == NULL)
305 return 0;
306 skb = skb2;
307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#endif
309
310#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700311 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
312 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700314 for (i = 0; i < skb->len && i < 99; i++) {
315 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700318 for (i = 0; i < skb->len && i < 30; i++) {
319 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700322 if (i == skb->len)
323 printk("%s\n", buf);
324 else
325 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#endif /* DUMP_PACKETS > 0 */
327
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700330 if (priv->is_trdev)
331 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 else
333#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 min_frame_size = LEC_MINIMUM_8023_SIZE;
335 if (skb->len < min_frame_size) {
336 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
337 skb2 = skb_copy_expand(skb, 0,
338 min_frame_size - skb->truesize,
339 GFP_ATOMIC);
340 dev_kfree_skb(skb);
341 if (skb2 == NULL) {
342 priv->stats.tx_dropped++;
343 return 0;
344 }
345 skb = skb2;
346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700348 }
349
350 /* Send to right vcc */
351 is_rdesc = 0;
352 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 if (priv->is_trdev) {
355 dst = get_tr_dst(skb->data + 2, rdesc);
356 if (dst == NULL) {
357 dst = rdesc;
358 is_rdesc = 1;
359 }
360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700362 entry = NULL;
363 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
364 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
365 vcc, vcc ? vcc->flags : 0, entry);
366 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
367 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
368 DPRINTK("%s:lec_start_xmit: queuing packet, ",
369 dev->name);
370 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
371 lec_h->h_dest[0], lec_h->h_dest[1],
372 lec_h->h_dest[2], lec_h->h_dest[3],
373 lec_h->h_dest[4], lec_h->h_dest[5]);
374 skb_queue_tail(&entry->tx_wait, skb);
375 } else {
376 DPRINTK
377 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
378 dev->name);
379 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
380 lec_h->h_dest[0], lec_h->h_dest[1],
381 lec_h->h_dest[2], lec_h->h_dest[3],
382 lec_h->h_dest[4], lec_h->h_dest[5]);
383 priv->stats.tx_dropped++;
384 dev_kfree_skb(skb);
385 }
386 return 0;
387 }
388#if DUMP_PACKETS > 0
389 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700391
392 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
393 DPRINTK("lec.c: emptying tx queue, ");
394 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
395 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
396 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 lec_send(vcc, skb, priv);
401
402 if (!atm_may_send(vcc, 0)) {
403 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
404
405 vpriv->xoff = 1;
406 netif_stop_queue(dev);
407
408 /*
409 * vcc->pop() might have occurred in between, making
410 * the vcc usuable again. Since xmit is serialized,
411 * this is the only situation we have to re-test.
412 */
413
414 if (atm_may_send(vcc, 0))
415 netif_wake_queue(dev);
416 }
417
418 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700423static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Chas Williamsd44f7742006-09-29 17:11:14 -0700425 netif_stop_queue(dev);
426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429/*
430 * Get the current statistics.
431 * This may be called with the card open or closed.
432 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700433static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Chas Williamsd44f7742006-09-29 17:11:14 -0700438static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700441 struct net_device *dev = (struct net_device *)vcc->proto_data;
442 struct lec_priv *priv = (struct lec_priv *)dev->priv;
443 struct atmlec_msg *mesg;
444 struct lec_arp_table *entry;
445 int i;
446 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700449 mesg = (struct atmlec_msg *)skb->data;
450 tmp = skb->data;
451 tmp += sizeof(struct atmlec_msg);
452 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
453 switch (mesg->type) {
454 case l_set_mac_addr:
455 for (i = 0; i < 6; i++) {
456 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
457 }
458 break;
459 case l_del_mac_addr:
460 for (i = 0; i < 6; i++) {
461 dev->dev_addr[i] = 0;
462 }
463 break;
464 case l_addr_delete:
465 lec_addr_delete(priv, mesg->content.normal.atm_addr,
466 mesg->content.normal.flag);
467 break;
468 case l_topology_change:
469 priv->topology_change = mesg->content.normal.flag;
470 break;
471 case l_flush_complete:
472 lec_flush_complete(priv, mesg->content.normal.flag);
473 break;
474 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700476 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
477 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
479
Chas Williamsd44f7742006-09-29 17:11:14 -0700480 if (mesg->content.normal.no_source_le_narp)
481 break;
482 /* FALL THROUGH */
483 case l_arp_update:
484 lec_arp_update(priv, mesg->content.normal.mac_addr,
485 mesg->content.normal.atm_addr,
486 mesg->content.normal.flag,
487 mesg->content.normal.targetless_le_arp);
488 DPRINTK("lec: in l_arp_update\n");
489 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
490 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
491 mesg->sizeoftlvs);
492 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
493 tmp, mesg->sizeoftlvs);
494 }
495 break;
496 case l_config:
497 priv->maximum_unknown_frame_count =
498 mesg->content.config.maximum_unknown_frame_count;
499 priv->max_unknown_frame_time =
500 (mesg->content.config.max_unknown_frame_time * HZ);
501 priv->max_retry_count = mesg->content.config.max_retry_count;
502 priv->aging_time = (mesg->content.config.aging_time * HZ);
503 priv->forward_delay_time =
504 (mesg->content.config.forward_delay_time * HZ);
505 priv->arp_response_time =
506 (mesg->content.config.arp_response_time * HZ);
507 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
508 priv->path_switching_delay =
509 (mesg->content.config.path_switching_delay * HZ);
510 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 priv->lane2_ops = NULL;
512 if (priv->lane_version > 1)
513 priv->lane2_ops = &lane2_ops;
514 if (dev->change_mtu(dev, mesg->content.config.mtu))
515 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700516 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700518 break;
519 case l_flush_tran_id:
520 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
521 mesg->content.normal.flag);
522 break;
523 case l_set_lecid:
524 priv->lecid =
525 (unsigned short)(0xffff & mesg->content.normal.flag);
526 break;
527 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700529 {
530 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Chas Williamsd44f7742006-09-29 17:11:14 -0700532 DPRINTK
533 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
534 dev->name, mesg->content.proxy.mac_addr[0],
535 mesg->content.proxy.mac_addr[1],
536 mesg->content.proxy.mac_addr[2],
537 mesg->content.proxy.mac_addr[3],
538 mesg->content.proxy.mac_addr[4],
539 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Chas Williamsd44f7742006-09-29 17:11:14 -0700541 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Chas Williamsd44f7742006-09-29 17:11:14 -0700544 f = br_fdb_get_hook(dev->br_port->br,
545 mesg->content.proxy.mac_addr);
546 if (f != NULL && f->dst->dev != dev
547 && f->dst->state == BR_STATE_FORWARDING) {
548 /* hit from bridge table, send LE_ARP_RESPONSE */
549 struct sk_buff *skb2;
550 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 DPRINTK
553 ("%s: entry found, responding to zeppelin\n",
554 dev->name);
555 skb2 =
556 alloc_skb(sizeof(struct atmlec_msg),
557 GFP_ATOMIC);
558 if (skb2 == NULL) {
559 br_fdb_put_hook(f);
560 break;
561 }
562 skb2->len = sizeof(struct atmlec_msg);
563 memcpy(skb2->data, mesg,
564 sizeof(struct atmlec_msg));
565 atm_force_charge(priv->lecd, skb2->truesize);
566 sk = sk_atm(priv->lecd);
567 skb_queue_tail(&sk->sk_receive_queue, skb2);
568 sk->sk_data_ready(sk, skb2->len);
569 }
570 if (f != NULL)
571 br_fdb_put_hook(f);
572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700574 break;
575 default:
576 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
577 dev_kfree_skb(skb);
578 return -EINVAL;
579 }
580 dev_kfree_skb(skb);
581 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
Chas Williamsd44f7742006-09-29 17:11:14 -0700584static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Chas Williamsd44f7742006-09-29 17:11:14 -0700586 struct sk_buff *skb;
587 struct net_device *dev = (struct net_device *)vcc->proto_data;
588 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Chas Williamsd44f7742006-09-29 17:11:14 -0700590 priv->lecd = NULL;
591 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Chas Williamsd44f7742006-09-29 17:11:14 -0700593 netif_stop_queue(dev);
594 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Chas Williamsd44f7742006-09-29 17:11:14 -0700596 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700598 dev->name);
599 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
600 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700602 }
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
608static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 .close = lec_atm_close,
610 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611};
612
613static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700614 .ops = &lecdev_ops,
615 .type = "lec",
616 .number = 999, /* dummy device number */
617 .lock = SPIN_LOCK_UNLOCKED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618};
619
620/*
621 * LANE2: new argument struct sk_buff *data contains
622 * the LE_ARP based TLVs introduced in the LANE2 spec
623 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700624static int
625send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
626 unsigned char *mac_addr, unsigned char *atm_addr,
627 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
629 struct sock *sk;
630 struct sk_buff *skb;
631 struct atmlec_msg *mesg;
632
633 if (!priv || !priv->lecd) {
634 return -1;
635 }
636 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
637 if (!skb)
638 return -1;
639 skb->len = sizeof(struct atmlec_msg);
640 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700641 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700643 if (data != NULL)
644 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (mac_addr)
646 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700647 else
648 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (atm_addr)
650 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
651
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 sk = sk_atm(priv->lecd);
654 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700655 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Chas Williamsd44f7742006-09-29 17:11:14 -0700657 if (data != NULL) {
658 DPRINTK("lec: about to send %d bytes of data\n", data->len);
659 atm_force_charge(priv->lecd, data->truesize);
660 skb_queue_tail(&sk->sk_receive_queue, data);
661 sk->sk_data_ready(sk, skb->len);
662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Chas Williamsd44f7742006-09-29 17:11:14 -0700664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
667/* shamelessly stolen from drivers/net/net_init.c */
668static int lec_change_mtu(struct net_device *dev, int new_mtu)
669{
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 if ((new_mtu < 68) || (new_mtu > 18190))
671 return -EINVAL;
672 dev->mtu = new_mtu;
673 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676static void lec_set_multicast_list(struct net_device *dev)
677{
Chas Williamsd44f7742006-09-29 17:11:14 -0700678 /*
679 * by default, all multicast frames arrive over the bus.
680 * eventually support selective multicast service
681 */
682 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Chas Williamsd44f7742006-09-29 17:11:14 -0700685static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Chas Williamsd44f7742006-09-29 17:11:14 -0700687 dev->change_mtu = lec_change_mtu;
688 dev->open = lec_open;
689 dev->stop = lec_close;
690 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 dev->tx_timeout = lec_tx_timeout;
692
Chas Williamsd44f7742006-09-29 17:11:14 -0700693 dev->get_stats = lec_get_stats;
694 dev->set_multicast_list = lec_set_multicast_list;
695 dev->do_ioctl = NULL;
696 printk("%s: Initialized!\n", dev->name);
697 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
700static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700701 0xff,
702 0x00,
703 0x01,
704 0x01
705};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Scott Talbert4a7097f2005-09-29 17:30:54 -0700707#define LEC_DATA_DIRECT_8023 2
708#define LEC_DATA_DIRECT_8025 3
709
710static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700711{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700712 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
713 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700714}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700715
Chas Williamsd44f7742006-09-29 17:11:14 -0700716static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700718 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700719 struct net_device *dev = (struct net_device *)vcc->proto_data;
720 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 int i = 0;
724 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Chas Williamsd44f7742006-09-29 17:11:14 -0700726 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
727 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 if (!skb) {
730 DPRINTK("%s: null skb\n", dev->name);
731 lec_vcc_close(priv, vcc);
732 return;
733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
736 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 for (i = 0; i < skb->len && i < 99; i++) {
739 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700742 for (i = 0; i < skb->len && i < 30; i++) {
743 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700746 if (i == skb->len)
747 printk("%s\n", buf);
748 else
749 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700751 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct sock *sk = sk_atm(vcc);
753
Chas Williamsd44f7742006-09-29 17:11:14 -0700754 DPRINTK("%s: To daemon\n", dev->name);
755 skb_queue_tail(&sk->sk_receive_queue, skb);
756 sk->sk_data_ready(sk, skb->len);
757 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700758 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700759 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Chas Williamsd44f7742006-09-29 17:11:14 -0700761 atm_return(vcc, skb->truesize);
762 if (*(uint16_t *) skb->data == htons(priv->lecid) ||
763 !priv->lecd || !(dev->flags & IFF_UP)) {
764 /*
765 * Probably looping back, or if lecd is missing,
766 * lecd has gone down
767 */
768 DPRINTK("Ignoring frame...\n");
769 dev_kfree_skb(skb);
770 return;
771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 if (priv->is_trdev)
774 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
775 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700777 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700778
Chas Williamsd44f7742006-09-29 17:11:14 -0700779 /*
780 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700781 * the LE_ARP cache entry, delete the LE_ARP cache entry.
782 */
783 spin_lock_irqsave(&priv->lec_arp_lock, flags);
784 if (lec_is_data_direct(vcc)) {
785#ifdef CONFIG_TR
786 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700787 src =
788 ((struct lecdatahdr_8025 *)skb->data)->
789 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700790 else
791#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700792 src =
793 ((struct lecdatahdr_8023 *)skb->data)->
794 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700795 entry = lec_arp_find(priv, src);
796 if (entry && entry->vcc != vcc) {
797 lec_arp_remove(priv, entry);
798 kfree(entry);
799 }
800 }
801 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Chas Williamsd44f7742006-09-29 17:11:14 -0700803 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
804 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700806 dev_kfree_skb(skb);
807 return;
808 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700809 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700810 lec_arp_check_empties(priv, vcc, skb);
811 }
812 skb->dev = dev;
813 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700815 if (priv->is_trdev)
816 skb->protocol = tr_type_trans(skb, dev);
817 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700819 skb->protocol = eth_type_trans(skb, dev);
820 priv->stats.rx_packets++;
821 priv->stats.rx_bytes += skb->len;
822 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
823 netif_rx(skb);
824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Chas Williamsd44f7742006-09-29 17:11:14 -0700827static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
829 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
830 struct net_device *dev = skb->dev;
831
832 if (vpriv == NULL) {
833 printk("lec_pop(): vpriv = NULL!?!?!?\n");
834 return;
835 }
836
837 vpriv->old_pop(vcc, skb);
838
839 if (vpriv->xoff && atm_may_send(vcc, 0)) {
840 vpriv->xoff = 0;
841 if (netif_running(dev) && netif_queue_stopped(dev))
842 netif_wake_queue(dev);
843 }
844}
845
Chas Williamsd44f7742006-09-29 17:11:14 -0700846static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700849 int bytes_left;
850 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Chas Williamsd44f7742006-09-29 17:11:14 -0700852 /* Lecd must be up in this case */
853 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
854 if (bytes_left != 0) {
855 printk
856 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
857 bytes_left);
858 }
859 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
860 !dev_lec[ioc_data.dev_num])
861 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
863 return -ENOMEM;
864 vpriv->xoff = 0;
865 vpriv->old_pop = vcc->pop;
866 vcc->user_back = vpriv;
867 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700868 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
869 &ioc_data, vcc, vcc->push);
870 vcc->proto_data = dev_lec[ioc_data.dev_num];
871 vcc->push = lec_push;
872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
Chas Williamsd44f7742006-09-29 17:11:14 -0700875static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Chas Williamsd44f7742006-09-29 17:11:14 -0700877 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
878 return -EINVAL;
879 vcc->proto_data = dev_lec[arg];
880 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700884static int lecd_attach(struct atm_vcc *vcc, int arg)
885{
886 int i;
887 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Chas Williamsd44f7742006-09-29 17:11:14 -0700889 if (arg < 0)
890 i = 0;
891 else
892 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700894 if (arg >= MAX_LEC_ITF)
895 return -EINVAL;
896#else /* Reserve the top NUM_TR_DEVS for TR */
897 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
898 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700900 if (!dev_lec[i]) {
901 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Chas Williamsd44f7742006-09-29 17:11:14 -0700903 is_trdev = 0;
904 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
905 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Chas Williamsd44f7742006-09-29 17:11:14 -0700907 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700909 if (is_trdev)
910 dev_lec[i] = alloc_trdev(size);
911 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700913 dev_lec[i] = alloc_etherdev(size);
914 if (!dev_lec[i])
915 return -ENOMEM;
916 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
917 if (register_netdev(dev_lec[i])) {
918 free_netdev(dev_lec[i]);
919 return -EINVAL;
920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Chas Williamsd44f7742006-09-29 17:11:14 -0700922 priv = dev_lec[i]->priv;
923 priv->is_trdev = is_trdev;
924 lec_init(dev_lec[i]);
925 } else {
926 priv = dev_lec[i]->priv;
927 if (priv->lecd)
928 return -EADDRINUSE;
929 }
930 lec_arp_init(priv);
931 priv->itfnum = i; /* LANE2 addition */
932 priv->lecd = vcc;
933 vcc->dev = &lecatm_dev;
934 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Chas Williamsd44f7742006-09-29 17:11:14 -0700936 vcc->proto_data = dev_lec[i];
937 set_bit(ATM_VF_META, &vcc->flags);
938 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Chas Williamsd44f7742006-09-29 17:11:14 -0700940 /* Set default values to these variables */
941 priv->maximum_unknown_frame_count = 1;
942 priv->max_unknown_frame_time = (1 * HZ);
943 priv->vcc_timeout_period = (1200 * HZ);
944 priv->max_retry_count = 1;
945 priv->aging_time = (300 * HZ);
946 priv->forward_delay_time = (15 * HZ);
947 priv->topology_change = 0;
948 priv->arp_response_time = (1 * HZ);
949 priv->flush_timeout = (4 * HZ);
950 priv->path_switching_delay = (6 * HZ);
951
952 if (dev_lec[i]->flags & IFF_UP) {
953 netif_start_queue(dev_lec[i]);
954 }
955 __module_get(THIS_MODULE);
956 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957}
958
959#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700960static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
962 static char *lec_arp_status_string[] = {
963 "ESI_UNKNOWN ",
964 "ESI_ARP_PENDING ",
965 "ESI_VC_PENDING ",
966 "<Undefined> ",
967 "ESI_FLUSH_PENDING ",
968 "ESI_FORWARD_DIRECT"
969 };
970
971 if (status > ESI_FORWARD_DIRECT)
972 status = 3; /* ESI_UNDEFINED */
973 return lec_arp_status_string[status];
974}
975
976static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
977{
978 int i;
979
980 for (i = 0; i < ETH_ALEN; i++)
981 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
982 seq_printf(seq, " ");
983 for (i = 0; i < ATM_ESA_LEN; i++)
984 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
985 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
986 entry->flags & 0xffff);
987 if (entry->vcc)
988 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
989 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700990 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (entry->recv_vcc) {
992 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
993 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700994 }
995 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998struct lec_state {
999 unsigned long flags;
1000 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001001 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 struct net_device *dev;
1003 int itf;
1004 int arp_table;
1005 int misc_table;
1006};
1007
Chas Williamsd0732f62006-09-29 17:14:27 -07001008static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 loff_t *l)
1010{
Chas Williamsd0732f62006-09-29 17:14:27 -07001011 struct hlist_node *e = state->node;
1012 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001015 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001017 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 --*l;
1019 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001020
1021 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (--*l < 0)
1023 break;
1024 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001025 state->node = e;
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return (*l < 0) ? state : NULL;
1028}
1029
1030static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001031 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 void *v = NULL;
1034 int p;
1035
1036 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001037 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (v)
1039 break;
1040 }
1041 state->arp_table = p;
1042 return v;
1043}
1044
1045static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1046 struct lec_priv *priv)
1047{
Chas Williamsd0732f62006-09-29 17:14:27 -07001048 struct hlist_head *lec_misc_tables[] = {
1049 &priv->lec_arp_empty_ones,
1050 &priv->lec_no_forward,
1051 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 };
1053 void *v = NULL;
1054 int q;
1055
1056 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1057 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1058 if (v)
1059 break;
1060 }
1061 state->misc_table = q;
1062 return v;
1063}
1064
1065static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1066 struct lec_priv *priv)
1067{
1068 if (!state->locked) {
1069 state->locked = priv;
1070 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1071 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001072 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1074 state->locked = NULL;
1075 /* Partial state reset for the next time we get called */
1076 state->arp_table = state->misc_table = 0;
1077 }
1078 return state->locked;
1079}
1080
1081static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1082{
1083 struct net_device *dev;
1084 void *v;
1085
1086 dev = state->dev ? state->dev : dev_lec[state->itf];
1087 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1088 if (!v && dev) {
1089 dev_put(dev);
1090 /* Partial state reset for the next time we get called */
1091 dev = NULL;
1092 }
1093 state->dev = dev;
1094 return v;
1095}
1096
1097static void *lec_get_idx(struct lec_state *state, loff_t l)
1098{
1099 void *v = NULL;
1100
1101 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1102 v = lec_itf_walk(state, &l);
1103 if (v)
1104 break;
1105 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001106 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
1109static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1110{
1111 struct lec_state *state = seq->private;
1112
1113 state->itf = 0;
1114 state->dev = NULL;
1115 state->locked = NULL;
1116 state->arp_table = 0;
1117 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001118 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Chas Williamsd44f7742006-09-29 17:11:14 -07001120 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
1123static void lec_seq_stop(struct seq_file *seq, void *v)
1124{
1125 struct lec_state *state = seq->private;
1126
1127 if (state->dev) {
1128 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1129 state->flags);
1130 dev_put(state->dev);
1131 }
1132}
1133
1134static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1135{
1136 struct lec_state *state = seq->private;
1137
1138 v = lec_get_idx(state, 1);
1139 *pos += !!PTR_ERR(v);
1140 return v;
1141}
1142
1143static int lec_seq_show(struct seq_file *seq, void *v)
1144{
Chas Williamsd44f7742006-09-29 17:11:14 -07001145 static char lec_banner[] = "Itf MAC ATM destination"
1146 " Status Flags "
1147 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 if (v == (void *)1)
1150 seq_puts(seq, lec_banner);
1151 else {
1152 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001153 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001154 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001157 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
1159 return 0;
1160}
1161
1162static struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001163 .start = lec_seq_start,
1164 .next = lec_seq_next,
1165 .stop = lec_seq_stop,
1166 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167};
1168
1169static int lec_seq_open(struct inode *inode, struct file *file)
1170{
1171 struct lec_state *state;
1172 struct seq_file *seq;
1173 int rc = -EAGAIN;
1174
1175 state = kmalloc(sizeof(*state), GFP_KERNEL);
1176 if (!state) {
1177 rc = -ENOMEM;
1178 goto out;
1179 }
1180
1181 rc = seq_open(file, &lec_seq_ops);
1182 if (rc)
1183 goto out_kfree;
1184 seq = file->private_data;
1185 seq->private = state;
1186out:
1187 return rc;
1188
1189out_kfree:
1190 kfree(state);
1191 goto out;
1192}
1193
1194static int lec_seq_release(struct inode *inode, struct file *file)
1195{
1196 return seq_release_private(inode, file);
1197}
1198
1199static struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001200 .owner = THIS_MODULE,
1201 .open = lec_seq_open,
1202 .read = seq_read,
1203 .llseek = seq_lseek,
1204 .release = lec_seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205};
1206#endif
1207
1208static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1209{
1210 struct atm_vcc *vcc = ATM_SD(sock);
1211 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001212
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001214 case ATMLEC_CTRL:
1215 case ATMLEC_MCAST:
1216 case ATMLEC_DATA:
1217 if (!capable(CAP_NET_ADMIN))
1218 return -EPERM;
1219 break;
1220 default:
1221 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001225 case ATMLEC_CTRL:
1226 err = lecd_attach(vcc, (int)arg);
1227 if (err >= 0)
1228 sock->state = SS_CONNECTED;
1229 break;
1230 case ATMLEC_MCAST:
1231 err = lec_mcast_attach(vcc, (int)arg);
1232 break;
1233 case ATMLEC_DATA:
1234 err = lec_vcc_attach(vcc, (void __user *)arg);
1235 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237
1238 return err;
1239}
1240
1241static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001242 .owner = THIS_MODULE,
1243 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244};
1245
1246static int __init lane_module_init(void)
1247{
1248#ifdef CONFIG_PROC_FS
1249 struct proc_dir_entry *p;
1250
1251 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1252 if (p)
1253 p->proc_fops = &lec_seq_fops;
1254#endif
1255
1256 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001257 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1258 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
1261static void __exit lane_module_cleanup(void)
1262{
Chas Williamsd44f7742006-09-29 17:11:14 -07001263 int i;
1264 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 remove_proc_entry("lec", atm_proc_root);
1267
1268 deregister_atm_ioctl(&lane_ioctl_ops);
1269
Chas Williamsd44f7742006-09-29 17:11:14 -07001270 for (i = 0; i < MAX_LEC_ITF; i++) {
1271 if (dev_lec[i] != NULL) {
1272 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001274 free_netdev(dev_lec[i]);
1275 dev_lec[i] = NULL;
1276 }
1277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Chas Williamsd44f7742006-09-29 17:11:14 -07001279 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
1281
1282module_init(lane_module_init);
1283module_exit(lane_module_cleanup);
1284
1285/*
1286 * LANE2: 3.1.3, LE_RESOLVE.request
1287 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1288 * If sizeoftlvs == NULL the default TLVs associated with with this
1289 * lec will be used.
1290 * If dst_mac == NULL, targetless LE_ARP will be sent
1291 */
1292static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001293 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
1295 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001296 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1297 struct lec_arp_table *table;
1298 struct sk_buff *skb;
1299 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Chas Williamsd44f7742006-09-29 17:11:14 -07001301 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001303 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001305 if (table == NULL)
1306 return -1;
1307
1308 *tlvs = kmalloc(table->sizeoftlvs, GFP_ATOMIC);
1309 if (*tlvs == NULL)
1310 return -1;
1311
1312 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
1313 *sizeoftlvs = table->sizeoftlvs;
1314
1315 return 0;
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 if (sizeoftlvs == NULL)
1319 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 else {
1322 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1323 if (skb == NULL)
1324 return -1;
1325 skb->len = *sizeoftlvs;
1326 memcpy(skb->data, *tlvs, *sizeoftlvs);
1327 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1328 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001329 return retval;
1330}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332/*
1333 * LANE2: 3.1.4, LE_ASSOCIATE.request
1334 * Associate the *tlvs with the *lan_dst address.
1335 * Will overwrite any previous association
1336 * Returns 1 for success, 0 for failure (out of memory)
1337 *
1338 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001339static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1340 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Chas Williamsd44f7742006-09-29 17:11:14 -07001342 int retval;
1343 struct sk_buff *skb;
1344 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Chas Williamsd44f7742006-09-29 17:11:14 -07001346 if (compare_ether_addr(lan_dst, dev->dev_addr))
1347 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Chas Williamsd44f7742006-09-29 17:11:14 -07001349 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Chas Williamsd44f7742006-09-29 17:11:14 -07001351 priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1352 if (priv->tlvs == NULL)
1353 return (0);
1354 priv->sizeoftlvs = sizeoftlvs;
1355 memcpy(priv->tlvs, tlvs, sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Chas Williamsd44f7742006-09-29 17:11:14 -07001357 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1358 if (skb == NULL)
1359 return 0;
1360 skb->len = sizeoftlvs;
1361 memcpy(skb->data, tlvs, sizeoftlvs);
1362 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1363 if (retval != 0)
1364 printk("lec.c: lane2_associate_req() failed\n");
1365 /*
1366 * If the previous association has changed we must
1367 * somehow notify other LANE entities about the change
1368 */
1369 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
1372/*
1373 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1374 *
1375 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001376static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1377 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001380 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381#endif
1382 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001383#if 0 /*
1384 * Why have the TLVs in LE_ARP entries
1385 * since we do not use them? When you
1386 * uncomment this code, make sure the
1387 * TLVs get freed when entry is killed
1388 */
1389 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Chas Williamsd44f7742006-09-29 17:11:14 -07001391 if (entry == NULL)
1392 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Chas Williamsd44f7742006-09-29 17:11:14 -07001394 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Chas Williamsd44f7742006-09-29 17:11:14 -07001396 entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1397 if (entry->tlvs == NULL)
1398 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Chas Williamsd44f7742006-09-29 17:11:14 -07001400 entry->sizeoftlvs = sizeoftlvs;
1401 memcpy(entry->tlvs, tlvs, sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402#endif
1403#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001404 printk("lec.c: lane2_associate_ind()\n");
1405 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1406 while (i < sizeoftlvs)
1407 printk("%02x ", tlvs[i++]);
1408
1409 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410#endif
1411
Chas Williamsd44f7742006-09-29 17:11:14 -07001412 /* tell MPOA about the TLVs we saw */
1413 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1414 priv->lane2_ops->associate_indicator(dev, mac_addr,
1415 tlvs, sizeoftlvs);
1416 }
1417 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418}
1419
1420/*
1421 * Here starts what used to lec_arpc.c
1422 *
1423 * lec_arpc.c was added here when making
1424 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 */
1426
1427#include <linux/types.h>
1428#include <linux/sched.h>
1429#include <linux/timer.h>
1430#include <asm/param.h>
1431#include <asm/atomic.h>
1432#include <linux/inetdevice.h>
1433#include <net/route.h>
1434
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435#if 0
1436#define DPRINTK(format,args...)
1437/*
1438#define DPRINTK printk
1439*/
1440#endif
1441#define DEBUG_ARP_TABLE 0
1442
1443#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1444
1445static void lec_arp_check_expire(unsigned long data);
1446static void lec_arp_expire_arp(unsigned long data);
1447
1448/*
1449 * Arp table funcs
1450 */
1451
1452#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1453
1454/*
1455 * Initialization of arp-cache
1456 */
Chas Williams1fa99612006-09-29 17:11:47 -07001457static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Chas Williams1fa99612006-09-29 17:11:47 -07001459 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Chas Williams1fa99612006-09-29 17:11:47 -07001461 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001462 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001463 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001464 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1465 INIT_HLIST_HEAD(&priv->lec_no_forward);
1466 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 spin_lock_init(&priv->lec_arp_lock);
Chas Williams1fa99612006-09-29 17:11:47 -07001468 init_timer(&priv->lec_arp_timer);
1469 priv->lec_arp_timer.expires = jiffies + LEC_ARP_REFRESH_INTERVAL;
1470 priv->lec_arp_timer.data = (unsigned long)priv;
1471 priv->lec_arp_timer.function = lec_arp_check_expire;
1472 add_timer(&priv->lec_arp_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Chas Williams1fa99612006-09-29 17:11:47 -07001475static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Chas Williams1fa99612006-09-29 17:11:47 -07001477 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 struct atm_vcc *vcc = entry->vcc;
1479 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001480 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Chas Williams1fa99612006-09-29 17:11:47 -07001482 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 if (vpriv->xoff)
1484 netif_wake_queue(dev);
1485 kfree(vpriv);
1486 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001487 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001489 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001490 }
1491 if (entry->recv_vcc) {
1492 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001494 entry->recv_vcc = NULL;
1495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
1497
1498/*
1499 * Insert entry to lec_arp_table
1500 * LANE2: Add to the end of the list to satisfy 8.1.13
1501 */
Chas Williams1fa99612006-09-29 17:11:47 -07001502static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001503lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Chas Williamsd0732f62006-09-29 17:14:27 -07001505 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Chas Williamsd0732f62006-09-29 17:14:27 -07001507 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1508 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001509
1510 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 -07001511 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1512 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1513 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514}
1515
1516/*
1517 * Remove entry from lec_arp_table
1518 */
Chas Williams1fa99612006-09-29 17:11:47 -07001519static int
1520lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Chas Williamsd0732f62006-09-29 17:14:27 -07001522 struct hlist_node *node;
1523 struct lec_arp_table *entry;
1524 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Chas Williams1fa99612006-09-29 17:11:47 -07001526 if (!to_remove) {
1527 return -1;
1528 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001529
1530 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001531 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Chas Williamsd0732f62006-09-29 17:14:27 -07001533 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001534 if (to_remove->status >= ESI_FLUSH_PENDING) {
1535 /*
1536 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1537 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001538 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1539 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1540 if (memcmp(to_remove->atm_addr,
1541 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001542 remove_vcc = 0;
1543 break;
1544 }
1545 }
1546 }
1547 if (remove_vcc)
1548 lec_arp_clear_vccs(to_remove);
1549 }
1550 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1551
1552 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1553 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1554 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1555 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
1559#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001560static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Chas Williams1fa99612006-09-29 17:11:47 -07001562 switch (st) {
1563 case ESI_UNKNOWN:
1564 return "ESI_UNKNOWN";
1565 case ESI_ARP_PENDING:
1566 return "ESI_ARP_PENDING";
1567 case ESI_VC_PENDING:
1568 return "ESI_VC_PENDING";
1569 case ESI_FLUSH_PENDING:
1570 return "ESI_FLUSH_PENDING";
1571 case ESI_FORWARD_DIRECT:
1572 return "ESI_FORWARD_DIRECT";
1573 default:
1574 return "<UNKNOWN>";
1575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Chas Williams1fa99612006-09-29 17:11:47 -07001578static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Chas Williamsd0732f62006-09-29 17:14:27 -07001580 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001581 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001582 char buf[256];
1583 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Chas Williams1fa99612006-09-29 17:11:47 -07001585 printk("Dump %p:\n", priv);
1586 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001587 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1588 offset = 0;
1589 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001590 offset += sprintf(buf + offset, "Mac:");
1591 for (j = 0; j < ETH_ALEN; j++) {
1592 offset += sprintf(buf + offset,
1593 "%2.2x ",
1594 rulla->mac_addr[j] & 0xff);
1595 }
1596 offset += sprintf(buf + offset, "Atm:");
1597 for (j = 0; j < ATM_ESA_LEN; j++) {
1598 offset += sprintf(buf + offset,
1599 "%2.2x ",
1600 rulla->atm_addr[j] & 0xff);
1601 }
1602 offset += sprintf(buf + offset,
1603 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1604 rulla->vcc ? rulla->vcc->vpi : 0,
1605 rulla->vcc ? rulla->vcc->vci : 0,
1606 rulla->recv_vcc ? rulla->recv_vcc->
1607 vpi : 0,
1608 rulla->recv_vcc ? rulla->recv_vcc->
1609 vci : 0, rulla->last_used,
1610 rulla->timestamp, rulla->no_tries);
1611 offset +=
1612 sprintf(buf + offset,
1613 "Flags:%x, Packets_flooded:%x, Status: %s ",
1614 rulla->flags, rulla->packets_flooded,
1615 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001616 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001617 }
Chas Williams1fa99612006-09-29 17:11:47 -07001618 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001619
1620 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001621 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001622 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001623 offset = 0;
1624 offset += sprintf(buf + offset, "Mac:");
1625 for (j = 0; j < ETH_ALEN; j++) {
1626 offset += sprintf(buf + offset, "%2.2x ",
1627 rulla->mac_addr[j] & 0xff);
1628 }
1629 offset += sprintf(buf + offset, "Atm:");
1630 for (j = 0; j < ATM_ESA_LEN; j++) {
1631 offset += sprintf(buf + offset, "%2.2x ",
1632 rulla->atm_addr[j] & 0xff);
1633 }
1634 offset += sprintf(buf + offset,
1635 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1636 rulla->vcc ? rulla->vcc->vpi : 0,
1637 rulla->vcc ? rulla->vcc->vci : 0,
1638 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1639 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1640 rulla->last_used,
1641 rulla->timestamp, rulla->no_tries);
1642 offset += sprintf(buf + offset,
1643 "Flags:%x, Packets_flooded:%x, Status: %s ",
1644 rulla->flags, rulla->packets_flooded,
1645 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001646 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001647 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001648
1649 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001650 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001651 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001652 offset = 0;
1653 offset += sprintf(buf + offset, "Mac:");
1654 for (j = 0; j < ETH_ALEN; j++) {
1655 offset += sprintf(buf + offset, "%2.2x ",
1656 rulla->mac_addr[j] & 0xff);
1657 }
1658 offset += sprintf(buf + offset, "Atm:");
1659 for (j = 0; j < ATM_ESA_LEN; j++) {
1660 offset += sprintf(buf + offset, "%2.2x ",
1661 rulla->atm_addr[j] & 0xff);
1662 }
1663 offset += sprintf(buf + offset,
1664 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1665 rulla->vcc ? rulla->vcc->vpi : 0,
1666 rulla->vcc ? rulla->vcc->vci : 0,
1667 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1668 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1669 rulla->last_used,
1670 rulla->timestamp, rulla->no_tries);
1671 offset += sprintf(buf + offset,
1672 "Flags:%x, Packets_flooded:%x, Status: %s ",
1673 rulla->flags, rulla->packets_flooded,
1674 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001675 printk("%s", buf);
1676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Chas Williamsd0732f62006-09-29 17:14:27 -07001678 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001679 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001680 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001681 offset = 0;
1682 offset += sprintf(buf + offset, "Mac:");
1683 for (j = 0; j < ETH_ALEN; j++) {
1684 offset += sprintf(buf + offset, "%2.2x ",
1685 rulla->mac_addr[j] & 0xff);
1686 }
1687 offset += sprintf(buf + offset, "Atm:");
1688 for (j = 0; j < ATM_ESA_LEN; j++) {
1689 offset += sprintf(buf + offset, "%2.2x ",
1690 rulla->atm_addr[j] & 0xff);
1691 }
1692 offset += sprintf(buf + offset,
1693 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1694 rulla->vcc ? rulla->vcc->vpi : 0,
1695 rulla->vcc ? rulla->vcc->vci : 0,
1696 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1697 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1698 rulla->last_used,
1699 rulla->timestamp, rulla->no_tries);
1700 offset += sprintf(buf + offset,
1701 "Flags:%x, Packets_flooded:%x, Status: %s ",
1702 rulla->flags, rulla->packets_flooded,
1703 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001704 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707}
Chas Williamsd0732f62006-09-29 17:14:27 -07001708#else
1709#define dump_arp_table(priv) do { } while (0)
1710#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712/*
1713 * Destruction of arp-cache
1714 */
Chas Williams1fa99612006-09-29 17:11:47 -07001715static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001718 struct hlist_node *node, *next;
1719 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001720 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Chas Williams1fa99612006-09-29 17:11:47 -07001722 del_timer_sync(&priv->lec_arp_timer);
1723
1724 /*
1725 * Remove all entries
1726 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001729 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001730 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001731 lec_arp_remove(priv, entry);
1732 kfree(entry);
1733 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001735 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001736
1737 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001738 del_timer_sync(&entry->timer);
1739 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001741 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001742 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001743 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1744
1745 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001746 del_timer_sync(&entry->timer);
1747 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001748 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001749 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001750 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001751 INIT_HLIST_HEAD(&priv->lec_no_forward);
1752
1753 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001754 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1755 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001756 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001757 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001758 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001759 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001760 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1762}
1763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764/*
1765 * Find entry by mac_address
1766 */
Chas Williams1fa99612006-09-29 17:11:47 -07001767static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1768 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Chas Williamsd0732f62006-09-29 17:14:27 -07001770 struct hlist_node *node;
1771 struct hlist_head *head;
1772 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Chas Williams1fa99612006-09-29 17:11:47 -07001774 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1775 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1776 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001777
Chas Williamsd0732f62006-09-29 17:14:27 -07001778 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1779 hlist_for_each_entry(entry, node, head, next) {
1780 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1781 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001782 }
Chas Williams1fa99612006-09-29 17:11:47 -07001783 }
1784 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}
1786
Chas Williams1fa99612006-09-29 17:11:47 -07001787static struct lec_arp_table *make_entry(struct lec_priv *priv,
1788 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
Chas Williams1fa99612006-09-29 17:11:47 -07001790 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Chas Williams1fa99612006-09-29 17:11:47 -07001792 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1793 if (!to_return) {
1794 printk("LEC: Arp entry kmalloc failed\n");
1795 return NULL;
1796 }
1797 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001798 INIT_HLIST_NODE(&to_return->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001799 init_timer(&to_return->timer);
1800 to_return->timer.function = lec_arp_expire_arp;
1801 to_return->timer.data = (unsigned long)to_return;
1802 to_return->last_used = jiffies;
1803 to_return->priv = priv;
1804 skb_queue_head_init(&to_return->tx_wait);
1805 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
Chas Williams1fa99612006-09-29 17:11:47 -07001808/* Arp sent timer expired */
1809static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
Chas Williams1fa99612006-09-29 17:11:47 -07001811 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Chas Williams1fa99612006-09-29 17:11:47 -07001813 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Chas Williams1fa99612006-09-29 17:11:47 -07001815 DPRINTK("lec_arp_expire_arp\n");
1816 if (entry->status == ESI_ARP_PENDING) {
1817 if (entry->no_tries <= entry->priv->max_retry_count) {
1818 if (entry->is_rdesc)
1819 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1820 entry->mac_addr, NULL, NULL);
1821 else
1822 send_to_lecd(entry->priv, l_arp_xmt,
1823 entry->mac_addr, NULL, NULL);
1824 entry->no_tries++;
1825 }
1826 mod_timer(&entry->timer, jiffies + (1 * HZ));
1827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
Chas Williams1fa99612006-09-29 17:11:47 -07001830/* Unknown/unused vcc expire, remove associated entry */
1831static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
1833 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001834 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1835 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Chas Williams1fa99612006-09-29 17:11:47 -07001837 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
Chas Williams1fa99612006-09-29 17:11:47 -07001839 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1840 to_remove, priv,
1841 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1842 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001845 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1847
Chas Williams1fa99612006-09-29 17:11:47 -07001848 lec_arp_clear_vccs(to_remove);
1849 kfree(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850}
1851
1852/*
1853 * Expire entries.
1854 * 1. Re-set timer
1855 * 2. For each entry, delete entries that have aged past the age limit.
1856 * 3. For each entry, depending on the status of the entry, perform
1857 * the following maintenance.
1858 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1859 * tick_count is above the max_unknown_frame_time, clear
1860 * the tick_count to zero and clear the packets_flooded counter
1861 * to zero. This supports the packet rate limit per address
1862 * while flooding unknowns.
1863 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1864 * than or equal to the path_switching_delay, change the status
1865 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1866 * regardless of the progress of the flush protocol.
1867 */
Chas Williams1fa99612006-09-29 17:11:47 -07001868static void lec_arp_check_expire(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001871 struct lec_priv *priv = (struct lec_priv *)data;
Chas Williamsd0732f62006-09-29 17:14:27 -07001872 struct hlist_node *node, *next;
1873 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001874 unsigned long now;
1875 unsigned long time_to_check;
1876 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Chas Williams1fa99612006-09-29 17:11:47 -07001878 DPRINTK("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 now = jiffies;
1880 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001881 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001882 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001883 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 priv->topology_change)
1885 time_to_check = priv->forward_delay_time;
1886 else
1887 time_to_check = priv->aging_time;
1888
1889 DPRINTK("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001890 now, entry->last_used, time_to_check);
1891 if (time_after(now, entry->last_used + time_to_check)
1892 && !(entry->flags & LEC_PERMANENT_FLAG)
1893 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 /* Remove entry */
1895 DPRINTK("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 lec_arp_remove(priv, entry);
1897 kfree(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 } else {
1899 /* Something else */
1900 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001901 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001903 entry->timestamp +
1904 priv->
1905 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 entry->timestamp = jiffies;
1907 entry->packets_flooded = 0;
1908 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001909 send_to_lecd(priv, l_svc_setup,
1910 entry->mac_addr,
1911 entry->atm_addr,
1912 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 }
Chas Williams1fa99612006-09-29 17:11:47 -07001914 if (entry->status == ESI_FLUSH_PENDING
1915 &&
1916 time_after_eq(now, entry->timestamp +
1917 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 struct sk_buff *skb;
1919
Chas Williams1fa99612006-09-29 17:11:47 -07001920 while ((skb =
1921 skb_dequeue(&entry->tx_wait)) !=
1922 NULL)
1923 lec_send(entry->vcc, skb,
1924 entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001926 entry->status = ESI_FORWARD_DIRECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
1929 }
1930 }
1931 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1932
Chas Williams1fa99612006-09-29 17:11:47 -07001933 mod_timer(&priv->lec_arp_timer, jiffies + LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934}
Chas Williams1fa99612006-09-29 17:11:47 -07001935
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936/*
1937 * Try to find vcc where mac_address is attached.
1938 *
1939 */
Chas Williams1fa99612006-09-29 17:11:47 -07001940static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1941 unsigned char *mac_to_find, int is_rdesc,
1942 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
1944 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001945 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 struct atm_vcc *found;
1947
Chas Williams1fa99612006-09-29 17:11:47 -07001948 if (mac_to_find[0] & 0x01) {
1949 switch (priv->lane_version) {
1950 case 1:
1951 return priv->mcast_vcc;
1952 break;
1953 case 2: /* LANE2 wants arp for multicast addresses */
1954 if (!compare_ether_addr(mac_to_find, bus_mac))
1955 return priv->mcast_vcc;
1956 break;
1957 default:
1958 break;
1959 }
1960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001963 entry = lec_arp_find(priv, mac_to_find);
1964
1965 if (entry) {
1966 if (entry->status == ESI_FORWARD_DIRECT) {
1967 /* Connection Ok */
1968 entry->last_used = jiffies;
1969 *ret_entry = entry;
1970 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001972 }
1973 /*
1974 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001975 * so another LE_ARP request can be made for this frame.
1976 */
1977 if (entry->status == ESI_ARP_PENDING) {
1978 entry->no_tries = 0;
1979 }
Chas Williams1fa99612006-09-29 17:11:47 -07001980 /*
1981 * Data direct VC not yet set up, check to see if the unknown
1982 * frame count is greater than the limit. If the limit has
1983 * not been reached, allow the caller to send packet to
1984 * BUS.
1985 */
1986 if (entry->status != ESI_FLUSH_PENDING &&
1987 entry->packets_flooded <
1988 priv->maximum_unknown_frame_count) {
1989 entry->packets_flooded++;
1990 DPRINTK("LEC_ARP: Flooding..\n");
1991 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001993 }
1994 /*
1995 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 * or BUS flood limit was reached for an entry which is
1997 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1998 */
Chas Williams1fa99612006-09-29 17:11:47 -07001999 *ret_entry = entry;
2000 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
2001 entry->vcc);
2002 found = NULL;
2003 } else {
2004 /* No matching entry was found */
2005 entry = make_entry(priv, mac_to_find);
2006 DPRINTK("LEC_ARP: Making entry\n");
2007 if (!entry) {
2008 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002010 }
2011 lec_arp_add(priv, entry);
2012 /* We want arp-request(s) to be sent */
2013 entry->packets_flooded = 1;
2014 entry->status = ESI_ARP_PENDING;
2015 entry->no_tries = 1;
2016 entry->last_used = entry->timestamp = jiffies;
2017 entry->is_rdesc = is_rdesc;
2018 if (entry->is_rdesc)
2019 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2020 NULL);
2021 else
2022 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2023 entry->timer.expires = jiffies + (1 * HZ);
2024 entry->timer.function = lec_arp_expire_arp;
2025 add_timer(&entry->timer);
2026 found = priv->mcast_vcc;
2027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029out:
2030 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2031 return found;
2032}
2033
2034static int
Chas Williams1fa99612006-09-29 17:11:47 -07002035lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2036 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
2038 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002039 struct hlist_node *node, *next;
2040 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002041 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Chas Williams1fa99612006-09-29 17:11:47 -07002043 DPRINTK("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002045 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002046 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002047 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2048 && (permanent ||
2049 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 lec_arp_remove(priv, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002051 kfree(entry);
2052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002054 return 0;
2055 }
2056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002058 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
2061/*
2062 * Notifies: Response to arp_request (atm_addr != NULL)
2063 */
2064static void
2065lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002066 unsigned char *atm_addr, unsigned long remoteflag,
2067 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
2069 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002070 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002071 struct lec_arp_table *entry, *tmp;
2072 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
Chas Williams1fa99612006-09-29 17:11:47 -07002074 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2075 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2076 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2077 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002080 entry = lec_arp_find(priv, mac_addr);
2081 if (entry == NULL && targetless_le_arp)
2082 goto out; /*
2083 * LANE2: ignore targetless LE_ARPs for which
2084 * we have no entry in the cache. 7.1.30
2085 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002086 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2087 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2088 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2089 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002090 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002091 tmp = lec_arp_find(priv, mac_addr);
2092 if (tmp) {
2093 del_timer(&tmp->timer);
2094 tmp->status = ESI_FORWARD_DIRECT;
2095 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2096 tmp->vcc = entry->vcc;
2097 tmp->old_push = entry->old_push;
2098 tmp->last_used = jiffies;
2099 del_timer(&entry->timer);
2100 kfree(entry);
2101 entry = tmp;
2102 } else {
2103 entry->status = ESI_FORWARD_DIRECT;
2104 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2105 entry->last_used = jiffies;
2106 lec_arp_add(priv, entry);
2107 }
2108 if (remoteflag)
2109 entry->flags |= LEC_REMOTE_FLAG;
2110 else
2111 entry->flags &= ~LEC_REMOTE_FLAG;
2112 DPRINTK("After update\n");
2113 dump_arp_table(priv);
2114 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002115 }
Chas Williams1fa99612006-09-29 17:11:47 -07002116 }
2117 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002118
Chas Williams1fa99612006-09-29 17:11:47 -07002119 entry = lec_arp_find(priv, mac_addr);
2120 if (!entry) {
2121 entry = make_entry(priv, mac_addr);
2122 if (!entry)
2123 goto out;
2124 entry->status = ESI_UNKNOWN;
2125 lec_arp_add(priv, entry);
2126 /* Temporary, changes before end of function */
2127 }
2128 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2129 del_timer(&entry->timer);
2130 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002131 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002132 if (entry != tmp &&
2133 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2134 /* Vcc to this host exists */
2135 if (tmp->status > ESI_VC_PENDING) {
2136 /*
2137 * ESI_FLUSH_PENDING,
2138 * ESI_FORWARD_DIRECT
2139 */
2140 entry->vcc = tmp->vcc;
2141 entry->old_push = tmp->old_push;
2142 }
2143 entry->status = tmp->status;
2144 break;
2145 }
2146 }
2147 }
2148 if (remoteflag)
2149 entry->flags |= LEC_REMOTE_FLAG;
2150 else
2151 entry->flags &= ~LEC_REMOTE_FLAG;
2152 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2153 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002154 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002155 }
2156 DPRINTK("After update2\n");
2157 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158out:
2159 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2160}
2161
2162/*
2163 * Notifies: Vcc setup ready
2164 */
2165static void
2166lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002167 struct atm_vcc *vcc,
2168 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
2170 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002171 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002172 struct lec_arp_table *entry;
2173 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002176 if (ioc_data->receive == 2) {
2177 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chas Williams1fa99612006-09-29 17:11:47 -07002179 DPRINTK("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002181 entry = lec_arp_find(priv, bus_mac);
2182 if (!entry) {
2183 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002185 }
2186 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2187 entry->recv_vcc = vcc;
2188 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002190 entry = make_entry(priv, bus_mac);
2191 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002193 del_timer(&entry->timer);
2194 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2195 entry->recv_vcc = vcc;
2196 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002197 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002198 goto out;
2199 } else if (ioc_data->receive == 1) {
2200 /*
2201 * Vcc which we don't want to make default vcc,
2202 * attach it anyway.
2203 */
2204 DPRINTK
2205 ("LEC_ARP:Attaching data direct, not default: "
2206 "%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",
2207 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2208 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2209 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2210 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2211 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2212 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2213 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2214 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2215 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2216 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2217 entry = make_entry(priv, bus_mac);
2218 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002220 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2221 memset(entry->mac_addr, 0, ETH_ALEN);
2222 entry->recv_vcc = vcc;
2223 entry->old_recv_push = old_push;
2224 entry->status = ESI_UNKNOWN;
2225 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2226 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002227 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002228 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 dump_arp_table(priv);
2230 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002231 }
2232 DPRINTK
2233 ("LEC_ARP:Attaching data direct, default: "
2234 "%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",
2235 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2236 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2237 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2238 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2239 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2240 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2241 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2242 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2243 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2244 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2245 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002246 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002247 if (memcmp
2248 (ioc_data->atm_addr, entry->atm_addr,
2249 ATM_ESA_LEN) == 0) {
2250 DPRINTK("LEC_ARP: Attaching data direct\n");
2251 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2252 entry->vcc ? entry->vcc->vci : 0,
2253 entry->recv_vcc ? entry->recv_vcc->
2254 vci : 0);
2255 found_entry = 1;
2256 del_timer(&entry->timer);
2257 entry->vcc = vcc;
2258 entry->old_push = old_push;
2259 if (entry->status == ESI_VC_PENDING) {
2260 if (priv->maximum_unknown_frame_count
2261 == 0)
2262 entry->status =
2263 ESI_FORWARD_DIRECT;
2264 else {
2265 entry->timestamp = jiffies;
2266 entry->status =
2267 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002269 send_to_lecd(priv, l_flush_xmt,
2270 NULL,
2271 entry->atm_addr,
2272 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002274 }
2275 } else {
2276 /*
2277 * They were forming a connection
2278 * to us, and we to them. Our
2279 * ATM address is numerically lower
2280 * than theirs, so we make connection
2281 * we formed into default VCC (8.1.11).
2282 * Connection they made gets torn
2283 * down. This might confuse some
2284 * clients. Can be changed if
2285 * someone reports trouble...
2286 */
2287 ;
2288 }
2289 }
2290 }
2291 }
2292 if (found_entry) {
2293 DPRINTK("After vcc was added\n");
2294 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002296 }
2297 /*
2298 * Not found, snatch address from first data packet that arrives
2299 * from this vcc
2300 */
2301 entry = make_entry(priv, bus_mac);
2302 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002304 entry->vcc = vcc;
2305 entry->old_push = old_push;
2306 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2307 memset(entry->mac_addr, 0, ETH_ALEN);
2308 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002309 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002310 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2311 entry->timer.function = lec_arp_expire_vcc;
2312 add_timer(&entry->timer);
2313 DPRINTK("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 dump_arp_table(priv);
2315out:
2316 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2317}
2318
Chas Williams1fa99612006-09-29 17:11:47 -07002319static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
2321 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002322 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002323 struct lec_arp_table *entry;
2324 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chas Williams1fa99612006-09-29 17:11:47 -07002326 DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
2327 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2328 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002329 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002330 if (entry->flush_tran_id == tran_id
2331 && entry->status == ESI_FLUSH_PENDING) {
2332 struct sk_buff *skb;
2333
2334 while ((skb =
2335 skb_dequeue(&entry->tx_wait)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 lec_send(entry->vcc, skb, entry->priv);
Chas Williams1fa99612006-09-29 17:11:47 -07002337 entry->status = ESI_FORWARD_DIRECT;
2338 DPRINTK("LEC_ARP: Flushed\n");
2339 }
2340 }
2341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002343 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346static void
2347lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002348 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349{
2350 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002351 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002352 struct lec_arp_table *entry;
2353 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002356 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002357 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002358 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2359 entry->flush_tran_id = tran_id;
Chas Williamsd0732f62006-09-29 17:14:27 -07002360 DPRINTK("Set flush transaction id to %lx for %p\n",
2361 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002362 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2365}
2366
Chas Williams1fa99612006-09-29 17:11:47 -07002367static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
2369 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002370 unsigned char mac_addr[] = {
2371 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2372 };
2373 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct lec_vcc_priv *vpriv;
2375 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002376
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2378 return -ENOMEM;
2379 vpriv->xoff = 0;
2380 vpriv->old_pop = vcc->pop;
2381 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002382 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002384 to_add = make_entry(priv, mac_addr);
2385 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 vcc->pop = vpriv->old_pop;
2387 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002388 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002390 }
2391 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2392 to_add->status = ESI_FORWARD_DIRECT;
2393 to_add->flags |= LEC_PERMANENT_FLAG;
2394 to_add->vcc = vcc;
2395 to_add->old_push = vcc->push;
2396 vcc->push = lec_push;
2397 priv->mcast_vcc = vcc;
2398 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399out:
2400 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002401 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
Chas Williams1fa99612006-09-29 17:11:47 -07002404static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405{
2406 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002407 struct hlist_node *node, *next;
2408 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002409 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Chas Williams1fa99612006-09-29 17:11:47 -07002411 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2412 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002415
Chas Williams1fa99612006-09-29 17:11:47 -07002416 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002417 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002418 if (vcc == entry->vcc) {
2419 lec_arp_remove(priv, entry);
2420 kfree(entry);
2421 if (priv->mcast_vcc == vcc) {
2422 priv->mcast_vcc = NULL;
2423 }
2424 }
2425 }
2426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chas Williamsd0732f62006-09-29 17:14:27 -07002428 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2429 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002430 lec_arp_clear_vccs(entry);
2431 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002432 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002433 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002434 }
Chas Williams1fa99612006-09-29 17:11:47 -07002435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Chas Williamsd0732f62006-09-29 17:14:27 -07002437 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002438 if (entry->recv_vcc == vcc) {
2439 lec_arp_clear_vccs(entry);
2440 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002441 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002442 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002443 }
Chas Williams1fa99612006-09-29 17:11:47 -07002444 }
2445
Chas Williamsd0732f62006-09-29 17:14:27 -07002446 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002447 if (entry->recv_vcc == vcc) {
2448 lec_arp_clear_vccs(entry);
2449 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002450 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002451 kfree(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002452 }
Chas Williams1fa99612006-09-29 17:11:47 -07002453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
2455 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2456 dump_arp_table(priv);
2457}
2458
2459static void
2460lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002461 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Chas Williams1fa99612006-09-29 17:11:47 -07002463 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002464 struct hlist_node *node, *next;
2465 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002466 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2467 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002469 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Chas Williams1fa99612006-09-29 17:11:47 -07002471 if (priv->is_trdev)
2472 src = tr_hdr->h_source;
2473 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002475 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
2477 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002478 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2479 if (vcc == entry->vcc) {
2480 del_timer(&entry->timer);
2481 memcpy(entry->mac_addr, src, ETH_ALEN);
2482 entry->status = ESI_FORWARD_DIRECT;
2483 entry->last_used = jiffies;
2484 /* We might have got an entry */
2485 if ((tmp = lec_arp_find(priv, src))) {
2486 lec_arp_remove(priv, tmp);
2487 kfree(tmp);
2488 }
2489 hlist_del(&entry->next);
2490 lec_arp_add(priv, entry);
2491 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002492 }
Chas Williams1fa99612006-09-29 17:11:47 -07002493 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002494 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495out:
2496 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2497}
Chas Williams1fa99612006-09-29 17:11:47 -07002498
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499MODULE_LICENSE("GPL");