blob: 1def62d17739be048671644c8d88c8fb15719284 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37#include <linux/if_bridge.h>
38#include "../bridge/br_private.h"
39
Chas Williamsd44f7742006-09-29 17:11:14 -070040static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42
43/* Modular too */
44#include <linux/module.h>
45#include <linux/init.h>
46
47#include "lec.h"
48#include "lec_arpc.h"
49#include "resources.h"
50
Chas Williamsd44f7742006-09-29 17:11:14 -070051#define DUMP_PACKETS 0 /*
52 * 0 = None,
53 * 1 = 30 first bytes
54 * 2 = Whole packet
55 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Chas Williamsd44f7742006-09-29 17:11:14 -070057#define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
60 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62static int lec_open(struct net_device *dev);
63static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
64static int lec_close(struct net_device *dev);
65static struct net_device_stats *lec_get_stats(struct net_device *dev);
66static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070067static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070068 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070070 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070072static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
73 const u8 *tlvs, u32 sizeoftlvs);
74static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070075 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070076static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
77 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070079static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned long permanent);
81static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83static void lec_arp_destroy(struct lec_priv *priv);
84static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070085static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070086 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 int is_rdesc,
88 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070089static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
90 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 unsigned int targetless_le_arp);
92static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070095 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070097static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070099 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102
Chas Williams33a9c2d2006-09-29 17:16:48 -0700103/* must be done under lec_arp_lock */
104static inline void lec_arp_hold(struct lec_arp_table *entry)
105{
106 atomic_inc(&entry->usage);
107}
108
109static inline void lec_arp_put(struct lec_arp_table *entry)
110{
111 if (atomic_dec_and_test(&entry->usage))
112 kfree(entry);
113}
114
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Chas Williamsd44f7742006-09-29 17:11:14 -0700122static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Device structures */
125static struct net_device *dev_lec[MAX_LEC_ITF];
126
127#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
129{
Chas Williamsd44f7742006-09-29 17:11:14 -0700130 struct ethhdr *eth;
131 char *buff;
132 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Chas Williamsd44f7742006-09-29 17:11:14 -0700134 /*
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
138 */
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Chas Williamsd44f7742006-09-29 17:11:14 -0700146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
147 if (skb2 == NULL)
148 return;
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Chas Williamsd44f7742006-09-29 17:11:14 -0700155 priv = (struct lec_priv *)dev->priv;
156 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Chas Williamsd44f7742006-09-29 17:11:14 -0700162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165
166/*
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
173 * and returns NULL.
174 */
175#ifdef CONFIG_TR
176static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177{
Chas Williamsd44f7742006-09-29 17:11:14 -0700178 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800179 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Chas Williamsd44f7742006-09-29 17:11:14 -0700181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Chas Williamsd44f7742006-09-29 17:11:14 -0700185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
189 } else
190 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chas Williamsd44f7742006-09-29 17:11:14 -0700192 if (riflen < 6)
193 return trh->daddr; /* last hop, source routed */
194
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 else {
Al Viro30d492d2006-11-14 21:11:29 -0800202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
204 }
205
206 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208#endif /* CONFIG_TR */
209
210/*
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
213 *
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
217 */
218
Chas Williamsd44f7742006-09-29 17:11:14 -0700219static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Chas Williamsd44f7742006-09-29 17:11:14 -0700221 struct lec_priv *priv = (struct lec_priv *)dev->priv;
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
225
226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static __inline__ void
230lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
231{
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 priv->stats.tx_dropped++;
238 return;
239 }
240
241 priv->stats.tx_packets++;
242 priv->stats.tx_bytes += skb->len;
243}
244
Chas Williamsd44f7742006-09-29 17:11:14 -0700245static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 printk(KERN_INFO "%s: tx timeout\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
Chas Williamsd44f7742006-09-29 17:11:14 -0700252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct sk_buff *skb2;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv;
256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700259 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 int min_frame_size;
261#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700266 char buf[300];
267 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Stephen Hemminger52240062007-08-28 15:22:09 -0700270 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
275 return -EUNATCH;
276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700280 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285
Chas Williamsd44f7742006-09-29 17:11:14 -0700286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Stephen Hemminger52240062007-08-28 15:22:09 -0700289 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
293 return 0;
294 skb = skb2;
295 }
296 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Chas Williamsd44f7742006-09-29 17:11:14 -0700298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
311 return 0;
312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
316#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif /* DUMP_PACKETS > 0 */
333
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
339#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
348 priv->stats.tx_dropped++;
349 return 0;
350 }
351 skb = skb2;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700374 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700376 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700377 skb_queue_tail(&entry->tx_wait, skb);
378 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700379 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
381 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700382 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 priv->stats.tx_dropped++;
384 dev_kfree_skb(skb);
385 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700386 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700387 }
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))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700393 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700394 pr_debug("MAC address %pM\n", lec_h->h_dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 lec_send(vcc, skb, priv);
399
400 if (!atm_may_send(vcc, 0)) {
401 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
402
403 vpriv->xoff = 1;
404 netif_stop_queue(dev);
405
406 /*
407 * vcc->pop() might have occurred in between, making
408 * the vcc usuable again. Since xmit is serialized,
409 * this is the only situation we have to re-test.
410 */
411
412 if (atm_may_send(vcc, 0))
413 netif_wake_queue(dev);
414 }
415
Chas Williams6656e3c2006-09-29 17:17:17 -0700416out:
417 if (entry)
418 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700420 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700424static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Chas Williamsd44f7742006-09-29 17:11:14 -0700426 netif_stop_queue(dev);
427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
430/*
431 * Get the current statistics.
432 * This may be called with the card open or closed.
433 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700434static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Chas Williamsd44f7742006-09-29 17:11:14 -0700436 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Chas Williamsd44f7742006-09-29 17:11:14 -0700439static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700442 struct net_device *dev = (struct net_device *)vcc->proto_data;
443 struct lec_priv *priv = (struct lec_priv *)dev->priv;
444 struct atmlec_msg *mesg;
445 struct lec_arp_table *entry;
446 int i;
447 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700450 mesg = (struct atmlec_msg *)skb->data;
451 tmp = skb->data;
452 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700453 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700454 switch (mesg->type) {
455 case l_set_mac_addr:
456 for (i = 0; i < 6; i++) {
457 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
458 }
459 break;
460 case l_del_mac_addr:
461 for (i = 0; i < 6; i++) {
462 dev->dev_addr[i] = 0;
463 }
464 break;
465 case l_addr_delete:
466 lec_addr_delete(priv, mesg->content.normal.atm_addr,
467 mesg->content.normal.flag);
468 break;
469 case l_topology_change:
470 priv->topology_change = mesg->content.normal.flag;
471 break;
472 case l_flush_complete:
473 lec_flush_complete(priv, mesg->content.normal.flag);
474 break;
475 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700477 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
478 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
480
Chas Williamsd44f7742006-09-29 17:11:14 -0700481 if (mesg->content.normal.no_source_le_narp)
482 break;
483 /* FALL THROUGH */
484 case l_arp_update:
485 lec_arp_update(priv, mesg->content.normal.mac_addr,
486 mesg->content.normal.atm_addr,
487 mesg->content.normal.flag,
488 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700489 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700490 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700491 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700492 mesg->sizeoftlvs);
493 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
494 tmp, mesg->sizeoftlvs);
495 }
496 break;
497 case l_config:
498 priv->maximum_unknown_frame_count =
499 mesg->content.config.maximum_unknown_frame_count;
500 priv->max_unknown_frame_time =
501 (mesg->content.config.max_unknown_frame_time * HZ);
502 priv->max_retry_count = mesg->content.config.max_retry_count;
503 priv->aging_time = (mesg->content.config.aging_time * HZ);
504 priv->forward_delay_time =
505 (mesg->content.config.forward_delay_time * HZ);
506 priv->arp_response_time =
507 (mesg->content.config.arp_response_time * HZ);
508 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
509 priv->path_switching_delay =
510 (mesg->content.config.path_switching_delay * HZ);
511 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 priv->lane2_ops = NULL;
513 if (priv->lane_version > 1)
514 priv->lane2_ops = &lane2_ops;
515 if (dev->change_mtu(dev, mesg->content.config.mtu))
516 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700517 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700519 break;
520 case l_flush_tran_id:
521 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
522 mesg->content.normal.flag);
523 break;
524 case l_set_lecid:
525 priv->lecid =
526 (unsigned short)(0xffff & mesg->content.normal.flag);
527 break;
528 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700530 {
531 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Johannes Berge1749612008-10-27 15:59:26 -0700533 pr_debug("%s: bridge zeppelin asks about %pM\n",
534 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Chas Williamsd44f7742006-09-29 17:11:14 -0700536 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
537 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 f = br_fdb_get_hook(dev->br_port->br,
540 mesg->content.proxy.mac_addr);
541 if (f != NULL && f->dst->dev != dev
542 && f->dst->state == BR_STATE_FORWARDING) {
543 /* hit from bridge table, send LE_ARP_RESPONSE */
544 struct sk_buff *skb2;
545 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Stephen Hemminger52240062007-08-28 15:22:09 -0700547 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700548 ("%s: entry found, responding to zeppelin\n",
549 dev->name);
550 skb2 =
551 alloc_skb(sizeof(struct atmlec_msg),
552 GFP_ATOMIC);
553 if (skb2 == NULL) {
554 br_fdb_put_hook(f);
555 break;
556 }
557 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300558 skb_copy_to_linear_data(skb2, mesg,
559 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700560 atm_force_charge(priv->lecd, skb2->truesize);
561 sk = sk_atm(priv->lecd);
562 skb_queue_tail(&sk->sk_receive_queue, skb2);
563 sk->sk_data_ready(sk, skb2->len);
564 }
565 if (f != NULL)
566 br_fdb_put_hook(f);
567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700569 break;
570 default:
571 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
572 dev_kfree_skb(skb);
573 return -EINVAL;
574 }
575 dev_kfree_skb(skb);
576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Chas Williamsd44f7742006-09-29 17:11:14 -0700579static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Chas Williamsd44f7742006-09-29 17:11:14 -0700581 struct sk_buff *skb;
582 struct net_device *dev = (struct net_device *)vcc->proto_data;
583 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Chas Williamsd44f7742006-09-29 17:11:14 -0700585 priv->lecd = NULL;
586 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Chas Williamsd44f7742006-09-29 17:11:14 -0700588 netif_stop_queue(dev);
589 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Chas Williamsd44f7742006-09-29 17:11:14 -0700591 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700593 dev->name);
594 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
595 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700597 }
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700600 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
603static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 .close = lec_atm_close,
605 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606};
607
608static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 .ops = &lecdev_ops,
610 .type = "lec",
611 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700612 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613};
614
615/*
616 * LANE2: new argument struct sk_buff *data contains
617 * the LE_ARP based TLVs introduced in the LANE2 spec
618 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700619static int
620send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700621 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700622 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
624 struct sock *sk;
625 struct sk_buff *skb;
626 struct atmlec_msg *mesg;
627
628 if (!priv || !priv->lecd) {
629 return -1;
630 }
631 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
632 if (!skb)
633 return -1;
634 skb->len = sizeof(struct atmlec_msg);
635 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700636 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700638 if (data != NULL)
639 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (mac_addr)
641 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700642 else
643 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (atm_addr)
645 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
646
Chas Williamsd44f7742006-09-29 17:11:14 -0700647 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 sk = sk_atm(priv->lecd);
649 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700650 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700653 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 atm_force_charge(priv->lecd, data->truesize);
655 skb_queue_tail(&sk->sk_receive_queue, data);
656 sk->sk_data_ready(sk, skb->len);
657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Chas Williamsd44f7742006-09-29 17:11:14 -0700659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
662/* shamelessly stolen from drivers/net/net_init.c */
663static int lec_change_mtu(struct net_device *dev, int new_mtu)
664{
Chas Williamsd44f7742006-09-29 17:11:14 -0700665 if ((new_mtu < 68) || (new_mtu > 18190))
666 return -EINVAL;
667 dev->mtu = new_mtu;
668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
671static void lec_set_multicast_list(struct net_device *dev)
672{
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 /*
674 * by default, all multicast frames arrive over the bus.
675 * eventually support selective multicast service
676 */
677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Chas Williamsd44f7742006-09-29 17:11:14 -0700680static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Chas Williamsd44f7742006-09-29 17:11:14 -0700682 dev->change_mtu = lec_change_mtu;
683 dev->open = lec_open;
684 dev->stop = lec_close;
685 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 dev->tx_timeout = lec_tx_timeout;
687
Chas Williamsd44f7742006-09-29 17:11:14 -0700688 dev->get_stats = lec_get_stats;
689 dev->set_multicast_list = lec_set_multicast_list;
690 dev->do_ioctl = NULL;
691 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700694static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700695 0xff,
696 0x00,
697 0x01,
698 0x01
699};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Scott Talbert4a7097f2005-09-29 17:30:54 -0700701#define LEC_DATA_DIRECT_8023 2
702#define LEC_DATA_DIRECT_8025 3
703
704static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700705{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700706 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
707 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700708}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700709
Chas Williamsd44f7742006-09-29 17:11:14 -0700710static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700712 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700713 struct net_device *dev = (struct net_device *)vcc->proto_data;
714 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700717 int i = 0;
718 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Chas Williamsd44f7742006-09-29 17:11:14 -0700720 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
721 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700724 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700725 lec_vcc_close(priv, vcc);
726 return;
727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
730 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700732 for (i = 0; i < skb->len && i < 99; i++) {
733 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700736 for (i = 0; i < skb->len && i < 30; i++) {
737 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 if (i == skb->len)
741 printk("%s\n", buf);
742 else
743 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 struct sock *sk = sk_atm(vcc);
747
Stephen Hemminger52240062007-08-28 15:22:09 -0700748 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 skb_queue_tail(&sk->sk_receive_queue, skb);
750 sk->sk_data_ready(sk, skb->len);
751 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700752 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Chas Williamsd44f7742006-09-29 17:11:14 -0700755 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800756 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 !priv->lecd || !(dev->flags & IFF_UP)) {
758 /*
759 * Probably looping back, or if lecd is missing,
760 * lecd has gone down
761 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700762 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 dev_kfree_skb(skb);
764 return;
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 if (priv->is_trdev)
768 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
769 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700771 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700772
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 /*
774 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700775 * the LE_ARP cache entry, delete the LE_ARP cache entry.
776 */
777 spin_lock_irqsave(&priv->lec_arp_lock, flags);
778 if (lec_is_data_direct(vcc)) {
779#ifdef CONFIG_TR
780 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700781 src =
782 ((struct lecdatahdr_8025 *)skb->data)->
783 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700784 else
785#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700786 src =
787 ((struct lecdatahdr_8023 *)skb->data)->
788 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700789 entry = lec_arp_find(priv, src);
790 if (entry && entry->vcc != vcc) {
791 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700792 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700793 }
794 }
795 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Chas Williamsd44f7742006-09-29 17:11:14 -0700797 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
798 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700800 dev_kfree_skb(skb);
801 return;
802 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700803 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700804 lec_arp_check_empties(priv, vcc, skb);
805 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700806 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700808 if (priv->is_trdev)
809 skb->protocol = tr_type_trans(skb, dev);
810 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700812 skb->protocol = eth_type_trans(skb, dev);
813 priv->stats.rx_packets++;
814 priv->stats.rx_bytes += skb->len;
815 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
816 netif_rx(skb);
817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Chas Williamsd44f7742006-09-29 17:11:14 -0700820static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
823 struct net_device *dev = skb->dev;
824
825 if (vpriv == NULL) {
826 printk("lec_pop(): vpriv = NULL!?!?!?\n");
827 return;
828 }
829
830 vpriv->old_pop(vcc, skb);
831
832 if (vpriv->xoff && atm_may_send(vcc, 0)) {
833 vpriv->xoff = 0;
834 if (netif_running(dev) && netif_queue_stopped(dev))
835 netif_wake_queue(dev);
836 }
837}
838
Chas Williamsd44f7742006-09-29 17:11:14 -0700839static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
841 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700842 int bytes_left;
843 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Chas Williamsd44f7742006-09-29 17:11:14 -0700845 /* Lecd must be up in this case */
846 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
847 if (bytes_left != 0) {
848 printk
849 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
850 bytes_left);
851 }
852 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
853 !dev_lec[ioc_data.dev_num])
854 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
856 return -ENOMEM;
857 vpriv->xoff = 0;
858 vpriv->old_pop = vcc->pop;
859 vcc->user_back = vpriv;
860 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700861 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
862 &ioc_data, vcc, vcc->push);
863 vcc->proto_data = dev_lec[ioc_data.dev_num];
864 vcc->push = lec_push;
865 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
Chas Williamsd44f7742006-09-29 17:11:14 -0700868static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Chas Williamsd44f7742006-09-29 17:11:14 -0700870 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
871 return -EINVAL;
872 vcc->proto_data = dev_lec[arg];
873 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
876/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700877static int lecd_attach(struct atm_vcc *vcc, int arg)
878{
879 int i;
880 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Chas Williamsd44f7742006-09-29 17:11:14 -0700882 if (arg < 0)
883 i = 0;
884 else
885 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700887 if (arg >= MAX_LEC_ITF)
888 return -EINVAL;
889#else /* Reserve the top NUM_TR_DEVS for TR */
890 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
891 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700893 if (!dev_lec[i]) {
894 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Chas Williamsd44f7742006-09-29 17:11:14 -0700896 is_trdev = 0;
897 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
898 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Chas Williamsd44f7742006-09-29 17:11:14 -0700900 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700902 if (is_trdev)
903 dev_lec[i] = alloc_trdev(size);
904 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700906 dev_lec[i] = alloc_etherdev(size);
907 if (!dev_lec[i])
908 return -ENOMEM;
909 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
910 if (register_netdev(dev_lec[i])) {
911 free_netdev(dev_lec[i]);
912 return -EINVAL;
913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Chas Williamsd44f7742006-09-29 17:11:14 -0700915 priv = dev_lec[i]->priv;
916 priv->is_trdev = is_trdev;
917 lec_init(dev_lec[i]);
918 } else {
919 priv = dev_lec[i]->priv;
920 if (priv->lecd)
921 return -EADDRINUSE;
922 }
923 lec_arp_init(priv);
924 priv->itfnum = i; /* LANE2 addition */
925 priv->lecd = vcc;
926 vcc->dev = &lecatm_dev;
927 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Chas Williamsd44f7742006-09-29 17:11:14 -0700929 vcc->proto_data = dev_lec[i];
930 set_bit(ATM_VF_META, &vcc->flags);
931 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Chas Williamsd44f7742006-09-29 17:11:14 -0700933 /* Set default values to these variables */
934 priv->maximum_unknown_frame_count = 1;
935 priv->max_unknown_frame_time = (1 * HZ);
936 priv->vcc_timeout_period = (1200 * HZ);
937 priv->max_retry_count = 1;
938 priv->aging_time = (300 * HZ);
939 priv->forward_delay_time = (15 * HZ);
940 priv->topology_change = 0;
941 priv->arp_response_time = (1 * HZ);
942 priv->flush_timeout = (4 * HZ);
943 priv->path_switching_delay = (6 * HZ);
944
945 if (dev_lec[i]->flags & IFF_UP) {
946 netif_start_queue(dev_lec[i]);
947 }
948 __module_get(THIS_MODULE);
949 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700953static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
955 static char *lec_arp_status_string[] = {
956 "ESI_UNKNOWN ",
957 "ESI_ARP_PENDING ",
958 "ESI_VC_PENDING ",
959 "<Undefined> ",
960 "ESI_FLUSH_PENDING ",
961 "ESI_FORWARD_DIRECT"
962 };
963
964 if (status > ESI_FORWARD_DIRECT)
965 status = 3; /* ESI_UNDEFINED */
966 return lec_arp_status_string[status];
967}
968
969static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
970{
971 int i;
972
973 for (i = 0; i < ETH_ALEN; i++)
974 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
975 seq_printf(seq, " ");
976 for (i = 0; i < ATM_ESA_LEN; i++)
977 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
978 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
979 entry->flags & 0xffff);
980 if (entry->vcc)
981 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
982 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700983 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (entry->recv_vcc) {
985 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
986 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700987 }
988 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991struct lec_state {
992 unsigned long flags;
993 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700994 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 struct net_device *dev;
996 int itf;
997 int arp_table;
998 int misc_table;
999};
1000
Chas Williamsd0732f62006-09-29 17:14:27 -07001001static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 loff_t *l)
1003{
Chas Williamsd0732f62006-09-29 17:14:27 -07001004 struct hlist_node *e = state->node;
1005 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001008 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -07001009 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001010 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 --*l;
1012 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001013
1014 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (--*l < 0)
1016 break;
1017 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001018 state->node = e;
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 return (*l < 0) ? state : NULL;
1021}
1022
1023static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001024 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
1026 void *v = NULL;
1027 int p;
1028
1029 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001030 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (v)
1032 break;
1033 }
1034 state->arp_table = p;
1035 return v;
1036}
1037
1038static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1039 struct lec_priv *priv)
1040{
Chas Williamsd0732f62006-09-29 17:14:27 -07001041 struct hlist_head *lec_misc_tables[] = {
1042 &priv->lec_arp_empty_ones,
1043 &priv->lec_no_forward,
1044 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 };
1046 void *v = NULL;
1047 int q;
1048
1049 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1050 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1051 if (v)
1052 break;
1053 }
1054 state->misc_table = q;
1055 return v;
1056}
1057
1058static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1059 struct lec_priv *priv)
1060{
1061 if (!state->locked) {
1062 state->locked = priv;
1063 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1064 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001065 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1067 state->locked = NULL;
1068 /* Partial state reset for the next time we get called */
1069 state->arp_table = state->misc_table = 0;
1070 }
1071 return state->locked;
1072}
1073
1074static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1075{
1076 struct net_device *dev;
1077 void *v;
1078
1079 dev = state->dev ? state->dev : dev_lec[state->itf];
1080 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1081 if (!v && dev) {
1082 dev_put(dev);
1083 /* Partial state reset for the next time we get called */
1084 dev = NULL;
1085 }
1086 state->dev = dev;
1087 return v;
1088}
1089
1090static void *lec_get_idx(struct lec_state *state, loff_t l)
1091{
1092 void *v = NULL;
1093
1094 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1095 v = lec_itf_walk(state, &l);
1096 if (v)
1097 break;
1098 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001099 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1103{
1104 struct lec_state *state = seq->private;
1105
1106 state->itf = 0;
1107 state->dev = NULL;
1108 state->locked = NULL;
1109 state->arp_table = 0;
1110 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001111 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Joe Perches2e1e9842008-04-10 03:33:03 -07001113 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
1116static void lec_seq_stop(struct seq_file *seq, void *v)
1117{
1118 struct lec_state *state = seq->private;
1119
1120 if (state->dev) {
1121 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1122 state->flags);
1123 dev_put(state->dev);
1124 }
1125}
1126
1127static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1128{
1129 struct lec_state *state = seq->private;
1130
1131 v = lec_get_idx(state, 1);
1132 *pos += !!PTR_ERR(v);
1133 return v;
1134}
1135
1136static int lec_seq_show(struct seq_file *seq, void *v)
1137{
Chas Williamsd44f7742006-09-29 17:11:14 -07001138 static char lec_banner[] = "Itf MAC ATM destination"
1139 " Status Flags "
1140 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Joe Perches2e1e9842008-04-10 03:33:03 -07001142 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 seq_puts(seq, lec_banner);
1144 else {
1145 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001146 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001147 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001150 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 }
1152 return 0;
1153}
1154
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001155static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001156 .start = lec_seq_start,
1157 .next = lec_seq_next,
1158 .stop = lec_seq_stop,
1159 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160};
1161
1162static int lec_seq_open(struct inode *inode, struct file *file)
1163{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001164 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Arjan van de Ven9a321442007-02-12 00:55:35 -08001167static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001168 .owner = THIS_MODULE,
1169 .open = lec_seq_open,
1170 .read = seq_read,
1171 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001172 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173};
1174#endif
1175
1176static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1177{
1178 struct atm_vcc *vcc = ATM_SD(sock);
1179 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001182 case ATMLEC_CTRL:
1183 case ATMLEC_MCAST:
1184 case ATMLEC_DATA:
1185 if (!capable(CAP_NET_ADMIN))
1186 return -EPERM;
1187 break;
1188 default:
1189 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 }
1191
1192 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001193 case ATMLEC_CTRL:
1194 err = lecd_attach(vcc, (int)arg);
1195 if (err >= 0)
1196 sock->state = SS_CONNECTED;
1197 break;
1198 case ATMLEC_MCAST:
1199 err = lec_mcast_attach(vcc, (int)arg);
1200 break;
1201 case ATMLEC_DATA:
1202 err = lec_vcc_attach(vcc, (void __user *)arg);
1203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 }
1205
1206 return err;
1207}
1208
1209static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001210 .owner = THIS_MODULE,
1211 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212};
1213
1214static int __init lane_module_init(void)
1215{
1216#ifdef CONFIG_PROC_FS
1217 struct proc_dir_entry *p;
1218
Wang Chen16e297b2008-02-28 13:55:45 -08001219 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001220 if (!p) {
1221 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1222 return -ENOMEM;
1223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224#endif
1225
1226 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001227 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
1231static void __exit lane_module_cleanup(void)
1232{
Chas Williamsd44f7742006-09-29 17:11:14 -07001233 int i;
1234 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 remove_proc_entry("lec", atm_proc_root);
1237
1238 deregister_atm_ioctl(&lane_ioctl_ops);
1239
Chas Williamsd44f7742006-09-29 17:11:14 -07001240 for (i = 0; i < MAX_LEC_ITF; i++) {
1241 if (dev_lec[i] != NULL) {
1242 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001244 free_netdev(dev_lec[i]);
1245 dev_lec[i] = NULL;
1246 }
1247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Chas Williamsd44f7742006-09-29 17:11:14 -07001249 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250}
1251
1252module_init(lane_module_init);
1253module_exit(lane_module_cleanup);
1254
1255/*
1256 * LANE2: 3.1.3, LE_RESOLVE.request
1257 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1258 * If sizeoftlvs == NULL the default TLVs associated with with this
1259 * lec will be used.
1260 * If dst_mac == NULL, targetless LE_ARP will be sent
1261 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001262static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001263 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264{
1265 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001266 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1267 struct lec_arp_table *table;
1268 struct sk_buff *skb;
1269 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001273 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 if (table == NULL)
1276 return -1;
1277
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001278 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001279 if (*tlvs == NULL)
1280 return -1;
1281
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 *sizeoftlvs = table->sizeoftlvs;
1283
1284 return 0;
1285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 if (sizeoftlvs == NULL)
1288 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 else {
1291 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1292 if (skb == NULL)
1293 return -1;
1294 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001295 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1297 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001298 return retval;
1299}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
1301/*
1302 * LANE2: 3.1.4, LE_ASSOCIATE.request
1303 * Associate the *tlvs with the *lan_dst address.
1304 * Will overwrite any previous association
1305 * Returns 1 for success, 0 for failure (out of memory)
1306 *
1307 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001308static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1309 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
Chas Williamsd44f7742006-09-29 17:11:14 -07001311 int retval;
1312 struct sk_buff *skb;
1313 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 if (compare_ether_addr(lan_dst, dev->dev_addr))
1316 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Chas Williamsd44f7742006-09-29 17:11:14 -07001318 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001320 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001321 if (priv->tlvs == NULL)
1322 return (0);
1323 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Chas Williamsd44f7742006-09-29 17:11:14 -07001325 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1326 if (skb == NULL)
1327 return 0;
1328 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001329 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001330 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1331 if (retval != 0)
1332 printk("lec.c: lane2_associate_req() failed\n");
1333 /*
1334 * If the previous association has changed we must
1335 * somehow notify other LANE entities about the change
1336 */
1337 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
1340/*
1341 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1342 *
1343 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001344static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1345 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
1347#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001348 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349#endif
1350 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001351#if 0 /*
1352 * Why have the TLVs in LE_ARP entries
1353 * since we do not use them? When you
1354 * uncomment this code, make sure the
1355 * TLVs get freed when entry is killed
1356 */
1357 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 if (entry == NULL)
1360 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Chas Williamsd44f7742006-09-29 17:11:14 -07001362 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001364 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001365 if (entry->tlvs == NULL)
1366 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001367 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368#endif
1369#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001370 printk("lec.c: lane2_associate_ind()\n");
1371 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1372 while (i < sizeoftlvs)
1373 printk("%02x ", tlvs[i++]);
1374
1375 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376#endif
1377
Chas Williamsd44f7742006-09-29 17:11:14 -07001378 /* tell MPOA about the TLVs we saw */
1379 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1380 priv->lane2_ops->associate_indicator(dev, mac_addr,
1381 tlvs, sizeoftlvs);
1382 }
1383 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
1386/*
1387 * Here starts what used to lec_arpc.c
1388 *
1389 * lec_arpc.c was added here when making
1390 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 */
1392
1393#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394#include <linux/timer.h>
1395#include <asm/param.h>
1396#include <asm/atomic.h>
1397#include <linux/inetdevice.h>
1398#include <net/route.h>
1399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001401#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001403#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404*/
1405#endif
1406#define DEBUG_ARP_TABLE 0
1407
1408#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1409
David Howellsc4028952006-11-22 14:57:56 +00001410static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411static void lec_arp_expire_arp(unsigned long data);
1412
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001413/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 * Arp table funcs
1415 */
1416
1417#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1418
1419/*
1420 * Initialization of arp-cache
1421 */
Chas Williams1fa99612006-09-29 17:11:47 -07001422static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Chas Williams1fa99612006-09-29 17:11:47 -07001424 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Chas Williams1fa99612006-09-29 17:11:47 -07001426 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001427 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001428 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001429 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1430 INIT_HLIST_HEAD(&priv->lec_no_forward);
1431 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001433 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001434 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435}
1436
Chas Williams1fa99612006-09-29 17:11:47 -07001437static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Chas Williams1fa99612006-09-29 17:11:47 -07001439 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 struct atm_vcc *vcc = entry->vcc;
1441 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001442 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Chas Williams1fa99612006-09-29 17:11:47 -07001444 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 if (vpriv->xoff)
1446 netif_wake_queue(dev);
1447 kfree(vpriv);
1448 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001449 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001451 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001452 }
1453 if (entry->recv_vcc) {
1454 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001456 entry->recv_vcc = NULL;
1457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458}
1459
1460/*
1461 * Insert entry to lec_arp_table
1462 * LANE2: Add to the end of the list to satisfy 8.1.13
1463 */
Chas Williams1fa99612006-09-29 17:11:47 -07001464static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001465lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
Chas Williamsd0732f62006-09-29 17:14:27 -07001467 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Chas Williamsd0732f62006-09-29 17:14:27 -07001469 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1470 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001471
Stephen Hemminger52240062007-08-28 15:22:09 -07001472 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williamsd0732f62006-09-29 17:14:27 -07001473 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1474 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1475 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
1478/*
1479 * Remove entry from lec_arp_table
1480 */
Chas Williams1fa99612006-09-29 17:11:47 -07001481static int
1482lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Chas Williamsd0732f62006-09-29 17:14:27 -07001484 struct hlist_node *node;
1485 struct lec_arp_table *entry;
1486 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Chas Williams1fa99612006-09-29 17:11:47 -07001488 if (!to_remove) {
1489 return -1;
1490 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001491
1492 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001493 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Chas Williamsd0732f62006-09-29 17:14:27 -07001495 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001496 if (to_remove->status >= ESI_FLUSH_PENDING) {
1497 /*
1498 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1499 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001500 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1501 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1502 if (memcmp(to_remove->atm_addr,
1503 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001504 remove_vcc = 0;
1505 break;
1506 }
1507 }
1508 }
1509 if (remove_vcc)
1510 lec_arp_clear_vccs(to_remove);
1511 }
1512 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1513
Stephen Hemminger52240062007-08-28 15:22:09 -07001514 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001515 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1516 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1517 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1518 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
1521#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001522static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Chas Williams1fa99612006-09-29 17:11:47 -07001524 switch (st) {
1525 case ESI_UNKNOWN:
1526 return "ESI_UNKNOWN";
1527 case ESI_ARP_PENDING:
1528 return "ESI_ARP_PENDING";
1529 case ESI_VC_PENDING:
1530 return "ESI_VC_PENDING";
1531 case ESI_FLUSH_PENDING:
1532 return "ESI_FLUSH_PENDING";
1533 case ESI_FORWARD_DIRECT:
1534 return "ESI_FORWARD_DIRECT";
1535 default:
1536 return "<UNKNOWN>";
1537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Chas Williams1fa99612006-09-29 17:11:47 -07001540static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Chas Williamsd0732f62006-09-29 17:14:27 -07001542 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001543 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001544 char buf[256];
1545 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Chas Williams1fa99612006-09-29 17:11:47 -07001547 printk("Dump %p:\n", priv);
1548 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001549 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1550 offset = 0;
1551 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001552 offset += sprintf(buf + offset, "Mac:");
1553 for (j = 0; j < ETH_ALEN; j++) {
1554 offset += sprintf(buf + offset,
1555 "%2.2x ",
1556 rulla->mac_addr[j] & 0xff);
1557 }
1558 offset += sprintf(buf + offset, "Atm:");
1559 for (j = 0; j < ATM_ESA_LEN; j++) {
1560 offset += sprintf(buf + offset,
1561 "%2.2x ",
1562 rulla->atm_addr[j] & 0xff);
1563 }
1564 offset += sprintf(buf + offset,
1565 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1566 rulla->vcc ? rulla->vcc->vpi : 0,
1567 rulla->vcc ? rulla->vcc->vci : 0,
1568 rulla->recv_vcc ? rulla->recv_vcc->
1569 vpi : 0,
1570 rulla->recv_vcc ? rulla->recv_vcc->
1571 vci : 0, rulla->last_used,
1572 rulla->timestamp, rulla->no_tries);
1573 offset +=
1574 sprintf(buf + offset,
1575 "Flags:%x, Packets_flooded:%x, Status: %s ",
1576 rulla->flags, rulla->packets_flooded,
1577 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001578 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001579 }
Chas Williams1fa99612006-09-29 17:11:47 -07001580 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001581
1582 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001583 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001584 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001585 offset = 0;
1586 offset += sprintf(buf + offset, "Mac:");
1587 for (j = 0; j < ETH_ALEN; j++) {
1588 offset += sprintf(buf + offset, "%2.2x ",
1589 rulla->mac_addr[j] & 0xff);
1590 }
1591 offset += sprintf(buf + offset, "Atm:");
1592 for (j = 0; j < ATM_ESA_LEN; j++) {
1593 offset += sprintf(buf + offset, "%2.2x ",
1594 rulla->atm_addr[j] & 0xff);
1595 }
1596 offset += sprintf(buf + offset,
1597 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1598 rulla->vcc ? rulla->vcc->vpi : 0,
1599 rulla->vcc ? rulla->vcc->vci : 0,
1600 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1601 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1602 rulla->last_used,
1603 rulla->timestamp, rulla->no_tries);
1604 offset += sprintf(buf + offset,
1605 "Flags:%x, Packets_flooded:%x, Status: %s ",
1606 rulla->flags, rulla->packets_flooded,
1607 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001608 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001609 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001610
1611 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001612 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001613 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001614 offset = 0;
1615 offset += sprintf(buf + offset, "Mac:");
1616 for (j = 0; j < ETH_ALEN; j++) {
1617 offset += sprintf(buf + offset, "%2.2x ",
1618 rulla->mac_addr[j] & 0xff);
1619 }
1620 offset += sprintf(buf + offset, "Atm:");
1621 for (j = 0; j < ATM_ESA_LEN; j++) {
1622 offset += sprintf(buf + offset, "%2.2x ",
1623 rulla->atm_addr[j] & 0xff);
1624 }
1625 offset += sprintf(buf + offset,
1626 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1627 rulla->vcc ? rulla->vcc->vpi : 0,
1628 rulla->vcc ? rulla->vcc->vci : 0,
1629 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1630 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1631 rulla->last_used,
1632 rulla->timestamp, rulla->no_tries);
1633 offset += sprintf(buf + offset,
1634 "Flags:%x, Packets_flooded:%x, Status: %s ",
1635 rulla->flags, rulla->packets_flooded,
1636 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001637 printk("%s", buf);
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Chas Williamsd0732f62006-09-29 17:14:27 -07001640 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001641 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001642 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001643 offset = 0;
1644 offset += sprintf(buf + offset, "Mac:");
1645 for (j = 0; j < ETH_ALEN; j++) {
1646 offset += sprintf(buf + offset, "%2.2x ",
1647 rulla->mac_addr[j] & 0xff);
1648 }
1649 offset += sprintf(buf + offset, "Atm:");
1650 for (j = 0; j < ATM_ESA_LEN; j++) {
1651 offset += sprintf(buf + offset, "%2.2x ",
1652 rulla->atm_addr[j] & 0xff);
1653 }
1654 offset += sprintf(buf + offset,
1655 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1656 rulla->vcc ? rulla->vcc->vpi : 0,
1657 rulla->vcc ? rulla->vcc->vci : 0,
1658 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1659 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1660 rulla->last_used,
1661 rulla->timestamp, rulla->no_tries);
1662 offset += sprintf(buf + offset,
1663 "Flags:%x, Packets_flooded:%x, Status: %s ",
1664 rulla->flags, rulla->packets_flooded,
1665 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001666 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669}
Chas Williamsd0732f62006-09-29 17:14:27 -07001670#else
1671#define dump_arp_table(priv) do { } while (0)
1672#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674/*
1675 * Destruction of arp-cache
1676 */
Chas Williams1fa99612006-09-29 17:11:47 -07001677static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
1679 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001680 struct hlist_node *node, *next;
1681 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001682 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Chas Williams987e46b2006-09-29 17:15:59 -07001684 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001685
1686 /*
1687 * Remove all entries
1688 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001691 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001692 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001693 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001694 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001695 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001696 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001697 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001698
1699 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001700 del_timer_sync(&entry->timer);
1701 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001702 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001703 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001704 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001705 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1706
1707 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001708 del_timer_sync(&entry->timer);
1709 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001710 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001711 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001712 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001713 INIT_HLIST_HEAD(&priv->lec_no_forward);
1714
1715 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001716 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1717 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001718 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001719 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001720 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001721 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001722 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1724}
1725
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001726/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 * Find entry by mac_address
1728 */
Chas Williams1fa99612006-09-29 17:11:47 -07001729static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001730 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Chas Williamsd0732f62006-09-29 17:14:27 -07001732 struct hlist_node *node;
1733 struct hlist_head *head;
1734 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Stephen Hemminger52240062007-08-28 15:22:09 -07001736 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001737 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1738 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001739
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1741 hlist_for_each_entry(entry, node, head, next) {
1742 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1743 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001744 }
Chas Williams1fa99612006-09-29 17:11:47 -07001745 }
1746 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
Chas Williams1fa99612006-09-29 17:11:47 -07001749static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001750 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
Chas Williams1fa99612006-09-29 17:11:47 -07001752 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Chas Williams1fa99612006-09-29 17:11:47 -07001754 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1755 if (!to_return) {
1756 printk("LEC: Arp entry kmalloc failed\n");
1757 return NULL;
1758 }
1759 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001760 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001761 setup_timer(&to_return->timer, lec_arp_expire_arp,
1762 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001763 to_return->last_used = jiffies;
1764 to_return->priv = priv;
1765 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001766 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001767 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Chas Williams1fa99612006-09-29 17:11:47 -07001770/* Arp sent timer expired */
1771static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772{
Chas Williams1fa99612006-09-29 17:11:47 -07001773 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Chas Williams1fa99612006-09-29 17:11:47 -07001775 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Stephen Hemminger52240062007-08-28 15:22:09 -07001777 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001778 if (entry->status == ESI_ARP_PENDING) {
1779 if (entry->no_tries <= entry->priv->max_retry_count) {
1780 if (entry->is_rdesc)
1781 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1782 entry->mac_addr, NULL, NULL);
1783 else
1784 send_to_lecd(entry->priv, l_arp_xmt,
1785 entry->mac_addr, NULL, NULL);
1786 entry->no_tries++;
1787 }
1788 mod_timer(&entry->timer, jiffies + (1 * HZ));
1789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790}
1791
Chas Williams1fa99612006-09-29 17:11:47 -07001792/* Unknown/unused vcc expire, remove associated entry */
1793static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
1795 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001796 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1797 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Chas Williams1fa99612006-09-29 17:11:47 -07001799 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Stephen Hemminger52240062007-08-28 15:22:09 -07001801 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001802 to_remove, priv,
1803 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1804 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
1806 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001807 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1809
Chas Williams1fa99612006-09-29 17:11:47 -07001810 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001811 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812}
1813
1814/*
1815 * Expire entries.
1816 * 1. Re-set timer
1817 * 2. For each entry, delete entries that have aged past the age limit.
1818 * 3. For each entry, depending on the status of the entry, perform
1819 * the following maintenance.
1820 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1821 * tick_count is above the max_unknown_frame_time, clear
1822 * the tick_count to zero and clear the packets_flooded counter
1823 * to zero. This supports the packet rate limit per address
1824 * while flooding unknowns.
1825 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1826 * than or equal to the path_switching_delay, change the status
1827 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1828 * regardless of the progress of the flush protocol.
1829 */
David Howellsc4028952006-11-22 14:57:56 +00001830static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
1832 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001833 struct lec_priv *priv =
1834 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001835 struct hlist_node *node, *next;
1836 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001837 unsigned long now;
1838 unsigned long time_to_check;
1839 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Stephen Hemminger52240062007-08-28 15:22:09 -07001841 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001843restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001845 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001846 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001847 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 priv->topology_change)
1849 time_to_check = priv->forward_delay_time;
1850 else
1851 time_to_check = priv->aging_time;
1852
Stephen Hemminger52240062007-08-28 15:22:09 -07001853 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001854 now, entry->last_used, time_to_check);
1855 if (time_after(now, entry->last_used + time_to_check)
1856 && !(entry->flags & LEC_PERMANENT_FLAG)
1857 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001859 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001861 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 } else {
1863 /* Something else */
1864 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001865 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001867 entry->timestamp +
1868 priv->
1869 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 entry->timestamp = jiffies;
1871 entry->packets_flooded = 0;
1872 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001873 send_to_lecd(priv, l_svc_setup,
1874 entry->mac_addr,
1875 entry->atm_addr,
1876 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 }
Chas Williams1fa99612006-09-29 17:11:47 -07001878 if (entry->status == ESI_FLUSH_PENDING
1879 &&
1880 time_after_eq(now, entry->timestamp +
1881 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001883 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Chas Williams6656e3c2006-09-29 17:17:17 -07001885 lec_arp_hold(entry);
1886 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1887 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1888 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001890 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001891 lec_arp_put(entry);
1892 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 }
1895 }
1896 }
1897 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1898
Chas Williams987e46b2006-09-29 17:15:59 -07001899 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
Chas Williams1fa99612006-09-29 17:11:47 -07001901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902/*
1903 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001904 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 */
Chas Williams1fa99612006-09-29 17:11:47 -07001906static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001907 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001908 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
1910 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001911 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 struct atm_vcc *found;
1913
Chas Williams1fa99612006-09-29 17:11:47 -07001914 if (mac_to_find[0] & 0x01) {
1915 switch (priv->lane_version) {
1916 case 1:
1917 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001918 case 2: /* LANE2 wants arp for multicast addresses */
1919 if (!compare_ether_addr(mac_to_find, bus_mac))
1920 return priv->mcast_vcc;
1921 break;
1922 default:
1923 break;
1924 }
1925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
1927 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001928 entry = lec_arp_find(priv, mac_to_find);
1929
1930 if (entry) {
1931 if (entry->status == ESI_FORWARD_DIRECT) {
1932 /* Connection Ok */
1933 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001934 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001935 *ret_entry = entry;
1936 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001938 }
1939 /*
1940 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001941 * so another LE_ARP request can be made for this frame.
1942 */
1943 if (entry->status == ESI_ARP_PENDING) {
1944 entry->no_tries = 0;
1945 }
Chas Williams1fa99612006-09-29 17:11:47 -07001946 /*
1947 * Data direct VC not yet set up, check to see if the unknown
1948 * frame count is greater than the limit. If the limit has
1949 * not been reached, allow the caller to send packet to
1950 * BUS.
1951 */
1952 if (entry->status != ESI_FLUSH_PENDING &&
1953 entry->packets_flooded <
1954 priv->maximum_unknown_frame_count) {
1955 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001956 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001957 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001959 }
1960 /*
1961 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 * or BUS flood limit was reached for an entry which is
1963 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1964 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001965 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001966 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001967 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001968 entry->vcc);
1969 found = NULL;
1970 } else {
1971 /* No matching entry was found */
1972 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001973 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001974 if (!entry) {
1975 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001977 }
1978 lec_arp_add(priv, entry);
1979 /* We want arp-request(s) to be sent */
1980 entry->packets_flooded = 1;
1981 entry->status = ESI_ARP_PENDING;
1982 entry->no_tries = 1;
1983 entry->last_used = entry->timestamp = jiffies;
1984 entry->is_rdesc = is_rdesc;
1985 if (entry->is_rdesc)
1986 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1987 NULL);
1988 else
1989 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1990 entry->timer.expires = jiffies + (1 * HZ);
1991 entry->timer.function = lec_arp_expire_arp;
1992 add_timer(&entry->timer);
1993 found = priv->mcast_vcc;
1994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996out:
1997 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1998 return found;
1999}
2000
2001static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002002lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002003 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
2005 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002006 struct hlist_node *node, *next;
2007 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002008 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
Stephen Hemminger52240062007-08-28 15:22:09 -07002010 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002012 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002013 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002014 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2015 && (permanent ||
2016 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002018 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002021 return 0;
2022 }
2023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002025 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
2028/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002029 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 */
2031static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002032lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2033 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002034 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
2036 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002037 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002038 struct lec_arp_table *entry, *tmp;
2039 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Stephen Hemminger52240062007-08-28 15:22:09 -07002041 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2042 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002043 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2044 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002047 entry = lec_arp_find(priv, mac_addr);
2048 if (entry == NULL && targetless_le_arp)
2049 goto out; /*
2050 * LANE2: ignore targetless LE_ARPs for which
2051 * we have no entry in the cache. 7.1.30
2052 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002053 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2054 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2055 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2056 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002057 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002058 tmp = lec_arp_find(priv, mac_addr);
2059 if (tmp) {
2060 del_timer(&tmp->timer);
2061 tmp->status = ESI_FORWARD_DIRECT;
2062 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2063 tmp->vcc = entry->vcc;
2064 tmp->old_push = entry->old_push;
2065 tmp->last_used = jiffies;
2066 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002067 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002068 entry = tmp;
2069 } else {
2070 entry->status = ESI_FORWARD_DIRECT;
2071 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2072 entry->last_used = jiffies;
2073 lec_arp_add(priv, entry);
2074 }
2075 if (remoteflag)
2076 entry->flags |= LEC_REMOTE_FLAG;
2077 else
2078 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002079 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002080 dump_arp_table(priv);
2081 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002082 }
Chas Williams1fa99612006-09-29 17:11:47 -07002083 }
2084 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002085
Chas Williams1fa99612006-09-29 17:11:47 -07002086 entry = lec_arp_find(priv, mac_addr);
2087 if (!entry) {
2088 entry = make_entry(priv, mac_addr);
2089 if (!entry)
2090 goto out;
2091 entry->status = ESI_UNKNOWN;
2092 lec_arp_add(priv, entry);
2093 /* Temporary, changes before end of function */
2094 }
2095 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2096 del_timer(&entry->timer);
2097 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002098 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002099 if (entry != tmp &&
2100 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2101 /* Vcc to this host exists */
2102 if (tmp->status > ESI_VC_PENDING) {
2103 /*
2104 * ESI_FLUSH_PENDING,
2105 * ESI_FORWARD_DIRECT
2106 */
2107 entry->vcc = tmp->vcc;
2108 entry->old_push = tmp->old_push;
2109 }
2110 entry->status = tmp->status;
2111 break;
2112 }
2113 }
2114 }
2115 if (remoteflag)
2116 entry->flags |= LEC_REMOTE_FLAG;
2117 else
2118 entry->flags &= ~LEC_REMOTE_FLAG;
2119 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2120 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002121 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002122 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002123 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002124 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125out:
2126 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2127}
2128
2129/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002130 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 */
2132static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002133lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002134 struct atm_vcc *vcc,
2135 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
2137 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002138 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002139 struct lec_arp_table *entry;
2140 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002143 if (ioc_data->receive == 2) {
2144 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Stephen Hemminger52240062007-08-28 15:22:09 -07002146 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002148 entry = lec_arp_find(priv, bus_mac);
2149 if (!entry) {
2150 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002152 }
2153 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2154 entry->recv_vcc = vcc;
2155 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002157 entry = make_entry(priv, bus_mac);
2158 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002160 del_timer(&entry->timer);
2161 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2162 entry->recv_vcc = vcc;
2163 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002164 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002165 goto out;
2166 } else if (ioc_data->receive == 1) {
2167 /*
2168 * Vcc which we don't want to make default vcc,
2169 * attach it anyway.
2170 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002171 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002172 ("LEC_ARP:Attaching data direct, not default: "
2173 "%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",
2174 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2175 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2176 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2177 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2178 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2179 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2180 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2181 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2182 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2183 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2184 entry = make_entry(priv, bus_mac);
2185 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002187 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2188 memset(entry->mac_addr, 0, ETH_ALEN);
2189 entry->recv_vcc = vcc;
2190 entry->old_recv_push = old_push;
2191 entry->status = ESI_UNKNOWN;
2192 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2193 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002194 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002195 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 dump_arp_table(priv);
2197 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002198 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002199 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002200 ("LEC_ARP:Attaching data direct, default: "
2201 "%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",
2202 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2203 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2204 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2205 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2206 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2207 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2208 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2209 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2210 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2211 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2212 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002213 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002214 if (memcmp
2215 (ioc_data->atm_addr, entry->atm_addr,
2216 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002217 pr_debug("LEC_ARP: Attaching data direct\n");
2218 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002219 entry->vcc ? entry->vcc->vci : 0,
2220 entry->recv_vcc ? entry->recv_vcc->
2221 vci : 0);
2222 found_entry = 1;
2223 del_timer(&entry->timer);
2224 entry->vcc = vcc;
2225 entry->old_push = old_push;
2226 if (entry->status == ESI_VC_PENDING) {
2227 if (priv->maximum_unknown_frame_count
2228 == 0)
2229 entry->status =
2230 ESI_FORWARD_DIRECT;
2231 else {
2232 entry->timestamp = jiffies;
2233 entry->status =
2234 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002236 send_to_lecd(priv, l_flush_xmt,
2237 NULL,
2238 entry->atm_addr,
2239 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002241 }
2242 } else {
2243 /*
2244 * They were forming a connection
2245 * to us, and we to them. Our
2246 * ATM address is numerically lower
2247 * than theirs, so we make connection
2248 * we formed into default VCC (8.1.11).
2249 * Connection they made gets torn
2250 * down. This might confuse some
2251 * clients. Can be changed if
2252 * someone reports trouble...
2253 */
2254 ;
2255 }
2256 }
2257 }
2258 }
2259 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002260 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002261 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002263 }
2264 /*
2265 * Not found, snatch address from first data packet that arrives
2266 * from this vcc
2267 */
2268 entry = make_entry(priv, bus_mac);
2269 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002271 entry->vcc = vcc;
2272 entry->old_push = old_push;
2273 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2274 memset(entry->mac_addr, 0, ETH_ALEN);
2275 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002276 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002277 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2278 entry->timer.function = lec_arp_expire_vcc;
2279 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002280 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 dump_arp_table(priv);
2282out:
2283 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2284}
2285
Chas Williams1fa99612006-09-29 17:11:47 -07002286static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
2288 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002289 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002290 struct lec_arp_table *entry;
2291 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Stephen Hemminger52240062007-08-28 15:22:09 -07002293 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002294restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002295 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2296 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002297 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002298 if (entry->flush_tran_id == tran_id
2299 && entry->status == ESI_FLUSH_PENDING) {
2300 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002301 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002302
Chas Williams6656e3c2006-09-29 17:17:17 -07002303 lec_arp_hold(entry);
2304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2305 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2306 lec_send(vcc, skb, entry->priv);
2307 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002308 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002309 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002310 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002311 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002312 }
2313 }
2314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002316 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319static void
2320lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002321 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
2323 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002324 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002325 struct lec_arp_table *entry;
2326 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
2328 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002329 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002330 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002331 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2332 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002333 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002334 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002335 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2338}
2339
Chas Williams1fa99612006-09-29 17:11:47 -07002340static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
2342 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002343 unsigned char mac_addr[] = {
2344 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2345 };
2346 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct lec_vcc_priv *vpriv;
2348 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2351 return -ENOMEM;
2352 vpriv->xoff = 0;
2353 vpriv->old_pop = vcc->pop;
2354 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002355 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002357 to_add = make_entry(priv, mac_addr);
2358 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 vcc->pop = vpriv->old_pop;
2360 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002361 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002363 }
2364 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2365 to_add->status = ESI_FORWARD_DIRECT;
2366 to_add->flags |= LEC_PERMANENT_FLAG;
2367 to_add->vcc = vcc;
2368 to_add->old_push = vcc->push;
2369 vcc->push = lec_push;
2370 priv->mcast_vcc = vcc;
2371 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372out:
2373 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002374 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
Chas Williams1fa99612006-09-29 17:11:47 -07002377static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378{
2379 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002380 struct hlist_node *node, *next;
2381 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002382 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Stephen Hemminger52240062007-08-28 15:22:09 -07002384 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002385 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002388
Chas Williams1fa99612006-09-29 17:11:47 -07002389 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002390 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002391 if (vcc == entry->vcc) {
2392 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002393 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002394 if (priv->mcast_vcc == vcc) {
2395 priv->mcast_vcc = NULL;
2396 }
2397 }
2398 }
2399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Chas Williamsd0732f62006-09-29 17:14:27 -07002401 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2402 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002403 lec_arp_clear_vccs(entry);
2404 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002405 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002406 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002407 }
Chas Williams1fa99612006-09-29 17:11:47 -07002408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
Chas Williamsd0732f62006-09-29 17:14:27 -07002410 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002411 if (entry->recv_vcc == vcc) {
2412 lec_arp_clear_vccs(entry);
2413 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002414 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002415 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002416 }
Chas Williams1fa99612006-09-29 17:11:47 -07002417 }
2418
Chas Williamsd0732f62006-09-29 17:14:27 -07002419 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002420 if (entry->recv_vcc == vcc) {
2421 lec_arp_clear_vccs(entry);
2422 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002423 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002424 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002425 }
Chas Williams1fa99612006-09-29 17:11:47 -07002426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2429 dump_arp_table(priv);
2430}
2431
2432static void
2433lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002434 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435{
Chas Williams1fa99612006-09-29 17:11:47 -07002436 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002437 struct hlist_node *node, *next;
2438 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002439 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2440 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002442 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Chas Williams1fa99612006-09-29 17:11:47 -07002444 if (priv->is_trdev)
2445 src = tr_hdr->h_source;
2446 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002448 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
2450 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002451 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2452 if (vcc == entry->vcc) {
2453 del_timer(&entry->timer);
2454 memcpy(entry->mac_addr, src, ETH_ALEN);
2455 entry->status = ESI_FORWARD_DIRECT;
2456 entry->last_used = jiffies;
2457 /* We might have got an entry */
2458 if ((tmp = lec_arp_find(priv, src))) {
2459 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002460 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002461 }
2462 hlist_del(&entry->next);
2463 lec_arp_add(priv, entry);
2464 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002465 }
Chas Williams1fa99612006-09-29 17:11:47 -07002466 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002467 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468out:
2469 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2470}
Chas Williams1fa99612006-09-29 17:11:47 -07002471
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472MODULE_LICENSE("GPL");