blob: 5da5753157f9d8da1799e93649e52e9f258d85dd [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) {
Joe Perches99824462010-01-26 11:40:00 +0000288 pr_debug("reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
290 kfree_skb(skb);
291 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000292 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700293 skb = skb2;
294 }
295 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Chas Williamsd44f7742006-09-29 17:11:14 -0700297 /* Put le header to place, works for TokenRing too */
298 lec_h = (struct lecdatahdr_8023 *)skb->data;
299 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700302 /*
303 * Ugly. Use this to realign Token Ring packets for
304 * e.g. PCA-200E driver.
305 */
306 if (priv->is_trdev) {
307 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
308 kfree_skb(skb);
309 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000310 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700311 skb = skb2;
312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#endif
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#if DUMP_PACKETS >= 2
Joe Perchesc48192a2010-01-26 11:40:08 +0000316#define MAX_DUMP_SKB 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#elif DUMP_PACKETS >= 1
Joe Perchesc48192a2010-01-26 11:40:08 +0000318#define MAX_DUMP_SKB 30
319#endif
320#if DUMP_PACKETS >= 1
321 printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
322 dev->name, skb->len, priv->lecid);
323 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
324 skb->data, min(skb->len, MAX_DUMP_SKB), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#endif /* DUMP_PACKETS >= 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Chas Williamsd44f7742006-09-29 17:11:14 -0700327 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700329 if (priv->is_trdev)
330 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 else
332#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700333 min_frame_size = LEC_MINIMUM_8023_SIZE;
334 if (skb->len < min_frame_size) {
335 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
336 skb2 = skb_copy_expand(skb, 0,
337 min_frame_size - skb->truesize,
338 GFP_ATOMIC);
339 dev_kfree_skb(skb);
340 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000341 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000342 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700343 }
344 skb = skb2;
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700347 }
348
349 /* Send to right vcc */
350 is_rdesc = 0;
351 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700353 if (priv->is_trdev) {
354 dst = get_tr_dst(skb->data + 2, rdesc);
355 if (dst == NULL) {
356 dst = rdesc;
357 is_rdesc = 1;
358 }
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700361 entry = NULL;
362 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Joe Perches99824462010-01-26 11:40:00 +0000363 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
364 dev->name, vcc, vcc ? vcc->flags : 0, entry);
Chas Williamsd44f7742006-09-29 17:11:14 -0700365 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
366 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Joe Perches99824462010-01-26 11:40:00 +0000367 pr_debug("%s:queuing packet, MAC address %pM\n",
368 dev->name, lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700369 skb_queue_tail(&entry->tx_wait, skb);
370 } else {
Joe Perches99824462010-01-26 11:40:00 +0000371 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
372 dev->name, lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000373 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700374 dev_kfree_skb(skb);
375 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700376 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700377 }
378#if DUMP_PACKETS > 0
Joe Perchesc48192a2010-01-26 11:40:08 +0000379 printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
380 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700382
383 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Joe Perches99824462010-01-26 11:40:00 +0000384 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000385 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Stephen Hemminger162619e2009-01-09 13:01:01 +0000388 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 if (!atm_may_send(vcc, 0)) {
391 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
392
393 vpriv->xoff = 1;
394 netif_stop_queue(dev);
395
396 /*
397 * vcc->pop() might have occurred in between, making
398 * the vcc usuable again. Since xmit is serialized,
399 * this is the only situation we have to re-test.
400 */
401
402 if (atm_may_send(vcc, 0))
403 netif_wake_queue(dev);
404 }
405
Chas Williams6656e3c2006-09-29 17:17:17 -0700406out:
407 if (entry)
408 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000410 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700414static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Chas Williamsd44f7742006-09-29 17:11:14 -0700416 netif_stop_queue(dev);
417 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Chas Williamsd44f7742006-09-29 17:11:14 -0700420static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
422 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700423 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800424 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700425 struct atmlec_msg *mesg;
426 struct lec_arp_table *entry;
427 int i;
428 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700431 mesg = (struct atmlec_msg *)skb->data;
432 tmp = skb->data;
433 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700434 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 switch (mesg->type) {
436 case l_set_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000437 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700438 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
Chas Williamsd44f7742006-09-29 17:11:14 -0700439 break;
440 case l_del_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000441 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700442 dev->dev_addr[i] = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -0700443 break;
444 case l_addr_delete:
445 lec_addr_delete(priv, mesg->content.normal.atm_addr,
446 mesg->content.normal.flag);
447 break;
448 case l_topology_change:
449 priv->topology_change = mesg->content.normal.flag;
450 break;
451 case l_flush_complete:
452 lec_flush_complete(priv, mesg->content.normal.flag);
453 break;
454 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700456 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
457 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
459
Chas Williamsd44f7742006-09-29 17:11:14 -0700460 if (mesg->content.normal.no_source_le_narp)
461 break;
462 /* FALL THROUGH */
463 case l_arp_update:
464 lec_arp_update(priv, mesg->content.normal.mac_addr,
465 mesg->content.normal.atm_addr,
466 mesg->content.normal.flag,
467 mesg->content.normal.targetless_le_arp);
Joe Perches99824462010-01-26 11:40:00 +0000468 pr_debug("in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700469 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Joe Perches99824462010-01-26 11:40:00 +0000470 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
471 mesg->sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -0700472 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
473 tmp, mesg->sizeoftlvs);
474 }
475 break;
476 case l_config:
477 priv->maximum_unknown_frame_count =
478 mesg->content.config.maximum_unknown_frame_count;
479 priv->max_unknown_frame_time =
480 (mesg->content.config.max_unknown_frame_time * HZ);
481 priv->max_retry_count = mesg->content.config.max_retry_count;
482 priv->aging_time = (mesg->content.config.aging_time * HZ);
483 priv->forward_delay_time =
484 (mesg->content.config.forward_delay_time * HZ);
485 priv->arp_response_time =
486 (mesg->content.config.arp_response_time * HZ);
487 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
488 priv->path_switching_delay =
489 (mesg->content.config.path_switching_delay * HZ);
Joe Perchesc48192a2010-01-26 11:40:08 +0000490 priv->lane_version = mesg->content.config.lane_version;
491 /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 priv->lane2_ops = NULL;
493 if (priv->lane_version > 1)
494 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700495 if (dev_set_mtu(dev, mesg->content.config.mtu))
Joe Perchesc48192a2010-01-26 11:40:08 +0000496 pr_info("%s: change_mtu to %d failed\n",
497 dev->name, mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700499 break;
500 case l_flush_tran_id:
501 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
502 mesg->content.normal.flag);
503 break;
504 case l_set_lecid:
505 priv->lecid =
506 (unsigned short)(0xffff & mesg->content.normal.flag);
507 break;
508 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000510 {
511 pr_debug("%s: bridge zeppelin asks about %pM\n",
512 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000514 if (br_fdb_test_addr_hook == NULL)
515 break;
516
517 if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) {
518 /* hit from bridge table, send LE_ARP_RESPONSE */
519 struct sk_buff *skb2;
520 struct sock *sk;
521
522 pr_debug("%s: entry found, responding to zeppelin\n",
523 dev->name);
524 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
525 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700526 break;
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000527 skb2->len = sizeof(struct atmlec_msg);
528 skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg));
529 atm_force_charge(priv->lecd, skb2->truesize);
530 sk = sk_atm(priv->lecd);
531 skb_queue_tail(&sk->sk_receive_queue, skb2);
532 sk->sk_data_ready(sk, skb2->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700533 }
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700536 break;
537 default:
Joe Perchesc48192a2010-01-26 11:40:08 +0000538 pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 dev_kfree_skb(skb);
540 return -EINVAL;
541 }
542 dev_kfree_skb(skb);
543 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Chas Williamsd44f7742006-09-29 17:11:14 -0700546static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Chas Williamsd44f7742006-09-29 17:11:14 -0700548 struct sk_buff *skb;
549 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800550 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 priv->lecd = NULL;
553 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Chas Williamsd44f7742006-09-29 17:11:14 -0700555 netif_stop_queue(dev);
556 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Chas Williamsd44f7742006-09-29 17:11:14 -0700558 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Joe Perchesc48192a2010-01-26 11:40:08 +0000559 pr_info("%s closing with messages pending\n", dev->name);
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000560 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700561 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700563 }
564
Joe Perchesc48192a2010-01-26 11:40:08 +0000565 pr_info("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700566 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700570 .close = lec_atm_close,
571 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572};
573
574static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700575 .ops = &lecdev_ops,
576 .type = "lec",
577 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700578 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579};
580
581/*
582 * LANE2: new argument struct sk_buff *data contains
583 * the LE_ARP based TLVs introduced in the LANE2 spec
584 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700585static int
586send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700587 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700588 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
590 struct sock *sk;
591 struct sk_buff *skb;
592 struct atmlec_msg *mesg;
593
Joe Perchesc48192a2010-01-26 11:40:08 +0000594 if (!priv || !priv->lecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
597 if (!skb)
598 return -1;
599 skb->len = sizeof(struct atmlec_msg);
600 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700601 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700603 if (data != NULL)
604 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (mac_addr)
606 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 else
608 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 if (atm_addr)
610 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
611
Chas Williamsd44f7742006-09-29 17:11:14 -0700612 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 sk = sk_atm(priv->lecd);
614 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700615 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Chas Williamsd44f7742006-09-29 17:11:14 -0700617 if (data != NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000618 pr_debug("about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700619 atm_force_charge(priv->lecd, data->truesize);
620 skb_queue_tail(&sk->sk_receive_queue, data);
621 sk->sk_data_ready(sk, skb->len);
622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Chas Williamsd44f7742006-09-29 17:11:14 -0700624 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
627/* shamelessly stolen from drivers/net/net_init.c */
628static int lec_change_mtu(struct net_device *dev, int new_mtu)
629{
Chas Williamsd44f7742006-09-29 17:11:14 -0700630 if ((new_mtu < 68) || (new_mtu > 18190))
631 return -EINVAL;
632 dev->mtu = new_mtu;
633 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
635
636static void lec_set_multicast_list(struct net_device *dev)
637{
Chas Williamsd44f7742006-09-29 17:11:14 -0700638 /*
639 * by default, all multicast frames arrive over the bus.
640 * eventually support selective multicast service
641 */
642 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
Stephen Hemminger004b3222009-01-09 13:01:02 +0000645static const struct net_device_ops lec_netdev_ops = {
646 .ndo_open = lec_open,
647 .ndo_stop = lec_close,
648 .ndo_start_xmit = lec_start_xmit,
649 .ndo_change_mtu = lec_change_mtu,
650 .ndo_tx_timeout = lec_tx_timeout,
651 .ndo_set_multicast_list = lec_set_multicast_list,
652};
653
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700654static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700655 0xff,
656 0x00,
657 0x01,
658 0x01
659};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Scott Talbert4a7097f2005-09-29 17:30:54 -0700661#define LEC_DATA_DIRECT_8023 2
662#define LEC_DATA_DIRECT_8025 3
663
664static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700665{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700666 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
667 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700668}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700669
Chas Williamsd44f7742006-09-29 17:11:14 -0700670static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700672 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800674 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Joe Perchesc48192a2010-01-26 11:40:08 +0000676#if DUMP_PACKETS > 0
Joe Perches99824462010-01-26 11:40:00 +0000677 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
678 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700680 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700681 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700682 lec_vcc_close(priv, vcc);
683 return;
684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#if DUMP_PACKETS >= 2
Joe Perches99824462010-01-26 11:40:00 +0000686#define MAX_SKB_DUMP 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#elif DUMP_PACKETS >= 1
Joe Perches99824462010-01-26 11:40:00 +0000688#define MAX_SKB_DUMP 30
689#endif
690#if DUMP_PACKETS > 0
691 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
692 dev->name, skb->len, priv->lecid);
693 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
694 skb->data, min(MAX_SKB_DUMP, skb->len), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#endif /* DUMP_PACKETS > 0 */
Joe Perches99824462010-01-26 11:40:00 +0000696 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
697 /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 struct sock *sk = sk_atm(vcc);
699
Stephen Hemminger52240062007-08-28 15:22:09 -0700700 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700701 skb_queue_tail(&sk->sk_receive_queue, skb);
702 sk->sk_data_ready(sk, skb->len);
703 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700704 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700705 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Chas Williamsd44f7742006-09-29 17:11:14 -0700707 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800708 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 !priv->lecd || !(dev->flags & IFF_UP)) {
710 /*
711 * Probably looping back, or if lecd is missing,
712 * lecd has gone down
713 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700714 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700715 dev_kfree_skb(skb);
716 return;
717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700719 if (priv->is_trdev)
720 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
721 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700724
Chas Williamsd44f7742006-09-29 17:11:14 -0700725 /*
726 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700727 * the LE_ARP cache entry, delete the LE_ARP cache entry.
728 */
729 spin_lock_irqsave(&priv->lec_arp_lock, flags);
730 if (lec_is_data_direct(vcc)) {
731#ifdef CONFIG_TR
732 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700733 src =
734 ((struct lecdatahdr_8025 *)skb->data)->
735 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700736 else
737#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 src =
739 ((struct lecdatahdr_8023 *)skb->data)->
740 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700741 entry = lec_arp_find(priv, src);
742 if (entry && entry->vcc != vcc) {
743 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700744 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700745 }
746 }
747 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
750 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700752 dev_kfree_skb(skb);
753 return;
754 }
Joe Perchesc48192a2010-01-26 11:40:08 +0000755 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williamsd44f7742006-09-29 17:11:14 -0700756 lec_arp_check_empties(priv, vcc, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700759 if (priv->is_trdev)
760 skb->protocol = tr_type_trans(skb, dev);
761 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000764 dev->stats.rx_packets++;
765 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700766 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
767 netif_rx(skb);
768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769}
770
Chas Williamsd44f7742006-09-29 17:11:14 -0700771static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
774 struct net_device *dev = skb->dev;
775
776 if (vpriv == NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000777 pr_info("vpriv = NULL!?!?!?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 return;
779 }
780
781 vpriv->old_pop(vcc, skb);
782
783 if (vpriv->xoff && atm_may_send(vcc, 0)) {
784 vpriv->xoff = 0;
785 if (netif_running(dev) && netif_queue_stopped(dev))
786 netif_wake_queue(dev);
787 }
788}
789
Chas Williamsd44f7742006-09-29 17:11:14 -0700790static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
792 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700793 int bytes_left;
794 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Chas Williamsd44f7742006-09-29 17:11:14 -0700796 /* Lecd must be up in this case */
797 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
Joe Perches99824462010-01-26 11:40:00 +0000798 if (bytes_left != 0)
799 pr_info("copy from user failed for %d bytes\n", bytes_left);
Chas Williamsd44f7742006-09-29 17:11:14 -0700800 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
801 !dev_lec[ioc_data.dev_num])
802 return -EINVAL;
Joe Perchesc48192a2010-01-26 11:40:08 +0000803 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
804 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 return -ENOMEM;
806 vpriv->xoff = 0;
807 vpriv->old_pop = vcc->pop;
808 vcc->user_back = vpriv;
809 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800810 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700811 &ioc_data, vcc, vcc->push);
812 vcc->proto_data = dev_lec[ioc_data.dev_num];
813 vcc->push = lec_push;
814 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
816
Chas Williamsd44f7742006-09-29 17:11:14 -0700817static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Chas Williamsd44f7742006-09-29 17:11:14 -0700819 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
820 return -EINVAL;
821 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800822 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
823 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
826/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700827static int lecd_attach(struct atm_vcc *vcc, int arg)
828{
829 int i;
830 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Chas Williamsd44f7742006-09-29 17:11:14 -0700832 if (arg < 0)
833 i = 0;
834 else
835 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700837 if (arg >= MAX_LEC_ITF)
838 return -EINVAL;
839#else /* Reserve the top NUM_TR_DEVS for TR */
840 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
841 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700843 if (!dev_lec[i]) {
844 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Chas Williamsd44f7742006-09-29 17:11:14 -0700846 is_trdev = 0;
847 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
848 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Chas Williamsd44f7742006-09-29 17:11:14 -0700850 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700852 if (is_trdev)
853 dev_lec[i] = alloc_trdev(size);
854 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700856 dev_lec[i] = alloc_etherdev(size);
857 if (!dev_lec[i])
858 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000859 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700860 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
861 if (register_netdev(dev_lec[i])) {
862 free_netdev(dev_lec[i]);
863 return -EINVAL;
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Wang Chen524ad0a2008-11-12 23:39:10 -0800866 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700867 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700868 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800869 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700870 if (priv->lecd)
871 return -EADDRINUSE;
872 }
873 lec_arp_init(priv);
874 priv->itfnum = i; /* LANE2 addition */
875 priv->lecd = vcc;
876 vcc->dev = &lecatm_dev;
877 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Chas Williamsd44f7742006-09-29 17:11:14 -0700879 vcc->proto_data = dev_lec[i];
880 set_bit(ATM_VF_META, &vcc->flags);
881 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Chas Williamsd44f7742006-09-29 17:11:14 -0700883 /* Set default values to these variables */
884 priv->maximum_unknown_frame_count = 1;
885 priv->max_unknown_frame_time = (1 * HZ);
886 priv->vcc_timeout_period = (1200 * HZ);
887 priv->max_retry_count = 1;
888 priv->aging_time = (300 * HZ);
889 priv->forward_delay_time = (15 * HZ);
890 priv->topology_change = 0;
891 priv->arp_response_time = (1 * HZ);
892 priv->flush_timeout = (4 * HZ);
893 priv->path_switching_delay = (6 * HZ);
894
Joe Perchesc48192a2010-01-26 11:40:08 +0000895 if (dev_lec[i]->flags & IFF_UP)
Chas Williamsd44f7742006-09-29 17:11:14 -0700896 netif_start_queue(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700897 __module_get(THIS_MODULE);
898 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700902static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700904 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 "ESI_UNKNOWN ",
906 "ESI_ARP_PENDING ",
907 "ESI_VC_PENDING ",
908 "<Undefined> ",
909 "ESI_FLUSH_PENDING ",
910 "ESI_FORWARD_DIRECT"
911 };
912
913 if (status > ESI_FORWARD_DIRECT)
914 status = 3; /* ESI_UNDEFINED */
915 return lec_arp_status_string[status];
916}
917
918static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
919{
920 int i;
921
922 for (i = 0; i < ETH_ALEN; i++)
923 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
924 seq_printf(seq, " ");
925 for (i = 0; i < ATM_ESA_LEN; i++)
926 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
927 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
928 entry->flags & 0xffff);
929 if (entry->vcc)
930 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
931 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700932 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (entry->recv_vcc) {
934 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
935 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700936 }
937 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940struct lec_state {
941 unsigned long flags;
942 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700943 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 struct net_device *dev;
945 int itf;
946 int arp_table;
947 int misc_table;
948};
949
Chas Williamsd0732f62006-09-29 17:14:27 -0700950static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 loff_t *l)
952{
Chas Williamsd0732f62006-09-29 17:14:27 -0700953 struct hlist_node *e = state->node;
954 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700957 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700958 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700959 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 --*l;
961 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700962
963 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 if (--*l < 0)
965 break;
966 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700967 state->node = e;
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return (*l < 0) ? state : NULL;
970}
971
972static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -0700973 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
975 void *v = NULL;
976 int p;
977
978 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700979 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (v)
981 break;
982 }
983 state->arp_table = p;
984 return v;
985}
986
987static void *lec_misc_walk(struct lec_state *state, loff_t *l,
988 struct lec_priv *priv)
989{
Chas Williamsd0732f62006-09-29 17:14:27 -0700990 struct hlist_head *lec_misc_tables[] = {
991 &priv->lec_arp_empty_ones,
992 &priv->lec_no_forward,
993 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 };
995 void *v = NULL;
996 int q;
997
998 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
999 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1000 if (v)
1001 break;
1002 }
1003 state->misc_table = q;
1004 return v;
1005}
1006
1007static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1008 struct lec_priv *priv)
1009{
1010 if (!state->locked) {
1011 state->locked = priv;
1012 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1013 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001014 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1016 state->locked = NULL;
1017 /* Partial state reset for the next time we get called */
1018 state->arp_table = state->misc_table = 0;
1019 }
1020 return state->locked;
1021}
1022
1023static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1024{
1025 struct net_device *dev;
1026 void *v;
1027
1028 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001029 v = (dev && netdev_priv(dev)) ?
1030 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (!v && dev) {
1032 dev_put(dev);
1033 /* Partial state reset for the next time we get called */
1034 dev = NULL;
1035 }
1036 state->dev = dev;
1037 return v;
1038}
1039
1040static void *lec_get_idx(struct lec_state *state, loff_t l)
1041{
1042 void *v = NULL;
1043
1044 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1045 v = lec_itf_walk(state, &l);
1046 if (v)
1047 break;
1048 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001049 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
1052static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1053{
1054 struct lec_state *state = seq->private;
1055
1056 state->itf = 0;
1057 state->dev = NULL;
1058 state->locked = NULL;
1059 state->arp_table = 0;
1060 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001061 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Joe Perches2e1e9842008-04-10 03:33:03 -07001063 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
1066static void lec_seq_stop(struct seq_file *seq, void *v)
1067{
1068 struct lec_state *state = seq->private;
1069
1070 if (state->dev) {
1071 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1072 state->flags);
1073 dev_put(state->dev);
1074 }
1075}
1076
1077static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1078{
1079 struct lec_state *state = seq->private;
1080
1081 v = lec_get_idx(state, 1);
1082 *pos += !!PTR_ERR(v);
1083 return v;
1084}
1085
1086static int lec_seq_show(struct seq_file *seq, void *v)
1087{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001088 static const char lec_banner[] =
1089 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001090 " Status Flags "
1091 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Joe Perches2e1e9842008-04-10 03:33:03 -07001093 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 seq_puts(seq, lec_banner);
1095 else {
1096 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001097 struct net_device *dev = state->dev;
Joe Perchesc48192a2010-01-26 11:40:08 +00001098 struct lec_arp_table *entry = hlist_entry(state->node,
1099 struct lec_arp_table,
1100 next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001103 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 }
1105 return 0;
1106}
1107
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001108static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001109 .start = lec_seq_start,
1110 .next = lec_seq_next,
1111 .stop = lec_seq_stop,
1112 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113};
1114
1115static int lec_seq_open(struct inode *inode, struct file *file)
1116{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001117 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Arjan van de Ven9a321442007-02-12 00:55:35 -08001120static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001121 .owner = THIS_MODULE,
1122 .open = lec_seq_open,
1123 .read = seq_read,
1124 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001125 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126};
1127#endif
1128
1129static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1130{
1131 struct atm_vcc *vcc = ATM_SD(sock);
1132 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001135 case ATMLEC_CTRL:
1136 case ATMLEC_MCAST:
1137 case ATMLEC_DATA:
1138 if (!capable(CAP_NET_ADMIN))
1139 return -EPERM;
1140 break;
1141 default:
1142 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144
1145 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001146 case ATMLEC_CTRL:
1147 err = lecd_attach(vcc, (int)arg);
1148 if (err >= 0)
1149 sock->state = SS_CONNECTED;
1150 break;
1151 case ATMLEC_MCAST:
1152 err = lec_mcast_attach(vcc, (int)arg);
1153 break;
1154 case ATMLEC_DATA:
1155 err = lec_vcc_attach(vcc, (void __user *)arg);
1156 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
1158
1159 return err;
1160}
1161
1162static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001163 .owner = THIS_MODULE,
1164 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165};
1166
1167static int __init lane_module_init(void)
1168{
1169#ifdef CONFIG_PROC_FS
1170 struct proc_dir_entry *p;
1171
Wang Chen16e297b2008-02-28 13:55:45 -08001172 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001173 if (!p) {
Joe Perches99824462010-01-26 11:40:00 +00001174 pr_err("Unable to initialize /proc/net/atm/lec\n");
Wang Chendbee0d32008-03-23 21:45:36 -07001175 return -ENOMEM;
1176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177#endif
1178
1179 register_atm_ioctl(&lane_ioctl_ops);
Joe Perchesc48192a2010-01-26 11:40:08 +00001180 pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001181 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
1184static void __exit lane_module_cleanup(void)
1185{
Chas Williamsd44f7742006-09-29 17:11:14 -07001186 int i;
1187 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 remove_proc_entry("lec", atm_proc_root);
1190
1191 deregister_atm_ioctl(&lane_ioctl_ops);
1192
Chas Williamsd44f7742006-09-29 17:11:14 -07001193 for (i = 0; i < MAX_LEC_ITF; i++) {
1194 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001195 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001197 free_netdev(dev_lec[i]);
1198 dev_lec[i] = NULL;
1199 }
1200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Chas Williamsd44f7742006-09-29 17:11:14 -07001202 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
1205module_init(lane_module_init);
1206module_exit(lane_module_cleanup);
1207
1208/*
1209 * LANE2: 3.1.3, LE_RESOLVE.request
1210 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1211 * If sizeoftlvs == NULL the default TLVs associated with with this
1212 * lec will be used.
1213 * If dst_mac == NULL, targetless LE_ARP will be sent
1214 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001215static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001216 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
1218 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001219 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001220 struct lec_arp_table *table;
1221 struct sk_buff *skb;
1222 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Chas Williamsd44f7742006-09-29 17:11:14 -07001224 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001226 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001228 if (table == NULL)
1229 return -1;
1230
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001231 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001232 if (*tlvs == NULL)
1233 return -1;
1234
Chas Williamsd44f7742006-09-29 17:11:14 -07001235 *sizeoftlvs = table->sizeoftlvs;
1236
1237 return 0;
1238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 if (sizeoftlvs == NULL)
1241 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 else {
1244 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1245 if (skb == NULL)
1246 return -1;
1247 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001248 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1250 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001251 return retval;
1252}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254/*
1255 * LANE2: 3.1.4, LE_ASSOCIATE.request
1256 * Associate the *tlvs with the *lan_dst address.
1257 * Will overwrite any previous association
1258 * Returns 1 for success, 0 for failure (out of memory)
1259 *
1260 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001261static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1262 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Chas Williamsd44f7742006-09-29 17:11:14 -07001264 int retval;
1265 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001266 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Chas Williamsd44f7742006-09-29 17:11:14 -07001268 if (compare_ether_addr(lan_dst, dev->dev_addr))
Joe Perchesc48192a2010-01-26 11:40:08 +00001269 return 0; /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001273 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001274 if (priv->tlvs == NULL)
Joe Perchesc48192a2010-01-26 11:40:08 +00001275 return 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001276 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Chas Williamsd44f7742006-09-29 17:11:14 -07001278 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1279 if (skb == NULL)
1280 return 0;
1281 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001282 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001283 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1284 if (retval != 0)
Joe Perchesc48192a2010-01-26 11:40:08 +00001285 pr_info("lec.c: lane2_associate_req() failed\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001286 /*
1287 * If the previous association has changed we must
1288 * somehow notify other LANE entities about the change
1289 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001290 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291}
1292
1293/*
1294 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1295 *
1296 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001297static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1298 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001301 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001303 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001304#if 0 /*
1305 * Why have the TLVs in LE_ARP entries
1306 * since we do not use them? When you
1307 * uncomment this code, make sure the
1308 * TLVs get freed when entry is killed
1309 */
1310 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Chas Williamsd44f7742006-09-29 17:11:14 -07001312 if (entry == NULL)
1313 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001317 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001318 if (entry->tlvs == NULL)
1319 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001320 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321#endif
1322#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001323 pr_info("\n");
1324 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001325 while (i < sizeoftlvs)
Joe Perchesc48192a2010-01-26 11:40:08 +00001326 pr_cont("%02x ", tlvs[i++]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001327
Joe Perchesc48192a2010-01-26 11:40:08 +00001328 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329#endif
1330
Chas Williamsd44f7742006-09-29 17:11:14 -07001331 /* tell MPOA about the TLVs we saw */
1332 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1333 priv->lane2_ops->associate_indicator(dev, mac_addr,
1334 tlvs, sizeoftlvs);
1335 }
1336 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
1339/*
1340 * Here starts what used to lec_arpc.c
1341 *
1342 * lec_arpc.c was added here when making
1343 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 */
1345
1346#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347#include <linux/timer.h>
Joe Perchesc48192a2010-01-26 11:40:08 +00001348#include <linux/param.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349#include <asm/atomic.h>
1350#include <linux/inetdevice.h>
1351#include <net/route.h>
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001354#define pr_debug(format, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355/*
Joe Perches99824462010-01-26 11:40:00 +00001356 #define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357*/
1358#endif
1359#define DEBUG_ARP_TABLE 0
1360
1361#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1362
David Howellsc4028952006-11-22 14:57:56 +00001363static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364static void lec_arp_expire_arp(unsigned long data);
1365
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001366/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 * Arp table funcs
1368 */
1369
Joe Perchesc48192a2010-01-26 11:40:08 +00001370#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
1372/*
1373 * Initialization of arp-cache
1374 */
Chas Williams1fa99612006-09-29 17:11:47 -07001375static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Chas Williams1fa99612006-09-29 17:11:47 -07001377 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Joe Perchesc48192a2010-01-26 11:40:08 +00001379 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07001380 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001381 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1382 INIT_HLIST_HEAD(&priv->lec_no_forward);
1383 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001385 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001386 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
Chas Williams1fa99612006-09-29 17:11:47 -07001389static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Chas Williams1fa99612006-09-29 17:11:47 -07001391 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 struct atm_vcc *vcc = entry->vcc;
1393 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001394 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Chas Williams1fa99612006-09-29 17:11:47 -07001396 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (vpriv->xoff)
1398 netif_wake_queue(dev);
1399 kfree(vpriv);
1400 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001401 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001403 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001404 }
1405 if (entry->recv_vcc) {
1406 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001408 entry->recv_vcc = NULL;
1409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
1412/*
1413 * Insert entry to lec_arp_table
1414 * LANE2: Add to the end of the list to satisfy 8.1.13
1415 */
Chas Williams1fa99612006-09-29 17:11:47 -07001416static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001417lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418{
Chas Williamsd0732f62006-09-29 17:14:27 -07001419 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Chas Williamsd0732f62006-09-29 17:14:27 -07001421 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1422 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001423
Joe Perches99824462010-01-26 11:40:00 +00001424 pr_debug("Added entry:%pM\n", entry->mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
1427/*
1428 * Remove entry from lec_arp_table
1429 */
Chas Williams1fa99612006-09-29 17:11:47 -07001430static int
1431lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432{
Chas Williamsd0732f62006-09-29 17:14:27 -07001433 struct hlist_node *node;
1434 struct lec_arp_table *entry;
1435 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Joe Perchesc48192a2010-01-26 11:40:08 +00001437 if (!to_remove)
Chas Williams1fa99612006-09-29 17:11:47 -07001438 return -1;
Chas Williamsd0732f62006-09-29 17:14:27 -07001439
1440 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001441 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Joe Perchesc48192a2010-01-26 11:40:08 +00001443 /*
1444 * If this is the only MAC connected to this VCC,
1445 * also tear down the VCC
1446 */
Chas Williams1fa99612006-09-29 17:11:47 -07001447 if (to_remove->status >= ESI_FLUSH_PENDING) {
1448 /*
1449 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1450 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001451 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001452 hlist_for_each_entry(entry, node,
1453 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001454 if (memcmp(to_remove->atm_addr,
1455 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001456 remove_vcc = 0;
1457 break;
1458 }
1459 }
1460 }
1461 if (remove_vcc)
1462 lec_arp_clear_vccs(to_remove);
1463 }
1464 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1465
Joe Perches99824462010-01-26 11:40:00 +00001466 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001467 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
1470#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001471static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Chas Williams1fa99612006-09-29 17:11:47 -07001473 switch (st) {
1474 case ESI_UNKNOWN:
1475 return "ESI_UNKNOWN";
1476 case ESI_ARP_PENDING:
1477 return "ESI_ARP_PENDING";
1478 case ESI_VC_PENDING:
1479 return "ESI_VC_PENDING";
1480 case ESI_FLUSH_PENDING:
1481 return "ESI_FLUSH_PENDING";
1482 case ESI_FORWARD_DIRECT:
1483 return "ESI_FORWARD_DIRECT";
Chas Williams1fa99612006-09-29 17:11:47 -07001484 }
Joe Perchesc48192a2010-01-26 11:40:08 +00001485 return "<UNKNOWN>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Chas Williams1fa99612006-09-29 17:11:47 -07001488static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Chas Williamsd0732f62006-09-29 17:14:27 -07001490 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001491 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001492 char buf[256];
1493 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Joe Perchesc48192a2010-01-26 11:40:08 +00001495 pr_info("Dump %p:\n", priv);
Chas Williams1fa99612006-09-29 17:11:47 -07001496 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001497 hlist_for_each_entry(rulla, node,
1498 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001499 offset = 0;
1500 offset += sprintf(buf, "%d: %p\n", i, rulla);
Joe Perchesc48192a2010-01-26 11:40:08 +00001501 offset += sprintf(buf + offset, "Mac: %pM",
1502 rulla->mac_addr);
1503 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001504 for (j = 0; j < ATM_ESA_LEN; j++) {
1505 offset += sprintf(buf + offset,
1506 "%2.2x ",
1507 rulla->atm_addr[j] & 0xff);
1508 }
1509 offset += sprintf(buf + offset,
1510 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1511 rulla->vcc ? rulla->vcc->vpi : 0,
1512 rulla->vcc ? rulla->vcc->vci : 0,
1513 rulla->recv_vcc ? rulla->recv_vcc->
1514 vpi : 0,
1515 rulla->recv_vcc ? rulla->recv_vcc->
1516 vci : 0, rulla->last_used,
1517 rulla->timestamp, rulla->no_tries);
1518 offset +=
1519 sprintf(buf + offset,
1520 "Flags:%x, Packets_flooded:%x, Status: %s ",
1521 rulla->flags, rulla->packets_flooded,
1522 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001523 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001524 }
Chas Williams1fa99612006-09-29 17:11:47 -07001525 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001526
1527 if (!hlist_empty(&priv->lec_no_forward))
Joe Perchesc48192a2010-01-26 11:40:08 +00001528 pr_info("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001529 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001530 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001531 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1532 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001533 for (j = 0; j < ATM_ESA_LEN; j++) {
1534 offset += sprintf(buf + offset, "%2.2x ",
1535 rulla->atm_addr[j] & 0xff);
1536 }
1537 offset += sprintf(buf + offset,
1538 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1539 rulla->vcc ? rulla->vcc->vpi : 0,
1540 rulla->vcc ? rulla->vcc->vci : 0,
1541 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1542 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1543 rulla->last_used,
1544 rulla->timestamp, rulla->no_tries);
1545 offset += sprintf(buf + offset,
1546 "Flags:%x, Packets_flooded:%x, Status: %s ",
1547 rulla->flags, rulla->packets_flooded,
1548 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001549 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001550 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001551
1552 if (!hlist_empty(&priv->lec_arp_empty_ones))
Joe Perchesc48192a2010-01-26 11:40:08 +00001553 pr_info("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001554 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001555 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001556 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1557 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001558 for (j = 0; j < ATM_ESA_LEN; j++) {
1559 offset += sprintf(buf + offset, "%2.2x ",
1560 rulla->atm_addr[j] & 0xff);
1561 }
1562 offset += sprintf(buf + offset,
1563 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1564 rulla->vcc ? rulla->vcc->vpi : 0,
1565 rulla->vcc ? rulla->vcc->vci : 0,
1566 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1567 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1568 rulla->last_used,
1569 rulla->timestamp, rulla->no_tries);
1570 offset += sprintf(buf + offset,
1571 "Flags:%x, Packets_flooded:%x, Status: %s ",
1572 rulla->flags, rulla->packets_flooded,
1573 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001574 pr_info("%s", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Chas Williamsd0732f62006-09-29 17:14:27 -07001577 if (!hlist_empty(&priv->mcast_fwds))
Joe Perchesc48192a2010-01-26 11:40:08 +00001578 pr_info("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001579 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001580 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001581 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1582 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001583 for (j = 0; j < ATM_ESA_LEN; j++) {
1584 offset += sprintf(buf + offset, "%2.2x ",
1585 rulla->atm_addr[j] & 0xff);
1586 }
1587 offset += sprintf(buf + offset,
1588 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1589 rulla->vcc ? rulla->vcc->vpi : 0,
1590 rulla->vcc ? rulla->vcc->vci : 0,
1591 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1592 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1593 rulla->last_used,
1594 rulla->timestamp, rulla->no_tries);
1595 offset += sprintf(buf + offset,
1596 "Flags:%x, Packets_flooded:%x, Status: %s ",
1597 rulla->flags, rulla->packets_flooded,
1598 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001599 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
Chas Williamsd0732f62006-09-29 17:14:27 -07001603#else
1604#define dump_arp_table(priv) do { } while (0)
1605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
1607/*
1608 * Destruction of arp-cache
1609 */
Chas Williams1fa99612006-09-29 17:11:47 -07001610static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
1612 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001613 struct hlist_node *node, *next;
1614 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001615 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Chas Williams987e46b2006-09-29 17:15:59 -07001617 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001618
1619 /*
1620 * Remove all entries
1621 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001624 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001625 hlist_for_each_entry_safe(entry, node, next,
1626 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001627 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001628 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001629 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001630 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001631 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001632
Joe Perchesc48192a2010-01-26 11:40:08 +00001633 hlist_for_each_entry_safe(entry, node, next,
1634 &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001635 del_timer_sync(&entry->timer);
1636 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001637 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001638 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001639 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001640 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1641
Joe Perchesc48192a2010-01-26 11:40:08 +00001642 hlist_for_each_entry_safe(entry, node, next,
1643 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001644 del_timer_sync(&entry->timer);
1645 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001646 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001647 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001648 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001649 INIT_HLIST_HEAD(&priv->lec_no_forward);
1650
1651 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001652 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1653 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001654 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001655 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001656 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001657 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001658 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1660}
1661
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001662/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 * Find entry by mac_address
1664 */
Chas Williams1fa99612006-09-29 17:11:47 -07001665static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001666 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
Chas Williamsd0732f62006-09-29 17:14:27 -07001668 struct hlist_node *node;
1669 struct hlist_head *head;
1670 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Joe Perches99824462010-01-26 11:40:00 +00001672 pr_debug("%pM\n", mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001673
Chas Williamsd0732f62006-09-29 17:14:27 -07001674 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1675 hlist_for_each_entry(entry, node, head, next) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001676 if (!compare_ether_addr(mac_addr, entry->mac_addr))
Chas Williamsd0732f62006-09-29 17:14:27 -07001677 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001678 }
1679 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
Chas Williams1fa99612006-09-29 17:11:47 -07001682static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001683 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Chas Williams1fa99612006-09-29 17:11:47 -07001685 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Chas Williams1fa99612006-09-29 17:11:47 -07001687 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1688 if (!to_return) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001689 pr_info("LEC: Arp entry kmalloc failed\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001690 return NULL;
1691 }
1692 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001693 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001694 setup_timer(&to_return->timer, lec_arp_expire_arp,
1695 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001696 to_return->last_used = jiffies;
1697 to_return->priv = priv;
1698 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001699 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001700 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Chas Williams1fa99612006-09-29 17:11:47 -07001703/* Arp sent timer expired */
1704static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Chas Williams1fa99612006-09-29 17:11:47 -07001706 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Chas Williams1fa99612006-09-29 17:11:47 -07001708 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Joe Perches99824462010-01-26 11:40:00 +00001710 pr_debug("\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001711 if (entry->status == ESI_ARP_PENDING) {
1712 if (entry->no_tries <= entry->priv->max_retry_count) {
1713 if (entry->is_rdesc)
1714 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1715 entry->mac_addr, NULL, NULL);
1716 else
1717 send_to_lecd(entry->priv, l_arp_xmt,
1718 entry->mac_addr, NULL, NULL);
1719 entry->no_tries++;
1720 }
1721 mod_timer(&entry->timer, jiffies + (1 * HZ));
1722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723}
1724
Chas Williams1fa99612006-09-29 17:11:47 -07001725/* Unknown/unused vcc expire, remove associated entry */
1726static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727{
1728 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001729 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1730 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Chas Williams1fa99612006-09-29 17:11:47 -07001732 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Joe Perches99824462010-01-26 11:40:00 +00001734 pr_debug("%p %p: vpi:%d vci:%d\n",
1735 to_remove, priv,
1736 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1737 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
1739 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1742
Chas Williams1fa99612006-09-29 17:11:47 -07001743 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001744 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001747static bool __lec_arp_check_expire(struct lec_arp_table *entry,
1748 unsigned long now,
1749 struct lec_priv *priv)
1750{
1751 unsigned long time_to_check;
1752
1753 if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
1754 time_to_check = priv->forward_delay_time;
1755 else
1756 time_to_check = priv->aging_time;
1757
1758 pr_debug("About to expire: %lx - %lx > %lx\n",
1759 now, entry->last_used, time_to_check);
1760 if (time_after(now, entry->last_used + time_to_check) &&
1761 !(entry->flags & LEC_PERMANENT_FLAG) &&
1762 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1763 /* Remove entry */
1764 pr_debug("Entry timed out\n");
1765 lec_arp_remove(priv, entry);
1766 lec_arp_put(entry);
1767 } else {
1768 /* Something else */
1769 if ((entry->status == ESI_VC_PENDING ||
1770 entry->status == ESI_ARP_PENDING) &&
1771 time_after_eq(now, entry->timestamp +
1772 priv->max_unknown_frame_time)) {
1773 entry->timestamp = jiffies;
1774 entry->packets_flooded = 0;
1775 if (entry->status == ESI_VC_PENDING)
1776 send_to_lecd(priv, l_svc_setup,
1777 entry->mac_addr,
1778 entry->atm_addr,
1779 NULL);
1780 }
1781 if (entry->status == ESI_FLUSH_PENDING &&
1782 time_after_eq(now, entry->timestamp +
1783 priv->path_switching_delay)) {
1784 lec_arp_hold(entry);
1785 return true;
1786 }
1787 }
1788
1789 return false;
1790}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791/*
1792 * Expire entries.
1793 * 1. Re-set timer
1794 * 2. For each entry, delete entries that have aged past the age limit.
1795 * 3. For each entry, depending on the status of the entry, perform
1796 * the following maintenance.
1797 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1798 * tick_count is above the max_unknown_frame_time, clear
1799 * the tick_count to zero and clear the packets_flooded counter
1800 * to zero. This supports the packet rate limit per address
1801 * while flooding unknowns.
1802 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1803 * than or equal to the path_switching_delay, change the status
1804 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1805 * regardless of the progress of the flush protocol.
1806 */
David Howellsc4028952006-11-22 14:57:56 +00001807static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808{
1809 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001810 struct lec_priv *priv =
1811 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001812 struct hlist_node *node, *next;
1813 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001814 unsigned long now;
Chas Williams1fa99612006-09-29 17:11:47 -07001815 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Joe Perches99824462010-01-26 11:40:00 +00001817 pr_debug("%p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001819restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001821 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001822 hlist_for_each_entry_safe(entry, node, next,
1823 &priv->lec_arp_tables[i], next) {
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001824 if (__lec_arp_check_expire(entry, now, priv)) {
1825 struct sk_buff *skb;
1826 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001828 spin_unlock_irqrestore(&priv->lec_arp_lock,
1829 flags);
1830 while ((skb = skb_dequeue(&entry->tx_wait)))
1831 lec_send(vcc, skb);
1832 entry->last_used = jiffies;
1833 entry->status = ESI_FORWARD_DIRECT;
Chas Williams33a9c2d2006-09-29 17:16:48 -07001834 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001836 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 }
1838 }
1839 }
1840 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1841
Chas Williams987e46b2006-09-29 17:15:59 -07001842 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
Chas Williams1fa99612006-09-29 17:11:47 -07001844
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845/*
1846 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001847 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 */
Chas Williams1fa99612006-09-29 17:11:47 -07001849static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Joe Perchesc48192a2010-01-26 11:40:08 +00001850 const unsigned char *mac_to_find,
1851 int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001852 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001855 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 struct atm_vcc *found;
1857
Chas Williams1fa99612006-09-29 17:11:47 -07001858 if (mac_to_find[0] & 0x01) {
1859 switch (priv->lane_version) {
1860 case 1:
1861 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001862 case 2: /* LANE2 wants arp for multicast addresses */
1863 if (!compare_ether_addr(mac_to_find, bus_mac))
1864 return priv->mcast_vcc;
1865 break;
1866 default:
1867 break;
1868 }
1869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001872 entry = lec_arp_find(priv, mac_to_find);
1873
1874 if (entry) {
1875 if (entry->status == ESI_FORWARD_DIRECT) {
1876 /* Connection Ok */
1877 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001878 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001879 *ret_entry = entry;
1880 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001882 }
1883 /*
1884 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001885 * so another LE_ARP request can be made for this frame.
1886 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001887 if (entry->status == ESI_ARP_PENDING)
Scott Talbert75b895c2005-09-29 17:31:30 -07001888 entry->no_tries = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07001889 /*
1890 * Data direct VC not yet set up, check to see if the unknown
1891 * frame count is greater than the limit. If the limit has
1892 * not been reached, allow the caller to send packet to
1893 * BUS.
1894 */
1895 if (entry->status != ESI_FLUSH_PENDING &&
1896 entry->packets_flooded <
1897 priv->maximum_unknown_frame_count) {
1898 entry->packets_flooded++;
Joe Perches99824462010-01-26 11:40:00 +00001899 pr_debug("Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001900 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001902 }
1903 /*
1904 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 * or BUS flood limit was reached for an entry which is
1906 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1907 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001908 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001909 *ret_entry = entry;
Joe Perches99824462010-01-26 11:40:00 +00001910 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1911 entry->vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001912 found = NULL;
1913 } else {
1914 /* No matching entry was found */
1915 entry = make_entry(priv, mac_to_find);
Joe Perches99824462010-01-26 11:40:00 +00001916 pr_debug("Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001917 if (!entry) {
1918 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001920 }
1921 lec_arp_add(priv, entry);
1922 /* We want arp-request(s) to be sent */
1923 entry->packets_flooded = 1;
1924 entry->status = ESI_ARP_PENDING;
1925 entry->no_tries = 1;
1926 entry->last_used = entry->timestamp = jiffies;
1927 entry->is_rdesc = is_rdesc;
1928 if (entry->is_rdesc)
1929 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1930 NULL);
1931 else
1932 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1933 entry->timer.expires = jiffies + (1 * HZ);
1934 entry->timer.function = lec_arp_expire_arp;
1935 add_timer(&entry->timer);
1936 found = priv->mcast_vcc;
1937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
1939out:
1940 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1941 return found;
1942}
1943
1944static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001945lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001946 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001949 struct hlist_node *node, *next;
1950 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001951 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Joe Perches99824462010-01-26 11:40:00 +00001953 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001955 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001956 hlist_for_each_entry_safe(entry, node, next,
1957 &priv->lec_arp_tables[i], next) {
1958 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
1959 (permanent ||
1960 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001962 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001965 return 0;
1966 }
1967 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001969 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970}
1971
1972/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001973 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 */
1975static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001976lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1977 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07001978 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
1980 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001981 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07001982 struct lec_arp_table *entry, *tmp;
1983 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Joe Perches99824462010-01-26 11:40:00 +00001985 pr_debug("%smac:%pM\n",
1986 (targetless_le_arp) ? "targetless " : "", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001989 entry = lec_arp_find(priv, mac_addr);
1990 if (entry == NULL && targetless_le_arp)
1991 goto out; /*
1992 * LANE2: ignore targetless LE_ARPs for which
1993 * we have no entry in the cache. 7.1.30
1994 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001995 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001996 hlist_for_each_entry_safe(entry, node, next,
1997 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001998 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
1999 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002000 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002001 tmp = lec_arp_find(priv, mac_addr);
2002 if (tmp) {
2003 del_timer(&tmp->timer);
2004 tmp->status = ESI_FORWARD_DIRECT;
2005 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2006 tmp->vcc = entry->vcc;
2007 tmp->old_push = entry->old_push;
2008 tmp->last_used = jiffies;
2009 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002010 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002011 entry = tmp;
2012 } else {
2013 entry->status = ESI_FORWARD_DIRECT;
2014 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2015 entry->last_used = jiffies;
2016 lec_arp_add(priv, entry);
2017 }
2018 if (remoteflag)
2019 entry->flags |= LEC_REMOTE_FLAG;
2020 else
2021 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002022 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002023 dump_arp_table(priv);
2024 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002025 }
Chas Williams1fa99612006-09-29 17:11:47 -07002026 }
2027 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002028
Chas Williams1fa99612006-09-29 17:11:47 -07002029 entry = lec_arp_find(priv, mac_addr);
2030 if (!entry) {
2031 entry = make_entry(priv, mac_addr);
2032 if (!entry)
2033 goto out;
2034 entry->status = ESI_UNKNOWN;
2035 lec_arp_add(priv, entry);
2036 /* Temporary, changes before end of function */
2037 }
2038 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2039 del_timer(&entry->timer);
2040 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002041 hlist_for_each_entry(tmp, node,
2042 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002043 if (entry != tmp &&
2044 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2045 /* Vcc to this host exists */
2046 if (tmp->status > ESI_VC_PENDING) {
2047 /*
2048 * ESI_FLUSH_PENDING,
2049 * ESI_FORWARD_DIRECT
2050 */
2051 entry->vcc = tmp->vcc;
2052 entry->old_push = tmp->old_push;
2053 }
2054 entry->status = tmp->status;
2055 break;
2056 }
2057 }
2058 }
2059 if (remoteflag)
2060 entry->flags |= LEC_REMOTE_FLAG;
2061 else
2062 entry->flags &= ~LEC_REMOTE_FLAG;
2063 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2064 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002065 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002066 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002067 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002068 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069out:
2070 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2071}
2072
2073/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002074 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 */
2076static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002077lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002078 struct atm_vcc *vcc,
2079 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
2081 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002082 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002083 struct lec_arp_table *entry;
2084 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002087 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williams1fa99612006-09-29 17:11:47 -07002088 if (ioc_data->receive == 2) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002089 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002091 entry = lec_arp_find(priv, bus_mac);
2092 if (!entry) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002093 pr_info("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002095 }
2096 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2097 entry->recv_vcc = vcc;
2098 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002100 entry = make_entry(priv, bus_mac);
2101 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002103 del_timer(&entry->timer);
2104 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2105 entry->recv_vcc = vcc;
2106 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002107 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002108 goto out;
2109 } else if (ioc_data->receive == 1) {
2110 /*
2111 * Vcc which we don't want to make default vcc,
2112 * attach it anyway.
2113 */
Joe Perches99824462010-01-26 11:40:00 +00002114 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",
2115 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2116 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2117 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2118 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2119 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2120 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2121 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2122 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2123 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2124 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002125 entry = make_entry(priv, bus_mac);
2126 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002128 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2129 memset(entry->mac_addr, 0, ETH_ALEN);
2130 entry->recv_vcc = vcc;
2131 entry->old_recv_push = old_push;
2132 entry->status = ESI_UNKNOWN;
2133 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2134 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002135 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002136 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 dump_arp_table(priv);
2138 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002139 }
Joe Perches99824462010-01-26 11:40:00 +00002140 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",
2141 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2142 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2143 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2144 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2145 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2146 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2147 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2148 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2149 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2150 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002151 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002152 hlist_for_each_entry(entry, node,
2153 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002154 if (memcmp
2155 (ioc_data->atm_addr, entry->atm_addr,
2156 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002157 pr_debug("LEC_ARP: Attaching data direct\n");
2158 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Joe Perches99824462010-01-26 11:40:00 +00002159 entry->vcc ? entry->vcc->vci : 0,
2160 entry->recv_vcc ? entry->recv_vcc->
2161 vci : 0);
Chas Williams1fa99612006-09-29 17:11:47 -07002162 found_entry = 1;
2163 del_timer(&entry->timer);
2164 entry->vcc = vcc;
2165 entry->old_push = old_push;
2166 if (entry->status == ESI_VC_PENDING) {
2167 if (priv->maximum_unknown_frame_count
2168 == 0)
2169 entry->status =
2170 ESI_FORWARD_DIRECT;
2171 else {
2172 entry->timestamp = jiffies;
2173 entry->status =
2174 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002176 send_to_lecd(priv, l_flush_xmt,
2177 NULL,
2178 entry->atm_addr,
2179 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002181 }
2182 } else {
2183 /*
2184 * They were forming a connection
2185 * to us, and we to them. Our
2186 * ATM address is numerically lower
2187 * than theirs, so we make connection
2188 * we formed into default VCC (8.1.11).
2189 * Connection they made gets torn
2190 * down. This might confuse some
2191 * clients. Can be changed if
2192 * someone reports trouble...
2193 */
2194 ;
2195 }
2196 }
2197 }
2198 }
2199 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002200 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002201 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002203 }
2204 /*
2205 * Not found, snatch address from first data packet that arrives
2206 * from this vcc
2207 */
2208 entry = make_entry(priv, bus_mac);
2209 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002211 entry->vcc = vcc;
2212 entry->old_push = old_push;
2213 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2214 memset(entry->mac_addr, 0, ETH_ALEN);
2215 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002216 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002217 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2218 entry->timer.function = lec_arp_expire_vcc;
2219 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002220 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 dump_arp_table(priv);
2222out:
2223 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2224}
2225
Chas Williams1fa99612006-09-29 17:11:47 -07002226static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
2228 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002229 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002230 struct lec_arp_table *entry;
2231 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Joe Perches99824462010-01-26 11:40:00 +00002233 pr_debug("%lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002234restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002235 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2236 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002237 hlist_for_each_entry(entry, node,
2238 &priv->lec_arp_tables[i], next) {
2239 if (entry->flush_tran_id == tran_id &&
2240 entry->status == ESI_FLUSH_PENDING) {
Chas Williams1fa99612006-09-29 17:11:47 -07002241 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002242 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002243
Chas Williams6656e3c2006-09-29 17:17:17 -07002244 lec_arp_hold(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002245 spin_unlock_irqrestore(&priv->lec_arp_lock,
2246 flags);
Joe Perchesb4c84ec2010-01-26 11:40:19 +00002247 while ((skb = skb_dequeue(&entry->tx_wait)))
Stephen Hemminger162619e2009-01-09 13:01:01 +00002248 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002249 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002250 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002251 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002252 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002253 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002254 }
2255 }
2256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002258 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259}
2260
2261static void
2262lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002263 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
2265 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002266 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002267 struct lec_arp_table *entry;
2268 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002271 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Joe Perchesc48192a2010-01-26 11:40:08 +00002272 hlist_for_each_entry(entry, node,
2273 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002274 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2275 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002276 pr_debug("Set flush transaction id to %lx for %p\n",
Joe Perches99824462010-01-26 11:40:00 +00002277 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002278 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2281}
2282
Chas Williams1fa99612006-09-29 17:11:47 -07002283static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284{
2285 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002286 unsigned char mac_addr[] = {
2287 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2288 };
2289 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 struct lec_vcc_priv *vpriv;
2291 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002292
Joe Perchesc48192a2010-01-26 11:40:08 +00002293 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2294 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 return -ENOMEM;
2296 vpriv->xoff = 0;
2297 vpriv->old_pop = vcc->pop;
2298 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002299 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002301 to_add = make_entry(priv, mac_addr);
2302 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 vcc->pop = vpriv->old_pop;
2304 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002305 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002307 }
2308 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2309 to_add->status = ESI_FORWARD_DIRECT;
2310 to_add->flags |= LEC_PERMANENT_FLAG;
2311 to_add->vcc = vcc;
2312 to_add->old_push = vcc->push;
2313 vcc->push = lec_push;
2314 priv->mcast_vcc = vcc;
2315 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316out:
2317 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002318 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319}
2320
Chas Williams1fa99612006-09-29 17:11:47 -07002321static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
2323 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002324 struct hlist_node *node, *next;
2325 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002326 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Stephen Hemminger52240062007-08-28 15:22:09 -07002328 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002329 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002332
Chas Williams1fa99612006-09-29 17:11:47 -07002333 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002334 hlist_for_each_entry_safe(entry, node, next,
2335 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002336 if (vcc == entry->vcc) {
2337 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002338 lec_arp_put(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002339 if (priv->mcast_vcc == vcc)
Chas Williams1fa99612006-09-29 17:11:47 -07002340 priv->mcast_vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07002341 }
2342 }
2343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Joe Perchesc48192a2010-01-26 11:40:08 +00002345 hlist_for_each_entry_safe(entry, node, next,
2346 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002347 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002348 lec_arp_clear_vccs(entry);
2349 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002350 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002351 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002352 }
Chas Williams1fa99612006-09-29 17:11:47 -07002353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Joe Perchesc48192a2010-01-26 11:40:08 +00002355 hlist_for_each_entry_safe(entry, node, next,
2356 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002357 if (entry->recv_vcc == vcc) {
2358 lec_arp_clear_vccs(entry);
2359 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002360 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002361 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002362 }
Chas Williams1fa99612006-09-29 17:11:47 -07002363 }
2364
Chas Williamsd0732f62006-09-29 17:14:27 -07002365 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002366 if (entry->recv_vcc == vcc) {
2367 lec_arp_clear_vccs(entry);
2368 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002369 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002370 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002371 }
Chas Williams1fa99612006-09-29 17:11:47 -07002372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
2374 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2375 dump_arp_table(priv);
2376}
2377
2378static void
2379lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002380 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381{
Chas Williams1fa99612006-09-29 17:11:47 -07002382 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002383 struct hlist_node *node, *next;
2384 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002385 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2386 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002388 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Chas Williams1fa99612006-09-29 17:11:47 -07002390 if (priv->is_trdev)
2391 src = tr_hdr->h_source;
2392 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002394 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002397 hlist_for_each_entry_safe(entry, node, next,
2398 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002399 if (vcc == entry->vcc) {
2400 del_timer(&entry->timer);
2401 memcpy(entry->mac_addr, src, ETH_ALEN);
2402 entry->status = ESI_FORWARD_DIRECT;
2403 entry->last_used = jiffies;
2404 /* We might have got an entry */
Joe Perchesc48192a2010-01-26 11:40:08 +00002405 tmp = lec_arp_find(priv, src);
2406 if (tmp) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002407 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002408 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002409 }
2410 hlist_del(&entry->next);
2411 lec_arp_add(priv, entry);
2412 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002413 }
Chas Williams1fa99612006-09-29 17:11:47 -07002414 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002415 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416out:
2417 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2418}
Chas Williams1fa99612006-09-29 17:11:47 -07002419
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420MODULE_LICENSE("GPL");