blob: cb14ddf8f0c0c1b89489207c97253d6407bf2053 [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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080012#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/* We are ethernet device */
15#include <linux/if_ether.h>
16#include <linux/netdevice.h>
17#include <linux/etherdevice.h>
18#include <net/sock.h>
19#include <linux/skbuff.h>
20#include <linux/ip.h>
21#include <asm/byteorder.h>
Joe Perchesc48192a2010-01-26 11:40:08 +000022#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <net/arp.h>
24#include <net/dst.h>
25#include <linux/proc_fs.h>
26#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/seq_file.h>
28
29/* TokenRing if needed */
30#ifdef CONFIG_TR
31#include <linux/trdevice.h>
32#endif
33
34/* And atm device */
35#include <linux/atmdev.h>
36#include <linux/atmlec.h>
37
38/* Proxy LEC knows about bridging */
39#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "../bridge/br_private.h"
41
Chas Williamsd44f7742006-09-29 17:11:14 -070042static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#endif
44
45/* Modular too */
46#include <linux/module.h>
47#include <linux/init.h>
48
49#include "lec.h"
50#include "lec_arpc.h"
51#include "resources.h"
52
Chas Williamsd44f7742006-09-29 17:11:14 -070053#define DUMP_PACKETS 0 /*
54 * 0 = None,
55 * 1 = 30 first bytes
56 * 2 = Whole packet
57 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Chas Williamsd44f7742006-09-29 17:11:14 -070059#define LEC_UNRES_QUE_LEN 8 /*
60 * number of tx packets to queue for a
61 * single destination while waiting for SVC
62 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64static int lec_open(struct net_device *dev);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000065static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
66 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int lec_close(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070068static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070069 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070071 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070073static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
74 const u8 *tlvs, u32 sizeoftlvs);
75static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070076 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070077static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
78 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070080static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 unsigned long permanent);
82static void lec_arp_check_empties(struct lec_priv *priv,
83 struct atm_vcc *vcc, struct sk_buff *skb);
84static void lec_arp_destroy(struct lec_priv *priv);
85static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070086static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070087 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 int is_rdesc,
89 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070090static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
Joe Perchesc48192a2010-01-26 11:40:08 +000091 const unsigned char *atm_addr,
92 unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 unsigned int targetless_le_arp);
94static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
95static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
96static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070097 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 unsigned long tran_id);
Joe Perchesc48192a2010-01-26 11:40:08 +000099static void lec_vcc_added(struct lec_priv *priv,
100 const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 struct atm_vcc *vcc,
Joe Perchesc48192a2010-01-26 11:40:08 +0000102 void (*old_push)(struct atm_vcc *vcc,
103 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
105
Chas Williams33a9c2d2006-09-29 17:16:48 -0700106/* must be done under lec_arp_lock */
107static inline void lec_arp_hold(struct lec_arp_table *entry)
108{
109 atomic_inc(&entry->usage);
110}
111
112static inline void lec_arp_put(struct lec_arp_table *entry)
113{
114 if (atomic_dec_and_test(&entry->usage))
115 kfree(entry);
116}
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700119 lane2_resolve, /* resolve, spec 3.1.3 */
120 lane2_associate_req, /* associate_req, spec 3.1.4 */
121 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
Chas Williamsd44f7742006-09-29 17:11:14 -0700124static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126/* Device structures */
127static struct net_device *dev_lec[MAX_LEC_ITF];
128
129#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
130static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
131{
Chas Williamsd44f7742006-09-29 17:11:14 -0700132 struct ethhdr *eth;
133 char *buff;
134 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Chas Williamsd44f7742006-09-29 17:11:14 -0700136 /*
137 * Check if this is a BPDU. If so, ask zeppelin to send
138 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
139 * as the Config BPDU has
140 */
141 eth = (struct ethhdr *)skb->data;
142 buff = skb->data + skb->dev->hard_header_len;
143 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700145 struct sk_buff *skb2;
146 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Chas Williamsd44f7742006-09-29 17:11:14 -0700148 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
149 if (skb2 == NULL)
150 return;
151 skb2->len = sizeof(struct atmlec_msg);
152 mesg = (struct atmlec_msg *)skb2->data;
153 mesg->type = l_topology_change;
154 buff += 4;
Joe Perchesc48192a2010-01-26 11:40:08 +0000155 mesg->content.normal.flag = *buff & 0x01;
156 /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Wang Chen524ad0a2008-11-12 23:39:10 -0800158 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700159 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700161 skb_queue_tail(&sk->sk_receive_queue, skb2);
162 sk->sk_data_ready(sk, skb2->len);
163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
166
167/*
168 * Modelled after tr_type_trans
169 * All multicast and ARE or STE frames go to BUS.
170 * Non source routed frames go by destination address.
171 * Last hop source routed frames go by destination address.
172 * Not last hop source routed frames go by _next_ route descriptor.
173 * Returns pointer to destination MAC address or fills in rdesc
174 * and returns NULL.
175 */
176#ifdef CONFIG_TR
177static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
178{
Chas Williamsd44f7742006-09-29 17:11:14 -0700179 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800180 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Chas Williamsd44f7742006-09-29 17:11:14 -0700182 trh = (struct trh_hdr *)packet;
183 if (trh->daddr[0] & (uint8_t) 0x80)
184 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Chas Williamsd44f7742006-09-29 17:11:14 -0700186 if (trh->saddr[0] & TR_RII) {
187 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
188 if ((ntohs(trh->rcf) >> 13) != 0)
189 return bus_mac; /* ARE or STE */
190 } else
191 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Chas Williamsd44f7742006-09-29 17:11:14 -0700193 if (riflen < 6)
194 return trh->daddr; /* last hop, source routed */
195
196 /* riflen is 6 or more, packet has more than one route descriptor */
197 num_rdsc = (riflen / 2) - 1;
198 memset(rdesc, 0, ETH_ALEN);
199 /* offset 4 comes from LAN destination field in LE control frames */
200 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800201 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700202 else {
Al Viro30d492d2006-11-14 21:11:29 -0800203 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700204 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
205 }
206
207 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209#endif /* CONFIG_TR */
210
211/*
212 * Open/initialize the netdevice. This is called (in the current kernel)
213 * sometime after booting when the 'ifconfig' program is run.
214 *
215 * This routine should set everything up anew at each open, even
216 * registers that "should" only need to be set once at boot, so that
217 * there is non-reboot way to recover if something goes wrong.
218 */
219
Chas Williamsd44f7742006-09-29 17:11:14 -0700220static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700223
224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Stephen Hemminger162619e2009-01-09 13:01:01 +0000227static void
228lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000230 struct net_device *dev = skb->dev;
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000237 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return;
239 }
240
Stephen Hemminger162619e2009-01-09 13:01:01 +0000241 dev->stats.tx_packets++;
242 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Chas Williamsd44f7742006-09-29 17:11:14 -0700245static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Joe Perches99824462010-01-26 11:40:00 +0000247 pr_info("%s\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000252static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
253 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Chas Williamsd44f7742006-09-29 17:11:14 -0700255 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800256 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700257 struct lecdatahdr_8023 *lec_h;
258 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 int min_frame_size;
262#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700263 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Joe Perches99824462010-01-26 11:40:00 +0000267 pr_debug("called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700268 if (!priv->lecd) {
Joe Perchesc48192a2010-01-26 11:40:08 +0000269 pr_info("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000270 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000272 kfree_skb(skb);
273 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700274 }
275
Stephen Hemminger52240062007-08-28 15:22:09 -0700276 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Joe Perches99824462010-01-26 11:40:00 +0000277 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
278 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700280 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
281 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#endif
283
Chas Williamsd44f7742006-09-29 17:11:14 -0700284 /* Make sure we have room for lec_id */
285 if (skb_headroom(skb) < 2) {
Joe Perches99824462010-01-26 11:40:00 +0000286 pr_debug("reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700287 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
288 kfree_skb(skb);
289 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000290 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700291 skb = skb2;
292 }
293 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Chas Williamsd44f7742006-09-29 17:11:14 -0700295 /* Put le header to place, works for TokenRing too */
296 lec_h = (struct lecdatahdr_8023 *)skb->data;
297 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700300 /*
301 * Ugly. Use this to realign Token Ring packets for
302 * e.g. PCA-200E driver.
303 */
304 if (priv->is_trdev) {
305 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
306 kfree_skb(skb);
307 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000308 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700309 skb = skb2;
310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#endif
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#if DUMP_PACKETS >= 2
Joe Perchesc48192a2010-01-26 11:40:08 +0000314#define MAX_DUMP_SKB 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#elif DUMP_PACKETS >= 1
Joe Perchesc48192a2010-01-26 11:40:08 +0000316#define MAX_DUMP_SKB 30
317#endif
318#if DUMP_PACKETS >= 1
319 printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
320 dev->name, skb->len, priv->lecid);
321 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
322 skb->data, min(skb->len, MAX_DUMP_SKB), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#endif /* DUMP_PACKETS >= 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Chas Williamsd44f7742006-09-29 17:11:14 -0700325 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700327 if (priv->is_trdev)
328 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 else
330#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700331 min_frame_size = LEC_MINIMUM_8023_SIZE;
332 if (skb->len < min_frame_size) {
333 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
334 skb2 = skb_copy_expand(skb, 0,
335 min_frame_size - skb->truesize,
336 GFP_ATOMIC);
337 dev_kfree_skb(skb);
338 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000339 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000340 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700341 }
342 skb = skb2;
343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700345 }
346
347 /* Send to right vcc */
348 is_rdesc = 0;
349 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700351 if (priv->is_trdev) {
352 dst = get_tr_dst(skb->data + 2, rdesc);
353 if (dst == NULL) {
354 dst = rdesc;
355 is_rdesc = 1;
356 }
357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700359 entry = NULL;
360 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Joe Perches99824462010-01-26 11:40:00 +0000361 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
362 dev->name, vcc, vcc ? vcc->flags : 0, entry);
Chas Williamsd44f7742006-09-29 17:11:14 -0700363 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
364 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Joe Perches99824462010-01-26 11:40:00 +0000365 pr_debug("%s:queuing packet, MAC address %pM\n",
366 dev->name, lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700367 skb_queue_tail(&entry->tx_wait, skb);
368 } else {
Joe Perches99824462010-01-26 11:40:00 +0000369 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
370 dev->name, lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000371 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700372 dev_kfree_skb(skb);
373 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700374 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 }
376#if DUMP_PACKETS > 0
Joe Perchesc48192a2010-01-26 11:40:08 +0000377 printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
378 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700380
381 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Joe Perches99824462010-01-26 11:40:00 +0000382 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000383 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Stephen Hemminger162619e2009-01-09 13:01:01 +0000386 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 if (!atm_may_send(vcc, 0)) {
389 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
390
391 vpriv->xoff = 1;
392 netif_stop_queue(dev);
393
394 /*
395 * vcc->pop() might have occurred in between, making
396 * the vcc usuable again. Since xmit is serialized,
397 * this is the only situation we have to re-test.
398 */
399
400 if (atm_may_send(vcc, 0))
401 netif_wake_queue(dev);
402 }
403
Chas Williams6656e3c2006-09-29 17:17:17 -0700404out:
405 if (entry)
406 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000408 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700412static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Chas Williamsd44f7742006-09-29 17:11:14 -0700414 netif_stop_queue(dev);
415 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Chas Williamsd44f7742006-09-29 17:11:14 -0700418static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700421 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800422 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700423 struct atmlec_msg *mesg;
424 struct lec_arp_table *entry;
425 int i;
426 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700429 mesg = (struct atmlec_msg *)skb->data;
430 tmp = skb->data;
431 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700432 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700433 switch (mesg->type) {
434 case l_set_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000435 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700436 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
Chas Williamsd44f7742006-09-29 17:11:14 -0700437 break;
438 case l_del_mac_addr:
Joe Perchesc48192a2010-01-26 11:40:08 +0000439 for (i = 0; i < 6; i++)
Chas Williamsd44f7742006-09-29 17:11:14 -0700440 dev->dev_addr[i] = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -0700441 break;
442 case l_addr_delete:
443 lec_addr_delete(priv, mesg->content.normal.atm_addr,
444 mesg->content.normal.flag);
445 break;
446 case l_topology_change:
447 priv->topology_change = mesg->content.normal.flag;
448 break;
449 case l_flush_complete:
450 lec_flush_complete(priv, mesg->content.normal.flag);
451 break;
452 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700454 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
455 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
457
Chas Williamsd44f7742006-09-29 17:11:14 -0700458 if (mesg->content.normal.no_source_le_narp)
459 break;
460 /* FALL THROUGH */
461 case l_arp_update:
462 lec_arp_update(priv, mesg->content.normal.mac_addr,
463 mesg->content.normal.atm_addr,
464 mesg->content.normal.flag,
465 mesg->content.normal.targetless_le_arp);
Joe Perches99824462010-01-26 11:40:00 +0000466 pr_debug("in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700467 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Joe Perches99824462010-01-26 11:40:00 +0000468 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
469 mesg->sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -0700470 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
471 tmp, mesg->sizeoftlvs);
472 }
473 break;
474 case l_config:
475 priv->maximum_unknown_frame_count =
476 mesg->content.config.maximum_unknown_frame_count;
477 priv->max_unknown_frame_time =
478 (mesg->content.config.max_unknown_frame_time * HZ);
479 priv->max_retry_count = mesg->content.config.max_retry_count;
480 priv->aging_time = (mesg->content.config.aging_time * HZ);
481 priv->forward_delay_time =
482 (mesg->content.config.forward_delay_time * HZ);
483 priv->arp_response_time =
484 (mesg->content.config.arp_response_time * HZ);
485 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
486 priv->path_switching_delay =
487 (mesg->content.config.path_switching_delay * HZ);
Joe Perchesc48192a2010-01-26 11:40:08 +0000488 priv->lane_version = mesg->content.config.lane_version;
489 /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 priv->lane2_ops = NULL;
491 if (priv->lane_version > 1)
492 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700493 if (dev_set_mtu(dev, mesg->content.config.mtu))
Joe Perchesc48192a2010-01-26 11:40:08 +0000494 pr_info("%s: change_mtu to %d failed\n",
495 dev->name, mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700497 break;
498 case l_flush_tran_id:
499 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
500 mesg->content.normal.flag);
501 break;
502 case l_set_lecid:
503 priv->lecid =
504 (unsigned short)(0xffff & mesg->content.normal.flag);
505 break;
506 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000508 {
509 pr_debug("%s: bridge zeppelin asks about %pM\n",
510 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000512 if (br_fdb_test_addr_hook == NULL)
513 break;
514
515 if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) {
516 /* hit from bridge table, send LE_ARP_RESPONSE */
517 struct sk_buff *skb2;
518 struct sock *sk;
519
520 pr_debug("%s: entry found, responding to zeppelin\n",
521 dev->name);
522 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
523 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700524 break;
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000525 skb2->len = sizeof(struct atmlec_msg);
526 skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg));
527 atm_force_charge(priv->lecd, skb2->truesize);
528 sk = sk_atm(priv->lecd);
529 skb_queue_tail(&sk->sk_receive_queue, skb2);
530 sk->sk_data_ready(sk, skb2->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700531 }
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700534 break;
535 default:
Joe Perchesc48192a2010-01-26 11:40:08 +0000536 pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700537 dev_kfree_skb(skb);
538 return -EINVAL;
539 }
540 dev_kfree_skb(skb);
541 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
Chas Williamsd44f7742006-09-29 17:11:14 -0700544static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Chas Williamsd44f7742006-09-29 17:11:14 -0700546 struct sk_buff *skb;
547 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800548 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Chas Williamsd44f7742006-09-29 17:11:14 -0700550 priv->lecd = NULL;
551 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Chas Williamsd44f7742006-09-29 17:11:14 -0700553 netif_stop_queue(dev);
554 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Chas Williamsd44f7742006-09-29 17:11:14 -0700556 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Joe Perchesc48192a2010-01-26 11:40:08 +0000557 pr_info("%s closing with messages pending\n", dev->name);
Joe Perchesb4c84ec2010-01-26 11:40:19 +0000558 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700559 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700561 }
562
Joe Perchesc48192a2010-01-26 11:40:08 +0000563 pr_info("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700564 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
567static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700568 .close = lec_atm_close,
569 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570};
571
572static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700573 .ops = &lecdev_ops,
574 .type = "lec",
575 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700576 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577};
578
579/*
580 * LANE2: new argument struct sk_buff *data contains
581 * the LE_ARP based TLVs introduced in the LANE2 spec
582 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700583static int
584send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700585 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700586 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
588 struct sock *sk;
589 struct sk_buff *skb;
590 struct atmlec_msg *mesg;
591
Joe Perchesc48192a2010-01-26 11:40:08 +0000592 if (!priv || !priv->lecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
595 if (!skb)
596 return -1;
597 skb->len = sizeof(struct atmlec_msg);
598 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700599 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700601 if (data != NULL)
602 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (mac_addr)
604 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 else
606 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 if (atm_addr)
608 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
609
Chas Williamsd44f7742006-09-29 17:11:14 -0700610 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 sk = sk_atm(priv->lecd);
612 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700613 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Chas Williamsd44f7742006-09-29 17:11:14 -0700615 if (data != NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000616 pr_debug("about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700617 atm_force_charge(priv->lecd, data->truesize);
618 skb_queue_tail(&sk->sk_receive_queue, data);
619 sk->sk_data_ready(sk, skb->len);
620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Chas Williamsd44f7742006-09-29 17:11:14 -0700622 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}
624
625/* shamelessly stolen from drivers/net/net_init.c */
626static int lec_change_mtu(struct net_device *dev, int new_mtu)
627{
Chas Williamsd44f7742006-09-29 17:11:14 -0700628 if ((new_mtu < 68) || (new_mtu > 18190))
629 return -EINVAL;
630 dev->mtu = new_mtu;
631 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
634static void lec_set_multicast_list(struct net_device *dev)
635{
Chas Williamsd44f7742006-09-29 17:11:14 -0700636 /*
637 * by default, all multicast frames arrive over the bus.
638 * eventually support selective multicast service
639 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Stephen Hemminger004b3222009-01-09 13:01:02 +0000642static const struct net_device_ops lec_netdev_ops = {
643 .ndo_open = lec_open,
644 .ndo_stop = lec_close,
645 .ndo_start_xmit = lec_start_xmit,
646 .ndo_change_mtu = lec_change_mtu,
647 .ndo_tx_timeout = lec_tx_timeout,
648 .ndo_set_multicast_list = lec_set_multicast_list,
649};
650
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700651static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 0xff,
653 0x00,
654 0x01,
655 0x01
656};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Scott Talbert4a7097f2005-09-29 17:30:54 -0700658#define LEC_DATA_DIRECT_8023 2
659#define LEC_DATA_DIRECT_8025 3
660
661static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700662{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700663 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
664 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700665}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700666
Chas Williamsd44f7742006-09-29 17:11:14 -0700667static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700669 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800671 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Joe Perchesc48192a2010-01-26 11:40:08 +0000673#if DUMP_PACKETS > 0
Joe Perches99824462010-01-26 11:40:00 +0000674 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
675 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700677 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700678 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700679 lec_vcc_close(priv, vcc);
680 return;
681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682#if DUMP_PACKETS >= 2
Joe Perches99824462010-01-26 11:40:00 +0000683#define MAX_SKB_DUMP 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#elif DUMP_PACKETS >= 1
Joe Perches99824462010-01-26 11:40:00 +0000685#define MAX_SKB_DUMP 30
686#endif
687#if DUMP_PACKETS > 0
688 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
689 dev->name, skb->len, priv->lecid);
690 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
691 skb->data, min(MAX_SKB_DUMP, skb->len), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692#endif /* DUMP_PACKETS > 0 */
Joe Perches99824462010-01-26 11:40:00 +0000693 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
694 /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct sock *sk = sk_atm(vcc);
696
Stephen Hemminger52240062007-08-28 15:22:09 -0700697 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700698 skb_queue_tail(&sk->sk_receive_queue, skb);
699 sk->sk_data_ready(sk, skb->len);
700 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700701 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700702 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Chas Williamsd44f7742006-09-29 17:11:14 -0700704 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800705 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700706 !priv->lecd || !(dev->flags & IFF_UP)) {
707 /*
708 * Probably looping back, or if lecd is missing,
709 * lecd has gone down
710 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700711 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700712 dev_kfree_skb(skb);
713 return;
714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700716 if (priv->is_trdev)
717 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
718 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700720 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700721
Chas Williamsd44f7742006-09-29 17:11:14 -0700722 /*
723 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700724 * the LE_ARP cache entry, delete the LE_ARP cache entry.
725 */
726 spin_lock_irqsave(&priv->lec_arp_lock, flags);
727 if (lec_is_data_direct(vcc)) {
728#ifdef CONFIG_TR
729 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700730 src =
731 ((struct lecdatahdr_8025 *)skb->data)->
732 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700733 else
734#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 src =
736 ((struct lecdatahdr_8023 *)skb->data)->
737 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700738 entry = lec_arp_find(priv, src);
739 if (entry && entry->vcc != vcc) {
740 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700741 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700742 }
743 }
744 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Chas Williamsd44f7742006-09-29 17:11:14 -0700746 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
747 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 dev_kfree_skb(skb);
750 return;
751 }
Joe Perchesc48192a2010-01-26 11:40:08 +0000752 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 lec_arp_check_empties(priv, vcc, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700754 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700756 if (priv->is_trdev)
757 skb->protocol = tr_type_trans(skb, dev);
758 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700760 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000761 dev->stats.rx_packets++;
762 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
764 netif_rx(skb);
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Chas Williamsd44f7742006-09-29 17:11:14 -0700768static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
771 struct net_device *dev = skb->dev;
772
773 if (vpriv == NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000774 pr_info("vpriv = NULL!?!?!?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return;
776 }
777
778 vpriv->old_pop(vcc, skb);
779
780 if (vpriv->xoff && atm_may_send(vcc, 0)) {
781 vpriv->xoff = 0;
782 if (netif_running(dev) && netif_queue_stopped(dev))
783 netif_wake_queue(dev);
784 }
785}
786
Chas Williamsd44f7742006-09-29 17:11:14 -0700787static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
789 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700790 int bytes_left;
791 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Chas Williamsd44f7742006-09-29 17:11:14 -0700793 /* Lecd must be up in this case */
794 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
Joe Perches99824462010-01-26 11:40:00 +0000795 if (bytes_left != 0)
796 pr_info("copy from user failed for %d bytes\n", bytes_left);
Chas Williamsd44f7742006-09-29 17:11:14 -0700797 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
798 !dev_lec[ioc_data.dev_num])
799 return -EINVAL;
Joe Perchesc48192a2010-01-26 11:40:08 +0000800 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
801 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return -ENOMEM;
803 vpriv->xoff = 0;
804 vpriv->old_pop = vcc->pop;
805 vcc->user_back = vpriv;
806 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800807 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700808 &ioc_data, vcc, vcc->push);
809 vcc->proto_data = dev_lec[ioc_data.dev_num];
810 vcc->push = lec_push;
811 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
Chas Williamsd44f7742006-09-29 17:11:14 -0700814static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Chas Williamsd44f7742006-09-29 17:11:14 -0700816 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
817 return -EINVAL;
818 vcc->proto_data = dev_lec[arg];
Joe Perches37d66802010-11-15 11:12:33 +0000819 return lec_mcast_make(netdev_priv(dev_lec[arg]), vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820}
821
822/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700823static int lecd_attach(struct atm_vcc *vcc, int arg)
824{
825 int i;
826 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Chas Williamsd44f7742006-09-29 17:11:14 -0700828 if (arg < 0)
829 i = 0;
830 else
831 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700833 if (arg >= MAX_LEC_ITF)
834 return -EINVAL;
835#else /* Reserve the top NUM_TR_DEVS for TR */
836 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
837 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700839 if (!dev_lec[i]) {
840 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Chas Williamsd44f7742006-09-29 17:11:14 -0700842 is_trdev = 0;
843 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
844 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Chas Williamsd44f7742006-09-29 17:11:14 -0700846 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700848 if (is_trdev)
849 dev_lec[i] = alloc_trdev(size);
850 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700852 dev_lec[i] = alloc_etherdev(size);
853 if (!dev_lec[i])
854 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000855 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700856 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
857 if (register_netdev(dev_lec[i])) {
858 free_netdev(dev_lec[i]);
859 return -EINVAL;
860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Wang Chen524ad0a2008-11-12 23:39:10 -0800862 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700863 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700864 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800865 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700866 if (priv->lecd)
867 return -EADDRINUSE;
868 }
869 lec_arp_init(priv);
870 priv->itfnum = i; /* LANE2 addition */
871 priv->lecd = vcc;
872 vcc->dev = &lecatm_dev;
873 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Chas Williamsd44f7742006-09-29 17:11:14 -0700875 vcc->proto_data = dev_lec[i];
876 set_bit(ATM_VF_META, &vcc->flags);
877 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Chas Williamsd44f7742006-09-29 17:11:14 -0700879 /* Set default values to these variables */
880 priv->maximum_unknown_frame_count = 1;
881 priv->max_unknown_frame_time = (1 * HZ);
882 priv->vcc_timeout_period = (1200 * HZ);
883 priv->max_retry_count = 1;
884 priv->aging_time = (300 * HZ);
885 priv->forward_delay_time = (15 * HZ);
886 priv->topology_change = 0;
887 priv->arp_response_time = (1 * HZ);
888 priv->flush_timeout = (4 * HZ);
889 priv->path_switching_delay = (6 * HZ);
890
Joe Perchesc48192a2010-01-26 11:40:08 +0000891 if (dev_lec[i]->flags & IFF_UP)
Chas Williamsd44f7742006-09-29 17:11:14 -0700892 netif_start_queue(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700893 __module_get(THIS_MODULE);
894 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700898static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700900 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 "ESI_UNKNOWN ",
902 "ESI_ARP_PENDING ",
903 "ESI_VC_PENDING ",
904 "<Undefined> ",
905 "ESI_FLUSH_PENDING ",
906 "ESI_FORWARD_DIRECT"
907 };
908
909 if (status > ESI_FORWARD_DIRECT)
910 status = 3; /* ESI_UNDEFINED */
911 return lec_arp_status_string[status];
912}
913
914static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
915{
916 int i;
917
918 for (i = 0; i < ETH_ALEN; i++)
919 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
920 seq_printf(seq, " ");
921 for (i = 0; i < ATM_ESA_LEN; i++)
922 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
923 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
924 entry->flags & 0xffff);
925 if (entry->vcc)
926 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
927 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700928 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 if (entry->recv_vcc) {
930 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
931 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700932 }
933 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936struct lec_state {
937 unsigned long flags;
938 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700939 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 struct net_device *dev;
941 int itf;
942 int arp_table;
943 int misc_table;
944};
945
Chas Williamsd0732f62006-09-29 17:14:27 -0700946static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 loff_t *l)
948{
Chas Williamsd0732f62006-09-29 17:14:27 -0700949 struct hlist_node *e = state->node;
950 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700953 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700954 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700955 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 --*l;
957 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700958
959 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (--*l < 0)
961 break;
962 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700963 state->node = e;
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return (*l < 0) ? state : NULL;
966}
967
968static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -0700969 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 void *v = NULL;
972 int p;
973
974 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700975 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (v)
977 break;
978 }
979 state->arp_table = p;
980 return v;
981}
982
983static void *lec_misc_walk(struct lec_state *state, loff_t *l,
984 struct lec_priv *priv)
985{
Chas Williamsd0732f62006-09-29 17:14:27 -0700986 struct hlist_head *lec_misc_tables[] = {
987 &priv->lec_arp_empty_ones,
988 &priv->lec_no_forward,
989 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 };
991 void *v = NULL;
992 int q;
993
994 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
995 v = lec_tbl_walk(state, lec_misc_tables[q], l);
996 if (v)
997 break;
998 }
999 state->misc_table = q;
1000 return v;
1001}
1002
1003static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1004 struct lec_priv *priv)
1005{
1006 if (!state->locked) {
1007 state->locked = priv;
1008 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1009 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001010 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1012 state->locked = NULL;
1013 /* Partial state reset for the next time we get called */
1014 state->arp_table = state->misc_table = 0;
1015 }
1016 return state->locked;
1017}
1018
1019static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1020{
1021 struct net_device *dev;
1022 void *v;
1023
1024 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001025 v = (dev && netdev_priv(dev)) ?
1026 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (!v && dev) {
1028 dev_put(dev);
1029 /* Partial state reset for the next time we get called */
1030 dev = NULL;
1031 }
1032 state->dev = dev;
1033 return v;
1034}
1035
1036static void *lec_get_idx(struct lec_state *state, loff_t l)
1037{
1038 void *v = NULL;
1039
1040 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1041 v = lec_itf_walk(state, &l);
1042 if (v)
1043 break;
1044 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001045 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
1048static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1049{
1050 struct lec_state *state = seq->private;
1051
1052 state->itf = 0;
1053 state->dev = NULL;
1054 state->locked = NULL;
1055 state->arp_table = 0;
1056 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001057 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Joe Perches2e1e9842008-04-10 03:33:03 -07001059 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
1062static void lec_seq_stop(struct seq_file *seq, void *v)
1063{
1064 struct lec_state *state = seq->private;
1065
1066 if (state->dev) {
1067 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1068 state->flags);
1069 dev_put(state->dev);
1070 }
1071}
1072
1073static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1074{
1075 struct lec_state *state = seq->private;
1076
1077 v = lec_get_idx(state, 1);
1078 *pos += !!PTR_ERR(v);
1079 return v;
1080}
1081
1082static int lec_seq_show(struct seq_file *seq, void *v)
1083{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001084 static const char lec_banner[] =
1085 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001086 " Status Flags "
1087 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Joe Perches2e1e9842008-04-10 03:33:03 -07001089 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 seq_puts(seq, lec_banner);
1091 else {
1092 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001093 struct net_device *dev = state->dev;
Joe Perchesc48192a2010-01-26 11:40:08 +00001094 struct lec_arp_table *entry = hlist_entry(state->node,
1095 struct lec_arp_table,
1096 next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001099 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 }
1101 return 0;
1102}
1103
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001104static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001105 .start = lec_seq_start,
1106 .next = lec_seq_next,
1107 .stop = lec_seq_stop,
1108 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109};
1110
1111static int lec_seq_open(struct inode *inode, struct file *file)
1112{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001113 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Arjan van de Ven9a321442007-02-12 00:55:35 -08001116static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001117 .owner = THIS_MODULE,
1118 .open = lec_seq_open,
1119 .read = seq_read,
1120 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001121 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122};
1123#endif
1124
1125static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1126{
1127 struct atm_vcc *vcc = ATM_SD(sock);
1128 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001131 case ATMLEC_CTRL:
1132 case ATMLEC_MCAST:
1133 case ATMLEC_DATA:
1134 if (!capable(CAP_NET_ADMIN))
1135 return -EPERM;
1136 break;
1137 default:
1138 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140
1141 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001142 case ATMLEC_CTRL:
1143 err = lecd_attach(vcc, (int)arg);
1144 if (err >= 0)
1145 sock->state = SS_CONNECTED;
1146 break;
1147 case ATMLEC_MCAST:
1148 err = lec_mcast_attach(vcc, (int)arg);
1149 break;
1150 case ATMLEC_DATA:
1151 err = lec_vcc_attach(vcc, (void __user *)arg);
1152 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
1154
1155 return err;
1156}
1157
1158static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001159 .owner = THIS_MODULE,
1160 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161};
1162
1163static int __init lane_module_init(void)
1164{
1165#ifdef CONFIG_PROC_FS
1166 struct proc_dir_entry *p;
1167
Wang Chen16e297b2008-02-28 13:55:45 -08001168 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001169 if (!p) {
Joe Perches99824462010-01-26 11:40:00 +00001170 pr_err("Unable to initialize /proc/net/atm/lec\n");
Wang Chendbee0d32008-03-23 21:45:36 -07001171 return -ENOMEM;
1172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173#endif
1174
1175 register_atm_ioctl(&lane_ioctl_ops);
Michal Marek36a9f772011-04-01 12:41:20 +02001176 pr_info("lec.c: initialized\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001177 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178}
1179
1180static void __exit lane_module_cleanup(void)
1181{
Chas Williamsd44f7742006-09-29 17:11:14 -07001182 int i;
1183 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 remove_proc_entry("lec", atm_proc_root);
1186
1187 deregister_atm_ioctl(&lane_ioctl_ops);
1188
Chas Williamsd44f7742006-09-29 17:11:14 -07001189 for (i = 0; i < MAX_LEC_ITF; i++) {
1190 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001191 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001193 free_netdev(dev_lec[i]);
1194 dev_lec[i] = NULL;
1195 }
1196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
1199module_init(lane_module_init);
1200module_exit(lane_module_cleanup);
1201
1202/*
1203 * LANE2: 3.1.3, LE_RESOLVE.request
1204 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1205 * If sizeoftlvs == NULL the default TLVs associated with with this
1206 * lec will be used.
1207 * If dst_mac == NULL, targetless LE_ARP will be sent
1208 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001209static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001210 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
1212 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001213 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001214 struct lec_arp_table *table;
1215 struct sk_buff *skb;
1216 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Chas Williamsd44f7742006-09-29 17:11:14 -07001218 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001220 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001222 if (table == NULL)
1223 return -1;
1224
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001225 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001226 if (*tlvs == NULL)
1227 return -1;
1228
Chas Williamsd44f7742006-09-29 17:11:14 -07001229 *sizeoftlvs = table->sizeoftlvs;
1230
1231 return 0;
1232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 if (sizeoftlvs == NULL)
1235 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 else {
1238 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1239 if (skb == NULL)
1240 return -1;
1241 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001242 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1244 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001245 return retval;
1246}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248/*
1249 * LANE2: 3.1.4, LE_ASSOCIATE.request
1250 * Associate the *tlvs with the *lan_dst address.
1251 * Will overwrite any previous association
1252 * Returns 1 for success, 0 for failure (out of memory)
1253 *
1254 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001255static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1256 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Chas Williamsd44f7742006-09-29 17:11:14 -07001258 int retval;
1259 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001260 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Chas Williamsd44f7742006-09-29 17:11:14 -07001262 if (compare_ether_addr(lan_dst, dev->dev_addr))
Joe Perchesc48192a2010-01-26 11:40:08 +00001263 return 0; /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001267 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001268 if (priv->tlvs == NULL)
Joe Perchesc48192a2010-01-26 11:40:08 +00001269 return 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001270 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Chas Williamsd44f7742006-09-29 17:11:14 -07001272 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1273 if (skb == NULL)
1274 return 0;
1275 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001276 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001277 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1278 if (retval != 0)
Joe Perchesc48192a2010-01-26 11:40:08 +00001279 pr_info("lec.c: lane2_associate_req() failed\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001280 /*
1281 * If the previous association has changed we must
1282 * somehow notify other LANE entities about the change
1283 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001284 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285}
1286
1287/*
1288 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1289 *
1290 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001291static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1292 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
1294#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001295 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001297 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001298#if 0 /*
1299 * Why have the TLVs in LE_ARP entries
1300 * since we do not use them? When you
1301 * uncomment this code, make sure the
1302 * TLVs get freed when entry is killed
1303 */
1304 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Chas Williamsd44f7742006-09-29 17:11:14 -07001306 if (entry == NULL)
1307 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Chas Williamsd44f7742006-09-29 17:11:14 -07001309 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001311 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001312 if (entry->tlvs == NULL)
1313 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001314 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315#endif
1316#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001317 pr_info("\n");
1318 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 while (i < sizeoftlvs)
Joe Perchesc48192a2010-01-26 11:40:08 +00001320 pr_cont("%02x ", tlvs[i++]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001321
Joe Perchesc48192a2010-01-26 11:40:08 +00001322 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323#endif
1324
Chas Williamsd44f7742006-09-29 17:11:14 -07001325 /* tell MPOA about the TLVs we saw */
1326 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1327 priv->lane2_ops->associate_indicator(dev, mac_addr,
1328 tlvs, sizeoftlvs);
1329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330}
1331
1332/*
1333 * Here starts what used to lec_arpc.c
1334 *
1335 * lec_arpc.c was added here when making
1336 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 */
1338
1339#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340#include <linux/timer.h>
Joe Perchesc48192a2010-01-26 11:40:08 +00001341#include <linux/param.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342#include <asm/atomic.h>
1343#include <linux/inetdevice.h>
1344#include <net/route.h>
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001347#define pr_debug(format, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348/*
Joe Perches99824462010-01-26 11:40:00 +00001349 #define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350*/
1351#endif
1352#define DEBUG_ARP_TABLE 0
1353
1354#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1355
David Howellsc4028952006-11-22 14:57:56 +00001356static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357static void lec_arp_expire_arp(unsigned long data);
1358
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001359/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 * Arp table funcs
1361 */
1362
Joe Perchesc48192a2010-01-26 11:40:08 +00001363#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365/*
1366 * Initialization of arp-cache
1367 */
Chas Williams1fa99612006-09-29 17:11:47 -07001368static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
Chas Williams1fa99612006-09-29 17:11:47 -07001370 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Joe Perchesc48192a2010-01-26 11:40:08 +00001372 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07001373 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001374 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1375 INIT_HLIST_HEAD(&priv->lec_no_forward);
1376 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001378 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001379 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
Chas Williams1fa99612006-09-29 17:11:47 -07001382static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
Chas Williams1fa99612006-09-29 17:11:47 -07001384 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 struct atm_vcc *vcc = entry->vcc;
1386 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001387 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Chas Williams1fa99612006-09-29 17:11:47 -07001389 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (vpriv->xoff)
1391 netif_wake_queue(dev);
1392 kfree(vpriv);
1393 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001394 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001396 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001397 }
1398 if (entry->recv_vcc) {
1399 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001401 entry->recv_vcc = NULL;
1402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
1405/*
1406 * Insert entry to lec_arp_table
1407 * LANE2: Add to the end of the list to satisfy 8.1.13
1408 */
Chas Williams1fa99612006-09-29 17:11:47 -07001409static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001410lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
Chas Williamsd0732f62006-09-29 17:14:27 -07001412 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Chas Williamsd0732f62006-09-29 17:14:27 -07001414 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1415 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001416
Joe Perches99824462010-01-26 11:40:00 +00001417 pr_debug("Added entry:%pM\n", entry->mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418}
1419
1420/*
1421 * Remove entry from lec_arp_table
1422 */
Chas Williams1fa99612006-09-29 17:11:47 -07001423static int
1424lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Chas Williamsd0732f62006-09-29 17:14:27 -07001426 struct hlist_node *node;
1427 struct lec_arp_table *entry;
1428 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Joe Perchesc48192a2010-01-26 11:40:08 +00001430 if (!to_remove)
Chas Williams1fa99612006-09-29 17:11:47 -07001431 return -1;
Chas Williamsd0732f62006-09-29 17:14:27 -07001432
1433 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001434 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Joe Perchesc48192a2010-01-26 11:40:08 +00001436 /*
1437 * If this is the only MAC connected to this VCC,
1438 * also tear down the VCC
1439 */
Chas Williams1fa99612006-09-29 17:11:47 -07001440 if (to_remove->status >= ESI_FLUSH_PENDING) {
1441 /*
1442 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1443 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001444 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001445 hlist_for_each_entry(entry, node,
1446 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001447 if (memcmp(to_remove->atm_addr,
1448 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001449 remove_vcc = 0;
1450 break;
1451 }
1452 }
1453 }
1454 if (remove_vcc)
1455 lec_arp_clear_vccs(to_remove);
1456 }
1457 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1458
Joe Perches99824462010-01-26 11:40:00 +00001459 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001460 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
1463#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001464static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Chas Williams1fa99612006-09-29 17:11:47 -07001466 switch (st) {
1467 case ESI_UNKNOWN:
1468 return "ESI_UNKNOWN";
1469 case ESI_ARP_PENDING:
1470 return "ESI_ARP_PENDING";
1471 case ESI_VC_PENDING:
1472 return "ESI_VC_PENDING";
1473 case ESI_FLUSH_PENDING:
1474 return "ESI_FLUSH_PENDING";
1475 case ESI_FORWARD_DIRECT:
1476 return "ESI_FORWARD_DIRECT";
Chas Williams1fa99612006-09-29 17:11:47 -07001477 }
Joe Perchesc48192a2010-01-26 11:40:08 +00001478 return "<UNKNOWN>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Chas Williams1fa99612006-09-29 17:11:47 -07001481static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Chas Williamsd0732f62006-09-29 17:14:27 -07001483 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001484 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001485 char buf[256];
1486 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Joe Perchesc48192a2010-01-26 11:40:08 +00001488 pr_info("Dump %p:\n", priv);
Chas Williams1fa99612006-09-29 17:11:47 -07001489 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001490 hlist_for_each_entry(rulla, node,
1491 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001492 offset = 0;
1493 offset += sprintf(buf, "%d: %p\n", i, rulla);
Joe Perchesc48192a2010-01-26 11:40:08 +00001494 offset += sprintf(buf + offset, "Mac: %pM",
1495 rulla->mac_addr);
1496 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001497 for (j = 0; j < ATM_ESA_LEN; j++) {
1498 offset += sprintf(buf + offset,
1499 "%2.2x ",
1500 rulla->atm_addr[j] & 0xff);
1501 }
1502 offset += sprintf(buf + offset,
1503 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1504 rulla->vcc ? rulla->vcc->vpi : 0,
1505 rulla->vcc ? rulla->vcc->vci : 0,
1506 rulla->recv_vcc ? rulla->recv_vcc->
1507 vpi : 0,
1508 rulla->recv_vcc ? rulla->recv_vcc->
1509 vci : 0, rulla->last_used,
1510 rulla->timestamp, rulla->no_tries);
1511 offset +=
1512 sprintf(buf + offset,
1513 "Flags:%x, Packets_flooded:%x, Status: %s ",
1514 rulla->flags, rulla->packets_flooded,
1515 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001516 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001517 }
Chas Williams1fa99612006-09-29 17:11:47 -07001518 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001519
1520 if (!hlist_empty(&priv->lec_no_forward))
Joe Perchesc48192a2010-01-26 11:40:08 +00001521 pr_info("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001522 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001523 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001524 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1525 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001526 for (j = 0; j < ATM_ESA_LEN; j++) {
1527 offset += sprintf(buf + offset, "%2.2x ",
1528 rulla->atm_addr[j] & 0xff);
1529 }
1530 offset += sprintf(buf + offset,
1531 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1532 rulla->vcc ? rulla->vcc->vpi : 0,
1533 rulla->vcc ? rulla->vcc->vci : 0,
1534 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1535 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1536 rulla->last_used,
1537 rulla->timestamp, rulla->no_tries);
1538 offset += sprintf(buf + offset,
1539 "Flags:%x, Packets_flooded:%x, Status: %s ",
1540 rulla->flags, rulla->packets_flooded,
1541 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001542 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001543 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001544
1545 if (!hlist_empty(&priv->lec_arp_empty_ones))
Joe Perchesc48192a2010-01-26 11:40:08 +00001546 pr_info("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001547 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001548 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001549 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1550 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001551 for (j = 0; j < ATM_ESA_LEN; j++) {
1552 offset += sprintf(buf + offset, "%2.2x ",
1553 rulla->atm_addr[j] & 0xff);
1554 }
1555 offset += sprintf(buf + offset,
1556 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1557 rulla->vcc ? rulla->vcc->vpi : 0,
1558 rulla->vcc ? rulla->vcc->vci : 0,
1559 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1560 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1561 rulla->last_used,
1562 rulla->timestamp, rulla->no_tries);
1563 offset += sprintf(buf + offset,
1564 "Flags:%x, Packets_flooded:%x, Status: %s ",
1565 rulla->flags, rulla->packets_flooded,
1566 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001567 pr_info("%s", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Chas Williamsd0732f62006-09-29 17:14:27 -07001570 if (!hlist_empty(&priv->mcast_fwds))
Joe Perchesc48192a2010-01-26 11:40:08 +00001571 pr_info("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001572 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001573 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001574 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1575 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001576 for (j = 0; j < ATM_ESA_LEN; j++) {
1577 offset += sprintf(buf + offset, "%2.2x ",
1578 rulla->atm_addr[j] & 0xff);
1579 }
1580 offset += sprintf(buf + offset,
1581 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1582 rulla->vcc ? rulla->vcc->vpi : 0,
1583 rulla->vcc ? rulla->vcc->vci : 0,
1584 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1585 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1586 rulla->last_used,
1587 rulla->timestamp, rulla->no_tries);
1588 offset += sprintf(buf + offset,
1589 "Flags:%x, Packets_flooded:%x, Status: %s ",
1590 rulla->flags, rulla->packets_flooded,
1591 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001592 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
Chas Williamsd0732f62006-09-29 17:14:27 -07001596#else
1597#define dump_arp_table(priv) do { } while (0)
1598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600/*
1601 * Destruction of arp-cache
1602 */
Chas Williams1fa99612006-09-29 17:11:47 -07001603static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
1605 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001606 struct hlist_node *node, *next;
1607 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001608 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Tejun Heoafe2c512010-12-14 16:21:17 +01001610 cancel_delayed_work_sync(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001611
1612 /*
1613 * Remove all entries
1614 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
1616 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001617 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001618 hlist_for_each_entry_safe(entry, node, next,
1619 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001620 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001621 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001622 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001623 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001624 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001625
Joe Perchesc48192a2010-01-26 11:40:08 +00001626 hlist_for_each_entry_safe(entry, node, next,
1627 &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001628 del_timer_sync(&entry->timer);
1629 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001630 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001631 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001632 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001633 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1634
Joe Perchesc48192a2010-01-26 11:40:08 +00001635 hlist_for_each_entry_safe(entry, node, next,
1636 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001637 del_timer_sync(&entry->timer);
1638 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001639 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001640 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001641 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001642 INIT_HLIST_HEAD(&priv->lec_no_forward);
1643
1644 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001645 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1646 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001647 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001648 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001649 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001650 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001651 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1653}
1654
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001655/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 * Find entry by mac_address
1657 */
Chas Williams1fa99612006-09-29 17:11:47 -07001658static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001659 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Chas Williamsd0732f62006-09-29 17:14:27 -07001661 struct hlist_node *node;
1662 struct hlist_head *head;
1663 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Joe Perches99824462010-01-26 11:40:00 +00001665 pr_debug("%pM\n", mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001666
Chas Williamsd0732f62006-09-29 17:14:27 -07001667 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1668 hlist_for_each_entry(entry, node, head, next) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001669 if (!compare_ether_addr(mac_addr, entry->mac_addr))
Chas Williamsd0732f62006-09-29 17:14:27 -07001670 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001671 }
1672 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Chas Williams1fa99612006-09-29 17:11:47 -07001675static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001676 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Chas Williams1fa99612006-09-29 17:11:47 -07001678 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Chas Williams1fa99612006-09-29 17:11:47 -07001680 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1681 if (!to_return) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001682 pr_info("LEC: Arp entry kmalloc failed\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001683 return NULL;
1684 }
1685 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001686 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001687 setup_timer(&to_return->timer, lec_arp_expire_arp,
1688 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001689 to_return->last_used = jiffies;
1690 to_return->priv = priv;
1691 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001692 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001693 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
Chas Williams1fa99612006-09-29 17:11:47 -07001696/* Arp sent timer expired */
1697static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698{
Chas Williams1fa99612006-09-29 17:11:47 -07001699 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Chas Williams1fa99612006-09-29 17:11:47 -07001701 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Joe Perches99824462010-01-26 11:40:00 +00001703 pr_debug("\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001704 if (entry->status == ESI_ARP_PENDING) {
1705 if (entry->no_tries <= entry->priv->max_retry_count) {
1706 if (entry->is_rdesc)
1707 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1708 entry->mac_addr, NULL, NULL);
1709 else
1710 send_to_lecd(entry->priv, l_arp_xmt,
1711 entry->mac_addr, NULL, NULL);
1712 entry->no_tries++;
1713 }
1714 mod_timer(&entry->timer, jiffies + (1 * HZ));
1715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Chas Williams1fa99612006-09-29 17:11:47 -07001718/* Unknown/unused vcc expire, remove associated entry */
1719static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
1721 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001722 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1723 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Chas Williams1fa99612006-09-29 17:11:47 -07001725 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Joe Perches99824462010-01-26 11:40:00 +00001727 pr_debug("%p %p: vpi:%d vci:%d\n",
1728 to_remove, priv,
1729 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1730 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001733 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1735
Chas Williams1fa99612006-09-29 17:11:47 -07001736 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001737 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001740static bool __lec_arp_check_expire(struct lec_arp_table *entry,
1741 unsigned long now,
1742 struct lec_priv *priv)
1743{
1744 unsigned long time_to_check;
1745
1746 if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
1747 time_to_check = priv->forward_delay_time;
1748 else
1749 time_to_check = priv->aging_time;
1750
1751 pr_debug("About to expire: %lx - %lx > %lx\n",
1752 now, entry->last_used, time_to_check);
1753 if (time_after(now, entry->last_used + time_to_check) &&
1754 !(entry->flags & LEC_PERMANENT_FLAG) &&
1755 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1756 /* Remove entry */
1757 pr_debug("Entry timed out\n");
1758 lec_arp_remove(priv, entry);
1759 lec_arp_put(entry);
1760 } else {
1761 /* Something else */
1762 if ((entry->status == ESI_VC_PENDING ||
1763 entry->status == ESI_ARP_PENDING) &&
1764 time_after_eq(now, entry->timestamp +
1765 priv->max_unknown_frame_time)) {
1766 entry->timestamp = jiffies;
1767 entry->packets_flooded = 0;
1768 if (entry->status == ESI_VC_PENDING)
1769 send_to_lecd(priv, l_svc_setup,
1770 entry->mac_addr,
1771 entry->atm_addr,
1772 NULL);
1773 }
1774 if (entry->status == ESI_FLUSH_PENDING &&
1775 time_after_eq(now, entry->timestamp +
1776 priv->path_switching_delay)) {
1777 lec_arp_hold(entry);
1778 return true;
1779 }
1780 }
1781
1782 return false;
1783}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784/*
1785 * Expire entries.
1786 * 1. Re-set timer
1787 * 2. For each entry, delete entries that have aged past the age limit.
1788 * 3. For each entry, depending on the status of the entry, perform
1789 * the following maintenance.
1790 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1791 * tick_count is above the max_unknown_frame_time, clear
1792 * the tick_count to zero and clear the packets_flooded counter
1793 * to zero. This supports the packet rate limit per address
1794 * while flooding unknowns.
1795 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1796 * than or equal to the path_switching_delay, change the status
1797 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1798 * regardless of the progress of the flush protocol.
1799 */
David Howellsc4028952006-11-22 14:57:56 +00001800static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001803 struct lec_priv *priv =
1804 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001805 struct hlist_node *node, *next;
1806 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001807 unsigned long now;
Chas Williams1fa99612006-09-29 17:11:47 -07001808 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
Joe Perches99824462010-01-26 11:40:00 +00001810 pr_debug("%p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001812restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001814 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001815 hlist_for_each_entry_safe(entry, node, next,
1816 &priv->lec_arp_tables[i], next) {
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001817 if (__lec_arp_check_expire(entry, now, priv)) {
1818 struct sk_buff *skb;
1819 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001821 spin_unlock_irqrestore(&priv->lec_arp_lock,
1822 flags);
1823 while ((skb = skb_dequeue(&entry->tx_wait)))
1824 lec_send(vcc, skb);
1825 entry->last_used = jiffies;
1826 entry->status = ESI_FORWARD_DIRECT;
Chas Williams33a9c2d2006-09-29 17:16:48 -07001827 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001829 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831 }
1832 }
1833 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1834
Chas Williams987e46b2006-09-29 17:15:59 -07001835 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836}
Chas Williams1fa99612006-09-29 17:11:47 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838/*
1839 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001840 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 */
Chas Williams1fa99612006-09-29 17:11:47 -07001842static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Joe Perchesc48192a2010-01-26 11:40:08 +00001843 const unsigned char *mac_to_find,
1844 int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001845 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
1847 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001848 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 struct atm_vcc *found;
1850
Chas Williams1fa99612006-09-29 17:11:47 -07001851 if (mac_to_find[0] & 0x01) {
1852 switch (priv->lane_version) {
1853 case 1:
1854 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001855 case 2: /* LANE2 wants arp for multicast addresses */
1856 if (!compare_ether_addr(mac_to_find, bus_mac))
1857 return priv->mcast_vcc;
1858 break;
1859 default:
1860 break;
1861 }
1862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001865 entry = lec_arp_find(priv, mac_to_find);
1866
1867 if (entry) {
1868 if (entry->status == ESI_FORWARD_DIRECT) {
1869 /* Connection Ok */
1870 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001871 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001872 *ret_entry = entry;
1873 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001875 }
1876 /*
1877 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001878 * so another LE_ARP request can be made for this frame.
1879 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001880 if (entry->status == ESI_ARP_PENDING)
Scott Talbert75b895c2005-09-29 17:31:30 -07001881 entry->no_tries = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07001882 /*
1883 * Data direct VC not yet set up, check to see if the unknown
1884 * frame count is greater than the limit. If the limit has
1885 * not been reached, allow the caller to send packet to
1886 * BUS.
1887 */
1888 if (entry->status != ESI_FLUSH_PENDING &&
1889 entry->packets_flooded <
1890 priv->maximum_unknown_frame_count) {
1891 entry->packets_flooded++;
Joe Perches99824462010-01-26 11:40:00 +00001892 pr_debug("Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001893 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001895 }
1896 /*
1897 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 * or BUS flood limit was reached for an entry which is
1899 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1900 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001901 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001902 *ret_entry = entry;
Joe Perches99824462010-01-26 11:40:00 +00001903 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1904 entry->vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001905 found = NULL;
1906 } else {
1907 /* No matching entry was found */
1908 entry = make_entry(priv, mac_to_find);
Joe Perches99824462010-01-26 11:40:00 +00001909 pr_debug("Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001910 if (!entry) {
1911 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001913 }
1914 lec_arp_add(priv, entry);
1915 /* We want arp-request(s) to be sent */
1916 entry->packets_flooded = 1;
1917 entry->status = ESI_ARP_PENDING;
1918 entry->no_tries = 1;
1919 entry->last_used = entry->timestamp = jiffies;
1920 entry->is_rdesc = is_rdesc;
1921 if (entry->is_rdesc)
1922 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1923 NULL);
1924 else
1925 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1926 entry->timer.expires = jiffies + (1 * HZ);
1927 entry->timer.function = lec_arp_expire_arp;
1928 add_timer(&entry->timer);
1929 found = priv->mcast_vcc;
1930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932out:
1933 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1934 return found;
1935}
1936
1937static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001938lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001939 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940{
1941 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001942 struct hlist_node *node, *next;
1943 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001944 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Joe Perches99824462010-01-26 11:40:00 +00001946 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001948 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001949 hlist_for_each_entry_safe(entry, node, next,
1950 &priv->lec_arp_tables[i], next) {
1951 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
1952 (permanent ||
1953 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001955 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001958 return 0;
1959 }
1960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001962 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
1965/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001966 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 */
1968static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001969lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1970 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07001971 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
1973 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001974 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07001975 struct lec_arp_table *entry, *tmp;
1976 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Joe Perches99824462010-01-26 11:40:00 +00001978 pr_debug("%smac:%pM\n",
1979 (targetless_le_arp) ? "targetless " : "", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001982 entry = lec_arp_find(priv, mac_addr);
1983 if (entry == NULL && targetless_le_arp)
1984 goto out; /*
1985 * LANE2: ignore targetless LE_ARPs for which
1986 * we have no entry in the cache. 7.1.30
1987 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001988 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001989 hlist_for_each_entry_safe(entry, node, next,
1990 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001991 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
1992 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001993 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07001994 tmp = lec_arp_find(priv, mac_addr);
1995 if (tmp) {
1996 del_timer(&tmp->timer);
1997 tmp->status = ESI_FORWARD_DIRECT;
1998 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
1999 tmp->vcc = entry->vcc;
2000 tmp->old_push = entry->old_push;
2001 tmp->last_used = jiffies;
2002 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002003 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002004 entry = tmp;
2005 } else {
2006 entry->status = ESI_FORWARD_DIRECT;
2007 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2008 entry->last_used = jiffies;
2009 lec_arp_add(priv, entry);
2010 }
2011 if (remoteflag)
2012 entry->flags |= LEC_REMOTE_FLAG;
2013 else
2014 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002015 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002016 dump_arp_table(priv);
2017 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002018 }
Chas Williams1fa99612006-09-29 17:11:47 -07002019 }
2020 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002021
Chas Williams1fa99612006-09-29 17:11:47 -07002022 entry = lec_arp_find(priv, mac_addr);
2023 if (!entry) {
2024 entry = make_entry(priv, mac_addr);
2025 if (!entry)
2026 goto out;
2027 entry->status = ESI_UNKNOWN;
2028 lec_arp_add(priv, entry);
2029 /* Temporary, changes before end of function */
2030 }
2031 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2032 del_timer(&entry->timer);
2033 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002034 hlist_for_each_entry(tmp, node,
2035 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002036 if (entry != tmp &&
2037 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2038 /* Vcc to this host exists */
2039 if (tmp->status > ESI_VC_PENDING) {
2040 /*
2041 * ESI_FLUSH_PENDING,
2042 * ESI_FORWARD_DIRECT
2043 */
2044 entry->vcc = tmp->vcc;
2045 entry->old_push = tmp->old_push;
2046 }
2047 entry->status = tmp->status;
2048 break;
2049 }
2050 }
2051 }
2052 if (remoteflag)
2053 entry->flags |= LEC_REMOTE_FLAG;
2054 else
2055 entry->flags &= ~LEC_REMOTE_FLAG;
2056 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2057 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002058 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002059 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002060 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002061 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062out:
2063 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2064}
2065
2066/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002067 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 */
2069static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002070lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002071 struct atm_vcc *vcc,
2072 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
2074 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002075 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002076 struct lec_arp_table *entry;
2077 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002080 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williams1fa99612006-09-29 17:11:47 -07002081 if (ioc_data->receive == 2) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002082 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002084 entry = lec_arp_find(priv, bus_mac);
2085 if (!entry) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002086 pr_info("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002088 }
2089 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2090 entry->recv_vcc = vcc;
2091 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002093 entry = make_entry(priv, bus_mac);
2094 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002096 del_timer(&entry->timer);
2097 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2098 entry->recv_vcc = vcc;
2099 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002100 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002101 goto out;
2102 } else if (ioc_data->receive == 1) {
2103 /*
2104 * Vcc which we don't want to make default vcc,
2105 * attach it anyway.
2106 */
Joe Perches99824462010-01-26 11:40:00 +00002107 pr_debug("LEC_ARP:Attaching data direct, not default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2108 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2109 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2110 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2111 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2112 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2113 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2114 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2115 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2116 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2117 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002118 entry = make_entry(priv, bus_mac);
2119 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002121 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2122 memset(entry->mac_addr, 0, ETH_ALEN);
2123 entry->recv_vcc = vcc;
2124 entry->old_recv_push = old_push;
2125 entry->status = ESI_UNKNOWN;
2126 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2127 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002128 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002129 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 dump_arp_table(priv);
2131 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002132 }
Joe Perches99824462010-01-26 11:40:00 +00002133 pr_debug("LEC_ARP:Attaching data direct, default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2134 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2135 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2136 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2137 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2138 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2139 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2140 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2141 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2142 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2143 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002144 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002145 hlist_for_each_entry(entry, node,
2146 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002147 if (memcmp
2148 (ioc_data->atm_addr, entry->atm_addr,
2149 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002150 pr_debug("LEC_ARP: Attaching data direct\n");
2151 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Joe Perches99824462010-01-26 11:40:00 +00002152 entry->vcc ? entry->vcc->vci : 0,
2153 entry->recv_vcc ? entry->recv_vcc->
2154 vci : 0);
Chas Williams1fa99612006-09-29 17:11:47 -07002155 found_entry = 1;
2156 del_timer(&entry->timer);
2157 entry->vcc = vcc;
2158 entry->old_push = old_push;
2159 if (entry->status == ESI_VC_PENDING) {
2160 if (priv->maximum_unknown_frame_count
2161 == 0)
2162 entry->status =
2163 ESI_FORWARD_DIRECT;
2164 else {
2165 entry->timestamp = jiffies;
2166 entry->status =
2167 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002169 send_to_lecd(priv, l_flush_xmt,
2170 NULL,
2171 entry->atm_addr,
2172 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002174 }
2175 } else {
2176 /*
2177 * They were forming a connection
2178 * to us, and we to them. Our
2179 * ATM address is numerically lower
2180 * than theirs, so we make connection
2181 * we formed into default VCC (8.1.11).
2182 * Connection they made gets torn
2183 * down. This might confuse some
2184 * clients. Can be changed if
2185 * someone reports trouble...
2186 */
2187 ;
2188 }
2189 }
2190 }
2191 }
2192 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002193 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002194 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002196 }
2197 /*
2198 * Not found, snatch address from first data packet that arrives
2199 * from this vcc
2200 */
2201 entry = make_entry(priv, bus_mac);
2202 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002204 entry->vcc = vcc;
2205 entry->old_push = old_push;
2206 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2207 memset(entry->mac_addr, 0, ETH_ALEN);
2208 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002209 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002210 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2211 entry->timer.function = lec_arp_expire_vcc;
2212 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002213 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 dump_arp_table(priv);
2215out:
2216 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2217}
2218
Chas Williams1fa99612006-09-29 17:11:47 -07002219static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
2221 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002222 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002223 struct lec_arp_table *entry;
2224 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Joe Perches99824462010-01-26 11:40:00 +00002226 pr_debug("%lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002227restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002228 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2229 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002230 hlist_for_each_entry(entry, node,
2231 &priv->lec_arp_tables[i], next) {
2232 if (entry->flush_tran_id == tran_id &&
2233 entry->status == ESI_FLUSH_PENDING) {
Chas Williams1fa99612006-09-29 17:11:47 -07002234 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002235 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002236
Chas Williams6656e3c2006-09-29 17:17:17 -07002237 lec_arp_hold(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002238 spin_unlock_irqrestore(&priv->lec_arp_lock,
2239 flags);
Joe Perchesb4c84ec2010-01-26 11:40:19 +00002240 while ((skb = skb_dequeue(&entry->tx_wait)))
Stephen Hemminger162619e2009-01-09 13:01:01 +00002241 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002242 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002243 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002244 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002245 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002246 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002247 }
2248 }
2249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002251 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
2254static void
2255lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002256 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
2258 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002259 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002260 struct lec_arp_table *entry;
2261 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002264 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Joe Perchesc48192a2010-01-26 11:40:08 +00002265 hlist_for_each_entry(entry, node,
2266 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002267 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2268 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002269 pr_debug("Set flush transaction id to %lx for %p\n",
Joe Perches99824462010-01-26 11:40:00 +00002270 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002271 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2274}
2275
Chas Williams1fa99612006-09-29 17:11:47 -07002276static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
2278 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002279 unsigned char mac_addr[] = {
2280 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2281 };
2282 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 struct lec_vcc_priv *vpriv;
2284 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002285
Joe Perchesc48192a2010-01-26 11:40:08 +00002286 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2287 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 return -ENOMEM;
2289 vpriv->xoff = 0;
2290 vpriv->old_pop = vcc->pop;
2291 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002292 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002294 to_add = make_entry(priv, mac_addr);
2295 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 vcc->pop = vpriv->old_pop;
2297 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002298 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002300 }
2301 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2302 to_add->status = ESI_FORWARD_DIRECT;
2303 to_add->flags |= LEC_PERMANENT_FLAG;
2304 to_add->vcc = vcc;
2305 to_add->old_push = vcc->push;
2306 vcc->push = lec_push;
2307 priv->mcast_vcc = vcc;
2308 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309out:
2310 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002311 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
Chas Williams1fa99612006-09-29 17:11:47 -07002314static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
2316 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002317 struct hlist_node *node, *next;
2318 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002319 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Stephen Hemminger52240062007-08-28 15:22:09 -07002321 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002322 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002325
Chas Williams1fa99612006-09-29 17:11:47 -07002326 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002327 hlist_for_each_entry_safe(entry, node, next,
2328 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002329 if (vcc == entry->vcc) {
2330 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002331 lec_arp_put(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002332 if (priv->mcast_vcc == vcc)
Chas Williams1fa99612006-09-29 17:11:47 -07002333 priv->mcast_vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07002334 }
2335 }
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Joe Perchesc48192a2010-01-26 11:40:08 +00002338 hlist_for_each_entry_safe(entry, node, next,
2339 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002340 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002341 lec_arp_clear_vccs(entry);
2342 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002343 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002344 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002345 }
Chas Williams1fa99612006-09-29 17:11:47 -07002346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Joe Perchesc48192a2010-01-26 11:40:08 +00002348 hlist_for_each_entry_safe(entry, node, next,
2349 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002350 if (entry->recv_vcc == vcc) {
2351 lec_arp_clear_vccs(entry);
2352 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002353 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002354 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002355 }
Chas Williams1fa99612006-09-29 17:11:47 -07002356 }
2357
Chas Williamsd0732f62006-09-29 17:14:27 -07002358 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002359 if (entry->recv_vcc == vcc) {
2360 lec_arp_clear_vccs(entry);
2361 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002362 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002363 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002364 }
Chas Williams1fa99612006-09-29 17:11:47 -07002365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
2367 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2368 dump_arp_table(priv);
2369}
2370
2371static void
2372lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002373 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Chas Williams1fa99612006-09-29 17:11:47 -07002375 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002376 struct hlist_node *node, *next;
2377 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002378 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2379 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002381 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Chas Williams1fa99612006-09-29 17:11:47 -07002383 if (priv->is_trdev)
2384 src = tr_hdr->h_source;
2385 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002387 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
2389 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002390 hlist_for_each_entry_safe(entry, node, next,
2391 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002392 if (vcc == entry->vcc) {
2393 del_timer(&entry->timer);
2394 memcpy(entry->mac_addr, src, ETH_ALEN);
2395 entry->status = ESI_FORWARD_DIRECT;
2396 entry->last_used = jiffies;
2397 /* We might have got an entry */
Joe Perchesc48192a2010-01-26 11:40:08 +00002398 tmp = lec_arp_find(priv, src);
2399 if (tmp) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002400 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002401 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002402 }
2403 hlist_del(&entry->next);
2404 lec_arp_add(priv, entry);
2405 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002406 }
Chas Williams1fa99612006-09-29 17:11:47 -07002407 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002408 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409out:
2410 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2411}
Chas Williams1fa99612006-09-29 17:11:47 -07002412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413MODULE_LICENSE("GPL");