blob: aefd278d6af6cbd3ea726498646d51d24fb6086a [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
Joe Perches99824462010-01-26 11:40:00 +00007#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080011#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13/* We are ethernet device */
14#include <linux/if_ether.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <net/sock.h>
18#include <linux/skbuff.h>
19#include <linux/ip.h>
20#include <asm/byteorder.h>
Joe Perchesc48192a2010-01-26 11:40:08 +000021#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <net/arp.h>
23#include <net/dst.h>
24#include <linux/proc_fs.h>
25#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/seq_file.h>
27
28/* TokenRing if needed */
29#ifdef CONFIG_TR
30#include <linux/trdevice.h>
31#endif
32
33/* And atm device */
34#include <linux/atmdev.h>
35#include <linux/atmlec.h>
36
37/* Proxy LEC knows about bridging */
38#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "../bridge/br_private.h"
40
Chas Williamsd44f7742006-09-29 17:11:14 -070041static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43
44/* Modular too */
45#include <linux/module.h>
46#include <linux/init.h>
47
48#include "lec.h"
49#include "lec_arpc.h"
50#include "resources.h"
51
Chas Williamsd44f7742006-09-29 17:11:14 -070052#define DUMP_PACKETS 0 /*
53 * 0 = None,
54 * 1 = 30 first bytes
55 * 2 = Whole packet
56 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Chas Williamsd44f7742006-09-29 17:11:14 -070058#define LEC_UNRES_QUE_LEN 8 /*
59 * number of tx packets to queue for a
60 * single destination while waiting for SVC
61 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63static int lec_open(struct net_device *dev);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000064static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
65 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static int lec_close(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,
Joe Perchesc48192a2010-01-26 11:40:08 +000090 const unsigned char *atm_addr,
91 unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 unsigned int targetless_le_arp);
93static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
94static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
95static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070096 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 unsigned long tran_id);
Joe Perchesc48192a2010-01-26 11:40:08 +000098static void lec_vcc_added(struct lec_priv *priv,
99 const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 struct atm_vcc *vcc,
Joe Perchesc48192a2010-01-26 11:40:08 +0000101 void (*old_push)(struct atm_vcc *vcc,
102 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
104
Chas Williams33a9c2d2006-09-29 17:16:48 -0700105/* must be done under lec_arp_lock */
106static inline void lec_arp_hold(struct lec_arp_table *entry)
107{
108 atomic_inc(&entry->usage);
109}
110
111static inline void lec_arp_put(struct lec_arp_table *entry)
112{
113 if (atomic_dec_and_test(&entry->usage))
114 kfree(entry);
115}
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700118 lane2_resolve, /* resolve, spec 3.1.3 */
119 lane2_associate_req, /* associate_req, spec 3.1.4 */
120 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
Chas Williamsd44f7742006-09-29 17:11:14 -0700123static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125/* Device structures */
126static struct net_device *dev_lec[MAX_LEC_ITF];
127
128#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
129static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
130{
Chas Williamsd44f7742006-09-29 17:11:14 -0700131 struct ethhdr *eth;
132 char *buff;
133 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Chas Williamsd44f7742006-09-29 17:11:14 -0700135 /*
136 * Check if this is a BPDU. If so, ask zeppelin to send
137 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
138 * as the Config BPDU has
139 */
140 eth = (struct ethhdr *)skb->data;
141 buff = skb->data + skb->dev->hard_header_len;
142 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700144 struct sk_buff *skb2;
145 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Chas Williamsd44f7742006-09-29 17:11:14 -0700147 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
148 if (skb2 == NULL)
149 return;
150 skb2->len = sizeof(struct atmlec_msg);
151 mesg = (struct atmlec_msg *)skb2->data;
152 mesg->type = l_topology_change;
153 buff += 4;
Joe Perchesc48192a2010-01-26 11:40:08 +0000154 mesg->content.normal.flag = *buff & 0x01;
155 /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Wang Chen524ad0a2008-11-12 23:39:10 -0800157 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700158 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700160 skb_queue_tail(&sk->sk_receive_queue, skb2);
161 sk->sk_data_ready(sk, skb2->len);
162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Chas Williamsd44f7742006-09-29 17:11:14 -0700164 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
167
168/*
169 * Modelled after tr_type_trans
170 * All multicast and ARE or STE frames go to BUS.
171 * Non source routed frames go by destination address.
172 * Last hop source routed frames go by destination address.
173 * Not last hop source routed frames go by _next_ route descriptor.
174 * Returns pointer to destination MAC address or fills in rdesc
175 * and returns NULL.
176 */
177#ifdef CONFIG_TR
178static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
179{
Chas Williamsd44f7742006-09-29 17:11:14 -0700180 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800181 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Chas Williamsd44f7742006-09-29 17:11:14 -0700183 trh = (struct trh_hdr *)packet;
184 if (trh->daddr[0] & (uint8_t) 0x80)
185 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Chas Williamsd44f7742006-09-29 17:11:14 -0700187 if (trh->saddr[0] & TR_RII) {
188 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
189 if ((ntohs(trh->rcf) >> 13) != 0)
190 return bus_mac; /* ARE or STE */
191 } else
192 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Chas Williamsd44f7742006-09-29 17:11:14 -0700194 if (riflen < 6)
195 return trh->daddr; /* last hop, source routed */
196
197 /* riflen is 6 or more, packet has more than one route descriptor */
198 num_rdsc = (riflen / 2) - 1;
199 memset(rdesc, 0, ETH_ALEN);
200 /* offset 4 comes from LAN destination field in LE control frames */
201 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800202 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700203 else {
Al Viro30d492d2006-11-14 21:11:29 -0800204 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700205 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
206 }
207
208 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210#endif /* CONFIG_TR */
211
212/*
213 * Open/initialize the netdevice. This is called (in the current kernel)
214 * sometime after booting when the 'ifconfig' program is run.
215 *
216 * This routine should set everything up anew at each open, even
217 * registers that "should" only need to be set once at boot, so that
218 * there is non-reboot way to recover if something goes wrong.
219 */
220
Chas Williamsd44f7742006-09-29 17:11:14 -0700221static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000224 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700225
226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Stephen Hemminger162619e2009-01-09 13:01:01 +0000229static void
230lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000232 struct net_device *dev = skb->dev;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 ATM_SKB(skb)->vcc = vcc;
235 ATM_SKB(skb)->atm_options = vcc->atm_options;
236
237 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
238 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000239 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return;
241 }
242
Stephen Hemminger162619e2009-01-09 13:01:01 +0000243 dev->stats.tx_packets++;
244 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Chas Williamsd44f7742006-09-29 17:11:14 -0700247static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Joe Perches99824462010-01-26 11:40:00 +0000249 pr_info("%s\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 dev->trans_start = jiffies;
251 netif_wake_queue(dev);
252}
253
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000254static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
255 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Chas Williamsd44f7742006-09-29 17:11:14 -0700257 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800258 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700259 struct lecdatahdr_8023 *lec_h;
260 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 int min_frame_size;
264#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700267 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Joe Perches99824462010-01-26 11:40:00 +0000269 pr_debug("called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700270 if (!priv->lecd) {
Joe Perchesc48192a2010-01-26 11:40:08 +0000271 pr_info("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000272 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700273 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000274 kfree_skb(skb);
275 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Joe Perches99824462010-01-26 11:40:00 +0000279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
280 (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
Joe Perches99824462010-01-26 11:40:00 +0000289 pr_debug("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)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000293 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700294 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)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000311 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#if DUMP_PACKETS >= 2
Joe Perchesc48192a2010-01-26 11:40:08 +0000317#define MAX_DUMP_SKB 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#elif DUMP_PACKETS >= 1
Joe Perchesc48192a2010-01-26 11:40:08 +0000319#define MAX_DUMP_SKB 30
320#endif
321#if DUMP_PACKETS >= 1
322 printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
323 dev->name, skb->len, priv->lecid);
324 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
325 skb->data, min(skb->len, MAX_DUMP_SKB), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#endif /* DUMP_PACKETS >= 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700330 if (priv->is_trdev)
331 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 else
333#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 min_frame_size = LEC_MINIMUM_8023_SIZE;
335 if (skb->len < min_frame_size) {
336 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
337 skb2 = skb_copy_expand(skb, 0,
338 min_frame_size - skb->truesize,
339 GFP_ATOMIC);
340 dev_kfree_skb(skb);
341 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000342 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000343 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700344 }
345 skb = skb2;
346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700348 }
349
350 /* Send to right vcc */
351 is_rdesc = 0;
352 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 if (priv->is_trdev) {
355 dst = get_tr_dst(skb->data + 2, rdesc);
356 if (dst == NULL) {
357 dst = rdesc;
358 is_rdesc = 1;
359 }
360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700362 entry = NULL;
363 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Joe Perches99824462010-01-26 11:40:00 +0000364 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
365 dev->name, vcc, vcc ? vcc->flags : 0, entry);
Chas Williamsd44f7742006-09-29 17:11:14 -0700366 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
367 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Joe Perches99824462010-01-26 11:40:00 +0000368 pr_debug("%s:queuing packet, MAC address %pM\n",
369 dev->name, lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700370 skb_queue_tail(&entry->tx_wait, skb);
371 } else {
Joe Perches99824462010-01-26 11:40:00 +0000372 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
373 dev->name, lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000374 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev_kfree_skb(skb);
376 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700377 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700378 }
379#if DUMP_PACKETS > 0
Joe Perchesc48192a2010-01-26 11:40:08 +0000380 printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
381 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700383
384 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Joe Perches99824462010-01-26 11:40:00 +0000385 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000386 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Stephen Hemminger162619e2009-01-09 13:01:01 +0000389 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 if (!atm_may_send(vcc, 0)) {
392 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
393
394 vpriv->xoff = 1;
395 netif_stop_queue(dev);
396
397 /*
398 * vcc->pop() might have occurred in between, making
399 * the vcc usuable again. Since xmit is serialized,
400 * this is the only situation we have to re-test.
401 */
402
403 if (atm_may_send(vcc, 0))
404 netif_wake_queue(dev);
405 }
406
Chas Williams6656e3c2006-09-29 17:17:17 -0700407out:
408 if (entry)
409 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000411 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700415static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Chas Williamsd44f7742006-09-29 17:11:14 -0700417 netif_stop_queue(dev);
418 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
Chas Williamsd44f7742006-09-29 17:11:14 -0700421static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
423 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700424 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800425 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700426 struct atmlec_msg *mesg;
427 struct lec_arp_table *entry;
428 int i;
429 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700432 mesg = (struct atmlec_msg *)skb->data;
433 tmp = skb->data;
434 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700435 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700436 switch (mesg->type) {
437 case l_set_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000438 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700439 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
Chas Williamsd44f7742006-09-29 17:11:14 -0700440 break;
441 case l_del_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000442 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700443 dev->dev_addr[i] = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -0700444 break;
445 case l_addr_delete:
446 lec_addr_delete(priv, mesg->content.normal.atm_addr,
447 mesg->content.normal.flag);
448 break;
449 case l_topology_change:
450 priv->topology_change = mesg->content.normal.flag;
451 break;
452 case l_flush_complete:
453 lec_flush_complete(priv, mesg->content.normal.flag);
454 break;
455 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700457 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
458 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
460
Chas Williamsd44f7742006-09-29 17:11:14 -0700461 if (mesg->content.normal.no_source_le_narp)
462 break;
463 /* FALL THROUGH */
464 case l_arp_update:
465 lec_arp_update(priv, mesg->content.normal.mac_addr,
466 mesg->content.normal.atm_addr,
467 mesg->content.normal.flag,
468 mesg->content.normal.targetless_le_arp);
Joe Perches99824462010-01-26 11:40:00 +0000469 pr_debug("in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700470 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Joe Perches99824462010-01-26 11:40:00 +0000471 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
472 mesg->sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -0700473 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
474 tmp, mesg->sizeoftlvs);
475 }
476 break;
477 case l_config:
478 priv->maximum_unknown_frame_count =
479 mesg->content.config.maximum_unknown_frame_count;
480 priv->max_unknown_frame_time =
481 (mesg->content.config.max_unknown_frame_time * HZ);
482 priv->max_retry_count = mesg->content.config.max_retry_count;
483 priv->aging_time = (mesg->content.config.aging_time * HZ);
484 priv->forward_delay_time =
485 (mesg->content.config.forward_delay_time * HZ);
486 priv->arp_response_time =
487 (mesg->content.config.arp_response_time * HZ);
488 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
489 priv->path_switching_delay =
490 (mesg->content.config.path_switching_delay * HZ);
Joe Perchesc48192a2010-01-26 11:40:08 +0000491 priv->lane_version = mesg->content.config.lane_version;
492 /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 priv->lane2_ops = NULL;
494 if (priv->lane_version > 1)
495 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700496 if (dev_set_mtu(dev, mesg->content.config.mtu))
Joe Perchesc48192a2010-01-26 11:40:08 +0000497 pr_info("%s: change_mtu to %d failed\n",
498 dev->name, mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700500 break;
501 case l_flush_tran_id:
502 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
503 mesg->content.normal.flag);
504 break;
505 case l_set_lecid:
506 priv->lecid =
507 (unsigned short)(0xffff & mesg->content.normal.flag);
508 break;
509 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700511 {
Johannes Berge1749612008-10-27 15:59:26 -0700512 pr_debug("%s: bridge zeppelin asks about %pM\n",
513 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Michał Mirosławda678292009-06-05 05:35:28 +0000515 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700516 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Michał Mirosławda678292009-06-05 05:35:28 +0000518 if (br_fdb_test_addr_hook(dev,
Joe Perchesc48192a2010-01-26 11:40:08 +0000519 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700520 /* hit from bridge table, send LE_ARP_RESPONSE */
521 struct sk_buff *skb2;
522 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Joe Perches99824462010-01-26 11:40:00 +0000524 pr_debug("%s: entry found, responding to zeppelin\n",
525 dev->name);
Joe Perchesc48192a2010-01-26 11:40:08 +0000526 skb2 = alloc_skb(sizeof(struct atmlec_msg),
527 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000528 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700529 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700530 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300531 skb_copy_to_linear_data(skb2, mesg,
532 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700533 atm_force_charge(priv->lecd, skb2->truesize);
534 sk = sk_atm(priv->lecd);
535 skb_queue_tail(&sk->sk_receive_queue, skb2);
536 sk->sk_data_ready(sk, skb2->len);
537 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700540 break;
541 default:
Joe Perchesc48192a2010-01-26 11:40:08 +0000542 pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700543 dev_kfree_skb(skb);
544 return -EINVAL;
545 }
546 dev_kfree_skb(skb);
547 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Chas Williamsd44f7742006-09-29 17:11:14 -0700550static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 struct sk_buff *skb;
553 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800554 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Chas Williamsd44f7742006-09-29 17:11:14 -0700556 priv->lecd = NULL;
557 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Chas Williamsd44f7742006-09-29 17:11:14 -0700559 netif_stop_queue(dev);
560 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Chas Williamsd44f7742006-09-29 17:11:14 -0700562 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Joe Perchesc48192a2010-01-26 11:40:08 +0000563 pr_info("%s closing with messages pending\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700564 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
565 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700567 }
568
Joe Perchesc48192a2010-01-26 11:40:08 +0000569 pr_info("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700570 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
573static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700574 .close = lec_atm_close,
575 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576};
577
578static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700579 .ops = &lecdev_ops,
580 .type = "lec",
581 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700582 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583};
584
585/*
586 * LANE2: new argument struct sk_buff *data contains
587 * the LE_ARP based TLVs introduced in the LANE2 spec
588 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700589static int
590send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700591 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700592 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
594 struct sock *sk;
595 struct sk_buff *skb;
596 struct atmlec_msg *mesg;
597
Joe Perchesc48192a2010-01-26 11:40:08 +0000598 if (!priv || !priv->lecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
601 if (!skb)
602 return -1;
603 skb->len = sizeof(struct atmlec_msg);
604 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 if (data != NULL)
608 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 if (mac_addr)
610 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700611 else
612 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (atm_addr)
614 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
615
Chas Williamsd44f7742006-09-29 17:11:14 -0700616 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 sk = sk_atm(priv->lecd);
618 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700619 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Chas Williamsd44f7742006-09-29 17:11:14 -0700621 if (data != NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000622 pr_debug("about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700623 atm_force_charge(priv->lecd, data->truesize);
624 skb_queue_tail(&sk->sk_receive_queue, data);
625 sk->sk_data_ready(sk, skb->len);
626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Chas Williamsd44f7742006-09-29 17:11:14 -0700628 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629}
630
631/* shamelessly stolen from drivers/net/net_init.c */
632static int lec_change_mtu(struct net_device *dev, int new_mtu)
633{
Chas Williamsd44f7742006-09-29 17:11:14 -0700634 if ((new_mtu < 68) || (new_mtu > 18190))
635 return -EINVAL;
636 dev->mtu = new_mtu;
637 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
640static void lec_set_multicast_list(struct net_device *dev)
641{
Chas Williamsd44f7742006-09-29 17:11:14 -0700642 /*
643 * by default, all multicast frames arrive over the bus.
644 * eventually support selective multicast service
645 */
646 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
Stephen Hemminger004b3222009-01-09 13:01:02 +0000649static const struct net_device_ops lec_netdev_ops = {
650 .ndo_open = lec_open,
651 .ndo_stop = lec_close,
652 .ndo_start_xmit = lec_start_xmit,
653 .ndo_change_mtu = lec_change_mtu,
654 .ndo_tx_timeout = lec_tx_timeout,
655 .ndo_set_multicast_list = lec_set_multicast_list,
656};
657
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700658static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700659 0xff,
660 0x00,
661 0x01,
662 0x01
663};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Scott Talbert4a7097f2005-09-29 17:30:54 -0700665#define LEC_DATA_DIRECT_8023 2
666#define LEC_DATA_DIRECT_8025 3
667
668static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700669{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700670 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
671 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700672}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700673
Chas Williamsd44f7742006-09-29 17:11:14 -0700674static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700676 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700677 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800678 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Joe Perchesc48192a2010-01-26 11:40:08 +0000680#if DUMP_PACKETS > 0
Joe Perches99824462010-01-26 11:40:00 +0000681 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
682 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700684 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700685 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700686 lec_vcc_close(priv, vcc);
687 return;
688 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#if DUMP_PACKETS >= 2
Joe Perches99824462010-01-26 11:40:00 +0000690#define MAX_SKB_DUMP 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#elif DUMP_PACKETS >= 1
Joe Perches99824462010-01-26 11:40:00 +0000692#define MAX_SKB_DUMP 30
693#endif
694#if DUMP_PACKETS > 0
695 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
696 dev->name, skb->len, priv->lecid);
697 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
698 skb->data, min(MAX_SKB_DUMP, skb->len), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#endif /* DUMP_PACKETS > 0 */
Joe Perches99824462010-01-26 11:40:00 +0000700 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
701 /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 struct sock *sk = sk_atm(vcc);
703
Stephen Hemminger52240062007-08-28 15:22:09 -0700704 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700705 skb_queue_tail(&sk->sk_receive_queue, skb);
706 sk->sk_data_ready(sk, skb->len);
707 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700708 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Chas Williamsd44f7742006-09-29 17:11:14 -0700711 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800712 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700713 !priv->lecd || !(dev->flags & IFF_UP)) {
714 /*
715 * Probably looping back, or if lecd is missing,
716 * lecd has gone down
717 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700718 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700719 dev_kfree_skb(skb);
720 return;
721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 if (priv->is_trdev)
724 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
725 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700727 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700728
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 /*
730 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700731 * the LE_ARP cache entry, delete the LE_ARP cache entry.
732 */
733 spin_lock_irqsave(&priv->lec_arp_lock, flags);
734 if (lec_is_data_direct(vcc)) {
735#ifdef CONFIG_TR
736 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700737 src =
738 ((struct lecdatahdr_8025 *)skb->data)->
739 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700740 else
741#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700742 src =
743 ((struct lecdatahdr_8023 *)skb->data)->
744 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700745 entry = lec_arp_find(priv, src);
746 if (entry && entry->vcc != vcc) {
747 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700748 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700749 }
750 }
751 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
754 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700756 dev_kfree_skb(skb);
757 return;
758 }
Joe Perchesc48192a2010-01-26 11:40:08 +0000759 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williamsd44f7742006-09-29 17:11:14 -0700760 lec_arp_check_empties(priv, vcc, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700761 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 if (priv->is_trdev)
764 skb->protocol = tr_type_trans(skb, dev);
765 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000768 dev->stats.rx_packets++;
769 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700770 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
771 netif_rx(skb);
772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774
Chas Williamsd44f7742006-09-29 17:11:14 -0700775static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
778 struct net_device *dev = skb->dev;
779
780 if (vpriv == NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000781 pr_info("vpriv = NULL!?!?!?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return;
783 }
784
785 vpriv->old_pop(vcc, skb);
786
787 if (vpriv->xoff && atm_may_send(vcc, 0)) {
788 vpriv->xoff = 0;
789 if (netif_running(dev) && netif_queue_stopped(dev))
790 netif_wake_queue(dev);
791 }
792}
793
Chas Williamsd44f7742006-09-29 17:11:14 -0700794static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
796 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700797 int bytes_left;
798 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Chas Williamsd44f7742006-09-29 17:11:14 -0700800 /* Lecd must be up in this case */
801 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
Joe Perches99824462010-01-26 11:40:00 +0000802 if (bytes_left != 0)
803 pr_info("copy from user failed for %d bytes\n", bytes_left);
Chas Williamsd44f7742006-09-29 17:11:14 -0700804 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
805 !dev_lec[ioc_data.dev_num])
806 return -EINVAL;
Joe Perchesc48192a2010-01-26 11:40:08 +0000807 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
808 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return -ENOMEM;
810 vpriv->xoff = 0;
811 vpriv->old_pop = vcc->pop;
812 vcc->user_back = vpriv;
813 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800814 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700815 &ioc_data, vcc, vcc->push);
816 vcc->proto_data = dev_lec[ioc_data.dev_num];
817 vcc->push = lec_push;
818 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
Chas Williamsd44f7742006-09-29 17:11:14 -0700821static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Chas Williamsd44f7742006-09-29 17:11:14 -0700823 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
824 return -EINVAL;
825 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800826 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
827 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
830/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700831static int lecd_attach(struct atm_vcc *vcc, int arg)
832{
833 int i;
834 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Chas Williamsd44f7742006-09-29 17:11:14 -0700836 if (arg < 0)
837 i = 0;
838 else
839 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700841 if (arg >= MAX_LEC_ITF)
842 return -EINVAL;
843#else /* Reserve the top NUM_TR_DEVS for TR */
844 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
845 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700847 if (!dev_lec[i]) {
848 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Chas Williamsd44f7742006-09-29 17:11:14 -0700850 is_trdev = 0;
851 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
852 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Chas Williamsd44f7742006-09-29 17:11:14 -0700854 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700856 if (is_trdev)
857 dev_lec[i] = alloc_trdev(size);
858 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700860 dev_lec[i] = alloc_etherdev(size);
861 if (!dev_lec[i])
862 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000863 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700864 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
865 if (register_netdev(dev_lec[i])) {
866 free_netdev(dev_lec[i]);
867 return -EINVAL;
868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Wang Chen524ad0a2008-11-12 23:39:10 -0800870 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700871 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700872 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800873 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700874 if (priv->lecd)
875 return -EADDRINUSE;
876 }
877 lec_arp_init(priv);
878 priv->itfnum = i; /* LANE2 addition */
879 priv->lecd = vcc;
880 vcc->dev = &lecatm_dev;
881 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Chas Williamsd44f7742006-09-29 17:11:14 -0700883 vcc->proto_data = dev_lec[i];
884 set_bit(ATM_VF_META, &vcc->flags);
885 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Chas Williamsd44f7742006-09-29 17:11:14 -0700887 /* Set default values to these variables */
888 priv->maximum_unknown_frame_count = 1;
889 priv->max_unknown_frame_time = (1 * HZ);
890 priv->vcc_timeout_period = (1200 * HZ);
891 priv->max_retry_count = 1;
892 priv->aging_time = (300 * HZ);
893 priv->forward_delay_time = (15 * HZ);
894 priv->topology_change = 0;
895 priv->arp_response_time = (1 * HZ);
896 priv->flush_timeout = (4 * HZ);
897 priv->path_switching_delay = (6 * HZ);
898
Joe Perchesc48192a2010-01-26 11:40:08 +0000899 if (dev_lec[i]->flags & IFF_UP)
Chas Williamsd44f7742006-09-29 17:11:14 -0700900 netif_start_queue(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700901 __module_get(THIS_MODULE);
902 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903}
904
905#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700906static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700908 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 "ESI_UNKNOWN ",
910 "ESI_ARP_PENDING ",
911 "ESI_VC_PENDING ",
912 "<Undefined> ",
913 "ESI_FLUSH_PENDING ",
914 "ESI_FORWARD_DIRECT"
915 };
916
917 if (status > ESI_FORWARD_DIRECT)
918 status = 3; /* ESI_UNDEFINED */
919 return lec_arp_status_string[status];
920}
921
922static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
923{
924 int i;
925
926 for (i = 0; i < ETH_ALEN; i++)
927 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
928 seq_printf(seq, " ");
929 for (i = 0; i < ATM_ESA_LEN; i++)
930 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
931 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
932 entry->flags & 0xffff);
933 if (entry->vcc)
934 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
935 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700936 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (entry->recv_vcc) {
938 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
939 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700940 }
941 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944struct lec_state {
945 unsigned long flags;
946 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700947 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 struct net_device *dev;
949 int itf;
950 int arp_table;
951 int misc_table;
952};
953
Chas Williamsd0732f62006-09-29 17:14:27 -0700954static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 loff_t *l)
956{
Chas Williamsd0732f62006-09-29 17:14:27 -0700957 struct hlist_node *e = state->node;
958 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700961 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700962 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700963 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 --*l;
965 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700966
967 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (--*l < 0)
969 break;
970 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700971 state->node = e;
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 return (*l < 0) ? state : NULL;
974}
975
976static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -0700977 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
979 void *v = NULL;
980 int p;
981
982 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700983 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (v)
985 break;
986 }
987 state->arp_table = p;
988 return v;
989}
990
991static void *lec_misc_walk(struct lec_state *state, loff_t *l,
992 struct lec_priv *priv)
993{
Chas Williamsd0732f62006-09-29 17:14:27 -0700994 struct hlist_head *lec_misc_tables[] = {
995 &priv->lec_arp_empty_ones,
996 &priv->lec_no_forward,
997 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 };
999 void *v = NULL;
1000 int q;
1001
1002 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1003 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1004 if (v)
1005 break;
1006 }
1007 state->misc_table = q;
1008 return v;
1009}
1010
1011static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1012 struct lec_priv *priv)
1013{
1014 if (!state->locked) {
1015 state->locked = priv;
1016 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1017 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001018 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1020 state->locked = NULL;
1021 /* Partial state reset for the next time we get called */
1022 state->arp_table = state->misc_table = 0;
1023 }
1024 return state->locked;
1025}
1026
1027static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1028{
1029 struct net_device *dev;
1030 void *v;
1031
1032 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001033 v = (dev && netdev_priv(dev)) ?
1034 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (!v && dev) {
1036 dev_put(dev);
1037 /* Partial state reset for the next time we get called */
1038 dev = NULL;
1039 }
1040 state->dev = dev;
1041 return v;
1042}
1043
1044static void *lec_get_idx(struct lec_state *state, loff_t l)
1045{
1046 void *v = NULL;
1047
1048 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1049 v = lec_itf_walk(state, &l);
1050 if (v)
1051 break;
1052 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001053 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
1056static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1057{
1058 struct lec_state *state = seq->private;
1059
1060 state->itf = 0;
1061 state->dev = NULL;
1062 state->locked = NULL;
1063 state->arp_table = 0;
1064 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001065 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Joe Perches2e1e9842008-04-10 03:33:03 -07001067 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068}
1069
1070static void lec_seq_stop(struct seq_file *seq, void *v)
1071{
1072 struct lec_state *state = seq->private;
1073
1074 if (state->dev) {
1075 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1076 state->flags);
1077 dev_put(state->dev);
1078 }
1079}
1080
1081static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1082{
1083 struct lec_state *state = seq->private;
1084
1085 v = lec_get_idx(state, 1);
1086 *pos += !!PTR_ERR(v);
1087 return v;
1088}
1089
1090static int lec_seq_show(struct seq_file *seq, void *v)
1091{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001092 static const char lec_banner[] =
1093 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001094 " Status Flags "
1095 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Joe Perches2e1e9842008-04-10 03:33:03 -07001097 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 seq_puts(seq, lec_banner);
1099 else {
1100 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001101 struct net_device *dev = state->dev;
Joe Perchesc48192a2010-01-26 11:40:08 +00001102 struct lec_arp_table *entry = hlist_entry(state->node,
1103 struct lec_arp_table,
1104 next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001107 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109 return 0;
1110}
1111
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001112static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001113 .start = lec_seq_start,
1114 .next = lec_seq_next,
1115 .stop = lec_seq_stop,
1116 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117};
1118
1119static int lec_seq_open(struct inode *inode, struct file *file)
1120{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001121 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Arjan van de Ven9a321442007-02-12 00:55:35 -08001124static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001125 .owner = THIS_MODULE,
1126 .open = lec_seq_open,
1127 .read = seq_read,
1128 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001129 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130};
1131#endif
1132
1133static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1134{
1135 struct atm_vcc *vcc = ATM_SD(sock);
1136 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001139 case ATMLEC_CTRL:
1140 case ATMLEC_MCAST:
1141 case ATMLEC_DATA:
1142 if (!capable(CAP_NET_ADMIN))
1143 return -EPERM;
1144 break;
1145 default:
1146 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
1148
1149 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001150 case ATMLEC_CTRL:
1151 err = lecd_attach(vcc, (int)arg);
1152 if (err >= 0)
1153 sock->state = SS_CONNECTED;
1154 break;
1155 case ATMLEC_MCAST:
1156 err = lec_mcast_attach(vcc, (int)arg);
1157 break;
1158 case ATMLEC_DATA:
1159 err = lec_vcc_attach(vcc, (void __user *)arg);
1160 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 }
1162
1163 return err;
1164}
1165
1166static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001167 .owner = THIS_MODULE,
1168 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169};
1170
1171static int __init lane_module_init(void)
1172{
1173#ifdef CONFIG_PROC_FS
1174 struct proc_dir_entry *p;
1175
Wang Chen16e297b2008-02-28 13:55:45 -08001176 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001177 if (!p) {
Joe Perches99824462010-01-26 11:40:00 +00001178 pr_err("Unable to initialize /proc/net/atm/lec\n");
Wang Chendbee0d32008-03-23 21:45:36 -07001179 return -ENOMEM;
1180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181#endif
1182
1183 register_atm_ioctl(&lane_ioctl_ops);
Joe Perchesc48192a2010-01-26 11:40:08 +00001184 pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
1188static void __exit lane_module_cleanup(void)
1189{
Chas Williamsd44f7742006-09-29 17:11:14 -07001190 int i;
1191 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 remove_proc_entry("lec", atm_proc_root);
1194
1195 deregister_atm_ioctl(&lane_ioctl_ops);
1196
Chas Williamsd44f7742006-09-29 17:11:14 -07001197 for (i = 0; i < MAX_LEC_ITF; i++) {
1198 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001199 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001201 free_netdev(dev_lec[i]);
1202 dev_lec[i] = NULL;
1203 }
1204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Chas Williamsd44f7742006-09-29 17:11:14 -07001206 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
1209module_init(lane_module_init);
1210module_exit(lane_module_cleanup);
1211
1212/*
1213 * LANE2: 3.1.3, LE_RESOLVE.request
1214 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1215 * If sizeoftlvs == NULL the default TLVs associated with with this
1216 * lec will be used.
1217 * If dst_mac == NULL, targetless LE_ARP will be sent
1218 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001219static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001220 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
1222 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001223 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001224 struct lec_arp_table *table;
1225 struct sk_buff *skb;
1226 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Chas Williamsd44f7742006-09-29 17:11:14 -07001228 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001230 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001232 if (table == NULL)
1233 return -1;
1234
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001235 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001236 if (*tlvs == NULL)
1237 return -1;
1238
Chas Williamsd44f7742006-09-29 17:11:14 -07001239 *sizeoftlvs = table->sizeoftlvs;
1240
1241 return 0;
1242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 if (sizeoftlvs == NULL)
1245 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 else {
1248 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1249 if (skb == NULL)
1250 return -1;
1251 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001252 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1254 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001255 return retval;
1256}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258/*
1259 * LANE2: 3.1.4, LE_ASSOCIATE.request
1260 * Associate the *tlvs with the *lan_dst address.
1261 * Will overwrite any previous association
1262 * Returns 1 for success, 0 for failure (out of memory)
1263 *
1264 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001265static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1266 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Chas Williamsd44f7742006-09-29 17:11:14 -07001268 int retval;
1269 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001270 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Chas Williamsd44f7742006-09-29 17:11:14 -07001272 if (compare_ether_addr(lan_dst, dev->dev_addr))
Joe Perchesc48192a2010-01-26 11:40:08 +00001273 return 0; /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001277 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001278 if (priv->tlvs == NULL)
Joe Perchesc48192a2010-01-26 11:40:08 +00001279 return 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001280 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1283 if (skb == NULL)
1284 return 0;
1285 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001286 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001287 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1288 if (retval != 0)
Joe Perchesc48192a2010-01-26 11:40:08 +00001289 pr_info("lec.c: lane2_associate_req() failed\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001290 /*
1291 * If the previous association has changed we must
1292 * somehow notify other LANE entities about the change
1293 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001294 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295}
1296
1297/*
1298 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1299 *
1300 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001301static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1302 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
1304#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001305 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001307 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001308#if 0 /*
1309 * Why have the TLVs in LE_ARP entries
1310 * since we do not use them? When you
1311 * uncomment this code, make sure the
1312 * TLVs get freed when entry is killed
1313 */
1314 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Chas Williamsd44f7742006-09-29 17:11:14 -07001316 if (entry == NULL)
1317 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001321 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001322 if (entry->tlvs == NULL)
1323 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001324 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325#endif
1326#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001327 pr_info("\n");
1328 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001329 while (i < sizeoftlvs)
Joe Perchesc48192a2010-01-26 11:40:08 +00001330 pr_cont("%02x ", tlvs[i++]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001331
Joe Perchesc48192a2010-01-26 11:40:08 +00001332 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333#endif
1334
Chas Williamsd44f7742006-09-29 17:11:14 -07001335 /* tell MPOA about the TLVs we saw */
1336 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1337 priv->lane2_ops->associate_indicator(dev, mac_addr,
1338 tlvs, sizeoftlvs);
1339 }
1340 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
1343/*
1344 * Here starts what used to lec_arpc.c
1345 *
1346 * lec_arpc.c was added here when making
1347 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 */
1349
1350#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351#include <linux/timer.h>
Joe Perchesc48192a2010-01-26 11:40:08 +00001352#include <linux/param.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#include <asm/atomic.h>
1354#include <linux/inetdevice.h>
1355#include <net/route.h>
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001358#define pr_debug(format, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359/*
Joe Perches99824462010-01-26 11:40:00 +00001360 #define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361*/
1362#endif
1363#define DEBUG_ARP_TABLE 0
1364
1365#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1366
David Howellsc4028952006-11-22 14:57:56 +00001367static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368static void lec_arp_expire_arp(unsigned long data);
1369
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001370/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 * Arp table funcs
1372 */
1373
Joe Perchesc48192a2010-01-26 11:40:08 +00001374#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376/*
1377 * Initialization of arp-cache
1378 */
Chas Williams1fa99612006-09-29 17:11:47 -07001379static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Chas Williams1fa99612006-09-29 17:11:47 -07001381 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Joe Perchesc48192a2010-01-26 11:40:08 +00001383 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07001384 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001385 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1386 INIT_HLIST_HEAD(&priv->lec_no_forward);
1387 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001389 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001390 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391}
1392
Chas Williams1fa99612006-09-29 17:11:47 -07001393static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
Chas Williams1fa99612006-09-29 17:11:47 -07001395 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 struct atm_vcc *vcc = entry->vcc;
1397 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001398 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Chas Williams1fa99612006-09-29 17:11:47 -07001400 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (vpriv->xoff)
1402 netif_wake_queue(dev);
1403 kfree(vpriv);
1404 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001405 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001407 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001408 }
1409 if (entry->recv_vcc) {
1410 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001412 entry->recv_vcc = NULL;
1413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
1416/*
1417 * Insert entry to lec_arp_table
1418 * LANE2: Add to the end of the list to satisfy 8.1.13
1419 */
Chas Williams1fa99612006-09-29 17:11:47 -07001420static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001421lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
Chas Williamsd0732f62006-09-29 17:14:27 -07001423 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Chas Williamsd0732f62006-09-29 17:14:27 -07001425 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1426 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001427
Joe Perches99824462010-01-26 11:40:00 +00001428 pr_debug("Added entry:%pM\n", entry->mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
1431/*
1432 * Remove entry from lec_arp_table
1433 */
Chas Williams1fa99612006-09-29 17:11:47 -07001434static int
1435lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Chas Williamsd0732f62006-09-29 17:14:27 -07001437 struct hlist_node *node;
1438 struct lec_arp_table *entry;
1439 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Joe Perchesc48192a2010-01-26 11:40:08 +00001441 if (!to_remove)
Chas Williams1fa99612006-09-29 17:11:47 -07001442 return -1;
Chas Williamsd0732f62006-09-29 17:14:27 -07001443
1444 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001445 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Joe Perchesc48192a2010-01-26 11:40:08 +00001447 /*
1448 * If this is the only MAC connected to this VCC,
1449 * also tear down the VCC
1450 */
Chas Williams1fa99612006-09-29 17:11:47 -07001451 if (to_remove->status >= ESI_FLUSH_PENDING) {
1452 /*
1453 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1454 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001455 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001456 hlist_for_each_entry(entry, node,
1457 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001458 if (memcmp(to_remove->atm_addr,
1459 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001460 remove_vcc = 0;
1461 break;
1462 }
1463 }
1464 }
1465 if (remove_vcc)
1466 lec_arp_clear_vccs(to_remove);
1467 }
1468 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1469
Joe Perches99824462010-01-26 11:40:00 +00001470 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
1474#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001475static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Chas Williams1fa99612006-09-29 17:11:47 -07001477 switch (st) {
1478 case ESI_UNKNOWN:
1479 return "ESI_UNKNOWN";
1480 case ESI_ARP_PENDING:
1481 return "ESI_ARP_PENDING";
1482 case ESI_VC_PENDING:
1483 return "ESI_VC_PENDING";
1484 case ESI_FLUSH_PENDING:
1485 return "ESI_FLUSH_PENDING";
1486 case ESI_FORWARD_DIRECT:
1487 return "ESI_FORWARD_DIRECT";
Chas Williams1fa99612006-09-29 17:11:47 -07001488 }
Joe Perchesc48192a2010-01-26 11:40:08 +00001489 return "<UNKNOWN>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Chas Williams1fa99612006-09-29 17:11:47 -07001492static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Chas Williamsd0732f62006-09-29 17:14:27 -07001494 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001495 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001496 char buf[256];
1497 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Joe Perchesc48192a2010-01-26 11:40:08 +00001499 pr_info("Dump %p:\n", priv);
Chas Williams1fa99612006-09-29 17:11:47 -07001500 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001501 hlist_for_each_entry(rulla, node,
1502 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001503 offset = 0;
1504 offset += sprintf(buf, "%d: %p\n", i, rulla);
Joe Perchesc48192a2010-01-26 11:40:08 +00001505 offset += sprintf(buf + offset, "Mac: %pM",
1506 rulla->mac_addr);
1507 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001508 for (j = 0; j < ATM_ESA_LEN; j++) {
1509 offset += sprintf(buf + offset,
1510 "%2.2x ",
1511 rulla->atm_addr[j] & 0xff);
1512 }
1513 offset += sprintf(buf + offset,
1514 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1515 rulla->vcc ? rulla->vcc->vpi : 0,
1516 rulla->vcc ? rulla->vcc->vci : 0,
1517 rulla->recv_vcc ? rulla->recv_vcc->
1518 vpi : 0,
1519 rulla->recv_vcc ? rulla->recv_vcc->
1520 vci : 0, rulla->last_used,
1521 rulla->timestamp, rulla->no_tries);
1522 offset +=
1523 sprintf(buf + offset,
1524 "Flags:%x, Packets_flooded:%x, Status: %s ",
1525 rulla->flags, rulla->packets_flooded,
1526 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001527 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001528 }
Chas Williams1fa99612006-09-29 17:11:47 -07001529 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001530
1531 if (!hlist_empty(&priv->lec_no_forward))
Joe Perchesc48192a2010-01-26 11:40:08 +00001532 pr_info("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001533 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001534 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001535 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1536 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001537 for (j = 0; j < ATM_ESA_LEN; j++) {
1538 offset += sprintf(buf + offset, "%2.2x ",
1539 rulla->atm_addr[j] & 0xff);
1540 }
1541 offset += sprintf(buf + offset,
1542 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1543 rulla->vcc ? rulla->vcc->vpi : 0,
1544 rulla->vcc ? rulla->vcc->vci : 0,
1545 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1546 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1547 rulla->last_used,
1548 rulla->timestamp, rulla->no_tries);
1549 offset += sprintf(buf + offset,
1550 "Flags:%x, Packets_flooded:%x, Status: %s ",
1551 rulla->flags, rulla->packets_flooded,
1552 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001553 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001554 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001555
1556 if (!hlist_empty(&priv->lec_arp_empty_ones))
Joe Perchesc48192a2010-01-26 11:40:08 +00001557 pr_info("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001558 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001559 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001560 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1561 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001562 for (j = 0; j < ATM_ESA_LEN; j++) {
1563 offset += sprintf(buf + offset, "%2.2x ",
1564 rulla->atm_addr[j] & 0xff);
1565 }
1566 offset += sprintf(buf + offset,
1567 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1568 rulla->vcc ? rulla->vcc->vpi : 0,
1569 rulla->vcc ? rulla->vcc->vci : 0,
1570 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1571 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1572 rulla->last_used,
1573 rulla->timestamp, rulla->no_tries);
1574 offset += sprintf(buf + offset,
1575 "Flags:%x, Packets_flooded:%x, Status: %s ",
1576 rulla->flags, rulla->packets_flooded,
1577 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001578 pr_info("%s", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Chas Williamsd0732f62006-09-29 17:14:27 -07001581 if (!hlist_empty(&priv->mcast_fwds))
Joe Perchesc48192a2010-01-26 11:40:08 +00001582 pr_info("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001583 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001584 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001585 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1586 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001587 for (j = 0; j < ATM_ESA_LEN; j++) {
1588 offset += sprintf(buf + offset, "%2.2x ",
1589 rulla->atm_addr[j] & 0xff);
1590 }
1591 offset += sprintf(buf + offset,
1592 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1593 rulla->vcc ? rulla->vcc->vpi : 0,
1594 rulla->vcc ? rulla->vcc->vci : 0,
1595 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1596 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1597 rulla->last_used,
1598 rulla->timestamp, rulla->no_tries);
1599 offset += sprintf(buf + offset,
1600 "Flags:%x, Packets_flooded:%x, Status: %s ",
1601 rulla->flags, rulla->packets_flooded,
1602 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001603 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
Chas Williamsd0732f62006-09-29 17:14:27 -07001607#else
1608#define dump_arp_table(priv) do { } while (0)
1609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611/*
1612 * Destruction of arp-cache
1613 */
Chas Williams1fa99612006-09-29 17:11:47 -07001614static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
1616 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001617 struct hlist_node *node, *next;
1618 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001619 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Chas Williams987e46b2006-09-29 17:15:59 -07001621 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001622
1623 /*
1624 * Remove all entries
1625 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001628 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001629 hlist_for_each_entry_safe(entry, node, next,
1630 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001631 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001632 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001633 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001634 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001635 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001636
Joe Perchesc48192a2010-01-26 11:40:08 +00001637 hlist_for_each_entry_safe(entry, node, next,
1638 &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001639 del_timer_sync(&entry->timer);
1640 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001641 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001642 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001643 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001644 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1645
Joe Perchesc48192a2010-01-26 11:40:08 +00001646 hlist_for_each_entry_safe(entry, node, next,
1647 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001648 del_timer_sync(&entry->timer);
1649 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001650 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001651 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001652 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001653 INIT_HLIST_HEAD(&priv->lec_no_forward);
1654
1655 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001656 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1657 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001658 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001659 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001660 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001661 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001662 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1664}
1665
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001666/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 * Find entry by mac_address
1668 */
Chas Williams1fa99612006-09-29 17:11:47 -07001669static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001670 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Chas Williamsd0732f62006-09-29 17:14:27 -07001672 struct hlist_node *node;
1673 struct hlist_head *head;
1674 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Joe Perches99824462010-01-26 11:40:00 +00001676 pr_debug("%pM\n", mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001677
Chas Williamsd0732f62006-09-29 17:14:27 -07001678 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1679 hlist_for_each_entry(entry, node, head, next) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001680 if (!compare_ether_addr(mac_addr, entry->mac_addr))
Chas Williamsd0732f62006-09-29 17:14:27 -07001681 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001682 }
1683 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Chas Williams1fa99612006-09-29 17:11:47 -07001686static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001687 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Chas Williams1fa99612006-09-29 17:11:47 -07001689 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Chas Williams1fa99612006-09-29 17:11:47 -07001691 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1692 if (!to_return) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001693 pr_info("LEC: Arp entry kmalloc failed\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001694 return NULL;
1695 }
1696 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001697 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001698 setup_timer(&to_return->timer, lec_arp_expire_arp,
1699 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001700 to_return->last_used = jiffies;
1701 to_return->priv = priv;
1702 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001703 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001704 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Chas Williams1fa99612006-09-29 17:11:47 -07001707/* Arp sent timer expired */
1708static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Chas Williams1fa99612006-09-29 17:11:47 -07001710 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Chas Williams1fa99612006-09-29 17:11:47 -07001712 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Joe Perches99824462010-01-26 11:40:00 +00001714 pr_debug("\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001715 if (entry->status == ESI_ARP_PENDING) {
1716 if (entry->no_tries <= entry->priv->max_retry_count) {
1717 if (entry->is_rdesc)
1718 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1719 entry->mac_addr, NULL, NULL);
1720 else
1721 send_to_lecd(entry->priv, l_arp_xmt,
1722 entry->mac_addr, NULL, NULL);
1723 entry->no_tries++;
1724 }
1725 mod_timer(&entry->timer, jiffies + (1 * HZ));
1726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727}
1728
Chas Williams1fa99612006-09-29 17:11:47 -07001729/* Unknown/unused vcc expire, remove associated entry */
1730static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
1732 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001733 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1734 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Chas Williams1fa99612006-09-29 17:11:47 -07001736 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Joe Perches99824462010-01-26 11:40:00 +00001738 pr_debug("%p %p: vpi:%d vci:%d\n",
1739 to_remove, priv,
1740 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1741 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001744 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1746
Chas Williams1fa99612006-09-29 17:11:47 -07001747 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001748 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
1751/*
1752 * Expire entries.
1753 * 1. Re-set timer
1754 * 2. For each entry, delete entries that have aged past the age limit.
1755 * 3. For each entry, depending on the status of the entry, perform
1756 * the following maintenance.
1757 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1758 * tick_count is above the max_unknown_frame_time, clear
1759 * the tick_count to zero and clear the packets_flooded counter
1760 * to zero. This supports the packet rate limit per address
1761 * while flooding unknowns.
1762 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1763 * than or equal to the path_switching_delay, change the status
1764 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1765 * regardless of the progress of the flush protocol.
1766 */
David Howellsc4028952006-11-22 14:57:56 +00001767static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
1769 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001770 struct lec_priv *priv =
1771 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001772 struct hlist_node *node, *next;
1773 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001774 unsigned long now;
1775 unsigned long time_to_check;
1776 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Joe Perches99824462010-01-26 11:40:00 +00001778 pr_debug("%p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001780restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001782 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001783 hlist_for_each_entry_safe(entry, node, next,
1784 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001785 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 priv->topology_change)
1787 time_to_check = priv->forward_delay_time;
1788 else
1789 time_to_check = priv->aging_time;
1790
Stephen Hemminger52240062007-08-28 15:22:09 -07001791 pr_debug("About to expire: %lx - %lx > %lx\n",
Joe Perches99824462010-01-26 11:40:00 +00001792 now, entry->last_used, time_to_check);
Joe Perchesc48192a2010-01-26 11:40:08 +00001793 if (time_after(now, entry->last_used + time_to_check) &&
1794 !(entry->flags & LEC_PERMANENT_FLAG) &&
1795 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 /* Remove entry */
Joe Perches99824462010-01-26 11:40:00 +00001797 pr_debug("Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001799 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 } else {
1801 /* Something else */
1802 if ((entry->status == ESI_VC_PENDING ||
Joe Perchesc48192a2010-01-26 11:40:08 +00001803 entry->status == ESI_ARP_PENDING) &&
1804 time_after_eq(now,
1805 entry->timestamp +
1806 priv->max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 entry->timestamp = jiffies;
1808 entry->packets_flooded = 0;
1809 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001810 send_to_lecd(priv, l_svc_setup,
1811 entry->mac_addr,
1812 entry->atm_addr,
1813 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 }
Joe Perchesc48192a2010-01-26 11:40:08 +00001815 if (entry->status == ESI_FLUSH_PENDING &&
Chas Williams1fa99612006-09-29 17:11:47 -07001816 time_after_eq(now, entry->timestamp +
1817 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001819 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Chas Williams6656e3c2006-09-29 17:17:17 -07001821 lec_arp_hold(entry);
1822 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1823 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001824 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001826 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001827 lec_arp_put(entry);
1828 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831 }
1832 }
1833 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1834
Chas Williams987e46b2006-09-29 17:15:59 -07001835 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836}
Chas Williams1fa99612006-09-29 17:11:47 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838/*
1839 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001840 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 */
Chas Williams1fa99612006-09-29 17:11:47 -07001842static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Joe Perchesc48192a2010-01-26 11:40:08 +00001843 const unsigned char *mac_to_find,
1844 int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001845 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
1847 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001848 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 struct atm_vcc *found;
1850
Chas Williams1fa99612006-09-29 17:11:47 -07001851 if (mac_to_find[0] & 0x01) {
1852 switch (priv->lane_version) {
1853 case 1:
1854 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001855 case 2: /* LANE2 wants arp for multicast addresses */
1856 if (!compare_ether_addr(mac_to_find, bus_mac))
1857 return priv->mcast_vcc;
1858 break;
1859 default:
1860 break;
1861 }
1862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001865 entry = lec_arp_find(priv, mac_to_find);
1866
1867 if (entry) {
1868 if (entry->status == ESI_FORWARD_DIRECT) {
1869 /* Connection Ok */
1870 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001871 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001872 *ret_entry = entry;
1873 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001875 }
1876 /*
1877 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001878 * so another LE_ARP request can be made for this frame.
1879 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001880 if (entry->status == ESI_ARP_PENDING)
Scott Talbert75b895c2005-09-29 17:31:30 -07001881 entry->no_tries = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07001882 /*
1883 * Data direct VC not yet set up, check to see if the unknown
1884 * frame count is greater than the limit. If the limit has
1885 * not been reached, allow the caller to send packet to
1886 * BUS.
1887 */
1888 if (entry->status != ESI_FLUSH_PENDING &&
1889 entry->packets_flooded <
1890 priv->maximum_unknown_frame_count) {
1891 entry->packets_flooded++;
Joe Perches99824462010-01-26 11:40:00 +00001892 pr_debug("Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001893 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001895 }
1896 /*
1897 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 * or BUS flood limit was reached for an entry which is
1899 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1900 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001901 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001902 *ret_entry = entry;
Joe Perches99824462010-01-26 11:40:00 +00001903 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1904 entry->vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001905 found = NULL;
1906 } else {
1907 /* No matching entry was found */
1908 entry = make_entry(priv, mac_to_find);
Joe Perches99824462010-01-26 11:40:00 +00001909 pr_debug("Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001910 if (!entry) {
1911 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001913 }
1914 lec_arp_add(priv, entry);
1915 /* We want arp-request(s) to be sent */
1916 entry->packets_flooded = 1;
1917 entry->status = ESI_ARP_PENDING;
1918 entry->no_tries = 1;
1919 entry->last_used = entry->timestamp = jiffies;
1920 entry->is_rdesc = is_rdesc;
1921 if (entry->is_rdesc)
1922 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1923 NULL);
1924 else
1925 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1926 entry->timer.expires = jiffies + (1 * HZ);
1927 entry->timer.function = lec_arp_expire_arp;
1928 add_timer(&entry->timer);
1929 found = priv->mcast_vcc;
1930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932out:
1933 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1934 return found;
1935}
1936
1937static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001938lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001939 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940{
1941 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001942 struct hlist_node *node, *next;
1943 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001944 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Joe Perches99824462010-01-26 11:40:00 +00001946 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001948 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001949 hlist_for_each_entry_safe(entry, node, next,
1950 &priv->lec_arp_tables[i], next) {
1951 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
1952 (permanent ||
1953 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001955 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001958 return 0;
1959 }
1960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001962 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
1965/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001966 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 */
1968static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001969lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1970 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07001971 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
1973 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001974 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07001975 struct lec_arp_table *entry, *tmp;
1976 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Joe Perches99824462010-01-26 11:40:00 +00001978 pr_debug("%smac:%pM\n",
1979 (targetless_le_arp) ? "targetless " : "", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001982 entry = lec_arp_find(priv, mac_addr);
1983 if (entry == NULL && targetless_le_arp)
1984 goto out; /*
1985 * LANE2: ignore targetless LE_ARPs for which
1986 * we have no entry in the cache. 7.1.30
1987 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001988 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001989 hlist_for_each_entry_safe(entry, node, next,
1990 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001991 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
1992 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001993 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07001994 tmp = lec_arp_find(priv, mac_addr);
1995 if (tmp) {
1996 del_timer(&tmp->timer);
1997 tmp->status = ESI_FORWARD_DIRECT;
1998 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
1999 tmp->vcc = entry->vcc;
2000 tmp->old_push = entry->old_push;
2001 tmp->last_used = jiffies;
2002 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002003 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002004 entry = tmp;
2005 } else {
2006 entry->status = ESI_FORWARD_DIRECT;
2007 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2008 entry->last_used = jiffies;
2009 lec_arp_add(priv, entry);
2010 }
2011 if (remoteflag)
2012 entry->flags |= LEC_REMOTE_FLAG;
2013 else
2014 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002015 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002016 dump_arp_table(priv);
2017 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002018 }
Chas Williams1fa99612006-09-29 17:11:47 -07002019 }
2020 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002021
Chas Williams1fa99612006-09-29 17:11:47 -07002022 entry = lec_arp_find(priv, mac_addr);
2023 if (!entry) {
2024 entry = make_entry(priv, mac_addr);
2025 if (!entry)
2026 goto out;
2027 entry->status = ESI_UNKNOWN;
2028 lec_arp_add(priv, entry);
2029 /* Temporary, changes before end of function */
2030 }
2031 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2032 del_timer(&entry->timer);
2033 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002034 hlist_for_each_entry(tmp, node,
2035 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002036 if (entry != tmp &&
2037 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2038 /* Vcc to this host exists */
2039 if (tmp->status > ESI_VC_PENDING) {
2040 /*
2041 * ESI_FLUSH_PENDING,
2042 * ESI_FORWARD_DIRECT
2043 */
2044 entry->vcc = tmp->vcc;
2045 entry->old_push = tmp->old_push;
2046 }
2047 entry->status = tmp->status;
2048 break;
2049 }
2050 }
2051 }
2052 if (remoteflag)
2053 entry->flags |= LEC_REMOTE_FLAG;
2054 else
2055 entry->flags &= ~LEC_REMOTE_FLAG;
2056 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2057 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002058 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002059 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002060 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002061 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062out:
2063 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2064}
2065
2066/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002067 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 */
2069static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002070lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002071 struct atm_vcc *vcc,
2072 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
2074 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002075 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002076 struct lec_arp_table *entry;
2077 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002080 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williams1fa99612006-09-29 17:11:47 -07002081 if (ioc_data->receive == 2) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002082 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002084 entry = lec_arp_find(priv, bus_mac);
2085 if (!entry) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002086 pr_info("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002088 }
2089 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2090 entry->recv_vcc = vcc;
2091 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002093 entry = make_entry(priv, bus_mac);
2094 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002096 del_timer(&entry->timer);
2097 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2098 entry->recv_vcc = vcc;
2099 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002100 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002101 goto out;
2102 } else if (ioc_data->receive == 1) {
2103 /*
2104 * Vcc which we don't want to make default vcc,
2105 * attach it anyway.
2106 */
Joe Perches99824462010-01-26 11:40:00 +00002107 pr_debug("LEC_ARP:Attaching data direct, not default: %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",
2108 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2109 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2110 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2111 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2112 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2113 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2114 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2115 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2116 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2117 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002118 entry = make_entry(priv, bus_mac);
2119 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002121 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2122 memset(entry->mac_addr, 0, ETH_ALEN);
2123 entry->recv_vcc = vcc;
2124 entry->old_recv_push = old_push;
2125 entry->status = ESI_UNKNOWN;
2126 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2127 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002128 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002129 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 dump_arp_table(priv);
2131 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002132 }
Joe Perches99824462010-01-26 11:40:00 +00002133 pr_debug("LEC_ARP:Attaching data direct, default: %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",
2134 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2135 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2136 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2137 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2138 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2139 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2140 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2141 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2142 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2143 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002144 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002145 hlist_for_each_entry(entry, node,
2146 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002147 if (memcmp
2148 (ioc_data->atm_addr, entry->atm_addr,
2149 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002150 pr_debug("LEC_ARP: Attaching data direct\n");
2151 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Joe Perches99824462010-01-26 11:40:00 +00002152 entry->vcc ? entry->vcc->vci : 0,
2153 entry->recv_vcc ? entry->recv_vcc->
2154 vci : 0);
Chas Williams1fa99612006-09-29 17:11:47 -07002155 found_entry = 1;
2156 del_timer(&entry->timer);
2157 entry->vcc = vcc;
2158 entry->old_push = old_push;
2159 if (entry->status == ESI_VC_PENDING) {
2160 if (priv->maximum_unknown_frame_count
2161 == 0)
2162 entry->status =
2163 ESI_FORWARD_DIRECT;
2164 else {
2165 entry->timestamp = jiffies;
2166 entry->status =
2167 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002169 send_to_lecd(priv, l_flush_xmt,
2170 NULL,
2171 entry->atm_addr,
2172 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002174 }
2175 } else {
2176 /*
2177 * They were forming a connection
2178 * to us, and we to them. Our
2179 * ATM address is numerically lower
2180 * than theirs, so we make connection
2181 * we formed into default VCC (8.1.11).
2182 * Connection they made gets torn
2183 * down. This might confuse some
2184 * clients. Can be changed if
2185 * someone reports trouble...
2186 */
2187 ;
2188 }
2189 }
2190 }
2191 }
2192 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002193 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002194 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002196 }
2197 /*
2198 * Not found, snatch address from first data packet that arrives
2199 * from this vcc
2200 */
2201 entry = make_entry(priv, bus_mac);
2202 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002204 entry->vcc = vcc;
2205 entry->old_push = old_push;
2206 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2207 memset(entry->mac_addr, 0, ETH_ALEN);
2208 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002209 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002210 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2211 entry->timer.function = lec_arp_expire_vcc;
2212 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002213 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 dump_arp_table(priv);
2215out:
2216 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2217}
2218
Chas Williams1fa99612006-09-29 17:11:47 -07002219static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
2221 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002222 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002223 struct lec_arp_table *entry;
2224 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Joe Perches99824462010-01-26 11:40:00 +00002226 pr_debug("%lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002227restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002228 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2229 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002230 hlist_for_each_entry(entry, node,
2231 &priv->lec_arp_tables[i], next) {
2232 if (entry->flush_tran_id == tran_id &&
2233 entry->status == ESI_FLUSH_PENDING) {
Chas Williams1fa99612006-09-29 17:11:47 -07002234 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002235 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002236
Chas Williams6656e3c2006-09-29 17:17:17 -07002237 lec_arp_hold(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002238 spin_unlock_irqrestore(&priv->lec_arp_lock,
2239 flags);
Chas Williams6656e3c2006-09-29 17:17:17 -07002240 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002241 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002242 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002243 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002244 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002245 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002246 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002247 }
2248 }
2249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002251 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
2254static void
2255lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002256 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
2258 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002259 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002260 struct lec_arp_table *entry;
2261 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002264 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Joe Perchesc48192a2010-01-26 11:40:08 +00002265 hlist_for_each_entry(entry, node,
2266 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002267 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2268 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002269 pr_debug("Set flush transaction id to %lx for %p\n",
Joe Perches99824462010-01-26 11:40:00 +00002270 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002271 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2274}
2275
Chas Williams1fa99612006-09-29 17:11:47 -07002276static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
2278 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002279 unsigned char mac_addr[] = {
2280 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2281 };
2282 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 struct lec_vcc_priv *vpriv;
2284 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002285
Joe Perchesc48192a2010-01-26 11:40:08 +00002286 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2287 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 return -ENOMEM;
2289 vpriv->xoff = 0;
2290 vpriv->old_pop = vcc->pop;
2291 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002292 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002294 to_add = make_entry(priv, mac_addr);
2295 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 vcc->pop = vpriv->old_pop;
2297 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002298 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002300 }
2301 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2302 to_add->status = ESI_FORWARD_DIRECT;
2303 to_add->flags |= LEC_PERMANENT_FLAG;
2304 to_add->vcc = vcc;
2305 to_add->old_push = vcc->push;
2306 vcc->push = lec_push;
2307 priv->mcast_vcc = vcc;
2308 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309out:
2310 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002311 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
Chas Williams1fa99612006-09-29 17:11:47 -07002314static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
2316 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002317 struct hlist_node *node, *next;
2318 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002319 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Stephen Hemminger52240062007-08-28 15:22:09 -07002321 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002322 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002325
Chas Williams1fa99612006-09-29 17:11:47 -07002326 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002327 hlist_for_each_entry_safe(entry, node, next,
2328 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002329 if (vcc == entry->vcc) {
2330 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002331 lec_arp_put(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002332 if (priv->mcast_vcc == vcc)
Chas Williams1fa99612006-09-29 17:11:47 -07002333 priv->mcast_vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07002334 }
2335 }
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Joe Perchesc48192a2010-01-26 11:40:08 +00002338 hlist_for_each_entry_safe(entry, node, next,
2339 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002340 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002341 lec_arp_clear_vccs(entry);
2342 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002343 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002344 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002345 }
Chas Williams1fa99612006-09-29 17:11:47 -07002346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Joe Perchesc48192a2010-01-26 11:40:08 +00002348 hlist_for_each_entry_safe(entry, node, next,
2349 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002350 if (entry->recv_vcc == vcc) {
2351 lec_arp_clear_vccs(entry);
2352 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002353 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002354 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002355 }
Chas Williams1fa99612006-09-29 17:11:47 -07002356 }
2357
Chas Williamsd0732f62006-09-29 17:14:27 -07002358 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002359 if (entry->recv_vcc == vcc) {
2360 lec_arp_clear_vccs(entry);
2361 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002362 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002363 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002364 }
Chas Williams1fa99612006-09-29 17:11:47 -07002365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
2367 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2368 dump_arp_table(priv);
2369}
2370
2371static void
2372lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002373 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Chas Williams1fa99612006-09-29 17:11:47 -07002375 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002376 struct hlist_node *node, *next;
2377 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002378 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2379 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002381 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Chas Williams1fa99612006-09-29 17:11:47 -07002383 if (priv->is_trdev)
2384 src = tr_hdr->h_source;
2385 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002387 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
2389 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002390 hlist_for_each_entry_safe(entry, node, next,
2391 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002392 if (vcc == entry->vcc) {
2393 del_timer(&entry->timer);
2394 memcpy(entry->mac_addr, src, ETH_ALEN);
2395 entry->status = ESI_FORWARD_DIRECT;
2396 entry->last_used = jiffies;
2397 /* We might have got an entry */
Joe Perchesc48192a2010-01-26 11:40:08 +00002398 tmp = lec_arp_find(priv, src);
2399 if (tmp) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002400 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002401 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002402 }
2403 hlist_del(&entry->next);
2404 lec_arp_add(priv, entry);
2405 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002406 }
Chas Williams1fa99612006-09-29 17:11:47 -07002407 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002408 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409out:
2410 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2411}
Chas Williams1fa99612006-09-29 17:11:47 -07002412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413MODULE_LICENSE("GPL");