blob: 8f701cde5945b0f8ee7d9c6d6a3412130ce840a8 [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);
David S. Miller21f644f2008-04-08 16:50:44 -0700376 pr_debug("MAC address " MAC_FMT "\n",
377 lec_h->h_dest[0], lec_h->h_dest[1],
378 lec_h->h_dest[2], lec_h->h_dest[3],
379 lec_h->h_dest[4], lec_h->h_dest[5]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700380 skb_queue_tail(&entry->tx_wait, skb);
381 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700382 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
384 dev->name);
David S. Miller21f644f2008-04-08 16:50:44 -0700385 pr_debug("MAC address " MAC_FMT "\n",
386 lec_h->h_dest[0], lec_h->h_dest[1],
387 lec_h->h_dest[2], lec_h->h_dest[3],
388 lec_h->h_dest[4], lec_h->h_dest[5]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700389 priv->stats.tx_dropped++;
390 dev_kfree_skb(skb);
391 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700392 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700393 }
394#if DUMP_PACKETS > 0
395 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700397
398 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700399 pr_debug("lec.c: emptying tx queue, ");
David S. Miller21f644f2008-04-08 16:50:44 -0700400 pr_debug("MAC address " MAC_FMT "\n",
401 lec_h->h_dest[0], lec_h->h_dest[1],
402 lec_h->h_dest[2], lec_h->h_dest[3],
403 lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 lec_send(vcc, skb, priv);
408
409 if (!atm_may_send(vcc, 0)) {
410 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
411
412 vpriv->xoff = 1;
413 netif_stop_queue(dev);
414
415 /*
416 * vcc->pop() might have occurred in between, making
417 * the vcc usuable again. Since xmit is serialized,
418 * this is the only situation we have to re-test.
419 */
420
421 if (atm_may_send(vcc, 0))
422 netif_wake_queue(dev);
423 }
424
Chas Williams6656e3c2006-09-29 17:17:17 -0700425out:
426 if (entry)
427 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700429 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700433static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 netif_stop_queue(dev);
436 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439/*
440 * Get the current statistics.
441 * This may be called with the card open or closed.
442 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700443static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Chas Williamsd44f7742006-09-29 17:11:14 -0700445 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Chas Williamsd44f7742006-09-29 17:11:14 -0700448static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700451 struct net_device *dev = (struct net_device *)vcc->proto_data;
452 struct lec_priv *priv = (struct lec_priv *)dev->priv;
453 struct atmlec_msg *mesg;
454 struct lec_arp_table *entry;
455 int i;
456 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700459 mesg = (struct atmlec_msg *)skb->data;
460 tmp = skb->data;
461 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700462 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700463 switch (mesg->type) {
464 case l_set_mac_addr:
465 for (i = 0; i < 6; i++) {
466 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
467 }
468 break;
469 case l_del_mac_addr:
470 for (i = 0; i < 6; i++) {
471 dev->dev_addr[i] = 0;
472 }
473 break;
474 case l_addr_delete:
475 lec_addr_delete(priv, mesg->content.normal.atm_addr,
476 mesg->content.normal.flag);
477 break;
478 case l_topology_change:
479 priv->topology_change = mesg->content.normal.flag;
480 break;
481 case l_flush_complete:
482 lec_flush_complete(priv, mesg->content.normal.flag);
483 break;
484 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700486 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
487 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
489
Chas Williamsd44f7742006-09-29 17:11:14 -0700490 if (mesg->content.normal.no_source_le_narp)
491 break;
492 /* FALL THROUGH */
493 case l_arp_update:
494 lec_arp_update(priv, mesg->content.normal.mac_addr,
495 mesg->content.normal.atm_addr,
496 mesg->content.normal.flag,
497 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700498 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700499 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700500 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700501 mesg->sizeoftlvs);
502 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
503 tmp, mesg->sizeoftlvs);
504 }
505 break;
506 case l_config:
507 priv->maximum_unknown_frame_count =
508 mesg->content.config.maximum_unknown_frame_count;
509 priv->max_unknown_frame_time =
510 (mesg->content.config.max_unknown_frame_time * HZ);
511 priv->max_retry_count = mesg->content.config.max_retry_count;
512 priv->aging_time = (mesg->content.config.aging_time * HZ);
513 priv->forward_delay_time =
514 (mesg->content.config.forward_delay_time * HZ);
515 priv->arp_response_time =
516 (mesg->content.config.arp_response_time * HZ);
517 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
518 priv->path_switching_delay =
519 (mesg->content.config.path_switching_delay * HZ);
520 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 priv->lane2_ops = NULL;
522 if (priv->lane_version > 1)
523 priv->lane2_ops = &lane2_ops;
524 if (dev->change_mtu(dev, mesg->content.config.mtu))
525 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700526 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700528 break;
529 case l_flush_tran_id:
530 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
531 mesg->content.normal.flag);
532 break;
533 case l_set_lecid:
534 priv->lecid =
535 (unsigned short)(0xffff & mesg->content.normal.flag);
536 break;
537 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 {
540 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Stephen Hemminger52240062007-08-28 15:22:09 -0700542 pr_debug
David S. Miller21f644f2008-04-08 16:50:44 -0700543 ("%s: bridge zeppelin asks about " MAC_FMT "\n",
Joe Perches0795af52007-10-03 17:59:30 -0700544 dev->name,
David S. Miller21f644f2008-04-08 16:50:44 -0700545 mesg->content.proxy.mac_addr[0],
546 mesg->content.proxy.mac_addr[1],
547 mesg->content.proxy.mac_addr[2],
548 mesg->content.proxy.mac_addr[3],
549 mesg->content.proxy.mac_addr[4],
550 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
553 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Chas Williamsd44f7742006-09-29 17:11:14 -0700555 f = br_fdb_get_hook(dev->br_port->br,
556 mesg->content.proxy.mac_addr);
557 if (f != NULL && f->dst->dev != dev
558 && f->dst->state == BR_STATE_FORWARDING) {
559 /* hit from bridge table, send LE_ARP_RESPONSE */
560 struct sk_buff *skb2;
561 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Stephen Hemminger52240062007-08-28 15:22:09 -0700563 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700564 ("%s: entry found, responding to zeppelin\n",
565 dev->name);
566 skb2 =
567 alloc_skb(sizeof(struct atmlec_msg),
568 GFP_ATOMIC);
569 if (skb2 == NULL) {
570 br_fdb_put_hook(f);
571 break;
572 }
573 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300574 skb_copy_to_linear_data(skb2, mesg,
575 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700576 atm_force_charge(priv->lecd, skb2->truesize);
577 sk = sk_atm(priv->lecd);
578 skb_queue_tail(&sk->sk_receive_queue, skb2);
579 sk->sk_data_ready(sk, skb2->len);
580 }
581 if (f != NULL)
582 br_fdb_put_hook(f);
583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700585 break;
586 default:
587 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
588 dev_kfree_skb(skb);
589 return -EINVAL;
590 }
591 dev_kfree_skb(skb);
592 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Chas Williamsd44f7742006-09-29 17:11:14 -0700595static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Chas Williamsd44f7742006-09-29 17:11:14 -0700597 struct sk_buff *skb;
598 struct net_device *dev = (struct net_device *)vcc->proto_data;
599 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Chas Williamsd44f7742006-09-29 17:11:14 -0700601 priv->lecd = NULL;
602 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 netif_stop_queue(dev);
605 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 dev->name);
610 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
611 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700613 }
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700616 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
619static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700620 .close = lec_atm_close,
621 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622};
623
624static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700625 .ops = &lecdev_ops,
626 .type = "lec",
627 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700628 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629};
630
631/*
632 * LANE2: new argument struct sk_buff *data contains
633 * the LE_ARP based TLVs introduced in the LANE2 spec
634 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700635static int
636send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700637 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700638 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 struct sock *sk;
641 struct sk_buff *skb;
642 struct atmlec_msg *mesg;
643
644 if (!priv || !priv->lecd) {
645 return -1;
646 }
647 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
648 if (!skb)
649 return -1;
650 skb->len = sizeof(struct atmlec_msg);
651 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 if (data != NULL)
655 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (mac_addr)
657 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700658 else
659 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (atm_addr)
661 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
662
Chas Williamsd44f7742006-09-29 17:11:14 -0700663 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 sk = sk_atm(priv->lecd);
665 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700666 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Chas Williamsd44f7742006-09-29 17:11:14 -0700668 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700669 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 atm_force_charge(priv->lecd, data->truesize);
671 skb_queue_tail(&sk->sk_receive_queue, data);
672 sk->sk_data_ready(sk, skb->len);
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Chas Williamsd44f7742006-09-29 17:11:14 -0700675 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678/* shamelessly stolen from drivers/net/net_init.c */
679static int lec_change_mtu(struct net_device *dev, int new_mtu)
680{
Chas Williamsd44f7742006-09-29 17:11:14 -0700681 if ((new_mtu < 68) || (new_mtu > 18190))
682 return -EINVAL;
683 dev->mtu = new_mtu;
684 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
687static void lec_set_multicast_list(struct net_device *dev)
688{
Chas Williamsd44f7742006-09-29 17:11:14 -0700689 /*
690 * by default, all multicast frames arrive over the bus.
691 * eventually support selective multicast service
692 */
693 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
Chas Williamsd44f7742006-09-29 17:11:14 -0700696static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Chas Williamsd44f7742006-09-29 17:11:14 -0700698 dev->change_mtu = lec_change_mtu;
699 dev->open = lec_open;
700 dev->stop = lec_close;
701 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 dev->tx_timeout = lec_tx_timeout;
703
Chas Williamsd44f7742006-09-29 17:11:14 -0700704 dev->get_stats = lec_get_stats;
705 dev->set_multicast_list = lec_set_multicast_list;
706 dev->do_ioctl = NULL;
707 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700710static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700711 0xff,
712 0x00,
713 0x01,
714 0x01
715};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Scott Talbert4a7097f2005-09-29 17:30:54 -0700717#define LEC_DATA_DIRECT_8023 2
718#define LEC_DATA_DIRECT_8025 3
719
720static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700721{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700722 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
723 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700724}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700725
Chas Williamsd44f7742006-09-29 17:11:14 -0700726static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700728 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 struct net_device *dev = (struct net_device *)vcc->proto_data;
730 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700733 int i = 0;
734 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Chas Williamsd44f7742006-09-29 17:11:14 -0700736 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
737 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700739 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700740 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 lec_vcc_close(priv, vcc);
742 return;
743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
746 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700748 for (i = 0; i < skb->len && i < 99; i++) {
749 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700752 for (i = 0; i < skb->len && i < 30; i++) {
753 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700756 if (i == skb->len)
757 printk("%s\n", buf);
758 else
759 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700761 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 struct sock *sk = sk_atm(vcc);
763
Stephen Hemminger52240062007-08-28 15:22:09 -0700764 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700765 skb_queue_tail(&sk->sk_receive_queue, skb);
766 sk->sk_data_ready(sk, skb->len);
767 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700768 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700769 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Chas Williamsd44f7742006-09-29 17:11:14 -0700771 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800772 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 !priv->lecd || !(dev->flags & IFF_UP)) {
774 /*
775 * Probably looping back, or if lecd is missing,
776 * lecd has gone down
777 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700778 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700779 dev_kfree_skb(skb);
780 return;
781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700783 if (priv->is_trdev)
784 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
785 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700787 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700788
Chas Williamsd44f7742006-09-29 17:11:14 -0700789 /*
790 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700791 * the LE_ARP cache entry, delete the LE_ARP cache entry.
792 */
793 spin_lock_irqsave(&priv->lec_arp_lock, flags);
794 if (lec_is_data_direct(vcc)) {
795#ifdef CONFIG_TR
796 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700797 src =
798 ((struct lecdatahdr_8025 *)skb->data)->
799 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700800 else
801#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700802 src =
803 ((struct lecdatahdr_8023 *)skb->data)->
804 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700805 entry = lec_arp_find(priv, src);
806 if (entry && entry->vcc != vcc) {
807 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700808 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700809 }
810 }
811 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Chas Williamsd44f7742006-09-29 17:11:14 -0700813 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
814 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700816 dev_kfree_skb(skb);
817 return;
818 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700819 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700820 lec_arp_check_empties(priv, vcc, skb);
821 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700822 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700824 if (priv->is_trdev)
825 skb->protocol = tr_type_trans(skb, dev);
826 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700828 skb->protocol = eth_type_trans(skb, dev);
829 priv->stats.rx_packets++;
830 priv->stats.rx_bytes += skb->len;
831 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
832 netif_rx(skb);
833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
Chas Williamsd44f7742006-09-29 17:11:14 -0700836static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
839 struct net_device *dev = skb->dev;
840
841 if (vpriv == NULL) {
842 printk("lec_pop(): vpriv = NULL!?!?!?\n");
843 return;
844 }
845
846 vpriv->old_pop(vcc, skb);
847
848 if (vpriv->xoff && atm_may_send(vcc, 0)) {
849 vpriv->xoff = 0;
850 if (netif_running(dev) && netif_queue_stopped(dev))
851 netif_wake_queue(dev);
852 }
853}
854
Chas Williamsd44f7742006-09-29 17:11:14 -0700855static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700858 int bytes_left;
859 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Chas Williamsd44f7742006-09-29 17:11:14 -0700861 /* Lecd must be up in this case */
862 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
863 if (bytes_left != 0) {
864 printk
865 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
866 bytes_left);
867 }
868 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
869 !dev_lec[ioc_data.dev_num])
870 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
872 return -ENOMEM;
873 vpriv->xoff = 0;
874 vpriv->old_pop = vcc->pop;
875 vcc->user_back = vpriv;
876 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700877 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
878 &ioc_data, vcc, vcc->push);
879 vcc->proto_data = dev_lec[ioc_data.dev_num];
880 vcc->push = lec_push;
881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Chas Williamsd44f7742006-09-29 17:11:14 -0700884static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Chas Williamsd44f7742006-09-29 17:11:14 -0700886 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
887 return -EINVAL;
888 vcc->proto_data = dev_lec[arg];
889 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
892/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700893static int lecd_attach(struct atm_vcc *vcc, int arg)
894{
895 int i;
896 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Chas Williamsd44f7742006-09-29 17:11:14 -0700898 if (arg < 0)
899 i = 0;
900 else
901 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700903 if (arg >= MAX_LEC_ITF)
904 return -EINVAL;
905#else /* Reserve the top NUM_TR_DEVS for TR */
906 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
907 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700909 if (!dev_lec[i]) {
910 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Chas Williamsd44f7742006-09-29 17:11:14 -0700912 is_trdev = 0;
913 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
914 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Chas Williamsd44f7742006-09-29 17:11:14 -0700916 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700918 if (is_trdev)
919 dev_lec[i] = alloc_trdev(size);
920 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700922 dev_lec[i] = alloc_etherdev(size);
923 if (!dev_lec[i])
924 return -ENOMEM;
925 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
926 if (register_netdev(dev_lec[i])) {
927 free_netdev(dev_lec[i]);
928 return -EINVAL;
929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Chas Williamsd44f7742006-09-29 17:11:14 -0700931 priv = dev_lec[i]->priv;
932 priv->is_trdev = is_trdev;
933 lec_init(dev_lec[i]);
934 } else {
935 priv = dev_lec[i]->priv;
936 if (priv->lecd)
937 return -EADDRINUSE;
938 }
939 lec_arp_init(priv);
940 priv->itfnum = i; /* LANE2 addition */
941 priv->lecd = vcc;
942 vcc->dev = &lecatm_dev;
943 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Chas Williamsd44f7742006-09-29 17:11:14 -0700945 vcc->proto_data = dev_lec[i];
946 set_bit(ATM_VF_META, &vcc->flags);
947 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Chas Williamsd44f7742006-09-29 17:11:14 -0700949 /* Set default values to these variables */
950 priv->maximum_unknown_frame_count = 1;
951 priv->max_unknown_frame_time = (1 * HZ);
952 priv->vcc_timeout_period = (1200 * HZ);
953 priv->max_retry_count = 1;
954 priv->aging_time = (300 * HZ);
955 priv->forward_delay_time = (15 * HZ);
956 priv->topology_change = 0;
957 priv->arp_response_time = (1 * HZ);
958 priv->flush_timeout = (4 * HZ);
959 priv->path_switching_delay = (6 * HZ);
960
961 if (dev_lec[i]->flags & IFF_UP) {
962 netif_start_queue(dev_lec[i]);
963 }
964 __module_get(THIS_MODULE);
965 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
968#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700969static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 static char *lec_arp_status_string[] = {
972 "ESI_UNKNOWN ",
973 "ESI_ARP_PENDING ",
974 "ESI_VC_PENDING ",
975 "<Undefined> ",
976 "ESI_FLUSH_PENDING ",
977 "ESI_FORWARD_DIRECT"
978 };
979
980 if (status > ESI_FORWARD_DIRECT)
981 status = 3; /* ESI_UNDEFINED */
982 return lec_arp_status_string[status];
983}
984
985static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
986{
987 int i;
988
989 for (i = 0; i < ETH_ALEN; i++)
990 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
991 seq_printf(seq, " ");
992 for (i = 0; i < ATM_ESA_LEN; i++)
993 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
994 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
995 entry->flags & 0xffff);
996 if (entry->vcc)
997 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
998 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700999 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (entry->recv_vcc) {
1001 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1002 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -07001003 }
1004 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007struct lec_state {
1008 unsigned long flags;
1009 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001010 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 struct net_device *dev;
1012 int itf;
1013 int arp_table;
1014 int misc_table;
1015};
1016
Chas Williamsd0732f62006-09-29 17:14:27 -07001017static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 loff_t *l)
1019{
Chas Williamsd0732f62006-09-29 17:14:27 -07001020 struct hlist_node *e = state->node;
1021 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001024 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -07001025 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001026 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 --*l;
1028 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001029
1030 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (--*l < 0)
1032 break;
1033 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001034 state->node = e;
1035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 return (*l < 0) ? state : NULL;
1037}
1038
1039static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001040 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 void *v = NULL;
1043 int p;
1044
1045 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001046 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (v)
1048 break;
1049 }
1050 state->arp_table = p;
1051 return v;
1052}
1053
1054static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1055 struct lec_priv *priv)
1056{
Chas Williamsd0732f62006-09-29 17:14:27 -07001057 struct hlist_head *lec_misc_tables[] = {
1058 &priv->lec_arp_empty_ones,
1059 &priv->lec_no_forward,
1060 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 };
1062 void *v = NULL;
1063 int q;
1064
1065 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1066 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1067 if (v)
1068 break;
1069 }
1070 state->misc_table = q;
1071 return v;
1072}
1073
1074static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1075 struct lec_priv *priv)
1076{
1077 if (!state->locked) {
1078 state->locked = priv;
1079 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1080 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001081 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1083 state->locked = NULL;
1084 /* Partial state reset for the next time we get called */
1085 state->arp_table = state->misc_table = 0;
1086 }
1087 return state->locked;
1088}
1089
1090static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1091{
1092 struct net_device *dev;
1093 void *v;
1094
1095 dev = state->dev ? state->dev : dev_lec[state->itf];
1096 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1097 if (!v && dev) {
1098 dev_put(dev);
1099 /* Partial state reset for the next time we get called */
1100 dev = NULL;
1101 }
1102 state->dev = dev;
1103 return v;
1104}
1105
1106static void *lec_get_idx(struct lec_state *state, loff_t l)
1107{
1108 void *v = NULL;
1109
1110 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1111 v = lec_itf_walk(state, &l);
1112 if (v)
1113 break;
1114 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001115 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1119{
1120 struct lec_state *state = seq->private;
1121
1122 state->itf = 0;
1123 state->dev = NULL;
1124 state->locked = NULL;
1125 state->arp_table = 0;
1126 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001127 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Joe Perches2e1e9842008-04-10 03:33:03 -07001129 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
1132static void lec_seq_stop(struct seq_file *seq, void *v)
1133{
1134 struct lec_state *state = seq->private;
1135
1136 if (state->dev) {
1137 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1138 state->flags);
1139 dev_put(state->dev);
1140 }
1141}
1142
1143static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1144{
1145 struct lec_state *state = seq->private;
1146
1147 v = lec_get_idx(state, 1);
1148 *pos += !!PTR_ERR(v);
1149 return v;
1150}
1151
1152static int lec_seq_show(struct seq_file *seq, void *v)
1153{
Chas Williamsd44f7742006-09-29 17:11:14 -07001154 static char lec_banner[] = "Itf MAC ATM destination"
1155 " Status Flags "
1156 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Joe Perches2e1e9842008-04-10 03:33:03 -07001158 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 seq_puts(seq, lec_banner);
1160 else {
1161 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001162 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001163 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001166 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
1168 return 0;
1169}
1170
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001171static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001172 .start = lec_seq_start,
1173 .next = lec_seq_next,
1174 .stop = lec_seq_stop,
1175 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176};
1177
1178static int lec_seq_open(struct inode *inode, struct file *file)
1179{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001180 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181}
1182
Arjan van de Ven9a321442007-02-12 00:55:35 -08001183static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001184 .owner = THIS_MODULE,
1185 .open = lec_seq_open,
1186 .read = seq_read,
1187 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001188 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189};
1190#endif
1191
1192static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1193{
1194 struct atm_vcc *vcc = ATM_SD(sock);
1195 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001198 case ATMLEC_CTRL:
1199 case ATMLEC_MCAST:
1200 case ATMLEC_DATA:
1201 if (!capable(CAP_NET_ADMIN))
1202 return -EPERM;
1203 break;
1204 default:
1205 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207
1208 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001209 case ATMLEC_CTRL:
1210 err = lecd_attach(vcc, (int)arg);
1211 if (err >= 0)
1212 sock->state = SS_CONNECTED;
1213 break;
1214 case ATMLEC_MCAST:
1215 err = lec_mcast_attach(vcc, (int)arg);
1216 break;
1217 case ATMLEC_DATA:
1218 err = lec_vcc_attach(vcc, (void __user *)arg);
1219 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
1221
1222 return err;
1223}
1224
1225static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001226 .owner = THIS_MODULE,
1227 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228};
1229
1230static int __init lane_module_init(void)
1231{
1232#ifdef CONFIG_PROC_FS
1233 struct proc_dir_entry *p;
1234
Wang Chen16e297b2008-02-28 13:55:45 -08001235 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001236 if (!p) {
1237 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1238 return -ENOMEM;
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240#endif
1241
1242 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001243 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247static void __exit lane_module_cleanup(void)
1248{
Chas Williamsd44f7742006-09-29 17:11:14 -07001249 int i;
1250 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
1252 remove_proc_entry("lec", atm_proc_root);
1253
1254 deregister_atm_ioctl(&lane_ioctl_ops);
1255
Chas Williamsd44f7742006-09-29 17:11:14 -07001256 for (i = 0; i < MAX_LEC_ITF; i++) {
1257 if (dev_lec[i] != NULL) {
1258 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 free_netdev(dev_lec[i]);
1261 dev_lec[i] = NULL;
1262 }
1263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
1268module_init(lane_module_init);
1269module_exit(lane_module_cleanup);
1270
1271/*
1272 * LANE2: 3.1.3, LE_RESOLVE.request
1273 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1274 * If sizeoftlvs == NULL the default TLVs associated with with this
1275 * lec will be used.
1276 * If dst_mac == NULL, targetless LE_ARP will be sent
1277 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001278static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001279 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
1281 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1283 struct lec_arp_table *table;
1284 struct sk_buff *skb;
1285 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Chas Williamsd44f7742006-09-29 17:11:14 -07001287 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001289 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001291 if (table == NULL)
1292 return -1;
1293
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001294 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001295 if (*tlvs == NULL)
1296 return -1;
1297
Chas Williamsd44f7742006-09-29 17:11:14 -07001298 *sizeoftlvs = table->sizeoftlvs;
1299
1300 return 0;
1301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 if (sizeoftlvs == NULL)
1304 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 else {
1307 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1308 if (skb == NULL)
1309 return -1;
1310 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001311 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1313 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001314 return retval;
1315}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317/*
1318 * LANE2: 3.1.4, LE_ASSOCIATE.request
1319 * Associate the *tlvs with the *lan_dst address.
1320 * Will overwrite any previous association
1321 * Returns 1 for success, 0 for failure (out of memory)
1322 *
1323 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001324static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1325 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Chas Williamsd44f7742006-09-29 17:11:14 -07001327 int retval;
1328 struct sk_buff *skb;
1329 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Chas Williamsd44f7742006-09-29 17:11:14 -07001331 if (compare_ether_addr(lan_dst, dev->dev_addr))
1332 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Chas Williamsd44f7742006-09-29 17:11:14 -07001334 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001336 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001337 if (priv->tlvs == NULL)
1338 return (0);
1339 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Chas Williamsd44f7742006-09-29 17:11:14 -07001341 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1342 if (skb == NULL)
1343 return 0;
1344 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001345 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001346 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1347 if (retval != 0)
1348 printk("lec.c: lane2_associate_req() failed\n");
1349 /*
1350 * If the previous association has changed we must
1351 * somehow notify other LANE entities about the change
1352 */
1353 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
1356/*
1357 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1358 *
1359 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001360static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1361 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
1363#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001364 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365#endif
1366 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001367#if 0 /*
1368 * Why have the TLVs in LE_ARP entries
1369 * since we do not use them? When you
1370 * uncomment this code, make sure the
1371 * TLVs get freed when entry is killed
1372 */
1373 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Chas Williamsd44f7742006-09-29 17:11:14 -07001375 if (entry == NULL)
1376 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Chas Williamsd44f7742006-09-29 17:11:14 -07001378 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001380 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001381 if (entry->tlvs == NULL)
1382 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001383 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384#endif
1385#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001386 printk("lec.c: lane2_associate_ind()\n");
1387 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1388 while (i < sizeoftlvs)
1389 printk("%02x ", tlvs[i++]);
1390
1391 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392#endif
1393
Chas Williamsd44f7742006-09-29 17:11:14 -07001394 /* tell MPOA about the TLVs we saw */
1395 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1396 priv->lane2_ops->associate_indicator(dev, mac_addr,
1397 tlvs, sizeoftlvs);
1398 }
1399 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
1402/*
1403 * Here starts what used to lec_arpc.c
1404 *
1405 * lec_arpc.c was added here when making
1406 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 */
1408
1409#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410#include <linux/timer.h>
1411#include <asm/param.h>
1412#include <asm/atomic.h>
1413#include <linux/inetdevice.h>
1414#include <net/route.h>
1415
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001417#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001419#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420*/
1421#endif
1422#define DEBUG_ARP_TABLE 0
1423
1424#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1425
David Howellsc4028952006-11-22 14:57:56 +00001426static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427static void lec_arp_expire_arp(unsigned long data);
1428
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001429/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 * Arp table funcs
1431 */
1432
1433#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1434
1435/*
1436 * Initialization of arp-cache
1437 */
Chas Williams1fa99612006-09-29 17:11:47 -07001438static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Chas Williams1fa99612006-09-29 17:11:47 -07001440 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Chas Williams1fa99612006-09-29 17:11:47 -07001442 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001443 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001444 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001445 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1446 INIT_HLIST_HEAD(&priv->lec_no_forward);
1447 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001449 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001450 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451}
1452
Chas Williams1fa99612006-09-29 17:11:47 -07001453static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Chas Williams1fa99612006-09-29 17:11:47 -07001455 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 struct atm_vcc *vcc = entry->vcc;
1457 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001458 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Chas Williams1fa99612006-09-29 17:11:47 -07001460 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 if (vpriv->xoff)
1462 netif_wake_queue(dev);
1463 kfree(vpriv);
1464 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001465 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001467 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001468 }
1469 if (entry->recv_vcc) {
1470 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001472 entry->recv_vcc = NULL;
1473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
1476/*
1477 * Insert entry to lec_arp_table
1478 * LANE2: Add to the end of the list to satisfy 8.1.13
1479 */
Chas Williams1fa99612006-09-29 17:11:47 -07001480static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001481lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Chas Williamsd0732f62006-09-29 17:14:27 -07001483 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Chas Williamsd0732f62006-09-29 17:14:27 -07001485 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1486 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001487
Stephen Hemminger52240062007-08-28 15:22:09 -07001488 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 -07001489 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1490 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1491 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
1494/*
1495 * Remove entry from lec_arp_table
1496 */
Chas Williams1fa99612006-09-29 17:11:47 -07001497static int
1498lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Chas Williamsd0732f62006-09-29 17:14:27 -07001500 struct hlist_node *node;
1501 struct lec_arp_table *entry;
1502 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Chas Williams1fa99612006-09-29 17:11:47 -07001504 if (!to_remove) {
1505 return -1;
1506 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001507
1508 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001509 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Chas Williamsd0732f62006-09-29 17:14:27 -07001511 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001512 if (to_remove->status >= ESI_FLUSH_PENDING) {
1513 /*
1514 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1515 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001516 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1517 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1518 if (memcmp(to_remove->atm_addr,
1519 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001520 remove_vcc = 0;
1521 break;
1522 }
1523 }
1524 }
1525 if (remove_vcc)
1526 lec_arp_clear_vccs(to_remove);
1527 }
1528 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1529
Stephen Hemminger52240062007-08-28 15:22:09 -07001530 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 -07001531 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1532 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1533 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
1537#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001538static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Chas Williams1fa99612006-09-29 17:11:47 -07001540 switch (st) {
1541 case ESI_UNKNOWN:
1542 return "ESI_UNKNOWN";
1543 case ESI_ARP_PENDING:
1544 return "ESI_ARP_PENDING";
1545 case ESI_VC_PENDING:
1546 return "ESI_VC_PENDING";
1547 case ESI_FLUSH_PENDING:
1548 return "ESI_FLUSH_PENDING";
1549 case ESI_FORWARD_DIRECT:
1550 return "ESI_FORWARD_DIRECT";
1551 default:
1552 return "<UNKNOWN>";
1553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Chas Williams1fa99612006-09-29 17:11:47 -07001556static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Chas Williamsd0732f62006-09-29 17:14:27 -07001558 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001559 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001560 char buf[256];
1561 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Chas Williams1fa99612006-09-29 17:11:47 -07001563 printk("Dump %p:\n", priv);
1564 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001565 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1566 offset = 0;
1567 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001568 offset += sprintf(buf + offset, "Mac:");
1569 for (j = 0; j < ETH_ALEN; j++) {
1570 offset += sprintf(buf + offset,
1571 "%2.2x ",
1572 rulla->mac_addr[j] & 0xff);
1573 }
1574 offset += sprintf(buf + offset, "Atm:");
1575 for (j = 0; j < ATM_ESA_LEN; j++) {
1576 offset += sprintf(buf + offset,
1577 "%2.2x ",
1578 rulla->atm_addr[j] & 0xff);
1579 }
1580 offset += sprintf(buf + offset,
1581 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1582 rulla->vcc ? rulla->vcc->vpi : 0,
1583 rulla->vcc ? rulla->vcc->vci : 0,
1584 rulla->recv_vcc ? rulla->recv_vcc->
1585 vpi : 0,
1586 rulla->recv_vcc ? rulla->recv_vcc->
1587 vci : 0, rulla->last_used,
1588 rulla->timestamp, rulla->no_tries);
1589 offset +=
1590 sprintf(buf + offset,
1591 "Flags:%x, Packets_flooded:%x, Status: %s ",
1592 rulla->flags, rulla->packets_flooded,
1593 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001594 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001595 }
Chas Williams1fa99612006-09-29 17:11:47 -07001596 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001597
1598 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001599 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001600 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001601 offset = 0;
1602 offset += sprintf(buf + offset, "Mac:");
1603 for (j = 0; j < ETH_ALEN; j++) {
1604 offset += sprintf(buf + offset, "%2.2x ",
1605 rulla->mac_addr[j] & 0xff);
1606 }
1607 offset += sprintf(buf + offset, "Atm:");
1608 for (j = 0; j < ATM_ESA_LEN; j++) {
1609 offset += sprintf(buf + offset, "%2.2x ",
1610 rulla->atm_addr[j] & 0xff);
1611 }
1612 offset += sprintf(buf + offset,
1613 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1614 rulla->vcc ? rulla->vcc->vpi : 0,
1615 rulla->vcc ? rulla->vcc->vci : 0,
1616 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1617 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1618 rulla->last_used,
1619 rulla->timestamp, rulla->no_tries);
1620 offset += sprintf(buf + offset,
1621 "Flags:%x, Packets_flooded:%x, Status: %s ",
1622 rulla->flags, rulla->packets_flooded,
1623 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001624 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001625 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001626
1627 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001628 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001629 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001630 offset = 0;
1631 offset += sprintf(buf + offset, "Mac:");
1632 for (j = 0; j < ETH_ALEN; j++) {
1633 offset += sprintf(buf + offset, "%2.2x ",
1634 rulla->mac_addr[j] & 0xff);
1635 }
1636 offset += sprintf(buf + offset, "Atm:");
1637 for (j = 0; j < ATM_ESA_LEN; j++) {
1638 offset += sprintf(buf + offset, "%2.2x ",
1639 rulla->atm_addr[j] & 0xff);
1640 }
1641 offset += sprintf(buf + offset,
1642 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1643 rulla->vcc ? rulla->vcc->vpi : 0,
1644 rulla->vcc ? rulla->vcc->vci : 0,
1645 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1646 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1647 rulla->last_used,
1648 rulla->timestamp, rulla->no_tries);
1649 offset += sprintf(buf + offset,
1650 "Flags:%x, Packets_flooded:%x, Status: %s ",
1651 rulla->flags, rulla->packets_flooded,
1652 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001653 printk("%s", buf);
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Chas Williamsd0732f62006-09-29 17:14:27 -07001656 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001657 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001658 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001659 offset = 0;
1660 offset += sprintf(buf + offset, "Mac:");
1661 for (j = 0; j < ETH_ALEN; j++) {
1662 offset += sprintf(buf + offset, "%2.2x ",
1663 rulla->mac_addr[j] & 0xff);
1664 }
1665 offset += sprintf(buf + offset, "Atm:");
1666 for (j = 0; j < ATM_ESA_LEN; j++) {
1667 offset += sprintf(buf + offset, "%2.2x ",
1668 rulla->atm_addr[j] & 0xff);
1669 }
1670 offset += sprintf(buf + offset,
1671 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1672 rulla->vcc ? rulla->vcc->vpi : 0,
1673 rulla->vcc ? rulla->vcc->vci : 0,
1674 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1675 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1676 rulla->last_used,
1677 rulla->timestamp, rulla->no_tries);
1678 offset += sprintf(buf + offset,
1679 "Flags:%x, Packets_flooded:%x, Status: %s ",
1680 rulla->flags, rulla->packets_flooded,
1681 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001682 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
Chas Williamsd0732f62006-09-29 17:14:27 -07001686#else
1687#define dump_arp_table(priv) do { } while (0)
1688#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690/*
1691 * Destruction of arp-cache
1692 */
Chas Williams1fa99612006-09-29 17:11:47 -07001693static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001696 struct hlist_node *node, *next;
1697 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001698 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Chas Williams987e46b2006-09-29 17:15:59 -07001700 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001701
1702 /*
1703 * Remove all entries
1704 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001707 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001708 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001709 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001710 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001711 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001712 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001713 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001714
1715 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001716 del_timer_sync(&entry->timer);
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->lec_arp_empty_ones);
1722
1723 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001724 del_timer_sync(&entry->timer);
1725 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001726 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001727 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001728 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001729 INIT_HLIST_HEAD(&priv->lec_no_forward);
1730
1731 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001732 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1733 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001735 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001736 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001737 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001738 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1740}
1741
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001742/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 * Find entry by mac_address
1744 */
Chas Williams1fa99612006-09-29 17:11:47 -07001745static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001746 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Chas Williamsd0732f62006-09-29 17:14:27 -07001748 struct hlist_node *node;
1749 struct hlist_head *head;
1750 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Stephen Hemminger52240062007-08-28 15:22:09 -07001752 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 -07001753 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1754 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001755
Chas Williamsd0732f62006-09-29 17:14:27 -07001756 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1757 hlist_for_each_entry(entry, node, head, next) {
1758 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1759 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001760 }
Chas Williams1fa99612006-09-29 17:11:47 -07001761 }
1762 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763}
1764
Chas Williams1fa99612006-09-29 17:11:47 -07001765static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001766 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
Chas Williams1fa99612006-09-29 17:11:47 -07001768 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Chas Williams1fa99612006-09-29 17:11:47 -07001770 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1771 if (!to_return) {
1772 printk("LEC: Arp entry kmalloc failed\n");
1773 return NULL;
1774 }
1775 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001776 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001777 setup_timer(&to_return->timer, lec_arp_expire_arp,
1778 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001779 to_return->last_used = jiffies;
1780 to_return->priv = priv;
1781 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001782 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001783 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784}
1785
Chas Williams1fa99612006-09-29 17:11:47 -07001786/* Arp sent timer expired */
1787static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
Chas Williams1fa99612006-09-29 17:11:47 -07001789 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Chas Williams1fa99612006-09-29 17:11:47 -07001791 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Stephen Hemminger52240062007-08-28 15:22:09 -07001793 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001794 if (entry->status == ESI_ARP_PENDING) {
1795 if (entry->no_tries <= entry->priv->max_retry_count) {
1796 if (entry->is_rdesc)
1797 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1798 entry->mac_addr, NULL, NULL);
1799 else
1800 send_to_lecd(entry->priv, l_arp_xmt,
1801 entry->mac_addr, NULL, NULL);
1802 entry->no_tries++;
1803 }
1804 mod_timer(&entry->timer, jiffies + (1 * HZ));
1805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
Chas Williams1fa99612006-09-29 17:11:47 -07001808/* Unknown/unused vcc expire, remove associated entry */
1809static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
1811 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001812 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1813 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Chas Williams1fa99612006-09-29 17:11:47 -07001815 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Stephen Hemminger52240062007-08-28 15:22:09 -07001817 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001818 to_remove, priv,
1819 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1820 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
1822 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001823 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1825
Chas Williams1fa99612006-09-29 17:11:47 -07001826 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001827 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
1830/*
1831 * Expire entries.
1832 * 1. Re-set timer
1833 * 2. For each entry, delete entries that have aged past the age limit.
1834 * 3. For each entry, depending on the status of the entry, perform
1835 * the following maintenance.
1836 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1837 * tick_count is above the max_unknown_frame_time, clear
1838 * the tick_count to zero and clear the packets_flooded counter
1839 * to zero. This supports the packet rate limit per address
1840 * while flooding unknowns.
1841 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1842 * than or equal to the path_switching_delay, change the status
1843 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1844 * regardless of the progress of the flush protocol.
1845 */
David Howellsc4028952006-11-22 14:57:56 +00001846static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847{
1848 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001849 struct lec_priv *priv =
1850 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001851 struct hlist_node *node, *next;
1852 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001853 unsigned long now;
1854 unsigned long time_to_check;
1855 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Stephen Hemminger52240062007-08-28 15:22:09 -07001857 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001859restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001861 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001862 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001863 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 priv->topology_change)
1865 time_to_check = priv->forward_delay_time;
1866 else
1867 time_to_check = priv->aging_time;
1868
Stephen Hemminger52240062007-08-28 15:22:09 -07001869 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001870 now, entry->last_used, time_to_check);
1871 if (time_after(now, entry->last_used + time_to_check)
1872 && !(entry->flags & LEC_PERMANENT_FLAG)
1873 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001875 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001877 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } else {
1879 /* Something else */
1880 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001881 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001883 entry->timestamp +
1884 priv->
1885 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 entry->timestamp = jiffies;
1887 entry->packets_flooded = 0;
1888 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001889 send_to_lecd(priv, l_svc_setup,
1890 entry->mac_addr,
1891 entry->atm_addr,
1892 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 }
Chas Williams1fa99612006-09-29 17:11:47 -07001894 if (entry->status == ESI_FLUSH_PENDING
1895 &&
1896 time_after_eq(now, entry->timestamp +
1897 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001899 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Chas Williams6656e3c2006-09-29 17:17:17 -07001901 lec_arp_hold(entry);
1902 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1903 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1904 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001906 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001907 lec_arp_put(entry);
1908 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 }
1911 }
1912 }
1913 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1914
Chas Williams987e46b2006-09-29 17:15:59 -07001915 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916}
Chas Williams1fa99612006-09-29 17:11:47 -07001917
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918/*
1919 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001920 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 */
Chas Williams1fa99612006-09-29 17:11:47 -07001922static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001923 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001924 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
1926 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001927 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 struct atm_vcc *found;
1929
Chas Williams1fa99612006-09-29 17:11:47 -07001930 if (mac_to_find[0] & 0x01) {
1931 switch (priv->lane_version) {
1932 case 1:
1933 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001934 case 2: /* LANE2 wants arp for multicast addresses */
1935 if (!compare_ether_addr(mac_to_find, bus_mac))
1936 return priv->mcast_vcc;
1937 break;
1938 default:
1939 break;
1940 }
1941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001944 entry = lec_arp_find(priv, mac_to_find);
1945
1946 if (entry) {
1947 if (entry->status == ESI_FORWARD_DIRECT) {
1948 /* Connection Ok */
1949 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001950 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001951 *ret_entry = entry;
1952 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001954 }
1955 /*
1956 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001957 * so another LE_ARP request can be made for this frame.
1958 */
1959 if (entry->status == ESI_ARP_PENDING) {
1960 entry->no_tries = 0;
1961 }
Chas Williams1fa99612006-09-29 17:11:47 -07001962 /*
1963 * Data direct VC not yet set up, check to see if the unknown
1964 * frame count is greater than the limit. If the limit has
1965 * not been reached, allow the caller to send packet to
1966 * BUS.
1967 */
1968 if (entry->status != ESI_FLUSH_PENDING &&
1969 entry->packets_flooded <
1970 priv->maximum_unknown_frame_count) {
1971 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001972 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001973 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001975 }
1976 /*
1977 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 * or BUS flood limit was reached for an entry which is
1979 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1980 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001981 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001982 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001983 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001984 entry->vcc);
1985 found = NULL;
1986 } else {
1987 /* No matching entry was found */
1988 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001989 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001990 if (!entry) {
1991 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001993 }
1994 lec_arp_add(priv, entry);
1995 /* We want arp-request(s) to be sent */
1996 entry->packets_flooded = 1;
1997 entry->status = ESI_ARP_PENDING;
1998 entry->no_tries = 1;
1999 entry->last_used = entry->timestamp = jiffies;
2000 entry->is_rdesc = is_rdesc;
2001 if (entry->is_rdesc)
2002 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2003 NULL);
2004 else
2005 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2006 entry->timer.expires = jiffies + (1 * HZ);
2007 entry->timer.function = lec_arp_expire_arp;
2008 add_timer(&entry->timer);
2009 found = priv->mcast_vcc;
2010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012out:
2013 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2014 return found;
2015}
2016
2017static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002018lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002019 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002022 struct hlist_node *node, *next;
2023 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002024 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
Stephen Hemminger52240062007-08-28 15:22:09 -07002026 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002028 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002029 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002030 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2031 && (permanent ||
2032 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002034 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002037 return 0;
2038 }
2039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002041 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042}
2043
2044/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002045 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 */
2047static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002048lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2049 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002050 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
2052 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002053 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002054 struct lec_arp_table *entry, *tmp;
2055 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
Stephen Hemminger52240062007-08-28 15:22:09 -07002057 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2058 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 -07002059 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2060 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002063 entry = lec_arp_find(priv, mac_addr);
2064 if (entry == NULL && targetless_le_arp)
2065 goto out; /*
2066 * LANE2: ignore targetless LE_ARPs for which
2067 * we have no entry in the cache. 7.1.30
2068 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002069 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2070 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2071 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2072 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002073 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002074 tmp = lec_arp_find(priv, mac_addr);
2075 if (tmp) {
2076 del_timer(&tmp->timer);
2077 tmp->status = ESI_FORWARD_DIRECT;
2078 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2079 tmp->vcc = entry->vcc;
2080 tmp->old_push = entry->old_push;
2081 tmp->last_used = jiffies;
2082 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002083 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002084 entry = tmp;
2085 } else {
2086 entry->status = ESI_FORWARD_DIRECT;
2087 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2088 entry->last_used = jiffies;
2089 lec_arp_add(priv, entry);
2090 }
2091 if (remoteflag)
2092 entry->flags |= LEC_REMOTE_FLAG;
2093 else
2094 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002095 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002096 dump_arp_table(priv);
2097 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002098 }
Chas Williams1fa99612006-09-29 17:11:47 -07002099 }
2100 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002101
Chas Williams1fa99612006-09-29 17:11:47 -07002102 entry = lec_arp_find(priv, mac_addr);
2103 if (!entry) {
2104 entry = make_entry(priv, mac_addr);
2105 if (!entry)
2106 goto out;
2107 entry->status = ESI_UNKNOWN;
2108 lec_arp_add(priv, entry);
2109 /* Temporary, changes before end of function */
2110 }
2111 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2112 del_timer(&entry->timer);
2113 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002114 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002115 if (entry != tmp &&
2116 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2117 /* Vcc to this host exists */
2118 if (tmp->status > ESI_VC_PENDING) {
2119 /*
2120 * ESI_FLUSH_PENDING,
2121 * ESI_FORWARD_DIRECT
2122 */
2123 entry->vcc = tmp->vcc;
2124 entry->old_push = tmp->old_push;
2125 }
2126 entry->status = tmp->status;
2127 break;
2128 }
2129 }
2130 }
2131 if (remoteflag)
2132 entry->flags |= LEC_REMOTE_FLAG;
2133 else
2134 entry->flags &= ~LEC_REMOTE_FLAG;
2135 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2136 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002137 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002138 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002139 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002140 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141out:
2142 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2143}
2144
2145/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002146 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 */
2148static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002149lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002150 struct atm_vcc *vcc,
2151 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002154 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002155 struct lec_arp_table *entry;
2156 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002159 if (ioc_data->receive == 2) {
2160 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Stephen Hemminger52240062007-08-28 15:22:09 -07002162 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002164 entry = lec_arp_find(priv, bus_mac);
2165 if (!entry) {
2166 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002168 }
2169 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2170 entry->recv_vcc = vcc;
2171 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002173 entry = make_entry(priv, bus_mac);
2174 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002176 del_timer(&entry->timer);
2177 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2178 entry->recv_vcc = vcc;
2179 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002180 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002181 goto out;
2182 } else if (ioc_data->receive == 1) {
2183 /*
2184 * Vcc which we don't want to make default vcc,
2185 * attach it anyway.
2186 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002187 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002188 ("LEC_ARP:Attaching data direct, not default: "
2189 "%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",
2190 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2191 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2192 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2193 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2194 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2195 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2196 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2197 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2198 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2199 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2200 entry = make_entry(priv, bus_mac);
2201 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002203 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2204 memset(entry->mac_addr, 0, ETH_ALEN);
2205 entry->recv_vcc = vcc;
2206 entry->old_recv_push = old_push;
2207 entry->status = ESI_UNKNOWN;
2208 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2209 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002210 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002211 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 dump_arp_table(priv);
2213 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002214 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002215 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002216 ("LEC_ARP:Attaching data direct, default: "
2217 "%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",
2218 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2219 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2220 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2221 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2222 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2223 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2224 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2225 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2226 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2227 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2228 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002229 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002230 if (memcmp
2231 (ioc_data->atm_addr, entry->atm_addr,
2232 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002233 pr_debug("LEC_ARP: Attaching data direct\n");
2234 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002235 entry->vcc ? entry->vcc->vci : 0,
2236 entry->recv_vcc ? entry->recv_vcc->
2237 vci : 0);
2238 found_entry = 1;
2239 del_timer(&entry->timer);
2240 entry->vcc = vcc;
2241 entry->old_push = old_push;
2242 if (entry->status == ESI_VC_PENDING) {
2243 if (priv->maximum_unknown_frame_count
2244 == 0)
2245 entry->status =
2246 ESI_FORWARD_DIRECT;
2247 else {
2248 entry->timestamp = jiffies;
2249 entry->status =
2250 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002252 send_to_lecd(priv, l_flush_xmt,
2253 NULL,
2254 entry->atm_addr,
2255 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002257 }
2258 } else {
2259 /*
2260 * They were forming a connection
2261 * to us, and we to them. Our
2262 * ATM address is numerically lower
2263 * than theirs, so we make connection
2264 * we formed into default VCC (8.1.11).
2265 * Connection they made gets torn
2266 * down. This might confuse some
2267 * clients. Can be changed if
2268 * someone reports trouble...
2269 */
2270 ;
2271 }
2272 }
2273 }
2274 }
2275 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002276 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002277 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002279 }
2280 /*
2281 * Not found, snatch address from first data packet that arrives
2282 * from this vcc
2283 */
2284 entry = make_entry(priv, bus_mac);
2285 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002287 entry->vcc = vcc;
2288 entry->old_push = old_push;
2289 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2290 memset(entry->mac_addr, 0, ETH_ALEN);
2291 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002292 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002293 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2294 entry->timer.function = lec_arp_expire_vcc;
2295 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002296 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 dump_arp_table(priv);
2298out:
2299 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2300}
2301
Chas Williams1fa99612006-09-29 17:11:47 -07002302static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
2304 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002305 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002306 struct lec_arp_table *entry;
2307 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Stephen Hemminger52240062007-08-28 15:22:09 -07002309 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002310restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002311 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2312 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002313 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002314 if (entry->flush_tran_id == tran_id
2315 && entry->status == ESI_FLUSH_PENDING) {
2316 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002317 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002318
Chas Williams6656e3c2006-09-29 17:17:17 -07002319 lec_arp_hold(entry);
2320 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2321 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2322 lec_send(vcc, skb, entry->priv);
2323 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002324 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002325 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002326 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002327 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002328 }
2329 }
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002332 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333}
2334
2335static void
2336lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002337 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
2339 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002340 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002341 struct lec_arp_table *entry;
2342 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
2344 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002345 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002346 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002347 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2348 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002349 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002350 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002351 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2354}
2355
Chas Williams1fa99612006-09-29 17:11:47 -07002356static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357{
2358 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002359 unsigned char mac_addr[] = {
2360 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2361 };
2362 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct lec_vcc_priv *vpriv;
2364 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2367 return -ENOMEM;
2368 vpriv->xoff = 0;
2369 vpriv->old_pop = vcc->pop;
2370 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002371 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002373 to_add = make_entry(priv, mac_addr);
2374 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 vcc->pop = vpriv->old_pop;
2376 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002377 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002379 }
2380 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2381 to_add->status = ESI_FORWARD_DIRECT;
2382 to_add->flags |= LEC_PERMANENT_FLAG;
2383 to_add->vcc = vcc;
2384 to_add->old_push = vcc->push;
2385 vcc->push = lec_push;
2386 priv->mcast_vcc = vcc;
2387 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388out:
2389 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002390 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
Chas Williams1fa99612006-09-29 17:11:47 -07002393static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
2395 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002396 struct hlist_node *node, *next;
2397 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002398 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Stephen Hemminger52240062007-08-28 15:22:09 -07002400 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002401 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002404
Chas Williams1fa99612006-09-29 17:11:47 -07002405 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002406 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002407 if (vcc == entry->vcc) {
2408 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002409 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002410 if (priv->mcast_vcc == vcc) {
2411 priv->mcast_vcc = NULL;
2412 }
2413 }
2414 }
2415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Chas Williamsd0732f62006-09-29 17:14:27 -07002417 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2418 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002419 lec_arp_clear_vccs(entry);
2420 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002421 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002422 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002423 }
Chas Williams1fa99612006-09-29 17:11:47 -07002424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Chas Williamsd0732f62006-09-29 17:14:27 -07002426 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002427 if (entry->recv_vcc == vcc) {
2428 lec_arp_clear_vccs(entry);
2429 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002430 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002431 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002432 }
Chas Williams1fa99612006-09-29 17:11:47 -07002433 }
2434
Chas Williamsd0732f62006-09-29 17:14:27 -07002435 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002436 if (entry->recv_vcc == vcc) {
2437 lec_arp_clear_vccs(entry);
2438 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002439 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002440 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002441 }
Chas Williams1fa99612006-09-29 17:11:47 -07002442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
2444 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2445 dump_arp_table(priv);
2446}
2447
2448static void
2449lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002450 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
Chas Williams1fa99612006-09-29 17:11:47 -07002452 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002453 struct hlist_node *node, *next;
2454 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002455 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2456 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002458 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Chas Williams1fa99612006-09-29 17:11:47 -07002460 if (priv->is_trdev)
2461 src = tr_hdr->h_source;
2462 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002464 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
2466 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002467 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2468 if (vcc == entry->vcc) {
2469 del_timer(&entry->timer);
2470 memcpy(entry->mac_addr, src, ETH_ALEN);
2471 entry->status = ESI_FORWARD_DIRECT;
2472 entry->last_used = jiffies;
2473 /* We might have got an entry */
2474 if ((tmp = lec_arp_find(priv, src))) {
2475 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002476 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002477 }
2478 hlist_del(&entry->next);
2479 lec_arp_add(priv, entry);
2480 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002481 }
Chas Williams1fa99612006-09-29 17:11:47 -07002482 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002483 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484out:
2485 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2486}
Chas Williams1fa99612006-09-29 17:11:47 -07002487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488MODULE_LICENSE("GPL");