blob: 96a4a4bd23048b1085762772722b15d4d8a06fb5 [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];
Wang Chen524ad0a2008-11-12 23:39:10 -0800819 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
820 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
823/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700824static int lecd_attach(struct atm_vcc *vcc, int arg)
825{
826 int i;
827 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Chas Williamsd44f7742006-09-29 17:11:14 -0700829 if (arg < 0)
830 i = 0;
831 else
832 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700834 if (arg >= MAX_LEC_ITF)
835 return -EINVAL;
836#else /* Reserve the top NUM_TR_DEVS for TR */
837 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
838 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700840 if (!dev_lec[i]) {
841 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Chas Williamsd44f7742006-09-29 17:11:14 -0700843 is_trdev = 0;
844 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
845 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Chas Williamsd44f7742006-09-29 17:11:14 -0700847 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700849 if (is_trdev)
850 dev_lec[i] = alloc_trdev(size);
851 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700853 dev_lec[i] = alloc_etherdev(size);
854 if (!dev_lec[i])
855 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000856 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700857 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
858 if (register_netdev(dev_lec[i])) {
859 free_netdev(dev_lec[i]);
860 return -EINVAL;
861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Wang Chen524ad0a2008-11-12 23:39:10 -0800863 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700864 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700865 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800866 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700867 if (priv->lecd)
868 return -EADDRINUSE;
869 }
870 lec_arp_init(priv);
871 priv->itfnum = i; /* LANE2 addition */
872 priv->lecd = vcc;
873 vcc->dev = &lecatm_dev;
874 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Chas Williamsd44f7742006-09-29 17:11:14 -0700876 vcc->proto_data = dev_lec[i];
877 set_bit(ATM_VF_META, &vcc->flags);
878 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Chas Williamsd44f7742006-09-29 17:11:14 -0700880 /* Set default values to these variables */
881 priv->maximum_unknown_frame_count = 1;
882 priv->max_unknown_frame_time = (1 * HZ);
883 priv->vcc_timeout_period = (1200 * HZ);
884 priv->max_retry_count = 1;
885 priv->aging_time = (300 * HZ);
886 priv->forward_delay_time = (15 * HZ);
887 priv->topology_change = 0;
888 priv->arp_response_time = (1 * HZ);
889 priv->flush_timeout = (4 * HZ);
890 priv->path_switching_delay = (6 * HZ);
891
Joe Perchesc48192a2010-01-26 11:40:08 +0000892 if (dev_lec[i]->flags & IFF_UP)
Chas Williamsd44f7742006-09-29 17:11:14 -0700893 netif_start_queue(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700894 __module_get(THIS_MODULE);
895 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700899static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700901 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 "ESI_UNKNOWN ",
903 "ESI_ARP_PENDING ",
904 "ESI_VC_PENDING ",
905 "<Undefined> ",
906 "ESI_FLUSH_PENDING ",
907 "ESI_FORWARD_DIRECT"
908 };
909
910 if (status > ESI_FORWARD_DIRECT)
911 status = 3; /* ESI_UNDEFINED */
912 return lec_arp_status_string[status];
913}
914
915static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
916{
917 int i;
918
919 for (i = 0; i < ETH_ALEN; i++)
920 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
921 seq_printf(seq, " ");
922 for (i = 0; i < ATM_ESA_LEN; i++)
923 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
924 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
925 entry->flags & 0xffff);
926 if (entry->vcc)
927 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
928 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700929 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (entry->recv_vcc) {
931 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
932 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700933 }
934 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937struct lec_state {
938 unsigned long flags;
939 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700940 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 struct net_device *dev;
942 int itf;
943 int arp_table;
944 int misc_table;
945};
946
Chas Williamsd0732f62006-09-29 17:14:27 -0700947static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 loff_t *l)
949{
Chas Williamsd0732f62006-09-29 17:14:27 -0700950 struct hlist_node *e = state->node;
951 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700954 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700955 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700956 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 --*l;
958 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700959
960 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (--*l < 0)
962 break;
963 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700964 state->node = e;
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 return (*l < 0) ? state : NULL;
967}
968
969static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -0700970 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
972 void *v = NULL;
973 int p;
974
975 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700976 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (v)
978 break;
979 }
980 state->arp_table = p;
981 return v;
982}
983
984static void *lec_misc_walk(struct lec_state *state, loff_t *l,
985 struct lec_priv *priv)
986{
Chas Williamsd0732f62006-09-29 17:14:27 -0700987 struct hlist_head *lec_misc_tables[] = {
988 &priv->lec_arp_empty_ones,
989 &priv->lec_no_forward,
990 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 };
992 void *v = NULL;
993 int q;
994
995 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
996 v = lec_tbl_walk(state, lec_misc_tables[q], l);
997 if (v)
998 break;
999 }
1000 state->misc_table = q;
1001 return v;
1002}
1003
1004static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1005 struct lec_priv *priv)
1006{
1007 if (!state->locked) {
1008 state->locked = priv;
1009 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1010 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001011 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1013 state->locked = NULL;
1014 /* Partial state reset for the next time we get called */
1015 state->arp_table = state->misc_table = 0;
1016 }
1017 return state->locked;
1018}
1019
1020static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1021{
1022 struct net_device *dev;
1023 void *v;
1024
1025 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001026 v = (dev && netdev_priv(dev)) ?
1027 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (!v && dev) {
1029 dev_put(dev);
1030 /* Partial state reset for the next time we get called */
1031 dev = NULL;
1032 }
1033 state->dev = dev;
1034 return v;
1035}
1036
1037static void *lec_get_idx(struct lec_state *state, loff_t l)
1038{
1039 void *v = NULL;
1040
1041 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1042 v = lec_itf_walk(state, &l);
1043 if (v)
1044 break;
1045 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001046 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
1049static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1050{
1051 struct lec_state *state = seq->private;
1052
1053 state->itf = 0;
1054 state->dev = NULL;
1055 state->locked = NULL;
1056 state->arp_table = 0;
1057 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001058 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Joe Perches2e1e9842008-04-10 03:33:03 -07001060 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
1063static void lec_seq_stop(struct seq_file *seq, void *v)
1064{
1065 struct lec_state *state = seq->private;
1066
1067 if (state->dev) {
1068 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1069 state->flags);
1070 dev_put(state->dev);
1071 }
1072}
1073
1074static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1075{
1076 struct lec_state *state = seq->private;
1077
1078 v = lec_get_idx(state, 1);
1079 *pos += !!PTR_ERR(v);
1080 return v;
1081}
1082
1083static int lec_seq_show(struct seq_file *seq, void *v)
1084{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001085 static const char lec_banner[] =
1086 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001087 " Status Flags "
1088 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Joe Perches2e1e9842008-04-10 03:33:03 -07001090 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 seq_puts(seq, lec_banner);
1092 else {
1093 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001094 struct net_device *dev = state->dev;
Joe Perchesc48192a2010-01-26 11:40:08 +00001095 struct lec_arp_table *entry = hlist_entry(state->node,
1096 struct lec_arp_table,
1097 next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001100 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
1102 return 0;
1103}
1104
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001105static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001106 .start = lec_seq_start,
1107 .next = lec_seq_next,
1108 .stop = lec_seq_stop,
1109 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110};
1111
1112static int lec_seq_open(struct inode *inode, struct file *file)
1113{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001114 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Arjan van de Ven9a321442007-02-12 00:55:35 -08001117static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001118 .owner = THIS_MODULE,
1119 .open = lec_seq_open,
1120 .read = seq_read,
1121 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001122 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123};
1124#endif
1125
1126static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1127{
1128 struct atm_vcc *vcc = ATM_SD(sock);
1129 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001132 case ATMLEC_CTRL:
1133 case ATMLEC_MCAST:
1134 case ATMLEC_DATA:
1135 if (!capable(CAP_NET_ADMIN))
1136 return -EPERM;
1137 break;
1138 default:
1139 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
1142 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001143 case ATMLEC_CTRL:
1144 err = lecd_attach(vcc, (int)arg);
1145 if (err >= 0)
1146 sock->state = SS_CONNECTED;
1147 break;
1148 case ATMLEC_MCAST:
1149 err = lec_mcast_attach(vcc, (int)arg);
1150 break;
1151 case ATMLEC_DATA:
1152 err = lec_vcc_attach(vcc, (void __user *)arg);
1153 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155
1156 return err;
1157}
1158
1159static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001160 .owner = THIS_MODULE,
1161 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162};
1163
1164static int __init lane_module_init(void)
1165{
1166#ifdef CONFIG_PROC_FS
1167 struct proc_dir_entry *p;
1168
Wang Chen16e297b2008-02-28 13:55:45 -08001169 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001170 if (!p) {
Joe Perches99824462010-01-26 11:40:00 +00001171 pr_err("Unable to initialize /proc/net/atm/lec\n");
Wang Chendbee0d32008-03-23 21:45:36 -07001172 return -ENOMEM;
1173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#endif
1175
1176 register_atm_ioctl(&lane_ioctl_ops);
Joe Perchesc48192a2010-01-26 11:40:08 +00001177 pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
1181static void __exit lane_module_cleanup(void)
1182{
Chas Williamsd44f7742006-09-29 17:11:14 -07001183 int i;
1184 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
1186 remove_proc_entry("lec", atm_proc_root);
1187
1188 deregister_atm_ioctl(&lane_ioctl_ops);
1189
Chas Williamsd44f7742006-09-29 17:11:14 -07001190 for (i = 0; i < MAX_LEC_ITF; i++) {
1191 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001192 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001194 free_netdev(dev_lec[i]);
1195 dev_lec[i] = NULL;
1196 }
1197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
1200module_init(lane_module_init);
1201module_exit(lane_module_cleanup);
1202
1203/*
1204 * LANE2: 3.1.3, LE_RESOLVE.request
1205 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1206 * If sizeoftlvs == NULL the default TLVs associated with with this
1207 * lec will be used.
1208 * If dst_mac == NULL, targetless LE_ARP will be sent
1209 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001210static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001211 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001214 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001215 struct lec_arp_table *table;
1216 struct sk_buff *skb;
1217 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Chas Williamsd44f7742006-09-29 17:11:14 -07001219 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001221 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001223 if (table == NULL)
1224 return -1;
1225
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001226 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001227 if (*tlvs == NULL)
1228 return -1;
1229
Chas Williamsd44f7742006-09-29 17:11:14 -07001230 *sizeoftlvs = table->sizeoftlvs;
1231
1232 return 0;
1233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 if (sizeoftlvs == NULL)
1236 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 else {
1239 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1240 if (skb == NULL)
1241 return -1;
1242 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001243 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1245 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001246 return retval;
1247}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249/*
1250 * LANE2: 3.1.4, LE_ASSOCIATE.request
1251 * Associate the *tlvs with the *lan_dst address.
1252 * Will overwrite any previous association
1253 * Returns 1 for success, 0 for failure (out of memory)
1254 *
1255 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001256static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1257 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Chas Williamsd44f7742006-09-29 17:11:14 -07001259 int retval;
1260 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001261 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Chas Williamsd44f7742006-09-29 17:11:14 -07001263 if (compare_ether_addr(lan_dst, dev->dev_addr))
Joe Perchesc48192a2010-01-26 11:40:08 +00001264 return 0; /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Chas Williamsd44f7742006-09-29 17:11:14 -07001266 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001268 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001269 if (priv->tlvs == NULL)
Joe Perchesc48192a2010-01-26 11:40:08 +00001270 return 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Chas Williamsd44f7742006-09-29 17:11:14 -07001273 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1274 if (skb == NULL)
1275 return 0;
1276 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001277 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001278 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1279 if (retval != 0)
Joe Perchesc48192a2010-01-26 11:40:08 +00001280 pr_info("lec.c: lane2_associate_req() failed\n");
Chas Williamsd44f7742006-09-29 17:11:14 -07001281 /*
1282 * If the previous association has changed we must
1283 * somehow notify other LANE entities about the change
1284 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001285 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
1288/*
1289 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1290 *
1291 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001292static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1293 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
1295#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001296 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001298 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001299#if 0 /*
1300 * Why have the TLVs in LE_ARP entries
1301 * since we do not use them? When you
1302 * uncomment this code, make sure the
1303 * TLVs get freed when entry is killed
1304 */
1305 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Chas Williamsd44f7742006-09-29 17:11:14 -07001307 if (entry == NULL)
1308 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Chas Williamsd44f7742006-09-29 17:11:14 -07001310 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001312 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001313 if (entry->tlvs == NULL)
1314 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316#endif
1317#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001318 pr_info("\n");
1319 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001320 while (i < sizeoftlvs)
Joe Perchesc48192a2010-01-26 11:40:08 +00001321 pr_cont("%02x ", tlvs[i++]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001322
Joe Perchesc48192a2010-01-26 11:40:08 +00001323 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324#endif
1325
Chas Williamsd44f7742006-09-29 17:11:14 -07001326 /* tell MPOA about the TLVs we saw */
1327 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1328 priv->lane2_ops->associate_indicator(dev, mac_addr,
1329 tlvs, sizeoftlvs);
1330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
1333/*
1334 * Here starts what used to lec_arpc.c
1335 *
1336 * lec_arpc.c was added here when making
1337 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 */
1339
1340#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341#include <linux/timer.h>
Joe Perchesc48192a2010-01-26 11:40:08 +00001342#include <linux/param.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#include <asm/atomic.h>
1344#include <linux/inetdevice.h>
1345#include <net/route.h>
1346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347#if 0
Joe Perchesc48192a2010-01-26 11:40:08 +00001348#define pr_debug(format, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349/*
Joe Perches99824462010-01-26 11:40:00 +00001350 #define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351*/
1352#endif
1353#define DEBUG_ARP_TABLE 0
1354
1355#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1356
David Howellsc4028952006-11-22 14:57:56 +00001357static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358static void lec_arp_expire_arp(unsigned long data);
1359
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001360/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 * Arp table funcs
1362 */
1363
Joe Perchesc48192a2010-01-26 11:40:08 +00001364#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366/*
1367 * Initialization of arp-cache
1368 */
Chas Williams1fa99612006-09-29 17:11:47 -07001369static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
Chas Williams1fa99612006-09-29 17:11:47 -07001371 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Joe Perchesc48192a2010-01-26 11:40:08 +00001373 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07001374 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001375 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1376 INIT_HLIST_HEAD(&priv->lec_no_forward);
1377 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001379 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001380 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
Chas Williams1fa99612006-09-29 17:11:47 -07001383static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
Chas Williams1fa99612006-09-29 17:11:47 -07001385 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 struct atm_vcc *vcc = entry->vcc;
1387 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001388 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Chas Williams1fa99612006-09-29 17:11:47 -07001390 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 if (vpriv->xoff)
1392 netif_wake_queue(dev);
1393 kfree(vpriv);
1394 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001395 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001397 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001398 }
1399 if (entry->recv_vcc) {
1400 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001402 entry->recv_vcc = NULL;
1403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
1406/*
1407 * Insert entry to lec_arp_table
1408 * LANE2: Add to the end of the list to satisfy 8.1.13
1409 */
Chas Williams1fa99612006-09-29 17:11:47 -07001410static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001411lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Chas Williamsd0732f62006-09-29 17:14:27 -07001413 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Chas Williamsd0732f62006-09-29 17:14:27 -07001415 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1416 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001417
Joe Perches99824462010-01-26 11:40:00 +00001418 pr_debug("Added entry:%pM\n", entry->mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419}
1420
1421/*
1422 * Remove entry from lec_arp_table
1423 */
Chas Williams1fa99612006-09-29 17:11:47 -07001424static int
1425lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Chas Williamsd0732f62006-09-29 17:14:27 -07001427 struct hlist_node *node;
1428 struct lec_arp_table *entry;
1429 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Joe Perchesc48192a2010-01-26 11:40:08 +00001431 if (!to_remove)
Chas Williams1fa99612006-09-29 17:11:47 -07001432 return -1;
Chas Williamsd0732f62006-09-29 17:14:27 -07001433
1434 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001435 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Joe Perchesc48192a2010-01-26 11:40:08 +00001437 /*
1438 * If this is the only MAC connected to this VCC,
1439 * also tear down the VCC
1440 */
Chas Williams1fa99612006-09-29 17:11:47 -07001441 if (to_remove->status >= ESI_FLUSH_PENDING) {
1442 /*
1443 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1444 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001445 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001446 hlist_for_each_entry(entry, node,
1447 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001448 if (memcmp(to_remove->atm_addr,
1449 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001450 remove_vcc = 0;
1451 break;
1452 }
1453 }
1454 }
1455 if (remove_vcc)
1456 lec_arp_clear_vccs(to_remove);
1457 }
1458 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1459
Joe Perches99824462010-01-26 11:40:00 +00001460 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001461 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
1464#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001465static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
Chas Williams1fa99612006-09-29 17:11:47 -07001467 switch (st) {
1468 case ESI_UNKNOWN:
1469 return "ESI_UNKNOWN";
1470 case ESI_ARP_PENDING:
1471 return "ESI_ARP_PENDING";
1472 case ESI_VC_PENDING:
1473 return "ESI_VC_PENDING";
1474 case ESI_FLUSH_PENDING:
1475 return "ESI_FLUSH_PENDING";
1476 case ESI_FORWARD_DIRECT:
1477 return "ESI_FORWARD_DIRECT";
Chas Williams1fa99612006-09-29 17:11:47 -07001478 }
Joe Perchesc48192a2010-01-26 11:40:08 +00001479 return "<UNKNOWN>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Chas Williams1fa99612006-09-29 17:11:47 -07001482static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Chas Williamsd0732f62006-09-29 17:14:27 -07001484 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001485 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001486 char buf[256];
1487 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Joe Perchesc48192a2010-01-26 11:40:08 +00001489 pr_info("Dump %p:\n", priv);
Chas Williams1fa99612006-09-29 17:11:47 -07001490 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001491 hlist_for_each_entry(rulla, node,
1492 &priv->lec_arp_tables[i], next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001493 offset = 0;
1494 offset += sprintf(buf, "%d: %p\n", i, rulla);
Joe Perchesc48192a2010-01-26 11:40:08 +00001495 offset += sprintf(buf + offset, "Mac: %pM",
1496 rulla->mac_addr);
1497 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001498 for (j = 0; j < ATM_ESA_LEN; j++) {
1499 offset += sprintf(buf + offset,
1500 "%2.2x ",
1501 rulla->atm_addr[j] & 0xff);
1502 }
1503 offset += sprintf(buf + offset,
1504 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1505 rulla->vcc ? rulla->vcc->vpi : 0,
1506 rulla->vcc ? rulla->vcc->vci : 0,
1507 rulla->recv_vcc ? rulla->recv_vcc->
1508 vpi : 0,
1509 rulla->recv_vcc ? rulla->recv_vcc->
1510 vci : 0, rulla->last_used,
1511 rulla->timestamp, rulla->no_tries);
1512 offset +=
1513 sprintf(buf + offset,
1514 "Flags:%x, Packets_flooded:%x, Status: %s ",
1515 rulla->flags, rulla->packets_flooded,
1516 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001517 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001518 }
Chas Williams1fa99612006-09-29 17:11:47 -07001519 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001520
1521 if (!hlist_empty(&priv->lec_no_forward))
Joe Perchesc48192a2010-01-26 11:40:08 +00001522 pr_info("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001523 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001524 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001525 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1526 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001527 for (j = 0; j < ATM_ESA_LEN; j++) {
1528 offset += sprintf(buf + offset, "%2.2x ",
1529 rulla->atm_addr[j] & 0xff);
1530 }
1531 offset += sprintf(buf + offset,
1532 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1533 rulla->vcc ? rulla->vcc->vpi : 0,
1534 rulla->vcc ? rulla->vcc->vci : 0,
1535 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1536 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1537 rulla->last_used,
1538 rulla->timestamp, rulla->no_tries);
1539 offset += sprintf(buf + offset,
1540 "Flags:%x, Packets_flooded:%x, Status: %s ",
1541 rulla->flags, rulla->packets_flooded,
1542 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001543 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001544 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001545
1546 if (!hlist_empty(&priv->lec_arp_empty_ones))
Joe Perchesc48192a2010-01-26 11:40:08 +00001547 pr_info("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001548 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001549 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001550 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1551 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001552 for (j = 0; j < ATM_ESA_LEN; j++) {
1553 offset += sprintf(buf + offset, "%2.2x ",
1554 rulla->atm_addr[j] & 0xff);
1555 }
1556 offset += sprintf(buf + offset,
1557 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1558 rulla->vcc ? rulla->vcc->vpi : 0,
1559 rulla->vcc ? rulla->vcc->vci : 0,
1560 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1561 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1562 rulla->last_used,
1563 rulla->timestamp, rulla->no_tries);
1564 offset += sprintf(buf + offset,
1565 "Flags:%x, Packets_flooded:%x, Status: %s ",
1566 rulla->flags, rulla->packets_flooded,
1567 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001568 pr_info("%s", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Chas Williamsd0732f62006-09-29 17:14:27 -07001571 if (!hlist_empty(&priv->mcast_fwds))
Joe Perchesc48192a2010-01-26 11:40:08 +00001572 pr_info("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001573 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001574 offset = 0;
Joe Perchesc48192a2010-01-26 11:40:08 +00001575 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1576 offset += sprintf(buf + offset, " Atm:");
Chas Williams1fa99612006-09-29 17:11:47 -07001577 for (j = 0; j < ATM_ESA_LEN; j++) {
1578 offset += sprintf(buf + offset, "%2.2x ",
1579 rulla->atm_addr[j] & 0xff);
1580 }
1581 offset += sprintf(buf + offset,
1582 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1583 rulla->vcc ? rulla->vcc->vpi : 0,
1584 rulla->vcc ? rulla->vcc->vci : 0,
1585 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1586 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1587 rulla->last_used,
1588 rulla->timestamp, rulla->no_tries);
1589 offset += sprintf(buf + offset,
1590 "Flags:%x, Packets_flooded:%x, Status: %s ",
1591 rulla->flags, rulla->packets_flooded,
1592 get_status_string(rulla->status));
Joe Perchesc48192a2010-01-26 11:40:08 +00001593 pr_info("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
Chas Williamsd0732f62006-09-29 17:14:27 -07001597#else
1598#define dump_arp_table(priv) do { } while (0)
1599#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601/*
1602 * Destruction of arp-cache
1603 */
Chas Williams1fa99612006-09-29 17:11:47 -07001604static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001607 struct hlist_node *node, *next;
1608 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001609 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Tejun Heoafe2c512010-12-14 16:21:17 +01001611 cancel_delayed_work_sync(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001612
1613 /*
1614 * Remove all entries
1615 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001618 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001619 hlist_for_each_entry_safe(entry, node, next,
1620 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001621 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001622 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001623 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001624 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001625 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001626
Joe Perchesc48192a2010-01-26 11:40:08 +00001627 hlist_for_each_entry_safe(entry, node, next,
1628 &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001629 del_timer_sync(&entry->timer);
1630 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001631 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001632 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001633 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001634 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1635
Joe Perchesc48192a2010-01-26 11:40:08 +00001636 hlist_for_each_entry_safe(entry, node, next,
1637 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001638 del_timer_sync(&entry->timer);
1639 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001640 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001641 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001642 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001643 INIT_HLIST_HEAD(&priv->lec_no_forward);
1644
1645 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001646 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1647 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001648 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001649 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001650 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001651 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001652 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1654}
1655
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001656/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 * Find entry by mac_address
1658 */
Chas Williams1fa99612006-09-29 17:11:47 -07001659static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001660 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Chas Williamsd0732f62006-09-29 17:14:27 -07001662 struct hlist_node *node;
1663 struct hlist_head *head;
1664 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Joe Perches99824462010-01-26 11:40:00 +00001666 pr_debug("%pM\n", mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001667
Chas Williamsd0732f62006-09-29 17:14:27 -07001668 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1669 hlist_for_each_entry(entry, node, head, next) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001670 if (!compare_ether_addr(mac_addr, entry->mac_addr))
Chas Williamsd0732f62006-09-29 17:14:27 -07001671 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001672 }
1673 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Chas Williams1fa99612006-09-29 17:11:47 -07001676static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001677 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
Chas Williams1fa99612006-09-29 17:11:47 -07001679 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Chas Williams1fa99612006-09-29 17:11:47 -07001681 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1682 if (!to_return) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001683 pr_info("LEC: Arp entry kmalloc failed\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001684 return NULL;
1685 }
1686 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001687 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001688 setup_timer(&to_return->timer, lec_arp_expire_arp,
1689 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001690 to_return->last_used = jiffies;
1691 to_return->priv = priv;
1692 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001693 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001694 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
Chas Williams1fa99612006-09-29 17:11:47 -07001697/* Arp sent timer expired */
1698static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Chas Williams1fa99612006-09-29 17:11:47 -07001700 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Chas Williams1fa99612006-09-29 17:11:47 -07001702 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Joe Perches99824462010-01-26 11:40:00 +00001704 pr_debug("\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001705 if (entry->status == ESI_ARP_PENDING) {
1706 if (entry->no_tries <= entry->priv->max_retry_count) {
1707 if (entry->is_rdesc)
1708 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1709 entry->mac_addr, NULL, NULL);
1710 else
1711 send_to_lecd(entry->priv, l_arp_xmt,
1712 entry->mac_addr, NULL, NULL);
1713 entry->no_tries++;
1714 }
1715 mod_timer(&entry->timer, jiffies + (1 * HZ));
1716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Chas Williams1fa99612006-09-29 17:11:47 -07001719/* Unknown/unused vcc expire, remove associated entry */
1720static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
1722 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001723 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1724 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Chas Williams1fa99612006-09-29 17:11:47 -07001726 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Joe Perches99824462010-01-26 11:40:00 +00001728 pr_debug("%p %p: vpi:%d vci:%d\n",
1729 to_remove, priv,
1730 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1731 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1736
Chas Williams1fa99612006-09-29 17:11:47 -07001737 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001738 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739}
1740
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001741static bool __lec_arp_check_expire(struct lec_arp_table *entry,
1742 unsigned long now,
1743 struct lec_priv *priv)
1744{
1745 unsigned long time_to_check;
1746
1747 if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
1748 time_to_check = priv->forward_delay_time;
1749 else
1750 time_to_check = priv->aging_time;
1751
1752 pr_debug("About to expire: %lx - %lx > %lx\n",
1753 now, entry->last_used, time_to_check);
1754 if (time_after(now, entry->last_used + time_to_check) &&
1755 !(entry->flags & LEC_PERMANENT_FLAG) &&
1756 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1757 /* Remove entry */
1758 pr_debug("Entry timed out\n");
1759 lec_arp_remove(priv, entry);
1760 lec_arp_put(entry);
1761 } else {
1762 /* Something else */
1763 if ((entry->status == ESI_VC_PENDING ||
1764 entry->status == ESI_ARP_PENDING) &&
1765 time_after_eq(now, entry->timestamp +
1766 priv->max_unknown_frame_time)) {
1767 entry->timestamp = jiffies;
1768 entry->packets_flooded = 0;
1769 if (entry->status == ESI_VC_PENDING)
1770 send_to_lecd(priv, l_svc_setup,
1771 entry->mac_addr,
1772 entry->atm_addr,
1773 NULL);
1774 }
1775 if (entry->status == ESI_FLUSH_PENDING &&
1776 time_after_eq(now, entry->timestamp +
1777 priv->path_switching_delay)) {
1778 lec_arp_hold(entry);
1779 return true;
1780 }
1781 }
1782
1783 return false;
1784}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785/*
1786 * Expire entries.
1787 * 1. Re-set timer
1788 * 2. For each entry, delete entries that have aged past the age limit.
1789 * 3. For each entry, depending on the status of the entry, perform
1790 * the following maintenance.
1791 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1792 * tick_count is above the max_unknown_frame_time, clear
1793 * the tick_count to zero and clear the packets_flooded counter
1794 * to zero. This supports the packet rate limit per address
1795 * while flooding unknowns.
1796 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1797 * than or equal to the path_switching_delay, change the status
1798 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1799 * regardless of the progress of the flush protocol.
1800 */
David Howellsc4028952006-11-22 14:57:56 +00001801static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
1803 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001804 struct lec_priv *priv =
1805 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001806 struct hlist_node *node, *next;
1807 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001808 unsigned long now;
Chas Williams1fa99612006-09-29 17:11:47 -07001809 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Joe Perches99824462010-01-26 11:40:00 +00001811 pr_debug("%p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001813restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001815 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001816 hlist_for_each_entry_safe(entry, node, next,
1817 &priv->lec_arp_tables[i], next) {
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001818 if (__lec_arp_check_expire(entry, now, priv)) {
1819 struct sk_buff *skb;
1820 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001822 spin_unlock_irqrestore(&priv->lec_arp_lock,
1823 flags);
1824 while ((skb = skb_dequeue(&entry->tx_wait)))
1825 lec_send(vcc, skb);
1826 entry->last_used = jiffies;
1827 entry->status = ESI_FORWARD_DIRECT;
Chas Williams33a9c2d2006-09-29 17:16:48 -07001828 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Joe Perchesb4c84ec2010-01-26 11:40:19 +00001830 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832 }
1833 }
1834 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1835
Chas Williams987e46b2006-09-29 17:15:59 -07001836 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837}
Chas Williams1fa99612006-09-29 17:11:47 -07001838
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839/*
1840 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001841 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 */
Chas Williams1fa99612006-09-29 17:11:47 -07001843static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Joe Perchesc48192a2010-01-26 11:40:08 +00001844 const unsigned char *mac_to_find,
1845 int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001846 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847{
1848 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001849 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 struct atm_vcc *found;
1851
Chas Williams1fa99612006-09-29 17:11:47 -07001852 if (mac_to_find[0] & 0x01) {
1853 switch (priv->lane_version) {
1854 case 1:
1855 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001856 case 2: /* LANE2 wants arp for multicast addresses */
1857 if (!compare_ether_addr(mac_to_find, bus_mac))
1858 return priv->mcast_vcc;
1859 break;
1860 default:
1861 break;
1862 }
1863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001866 entry = lec_arp_find(priv, mac_to_find);
1867
1868 if (entry) {
1869 if (entry->status == ESI_FORWARD_DIRECT) {
1870 /* Connection Ok */
1871 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001872 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001873 *ret_entry = entry;
1874 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001876 }
1877 /*
1878 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001879 * so another LE_ARP request can be made for this frame.
1880 */
Joe Perchesc48192a2010-01-26 11:40:08 +00001881 if (entry->status == ESI_ARP_PENDING)
Scott Talbert75b895c2005-09-29 17:31:30 -07001882 entry->no_tries = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07001883 /*
1884 * Data direct VC not yet set up, check to see if the unknown
1885 * frame count is greater than the limit. If the limit has
1886 * not been reached, allow the caller to send packet to
1887 * BUS.
1888 */
1889 if (entry->status != ESI_FLUSH_PENDING &&
1890 entry->packets_flooded <
1891 priv->maximum_unknown_frame_count) {
1892 entry->packets_flooded++;
Joe Perches99824462010-01-26 11:40:00 +00001893 pr_debug("Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001894 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001896 }
1897 /*
1898 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 * or BUS flood limit was reached for an entry which is
1900 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1901 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001902 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001903 *ret_entry = entry;
Joe Perches99824462010-01-26 11:40:00 +00001904 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1905 entry->vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001906 found = NULL;
1907 } else {
1908 /* No matching entry was found */
1909 entry = make_entry(priv, mac_to_find);
Joe Perches99824462010-01-26 11:40:00 +00001910 pr_debug("Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001911 if (!entry) {
1912 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001914 }
1915 lec_arp_add(priv, entry);
1916 /* We want arp-request(s) to be sent */
1917 entry->packets_flooded = 1;
1918 entry->status = ESI_ARP_PENDING;
1919 entry->no_tries = 1;
1920 entry->last_used = entry->timestamp = jiffies;
1921 entry->is_rdesc = is_rdesc;
1922 if (entry->is_rdesc)
1923 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1924 NULL);
1925 else
1926 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1927 entry->timer.expires = jiffies + (1 * HZ);
1928 entry->timer.function = lec_arp_expire_arp;
1929 add_timer(&entry->timer);
1930 found = priv->mcast_vcc;
1931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933out:
1934 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1935 return found;
1936}
1937
1938static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001939lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001940 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
1942 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001943 struct hlist_node *node, *next;
1944 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001945 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Joe Perches99824462010-01-26 11:40:00 +00001947 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001949 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001950 hlist_for_each_entry_safe(entry, node, next,
1951 &priv->lec_arp_tables[i], next) {
1952 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
1953 (permanent ||
1954 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001956 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001959 return 0;
1960 }
1961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001963 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
1966/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001967 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 */
1969static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001970lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1971 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07001972 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973{
1974 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001975 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07001976 struct lec_arp_table *entry, *tmp;
1977 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Joe Perches99824462010-01-26 11:40:00 +00001979 pr_debug("%smac:%pM\n",
1980 (targetless_le_arp) ? "targetless " : "", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
1982 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001983 entry = lec_arp_find(priv, mac_addr);
1984 if (entry == NULL && targetless_le_arp)
1985 goto out; /*
1986 * LANE2: ignore targetless LE_ARPs for which
1987 * we have no entry in the cache. 7.1.30
1988 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001989 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Joe Perchesc48192a2010-01-26 11:40:08 +00001990 hlist_for_each_entry_safe(entry, node, next,
1991 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001992 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
1993 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001994 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07001995 tmp = lec_arp_find(priv, mac_addr);
1996 if (tmp) {
1997 del_timer(&tmp->timer);
1998 tmp->status = ESI_FORWARD_DIRECT;
1999 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2000 tmp->vcc = entry->vcc;
2001 tmp->old_push = entry->old_push;
2002 tmp->last_used = jiffies;
2003 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002004 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002005 entry = tmp;
2006 } else {
2007 entry->status = ESI_FORWARD_DIRECT;
2008 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2009 entry->last_used = jiffies;
2010 lec_arp_add(priv, entry);
2011 }
2012 if (remoteflag)
2013 entry->flags |= LEC_REMOTE_FLAG;
2014 else
2015 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002016 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002017 dump_arp_table(priv);
2018 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002019 }
Chas Williams1fa99612006-09-29 17:11:47 -07002020 }
2021 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002022
Chas Williams1fa99612006-09-29 17:11:47 -07002023 entry = lec_arp_find(priv, mac_addr);
2024 if (!entry) {
2025 entry = make_entry(priv, mac_addr);
2026 if (!entry)
2027 goto out;
2028 entry->status = ESI_UNKNOWN;
2029 lec_arp_add(priv, entry);
2030 /* Temporary, changes before end of function */
2031 }
2032 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2033 del_timer(&entry->timer);
2034 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002035 hlist_for_each_entry(tmp, node,
2036 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002037 if (entry != tmp &&
2038 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2039 /* Vcc to this host exists */
2040 if (tmp->status > ESI_VC_PENDING) {
2041 /*
2042 * ESI_FLUSH_PENDING,
2043 * ESI_FORWARD_DIRECT
2044 */
2045 entry->vcc = tmp->vcc;
2046 entry->old_push = tmp->old_push;
2047 }
2048 entry->status = tmp->status;
2049 break;
2050 }
2051 }
2052 }
2053 if (remoteflag)
2054 entry->flags |= LEC_REMOTE_FLAG;
2055 else
2056 entry->flags &= ~LEC_REMOTE_FLAG;
2057 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2058 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002059 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002060 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002061 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002062 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063out:
2064 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2065}
2066
2067/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002068 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 */
2070static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002071lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002072 struct atm_vcc *vcc,
2073 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
2075 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002076 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002077 struct lec_arp_table *entry;
2078 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002081 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williams1fa99612006-09-29 17:11:47 -07002082 if (ioc_data->receive == 2) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002083 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002085 entry = lec_arp_find(priv, bus_mac);
2086 if (!entry) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002087 pr_info("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002089 }
2090 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2091 entry->recv_vcc = vcc;
2092 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002094 entry = make_entry(priv, bus_mac);
2095 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002097 del_timer(&entry->timer);
2098 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2099 entry->recv_vcc = vcc;
2100 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002101 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002102 goto out;
2103 } else if (ioc_data->receive == 1) {
2104 /*
2105 * Vcc which we don't want to make default vcc,
2106 * attach it anyway.
2107 */
Joe Perches99824462010-01-26 11:40:00 +00002108 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",
2109 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2110 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2111 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2112 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2113 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2114 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2115 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2116 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2117 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2118 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002119 entry = make_entry(priv, bus_mac);
2120 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002122 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2123 memset(entry->mac_addr, 0, ETH_ALEN);
2124 entry->recv_vcc = vcc;
2125 entry->old_recv_push = old_push;
2126 entry->status = ESI_UNKNOWN;
2127 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2128 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002129 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002130 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 dump_arp_table(priv);
2132 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002133 }
Joe Perches99824462010-01-26 11:40:00 +00002134 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",
2135 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2136 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2137 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2138 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2139 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2140 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2141 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2142 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2143 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2144 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002145 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002146 hlist_for_each_entry(entry, node,
2147 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002148 if (memcmp
2149 (ioc_data->atm_addr, entry->atm_addr,
2150 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002151 pr_debug("LEC_ARP: Attaching data direct\n");
2152 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Joe Perches99824462010-01-26 11:40:00 +00002153 entry->vcc ? entry->vcc->vci : 0,
2154 entry->recv_vcc ? entry->recv_vcc->
2155 vci : 0);
Chas Williams1fa99612006-09-29 17:11:47 -07002156 found_entry = 1;
2157 del_timer(&entry->timer);
2158 entry->vcc = vcc;
2159 entry->old_push = old_push;
2160 if (entry->status == ESI_VC_PENDING) {
2161 if (priv->maximum_unknown_frame_count
2162 == 0)
2163 entry->status =
2164 ESI_FORWARD_DIRECT;
2165 else {
2166 entry->timestamp = jiffies;
2167 entry->status =
2168 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002170 send_to_lecd(priv, l_flush_xmt,
2171 NULL,
2172 entry->atm_addr,
2173 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002175 }
2176 } else {
2177 /*
2178 * They were forming a connection
2179 * to us, and we to them. Our
2180 * ATM address is numerically lower
2181 * than theirs, so we make connection
2182 * we formed into default VCC (8.1.11).
2183 * Connection they made gets torn
2184 * down. This might confuse some
2185 * clients. Can be changed if
2186 * someone reports trouble...
2187 */
2188 ;
2189 }
2190 }
2191 }
2192 }
2193 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002194 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002195 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002197 }
2198 /*
2199 * Not found, snatch address from first data packet that arrives
2200 * from this vcc
2201 */
2202 entry = make_entry(priv, bus_mac);
2203 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002205 entry->vcc = vcc;
2206 entry->old_push = old_push;
2207 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2208 memset(entry->mac_addr, 0, ETH_ALEN);
2209 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002210 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002211 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2212 entry->timer.function = lec_arp_expire_vcc;
2213 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002214 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 dump_arp_table(priv);
2216out:
2217 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2218}
2219
Chas Williams1fa99612006-09-29 17:11:47 -07002220static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
2222 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002223 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002224 struct lec_arp_table *entry;
2225 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Joe Perches99824462010-01-26 11:40:00 +00002227 pr_debug("%lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002228restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002229 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2230 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002231 hlist_for_each_entry(entry, node,
2232 &priv->lec_arp_tables[i], next) {
2233 if (entry->flush_tran_id == tran_id &&
2234 entry->status == ESI_FLUSH_PENDING) {
Chas Williams1fa99612006-09-29 17:11:47 -07002235 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002236 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002237
Chas Williams6656e3c2006-09-29 17:17:17 -07002238 lec_arp_hold(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002239 spin_unlock_irqrestore(&priv->lec_arp_lock,
2240 flags);
Joe Perchesb4c84ec2010-01-26 11:40:19 +00002241 while ((skb = skb_dequeue(&entry->tx_wait)))
Stephen Hemminger162619e2009-01-09 13:01:01 +00002242 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002243 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002244 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002245 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002246 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002247 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002248 }
2249 }
2250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002252 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253}
2254
2255static void
2256lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002257 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
2259 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002260 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002261 struct lec_arp_table *entry;
2262 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
2264 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002265 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Joe Perchesc48192a2010-01-26 11:40:08 +00002266 hlist_for_each_entry(entry, node,
2267 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002268 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2269 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002270 pr_debug("Set flush transaction id to %lx for %p\n",
Joe Perches99824462010-01-26 11:40:00 +00002271 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002272 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2275}
2276
Chas Williams1fa99612006-09-29 17:11:47 -07002277static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
2279 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002280 unsigned char mac_addr[] = {
2281 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2282 };
2283 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct lec_vcc_priv *vpriv;
2285 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002286
Joe Perchesc48192a2010-01-26 11:40:08 +00002287 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2288 if (!vpriv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 return -ENOMEM;
2290 vpriv->xoff = 0;
2291 vpriv->old_pop = vcc->pop;
2292 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002293 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002295 to_add = make_entry(priv, mac_addr);
2296 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 vcc->pop = vpriv->old_pop;
2298 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002299 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002301 }
2302 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2303 to_add->status = ESI_FORWARD_DIRECT;
2304 to_add->flags |= LEC_PERMANENT_FLAG;
2305 to_add->vcc = vcc;
2306 to_add->old_push = vcc->push;
2307 vcc->push = lec_push;
2308 priv->mcast_vcc = vcc;
2309 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310out:
2311 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002312 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
Chas Williams1fa99612006-09-29 17:11:47 -07002315static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
2317 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002318 struct hlist_node *node, *next;
2319 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002320 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Stephen Hemminger52240062007-08-28 15:22:09 -07002322 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002323 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002324
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002326
Chas Williams1fa99612006-09-29 17:11:47 -07002327 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Joe Perchesc48192a2010-01-26 11:40:08 +00002328 hlist_for_each_entry_safe(entry, node, next,
2329 &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002330 if (vcc == entry->vcc) {
2331 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002332 lec_arp_put(entry);
Joe Perchesc48192a2010-01-26 11:40:08 +00002333 if (priv->mcast_vcc == vcc)
Chas Williams1fa99612006-09-29 17:11:47 -07002334 priv->mcast_vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07002335 }
2336 }
2337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Joe Perchesc48192a2010-01-26 11:40:08 +00002339 hlist_for_each_entry_safe(entry, node, next,
2340 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002341 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002342 lec_arp_clear_vccs(entry);
2343 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002344 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002345 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002346 }
Chas Williams1fa99612006-09-29 17:11:47 -07002347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
Joe Perchesc48192a2010-01-26 11:40:08 +00002349 hlist_for_each_entry_safe(entry, node, next,
2350 &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002351 if (entry->recv_vcc == vcc) {
2352 lec_arp_clear_vccs(entry);
2353 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002354 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002355 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002356 }
Chas Williams1fa99612006-09-29 17:11:47 -07002357 }
2358
Chas Williamsd0732f62006-09-29 17:14:27 -07002359 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002360 if (entry->recv_vcc == vcc) {
2361 lec_arp_clear_vccs(entry);
2362 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002363 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002364 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002365 }
Chas Williams1fa99612006-09-29 17:11:47 -07002366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
2368 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2369 dump_arp_table(priv);
2370}
2371
2372static void
2373lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002374 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Chas Williams1fa99612006-09-29 17:11:47 -07002376 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002377 struct hlist_node *node, *next;
2378 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002379 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2380 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002382 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Chas Williams1fa99612006-09-29 17:11:47 -07002384 if (priv->is_trdev)
2385 src = tr_hdr->h_source;
2386 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002388 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
2390 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Joe Perchesc48192a2010-01-26 11:40:08 +00002391 hlist_for_each_entry_safe(entry, node, next,
2392 &priv->lec_arp_empty_ones, next) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002393 if (vcc == entry->vcc) {
2394 del_timer(&entry->timer);
2395 memcpy(entry->mac_addr, src, ETH_ALEN);
2396 entry->status = ESI_FORWARD_DIRECT;
2397 entry->last_used = jiffies;
2398 /* We might have got an entry */
Joe Perchesc48192a2010-01-26 11:40:08 +00002399 tmp = lec_arp_find(priv, src);
2400 if (tmp) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002401 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002402 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002403 }
2404 hlist_del(&entry->next);
2405 lec_arp_add(priv, entry);
2406 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002407 }
Chas Williams1fa99612006-09-29 17:11:47 -07002408 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002409 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410out:
2411 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2412}
Chas Williams1fa99612006-09-29 17:11:47 -07002413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414MODULE_LICENSE("GPL");